Package org.apache.flex.abc.instructionlist

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


     @return an InstructionList containing
     *    the method's prologue instructions.
     */
    InstructionList finishMethodDeclaration(final boolean hasBody, String source_path)
    {
        InstructionList result = new InstructionList();

        // TODO: The scope stack can be optimized out if
        // no instruction (e.g., findprop) requires one.
        if ( this.needsThis )
            // && this.needsScopeStack() )
        {
            result.addInstruction(ABCConstants.OP_getlocal0);
            result.addInstruction(ABCConstants.OP_pushscope);
        }

        // Add a debugfile to start the method.
        if( source_path != null )
        {
            String encoded_filename = getGlobalScope().getEncodedDebugFile(source_path);
            result.addInstruction(ABCConstants.OP_debugfile, encoded_filename);
        }


        // TODO: Set this more intelligently;
        // it's only necessary if arguments is read but not written.
        if (needsImplicitArguments())
        {
            this.setNeedsArguments();
        }

        if ( this.needsArguments() )
        {
            makeImplicitParameter(NAME_arguments, NAME_Array);
        }

        if ( !isGlobalScope() )
        {
            // temp_register_count is the total number of temp registers
            // which need to be initialized.
            int temp_register_count = 0;
            if ( this.needsActivation() )
            {
                //  Create a new activation object, store it in a local (so it can be restored
                //  if needed later, like in a catch block), and push the activation object
                //  onto the scope stack.
                result.addInstruction(ABCConstants.OP_newactivation);

                if( this.activationStorage != null )
                {
                    result.addInstruction(ABCConstants.OP_dup);
                    result.addInstruction(this.activationStorage.setlocal());
                }

                result.addInstruction(ABCConstants.OP_pushscope);

                //  TODO: More fine-grained determination
                //  of which parameters need to live in the activation record.
                for ( int param_num = 0; param_num < this.allParams.size(); param_num++ )
                {
                    Name param_name = this.allParams.get(param_num);
                    result.addInstruction(ABCConstants.OP_findpropstrict, param_name);
                    //  Parameter numbering in the AVM is 1-based
                    //  since local 0 holds "this."
                    result.addInstruction(ABCConstants.OP_getlocal, param_num + 1);
                    result.addInstruction(ABCConstants.OP_setproperty, param_name);
                }

                temp_register_count = this.allParams.size() + 1;
            }
            else
            {
                // Find the bindings for the parameters
                // and give them their corresponding local number.
                // There is a complication, however. The same parameter name may occur more than
                // Once in the parameter list. In this case, ECMA says the last one wins.
                // So in the loop below will go from last parameter to first, and skip any
                // that we have already seen
               
                Set<String> uniqueParamNames = new HashSet<String>();
                for (int param_num = this.allParams.size()-1; param_num >= 0; param_num--)
                {
                    Name param_name = this.allParams.get(param_num);
                    String param_base_name = param_name.getBaseName();
                    Binding param_binding = this.localBindings.get(param_base_name);
                    if (param_binding!=null && !uniqueParamNames.contains(param_base_name))
                    {
                        param_binding.setLocalRegister(param_num+1);
                        uniqueParamNames.add(param_base_name);
                    }
                }

                //  Now traverse the entire set of local bindings and
                //  give local numbers to those that weren't parameters.
                int local_num = this.allParams.size() + 1;
                for ( Binding local_binding : this.localBindings.values() )
                {
                    if ( ! local_binding.localNumberIsSet() )
                    {
                        local_binding.setLocalRegister(local_num++);
                    }
                }

                temp_register_count = local_num;
            }

            // Normally nothing should be called after initializeTempRegisters(), as bad things will happen
            // if another register is added.  The addDebugNamesToDefinitions() is a special case, as it needs
            // to have all registers set.
            this.initializeTempRegisters(temp_register_count);
        }

        // Need to call this after initializeTempRegisters to ensure that the registers are set in all cases.
        addDebugNamesToDefinitions(result);

        if ( this.hasHoistedInitInstructions() )
            result.addAll(this.getHoistedInitInstructions());

        return result;
    }
