Package org.formulacompiler.compiler.internal.expressions

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


      for (int iArray = 0; iArray < nArrays; iArray++) {
        final ExpressionNode valueArrayNode = getHVLookupSubArray( fun, arrayNode, iArray );
        final ExpressionNode lookupNode = fun( INDEX, valueArrayNode, matchRefNode );
        caseNodes[ iArray ] = new ExpressionNodeForSwitchCase( lookupNode, iArray + 1 );
      }
      final ExpressionNode switchNode = new ExpressionNodeForSwitch( selectorNode, defaultNode, caseNodes );
      final ExpressionNode matchLetNode = letByName( matchRefName, matchNode, switchNode );
      return matchLetNode;
    }
  }
View Full Code Here


  /**
   * Rewrites CHOOSE to SWITCH.
   */
  private ExpressionNode rewriteChoose( ExpressionNodeForFunction _fun )
  {
    final ExpressionNodeForSwitch result = new ExpressionNodeForSwitch( _fun.argument( 0 ),
        err( "#VALUE! because index to CHOOSE is out of range" ) );
    for (int iCase = 1; iCase < _fun.cardinality(); iCase++) {
      result.addArgument( new ExpressionNodeForSwitchCase( _fun.argument( iCase ), iCase ) );
    }
    return result;
  }
View Full Code Here


  @Override
  protected TypedResult eval() throws CompilerException
  {
    final ExpressionNodeForSwitch switchNode = (ExpressionNodeForSwitch) node();
    final TypedResult valueArg = evaluateArgument( switchNode.offsetOfValueInArguments() );
    if (valueArg.hasConstantValue()) {
      final int value = type().toInt( valueArg.getConstantValue(), -1 );
      if (value >= 0) {
        final Iterable<ExpressionNodeForSwitchCase> cases = switchNode.cases();
        int iCase = 0;
        for (ExpressionNodeForSwitchCase caze : cases) {
          if (value == caze.caseValue()) {
            final EvalSwitchCase caseEval = (EvalSwitchCase) arguments().get(
                iCase + switchNode.offsetOfCasesInArguments() );
            final TypedResult caseResult = caseEval.evaluateArgument( 0, context() );
            return caseResult;
          }
          iCase++;
        }
      }
      return evaluateArgument( switchNode.offsetOfDefaultInArguments() );
    }
    return super.eval();
  }
View Full Code Here


  @Override
  protected void compileBody() throws CompilerException
  {
    final ExpressionNodeForSwitch switchNode = (ExpressionNodeForSwitch) node();
    numericCompiler().compileInt( switchNode.selector() );

    int nCases = switchNode.numberOfCases();
    if (nCases > 0) {
      final int[] switchValues = new int[ nCases ];
      final ExpressionNodeForSwitchCase[] switchValueCases = new ExpressionNodeForSwitchCase[ nCases ];
      int iSwitchValue = 0;
      for (ExpressionNodeForSwitchCase caze : switchNode.cases()) {
        switchValueCases[ iSwitchValue ] = caze;
        switchValues[ iSwitchValue ] = caze.caseValue();
        iSwitchValue++;
      }

      compileTableSwitch( switchValues, new TableSwitchGenerator()
      {
        private final int valReturn = expressionCompiler().typeCompiler().returnOpcode();
        private int switchIndex = 0;

        @Override
        protected void generateCase( int _key, Label _end ) throws CompilerException
        {
          final ExpressionNodeForSwitchCase caze = switchValueCases[ this.switchIndex++ ];
          if (null != caze) {
            compileExpression( caze.value() );
            mv().visitInsn( this.valReturn );
          }
        }

      } );
    }

    compileExpression( switchNode.defaultValue() );
  }
View Full Code Here

TOP

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

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.