Package org.formulacompiler.compiler.internal.expressions

Examples of org.formulacompiler.compiler.internal.expressions.ExpressionNodeForArrayReference


  }


  private ExpressionNode rewriteArrayLookup( ExpressionNodeForFunction _fun )
  {
    final ExpressionNodeForArrayReference array = (ExpressionNodeForArrayReference) _fun.argument( 1 );
    final ArrayDescriptor desc = array.arrayDescriptor();
    final int cols = desc.numberOfColumns();
    final int rows = desc.numberOfRows();
    final Function lookupFun;
    final int index;
    if (cols > rows) {
View Full Code Here


  private ExpressionNode rewriteHVLookup( ExpressionNodeForFunction _fun )
  {
    final Function fun = _fun.getFunction();
    final ExpressionNode valueNode = _fun.argument( 0 );
    final ExpressionNodeForArrayReference arrayNode = (ExpressionNodeForArrayReference) _fun.argument( 1 );
    final ExpressionNode indexNode = _fun.argument( 2 );
    final ExpressionNode lookupArrayNode = getHVLookupSubArray( fun, arrayNode, 0 );

    final ExpressionNode matchNode;
    final Function matchFun = (indexNode instanceof ExpressionNodeForConstantValue) ? INTERNAL_MATCH_INT : MATCH;
    if (_fun.cardinality() >= 4) {
      final ExpressionNode typeNode = _fun.argument( 3 );
      matchNode = new ExpressionNodeForFunction( matchFun, valueNode, lookupArrayNode, typeNode );
    }
    else {
      matchNode = new ExpressionNodeForFunction( matchFun, valueNode, lookupArrayNode );
    }

    if (indexNode instanceof ExpressionNodeForConstantValue) {
      final ExpressionNodeForConstantValue constIndex = (ExpressionNodeForConstantValue) indexNode;
      final int index = this.numericType.toInt( constIndex.value(), -1 ) - 1;
      final ExpressionNode valueArrayNode = getHVLookupSubArray( fun, arrayNode, index );
      return fun( INDEX, valueArrayNode, matchNode );
    }
    else {
      final String matchRefName = "x";
      final ExpressionNode matchRefNode = var( matchRefName );
      final ExpressionNode selectorNode = indexNode;
      final ExpressionNode defaultNode = err( "#VALUE/REF! because index is out of range in H/VLOOKUP" );

      final ArrayDescriptor desc = arrayNode.arrayDescriptor();
      final int nArrays = (fun == HLOOKUP) ? desc.numberOfRows() : desc.numberOfColumns();
      final ExpressionNodeForSwitchCase[] caseNodes = new ExpressionNodeForSwitchCase[ nArrays ];
      for (int iArray = 0; iArray < nArrays; iArray++) {
        final ExpressionNode valueArrayNode = getHVLookupSubArray( fun, arrayNode, iArray );
        final ExpressionNode lookupNode = fun( INDEX, valueArrayNode, matchRefNode );
View Full Code Here

    final int eltCount = fold.eltCount();
    final ArrayDescriptor desc = new ArrayDescriptor( 1, _dynArgs.size(), 1 );
    final ExpressionNode[] vectors = new ExpressionNode[ eltCount ];
    ExpressionNode[] firstElts = _dynArgs.iterator().next();
    for (int i = 0; i < eltCount; i++) {
      vectors[ i ] = new ExpressionNodeForArrayReference( desc );
      vectors[ i ].setDataType( firstElts[ i ].getDataType() );
      _apply.addArgument( vectors[ i ] );
    }
    for (ExpressionNode[] elts : _dynArgs) {
      assert elts.length == eltCount;
View Full Code Here

  public static int match( Object _lookup, Object _in, int _type )
  {
    if (null == _in) {
      throw new FormulaException( "#VALUE! because range is empty in MATCH" );
    }
    final ExpressionNodeForArrayReference range = (ExpressionNodeForArrayReference) _in;
    if (0 == _type) {
      int iObj = 0;
      for (Object arg : range.arguments()) {
        final Object elt = ((ExpressionNodeForConstantValue) arg).value();
        if (_lookup.equals( elt )) return iObj;
        iObj++;
      }
      throw new NotAvailableException();
    }
    else {
      final Comparable comp = (Comparable) _lookup;
      final int isToRightWhenComparesAs = (_type > 0) ? 1 : -1;
      final List<ExpressionNode> args = range.arguments();
      final int iLast = args.size() - 1;
      int iLeft = 0;
      int iRight = iLast;
      while (iLeft < iRight) {
        final int iMid = iLeft + ((iRight - iLeft) >> 1);
View Full Code Here


  protected final Object[] asArrayOfConsts( Object _value )
  {
    if (_value instanceof ExpressionNodeForArrayReference) {
      final ExpressionNodeForArrayReference array = (ExpressionNodeForArrayReference) _value;
      final Object[] r = new Object[ array.arrayDescriptor().numberOfElements() ];
      int i = 0;
      for (ExpressionNode cst : array.arguments()) {
        r[ i++ ] = ((ExpressionNodeForConstantValue) cst).value();
      }
      return r;
    }
    else {
View Full Code Here

          elts.add( buildExpressionModelForLocalRange( next ) );
        }
      }

      final CellIndex from = range.getFrom();
      final ExpressionNode result = (shaped) ? new ExpressionNodeForArrayReference( new ArrayDescriptor(
          from.getSheetIndex(), from.getRowIndex(), from.getColumnIndex(), sheets, rows, cols ) )
          : new ExpressionNodeForSubstitution();
      result.arguments().addAll( elts );
      return result;
    }
View Full Code Here

      final CellIndex from = _range.getFrom();
      final CellIndex to = _range.getTo();
      final int sheets = to.getSheetIndex() - from.getSheetIndex() + 1;
      final int rows = to.getRowIndex() - from.getRowIndex() + 1;
      final int cols = to.getColumnIndex() - from.getColumnIndex() + 1;
      final ExpressionNode result = new ExpressionNodeForArrayReference( new ArrayDescriptor( from.getSheetIndex(),
          from.getRowIndex(), from.getColumnIndex(), sheets, rows, cols ) );
      buildExpressionModelsForLocalRangeCells( _range, result.arguments() );
      return result;
    }
View Full Code Here

  }

  @Override
  protected TypedResult evaluateToConst( TypedResult... _args )
  {
    final ExpressionNodeForArrayReference rangeNode = (ExpressionNodeForArrayReference) node();
    final ExpressionNodeForArrayReference result = new ExpressionNodeForArrayReference( rangeNode.arrayDescriptor() );
    result.setDataType( rangeNode.getDataType() );
    for (TypedResult arg : _args) {
      if (arg instanceof ExpressionNode) {
        result.addArgument( (ExpressionNode) arg );
      }
      else {
        result.addArgument( new ExpressionNodeForConstantValue( arg.getConstantValue(), arg.getDataType() ) );
      }
    }
    return result;
  }
View Full Code Here


  public final ExpressionNode rewrite() throws CompilerException
  {
    // We need the type info to properly treat by-example criteria contained in strings.
    final ExpressionNodeForArrayReference tested = makeVertical( this.tested );
    TypeAnnotator.annotateExpr( tested );

    final FilterBuilder filterBuilder = new FilterBuilder();
    final DataType testedType = tested.getDataType();
    final ExpressionNode filter = filterBuilder.buildFilterByExample( 0, this.test, testedType );

    final ExpressionNodeForFoldDatabase apply;
    if (this.folded == null) {
      apply = new ExpressionNodeForFoldDatabase( this.fold, New.array( testedType ), this.colPrefix(), filter, 0,
View Full Code Here

    }
    else {
      assert desc.numberOfRows() == 1;
      final ArrayDescriptor newDesc = new ArrayDescriptor( desc.origin(), new ArrayDescriptor.Point( 1, desc
          .numberOfColumns(), 1 ) );
      final ExpressionNodeForArrayReference newVector = new ExpressionNodeForArrayReference( newDesc );
      newVector.arguments().addAll( _vector.arguments() );
      return newVector;
    }
  }
View Full Code Here

TOP

Related Classes of org.formulacompiler.compiler.internal.expressions.ExpressionNodeForArrayReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.