Fixed the issue in the library instance constructor calling sequence
authorjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Dec 2006 01:30:56 +0000 (01:30 +0000)
committerjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 22 Dec 2006 01:30:56 +0000 (01:30 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2127 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java

index e14df92..9674c5d 100644 (file)
@@ -18,8 +18,12 @@ package org.tianocore.build.autogen;
 \r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 \r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.LinkedList;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Stack;\r
+import java.util.HashSet;\r
 \r
 import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.build.exception.AutoGenException;\r
 \r
 import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.build.exception.AutoGenException;\r
@@ -142,7 +146,7 @@ public class AutogenLibOrder {
       \r
       @return     List which content the ordered library instance.\r
     **/\r
       \r
       @return     List which content the ordered library instance.\r
     **/\r
-    List<ModuleIdentification> orderLibInstance() {\r
+    List<ModuleIdentification> orderLibInstance1() {\r
         List<ModuleIdentification> orderList = new ArrayList<ModuleIdentification>();\r
         //\r
         // Stack of node which track the library instance name ant its visiting\r
         List<ModuleIdentification> orderList = new ArrayList<ModuleIdentification>();\r
         //\r
         // Stack of node which track the library instance name ant its visiting\r
@@ -207,7 +211,7 @@ public class AutogenLibOrder {
                                 // instacne in stack.\r
                                 //\r
                                 if (!isInStackList(stackList, this.libClassMap\r
                                 // instacne in stack.\r
                                 //\r
                                 if (!isInStackList(stackList, this.libClassMap\r
-                                        .get(libClassList[j])) && isHaveConsDestructor(libInstanceId)) {\r
+                                        .get(libClassList[j])) /* && isHaveConsDestructor(libInstanceId) */) {\r
                                     stackList.add(new Node(this.libClassMap\r
                                             .get(libClassList[j]), false));\r
                                 }\r
                                     stackList.add(new Node(this.libClassMap\r
                                             .get(libClassList[j]), false));\r
                                 }\r
@@ -215,11 +219,64 @@ public class AutogenLibOrder {
                         }\r
                     }\r
                 }\r
                         }\r
                     }\r
                 }\r
+                System.out.println("################################################");\r
+                for (int ii = 0; ii < orderList.size(); ++ii) {\r
+                    System.out.println("  " + orderList.get(ii));\r
+                }\r
+            }\r
+        }\r
+        return orderList;\r
+    }\r
+\r
+    List<ModuleIdentification> orderLibInstance() {\r
+        LinkedList<ModuleIdentification> orderList = new LinkedList<ModuleIdentification>();\r
+        for (int i = 0; i < libInstanceList.size(); ++i) {\r
+            ModuleIdentification current = libInstanceList.get(i).libId;\r
+            int insertPoint = orderList.size();\r
+            for (int j = 0; j < orderList.size(); ++j) {\r
+                ModuleIdentification old = orderList.get(j);\r
+                //System.out.println("### old = " + old);\r
+                if (consumes(current, old)) {\r
+                    insertPoint = j + 1;\r
+                } else if (consumes(old, current)) {\r
+                    insertPoint = j;\r
+                    break;\r
+                }\r
             }\r
             }\r
+            orderList.add(insertPoint, current);\r
+//             System.out.println("################################################");\r
+//             for (int ii = 0; ii < orderList.size(); ++ii) {\r
+//                 System.out.println("  " + orderList.get(ii));\r
+//             }\r
         }\r
         }\r
+\r
         return orderList;\r
     }\r
 \r
         return orderList;\r
     }\r
 \r
+    boolean consumes(ModuleIdentification lib1, ModuleIdentification lib2) {\r
+        //System.out.println("$$$ lib1 = " + lib1);\r
+        LinkedList<ModuleIdentification> stack = new LinkedList<ModuleIdentification>();\r
+        stack.add(lib1);\r
+        int j = 0;\r
+        while (j < stack.size()) {\r
+            ModuleIdentification lib = stack.get(j++);\r
+            String[] consumedClasses = libInstanceMap.get(lib);\r
+            for (int i = 0; i < consumedClasses.length; ++i) {\r
+                ModuleIdentification consumedLib = libClassMap.get(consumedClasses[i]);\r
+                //System.out.println("$$$ class = " + consumedClasses[i]);\r
+                //System.out.println("$$$ insta = " + consumedLib);\r
+                if (consumedLib == lib2) {\r
+                    //System.out.println(lib1 + "\n   consumes\n" + lib2 + "\n");\r
+                    return true;\r
+                }\r
+                if (consumedLib != null && !stack.contains(consumedLib)) {\r
+                    stack.offer(consumedLib);\r
+                }\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+\r
     /**\r
       isInLibInstance\r
     \r
     /**\r
       isInLibInstance\r
     \r