]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutogenLibOrder.java
index 77404d40072f740ae5791f14bd8590a1b2fc70bd..8aad4cc0015ac7dea3540cf0a037ab91ca7da032 100644 (file)
@@ -26,6 +26,7 @@ import org.tianocore.LibraryClassDocument.LibraryClass;
 \r
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
 \r
 /**\r
   This class This class is to reorder library instance sequence according to\r
@@ -35,18 +36,18 @@ public class AutogenLibOrder {
     ///\r
     /// The map of library class and its library instance.\r
     ///\r
-    private Map<String, String> libClassMap = new HashMap<String, String>();\r
+    private Map<String, ModuleIdentification> libClassMap = new HashMap<String, ModuleIdentification>();\r
 \r
     ///\r
-    /// The map of library instance and its implemet instance.\r
+    /// The map of library instance and its implemet libraryClass.\r
     ///\r
-    private Map<String, String[]> libInstanceMap = new HashMap<String, String[]>();\r
+    private Map<ModuleIdentification, String[]> libInstanceMap = new HashMap<ModuleIdentification, String[]>();\r
 \r
     ///\r
     /// List of library instance. It is String[3] list, String[0] is libraryName,\r
     /// String[1] is libraryConstructor name, String[2] is libDestructor name.\r
     ///\r
-    private List<String[]> libInstanceList = new ArrayList<String[]>();\r
+    private List<LibraryInstanceNode> libInstanceList = new ArrayList<LibraryInstanceNode>();\r
     \r
     /**\r
       Constructor function\r
@@ -56,39 +57,37 @@ public class AutogenLibOrder {
       @param  libraryList   List of the library instance.\r
       @throws Exception\r
     **/\r
