]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
Coding Style
[mirror_edk2.git] / Tools / Java / Source / MigrationTools / org / tianocore / migration / ModuleReader.java
index d6a7ed639e0f2eabd00c34e1fe05fa19cffe9c67..d65d72fa443a963485e67cc4d186b07982683d77 100644 (file)
  **/\r
 package org.tianocore.migration;\r
 \r
-import java.io.*;\r
-import java.util.*;\r
-import java.util.regex.*;\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.StringReader;\r
+import java.util.Iterator;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
 \r
-import org.tianocore.*;\r
+import org.tianocore.FilenameDocument;\r
+import org.tianocore.ModuleSurfaceAreaDocument;\r
+import org.tianocore.MsaHeaderDocument;\r
+import org.tianocore.SourceFilesDocument;\r
 \r
 public final class ModuleReader implements Common.ForDoAll {\r
-    private static final ModuleReader modulereader = new ModuleReader();\r
-    private ModuleInfo mi;\r
-    private final CommentLaplace commentlaplace = new CommentLaplace();\r
-    \r
-    private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
-    private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
-    private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
-\r
-    public final void ModuleScan() throws Exception {\r
-        Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);\r
-\r
-        // inf&msa\r
-        String filename = null;\r
-        if (mi.msaorinf.isEmpty()) {\r
-            MigrationTool.ui.println("No INF nor MSA file found!");\r
-            System.exit(0);\r
-        } else {\r
-            if (mi.msaorinf.size() == 1) {\r
-                filename = (String)mi.msaorinf.toArray()[0];\r
-            } else {\r
-                filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());\r
-            }\r
-        }\r
-\r
-        if (filename.contains(".inf")) {\r
-            readInf(filename);\r
-        } else if (filename.contains(".msa")) {\r
-            readMsa(filename);\r
-        }\r
-        // inf&msa\r
-\r
-        preProcessModule();\r
-    }\r
-    \r
-    private final void readMsa(String name) throws Exception {\r
-        ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));\r
-        ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
-        MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
-\r
-        mi.modulename = msaheader.getModuleName();\r
-        mi.guidvalue = msaheader.getGuidValue();\r
-        mi.moduletype = msaheader.getModuleType().toString();        // ???\r
-\r
-        SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
-        \r
-        String temp;\r
-        Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();\r
-        while (li.hasNext()) {\r
-            if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
-                System.out.println("Source File Missing! : " + temp);\r
-            }\r
-        }\r
-    }\r
-    private final String extractLicense(String wholeline) throws Exception {\r
-        String tempLine;\r
-        String license = null;\r
-\r
-        BufferedReader rd = new BufferedReader(new StringReader(wholeline));\r
-        while ((tempLine = rd.readLine()) != null) {\r
-            if (tempLine.contains("#")) {\r
-                if (tempLine.contains("Copyright")) {\r
-                    //\r
-                    // Find license info.\r
-                    // \r
-                    license = "";\r
-                    while ((tempLine = rd.readLine())!= null) {\r
-                        if (!tempLine.contains("#") ||\r
-                             tempLine.contains("Module Name:") ||\r
-                             tempLine.contains("Abstract:")) {\r
-                            //\r
-                            // We assume license ends here.\r
-                            // \r
-                            break;\r
-                        }\r
-                        license += "      " + tempLine.replaceAll("\\s*[#]\\s*(.*)", "$1\n");\r
-                    }\r
-                    break;\r
-                }\r
-            }\r
-        }\r
-        return license;\r
-    }\r
-\r
-    private final void readInf(String name) throws Exception {\r
-        System.out.println("\nParsing INF file: " + name);\r
-        String wholeline;\r
-        Matcher mtrinfequation;\r
-        Matcher mtrsection;\r
-        Matcher mtrfilename;\r
-\r
-        wholeline = Common.file2string(mi.modulepath + File.separator + name);\r
-        mi.license = extractLicense(wholeline);\r
-        mtrsection = ptnsection.matcher(wholeline);\r
-        while (mtrsection.find()) {\r
-            if (mtrsection.group(1).matches("defines")) {\r
-                mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
-                while (mtrinfequation.find()) {\r
-                    if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
-                        mi.modulename = mtrinfequation.group(2);\r
-                    }\r
-                    if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
-                        mi.guidvalue = mtrinfequation.group(2);\r
-                    }\r
-                    if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
-                        mi.moduletype = mtrinfequation.group(2);\r
-                    }\r
-                }\r
-            }\r
-            if (mtrsection.group(1).contains("nmake.")) {\r
-                mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
-                while (mtrinfequation.find()) {\r
-                    if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
-                        mi.entrypoint = mtrinfequation.group(2);\r
-                    }\r
-                    if (mtrinfequation.group(1).matches("DPX_SOURCE")) {\r
-                        if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {\r
-                            MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-            if (mtrsection.group(1).contains("sources.")) {\r
-                mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
-                while (mtrfilename.find()) {\r
-                    mi.infsources.add(mtrfilename.group());\r
-                    if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
-                        MigrationTool.ui.println("Warn: Source File Missing! : " + mtrfilename.group());\r
-                    }\r
-                }\r
-            }\r
-            if (mtrsection.group(1).matches("includes.")) {\r
-                mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
-                while (mtrfilename.find()) {\r
-                    mi.infincludes.add(mtrfilename.group());\r
-                }\r
-            }\r
-        }\r
-    }\r
-    \r
-    private final void preProcessModule() throws Exception {\r
-        // according to .inf file, add extraordinary includes and sourcefiles\r
-        Common.dirCopy(mi.modulepath, mi.temppath);    // collect all Laplace.namechange to here???\r
-        \r
-        if (!mi.infincludes.isEmpty()) {\r
-            Iterator<String> it = mi.infincludes.iterator();\r
-            String tempincludename = null;\r
-            while (it.hasNext()) {\r
-                tempincludename = it.next();\r
-                if (tempincludename.contains("..")) {\r
-                    Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);\r
-                    if (mtr.find() && !mtr.group(2).matches(".")) {\r
-                        Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath, ".h");\r
-                    } else {\r
-                        Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.temppath, ".h");\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        if (!mi.infsources.isEmpty()) {\r
-            Iterator<String> it = mi.infsources.iterator();\r
-            String tempsourcename = null;\r
-            while (it.hasNext()) {\r
-                tempsourcename = it.next();\r
-                if (tempsourcename.contains("..")) {\r
-                    Common.ensureDir(mi.temppath + File.separator + "MT_Parent_Sources");\r
-                    Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);\r
-                    if (mtr.find()) {\r
-                        Common.fileCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath + File.separator + "MT_Parent_Sources" + File.separator + mtr.group(2));\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-        Common.toDoAll(mi.temppath, this, Common.FILE);\r
-        \r
-        parsePreProcessedSourceCode();\r
-\r
-    }\r
-\r
-    private final void parsePreProcessedSourceCode() throws Exception {\r
-        BufferedReader rd = null;\r
-        String ifile = null;\r
-        String line = null;\r
-        String temp = null;\r
-        \r
-        Iterator<String> ii = mi.localmodulesources.iterator();\r
-        while (ii.hasNext()) {\r
-            temp = ii.next();\r
-            if (temp.contains(".c") || temp.contains(".dxs")) {\r
-                mi.preprocessedccodes.add(temp);\r
-            }\r
-        }\r
-        \r
-        ii = mi.preprocessedccodes.iterator();\r
-        \r
-        Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
-        Matcher matguid;\r
-        Matcher matfuncc;\r
-        Matcher matfuncd;\r
-        Matcher matenclosereplace;\r
-        Matcher matefifuncc;\r
-        Matcher matmacro;\r
-        \r
-        while (ii.hasNext()) {\r
-            StringBuffer wholefile = new StringBuffer();\r
-            ifile = ii.next();\r
-            rd = new BufferedReader(new FileReader(mi.temppath + File.separator + ifile));\r
-            while ((line = rd.readLine()) != null) {\r
-                wholefile.append(line + '\n');\r
-            }\r
-            line = wholefile.toString();\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, mi, MigrationTool.db)) != null) {                // 2.use 3 different matchers , search 3 times to find each\r
-                    //matguid.appendReplacement(result, MigrationTool.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
-\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
-                mi.hashEFIcall.add(matefifuncc.group(2));\r
-            }\r
-\r
-            // find function call\r
-            matfuncc = Func.ptnfuncc.matcher(line);\r
-            while (matfuncc.find()) {\r
-                if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {\r
-                    //MigrationTool.ui.println(ifile + "  dofunc  " + temp);\r
-                    //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));\r
-                }\r
-            }\r
-            //matfuncc.appendTail(result);\r
-            //line = result.toString();\r
-\r
-            // find macro\r
-            matmacro = Macro.ptntmacro.matcher(line);\r
-            while (matmacro.find()) {\r
-                if ((temp = Macro.register(matmacro, mi, MigrationTool.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
-\r
-            matfuncd = Func.ptnfuncd.matcher(line);\r
-            while (matfuncd.find()) {\r
-                if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {\r
-                }\r
-            }\r
-        }\r
-        \r
-        // op on hash\r
-        Iterator<String> funcci = mi.hashfuncc.iterator();\r
-        while (funcci.hasNext()) {\r
-            if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {\r
-                mi.hashnonlocalfunc.add(temp);                    // this set contains both changed and not changed items\r
-            }\r
-        }\r
-    }\r
-    \r
-    public class CommentLaplace extends Common.Laplace {\r
-        public String operation(String wholeline) {\r
-            StringBuffer wholebuffer = new StringBuffer();\r
-            String templine = null;\r
-            Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");\r
-            Pattern ptninclude = Pattern.compile("#include\\s*(.*)");\r
-            Matcher mtrinclude = ptninclude.matcher(wholeline);\r
-            Matcher mtrincludefile = null;\r
-            while (mtrinclude.find()) {\r
-                mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));\r
-                if (mtrincludefile.find() && mi.localmodulesources.contains(mtrincludefile.group(1))) {\r
-                    templine = mtrinclude.group();\r
-                } else {\r
-                    templine = MigrationTool.MIGRATIONCOMMENT + mtrinclude.group();\r
-                }\r
-                mtrinclude.appendReplacement(wholebuffer, templine);\r
-            }\r
-            mtrinclude.appendTail(wholebuffer);\r
-            return wholebuffer.toString();\r
-        }\r
-        \r
-        public boolean recognize(String filename) {\r
-            return filename.contains(".c") || filename.contains(".h") || filename.contains(".dxs");\r
-        }\r
-        \r
-        public String namechange(String oldname) {\r
-            return oldname;\r
-        }\r
-    }\r
-\r
-    //-----------------------------------ForDoAll-----------------------------------//\r
-    public void run(String filepath) throws Exception {\r
-        String name = mi.temppath + File.separator + filepath.replace(mi.temppath + File.separator, "");\r
-        if (commentlaplace.recognize(name)) {\r
-            commentlaplace.transform(name, name);\r
-        }\r
-    }\r
-\r
-    public boolean filter(File dir) {\r
-        return true;\r
-    }\r
-    //-----------------------------------ForDoAll-----------------------------------//\r
-    \r
-    public final void setModuleInfo(ModuleInfo m) {\r
-        mi = m;\r
-    }\r
-    \r
-    public static final void aimAt(ModuleInfo mi) throws Exception {\r
-        modulereader.setModuleInfo(mi);\r
-        modulereader.ModuleScan();\r
-    }\r
+       private static final ModuleReader modulereader = new ModuleReader();\r
+\r
+       private ModuleInfo mi;\r
+\r
+       private final CommentLaplace commentlaplace = new CommentLaplace();\r
+\r
+       private static final Pattern ptninfequation = Pattern\r
+                       .compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
+\r
+       private static final Pattern ptnsection = Pattern.compile(\r
+                       "\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
+\r
+       private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
+\r
+       public final void ModuleScan() throws Exception {\r
+               Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll",\r
+                               String.class), mi, null, Common.FILE);\r
+\r
+               // inf&msa\r
+               String filename = null;\r
+               if (mi.msaorinf.isEmpty()) {\r
+                       MigrationTool.ui.println("No INF nor MSA file found!");\r
+                       System.exit(0);\r
+               } else {\r
+                       if (mi.msaorinf.size() == 1) {\r
+                               filename = (String) mi.msaorinf.toArray()[0];\r
+                       } else {\r
+                               filename = MigrationTool.ui.choose(\r
+                                               "Found .inf or .msa file for module\n" + mi.modulepath\r
+                                                               + "\nChoose one Please", mi.msaorinf.toArray());\r
+                       }\r
+               }\r
+\r
+               if (filename.contains(".inf")) {\r
+                       readInf(filename);\r
+               } else if (filename.contains(".msa")) {\r
+                       readMsa(filename);\r
+               }\r
+               // inf&msa\r
+\r
+               preProcessModule();\r
+       }\r
+\r
+       private final void readMsa(String name) throws Exception {\r
+               ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory\r
+                               .parse(new File(mi.modulepath + File.separator + name));\r
+               ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc\r
+                               .getModuleSurfaceArea();\r
+               MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
+\r
+               mi.modulename = msaheader.getModuleName();\r
+               mi.guidvalue = msaheader.getGuidValue();\r
+               mi.moduletype = msaheader.getModuleType().toString(); // ???\r
+\r
+               SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
+\r
+               String temp;\r
+               Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList()\r
+                               .iterator();\r
+               while (li.hasNext()) {\r
+                       if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
+                               System.out.println("Source File Missing! : " + temp);\r
+                       }\r
+               }\r
+       }\r
+\r
+       private final String extractLicense(String wholeline) throws Exception {\r
+               String tempLine;\r
+               String license = null;\r
+\r
+               BufferedReader rd = new BufferedReader(new StringReader(wholeline));\r
+               while ((tempLine = rd.readLine()) != null) {\r
+                       if (tempLine.contains("#")) {\r
+                               if (tempLine.contains("Copyright")) {\r
+                                       //\r
+                                       // Find license info.\r
+                                       // \r
+                                       license = "";\r
+                                       while ((tempLine = rd.readLine()) != null) {\r
+                                               if (!tempLine.contains("#")\r
+                                                               || tempLine.contains("Module Name:")\r
+                                                               || tempLine.contains("Abstract:")) {\r
+                                                       //\r
+                                                       // We assume license ends here.\r
+                                                       // \r
+                                                       break;\r
+                                               }\r
+                                               license += "      "\r
+                                                               + tempLine\r
+                                                                               .replaceAll("\\s*[#]\\s*(.*)", "$1\n");\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               return license;\r
+       }\r
+\r
+       private final void readInf(String name) throws Exception {\r
+               System.out.println("\nParsing INF file: " + name);\r
+               String wholeline;\r
+               Matcher mtrinfequation;\r
+               Matcher mtrsection;\r
+               Matcher mtrfilename;\r
+\r
+               wholeline = Common.file2string(mi.modulepath + File.separator + name);\r
+               mi.license = extractLicense(wholeline);\r
+               mtrsection = ptnsection.matcher(wholeline);\r
+               while (mtrsection.find()) {\r
+                       if (mtrsection.group(1).matches("defines")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
+                                               mi.modulename = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
+                                               mi.guidvalue = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
+                                               mi.moduletype = mtrinfequation.group(2);\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).contains("nmake.")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
+                                               mi.entrypoint = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("DPX_SOURCE")) {\r
+                                               if (!mi.localmodulesources.contains(mtrinfequation\r
+                                                               .group(2))) {\r
+                                                       MigrationTool.ui.println("DPX File Missing! : "\r
+                                                                       + mtrinfequation.group(2));\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).contains("sources.")) {\r
+                               mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
+                               while (mtrfilename.find()) {\r
+                                       mi.infsources.add(mtrfilename.group());\r
+                                       if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
+                                               MigrationTool.ui\r
+                                                               .println("Warn: Source File Missing! : "\r
+                                                                               + mtrfilename.group());\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).matches("includes.")) {\r
+                               mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
+                               while (mtrfilename.find()) {\r
+                                       mi.infincludes.add(mtrfilename.group());\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       private final void preProcessModule() throws Exception {\r
+               // according to .inf file, add extraordinary includes and sourcefiles\r
+               Common.dirCopy(mi.modulepath, mi.temppath); // collect all\r
+                                                                                                       // Laplace.namechange to\r
+                                                                                                       // here???\r
+\r
+               if (!mi.infincludes.isEmpty()) {\r
+                       Iterator<String> it = mi.infincludes.iterator();\r
+                       String tempincludename = null;\r
+                       while (it.hasNext()) {\r
+                               tempincludename = it.next();\r
+                               if (tempincludename.contains("..")) {\r
+                                       Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);\r
+                                       if (mtr.find() && !mtr.group(2).matches(".")) {\r
+                                               Common.oneLevelDirCopy(mi.modulepath.replaceAll(\r
+                                                               Common.STRSEPARATER, "$1")\r
+                                                               + File.separator + mtr.group(2), mi.temppath,\r
+                                                               ".h");\r
+                                       } else {\r
+                                               Common.oneLevelDirCopy(mi.modulepath.replaceAll(\r
+                                                               Common.STRSEPARATER, "$1"), mi.temppath, ".h");\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               if (!mi.infsources.isEmpty()) {\r
+                       Iterator<String> it = mi.infsources.iterator();\r
+                       String tempsourcename = null;\r
+                       while (it.hasNext()) {\r
+                               tempsourcename = it.next();\r
+                               if (tempsourcename.contains("..")) {\r
+                                       Common.ensureDir(mi.temppath + File.separator\r
+                                                       + "MT_Parent_Sources");\r
+                                       Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);\r
+                                       if (mtr.find()) {\r
+                                               Common.fileCopy(mi.modulepath.replaceAll(\r
+                                                               Common.STRSEPARATER, "$1")\r
+                                                               + File.separator + mtr.group(2), mi.temppath\r
+                                                               + File.separator + "MT_Parent_Sources"\r
+                                                               + File.separator + mtr.group(2));\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+               Common.toDoAll(mi.temppath, this, Common.FILE);\r
+\r
+               parsePreProcessedSourceCode();\r
+\r
+       }\r
+\r
+       private final void parsePreProcessedSourceCode() throws Exception {\r
+               BufferedReader rd = null;\r
+               String ifile = null;\r
+               String line = null;\r
+               String temp = null;\r
+\r
+               Iterator<String> ii = mi.localmodulesources.iterator();\r
+               while (ii.hasNext()) {\r
+                       temp = ii.next();\r
+                       if (temp.contains(".c") || temp.contains(".dxs")) {\r
+                               mi.preprocessedccodes.add(temp);\r
+                       }\r
+               }\r
+\r
+               ii = mi.preprocessedccodes.iterator();\r
+\r
+               Pattern patefifuncc = Pattern.compile(\r
+                               "g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)", Pattern.MULTILINE);\r
+               Matcher matguid;\r
+               Matcher matfuncc;\r
+               Matcher matfuncd;\r
+               Matcher matenclosereplace;\r
+               Matcher matefifuncc;\r
+               Matcher matmacro;\r
+\r
+               while (ii.hasNext()) {\r
+                       StringBuffer wholefile = new StringBuffer();\r
+                       ifile = ii.next();\r
+                       rd = new BufferedReader(new FileReader(mi.temppath + File.separator\r
+                                       + ifile));\r
+                       while ((line = rd.readLine()) != null) {\r
+                               wholefile.append(line + '\n');\r
+                       }\r
+                       line = wholefile.toString();\r
+\r
+                       // find guid\r
+                       matguid = Guid.ptnguid.matcher(line); // several ways to implement\r
+                                                                                                       // this , which one is\r
+                                                                                                       // faster ? :\r
+                       while (matguid.find()) { // 1.currently , find once , then call\r
+                                                                               // to identify which is it\r
+                               if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use\r
+                                                                                                                                                                               // 3\r
+                                                                                                                                                                               // different\r
+                                                                                                                                                                               // matchers\r
+                                                                                                                                                                               // ,\r
+                                                                                                                                                                               // search\r
+                                                                                                                                                                               // 3\r
+                                                                                                                                                                               // times\r
+                                                                                                                                                                               // to\r
+                                                                                                                                                                               // find\r
+                                                                                                                                                                               // each\r
+                                       // matguid.appendReplacement(result,\r
+                                       // MigrationTool.db.getR9Guidname(temp)); // search the\r
+                                       // database for all 3 kinds of guids , high cost\r
+                               }\r
+                       }\r
+                       // matguid.appendTail(result);\r
+                       // line = result.toString();\r
+\r
+                       // find EFI call in form of '->' , many\r
+                       // '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
+                               mi.hashEFIcall.add(matefifuncc.group(2));\r
+                       }\r
+\r
+                       // find function call\r
+                       matfuncc = Func.ptnfuncc.matcher(line);\r
+                       while (matfuncc.find()) {\r
+                               if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {\r
+                                       // MigrationTool.ui.println(ifile + " dofunc " + temp);\r
+                                       // matfuncc.appendReplacement(result,\r
+                                       // MigrationTool.db.getR9Func(temp));\r
+                               }\r
+                       }\r
+                       // matfuncc.appendTail(result);\r
+                       // line = result.toString();\r
+\r
+                       // find macro\r
+                       matmacro = Macro.ptntmacro.matcher(line);\r
+                       while (matmacro.find()) {\r
+                               if ((temp = Macro.register(matmacro, mi, MigrationTool.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
+\r
+                       matfuncd = Func.ptnfuncd.matcher(line);\r
+                       while (matfuncd.find()) {\r
+                               if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // op on hash\r
+               Iterator<String> funcci = mi.hashfuncc.iterator();\r
+               while (funcci.hasNext()) {\r
+                       if (!mi.hashfuncd.contains(temp = funcci.next())\r
+                                       && !mi.hashEFIcall.contains(temp)) {\r
+                               mi.hashnonlocalfunc.add(temp); // this set contains both\r
+                                                                                               // changed and not changed items\r
+                       }\r
+               }\r
+       }\r
+\r
+       public class CommentLaplace extends Common.Laplace {\r
+               public String operation(String wholeline) {\r
+                       StringBuffer wholebuffer = new StringBuffer();\r
+                       String templine = null;\r
+                       Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");\r
+                       Pattern ptninclude = Pattern.compile("#include\\s*(.*)");\r
+                       Matcher mtrinclude = ptninclude.matcher(wholeline);\r
+                       Matcher mtrincludefile = null;\r
+                       while (mtrinclude.find()) {\r
+                               mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));\r
+                               if (mtrincludefile.find()\r
+                                               && mi.localmodulesources.contains(mtrincludefile\r
+                                                               .group(1))) {\r
+                                       templine = mtrinclude.group();\r
+                               } else {\r
+                                       templine = MigrationTool.MIGRATIONCOMMENT\r
+                                                       + mtrinclude.group();\r
+                               }\r
+                               mtrinclude.appendReplacement(wholebuffer, templine);\r
+                       }\r
+                       mtrinclude.appendTail(wholebuffer);\r
+                       return wholebuffer.toString();\r
+               }\r
+\r
+               public boolean recognize(String filename) {\r
+                       return filename.contains(".c") || filename.contains(".h")\r
+                                       || filename.contains(".dxs");\r
+               }\r
+\r
+               public String namechange(String oldname) {\r
+                       return oldname;\r
+               }\r
+       }\r
+\r
+       // -----------------------------------ForDoAll-----------------------------------//\r
+       public void run(String filepath) throws Exception {\r
+               String name = mi.temppath + File.separator\r
+                               + filepath.replace(mi.temppath + File.separator, "");\r
+               if (commentlaplace.recognize(name)) {\r
+                       commentlaplace.transform(name, name);\r
+               }\r
+       }\r
+\r
+       public boolean filter(File dir) {\r
+               return true;\r
+       }\r
+\r
+       // -----------------------------------ForDoAll-----------------------------------//\r
+\r
+       public final void setModuleInfo(ModuleInfo m) {\r
+               mi = m;\r
+       }\r
+\r
+       public static final void aimAt(ModuleInfo mi) throws Exception {\r
+               modulereader.setModuleInfo(mi);\r
+               modulereader.ModuleScan();\r
+       }\r
 }\r