Package org.apache.flex.abc.instructionlist

Examples of org.apache.flex.abc.instructionlist.InstructionList


     */
    private enum XMLContentState { TagStart, TagLiteral, TagName, Attr, ValueNeedsEquals, Value, TagEnd, ContentLiteral, ContentExpression };

    public InstructionList reduce_XMLContent(IASNode iNode, Vector<InstructionList> exprs)
    {
        InstructionList result = createInstructionList(iNode);

        result.addAll(currentScope.getPropertyValue(xmlType, currentScope.getProject().getBuiltinType(BuiltinType.XML)));

        //  Add all the arguments up into a single String.

        XMLContentState[] content_state = computeXMLContentStateMatrix(exprs);

        result.addAll(exprs.elementAt(0));

        for ( int i = 1; i < exprs.size(); i++ )
        {
            result.addAll(exprs.elementAt(i));

            switch ( content_state[i] )
            {
                case TagName:
                    {
                        //  Parser elides whitespace after tag name expressions.
                        result.addInstruction(OP_pushstring, " ");
                        result.addInstruction(OP_add);
                    }
                    break;
                case Attr:
                    {
                        //  Parser elides whitespace before attribute name expressions.
                        if ( content_state[i-1] != XMLContentState.TagName )
                        {
                            result.addInstruction(OP_pushstring, " ");
                            result.addInstruction(OP_swap);
                            result.addInstruction(OP_add);
                        }
                    }
                    break;
                case ValueNeedsEquals:
                    {
                        if ( content_state[i-1] == XMLContentState.Attr )
                        {
                            //  Parser elided this token.
                            result.addInstruction(OP_pushstring, "=");
                            result.addInstruction(OP_swap);
                            result.addInstruction(OP_add);
                        }
                    }
                    //  falls through
                case Value:
                    {
                        result.addInstruction(OP_esc_xattr);

                        //  The attribute will need quote marks for the AVM's XML parser.
                        result.addInstruction(OP_pushstring, "\"");
                        result.addInstruction(OP_swap);
                        result.addInstruction(OP_add);
                        result.addInstruction(OP_pushstring, "\"");
                        result.addInstruction(OP_add);
                    }
                    break;
                case ContentExpression:
                    result.addInstruction(OP_esc_xelem);
            }

            result.addInstruction(OP_add);
        }

        result.addInstruction(OP_construct, 1);
        return result;
    }
View Full Code Here


    public InstructionList reduce_preIncNameExpr(IASNode iNode, Binding unary, boolean need_result)
    {
        currentScope.getMethodBodySemanticChecker().checkIncDec(iNode, true, unary);
       
        InstructionList result = createInstructionList(iNode);

        if ( unary.isLocal() ) {
            ICompilerProject project = currentScope.getProject();

            IDefinition inType = SemanticUtils.resolveUnaryExprType(iNode, project);

            IDefinition intType = project.getBuiltinType(BuiltinType.INT);
            IDefinition numberType = project.getBuiltinType(BuiltinType.NUMBER);
            if( inType == intType)
            {
                // Incrementing a local, typed as int
                // we can use inclocal_i since we know the result will be stored in an int
                result.addInstruction(unary.inclocal_i());
                if( need_result )
                    result.addInstruction(unary.getlocal());
            }
            else if( inType == numberType)
            {
                // Incrementing a local, typed as Number
                // we can use inclocal since we know the result will be stored in a Number
                result.addInstruction(unary.inclocal());
                if( need_result )
                    result.addInstruction(unary.getlocal());
            }
            else
            {
                result.addInstruction(unary.getlocal());
                result.addInstruction(OP_increment);
                if( need_result )
                    result.addInstruction(OP_dup);
                coerce(result, inType);
                result.addInstruction(unary.setlocal());
            }
        }
        else
        {
            Name n = unary.getName();
            result.addAll(currentScope.findProperty(unary, true));
            result.addInstruction(OP_getproperty,n);
            result.addInstruction(OP_increment);
            if( need_result )
                result.addInstruction(OP_dup);
            result.addAll(currentScope.findProperty(unary, true));
            result.addInstruction(OP_swap);
            result.addInstruction(OP_setproperty,n);
        }

        return result;
    }
