Package org.apache.flex.abc

Examples of org.apache.flex.abc.ABCEmitter


            return generatorSystemManagerName;
        }
       
        private boolean addGeneratedStylesClassToFrame(SWFFrame frame, Set<ICompilationUnit> emittedCompilationUnits) throws Exception
        {
            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
            ICSSCodeGenResult cssCodeGenResult = cssCompilationSession.emitStyleDataClass(flexProject, emitter);

            Name stylesClassName = new Name(getStylesClassName());

            IDefinition objectDef = objectReference.resolve(flexProject);
            if ((objectDef == null) || (!(objectDef instanceof ClassDefinition)))
                return false;

            ClassDefinition objectClassDef = (ClassDefinition)objectDef;

            // Generates a Style's class
            // Generated class name will be of the form _MyApplication_Styles
            // Eg:
            // public class _MyApplication_Styles
            // {
            // }

            final InstructionList cinit = cssCodeGenResult.getClassInitializationInstructions();
            assert cinit.canFallThrough() : "CSSReducer should not append 'returnvoid' to the initialization instructions.";
            cinit.addInstruction(ABCConstants.OP_returnvoid);

            ClassGeneratorHelper classGenerator = new ClassGeneratorHelper(
                        flexProject,
                        emitter,
                        stylesClassName,
                        objectClassDef,
                        Collections.<Name> emptyList(),
                        Collections.<Name> emptyList(),
                        ClassGeneratorHelper.returnVoid(),
                        cinit,
                        false);
            cssCodeGenResult.visitClassTraits(classGenerator.getCTraitsVisitor());

            classGenerator.finishScript();

            DoABCTag tag = new DoABCTag();
            tag.setABCData(emitter.emit());
            tag.setName("defaults.css and theme CSS data");
            frame.addTag(tag);

            return true;
        }
View Full Code Here


            String className = IMXMLTypeConstants._CompiledResourceBundleInfo;      
            IResolvedQualifiersReference mainClassRef = ReferenceFactory.packageQualifiedReference(
                     flexProject.getWorkspace(), className);

            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);

            ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter,
                     mainClassRef.getMName(),
                     (ClassDefinition)flexProject.getBuiltinType(BuiltinType.OBJECT),
                     ClassGeneratorHelper.returnVoid());

            //Create method body for compiledLocales getter
            InstructionList localesInstructionList = new InstructionList();

            for (String locale : locales)
            {
                localesInstructionList.addInstruction(ABCConstants.OP_pushstring, locale);
            }

            localesInstructionList.addInstruction(ABCConstants.OP_newarray, locales.size());
            localesInstructionList.addInstruction(ABCConstants.OP_returnvalue);

            classGen.addCTraitsGetter(new Name("compiledLocales"),
                    new Name(IASLanguageConstants.Array), localesInstructionList);

            //Create method body for compiledLocales getter
            InstructionList bundlesInstructionList = new InstructionList();

            for (String bundleName : frame1Info.compiledResourceBundleNames)
            {
                bundlesInstructionList.addInstruction(ABCConstants.OP_pushstring, bundleName);
            }

            bundlesInstructionList.addInstruction(ABCConstants.OP_newarray, frame1Info.compiledResourceBundleNames.size());
            bundlesInstructionList.addInstruction(ABCConstants.OP_returnvalue);

            classGen.addCTraitsGetter(new Name("compiledResourceBundleNames"),
                    new Name(IASLanguageConstants.Array), bundlesInstructionList);      
           
            //Generate script      
            classGen.finishScript();
           
            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
            }
            catch (Exception e)
            {
                return;
            }
