Package org.formulacompiler.compiler.internal.expressions

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



  @Override
  protected boolean visitCell( CellModel _cell ) throws CompilerException
  {
    final ExpressionNode expr = _cell.getExpression();
    if (null != expr) {
      inline( expr );
    }
    return true;
  }
View Full Code Here


    final List<String> tableLabels = getLabelsFromTable( tableDescriptor, tableElements );
    final List<ExpressionNode> dataElements = stripLabelsFromTable( tableDescriptor, tableElements );
    final List<CellModel> firstRow = getFirstRowFromTable( tableDescriptor, dataElements );
    final DataType[] colTypes = getColTypesFromFirstRow( firstRow );
    final int[] foldableColumnKeys = getFoldableColumnKeys( colTypes );
    final ExpressionNode data = getShapedDataFromTable( tableDescriptor, dataElements );

    final ArrayDescriptor critDescriptor = this.criteria.arrayDescriptor();
    final List<ExpressionNode> critElements = this.criteria.arguments();
    final List<String> critLabels = getLabelsFromTable( critDescriptor, critElements );
    final List<ExpressionNode> critData = stripLabelsFromTable( critDescriptor, critElements );
    final int[] critCols = associateCriteriaColumnsWithTableLabels( tableLabels, critLabels );

    final int foldedColumnIndex = buildFoldedColumnIndex( this.valueColumn, tableLabels );
    if (foldedColumnIndex < 0) {
      if (DataType.NUMERIC != TypeAnnotator.annotateExpr( this.valueColumn )) {
        throw new CompilerException.UnsupportedExpression(
            "The value column must either be a constant name or an index. It cannot be a computed name." );
      }
    }

    final FilterBuilder filterBuilder = new FilterBuilder();
    final ExpressionNode filter = filterBuilder.buildFilter( critCols, critData, colTypes, firstRow );

    final ExpressionNodeForFoldDatabase apply = new ExpressionNodeForFoldDatabase( this.fold, colTypes, this
        .colPrefix(), filter, foldedColumnIndex, foldableColumnKeys, this.valueColumn, data );

    return filterBuilder.encloseFoldInLets( apply );
View Full Code Here


  private List<String> getLabelsFromTable( ArrayDescriptor _tableDesc, List<ExpressionNode> _tableElements )
      throws CompilerException
  {
    final ExpressionNode first = _tableElements.get( 0 );
    if (first instanceof ExpressionNodeForArrayReference) {
      return getLabelsFromTable( _tableDesc, first.arguments() );
    }
    else {
      final int nCol = _tableDesc.numberOfColumns();
      final List<String> result = New.list( nCol );
      final Iterator<ExpressionNode> iElt = _tableElements.iterator();
View Full Code Here

  private void stripLabelsFromTableInto( ArrayDescriptor _tableDesc, List<ExpressionNode> _tableElements,
      List<ExpressionNode> _result )
  {
    final Iterator<ExpressionNode> iElt = _tableElements.iterator();
    final ExpressionNode first = iElt.next();
    if (first instanceof ExpressionNodeForArrayReference) {
      final ExpressionNodeForArrayReference firstArr = (ExpressionNodeForArrayReference) first;
      final ArrayDescriptor firstArrDesc = firstArr.arrayDescriptor();
      final int firstArrRows = firstArrDesc.numberOfRows();
      if (firstArrRows > 1) {
View Full Code Here

  private int getFirstRowFromTableInto( int _iCol, int _nCol, Iterator<ExpressionNode> _dataElements,
      Collection<CellModel> _row ) throws CompilerException
  {
    int iCol = _iCol;
    while (iCol < _nCol && _dataElements.hasNext()) {
      final ExpressionNode next = _dataElements.next();
      if (next instanceof ExpressionNodeForArrayReference || next instanceof ExpressionNodeForSubSectionModel) {
        iCol = getFirstRowFromTableInto( iCol, _nCol, next.arguments().iterator(), _row );
      }
      else {
        if (!(next instanceof ExpressionNodeForCellModel)) {
          throw new CompilerException.UnsupportedExpression( "Database table data must be cells." );
        }
View Full Code Here

  @Override
  protected boolean visitCell( CellModel _cell )
  {
    if (!isInlineable( _cell )) {
      final ExpressionNode expr = _cell.getExpression();
      if (null != expr) {
        _cell.setExpression( inlineIntermediateResultsInto( expr ) );
      }
    }
    return true;
View Full Code Here

  private ExpressionNode inlineIntermediateResultsInto( ExpressionNode _expr )
  {
    if (_expr == null) return null;

    ExpressionNode result = _expr;
    while (result instanceof ExpressionNodeForCellModel) {
      final ExpressionNodeForCellModel cellNode = (ExpressionNodeForCellModel) result;
      final CellModel cellModel = cellNode.getCellModel();
      if (!isInlineable( cellModel )) return result;
      result = cellModel.getExpression();
View Full Code Here


  @Override
  protected boolean visitCell( CellModel _cell ) throws CompilerException
  {
    ExpressionNode sourceExpr = _cell.getExpression();
    if (null != sourceExpr) {
      try {
        TypedResult optimizedResult = eliminateConstantsFrom( sourceExpr, _cell.getSection() );
        assert (optimizedResult.getDataType() == _cell.getDataType() || optimizedResult.getDataType() == DataType.NULL);
        if (optimizedResult.hasConstantValue()) {
          _cell.setExpression( null );
          final Object value = optimizedResult.getConstantValue();
          _cell.setConstantValue( value );
          if (this.listenerSupport != null) {
            this.listenerSupport.constantExpressionEliminated( _cell, value );
          }
        }
        else {
          ExpressionNode optimizedExpr = (ExpressionNode) optimizedResult;
          _cell.setExpression( optimizedExpr );
        }
      }
      catch (Throwable t) {
        throw new CompilerException.UnsupportedExpression( t );
View Full Code Here

  public void stepInto( SectionBinding _sectionDef )
  {
    SectionModelCompiler sectionCompiler = this.targetSectionCompiler.getOrCreateSectionCompiler( _sectionDef );
    SectionModel sectionModel = sectionCompiler.getSectionModel();
    ExpressionNode step = new ExpressionNodeForSubSectionModel( sectionModel );
    add( step );
    this.targetSectionCompiler = sectionCompiler;
  }
View Full Code Here

  public void stepOut()
  {
    SectionModel parentModel = this.targetSectionCompiler.getSectionModel().getSection();
    assert null != parentModel;
    SectionModelCompiler parentCompiler = this.targetSectionCompiler.getSection();
    ExpressionNode step = new ExpressionNodeForParentSectionModel( parentModel );
    add( step );
    this.targetSectionCompiler = parentCompiler;
  }
View Full Code Here

TOP

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

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.