]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
MsaOwner usable
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleInfo.java
index 3576578202f68cef37e63865d82a0d107cc37bf7..aa19522e02d1dd2af8e75ef9187c9a8485678495 100644 (file)
@@ -14,283 +14,106 @@ package org.tianocore.migration;
 \r
 import java.io.*;\r
 import java.util.*;\r
-import java.util.regex.*;\r
+\r
+import org.tianocore.UsageTypes;\r
 \r
 /*\r
-       Class ModuleInfo is built for scanning the source files, it contains all the needed\r
+    Class ModuleInfo is built for scanning the source files, it contains all the needed\r
 information and all the temporary data.\r
 */\r
-public class ModuleInfo {\r
-       ModuleInfo(String modulepath, UI ui, Database db) throws Exception {\r
-               this.modulepath = modulepath;\r
-               this.ui = ui;\r
-               this.db = db;\r
-               moduleScan();\r
-       }\r
-       \r
-       private String modulepath = null;\r
-       private Database db = null;\r
-       private UI ui = null;\r
-       \r
-       public String modulename = null;\r
-       public String guidvalue = null;\r
-       public String moduletype = null;\r
-       public String entrypoint = null;\r
-       \r
-       public Set<String> localmodulesources = new HashSet<String>();          //contains both .c and .h\r
-       public Set<String> localmoduleheaders = new HashSet<String>();\r
-       public Set<String> preprocessedccodes = new HashSet<String>();\r
-       \r
-       public Set<String> hashfuncc = new HashSet<String>();\r
-       public Set<String> hashfuncd = new HashSet<String>();\r
-       public Set<String> hashnonlocalfunc = new HashSet<String>();\r
-       public Set<String> hashnonlocalmacro = new HashSet<String>();\r
-       public Set<String> hashEFIcall = new HashSet<String>();\r
-       public Set<String> hashr8only = new HashSet<String>();\r
-       \r
-       public Set<String> hashrequiredr9libs = new HashSet<String>();  // hashrequiredr9libs is now all added in SourceFileReplacer \r
-       public Set<String> guid = new HashSet<String>();\r
-       public Set<String> protocol = new HashSet<String>();\r
-       public Set<String> ppi = new HashSet<String>();\r
-       \r
-       private static String migrationcomment = "//%$//";\r
-       \r
-       private void moduleScan() throws Exception {\r
-               String[] list = new File(modulepath).list();\r
-               boolean hasInf = false;\r
-               String infname = null;\r
-               boolean hasMsa = false;\r
-               String msaname = null;\r
-               \r
-               for (int i = 0 ; i < list.length ; i++) {\r
-                       if (new File(list[i]).isDirectory()) {\r
-                               ;\r
-                       } else {\r
-                               if (list[i].contains(".c") || list[i].contains(".C")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".h") || list[i].contains(".H")) {\r
-                                       localmodulesources.add(list[i]);\r
-                                       localmoduleheaders.add(list[i]);        //the case that several .inf or .msa found is not concerned\r
-                               } else if (list[i].contains(".dxs")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".uni")) {\r
-                                       localmodulesources.add(list[i]);\r
-                               } else if (list[i].contains(".inf")) {\r
-                                       if (ui.yesOrNo("Found .inf file : " + list[i] + "\nUse this file as this module's .inf ?")) {\r
-                                               hasInf = true;\r
-                                               infname = list[i];\r
-                                       } else {\r
-                                               continue;\r
-                                       }\r
-                               } else if (list[i].contains(".msa")) {\r
-                                       if (ui.yesOrNo("Found .msa file : " + list[i] + "\nUse this file as this module's .msa ?")) {\r
-                                               hasMsa = true;\r
-                                               msaname = list[i];\r
-                                       } else {\r
-                                               continue;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               ModuleReader mr = new ModuleReader(modulepath, this, db);\r
-               if (hasInf) {                                                   // this sequence shows using .inf as default\r
-                       mr.readInf(infname);\r
-               } else if (hasMsa) {\r
-                       mr.readMsa(msaname);\r
-               } else {\r
-                       ui.println("No Inf Nor Msa Found");\r
-               }\r
-               \r
-               CommentOutNonLocalHFile();\r
-               parsePreProcessedSourceCode();\r
-               \r
-               new SourceFileReplacer(modulepath, this, db, ui).flush();       // some adding library actions are taken here,so it must be put before "MsaWriter"\r
-               \r
-               // show result\r
-               if (ui.yesOrNo("Parse Module Information Complete . See details ?")) {\r
-                       ui.println("\nModule Information : ");\r
-                       ui.println("Entrypoint : " + entrypoint);\r
-                       show(protocol, "Protocol : ");\r
-                       show(ppi, "Ppi : ");\r
-                       show(guid, "Guid : ");\r
-                       show(hashfuncc, "call : ");\r
-                       show(hashfuncd, "def : ");\r
-                       show(hashEFIcall, "EFIcall : ");\r
-                       show(hashnonlocalmacro, "macro : ");\r
-                       show(hashnonlocalfunc, "nonlocal : ");\r
-                       show(hashr8only, "hashr8only : ");\r
-               }\r
-               \r
-               new MsaWriter(modulepath, this, db).flush();\r
-               \r
-               // remove temp directory\r
-               //File tempdir = new File(modulepath + File.separator + "temp");\r
-               //System.out.println("Deleting Dir");\r
-               //if (tempdir.exists()) tempdir.d;\r
-               \r
-               ui.println("Errors Left : " + db.error);\r
-               ui.println("Complete!");\r
-               ui.println("Your R9 module is placed at " + modulepath + File.separator + "result");\r
-               ui.println("Your logfile is placed at " + modulepath);\r
-       }\r
-       \r
-       private void show(Set<String> hash, String show) {\r
-               ui.println(show + hash.size());\r
-               ui.println(hash);\r
-       }\r
-\r
-       // add '//' to all non-local include lines\r
-       private void CommentOutNonLocalHFile() throws IOException {\r
-               BufferedReader rd;\r
-               String line;\r
-               String curFile;\r
-               PrintWriter outfile;\r
-\r
-               Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");\r
-               Matcher mtcinclude;\r
-               \r
-               File tempdir = new File(modulepath + File.separator + "temp" + File.separator);\r
-               if (!tempdir.exists()) tempdir.mkdir();\r
-               \r
-               Iterator<String> ii = localmodulesources.iterator();\r
-               while ( ii.hasNext() ) {\r
-                       curFile = ii.next();\r
-                       rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile));\r
-                       outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile)));\r
-                       while ((line = rd.readLine()) != null) {\r
-                               if (line.contains("#include")) {\r
-                                       mtcinclude = ptninclude.matcher(line);\r
-                                       if (mtcinclude.find() && localmoduleheaders.contains(mtcinclude.group(1))) {\r
-                                       } else {\r
-                                               line = migrationcomment + line;\r
-                                       }\r
-                               }\r
-                               outfile.append(line + '\n');\r
-                       }\r
-                       outfile.flush();\r
-                       outfile.close();\r
-               }\r
-       }\r
-       /*\r
-       private void search(String line, Pattern ptn, Method md) {\r
-               matmacro = Func.ptntmacro.matcher(line);\r
-               while (matmacro.find()) {\r
-                       if ((temp = Func.registerMacro(matmacro, this, db)) != null) {\r
-                       }\r
-               }\r
-       }\r
-       */\r
-       private void parsePreProcessedSourceCode() throws Exception {\r
-               //Cl cl = new Cl(modulepath);\r
-               //cl.execute("Fat.c");\r
-               //cl.generateAll(preprocessedccodes);\r
-               //\r
-               //System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");\r
-               //System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");\r
-               //String[] list = new File(modulepath + File.separator + "temp").list();        // without CL , add\r
-               String[] list = new File(modulepath).list();\r
-               for (int i = 0 ; i < list.length ; i++) {\r
-                       if (list[i].contains(".c")) {                                                                                   // without CL , change to .i\r
-                               preprocessedccodes.add(list[i]);\r
-                       }\r
-               }\r
-               //\r
-               Iterator<String> ii = preprocessedccodes.iterator();\r
-               BufferedReader rd = null;\r
-               String ifile = null;\r
-               String line = null;\r
-               String temp = null;\r
-               //StringBuffer result = new StringBuffer();\r
-               \r
-               Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
-               Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);\r
-               Matcher matguid;\r
-               Matcher matfuncc;\r
-               Matcher matfuncd;\r
-               Matcher matenclosereplace;\r
-               Matcher matefifuncc;\r
-               Matcher matentrypoint;\r
-               Matcher matmacro;\r
-               \r
-               while (ii.hasNext()) {\r
-                       StringBuffer wholefile = new StringBuffer();\r
-                       ifile = ii.next();\r
-                       rd = new BufferedReader(new FileReader(modulepath + File.separator + "temp" + File.separator + ifile));\r
-                       while ((line = rd.readLine()) != null) {\r
-                               wholefile.append(line + '\n');\r
-                       }\r
-                       line = wholefile.toString();\r
-                       \r
-                       // if this is a Pei phase module , add these library class to .msa\r
-                       matentrypoint = patentrypoint.matcher(line);\r
-                       if (matentrypoint.find()) {\r
-                               entrypoint = matentrypoint.group(2);\r
-                               if (matentrypoint.group(1).matches("PEIM")) {\r
-                                       hashrequiredr9libs.add("PeimEntryPoint");\r
-                               } else {\r
-                                       hashrequiredr9libs.add("UefiDriverEntryPoint");\r
-                               }\r
-                       }\r
-                       \r
-                       // find guid\r
-                       matguid = Guid.ptnguid.matcher(line);                                                                           // several ways to implement this , which one is faster ? :\r
-                       while (matguid.find()) {                                                                                                        // 1.currently , find once , then call to identify which is it\r
-                               if ((temp = Guid.register(matguid, this, db)) != null) {                        // 2.use 3 different matchers , search 3 times to find each\r
-                                       //matguid.appendReplacement(result, db.getR9Guidname(temp));            // search the database for all 3 kinds of guids , high cost\r
-                               }\r
-                       }\r
-                       //matguid.appendTail(result);\r
-                       //line = result.toString();\r
+public final class ModuleInfo {\r
+    ModuleInfo(String modulepath) throws Exception {\r
+        this.modulepath = modulepath;\r
+        this.temppath = MigrationTool.getTempDir(this.modulepath);\r
+    }\r
 \r
-                       // find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed\r
-                       // This item is not simply replaced , special operation is required.\r
-                       matefifuncc = patefifuncc.matcher(line);\r
-                       while (matefifuncc.find()) {\r
-                               hashEFIcall.add(matefifuncc.group(2));\r
-                       }\r
+    public final String modulepath;\r
+    public final String temppath;\r
+    \r
+    private MsaOwner msaowner = MsaOwner.initNewMsaOwner();\r
+    \r
+    public String modulename = null;\r
+    public String guidvalue = null;\r
+    public String moduletype = null;\r
+    public String entrypoint = null;\r
+    \r
+    public final Set<String> localmodulesources = new HashSet<String>();        //contains both .c and .h\r
+    public final Set<String> preprocessedccodes = new HashSet<String>();\r
+    public final Set<String> msaorinf = new HashSet<String>();                //only a little, hash may be too big for this\r
+    public final Set<String> infincludes = new HashSet<String>();\r
+    public final Set<String> infsources = new HashSet<String>();\r
+    \r
+    public final Set<String> hashfuncc = new HashSet<String>();\r
+    public final Set<String> hashfuncd = new HashSet<String>();\r
+    public final Set<String> hashnonlocalfunc = new HashSet<String>();\r
+    public final Set<String> hashnonlocalmacro = new HashSet<String>();\r
+    public final Set<String> hashEFIcall = new HashSet<String>();\r
+    public final Set<String> hashr8only = new HashSet<String>();\r
+    public final Set<String> hashmacro = new HashSet<String>();\r
+    \r
+    public final Set<String> hashrequiredr9libs = new HashSet<String>();    // hashrequiredr9libs is now all added in SourceFileReplacer \r
+    public final Set<String> guids = new HashSet<String>();\r
+    public final Set<String> protocols = new HashSet<String>();\r
+    public final Set<String> ppis = new HashSet<String>();\r
 \r
-                       // find function call\r
-                       matfuncc = Func.ptnfuncc.matcher(line);\r
-                       while (matfuncc.find()) {\r
-                               if ((temp = Func.register(matfuncc, this, db)) != null) {\r
-                                       //ui.println(ifile + "  dofunc  " + temp);\r
-                                       //matfuncc.appendReplacement(result, db.getR9Func(temp));\r
-                               }\r
-                       }\r
-                       //matfuncc.appendTail(result);\r
-                       //line = result.toString();\r
+    //-----------------------------------------------------------------------------------//\r
 \r
-                       // find macro\r
-                       matmacro = Macro.ptntmacro.matcher(line);\r
-                       while (matmacro.find()) {\r
-                               if ((temp = Macro.register(matmacro, this, db)) != null) {\r
-                               }\r
-                       }\r
-                       \r
-                       // find function definition\r
-                       // replace all {} to @\r
-                       while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {\r
-                               line = matenclosereplace.replaceAll("@");\r
-                       }\r
+    public final boolean addProtocol (String proname, UsageTypes.Enum usage) {\r
+        //protocols.add(proname);\r
+        return msaowner.addProtocol(proname, usage);\r
+    }\r
+    \r
+    public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {\r
+        //ppis.add(ppiname);\r
+        return msaowner.addPpi(ppiname, usage);\r
+    }\r
+    \r
+    public final boolean addGuid (String guidname, UsageTypes.Enum usage) {\r
+        //guids.add(guidname);\r
+        return msaowner.addGuid(guidname, usage);\r
+    }\r
+    \r
+    public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {\r
+        //hashrequiredr9libs.add(name);\r
+        return msaowner.addLibraryClass(name, usage);\r
+    }\r
+    \r
+    //-----------------------------------------------------------------------------------//\r
+    \r
+    public final String getModuleType() {\r
+        if (moduletype.contains("PEI")) {\r
+            return "PEIM";\r
+        } else {\r
+            return "DXE_DRIVER";\r
+        }\r
+    }\r
+    \r
+    public final void enroll(String filepath) throws Exception {\r
+        String temp = null;\r
+        if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
+                filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {\r
+            localmodulesources.add(filepath.replace(modulepath + File.separator, ""));\r
+        } else if (filepath.contains(".inf") || filepath.contains(".msa")) {\r
+            temp = filepath.replace(modulepath + File.separator, "");\r
+            if (!temp.contains(File.separator)) {                            // .inf in subdirectory is not regarded\r
+                msaorinf.add(temp);\r
+            }\r
+        }\r
+    }\r
 \r
-                       matfuncd = Func.ptnfuncd.matcher(line);\r
-                       while (matfuncd.find()) {\r
-                               if ((temp = Func.register(matfuncd, this, db)) != null) {\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               // op on hash\r
-               Iterator<String> funcci = hashfuncc.iterator();\r
-               while (funcci.hasNext()) {\r
-                       if (!hashfuncd.contains(temp = funcci.next()) && !hashEFIcall.contains(temp)) {\r
-                               hashnonlocalfunc.add(temp);                                     // this set contains both changed and not changed items\r
-                       }\r
-               }\r
-       }\r
-       \r
-       public static void main(String[] args) throws Exception {\r
-               FirstPanel.init();\r
-       }\r
+    public static final boolean isModule(String path) {\r
+        String[] list = new File(path).list();\r
+        for (int i = 0 ; i < list.length ; i++) {\r
+            if (!new File(list[i]).isDirectory()) {\r
+                if (list[i].contains(".inf") || list[i].contains(".msa")) {\r
+                    return true;\r
+                }\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+    \r
+    public final MsaOwner getMsaOwner() {\r
+        return msaowner;\r
+    }\r
 }
\ No newline at end of file