View Full Code Here

         * @throws InterruptedException
         */
        private boolean addGeneratedFlexInitToFrame(final Collection<ICompilerProblem> problems, SWFFrame frame, Set<ICompilationUnit> emittedCompilationUnits,
                boolean isAppFlexInfo, FlexApplicationFrame1Info frame1Info, FlexRSLInfo rslInfo) throws InterruptedException
        {
            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
           
           
            String flexInitClassNameString = getFlexInitClassName();
           
            Name flexInitClassName = new Name(flexInitClassNameString);
           
            Name stylesClassName = new Name(getStylesClassName());

            IDefinition objectDef = objectReference.resolve(flexProject);
            if ((objectDef == null) || (!(objectDef instanceof ClassDefinition)))
                return false;
            ClassDefinition objectClassDef = (ClassDefinition)objectDef;
           
           
            // 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(flexProject, emitter, flexInitClassName,
                    objectClassDef, Collections.<Name>emptyList(), classITraitsInit);
           
            // Generate code for the static init method:
            // public static function init(mf : IFlexModuleFactory) : void
            // {
            //    new ChildManager(mf);
            //    var local2 : * = new StyleManagerImpl(mf);
            //
            //    // For each effect declared in the application:
            //    EffectManager.mx_internal::registerEffectTrigger(<effectName>, <eventName>);
            //
            //    // For each remote class alias declared in the application
            //    try
            //    {
            //        if (flash.net.getClassByAlias(<remote class alias>) != <class>)
            //        {
            //            flash.net.registerClassAlias(<remote class alias>, <class>);
            //        }
            //    }
            //    catch (e:Error)
            //    {
            //        flash.net.registerClassAlias(<remote class alias>, <class>);
            //    }
            //
            //    var local3 : * = [<names of all inheriting styles declared in the application>];
            //
            //    for each (var local0 : * in local3)
            //    {
            //        local2.registerInheritingStyle(local0);  // local2 is the style manager.
            //    }
            // }
            if (isAppFlexInfo)
            {
                MethodInfo initMethodInfo = new MethodInfo();
                initMethodInfo.setMethodName("FlexInit init method");
                initMethodInfo.setParamTypes(new Vector<Name>(Collections.singleton(new Name("Object"))));
                initMethodInfo.setReturnType(new Name(IASLanguageConstants.void_));
                IMethodVisitor initMethodVisitor = emitter.visitMethod(initMethodInfo);
                initMethodVisitor.visit();
                MethodBodyInfo initMethodBodyInfo = new MethodBodyInfo();
                initMethodBodyInfo.setMethodInfo(initMethodInfo);
                IMethodBodyVisitor initMethodBodyVisitor = initMethodVisitor.visitBody(initMethodBodyInfo);
                initMethodBodyVisitor.visit();
               
                // local0 = temp
                // local1 = module factory argument
                // local2 = style manager
                // local3 = inherited styles array
                InstructionList initMethod = new InstructionList();
                initMethod.addInstruction(ABCConstants.OP_returnvoid);
               
                initMethodBodyVisitor.visitInstructionList(initMethod);
                initMethodBodyVisitor.visitEnd();
                initMethodVisitor.visitEnd();
               
                ITraitVisitor initMethodTraitVisitor =
                    classGen.getCTraitsVisitor().visitMethodTrait(ABCConstants.TRAIT_Method, new Name("init"), 0, initMethodInfo);
                initMethodTraitVisitor.visitStart();
                initMethodTraitVisitor.visitEnd();

                codegenInfoMethod(classGen,
                        flexProject.getCompatibilityVersion(),
                        getMainClassQName(),
                        getPreloaderClassReference(),
                        getRuntimeDPIProviderClassReference(),
                        splashScreenImage,
                        getRootNode(),
                        getTargetAttributes(),
                        flexProject.getLocales(),
                        frame1Info,
                        accessibleClassNames,
                        getFlexInitClassName(),
                        getStylesClassName(),
                        targetSettings.getRuntimeSharedLibraries(),
                        rslInfo,
                        problems,
                        isAppFlexInfo);
               
            }
            else
            {
                MethodInfo initMethodInfo = new MethodInfo();
                initMethodInfo.setMethodName("FlexInit init method");
                initMethodInfo.setParamTypes(new Vector<Name>(Collections.singleton(iModuleFactoryReference.getMName())));
                initMethodInfo.setReturnType(new Name(IASLanguageConstants.void_));
                IMethodVisitor initMethodVisitor = emitter.visitMethod(initMethodInfo);
                initMethodVisitor.visit();
                MethodBodyInfo initMethodBodyInfo = new MethodBodyInfo();
                initMethodBodyInfo.setMethodInfo(initMethodInfo);
                IMethodBodyVisitor initMethodBodyVisitor = initMethodVisitor.visitBody(initMethodBodyInfo);
                initMethodBodyVisitor.visit();
               
                // local0 = temp
                // local1 = module factory argument
                // local2 = style manager
                // local3 = inherited styles array
                InstructionList initMethod = new InstructionList();
               
                // Since we don't need "this", we can kill local0, we'll use it later for something else.
                initMethod.addInstruction(ABCConstants.OP_kill, 0);
                initMethod.addInstruction(ABCConstants.OP_finddef, childManagerReference.getMName());
                initMethod.addInstruction(ABCConstants.OP_getlocal1);
                initMethod.addInstruction(ABCConstants.OP_constructprop, new Object[] { childManagerReference.getMName(), 1 });
                initMethod.addInstruction(ABCConstants.OP_pop);
                initMethod.addInstruction(ABCConstants.OP_finddef, styleManagerImplReference.getMName());
                initMethod.addInstruction(ABCConstants.OP_getlocal1);
                initMethod.addInstruction(ABCConstants.OP_constructprop, new Object[] { styleManagerImplReference.getMName(), 1 });
                initMethod.addInstruction(ABCConstants.OP_setlocal2);
               
                Map<String, String> effectNameToTriggerMap = new TreeMap<String, String>();
                Map<String, Boolean> inheritingStyleMap = new TreeMap<String, Boolean>();
                Map<ClassDefinition, String> remoteClassAliasMap =
                    new TreeMap<ClassDefinition, String>(new Comparator<ClassDefinition>()
                    {
                        @Override
                        public int compare(ClassDefinition o1, ClassDefinition o2)
                        {
                            return o1.getQualifiedName().compareTo(o2.getQualifiedName());
                        }
                    })
                    {
                        private static final long serialVersionUID = 1L;
   
                        /**
                         *  Override so warning messages can be logged.
                         */
                        @Override
                        public String put(ClassDefinition key, String value)
                        {
                            // check for duplicate values and log a warning if any remote
                            // classes try to use the same alias.
                            if (containsValue(value))
                            {
                               for (Map.Entry<ClassDefinition,String> entry  : entrySet())
                               {
                                   if (value != null && value.equals(entry.getValue()))
                                   {
                                       problems.add(new ClassesMappedToSameRemoteAliasProblem(key.getQualifiedName(),
                                               entry.getKey().getQualifiedName(), value));
                                       break;
                                   }
                               }
                            }
                            return super.put(key, value);
                        }
                    };
                   
                for (ICompilationUnit cu : emittedCompilationUnits)
                {
                    Collection<IDefinition> visibleDefs = cu.getFileScopeRequest().get().getExternallyVisibleDefinitions();
                    for (IDefinition visibleDef : visibleDefs)
                    {
                        if (visibleDef instanceof ClassDefinition)
                        {
                            ClassDefinition visibleClass = (ClassDefinition) visibleDef;
                            IEffectDefinition[] effectDefinitions = visibleClass.getEffectDefinitions(flexProject.getWorkspace());
                            for (IEffectDefinition effectDefinition : effectDefinitions)
                            {
                                // TODO create compiler problem if effect already has a trigger.
                                effectNameToTriggerMap.put(effectDefinition.getBaseName(), effectDefinition.getEvent());
                            }
                           
                            IStyleDefinition[] styleDefinitions = visibleClass.getStyleDefinitions(flexProject.getWorkspace());
                            for (IStyleDefinition styleDefinition : styleDefinitions)
                            {
                                boolean isInheriting = styleDefinition.isInheriting();
                                // TODO create compiler problem if style definitions conflict
                                inheritingStyleMap.put(styleDefinition.getBaseName(), isInheriting);
                            }
                           
                            String remoteClassAlias = visibleClass.getRemoteClassAlias();
                            if (remoteClassAlias != null)
                                remoteClassAliasMap.put(visibleClass, remoteClassAlias);
                        }
                    }
                }
               
                // register effects
                if (!effectNameToTriggerMap.isEmpty())
                {
                    IDefinition mxInternalDef = mxInternalReference.resolve(flexProject);
                    if (!(mxInternalDef instanceof NamespaceDefinition))
                        return false;
                   
                   
                    IResolvedQualifiersReference registerEffectTriggerRef =
                        ReferenceFactory.resolvedQualifierQualifiedReference(flexProject.getWorkspace(), (INamespaceDefinition)mxInternalDef,
                                "registerEffectTrigger");
                    Name registerEffectTriggerName = registerEffectTriggerRef.getMName();
                   
                    initMethod.addInstruction(ABCConstants.OP_getlex, effectManagerReference.getMName());
                   
                    for (Map.Entry<String, String> effectEntry : effectNameToTriggerMap.entrySet())
                    {
                        initMethod.addInstruction(ABCConstants.OP_dup)// copy the effectManager class closure
                        initMethod.addInstruction(ABCConstants.OP_pushstring, effectEntry.getKey());
                        initMethod.addInstruction(ABCConstants.OP_pushstring, effectEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, new Object[] { registerEffectTriggerName, 2 });
                    }
                    initMethod.addInstruction(ABCConstants.OP_pop);
                   
                }
               
                // Initialize AccessibilityClasses. Below is example code. Each
                // accessibility class found by the compiler will have its
                // enableAccessibility() method called.
                //
                // if (Capabilities.hasAccessibility) {
                //    spark.accessibility.TextBaseAccImpl.enableAccessibility();
                //    mx.accessibility.UIComponentAccProps.enableAccessibility();
                //    spark.accessibility.ButtonBaseAccImpl.enableAccessibility();
                // }
                if (targetSettings.isAccessible())
                {
                    Name capabilitiesSlotName = capabilitiesReference.getMName();
                    initMethod.addInstruction(ABCConstants.OP_findpropstrict, capabilitiesSlotName);
                    initMethod.addInstruction(ABCConstants.OP_getproperty, capabilitiesSlotName);
                    initMethod.addInstruction(ABCConstants.OP_getproperty, new Name("hasAccessibility"));
                    Label accessibilityEnd = new Label();
                    initMethod.addInstruction(ABCConstants.OP_iffalse, accessibilityEnd);
   
                    IResolvedQualifiersReference enableAccessibilityReference = ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(),
                            "enableAccessibility");           
                    Name enableAccessibilityName = enableAccessibilityReference.getMName();
                    Object[] enableAccessibilityCallPropOperands = new Object[] { enableAccessibilityName, 0 };
                    for (String accessibilityClassName : accessibleClassNames)
                    {
                        IResolvedQualifiersReference ref = ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(),
                                accessibilityClassName);
                        Name accName = ref.getMName();
                        initMethod.addInstruction(ABCConstants.OP_getlex, accName);
                        initMethod.addInstruction(ABCConstants.OP_callproperty, enableAccessibilityCallPropOperands);
                        initMethod.addInstruction(ABCConstants.OP_pop);
                    }
   
                    initMethod.labelNext(accessibilityEnd);
                }
               
                // register class aliases
                if (!remoteClassAliasMap.isEmpty())
                {
                    Name getClassByAliasName = getClassByAliasReference.getMName();
                    Name registerClassAliasName = registerClassAliasReference.getMName();
                    Object[] getClassByAliasCallPropOperands = new Object[] { getClassByAliasName, 1 };
                    Object [] registerClassAliasCallPropOperands = new Object[] { registerClassAliasName, 2 };
                    for (Map.Entry<ClassDefinition, String> classAliasEntry : remoteClassAliasMap.entrySet())
                    {
                        Label tryLabel = new Label();
                        initMethod.labelNext(tryLabel);
                        initMethod.addInstruction(ABCConstants.OP_finddef, getClassByAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_callproperty, getClassByAliasCallPropOperands);
                        Name classMName = classAliasEntry.getKey().getMName(flexProject);
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        Label endTryLabel = new Label();
                        initMethod.addInstruction(ABCConstants.OP_ifeq, endTryLabel);
                        initMethod.addInstruction(ABCConstants.OP_finddef, registerClassAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, registerClassAliasCallPropOperands);
                        initMethod.labelNext(endTryLabel);
                        Label afterCatch = new Label();
                        initMethod.addInstruction(ABCConstants.OP_jump, afterCatch);
                        Label catchLabel = new Label();
                        initMethod.labelNext(catchLabel);
                        initMethod.addInstruction(ABCConstants.OP_pop);
                        initMethod.addInstruction(ABCConstants.OP_finddef, registerClassAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, registerClassAliasCallPropOperands);
                        initMethod.labelNext(afterCatch);
                        initMethodBodyVisitor.visitException(tryLabel, endTryLabel, catchLabel,
                                new Name(IASLanguageConstants.Error), null);
                    }
                }
               
                // register inheriting styles
                if (!inheritingStyleMap.isEmpty())
                {
                    initMethod.addInstruction(ABCConstants.OP_getlex, stylesClassName);
                    int count = 0;
                    for (Map.Entry<String, Boolean> styleEntry : inheritingStyleMap.entrySet())
                    {
                        if (styleEntry.getValue().booleanValue())
                        {
                            ++count;
                            initMethod.addInstruction(ABCConstants.OP_pushstring, styleEntry.getKey());
                        }
                    }
                   
                    initMethod.addInstruction(ABCConstants.OP_newarray, count);
                    initMethod.addInstruction(ABCConstants.OP_setproperty, new Name("inheritingStyles"));
   
                }
   
                initMethod.addInstruction(ABCConstants.OP_returnvoid);
               
                initMethodBodyVisitor.visitInstructionList(initMethod);
                initMethodBodyVisitor.visitEnd();
                initMethodVisitor.visitEnd();
               
                ITraitVisitor initMethodTraitVisitor =
                    classGen.getCTraitsVisitor().visitMethodTrait(ABCConstants.TRAIT_Method, new Name("init"), 0, initMethodInfo);
                initMethodTraitVisitor.visitStart();
                initMethodTraitVisitor.visitEnd();
            }
            classGen.finishScript();
           
            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
            }
            catch (Exception e)
            {
                return false;
            }
