Package org.apache.flex.abc.instructionlist

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


    {
        assert site instanceof ICSSProperty : "Expected ICSSProperty node but got " + site.getClass().getName();
        final ICSSProperty propertyNode = (ICSSProperty)site;
        final String name = propertyNode.getName();
        final ICSSPropertyValue value = propertyNode.getValue();
        final InstructionList inst = new InstructionList();

        final InstructionList valueInstructions = getInstructionListForPropertyValue(value);
        if (!valueInstructions.isEmpty())
        {
            // push "this" on the stack
            inst.addInstruction(ABCConstants.OP_getlocal0);
            // push value on the stack
            inst.addAll(valueInstructions);
            // set the property value
            inst.addInstruction(ABCConstants.OP_setproperty, new Name(name));
        }

        return new PairOfInstructionLists(new InstructionList(), inst);
    }
View Full Code Here


     * @param value CSS property value.
     * @return AET instructions.
     */
    private InstructionList getInstructionListForPropertyValue(final ICSSPropertyValue value)
    {
        final InstructionList valueInstructions = new InstructionList();
        // push property value on the stack
        if (value instanceof CSSStringPropertyValue)
        {
            valueInstructions.addInstruction(ABCConstants.OP_pushstring, ((CSSStringPropertyValue)value).getValue());
        }
        else if (value instanceof CSSColorPropertyValue)
        {
            valueInstructions.addInstruction(ABCConstants.OP_pushint, new Integer(((CSSColorPropertyValue)value).getColorAsInt()));
        }
        else if (value instanceof CSSRgbColorPropertyValue)
        {
            valueInstructions.addInstruction(ABCConstants.OP_pushint, new Integer(((CSSRgbColorPropertyValue)value).getColorAsInt()));
        }
        else if (value instanceof CSSKeywordPropertyValue)
        {
            CSSKeywordPropertyValue keywordValue = (CSSKeywordPropertyValue)value;
            String keywordString = keywordValue.getKeyword();
            if (IASLanguageConstants.TRUE.equals(keywordString))
                valueInstructions.addInstruction(ABCConstants.OP_pushtrue);
            else if (IASLanguageConstants.FALSE.equals(keywordString))
                valueInstructions.addInstruction(ABCConstants.OP_pushfalse);
            else
                valueInstructions.addInstruction(ABCConstants.OP_pushstring, ((CSSKeywordPropertyValue)value).getKeyword());
        }
        else if (value instanceof CSSNumberPropertyValue)
        {
            valueInstructions.addInstruction(ABCConstants.OP_pushdouble, new Double(((CSSNumberPropertyValue)value).getNumber().doubleValue()));
        }
        else if (value instanceof CSSFunctionCallPropertyValue)
        {
            final CSSFunctionCallPropertyValue functionCall = (CSSFunctionCallPropertyValue)value;
            if ("ClassReference".equals(functionCall.name))
            {
                final String className = CSSFunctionCallPropertyValue.getSingleArgumentFromRaw(functionCall.rawArguments);
                if ("null".equals(className))
                {
                    // ClassReference(null) resets the property's class reference.
                    valueInstructions.addInstruction(ABCConstants.OP_pushnull);
                }
                else
                {
                    final IResolvedQualifiersReference reference = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), className);
                    valueInstructions.addInstruction(ABCConstants.OP_getlex, reference.getMName());
                }
            }
            else if ("url".equals(functionCall.name))
            {
                final String urlString = CSSFunctionCallPropertyValue.getSingleArgumentFromRaw(functionCall.rawArguments);
                valueInstructions.addInstruction(ABCConstants.OP_pushstring, urlString);
            }
            else if ("PropertyReference".equals(functionCall.name))
            {
                // TODO: implement me
            }
            else if ("Embed".equals(functionCall.name))
            {
                final EmbedCompilationUnit embedCompilationUnit = session.resolvedEmbedProperties.get(functionCall);
                if (embedCompilationUnit == null)
                {
                    final ICompilerProblem e = new CSSCodeGenProblem(
                            new IllegalStateException("Unable to find compilation unit for " + functionCall));
                    problems.add(e);
                }
                else
                {
                    final String qName = embedCompilationUnit.getName();
                    final IResolvedQualifiersReference reference = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), qName);
                    valueInstructions.addInstruction(ABCConstants.OP_getlex, reference.getMName());
                }
            }
            else
            {
                assert false : "CSS parser bug: unexpected function call property value: " + functionCall;
                throw new IllegalStateException("Unexpected function call property value: " + functionCall);
            }
        }
        else if (value instanceof CSSArrayPropertyValue)
        {
            final CSSArrayPropertyValue arrayValue = (CSSArrayPropertyValue)value;
            for (final ICSSPropertyValue elementValue : arrayValue.getElements())
            {
                valueInstructions.addAll(getInstructionListForPropertyValue(elementValue));
            }
            valueInstructions.addInstruction(ABCConstants.OP_newarray, arrayValue.getElements().size());
        }
        else
        {
            assert false : "Unsupported property value: " + value;
        }
View Full Code Here

     * to set property values. It also add instructions to setup the stack frame
     * for this function closure.
     */
    public PairOfInstructionLists reducePropertyList(ICSSNode site, List<PairOfInstructionLists> properties)
    {
        final InstructionList closureInstructions = new InstructionList();
        for (final PairOfInstructionLists inst : properties)
            closureInstructions.addAll(inst.closureReduction);

        closureInstructions.addInstruction(ABCConstants.OP_returnvoid);
        return new PairOfInstructionLists(null, closureInstructions);
    }