View Full Code Here


     *    for hoisted instructions without creating them.
     */
    InstructionList getHoistedInitInstructions()
    {
        if ( this.hoistedInitInstructions == null )
            this.hoistedInitInstructions = new InstructionList();

        return this.hoistedInitInstructions;
    }
View Full Code Here

        @Override
        public void visitInstructionList(InstructionList new_list)
        {
            // for the delegates that run after this IVisitor, they will be processing
            // a new copy of the instruction list, which will not have the debug opcodes
            InstructionList strippedInstructionList = new InstructionList(new_list.size());
            for (Instruction inst : new_list.getInstructions())
            {
                if (!stripInstruction(inst.getOpcode()))
                    strippedInstructionList.addInstruction(inst);
            }
            super.visitInstructionList(strippedInstructionList);
        }
View Full Code Here

        // pushscope
        // newclass
        // popscope
        // popscope
        // initproperty B
        InstructionList initInstructions = this.classScope.getInitInstructions();
        initInstructions.addInstruction(OP_getscopeobject, 0);

        // Push ancestor classes onto the scope stack.
        for (int i = ancestorClassNames.size() - 1; i >= 0; i--)
        {
            Name ancestorClassName = ancestorClassNames.get(i);
            initInstructions.addInstruction(OP_getlex, ancestorClassName);
            // The newclass instruction below also needs the superclass on the stack, so dup it
            if (i == 0)
                initInstructions.addInstruction(OP_dup);
            initInstructions.addInstruction(OP_pushscope);
        }

        initInstructions.addInstruction(OP_newclass, cinfo);

        for (int i = 0; i < ancestorClassNames.size(); i++)
            initInstructions.addInstruction(OP_popscope);
       
        initInstructions.addInstruction(OP_initproperty, className);
       
        implementedInterfaceSemanticChecks(class_definition);

        processResourceBundles(class_definition, project, classScope.getProblems());
    }
