another attempt at dependency management.  Assumes no important dependencies 
are found during emitting


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/feb25bfc
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/feb25bfc
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/feb25bfc

Branch: refs/heads/develop
Commit: feb25bfc80158c5bf0fbcdb0d6cc0f4b5b6fa1a7
Parents: 32186ca
Author: Alex Harui <[email protected]>
Authored: Fri Apr 19 09:45:39 2013 -0700
Committer: Alex Harui <[email protected]>
Committed: Fri Apr 19 10:39:42 2013 -0700

----------------------------------------------------------------------
 .../org/apache/flex/compiler/clients/MXMLJSC.java  |    2 +-
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java     |    1 +
 .../compiler/internal/projects/FlexJSProject.java  |  106 +++++++++++----
 3 files changed, 78 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/feb25bfc/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java 
b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
index 5ed4dca..35b539f 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -444,7 +444,7 @@ public class MXMLJSC
         final List<ICompilerProblem> problemsBuildingSWF = new 
ArrayList<ICompilerProblem>();
 
         String qname = config.getMainDefinition();
-        ((FlexJSProject)project).alreadyRequired.put(qname, mainCU);
+        ((FlexJSProject)project).mainCU = mainCU;
         final IJSApplication app = buildApplication(project,
                 config.getMainDefinition(), mainCU, problemsBuildingSWF);
         problems.addAll(problemsBuildingSWF);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/feb25bfc/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git 
a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
 
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index aa2df2c..6e18b20 100644
--- 
a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ 
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -652,6 +652,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter 
implements
                 writtenInstances.add(imp);
             }
         }
+        
     }
 
     private void emitHeaderLine(String qname)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/feb25bfc/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
----------------------------------------------------------------------
diff --git 
a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java 
b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
index 4af001a..f4aa6a1 100644
--- 
a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
+++ 
b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java
@@ -20,6 +20,8 @@ package org.apache.flex.compiler.internal.projects;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.flex.compiler.common.DependencyType;
 import org.apache.flex.compiler.definitions.IDefinition;
@@ -28,6 +30,8 @@ import 
org.apache.flex.compiler.internal.scopes.ASProjectScope.DefinitionPromise
 import org.apache.flex.compiler.internal.workspaces.Workspace;
 import org.apache.flex.compiler.units.ICompilationUnit;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * @author aharui
  *
@@ -45,8 +49,9 @@ public class FlexJSProject extends FlexProject
         super(workspace);
     }
 
-    private HashMap<ICompilationUnit, ArrayList<String>> requires = new 
HashMap<ICompilationUnit, ArrayList<String>>();
-    public HashMap<String, ICompilationUnit> alreadyRequired = new 
HashMap<String, ICompilationUnit>();
+    private HashMap<ICompilationUnit, HashMap<String, DependencyType>> 
requires = new HashMap<ICompilationUnit, HashMap<String, DependencyType>>();
+    
+    public ICompilationUnit mainCU;
     
     @Override
     public void addDependency(ICompilationUnit from, ICompilationUnit to, 
DependencyType dt, String qname)
@@ -54,43 +59,84 @@ public class FlexJSProject extends FlexProject
         IDefinition def = to.getDefinitionPromises().get(0);
         IDefinition actualDef = ((DefinitionPromise) 
def).getActualDefinition();
         boolean isInterface = actualDef instanceof InterfaceDefinition;
-        if (isInterface)
-        {
-            //System.out.println("Interface: " + qname);
-        }
-        else
+        if (!isInterface)
         {
-            
-               ArrayList<String> reqs;
-               if (requires.containsKey(from))
-                       reqs = requires.get(from);
-               else
-               {
-                       reqs = new ArrayList<String>();
-                       requires.put(from, reqs);
-               }
-               // if the class is already required by some other class
-               // don't add it.  Otherwise we can get circular
-               // dependencies.
-               boolean circular = (from == to);
-               if (requires.containsKey(to))
-               {
-                       if (alreadyRequired.containsKey(qname))
-                               circular = true;
-               }
-               if (!circular || dt == DependencyType.INHERITANCE)
+               if (from != to)
                {
-                       reqs.add(qname);
-                       alreadyRequired.put(qname, from);
+                HashMap<String, DependencyType> reqs;
+               if (requires.containsKey(from))
+                       reqs = requires.get(from);
+               else
+               {
+                       reqs = new HashMap<String, DependencyType>();
+                       requires.put(from, reqs);
+               }
+               if (reqs.containsKey(qname))
+               {
+                   // inheritance is important so remember it
+                   if (reqs.get(qname) != DependencyType.INHERITANCE)
+                   {
+                       reqs.put(qname, dt);
+                   }
+               }
+               else
+                   reqs.put(qname, dt);
                }
         }
         super.addDependency(from, to, dt, qname);
     }
+
+    private boolean needToDetermineRequires = true;
+    
+    // this set is computed from the requires list .  we have to strip out any 
circularities starting from the mainCU
+    private HashMap<ICompilationUnit, ArrayList<String>> googrequires = new 
HashMap<ICompilationUnit, ArrayList<String>>();
+    
+    private void determineRequires()
+    {
+        if (mainCU == null)
+            return;
+        
+        needToDetermineRequires = false;
+        List<ICompilationUnit> reachableCompilationUnits = 
+            getReachableCompilationUnitsInSWFOrder(ImmutableSet
+                .of(mainCU));
+        
+        HashMap<String, String> already = new HashMap<String, String>();
+        
+        for (ICompilationUnit cu: reachableCompilationUnits)
+        {
+            if (requires.containsKey(cu))
+            {
+                HashMap<String, DependencyType> reqs = requires.get(cu);
+                Set<String> it = reqs.keySet();
+                ArrayList<String> newreqs = new ArrayList<String>();
+                for (String req : it)
+                {
+                    DependencyType dt = reqs.get(req);
+                    if (dt == DependencyType.INHERITANCE)
+                        newreqs.add(req);
+                    else
+                    {
+                        if (!already.containsKey(req))
+                        {
+                            newreqs.add(req);
+                            already.put(req, req);
+                        }
+                    }
+                }
+                googrequires.put(cu, newreqs);
+            }
+        }
+    }
     
     public ArrayList<String> getRequires(ICompilationUnit from)
     {
-       if (requires.containsKey(from))
-               return requires.get(from);
+        if (needToDetermineRequires)
+            determineRequires();
+        
+       if (googrequires.containsKey(from))
+               return googrequires.get(from);
        return null;
     }
+    
 }

Reply via email to