flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cd...@apache.org
Subject [18/51] [partial] - Migrated the directory structure to a more Maven style structure. - Started migrating the Parser from Antlr2+3 and JFlex to Antlr4.
Date Tue, 22 Jul 2014 13:35:44 GMT
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ClassGeneratorHelper.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ClassGeneratorHelper.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ClassGeneratorHelper.java
new file mode 100644
index 0000000..0030f8e
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ClassGeneratorHelper.java
@@ -0,0 +1,483 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import static org.apache.flex.abc.ABCConstants.OP_dup;
+import static org.apache.flex.abc.ABCConstants.OP_findpropstrict;
+import static org.apache.flex.abc.ABCConstants.OP_getlocal0;
+import static org.apache.flex.abc.ABCConstants.OP_getproperty;
+import static org.apache.flex.abc.ABCConstants.OP_getscopeobject;
+import static org.apache.flex.abc.ABCConstants.OP_initproperty;
+import static org.apache.flex.abc.ABCConstants.OP_newclass;
+import static org.apache.flex.abc.ABCConstants.OP_popscope;
+import static org.apache.flex.abc.ABCConstants.OP_pushscope;
+import static org.apache.flex.abc.ABCConstants.OP_returnvoid;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Vector;
+
+import org.apache.flex.abc.ABCConstants;
+import org.apache.flex.abc.instructionlist.InstructionList;
+import org.apache.flex.abc.semantics.ClassInfo;
+import org.apache.flex.abc.semantics.InstanceInfo;
+import org.apache.flex.abc.semantics.MethodBodyInfo;
+import org.apache.flex.abc.semantics.MethodInfo;
+import org.apache.flex.abc.semantics.Name;
+import org.apache.flex.abc.semantics.Namespace;
+import org.apache.flex.abc.semantics.PooledValue;
+import org.apache.flex.abc.semantics.Trait;
+import org.apache.flex.abc.visitors.IABCVisitor;
+import org.apache.flex.abc.visitors.IClassVisitor;
+import org.apache.flex.abc.visitors.IMethodBodyVisitor;
+import org.apache.flex.abc.visitors.IMethodVisitor;
+import org.apache.flex.abc.visitors.IScriptVisitor;
+import org.apache.flex.abc.visitors.ITraitVisitor;
+import org.apache.flex.abc.visitors.ITraitsVisitor;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.internal.as.codegen.LexicalScope;
+import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.projects.ICompilerProject;
+
+/**
+ * Utility class for writing a class definition into an IABCVisitor.
+ * <p>
+ * After construction:
+ * <ul>
+ * <li>Instance trait's can be added to the class by calling
+ * {@link #getITraitsVisitor()} and visiting each trait to be added.</li>
+ * <li>Class trait's can be added to the class by calling
+ * {@link #getCTraitsVisitor()} and visiting each trait to be added.</li>
+ * <li>Instance methods can be added to the class by calling
+ * {@link #addITraitsMethod(Name, Collection, Name, Collection, boolean, boolean, boolean, InstructionList)}
+ * .</li>
+ * </ul>
+ * <p>
+ * After all the trait's and instructions have been added to the class, either
+ * {@link #finishClass(InstructionList)} or {@link #finishScript()} must be
+ * called.
+ */
+public class ClassGeneratorHelper
+{
+    /**
+     * @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;
+    }
+    
+    /**
+     * Constuctor that thunks to
+     * {@link #ClassGeneratorHelper(ICompilerProject, IABCVisitor, Name, ClassDefinition, Collection, Collection, InstructionList, boolean)}.
+     * 
+     * @param project A compiler project.
+     * @param visitor An ABC visitor.
+     * @param className The ABC name of the new class.
+     * @param baseClass The definition of the class being extended.
+     */
+    public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, InstructionList constructorInstructions)
+    {
+        this(project, visitor, className, baseClass, Collections.<Name> emptyList(), Collections.<Name> emptyList(), constructorInstructions, false);
+    }
+
+    /**
+     * Constuctor that thunks to
+     * {@link #ClassGeneratorHelper(ICompilerProject, IABCVisitor, Name, ClassDefinition, Collection, Collection, InstructionList, boolean)}.
+     * 
+     * @param project A compiler project.
+     * @param visitor An ABC visitor.
+     * @param className The ABC name of the new class.
+     * @param baseClass The definition of the class being extended.
+     * @param implementedInterfaces The ABC name of the interfaces being implemented.
+     */
+    public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, Collection<Name> implementedInterfaces, InstructionList constructorInstructions)
+    {
+        this(project, visitor, className, baseClass, implementedInterfaces, Collections.<Name> emptyList(), constructorInstructions, false);
+    }
+
+    /**
+     * Generate an ABC class with constructor instructions.
+     * 
+     * @see #ClassGeneratorHelper(ICompilerProject, IABCVisitor, Name, ClassDefinition, Collection, Collection, InstructionList, InstructionList, boolean)
+     */
+    public ClassGeneratorHelper(ICompilerProject project, IABCVisitor visitor, Name className, ClassDefinition baseClass, Collection<Name> implementedInterfaces, Collection<Name> constructorParamTypes, InstructionList constructorInstructions, boolean hasProtectedMembers)
+    {
+        this(project, visitor, className, baseClass, implementedInterfaces, constructorParamTypes, constructorInstructions, returnVoid(), hasProtectedMembers);
+    }
+    
+    /**
+     * Constructor
+     * 
+     * @param project {@link ICompilerProject} project for which ABC is being
+     * generated.
+     * @param visitor {@link IABCVisitor} to write the new class into.
+     * @param className {@link Name} of the class to generate
+     * @param baseClass {@link ClassDefinition} for the base class the generated
+     * class extends.
+     * @param implementedInterfaces Collection of {@link Name}'s that at runtime
+     * will refer to interfaces the generated class implement.
+     * @param iinitParameterTypes Collection of {@link Name}'s that at runtime
+     * will refer to the types of the constructor arguments.
+     * @param iinitInstructions Instructions for the constructor.
+     * @param cinitInstructions Instructions for the {@code cinit()} method.
+     * @param hasProtectedMembers whether or not this class has protected members
+     * There must be one {@code returnvoid} instruction.
+     */
+    public ClassGeneratorHelper(final ICompilerProject project,
+                                final IABCVisitor visitor,
+                                final Name className,
+                                final ClassDefinition baseClass,
+                                final Collection<Name> implementedInterfaces,
+                                final Collection<Name> iinitParameterTypes,
+                                final InstructionList iinitInstructions,
+                                final InstructionList cinitInstructions,
+                                boolean hasProtectedMembers)
+    {
+        if (iinitInstructions.canFallThrough())
+            throw new IllegalArgumentException("Expected a 'returnvoid' instruction in the iinit() instructions.");
+        
+        if (cinitInstructions.canFallThrough())
+            throw new IllegalArgumentException("Expected a 'returnvoid' instruction in the cinit() instructions.");
+
+        this.project = project;
+        this.className = className;
+        this.baseClass = baseClass;
+        cinfo = new ClassInfo();
+        cinfo.cInit = new MethodInfo();
+        IMethodVisitor cInitVisitor = visitor.visitMethod(cinfo.cInit);
+        cInitVisitor.visit();
+        MethodBodyInfo cInitMethodBodyInfo = new MethodBodyInfo();
+        cInitMethodBodyInfo.setMethodInfo(cinfo.cInit);
+        IMethodBodyVisitor cInitMethodBodyVisitor = cInitVisitor.visitBody(cInitMethodBodyInfo);
+        cInitMethodBodyVisitor.visit();
+        cInitMethodBodyVisitor.visitInstructionList(cinitInstructions);
+        cInitMethodBodyVisitor.visitEnd();
+        cInitVisitor.visitEnd();
+
+        iinfo = new InstanceInfo();
+        
+        if(hasProtectedMembers) 
+        {
+            iinfo.flags |= ABCConstants.CONSTANT_ClassProtectedNs;
+            iinfo.protectedNs = new Namespace(ABCConstants.CONSTANT_ProtectedNs, 
+                    className.getSingleQualifier().getName() + ":" +className.getBaseName());
+        }
+        
+        iinfo.interfaceNames = implementedInterfaces.toArray(new Name[implementedInterfaces.size()]);
+        iinfo.name = className;
+        iinfo.superName = baseClass.getMName(project);
+        iinfo.iInit = new MethodInfo();
+        iinfo.iInit.setParamTypes(new Vector<Name>(iinitParameterTypes));
+        iTraitsInitMethodVisitor = visitor.visitMethod(iinfo.iInit);
+        iTraitsInitMethodVisitor.visit();
+        MethodBodyInfo iTraitsInitMethodBodyInfo = new MethodBodyInfo();
+        iTraitsInitMethodBodyInfo.setMethodInfo(iinfo.iInit);
+        iTraitsInitMethodBodyVisitor = iTraitsInitMethodVisitor.visitBody(iTraitsInitMethodBodyInfo);
+        iTraitsInitMethodBodyVisitor.visit();
+        iTraitsInitMethodBodyVisitor.visitInstructionList(iinitInstructions);
+
+        this.visitor = visitor;
+        classVisitor = visitor.visitClass(iinfo, cinfo);
+        classVisitor.visit();
+        itraits = classVisitor.visitInstanceTraits();
+        itraits.visit();
+
+        ctraits = classVisitor.visitClassTraits();
+        ctraits.visit();
+    }
+    
+    private final ICompilerProject project;
+    private final Name className;
+    private final ClassDefinition baseClass;
+    private final ClassInfo cinfo;
+    private final InstanceInfo iinfo;
+    private final IABCVisitor visitor;
+    private final IClassVisitor classVisitor;
+    private final ITraitsVisitor itraits;
+    private final ITraitsVisitor ctraits;
+    private final IMethodVisitor iTraitsInitMethodVisitor;
+    private final IMethodBodyVisitor iTraitsInitMethodBodyVisitor;
+    
+    /**
+     * Adds a new script to the ABC with a trait for the class closure and an
+     * init with instructions to create the class closure for the generated
+     * class.
+     * 
+     * <p>
+     * After this method is called no other methods on this class should be called.
+     */
+    public void finishScript()
+    {
+        IScriptVisitor sv = visitor.visitScript();
+        sv.visit();
+        ITraitsVisitor scriptTraits = sv.visitTraits();
+        scriptTraits.visit();
+        scriptTraits.visitClassTrait(ABCConstants.TRAIT_Class, className, 0, cinfo);
+        scriptTraits.visitEnd();
+        MethodInfo scriptInitMethodInfo = new MethodInfo();
+        IMethodVisitor scriptInitMethodVisitor = visitor.visitMethod(scriptInitMethodInfo);
+        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();
+    }
+    
+    /**
+     * Generates the instructions to create the class closure and adds them to
+     * the specified {@link InstructionList}.
+     * 
+     * @param scriptInitInstructions {@link InstructionList} to add the
+     * instructions that create the class closure to.
+     */
+    public void finishClass(InstructionList scriptInitInstructions)
+    {
+        iTraitsInitMethodBodyVisitor.visitEnd();
+        iTraitsInitMethodVisitor.visitEnd();
+        
+        LinkedList<Name> ancestorNames = new LinkedList<Name>();
+        
+        for (IClassDefinition ancestorIClass : baseClass.classIterable(project, true))
+        {
+            final ClassDefinition ancestorClass = (ClassDefinition) ancestorIClass;
+            ancestorNames.addFirst(ancestorClass.getMName(project));
+        }
+        
+        scriptInitInstructions.addInstruction(OP_getscopeobject, 0);
+        
+        //  Push ancestor classes onto the scope stack in
+        //  order by superclass relationship; the immediate
+        //  superclass is handled specially just below.
+        
+        assert ancestorNames.size() > 0;
+        Name superclassName = ancestorNames.removeLast();
+        for (Name ancestorName : ancestorNames)
+        {
+            scriptInitInstructions.addInstruction(OP_findpropstrict, ancestorName);
+            scriptInitInstructions.addInstruction(OP_getproperty, ancestorName);
+            scriptInitInstructions.addInstruction(OP_pushscope);
+        }
+        
+        scriptInitInstructions.addInstruction(OP_findpropstrict, superclassName);
+        scriptInitInstructions.addInstruction(OP_getproperty, superclassName);
+        scriptInitInstructions.addInstruction(OP_dup);
+        scriptInitInstructions.addInstruction(OP_pushscope);
+     
+        scriptInitInstructions.addInstruction(OP_newclass, cinfo);
+        
+        for ( int i = 0; i < ancestorNames.size(); i++ )
+            scriptInitInstructions.addInstruction(OP_popscope);
+
+        scriptInitInstructions.addInstruction(OP_popscope);
+        
+        scriptInitInstructions.addInstruction(OP_initproperty, className);
+        
+        ctraits.visitEnd();
+        itraits.visitEnd();
+        
+        classVisitor.visitEnd();
+        
+    }
+    
+    /**
+     * @return The {@link ITraitsVisitor} for the instance trait's of the generated class.
+     */
+    public ITraitsVisitor getITraitsVisitor()
+    {
+        return itraits;
+    }
+    
+    /**
+     * @return The {@link ITraitsVisitor} for the class trait's of the generated class.
+     */
+    public ITraitsVisitor getCTraitsVisitor()
+    {
+        return ctraits;
+    }
+    
+    private ITraitVisitor addMethodToTraits(ITraitsVisitor traits, Name methodName,
+            Collection<Name> parameterTypes,
+            Name returnType,
+            Collection<Object> defaultParameterValues,
+            boolean needsRest,
+            int functionTraitKind,
+            InstructionList body)
+    {
+        MethodInfo mi = new MethodInfo();
+        for (Object defaultParameterValue : defaultParameterValues)
+            mi.addDefaultValue(new PooledValue(defaultParameterValue));
+        mi.setParamTypes(new Vector<Name>(parameterTypes));
+        mi.setReturnType(returnType);
+        if (needsRest)
+            mi.setFlags(mi.getFlags() | ABCConstants.METHOD_Needrest);
+        FunctionGeneratorHelper.generateFunction(visitor, mi, body);
+        return traits.visitMethodTrait(functionTraitKind, methodName, 0, mi);
+    }
+    
+    /**
+     * Utility method to add an instance method to the generated class.
+     * 
+     * @param methodName {@link Name} of the method to add.
+     * @param parameterTypes Collection of {@link Name}'s of the parameters to
+     * the method.
+     * @param returnType {@link Name} of the return type of the method.
+     * @param defaultParameterValues Collection of object's that can be
+     * converted to ABC constants for the default values of parameters.
+     * @param needsRest true if the method needs the rest parameter, false otherwise
+     * @param isFinal true if the method is final, false otherwise
+     * @param isOverride true if the method is an override of another method, false otherwise
+     * @param body An {@link InstructionList} for the body of the method.
+     */
+    public void addITraitsMethod(Name methodName,
+            Collection<Name> parameterTypes,
+            Name returnType,
+            Collection<Object> defaultParameterValues,
+            boolean needsRest,
+            boolean isFinal,
+            boolean isOverride,
+            InstructionList body)
+    {
+        addITraitsMethod(methodName, parameterTypes, returnType, defaultParameterValues,
+                needsRest, isFinal, isOverride, body, ABCConstants.TRAIT_Method);
+    }
+    
+    /**
+     * Utility method to add an instance method to the generated class.
+     * 
+     * @param methodName {@link Name} of the method to add.
+     * @param parameterTypes Collection of {@link Name}'s of the parameters to
+     * the method.
+     * @param returnType {@link Name} of the return type of the method.
+     * @param defaultParameterValues Collection of object's that can be
+     * converted to ABC constants for the default values of parameters.
+     * @param needsRest true if the method needs the rest parameter, false otherwise
+     * @param isFinal true if the method is final, false otherwise
+     * @param isOverride true if the method is an override of another method, false otherwise
+     * @param body An {@link InstructionList} for the body of the method.
+     * @param functionKindTrait One of ABCConstants, TRAIT_Method, TRAIT_Getter, 
+     * TRAIT_Setter.
+     */
+    public void addITraitsMethod(Name methodName,
+            Collection<Name> parameterTypes,
+            Name returnType,
+            Collection<Object> defaultParameterValues,
+            boolean needsRest,
+            boolean isFinal,
+            boolean isOverride,
+            InstructionList body,
+            int functionKindTrait)
+    {
+        ITraitVisitor traitVisitor = addMethodToTraits(itraits, methodName, parameterTypes, 
+                returnType, defaultParameterValues, needsRest, functionKindTrait, body);
+        traitVisitor.visitStart();
+        if (isFinal)
+            traitVisitor.visitAttribute(Trait.TRAIT_FINAL, true);
+        if (isOverride)
+            traitVisitor.visitAttribute(Trait.TRAIT_OVERRIDE, true);
+        traitVisitor.visitEnd();
+    }
+
+    /**
+     * Utility method to add a static method to the generated class.
+     * 
+     * @param methodName {@link Name} of the method to add.
+     * @param parameterTypes Collection of {@link Name}'s of the parameters to
+     * the method.
+     * @param returnType {@link Name} of the return type of the method.
+     * @param defaultParameterValues Collection of object's that can be
+     * converted to ABC constants for the default values of parameters.
+     * @param needsRest true if the method needs the rest parameter, false otherwise
+     * @param body An {@link InstructionList} for the body of the method.
+     */
+    public void addCTraitsMethod(Name methodName,
+            Collection<Name> parameterTypes,
+            Name returnType,
+            Collection<Object> defaultParameterValues,
+            boolean needsRest,
+            InstructionList body) 
+    {
+        ITraitVisitor traitVisitor = addMethodToTraits(ctraits, methodName, parameterTypes, returnType, defaultParameterValues, needsRest, ABCConstants.TRAIT_Method, body);
+        traitVisitor.visitStart();
+        traitVisitor.visitEnd();
+    }
+
+    /**
+     * Utility method to add an instance getter to the generated class.
+     * 
+     * @param getterName {@link Name} of the method to add.
+     * @param returnType {@link Name} of the return type of the method.
+     * @param body An {@link InstructionList} for the body of the method.
+     */
+    public void addITraitsGetter(Name getterName, Name returnType, InstructionList body)
+    {
+        ITraitVisitor traitVisitor = addMethodToTraits(itraits, getterName, Collections.<Name>emptyList(), returnType, Collections.<Object>emptyList(), false, ABCConstants.TRAIT_Getter, body);
+        traitVisitor.visitStart();
+        traitVisitor.visitEnd();
+    }
+    
+    /**
+     * Utility method to add a static getter to the generated class.
+     * 
+     * @param getterName {@link Name} of the method to add.
+     * @param returnType {@link Name} of the return type of the method.
+     * @param body An {@link InstructionList} for the body of the method.
+     */
+    public void addCTraitsGetter(Name getterName, Name returnType, InstructionList body)
+    {
+        ITraitVisitor traitVisitor = addMethodToTraits(ctraits, getterName, Collections.<Name>emptyList(), returnType, Collections.<Object>emptyList(), false, ABCConstants.TRAIT_Getter, body);
+        traitVisitor.visitStart();
+        traitVisitor.visitEnd();
+    }
+
+    /**
+     * Utility method to add a member variable to a class.
+     * 
+     * @param variableName {@link Name} of the member variable to add.
+     */
+    public void addMemberVariable(Name variableName, Name type)
+    {
+        ITraitVisitor traitVisitor = itraits.visitSlotTrait(ABCConstants.TRAIT_Var, variableName, ITraitsVisitor.RUNTIME_SLOT, type, LexicalScope.noInitializer);
+        traitVisitor.visitStart();
+        traitVisitor.visitEnd();
+    }
+
+    /**
+     * @return protected namespace if it is asked for while creating this helper class
+     */
+    public Namespace getProtectedNamespace() {
+        assert iinfo.protectedNs != null : "protected namespace is only available if you pass true for the hasProtectedMembers argument of this class' constructor";
+        return iinfo.protectedNs;
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/CollectMetadataTraitVisitor.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/CollectMetadataTraitVisitor.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/CollectMetadataTraitVisitor.java
new file mode 100644
index 0000000..9fe2780
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/CollectMetadataTraitVisitor.java
@@ -0,0 +1,153 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import org.apache.flex.abc.semantics.Metadata;
+import org.apache.flex.abc.semantics.Trait;
+import org.apache.flex.abc.visitors.IMetadataVisitor;
+import org.apache.flex.abc.visitors.ITraitVisitor;
+import org.apache.flex.compiler.constants.IMetaAttributeConstants;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.metadata.IMetaTag;
+import org.apache.flex.compiler.definitions.metadata.IMetaTagAttribute;
+import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.DefinitionBase;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
+import org.apache.flex.compiler.internal.definitions.metadata.MetaTag;
+import org.apache.flex.compiler.internal.definitions.metadata.MetaTagAttribute;
+
+/**
+ * Collect all the metadata and attributes in this trait.
+ */
+class CollectMetadataTraitVisitor implements ITraitVisitor
+{
+    CollectMetadataTraitVisitor(final DefinitionBase definition)
+    {
+        assert definition != null;
+        this.definition = definition;
+    }
+
+    private final DefinitionBase definition;
+    private IMetaTag[] metaTags;
+
+    /**
+     * Visiting all the metadata associated with this trait. The {@code count}
+     * is used to determine size of MetaTag array.
+     */
+    @Override
+    public IMetadataVisitor visitMetadata(final int count)
+    {
+        assert metaTags == null : "Can not re-use the collector.";
+        metaTags = new IMetaTag[count];
+        return new IMetadataVisitor()
+        {
+            int currentIndex = 0;
+
+            @Override
+            public void visit(Metadata metadata)
+            {
+                metaTags[currentIndex++] = createMetaTag(definition, metadata);
+            }
+        };
+    }
+
+    @Override
+    public void visitStart()
+    {
+    }
+
+    private IMetaTag findMetaTag(String name)
+    {
+        for (IMetaTag tag : metaTags)
+        {
+            if (tag.getTagName().equals(name))
+                return tag;
+        }
+        return null;
+    }
+    
+    private static void setNameLocation(IDefinition def, IMetaTag gotoDefTag)
+    {
+        String posString = gotoDefTag.getAttributeValue(IMetaAttributeConstants.NAME_GOTODEFINITIONHELP_POS);
+        int nameStart = Integer.parseInt(posString);
+
+        DefinitionBase constructorDef = (DefinitionBase)def;
+        int nameEnd = nameStart + def.getBaseName().length();
+        constructorDef.setNameLocation(nameStart, nameEnd);
+    }
+    
+    /**
+     * Store the meta tags in the definition object.
+     */
+    @Override
+    public void visitEnd()
+    {
+        if (metaTags == null)
+            metaTags = new IMetaTag[0];
+        if (definition instanceof ClassDefinition)
+        {
+            ClassDefinition classDef = (ClassDefinition)definition;
+            IFunctionDefinition constructor = classDef.getConstructor();
+            if (constructor != null)
+            {
+                IMetaTag ctorGotoDefHelpTag = findMetaTag(IMetaAttributeConstants.ATTRIBUTE_GOTODEFINITION_CTOR_HELP);
+                if (ctorGotoDefHelpTag != null)
+                    setNameLocation(constructor, ctorGotoDefHelpTag);
+            }
+        }
+        IMetaTag gotoDefHelpTag = findMetaTag(IMetaAttributeConstants.ATTRIBUTE_GOTODEFINITIONHELP);
+        if (gotoDefHelpTag != null)
+            setNameLocation(definition, gotoDefHelpTag);
+        definition.setMetaTags(metaTags);
+    }
+
+    @Override
+    public void visitAttribute(String attr_name, Object attr_value)
+    {
+        if (definition instanceof FunctionDefinition)
+        {
+            if (attr_name.equals(Trait.TRAIT_FINAL) && (Boolean)attr_value)
+                definition.setFinal();
+            else if (attr_name.equals(Trait.TRAIT_OVERRIDE) && (Boolean)attr_value)
+                definition.setOverride();
+        }
+    }
+
+    /**
+     * Create a {@link IMetaTag} object from {@link Metadata}.
+     * 
+     * @param metadata metadata object
+     * @return IMetaTag object
+     */
+    private static IMetaTag createMetaTag(final IDefinition definition, final Metadata metadata)
+    {
+        final String[] keys = metadata.getKeys();
+        final String[] values = metadata.getValues();
+        
+        assert keys.length == values.length;
+        final int attributesCount = keys.length;
+        final IMetaTagAttribute[] attributes = new IMetaTagAttribute[attributesCount];
+        for (int i = 0; i < attributesCount; i++)
+            attributes[i] = new MetaTagAttribute(keys[i], values[i]);
+        
+        return new MetaTag(definition, metadata.getName(), attributes);
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/FunctionGeneratorHelper.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/FunctionGeneratorHelper.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/FunctionGeneratorHelper.java
new file mode 100644
index 0000000..77ba616
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/FunctionGeneratorHelper.java
@@ -0,0 +1,58 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import org.apache.flex.abc.instructionlist.InstructionList;
+import org.apache.flex.abc.semantics.MethodBodyInfo;
+import org.apache.flex.abc.semantics.MethodInfo;
+import org.apache.flex.abc.visitors.IABCVisitor;
+import org.apache.flex.abc.visitors.IMethodBodyVisitor;
+import org.apache.flex.abc.visitors.IMethodVisitor;
+
+/**
+ * Utility class for writing a function into an {@link IABCVisitor}.
+ */
+public class FunctionGeneratorHelper
+{
+    /**
+     * Adds the specified {@link MethodInfo} with the specified
+     * {@link InstructionList} as its body to the specified {@link IABCVisitor}
+     * <p>
+     * After calling the method, the specified {@link MethodInfo} and
+     * {@link InstructionList} must not be modified.
+     * 
+     * @param abcVisitor {@link IABCVisitor} to write the function/method into.
+     * @param mi {@link MethodInfo} for the function/method
+     * @param functionBody {@link InstructionList} for the body of the
+     * function/method.
+     */
+    public static void generateFunction(IABCVisitor abcVisitor, MethodInfo mi, InstructionList functionBody)
+    {
+        IMethodVisitor methodVisitor = abcVisitor.visitMethod(mi);
+        methodVisitor.visit();
+        MethodBodyInfo methodBodyInfo = new MethodBodyInfo();
+        methodBodyInfo.setMethodInfo(mi);
+        IMethodBodyVisitor methodBodyVisitor = methodVisitor.visitBody(methodBodyInfo);
+        methodBodyVisitor.visit();
+        methodBodyVisitor.visitInstructionList(functionBody);
+        methodBodyVisitor.visitEnd();
+        methodVisitor.visitEnd();
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScopedDefinitionTraitsVisitor.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScopedDefinitionTraitsVisitor.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScopedDefinitionTraitsVisitor.java
new file mode 100644
index 0000000..2ca39d1
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScopedDefinitionTraitsVisitor.java
@@ -0,0 +1,311 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import java.util.Vector;
+
+import org.apache.flex.abc.ABCConstants;
+import org.apache.flex.abc.semantics.ClassInfo;
+import org.apache.flex.abc.semantics.MethodInfo;
+import org.apache.flex.abc.semantics.Name;
+import org.apache.flex.abc.semantics.Namespace;
+import org.apache.flex.abc.semantics.Nsset;
+import org.apache.flex.abc.semantics.PooledValue;
+import org.apache.flex.abc.semantics.Traits;
+import org.apache.flex.abc.visitors.ITraitVisitor;
+import org.apache.flex.abc.visitors.ITraitsVisitor;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
+import org.apache.flex.compiler.definitions.IParameterDefinition;
+import org.apache.flex.compiler.definitions.references.INamespaceReference;
+import org.apache.flex.compiler.definitions.references.IReference;
+import org.apache.flex.compiler.definitions.references.ReferenceFactory;
+import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.ConstantDefinition;
+import org.apache.flex.compiler.internal.definitions.DefinitionBase;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
+import org.apache.flex.compiler.internal.definitions.GetterDefinition;
+import org.apache.flex.compiler.internal.definitions.NamespaceDefinition;
+import org.apache.flex.compiler.internal.definitions.ParameterDefinition;
+import org.apache.flex.compiler.internal.definitions.SetterDefinition;
+import org.apache.flex.compiler.internal.definitions.TypeDefinitionBase;
+import org.apache.flex.compiler.internal.definitions.VariableDefinition;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.scopes.FunctionScope;
+import org.apache.flex.compiler.scopes.IASScope;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * This {@link ITraitsVisitor} creates definition for each trait, and add the
+ * definitions to a scope object.
+ */
+public class ScopedDefinitionTraitsVisitor implements ITraitsVisitor
+{
+    private static final IReference TYPE_ANY = ReferenceFactory.builtinReference(IASLanguageConstants.BuiltinType.ANY_TYPE); 
+    private static final IReference TYPE_FUNCTION = ReferenceFactory.builtinReference(IASLanguageConstants.BuiltinType.FUNCTION);
+
+    private final ASScope scope;
+    private final boolean isStatic;
+    private final ABCScopeBuilder scopeBuilder;
+    private final INamespaceReference interfNamespace;
+
+    public ScopedDefinitionTraitsVisitor(final ABCScopeBuilder owner, final IASScope scope,
+            boolean isStatic)
+    {
+        this(owner, scope, isStatic, null);
+    }
+    
+    public ScopedDefinitionTraitsVisitor(final ABCScopeBuilder owner, final IASScope scope,
+                                         boolean isStatic, INamespaceReference interfNamespace)
+    {
+        assert scope instanceof ASScope;
+
+        this.scopeBuilder = owner;
+        this.scope = (ASScope)scope;
+        this.isStatic = isStatic;
+        this.interfNamespace = interfNamespace;
+    }
+
+    @Override
+    public ITraitVisitor visitSlotTrait(int kind, Name name, int slot_id, Name slot_type, Object slot_value)
+    {
+        final String definitionName = getDefinitionName(name);
+
+        final DefinitionBase def;        
+        kind &= ABCConstants.TRAIT_KIND_MASK;
+        switch (kind)
+        {
+            case ABCConstants.KIND_SLOT:
+                def = new VariableDefinition(definitionName, slot_value);
+                break;
+            case ABCConstants.KIND_CONST:
+                if (slot_value instanceof Namespace)
+                    def = NamespaceDefinition.createNamespaceDefinition(definitionName, (Namespace)slot_value);
+                else
+                    def = new ConstantDefinition(definitionName, slot_value);
+                break;
+                
+            default:
+                throw new IllegalStateException("Invalid slot kind: " + kind);
+        }
+        
+        final INamespaceReference namespaceReference = getNamespaceReference(name);
+        def.setNamespaceReference(namespaceReference);
+
+        if (isStatic)
+            def.setStatic();
+
+        def.setTypeReference(slot_type == null ? TYPE_ANY : scopeBuilder.getReference(slot_type));
+        
+        scope.addDefinition(def);
+
+        return new CollectMetadataTraitVisitor(def);
+    }
+
+    @Override
+    public ITraitVisitor visitMethodTrait(int kind, Name name, int disp_id, MethodInfo method)
+    {
+        final String definitionName = getDefinitionName(name);
+
+        FunctionDefinition methodDef;
+        
+        kind &= ABCConstants.TRAIT_KIND_MASK;
+        switch (kind)
+        {
+            case ABCConstants.KIND_METHOD:
+                methodDef = new FunctionDefinition(definitionName);
+                break;
+            case ABCConstants.KIND_GETTER:
+                methodDef = new GetterDefinition(definitionName);
+                break;
+            case ABCConstants.KIND_SETTER:
+                methodDef = new SetterDefinition(definitionName);
+                break;
+            case ABCConstants.KIND_FUNCTION:
+                methodDef = new FunctionDefinition(definitionName);
+                break;
+            default:
+                throw new IllegalStateException("Invalid method kind:" + kind);
+        }
+        
+        final INamespaceReference namespaceReference = getNamespaceReference(name);
+        methodDef.setNamespaceReference(namespaceReference);
+
+        int paramTypesSize = method.getParamTypes().size();
+        final ParameterDefinition params[] = new ParameterDefinition[paramTypesSize + (method.needsRest() ? 1 : 0)];
+        if (params.length > 0)
+        {
+            ASScope methodScope = new FunctionScope(scope);
+            methodScope.setContainingDefinition(methodDef);
+            methodDef.setContainedScope(methodScope);
+            Vector<PooledValue> defaultValues = method.getDefaultValues();
+            int firstOptionalParam = paramTypesSize - defaultValues.size();
+            for (int i = 0; i < paramTypesSize; i++)
+            {
+                final Name paramType = method.getParamTypes().get(i);
+                final String paramName = i < method.getParamNames().size() ? method.getParamNames().get(i) : MethodInfo.UNKNOWN_PARAM_NAME;
+                params[i] = new ParameterDefinition(paramName);
+                params[i].setTypeReference(paramType == null ? TYPE_ANY : scopeBuilder.getReference(paramType));
+                if (i >= firstOptionalParam)
+                {
+                    Object defaultValue = defaultValues.get(i - firstOptionalParam).getValue();
+                    params[i].setDefaultValue(defaultValue);
+                }
+                methodScope.addDefinition(params[i]);
+            }
+            if( method.needsRest() )
+            {
+                ParameterDefinition rest = new ParameterDefinition(MethodInfo.UNKNOWN_PARAM_NAME);
+                rest.setRest();
+                rest.setTypeReference(ReferenceFactory.builtinReference(IASLanguageConstants.BuiltinType.ARRAY));
+                params[paramTypesSize] = rest;
+            }
+        }
+        methodDef.setParameters(params);
+
+        Name returnType = method.getReturnType();
+        methodDef.setReturnTypeReference(returnType == null ? TYPE_ANY : scopeBuilder.getReference(returnType));
+        
+        // The type of a getter or setter is its property type
+        // (i.e., the getter's return type or the setter's parameter type).
+        // The type of a method or function is "Function".
+        switch (kind)
+        {
+            case ABCConstants.KIND_GETTER:
+                methodDef.setTypeReference(methodDef.getReturnTypeReference());
+                break;
+            case ABCConstants.KIND_SETTER:
+                methodDef.setTypeReference(methodDef.getParameters()[0].getTypeReference());
+                break;
+            case ABCConstants.KIND_METHOD:
+            case ABCConstants.KIND_FUNCTION:
+                methodDef.setTypeReference(TYPE_FUNCTION);
+                break;
+            default:
+                throw new IllegalStateException("Invalid method kind:" + kind);
+        }
+
+        if (isStatic)
+            methodDef.setStatic();
+
+        scope.addDefinition(methodDef);
+
+        return new CollectMetadataTraitVisitor(methodDef);
+    }
+    
+
+    @Override
+    public ITraitVisitor visitClassTrait(int kind, Name name, int slot_id, ClassInfo clazz)
+    {
+        final TypeDefinitionBase classDef = scopeBuilder.classDefinitions.get(clazz);
+        assert classDef != null : "Null class def at #" + slot_id;
+        scope.addDefinition(classDef);
+        classDef.getContainedScope().setContainingScope(scope);
+
+        // Need to setup the scopes for the constructor and any params
+        // here instead of ABCScopeBuilder, as we need to have a handle to the
+        // class scope which isn't set until here.
+        if (classDef instanceof ClassDefinition)
+        {
+            FunctionDefinition ctor = (FunctionDefinition)((ClassDefinition)classDef).getConstructor();
+            classDef.getContainedScope().addDefinition(ctor);
+
+            IParameterDefinition[] params = ctor.getParameters();
+            if (params.length > 0)
+            {
+                ASScope ctorScope = new FunctionScope(scope);
+                ctorScope.setContainingDefinition(ctor);
+                ctor.setContainedScope(ctorScope);
+
+                for (IParameterDefinition param : params)
+                {
+                    ctorScope.addDefinition(param);
+                }
+            }
+        }
+
+        return new CollectMetadataTraitVisitor(classDef);
+    }
+    
+    private static boolean legalDefinitionNsset(Nsset nsSet)
+    {
+        if (nsSet == null)
+            return false;
+        if (nsSet.length() == 1)
+            return true;
+        return Iterables.all(nsSet, new Predicate<Namespace>() {
+
+            @Override
+            public boolean apply(Namespace ns)
+            {
+                return ns.getApiVersion() != ABCConstants.NO_API_VERSION;
+            } }); 
+    }
+    
+    public static String getDefinitionName(Name name)
+    {
+        final String baseName = name.getBaseName();
+
+        // A definition can only ever have one namespace entry
+        // otherwise it is an invalid SWC.
+        Nsset nsSet = name.getQualifiers();
+        if (!legalDefinitionNsset(nsSet))
+        {
+            throw new IllegalStateException("Definition " + baseName + " can have only one qualifier or all qualifiers should be versioned namespaces");
+        }
+
+        return baseName;
+    }
+    
+    private INamespaceReference getNamespaceReference(Name name)
+    {
+        final Namespace namespace = Iterables.getFirst(name.getQualifiers(), null);
+        assert namespace != null;
+        
+        INamespaceReference namespaceReference =
+            (INamespaceReference)scopeBuilder.getNamespaceReferenceForNamespace(namespace);
+        
+        // Interface Namespaces are encoded as regular user defined namespaces in the ABC, but internally
+        // we want them to be InterfaceNamespaceDefinitions.  If we come across a user defined namespace while
+        // building the traits for an interface, and it matches the interface namespace, then use the interface
+        // namespace instead so that other processing that relies on InterfaceNamespaceDefinitions works right.
+        if( interfNamespace != null && interfNamespace.equals(namespaceReference) )
+            namespaceReference = interfNamespace;
+        
+        return namespaceReference;
+    }
+
+    @Override
+    public void visit()
+    {
+    }
+
+    @Override
+    public void visitEnd()
+    {
+    }
+
+    @Override
+    public Traits getTraits()
+    {
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScriptDefinitionBuilder.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScriptDefinitionBuilder.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScriptDefinitionBuilder.java
new file mode 100644
index 0000000..b9b783b
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/ScriptDefinitionBuilder.java
@@ -0,0 +1,72 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import org.apache.flex.abc.semantics.MethodInfo;
+import org.apache.flex.abc.visitors.IScriptVisitor;
+import org.apache.flex.abc.visitors.ITraitsVisitor;
+import org.apache.flex.compiler.scopes.IASScope;
+
+/**
+ * Implementation of the {@linkplain IScriptVisitor}. It builds the script-level
+ * scope object.
+ */
+class ScriptDefinitionBuilder implements IScriptVisitor
+{
+    /**
+     * Create a ScriptDefinitionBuilder. The definitions will be added to the
+     * given scope object.
+     * 
+     * @param scope the scope contained by the script
+     */
+    protected ScriptDefinitionBuilder(final ABCScopeBuilder owner, final IASScope scope)
+    {
+        this.scope = scope;
+        this.scopeBuilder = owner;
+    }
+
+    private final IASScope scope;
+    private final ABCScopeBuilder scopeBuilder;
+
+    @Override
+    public void visit()
+    {
+    }
+
+    @Override
+    public void visitEnd()
+    {
+    }
+
+    @Override
+    public ITraitsVisitor visitTraits()
+    {
+        final ITraitsVisitor visitor = new ScopedDefinitionTraitsVisitor(scopeBuilder,
+                                                                        scope,
+                                                                        false);
+        return visitor;
+    }
+
+    @Override
+    public void visitInit(MethodInfo methodInfo)
+    {
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/59f6373b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/TypeDefinitionBuilder.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/abc/TypeDefinitionBuilder.java b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/TypeDefinitionBuilder.java
new file mode 100644
index 0000000..d437e1c
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/abc/TypeDefinitionBuilder.java
@@ -0,0 +1,80 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.internal.abc;
+
+import org.apache.flex.abc.visitors.IClassVisitor;
+import org.apache.flex.abc.visitors.ITraitsVisitor;
+import org.apache.flex.compiler.definitions.references.INamespaceReference;
+import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.InterfaceDefinition;
+import org.apache.flex.compiler.internal.definitions.TypeDefinitionBase;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.scopes.TypeScope;
+
+/**
+ * Visit class_info and instance_info to build an ActionScript3 class or
+ * interface definition.
+ */
+class TypeDefinitionBuilder implements IClassVisitor
+{
+    protected TypeDefinitionBuilder(final ABCScopeBuilder scopeBuilder, final TypeDefinitionBase typeDefinition)
+    {
+        assert typeDefinition instanceof ClassDefinition || typeDefinition instanceof InterfaceDefinition;
+        this.scope = new TypeScope(null, typeDefinition);
+        this.definition = typeDefinition;
+        this.definition.setContainedScope(scope);
+        this.scopeBuilder = scopeBuilder;
+    }
+
+    private final ABCScopeBuilder scopeBuilder;
+    private final TypeDefinitionBase definition;
+    private final ASScope scope;
+
+    @Override
+    public void visit()
+    {
+    }
+
+    @Override
+    public void visitEnd()
+    {
+    }
+
+    /**
+     * All the static members are on ClassTraits.
+     */
+    @Override
+    public ITraitsVisitor visitClassTraits()
+    {
+        return new ScopedDefinitionTraitsVisitor(scopeBuilder, scope, true);
+    }
+
+    /**
+     * All the non-static members are on InstanceTraits.
+     */
+    @Override
+    public ITraitsVisitor visitInstanceTraits()
+    {
+        INamespaceReference interfNs = null;
+        if( definition instanceof InterfaceDefinition )
+            interfNs = ((InterfaceDefinition)definition).getInterfaceNamespaceReference();
+        return new ScopedDefinitionTraitsVisitor(scopeBuilder, scope, false, interfNs);
+    }
+}


Mime
View raw message