-    AutogenLibOrder(List<String> libraryList) throws Exception {\r
-        String[]       libInstance = new String[3];\r
-        LibraryClass[] libClassDeclList = null;\r
-        LibraryClass[] libClassConsmList = null;\r
+    AutogenLibOrder(ModuleIdentification[] libraryList, String arch) throws Exception {\r
+        LibraryInstanceNode libInstanceNode;\r
+        String[]       libClassDeclList = null;\r
+        String[]       libClassConsmList = null;\r
         \r
-        for (int i = 0; i < libraryList.size(); i++) {\r
+        for (int i = 0; i < libraryList.length; i++) {\r
             //\r
             // Add libraryInstance in to libInstanceList.\r
-            //\r
-            libInstance[0] = libraryList.get(i);\r
-            Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstance[0]);\r
+            // \r
+            Map<String, XmlObject> libDoc = GlobalData.getDoc(libraryList[i], arch);\r
             SurfaceAreaQuery.push(libDoc);\r
-            libInstance[1] = SurfaceAreaQuery.getLibConstructorName();\r
-            libInstance[2] = SurfaceAreaQuery.getLibDestructorName();\r
-            libInstanceList.add(libInstance.clone());\r
+            libInstanceNode = new LibraryInstanceNode (libraryList[i],SurfaceAreaQuery.getLibConstructorName(), SurfaceAreaQuery.getLibDestructorName());\r
+            libInstanceList.add(libInstanceNode);\r
             \r
             //\r
             // Add library instance and consumed library class list to\r
             // libInstanceMap.\r
             //\r
             libClassConsmList = SurfaceAreaQuery\r
-                    .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+                    .getLibraryClasses(CommonDefinition.AlwaysConsumed, arch);\r
             if (libClassConsmList != null) {\r
                 String[] classStr = new String[libClassConsmList.length];\r
                 for (int k = 0; k < libClassConsmList.length; k++) {\r
-                    classStr[k] = libClassConsmList[k].getStringValue();\r
+                    classStr[k] = libClassConsmList[k];\r
                 }\r
-                if (this.libInstanceMap.containsKey(libInstance[0])) {\r
+                if (this.libInstanceMap.containsKey(libraryList[i])) {\r
                     throw new Exception(\r
-                            libInstance[0]\r
-                                    + "this library instance is already exist, please check you library instance list!");\r
+                            libraryList[i].getName()\r
+                                    + "this library instance already exists, please check the library instance list!");\r
                 } else {\r
-                    this.libInstanceMap.put(libInstance[0], classStr);\r
+                    this.libInstanceMap.put(libraryList[i], classStr);\r
                 }\r
             }\r
 \r
@@ -96,20 +95,17 @@ public class AutogenLibOrder {
             // Add library class and library instance map.\r
             //\r
             libClassDeclList = SurfaceAreaQuery\r
-                    .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                    .getLibraryClasses(CommonDefinition.AlwaysProduced, arch);\r
             if (libClassDeclList != null) {\r
                 for (int j = 0; j < libClassDeclList.length; j++) {\r
-                    if (this.libClassMap.containsKey(libClassDeclList[j]\r
-                            .getStringValue())) {\r
-                        System.out.println(libClassDeclList[j].getStringValue()\r
+                    if (this.libClassMap.containsKey(libClassDeclList[j])) {\r
+                        System.out.println(libClassDeclList[j]\r
                                 + " class is already implement by "\r
-                                + this.libClassMap.get(libClassDeclList[j]\r
-                                        .getStringValue()));\r
-                        throw new Exception(libClassDeclList\r
-                                + " is already have library instance!");\r
+                                + this.libClassMap.get(libClassDeclList[j]));\r
+                        throw new Exception("Library Class: " + libClassDeclList\r
+                                + " already has a library instance!");\r
                     } else {\r
-                        this.libClassMap.put(libClassDeclList[j]\r
-                                .getStringValue(), libInstance[0]);\r
+                        this.libClassMap.put(libClassDeclList[j], libraryList[i]);\r
                     }\r
                 }\r
             }\r
@@ -149,15 +145,15 @@ public class AutogenLibOrder {
       \r
       @return     List which content the ordered library instance.\r
     **/\r
-    List orderLibInstance() {\r
-        List<String> orderList = new ArrayList<String>();\r
+    List<ModuleIdentification> orderLibInstance() {\r
+        List<ModuleIdentification> orderList = new ArrayList<ModuleIdentification>();\r
         //\r
         // Stack of node which track the library instance name ant its visiting\r
         // flag.\r
         //\r
         List<Node> stackList = new ArrayList<Node>();\r
         int stackSize = 0;\r
-        String libInstance = null;\r
+        ModuleIdentification libInstanceId = null;\r
         if (libInstanceList.size() < 0) {\r
             return null;\r
         }\r
@@ -169,11 +165,11 @@ public class AutogenLibOrder {
             //\r
             // If library instance is already in the order list skip it.\r
             //\r
-            if (isInLibInstance(orderList, libInstanceList.get(i)[0])) {\r
+            if (isInLibInstance(orderList, libInstanceList.get(i).libId)) {\r
                 continue;\r
             }\r
             \r
-            Node node = new Node(libInstanceList.get(i)[0], false);\r
+            Node node = new Node(libInstanceList.get(i).libId, false);\r
             //\r
             // Use stack to reorder library instance.\r
             // Push node to stack.\r
@@ -187,8 +183,8 @@ public class AutogenLibOrder {
                 //\r
                 if (stackList.get(stackSize).isVisit) {\r
                     if (!isInLibInstance(orderList,\r
-                            stackList.get(stackSize).nodeName)) {\r
-                        orderList.add(stackList.get(stackSize).nodeName);\r
+                            stackList.get(stackSize).nodeId)) {\r
+                        orderList.add(stackList.get(stackSize).nodeId);\r
                         stackList.remove(stackSize);\r
                     }\r
                     \r
@@ -198,15 +194,15 @@ public class AutogenLibOrder {
                     //\r
                     stackList.get(stackList.size() - 1).isVisit = true;\r
                     String[] libClassList = this.libInstanceMap.get(stackList\r
-                            .get(stackSize).nodeName);\r
+                            .get(stackSize).nodeId);\r
                     //\r
                     // Push the node dependence library instance to the stack.\r
                     //\r
                     if (libClassList != null) {\r
                         for (int j = 0; j < libClassList.length; j++) {\r
-                            libInstance = this.libClassMap.get(libClassList[j]);\r
-                            if (libInstance != null\r
-                                    && !isInLibInstance(orderList, libInstance)) {\r
+                            libInstanceId = this.libClassMap.get(libClassList[j]);\r
+                            if (libInstanceId != null\r
+                                    && !isInLibInstance(orderList, libInstanceId)) {\r
                                 //\r
                                 // If and only if the currently library instance\r
                                 // is not in stack and it have constructor or \r
@@ -214,7 +210,7 @@ public class AutogenLibOrder {
                                 // instacne in stack.\r
                                 //\r
                                 if (!isInStackList(stackList, this.libClassMap\r
-                                        .get(libClassList[j])) && isHaveConsDestructor(libInstance)) {\r
+                                        .get(libClassList[j])) && isHaveConsDestructor(libInstanceId)) {\r
                                     stackList.add(new Node(this.libClassMap\r
                                             .get(libClassList[j]), false));\r
                                 }\r
@@ -237,9 +233,10 @@ public class AutogenLibOrder {
       @return                 "true" the library instance in list |\r
                               "false" the library instance is not in list.\r
     **/\r
-    private boolean isInLibInstance(List list, String instanceName) {\r
+    private boolean isInLibInstance(List<ModuleIdentification> list, ModuleIdentification instanceId) {\r
         for (int i = 0; i < list.size(); i++) {\r
-            if (instanceName.equalsIgnoreCase(list.get(i).toString())) {\r
+            \r
+            if (instanceId.equals(list.get(i))) {\r
                 return true;\r
             }\r
         }\r
@@ -256,9 +253,9 @@ public class AutogenLibOrder {
       @return            "true" if node have in stack |\r
                          "false" if node don't in stack.\r
     **/ \r
-    private boolean isInStackList(List<Node> list, String nodeName) {\r
+    private boolean isInStackList(List<Node> list, ModuleIdentification instanceId) {\r
         for (int i = 0; i < list.size(); i++) {\r
-            if (nodeName.equalsIgnoreCase(list.get(i).nodeName)) {\r
+            if (instanceId.equals(list.get(i).nodeId)) {\r
                 return true;\r
             }\r
         }\r
@@ -276,10 +273,10 @@ public class AutogenLibOrder {
                          "false" if library don't have constructor \r
                          and desconstructor.\r
     **/\r
-    private boolean isHaveConsDestructor (String libName){\r
+    private boolean isHaveConsDestructor (ModuleIdentification libNode){\r
         for (int i = 0; i < libInstanceList.size(); i++){\r
-            if (libInstanceList.get(i)[0].equalsIgnoreCase(libName)){\r
-                if (libInstanceList.get(i)[1] != null || libInstanceList.get(i)[2] != null){\r
+            if (libInstanceList.get(i).libId.equals(libNode)){\r
+                if (libInstanceList.get(i).constructorName != null || libInstanceList.get(i).deconstructorName != null){\r
                     return true;\r
                 }\r
             }\r
@@ -295,12 +292,29 @@ public class AutogenLibOrder {
  \r
  **/\r
 class Node {\r
-    String nodeName;\r
+    ModuleIdentification nodeId;\r
 \r
     boolean isVisit;\r
 \r
-    Node(String name, boolean isVisit) {\r
-        this.nodeName = name;\r
+    Node(ModuleIdentification nodeId, boolean isVisit) {\r
+        this.nodeId = nodeId;\r
         this.isVisit = false;\r
     }\r
-}
\ No newline at end of file
+}  \r
+/**\r
+  LibraryInstance Node   \r
+  \r
+  This class is used to store LibrayInstance and it's deconstructor and constructor\r
+**/\r
+    \r
+class LibraryInstanceNode {\r
+    ModuleIdentification libId;\r
+    String deconstructorName;\r
+    String constructorName;\r
+    \r
+    LibraryInstanceNode (ModuleIdentification libId, String deconstructor, String constructor){\r
+        this.libId = libId;\r
+        this.deconstructorName = deconstructor;\r
+        this.constructorName   = constructor;\r
+    }\r
+}\r