View Full Code Here

    public InstructionList reduce_regexLiteral(IASNode iNode)
    {
        String flags = ((RegExpLiteralNode) iNode).getFlagString();
       
        // If flags are defined, additional pushstring instruction is needed
        InstructionList result = createInstructionList(iNode, (flags.isEmpty()) ? 4 : 5);

        result.addAll(currentScope.getPropertyValue(regexType, currentScope.getProject().getBuiltinType(BuiltinType.REGEXP)));
        result.addInstruction(OP_pushstring, getStringLiteralContent(iNode));
       
        if (!flags.isEmpty())
        {
            result.addInstruction(OP_pushstring, flags);
            result.addInstruction(OP_construct, 2);
        }
        else
        {
            result.addInstruction(OP_construct, 1);
        }
       
        return result;
    }
View Full Code Here

    public InstructionList reduce_returnVoidSideEffect(IASNode iNode, InstructionList value)
  {
        currentScope.getMethodBodySemanticChecker().checkReturnValue(iNode);

    //  Evaluate the expression for possible side effects.
    InstructionList result = createInstructionList(iNode);
    result.addAll(value);
    result.addInstruction(OP_returnvoid);
    return result;
  }
View Full Code Here

        //  goes to the control-flow manager to be massaged into
        //  the control-flow unwinding code required by the current
        //  control flow contexts, if any.
        //  HOWEVER: as an optimization, the temp and the stub IL
        //  are only used when the flow manager says they're needed.
        InstructionList result = createInstructionList(iNode);
        result.addAll(value);

        Binding result_temp = null;
        boolean need_temp = currentScope.getFlowManager().hasNontrivialFlowCharacteristics();

        if ( need_temp )
        {
            result_temp = currentScope.allocateTemp();
            result.addInstruction(result_temp.setlocal());
        }

        InstructionList controlFlowStub = null;
        FunctionDefinition function_def = SemanticUtils.getFunctionDefinition(iNode);
        if ( need_temp )
        {
            controlFlowStub = createInstructionList(iNode);
            controlFlowStub.addInstruction(result_temp.getlocal());
            addRelevantReturnOpcode(function_def, opcode, controlFlowStub);
        }
        else
        {
            addRelevantReturnOpcode(function_def, opcode, result);
        }

        try
        {
            if ( need_temp )
            {
                //  The controlFlowStub may be replaced by code that
                //  branches to some context unwinding.
                result.addAll(getNonLocalControlFlow(controlFlowStub, ControlFlowContextManager.FIND_ALL_CONTEXTS));
            }
            else
            {
                //  Ensure we get back the same IL as sent in,
                //  or the ABC will be incorrect.
                InstructionList prev_result = result;
                result = getNonLocalControlFlow(result, ControlFlowContextManager.FIND_ALL_CONTEXTS);
                assert result == prev_result;
            }
        }
        catch ( UnknownControlFlowTargetException cant_return )
View Full Code Here

        return result;
    }

    public InstructionList reduce_returnVoid(IASNode iNode)
    {
        InstructionList result = createInstructionList(iNode, 1);
        currentScope.getMethodBodySemanticChecker().checkReturnVoid(iNode);
        FunctionDefinition functionDef = SemanticUtils.getFunctionDefinition(iNode);
        addRelevantReturnOpcode(functionDef, OP_returnvoid, result);

        try
View Full Code Here

        return n;
    }
   
    public InstructionList reduce_strictneqExpr(IASNode iNode, InstructionList l, InstructionList r)
    {
        InstructionList result = binaryOp(iNode, l, r, OP_strictequals);
        result.addInstruction(OP_not);
        return result;
    }
View Full Code Here

    public InstructionList reduce_superCallExpr(IASNode iNode, Vector<InstructionList> args)
    {
        currentScope.getMethodBodySemanticChecker().checkExplicitSuperCall(iNode, args);
        //  TODO: Investigate optimizing this.
        InstructionList result = createInstructionList(iNode);
        //  Special case first part: don't look for the "super" name,
        //  push "this" on the stack.
        result.addInstruction(OP_getlocal0);
        for ( InstructionList arg: args)
            result.addAll(arg);
        // Special case second part: call constructsuper.
        result.addInstruction(OP_constructsuper, args.size() );
        return result;
    }