View Full Code Here

            MethodInfo mi = new MethodInfo();
            mi.setMethodName("skinParts");

            mi.setReturnType(NAME_OBJECT);

            InstructionList insns = new InstructionList(3);
            insns.addInstruction(OP_getlocal0);
            insns.addInstruction(OP_findpropstrict, var_name);
            insns.addInstruction(OP_getproperty, var_name);
            insns.addInstruction(OP_returnvalue);

            FunctionGeneratorHelper.generateFunction(classScope.getEmitter(), mi, insns);

            NamespaceDefinition nd = (NamespaceDefinition)classDefinition.getProtectedNamespaceReference();
            Name func_name = new Name(nd.getAETNamespace(), "skinParts");
            tv = classScope.traitsVisitor.visitMethodTrait(TRAIT_Getter, func_name, 0, mi);
            tv.visitAttribute(Trait.TRAIT_OVERRIDE, Boolean.TRUE);
            tv.visitEnd();

        }
       
        // the generation of instructions for variable initialization is delayed
        // until now, so we can add that initialization to the front of
        // the cinit instruction list.
        if (!staticVariableInitializers.isEmpty())
        {
            InstructionList exisitingCinitInsns = null;
            if (!this.cinitInsns.isEmpty())
            {
                exisitingCinitInsns = new InstructionList();
                exisitingCinitInsns.addAll(this.cinitInsns);
                this.cinitInsns = new InstructionList();
            }

            for (VariableNode var : staticVariableInitializers)
                generateInstructions(var, true);

            if (exisitingCinitInsns != null)
                this.cinitInsns.addAll(exisitingCinitInsns);
        }

        // add "goto_definition_help" metadata to user defined metadata.
        ITraitVisitor tv = classScope.getGlobalScope().traitsVisitor.visitClassTrait(
                TRAIT_Class, className, 0, cinfo);
        IMetaInfo[] metaTags = getAllMetaTags(classDefinition);

        // Add "goto definition help" metadata for the constructor.
        if (this.ctorFunction != null)
        {
            FunctionDefinition ctorDef = this.ctorFunction.getDefinition();
            MetaTag metaTag = MetaTag.createGotoDefinitionHelp(classDefinition,
                    classDefinition.getContainingFilePath(),
                    Integer.toString(ctorDef.getNameStart()), true);
            if (metaTag != null)
                metaTags = MetaTag.addMetaTag(metaTags, metaTag);
        }       

        this.classScope.processMetadata(tv, metaTags);
        tv.visitEnd();
       
        // Need to do this before generating the CTOR as the generated code may result in insns that
        // need to be added to the ctor.
        generateBindableImpl();

        generateRequiredContingentDefinitions();
       
        addAnyEmbeddedAsset();

        // Make any vistEnd method calls
        // that were deferred.
        // callVisitEnds must be called on the same thread
        // that started code generation.  Since we don't generate
        // classes in parallel yet, we know that we are on the thread
        // that started code generation here.
        classScope.callVisitEnds();
        classStaticScope.callVisitEnds();
       
        //  Create the class' constructor function.
        if ( this.ctorFunction != null )
        {
            MethodInfo mi = classScope.getGenerator().generateFunction(this.ctorFunction, classScope, this.iinitInsns, null);

            if ( mi != null )
                this.iinfo.iInit = mi;
        }
        else if ( !this.iinitInsns.isEmpty() )
        {
            //  Synthesize a constructor.

            this.iinfo.iInit = new MethodInfo();
            MethodBodyInfo iinit = new MethodBodyInfo();
            iinit.setMethodInfo(this.iinfo.iInit);
           
            IMethodVisitor mv = emitter.visitMethod(this.iinfo.iInit);
            mv.visit();
            IMethodBodyVisitor mbv = mv.visitBody(iinit);
            InstructionList ctor_insns = new InstructionList();
            ctor_insns.addInstruction(OP_getlocal0);
            ctor_insns.addInstruction(OP_pushscope);
           
            ctor_insns.addAll(this.iinitInsns);

            //  Call the superclass' constructor after the instance
            //  init instructions; this doesn't seem like an abstractly
            //  correct sequence, but it's what ASC does.
            ctor_insns.addInstruction(OP_getlocal0);
            ctor_insns.addInstruction(OP_constructsuper, 0);

            ctor_insns.addInstruction(OP_returnvoid);
            mbv.visit();
            mbv.visitInstructionList(ctor_insns);
            mbv.visitEnd();
            mv.visitEnd();
        }

        //  If the class has static initialization
        //  logic, emit a cinit routine.
        if ( ! this.cinitInsns.isEmpty() )
        {
            InstructionList cinit_insns   = new InstructionList();
            cinit_insns.addInstruction(OP_getlocal0);
            cinit_insns.addInstruction(OP_pushscope);

            //  TODO: Examine other end-of-function processing
            //  and ensure it's completed.
            this.classStaticScope.finishClassStaticInitializer(this.cinitInsns);
            cinit_insns.addAll(this.cinitInsns);

            cinit_insns.addInstruction(OP_returnvoid);
           
            createCInitIfNeeded();
           
            this.classStaticScope.methodBodyVisitor.visitInstructionList(cinit_insns);
            this.classStaticScope.methodBodyVisitor.visitEnd();
View Full Code Here

        if ( createNewCinit )
        {
            createCInitIfNeeded();
        }

        InstructionList cgResult = null;

        LexicalScope ls = isStatic? this.classStaticScope: this.classScope;

        ls.resetDebugInfo();
        cgResult = ls.getGenerator().generateInstructions( node, CmcEmitter.__statement_NT, ls );

        //  If nothing came back, revert any change made to the cinit information.
        if ( (cgResult == null || cgResult.isEmpty() ) && createNewCinit )
            {
                this.cinfo.cInit = null;
            this.classStaticScope.resetMethodInfo();
            this.classStaticScope.methodVisitor = null;
            this.classStaticScope.methodBodyVisitor = null;
View Full Code Here

        // inline this, so just bail to the super call which will cause the inline
        // to fail.
        if (def == null)
            return super.findProperty(name, def, useStrict);

        InstructionList result = new InstructionList(def.isStatic() ? 2 : 1);

        if (def instanceof IClassDefinition)
        {
            result.addInstruction(OP_finddef, name);
        }
        else if (def.isStatic())
        {
            DefinitionBase staticContainingScope = (DefinitionBase)def.getContainingScope().getDefinition();
            Name containingScopeName = staticContainingScope.getMName(getProject());
            result.addInstruction(OP_finddef, containingScopeName);
            result.addInstruction(OP_getproperty, containingScopeName);
        }
        else if (((DefinitionBase)def).isTopLevelDefinition())
        {
            result.addInstruction(OP_finddef, name);
        }
        else if (containingScope instanceof ScopeView)
        {
            // Check if the property is a member of the ViewScope.  If so, then
            // return the containing class register
            ScopeView scopeView = (ScopeView)containingScope;
            final String baseName = name.getBaseName();
            IDefinition propertyDef = scopeView.getPropertyFromDef(getProject(), scopeView.getDefinition(), baseName, false);

            if (propertyDef != null)
                result.addInstruction(getContainingClass());
        }

        if (!result.isEmpty())
            return result;

        // couldn't statically resolve the definition, so
        // just emit the normal findprop, and the inlining check
        // AbcGeneratingReducer.checkInlinedInstructions() will
View Full Code Here

    }

    @Override
    public InstructionList getPropertyValue(Name name, IDefinition def)
    {
        InstructionList findPropResult = findProperty(name, def, true);

        InstructionList result = new InstructionList(findPropResult.size() + 1);
        result.addAll(findPropResult);
        result.addInstruction(OP_getproperty, name);
        return result;
    }
View Full Code Here

                //this class extends "flex.compiler.support.ResourceModuleBase"
                IResolvedQualifiersReference resourceModuleBaseRef = ReferenceFactory.packageQualifiedReference(
                        flexProject.getWorkspace(), flexProject.getResourceModuleBaseClass());
               
                //Create constructor instruction list
                InstructionList constructorInstructionList = new InstructionList();
                constructorInstructionList.addInstruction(ABCConstants.OP_getlocal0);
                constructorInstructionList.addInstruction(ABCConstants.OP_pushscope)
               
                int resourceBundleCount = 0;
                for(ICompilationUnit compUnit : resourceBundleCompUnits)
                {
                    for(IDefinition def : compUnit.getDefinitionPromises())
                    {
                        constructorInstructionList.addInstruction(ABCConstants.OP_pushstring, def.getQualifiedName());
                        resourceBundleCount++;
                    }
                }
               
                constructorInstructionList.addInstruction(ABCConstants.OP_newarray, resourceBundleCount);
                constructorInstructionList.addInstruction(ABCConstants.OP_constructsuper, 1);
                constructorInstructionList.addInstruction(ABCConstants.OP_returnvoid);
               
                ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter,
                        new Name(qname),
                        (ClassDefinition)resourceModuleBaseRef.resolve(flexProject),
                        Collections.<Name> emptyList(),
View Full Code Here

            // Generate code for the constructor:
            // public function ClassName()
            // {
            //    super();
            // }
            InstructionList classITraitsInit = new InstructionList();
            classITraitsInit.addInstruction(ABCConstants.OP_getlocal0);
            classITraitsInit.addInstruction(ABCConstants.OP_constructsuper, 0);
            classITraitsInit.addInstruction(ABCConstants.OP_returnvoid);
            ClassGeneratorHelper classGen = new ClassGeneratorHelper(project,
                    emitter,
                    generatedRootName,
                    (ClassDefinition)moduleFactoryInfo.moduleFactoryBaseClass,
                    Collections.<Name>emptyList(),
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.