View Full Code Here

         */
        boolean addGeneratedSystemManagerToFrame(SWFFrame frame, FlexApplicationFrame1Info frame1Info, ClassDefinition systemManagerClass,
                ImmutableSet<ICompilationUnit> builtCompilationUnits,
                Collection<ICompilerProblem> problemCollection) throws InterruptedException
        {
            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
           

            String generatedSystemManagerClassNameString = getGeneratedSystemManagerClassName(systemManagerClass);

            Name generatedSystemManagerName = new Name(generatedSystemManagerClassNameString);

            Collection<Name> implementedInterfaces = new ImmutableList.Builder<Name>()
                    .add(iModuleFactoryReference.getMName())
                    .add(iSWFContextReference.getMName())
                    .build();

            // Generate code for the constructor:
            // public function ClassName()
            // {
            //    FlexVersion.compatibilityVersionString = "4.5.0";
            //    super();
            // }
            final String compatibilityVersion = flexProject.getCompatibilityVersionString();
            final InstructionList classITraitsInit = new InstructionList();
            if (compatibilityVersion != null)
            {
                Name flexVersionSlotName = flexVersionReference.getMName();
                classITraitsInit.addInstruction(ABCConstants.OP_getlex, flexVersionSlotName);
                classITraitsInit.addInstruction(ABCConstants.OP_pushstring, compatibilityVersion);
                classITraitsInit.addInstruction(ABCConstants.OP_setproperty, new Name("compatibilityVersionString"));
            }
            classITraitsInit.addInstruction(ABCConstants.OP_getlocal0);
            classITraitsInit.addInstruction(ABCConstants.OP_constructsuper, 0);
            classITraitsInit.addInstruction(ABCConstants.OP_returnvoid);
            ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter, generatedSystemManagerName, systemManagerClass, implementedInterfaces, classITraitsInit);

            final FlexRSLInfo rslInfo = getRSLInfo();
           
            final FlexSplashScreenImage splashScreenImage = getSplashScreenImage();
           
            // Codegen various methods
            codegenCallInContextMethod(classGen, true);
            codegenCreateMethod(classGen, ((DefinitionBase)mainApplicationClassDefinition).getMName(flexProject));
            codegenInfoMethod(classGen,
                    flexProject.getCompatibilityVersion(),
                    getMainClassQName(),
                    getPreloaderClassReference(),
                    getRuntimeDPIProviderClassReference(),
                    splashScreenImage,
                    getRootNode(),
                    getTargetAttributes(),
                    flexProject.getLocales(),
                    frame1Info,
                    accessibleClassNames,
                    getFlexInitClassName(),
                    getStylesClassName(),
                    targetSettings.getRuntimeSharedLibraries(),
                    rslInfo,
                    problemCollection,
                    false);
           
            classGen.finishScript();

            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
            }
            catch (Exception e)
            {
                return false;
            }
