r8lib in database
authoralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 22 Aug 2006 07:39:14 +0000 (07:39 +0000)
committeralfred <alfred@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 22 Aug 2006 07:39:14 +0000 (07:39 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1349 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/MigrationTools/org/tianocore/migration/Critic.java
Tools/Source/MigrationTools/org/tianocore/migration/Database.java
Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
Tools/Source/MigrationTools/org/tianocore/migration/MsaWriter.java
Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java

index 5747a4250b8befc95a1d9212536efa21c670af3f..28bfd0884f2871f09fd8b030ba8d5676738373fb 100644 (file)
@@ -15,13 +15,13 @@ package org.tianocore.migration;
 import java.util.regex.*;\r
 import java.io.*;\r
 \r
-public class Critic {\r
-       private static Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
-       private static Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);         // find function with {;">/ , may be unsafe\r
+public final class Critic {\r
+       private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);\r
+       private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/(\\s*.*?)([\\{;])",Pattern.DOTALL);           // find function with {;">/ , may be unsafe\r
        //private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);\r
-       private static Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
+       private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");\r
        private static Matcher mtrcommentequation;\r
-       private static Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
+       private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");\r
        private static Matcher mtrnewcomment;\r
        \r
        private static final int totallinelength = 82;\r
index a4b0d47872f374c599e8dc69b8eb2b5e6d167fab..8b088c9cbb2135cad003c583c4d2b2f4d29e33cd 100644 (file)
@@ -14,6 +14,7 @@ package org.tianocore.migration;
 \r
 import java.io.*;\r
 import java.util.*;\r
+import java.util.regex.*;\r
 \r
 public final class Database {\r
        Database(String path) throws Exception {\r
@@ -24,17 +25,19 @@ public final class Database {
                importDBGuid("Ppi.csv", "Ppi");\r
                importDBGuid("Protocol.csv", "Protocol");\r
                importDBMacro("Macro.csv");\r
+               importListR8Only();\r
        }\r
        \r
-       public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
-       \r
        public String DatabasePath;\r
        public Set<String> error = new HashSet<String>();\r
+       public Set<String> r8only = new HashSet<String>();\r
        \r
        private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
        private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
        private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
        \r
+       //-------------------------------------import------------------------------------------//\r
+       \r
        private void importDBLib(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
                String line;\r
@@ -88,7 +91,21 @@ public final class Database {
                        }\r
                }\r
        }\r
+\r
+       private void importListR8Only() throws Exception {\r
+               Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);\r
+               String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");\r
+               System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");\r
+               Matcher mtrr8only = ptnr8only.matcher(wholeline);\r
+               while (mtrr8only.find()) {\r
+                       r8only.add(mtrr8only.group(2));\r
+               }\r
+       }\r
        \r
+       //-------------------------------------import------------------------------------------//\r
+\r
+       //-------------------------------------get------------------------------------------//\r
+\r
        public String getR9Lib(String r8funcname) {\r
                String temp = null;\r
                if (hashfunc.containsKey(r8funcname)) {\r
@@ -105,18 +122,6 @@ public final class Database {
                return temp;\r
        }\r
        \r
-       public boolean hasFunc(String r8lib) {\r
-               return hashfunc.containsKey(r8lib);\r
-       }\r
-\r
-       public boolean hasGuid(String r8guid) {\r
-               return hashguid.containsKey(r8guid);\r
-       }\r
-\r
-       public boolean hasMacro(String r8macro) {\r
-               return hashmacro.containsKey(r8macro);\r
-       }\r
-       \r
        public String getR9Macro(String r8macro) {\r
                return hashmacro.get(r8macro).r9name;                   // the verification job of if the macro exists in the database is done when registering it\r
        }\r
@@ -141,6 +146,26 @@ public final class Database {
                return temp;\r
        }\r
 \r
+       //-------------------------------------get------------------------------------------//\r
+\r
+       //-------------------------------------has------------------------------------------//\r
+\r
+       public boolean hasFunc(String r8lib) {\r
+               return hashfunc.containsKey(r8lib);\r
+       }\r
+\r
+       public boolean hasGuid(String r8guid) {\r
+               return hashguid.containsKey(r8guid);\r
+       }\r
+\r
+       public boolean hasMacro(String r8macro) {\r
+               return hashmacro.containsKey(r8macro);\r
+       }\r
+       \r
+       //-------------------------------------has------------------------------------------//\r
+       \r
+       //-------------------------------------init------------------------------------------//\r
+       \r
        public static Database init() throws Exception {\r
                if (System.getenv("WORKSPACE") == null) {\r
                        return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
index 5502cbb00c573b475b251496072e1dbbdf7bbb5b..4d59a9e953bc264d88d813795326398395fd8b60 100644 (file)
@@ -83,7 +83,7 @@ public class ModuleInfo {
                CommentOutNonLocalHFile();\r
                parsePreProcessedSourceCode();\r
 \r
-               new SourceFileReplacer(modulepath, outputpath, this).flush();   // some adding library actions are taken here,so it must be put before "MsaWriter"\r
+               SourceFileReplacer.flush(this); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
                \r
                // show result\r
                if (MigrationTool.ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
@@ -100,7 +100,7 @@ public class ModuleInfo {
                        show(hashr8only, "hashr8only : ");\r
                }\r
                \r
-               new MsaWriter(modulepath, outputpath, this).flush();\r
+               new MsaWriter(this).flush();\r
 \r
                Common.deleteDir(modulepath + File.separator + "temp");\r
                //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);\r
index f79843337c4a32fab4822708a3ec3ac584d962b7..cf4426df827c0f2c4362d75363dc781161c74dc9 100644 (file)
@@ -20,14 +20,10 @@ import org.tianocore.SupportedArchitectures.Enum;
 import org.apache.xmlbeans.*;\r
 \r
 public class MsaWriter {\r
-       MsaWriter(String path, String outpath, ModuleInfo moduleinfo) {\r
-               modulepath = path;\r
-               outputpath = outpath;\r
+       MsaWriter(ModuleInfo moduleinfo) {\r
                mi = moduleinfo;\r
        }\r
 \r
-       private String modulepath;\r
-       private String outputpath;\r
        private ModuleInfo mi;\r
        \r
        private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
@@ -185,7 +181,7 @@ public class MsaWriter {
         options.setSavePrettyPrintIndent(2);\r
         options.setUseDefaultNamespace();\r
         \r
-               BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
+               BufferedWriter bw = new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
                fulfillMsadoc().save(bw, options);\r
                //MsaTreeEditor.init(mi, ui, msadoc);\r
                bw.flush();\r
index bc579ac741945ccc984cec8a78a0a38f177a89f7..868509a88b411da0e972907f46b95d2baeaad0c2 100644 (file)
@@ -18,17 +18,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;\r
 \r
 public final class SourceFileReplacer {\r
-       SourceFileReplacer(String path, String outpath, ModuleInfo moduleinfo) {\r
-               modulepath = path;\r
-               outputpath = outpath;\r
-               mi = moduleinfo;\r
-       }\r
-       private String modulepath;\r
-       private String outputpath;\r
-       private ModuleInfo mi;\r
-       private boolean showdetails = false;\r
+       private static ModuleInfo mi;\r
+       private static boolean showdetails = false;\r
        \r
-       private class r8tor9 {\r
+       private static class r8tor9 {\r
                r8tor9(String r8, String r9) {\r
                        r8thing = r8;\r
                        r9thing = r9;\r
@@ -38,34 +31,17 @@ public final class SourceFileReplacer {
        }\r
        \r
        // these sets are used only for printing log of the changes in current file\r
-       private Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
-       private Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
-       private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
-       private Set<String> filer8only = new HashSet<String>();\r
-       \r
-       private static final String r8only = "EfiLibInstallDriverBinding " +\r
-                       "EfiLibInstallAllDriverProtocols " +\r
-                       "EfiLibCompareLanguage " +\r
-                       "BufToHexString " +\r
-                       "EfiStrTrim " +                                                 //is the r8only lib going to be enlarged????  Caution !!!!\r
-                       "EfiValueToHexStr " +\r
-                       "HexStringToBuf " +\r
-                       "IsHexDigit " +\r
-                       "NibbleToHexChar " +\r
-                       "GetHob " +\r
-                       "GetHobListSize " +\r
-                       "GetHobVersion " +\r
-                       "GetHobBootMode " +\r
-                       "GetCpuHobInfo " +\r
-                       "GetDxeCoreHobInfo " +\r
-                       "GetNextFirmwareVolumeHob " +\r
-                       "GetNextGuidHob " +\r
-                       "GetPalEntryHobInfo " +\r
-                       "GetIoPortSpaceAddressHobInfo ";\r
+       private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
+       private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
+       private static final Set<String> filer8only = new HashSet<String>();\r
        \r
-       public void flush() throws Exception {\r
+       public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
+               \r
+               mi = moduleinfo;\r
+               \r
                String outname = null;\r
                String inname = null;\r
                if (MigrationTool.ui.yesOrNo("Changes will be made to the Source Code.  View details?")) {\r
@@ -82,7 +58,7 @@ public final class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                MigrationTool.ui.println("\nModifying file: " + inname);\r
-                               Common.string2file(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
+                               Common.string2file(sourcefilereplace(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
                                if (inname.contains(".H")) {\r
                                        outname = inname.replaceFirst(".H", ".h");\r
@@ -90,7 +66,7 @@ public final class SourceFileReplacer {
                                        outname = inname;\r
                                }\r
                                MigrationTool.ui.println("\nCopying file: " + inname);\r
-                               Common.string2file(Common.file2string(modulepath + File.separator + "temp" + File.separator + inname), outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
+                               Common.string2file(Common.file2string(mi.modulepath + File.separator + "temp" + File.separator + inname), mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
                        }\r
                }\r
 \r
@@ -99,12 +75,12 @@ public final class SourceFileReplacer {
                }\r
        }\r
        \r
-       private void addr8only() throws Exception {\r
+       private static final void addr8only() throws Exception {\r
                String paragraph = null;\r
-               String line = Common.file2string(Database.defaultpath + File.separator + "R8Lib.c");\r
-               Common.ensureDir(modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
-               PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
-               PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));\r
+               String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
+               Common.ensureDir(mi.modulepath + File.separator + "result" + File.separator + "R8Lib.c");\r
+               PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));\r
+               PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(mi.outputpath + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));\r
                Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
                Matcher mtrr8only = ptnr8only.matcher(line);\r
                Matcher mtrr8onlyhead;\r
@@ -132,7 +108,7 @@ public final class SourceFileReplacer {
        }\r
        \r
        // Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
-       private String sourcefilereplace(String filename) throws Exception {\r
+       private static final String sourcefilereplace(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
                String line;\r
@@ -198,7 +174,7 @@ public final class SourceFileReplacer {
                                                Iterator<r8tor9> rt = filefunc.iterator();\r
                                                while (rt.hasNext()) {\r
                                                        temp = rt.next();\r
-                                                       if (r8only.contains(temp.r8thing)) {\r
+                                                       if (MigrationTool.db.r8only.contains(temp.r8thing)) {\r
                                                                filer8only.add(r8thing);\r
                                                                mi.hashr8only.add(r8thing);\r
                                                                addr8 = true;\r
@@ -297,7 +273,7 @@ public final class SourceFileReplacer {
                return line;\r
        }\r
        \r
-       private void show(Set<r8tor9> hash, String sh) {\r
+       private static final void show(Set<r8tor9> hash, String sh) {\r
                Iterator<r8tor9> it = hash.iterator();\r
                r8tor9 temp;\r
                if (showdetails) {\r
@@ -312,7 +288,7 @@ public final class SourceFileReplacer {
                }\r
        }\r
        \r
-       private void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {\r
+       private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {\r
                Iterator<String> it;\r
                String r8thing;\r
                String r9thing;\r