]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutogenLibOrder.java
diff --git a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java
deleted file mode 100644 (file)
index bddea90..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/**@file\r
- AutogenLibOrder class.\r
-\r
- This class is to reorder library instance sequence according to library \r
- dependence.\r
\r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution.  The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- **/\r
-package org.tianocore.build.autogen;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.build.exception.AutoGenException;\r
-import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
-import org.tianocore.build.id.ModuleIdentification;\r
-import org.tianocore.common.exception.EdkException;\r
-\r
-/**\r
-  This class This class is to reorder library instance sequence according to\r
-  library dependence.\r
-**/\r
-public class AutogenLibOrder {\r
-    ///\r
-    /// The map of library class and its library instance.\r
-    ///\r
-    private Map<String, ModuleIdentification> libClassMap = new HashMap<String, ModuleIdentification>();\r
-\r
-    ///\r
-    /// The map of library instance and its implemet libraryClass.\r
-    ///\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<LibraryInstanceNode> libInstanceList = new ArrayList<LibraryInstanceNode>();\r
-    \r
-    /**\r
-      Constructor function\r
-    \r
-      This function mainly initialize some member variable.\r
-     \r
-      @param  libraryList   List of the library instance.\r
-      @throws Exception\r
-    **/\r
-    AutogenLibOrder(ModuleIdentification[] libraryList, String arch) throws EdkException {\r
-        LibraryInstanceNode libInstanceNode;\r
-        String[]       libClassDeclList = null;\r
-        String[]       libClassConsmList = null;\r
-        \r
-        for (int i = 0; i < libraryList.length; i++) {\r
-            //\r
-            // Add libraryInstance in to libInstanceList.\r
-            // \r
-            Map<String, XmlObject> libDoc = GlobalData.getDoc(libraryList[i], arch);\r
-            SurfaceAreaQuery saq = new SurfaceAreaQuery(libDoc);\r
-            libInstanceNode = new LibraryInstanceNode (libraryList[i],saq.getLibConstructorName(), saq.getLibDestructorName());\r
-            libInstanceList.add(libInstanceNode);\r
-            \r
-            //\r
-            // Add library instance and consumed library class list to\r
-            // libInstanceMap.\r
-            //\r
-            libClassConsmList = saq.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];\r
-                }\r
-                if (this.libInstanceMap.containsKey(libraryList[i])) {\r
-                    throw new AutoGenException(\r
-                            libraryList[i].getName()\r
-                                    + "-- this library instance already exists, please check the library instance list!");\r
-                } else {\r
-                    this.libInstanceMap.put(libraryList[i], classStr);\r
-                }\r
-            }\r
-\r
-            //\r
-            // Add library class and library instance map.\r
-            //\r
-            libClassDeclList = saq.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
-                        System.out.println(libClassDeclList[j]\r
-                                + " class is already implement by "\r
-                                + this.libClassMap.get(libClassDeclList[j]));\r
-                        throw new AutoGenException("Library Class: " + libClassDeclList\r
-                                + " already has a library instance!");\r
-                    } else {\r
-                        this.libClassMap.put(libClassDeclList[j], libraryList[i]);\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-        //\r
-        // Check is the library instance list meet the require;\r
-        //\r
-        //for (int s = 0; s < this.libInstanceList.size(); s++) {\r
-        //    String[] libClass = this.libInstanceMap.get(this.libInstanceList\r
-        //            .get(s));\r
-        //    if (libClass != null) {\r
-        //        for (int t = 0; t < libClass.length; t++) {\r
-        //            if (this.libClassMap.get(libClass[t]) == null) {\r
-                        //\r
-                        // Note: There exist a kind of module which depend on \r
-                        // library class with no instance or whose instance will\r
-                        // never be linked into the module. \r
-                        // For this satuation, the module has the description of \r
-                        // library class in MSA file but no description of \r
-                        // corresponding library instance in MBD file. There \r
-                        // will be a warnig message given here after a standard \r
-                        // log way has been decided.\r
-                        //\r
-        //           }\r
-        //       }\r
-        //   }\r
-        //}\r
-    }\r
-\r
-    /**\r
-      orderLibInstance\r
-      \r
-      This function reorder the library instance according the library class \r
-      dependency.\r
-      \r
-      @return     List which content the ordered library instance.\r
-    **/\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
-        ModuleIdentification libInstanceId = null;\r
-        if (libInstanceList.size() < 0) {\r
-            return null;\r
-        }\r
-\r
-        //\r
-        // Reorder the library instance.\r
-        //\r
-        for (int i = 0; i < libInstanceList.size(); i++) {\r
-            //\r
-            // If library instance is already in the order list skip it.\r
-            //\r
-            if (isInLibInstance(orderList, libInstanceList.get(i).libId)) {\r
-                continue;\r
-            }\r
-            \r
-            Node node = new Node(libInstanceList.get(i).libId, false);\r
-            //\r
-            // Use stack to reorder library instance.\r
-            // Push node to stack.\r
-            //\r
-            stackList.add(node);\r
-            while (stackList.size() > 0) {\r
-                stackSize = stackList.size() - 1;\r
-                //\r
-                // Pop the first node in stack. If the node flag has been visited\r
-                // add this node to orderlist and remove it from stack.\r
-                //\r
-                if (stackList.get(stackSize).isVisit) {\r
-                    if (!isInLibInstance(orderList,\r
-                            stackList.get(stackSize).nodeId)) {\r
-                        orderList.add(stackList.get(stackSize).nodeId);\r
-                        stackList.remove(stackSize);\r
-                    }\r
-                    \r
-                } else {\r
-                    //\r
-                    // Get the node value and set visit flag as true.\r
-                    //\r
-                    stackList.get(stackList.size() - 1).isVisit = true;\r
-                    String[] libClassList = this.libInstanceMap.get(stackList\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
-                            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
-                                // destructor function, push this library \r
-                                // instacne in stack.\r
-                                //\r
-                                if (!isInStackList(stackList, this.libClassMap\r
-                                        .get(libClassList[j])) && isHaveConsDestructor(libInstanceId)) {\r
-                                    stackList.add(new Node(this.libClassMap\r
-                                            .get(libClassList[j]), false));\r
-                                }\r
-                            }\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return orderList;\r
-    }\r
-\r
-    /**\r
-      isInLibInstance\r
-    \r
-      This function check does the library instance already in the list.\r
-    \r
-      @param list             List of the library instance.\r
-      @param instanceName     Name of library instance.\r
-      @return                 "true" the library instance in list |\r
-                              "false" the library instance is not in list.\r
-    **/\r
-    private boolean isInLibInstance(List<ModuleIdentification> list, ModuleIdentification instanceId) {\r
-        for (int i = 0; i < list.size(); i++) {\r
-            \r
-            if (instanceId.equals(list.get(i))) {\r
-                return true;\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-\r
-    /**\r
-      isInStackList \r
-      \r
-      This function check if the node already in the stack.\r
-       \r
-      @param list        Stack.\r
-      @param nodeName    Name of node.\r
-      @return            "true" if node have in stack |\r
-                         "false" if node don't in stack.\r
-    **/ \r
-    private boolean isInStackList(List<Node> list, ModuleIdentification instanceId) {\r
-        for (int i = 0; i < list.size(); i++) {\r
-            if (instanceId.equals(list.get(i).nodeId)) {\r
-                return true;\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-    \r
-    /**\r
-      isHaveConsDestructor\r
-      \r
-      This function check if the library have constructor or destructor \r
-      function.\r
-      \r
-      @param  libName    Name of library\r
-      @return            "true" if library have constructor or desconstructor |\r
-                         "false" if library don't have constructor \r
-                         and desconstructor.\r
-    **/\r
-    private boolean isHaveConsDestructor (ModuleIdentification libNode){\r
-        for (int i = 0; i < libInstanceList.size(); i++){\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
-        }\r
-        return false;\r
-    }\r
-}\r
-\r
-/**\r
-  Node \r
\r
-  This class is used as stack node.\r
\r
- **/\r
-class Node {\r
-    ModuleIdentification nodeId;\r
-\r
-    boolean isVisit;\r
-\r
-    Node(ModuleIdentification nodeId, boolean isVisit) {\r
-        this.nodeId = nodeId;\r
-        this.isVisit = false;\r
-    }\r
-}  \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