View Full Code Here

  {
        //  Set up the global lexical scope.
        final GlobalLexicalScope global_scope = new GlobalLexicalScope(
            project, this, synthetic_name_prefix, inInvisibleCompilationUnit, useParallelCodegen, encodedDebugFiles);
       
      final ABCEmitter emitter = (ABCEmitter)global_scope.getEmitter();

        // CG targets the latest version - these ABCs can be postprocessed to downgrade to previous versions
        emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);

        IScriptVisitor sv = emitter.visitScript();
        sv.visit();
        MethodInfo init_method = new MethodInfo();
        sv.visitInit(init_method);
       
        MethodBodyInfo init_body = new MethodBodyInfo();
        init_body.setMethodInfo(init_method);
       
        IMethodVisitor mv = emitter.visitMethod(init_method);
        mv.visit();
        IMethodBodyVisitor mbv = mv.visitBody(init_body);
        mbv.visit();
       
        global_scope.traitsVisitor = sv.visitTraits();
        global_scope.setMethodInfo(init_method);
        global_scope.methodBodyVisitor = mbv;
        global_scope.setInitialControlFlowRegionNode(root_node);

        //  Process global directives.
        GlobalDirectiveProcessor top_level_processor = new GlobalDirectiveProcessor(executorService, useParallelCodegen, global_scope, emitter);
        boolean fatal_error_encountered = false;
        try
        {
            top_level_processor.traverse(root_node);
        }
        catch (MissingBuiltinException e)
        {
            global_scope.addProblem(new MissingBuiltinProblem(root_node, e.getBuiltinName()));
            fatal_error_encountered = true;
        }
        catch (CodegenInterruptedException e)
        {
            //  Unwrap the InterruptedException and rethrow it.
            throw e.getException();
        }

        top_level_processor.finish();
       
        byte[] generatedBytes = IABCBytesRequestResult.ZEROBYTES;
       
        if ( !fatal_error_encountered )
        {
            //  Initialize the init script.
            InstructionList script_init_insns = new InstructionList();

            script_init_insns.addInstruction(OP_getlocal0);
            script_init_insns.addInstruction(OP_pushscope);

            script_init_insns.addAll(global_scope.getInitInstructions());
            script_init_insns.addAll(top_level_processor.directiveInsns);

            if ( script_init_insns.canFallThrough() || script_init_insns.hasPendingLabels() )
                script_init_insns.addInstruction(OP_returnvoid);

            //  Allocate temps beginning with register 1,
            //  register 0 is reserved for "this" global.
            global_scope.initializeTempRegisters(1);

            // Make any vistEnd method calls
            // that were deferred.
            // callVisitEnds must be called on the same thread
            // that original called ABCGenerator.generate ( this method ).
            global_scope.callVisitEnds();
           
            mbv.visitInstructionList(script_init_insns);
            mbv.visitEnd();
            mv.visitEnd();
            global_scope.traitsVisitor.visitEnd();
            sv.visitEnd();

            try
            {
                generatedBytes = emitter.emit();
            }
            catch ( Throwable cant_generate )
            {
                global_scope.addProblem(new CodegenInternalProblem(root_node, cant_generate));
            }
View Full Code Here

        super.methodBodySemanticChecker = new MethodBodySemanticChecker(this);

        if ( emitter != USE_DEFAULT_EMITTER )
            this.emitter = emitter;
        else
            this.emitter = new ABCEmitter(new AETDiagnosticsVisitor());

        // If we are using parallel code generation make sure the
        // collections are a synchronized collection so that
        // multiple threads can safely add to the collection simultaneously.
        if (useParallelCodegen)
View Full Code Here

        startProfile(Operation.GET_ABC_BYTES);
        try
        {
            final Collection<ICompilerProblem> problems = new LinkedList<ICompilerProblem>();
            final ABCEmitter emitter = new ABCEmitter();

            // TODO: hook this up to something in the settings - how do we access settings from here?
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);

            byte[] generatedBytes = null;
            try
            {
                for (IDefinition def : getDefinitionPromises())
                {
                    String qualifiedClassName = def.getQualifiedName();
                    String locale = ResourceBundleUtils.getLocale(qualifiedClassName);

                    generateABCForBundle(emitter, (ResourceBundleFileNode)rootNode, qualifiedClassName, bundleNameInColonSyntax, locale, problems);
                }

                generatedBytes = emitter.emit();
            }
            catch (Throwable ex)
            {
                problems.add(new CodegenInternalProblem(rootNode, ex));
            }
View Full Code Here

     */
    @Override
    protected IABCBytesRequestResult handleABCBytesRequest() throws InterruptedException
    {
        final StyleModuleSemanticRequestResult semanticResult = (StyleModuleSemanticRequestResult) getOutgoingDependenciesRequest().get();
        final ABCEmitter emitter = new ABCEmitter();
        emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
        final FlexProject project = (FlexProject)getProject();
        final List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
        byte[] bytes = null;
        try
        {
            // TODO: Generate class names from CSS file name after the CSS module runtime code is finalized.
            final String moduleName = "CSSModule2";

            final Name mainClassName = new Name(moduleName + "Main");
            CSSModuleGenerator.generateMainClass(emitter, project, mainClassName);

            final Name styleDataClassName = new Name(moduleName + "_StyleData");
            CSSModuleGenerator.generateStyleDataClass(
                    emitter,
                    project,
                    semanticResult.cssDocument,
                    semanticResult.cssCompilationSession,
                    styleDataClassName);

            bytes = emitter.emit();
        }
        catch (Exception e)
        {
            final CSSCodeGenProblem problem = new CSSCodeGenProblem(e);
            problems.add(problem);
View Full Code Here

        startProfile(Operation.GET_ABC_BYTES);
        try
        {
            final FlexProject flexProject = (FlexProject)getProject();
            final Collection<ICompilerProblem> problems = new LinkedList<ICompilerProblem>();
            final ABCEmitter emitter = new ABCEmitter();
           
            byte[] generatedBytes = null;
            try
            {
                //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(),
                        constructorInstructionList);

                classGen.finishScript();
                generatedBytes = emitter.emit();
            }
            catch (Throwable ex)
            {
                problems.add(new InternalCompilerProblem(ex));
            }
View Full Code Here

         */
        private boolean addGeneratedRootClassToSWFFrame(SWFFrame frame, ISWF swf, ModuleFactoryInfo moduleFactoryInfo,
                ImmutableSet<ICompilationUnit> emittedCompilationUnits,
                Collection<ICompilerProblem> problemCollection) throws InterruptedException
        {
            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
           

            final String generatedRootClassNameString = moduleFactoryInfo.generatedModuleFactoryClassName;

            Name generatedRootName = new Name(generatedRootClassNameString);
           
            // 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(),
                    classITraitsInit);
            IResolvedQualifiersReference objectReference =
                ReferenceFactory.packageQualifiedReference(project.getWorkspace(),
                    IASLanguageConstants.Object);
           
            // Codegen various methods
            // TODO: Determine whether a override is needed or not depending on the
            // methods in the base class. Same deal for the Create and Info Methods.
            codegenCallInContextMethod(classGen, true);

            final FlexLibraryFrame1Info frame1Info =
                new FlexLibraryFrame1Info(flexProject, emittedCompilationUnits);
           
            // Override the create() and info() methods if we have embedded fonts.
            if (!frame1Info.embeddedFonts.isEmpty())
            {
                codegenCreateMethod(classGen, objectReference.getMName());
                codegenInfoMethod(classGen,
                        IASLanguageConstants.Object,
                        frame1Info,
                        accessibleClassNames,
                        problemCollection);           
            }
           
            classGen.finishScript();

            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
            }
            catch (Exception e)
            {
                return false;
            }
View Full Code Here

TOP

Related Classes of org.apache.flex.abc.ABCEmitter

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.