Coding Style
Phase 1 Eclipse Format Comment for MigrationTool.java git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1869 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -12,20 +12,32 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
import java.util.regex.*;
|
import java.io.BufferedWriter;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import java.lang.reflect.*;
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class Common {
|
public final class Common {
|
||||||
public static final int BOTH = 0;
|
public static final int BOTH = 0;
|
||||||
|
|
||||||
public static final int FILE = 1;
|
public static final int FILE = 1;
|
||||||
|
|
||||||
public static final int DIR = 2;
|
public static final int DIR = 2;
|
||||||
|
|
||||||
public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";
|
public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";
|
||||||
public static final Pattern PTNSEPARATER = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
|
||||||
|
|
||||||
//-------------------------------------regex------------------------------------------//
|
public static final Pattern PTNSEPARATER = Pattern
|
||||||
|
.compile("(.*)\\\\([^\\\\]*)");
|
||||||
|
|
||||||
|
// -------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
public static final String replaceAll(String line, Pattern ptn, String des) {
|
public static final String replaceAll(String line, Pattern ptn, String des) {
|
||||||
Matcher mtr = ptn.matcher(line);
|
Matcher mtr = ptn.matcher(line);
|
||||||
@ -37,14 +49,15 @@ public final class Common {
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean find (String line, String regex) {
|
public static final boolean find(String line, String regex) {
|
||||||
Pattern ptn = Pattern.compile(regex);
|
Pattern ptn = Pattern.compile(regex);
|
||||||
|
|
||||||
return ptn.matcher (line).find ();
|
return ptn.matcher(line).find();
|
||||||
}
|
}
|
||||||
//-------------------------------------regex------------------------------------------//
|
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
// -------------------------------------regex------------------------------------------//
|
||||||
|
|
||||||
|
// -----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
public static final String file2string(String filename) throws Exception {
|
public static final String file2string(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
||||||
@ -57,9 +70,11 @@ public final class Common {
|
|||||||
return wholefile.toString();
|
return wholefile.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void string2file(String content, String filename) throws Exception {
|
public static final void string2file(String content, String filename)
|
||||||
|
throws Exception {
|
||||||
ensureDir(filename);
|
ensureDir(filename);
|
||||||
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
PrintWriter outfile = new PrintWriter(new BufferedWriter(
|
||||||
|
new FileWriter(filename)));
|
||||||
outfile.append(content);
|
outfile.append(content);
|
||||||
outfile.flush();
|
outfile.flush();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
@ -69,29 +84,29 @@ public final class Common {
|
|||||||
string2file(file2string(src), des);
|
string2file(file2string(src), des);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
// -----------------------------------file&string---------------------------------------//
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
// --------------------------------------dir--------------------------------------------//
|
||||||
/*
|
/*
|
||||||
public static final HashSet<String> walkDir(String path, int mode) throws Exception {
|
* public static final HashSet<String> walkDir(String path, int mode)
|
||||||
HashSet<String> pathlist = new HashSet<String>();
|
* throws Exception { HashSet<String> pathlist = new HashSet<String>();
|
||||||
Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);
|
* Common.toDoAll(path, Common.class.getMethod("walkDir", String.class),
|
||||||
return pathlist;
|
* null, null, mode); return pathlist; }
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
public static final void ensureDir(String objFileWhole) {
|
public static final void ensureDir(String objFileWhole) {
|
||||||
File tempdir;
|
File tempdir;
|
||||||
Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);
|
Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);
|
||||||
if (mtrseparate.find()) {
|
if (mtrseparate.find()) {
|
||||||
tempdir = new File(mtrseparate.group(1));
|
tempdir = new File(mtrseparate.group(1));
|
||||||
if (!tempdir.exists()) tempdir.mkdirs();
|
if (!tempdir.exists())
|
||||||
|
tempdir.mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void deleteDir(String objFileWhole) {
|
public static final void deleteDir(String objFileWhole) {
|
||||||
String[] list = new File(objFileWhole).list();
|
String[] list = new File(objFileWhole).list();
|
||||||
File temp;
|
File temp;
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
temp = new File(objFileWhole + File.separator + list[i]);
|
temp = new File(objFileWhole + File.separator + list[i]);
|
||||||
if (temp.isDirectory()) {
|
if (temp.isDirectory()) {
|
||||||
deleteDir(objFileWhole + File.separator + list[i]);
|
deleteDir(objFileWhole + File.separator + list[i]);
|
||||||
@ -105,9 +120,11 @@ public final class Common {
|
|||||||
public static final String dirCopy_(String src) throws Exception {
|
public static final String dirCopy_(String src) throws Exception {
|
||||||
Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);
|
Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);
|
||||||
if (mtrseparate.find()) {
|
if (mtrseparate.find()) {
|
||||||
dirCopy(src, mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2));
|
dirCopy(src, mtrseparate.group(1) + File.separator + "_"
|
||||||
|
+ mtrseparate.group(2));
|
||||||
}
|
}
|
||||||
return mtrseparate.group(1) + File.separator + "_" + mtrseparate.group(2);
|
return mtrseparate.group(1) + File.separator + "_"
|
||||||
|
+ mtrseparate.group(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void dirCopy(String src, String des) throws Exception {
|
public static final void dirCopy(String src, String des) throws Exception {
|
||||||
@ -115,33 +132,39 @@ public final class Common {
|
|||||||
File test;
|
File test;
|
||||||
|
|
||||||
ensureDir(des);
|
ensureDir(des);
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
test = new File(src + File.separator + list[i]);
|
test = new File(src + File.separator + list[i]);
|
||||||
if (test.isDirectory()) {
|
if (test.isDirectory()) {
|
||||||
dirCopy(src + File.separator + list[i], des + File.separator + list[i]);
|
dirCopy(src + File.separator + list[i], des + File.separator
|
||||||
|
+ list[i]);
|
||||||
} else {
|
} else {
|
||||||
//ensureDir(des + File.separator + list[i]);
|
// ensureDir(des + File.separator + list[i]);
|
||||||
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
|
string2file(file2string(src + File.separator + list[i]), des
|
||||||
|
+ File.separator + list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void oneLevelDirCopy(String src, String des, String type) throws Exception {
|
public static final void oneLevelDirCopy(String src, String des, String type)
|
||||||
|
throws Exception {
|
||||||
String[] list = new File(src).list();
|
String[] list = new File(src).list();
|
||||||
|
|
||||||
ensureDir(des);
|
ensureDir(des);
|
||||||
for (int i = 0; i < list.length; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
if (list[i].contains(type)) {
|
if (list[i].contains(type)) {
|
||||||
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
|
string2file(file2string(src + File.separator + list[i]), des
|
||||||
|
+ File.separator + list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
// --------------------------------------dir--------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------like python walk-----------------------------------------//
|
// -------------------------------like python
|
||||||
|
// walk-----------------------------------------//
|
||||||
|
|
||||||
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
|
public static final void toDoAll(String path, Method md, Object obj,
|
||||||
|
Object[] args, int type) throws Exception {
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
ArrayList<Object> _args = new ArrayList<Object>();
|
ArrayList<Object> _args = new ArrayList<Object>();
|
||||||
|
|
||||||
@ -155,7 +178,7 @@ public final class Common {
|
|||||||
if (type == DIR || type == BOTH) {
|
if (type == DIR || type == BOTH) {
|
||||||
md.invoke(obj, _args.toArray());
|
md.invoke(obj, _args.toArray());
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
if (new File(path + File.separator + list[i]).isDirectory()) {
|
if (new File(path + File.separator + list[i]).isDirectory()) {
|
||||||
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
||||||
} else {
|
} else {
|
||||||
@ -167,21 +190,23 @@ public final class Common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {
|
public static final void toDoAll(Set<String> set, ForDoAll fda)
|
||||||
|
throws Exception {
|
||||||
Iterator<String> di = set.iterator();
|
Iterator<String> di = set.iterator();
|
||||||
while (di.hasNext()) {
|
while (di.hasNext()) {
|
||||||
fda.run(di.next());
|
fda.run(di.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo
|
public static final void toDoAll(String path, ForDoAll fda, int type)
|
||||||
|
throws Exception { // filter of file type can be done in toDo
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
File test;
|
File test;
|
||||||
|
|
||||||
if (type == DIR || type == BOTH) {
|
if (type == DIR || type == BOTH) {
|
||||||
fda.run(path);
|
fda.run(path);
|
||||||
}
|
}
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
test = new File(path + File.separator + list[i]);
|
test = new File(path + File.separator + list[i]);
|
||||||
if (test.isDirectory()) {
|
if (test.isDirectory()) {
|
||||||
if (fda.filter(test)) {
|
if (fda.filter(test)) {
|
||||||
@ -215,16 +240,16 @@ public final class Common {
|
|||||||
|
|
||||||
public static interface Element {
|
public static interface Element {
|
||||||
|
|
||||||
// public int replace = 0;
|
// public int replace = 0;
|
||||||
// public int type = 1;
|
// public int type = 1;
|
||||||
|
|
||||||
public String getReplace(String key);
|
public String getReplace(String key);
|
||||||
|
|
||||||
// public void getType(String key);
|
// public void getType(String key);
|
||||||
//
|
//
|
||||||
// public void setReplace(int num);
|
// public void setReplace(int num);
|
||||||
//
|
//
|
||||||
// public void setType(int num);
|
// public void setType(int num);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,23 +12,42 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.regex.*;
|
import java.io.BufferedReader;
|
||||||
import java.io.*;
|
import java.io.StringReader;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class Critic {
|
public final class Critic {
|
||||||
public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile("^\\/\\*\\*.*?\\*\\*\\/",Pattern.DOTALL);
|
public static final Pattern PTN_NEW_HEAD_COMMENT = Pattern.compile(
|
||||||
private static final Pattern ptnheadcomment = Pattern.compile("^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/",Pattern.DOTALL);
|
"^\\/\\*\\*.*?\\*\\*\\/", Pattern.DOTALL);
|
||||||
private static final Pattern ptnfunccomment = Pattern.compile("([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*(.*?)(?=[\\{;])",Pattern.DOTALL); // find function with {;">/ , may be unsafe
|
|
||||||
//private static Pattern ptncommentstructure = Pattern.compile("\\/\\*\\+\\+\\s*Routine Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
private static final Pattern ptnheadcomment = Pattern.compile(
|
||||||
private static final Pattern ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
"^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/", Pattern.DOTALL);
|
||||||
|
|
||||||
|
private static final Pattern ptnfunccomment = Pattern
|
||||||
|
.compile(
|
||||||
|
"([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*(.*?)(?=[\\{;])",
|
||||||
|
Pattern.DOTALL); // find function with {;">/ , may be
|
||||||
|
// unsafe
|
||||||
|
|
||||||
|
// private static Pattern ptncommentstructure =
|
||||||
|
// Pattern.compile("\\/\\*\\+\\+\\s*Routine
|
||||||
|
// Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
|
private static final Pattern ptncommentequation = Pattern
|
||||||
|
.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
||||||
|
|
||||||
private static Matcher mtrcommentequation;
|
private static Matcher mtrcommentequation;
|
||||||
private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
|
||||||
|
private static final Pattern ptnnewcomment = Pattern
|
||||||
|
.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
||||||
|
|
||||||
private static Matcher mtrnewcomment;
|
private static Matcher mtrnewcomment;
|
||||||
|
|
||||||
private static final int totallinelength = 82;
|
private static final int totallinelength = 82;
|
||||||
|
|
||||||
public static final void run(String filepath) throws Exception {
|
public static final void run(String filepath) throws Exception {
|
||||||
if (MigrationTool.doCritic) { // this is left here to set an example for future structure
|
if (MigrationTool.doCritic) { // this is left here to set an example
|
||||||
|
// for future structure
|
||||||
critic(filepath);
|
critic(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,9 +63,12 @@ public final class Critic {
|
|||||||
String wholeline = Common.file2string(filepath);
|
String wholeline = Common.file2string(filepath);
|
||||||
|
|
||||||
wholeline = wholeline.replaceAll("\t", " ");
|
wholeline = wholeline.replaceAll("\t", " ");
|
||||||
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
wholeline = Common.replaceAll(wholeline, ptnheadcomment,
|
||||||
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1\n/**$3\n**/\n$4$2");
|
"/** @file$1**/");
|
||||||
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
wholeline = Common.replaceAll(wholeline, ptnfunccomment,
|
||||||
|
"$1\n/**$3\n**/\n$4$2");
|
||||||
|
// wholeline = Common.replaceAll(wholeline, ptncommentstructure,
|
||||||
|
// "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
||||||
|
|
||||||
// first scan
|
// first scan
|
||||||
boolean description = false;
|
boolean description = false;
|
||||||
@ -87,7 +109,9 @@ public final class Critic {
|
|||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrcommentequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
templine.append(" @param "
|
||||||
|
+ mtrcommentequation.group(1) + " "
|
||||||
|
+ mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
@ -101,14 +125,17 @@ public final class Critic {
|
|||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
if (mtrcommentequation.find()) {
|
if (mtrcommentequation.find()) {
|
||||||
inequation = true;
|
inequation = true;
|
||||||
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
templine.append(" @retval "
|
||||||
|
+ mtrcommentequation.group(1) + " "
|
||||||
|
+ mtrcommentequation.group(2) + "\n");
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
inequation = false;
|
inequation = false;
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
templine.append("#%#%" + line + "\n");
|
templine.append("#%#%" + line + "\n");
|
||||||
} else {
|
} else {
|
||||||
if (line.trim().length() != 0) {
|
if (line.trim().length() != 0) {
|
||||||
templine.append(" @return " + line.trim() + "\n");
|
templine.append(" @return " + line.trim()
|
||||||
|
+ "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +160,9 @@ public final class Critic {
|
|||||||
} else if (incomment) {
|
} else if (incomment) {
|
||||||
mtrnewcomment = ptnnewcomment.matcher(line);
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
if (mtrnewcomment.find()) {
|
if (mtrnewcomment.find()) {
|
||||||
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
|
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment
|
||||||
|
.group(1).length()
|
||||||
|
: startmax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,15 +222,18 @@ public final class Critic {
|
|||||||
//
|
//
|
||||||
// Remove trailing blanks.
|
// Remove trailing blanks.
|
||||||
//
|
//
|
||||||
wholeline = wholeline.replaceAll (" +\n", "\n");
|
wholeline = wholeline.replaceAll(" +\n", "\n");
|
||||||
Common.string2file(wholeline, filepath);
|
Common.string2file(wholeline, filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void fireAt(String path) throws Exception {
|
public static final void fireAt(String path) throws Exception {
|
||||||
//Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);
|
// Common.toDoAll(Common.dirCopy_(path),
|
||||||
Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);
|
// Critic.class.getMethod("critic", String.class), null, null,
|
||||||
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
// Common.FILE);
|
||||||
|
Common.toDoAll(path, Critic.class.getMethod("run", String.class), null,
|
||||||
|
null, Common.FILE);
|
||||||
|
// Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
||||||
System.out.println("Critic Done");
|
System.out.println("Critic Done");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,23 +12,28 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import java.util.regex.*;
|
import java.io.FileReader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlObject.Factory;
|
|
||||||
import org.tianocore.DbPathAndFilename;
|
import org.tianocore.DbPathAndFilename;
|
||||||
import org.tianocore.FrameworkDatabaseDocument;
|
import org.tianocore.FrameworkDatabaseDocument;
|
||||||
|
import org.tianocore.PackageSurfaceAreaDocument;
|
||||||
import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
|
import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
|
||||||
import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;
|
import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;
|
||||||
import org.tianocore.PackageListDocument.PackageList;
|
import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;
|
||||||
import org.tianocore.PackageSurfaceAreaDocument;
|
import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass;
|
||||||
import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
|
import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
|
||||||
import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;
|
import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;
|
||||||
import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;
|
import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;
|
||||||
import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;
|
|
||||||
import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass;
|
|
||||||
|
|
||||||
public final class Database {
|
public final class Database {
|
||||||
private static final Database INSTANCE = Database.init();;
|
private static final Database INSTANCE = Database.init();;
|
||||||
@ -37,7 +42,7 @@ public final class Database {
|
|||||||
DatabasePath = path;
|
DatabasePath = path;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//collectWorkSpaceDatabase();
|
// collectWorkSpaceDatabase();
|
||||||
importPkgGuid("PkgGuid.csv");
|
importPkgGuid("PkgGuid.csv");
|
||||||
importDBLib("Library.csv");
|
importDBLib("Library.csv");
|
||||||
importDBGuid("Guid.csv", "Guid");
|
importDBGuid("Guid.csv", "Guid");
|
||||||
@ -51,23 +56,29 @@ public final class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String DatabasePath;
|
public String DatabasePath;
|
||||||
|
|
||||||
public Set<String> error = new HashSet<String>();
|
public Set<String> error = new HashSet<String>();
|
||||||
|
|
||||||
public Set<String> r8only = new HashSet<String>();
|
public Set<String> r8only = new HashSet<String>();
|
||||||
|
|
||||||
private Map<String,Guid> hashguid = new HashMap<String,Guid>();
|
private Map<String, Guid> hashguid = new HashMap<String, Guid>();
|
||||||
private Map<String,Func> hashfunc = new HashMap<String,Func>();
|
|
||||||
private Map<String,Macro> hashmacro = new HashMap<String,Macro>();
|
|
||||||
private Map<String,String> hashPkgGuid = new HashMap<String,String>();
|
|
||||||
|
|
||||||
|
private Map<String, Func> hashfunc = new HashMap<String, Func>();
|
||||||
|
|
||||||
//-------------------------------------import------------------------------------------//
|
private Map<String, Macro> hashmacro = new HashMap<String, Macro>();
|
||||||
|
|
||||||
|
private Map<String, String> hashPkgGuid = new HashMap<String, String>();
|
||||||
|
|
||||||
|
// -------------------------------------import------------------------------------------//
|
||||||
private void importPkgGuid(String filename) throws Exception {
|
private void importPkgGuid(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing Package Guid Database.");
|
System.out.println("Found " + filename
|
||||||
|
+ ", Importing Package Guid Database.");
|
||||||
//
|
//
|
||||||
// Skip the title row.
|
// Skip the title row.
|
||||||
//
|
//
|
||||||
@ -80,76 +91,87 @@ public final class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<String> dumpAllPkgGuid() {
|
public Iterator<String> dumpAllPkgGuid() {
|
||||||
return hashPkgGuid.values().iterator();
|
return hashPkgGuid.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importDBLib(String filename) throws Exception {
|
private void importDBLib(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Func lf;
|
Func lf;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing Library Database.");
|
System.out.println("Found " + filename
|
||||||
|
+ ", Importing Library Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
lf = new Func(linecontext);
|
lf = new Func(linecontext);
|
||||||
hashfunc.put(lf.r8funcname,lf);
|
hashfunc.put(lf.r8funcname, lf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importDBGuid(String filename, String type) throws Exception {
|
private void importDBGuid(String filename, String type) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Guid gu;
|
Guid gu;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing " + type + " Database.");
|
System.out.println("Found " + filename + ", Importing " + type
|
||||||
|
+ " Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
gu = new Guid(linecontext, type);
|
gu = new Guid(linecontext, type);
|
||||||
hashguid.put(gu.r8name,gu);
|
hashguid.put(gu.r8name, gu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importDBMacro(String filename) throws Exception {
|
private void importDBMacro(String filename) throws Exception {
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
String line;
|
String line;
|
||||||
String[] linecontext;
|
String[] linecontext;
|
||||||
Macro mc;
|
Macro mc;
|
||||||
|
|
||||||
if (rd.ready()) {
|
if (rd.ready()) {
|
||||||
System.out.println("Found " + filename + ", Importing Macro Database.");
|
System.out.println("Found " + filename
|
||||||
|
+ ", Importing Macro Database.");
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
if (line.length() != 0) {
|
if (line.length() != 0) {
|
||||||
linecontext = line.split(",");
|
linecontext = line.split(",");
|
||||||
mc = new Macro(linecontext);
|
mc = new Macro(linecontext);
|
||||||
hashmacro.put(mc.r8name,mc);
|
hashmacro.put(mc.r8name, mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importListR8Only() throws Exception {
|
private void importListR8Only() throws Exception {
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
Pattern ptnr8only = Pattern.compile(
|
||||||
String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");
|
"////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
||||||
System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
String wholeline = Common.file2string(DatabasePath + File.separator
|
||||||
|
+ "R8Lib.c");
|
||||||
|
System.out
|
||||||
|
.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
||||||
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
||||||
while (mtrr8only.find()) {
|
while (mtrr8only.find()) {
|
||||||
r8only.add(mtrr8only.group(2));
|
r8only.add(mtrr8only.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------import------------------------------------------//
|
// -------------------------------------import------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
// -------------------------------------get------------------------------------------//
|
||||||
|
|
||||||
public String getR9Lib(String r8funcname) {
|
public String getR9Lib(String r8funcname) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
@ -168,7 +190,10 @@ public final class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getR9Macro(String r8macro) {
|
public String getR9Macro(String r8macro) {
|
||||||
return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it
|
return hashmacro.get(r8macro).r9name; // the verification job of if
|
||||||
|
// the macro exists in the
|
||||||
|
// database is done when
|
||||||
|
// registering it
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getR9Guidname(String r8Guid) {
|
public String getR9Guidname(String r8Guid) {
|
||||||
@ -191,9 +216,9 @@ public final class Database {
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
// -------------------------------------get------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
// -------------------------------------has------------------------------------------//
|
||||||
|
|
||||||
public boolean hasFunc(String r8lib) {
|
public boolean hasFunc(String r8lib) {
|
||||||
return hashfunc.containsKey(r8lib);
|
return hashfunc.containsKey(r8lib);
|
||||||
@ -207,15 +232,19 @@ public final class Database {
|
|||||||
return hashmacro.containsKey(r8macro);
|
return hashmacro.containsKey(r8macro);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
// -------------------------------------has------------------------------------------//
|
||||||
|
|
||||||
//-------------------------------------init------------------------------------------//
|
// -------------------------------------init------------------------------------------//
|
||||||
|
|
||||||
private static final Database init() {
|
private static final Database init() {
|
||||||
if (System.getenv("WORKSPACE") == null) {
|
if (System.getenv("WORKSPACE") == null) {
|
||||||
return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
return new Database("C:" + File.separator + "tianocore"
|
||||||
|
+ File.separator + "edk2" + File.separator + "Tools"
|
||||||
|
+ File.separator + "Conf" + File.separator + "Migration");
|
||||||
} else {
|
} else {
|
||||||
return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
return new Database(System.getenv("WORKSPACE") + File.separator
|
||||||
|
+ "Tools" + File.separator + "Conf" + File.separator
|
||||||
|
+ "Migration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,35 +252,47 @@ public final class Database {
|
|||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String workspacePath;
|
private String workspacePath;
|
||||||
|
|
||||||
private HashMap<String, String> hashDbGuids = new HashMap<String, String>();
|
private HashMap<String, String> hashDbGuids = new HashMap<String, String>();
|
||||||
|
|
||||||
private HashMap<String, String> hashDbPpis = new HashMap<String, String>();
|
private HashMap<String, String> hashDbPpis = new HashMap<String, String>();
|
||||||
|
|
||||||
private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();
|
private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();
|
||||||
|
|
||||||
private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();
|
private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();
|
||||||
|
|
||||||
private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();
|
private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();
|
||||||
|
|
||||||
private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();
|
private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();
|
||||||
|
|
||||||
private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";
|
private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";
|
||||||
|
|
||||||
private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);
|
private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);
|
||||||
|
|
||||||
private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";
|
private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";
|
||||||
|
|
||||||
private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);
|
private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);
|
||||||
|
|
||||||
private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";
|
private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";
|
||||||
private final String regLibFunction = regLibDataType + "\\s*(?:EFIAPI)?\\s+" +
|
|
||||||
"(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";
|
private final String regLibFunction = regLibDataType
|
||||||
|
+ "\\s*(?:EFIAPI)?\\s+" + "(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";
|
||||||
|
|
||||||
private Pattern ptnLibFunction = Pattern.compile(regLibFunction);
|
private Pattern ptnLibFunction = Pattern.compile(regLibFunction);
|
||||||
|
|
||||||
private final String regLibExtern = "extern\\s+" + regLibDataType +
|
private final String regLibExtern = "extern\\s+" + regLibDataType
|
||||||
"\\s*(\\w[\\w\\d]*)";
|
+ "\\s*(\\w[\\w\\d]*)";
|
||||||
|
|
||||||
private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);
|
private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);
|
||||||
|
|
||||||
private final String convertToOsFilePath(String filePath) {
|
private final String convertToOsFilePath(String filePath) {
|
||||||
return filePath.replace("/", File.separator).replace("\\", File.separator);
|
return filePath.replace("/", File.separator).replace("\\",
|
||||||
|
File.separator);
|
||||||
}
|
}
|
||||||
private final void collectLibHeaderFileInfo(String libHeaderFile, String pkgGuid) throws Exception {
|
|
||||||
|
private final void collectLibHeaderFileInfo(String libHeaderFile,
|
||||||
|
String pkgGuid) throws Exception {
|
||||||
String fileContents;
|
String fileContents;
|
||||||
String libClassName;
|
String libClassName;
|
||||||
String libContainer;
|
String libContainer;
|
||||||
@ -260,7 +301,7 @@ public final class Database {
|
|||||||
Matcher mtrLibFunction;
|
Matcher mtrLibFunction;
|
||||||
Matcher mtrLibExtern;
|
Matcher mtrLibExtern;
|
||||||
|
|
||||||
System.out.println ("Parsing: " + libHeaderFile);
|
System.out.println("Parsing: " + libHeaderFile);
|
||||||
mtrLibClass = ptnLibClassName.matcher(libHeaderFile);
|
mtrLibClass = ptnLibClassName.matcher(libHeaderFile);
|
||||||
if (!mtrLibClass.matches()) {
|
if (!mtrLibClass.matches()) {
|
||||||
throw new Exception("Illegal libary header file");
|
throw new Exception("Illegal libary header file");
|
||||||
@ -279,8 +320,8 @@ public final class Database {
|
|||||||
if (oldLibContainer != null) {
|
if (oldLibContainer != null) {
|
||||||
String warnMessage;
|
String warnMessage;
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. " +
|
warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. "
|
||||||
"Later package will overide the previous one";
|
+ "Later package will overide the previous one";
|
||||||
System.out.println(warnMessage);
|
System.out.println(warnMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,8 +336,9 @@ public final class Database {
|
|||||||
if (oldLibContainer != null) {
|
if (oldLibContainer != null) {
|
||||||
String warnMessage;
|
String warnMessage;
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Function:" + libFunction + " Found. " +
|
warnMessage = "Duplicated Lib Function:" + libFunction
|
||||||
"Later package will overide the previous one";
|
+ " Found. "
|
||||||
|
+ "Later package will overide the previous one";
|
||||||
System.out.println(warnMessage);
|
System.out.println(warnMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,13 +353,15 @@ public final class Database {
|
|||||||
if (oldLibContainer != null) {
|
if (oldLibContainer != null) {
|
||||||
String warnMessage;
|
String warnMessage;
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. " +
|
warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. "
|
||||||
"Later package will overide the previous one";
|
+ "Later package will overide the previous one";
|
||||||
System.out.println(warnMessage);
|
System.out.println(warnMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private final void collectLibDataBase(PackageSurfaceArea spdDatabase, String pkgDirectory) throws Exception {
|
|
||||||
|
private final void collectLibDataBase(PackageSurfaceArea spdDatabase,
|
||||||
|
String pkgDirectory) throws Exception {
|
||||||
String pkgGuid;
|
String pkgGuid;
|
||||||
LibraryClassDeclarations libClassDeclarations;
|
LibraryClassDeclarations libClassDeclarations;
|
||||||
|
|
||||||
@ -330,22 +374,24 @@ public final class Database {
|
|||||||
while (itLibClass.hasNext()) {
|
while (itLibClass.hasNext()) {
|
||||||
String libHeaderFile;
|
String libHeaderFile;
|
||||||
|
|
||||||
libHeaderFile = pkgDirectory + File.separator +
|
libHeaderFile = pkgDirectory + File.separator
|
||||||
itLibClass.next().getIncludeHeader();
|
+ itLibClass.next().getIncludeHeader();
|
||||||
libHeaderFile = convertToOsFilePath (libHeaderFile);
|
libHeaderFile = convertToOsFilePath(libHeaderFile);
|
||||||
try {
|
try {
|
||||||
collectLibHeaderFileInfo(libHeaderFile, pkgGuid);
|
collectLibHeaderFileInfo(libHeaderFile, pkgGuid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String errorMessage;
|
String errorMessage;
|
||||||
|
|
||||||
errorMessage = "Error (" + e.getMessage() + ")occurs when parsing " +
|
errorMessage = "Error (" + e.getMessage()
|
||||||
libHeaderFile;
|
+ ")occurs when parsing " + libHeaderFile;
|
||||||
System.out.println(errorMessage);
|
System.out.println(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private final void collectGuidDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
|
||||||
|
private final void collectGuidDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
String pkgGuid;
|
String pkgGuid;
|
||||||
GuidDeclarations guidDeclarations;
|
GuidDeclarations guidDeclarations;
|
||||||
|
|
||||||
@ -362,7 +408,8 @@ public final class Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void collectPpiDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
private final void collectPpiDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
String pkgGuid;
|
String pkgGuid;
|
||||||
PpiDeclarations ppiDeclarations;
|
PpiDeclarations ppiDeclarations;
|
||||||
|
|
||||||
@ -380,7 +427,8 @@ public final class Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
String pkgGuid;
|
String pkgGuid;
|
||||||
ProtocolDeclarations protocolDeclarations;
|
ProtocolDeclarations protocolDeclarations;
|
||||||
|
|
||||||
@ -398,22 +446,24 @@ public final class Database {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void collectPackageDatabase(String packageFileName) throws Exception {
|
private final void collectPackageDatabase(String packageFileName)
|
||||||
|
throws Exception {
|
||||||
XmlObject xmlPackage;
|
XmlObject xmlPackage;
|
||||||
PackageSurfaceArea spdDatabase;
|
PackageSurfaceArea spdDatabase;
|
||||||
File pkgFile;
|
File pkgFile;
|
||||||
|
|
||||||
pkgFile = new File(packageFileName);
|
pkgFile = new File(packageFileName);
|
||||||
xmlPackage = XmlObject.Factory.parse(pkgFile);
|
xmlPackage = XmlObject.Factory.parse(pkgFile);
|
||||||
spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage).getPackageSurfaceArea();
|
spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage)
|
||||||
|
.getPackageSurfaceArea();
|
||||||
|
|
||||||
collectGuidDatabase(spdDatabase);
|
collectGuidDatabase(spdDatabase);
|
||||||
collectProtocolDatabase(spdDatabase);
|
collectProtocolDatabase(spdDatabase);
|
||||||
collectPpiDatabase(spdDatabase);
|
collectPpiDatabase(spdDatabase);
|
||||||
collectLibDataBase(spdDatabase, pkgFile.getParent());
|
collectLibDataBase(spdDatabase, pkgFile.getParent());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void collectWorkSpaceDatabase() throws Exception {
|
public final void collectWorkSpaceDatabase() throws Exception {
|
||||||
String databaseFileName;
|
String databaseFileName;
|
||||||
File databaseFile;
|
File databaseFile;
|
||||||
@ -427,15 +477,16 @@ public final class Database {
|
|||||||
String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";
|
String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";
|
||||||
throw new Exception(errorMessage);
|
throw new Exception(errorMessage);
|
||||||
}
|
}
|
||||||
databaseFileName = workspacePath + File.separator +
|
databaseFileName = workspacePath + File.separator + "Tools"
|
||||||
"Tools" + File.separator +
|
+ File.separator + "Conf" + File.separator
|
||||||
"Conf" + File.separator +
|
+ "FrameworkDatabase.db";
|
||||||
"FrameworkDatabase.db";
|
|
||||||
System.out.println("Open " + databaseFileName);
|
System.out.println("Open " + databaseFileName);
|
||||||
databaseFile = new File(databaseFileName);
|
databaseFile = new File(databaseFileName);
|
||||||
xmlDatabase = XmlObject.Factory.parse(databaseFile);
|
xmlDatabase = XmlObject.Factory.parse(databaseFile);
|
||||||
frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase).getFrameworkDatabase();
|
frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase)
|
||||||
packageFile = frameworkDatabase.getPackageList().getFilenameList().iterator();
|
.getFrameworkDatabase();
|
||||||
|
packageFile = frameworkDatabase.getPackageList().getFilenameList()
|
||||||
|
.iterator();
|
||||||
|
|
||||||
while (packageFile.hasNext()) {
|
while (packageFile.hasNext()) {
|
||||||
String packageFileName = packageFile.next().getStringValue();
|
String packageFileName = packageFile.next().getStringValue();
|
||||||
@ -446,7 +497,8 @@ public final class Database {
|
|||||||
try {
|
try {
|
||||||
collectPackageDatabase(packageFileName);
|
collectPackageDatabase(packageFileName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error occured when opening " + packageFileName + e.getMessage());
|
System.out.println("Error occured when opening "
|
||||||
|
+ packageFileName + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,33 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.event.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.io.*;
|
import java.awt.Insets;
|
||||||
import java.util.*;
|
import java.awt.event.ActionEvent;
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
public final class FirstPanel extends JPanel implements ActionListener,
|
||||||
|
ItemListener, UI {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
@ -28,13 +48,19 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
|
|
||||||
private String startpath = null;
|
private String startpath = null;
|
||||||
|
|
||||||
private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;
|
private JButton moduleButton, goButton, msaEditorButton, criticButton,
|
||||||
|
specifyCommentButton;
|
||||||
|
|
||||||
private JTextField moduletext;
|
private JTextField moduletext;
|
||||||
|
|
||||||
private JTextArea log;
|
private JTextArea log;
|
||||||
|
|
||||||
private JFileChooser fc = new JFileChooser();
|
private JFileChooser fc = new JFileChooser();
|
||||||
|
|
||||||
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
||||||
|
|
||||||
private boolean tofile = true, toscreen = true;
|
private boolean tofile = true, toscreen = true;
|
||||||
|
|
||||||
private PrintWriter logfile;
|
private PrintWriter logfile;
|
||||||
|
|
||||||
FirstPanel() {
|
FirstPanel() {
|
||||||
@ -83,10 +109,10 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
modulePanel.add(moduleButton);
|
modulePanel.add(moduleButton);
|
||||||
modulePanel.add(moduletext);
|
modulePanel.add(moduletext);
|
||||||
modulePanel.add(goButton);
|
modulePanel.add(goButton);
|
||||||
//modulePanel.add(msaEditorButton);
|
// modulePanel.add(msaEditorButton);
|
||||||
cst.gridx = 0;
|
cst.gridx = 0;
|
||||||
cst.gridy = 0;
|
cst.gridy = 0;
|
||||||
//cst.gridwidth = GridBagConstraints.REMAINDER;
|
// cst.gridwidth = GridBagConstraints.REMAINDER;
|
||||||
gridbag.setConstraints(modulePanel, cst);
|
gridbag.setConstraints(modulePanel, cst);
|
||||||
add(modulePanel);
|
add(modulePanel);
|
||||||
|
|
||||||
@ -94,8 +120,8 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
cst.gridy = 0;
|
cst.gridy = 0;
|
||||||
gridbag.setConstraints(specifyCommentButton, cst);
|
gridbag.setConstraints(specifyCommentButton, cst);
|
||||||
add(specifyCommentButton);
|
add(specifyCommentButton);
|
||||||
//gridbag.setConstraints(criticButton, cst);
|
// gridbag.setConstraints(criticButton, cst);
|
||||||
//add(criticButton);
|
// add(criticButton);
|
||||||
|
|
||||||
JPanel checkboxPanel = new JPanel();
|
JPanel checkboxPanel = new JPanel();
|
||||||
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
|
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
|
||||||
@ -106,12 +132,12 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
checkboxPanel.add(defaultpathbox);
|
checkboxPanel.add(defaultpathbox);
|
||||||
cst.gridx = 1;
|
cst.gridx = 1;
|
||||||
cst.gridy = 1;
|
cst.gridy = 1;
|
||||||
//cst.gridheight = 2;
|
// cst.gridheight = 2;
|
||||||
gridbag.setConstraints(checkboxPanel, cst);
|
gridbag.setConstraints(checkboxPanel, cst);
|
||||||
add(checkboxPanel);
|
add(checkboxPanel);
|
||||||
|
|
||||||
log = new JTextArea(10,20);
|
log = new JTextArea(10, 20);
|
||||||
log.setMargin(new Insets(5,5,5,5));
|
log.setMargin(new Insets(5, 5, 5, 5));
|
||||||
log.setEditable(false);
|
log.setEditable(false);
|
||||||
JScrollPane logScrollPane = new JScrollPane(log);
|
JScrollPane logScrollPane = new JScrollPane(log);
|
||||||
cst.gridx = 0;
|
cst.gridx = 0;
|
||||||
@ -121,10 +147,11 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
add(logScrollPane);
|
add(logScrollPane);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public boolean yesOrNo(String question) {
|
public boolean yesOrNo(String question) {
|
||||||
return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
return JOptionPane.showConfirmDialog(this, question, "Yes or No",
|
||||||
|
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(String message) {
|
public void print(String message) {
|
||||||
@ -152,14 +179,15 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String choose(String message, Object[] choicelist) {
|
public String choose(String message, Object[] choicelist) {
|
||||||
return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
|
return (String) JOptionPane.showInputDialog(this, message, "Choose",
|
||||||
|
JOptionPane.PLAIN_MESSAGE, null, choicelist, choicelist[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInput(String message) {
|
public String getInput(String message) {
|
||||||
return (String)JOptionPane.showInputDialog(message);
|
return (String) JOptionPane.showInputDialog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public String getFilepath(String title, int mode) {
|
public String getFilepath(String title, int mode) {
|
||||||
fc.setDialogTitle(title);
|
fc.setDialogTitle(title);
|
||||||
@ -171,16 +199,19 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if ( e.getSource() == moduleButton ) {
|
if (e.getSource() == moduleButton) {
|
||||||
startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);
|
startpath = getFilepath("Please choose a starting path",
|
||||||
|
JFileChooser.DIRECTORIES_ONLY);
|
||||||
moduletext.setText(startpath);
|
moduletext.setText(startpath);
|
||||||
}
|
}
|
||||||
if ( e.getSource() == goButton ) {
|
if (e.getSource() == goButton) {
|
||||||
try {
|
try {
|
||||||
logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + "migration.log")));
|
logfile = new PrintWriter(new BufferedWriter(new FileWriter(
|
||||||
|
startpath.replaceAll(Common.STRSEPARATER, "$1")
|
||||||
|
+ File.separator + "migration.log")));
|
||||||
MigrationTool.startMigrateAll(startpath);
|
MigrationTool.startMigrateAll(startpath);
|
||||||
logfile.flush();
|
logfile.flush();
|
||||||
logfile.close();
|
logfile.close();
|
||||||
@ -188,24 +219,24 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == msaEditorButton) {
|
if (e.getSource() == msaEditorButton) {
|
||||||
try {
|
try {
|
||||||
MsaTreeEditor.init();
|
MsaTreeEditor.init();
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == criticButton) {
|
if (e.getSource() == criticButton) {
|
||||||
try {
|
try {
|
||||||
Critic.fireAt(startpath);
|
Critic.fireAt(startpath);
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( e.getSource() == specifyCommentButton) {
|
if (e.getSource() == specifyCommentButton) {
|
||||||
try { // input examine is not imposed but should be added
|
try { // input examine is not imposed but should be added
|
||||||
MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
|
MigrationTool.MIGRATIONCOMMENT = getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
|
||||||
//MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
// MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
||||||
} catch (Exception en) {
|
} catch (Exception en) {
|
||||||
println(en.getMessage());
|
println(en.getMessage());
|
||||||
}
|
}
|
||||||
@ -246,7 +277,7 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
private static final FirstPanel init() {
|
private static final FirstPanel init() {
|
||||||
try {
|
try {
|
||||||
|
@ -12,41 +12,59 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.regex.*;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Func {
|
public class Func {
|
||||||
Func(String r8func,String r8lib,String r9func,String r9lib) {
|
Func(String r8func, String r8lib, String r9func, String r9lib) {
|
||||||
r8funcname = r8func;
|
r8funcname = r8func;
|
||||||
r8libname = r8lib;
|
r8libname = r8lib;
|
||||||
r9funcname = r9func;
|
r9funcname = r9func;
|
||||||
r9libname = r9lib;
|
r9libname = r9lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
Func(String[] linecontext) {
|
Func(String[] linecontext) {
|
||||||
r8funcname = linecontext[1];
|
r8funcname = linecontext[1];
|
||||||
r8libname = linecontext[0];
|
r8libname = linecontext[0];
|
||||||
r9funcname = linecontext[2];
|
r9funcname = linecontext[2];
|
||||||
if (r9funcname.contains("n/a")) {
|
if (r9funcname.contains("n/a")) {
|
||||||
r9funcname = "#error Unknown or missing library function in EDKII: " + r8funcname;
|
r9funcname = "#error Unknown or missing library function in EDKII: "
|
||||||
|
+ r8funcname;
|
||||||
}
|
}
|
||||||
r9libname = linecontext[3];
|
r9libname = linecontext[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String r8funcname;
|
public String r8funcname;
|
||||||
|
|
||||||
public String r8libname;
|
public String r8libname;
|
||||||
|
|
||||||
public String r9funcname;
|
public String r9funcname;
|
||||||
|
|
||||||
public String r9libname;
|
public String r9libname;
|
||||||
|
|
||||||
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);
|
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",
|
||||||
public static Pattern ptnfuncc = Pattern.compile("(?<!->)([a-zA-Z_]\\w*)\\s*\\(",Pattern.MULTILINE);
|
Pattern.MULTILINE);
|
||||||
public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);
|
|
||||||
public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed
|
public static Pattern ptnfuncc = Pattern.compile(
|
||||||
|
"(?<!->)([a-zA-Z_]\\w*)\\s*\\(", Pattern.MULTILINE);
|
||||||
|
|
||||||
|
public static Pattern ptnfuncd = Pattern.compile(
|
||||||
|
"([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@", Pattern.MULTILINE);
|
||||||
|
|
||||||
|
public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be
|
||||||
|
// removed
|
||||||
|
|
||||||
private static String reservedwords = "if for pack while switch return sizeof";
|
private static String reservedwords = "if for pack while switch return sizeof";
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls
|
temp = mtr.group(1); // both changed and not changed funcc are
|
||||||
Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged
|
// registered , for finding all the non-local
|
||||||
|
// function calls
|
||||||
|
Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so
|
||||||
|
// the two funcs can be
|
||||||
|
// merged
|
||||||
if (!reservedwords.contains(temp) && mtrlowcase.find()) {
|
if (!reservedwords.contains(temp) && mtrlowcase.find()) {
|
||||||
mi.hashfuncc.add(temp);
|
mi.hashfuncc.add(temp);
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.regex.*;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.tianocore.UsageTypes;
|
import org.tianocore.UsageTypes;
|
||||||
|
|
||||||
public class Guid {
|
public class Guid {
|
||||||
Guid (String r8, String t, String n, String r9, String gv, String p) {
|
Guid(String r8, String t, String n, String r9, String gv, String p) {
|
||||||
r8name = r8;
|
r8name = r8;
|
||||||
type = t;
|
type = t;
|
||||||
name = n;
|
name = n;
|
||||||
@ -25,7 +26,8 @@ public class Guid {
|
|||||||
guidvalue = gv;
|
guidvalue = gv;
|
||||||
pack = p;
|
pack = p;
|
||||||
}
|
}
|
||||||
Guid (String[] linecontext, String t) {
|
|
||||||
|
Guid(String[] linecontext, String t) {
|
||||||
r8name = linecontext[1];
|
r8name = linecontext[1];
|
||||||
type = t;
|
type = t;
|
||||||
name = linecontext[0];
|
name = linecontext[0];
|
||||||
@ -33,11 +35,17 @@ public class Guid {
|
|||||||
guidvalue = linecontext[3];
|
guidvalue = linecontext[3];
|
||||||
pack = linecontext[4];
|
pack = linecontext[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String r8name;
|
public String r8name;
|
||||||
|
|
||||||
public String type;
|
public String type;
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
public String r9name;
|
public String r9name;
|
||||||
|
|
||||||
public String guidvalue;
|
public String guidvalue;
|
||||||
|
|
||||||
public String pack;
|
public String pack;
|
||||||
|
|
||||||
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
||||||
@ -47,17 +55,20 @@ public class Guid {
|
|||||||
String temp = null;
|
String temp = null;
|
||||||
|
|
||||||
temp = mtr.group();
|
temp = mtr.group();
|
||||||
if (MigrationTool.db.hasGuid(temp)) { // only changed guids registered, because both changed and not changed guids are included in database
|
if (MigrationTool.db.hasGuid(temp)) { // only changed guids
|
||||||
|
// registered, because both
|
||||||
|
// changed and not changed guids
|
||||||
|
// are included in database
|
||||||
type = MigrationTool.db.getGuidType(temp);
|
type = MigrationTool.db.getGuidType(temp);
|
||||||
if (type.matches("Protocol")) {
|
if (type.matches("Protocol")) {
|
||||||
mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);
|
mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
//mi.protocols.add(temp);
|
// mi.protocols.add(temp);
|
||||||
} else if (type.matches("Ppi")) {
|
} else if (type.matches("Ppi")) {
|
||||||
mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);
|
mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
//mi.ppis.add(temp);
|
// mi.ppis.add(temp);
|
||||||
} else if (type.matches("Guid")) {
|
} else if (type.matches("Guid")) {
|
||||||
mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);
|
mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
//mi.guids.add(temp);
|
// mi.guids.add(temp);
|
||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
@ -12,22 +12,26 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.regex.*;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Macro {
|
public class Macro {
|
||||||
Macro(String r8, String r9) {
|
Macro(String r8, String r9) {
|
||||||
r8name = r8;
|
r8name = r8;
|
||||||
r9name = r9;
|
r9name = r9;
|
||||||
}
|
}
|
||||||
|
|
||||||
Macro(String[] linecontext) {
|
Macro(String[] linecontext) {
|
||||||
r8name = linecontext[0];
|
r8name = linecontext[0];
|
||||||
r9name = linecontext[1];
|
r9name = linecontext[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public String r8name;
|
public String r8name;
|
||||||
|
|
||||||
public String r9name;
|
public String r9name;
|
||||||
|
|
||||||
public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",Pattern.MULTILINE);
|
public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",
|
||||||
|
Pattern.MULTILINE);
|
||||||
|
|
||||||
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
||||||
|
|
||||||
@ -36,7 +40,10 @@ public class Macro {
|
|||||||
|
|
||||||
temp = mtr.group();
|
temp = mtr.group();
|
||||||
mi.hashmacro.add(temp);
|
mi.hashmacro.add(temp);
|
||||||
if (MigrationTool.db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones
|
if (MigrationTool.db.hasMacro(temp)) { // only changed macros
|
||||||
|
// registered, because the
|
||||||
|
// database of macro has only
|
||||||
|
// changed ones
|
||||||
if (!unmacro.contains(temp)) {
|
if (!unmacro.contains(temp)) {
|
||||||
mi.hashnonlocalmacro.add(temp);
|
mi.hashnonlocalmacro.add(temp);
|
||||||
}
|
}
|
||||||
|
@ -13,29 +13,63 @@
|
|||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
import org.tianocore.UsageTypes;
|
/**
|
||||||
|
* The class is used as the main class of the MigrationTool, maintains the main
|
||||||
|
* work flow, and all the global variables and constants. It extends nothing.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class MigrationTool {
|
public class MigrationTool {
|
||||||
|
|
||||||
|
//
|
||||||
|
// These two objects are serves globally, it is always required, and only
|
||||||
|
// one instance is ever allowed.
|
||||||
|
//
|
||||||
public static UI ui = null;
|
public static UI ui = null;
|
||||||
|
|
||||||
public static Database db = null;
|
public static Database db = null;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The global constant for MigrationTool generated comments.
|
||||||
|
//
|
||||||
public static String MIGRATIONCOMMENT = "//@MT:";
|
public static String MIGRATIONCOMMENT = "//@MT:";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Global switches that are changed by user by the FirstPanel.
|
||||||
|
//
|
||||||
public static boolean printModuleInfo = false;
|
public static boolean printModuleInfo = false;
|
||||||
|
|
||||||
public static boolean doCritic = false;
|
public static boolean doCritic = false;
|
||||||
|
|
||||||
public static boolean defaultoutput = false;
|
public static boolean defaultoutput = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// A hashmap that associates the reference to a ModuleInfo with its
|
||||||
|
// outputpath.
|
||||||
|
//
|
||||||
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
||||||
|
|
||||||
|
//
|
||||||
|
// The starting point of the MigrationTool.
|
||||||
|
//
|
||||||
private static String startpath = null;
|
private static String startpath = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method defines the overall main work flow of the MigrationTool.
|
||||||
|
*
|
||||||
|
* @param mi
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
||||||
ModuleReader.aimAt(mi);
|
ModuleReader.aimAt(mi);
|
||||||
SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
SourceFileReplacer.fireAt(mi); // some adding library actions are taken
|
||||||
|
// here,so it must be put before
|
||||||
|
// "MsaWriter"
|
||||||
|
|
||||||
// show result
|
// show result
|
||||||
if (MigrationTool.printModuleInfo) {
|
if (MigrationTool.printModuleInfo) {
|
||||||
@ -53,36 +87,56 @@ public class MigrationTool {
|
|||||||
}
|
}
|
||||||
new MsaWriter(mi).flush();
|
new MsaWriter(mi).flush();
|
||||||
|
|
||||||
//mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".___");
|
// mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +
|
||||||
|
// File.separator + "Migration_" + mi.modulename + File.separator +
|
||||||
|
// mi.modulename + ".___");
|
||||||
|
|
||||||
if (MigrationTool.doCritic) {
|
if (MigrationTool.doCritic) {
|
||||||
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);
|
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_"
|
||||||
|
+ mi.modulename);
|
||||||
}
|
}
|
||||||
|
|
||||||
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
||||||
MigrationTool.ui.println("Complete!");
|
MigrationTool.ui.println("Complete!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is specially written to print the message for ModuleInfo,
|
||||||
|
* just for less code repeating.
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
* @param show
|
||||||
|
*/
|
||||||
private static final void show(Set<String> hash, String show) {
|
private static final void show(Set<String> hash, String show) {
|
||||||
MigrationTool.ui.println(show + hash.size());
|
MigrationTool.ui.println(show + hash.size());
|
||||||
MigrationTool.ui.println(hash);
|
MigrationTool.ui.println(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method designates the location of temp directory.
|
||||||
|
*
|
||||||
|
* @param modulepath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static final String getTempDir(String modulepath) {
|
public static final String getTempDir(String modulepath) {
|
||||||
return "C:" + File.separator + "MigrationTool_Temp" + modulepath.replace(startpath, "");
|
return "C:" + File.separator + "MigrationTool_Temp"
|
||||||
|
+ modulepath.replace(startpath, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String assignOutPutPath(String inputpath) {
|
private static final String assignOutPutPath(String inputpath) {
|
||||||
if (MigrationTool.defaultoutput) {
|
if (MigrationTool.defaultoutput) {
|
||||||
return inputpath.replaceAll(Common.STRSEPARATER, "$1");
|
return inputpath.replaceAll(Common.STRSEPARATER, "$1");
|
||||||
} else {
|
} else {
|
||||||
return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);
|
return MigrationTool.ui.getFilepath(
|
||||||
|
"Please choose where to place the output module",
|
||||||
|
JFileChooser.DIRECTORIES_ONLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void seekModule(String filepath) throws Exception {
|
public static final void seekModule(String filepath) throws Exception {
|
||||||
if (ModuleInfo.isModule(filepath)) {
|
if (ModuleInfo.isModule(filepath)) {
|
||||||
ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));
|
ModuleInfoMap.put(new ModuleInfo(filepath),
|
||||||
|
assignOutPutPath(filepath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +149,8 @@ public class MigrationTool {
|
|||||||
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
||||||
}
|
}
|
||||||
|
|
||||||
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);
|
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",
|
||||||
|
String.class), null, null, Common.DIR);
|
||||||
|
|
||||||
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
||||||
while (miit.hasNext()) {
|
while (miit.hasNext()) {
|
||||||
|
@ -12,16 +12,17 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.tianocore.UsageTypes;
|
import org.tianocore.UsageTypes;
|
||||||
import org.tianocore.SupportedArchitectures.Enum;
|
import org.tianocore.SupportedArchitectures.Enum;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Class ModuleInfo is built for scanning the source files, it contains all the needed
|
* Class ModuleInfo is built for scanning the source files, it contains all the
|
||||||
information and all the temporary data.
|
* needed information and all the temporary data.
|
||||||
*/
|
*/
|
||||||
public final class ModuleInfo {
|
public final class ModuleInfo {
|
||||||
ModuleInfo(String modulepath) throws Exception {
|
ModuleInfo(String modulepath) throws Exception {
|
||||||
this.modulepath = modulepath;
|
this.modulepath = modulepath;
|
||||||
@ -29,74 +30,106 @@ public final class ModuleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final String modulepath;
|
public final String modulepath;
|
||||||
|
|
||||||
public final String temppath;
|
public final String temppath;
|
||||||
|
|
||||||
private MsaOwner msaowner = MsaOwner.initNewMsaOwner();
|
private MsaOwner msaowner = MsaOwner.initNewMsaOwner();
|
||||||
|
|
||||||
public String modulename = null;
|
public String modulename = null;
|
||||||
|
|
||||||
public String guidvalue = null;
|
public String guidvalue = null;
|
||||||
|
|
||||||
public String moduletype = null;
|
public String moduletype = null;
|
||||||
|
|
||||||
public String entrypoint = null;
|
public String entrypoint = null;
|
||||||
|
|
||||||
public String license = null;
|
public String license = null;
|
||||||
|
|
||||||
public final Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h
|
public final Set<String> localmodulesources = new HashSet<String>(); // contains
|
||||||
|
// both
|
||||||
|
// .c
|
||||||
|
// and
|
||||||
|
// .h
|
||||||
|
|
||||||
public final Set<String> preprocessedccodes = new HashSet<String>();
|
public final Set<String> preprocessedccodes = new HashSet<String>();
|
||||||
public final Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this
|
|
||||||
|
public final Set<String> msaorinf = new HashSet<String>(); // only a
|
||||||
|
// little, hash
|
||||||
|
// may be too
|
||||||
|
// big for this
|
||||||
|
|
||||||
public final Set<String> infincludes = new HashSet<String>();
|
public final Set<String> infincludes = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> infsources = new HashSet<String>();
|
public final Set<String> infsources = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashfuncc = new HashSet<String>();
|
public final Set<String> hashfuncc = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashfuncd = new HashSet<String>();
|
public final Set<String> hashfuncd = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashEFIcall = new HashSet<String>();
|
public final Set<String> hashEFIcall = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashr8only = new HashSet<String>();
|
public final Set<String> hashr8only = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashmacro = new HashSet<String>();
|
public final Set<String> hashmacro = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer
|
public final Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs
|
||||||
|
// is
|
||||||
|
// now
|
||||||
|
// all
|
||||||
|
// added
|
||||||
|
// in
|
||||||
|
// SourceFileReplacer
|
||||||
|
|
||||||
public final Set<String> guids = new HashSet<String>();
|
public final Set<String> guids = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> protocols = new HashSet<String>();
|
public final Set<String> protocols = new HashSet<String>();
|
||||||
|
|
||||||
public final Set<String> ppis = new HashSet<String>();
|
public final Set<String> ppis = new HashSet<String>();
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
|
||||||
//addModuleType
|
// addModuleType
|
||||||
//addGuidValue
|
// addGuidValue
|
||||||
//addModuleName
|
// addModuleName
|
||||||
|
|
||||||
public final boolean addSourceFile (String filename, Enum en) {
|
public final boolean addSourceFile(String filename, Enum en) {
|
||||||
localmodulesources.add(filename);
|
localmodulesources.add(filename);
|
||||||
return msaowner.addSourceFile(filename, en);
|
return msaowner.addSourceFile(filename, en);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
|
public final boolean addProtocol(String proname, UsageTypes.Enum usage) {
|
||||||
protocols.add(proname);
|
protocols.add(proname);
|
||||||
return msaowner.addProtocol(proname, usage);
|
return msaowner.addProtocol(proname, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
|
public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {
|
||||||
ppis.add(ppiname);
|
ppis.add(ppiname);
|
||||||
return msaowner.addPpi(ppiname, usage);
|
return msaowner.addPpi(ppiname, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
|
public final boolean addGuid(String guidname, UsageTypes.Enum usage) {
|
||||||
guids.add(guidname);
|
guids.add(guidname);
|
||||||
return msaowner.addGuid(guidname, usage);
|
return msaowner.addGuid(guidname, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
||||||
//
|
//
|
||||||
// This section is only for adding library classes, this functionality should be inside MsaOwner!!!
|
// This section is only for adding library classes, this functionality
|
||||||
|
// should be inside MsaOwner!!!
|
||||||
//
|
//
|
||||||
//if (!hashrequiredr9libs.contains(name)) {
|
// if (!hashrequiredr9libs.contains(name)) {
|
||||||
msaowner.addLibraryClass(name, usage);
|
msaowner.addLibraryClass(name, usage);
|
||||||
//}
|
// }
|
||||||
//
|
//
|
||||||
hashrequiredr9libs.add(name);
|
hashrequiredr9libs.add(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
|
||||||
public final String getModuleType() {
|
public final String getModuleType() {
|
||||||
if (moduletype.contains("PEI")) {
|
if (moduletype.contains("PEI")) {
|
||||||
@ -110,20 +143,23 @@ public final class ModuleInfo {
|
|||||||
String temp = null;
|
String temp = null;
|
||||||
if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
||||||
temp = filepath.replace(modulepath + File.separator, "");
|
temp = filepath.replace(modulepath + File.separator, "");
|
||||||
if (!temp.contains(File.separator)) { // .inf in subdirectory is not regarded
|
if (!temp.contains(File.separator)) { // .inf in subdirectory is
|
||||||
|
// not regarded
|
||||||
msaorinf.add(temp);
|
msaorinf.add(temp);
|
||||||
}
|
}
|
||||||
} else if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
|
} else if (filepath.contains(".c") || filepath.contains(".C")
|
||||||
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni") ||
|
|| filepath.contains(".h") || filepath.contains(".H")
|
||||||
filepath.contains(".s") || filepath.contains(".S") || filepath.contains(".i") ||
|
|| filepath.contains(".dxs") || filepath.contains(".uni")
|
||||||
filepath.contains(".asm")) {
|
|| filepath.contains(".s") || filepath.contains(".S")
|
||||||
addSourceFile(filepath.replace(modulepath + File.separator, ""), null);
|
|| filepath.contains(".i") || filepath.contains(".asm")) {
|
||||||
|
addSourceFile(filepath.replace(modulepath + File.separator, ""),
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean isModule(String path) {
|
public static final boolean isModule(String path) {
|
||||||
String[] list = new File(path).list();
|
String[] list = new File(path).list();
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
if (!new File(list[i]).isDirectory()) {
|
if (!new File(list[i]).isDirectory()) {
|
||||||
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -12,23 +12,37 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
import java.util.regex.*;
|
import java.io.FileReader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.tianocore.*;
|
import org.tianocore.FilenameDocument;
|
||||||
|
import org.tianocore.ModuleSurfaceAreaDocument;
|
||||||
|
import org.tianocore.MsaHeaderDocument;
|
||||||
|
import org.tianocore.SourceFilesDocument;
|
||||||
|
|
||||||
public final class ModuleReader implements Common.ForDoAll {
|
public final class ModuleReader implements Common.ForDoAll {
|
||||||
private static final ModuleReader modulereader = new ModuleReader();
|
private static final ModuleReader modulereader = new ModuleReader();
|
||||||
|
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
|
|
||||||
private final CommentLaplace commentlaplace = new CommentLaplace();
|
private final CommentLaplace commentlaplace = new CommentLaplace();
|
||||||
|
|
||||||
private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
private static final Pattern ptninfequation = Pattern
|
||||||
private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
||||||
|
|
||||||
|
private static final Pattern ptnsection = Pattern.compile(
|
||||||
|
"\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
||||||
|
|
||||||
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
||||||
|
|
||||||
public final void ModuleScan() throws Exception {
|
public final void ModuleScan() throws Exception {
|
||||||
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
|
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll",
|
||||||
|
String.class), mi, null, Common.FILE);
|
||||||
|
|
||||||
// inf&msa
|
// inf&msa
|
||||||
String filename = null;
|
String filename = null;
|
||||||
@ -37,9 +51,11 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else {
|
} else {
|
||||||
if (mi.msaorinf.size() == 1) {
|
if (mi.msaorinf.size() == 1) {
|
||||||
filename = (String)mi.msaorinf.toArray()[0];
|
filename = (String) mi.msaorinf.toArray()[0];
|
||||||
} else {
|
} else {
|
||||||
filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());
|
filename = MigrationTool.ui.choose(
|
||||||
|
"Found .inf or .msa file for module\n" + mi.modulepath
|
||||||
|
+ "\nChoose one Please", mi.msaorinf.toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +70,10 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void readMsa(String name) throws Exception {
|
private final void readMsa(String name) throws Exception {
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
|
.parse(new File(mi.modulepath + File.separator + name));
|
||||||
|
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc
|
||||||
|
.getModuleSurfaceArea();
|
||||||
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
||||||
|
|
||||||
mi.modulename = msaheader.getModuleName();
|
mi.modulename = msaheader.getModuleName();
|
||||||
@ -65,13 +83,15 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
||||||
|
|
||||||
String temp;
|
String temp;
|
||||||
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
|
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList()
|
||||||
|
.iterator();
|
||||||
while (li.hasNext()) {
|
while (li.hasNext()) {
|
||||||
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
||||||
System.out.println("Source File Missing! : " + temp);
|
System.out.println("Source File Missing! : " + temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String extractLicense(String wholeline) throws Exception {
|
private final String extractLicense(String wholeline) throws Exception {
|
||||||
String tempLine;
|
String tempLine;
|
||||||
String license = null;
|
String license = null;
|
||||||
@ -84,16 +104,18 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
// Find license info.
|
// Find license info.
|
||||||
//
|
//
|
||||||
license = "";
|
license = "";
|
||||||
while ((tempLine = rd.readLine())!= null) {
|
while ((tempLine = rd.readLine()) != null) {
|
||||||
if (!tempLine.contains("#") ||
|
if (!tempLine.contains("#")
|
||||||
tempLine.contains("Module Name:") ||
|
|| tempLine.contains("Module Name:")
|
||||||
tempLine.contains("Abstract:")) {
|
|| tempLine.contains("Abstract:")) {
|
||||||
//
|
//
|
||||||
// We assume license ends here.
|
// We assume license ends here.
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
license += " " + tempLine.replaceAll("\\s*[#]\\s*(.*)", "$1\n");
|
license += " "
|
||||||
|
+ tempLine
|
||||||
|
.replaceAll("\\s*[#]\\s*(.*)", "$1\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -134,8 +156,10 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
mi.entrypoint = mtrinfequation.group(2);
|
mi.entrypoint = mtrinfequation.group(2);
|
||||||
}
|
}
|
||||||
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
||||||
if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
|
if (!mi.localmodulesources.contains(mtrinfequation
|
||||||
MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));
|
.group(2))) {
|
||||||
|
MigrationTool.ui.println("DPX File Missing! : "
|
||||||
|
+ mtrinfequation.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +169,9 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
while (mtrfilename.find()) {
|
while (mtrfilename.find()) {
|
||||||
mi.infsources.add(mtrfilename.group());
|
mi.infsources.add(mtrfilename.group());
|
||||||
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
||||||
MigrationTool.ui.println("Warn: Source File Missing! : " + mtrfilename.group());
|
MigrationTool.ui
|
||||||
|
.println("Warn: Source File Missing! : "
|
||||||
|
+ mtrfilename.group());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +186,9 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
|
|
||||||
private final void preProcessModule() throws Exception {
|
private final void preProcessModule() throws Exception {
|
||||||
// according to .inf file, add extraordinary includes and sourcefiles
|
// according to .inf file, add extraordinary includes and sourcefiles
|
||||||
Common.dirCopy(mi.modulepath, mi.temppath); // collect all Laplace.namechange to here???
|
Common.dirCopy(mi.modulepath, mi.temppath); // collect all
|
||||||
|
// Laplace.namechange to
|
||||||
|
// here???
|
||||||
|
|
||||||
if (!mi.infincludes.isEmpty()) {
|
if (!mi.infincludes.isEmpty()) {
|
||||||
Iterator<String> it = mi.infincludes.iterator();
|
Iterator<String> it = mi.infincludes.iterator();
|
||||||
@ -170,9 +198,13 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
if (tempincludename.contains("..")) {
|
if (tempincludename.contains("..")) {
|
||||||
Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
|
Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
|
||||||
if (mtr.find() && !mtr.group(2).matches(".")) {
|
if (mtr.find() && !mtr.group(2).matches(".")) {
|
||||||
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath, ".h");
|
Common.oneLevelDirCopy(mi.modulepath.replaceAll(
|
||||||
|
Common.STRSEPARATER, "$1")
|
||||||
|
+ File.separator + mtr.group(2), mi.temppath,
|
||||||
|
".h");
|
||||||
} else {
|
} else {
|
||||||
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.temppath, ".h");
|
Common.oneLevelDirCopy(mi.modulepath.replaceAll(
|
||||||
|
Common.STRSEPARATER, "$1"), mi.temppath, ".h");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,10 +215,15 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
tempsourcename = it.next();
|
tempsourcename = it.next();
|
||||||
if (tempsourcename.contains("..")) {
|
if (tempsourcename.contains("..")) {
|
||||||
Common.ensureDir(mi.temppath + File.separator + "MT_Parent_Sources");
|
Common.ensureDir(mi.temppath + File.separator
|
||||||
|
+ "MT_Parent_Sources");
|
||||||
Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);
|
Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);
|
||||||
if (mtr.find()) {
|
if (mtr.find()) {
|
||||||
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));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,7 +251,8 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
|
|
||||||
ii = mi.preprocessedccodes.iterator();
|
ii = mi.preprocessedccodes.iterator();
|
||||||
|
|
||||||
Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);
|
Pattern patefifuncc = Pattern.compile(
|
||||||
|
"g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)", Pattern.MULTILINE);
|
||||||
Matcher matguid;
|
Matcher matguid;
|
||||||
Matcher matfuncc;
|
Matcher matfuncc;
|
||||||
Matcher matfuncd;
|
Matcher matfuncd;
|
||||||
@ -225,23 +263,40 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
while (ii.hasNext()) {
|
while (ii.hasNext()) {
|
||||||
StringBuffer wholefile = new StringBuffer();
|
StringBuffer wholefile = new StringBuffer();
|
||||||
ifile = ii.next();
|
ifile = ii.next();
|
||||||
rd = new BufferedReader(new FileReader(mi.temppath + File.separator + ifile));
|
rd = new BufferedReader(new FileReader(mi.temppath + File.separator
|
||||||
|
+ ifile));
|
||||||
while ((line = rd.readLine()) != null) {
|
while ((line = rd.readLine()) != null) {
|
||||||
wholefile.append(line + '\n');
|
wholefile.append(line + '\n');
|
||||||
}
|
}
|
||||||
line = wholefile.toString();
|
line = wholefile.toString();
|
||||||
|
|
||||||
// find guid
|
// find guid
|
||||||
matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :
|
matguid = Guid.ptnguid.matcher(line); // several ways to implement
|
||||||
while (matguid.find()) { // 1.currently , find once , then call to identify which is it
|
// this , which one is
|
||||||
if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use 3 different matchers , search 3 times to find each
|
// faster ? :
|
||||||
//matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost
|
while (matguid.find()) { // 1.currently , find once , then call
|
||||||
|
// to identify which is it
|
||||||
|
if ((temp = Guid.register(matguid, mi, MigrationTool.db)) != null) { // 2.use
|
||||||
|
// 3
|
||||||
|
// different
|
||||||
|
// matchers
|
||||||
|
// ,
|
||||||
|
// search
|
||||||
|
// 3
|
||||||
|
// times
|
||||||
|
// to
|
||||||
|
// find
|
||||||
|
// each
|
||||||
|
// matguid.appendReplacement(result,
|
||||||
|
// MigrationTool.db.getR9Guidname(temp)); // search the
|
||||||
|
// database for all 3 kinds of guids , high cost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//matguid.appendTail(result);
|
// matguid.appendTail(result);
|
||||||
//line = result.toString();
|
// line = result.toString();
|
||||||
|
|
||||||
// find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed
|
// find EFI call in form of '->' , many
|
||||||
|
// 'gUnicodeCollationInterface->' like things are not changed
|
||||||
// This item is not simply replaced , special operation is required.
|
// This item is not simply replaced , special operation is required.
|
||||||
matefifuncc = patefifuncc.matcher(line);
|
matefifuncc = patefifuncc.matcher(line);
|
||||||
while (matefifuncc.find()) {
|
while (matefifuncc.find()) {
|
||||||
@ -252,12 +307,13 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
matfuncc = Func.ptnfuncc.matcher(line);
|
matfuncc = Func.ptnfuncc.matcher(line);
|
||||||
while (matfuncc.find()) {
|
while (matfuncc.find()) {
|
||||||
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
||||||
//MigrationTool.ui.println(ifile + " dofunc " + temp);
|
// MigrationTool.ui.println(ifile + " dofunc " + temp);
|
||||||
//matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));
|
// matfuncc.appendReplacement(result,
|
||||||
|
// MigrationTool.db.getR9Func(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//matfuncc.appendTail(result);
|
// matfuncc.appendTail(result);
|
||||||
//line = result.toString();
|
// line = result.toString();
|
||||||
|
|
||||||
// find macro
|
// find macro
|
||||||
matmacro = Macro.ptntmacro.matcher(line);
|
matmacro = Macro.ptntmacro.matcher(line);
|
||||||
@ -282,8 +338,10 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
// op on hash
|
// op on hash
|
||||||
Iterator<String> funcci = mi.hashfuncc.iterator();
|
Iterator<String> funcci = mi.hashfuncc.iterator();
|
||||||
while (funcci.hasNext()) {
|
while (funcci.hasNext()) {
|
||||||
if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {
|
if (!mi.hashfuncd.contains(temp = funcci.next())
|
||||||
mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items
|
&& !mi.hashEFIcall.contains(temp)) {
|
||||||
|
mi.hashnonlocalfunc.add(temp); // this set contains both
|
||||||
|
// changed and not changed items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,10 +356,13 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
Matcher mtrincludefile = null;
|
Matcher mtrincludefile = null;
|
||||||
while (mtrinclude.find()) {
|
while (mtrinclude.find()) {
|
||||||
mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));
|
mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));
|
||||||
if (mtrincludefile.find() && mi.localmodulesources.contains(mtrincludefile.group(1))) {
|
if (mtrincludefile.find()
|
||||||
|
&& mi.localmodulesources.contains(mtrincludefile
|
||||||
|
.group(1))) {
|
||||||
templine = mtrinclude.group();
|
templine = mtrinclude.group();
|
||||||
} else {
|
} else {
|
||||||
templine = MigrationTool.MIGRATIONCOMMENT + mtrinclude.group();
|
templine = MigrationTool.MIGRATIONCOMMENT
|
||||||
|
+ mtrinclude.group();
|
||||||
}
|
}
|
||||||
mtrinclude.appendReplacement(wholebuffer, templine);
|
mtrinclude.appendReplacement(wholebuffer, templine);
|
||||||
}
|
}
|
||||||
@ -310,7 +371,8 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
public boolean recognize(String filename) {
|
||||||
return filename.contains(".c") || filename.contains(".h") || filename.contains(".dxs");
|
return filename.contains(".c") || filename.contains(".h")
|
||||||
|
|| filename.contains(".dxs");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
public String namechange(String oldname) {
|
||||||
@ -318,9 +380,10 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
public void run(String filepath) throws Exception {
|
public void run(String filepath) throws Exception {
|
||||||
String name = mi.temppath + File.separator + filepath.replace(mi.temppath + File.separator, "");
|
String name = mi.temppath + File.separator
|
||||||
|
+ filepath.replace(mi.temppath + File.separator, "");
|
||||||
if (commentlaplace.recognize(name)) {
|
if (commentlaplace.recognize(name)) {
|
||||||
commentlaplace.transform(name, name);
|
commentlaplace.transform(name, name);
|
||||||
}
|
}
|
||||||
@ -329,7 +392,8 @@ public final class ModuleReader implements Common.ForDoAll {
|
|||||||
public boolean filter(File dir) {
|
public boolean filter(File dir) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
|
||||||
public final void setModuleInfo(ModuleInfo m) {
|
public final void setModuleInfo(ModuleInfo m) {
|
||||||
mi = m;
|
mi = m;
|
||||||
|
@ -14,71 +14,109 @@ package org.tianocore.migration;
|
|||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.tianocore.*;
|
import org.tianocore.ExternsDocument;
|
||||||
|
import org.tianocore.FilenameDocument;
|
||||||
|
import org.tianocore.GuidsDocument;
|
||||||
|
import org.tianocore.LibraryClassDefinitionsDocument;
|
||||||
|
import org.tianocore.LibraryClassDocument;
|
||||||
|
import org.tianocore.LicenseDocument;
|
||||||
|
import org.tianocore.ModuleDefinitionsDocument;
|
||||||
|
import org.tianocore.ModuleSurfaceAreaDocument;
|
||||||
|
import org.tianocore.ModuleTypeDef;
|
||||||
|
import org.tianocore.MsaHeaderDocument;
|
||||||
|
import org.tianocore.PPIsDocument;
|
||||||
|
import org.tianocore.PackageDependenciesDocument;
|
||||||
|
import org.tianocore.ProtocolsDocument;
|
||||||
|
import org.tianocore.SourceFilesDocument;
|
||||||
|
import org.tianocore.SupportedArchitectures;
|
||||||
|
import org.tianocore.UsageTypes;
|
||||||
import org.tianocore.SupportedArchitectures.Enum;
|
import org.tianocore.SupportedArchitectures.Enum;
|
||||||
|
|
||||||
public class MsaOwner {
|
public class MsaOwner {
|
||||||
public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";
|
public static final String COPYRIGHT = "Copyright (c) 2006, Intel Corporation";
|
||||||
|
|
||||||
public static final String VERSION = "1.0";
|
public static final String VERSION = "1.0";
|
||||||
|
|
||||||
public static final String ABSTRACT = "Component name for module ";
|
public static final String ABSTRACT = "Component name for module ";
|
||||||
|
|
||||||
public static final String DESCRIPTION = "FIX ME!";
|
public static final String DESCRIPTION = "FIX ME!";
|
||||||
public static final String LICENSE = "All rights reserved.\n" +
|
|
||||||
" This software and associated documentation (if any) is furnished\n" +
|
public static final String LICENSE = "All rights reserved.\n"
|
||||||
" under a license and may only be used or copied in accordance\n" +
|
+ " This software and associated documentation (if any) is furnished\n"
|
||||||
" with the terms of the license. Except as permitted by such\n" +
|
+ " under a license and may only be used or copied in accordance\n"
|
||||||
" license, no part of this software or documentation may be\n" +
|
+ " with the terms of the license. Except as permitted by such\n"
|
||||||
" reproduced, stored in a retrieval system, or transmitted in any\n" +
|
+ " license, no part of this software or documentation may be\n"
|
||||||
" form or by any means without the express written consent of\n" +
|
+ " reproduced, stored in a retrieval system, or transmitted in any\n"
|
||||||
" Intel Corporation.";
|
+ " form or by any means without the express written consent of\n"
|
||||||
|
+ " Intel Corporation.";
|
||||||
|
|
||||||
public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
|
public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
|
||||||
|
|
||||||
public static final Enum IA32 = SupportedArchitectures.IA_32;
|
public static final Enum IA32 = SupportedArchitectures.IA_32;
|
||||||
|
|
||||||
public static final Enum X64 = SupportedArchitectures.X_64;
|
public static final Enum X64 = SupportedArchitectures.X_64;
|
||||||
|
|
||||||
public static final Enum IPF = SupportedArchitectures.IPF;
|
public static final Enum IPF = SupportedArchitectures.IPF;
|
||||||
|
|
||||||
public static final Enum EBC = SupportedArchitectures.EBC;
|
public static final Enum EBC = SupportedArchitectures.EBC;
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
|
.newInstance();
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
|
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
|
||||||
|
|
||||||
private MsaHeaderDocument.MsaHeader msaheader = null;
|
private MsaHeaderDocument.MsaHeader msaheader = null;
|
||||||
|
|
||||||
private LicenseDocument.License license = null;
|
private LicenseDocument.License license = null;
|
||||||
|
|
||||||
private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
|
private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
|
||||||
private SourceFilesDocument.SourceFiles sourcefiles = null; //found local .h files are not written
|
|
||||||
|
private SourceFilesDocument.SourceFiles sourcefiles = null; // found local
|
||||||
|
// .h files are
|
||||||
|
// not written
|
||||||
|
|
||||||
private GuidsDocument.Guids guids = null;
|
private GuidsDocument.Guids guids = null;
|
||||||
|
|
||||||
private ProtocolsDocument.Protocols protocols = null;
|
private ProtocolsDocument.Protocols protocols = null;
|
||||||
|
|
||||||
private PPIsDocument.PPIs ppis = null;
|
private PPIsDocument.PPIs ppis = null;
|
||||||
|
|
||||||
private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
|
private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
|
||||||
|
|
||||||
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
|
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
|
||||||
|
|
||||||
private ExternsDocument.Externs externs = null;
|
private ExternsDocument.Externs externs = null;
|
||||||
|
|
||||||
private List<Enum> listarch = new ArrayList<Enum>();
|
private List<Enum> listarch = new ArrayList<Enum>();
|
||||||
//private Map<String, Enum> mapfilenames = new HashMap<String, Enum>(); //this need to be installed manually when msa is to be written
|
|
||||||
//private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String, UsageTypes.Enum>();
|
|
||||||
|
|
||||||
//-----------------------------msaheader-------------------------------------//
|
// private Map<String, Enum> mapfilenames = new HashMap<String, Enum>();
|
||||||
|
// //this need to be installed manually when msa is to be written
|
||||||
|
// private Map<String, UsageTypes.Enum> mapprotocols = new HashMap<String,
|
||||||
|
// UsageTypes.Enum>();
|
||||||
|
|
||||||
public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {
|
// -----------------------------msaheader-------------------------------------//
|
||||||
|
|
||||||
|
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
||||||
/*
|
/*
|
||||||
if (!libclassdefs.getLibraryClassList().contains(name)) {
|
* if (!libclassdefs.getLibraryClassList().contains(name)) {
|
||||||
LibraryClassDocument.LibraryClass classname;
|
* LibraryClassDocument.LibraryClass classname; classname =
|
||||||
classname = libclassdefs.addNewLibraryClass();
|
* libclassdefs.addNewLibraryClass(); classname.setKeyword(name);
|
||||||
classname.setKeyword(name);
|
* classname.setUsage(usage); return true; } else { return false; }
|
||||||
classname.setUsage(usage);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();
|
Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs
|
||||||
|
.getLibraryClassList().iterator();
|
||||||
while (classit.hasNext()) {
|
while (classit.hasNext()) {
|
||||||
if (classit.next().getKeyword().matches(name)) {
|
if (classit.next().getKeyword().matches(name)) {
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate LibraryClass");
|
// MigrationTool.ui.println ("Warning: Duplicate
|
||||||
|
// LibraryClass");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,15 +130,16 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
|
public final boolean addGuid(String guidname, UsageTypes.Enum usage) {
|
||||||
if (guids == null) {
|
if (guids == null) {
|
||||||
guids = msa.addNewGuids();
|
guids = msa.addNewGuids();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();
|
Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids
|
||||||
|
.getGuidCNamesList().iterator();
|
||||||
while (guidit.hasNext()) {
|
while (guidit.hasNext()) {
|
||||||
if (guidit.next().getGuidCName() == guidname) {
|
if (guidit.next().getGuidCName() == guidname) {
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Guid");
|
// MigrationTool.ui.println ("Warning: Duplicate Guid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +151,7 @@ public class MsaOwner {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {
|
||||||
public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
|
|
||||||
if (ppis == null) {
|
if (ppis == null) {
|
||||||
ppis = msa.addNewPPIs();
|
ppis = msa.addNewPPIs();
|
||||||
}
|
}
|
||||||
@ -121,7 +159,7 @@ public class MsaOwner {
|
|||||||
Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
|
Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
|
||||||
while (ppiit.hasNext()) {
|
while (ppiit.hasNext()) {
|
||||||
if (ppiit.next().getPpiCName() == ppiname) {
|
if (ppiit.next().getPpiCName() == ppiname) {
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Ppi");
|
// MigrationTool.ui.println ("Warning: Duplicate Ppi");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,15 +171,16 @@ public class MsaOwner {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
|
public final boolean addProtocol(String proname, UsageTypes.Enum usage) {
|
||||||
if (protocols == null) {
|
if (protocols == null) {
|
||||||
protocols = msa.addNewProtocols();
|
protocols = msa.addNewProtocols();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();
|
Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols
|
||||||
|
.getProtocolList().iterator();
|
||||||
while (proit.hasNext()) {
|
while (proit.hasNext()) {
|
||||||
if (proit.next().getProtocolCName() == proname) {
|
if (proit.next().getProtocolCName() == proname) {
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Protocol");
|
// MigrationTool.ui.println ("Warning: Duplicate Protocol");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,11 +192,12 @@ public class MsaOwner {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addSourceFile (String name, Enum en) {
|
public final boolean addSourceFile(String name, Enum en) {
|
||||||
Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();
|
Iterator<FilenameDocument.Filename> fileit = sourcefiles
|
||||||
|
.getFilenameList().iterator();
|
||||||
while (fileit.hasNext()) {
|
while (fileit.hasNext()) {
|
||||||
if (fileit.next().getStringValue() == name) {
|
if (fileit.next().getStringValue() == name) {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate SourceFileName");
|
MigrationTool.ui.println("Warning: Duplicate SourceFileName");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,13 +213,13 @@ public class MsaOwner {
|
|||||||
|
|
||||||
// entry point todo
|
// entry point todo
|
||||||
|
|
||||||
public final boolean setupExternSpecification () {
|
public final boolean setupExternSpecification() {
|
||||||
addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
|
addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
|
||||||
addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
|
addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addExternSpecification (String specification) {
|
public final boolean addExternSpecification(String specification) {
|
||||||
if (externs.getSpecificationList().contains(specification)) {
|
if (externs.getSpecificationList().contains(specification)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -200,7 +240,7 @@ public class MsaOwner {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addPackage (String guid) {
|
public final boolean addPackage(String guid) {
|
||||||
if (packagedependencies.getPackageList().contains(guid)) {
|
if (packagedependencies.getPackageList().contains(guid)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -209,12 +249,14 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
|
public final boolean setupModuleDefinitions() { // ????????? give this job
|
||||||
|
// to moduleinfo
|
||||||
moduledefinitions.setBinaryModule(false);
|
moduledefinitions.setBinaryModule(false);
|
||||||
moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
|
moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public final boolean addSupportedArchitectures (Enum arch) {
|
|
||||||
|
public final boolean addSupportedArchitectures(Enum arch) {
|
||||||
if (listarch.contains(arch)) {
|
if (listarch.contains(arch)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -223,7 +265,7 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addSpecification (String specification) {
|
public final boolean addSpecification(String specification) {
|
||||||
if (msaheader.getSpecification() == null) {
|
if (msaheader.getSpecification() == null) {
|
||||||
if (specification == null) {
|
if (specification == null) {
|
||||||
msaheader.setSpecification(SPECIFICATION);
|
msaheader.setSpecification(SPECIFICATION);
|
||||||
@ -232,12 +274,12 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Specification");
|
MigrationTool.ui.println("Warning: Duplicate Specification");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addLicense (String licensecontent) {
|
public final boolean addLicense(String licensecontent) {
|
||||||
if (msaheader.getLicense() == null) {
|
if (msaheader.getLicense() == null) {
|
||||||
license = msaheader.addNewLicense();
|
license = msaheader.addNewLicense();
|
||||||
if (licensecontent == null) {
|
if (licensecontent == null) {
|
||||||
@ -247,12 +289,12 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate License");
|
MigrationTool.ui.println("Warning: Duplicate License");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addDescription (String description) {
|
public final boolean addDescription(String description) {
|
||||||
if (msaheader.getDescription() == null) {
|
if (msaheader.getDescription() == null) {
|
||||||
if (description == null) {
|
if (description == null) {
|
||||||
msaheader.setDescription(DESCRIPTION);
|
msaheader.setDescription(DESCRIPTION);
|
||||||
@ -261,12 +303,12 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Description");
|
MigrationTool.ui.println("Warning: Duplicate Description");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addAbstract (String abs) {
|
public final boolean addAbstract(String abs) {
|
||||||
if (msaheader.getAbstract() == null) {
|
if (msaheader.getAbstract() == null) {
|
||||||
if (abs == null) {
|
if (abs == null) {
|
||||||
msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
|
msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
|
||||||
@ -275,12 +317,12 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Abstract");
|
MigrationTool.ui.println("Warning: Duplicate Abstract");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addVersion (String version) {
|
public final boolean addVersion(String version) {
|
||||||
if (msaheader.getVersion() == null) {
|
if (msaheader.getVersion() == null) {
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
msaheader.setVersion(VERSION);
|
msaheader.setVersion(VERSION);
|
||||||
@ -289,12 +331,12 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Version");
|
MigrationTool.ui.println("Warning: Duplicate Version");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addCopyRight (String copyright) {
|
public final boolean addCopyRight(String copyright) {
|
||||||
if (msaheader.getCopyright() == null) {
|
if (msaheader.getCopyright() == null) {
|
||||||
if (copyright == null) {
|
if (copyright == null) {
|
||||||
msaheader.setCopyright(COPYRIGHT);
|
msaheader.setCopyright(COPYRIGHT);
|
||||||
@ -303,43 +345,44 @@ public class MsaOwner {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate CopyRight");
|
MigrationTool.ui.println("Warning: Duplicate CopyRight");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addModuleType (String moduletype) {
|
public final boolean addModuleType(String moduletype) {
|
||||||
if (msaheader.getModuleType() == null) {
|
if (msaheader.getModuleType() == null) {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate ModuleType");
|
MigrationTool.ui.println("Warning: Duplicate ModuleType");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addGuidValue (String guidvalue) {
|
public final boolean addGuidValue(String guidvalue) {
|
||||||
if (msaheader.getGuidValue() == null) {
|
if (msaheader.getGuidValue() == null) {
|
||||||
msaheader.setGuidValue(guidvalue);
|
msaheader.setGuidValue(guidvalue);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate GuidValue");
|
MigrationTool.ui.println("Warning: Duplicate GuidValue");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean addModuleName (String modulename) {
|
public final boolean addModuleName(String modulename) {
|
||||||
if (msaheader.getModuleName() == null) {
|
if (msaheader.getModuleName() == null) {
|
||||||
msaheader.setModuleName(modulename);
|
msaheader.setModuleName(modulename);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
MigrationTool.ui.println ("Warning: Duplicate ModuleName");
|
MigrationTool.ui.println("Warning: Duplicate ModuleName");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-----------------------------msaheader-------------------------------------//
|
|
||||||
|
|
||||||
private final void fullfill () throws Exception {
|
// -----------------------------msaheader-------------------------------------//
|
||||||
|
|
||||||
|
private final void fullfill() throws Exception {
|
||||||
addCopyRight(null);
|
addCopyRight(null);
|
||||||
addVersion(null);
|
addVersion(null);
|
||||||
addAbstract(null);
|
addAbstract(null);
|
||||||
@ -363,7 +406,7 @@ public class MsaOwner {
|
|||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final MsaOwner init () {
|
private final MsaOwner init() {
|
||||||
msa = msadoc.addNewModuleSurfaceArea();
|
msa = msadoc.addNewModuleSurfaceArea();
|
||||||
msaheader = msa.addNewMsaHeader();
|
msaheader = msa.addNewMsaHeader();
|
||||||
moduledefinitions = msa.addNewModuleDefinitions();
|
moduledefinitions = msa.addNewModuleDefinitions();
|
||||||
|
@ -1,11 +1,31 @@
|
|||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ActionEvent;
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.tree.*;
|
import java.awt.event.MouseAdapter;
|
||||||
import javax.xml.parsers.*;
|
import java.awt.event.MouseEvent;
|
||||||
import org.w3c.dom.*;
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
import javax.swing.tree.TreeSelectionModel;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
public class MsaTreeEditor extends JPanel {
|
public class MsaTreeEditor extends JPanel {
|
||||||
/**
|
/**
|
||||||
@ -19,12 +39,13 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
|
|
||||||
tree = new JTree(treeModel);
|
tree = new JTree(treeModel);
|
||||||
tree.setEditable(true);
|
tree.setEditable(true);
|
||||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
tree.getSelectionModel().setSelectionMode(
|
||||||
|
TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
tree.setShowsRootHandles(false);
|
tree.setShowsRootHandles(false);
|
||||||
tree.addMouseListener(mouseadapter);
|
tree.addMouseListener(mouseadapter);
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(tree);
|
JScrollPane scrollPane = new JScrollPane(tree);
|
||||||
//scrollPane.setSize(800, 600);
|
// scrollPane.setSize(800, 600);
|
||||||
add(scrollPane);
|
add(scrollPane);
|
||||||
|
|
||||||
popupmenu = new JPopupMenu();
|
popupmenu = new JPopupMenu();
|
||||||
@ -38,25 +59,33 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
menuitemdel.addActionListener(actionListener);
|
menuitemdel.addActionListener(actionListener);
|
||||||
menuitemedit.addActionListener(actionListener);
|
menuitemedit.addActionListener(actionListener);
|
||||||
|
|
||||||
genDomTree(MigrationTool.ui.getFilepath("Select a msa file", JFileChooser.FILES_AND_DIRECTORIES));
|
genDomTree(MigrationTool.ui.getFilepath("Select a msa file",
|
||||||
|
JFileChooser.FILES_AND_DIRECTORIES));
|
||||||
}
|
}
|
||||||
|
|
||||||
//private ModuleSurfaceAreaDocument msadoc;
|
// private ModuleSurfaceAreaDocument msadoc;
|
||||||
|
|
||||||
private JTree tree;
|
private JTree tree;
|
||||||
|
|
||||||
private DefaultMutableTreeNode rootNode;
|
private DefaultMutableTreeNode rootNode;
|
||||||
|
|
||||||
private DefaultTreeModel treeModel;
|
private DefaultTreeModel treeModel;
|
||||||
|
|
||||||
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
||||||
|
|
||||||
private JPopupMenu popupmenu;
|
private JPopupMenu popupmenu;
|
||||||
|
|
||||||
private MouseAdapter mouseadapter = new MouseAdapter() {
|
private MouseAdapter mouseadapter = new MouseAdapter() {
|
||||||
public void mouseReleased(MouseEvent me) {
|
public void mouseReleased(MouseEvent me) {
|
||||||
if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {
|
if (me.getClickCount() == 1
|
||||||
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));
|
&& SwingUtilities.isRightMouseButton(me)) {
|
||||||
|
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me
|
||||||
|
.getY()));
|
||||||
popupmenu.show(tree, me.getX(), me.getY());
|
popupmenu.show(tree, me.getX(), me.getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private ActionListener actionListener = new ActionListener() {
|
private ActionListener actionListener = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ae) {
|
public void actionPerformed(ActionEvent ae) {
|
||||||
if (ae.getSource() == menuitemadd) {
|
if (ae.getSource() == menuitemadd) {
|
||||||
@ -70,22 +99,28 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private void editNode() {
|
private void editNode() {
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent());
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) (tree
|
||||||
Element element = (Element)node.getUserObject();
|
.getSelectionPath().getLastPathComponent());
|
||||||
|
Element element = (Element) node.getUserObject();
|
||||||
System.out.println(element.getTextContent());
|
System.out.println(element.getTextContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void delNode() {
|
private void delNode() {
|
||||||
treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));
|
treeModel.removeNodeFromParent((DefaultMutableTreeNode) (tree
|
||||||
|
.getSelectionPath().getLastPathComponent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNode() {
|
private void addNode() {
|
||||||
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));
|
addNode((DefaultMutableTreeNode) (tree.getSelectionPath()
|
||||||
|
.getLastPathComponent()), MigrationTool.ui
|
||||||
|
.getInput("Input Node Name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, Object child) {
|
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode,
|
||||||
|
Object child) {
|
||||||
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
||||||
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
treeModel.insertNodeInto(childNode, parentNode, parentNode
|
||||||
|
.getChildCount());
|
||||||
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||||
return childNode;
|
return childNode;
|
||||||
}
|
}
|
||||||
@ -95,9 +130,10 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
System.out.println("elem");
|
System.out.println("elem");
|
||||||
curNode = addNode(parentNode, node);
|
curNode = addNode(parentNode, node);
|
||||||
} else if (node.getNodeType() == Node.DOCUMENT_NODE){
|
} else if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||||
System.out.println("doc");
|
System.out.println("doc");
|
||||||
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with Root Node?
|
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with
|
||||||
|
// Root Node?
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList nodelist = node.getChildNodes();
|
NodeList nodelist = node.getChildNodes();
|
||||||
@ -107,7 +143,8 @@ public class MsaTreeEditor extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void genDomTree(String filename) throws Exception {
|
private final void genDomTree(String filename) throws Exception {
|
||||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
|
||||||
|
.newDocumentBuilder();
|
||||||
Document document = builder.parse(filename);
|
Document document = builder.parse(filename);
|
||||||
handleNode(document, rootNode);
|
handleNode(document, rootNode);
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,34 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedReader;
|
||||||
import java.util.*;
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.tianocore.*;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
|
import org.tianocore.ExternsDocument;
|
||||||
|
import org.tianocore.FilenameDocument;
|
||||||
|
import org.tianocore.GuidsDocument;
|
||||||
|
import org.tianocore.LibraryClassDefinitionsDocument;
|
||||||
|
import org.tianocore.LibraryClassDocument;
|
||||||
|
import org.tianocore.ModuleDefinitionsDocument;
|
||||||
|
import org.tianocore.ModuleSurfaceAreaDocument;
|
||||||
|
import org.tianocore.ModuleTypeDef;
|
||||||
|
import org.tianocore.MsaHeaderDocument;
|
||||||
|
import org.tianocore.PPIsDocument;
|
||||||
|
import org.tianocore.PackageDependenciesDocument;
|
||||||
|
import org.tianocore.ProtocolsDocument;
|
||||||
|
import org.tianocore.SourceFilesDocument;
|
||||||
|
import org.tianocore.SupportedArchitectures;
|
||||||
|
import org.tianocore.UsageTypes;
|
||||||
import org.tianocore.SupportedArchitectures.Enum;
|
import org.tianocore.SupportedArchitectures.Enum;
|
||||||
import org.apache.xmlbeans.*;
|
|
||||||
|
|
||||||
public class MsaWriter {
|
public class MsaWriter {
|
||||||
MsaWriter(ModuleInfo moduleinfo) {
|
MsaWriter(ModuleInfo moduleinfo) {
|
||||||
@ -25,28 +47,45 @@ public class MsaWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
|
.newInstance();
|
||||||
|
|
||||||
|
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc
|
||||||
|
.addNewModuleSurfaceArea();
|
||||||
|
|
||||||
private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();
|
private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();
|
||||||
private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();
|
|
||||||
private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written
|
private ModuleDefinitionsDocument.ModuleDefinitions md = msa
|
||||||
|
.addNewModuleDefinitions();
|
||||||
|
|
||||||
|
private SourceFilesDocument.SourceFiles sourcefiles = msa
|
||||||
|
.addNewSourceFiles(); // found local .h files are not written
|
||||||
|
|
||||||
private GuidsDocument.Guids guids;
|
private GuidsDocument.Guids guids;
|
||||||
|
|
||||||
private ProtocolsDocument.Protocols protocols;
|
private ProtocolsDocument.Protocols protocols;
|
||||||
|
|
||||||
private PPIsDocument.PPIs ppis;
|
private PPIsDocument.PPIs ppis;
|
||||||
private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();
|
|
||||||
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();
|
private PackageDependenciesDocument.PackageDependencies pd = msa
|
||||||
|
.addNewPackageDependencies();
|
||||||
|
|
||||||
|
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa
|
||||||
|
.addNewLibraryClassDefinitions();
|
||||||
|
|
||||||
private ExternsDocument.Externs externs = msa.addNewExterns();
|
private ExternsDocument.Externs externs = msa.addNewExterns();
|
||||||
|
|
||||||
private String Query (String requirement) throws Exception {
|
private String Query(String requirement) throws Exception {
|
||||||
String answer;
|
String answer;
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println(requirement);
|
System.out.println(requirement);
|
||||||
while ((answer = rd.readLine()).length() == 0) ;
|
while ((answer = rd.readLine()).length() == 0)
|
||||||
|
;
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSourceFiles (String name) { // furthur modification needed
|
private void addSourceFiles(String name) { // furthur modification needed
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
FilenameDocument.Filename filename;
|
FilenameDocument.Filename filename;
|
||||||
filename = sourcefiles.addNewFilename();
|
filename = sourcefiles.addNewFilename();
|
||||||
@ -70,16 +109,19 @@ public class MsaWriter {
|
|||||||
filename.setSupArchList(arch);
|
filename.setSupArchList(arch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWrapper() {
|
private void addWrapper() {
|
||||||
XmlCursor cursor = msa.newCursor();
|
XmlCursor cursor = msa.newCursor();
|
||||||
String uri = "http://www.TianoCore.org/2006/Edk2.0";
|
String uri = "http://www.TianoCore.org/2006/Edk2.0";
|
||||||
cursor.push();
|
cursor.push();
|
||||||
cursor.toNextToken();
|
cursor.toNextToken();
|
||||||
cursor.insertNamespace("", uri);
|
cursor.insertNamespace("", uri);
|
||||||
cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
cursor.insertNamespace("xsi",
|
||||||
|
"http://www.w3.org/2001/XMLSchema-instance");
|
||||||
cursor.pop();
|
cursor.pop();
|
||||||
msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)cursor.getObject();
|
msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) cursor.getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
String temp;
|
String temp;
|
||||||
@ -87,30 +129,39 @@ public class MsaWriter {
|
|||||||
if (mi.modulename != null) {
|
if (mi.modulename != null) {
|
||||||
msaheader.setModuleName(mi.modulename);
|
msaheader.setModuleName(mi.modulename);
|
||||||
} else {
|
} else {
|
||||||
msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
msaheader
|
||||||
|
.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
||||||
}
|
}
|
||||||
if (mi.guidvalue == null) {
|
if (mi.guidvalue == null) {
|
||||||
mi.guidvalue = UUID.randomUUID().toString();
|
mi.guidvalue = UUID.randomUUID().toString();
|
||||||
MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!");
|
MigrationTool.ui
|
||||||
|
.println("Guid value can not be retrieved from inf file. Generate "
|
||||||
|
+ mi.guidvalue + " at random!");
|
||||||
}
|
}
|
||||||
msaheader.setGuidValue(mi.guidvalue);
|
msaheader.setGuidValue(mi.guidvalue);
|
||||||
if (mi.moduletype != null) {
|
if (mi.moduletype != null) {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi
|
||||||
|
.getModuleType()));
|
||||||
} else {
|
} else {
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));
|
msaheader
|
||||||
|
.setModuleType(ModuleTypeDef.Enum
|
||||||
|
.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
msaheader.setCopyright("Copyright (c) 2006, Intel Corporation. All right reserved.");
|
msaheader
|
||||||
|
.setCopyright("Copyright (c) 2006, Intel Corporation. All right reserved.");
|
||||||
msaheader.setVersion("1.0");
|
msaheader.setVersion("1.0");
|
||||||
msaheader.setAbstract("Component name for module " + mi.modulename);
|
msaheader.setAbstract("Component name for module " + mi.modulename);
|
||||||
msaheader.setDescription("FIX ME!");
|
msaheader.setDescription("FIX ME!");
|
||||||
|
|
||||||
if (mi.license == null) {
|
if (mi.license == null) {
|
||||||
mi.license = "FIX ME!";
|
mi.license = "FIX ME!";
|
||||||
MigrationTool.ui.println ("Fail to extract license info in inf file");
|
MigrationTool.ui
|
||||||
|
.println("Fail to extract license info in inf file");
|
||||||
}
|
}
|
||||||
msaheader.addNewLicense().setStringValue(mi.license);
|
msaheader.addNewLicense().setStringValue(mi.license);
|
||||||
msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
msaheader
|
||||||
|
.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
||||||
|
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
arch.add(SupportedArchitectures.IA_32);
|
arch.add(SupportedArchitectures.IA_32);
|
||||||
@ -127,11 +178,14 @@ public class MsaWriter {
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
pd.addNewPackage().setPackageGuid(it.next());
|
pd.addNewPackage().setPackageGuid(it.next());
|
||||||
}
|
}
|
||||||
externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
|
externs.addNewSpecification().setStringValue(
|
||||||
externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
|
"EFI_SPECIFICATION_VERSION 0x00020000");
|
||||||
|
externs.addNewSpecification().setStringValue(
|
||||||
|
"EDK_RELEASE_VERSION 0x00020000");
|
||||||
if (mi.entrypoint != null) {
|
if (mi.entrypoint != null) {
|
||||||
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
||||||
org.tianocore.ModuleTypeDef.Enum moduleType = msaheader.getModuleType();
|
org.tianocore.ModuleTypeDef.Enum moduleType = msaheader
|
||||||
|
.getModuleType();
|
||||||
if (moduleType == ModuleTypeDef.PEIM) {
|
if (moduleType == ModuleTypeDef.PEIM) {
|
||||||
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
||||||
} else {
|
} else {
|
||||||
@ -148,7 +202,8 @@ public class MsaWriter {
|
|||||||
it = mi.protocols.iterator();
|
it = mi.protocols.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null) {
|
if ((temp = it.next()) != null) {
|
||||||
ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();
|
ProtocolsDocument.Protocols.Protocol pr = protocols
|
||||||
|
.addNewProtocol();
|
||||||
pr.setProtocolCName(temp);
|
pr.setProtocolCName(temp);
|
||||||
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
@ -170,7 +225,8 @@ public class MsaWriter {
|
|||||||
it = mi.guids.iterator();
|
it = mi.guids.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null) {
|
if ((temp = it.next()) != null) {
|
||||||
GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();
|
GuidsDocument.Guids.GuidCNames gcn = guids
|
||||||
|
.addNewGuidCNames();
|
||||||
gcn.setGuidCName(temp);
|
gcn.setGuidCName(temp);
|
||||||
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
@ -178,8 +234,10 @@ public class MsaWriter {
|
|||||||
}
|
}
|
||||||
it = mi.hashrequiredr9libs.iterator();
|
it = mi.hashrequiredr9libs.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if ((temp = it.next()) != null && !temp.matches("%") && !temp.matches("n/a")) {
|
if ((temp = it.next()) != null && !temp.matches("%")
|
||||||
LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();
|
&& !temp.matches("n/a")) {
|
||||||
|
LibraryClassDocument.LibraryClass lc = libclassdefs
|
||||||
|
.addNewLibraryClass();
|
||||||
lc.setKeyword(temp);
|
lc.setKeyword(temp);
|
||||||
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
}
|
}
|
||||||
@ -197,14 +255,18 @@ public class MsaWriter {
|
|||||||
options.setSavePrettyPrintIndent(2);
|
options.setSavePrettyPrintIndent(2);
|
||||||
options.setUseDefaultNamespace();
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(
|
||||||
|
MigrationTool.ModuleInfoMap.get(mi) + File.separator
|
||||||
|
+ "Migration_" + mi.modulename + File.separator
|
||||||
|
+ mi.modulename + ".msa"));
|
||||||
fulfillMsadoc().save(bw, options);
|
fulfillMsadoc().save(bw, options);
|
||||||
//MsaTreeEditor.init(mi, ui, msadoc);
|
// MsaTreeEditor.init(mi, ui, msadoc);
|
||||||
bw.flush();
|
bw.flush();
|
||||||
bw.close();
|
bw.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {
|
private static void flush(String path, ModuleSurfaceAreaDocument msadoc)
|
||||||
|
throws Exception {
|
||||||
XmlOptions options = new XmlOptions();
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
options.setCharacterEncoding("UTF-8");
|
||||||
@ -219,7 +281,8 @@ public class MsaWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final void parse(String msafile) throws Exception {
|
public static final void parse(String msafile) throws Exception {
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
|
.parse(msafile);
|
||||||
flush("c:\\temp.msa", msadoc);
|
flush("c:\\temp.msa", msadoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,19 +13,25 @@
|
|||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
public final class PathIterator implements Common.ForDoAll {
|
public final class PathIterator implements Common.ForDoAll {
|
||||||
// this PathIterator is based on HashSet, an thread implementation is required.
|
// this PathIterator is based on HashSet, an thread implementation is
|
||||||
|
// required.
|
||||||
PathIterator(String path, int md) throws Exception {
|
PathIterator(String path, int md) throws Exception {
|
||||||
startpath = path;
|
startpath = path;
|
||||||
mode = md;
|
mode = md;
|
||||||
Common.toDoAll(startpath, this, mode);
|
Common.toDoAll(startpath, this, mode);
|
||||||
it = pathlist.iterator();
|
it = pathlist.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String startpath = null;
|
private String startpath = null;
|
||||||
|
|
||||||
private int mode;
|
private int mode;
|
||||||
|
|
||||||
private HashSet<String> pathlist = new HashSet<String>();
|
private HashSet<String> pathlist = new HashSet<String>();
|
||||||
|
|
||||||
private Iterator<String> it = null;
|
private Iterator<String> it = null;
|
||||||
|
|
||||||
public final void run(String path) throws Exception {
|
public final void run(String path) throws Exception {
|
||||||
|
@ -12,8 +12,13 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.BufferedWriter;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -21,63 +26,58 @@ import org.tianocore.UsageTypes;
|
|||||||
|
|
||||||
public final class SourceFileReplacer implements Common.ForDoAll {
|
public final class SourceFileReplacer implements Common.ForDoAll {
|
||||||
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
||||||
|
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
|
|
||||||
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
||||||
|
|
||||||
// these sets are used only for printing log of the changes in current file
|
// these sets are used only for printing log of the changes in current file
|
||||||
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
||||||
|
|
||||||
private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();
|
private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();
|
||||||
|
|
||||||
private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();
|
||||||
|
|
||||||
private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();
|
||||||
|
|
||||||
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||||
|
|
||||||
private static final Set<String> filer8only = new HashSet<String>();
|
private static final Set<String> filer8only = new HashSet<String>();
|
||||||
|
|
||||||
private static final String[] specialhoblibfunc = {
|
private static final String[] specialhoblibfunc = { "BuildModuleHob",
|
||||||
"BuildModuleHob",
|
"BuildResourceDescriptorHob", "BuildFvHob", "BuildCpuHob",
|
||||||
"BuildResourceDescriptorHob",
|
"BuildGuidDataHob", "BuildStackHob", "BuildBspStoreHob",
|
||||||
"BuildFvHob",
|
"BuildMemoryAllocationHob" };
|
||||||
"BuildCpuHob",
|
|
||||||
"BuildGuidDataHob",
|
private static final String[] peiserviceslibfunc = { "InstallPpi",
|
||||||
"BuildStackHob",
|
"ReInstallPpi", "LocatePpi", "NotifyPpi", "GetBootMode",
|
||||||
"BuildBspStoreHob",
|
"SetBootMode", "GetHobList", "CreateHob", "FfsFindNextVolume",
|
||||||
"BuildMemoryAllocationHob"
|
"FfsFindNextFile", "FfsFindSectionData", "InstallPeiMemory",
|
||||||
};
|
"AllocatePages", "AllocatePool", "PeiResetSystem" };
|
||||||
private static final String[] peiserviceslibfunc = {
|
|
||||||
"InstallPpi",
|
// ---------------------------------------inner
|
||||||
"ReInstallPpi",
|
// classes---------------------------------------//
|
||||||
"LocatePpi",
|
|
||||||
"NotifyPpi",
|
|
||||||
"GetBootMode",
|
|
||||||
"SetBootMode",
|
|
||||||
"GetHobList",
|
|
||||||
"CreateHob",
|
|
||||||
"FfsFindNextVolume",
|
|
||||||
"FfsFindNextFile",
|
|
||||||
"FfsFindSectionData",
|
|
||||||
"InstallPeiMemory",
|
|
||||||
"AllocatePages",
|
|
||||||
"AllocatePool",
|
|
||||||
"PeiResetSystem"
|
|
||||||
};
|
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
|
||||||
private static class r8tor9 {
|
private static class r8tor9 {
|
||||||
r8tor9(String r8, String r9) {
|
r8tor9(String r8, String r9) {
|
||||||
r8thing = r8;
|
r8thing = r8;
|
||||||
r9thing = r9;
|
r9thing = r9;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String r8thing;
|
public String r8thing;
|
||||||
|
|
||||||
public String r9thing;
|
public String r9thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IdleLaplace extends Common.Laplace {
|
private class IdleLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
return replaceLibrary (wholeline, mi.hashmacro);
|
return replaceLibrary(wholeline, mi.hashmacro);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
public boolean recognize(String filename) {
|
||||||
return filename.contains(".h") || filename.contains(".H") || filename.contains(".uni") ||
|
return filename.contains(".h") || filename.contains(".H")
|
||||||
filename.contains(".s") || filename.contains(".S") || filename.contains(".asm") ||
|
|| filename.contains(".uni") || filename.contains(".s")
|
||||||
(!filename.contains(".inf") && filename.contains(".i"));
|
|| filename.contains(".S") || filename.contains(".asm")
|
||||||
|
|| (!filename.contains(".inf") && filename.contains(".i"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
public String namechange(String oldname) {
|
||||||
@ -88,6 +88,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DxsLaplace extends Common.Laplace {
|
private class DxsLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
||||||
@ -110,26 +111,31 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
private class CLaplace extends Common.Laplace {
|
private class CLaplace extends Common.Laplace {
|
||||||
public String operation(String wholeline) {
|
public String operation(String wholeline) {
|
||||||
// remove EFI_DRIVER_ENTRY_POINT
|
// remove EFI_DRIVER_ENTRY_POINT
|
||||||
wholeline = wholeline.replaceAll("(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*\\w(\\w|\\d)*\\s*\\))", MigrationTool.MIGRATIONCOMMENT + " $1");
|
wholeline = wholeline.replaceAll(
|
||||||
|
"(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*\\w(\\w|\\d)*\\s*\\))",
|
||||||
|
MigrationTool.MIGRATIONCOMMENT + " $1");
|
||||||
// redefine module entry point for some self-relocated modules
|
// redefine module entry point for some self-relocated modules
|
||||||
wholeline = wholeline.replaceAll (mi.entrypoint + "([^{]*?})", "_ModuleEntryPoint" + "$1");
|
wholeline = wholeline.replaceAll(mi.entrypoint + "([^{]*?})",
|
||||||
|
"_ModuleEntryPoint" + "$1");
|
||||||
// remove R8 library contractor
|
// remove R8 library contractor
|
||||||
wholeline = wholeline.replaceAll ("(\\b(?:Efi|Dxe)InitializeDriverLib\\b)", MigrationTool.MIGRATIONCOMMENT + " $1");
|
wholeline = wholeline.replaceAll(
|
||||||
|
"(\\b(?:Efi|Dxe)InitializeDriverLib\\b)",
|
||||||
|
MigrationTool.MIGRATIONCOMMENT + " $1");
|
||||||
// Add Library Class for potential reference of gBS, gRT & gDS.
|
// Add Library Class for potential reference of gBS, gRT & gDS.
|
||||||
if (Common.find (wholeline, "\\bg?BS\\b")) {
|
if (Common.find(wholeline, "\\bg?BS\\b")) {
|
||||||
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
||||||
}
|
}
|
||||||
if (Common.find (wholeline, "\\bg?RT\\b")) {
|
if (Common.find(wholeline, "\\bg?RT\\b")) {
|
||||||
mi.hashrequiredr9libs.add ("UefiRuntimeServicesTableLib");
|
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");
|
||||||
}
|
}
|
||||||
if (Common.find (wholeline, "\\bgDS\\b")) {
|
if (Common.find(wholeline, "\\bgDS\\b")) {
|
||||||
mi.hashrequiredr9libs.add ("DxeServicesTableLib");
|
mi.hashrequiredr9libs.add("DxeServicesTableLib");
|
||||||
}
|
}
|
||||||
|
|
||||||
wholeline = replaceLibrary (wholeline, mi.hashnonlocalfunc);
|
wholeline = replaceLibrary(wholeline, mi.hashnonlocalfunc);
|
||||||
wholeline = replaceLibrary (wholeline, mi.hashmacro);
|
wholeline = replaceLibrary(wholeline, mi.hashmacro);
|
||||||
// Converting macro
|
// Converting macro
|
||||||
wholeline = replaceMacro (wholeline, mi.hashnonlocalmacro);
|
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
||||||
|
|
||||||
// Converting guid
|
// Converting guid
|
||||||
replaceGuid(wholeline, mi.guids, "guid", fileguid);
|
replaceGuid(wholeline, mi.guids, "guid", fileguid);
|
||||||
@ -141,16 +147,16 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
//
|
//
|
||||||
// Try to remove PeiServicesTablePointer;
|
// Try to remove PeiServicesTablePointer;
|
||||||
//
|
//
|
||||||
wholeline = dropPeiServicesPointer (wholeline);
|
wholeline = dropPeiServicesPointer(wholeline);
|
||||||
//
|
//
|
||||||
// Drop the possible return Status of Hob building function.
|
// Drop the possible return Status of Hob building function.
|
||||||
//
|
//
|
||||||
wholeline = drophobLibReturnStatus (wholeline);
|
wholeline = drophobLibReturnStatus(wholeline);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Expand obsolete R8 macro.
|
// Expand obsolete R8 macro.
|
||||||
//
|
//
|
||||||
wholeline = replaceObsoleteMacro (wholeline);
|
wholeline = replaceObsoleteMacro(wholeline);
|
||||||
|
|
||||||
show(filefunc, "function");
|
show(filefunc, "function");
|
||||||
show(filemacro, "macro");
|
show(filemacro, "macro");
|
||||||
@ -183,11 +189,15 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
|
||||||
|
|
||||||
//-------------------------------------process functions-------------------------------------//
|
// ---------------------------------------inner
|
||||||
|
// classes---------------------------------------//
|
||||||
|
|
||||||
|
// -------------------------------------process
|
||||||
|
// functions-------------------------------------//
|
||||||
private static final String addincludefile(String wholeline, String hfile) {
|
private static final String addincludefile(String wholeline, String hfile) {
|
||||||
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile
|
||||||
|
+ "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void show(Set<r8tor9> hash, String sh) {
|
private static final void show(Set<r8tor9> hash, String sh) {
|
||||||
@ -197,13 +207,15 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
MigrationTool.ui.print("Converting " + sh + " : ");
|
MigrationTool.ui.print("Converting " + sh + " : ");
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
temp = it.next();
|
temp = it.next();
|
||||||
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");
|
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing
|
||||||
|
+ "] ");
|
||||||
}
|
}
|
||||||
MigrationTool.ui.println("");
|
MigrationTool.ui.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {
|
private static final void replaceGuid(String line, Set<String> hash,
|
||||||
|
String kind, Set<r8tor9> filehash) {
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
String r8thing;
|
String r8thing;
|
||||||
String r9thing;
|
String r9thing;
|
||||||
@ -221,7 +233,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String dropPeiServicesPointer (String wholeline) {
|
private final String dropPeiServicesPointer(String wholeline) {
|
||||||
String peiServicesTablePointer;
|
String peiServicesTablePointer;
|
||||||
String peiServicesTableCaller;
|
String peiServicesTableCaller;
|
||||||
String regPeiServices;
|
String regPeiServices;
|
||||||
@ -229,25 +241,30 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
Matcher mtrPei;
|
Matcher mtrPei;
|
||||||
|
|
||||||
peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*";
|
peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*";
|
||||||
peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer + ")\\s*\\)[.-]>?\\s*";
|
peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer
|
||||||
|
+ ")\\s*\\)[.-]>?\\s*";
|
||||||
for (int i = 0; i < peiserviceslibfunc.length; i++) {
|
for (int i = 0; i < peiserviceslibfunc.length; i++) {
|
||||||
regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i] + "\\s*\\(\\s*\\1\\s*,(\\t| )*";
|
regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i]
|
||||||
ptnPei = Pattern.compile (regPeiServices);
|
+ "\\s*\\(\\s*\\1\\s*,(\\t| )*";
|
||||||
mtrPei = ptnPei.matcher (wholeline);
|
ptnPei = Pattern.compile(regPeiServices);
|
||||||
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
if (mtrPei.find()) {
|
if (mtrPei.find()) {
|
||||||
wholeline = mtrPei.replaceAll("PeiServices" + peiserviceslibfunc[i] + " (");
|
wholeline = mtrPei.replaceAll("PeiServices"
|
||||||
|
+ peiserviceslibfunc[i] + " (");
|
||||||
mi.hashrequiredr9libs.add("PeiServicesLib");
|
mi.hashrequiredr9libs.add("PeiServicesLib");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)" + "\\s*\\((\\t| )*";
|
regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)"
|
||||||
ptnPei = Pattern.compile (regPeiServices);
|
+ "\\s*\\((\\t| )*";
|
||||||
mtrPei = ptnPei.matcher (wholeline);
|
ptnPei = Pattern.compile(regPeiServices);
|
||||||
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
if (mtrPei.find()) {
|
if (mtrPei.find()) {
|
||||||
wholeline = mtrPei.replaceAll("$2 (");
|
wholeline = mtrPei.replaceAll("$2 (");
|
||||||
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
||||||
}
|
}
|
||||||
|
|
||||||
ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer + "\\s*,\\s*", Pattern.MULTILINE);
|
ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer
|
||||||
|
+ "\\s*,\\s*", Pattern.MULTILINE);
|
||||||
mtrPei = ptnPei.matcher(wholeline);
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
while (mtrPei.find()) {
|
while (mtrPei.find()) {
|
||||||
wholeline = mtrPei.replaceAll("$1");
|
wholeline = mtrPei.replaceAll("$1");
|
||||||
@ -256,40 +273,53 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String drophobLibReturnStatus (String wholeline) { // or use regex to find pattern "Status = ..."
|
private final String drophobLibReturnStatus(String wholeline) { // or use
|
||||||
|
// regex to
|
||||||
|
// find
|
||||||
|
// pattern
|
||||||
|
// "Status =
|
||||||
|
// ..."
|
||||||
Pattern ptnhobstatus;
|
Pattern ptnhobstatus;
|
||||||
Matcher mtrhobstatus;
|
Matcher mtrhobstatus;
|
||||||
String templine = wholeline;
|
String templine = wholeline;
|
||||||
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
||||||
do {
|
do {
|
||||||
ptnhobstatus = Pattern.compile("((?:\t| )*)(\\w(?:\\w|\\d)*)\\s*=\\s*" + specialhoblibfunc[i] + "(.*?;)", Pattern.DOTALL);
|
ptnhobstatus = Pattern.compile(
|
||||||
|
"((?:\t| )*)(\\w(?:\\w|\\d)*)\\s*=\\s*"
|
||||||
|
+ specialhoblibfunc[i] + "(.*?;)",
|
||||||
|
Pattern.DOTALL);
|
||||||
mtrhobstatus = ptnhobstatus.matcher(templine);
|
mtrhobstatus = ptnhobstatus.matcher(templine);
|
||||||
if (!mtrhobstatus.find()) {
|
if (!mtrhobstatus.find()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
String captureIndent = mtrhobstatus.group(1);
|
String captureIndent = mtrhobstatus.group(1);
|
||||||
String captureStatus = mtrhobstatus.group(2);
|
String captureStatus = mtrhobstatus.group(2);
|
||||||
String replaceString = captureIndent + specialhoblibfunc[i] + mtrhobstatus.group(3) + "\n";
|
String replaceString = captureIndent + specialhoblibfunc[i]
|
||||||
replaceString += captureIndent + MigrationTool.MIGRATIONCOMMENT + "R9 Hob-building library functions will assert if build failure.\n";
|
+ mtrhobstatus.group(3) + "\n";
|
||||||
replaceString += captureIndent + captureStatus + " = EFI_SUCCESS;";
|
replaceString += captureIndent
|
||||||
|
+ MigrationTool.MIGRATIONCOMMENT
|
||||||
|
+ "R9 Hob-building library functions will assert if build failure.\n";
|
||||||
|
replaceString += captureIndent + captureStatus
|
||||||
|
+ " = EFI_SUCCESS;";
|
||||||
templine = mtrhobstatus.replaceFirst(replaceString);
|
templine = mtrhobstatus.replaceFirst(replaceString);
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
return templine;
|
return templine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String replaceMacro (String wholeline, Set<String> symbolSet) {
|
private final String replaceMacro(String wholeline, Set<String> symbolSet) {
|
||||||
String r8thing;
|
String r8thing;
|
||||||
String r9thing;
|
String r9thing;
|
||||||
Iterator<String> it;
|
Iterator<String> it;
|
||||||
|
|
||||||
it = symbolSet.iterator();
|
it = symbolSet.iterator();
|
||||||
while (it.hasNext()) { //macros are all assumed MdePkg currently
|
while (it.hasNext()) { // macros are all assumed MdePkg currently
|
||||||
r8thing = it.next();
|
r8thing = it.next();
|
||||||
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
// mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
||||||
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
||||||
if (wholeline.contains(r8thing)) {
|
if (wholeline.contains(r8thing)) {
|
||||||
String findString = "(?<!(?:\\d|\\w))" + r8thing + "(?!(?:\\d|\\w))";
|
String findString = "(?<!(?:\\d|\\w))" + r8thing
|
||||||
|
+ "(?!(?:\\d|\\w))";
|
||||||
wholeline = wholeline.replaceAll(findString, r9thing);
|
wholeline = wholeline.replaceAll(findString, r9thing);
|
||||||
filemacro.add(new r8tor9(r8thing, r9thing));
|
filemacro.add(new r8tor9(r8thing, r9thing));
|
||||||
}
|
}
|
||||||
@ -298,7 +328,7 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String replaceLibrary (String wholeline, Set<String> symbolSet) {
|
private final String replaceLibrary(String wholeline, Set<String> symbolSet) {
|
||||||
boolean addr8 = false;
|
boolean addr8 = false;
|
||||||
// start replacing names
|
// start replacing names
|
||||||
String r8thing;
|
String r8thing;
|
||||||
@ -308,14 +338,17 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
it = symbolSet.iterator();
|
it = symbolSet.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
r8thing = it.next();
|
r8thing = it.next();
|
||||||
mi.addLibraryClass(MigrationTool.db.getR9Lib(r8thing), UsageTypes.ALWAYS_CONSUMED);
|
mi.addLibraryClass(MigrationTool.db.getR9Lib(r8thing),
|
||||||
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here
|
UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
// mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); //
|
||||||
|
// add a library here
|
||||||
|
|
||||||
r8tor9 temp;
|
r8tor9 temp;
|
||||||
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
||||||
if (!r8thing.equals(r9thing)) {
|
if (!r8thing.equals(r9thing)) {
|
||||||
if (wholeline.contains(r8thing)) {
|
if (wholeline.contains(r8thing)) {
|
||||||
String findString = "(?<!(?:\\d|\\w))" + r8thing + "(?!(?:\\d|\\w))";
|
String findString = "(?<!(?:\\d|\\w))" + r8thing
|
||||||
|
+ "(?!(?:\\d|\\w))";
|
||||||
wholeline = wholeline.replaceAll(findString, r9thing);
|
wholeline = wholeline.replaceAll(findString, r9thing);
|
||||||
filefunc.add(new r8tor9(r8thing, r9thing));
|
filefunc.add(new r8tor9(r8thing, r9thing));
|
||||||
Iterator<r8tor9> rt = filefunc.iterator();
|
Iterator<r8tor9> rt = filefunc.iterator();
|
||||||
@ -330,54 +363,70 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //is any of the guids changed?
|
} // is any of the guids changed?
|
||||||
if (addr8 == true) {
|
if (addr8 == true) {
|
||||||
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
||||||
}
|
}
|
||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String replaceObsoleteMacro (String wholeline) {
|
private final String replaceObsoleteMacro(String wholeline) {
|
||||||
Matcher mtrmac;
|
Matcher mtrmac;
|
||||||
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(
|
||||||
|
wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
||||||
}
|
}
|
||||||
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);
|
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(
|
||||||
|
wholeline);
|
||||||
if (mtrmac.find()) {
|
if (mtrmac.find()) {
|
||||||
wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
||||||
}
|
}
|
||||||
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
||||||
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");
|
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK",
|
||||||
|
"(sizeof (UINTN) - 1)");
|
||||||
}
|
}
|
||||||
return wholeline;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void addr8only() throws Exception {
|
private final void addr8only() throws Exception {
|
||||||
String paragraph = null;
|
String paragraph = null;
|
||||||
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");
|
String line = Common.file2string(MigrationTool.db.DatabasePath
|
||||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
+ File.separator + "R8Lib.c");
|
||||||
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.h")));
|
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?(.*?R8_(\\w*).*?)////~", Pattern.DOTALL);
|
new FileWriter(MigrationTool.ModuleInfoMap.get(mi)
|
||||||
|
+ File.separator + "Migration_" + mi.modulename
|
||||||
|
+ File.separator + "R8Lib.c")));
|
||||||
|
PrintWriter outfile2 = new PrintWriter(new BufferedWriter(
|
||||||
|
new FileWriter(MigrationTool.ModuleInfoMap.get(mi)
|
||||||
|
+ File.separator + "Migration_" + mi.modulename
|
||||||
|
+ File.separator + "R8Lib.h")));
|
||||||
|
Pattern ptnr8only = Pattern.compile(
|
||||||
|
"////#?(\\w*)?(.*?R8_(\\w*).*?)////~", Pattern.DOTALL);
|
||||||
Matcher mtrr8only = ptnr8only.matcher(line);
|
Matcher mtrr8only = ptnr8only.matcher(line);
|
||||||
Matcher mtrr8onlyhead;
|
Matcher mtrr8onlyhead;
|
||||||
|
|
||||||
//add head comment
|
// add head comment
|
||||||
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT.matcher(line);
|
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT
|
||||||
|
.matcher(line);
|
||||||
if (mtrr8onlyheadcomment.find()) {
|
if (mtrr8onlyheadcomment.find()) {
|
||||||
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//add functions body
|
// add functions body
|
||||||
while (mtrr8only.find()) {
|
while (mtrr8only.find()) {
|
||||||
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
||||||
paragraph = mtrr8only.group(2);
|
paragraph = mtrr8only.group(2);
|
||||||
@ -385,8 +434,9 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
if (mtrr8only.group(1).length() != 0) {
|
if (mtrr8only.group(1).length() != 0) {
|
||||||
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
||||||
}
|
}
|
||||||
//generate R8lib.h
|
// generate R8lib.h
|
||||||
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) {
|
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph))
|
||||||
|
.find()) {
|
||||||
paragraph = mtrr8onlyhead.replaceAll(";");
|
paragraph = mtrr8onlyhead.replaceAll(";");
|
||||||
}
|
}
|
||||||
outfile2.append(paragraph + "\n\n");
|
outfile2.append(paragraph + "\n\n");
|
||||||
@ -400,20 +450,25 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
mi.localmodulesources.add("R8Lib.h");
|
mi.localmodulesources.add("R8Lib.h");
|
||||||
mi.localmodulesources.add("R8Lib.c");
|
mi.localmodulesources.add("R8Lib.c");
|
||||||
}
|
}
|
||||||
//-------------------------------------process functions-------------------------------------//
|
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
// -------------------------------------process
|
||||||
|
// functions-------------------------------------//
|
||||||
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
public void run(String filepath) throws Exception {
|
public void run(String filepath) throws Exception {
|
||||||
String inname = filepath.replace(mi.temppath + File.separator, "");
|
String inname = filepath.replace(mi.temppath + File.separator, "");
|
||||||
String tempinpath = mi.temppath + File.separator;
|
String tempinpath = mi.temppath + File.separator;
|
||||||
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi)
|
||||||
|
+ File.separator + "Migration_" + mi.modulename
|
||||||
|
+ File.separator;
|
||||||
|
|
||||||
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
||||||
while (itLaplace.hasNext()) {
|
while (itLaplace.hasNext()) {
|
||||||
Common.Laplace lap = itLaplace.next();
|
Common.Laplace lap = itLaplace.next();
|
||||||
if (lap.recognize(inname)) {
|
if (lap.recognize(inname)) {
|
||||||
MigrationTool.ui.println("\nHandling file: " + inname);
|
MigrationTool.ui.println("\nHandling file: " + inname);
|
||||||
lap.transform(tempinpath + inname, tempoutpath + lap.namechange(inname));
|
lap.transform(tempinpath + inname, tempoutpath
|
||||||
|
+ lap.namechange(inname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,7 +476,8 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
|||||||
public boolean filter(File dir) {
|
public boolean filter(File dir) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
|
||||||
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface UI {
|
public interface UI {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user