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
\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
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
}\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
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
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
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
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
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
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
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
}\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
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
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
}\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
}\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
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
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
}\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