View Full Code Here

        return lookupSwitchInfo;
    }

    private InstructionList reduce_lookup_switchStmt(IASNode iNode, InstructionList switch_expr, Vector<ConditionalFragment> cases, LookupSwitchInfo lookupSwitchInfo)
    {
        InstructionList result = createInstructionList(iNode);

        result.addAll(switch_expr);
        result.addInstruction(OP_convert_i);

        // save some space in the case table, by not generating entries
        // for any values between 0 and the min case value
        int caseOffset = 0;
        if (lookupSwitchInfo.minCase > 0)
        {
            caseOffset = lookupSwitchInfo.minCase;
            lookupSwitchInfo.minCase = 0;
            lookupSwitchInfo.maxCase = lookupSwitchInfo.maxCase - caseOffset;
            result.addInstruction(OP_pushint, Integer.valueOf(caseOffset));
            result.addInstruction(OP_subtract_i);
        }
        // if we have negative values in the case expression, need
        // to offset from zero
        else if (lookupSwitchInfo.minCase < 0)
        {
            caseOffset = lookupSwitchInfo.minCase;
            lookupSwitchInfo.minCase = 0;
            lookupSwitchInfo.maxCase = lookupSwitchInfo.maxCase - caseOffset;
            result.addInstruction(OP_pushint, new Integer(lookupSwitchInfo.minCase + 1));
            result.addInstruction(OP_add_i);
        }

        Label switchTail = null;
        Label defaultLabel;

        if (lookupSwitchInfo.defaultCase != null)
            defaultLabel = lookupSwitchInfo.defaultCase.getLabel();
        else
            defaultLabel = switchTail = new Label();

        // generate the case table, maxCase+2, as count from zero
        // and add one for the default label at the end
        Label[] caseLabels = new Label[lookupSwitchInfo.maxCase + 2];

        // pre-fill the case label table with the default label.
        Arrays.fill(caseLabels, defaultLabel);

        // fill in specific labels for any specified values
        for (ConditionalFragment current_case : cases)
        {
            if (current_case.isUnconditionalAlternative())
                continue;

            Object caseValue = current_case.constantCondition;
            // a constant of value 90000 was in a SWC as a double even though
            // the type of the constant was int
            if (caseValue instanceof Double)
                caseValue = new Integer(((Double)caseValue).intValue());
            assert (caseValue instanceof Integer) : "reduce_lookup_switchStmt called on non integer case value";
            final int index = (Integer)caseValue - caseOffset;
            // if there is already a non-default value for this
            // index, ignore it, as only the first case counts
            if (caseLabels[index] != defaultLabel)
                continue;

            caseLabels[index] = current_case.getLabel();
        }

        result.addInstruction(OP_lookupswitch, caseLabels);

        Label default_case_label = null;
        for (ConditionalFragment current_case : cases)
        {
            if (current_case.isUnconditionalAlternative())
            {
                //  The parser rejects duplicate default alternatives
                //  in some situations, but not in others.
                if (default_case_label == null)
                    default_case_label = current_case.statement.getLabel();
                else
                    currentScope.addProblem(new MultipleSwitchDefaultsProblem(current_case.site));
            }

            result.addAll(current_case.statement);
        }

        switchTail = addInterstitialControlFlow(result, switchTail);

        //  No continue here, and thus there is no need
        //  to check for previous labeled flow contexts.
        currentScope.getFlowManager().finishSwitchControlFlowContext(result);

        if ( switchTail != null )
            result.labelNext(switchTail);

        return result;
    }
View Full Code Here

        // to a conditional expression when not generating
        // a lookup switch
        convertConstantValueConditionsToInstructions(cases);

        //  TODO: Optimize InstructionList size.
        InstructionList result = createInstructionList(iNode);
        Label default_case_label = null;
        Label switch_tail = null;

        //  Get the switch value and save it in a temp.
        Binding switch_temp = currentScope.allocateTemp();
        result.addAll(switch_expr);
        result.addInstruction(switch_temp.setlocal());

        //  First, jump to the switch table.
        if ( ! cases.elementAt(0).isUnconditionalAlternative() || cases.size() == 1 )
            result.addInstruction(OP_jump, cases.elementAt(0).getLabel());
        else
            result.addInstruction(OP_jump, cases.elementAt(1).getLabel());


        for ( ConditionalFragment current_case: cases )
        {
            //  Ensure the case begins with a OP_label instruction
            //  so we can branch back to it.
            if ( current_case.statement.isEmpty() || current_case.statement.firstElement().getOpcode() != OP_label )
            {
                InstructionList labeled_list = createInstructionList(iNode);
                labeled_list.addInstruction(OP_label);
                labeled_list.addAll(current_case.statement);
                current_case.statement = labeled_list;
            }

            if ( current_case.isUnconditionalAlternative() )
            {
View Full Code Here

TOP

Related Classes of org.apache.flex.abc.instructionlist.InstructionList

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.