View Full Code Here

     */
    public InstructionListAndString reduceSelector(ICSSNode site)
    {
        assert site instanceof ICSSSelector : "Expected a 'selector' node, but got '" + site.getClass().getName() + "'.";

        final InstructionList arrayInstructions = new InstructionList();
        final List<String> resolvedSimpleSelectorNames = new ArrayList<String>();
        final ICSSSelector selectorNode = (ICSSSelector)site;
        final ImmutableList<ICSSSelector> selectors = CSSSelector.getCombinedSelectorList(selectorNode);
        for (final ICSSSelector selector : selectors)
        {
            final String selectorLiteral = getSelecterLiteralForABC(selector);

            // Generate array data for conditional selector.
            for (final ICSSSelectorCondition condition : selector.getConditions())
            {
                pushNumericConstant(ICSSRuntimeConstants.CONDITION, arrayInstructions);
                arrayInstructions.addInstruction(ABCConstants.OP_pushstring, condition.getConditionType().name().toLowerCase());
                arrayInstructions.addInstruction(ABCConstants.OP_pushstring, condition.getValue());
            }

            // Generate array data for type selector.
            pushNumericConstant(ICSSRuntimeConstants.SELECTOR, arrayInstructions);
            arrayInstructions.addInstruction(ABCConstants.OP_pushstring, selectorLiteral);

            // Collect resolved name for the simple selector in the combined selectors.
            // For example: "spark.components.Button#loginButton", ".highlight#main:up"
            final String resolvedSelectorName = selectorLiteral.concat(Joiner.on("").join(selector.getConditions()));
            resolvedSimpleSelectorNames.add(resolvedSelectorName);
View Full Code Here

    /**
     * Reduce rule list node.
     */
    public PairOfInstructionLists reduceRuleList(ICSSNode site, List<InstructionListAndClosure> rules)
    {
        final InstructionList arrayInstructions = new InstructionList();
        final InstructionList closureInstructions = new InstructionList();
        int closureCount = 0;
        for (final InstructionListAndClosure ruleReduction : rules)
        {
            arrayInstructions.addAll(ruleReduction.arrayReduction);

            for (final Entry<String, MethodInfo> entry : ruleReduction.closureReduction.entrySet())
            {
                closureInstructions.addInstruction(ABCConstants.OP_pushstring, entry.getKey());
                closureInstructions.addInstruction(ABCConstants.OP_newfunction, entry.getValue());
                closureCount++;
            }
        }
        closureInstructions.addInstruction(ABCConstants.OP_newobject, closureCount);

        return new PairOfInstructionLists(arrayInstructions, closureInstructions);
    }
View Full Code Here

     * They will be populated in the parent tree, because the {@link MethodInfo}
     * for the closure bodies come from a sibling "properties" tree.
     */
    public InstructionListAndClosure reduceSelectorGroup(ICSSNode site, List<InstructionListAndString> selectors)
    {
        final InstructionList arrayInstructions = new InstructionList();
        final Map<String, MethodInfo> closureNames = new HashMap<String, MethodInfo>();
        for (final InstructionListAndString selectorReduction : selectors)
        {
            arrayInstructions.addAll(selectorReduction.arrayReduction);
            closureNames.put(selectorReduction.closureReduction, null);
        }
        pushNumericConstant(ICSSRuntimeConstants.STYLE_DECLARATION, arrayInstructions);
        pushNumericConstant(factory, arrayInstructions);

View Full Code Here

    /**
     * @return An instruction list with only one "returnvoid" instruction.
     */
    public static InstructionList returnVoid()
    {
        final InstructionList inst = new InstructionList(1);
        inst.addInstruction(OP_returnvoid);
        return inst;
    }
View Full Code Here

        scriptInitMethodVisitor.visit();
        MethodBodyInfo scriptInitMethodBodyInfo = new MethodBodyInfo();
        scriptInitMethodBodyInfo.setMethodInfo(scriptInitMethodInfo);
        IMethodBodyVisitor scriptInitMethodBodyVisitor = scriptInitMethodVisitor.visitBody(scriptInitMethodBodyInfo);
        scriptInitMethodBodyVisitor.visit();
        InstructionList scriptInitInstructions = new InstructionList();
        scriptInitInstructions.addInstruction(OP_getlocal0);
        scriptInitInstructions.addInstruction(OP_pushscope);
        finishClass(scriptInitInstructions);
        if (scriptInitInstructions.canFallThrough())
            scriptInitInstructions.addInstruction(OP_returnvoid);
        scriptInitMethodBodyVisitor.visitInstructionList(scriptInitInstructions);
        scriptInitMethodBodyVisitor.visitEnd();
        scriptInitMethodVisitor.visitEnd();
        sv.visitInit(scriptInitMethodInfo);
        sv.visitEnd();
View Full Code Here

     * @param useStrict Use OP_findpropstrict
     * @return InstructionList
     */
    public InstructionList findProperty(Name name, IDefinition def, boolean useStrict)
    {
        InstructionList result = new InstructionList(1);

        if (useStrict)
            result.addInstruction(OP_findpropstrict, name);
        else
            result.addInstruction(OP_findproperty, name);

        return result;
    }
View Full Code Here

     * @param def Definition of the property to find
     * @return InstructionList
     */
    public InstructionList getPropertyValue(Name name, IDefinition def)
    {
        InstructionList result = new InstructionList(1);
        result.addInstruction(OP_getlex, name);
        return result;
    }
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.