Package org.formulacompiler.compiler

Examples of org.formulacompiler.compiler.CallFrame



  private CallFrame mapDynamicParams( CallFrame _frame ) throws CompilerException
  {
    if (null == _frame) return null;
    CallFrame prev = mapDynamicParams( _frame.getPrev() );
    final Object[] args = _frame.getArgs();
    boolean changed = false;
    if (null != args) {
      for (int i = 0; i < args.length; i++) {
        if (args[ i ] instanceof CellIndex) {
          CellIndex cell = (CellIndex) args[ i ];
          CellModel model = getOrCreateCellModel( cell );
          args[ i ] = model;
          changed = true;
        }
      }
    }
    if (null != prev) {
      return prev.chain( _frame.getMethod(), args );
    }
    else if (changed) {
      return FormulaCompiler.newCallFrame( _frame.getMethod(), args );
    }
    return _frame;
View Full Code Here


    public Section defineRepeatingSection( Range _range, Orientation _orientation,
        Method _inputMethodReturningIterable, Class _inputClass, Method _outputMethodReturningIterableToImplement,
        Class _outputClass ) throws CompilerException
    {
      final CallFrame inputCall = SpreadsheetCompiler.newCallFrame( _inputMethodReturningIterable );
      final CallFrame outputCall = (_outputMethodReturningIterableToImplement == null) ? null : SpreadsheetCompiler
          .newCallFrame( _outputMethodReturningIterableToImplement );
      return defineRepeatingSection( _range, _orientation, inputCall, _inputClass, outputCall, _outputClass );
    }
View Full Code Here

  protected void compileBody() throws CompilerException
  {
    final SubSectionCompiler sub = this.sub;
    final GeneratorAdapter mv = mv();

    final CallFrame outputCall = this.callToImplement;
    final Class outputContainerClass = outputCall.getMethod().getReturnType();

    // get$Sect0()
    mv.loadThis();
    mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL, section().classInternalName(), sub.getterName(), sub
        .getterDescriptor() );

    if (outputContainerClass.isArray()) {
      mv.visitInsn( Opcodes.ARETURN );
    }
    else {
      // Detail[] arr = get$Sect0();
      final int l_arr = mv.newLocal( sub.arrayType() );
      mv.storeLocal( l_arr );

      final int l_len = mv.newLocal( Type.INT_TYPE );
      mv.loadLocal( l_arr );
      mv.arrayLength();
      mv.storeLocal( l_len );

      // List lst = new ArrayList( arr.length );
      final int l_lst = mv.newLocal( ARRAYLIST_CLASS );
      mv.newInstance( ARRAYLIST_CLASS );
      mv.dup();
      mv.loadLocal( l_len );
      mv.visitMethodInsn( Opcodes.INVOKESPECIAL, ARRAYLIST_CLASS.getInternalName(), "<init>", "(I)V" );
      mv.storeLocal( l_lst );

      // for (int i = 0; i < len; i++) {
      final int l_i = mv.newLocal( Type.INT_TYPE );
      mv.push( 0 );
      mv.storeLocal( l_i );
      final Label test = mv.newLabel();
      mv.goTo( test );
      final Label again = mv.mark();

      // lst.add( arr[ i ] );
      mv.loadLocal( l_lst );
      mv.loadLocal( l_arr );
      mv.loadLocal( l_i );
      mv.arrayLoad( sub.classType() );
      mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL, ARRAYLIST_CLASS.getInternalName(), "add", "(Ljava/lang/Object;)Z" );
      mv.pop();

      // } // for
      mv.iinc( l_i, 1 );
      mv.mark( test );
      mv.loadLocal( l_i );
      mv.loadLocal( l_len );
      mv.ifCmp( Type.INT_TYPE, mv.LT, again );

      mv.loadLocal( l_lst );
      if (outputContainerClass.isAssignableFrom( List.class )) {
        // return lst;
        mv.visitInsn( Opcodes.ARETURN );
      }
      else if (outputContainerClass.isAssignableFrom( Iterator.class )) {
        // return lst.iterator();
        mv.visitMethodInsn( Opcodes.INVOKEVIRTUAL, ARRAYLIST_CLASS.getInternalName(), "iterator", "()"
            + ITERATOR_INTF.getDescriptor() );
        mv.visitInsn( Opcodes.ARETURN );
      }
      else {
        throw new CompilerException.UnsupportedDataType( "The return type of '"
            + outputCall.getMethod() + "' is not supported as input to a repeating section." );
      }
    }
  }
View Full Code Here

    mv.loadThis();
    mv.getField( section().classType(), sub.getterName(), sub.arrayType() );
    mv.ifNonNull( alreadySet );

    // ~ final DetailInput[] ds = this.inputs.getarray();
    final CallFrame inputCall = sub.model().getCallChainToCall();
    final Class inputContainerClass = inputCall.getMethod().getReturnType();
    final Type inputContainerType = Type.getType( inputContainerClass );
    final int l_ds = mv.newLocal( inputContainerType );
    compileInputGetterCall( inputCall );
    mv.storeLocal( l_ds );

    // ~ if (ds != null) {
    final Label isNull = mv.newLabel();
    mv.loadLocal( l_ds );
    mv.ifNull( isNull );

    int l_di;
    if (inputContainerClass.isArray()) {
      l_di = compileInitFromArray( sub, mv, l_ds );
    }
    else if (Collection.class.isAssignableFrom( inputContainerClass )) {
      l_di = compileInitFromCollection( sub, mv, l_ds );
    }
    else if (Iterable.class.isAssignableFrom( inputContainerClass )) {
      final int l_it = mv.newLocal( ITERATOR_INTF );
      mv.loadLocal( l_ds );
      mv.visitMethodInsn( Opcodes.INVOKEINTERFACE, ITERABLE_INTF.getInternalName(), "iterator", "()"
          + ITERATOR_INTF.getDescriptor() );
      mv.storeLocal( l_it );
      l_di = compileInitFromIterator( sub, mv, l_it );
    }
    else if (Iterator.class.isAssignableFrom( inputContainerClass )) {
      l_di = compileInitFromIterator( sub, mv, l_ds );
    }
    else {
      throw new CompilerException.UnsupportedDataType( "The return type of '"
          + inputCall.getMethod() + "' is not supported as input to a repeating section." );
    }

    // ~ ~ this.field = di;
    mv.loadThis();
    mv.loadLocal( l_di );
View Full Code Here

TOP

Related Classes of org.formulacompiler.compiler.CallFrame

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.