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,219 +12,244 @@
|
|||||||
**/
|
**/
|
||||||
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 DIR = 2;
|
|
||||||
|
|
||||||
public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";
|
|
||||||
public static final Pattern PTNSEPARATER = Pattern.compile("(.*)\\\\([^\\\\]*)");
|
|
||||||
|
|
||||||
//-------------------------------------regex------------------------------------------//
|
public static final int FILE = 1;
|
||||||
|
|
||||||
public static final String replaceAll(String line, Pattern ptn, String des) {
|
|
||||||
Matcher mtr = ptn.matcher(line);
|
|
||||||
|
|
||||||
if (mtr.find()) {
|
public static final int DIR = 2;
|
||||||
return mtr.replaceAll(des);
|
|
||||||
}
|
|
||||||
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final boolean find (String line, String regex) {
|
public static final String STRSEPARATER = "(.*)\\\\([^\\\\]*)";
|
||||||
Pattern ptn = Pattern.compile(regex);
|
|
||||||
|
|
||||||
return ptn.matcher (line).find ();
|
public static final Pattern PTNSEPARATER = Pattern
|
||||||
}
|
.compile("(.*)\\\\([^\\\\]*)");
|
||||||
//-------------------------------------regex------------------------------------------//
|
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
|
||||||
|
|
||||||
public static final String file2string(String filename) throws Exception {
|
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
|
||||||
StringBuffer wholefile = new StringBuffer();
|
|
||||||
String line;
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
wholefile.append(line + "\n");
|
|
||||||
}
|
|
||||||
rd.close();
|
|
||||||
return wholefile.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void string2file(String content, String filename) throws Exception {
|
// -------------------------------------regex------------------------------------------//
|
||||||
ensureDir(filename);
|
|
||||||
PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
|
|
||||||
outfile.append(content);
|
|
||||||
outfile.flush();
|
|
||||||
outfile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void fileCopy(String src, String des) throws Exception {
|
public static final String replaceAll(String line, Pattern ptn, String des) {
|
||||||
string2file(file2string(src), des);
|
Matcher mtr = ptn.matcher(line);
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------file&string---------------------------------------//
|
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
if (mtr.find()) {
|
||||||
/*
|
return mtr.replaceAll(des);
|
||||||
public static final HashSet<String> walkDir(String path, int mode) throws Exception {
|
}
|
||||||
HashSet<String> pathlist = new HashSet<String>();
|
|
||||||
Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);
|
|
||||||
return pathlist;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public static final void ensureDir(String objFileWhole) {
|
|
||||||
File tempdir;
|
|
||||||
Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);
|
|
||||||
if (mtrseparate.find()) {
|
|
||||||
tempdir = new File(mtrseparate.group(1));
|
|
||||||
if (!tempdir.exists()) tempdir.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void deleteDir(String objFileWhole) {
|
|
||||||
String[] list = new File(objFileWhole).list();
|
|
||||||
File temp;
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
|
||||||
temp = new File(objFileWhole + File.separator + list[i]);
|
|
||||||
if (temp.isDirectory()) {
|
|
||||||
deleteDir(objFileWhole + File.separator + list[i]);
|
|
||||||
} else {
|
|
||||||
temp.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
new File(objFileWhole).delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String dirCopy_(String src) throws Exception {
|
|
||||||
Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);
|
|
||||||
if (mtrseparate.find()) {
|
|
||||||
dirCopy(src, 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 {
|
|
||||||
String[] list = new File(src).list();
|
|
||||||
File test;
|
|
||||||
|
|
||||||
ensureDir(des);
|
return line;
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
}
|
||||||
test = new File(src + File.separator + list[i]);
|
|
||||||
if (test.isDirectory()) {
|
|
||||||
dirCopy(src + File.separator + list[i], des + File.separator + list[i]);
|
|
||||||
} else {
|
|
||||||
//ensureDir(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 {
|
|
||||||
String[] list = new File(src).list();
|
|
||||||
|
|
||||||
ensureDir(des);
|
|
||||||
for (int i = 0; i < list.length; i++) {
|
|
||||||
if (list[i].contains(type)) {
|
|
||||||
string2file(file2string(src + File.separator + list[i]), des + File.separator + list[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------dir--------------------------------------------//
|
public static final boolean find(String line, String regex) {
|
||||||
|
Pattern ptn = Pattern.compile(regex);
|
||||||
|
|
||||||
//-------------------------------like python walk-----------------------------------------//
|
return ptn.matcher(line).find();
|
||||||
|
}
|
||||||
public static final void toDoAll(String path, Method md, Object obj, Object[] args, int type) throws Exception {
|
|
||||||
String[] list = new File(path).list();
|
|
||||||
ArrayList<Object> _args = new ArrayList<Object>();
|
|
||||||
|
|
||||||
_args.add(path);
|
|
||||||
if (args != null) {
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
|
||||||
_args.add(args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == DIR || type == BOTH) {
|
// -------------------------------------regex------------------------------------------//
|
||||||
md.invoke(obj, _args.toArray());
|
|
||||||
}
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
|
||||||
if (new File(path + File.separator + list[i]).isDirectory()) {
|
|
||||||
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
|
||||||
} else {
|
|
||||||
if (type == FILE || type == BOTH) {
|
|
||||||
_args.set(0, path + File.separator + list[i]);
|
|
||||||
md.invoke(obj, _args.toArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {
|
// -----------------------------------file&string---------------------------------------//
|
||||||
Iterator<String> di = set.iterator();
|
|
||||||
while (di.hasNext()) {
|
|
||||||
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
|
|
||||||
String[] list = new File(path).list();
|
|
||||||
File test;
|
|
||||||
|
|
||||||
if (type == DIR || type == BOTH) {
|
public static final String file2string(String filename) throws Exception {
|
||||||
fda.run(path);
|
BufferedReader rd = new BufferedReader(new FileReader(filename));
|
||||||
}
|
StringBuffer wholefile = new StringBuffer();
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
String line;
|
||||||
test = new File(path + File.separator + list[i]);
|
while ((line = rd.readLine()) != null) {
|
||||||
if (test.isDirectory()) {
|
wholefile.append(line + "\n");
|
||||||
if (fda.filter(test)) {
|
}
|
||||||
toDoAll(path + File.separator + list[i], fda, type);
|
rd.close();
|
||||||
}
|
return wholefile.toString();
|
||||||
} else {
|
}
|
||||||
if (type == FILE || type == BOTH) {
|
|
||||||
fda.run(path + File.separator + list[i]);
|
public static final void string2file(String content, String filename)
|
||||||
}
|
throws Exception {
|
||||||
}
|
ensureDir(filename);
|
||||||
}
|
PrintWriter outfile = new PrintWriter(new BufferedWriter(
|
||||||
}
|
new FileWriter(filename)));
|
||||||
|
outfile.append(content);
|
||||||
public static interface ForDoAll {
|
outfile.flush();
|
||||||
public void run(String filepath) throws Exception;
|
outfile.close();
|
||||||
|
}
|
||||||
public boolean filter(File dir);
|
|
||||||
}
|
public static final void fileCopy(String src, String des) throws Exception {
|
||||||
|
string2file(file2string(src), des);
|
||||||
public static abstract class Laplace {
|
}
|
||||||
public void transform(String src, String des) throws Exception {
|
|
||||||
Common.string2file(operation(Common.file2string(src)), des);
|
// -----------------------------------file&string---------------------------------------//
|
||||||
}
|
|
||||||
|
// --------------------------------------dir--------------------------------------------//
|
||||||
public abstract String operation(String wholeline);
|
/*
|
||||||
|
* public static final HashSet<String> walkDir(String path, int mode)
|
||||||
public abstract boolean recognize(String filename);
|
* throws Exception { HashSet<String> pathlist = new HashSet<String>();
|
||||||
|
* Common.toDoAll(path, Common.class.getMethod("walkDir", String.class),
|
||||||
public abstract String namechange(String oldname);
|
* null, null, mode); return pathlist; }
|
||||||
}
|
*/
|
||||||
|
public static final void ensureDir(String objFileWhole) {
|
||||||
public static interface Element {
|
File tempdir;
|
||||||
|
Matcher mtrseparate = PTNSEPARATER.matcher(objFileWhole);
|
||||||
// public int replace = 0;
|
if (mtrseparate.find()) {
|
||||||
// public int type = 1;
|
tempdir = new File(mtrseparate.group(1));
|
||||||
|
if (!tempdir.exists())
|
||||||
public String getReplace(String key);
|
tempdir.mkdirs();
|
||||||
|
}
|
||||||
// public void getType(String key);
|
}
|
||||||
//
|
|
||||||
// public void setReplace(int num);
|
public static final void deleteDir(String objFileWhole) {
|
||||||
//
|
String[] list = new File(objFileWhole).list();
|
||||||
// public void setType(int num);
|
File temp;
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
}
|
temp = new File(objFileWhole + File.separator + list[i]);
|
||||||
|
if (temp.isDirectory()) {
|
||||||
|
deleteDir(objFileWhole + File.separator + list[i]);
|
||||||
|
} else {
|
||||||
|
temp.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new File(objFileWhole).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String dirCopy_(String src) throws Exception {
|
||||||
|
Matcher mtrseparate = Common.PTNSEPARATER.matcher(src);
|
||||||
|
if (mtrseparate.find()) {
|
||||||
|
dirCopy(src, 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 {
|
||||||
|
String[] list = new File(src).list();
|
||||||
|
File test;
|
||||||
|
|
||||||
|
ensureDir(des);
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
test = new File(src + File.separator + list[i]);
|
||||||
|
if (test.isDirectory()) {
|
||||||
|
dirCopy(src + File.separator + list[i], des + File.separator
|
||||||
|
+ list[i]);
|
||||||
|
} else {
|
||||||
|
// ensureDir(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 {
|
||||||
|
String[] list = new File(src).list();
|
||||||
|
|
||||||
|
ensureDir(des);
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
if (list[i].contains(type)) {
|
||||||
|
string2file(file2string(src + File.separator + list[i]), des
|
||||||
|
+ File.separator + list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------dir--------------------------------------------//
|
||||||
|
|
||||||
|
// -------------------------------like python
|
||||||
|
// walk-----------------------------------------//
|
||||||
|
|
||||||
|
public static final void toDoAll(String path, Method md, Object obj,
|
||||||
|
Object[] args, int type) throws Exception {
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
ArrayList<Object> _args = new ArrayList<Object>();
|
||||||
|
|
||||||
|
_args.add(path);
|
||||||
|
if (args != null) {
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
_args.add(args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == DIR || type == BOTH) {
|
||||||
|
md.invoke(obj, _args.toArray());
|
||||||
|
}
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
if (new File(path + File.separator + list[i]).isDirectory()) {
|
||||||
|
toDoAll(path + File.separator + list[i], md, obj, args, type);
|
||||||
|
} else {
|
||||||
|
if (type == FILE || type == BOTH) {
|
||||||
|
_args.set(0, path + File.separator + list[i]);
|
||||||
|
md.invoke(obj, _args.toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void toDoAll(Set<String> set, ForDoAll fda)
|
||||||
|
throws Exception {
|
||||||
|
Iterator<String> di = set.iterator();
|
||||||
|
while (di.hasNext()) {
|
||||||
|
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
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
File test;
|
||||||
|
|
||||||
|
if (type == DIR || type == BOTH) {
|
||||||
|
fda.run(path);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
test = new File(path + File.separator + list[i]);
|
||||||
|
if (test.isDirectory()) {
|
||||||
|
if (fda.filter(test)) {
|
||||||
|
toDoAll(path + File.separator + list[i], fda, type);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (type == FILE || type == BOTH) {
|
||||||
|
fda.run(path + File.separator + list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface ForDoAll {
|
||||||
|
public void run(String filepath) throws Exception;
|
||||||
|
|
||||||
|
public boolean filter(File dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class Laplace {
|
||||||
|
public void transform(String src, String des) throws Exception {
|
||||||
|
Common.string2file(operation(Common.file2string(src)), des);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String operation(String wholeline);
|
||||||
|
|
||||||
|
public abstract boolean recognize(String filename);
|
||||||
|
|
||||||
|
public abstract String namechange(String oldname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface Element {
|
||||||
|
|
||||||
|
// public int replace = 0;
|
||||||
|
// public int type = 1;
|
||||||
|
|
||||||
|
public String getReplace(String key);
|
||||||
|
|
||||||
|
// public void getType(String key);
|
||||||
|
//
|
||||||
|
// public void setReplace(int num);
|
||||||
|
//
|
||||||
|
// public void setType(int num);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,196 +12,228 @@
|
|||||||
**/
|
**/
|
||||||
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 ptncommentequation = Pattern.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
|
||||||
private static Matcher mtrcommentequation;
|
|
||||||
private static final Pattern ptnnewcomment = Pattern.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
|
||||||
private static Matcher mtrnewcomment;
|
|
||||||
|
|
||||||
private static final int totallinelength = 82;
|
|
||||||
|
|
||||||
public static final void run(String filepath) throws Exception {
|
|
||||||
if (MigrationTool.doCritic) { // this is left here to set an example for future structure
|
|
||||||
critic(filepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final void critic(String filepath) throws Exception {
|
|
||||||
if (filepath.contains(".c") || filepath.contains(".h")) {
|
|
||||||
BufferedReader rd = null;
|
|
||||||
String line = null;
|
|
||||||
StringBuffer templine = new StringBuffer();
|
|
||||||
boolean incomment = false;
|
|
||||||
|
|
||||||
System.out.println("Criticing " + filepath);
|
private static final Pattern ptnheadcomment = Pattern.compile(
|
||||||
String wholeline = Common.file2string(filepath);
|
"^\\/\\*\\+\\+(.*?)\\-\\-\\*\\/", Pattern.DOTALL);
|
||||||
|
|
||||||
wholeline = wholeline.replaceAll("\t", " ");
|
private static final Pattern ptnfunccomment = Pattern
|
||||||
wholeline = Common.replaceAll(wholeline, ptnheadcomment, "/** @file$1**/");
|
.compile(
|
||||||
wholeline = Common.replaceAll(wholeline, ptnfunccomment, "$1\n/**$3\n**/\n$4$2");
|
"([\\};\\/\">]\\s*)([\\w\\s\\*]*?[_\\w][_\\w\\d]*\\s*\\([^\\)\\(]*\\)\\s*)\\/\\*\\+\\+(.*?)\\-\\-\\*\\/\\s*(.*?)(?=[\\{;])",
|
||||||
//wholeline = Common.replaceAll(wholeline, ptncommentstructure, "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
Pattern.DOTALL); // find function with {;">/ , may be
|
||||||
|
// unsafe
|
||||||
|
|
||||||
// first scan
|
// private static Pattern ptncommentstructure =
|
||||||
boolean description = false;
|
// Pattern.compile("\\/\\*\\+\\+\\s*Routine
|
||||||
boolean arguments = false;
|
// Description:\\s*(.*?)\\s*Arguments:\\s*(.*?)\\s*Returns:\\s*(.*?)\\s*\\-\\-\\*\\/",Pattern.DOTALL);
|
||||||
boolean returns = false;
|
private static final Pattern ptncommentequation = Pattern
|
||||||
boolean inequation = false;
|
.compile("([^\\s]*)\\s+-\\s+(.*)\\s*");
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
|
||||||
while ((line = rd.readLine()) != null) {
|
private static Matcher mtrcommentequation;
|
||||||
if (line.matches("\\/\\*\\*")) {
|
|
||||||
incomment = true;
|
private static final Pattern ptnnewcomment = Pattern
|
||||||
description = false;
|
.compile("(\\s*@(param|retval)\\s+[^\\s]+)\\s+(.*)");
|
||||||
arguments = false;
|
|
||||||
returns = false;
|
private static Matcher mtrnewcomment;
|
||||||
templine.append(line + "\n");
|
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
private static final int totallinelength = 82;
|
||||||
incomment = false;
|
|
||||||
templine.append("\n" + line + "\n");
|
public static final void run(String filepath) throws Exception {
|
||||||
} else if (incomment) {
|
if (MigrationTool.doCritic) { // this is left here to set an example
|
||||||
if (line.contains("Routine Description:")) {
|
// for future structure
|
||||||
description = true;
|
critic(filepath);
|
||||||
arguments = false;
|
}
|
||||||
returns = false;
|
}
|
||||||
} else if (line.contains("Arguments:")) {
|
|
||||||
description = false;
|
private static final void critic(String filepath) throws Exception {
|
||||||
arguments = true;
|
if (filepath.contains(".c") || filepath.contains(".h")) {
|
||||||
returns = false;
|
BufferedReader rd = null;
|
||||||
templine.append("\n");
|
String line = null;
|
||||||
} else if (line.contains("Returns:")) {
|
StringBuffer templine = new StringBuffer();
|
||||||
description = false;
|
boolean incomment = false;
|
||||||
arguments = false;
|
|
||||||
returns = true;
|
System.out.println("Criticing " + filepath);
|
||||||
templine.append("\n");
|
String wholeline = Common.file2string(filepath);
|
||||||
} else if (description) {
|
|
||||||
if (line.trim().length() != 0) {
|
wholeline = wholeline.replaceAll("\t", " ");
|
||||||
templine.append(" " + line.trim() + "\n");
|
wholeline = Common.replaceAll(wholeline, ptnheadcomment,
|
||||||
}
|
"/** @file$1**/");
|
||||||
} else if (arguments) {
|
wholeline = Common.replaceAll(wholeline, ptnfunccomment,
|
||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
"$1\n/**$3\n**/\n$4$2");
|
||||||
if (mtrcommentequation.find()) {
|
// wholeline = Common.replaceAll(wholeline, ptncommentstructure,
|
||||||
inequation = true;
|
// "/**\n#%\n$1\n%#\n#%%\n$2\n%%#\n#%%%\n$3\n%%%#\n**/");
|
||||||
templine.append(" @param " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
// first scan
|
||||||
inequation = false;
|
boolean description = false;
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
boolean arguments = false;
|
||||||
templine.append("#%#%" + line + "\n");
|
boolean returns = false;
|
||||||
} else {
|
boolean inequation = false;
|
||||||
if (line.trim().length() != 0) {
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
templine.append(" " + line.trim() + "\n");
|
while ((line = rd.readLine()) != null) {
|
||||||
}
|
if (line.matches("\\/\\*\\*")) {
|
||||||
}
|
incomment = true;
|
||||||
} else if (returns) {
|
description = false;
|
||||||
mtrcommentequation = ptncommentequation.matcher(line);
|
arguments = false;
|
||||||
if (mtrcommentequation.find()) {
|
returns = false;
|
||||||
inequation = true;
|
templine.append(line + "\n");
|
||||||
templine.append(" @retval " + mtrcommentequation.group(1) + " " + mtrcommentequation.group(2) + "\n");
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
} else if (inequation && line.trim().length() == 0) {
|
incomment = false;
|
||||||
inequation = false;
|
templine.append("\n" + line + "\n");
|
||||||
} else if (inequation && line.trim().length() != 0) {
|
} else if (incomment) {
|
||||||
templine.append("#%#%" + line + "\n");
|
if (line.contains("Routine Description:")) {
|
||||||
} else {
|
description = true;
|
||||||
if (line.trim().length() != 0) {
|
arguments = false;
|
||||||
templine.append(" @return " + line.trim() + "\n");
|
returns = false;
|
||||||
}
|
} else if (line.contains("Arguments:")) {
|
||||||
}
|
description = false;
|
||||||
}
|
arguments = true;
|
||||||
} else {
|
returns = false;
|
||||||
templine.append(line + "\n");
|
templine.append("\n");
|
||||||
}
|
} else if (line.contains("Returns:")) {
|
||||||
}
|
description = false;
|
||||||
wholeline = templine.toString();
|
arguments = false;
|
||||||
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
returns = true;
|
||||||
//
|
templine.append("\n");
|
||||||
|
} else if (description) {
|
||||||
// secend scan
|
if (line.trim().length() != 0) {
|
||||||
int startmax = 0;
|
templine.append(" " + line.trim() + "\n");
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
}
|
||||||
while ((line = rd.readLine()) != null) {
|
} else if (arguments) {
|
||||||
if (line.matches("\\/\\*\\*")) {
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
incomment = true;
|
if (mtrcommentequation.find()) {
|
||||||
templine.append(line + "\n");
|
inequation = true;
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
templine.append(" @param "
|
||||||
incomment = false;
|
+ mtrcommentequation.group(1) + " "
|
||||||
templine.append(line + "\n");
|
+ mtrcommentequation.group(2) + "\n");
|
||||||
} else if (incomment) {
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
mtrnewcomment = ptnnewcomment.matcher(line);
|
inequation = false;
|
||||||
if (mtrnewcomment.find()) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment.group(1).length() : startmax;
|
templine.append("#%#%" + line + "\n");
|
||||||
}
|
} else {
|
||||||
}
|
if (line.trim().length() != 0) {
|
||||||
}
|
templine.append(" " + line.trim() + "\n");
|
||||||
startmax++;
|
}
|
||||||
//
|
}
|
||||||
|
} else if (returns) {
|
||||||
// third scan
|
mtrcommentequation = ptncommentequation.matcher(line);
|
||||||
int n = 0;
|
if (mtrcommentequation.find()) {
|
||||||
String temp = null;
|
inequation = true;
|
||||||
String[] tempcont = null;
|
templine.append(" @retval "
|
||||||
int count = 0;
|
+ mtrcommentequation.group(1) + " "
|
||||||
templine = new StringBuffer();
|
+ mtrcommentequation.group(2) + "\n");
|
||||||
rd = new BufferedReader(new StringReader(wholeline));
|
} else if (inequation && line.trim().length() == 0) {
|
||||||
while ((line = rd.readLine()) != null) {
|
inequation = false;
|
||||||
if (line.matches("\\/\\*\\*")) {
|
} else if (inequation && line.trim().length() != 0) {
|
||||||
incomment = true;
|
templine.append("#%#%" + line + "\n");
|
||||||
templine.append(line + "\n");
|
} else {
|
||||||
} else if (line.matches("\\*\\*\\/")) {
|
if (line.trim().length() != 0) {
|
||||||
incomment = false;
|
templine.append(" @return " + line.trim()
|
||||||
templine.append(line + "\n");
|
+ "\n");
|
||||||
} else if (incomment) {
|
}
|
||||||
mtrnewcomment = ptnnewcomment.matcher(line);
|
}
|
||||||
if (mtrnewcomment.find()) {
|
}
|
||||||
n = startmax - mtrnewcomment.group(1).length();
|
} else {
|
||||||
templine.append(mtrnewcomment.group(1));
|
templine.append(line + "\n");
|
||||||
while (n-- >= 0) {
|
}
|
||||||
templine.append(" ");
|
}
|
||||||
}
|
wholeline = templine.toString();
|
||||||
temp = mtrnewcomment.group(3);
|
wholeline = wholeline.replaceAll("\n#%#%\\s*", " ");
|
||||||
tempcont = temp.split(" "); // use \\s+ ?
|
//
|
||||||
|
|
||||||
count = 0;
|
// secend scan
|
||||||
for (int i = 0; i < tempcont.length; i++) {
|
int startmax = 0;
|
||||||
count += tempcont[i].length();
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
if (count <= (totallinelength - startmax)) {
|
while ((line = rd.readLine()) != null) {
|
||||||
templine.append(tempcont[i] + " ");
|
if (line.matches("\\/\\*\\*")) {
|
||||||
count += 1;
|
incomment = true;
|
||||||
} else {
|
templine.append(line + "\n");
|
||||||
templine.append("\n");
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
n = startmax;
|
incomment = false;
|
||||||
while (n-- >= 0) {
|
templine.append(line + "\n");
|
||||||
templine.append(" ");
|
} else if (incomment) {
|
||||||
}
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
templine.append(tempcont[i] + " ");
|
if (mtrnewcomment.find()) {
|
||||||
count = tempcont[i].length() + 1;
|
startmax = mtrnewcomment.group(1).length() > startmax ? mtrnewcomment
|
||||||
}
|
.group(1).length()
|
||||||
}
|
: startmax;
|
||||||
templine.append("\n");
|
}
|
||||||
} else {
|
}
|
||||||
templine.append(line + "\n");
|
}
|
||||||
}
|
startmax++;
|
||||||
} else {
|
//
|
||||||
templine.append(line + "\n");
|
|
||||||
}
|
// third scan
|
||||||
}
|
int n = 0;
|
||||||
wholeline = templine.toString();
|
String temp = null;
|
||||||
//
|
String[] tempcont = null;
|
||||||
// Remove trailing blanks.
|
int count = 0;
|
||||||
//
|
templine = new StringBuffer();
|
||||||
wholeline = wholeline.replaceAll (" +\n", "\n");
|
rd = new BufferedReader(new StringReader(wholeline));
|
||||||
Common.string2file(wholeline, filepath);
|
while ((line = rd.readLine()) != null) {
|
||||||
}
|
if (line.matches("\\/\\*\\*")) {
|
||||||
}
|
incomment = true;
|
||||||
|
templine.append(line + "\n");
|
||||||
public static final void fireAt(String path) throws Exception {
|
} else if (line.matches("\\*\\*\\/")) {
|
||||||
//Common.toDoAll(Common.dirCopy_(path), Critic.class.getMethod("critic", String.class), null, null, Common.FILE);
|
incomment = false;
|
||||||
Common.toDoAll(path, Critic.class.getMethod("run", String.class), null, null, Common.FILE);
|
templine.append(line + "\n");
|
||||||
//Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
} else if (incomment) {
|
||||||
System.out.println("Critic Done");
|
mtrnewcomment = ptnnewcomment.matcher(line);
|
||||||
}
|
if (mtrnewcomment.find()) {
|
||||||
|
n = startmax - mtrnewcomment.group(1).length();
|
||||||
|
templine.append(mtrnewcomment.group(1));
|
||||||
|
while (n-- >= 0) {
|
||||||
|
templine.append(" ");
|
||||||
|
}
|
||||||
|
temp = mtrnewcomment.group(3);
|
||||||
|
tempcont = temp.split(" "); // use \\s+ ?
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (int i = 0; i < tempcont.length; i++) {
|
||||||
|
count += tempcont[i].length();
|
||||||
|
if (count <= (totallinelength - startmax)) {
|
||||||
|
templine.append(tempcont[i] + " ");
|
||||||
|
count += 1;
|
||||||
|
} else {
|
||||||
|
templine.append("\n");
|
||||||
|
n = startmax;
|
||||||
|
while (n-- >= 0) {
|
||||||
|
templine.append(" ");
|
||||||
|
}
|
||||||
|
templine.append(tempcont[i] + " ");
|
||||||
|
count = tempcont[i].length() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templine.append("\n");
|
||||||
|
} else {
|
||||||
|
templine.append(line + "\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templine.append(line + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wholeline = templine.toString();
|
||||||
|
//
|
||||||
|
// Remove trailing blanks.
|
||||||
|
//
|
||||||
|
wholeline = wholeline.replaceAll(" +\n", "\n");
|
||||||
|
Common.string2file(wholeline, filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(path, Critic.class.getMethod("run", String.class), null,
|
||||||
|
null, Common.FILE);
|
||||||
|
// Common.toDoAll(Common.dirCopy_(path), critic, Common.FILE);
|
||||||
|
System.out.println("Critic Done");
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,442 +12,494 @@
|
|||||||
**/
|
**/
|
||||||
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();;
|
||||||
|
|
||||||
Database(String path) {
|
|
||||||
DatabasePath = path;
|
|
||||||
|
|
||||||
try {
|
Database(String path) {
|
||||||
//collectWorkSpaceDatabase();
|
DatabasePath = path;
|
||||||
importPkgGuid("PkgGuid.csv");
|
|
||||||
importDBLib("Library.csv");
|
|
||||||
importDBGuid("Guid.csv", "Guid");
|
|
||||||
importDBGuid("Ppi.csv", "Ppi");
|
|
||||||
importDBGuid("Protocol.csv", "Protocol");
|
|
||||||
importDBMacro("Macro.csv");
|
|
||||||
importListR8Only();
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DatabasePath;
|
|
||||||
public Set<String> error = new HashSet<String>();
|
|
||||||
public Set<String> r8only = new HashSet<String>();
|
|
||||||
|
|
||||||
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>();
|
|
||||||
|
|
||||||
|
try {
|
||||||
//-------------------------------------import------------------------------------------//
|
// collectWorkSpaceDatabase();
|
||||||
private void importPkgGuid(String filename) throws Exception {
|
importPkgGuid("PkgGuid.csv");
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
importDBLib("Library.csv");
|
||||||
String line;
|
importDBGuid("Guid.csv", "Guid");
|
||||||
String[] linecontext;
|
importDBGuid("Ppi.csv", "Ppi");
|
||||||
|
importDBGuid("Protocol.csv", "Protocol");
|
||||||
if (rd.ready()) {
|
importDBMacro("Macro.csv");
|
||||||
System.out.println("Found " + filename + ", Importing Package Guid Database.");
|
importListR8Only();
|
||||||
//
|
} catch (Exception e) {
|
||||||
// Skip the title row.
|
System.out.println(e.getMessage());
|
||||||
//
|
}
|
||||||
line = rd.readLine();
|
}
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
if (line.length() != 0) {
|
|
||||||
linecontext = line.split(",");
|
|
||||||
hashPkgGuid.put(linecontext[0], linecontext[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Iterator<String> dumpAllPkgGuid() {
|
|
||||||
return hashPkgGuid.values().iterator();
|
|
||||||
}
|
|
||||||
private void importDBLib(String filename) throws Exception {
|
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
|
||||||
String line;
|
|
||||||
String[] linecontext;
|
|
||||||
Func lf;
|
|
||||||
|
|
||||||
if (rd.ready()) {
|
|
||||||
System.out.println("Found " + filename + ", Importing Library Database.");
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
if (line.length() != 0) {
|
|
||||||
linecontext = line.split(",");
|
|
||||||
lf = new Func(linecontext);
|
|
||||||
hashfunc.put(lf.r8funcname,lf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importDBGuid(String filename, String type) throws Exception {
|
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
|
||||||
String line;
|
|
||||||
String[] linecontext;
|
|
||||||
Guid gu;
|
|
||||||
|
|
||||||
if (rd.ready()) {
|
|
||||||
System.out.println("Found " + filename + ", Importing " + type + " Database.");
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
if (line.length() != 0) {
|
|
||||||
linecontext = line.split(",");
|
|
||||||
gu = new Guid(linecontext, type);
|
|
||||||
hashguid.put(gu.r8name,gu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importDBMacro(String filename) throws Exception {
|
|
||||||
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
|
|
||||||
String line;
|
|
||||||
String[] linecontext;
|
|
||||||
Macro mc;
|
|
||||||
|
|
||||||
if (rd.ready()) {
|
|
||||||
System.out.println("Found " + filename + ", Importing Macro Database.");
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
if (line.length() != 0) {
|
|
||||||
linecontext = line.split(",");
|
|
||||||
mc = new Macro(linecontext);
|
|
||||||
hashmacro.put(mc.r8name,mc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void importListR8Only() throws Exception {
|
public String DatabasePath;
|
||||||
Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
|
||||||
String wholeline = Common.file2string(DatabasePath + File.separator + "R8Lib.c");
|
|
||||||
System.out.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
|
||||||
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
|
||||||
while (mtrr8only.find()) {
|
|
||||||
r8only.add(mtrr8only.group(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------import------------------------------------------//
|
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
public Set<String> error = new HashSet<String>();
|
||||||
|
|
||||||
public String getR9Lib(String r8funcname) {
|
public Set<String> r8only = new HashSet<String>();
|
||||||
String temp = null;
|
|
||||||
if (hashfunc.containsKey(r8funcname)) {
|
|
||||||
temp = hashfunc.get(r8funcname).r9libname;
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getR9Func(String r8funcname) {
|
|
||||||
String temp = null;
|
|
||||||
if (hashfunc.containsKey(r8funcname)) {
|
|
||||||
temp = hashfunc.get(r8funcname).r9funcname;
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getR9Guidname(String r8Guid) {
|
private Map<String, Guid> hashguid = new HashMap<String, Guid>();
|
||||||
String temp = null;
|
|
||||||
try {
|
|
||||||
temp = hashguid.get(r8Guid).r9name;
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
error.add("getR9Guidname :" + r8Guid);
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGuidType(String r8Guid) {
|
private Map<String, Func> hashfunc = new HashMap<String, Func>();
|
||||||
String temp = null;
|
|
||||||
try {
|
|
||||||
temp = hashguid.get(r8Guid).type;
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
error.add("getR9Guidname :" + r8Guid);
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------get------------------------------------------//
|
private Map<String, Macro> hashmacro = new HashMap<String, Macro>();
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
private Map<String, String> hashPkgGuid = new HashMap<String, String>();
|
||||||
|
|
||||||
public boolean hasFunc(String r8lib) {
|
// -------------------------------------import------------------------------------------//
|
||||||
return hashfunc.containsKey(r8lib);
|
private void importPkgGuid(String filename) throws Exception {
|
||||||
}
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
|
String line;
|
||||||
|
String[] linecontext;
|
||||||
|
|
||||||
public boolean hasGuid(String r8guid) {
|
if (rd.ready()) {
|
||||||
return hashguid.containsKey(r8guid);
|
System.out.println("Found " + filename
|
||||||
}
|
+ ", Importing Package Guid Database.");
|
||||||
|
//
|
||||||
|
// Skip the title row.
|
||||||
|
//
|
||||||
|
line = rd.readLine();
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
if (line.length() != 0) {
|
||||||
|
linecontext = line.split(",");
|
||||||
|
hashPkgGuid.put(linecontext[0], linecontext[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasMacro(String r8macro) {
|
public Iterator<String> dumpAllPkgGuid() {
|
||||||
return hashmacro.containsKey(r8macro);
|
return hashPkgGuid.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------has------------------------------------------//
|
|
||||||
|
|
||||||
//-------------------------------------init------------------------------------------//
|
|
||||||
|
|
||||||
private static final Database init() {
|
private void importDBLib(String filename) throws Exception {
|
||||||
if (System.getenv("WORKSPACE") == null) {
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
+ File.separator + filename));
|
||||||
} else {
|
String line;
|
||||||
return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
|
String[] linecontext;
|
||||||
}
|
Func lf;
|
||||||
}
|
|
||||||
|
|
||||||
public static final Database getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (rd.ready()) {
|
||||||
|
System.out.println("Found " + filename
|
||||||
|
+ ", Importing Library Database.");
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
if (line.length() != 0) {
|
||||||
|
linecontext = line.split(",");
|
||||||
|
lf = new Func(linecontext);
|
||||||
|
hashfunc.put(lf.r8funcname, lf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importDBGuid(String filename, String type) throws Exception {
|
||||||
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
|
String line;
|
||||||
|
String[] linecontext;
|
||||||
|
Guid gu;
|
||||||
|
|
||||||
private String workspacePath;
|
if (rd.ready()) {
|
||||||
private HashMap<String, String> hashDbGuids = new HashMap<String, String>();
|
System.out.println("Found " + filename + ", Importing " + type
|
||||||
private HashMap<String, String> hashDbPpis = new HashMap<String, String>();
|
+ " Database.");
|
||||||
private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();
|
while ((line = rd.readLine()) != null) {
|
||||||
private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();
|
if (line.length() != 0) {
|
||||||
private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();
|
linecontext = line.split(",");
|
||||||
private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();
|
gu = new Guid(linecontext, type);
|
||||||
|
hashguid.put(gu.r8name, gu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";
|
private void importDBMacro(String filename) throws Exception {
|
||||||
private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);
|
BufferedReader rd = new BufferedReader(new FileReader(DatabasePath
|
||||||
|
+ File.separator + filename));
|
||||||
|
String line;
|
||||||
|
String[] linecontext;
|
||||||
|
Macro mc;
|
||||||
|
|
||||||
private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";
|
if (rd.ready()) {
|
||||||
private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);
|
System.out.println("Found " + filename
|
||||||
|
+ ", Importing Macro Database.");
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
if (line.length() != 0) {
|
||||||
|
linecontext = line.split(",");
|
||||||
|
mc = new Macro(linecontext);
|
||||||
|
hashmacro.put(mc.r8name, mc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";
|
private void importListR8Only() throws Exception {
|
||||||
private final String regLibFunction = regLibDataType + "\\s*(?:EFIAPI)?\\s+" +
|
Pattern ptnr8only = Pattern.compile(
|
||||||
"(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";
|
"////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern.DOTALL);
|
||||||
private Pattern ptnLibFunction = Pattern.compile(regLibFunction);
|
String wholeline = Common.file2string(DatabasePath + File.separator
|
||||||
|
+ "R8Lib.c");
|
||||||
|
System.out
|
||||||
|
.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
|
||||||
|
Matcher mtrr8only = ptnr8only.matcher(wholeline);
|
||||||
|
while (mtrr8only.find()) {
|
||||||
|
r8only.add(mtrr8only.group(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String regLibExtern = "extern\\s+" + regLibDataType +
|
// -------------------------------------import------------------------------------------//
|
||||||
"\\s*(\\w[\\w\\d]*)";
|
|
||||||
private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);
|
|
||||||
|
|
||||||
private final String convertToOsFilePath(String filePath) {
|
// -------------------------------------get------------------------------------------//
|
||||||
return filePath.replace("/", File.separator).replace("\\", File.separator);
|
|
||||||
}
|
|
||||||
private final void collectLibHeaderFileInfo(String libHeaderFile, String pkgGuid) throws Exception {
|
|
||||||
String fileContents;
|
|
||||||
String libClassName;
|
|
||||||
String libContainer;
|
|
||||||
Matcher mtrLibClass;
|
|
||||||
Matcher mtrLibSymbol;
|
|
||||||
Matcher mtrLibFunction;
|
|
||||||
Matcher mtrLibExtern;
|
|
||||||
|
|
||||||
System.out.println ("Parsing: " + libHeaderFile);
|
public String getR9Lib(String r8funcname) {
|
||||||
mtrLibClass = ptnLibClassName.matcher(libHeaderFile);
|
String temp = null;
|
||||||
if (!mtrLibClass.matches()) {
|
if (hashfunc.containsKey(r8funcname)) {
|
||||||
throw new Exception("Illegal libary header file");
|
temp = hashfunc.get(r8funcname).r9libname;
|
||||||
}
|
}
|
||||||
libClassName = mtrLibClass.group(1);
|
return temp;
|
||||||
libContainer = libClassName + "@" + pkgGuid;
|
}
|
||||||
|
|
||||||
fileContents = Common.file2string(libHeaderFile);
|
public String getR9Func(String r8funcname) {
|
||||||
mtrLibSymbol = ptnLibSymbol.matcher(fileContents);
|
String temp = null;
|
||||||
while (mtrLibSymbol.find()) {
|
if (hashfunc.containsKey(r8funcname)) {
|
||||||
String libSymbol;
|
temp = hashfunc.get(r8funcname).r9funcname;
|
||||||
String oldLibContainer;
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
libSymbol = mtrLibSymbol.group(1);
|
public String getR9Macro(String r8macro) {
|
||||||
oldLibContainer = hashDbLibSymbols.put(libSymbol, libContainer);
|
return hashmacro.get(r8macro).r9name; // the verification job of if
|
||||||
if (oldLibContainer != null) {
|
// the macro exists in the
|
||||||
String warnMessage;
|
// database is done when
|
||||||
|
// registering it
|
||||||
|
}
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. " +
|
public String getR9Guidname(String r8Guid) {
|
||||||
"Later package will overide the previous one";
|
String temp = null;
|
||||||
System.out.println(warnMessage);
|
try {
|
||||||
}
|
temp = hashguid.get(r8Guid).r9name;
|
||||||
}
|
} catch (NullPointerException e) {
|
||||||
|
error.add("getR9Guidname :" + r8Guid);
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
mtrLibFunction = ptnLibFunction.matcher(fileContents);
|
public String getGuidType(String r8Guid) {
|
||||||
while (mtrLibFunction.find()) {
|
String temp = null;
|
||||||
String libFunction;
|
try {
|
||||||
String oldLibContainer;
|
temp = hashguid.get(r8Guid).type;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
error.add("getR9Guidname :" + r8Guid);
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
libFunction = mtrLibFunction.group(1);
|
// -------------------------------------get------------------------------------------//
|
||||||
oldLibContainer = hashDbLibFunctions.put(libFunction, libContainer);
|
|
||||||
if (oldLibContainer != null) {
|
|
||||||
String warnMessage;
|
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Function:" + libFunction + " Found. " +
|
// -------------------------------------has------------------------------------------//
|
||||||
"Later package will overide the previous one";
|
|
||||||
System.out.println(warnMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mtrLibExtern = ptnLibExtern.matcher(fileContents);
|
public boolean hasFunc(String r8lib) {
|
||||||
while (mtrLibExtern.find()) {
|
return hashfunc.containsKey(r8lib);
|
||||||
String libExtern;
|
}
|
||||||
String oldLibContainer;
|
|
||||||
|
|
||||||
libExtern = mtrLibExtern.group(1);
|
public boolean hasGuid(String r8guid) {
|
||||||
oldLibContainer = hashDbLibExterns.put(libExtern, libContainer);
|
return hashguid.containsKey(r8guid);
|
||||||
if (oldLibContainer != null) {
|
}
|
||||||
String warnMessage;
|
|
||||||
|
|
||||||
warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. " +
|
public boolean hasMacro(String r8macro) {
|
||||||
"Later package will overide the previous one";
|
return hashmacro.containsKey(r8macro);
|
||||||
System.out.println(warnMessage);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private final void collectLibDataBase(PackageSurfaceArea spdDatabase, String pkgDirectory) throws Exception {
|
|
||||||
String pkgGuid;
|
|
||||||
LibraryClassDeclarations libClassDeclarations;
|
|
||||||
|
|
||||||
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
// -------------------------------------has------------------------------------------//
|
||||||
libClassDeclarations = spdDatabase.getLibraryClassDeclarations();
|
|
||||||
if (libClassDeclarations != null) {
|
|
||||||
Iterator<LibraryClass> itLibClass;
|
|
||||||
|
|
||||||
itLibClass = libClassDeclarations.getLibraryClassList().iterator();
|
// -------------------------------------init------------------------------------------//
|
||||||
while (itLibClass.hasNext()) {
|
|
||||||
String libHeaderFile;
|
|
||||||
|
|
||||||
libHeaderFile = pkgDirectory + File.separator +
|
private static final Database init() {
|
||||||
itLibClass.next().getIncludeHeader();
|
if (System.getenv("WORKSPACE") == null) {
|
||||||
libHeaderFile = convertToOsFilePath (libHeaderFile);
|
return new Database("C:" + File.separator + "tianocore"
|
||||||
try {
|
+ File.separator + "edk2" + File.separator + "Tools"
|
||||||
collectLibHeaderFileInfo(libHeaderFile, pkgGuid);
|
+ File.separator + "Conf" + File.separator + "Migration");
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
String errorMessage;
|
return new Database(System.getenv("WORKSPACE") + File.separator
|
||||||
|
+ "Tools" + File.separator + "Conf" + File.separator
|
||||||
|
+ "Migration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
errorMessage = "Error (" + e.getMessage() + ")occurs when parsing " +
|
public static final Database getInstance() {
|
||||||
libHeaderFile;
|
return INSTANCE;
|
||||||
System.out.println(errorMessage);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private final void collectGuidDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
|
||||||
String pkgGuid;
|
|
||||||
GuidDeclarations guidDeclarations;
|
|
||||||
|
|
||||||
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
private String workspacePath;
|
||||||
guidDeclarations = spdDatabase.getGuidDeclarations();
|
|
||||||
if (guidDeclarations != null) {
|
|
||||||
Iterator<GuidDeclarations.Entry> itGuids;
|
|
||||||
|
|
||||||
itGuids = guidDeclarations.getEntryList().iterator();
|
private HashMap<String, String> hashDbGuids = new HashMap<String, String>();
|
||||||
while (itGuids.hasNext()) {
|
|
||||||
hashDbGuids.put(itGuids.next().getCName(), pkgGuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void collectPpiDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
private HashMap<String, String> hashDbPpis = new HashMap<String, String>();
|
||||||
String pkgGuid;
|
|
||||||
PpiDeclarations ppiDeclarations;
|
|
||||||
|
|
||||||
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
private HashMap<String, String> hashDbProtocols = new HashMap<String, String>();
|
||||||
ppiDeclarations = spdDatabase.getPpiDeclarations();
|
|
||||||
|
|
||||||
if (ppiDeclarations != null) {
|
private HashMap<String, String> hashDbLibSymbols = new HashMap<String, String>();
|
||||||
Iterator<PpiDeclarations.Entry> itPpis;
|
|
||||||
|
|
||||||
itPpis = ppiDeclarations.getEntryList().iterator();
|
private HashMap<String, String> hashDbLibFunctions = new HashMap<String, String>();
|
||||||
while (itPpis.hasNext()) {
|
|
||||||
hashDbPpis.put(itPpis.next().getCName(), pkgGuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase) throws Exception {
|
private HashMap<String, String> hashDbLibExterns = new HashMap<String, String>();
|
||||||
String pkgGuid;
|
|
||||||
ProtocolDeclarations protocolDeclarations;
|
|
||||||
|
|
||||||
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
private final String regLibClassName = ".*\\W(\\w[\\w\\d]*)\\.h";
|
||||||
protocolDeclarations = spdDatabase.getProtocolDeclarations();
|
|
||||||
|
|
||||||
if (protocolDeclarations != null) {
|
private final Pattern ptnLibClassName = Pattern.compile(regLibClassName);
|
||||||
Iterator<ProtocolDeclarations.Entry> itProtocols;
|
|
||||||
|
|
||||||
itProtocols = protocolDeclarations.getEntryList().iterator();
|
private final String regLibSymbol = "#define\\s+(\\w[\\w\\d]*)";
|
||||||
while (itProtocols.hasNext()) {
|
|
||||||
hashDbGuids.put(itProtocols.next().getCName(), pkgGuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void collectPackageDatabase(String packageFileName) throws Exception {
|
private final Pattern ptnLibSymbol = Pattern.compile(regLibSymbol);
|
||||||
XmlObject xmlPackage;
|
|
||||||
PackageSurfaceArea spdDatabase;
|
|
||||||
File pkgFile;
|
|
||||||
|
|
||||||
pkgFile = new File(packageFileName);
|
|
||||||
xmlPackage = XmlObject.Factory.parse(pkgFile);
|
|
||||||
spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage).getPackageSurfaceArea();
|
|
||||||
|
|
||||||
collectGuidDatabase(spdDatabase);
|
|
||||||
collectProtocolDatabase(spdDatabase);
|
|
||||||
collectPpiDatabase(spdDatabase);
|
|
||||||
collectLibDataBase(spdDatabase, pkgFile.getParent());
|
|
||||||
|
|
||||||
|
private final String regLibDataType = "[A-Z][A-Z0-9_]*\\s*\\**";
|
||||||
|
|
||||||
}
|
private final String regLibFunction = regLibDataType
|
||||||
public final void collectWorkSpaceDatabase() throws Exception {
|
+ "\\s*(?:EFIAPI)?\\s+" + "(\\w[\\w\\d]*)\\s*\\([^)]*\\)\\s*;";
|
||||||
String databaseFileName;
|
|
||||||
File databaseFile;
|
|
||||||
XmlObject xmlDatabase;
|
|
||||||
FrameworkDatabase frameworkDatabase;
|
|
||||||
Iterator<DbPathAndFilename> packageFile;
|
|
||||||
|
|
||||||
workspacePath = System.getenv("WORKSPACE");
|
|
||||||
|
|
||||||
if (workspacePath == null) {
|
|
||||||
String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";
|
|
||||||
throw new Exception(errorMessage);
|
|
||||||
}
|
|
||||||
databaseFileName = workspacePath + File.separator +
|
|
||||||
"Tools" + File.separator +
|
|
||||||
"Conf" + File.separator +
|
|
||||||
"FrameworkDatabase.db";
|
|
||||||
System.out.println("Open " + databaseFileName);
|
|
||||||
databaseFile = new File(databaseFileName);
|
|
||||||
xmlDatabase = XmlObject.Factory.parse(databaseFile);
|
|
||||||
frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase).getFrameworkDatabase();
|
|
||||||
packageFile = frameworkDatabase.getPackageList().getFilenameList().iterator();
|
|
||||||
|
|
||||||
while (packageFile.hasNext()) {
|
private Pattern ptnLibFunction = Pattern.compile(regLibFunction);
|
||||||
String packageFileName = packageFile.next().getStringValue();
|
|
||||||
packageFileName = workspacePath + File.separator + packageFileName;
|
|
||||||
packageFileName = convertToOsFilePath(packageFileName);
|
|
||||||
|
|
||||||
System.out.println("Parsing: " + packageFileName);
|
private final String regLibExtern = "extern\\s+" + regLibDataType
|
||||||
try {
|
+ "\\s*(\\w[\\w\\d]*)";
|
||||||
collectPackageDatabase(packageFileName);
|
|
||||||
} catch (Exception e) {
|
private final Pattern ptnLibExtern = Pattern.compile(regLibExtern);
|
||||||
System.out.println("Error occured when opening " + packageFileName + e.getMessage());
|
|
||||||
}
|
private final String convertToOsFilePath(String filePath) {
|
||||||
}
|
return filePath.replace("/", File.separator).replace("\\",
|
||||||
}
|
File.separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectLibHeaderFileInfo(String libHeaderFile,
|
||||||
|
String pkgGuid) throws Exception {
|
||||||
|
String fileContents;
|
||||||
|
String libClassName;
|
||||||
|
String libContainer;
|
||||||
|
Matcher mtrLibClass;
|
||||||
|
Matcher mtrLibSymbol;
|
||||||
|
Matcher mtrLibFunction;
|
||||||
|
Matcher mtrLibExtern;
|
||||||
|
|
||||||
|
System.out.println("Parsing: " + libHeaderFile);
|
||||||
|
mtrLibClass = ptnLibClassName.matcher(libHeaderFile);
|
||||||
|
if (!mtrLibClass.matches()) {
|
||||||
|
throw new Exception("Illegal libary header file");
|
||||||
|
}
|
||||||
|
libClassName = mtrLibClass.group(1);
|
||||||
|
libContainer = libClassName + "@" + pkgGuid;
|
||||||
|
|
||||||
|
fileContents = Common.file2string(libHeaderFile);
|
||||||
|
mtrLibSymbol = ptnLibSymbol.matcher(fileContents);
|
||||||
|
while (mtrLibSymbol.find()) {
|
||||||
|
String libSymbol;
|
||||||
|
String oldLibContainer;
|
||||||
|
|
||||||
|
libSymbol = mtrLibSymbol.group(1);
|
||||||
|
oldLibContainer = hashDbLibSymbols.put(libSymbol, libContainer);
|
||||||
|
if (oldLibContainer != null) {
|
||||||
|
String warnMessage;
|
||||||
|
|
||||||
|
warnMessage = "Duplicated Lib Symbol:" + libSymbol + " Found. "
|
||||||
|
+ "Later package will overide the previous one";
|
||||||
|
System.out.println(warnMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mtrLibFunction = ptnLibFunction.matcher(fileContents);
|
||||||
|
while (mtrLibFunction.find()) {
|
||||||
|
String libFunction;
|
||||||
|
String oldLibContainer;
|
||||||
|
|
||||||
|
libFunction = mtrLibFunction.group(1);
|
||||||
|
oldLibContainer = hashDbLibFunctions.put(libFunction, libContainer);
|
||||||
|
if (oldLibContainer != null) {
|
||||||
|
String warnMessage;
|
||||||
|
|
||||||
|
warnMessage = "Duplicated Lib Function:" + libFunction
|
||||||
|
+ " Found. "
|
||||||
|
+ "Later package will overide the previous one";
|
||||||
|
System.out.println(warnMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mtrLibExtern = ptnLibExtern.matcher(fileContents);
|
||||||
|
while (mtrLibExtern.find()) {
|
||||||
|
String libExtern;
|
||||||
|
String oldLibContainer;
|
||||||
|
|
||||||
|
libExtern = mtrLibExtern.group(1);
|
||||||
|
oldLibContainer = hashDbLibExterns.put(libExtern, libContainer);
|
||||||
|
if (oldLibContainer != null) {
|
||||||
|
String warnMessage;
|
||||||
|
|
||||||
|
warnMessage = "Duplicated Lib Extern:" + libExtern + " Found. "
|
||||||
|
+ "Later package will overide the previous one";
|
||||||
|
System.out.println(warnMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectLibDataBase(PackageSurfaceArea spdDatabase,
|
||||||
|
String pkgDirectory) throws Exception {
|
||||||
|
String pkgGuid;
|
||||||
|
LibraryClassDeclarations libClassDeclarations;
|
||||||
|
|
||||||
|
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
||||||
|
libClassDeclarations = spdDatabase.getLibraryClassDeclarations();
|
||||||
|
if (libClassDeclarations != null) {
|
||||||
|
Iterator<LibraryClass> itLibClass;
|
||||||
|
|
||||||
|
itLibClass = libClassDeclarations.getLibraryClassList().iterator();
|
||||||
|
while (itLibClass.hasNext()) {
|
||||||
|
String libHeaderFile;
|
||||||
|
|
||||||
|
libHeaderFile = pkgDirectory + File.separator
|
||||||
|
+ itLibClass.next().getIncludeHeader();
|
||||||
|
libHeaderFile = convertToOsFilePath(libHeaderFile);
|
||||||
|
try {
|
||||||
|
collectLibHeaderFileInfo(libHeaderFile, pkgGuid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String errorMessage;
|
||||||
|
|
||||||
|
errorMessage = "Error (" + e.getMessage()
|
||||||
|
+ ")occurs when parsing " + libHeaderFile;
|
||||||
|
System.out.println(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectGuidDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
|
String pkgGuid;
|
||||||
|
GuidDeclarations guidDeclarations;
|
||||||
|
|
||||||
|
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
||||||
|
guidDeclarations = spdDatabase.getGuidDeclarations();
|
||||||
|
if (guidDeclarations != null) {
|
||||||
|
Iterator<GuidDeclarations.Entry> itGuids;
|
||||||
|
|
||||||
|
itGuids = guidDeclarations.getEntryList().iterator();
|
||||||
|
while (itGuids.hasNext()) {
|
||||||
|
hashDbGuids.put(itGuids.next().getCName(), pkgGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectPpiDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
|
String pkgGuid;
|
||||||
|
PpiDeclarations ppiDeclarations;
|
||||||
|
|
||||||
|
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
||||||
|
ppiDeclarations = spdDatabase.getPpiDeclarations();
|
||||||
|
|
||||||
|
if (ppiDeclarations != null) {
|
||||||
|
Iterator<PpiDeclarations.Entry> itPpis;
|
||||||
|
|
||||||
|
itPpis = ppiDeclarations.getEntryList().iterator();
|
||||||
|
while (itPpis.hasNext()) {
|
||||||
|
hashDbPpis.put(itPpis.next().getCName(), pkgGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectProtocolDatabase(PackageSurfaceArea spdDatabase)
|
||||||
|
throws Exception {
|
||||||
|
String pkgGuid;
|
||||||
|
ProtocolDeclarations protocolDeclarations;
|
||||||
|
|
||||||
|
pkgGuid = spdDatabase.getSpdHeader().getGuidValue();
|
||||||
|
protocolDeclarations = spdDatabase.getProtocolDeclarations();
|
||||||
|
|
||||||
|
if (protocolDeclarations != null) {
|
||||||
|
Iterator<ProtocolDeclarations.Entry> itProtocols;
|
||||||
|
|
||||||
|
itProtocols = protocolDeclarations.getEntryList().iterator();
|
||||||
|
while (itProtocols.hasNext()) {
|
||||||
|
hashDbGuids.put(itProtocols.next().getCName(), pkgGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void collectPackageDatabase(String packageFileName)
|
||||||
|
throws Exception {
|
||||||
|
XmlObject xmlPackage;
|
||||||
|
PackageSurfaceArea spdDatabase;
|
||||||
|
File pkgFile;
|
||||||
|
|
||||||
|
pkgFile = new File(packageFileName);
|
||||||
|
xmlPackage = XmlObject.Factory.parse(pkgFile);
|
||||||
|
spdDatabase = ((PackageSurfaceAreaDocument) xmlPackage)
|
||||||
|
.getPackageSurfaceArea();
|
||||||
|
|
||||||
|
collectGuidDatabase(spdDatabase);
|
||||||
|
collectProtocolDatabase(spdDatabase);
|
||||||
|
collectPpiDatabase(spdDatabase);
|
||||||
|
collectLibDataBase(spdDatabase, pkgFile.getParent());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void collectWorkSpaceDatabase() throws Exception {
|
||||||
|
String databaseFileName;
|
||||||
|
File databaseFile;
|
||||||
|
XmlObject xmlDatabase;
|
||||||
|
FrameworkDatabase frameworkDatabase;
|
||||||
|
Iterator<DbPathAndFilename> packageFile;
|
||||||
|
|
||||||
|
workspacePath = System.getenv("WORKSPACE");
|
||||||
|
|
||||||
|
if (workspacePath == null) {
|
||||||
|
String errorMessage = "Envivornment variable \"WORKSPACE\" is not set!";
|
||||||
|
throw new Exception(errorMessage);
|
||||||
|
}
|
||||||
|
databaseFileName = workspacePath + File.separator + "Tools"
|
||||||
|
+ File.separator + "Conf" + File.separator
|
||||||
|
+ "FrameworkDatabase.db";
|
||||||
|
System.out.println("Open " + databaseFileName);
|
||||||
|
databaseFile = new File(databaseFileName);
|
||||||
|
xmlDatabase = XmlObject.Factory.parse(databaseFile);
|
||||||
|
frameworkDatabase = ((FrameworkDatabaseDocument) xmlDatabase)
|
||||||
|
.getFrameworkDatabase();
|
||||||
|
packageFile = frameworkDatabase.getPackageList().getFilenameList()
|
||||||
|
.iterator();
|
||||||
|
|
||||||
|
while (packageFile.hasNext()) {
|
||||||
|
String packageFileName = packageFile.next().getStringValue();
|
||||||
|
packageFileName = workspacePath + File.separator + packageFileName;
|
||||||
|
packageFileName = convertToOsFilePath(packageFileName);
|
||||||
|
|
||||||
|
System.out.println("Parsing: " + packageFileName);
|
||||||
|
try {
|
||||||
|
collectPackageDatabase(packageFileName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error occured when opening "
|
||||||
|
+ packageFileName + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,263 +12,294 @@
|
|||||||
**/
|
**/
|
||||||
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;
|
||||||
* Define class Serial Version UID
|
import javax.swing.JCheckBox;
|
||||||
*/
|
import javax.swing.JFileChooser;
|
||||||
private static final long serialVersionUID = 207759413522910399L;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
private static final FirstPanel INSTANCE = FirstPanel.init();
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
private String startpath = null;
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;
|
import javax.swing.UIManager;
|
||||||
private JTextField moduletext;
|
|
||||||
private JTextArea log;
|
|
||||||
private JFileChooser fc = new JFileChooser();
|
|
||||||
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
|
||||||
|
|
||||||
private boolean tofile = true, toscreen = true;
|
|
||||||
private PrintWriter logfile;
|
|
||||||
|
|
||||||
FirstPanel() {
|
public final class FirstPanel extends JPanel implements ActionListener,
|
||||||
GridBagLayout gridbag = new GridBagLayout();
|
ItemListener, UI {
|
||||||
setLayout(gridbag);
|
/**
|
||||||
|
* Define class Serial Version UID
|
||||||
GridBagConstraints cst = new GridBagConstraints();
|
*/
|
||||||
|
private static final long serialVersionUID = 207759413522910399L;
|
||||||
goButton = new JButton("Go");
|
|
||||||
goButton.addActionListener(this);
|
|
||||||
goButton.setActionCommand("go");
|
|
||||||
|
|
||||||
moduleButton = new JButton("Choose ModulePath");
|
|
||||||
moduleButton.addActionListener(this);
|
|
||||||
|
|
||||||
msaEditorButton = new JButton("MsaEditor");
|
private static final FirstPanel INSTANCE = FirstPanel.init();
|
||||||
msaEditorButton.addActionListener(this);
|
|
||||||
|
|
||||||
criticButton = new JButton("Critic");
|
|
||||||
criticButton.addActionListener(this);
|
|
||||||
|
|
||||||
specifyCommentButton = new JButton("Comment Style");
|
|
||||||
specifyCommentButton.addActionListener(this);
|
|
||||||
|
|
||||||
moduletext = new JTextField(30);
|
|
||||||
|
|
||||||
filebox = new JCheckBox("Output to logfile", true);
|
|
||||||
filebox.addItemListener(this);
|
|
||||||
|
|
||||||
screenbox = new JCheckBox("Specify logfile", false);
|
|
||||||
screenbox.addItemListener(this);
|
|
||||||
|
|
||||||
mibox = new JCheckBox("Print ModuleInfo", false);
|
|
||||||
mibox.addItemListener(this);
|
|
||||||
MigrationTool.printModuleInfo = false;
|
|
||||||
|
|
||||||
criticbox = new JCheckBox("Run Critic", true);
|
|
||||||
criticbox.addItemListener(this);
|
|
||||||
MigrationTool.doCritic = true;
|
|
||||||
|
|
||||||
defaultpathbox = new JCheckBox("Use Default Output Path", true);
|
|
||||||
defaultpathbox.addItemListener(this);
|
|
||||||
MigrationTool.defaultoutput = true;
|
|
||||||
|
|
||||||
JPanel modulePanel = new JPanel();
|
|
||||||
modulePanel.add(moduleButton);
|
|
||||||
modulePanel.add(moduletext);
|
|
||||||
modulePanel.add(goButton);
|
|
||||||
//modulePanel.add(msaEditorButton);
|
|
||||||
cst.gridx = 0;
|
|
||||||
cst.gridy = 0;
|
|
||||||
//cst.gridwidth = GridBagConstraints.REMAINDER;
|
|
||||||
gridbag.setConstraints(modulePanel, cst);
|
|
||||||
add(modulePanel);
|
|
||||||
|
|
||||||
cst.gridx = 1;
|
private String startpath = null;
|
||||||
cst.gridy = 0;
|
|
||||||
gridbag.setConstraints(specifyCommentButton, cst);
|
|
||||||
add(specifyCommentButton);
|
|
||||||
//gridbag.setConstraints(criticButton, cst);
|
|
||||||
//add(criticButton);
|
|
||||||
|
|
||||||
JPanel checkboxPanel = new JPanel();
|
|
||||||
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
|
|
||||||
checkboxPanel.add(filebox);
|
|
||||||
checkboxPanel.add(screenbox);
|
|
||||||
checkboxPanel.add(mibox);
|
|
||||||
checkboxPanel.add(criticbox);
|
|
||||||
checkboxPanel.add(defaultpathbox);
|
|
||||||
cst.gridx = 1;
|
|
||||||
cst.gridy = 1;
|
|
||||||
//cst.gridheight = 2;
|
|
||||||
gridbag.setConstraints(checkboxPanel, cst);
|
|
||||||
add(checkboxPanel);
|
|
||||||
|
|
||||||
log = new JTextArea(10,20);
|
|
||||||
log.setMargin(new Insets(5,5,5,5));
|
|
||||||
log.setEditable(false);
|
|
||||||
JScrollPane logScrollPane = new JScrollPane(log);
|
|
||||||
cst.gridx = 0;
|
|
||||||
cst.gridy = 1;
|
|
||||||
cst.fill = GridBagConstraints.BOTH;
|
|
||||||
gridbag.setConstraints(logScrollPane, cst);
|
|
||||||
add(logScrollPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
public boolean yesOrNo(String question) {
|
|
||||||
return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void print(String message) {
|
|
||||||
if (toscreen == true) {
|
|
||||||
log.append(message);
|
|
||||||
System.out.print(message);
|
|
||||||
}
|
|
||||||
if (tofile == true) {
|
|
||||||
logfile.append(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void println(String message) {
|
|
||||||
print(message + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void println(Set<String> hash) {
|
private JButton moduleButton, goButton, msaEditorButton, criticButton,
|
||||||
if (toscreen == true) {
|
specifyCommentButton;
|
||||||
log.append(hash + "\n");
|
|
||||||
System.out.println(hash);
|
|
||||||
}
|
|
||||||
if (tofile == true) {
|
|
||||||
logfile.append(hash + "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String choose(String message, Object[] choicelist) {
|
private JTextField moduletext;
|
||||||
return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInput(String message) {
|
|
||||||
return (String)JOptionPane.showInputDialog(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
private JTextArea log;
|
||||||
|
|
||||||
public String getFilepath(String title, int mode) {
|
private JFileChooser fc = new JFileChooser();
|
||||||
fc.setDialogTitle(title);
|
|
||||||
fc.setFileSelectionMode(mode);
|
|
||||||
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
||||||
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
|
|
||||||
return fc.getSelectedFile().getAbsolutePath();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
private boolean tofile = true, toscreen = true;
|
||||||
if ( e.getSource() == moduleButton ) {
|
|
||||||
startpath = getFilepath("Please choose a starting path", JFileChooser.DIRECTORIES_ONLY);
|
|
||||||
moduletext.setText(startpath);
|
|
||||||
}
|
|
||||||
if ( e.getSource() == goButton ) {
|
|
||||||
try {
|
|
||||||
logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + "migration.log")));
|
|
||||||
MigrationTool.startMigrateAll(startpath);
|
|
||||||
logfile.flush();
|
|
||||||
logfile.close();
|
|
||||||
} catch (Exception en) {
|
|
||||||
println(en.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( e.getSource() == msaEditorButton) {
|
|
||||||
try {
|
|
||||||
MsaTreeEditor.init();
|
|
||||||
} catch (Exception en) {
|
|
||||||
println(en.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( e.getSource() == criticButton) {
|
|
||||||
try {
|
|
||||||
Critic.fireAt(startpath);
|
|
||||||
} catch (Exception en) {
|
|
||||||
println(en.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( e.getSource() == specifyCommentButton) {
|
|
||||||
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");
|
|
||||||
//MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
|
||||||
} catch (Exception en) {
|
|
||||||
println(en.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void itemStateChanged(ItemEvent e) {
|
|
||||||
if (e.getSource() == filebox) {
|
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
||||||
System.out.println("filebox DESELECTED");
|
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
||||||
System.out.println("filebox SELECTED");
|
|
||||||
}
|
|
||||||
} else if (e.getSource() == screenbox) {
|
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
||||||
System.out.println("screenbox DESELECTED");
|
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
||||||
System.out.println("screenbox SELECTED");
|
|
||||||
}
|
|
||||||
} else if (e.getSource() == mibox) {
|
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
||||||
MigrationTool.printModuleInfo = false;
|
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
||||||
MigrationTool.printModuleInfo = true;
|
|
||||||
}
|
|
||||||
} else if (e.getSource() == criticbox) {
|
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
||||||
MigrationTool.doCritic = false;
|
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
||||||
MigrationTool.doCritic = true;
|
|
||||||
}
|
|
||||||
} else if (e.getSource() == defaultpathbox) {
|
|
||||||
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
||||||
MigrationTool.defaultoutput = false;
|
|
||||||
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
||||||
MigrationTool.defaultoutput = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------//
|
private PrintWriter logfile;
|
||||||
|
|
||||||
private static final FirstPanel init() {
|
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
JFrame frame = new JFrame("MigrationTools");
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
FirstPanel fp = new FirstPanel();
|
FirstPanel() {
|
||||||
fp.setOpaque(true);
|
GridBagLayout gridbag = new GridBagLayout();
|
||||||
frame.setContentPane(fp);
|
setLayout(gridbag);
|
||||||
|
|
||||||
frame.pack();
|
GridBagConstraints cst = new GridBagConstraints();
|
||||||
frame.setVisible(true);
|
|
||||||
|
goButton = new JButton("Go");
|
||||||
return fp;
|
goButton.addActionListener(this);
|
||||||
}
|
goButton.setActionCommand("go");
|
||||||
|
|
||||||
public static final FirstPanel getInstance() {
|
moduleButton = new JButton("Choose ModulePath");
|
||||||
return INSTANCE;
|
moduleButton.addActionListener(this);
|
||||||
}
|
|
||||||
|
msaEditorButton = new JButton("MsaEditor");
|
||||||
|
msaEditorButton.addActionListener(this);
|
||||||
|
|
||||||
|
criticButton = new JButton("Critic");
|
||||||
|
criticButton.addActionListener(this);
|
||||||
|
|
||||||
|
specifyCommentButton = new JButton("Comment Style");
|
||||||
|
specifyCommentButton.addActionListener(this);
|
||||||
|
|
||||||
|
moduletext = new JTextField(30);
|
||||||
|
|
||||||
|
filebox = new JCheckBox("Output to logfile", true);
|
||||||
|
filebox.addItemListener(this);
|
||||||
|
|
||||||
|
screenbox = new JCheckBox("Specify logfile", false);
|
||||||
|
screenbox.addItemListener(this);
|
||||||
|
|
||||||
|
mibox = new JCheckBox("Print ModuleInfo", false);
|
||||||
|
mibox.addItemListener(this);
|
||||||
|
MigrationTool.printModuleInfo = false;
|
||||||
|
|
||||||
|
criticbox = new JCheckBox("Run Critic", true);
|
||||||
|
criticbox.addItemListener(this);
|
||||||
|
MigrationTool.doCritic = true;
|
||||||
|
|
||||||
|
defaultpathbox = new JCheckBox("Use Default Output Path", true);
|
||||||
|
defaultpathbox.addItemListener(this);
|
||||||
|
MigrationTool.defaultoutput = true;
|
||||||
|
|
||||||
|
JPanel modulePanel = new JPanel();
|
||||||
|
modulePanel.add(moduleButton);
|
||||||
|
modulePanel.add(moduletext);
|
||||||
|
modulePanel.add(goButton);
|
||||||
|
// modulePanel.add(msaEditorButton);
|
||||||
|
cst.gridx = 0;
|
||||||
|
cst.gridy = 0;
|
||||||
|
// cst.gridwidth = GridBagConstraints.REMAINDER;
|
||||||
|
gridbag.setConstraints(modulePanel, cst);
|
||||||
|
add(modulePanel);
|
||||||
|
|
||||||
|
cst.gridx = 1;
|
||||||
|
cst.gridy = 0;
|
||||||
|
gridbag.setConstraints(specifyCommentButton, cst);
|
||||||
|
add(specifyCommentButton);
|
||||||
|
// gridbag.setConstraints(criticButton, cst);
|
||||||
|
// add(criticButton);
|
||||||
|
|
||||||
|
JPanel checkboxPanel = new JPanel();
|
||||||
|
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
|
||||||
|
checkboxPanel.add(filebox);
|
||||||
|
checkboxPanel.add(screenbox);
|
||||||
|
checkboxPanel.add(mibox);
|
||||||
|
checkboxPanel.add(criticbox);
|
||||||
|
checkboxPanel.add(defaultpathbox);
|
||||||
|
cst.gridx = 1;
|
||||||
|
cst.gridy = 1;
|
||||||
|
// cst.gridheight = 2;
|
||||||
|
gridbag.setConstraints(checkboxPanel, cst);
|
||||||
|
add(checkboxPanel);
|
||||||
|
|
||||||
|
log = new JTextArea(10, 20);
|
||||||
|
log.setMargin(new Insets(5, 5, 5, 5));
|
||||||
|
log.setEditable(false);
|
||||||
|
JScrollPane logScrollPane = new JScrollPane(log);
|
||||||
|
cst.gridx = 0;
|
||||||
|
cst.gridy = 1;
|
||||||
|
cst.fill = GridBagConstraints.BOTH;
|
||||||
|
gridbag.setConstraints(logScrollPane, cst);
|
||||||
|
add(logScrollPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
public boolean yesOrNo(String question) {
|
||||||
|
return JOptionPane.showConfirmDialog(this, question, "Yes or No",
|
||||||
|
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print(String message) {
|
||||||
|
if (toscreen == true) {
|
||||||
|
log.append(message);
|
||||||
|
System.out.print(message);
|
||||||
|
}
|
||||||
|
if (tofile == true) {
|
||||||
|
logfile.append(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void println(String message) {
|
||||||
|
print(message + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void println(Set<String> hash) {
|
||||||
|
if (toscreen == true) {
|
||||||
|
log.append(hash + "\n");
|
||||||
|
System.out.println(hash);
|
||||||
|
}
|
||||||
|
if (tofile == true) {
|
||||||
|
logfile.append(hash + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String choose(String message, Object[] choicelist) {
|
||||||
|
return (String) JOptionPane.showInputDialog(this, message, "Choose",
|
||||||
|
JOptionPane.PLAIN_MESSAGE, null, choicelist, choicelist[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInput(String message) {
|
||||||
|
return (String) JOptionPane.showInputDialog(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
public String getFilepath(String title, int mode) {
|
||||||
|
fc.setDialogTitle(title);
|
||||||
|
fc.setFileSelectionMode(mode);
|
||||||
|
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
|
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
|
||||||
|
return fc.getSelectedFile().getAbsolutePath();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (e.getSource() == moduleButton) {
|
||||||
|
startpath = getFilepath("Please choose a starting path",
|
||||||
|
JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
moduletext.setText(startpath);
|
||||||
|
}
|
||||||
|
if (e.getSource() == goButton) {
|
||||||
|
try {
|
||||||
|
logfile = new PrintWriter(new BufferedWriter(new FileWriter(
|
||||||
|
startpath.replaceAll(Common.STRSEPARATER, "$1")
|
||||||
|
+ File.separator + "migration.log")));
|
||||||
|
MigrationTool.startMigrateAll(startpath);
|
||||||
|
logfile.flush();
|
||||||
|
logfile.close();
|
||||||
|
} catch (Exception en) {
|
||||||
|
println(en.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getSource() == msaEditorButton) {
|
||||||
|
try {
|
||||||
|
MsaTreeEditor.init();
|
||||||
|
} catch (Exception en) {
|
||||||
|
println(en.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getSource() == criticButton) {
|
||||||
|
try {
|
||||||
|
Critic.fireAt(startpath);
|
||||||
|
} catch (Exception en) {
|
||||||
|
println(en.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getSource() == specifyCommentButton) {
|
||||||
|
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");
|
||||||
|
// MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
|
||||||
|
} catch (Exception en) {
|
||||||
|
println(en.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
if (e.getSource() == filebox) {
|
||||||
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
|
System.out.println("filebox DESELECTED");
|
||||||
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
System.out.println("filebox SELECTED");
|
||||||
|
}
|
||||||
|
} else if (e.getSource() == screenbox) {
|
||||||
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
|
System.out.println("screenbox DESELECTED");
|
||||||
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
System.out.println("screenbox SELECTED");
|
||||||
|
}
|
||||||
|
} else if (e.getSource() == mibox) {
|
||||||
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
|
MigrationTool.printModuleInfo = false;
|
||||||
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
MigrationTool.printModuleInfo = true;
|
||||||
|
}
|
||||||
|
} else if (e.getSource() == criticbox) {
|
||||||
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
|
MigrationTool.doCritic = false;
|
||||||
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
MigrationTool.doCritic = true;
|
||||||
|
}
|
||||||
|
} else if (e.getSource() == defaultpathbox) {
|
||||||
|
if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||||
|
MigrationTool.defaultoutput = false;
|
||||||
|
} else if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
MigrationTool.defaultoutput = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
private static final FirstPanel init() {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
JFrame frame = new JFrame("MigrationTools");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
FirstPanel fp = new FirstPanel();
|
||||||
|
fp.setOpaque(true);
|
||||||
|
frame.setContentPane(fp);
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
return fp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final FirstPanel getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,44 +12,62 @@
|
|||||||
**/
|
**/
|
||||||
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) {
|
|
||||||
r8funcname = linecontext[1];
|
|
||||||
r8libname = linecontext[0];
|
|
||||||
r9funcname = linecontext[2];
|
|
||||||
if (r9funcname.contains("n/a")) {
|
|
||||||
r9funcname = "#error Unknown or missing library function in EDKII: " + r8funcname;
|
|
||||||
}
|
|
||||||
r9libname = linecontext[3];
|
|
||||||
}
|
|
||||||
public String r8funcname;
|
|
||||||
public String r8libname;
|
|
||||||
public String r9funcname;
|
|
||||||
public String r9libname;
|
|
||||||
|
|
||||||
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);
|
Func(String[] linecontext) {
|
||||||
public static Pattern ptnfuncc = Pattern.compile("(?<!->)([a-zA-Z_]\\w*)\\s*\\(",Pattern.MULTILINE);
|
r8funcname = linecontext[1];
|
||||||
public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);
|
r8libname = linecontext[0];
|
||||||
public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed
|
r9funcname = linecontext[2];
|
||||||
|
if (r9funcname.contains("n/a")) {
|
||||||
private static String reservedwords = "if for pack while switch return sizeof";
|
r9funcname = "#error Unknown or missing library function in EDKII: "
|
||||||
|
+ r8funcname;
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
}
|
||||||
String temp = null;
|
r9libname = linecontext[3];
|
||||||
|
}
|
||||||
|
|
||||||
temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls
|
public String r8funcname;
|
||||||
Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged
|
|
||||||
if (!reservedwords.contains(temp) && mtrlowcase.find()) {
|
public String r8libname;
|
||||||
mi.hashfuncc.add(temp);
|
|
||||||
}
|
public String r9funcname;
|
||||||
return temp;
|
|
||||||
}
|
public String r9libname;
|
||||||
|
|
||||||
|
public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",
|
||||||
|
Pattern.MULTILINE);
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
|
String temp = null;
|
||||||
|
|
||||||
|
temp = mtr.group(1); // both changed and not changed funcc are
|
||||||
|
// 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()) {
|
||||||
|
mi.hashfuncc.add(temp);
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,55 +12,66 @@
|
|||||||
**/
|
**/
|
||||||
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;
|
||||||
r9name = r9;
|
r9name = r9;
|
||||||
guidvalue = gv;
|
guidvalue = gv;
|
||||||
pack = p;
|
pack = p;
|
||||||
}
|
}
|
||||||
Guid (String[] linecontext, String t) {
|
|
||||||
r8name = linecontext[1];
|
|
||||||
type = t;
|
|
||||||
name = linecontext[0];
|
|
||||||
r9name = linecontext[2];
|
|
||||||
guidvalue = linecontext[3];
|
|
||||||
pack = linecontext[4];
|
|
||||||
}
|
|
||||||
public String r8name;
|
|
||||||
public String type;
|
|
||||||
public String name;
|
|
||||||
public String r9name;
|
|
||||||
public String guidvalue;
|
|
||||||
public String pack;
|
|
||||||
|
|
||||||
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
Guid(String[] linecontext, String t) {
|
||||||
|
r8name = linecontext[1];
|
||||||
|
type = t;
|
||||||
|
name = linecontext[0];
|
||||||
|
r9name = linecontext[2];
|
||||||
|
guidvalue = linecontext[3];
|
||||||
|
pack = linecontext[4];
|
||||||
|
}
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public String r8name;
|
||||||
String type = null;
|
|
||||||
String temp = null;
|
public String type;
|
||||||
|
|
||||||
temp = mtr.group();
|
public String name;
|
||||||
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);
|
public String r9name;
|
||||||
if (type.matches("Protocol")) {
|
|
||||||
mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);
|
public String guidvalue;
|
||||||
//mi.protocols.add(temp);
|
|
||||||
} else if (type.matches("Ppi")) {
|
public String pack;
|
||||||
mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);
|
|
||||||
//mi.ppis.add(temp);
|
public static Pattern ptnguid = Pattern.compile("g\\w*Guid");
|
||||||
} else if (type.matches("Guid")) {
|
|
||||||
mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
//mi.guids.add(temp);
|
String type = null;
|
||||||
}
|
String temp = null;
|
||||||
return temp;
|
|
||||||
}
|
temp = mtr.group();
|
||||||
return null;
|
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);
|
||||||
|
if (type.matches("Protocol")) {
|
||||||
|
mi.addProtocol(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
// mi.protocols.add(temp);
|
||||||
|
} else if (type.matches("Ppi")) {
|
||||||
|
mi.addPpi(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
// mi.ppis.add(temp);
|
||||||
|
} else if (type.matches("Guid")) {
|
||||||
|
mi.addGuid(temp, UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
// mi.guids.add(temp);
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,36 +12,43 @@
|
|||||||
**/
|
**/
|
||||||
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) {
|
|
||||||
r8name = linecontext[0];
|
|
||||||
r9name = linecontext[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
public String r8name;
|
|
||||||
public String r9name;
|
|
||||||
|
|
||||||
public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",Pattern.MULTILINE);
|
Macro(String[] linecontext) {
|
||||||
|
r8name = linecontext[0];
|
||||||
|
r9name = linecontext[1];
|
||||||
|
}
|
||||||
|
|
||||||
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
public String r8name;
|
||||||
|
|
||||||
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
public String r9name;
|
||||||
String temp = null;
|
|
||||||
|
public static Pattern ptntmacro = Pattern.compile("\\b\\w(\\w|\\d)*",
|
||||||
temp = mtr.group();
|
Pattern.MULTILINE);
|
||||||
mi.hashmacro.add(temp);
|
|
||||||
if (MigrationTool.db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones
|
private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";
|
||||||
if (!unmacro.contains(temp)) {
|
|
||||||
mi.hashnonlocalmacro.add(temp);
|
public static String register(Matcher mtr, ModuleInfo mi, Database db) {
|
||||||
}
|
String temp = null;
|
||||||
return temp;
|
|
||||||
}
|
temp = mtr.group();
|
||||||
return null;
|
mi.hashmacro.add(temp);
|
||||||
}
|
if (MigrationTool.db.hasMacro(temp)) { // only changed macros
|
||||||
|
// registered, because the
|
||||||
|
// database of macro has only
|
||||||
|
// changed ones
|
||||||
|
if (!unmacro.contains(temp)) {
|
||||||
|
mi.hashnonlocalmacro.add(temp);
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,102 +13,157 @@
|
|||||||
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 {
|
||||||
public static UI ui = null;
|
|
||||||
public static Database db = null;
|
|
||||||
|
|
||||||
public static String MIGRATIONCOMMENT = "//@MT:";
|
//
|
||||||
|
// These two objects are serves globally, it is always required, and only
|
||||||
|
// one instance is ever allowed.
|
||||||
|
//
|
||||||
|
public static UI ui = null;
|
||||||
|
|
||||||
public static boolean printModuleInfo = false;
|
public static Database db = null;
|
||||||
public static boolean doCritic = false;
|
|
||||||
public static boolean defaultoutput = false;
|
|
||||||
|
|
||||||
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
|
||||||
|
|
||||||
private static String startpath = null;
|
//
|
||||||
|
// The global constant for MigrationTool generated comments.
|
||||||
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
//
|
||||||
ModuleReader.aimAt(mi);
|
public static String MIGRATIONCOMMENT = "//@MT:";
|
||||||
SourceFileReplacer.fireAt(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
|
|
||||||
|
|
||||||
// show result
|
//
|
||||||
if (MigrationTool.printModuleInfo) {
|
// Global switches that are changed by user by the FirstPanel.
|
||||||
MigrationTool.ui.println("\nModule Information : ");
|
//
|
||||||
MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);
|
public static boolean printModuleInfo = false;
|
||||||
show(mi.protocols, "Protocol : ");
|
|
||||||
show(mi.ppis, "Ppi : ");
|
|
||||||
show(mi.guids, "Guid : ");
|
|
||||||
show(mi.hashfuncc, "call : ");
|
|
||||||
show(mi.hashfuncd, "def : ");
|
|
||||||
show(mi.hashEFIcall, "EFIcall : ");
|
|
||||||
show(mi.hashnonlocalmacro, "macro : ");
|
|
||||||
show(mi.hashnonlocalfunc, "nonlocal : ");
|
|
||||||
show(mi.hashr8only, "hashr8only : ");
|
|
||||||
}
|
|
||||||
new MsaWriter(mi).flush();
|
|
||||||
|
|
||||||
//mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".___");
|
public static boolean doCritic = false;
|
||||||
|
|
||||||
if (MigrationTool.doCritic) {
|
public static boolean defaultoutput = false;
|
||||||
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename);
|
|
||||||
}
|
|
||||||
|
|
||||||
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
//
|
||||||
MigrationTool.ui.println("Complete!");
|
// A hashmap that associates the reference to a ModuleInfo with its
|
||||||
}
|
// outputpath.
|
||||||
|
//
|
||||||
|
public static final HashMap<ModuleInfo, String> ModuleInfoMap = new HashMap<ModuleInfo, String>();
|
||||||
|
|
||||||
private static final void show(Set<String> hash, String show) {
|
//
|
||||||
MigrationTool.ui.println(show + hash.size());
|
// The starting point of the MigrationTool.
|
||||||
MigrationTool.ui.println(hash);
|
//
|
||||||
}
|
private static String startpath = null;
|
||||||
|
|
||||||
public static final String getTempDir(String modulepath) {
|
/**
|
||||||
return "C:" + File.separator + "MigrationTool_Temp" + modulepath.replace(startpath, "");
|
* This method defines the overall main work flow of the MigrationTool.
|
||||||
}
|
*
|
||||||
|
* @param mi
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static final void mainFlow(ModuleInfo mi) throws Exception {
|
||||||
|
ModuleReader.aimAt(mi);
|
||||||
|
SourceFileReplacer.fireAt(mi); // some adding library actions are taken
|
||||||
|
// here,so it must be put before
|
||||||
|
// "MsaWriter"
|
||||||
|
|
||||||
private static final String assignOutPutPath(String inputpath) {
|
// show result
|
||||||
if (MigrationTool.defaultoutput) {
|
if (MigrationTool.printModuleInfo) {
|
||||||
return inputpath.replaceAll(Common.STRSEPARATER, "$1");
|
MigrationTool.ui.println("\nModule Information : ");
|
||||||
} else {
|
MigrationTool.ui.println("Entrypoint : " + mi.entrypoint);
|
||||||
return MigrationTool.ui.getFilepath("Please choose where to place the output module", JFileChooser.DIRECTORIES_ONLY);
|
show(mi.protocols, "Protocol : ");
|
||||||
}
|
show(mi.ppis, "Ppi : ");
|
||||||
}
|
show(mi.guids, "Guid : ");
|
||||||
|
show(mi.hashfuncc, "call : ");
|
||||||
public static final void seekModule(String filepath) throws Exception {
|
show(mi.hashfuncd, "def : ");
|
||||||
if (ModuleInfo.isModule(filepath)) {
|
show(mi.hashEFIcall, "EFIcall : ");
|
||||||
ModuleInfoMap.put(new ModuleInfo(filepath), assignOutPutPath(filepath));
|
show(mi.hashnonlocalmacro, "macro : ");
|
||||||
}
|
show(mi.hashnonlocalfunc, "nonlocal : ");
|
||||||
}
|
show(mi.hashr8only, "hashr8only : ");
|
||||||
|
}
|
||||||
|
new MsaWriter(mi).flush();
|
||||||
|
|
||||||
public static final void startMigrateAll(String path) throws Exception {
|
// mi.getMsaOwner().flush(MigrationTool.ModuleInfoMap.get(mi) +
|
||||||
startpath = path;
|
// File.separator + "Migration_" + mi.modulename + File.separator +
|
||||||
MigrationTool.ui.println("Project Migration");
|
// mi.modulename + ".___");
|
||||||
MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");
|
|
||||||
|
|
||||||
if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {
|
|
||||||
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
|
||||||
}
|
|
||||||
|
|
||||||
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule", String.class), null, null, Common.DIR);
|
|
||||||
|
|
||||||
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
|
||||||
while (miit.hasNext()) {
|
|
||||||
mainFlow(miit.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
ModuleInfoMap.clear();
|
|
||||||
|
|
||||||
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
if (MigrationTool.doCritic) {
|
||||||
ui = FirstPanel.getInstance();
|
Critic.fireAt(ModuleInfoMap.get(mi) + File.separator + "Migration_"
|
||||||
db = Database.getInstance();
|
+ mi.modulename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);
|
||||||
|
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) {
|
||||||
|
MigrationTool.ui.println(show + hash.size());
|
||||||
|
MigrationTool.ui.println(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method designates the location of temp directory.
|
||||||
|
*
|
||||||
|
* @param modulepath
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String getTempDir(String modulepath) {
|
||||||
|
return "C:" + File.separator + "MigrationTool_Temp"
|
||||||
|
+ modulepath.replace(startpath, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String assignOutPutPath(String inputpath) {
|
||||||
|
if (MigrationTool.defaultoutput) {
|
||||||
|
return inputpath.replaceAll(Common.STRSEPARATER, "$1");
|
||||||
|
} else {
|
||||||
|
return MigrationTool.ui.getFilepath(
|
||||||
|
"Please choose where to place the output module",
|
||||||
|
JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void seekModule(String filepath) throws Exception {
|
||||||
|
if (ModuleInfo.isModule(filepath)) {
|
||||||
|
ModuleInfoMap.put(new ModuleInfo(filepath),
|
||||||
|
assignOutPutPath(filepath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void startMigrateAll(String path) throws Exception {
|
||||||
|
startpath = path;
|
||||||
|
MigrationTool.ui.println("Project Migration");
|
||||||
|
MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");
|
||||||
|
|
||||||
|
if (new File("C:" + File.separator + "MigrationTool_Temp").exists()) {
|
||||||
|
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
||||||
|
}
|
||||||
|
|
||||||
|
Common.toDoAll(path, MigrationTool.class.getMethod("seekModule",
|
||||||
|
String.class), null, null, Common.DIR);
|
||||||
|
|
||||||
|
Iterator<ModuleInfo> miit = ModuleInfoMap.keySet().iterator();
|
||||||
|
while (miit.hasNext()) {
|
||||||
|
mainFlow(miit.next());
|
||||||
|
}
|
||||||
|
|
||||||
|
ModuleInfoMap.clear();
|
||||||
|
|
||||||
|
Common.deleteDir("C:" + File.separator + "MigrationTool_Temp");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
ui = FirstPanel.getInstance();
|
||||||
|
db = Database.getInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,128 +12,164 @@
|
|||||||
**/
|
**/
|
||||||
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;
|
||||||
this.temppath = MigrationTool.getTempDir(this.modulepath);
|
this.temppath = MigrationTool.getTempDir(this.modulepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String modulepath;
|
public final String modulepath;
|
||||||
public final String temppath;
|
|
||||||
|
|
||||||
private MsaOwner msaowner = MsaOwner.initNewMsaOwner();
|
|
||||||
|
|
||||||
public String modulename = null;
|
|
||||||
public String guidvalue = null;
|
|
||||||
public String moduletype = null;
|
|
||||||
public String entrypoint = null;
|
|
||||||
public String license = null;
|
|
||||||
|
|
||||||
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> 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> infsources = new HashSet<String>();
|
|
||||||
|
|
||||||
public final Set<String> hashfuncc = new HashSet<String>();
|
|
||||||
public final Set<String> hashfuncd = new HashSet<String>();
|
|
||||||
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
|
||||||
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
|
||||||
public final Set<String> hashEFIcall = new HashSet<String>();
|
|
||||||
public final Set<String> hashr8only = 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> guids = new HashSet<String>();
|
|
||||||
public final Set<String> protocols = new HashSet<String>();
|
|
||||||
public final Set<String> ppis = new HashSet<String>();
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------//
|
public final String temppath;
|
||||||
|
|
||||||
//addModuleType
|
private MsaOwner msaowner = MsaOwner.initNewMsaOwner();
|
||||||
//addGuidValue
|
|
||||||
//addModuleName
|
|
||||||
|
|
||||||
public final boolean addSourceFile (String filename, Enum en) {
|
|
||||||
localmodulesources.add(filename);
|
|
||||||
return msaowner.addSourceFile(filename, en);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
|
|
||||||
protocols.add(proname);
|
|
||||||
return msaowner.addProtocol(proname, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
|
|
||||||
ppis.add(ppiname);
|
|
||||||
return msaowner.addPpi(ppiname, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
|
|
||||||
guids.add(guidname);
|
|
||||||
return msaowner.addGuid(guidname, usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
|
||||||
//
|
|
||||||
// This section is only for adding library classes, this functionality should be inside MsaOwner!!!
|
|
||||||
//
|
|
||||||
//if (!hashrequiredr9libs.contains(name)) {
|
|
||||||
msaowner.addLibraryClass(name, usage);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
hashrequiredr9libs.add(name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
public final String getModuleType() {
|
|
||||||
if (moduletype.contains("PEI")) {
|
|
||||||
return "PEIM";
|
|
||||||
} else {
|
|
||||||
return "DXE_DRIVER";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void enroll(String filepath) throws Exception {
|
|
||||||
String temp = null;
|
|
||||||
if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
|
||||||
temp = filepath.replace(modulepath + File.separator, "");
|
|
||||||
if (!temp.contains(File.separator)) { // .inf in subdirectory is not regarded
|
|
||||||
msaorinf.add(temp);
|
|
||||||
}
|
|
||||||
} else if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
|
|
||||||
filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni") ||
|
|
||||||
filepath.contains(".s") || filepath.contains(".S") || filepath.contains(".i") ||
|
|
||||||
filepath.contains(".asm")) {
|
|
||||||
addSourceFile(filepath.replace(modulepath + File.separator, ""), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final boolean isModule(String path) {
|
public String modulename = null;
|
||||||
String[] list = new File(path).list();
|
|
||||||
for (int i = 0 ; i < list.length ; i++) {
|
public String guidvalue = null;
|
||||||
if (!new File(list[i]).isDirectory()) {
|
|
||||||
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
public String moduletype = null;
|
||||||
return true;
|
|
||||||
}
|
public String entrypoint = null;
|
||||||
}
|
|
||||||
}
|
public String license = null;
|
||||||
return false;
|
|
||||||
}
|
public final Set<String> localmodulesources = new HashSet<String>(); // contains
|
||||||
|
// both
|
||||||
public final MsaOwner getMsaOwner() {
|
// .c
|
||||||
return msaowner;
|
// and
|
||||||
}
|
// .h
|
||||||
|
|
||||||
|
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> infincludes = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> infsources = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashfuncc = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashfuncd = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashnonlocalfunc = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashnonlocalmacro = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashEFIcall = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> hashr8only = 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> guids = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> protocols = new HashSet<String>();
|
||||||
|
|
||||||
|
public final Set<String> ppis = new HashSet<String>();
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
// addModuleType
|
||||||
|
// addGuidValue
|
||||||
|
// addModuleName
|
||||||
|
|
||||||
|
public final boolean addSourceFile(String filename, Enum en) {
|
||||||
|
localmodulesources.add(filename);
|
||||||
|
return msaowner.addSourceFile(filename, en);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addProtocol(String proname, UsageTypes.Enum usage) {
|
||||||
|
protocols.add(proname);
|
||||||
|
return msaowner.addProtocol(proname, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {
|
||||||
|
ppis.add(ppiname);
|
||||||
|
return msaowner.addPpi(ppiname, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addGuid(String guidname, UsageTypes.Enum usage) {
|
||||||
|
guids.add(guidname);
|
||||||
|
return msaowner.addGuid(guidname, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
||||||
|
//
|
||||||
|
// This section is only for adding library classes, this functionality
|
||||||
|
// should be inside MsaOwner!!!
|
||||||
|
//
|
||||||
|
// if (!hashrequiredr9libs.contains(name)) {
|
||||||
|
msaowner.addLibraryClass(name, usage);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
hashrequiredr9libs.add(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
public final String getModuleType() {
|
||||||
|
if (moduletype.contains("PEI")) {
|
||||||
|
return "PEIM";
|
||||||
|
} else {
|
||||||
|
return "DXE_DRIVER";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void enroll(String filepath) throws Exception {
|
||||||
|
String temp = null;
|
||||||
|
if (filepath.contains(".inf") || filepath.contains(".msa")) {
|
||||||
|
temp = filepath.replace(modulepath + File.separator, "");
|
||||||
|
if (!temp.contains(File.separator)) { // .inf in subdirectory is
|
||||||
|
// not regarded
|
||||||
|
msaorinf.add(temp);
|
||||||
|
}
|
||||||
|
} else if (filepath.contains(".c") || filepath.contains(".C")
|
||||||
|
|| filepath.contains(".h") || filepath.contains(".H")
|
||||||
|
|| filepath.contains(".dxs") || filepath.contains(".uni")
|
||||||
|
|| filepath.contains(".s") || filepath.contains(".S")
|
||||||
|
|| filepath.contains(".i") || filepath.contains(".asm")) {
|
||||||
|
addSourceFile(filepath.replace(modulepath + File.separator, ""),
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final boolean isModule(String path) {
|
||||||
|
String[] list = new File(path).list();
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
if (!new File(list[i]).isDirectory()) {
|
||||||
|
if (list[i].contains(".inf") || list[i].contains(".msa")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final MsaOwner getMsaOwner() {
|
||||||
|
return msaowner;
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,331 +12,395 @@
|
|||||||
**/
|
**/
|
||||||
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 final CommentLaplace commentlaplace = new CommentLaplace();
|
|
||||||
|
|
||||||
private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
|
||||||
private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
|
||||||
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
|
||||||
|
|
||||||
public final void ModuleScan() throws Exception {
|
private ModuleInfo mi;
|
||||||
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE);
|
|
||||||
|
|
||||||
// inf&msa
|
private final CommentLaplace commentlaplace = new CommentLaplace();
|
||||||
String filename = null;
|
|
||||||
if (mi.msaorinf.isEmpty()) {
|
|
||||||
MigrationTool.ui.println("No INF nor MSA file found!");
|
|
||||||
System.exit(0);
|
|
||||||
} else {
|
|
||||||
if (mi.msaorinf.size() == 1) {
|
|
||||||
filename = (String)mi.msaorinf.toArray()[0];
|
|
||||||
} else {
|
|
||||||
filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filename.contains(".inf")) {
|
private static final Pattern ptninfequation = Pattern
|
||||||
readInf(filename);
|
.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
|
||||||
} else if (filename.contains(".msa")) {
|
|
||||||
readMsa(filename);
|
|
||||||
}
|
|
||||||
// inf&msa
|
|
||||||
|
|
||||||
preProcessModule();
|
private static final Pattern ptnsection = Pattern.compile(
|
||||||
}
|
"\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
|
||||||
|
|
||||||
private final void readMsa(String name) throws Exception {
|
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
|
|
||||||
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
|
|
||||||
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
|
||||||
|
|
||||||
mi.modulename = msaheader.getModuleName();
|
private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
|
||||||
mi.guidvalue = msaheader.getGuidValue();
|
|
||||||
mi.moduletype = msaheader.getModuleType().toString(); // ???
|
|
||||||
|
|
||||||
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
public final void ModuleScan() throws Exception {
|
||||||
|
Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll",
|
||||||
String temp;
|
String.class), mi, null, Common.FILE);
|
||||||
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
|
|
||||||
while (li.hasNext()) {
|
|
||||||
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
|
||||||
System.out.println("Source File Missing! : " + temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private final String extractLicense(String wholeline) throws Exception {
|
|
||||||
String tempLine;
|
|
||||||
String license = null;
|
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new StringReader(wholeline));
|
// inf&msa
|
||||||
while ((tempLine = rd.readLine()) != null) {
|
String filename = null;
|
||||||
if (tempLine.contains("#")) {
|
if (mi.msaorinf.isEmpty()) {
|
||||||
if (tempLine.contains("Copyright")) {
|
MigrationTool.ui.println("No INF nor MSA file found!");
|
||||||
//
|
System.exit(0);
|
||||||
// Find license info.
|
} else {
|
||||||
//
|
if (mi.msaorinf.size() == 1) {
|
||||||
license = "";
|
filename = (String) mi.msaorinf.toArray()[0];
|
||||||
while ((tempLine = rd.readLine())!= null) {
|
} else {
|
||||||
if (!tempLine.contains("#") ||
|
filename = MigrationTool.ui.choose(
|
||||||
tempLine.contains("Module Name:") ||
|
"Found .inf or .msa file for module\n" + mi.modulepath
|
||||||
tempLine.contains("Abstract:")) {
|
+ "\nChoose one Please", mi.msaorinf.toArray());
|
||||||
//
|
}
|
||||||
// We assume license ends here.
|
}
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
license += " " + tempLine.replaceAll("\\s*[#]\\s*(.*)", "$1\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return license;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void readInf(String name) throws Exception {
|
if (filename.contains(".inf")) {
|
||||||
System.out.println("\nParsing INF file: " + name);
|
readInf(filename);
|
||||||
String wholeline;
|
} else if (filename.contains(".msa")) {
|
||||||
Matcher mtrinfequation;
|
readMsa(filename);
|
||||||
Matcher mtrsection;
|
}
|
||||||
Matcher mtrfilename;
|
// inf&msa
|
||||||
|
|
||||||
wholeline = Common.file2string(mi.modulepath + File.separator + name);
|
preProcessModule();
|
||||||
mi.license = extractLicense(wholeline);
|
}
|
||||||
mtrsection = ptnsection.matcher(wholeline);
|
|
||||||
while (mtrsection.find()) {
|
|
||||||
if (mtrsection.group(1).matches("defines")) {
|
|
||||||
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
|
||||||
while (mtrinfequation.find()) {
|
|
||||||
if (mtrinfequation.group(1).matches("BASE_NAME")) {
|
|
||||||
mi.modulename = mtrinfequation.group(2);
|
|
||||||
}
|
|
||||||
if (mtrinfequation.group(1).matches("FILE_GUID")) {
|
|
||||||
mi.guidvalue = mtrinfequation.group(2);
|
|
||||||
}
|
|
||||||
if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
|
|
||||||
mi.moduletype = mtrinfequation.group(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mtrsection.group(1).contains("nmake.")) {
|
|
||||||
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
|
||||||
while (mtrinfequation.find()) {
|
|
||||||
if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
|
|
||||||
mi.entrypoint = mtrinfequation.group(2);
|
|
||||||
}
|
|
||||||
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
|
||||||
if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
|
|
||||||
MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mtrsection.group(1).contains("sources.")) {
|
|
||||||
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
|
||||||
while (mtrfilename.find()) {
|
|
||||||
mi.infsources.add(mtrfilename.group());
|
|
||||||
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
|
||||||
MigrationTool.ui.println("Warn: Source File Missing! : " + mtrfilename.group());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mtrsection.group(1).matches("includes.")) {
|
|
||||||
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
|
||||||
while (mtrfilename.find()) {
|
|
||||||
mi.infincludes.add(mtrfilename.group());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void preProcessModule() throws Exception {
|
|
||||||
// according to .inf file, add extraordinary includes and sourcefiles
|
|
||||||
Common.dirCopy(mi.modulepath, mi.temppath); // collect all Laplace.namechange to here???
|
|
||||||
|
|
||||||
if (!mi.infincludes.isEmpty()) {
|
|
||||||
Iterator<String> it = mi.infincludes.iterator();
|
|
||||||
String tempincludename = null;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
tempincludename = it.next();
|
|
||||||
if (tempincludename.contains("..")) {
|
|
||||||
Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
|
|
||||||
if (mtr.find() && !mtr.group(2).matches(".")) {
|
|
||||||
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1") + File.separator + mtr.group(2), mi.temppath, ".h");
|
|
||||||
} else {
|
|
||||||
Common.oneLevelDirCopy(mi.modulepath.replaceAll(Common.STRSEPARATER, "$1"), mi.temppath, ".h");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!mi.infsources.isEmpty()) {
|
|
||||||
Iterator<String> it = mi.infsources.iterator();
|
|
||||||
String tempsourcename = null;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
tempsourcename = it.next();
|
|
||||||
if (tempsourcename.contains("..")) {
|
|
||||||
Common.ensureDir(mi.temppath + File.separator + "MT_Parent_Sources");
|
|
||||||
Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);
|
|
||||||
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.toDoAll(mi.temppath, this, Common.FILE);
|
private final void readMsa(String name) throws Exception {
|
||||||
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
parsePreProcessedSourceCode();
|
.parse(new File(mi.modulepath + File.separator + name));
|
||||||
|
ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc
|
||||||
|
.getModuleSurfaceArea();
|
||||||
|
MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
|
||||||
|
|
||||||
}
|
mi.modulename = msaheader.getModuleName();
|
||||||
|
mi.guidvalue = msaheader.getGuidValue();
|
||||||
|
mi.moduletype = msaheader.getModuleType().toString(); // ???
|
||||||
|
|
||||||
private final void parsePreProcessedSourceCode() throws Exception {
|
SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
|
||||||
BufferedReader rd = null;
|
|
||||||
String ifile = null;
|
|
||||||
String line = null;
|
|
||||||
String temp = null;
|
|
||||||
|
|
||||||
Iterator<String> ii = mi.localmodulesources.iterator();
|
|
||||||
while (ii.hasNext()) {
|
|
||||||
temp = ii.next();
|
|
||||||
if (temp.contains(".c") || temp.contains(".dxs")) {
|
|
||||||
mi.preprocessedccodes.add(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ii = mi.preprocessedccodes.iterator();
|
|
||||||
|
|
||||||
Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);
|
|
||||||
Matcher matguid;
|
|
||||||
Matcher matfuncc;
|
|
||||||
Matcher matfuncd;
|
|
||||||
Matcher matenclosereplace;
|
|
||||||
Matcher matefifuncc;
|
|
||||||
Matcher matmacro;
|
|
||||||
|
|
||||||
while (ii.hasNext()) {
|
|
||||||
StringBuffer wholefile = new StringBuffer();
|
|
||||||
ifile = ii.next();
|
|
||||||
rd = new BufferedReader(new FileReader(mi.temppath + File.separator + ifile));
|
|
||||||
while ((line = rd.readLine()) != null) {
|
|
||||||
wholefile.append(line + '\n');
|
|
||||||
}
|
|
||||||
line = wholefile.toString();
|
|
||||||
|
|
||||||
// find guid
|
|
||||||
matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :
|
|
||||||
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);
|
|
||||||
//line = result.toString();
|
|
||||||
|
|
||||||
// find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed
|
String temp;
|
||||||
// This item is not simply replaced , special operation is required.
|
Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList()
|
||||||
matefifuncc = patefifuncc.matcher(line);
|
.iterator();
|
||||||
while (matefifuncc.find()) {
|
while (li.hasNext()) {
|
||||||
mi.hashEFIcall.add(matefifuncc.group(2));
|
if (!mi.localmodulesources.contains(temp = li.next().toString())) {
|
||||||
}
|
System.out.println("Source File Missing! : " + temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find function call
|
private final String extractLicense(String wholeline) throws Exception {
|
||||||
matfuncc = Func.ptnfuncc.matcher(line);
|
String tempLine;
|
||||||
while (matfuncc.find()) {
|
String license = null;
|
||||||
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
|
||||||
//MigrationTool.ui.println(ifile + " dofunc " + temp);
|
|
||||||
//matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//matfuncc.appendTail(result);
|
|
||||||
//line = result.toString();
|
|
||||||
|
|
||||||
// find macro
|
BufferedReader rd = new BufferedReader(new StringReader(wholeline));
|
||||||
matmacro = Macro.ptntmacro.matcher(line);
|
while ((tempLine = rd.readLine()) != null) {
|
||||||
while (matmacro.find()) {
|
if (tempLine.contains("#")) {
|
||||||
if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {
|
if (tempLine.contains("Copyright")) {
|
||||||
}
|
//
|
||||||
}
|
// Find license info.
|
||||||
|
//
|
||||||
// find function definition
|
license = "";
|
||||||
// replace all {} to @
|
while ((tempLine = rd.readLine()) != null) {
|
||||||
while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {
|
if (!tempLine.contains("#")
|
||||||
line = matenclosereplace.replaceAll("@");
|
|| tempLine.contains("Module Name:")
|
||||||
}
|
|| tempLine.contains("Abstract:")) {
|
||||||
|
//
|
||||||
|
// We assume license ends here.
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
license += " "
|
||||||
|
+ tempLine
|
||||||
|
.replaceAll("\\s*[#]\\s*(.*)", "$1\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return license;
|
||||||
|
}
|
||||||
|
|
||||||
matfuncd = Func.ptnfuncd.matcher(line);
|
private final void readInf(String name) throws Exception {
|
||||||
while (matfuncd.find()) {
|
System.out.println("\nParsing INF file: " + name);
|
||||||
if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {
|
String wholeline;
|
||||||
}
|
Matcher mtrinfequation;
|
||||||
}
|
Matcher mtrsection;
|
||||||
}
|
Matcher mtrfilename;
|
||||||
|
|
||||||
// op on hash
|
|
||||||
Iterator<String> funcci = mi.hashfuncc.iterator();
|
|
||||||
while (funcci.hasNext()) {
|
|
||||||
if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) {
|
|
||||||
mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CommentLaplace extends Common.Laplace {
|
|
||||||
public String operation(String wholeline) {
|
|
||||||
StringBuffer wholebuffer = new StringBuffer();
|
|
||||||
String templine = null;
|
|
||||||
Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");
|
|
||||||
Pattern ptninclude = Pattern.compile("#include\\s*(.*)");
|
|
||||||
Matcher mtrinclude = ptninclude.matcher(wholeline);
|
|
||||||
Matcher mtrincludefile = null;
|
|
||||||
while (mtrinclude.find()) {
|
|
||||||
mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));
|
|
||||||
if (mtrincludefile.find() && mi.localmodulesources.contains(mtrincludefile.group(1))) {
|
|
||||||
templine = mtrinclude.group();
|
|
||||||
} else {
|
|
||||||
templine = MigrationTool.MIGRATIONCOMMENT + mtrinclude.group();
|
|
||||||
}
|
|
||||||
mtrinclude.appendReplacement(wholebuffer, templine);
|
|
||||||
}
|
|
||||||
mtrinclude.appendTail(wholebuffer);
|
|
||||||
return wholebuffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
|
||||||
return filename.contains(".c") || filename.contains(".h") || filename.contains(".dxs");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
|
||||||
return oldname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
wholeline = Common.file2string(mi.modulepath + File.separator + name);
|
||||||
public void run(String filepath) throws Exception {
|
mi.license = extractLicense(wholeline);
|
||||||
String name = mi.temppath + File.separator + filepath.replace(mi.temppath + File.separator, "");
|
mtrsection = ptnsection.matcher(wholeline);
|
||||||
if (commentlaplace.recognize(name)) {
|
while (mtrsection.find()) {
|
||||||
commentlaplace.transform(name, name);
|
if (mtrsection.group(1).matches("defines")) {
|
||||||
}
|
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
||||||
}
|
while (mtrinfequation.find()) {
|
||||||
|
if (mtrinfequation.group(1).matches("BASE_NAME")) {
|
||||||
|
mi.modulename = mtrinfequation.group(2);
|
||||||
|
}
|
||||||
|
if (mtrinfequation.group(1).matches("FILE_GUID")) {
|
||||||
|
mi.guidvalue = mtrinfequation.group(2);
|
||||||
|
}
|
||||||
|
if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
|
||||||
|
mi.moduletype = mtrinfequation.group(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mtrsection.group(1).contains("nmake.")) {
|
||||||
|
mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
|
||||||
|
while (mtrinfequation.find()) {
|
||||||
|
if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
|
||||||
|
mi.entrypoint = mtrinfequation.group(2);
|
||||||
|
}
|
||||||
|
if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
|
||||||
|
if (!mi.localmodulesources.contains(mtrinfequation
|
||||||
|
.group(2))) {
|
||||||
|
MigrationTool.ui.println("DPX File Missing! : "
|
||||||
|
+ mtrinfequation.group(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mtrsection.group(1).contains("sources.")) {
|
||||||
|
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
||||||
|
while (mtrfilename.find()) {
|
||||||
|
mi.infsources.add(mtrfilename.group());
|
||||||
|
if (!mi.localmodulesources.contains(mtrfilename.group())) {
|
||||||
|
MigrationTool.ui
|
||||||
|
.println("Warn: Source File Missing! : "
|
||||||
|
+ mtrfilename.group());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mtrsection.group(1).matches("includes.")) {
|
||||||
|
mtrfilename = ptnfilename.matcher(mtrsection.group(2));
|
||||||
|
while (mtrfilename.find()) {
|
||||||
|
mi.infincludes.add(mtrfilename.group());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean filter(File dir) {
|
private final void preProcessModule() throws Exception {
|
||||||
return true;
|
// according to .inf file, add extraordinary includes and sourcefiles
|
||||||
}
|
Common.dirCopy(mi.modulepath, mi.temppath); // collect all
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
// Laplace.namechange to
|
||||||
|
// here???
|
||||||
public final void setModuleInfo(ModuleInfo m) {
|
|
||||||
mi = m;
|
if (!mi.infincludes.isEmpty()) {
|
||||||
}
|
Iterator<String> it = mi.infincludes.iterator();
|
||||||
|
String tempincludename = null;
|
||||||
public static final void aimAt(ModuleInfo mi) throws Exception {
|
while (it.hasNext()) {
|
||||||
modulereader.setModuleInfo(mi);
|
tempincludename = it.next();
|
||||||
modulereader.ModuleScan();
|
if (tempincludename.contains("..")) {
|
||||||
}
|
Matcher mtr = Common.PTNSEPARATER.matcher(tempincludename);
|
||||||
|
if (mtr.find() && !mtr.group(2).matches(".")) {
|
||||||
|
Common.oneLevelDirCopy(mi.modulepath.replaceAll(
|
||||||
|
Common.STRSEPARATER, "$1")
|
||||||
|
+ File.separator + mtr.group(2), mi.temppath,
|
||||||
|
".h");
|
||||||
|
} else {
|
||||||
|
Common.oneLevelDirCopy(mi.modulepath.replaceAll(
|
||||||
|
Common.STRSEPARATER, "$1"), mi.temppath, ".h");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mi.infsources.isEmpty()) {
|
||||||
|
Iterator<String> it = mi.infsources.iterator();
|
||||||
|
String tempsourcename = null;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
tempsourcename = it.next();
|
||||||
|
if (tempsourcename.contains("..")) {
|
||||||
|
Common.ensureDir(mi.temppath + File.separator
|
||||||
|
+ "MT_Parent_Sources");
|
||||||
|
Matcher mtr = Common.PTNSEPARATER.matcher(tempsourcename);
|
||||||
|
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.toDoAll(mi.temppath, this, Common.FILE);
|
||||||
|
|
||||||
|
parsePreProcessedSourceCode();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void parsePreProcessedSourceCode() throws Exception {
|
||||||
|
BufferedReader rd = null;
|
||||||
|
String ifile = null;
|
||||||
|
String line = null;
|
||||||
|
String temp = null;
|
||||||
|
|
||||||
|
Iterator<String> ii = mi.localmodulesources.iterator();
|
||||||
|
while (ii.hasNext()) {
|
||||||
|
temp = ii.next();
|
||||||
|
if (temp.contains(".c") || temp.contains(".dxs")) {
|
||||||
|
mi.preprocessedccodes.add(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ii = mi.preprocessedccodes.iterator();
|
||||||
|
|
||||||
|
Pattern patefifuncc = Pattern.compile(
|
||||||
|
"g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)", Pattern.MULTILINE);
|
||||||
|
Matcher matguid;
|
||||||
|
Matcher matfuncc;
|
||||||
|
Matcher matfuncd;
|
||||||
|
Matcher matenclosereplace;
|
||||||
|
Matcher matefifuncc;
|
||||||
|
Matcher matmacro;
|
||||||
|
|
||||||
|
while (ii.hasNext()) {
|
||||||
|
StringBuffer wholefile = new StringBuffer();
|
||||||
|
ifile = ii.next();
|
||||||
|
rd = new BufferedReader(new FileReader(mi.temppath + File.separator
|
||||||
|
+ ifile));
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
wholefile.append(line + '\n');
|
||||||
|
}
|
||||||
|
line = wholefile.toString();
|
||||||
|
|
||||||
|
// find guid
|
||||||
|
matguid = Guid.ptnguid.matcher(line); // several ways to implement
|
||||||
|
// this , which one is
|
||||||
|
// faster ? :
|
||||||
|
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);
|
||||||
|
// line = result.toString();
|
||||||
|
|
||||||
|
// find EFI call in form of '->' , many
|
||||||
|
// 'gUnicodeCollationInterface->' like things are not changed
|
||||||
|
// This item is not simply replaced , special operation is required.
|
||||||
|
matefifuncc = patefifuncc.matcher(line);
|
||||||
|
while (matefifuncc.find()) {
|
||||||
|
mi.hashEFIcall.add(matefifuncc.group(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// find function call
|
||||||
|
matfuncc = Func.ptnfuncc.matcher(line);
|
||||||
|
while (matfuncc.find()) {
|
||||||
|
if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) {
|
||||||
|
// MigrationTool.ui.println(ifile + " dofunc " + temp);
|
||||||
|
// matfuncc.appendReplacement(result,
|
||||||
|
// MigrationTool.db.getR9Func(temp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// matfuncc.appendTail(result);
|
||||||
|
// line = result.toString();
|
||||||
|
|
||||||
|
// find macro
|
||||||
|
matmacro = Macro.ptntmacro.matcher(line);
|
||||||
|
while (matmacro.find()) {
|
||||||
|
if ((temp = Macro.register(matmacro, mi, MigrationTool.db)) != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find function definition
|
||||||
|
// replace all {} to @
|
||||||
|
while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {
|
||||||
|
line = matenclosereplace.replaceAll("@");
|
||||||
|
}
|
||||||
|
|
||||||
|
matfuncd = Func.ptnfuncd.matcher(line);
|
||||||
|
while (matfuncd.find()) {
|
||||||
|
if ((temp = Func.register(matfuncd, mi, MigrationTool.db)) != null) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// op on hash
|
||||||
|
Iterator<String> funcci = mi.hashfuncc.iterator();
|
||||||
|
while (funcci.hasNext()) {
|
||||||
|
if (!mi.hashfuncd.contains(temp = funcci.next())
|
||||||
|
&& !mi.hashEFIcall.contains(temp)) {
|
||||||
|
mi.hashnonlocalfunc.add(temp); // this set contains both
|
||||||
|
// changed and not changed items
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CommentLaplace extends Common.Laplace {
|
||||||
|
public String operation(String wholeline) {
|
||||||
|
StringBuffer wholebuffer = new StringBuffer();
|
||||||
|
String templine = null;
|
||||||
|
Pattern ptnincludefile = Pattern.compile("[\"<](.*[.]h)[\">]");
|
||||||
|
Pattern ptninclude = Pattern.compile("#include\\s*(.*)");
|
||||||
|
Matcher mtrinclude = ptninclude.matcher(wholeline);
|
||||||
|
Matcher mtrincludefile = null;
|
||||||
|
while (mtrinclude.find()) {
|
||||||
|
mtrincludefile = ptnincludefile.matcher(mtrinclude.group(1));
|
||||||
|
if (mtrincludefile.find()
|
||||||
|
&& mi.localmodulesources.contains(mtrincludefile
|
||||||
|
.group(1))) {
|
||||||
|
templine = mtrinclude.group();
|
||||||
|
} else {
|
||||||
|
templine = MigrationTool.MIGRATIONCOMMENT
|
||||||
|
+ mtrinclude.group();
|
||||||
|
}
|
||||||
|
mtrinclude.appendReplacement(wholebuffer, templine);
|
||||||
|
}
|
||||||
|
mtrinclude.appendTail(wholebuffer);
|
||||||
|
return wholebuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recognize(String filename) {
|
||||||
|
return filename.contains(".c") || filename.contains(".h")
|
||||||
|
|| filename.contains(".dxs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String namechange(String oldname) {
|
||||||
|
return oldname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
public void run(String filepath) throws Exception {
|
||||||
|
String name = mi.temppath + File.separator
|
||||||
|
+ filepath.replace(mi.temppath + File.separator, "");
|
||||||
|
if (commentlaplace.recognize(name)) {
|
||||||
|
commentlaplace.transform(name, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean filter(File dir) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
|
||||||
|
public final void setModuleInfo(ModuleInfo m) {
|
||||||
|
mi = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void aimAt(ModuleInfo mi) throws Exception {
|
||||||
|
modulereader.setModuleInfo(mi);
|
||||||
|
modulereader.ModuleScan();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,369 +14,412 @@ 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 ABSTRACT = "Component name for module ";
|
|
||||||
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" +
|
|
||||||
" under a license and may only be used or copied in accordance\n" +
|
|
||||||
" with the terms of the license. Except as permitted by such\n" +
|
|
||||||
" license, no part of this software or documentation may be\n" +
|
|
||||||
" reproduced, stored in a retrieval system, or transmitted in any\n" +
|
|
||||||
" 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 Enum IA32 = SupportedArchitectures.IA_32;
|
|
||||||
public static final Enum X64 = SupportedArchitectures.X_64;
|
|
||||||
public static final Enum IPF = SupportedArchitectures.IPF;
|
|
||||||
public static final Enum EBC = SupportedArchitectures.EBC;
|
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
|
|
||||||
private MsaHeaderDocument.MsaHeader msaheader = null;
|
|
||||||
private LicenseDocument.License license = null;
|
|
||||||
private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
|
|
||||||
private SourceFilesDocument.SourceFiles sourcefiles = null; //found local .h files are not written
|
|
||||||
private GuidsDocument.Guids guids = null;
|
|
||||||
private ProtocolsDocument.Protocols protocols = null;
|
|
||||||
private PPIsDocument.PPIs ppis = null;
|
|
||||||
private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
|
|
||||||
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
|
|
||||||
private ExternsDocument.Externs externs = null;
|
|
||||||
|
|
||||||
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-------------------------------------//
|
public static final String VERSION = "1.0";
|
||||||
|
|
||||||
public final boolean addLibraryClass (String name, UsageTypes.Enum usage) {
|
public static final String ABSTRACT = "Component name for module ";
|
||||||
/*
|
|
||||||
if (!libclassdefs.getLibraryClassList().contains(name)) {
|
|
||||||
LibraryClassDocument.LibraryClass classname;
|
|
||||||
classname = libclassdefs.addNewLibraryClass();
|
|
||||||
classname.setKeyword(name);
|
|
||||||
classname.setUsage(usage);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (name == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs.getLibraryClassList().iterator();
|
|
||||||
while (classit.hasNext()) {
|
|
||||||
if (classit.next().getKeyword().matches(name)) {
|
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate LibraryClass");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LibraryClassDocument.LibraryClass classname;
|
|
||||||
classname = libclassdefs.addNewLibraryClass();
|
|
||||||
classname.setKeyword(name);
|
|
||||||
classname.setUsage(usage);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addGuid (String guidname, UsageTypes.Enum usage) {
|
|
||||||
if (guids == null) {
|
|
||||||
guids = msa.addNewGuids();
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids.getGuidCNamesList().iterator();
|
|
||||||
while (guidit.hasNext()) {
|
|
||||||
if (guidit.next().getGuidCName() == guidname) {
|
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Guid");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GuidsDocument.Guids.GuidCNames guid;
|
|
||||||
guid = guids.addNewGuidCNames();
|
|
||||||
guid.setGuidCName(guidname);
|
|
||||||
guid.setUsage(usage);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public final boolean addPpi (String ppiname, UsageTypes.Enum usage) {
|
|
||||||
if (ppis == null) {
|
|
||||||
ppis = msa.addNewPPIs();
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
|
|
||||||
while (ppiit.hasNext()) {
|
|
||||||
if (ppiit.next().getPpiCName() == ppiname) {
|
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Ppi");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PPIsDocument.PPIs.Ppi ppi;
|
|
||||||
ppi = ppis.addNewPpi();
|
|
||||||
ppi.setPpiCName(ppiname);
|
|
||||||
ppi.setUsage(usage);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addProtocol (String proname, UsageTypes.Enum usage) {
|
|
||||||
if (protocols == null) {
|
|
||||||
protocols = msa.addNewProtocols();
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols.getProtocolList().iterator();
|
public static final String DESCRIPTION = "FIX ME!";
|
||||||
while (proit.hasNext()) {
|
|
||||||
if (proit.next().getProtocolCName() == proname) {
|
|
||||||
//MigrationTool.ui.println ("Warning: Duplicate Protocol");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolsDocument.Protocols.Protocol protocol;
|
public static final String LICENSE = "All rights reserved.\n"
|
||||||
protocol = protocols.addNewProtocol();
|
+ " This software and associated documentation (if any) is furnished\n"
|
||||||
protocol.setProtocolCName(proname);
|
+ " under a license and may only be used or copied in accordance\n"
|
||||||
protocol.setUsage(usage);
|
+ " with the terms of the license. Except as permitted by such\n"
|
||||||
return true;
|
+ " license, no part of this software or documentation may be\n"
|
||||||
}
|
+ " reproduced, stored in a retrieval system, or transmitted in any\n"
|
||||||
|
+ " form or by any means without the express written consent of\n"
|
||||||
public final boolean addSourceFile (String name, Enum en) {
|
+ " Intel Corporation.";
|
||||||
Iterator<FilenameDocument.Filename> fileit = sourcefiles.getFilenameList().iterator();
|
|
||||||
while (fileit.hasNext()) {
|
|
||||||
if (fileit.next().getStringValue() == name) {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate SourceFileName");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FilenameDocument.Filename filename;
|
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
|
||||||
filename = sourcefiles.addNewFilename();
|
|
||||||
filename.setStringValue(name);
|
|
||||||
arch.add(en);
|
|
||||||
filename.setSupArchList(arch);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// entry point todo
|
|
||||||
|
|
||||||
public final boolean setupExternSpecification () {
|
|
||||||
addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
|
|
||||||
addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addExternSpecification (String specification) {
|
|
||||||
if (externs.getSpecificationList().contains(specification)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
externs.addSpecification(specification);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean setupPackageDependencies() {
|
|
||||||
Iterator<String> it;
|
|
||||||
//
|
|
||||||
// For now, simply add all package guids in the database.
|
|
||||||
//
|
|
||||||
it = MigrationTool.db.dumpAllPkgGuid();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
packagedependencies.addNewPackage().setPackageGuid(it.next());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addPackage (String guid) {
|
|
||||||
if (packagedependencies.getPackageList().contains(guid)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
packagedependencies.addNewPackage().setPackageGuid(guid);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean setupModuleDefinitions () { //????????? give this job to moduleinfo
|
|
||||||
moduledefinitions.setBinaryModule(false);
|
|
||||||
moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public final boolean addSupportedArchitectures (Enum arch) {
|
|
||||||
if (listarch.contains(arch)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
listarch.add(arch);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addSpecification (String specification) {
|
|
||||||
if (msaheader.getSpecification() == null) {
|
|
||||||
if (specification == null) {
|
|
||||||
msaheader.setSpecification(SPECIFICATION);
|
|
||||||
} else {
|
|
||||||
msaheader.setSpecification(specification);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Specification");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addLicense (String licensecontent) {
|
|
||||||
if (msaheader.getLicense() == null) {
|
|
||||||
license = msaheader.addNewLicense();
|
|
||||||
if (licensecontent == null) {
|
|
||||||
license.setStringValue(LICENSE);
|
|
||||||
} else {
|
|
||||||
license.setStringValue(licensecontent);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate License");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addDescription (String description) {
|
|
||||||
if (msaheader.getDescription() == null) {
|
|
||||||
if (description == null) {
|
|
||||||
msaheader.setDescription(DESCRIPTION);
|
|
||||||
} else {
|
|
||||||
msaheader.setDescription(description);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Description");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addAbstract (String abs) {
|
|
||||||
if (msaheader.getAbstract() == null) {
|
|
||||||
if (abs == null) {
|
|
||||||
msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
|
|
||||||
} else {
|
|
||||||
msaheader.setVersion(abs);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Abstract");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addVersion (String version) {
|
|
||||||
if (msaheader.getVersion() == null) {
|
|
||||||
if (version == null) {
|
|
||||||
msaheader.setVersion(VERSION);
|
|
||||||
} else {
|
|
||||||
msaheader.setVersion(version);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate Version");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addCopyRight (String copyright) {
|
|
||||||
if (msaheader.getCopyright() == null) {
|
|
||||||
if (copyright == null) {
|
|
||||||
msaheader.setCopyright(COPYRIGHT);
|
|
||||||
} else {
|
|
||||||
msaheader.setCopyright(copyright);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate CopyRight");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addModuleType (String moduletype) {
|
|
||||||
if (msaheader.getModuleType() == null) {
|
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate ModuleType");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addGuidValue (String guidvalue) {
|
|
||||||
if (msaheader.getGuidValue() == null) {
|
|
||||||
msaheader.setGuidValue(guidvalue);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate GuidValue");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean addModuleName (String modulename) {
|
|
||||||
if (msaheader.getModuleName() == null) {
|
|
||||||
msaheader.setModuleName(modulename);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
MigrationTool.ui.println ("Warning: Duplicate ModuleName");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//-----------------------------msaheader-------------------------------------//
|
|
||||||
|
|
||||||
private final void fullfill () throws Exception {
|
|
||||||
addCopyRight(null);
|
|
||||||
addVersion(null);
|
|
||||||
addAbstract(null);
|
|
||||||
addDescription(null);
|
|
||||||
addLicense(null);
|
|
||||||
addSpecification(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void flush(String outputpath) throws Exception {
|
|
||||||
XmlOptions options = new XmlOptions();
|
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
public static final String SPECIFICATION = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
|
||||||
options.setSavePrettyPrint();
|
|
||||||
options.setSavePrettyPrintIndent(2);
|
public static final Enum IA32 = SupportedArchitectures.IA_32;
|
||||||
options.setUseDefaultNamespace();
|
|
||||||
|
public static final Enum X64 = SupportedArchitectures.X_64;
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));
|
|
||||||
fullfill();
|
public static final Enum IPF = SupportedArchitectures.IPF;
|
||||||
msadoc.save(bw, options);
|
|
||||||
bw.flush();
|
public static final Enum EBC = SupportedArchitectures.EBC;
|
||||||
bw.close();
|
|
||||||
}
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
|
.newInstance();
|
||||||
private final MsaOwner init () {
|
|
||||||
msa = msadoc.addNewModuleSurfaceArea();
|
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;
|
||||||
msaheader = msa.addNewMsaHeader();
|
|
||||||
moduledefinitions = msa.addNewModuleDefinitions();
|
private MsaHeaderDocument.MsaHeader msaheader = null;
|
||||||
moduledefinitions.setSupportedArchitectures(listarch);
|
|
||||||
|
private LicenseDocument.License license = null;
|
||||||
sourcefiles = msa.addNewSourceFiles();
|
|
||||||
packagedependencies = msa.addNewPackageDependencies();
|
private ModuleDefinitionsDocument.ModuleDefinitions moduledefinitions = null;
|
||||||
libclassdefs = msa.addNewLibraryClassDefinitions();
|
|
||||||
externs = msa.addNewExterns();
|
private SourceFilesDocument.SourceFiles sourcefiles = null; // found local
|
||||||
return this;
|
// .h files are
|
||||||
}
|
// not written
|
||||||
|
|
||||||
public static final MsaOwner initNewMsaOwner() {
|
private GuidsDocument.Guids guids = null;
|
||||||
return new MsaOwner().init();
|
|
||||||
}
|
private ProtocolsDocument.Protocols protocols = null;
|
||||||
|
|
||||||
|
private PPIsDocument.PPIs ppis = null;
|
||||||
|
|
||||||
|
private PackageDependenciesDocument.PackageDependencies packagedependencies = null;
|
||||||
|
|
||||||
|
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = null;
|
||||||
|
|
||||||
|
private ExternsDocument.Externs externs = null;
|
||||||
|
|
||||||
|
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-------------------------------------//
|
||||||
|
|
||||||
|
public final boolean addLibraryClass(String name, UsageTypes.Enum usage) {
|
||||||
|
/*
|
||||||
|
* if (!libclassdefs.getLibraryClassList().contains(name)) {
|
||||||
|
* LibraryClassDocument.LibraryClass classname; classname =
|
||||||
|
* libclassdefs.addNewLibraryClass(); classname.setKeyword(name);
|
||||||
|
* classname.setUsage(usage); return true; } else { return false; }
|
||||||
|
*/
|
||||||
|
if (name == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Iterator<LibraryClassDocument.LibraryClass> classit = libclassdefs
|
||||||
|
.getLibraryClassList().iterator();
|
||||||
|
while (classit.hasNext()) {
|
||||||
|
if (classit.next().getKeyword().matches(name)) {
|
||||||
|
// MigrationTool.ui.println ("Warning: Duplicate
|
||||||
|
// LibraryClass");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LibraryClassDocument.LibraryClass classname;
|
||||||
|
classname = libclassdefs.addNewLibraryClass();
|
||||||
|
classname.setKeyword(name);
|
||||||
|
classname.setUsage(usage);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addGuid(String guidname, UsageTypes.Enum usage) {
|
||||||
|
if (guids == null) {
|
||||||
|
guids = msa.addNewGuids();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<GuidsDocument.Guids.GuidCNames> guidit = guids
|
||||||
|
.getGuidCNamesList().iterator();
|
||||||
|
while (guidit.hasNext()) {
|
||||||
|
if (guidit.next().getGuidCName() == guidname) {
|
||||||
|
// MigrationTool.ui.println ("Warning: Duplicate Guid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GuidsDocument.Guids.GuidCNames guid;
|
||||||
|
guid = guids.addNewGuidCNames();
|
||||||
|
guid.setGuidCName(guidname);
|
||||||
|
guid.setUsage(usage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addPpi(String ppiname, UsageTypes.Enum usage) {
|
||||||
|
if (ppis == null) {
|
||||||
|
ppis = msa.addNewPPIs();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<PPIsDocument.PPIs.Ppi> ppiit = ppis.getPpiList().iterator();
|
||||||
|
while (ppiit.hasNext()) {
|
||||||
|
if (ppiit.next().getPpiCName() == ppiname) {
|
||||||
|
// MigrationTool.ui.println ("Warning: Duplicate Ppi");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PPIsDocument.PPIs.Ppi ppi;
|
||||||
|
ppi = ppis.addNewPpi();
|
||||||
|
ppi.setPpiCName(ppiname);
|
||||||
|
ppi.setUsage(usage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addProtocol(String proname, UsageTypes.Enum usage) {
|
||||||
|
if (protocols == null) {
|
||||||
|
protocols = msa.addNewProtocols();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<ProtocolsDocument.Protocols.Protocol> proit = protocols
|
||||||
|
.getProtocolList().iterator();
|
||||||
|
while (proit.hasNext()) {
|
||||||
|
if (proit.next().getProtocolCName() == proname) {
|
||||||
|
// MigrationTool.ui.println ("Warning: Duplicate Protocol");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolsDocument.Protocols.Protocol protocol;
|
||||||
|
protocol = protocols.addNewProtocol();
|
||||||
|
protocol.setProtocolCName(proname);
|
||||||
|
protocol.setUsage(usage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addSourceFile(String name, Enum en) {
|
||||||
|
Iterator<FilenameDocument.Filename> fileit = sourcefiles
|
||||||
|
.getFilenameList().iterator();
|
||||||
|
while (fileit.hasNext()) {
|
||||||
|
if (fileit.next().getStringValue() == name) {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate SourceFileName");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FilenameDocument.Filename filename;
|
||||||
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
|
filename = sourcefiles.addNewFilename();
|
||||||
|
filename.setStringValue(name);
|
||||||
|
arch.add(en);
|
||||||
|
filename.setSupArchList(arch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// entry point todo
|
||||||
|
|
||||||
|
public final boolean setupExternSpecification() {
|
||||||
|
addExternSpecification("EFI_SPECIFICATION_VERSION 0x00020000");
|
||||||
|
addExternSpecification("EDK_RELEASE_VERSION 0x00020000");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addExternSpecification(String specification) {
|
||||||
|
if (externs.getSpecificationList().contains(specification)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
externs.addSpecification(specification);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean setupPackageDependencies() {
|
||||||
|
Iterator<String> it;
|
||||||
|
//
|
||||||
|
// For now, simply add all package guids in the database.
|
||||||
|
//
|
||||||
|
it = MigrationTool.db.dumpAllPkgGuid();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
packagedependencies.addNewPackage().setPackageGuid(it.next());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addPackage(String guid) {
|
||||||
|
if (packagedependencies.getPackageList().contains(guid)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
packagedependencies.addNewPackage().setPackageGuid(guid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean setupModuleDefinitions() { // ????????? give this job
|
||||||
|
// to moduleinfo
|
||||||
|
moduledefinitions.setBinaryModule(false);
|
||||||
|
moduledefinitions.setOutputFileBasename(msaheader.getModuleName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addSupportedArchitectures(Enum arch) {
|
||||||
|
if (listarch.contains(arch)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
listarch.add(arch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addSpecification(String specification) {
|
||||||
|
if (msaheader.getSpecification() == null) {
|
||||||
|
if (specification == null) {
|
||||||
|
msaheader.setSpecification(SPECIFICATION);
|
||||||
|
} else {
|
||||||
|
msaheader.setSpecification(specification);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate Specification");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addLicense(String licensecontent) {
|
||||||
|
if (msaheader.getLicense() == null) {
|
||||||
|
license = msaheader.addNewLicense();
|
||||||
|
if (licensecontent == null) {
|
||||||
|
license.setStringValue(LICENSE);
|
||||||
|
} else {
|
||||||
|
license.setStringValue(licensecontent);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate License");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addDescription(String description) {
|
||||||
|
if (msaheader.getDescription() == null) {
|
||||||
|
if (description == null) {
|
||||||
|
msaheader.setDescription(DESCRIPTION);
|
||||||
|
} else {
|
||||||
|
msaheader.setDescription(description);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate Description");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addAbstract(String abs) {
|
||||||
|
if (msaheader.getAbstract() == null) {
|
||||||
|
if (abs == null) {
|
||||||
|
msaheader.setAbstract(ABSTRACT + msaheader.getModuleName());
|
||||||
|
} else {
|
||||||
|
msaheader.setVersion(abs);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate Abstract");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addVersion(String version) {
|
||||||
|
if (msaheader.getVersion() == null) {
|
||||||
|
if (version == null) {
|
||||||
|
msaheader.setVersion(VERSION);
|
||||||
|
} else {
|
||||||
|
msaheader.setVersion(version);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate Version");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addCopyRight(String copyright) {
|
||||||
|
if (msaheader.getCopyright() == null) {
|
||||||
|
if (copyright == null) {
|
||||||
|
msaheader.setCopyright(COPYRIGHT);
|
||||||
|
} else {
|
||||||
|
msaheader.setCopyright(copyright);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate CopyRight");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addModuleType(String moduletype) {
|
||||||
|
if (msaheader.getModuleType() == null) {
|
||||||
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(moduletype));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate ModuleType");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addGuidValue(String guidvalue) {
|
||||||
|
if (msaheader.getGuidValue() == null) {
|
||||||
|
msaheader.setGuidValue(guidvalue);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate GuidValue");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean addModuleName(String modulename) {
|
||||||
|
if (msaheader.getModuleName() == null) {
|
||||||
|
msaheader.setModuleName(modulename);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
MigrationTool.ui.println("Warning: Duplicate ModuleName");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------msaheader-------------------------------------//
|
||||||
|
|
||||||
|
private final void fullfill() throws Exception {
|
||||||
|
addCopyRight(null);
|
||||||
|
addVersion(null);
|
||||||
|
addAbstract(null);
|
||||||
|
addDescription(null);
|
||||||
|
addLicense(null);
|
||||||
|
addSpecification(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void flush(String outputpath) throws Exception {
|
||||||
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
|
options.setCharacterEncoding("UTF-8");
|
||||||
|
options.setSavePrettyPrint();
|
||||||
|
options.setSavePrettyPrintIndent(2);
|
||||||
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(outputpath));
|
||||||
|
fullfill();
|
||||||
|
msadoc.save(bw, options);
|
||||||
|
bw.flush();
|
||||||
|
bw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final MsaOwner init() {
|
||||||
|
msa = msadoc.addNewModuleSurfaceArea();
|
||||||
|
msaheader = msa.addNewMsaHeader();
|
||||||
|
moduledefinitions = msa.addNewModuleDefinitions();
|
||||||
|
moduledefinitions.setSupportedArchitectures(listarch);
|
||||||
|
|
||||||
|
sourcefiles = msa.addNewSourceFiles();
|
||||||
|
packagedependencies = msa.addNewPackageDependencies();
|
||||||
|
libclassdefs = msa.addNewLibraryClassDefinitions();
|
||||||
|
externs = msa.addNewExterns();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final MsaOwner initNewMsaOwner() {
|
||||||
|
return new MsaOwner().init();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,129 +1,166 @@
|
|||||||
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 {
|
||||||
/**
|
/**
|
||||||
* Define class Serial Version UID
|
* Define class Serial Version UID
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 3169905938472150649L;
|
private static final long serialVersionUID = 3169905938472150649L;
|
||||||
|
|
||||||
MsaTreeEditor() throws Exception {
|
|
||||||
rootNode = new DefaultMutableTreeNode("Root Node");
|
|
||||||
treeModel = new DefaultTreeModel(rootNode);
|
|
||||||
|
|
||||||
tree = new JTree(treeModel);
|
MsaTreeEditor() throws Exception {
|
||||||
tree.setEditable(true);
|
rootNode = new DefaultMutableTreeNode("Root Node");
|
||||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
treeModel = new DefaultTreeModel(rootNode);
|
||||||
tree.setShowsRootHandles(false);
|
|
||||||
tree.addMouseListener(mouseadapter);
|
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(tree);
|
tree = new JTree(treeModel);
|
||||||
//scrollPane.setSize(800, 600);
|
tree.setEditable(true);
|
||||||
add(scrollPane);
|
tree.getSelectionModel().setSelectionMode(
|
||||||
|
TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||||
popupmenu = new JPopupMenu();
|
tree.setShowsRootHandles(false);
|
||||||
menuitemadd = new JMenuItem("Add Node");
|
tree.addMouseListener(mouseadapter);
|
||||||
menuitemdel = new JMenuItem("Delete Node");
|
|
||||||
menuitemedit = new JMenuItem("Edit Node");
|
|
||||||
popupmenu.add(menuitemadd);
|
|
||||||
popupmenu.add(menuitemdel);
|
|
||||||
popupmenu.add(menuitemedit);
|
|
||||||
menuitemadd.addActionListener(actionListener);
|
|
||||||
menuitemdel.addActionListener(actionListener);
|
|
||||||
menuitemedit.addActionListener(actionListener);
|
|
||||||
|
|
||||||
genDomTree(MigrationTool.ui.getFilepath("Select a msa file", JFileChooser.FILES_AND_DIRECTORIES));
|
JScrollPane scrollPane = new JScrollPane(tree);
|
||||||
}
|
// scrollPane.setSize(800, 600);
|
||||||
|
add(scrollPane);
|
||||||
//private ModuleSurfaceAreaDocument msadoc;
|
|
||||||
|
|
||||||
private JTree tree;
|
|
||||||
private DefaultMutableTreeNode rootNode;
|
|
||||||
private DefaultTreeModel treeModel;
|
|
||||||
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
|
||||||
|
|
||||||
private JPopupMenu popupmenu;
|
|
||||||
private MouseAdapter mouseadapter = new MouseAdapter() {
|
|
||||||
public void mouseReleased(MouseEvent me) {
|
|
||||||
if (me.getClickCount() == 1 && SwingUtilities.isRightMouseButton(me)) {
|
|
||||||
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me.getY()));
|
|
||||||
popupmenu.show(tree, me.getX(), me.getY());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private ActionListener actionListener = new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent ae) {
|
|
||||||
if (ae.getSource() == menuitemadd) {
|
|
||||||
addNode();
|
|
||||||
} else if (ae.getSource() == menuitemdel) {
|
|
||||||
delNode();
|
|
||||||
} else if (ae.getSource() == menuitemedit) {
|
|
||||||
editNode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void editNode() {
|
|
||||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent());
|
|
||||||
Element element = (Element)node.getUserObject();
|
|
||||||
System.out.println(element.getTextContent());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void delNode() {
|
|
||||||
treeModel.removeNodeFromParent((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNode() {
|
|
||||||
addNode((DefaultMutableTreeNode)(tree.getSelectionPath().getLastPathComponent()), MigrationTool.ui.getInput("Input Node Name"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, Object child) {
|
|
||||||
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
|
||||||
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
|
|
||||||
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
|
||||||
return childNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {
|
popupmenu = new JPopupMenu();
|
||||||
DefaultMutableTreeNode curNode = null;
|
menuitemadd = new JMenuItem("Add Node");
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
menuitemdel = new JMenuItem("Delete Node");
|
||||||
System.out.println("elem");
|
menuitemedit = new JMenuItem("Edit Node");
|
||||||
curNode = addNode(parentNode, node);
|
popupmenu.add(menuitemadd);
|
||||||
} else if (node.getNodeType() == Node.DOCUMENT_NODE){
|
popupmenu.add(menuitemdel);
|
||||||
System.out.println("doc");
|
popupmenu.add(menuitemedit);
|
||||||
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with Root Node?
|
menuitemadd.addActionListener(actionListener);
|
||||||
}
|
menuitemdel.addActionListener(actionListener);
|
||||||
|
menuitemedit.addActionListener(actionListener);
|
||||||
|
|
||||||
NodeList nodelist = node.getChildNodes();
|
genDomTree(MigrationTool.ui.getFilepath("Select a msa file",
|
||||||
for (int i = 0; i < nodelist.getLength(); i++) {
|
JFileChooser.FILES_AND_DIRECTORIES));
|
||||||
handleNode(nodelist.item(i), curNode);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void genDomTree(String filename) throws Exception {
|
|
||||||
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
||||||
Document document = builder.parse(filename);
|
|
||||||
handleNode(document, rootNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void init() throws Exception {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
|
|
||||||
JFrame frame = new JFrame("MsaTreeEditor");
|
// private ModuleSurfaceAreaDocument msadoc;
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
MsaTreeEditor mte = new MsaTreeEditor();
|
private JTree tree;
|
||||||
mte.setLayout(new GridBagLayout());
|
|
||||||
mte.setOpaque(true);
|
|
||||||
frame.setContentPane(mte);
|
|
||||||
|
|
||||||
frame.pack();
|
private DefaultMutableTreeNode rootNode;
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
private DefaultTreeModel treeModel;
|
||||||
|
|
||||||
|
private JMenuItem menuitemadd, menuitemdel, menuitemedit;
|
||||||
|
|
||||||
|
private JPopupMenu popupmenu;
|
||||||
|
|
||||||
|
private MouseAdapter mouseadapter = new MouseAdapter() {
|
||||||
|
public void mouseReleased(MouseEvent me) {
|
||||||
|
if (me.getClickCount() == 1
|
||||||
|
&& SwingUtilities.isRightMouseButton(me)) {
|
||||||
|
tree.setSelectionPath(tree.getPathForLocation(me.getX(), me
|
||||||
|
.getY()));
|
||||||
|
popupmenu.show(tree, me.getX(), me.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private ActionListener actionListener = new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent ae) {
|
||||||
|
if (ae.getSource() == menuitemadd) {
|
||||||
|
addNode();
|
||||||
|
} else if (ae.getSource() == menuitemdel) {
|
||||||
|
delNode();
|
||||||
|
} else if (ae.getSource() == menuitemedit) {
|
||||||
|
editNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void editNode() {
|
||||||
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) (tree
|
||||||
|
.getSelectionPath().getLastPathComponent());
|
||||||
|
Element element = (Element) node.getUserObject();
|
||||||
|
System.out.println(element.getTextContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void delNode() {
|
||||||
|
treeModel.removeNodeFromParent((DefaultMutableTreeNode) (tree
|
||||||
|
.getSelectionPath().getLastPathComponent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addNode() {
|
||||||
|
addNode((DefaultMutableTreeNode) (tree.getSelectionPath()
|
||||||
|
.getLastPathComponent()), MigrationTool.ui
|
||||||
|
.getInput("Input Node Name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode,
|
||||||
|
Object child) {
|
||||||
|
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
|
||||||
|
treeModel.insertNodeInto(childNode, parentNode, parentNode
|
||||||
|
.getChildCount());
|
||||||
|
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
|
||||||
|
return childNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void handleNode(Node node, DefaultMutableTreeNode parentNode) {
|
||||||
|
DefaultMutableTreeNode curNode = null;
|
||||||
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
System.out.println("elem");
|
||||||
|
curNode = addNode(parentNode, node);
|
||||||
|
} else if (node.getNodeType() == Node.DOCUMENT_NODE) {
|
||||||
|
System.out.println("doc");
|
||||||
|
curNode = addNode(parentNode, "MsaDocum"); // can Docum be with
|
||||||
|
// Root Node?
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList nodelist = node.getChildNodes();
|
||||||
|
for (int i = 0; i < nodelist.getLength(); i++) {
|
||||||
|
handleNode(nodelist.item(i), curNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void genDomTree(String filename) throws Exception {
|
||||||
|
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
|
||||||
|
.newDocumentBuilder();
|
||||||
|
Document document = builder.parse(filename);
|
||||||
|
handleNode(document, rootNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void init() throws Exception {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
|
JFrame frame = new JFrame("MsaTreeEditor");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
MsaTreeEditor mte = new MsaTreeEditor();
|
||||||
|
mte.setLayout(new GridBagLayout());
|
||||||
|
mte.setOpaque(true);
|
||||||
|
frame.setContentPane(mte);
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,214 +12,277 @@
|
|||||||
**/
|
**/
|
||||||
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) {
|
||||||
mi = moduleinfo;
|
mi = moduleinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleInfo mi;
|
|
||||||
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();
|
|
||||||
|
|
||||||
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();
|
|
||||||
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 GuidsDocument.Guids guids;
|
|
||||||
private ProtocolsDocument.Protocols protocols;
|
|
||||||
private PPIsDocument.PPIs ppis;
|
|
||||||
private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();
|
|
||||||
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();
|
|
||||||
private ExternsDocument.Externs externs = msa.addNewExterns();
|
|
||||||
|
|
||||||
private String Query (String requirement) throws Exception {
|
|
||||||
String answer;
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
|
||||||
System.out.println(requirement);
|
|
||||||
while ((answer = rd.readLine()).length() == 0) ;
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSourceFiles (String name) { // furthur modification needed
|
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
|
||||||
FilenameDocument.Filename filename;
|
|
||||||
filename = sourcefiles.addNewFilename();
|
|
||||||
filename.setStringValue(name);
|
|
||||||
|
|
||||||
if (name.contains("x64" + File.separator)) { // filename ???
|
|
||||||
arch.add(SupportedArchitectures.X_64);
|
|
||||||
System.out.println("x64" + File.separator);
|
|
||||||
filename.setSupArchList(arch);
|
|
||||||
} else if (name.contains("Ia32" + File.separator)) { // filename ???
|
|
||||||
arch.add(SupportedArchitectures.IA_32);
|
|
||||||
System.out.println("Ia32" + File.separator);
|
|
||||||
filename.setSupArchList(arch);
|
|
||||||
} else if (name.contains("Ipf" + File.separator)) { // filename ???
|
|
||||||
arch.add(SupportedArchitectures.IPF);
|
|
||||||
System.out.println("Ipf" + File.separator);
|
|
||||||
filename.setSupArchList(arch);
|
|
||||||
} else if (name.contains("Ebc" + File.separator)) { // filename ???
|
|
||||||
arch.add(SupportedArchitectures.EBC);
|
|
||||||
System.out.println("Ebc" + File.separator);
|
|
||||||
filename.setSupArchList(arch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void addWrapper() {
|
|
||||||
XmlCursor cursor = msa.newCursor();
|
|
||||||
String uri = "http://www.TianoCore.org/2006/Edk2.0";
|
|
||||||
cursor.push();
|
|
||||||
cursor.toNextToken();
|
|
||||||
cursor.insertNamespace("", uri);
|
|
||||||
cursor.insertNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
|
||||||
cursor.pop();
|
|
||||||
msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)cursor.getObject();
|
|
||||||
}
|
|
||||||
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
|
||||||
Iterator<String> it;
|
|
||||||
String temp;
|
|
||||||
|
|
||||||
if (mi.modulename != null) {
|
|
||||||
msaheader.setModuleName(mi.modulename);
|
|
||||||
} else {
|
|
||||||
msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
|
||||||
}
|
|
||||||
if (mi.guidvalue == null) {
|
|
||||||
mi.guidvalue = UUID.randomUUID().toString();
|
|
||||||
MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!");
|
|
||||||
}
|
|
||||||
msaheader.setGuidValue(mi.guidvalue);
|
|
||||||
if (mi.moduletype != null) {
|
|
||||||
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));
|
|
||||||
} else {
|
|
||||||
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.");
|
private ModuleInfo mi;
|
||||||
msaheader.setVersion("1.0");
|
|
||||||
msaheader.setAbstract("Component name for module " + mi.modulename);
|
|
||||||
msaheader.setDescription("FIX ME!");
|
|
||||||
|
|
||||||
if (mi.license == null) {
|
private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
mi.license = "FIX ME!";
|
.newInstance();
|
||||||
MigrationTool.ui.println ("Fail to extract license info in inf file");
|
|
||||||
}
|
|
||||||
msaheader.addNewLicense().setStringValue(mi.license);
|
|
||||||
msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
|
||||||
|
|
||||||
List<Enum> arch = new ArrayList<Enum>();
|
|
||||||
arch.add(SupportedArchitectures.IA_32);
|
|
||||||
arch.add(SupportedArchitectures.X_64);
|
|
||||||
arch.add(SupportedArchitectures.IPF);
|
|
||||||
arch.add(SupportedArchitectures.EBC);
|
|
||||||
md.setSupportedArchitectures(arch);
|
|
||||||
md.setBinaryModule(false);
|
|
||||||
md.setOutputFileBasename(mi.modulename);
|
|
||||||
//
|
|
||||||
// For now, simply add all package guids in the database.
|
|
||||||
//
|
|
||||||
it = MigrationTool.db.dumpAllPkgGuid();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
pd.addNewPackage().setPackageGuid(it.next());
|
|
||||||
}
|
|
||||||
externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");
|
|
||||||
externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");
|
|
||||||
if (mi.entrypoint != null) {
|
|
||||||
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
|
||||||
org.tianocore.ModuleTypeDef.Enum moduleType = msaheader.getModuleType();
|
|
||||||
if (moduleType == ModuleTypeDef.PEIM) {
|
|
||||||
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
|
||||||
} else {
|
|
||||||
mi.hashrequiredr9libs.add("UefiDriverEntryPoint");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it = mi.localmodulesources.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
addSourceFiles(it.next());
|
|
||||||
}
|
|
||||||
if (!mi.protocols.isEmpty()) {
|
|
||||||
protocols = msa.addNewProtocols();
|
|
||||||
it = mi.protocols.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
if ((temp = it.next()) != null) {
|
|
||||||
ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();
|
|
||||||
pr.setProtocolCName(temp);
|
|
||||||
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!mi.ppis.isEmpty()) {
|
|
||||||
ppis = msa.addNewPPIs();
|
|
||||||
it = mi.ppis.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
if ((temp = it.next()) != null) {
|
|
||||||
PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();
|
|
||||||
pp.setPpiCName(temp);
|
|
||||||
pp.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!mi.guids.isEmpty()) {
|
|
||||||
guids = msa.addNewGuids();
|
|
||||||
it = mi.guids.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
if ((temp = it.next()) != null) {
|
|
||||||
GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();
|
|
||||||
gcn.setGuidCName(temp);
|
|
||||||
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
it = mi.hashrequiredr9libs.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
if ((temp = it.next()) != null && !temp.matches("%") && !temp.matches("n/a")) {
|
|
||||||
LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();
|
|
||||||
lc.setKeyword(temp);
|
|
||||||
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addWrapper();
|
|
||||||
msadoc.setModuleSurfaceArea(msa);
|
|
||||||
return msadoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void flush() throws Exception {
|
|
||||||
XmlOptions options = new XmlOptions();
|
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc
|
||||||
options.setSavePrettyPrint();
|
.addNewModuleSurfaceArea();
|
||||||
options.setSavePrettyPrintIndent(2);
|
|
||||||
options.setUseDefaultNamespace();
|
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));
|
private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();
|
||||||
fulfillMsadoc().save(bw, options);
|
|
||||||
//MsaTreeEditor.init(mi, ui, msadoc);
|
|
||||||
bw.flush();
|
|
||||||
bw.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {
|
private ModuleDefinitionsDocument.ModuleDefinitions md = msa
|
||||||
XmlOptions options = new XmlOptions();
|
.addNewModuleDefinitions();
|
||||||
|
|
||||||
options.setCharacterEncoding("UTF-8");
|
private SourceFilesDocument.SourceFiles sourcefiles = msa
|
||||||
options.setSavePrettyPrint();
|
.addNewSourceFiles(); // found local .h files are not written
|
||||||
options.setSavePrettyPrintIndent(2);
|
|
||||||
options.setUseDefaultNamespace();
|
|
||||||
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
|
private GuidsDocument.Guids guids;
|
||||||
msadoc.save(bw, options);
|
|
||||||
bw.flush();
|
|
||||||
bw.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void parse(String msafile) throws Exception {
|
private ProtocolsDocument.Protocols protocols;
|
||||||
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);
|
|
||||||
flush("c:\\temp.msa", msadoc);
|
private PPIsDocument.PPIs ppis;
|
||||||
}
|
|
||||||
|
private PackageDependenciesDocument.PackageDependencies pd = msa
|
||||||
|
.addNewPackageDependencies();
|
||||||
|
|
||||||
|
private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa
|
||||||
|
.addNewLibraryClassDefinitions();
|
||||||
|
|
||||||
|
private ExternsDocument.Externs externs = msa.addNewExterns();
|
||||||
|
|
||||||
|
private String Query(String requirement) throws Exception {
|
||||||
|
String answer;
|
||||||
|
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
System.out.println(requirement);
|
||||||
|
while ((answer = rd.readLine()).length() == 0)
|
||||||
|
;
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSourceFiles(String name) { // furthur modification needed
|
||||||
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
|
FilenameDocument.Filename filename;
|
||||||
|
filename = sourcefiles.addNewFilename();
|
||||||
|
filename.setStringValue(name);
|
||||||
|
|
||||||
|
if (name.contains("x64" + File.separator)) { // filename ???
|
||||||
|
arch.add(SupportedArchitectures.X_64);
|
||||||
|
System.out.println("x64" + File.separator);
|
||||||
|
filename.setSupArchList(arch);
|
||||||
|
} else if (name.contains("Ia32" + File.separator)) { // filename ???
|
||||||
|
arch.add(SupportedArchitectures.IA_32);
|
||||||
|
System.out.println("Ia32" + File.separator);
|
||||||
|
filename.setSupArchList(arch);
|
||||||
|
} else if (name.contains("Ipf" + File.separator)) { // filename ???
|
||||||
|
arch.add(SupportedArchitectures.IPF);
|
||||||
|
System.out.println("Ipf" + File.separator);
|
||||||
|
filename.setSupArchList(arch);
|
||||||
|
} else if (name.contains("Ebc" + File.separator)) { // filename ???
|
||||||
|
arch.add(SupportedArchitectures.EBC);
|
||||||
|
System.out.println("Ebc" + File.separator);
|
||||||
|
filename.setSupArchList(arch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addWrapper() {
|
||||||
|
XmlCursor cursor = msa.newCursor();
|
||||||
|
String uri = "http://www.TianoCore.org/2006/Edk2.0";
|
||||||
|
cursor.push();
|
||||||
|
cursor.toNextToken();
|
||||||
|
cursor.insertNamespace("", uri);
|
||||||
|
cursor.insertNamespace("xsi",
|
||||||
|
"http://www.w3.org/2001/XMLSchema-instance");
|
||||||
|
cursor.pop();
|
||||||
|
msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) cursor.getObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {
|
||||||
|
Iterator<String> it;
|
||||||
|
String temp;
|
||||||
|
|
||||||
|
if (mi.modulename != null) {
|
||||||
|
msaheader.setModuleName(mi.modulename);
|
||||||
|
} else {
|
||||||
|
msaheader
|
||||||
|
.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));
|
||||||
|
}
|
||||||
|
if (mi.guidvalue == null) {
|
||||||
|
mi.guidvalue = UUID.randomUUID().toString();
|
||||||
|
MigrationTool.ui
|
||||||
|
.println("Guid value can not be retrieved from inf file. Generate "
|
||||||
|
+ mi.guidvalue + " at random!");
|
||||||
|
}
|
||||||
|
msaheader.setGuidValue(mi.guidvalue);
|
||||||
|
if (mi.moduletype != null) {
|
||||||
|
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi
|
||||||
|
.getModuleType()));
|
||||||
|
} else {
|
||||||
|
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.setVersion("1.0");
|
||||||
|
msaheader.setAbstract("Component name for module " + mi.modulename);
|
||||||
|
msaheader.setDescription("FIX ME!");
|
||||||
|
|
||||||
|
if (mi.license == null) {
|
||||||
|
mi.license = "FIX ME!";
|
||||||
|
MigrationTool.ui
|
||||||
|
.println("Fail to extract license info in inf file");
|
||||||
|
}
|
||||||
|
msaheader.addNewLicense().setStringValue(mi.license);
|
||||||
|
msaheader
|
||||||
|
.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
|
||||||
|
|
||||||
|
List<Enum> arch = new ArrayList<Enum>();
|
||||||
|
arch.add(SupportedArchitectures.IA_32);
|
||||||
|
arch.add(SupportedArchitectures.X_64);
|
||||||
|
arch.add(SupportedArchitectures.IPF);
|
||||||
|
arch.add(SupportedArchitectures.EBC);
|
||||||
|
md.setSupportedArchitectures(arch);
|
||||||
|
md.setBinaryModule(false);
|
||||||
|
md.setOutputFileBasename(mi.modulename);
|
||||||
|
//
|
||||||
|
// For now, simply add all package guids in the database.
|
||||||
|
//
|
||||||
|
it = MigrationTool.db.dumpAllPkgGuid();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
pd.addNewPackage().setPackageGuid(it.next());
|
||||||
|
}
|
||||||
|
externs.addNewSpecification().setStringValue(
|
||||||
|
"EFI_SPECIFICATION_VERSION 0x00020000");
|
||||||
|
externs.addNewSpecification().setStringValue(
|
||||||
|
"EDK_RELEASE_VERSION 0x00020000");
|
||||||
|
if (mi.entrypoint != null) {
|
||||||
|
externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);
|
||||||
|
org.tianocore.ModuleTypeDef.Enum moduleType = msaheader
|
||||||
|
.getModuleType();
|
||||||
|
if (moduleType == ModuleTypeDef.PEIM) {
|
||||||
|
mi.hashrequiredr9libs.add("PeimEntryPoint");
|
||||||
|
} else {
|
||||||
|
mi.hashrequiredr9libs.add("UefiDriverEntryPoint");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it = mi.localmodulesources.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
addSourceFiles(it.next());
|
||||||
|
}
|
||||||
|
if (!mi.protocols.isEmpty()) {
|
||||||
|
protocols = msa.addNewProtocols();
|
||||||
|
it = mi.protocols.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if ((temp = it.next()) != null) {
|
||||||
|
ProtocolsDocument.Protocols.Protocol pr = protocols
|
||||||
|
.addNewProtocol();
|
||||||
|
pr.setProtocolCName(temp);
|
||||||
|
pr.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mi.ppis.isEmpty()) {
|
||||||
|
ppis = msa.addNewPPIs();
|
||||||
|
it = mi.ppis.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if ((temp = it.next()) != null) {
|
||||||
|
PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();
|
||||||
|
pp.setPpiCName(temp);
|
||||||
|
pp.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mi.guids.isEmpty()) {
|
||||||
|
guids = msa.addNewGuids();
|
||||||
|
it = mi.guids.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if ((temp = it.next()) != null) {
|
||||||
|
GuidsDocument.Guids.GuidCNames gcn = guids
|
||||||
|
.addNewGuidCNames();
|
||||||
|
gcn.setGuidCName(temp);
|
||||||
|
gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it = mi.hashrequiredr9libs.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
if ((temp = it.next()) != null && !temp.matches("%")
|
||||||
|
&& !temp.matches("n/a")) {
|
||||||
|
LibraryClassDocument.LibraryClass lc = libclassdefs
|
||||||
|
.addNewLibraryClass();
|
||||||
|
lc.setKeyword(temp);
|
||||||
|
lc.setUsage(UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addWrapper();
|
||||||
|
msadoc.setModuleSurfaceArea(msa);
|
||||||
|
return msadoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flush() throws Exception {
|
||||||
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
|
options.setCharacterEncoding("UTF-8");
|
||||||
|
options.setSavePrettyPrint();
|
||||||
|
options.setSavePrettyPrintIndent(2);
|
||||||
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(
|
||||||
|
MigrationTool.ModuleInfoMap.get(mi) + File.separator
|
||||||
|
+ "Migration_" + mi.modulename + File.separator
|
||||||
|
+ mi.modulename + ".msa"));
|
||||||
|
fulfillMsadoc().save(bw, options);
|
||||||
|
// MsaTreeEditor.init(mi, ui, msadoc);
|
||||||
|
bw.flush();
|
||||||
|
bw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void flush(String path, ModuleSurfaceAreaDocument msadoc)
|
||||||
|
throws Exception {
|
||||||
|
XmlOptions options = new XmlOptions();
|
||||||
|
|
||||||
|
options.setCharacterEncoding("UTF-8");
|
||||||
|
options.setSavePrettyPrint();
|
||||||
|
options.setSavePrettyPrintIndent(2);
|
||||||
|
options.setUseDefaultNamespace();
|
||||||
|
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
|
||||||
|
msadoc.save(bw, options);
|
||||||
|
bw.flush();
|
||||||
|
bw.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void parse(String msafile) throws Exception {
|
||||||
|
ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory
|
||||||
|
.parse(msafile);
|
||||||
|
flush("c:\\temp.msa", msadoc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,38 +13,44 @@
|
|||||||
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
|
||||||
PathIterator(String path, int md) throws Exception {
|
// required.
|
||||||
startpath = path;
|
PathIterator(String path, int md) throws Exception {
|
||||||
mode = md;
|
startpath = path;
|
||||||
Common.toDoAll(startpath, this, mode);
|
mode = md;
|
||||||
it = pathlist.iterator();
|
Common.toDoAll(startpath, this, mode);
|
||||||
}
|
it = pathlist.iterator();
|
||||||
private String startpath = null;
|
}
|
||||||
private int mode;
|
|
||||||
private HashSet<String> pathlist = new HashSet<String>();
|
|
||||||
private Iterator<String> it = null;
|
|
||||||
|
|
||||||
public final void run(String path) throws Exception {
|
private String startpath = null;
|
||||||
pathlist.add(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean filter(File dir) {
|
private int mode;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String next() {
|
|
||||||
return it.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean hasNext() {
|
private HashSet<String> pathlist = new HashSet<String>();
|
||||||
return it.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String toString() {
|
private Iterator<String> it = null;
|
||||||
return pathlist.toString();
|
|
||||||
}
|
public final void run(String path) throws Exception {
|
||||||
|
pathlist.add(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean filter(File dir) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String next() {
|
||||||
|
return it.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final boolean hasNext() {
|
||||||
|
return it.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String toString() {
|
||||||
|
return pathlist.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,437 +12,493 @@
|
|||||||
**/
|
**/
|
||||||
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;
|
||||||
|
|
||||||
import org.tianocore.UsageTypes;
|
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 static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
|
||||||
|
|
||||||
// these sets are used only for printing log of the changes in current file
|
private ModuleInfo mi;
|
||||||
private static final Set<r8tor9> filefunc = 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> fileppi = new HashSet<r8tor9>();
|
|
||||||
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
|
||||||
private static final Set<String> filer8only = new HashSet<String>();
|
|
||||||
|
|
||||||
private static final String[] specialhoblibfunc = {
|
|
||||||
"BuildModuleHob",
|
|
||||||
"BuildResourceDescriptorHob",
|
|
||||||
"BuildFvHob",
|
|
||||||
"BuildCpuHob",
|
|
||||||
"BuildGuidDataHob",
|
|
||||||
"BuildStackHob",
|
|
||||||
"BuildBspStoreHob",
|
|
||||||
"BuildMemoryAllocationHob"
|
|
||||||
};
|
|
||||||
private static final String[] peiserviceslibfunc = {
|
|
||||||
"InstallPpi",
|
|
||||||
"ReInstallPpi",
|
|
||||||
"LocatePpi",
|
|
||||||
"NotifyPpi",
|
|
||||||
"GetBootMode",
|
|
||||||
"SetBootMode",
|
|
||||||
"GetHobList",
|
|
||||||
"CreateHob",
|
|
||||||
"FfsFindNextVolume",
|
|
||||||
"FfsFindNextFile",
|
|
||||||
"FfsFindSectionData",
|
|
||||||
"InstallPeiMemory",
|
|
||||||
"AllocatePages",
|
|
||||||
"AllocatePool",
|
|
||||||
"PeiResetSystem"
|
|
||||||
};
|
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
|
||||||
private static class r8tor9 {
|
|
||||||
r8tor9(String r8, String r9) {
|
|
||||||
r8thing = r8;
|
|
||||||
r9thing = r9;
|
|
||||||
}
|
|
||||||
public String r8thing;
|
|
||||||
public String r9thing;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class IdleLaplace extends Common.Laplace {
|
|
||||||
public String operation(String wholeline) {
|
|
||||||
return replaceLibrary (wholeline, mi.hashmacro);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
|
||||||
return filename.contains(".h") || filename.contains(".H") || filename.contains(".uni") ||
|
|
||||||
filename.contains(".s") || filename.contains(".S") || filename.contains(".asm") ||
|
|
||||||
(!filename.contains(".inf") && filename.contains(".i"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
||||||
if (oldname.contains(".H")) {
|
|
||||||
return oldname.replaceFirst(".H", ".h");
|
|
||||||
} else {
|
|
||||||
return oldname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class DxsLaplace extends Common.Laplace {
|
|
||||||
public String operation(String wholeline) {
|
|
||||||
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
|
||||||
if (mi.getModuleType().equals("PEIM")) {
|
|
||||||
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
|
||||||
} else {
|
|
||||||
return addincludefile(wholeline, "\\<DxeDepex.h\\>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean recognize(String filename) {
|
|
||||||
return filename.contains(".dxs");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
// these sets are used only for printing log of the changes in current file
|
||||||
return oldname;
|
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CLaplace extends Common.Laplace {
|
|
||||||
public String operation(String wholeline) {
|
|
||||||
// remove EFI_DRIVER_ENTRY_POINT
|
|
||||||
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
|
|
||||||
wholeline = wholeline.replaceAll (mi.entrypoint + "([^{]*?})", "_ModuleEntryPoint" + "$1");
|
|
||||||
// remove R8 library contractor
|
|
||||||
wholeline = wholeline.replaceAll ("(\\b(?:Efi|Dxe)InitializeDriverLib\\b)", MigrationTool.MIGRATIONCOMMENT + " $1");
|
|
||||||
// Add Library Class for potential reference of gBS, gRT & gDS.
|
|
||||||
if (Common.find (wholeline, "\\bg?BS\\b")) {
|
|
||||||
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
|
||||||
}
|
|
||||||
if (Common.find (wholeline, "\\bg?RT\\b")) {
|
|
||||||
mi.hashrequiredr9libs.add ("UefiRuntimeServicesTableLib");
|
|
||||||
}
|
|
||||||
if (Common.find (wholeline, "\\bgDS\\b")) {
|
|
||||||
mi.hashrequiredr9libs.add ("DxeServicesTableLib");
|
|
||||||
}
|
|
||||||
|
|
||||||
wholeline = replaceLibrary (wholeline, mi.hashnonlocalfunc);
|
private static final Set<r8tor9> filemacro = new HashSet<r8tor9>();
|
||||||
wholeline = replaceLibrary (wholeline, mi.hashmacro);
|
|
||||||
// Converting macro
|
|
||||||
wholeline = replaceMacro (wholeline, mi.hashnonlocalmacro);
|
|
||||||
|
|
||||||
// Converting guid
|
private static final Set<r8tor9> fileguid = new HashSet<r8tor9>();
|
||||||
replaceGuid(wholeline, mi.guids, "guid", fileguid);
|
|
||||||
replaceGuid(wholeline, mi.ppis, "ppi", fileppi);
|
|
||||||
replaceGuid(wholeline, mi.protocols, "protocol", fileprotocol);
|
|
||||||
|
|
||||||
// Converting Pei
|
private static final Set<r8tor9> fileppi = new HashSet<r8tor9>();
|
||||||
if (mi.getModuleType().matches("PEIM")) {
|
|
||||||
//
|
|
||||||
// Try to remove PeiServicesTablePointer;
|
|
||||||
//
|
|
||||||
wholeline = dropPeiServicesPointer (wholeline);
|
|
||||||
//
|
|
||||||
// Drop the possible return Status of Hob building function.
|
|
||||||
//
|
|
||||||
wholeline = drophobLibReturnStatus (wholeline);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Expand obsolete R8 macro.
|
|
||||||
//
|
|
||||||
wholeline = replaceObsoleteMacro (wholeline);
|
|
||||||
|
|
||||||
show(filefunc, "function");
|
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||||
show(filemacro, "macro");
|
|
||||||
show(fileguid, "guid");
|
|
||||||
show(fileppi, "ppi");
|
|
||||||
show(fileprotocol, "protocol");
|
|
||||||
if (!filer8only.isEmpty()) {
|
|
||||||
MigrationTool.ui.println("Converting r8only : " + filer8only);
|
|
||||||
}
|
|
||||||
|
|
||||||
filefunc.clear();
|
private static final Set<String> filer8only = new HashSet<String>();
|
||||||
filemacro.clear();
|
|
||||||
fileguid.clear();
|
|
||||||
fileppi.clear();
|
|
||||||
fileprotocol.clear();
|
|
||||||
filer8only.clear();
|
|
||||||
|
|
||||||
return wholeline;
|
private static final String[] specialhoblibfunc = { "BuildModuleHob",
|
||||||
}
|
"BuildResourceDescriptorHob", "BuildFvHob", "BuildCpuHob",
|
||||||
|
"BuildGuidDataHob", "BuildStackHob", "BuildBspStoreHob",
|
||||||
public boolean recognize(String filename) {
|
"BuildMemoryAllocationHob" };
|
||||||
return filename.contains(".c") || filename.contains(".C");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String namechange(String oldname) {
|
private static final String[] peiserviceslibfunc = { "InstallPpi",
|
||||||
if (oldname.contains(".C")) {
|
"ReInstallPpi", "LocatePpi", "NotifyPpi", "GetBootMode",
|
||||||
return oldname.replaceFirst(".C", ".c");
|
"SetBootMode", "GetHobList", "CreateHob", "FfsFindNextVolume",
|
||||||
} else {
|
"FfsFindNextFile", "FfsFindSectionData", "InstallPeiMemory",
|
||||||
return oldname;
|
"AllocatePages", "AllocatePool", "PeiResetSystem" };
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//---------------------------------------inner classes---------------------------------------//
|
|
||||||
|
|
||||||
//-------------------------------------process functions-------------------------------------//
|
// ---------------------------------------inner
|
||||||
private static final String addincludefile(String wholeline, String hfile) {
|
// classes---------------------------------------//
|
||||||
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
private static class r8tor9 {
|
||||||
}
|
r8tor9(String r8, String r9) {
|
||||||
|
r8thing = r8;
|
||||||
private static final void show(Set<r8tor9> hash, String sh) {
|
r9thing = r9;
|
||||||
Iterator<r8tor9> it = hash.iterator();
|
}
|
||||||
r8tor9 temp;
|
|
||||||
if (!hash.isEmpty()) {
|
|
||||||
MigrationTool.ui.print("Converting " + sh + " : ");
|
|
||||||
while (it.hasNext()) {
|
|
||||||
temp = it.next();
|
|
||||||
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");
|
|
||||||
}
|
|
||||||
MigrationTool.ui.println("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {
|
public String r8thing;
|
||||||
Iterator<String> it;
|
|
||||||
String r8thing;
|
|
||||||
String r9thing;
|
|
||||||
it = hash.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
r8thing = it.next();
|
|
||||||
if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) {
|
|
||||||
if (!r8thing.equals(r9thing)) {
|
|
||||||
if (line.contains(r8thing)) {
|
|
||||||
line = line.replaceAll(r8thing, r9thing);
|
|
||||||
filehash.add(new r8tor9(r8thing, r9thing));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String dropPeiServicesPointer (String wholeline) {
|
public String r9thing;
|
||||||
String peiServicesTablePointer;
|
}
|
||||||
String peiServicesTableCaller;
|
|
||||||
String regPeiServices;
|
|
||||||
Pattern ptnPei;
|
|
||||||
Matcher mtrPei;
|
|
||||||
|
|
||||||
peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*";
|
private class IdleLaplace extends Common.Laplace {
|
||||||
peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer + ")\\s*\\)[.-]>?\\s*";
|
public String operation(String wholeline) {
|
||||||
for (int i = 0; i < peiserviceslibfunc.length; i++) {
|
return replaceLibrary(wholeline, mi.hashmacro);
|
||||||
regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i] + "\\s*\\(\\s*\\1\\s*,(\\t| )*";
|
}
|
||||||
ptnPei = Pattern.compile (regPeiServices);
|
|
||||||
mtrPei = ptnPei.matcher (wholeline);
|
|
||||||
if (mtrPei.find()) {
|
|
||||||
wholeline = mtrPei.replaceAll("PeiServices" + peiserviceslibfunc[i] + " (");
|
|
||||||
mi.hashrequiredr9libs.add("PeiServicesLib");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)" + "\\s*\\((\\t| )*";
|
|
||||||
ptnPei = Pattern.compile (regPeiServices);
|
|
||||||
mtrPei = ptnPei.matcher (wholeline);
|
|
||||||
if (mtrPei.find()) {
|
|
||||||
wholeline = mtrPei.replaceAll("$2 (");
|
|
||||||
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
|
||||||
}
|
|
||||||
|
|
||||||
ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer + "\\s*,\\s*", Pattern.MULTILINE);
|
public boolean recognize(String filename) {
|
||||||
mtrPei = ptnPei.matcher(wholeline);
|
return filename.contains(".h") || filename.contains(".H")
|
||||||
while (mtrPei.find()) {
|
|| filename.contains(".uni") || filename.contains(".s")
|
||||||
wholeline = mtrPei.replaceAll("$1");
|
|| filename.contains(".S") || filename.contains(".asm")
|
||||||
}
|
|| (!filename.contains(".inf") && filename.contains(".i"));
|
||||||
|
}
|
||||||
|
|
||||||
return wholeline;
|
public String namechange(String oldname) {
|
||||||
}
|
if (oldname.contains(".H")) {
|
||||||
|
return oldname.replaceFirst(".H", ".h");
|
||||||
|
} else {
|
||||||
|
return oldname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final String drophobLibReturnStatus (String wholeline) { // or use regex to find pattern "Status = ..."
|
private class DxsLaplace extends Common.Laplace {
|
||||||
Pattern ptnhobstatus;
|
public String operation(String wholeline) {
|
||||||
Matcher mtrhobstatus;
|
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
||||||
String templine = wholeline;
|
if (mi.getModuleType().equals("PEIM")) {
|
||||||
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
||||||
do {
|
} else {
|
||||||
ptnhobstatus = Pattern.compile("((?:\t| )*)(\\w(?:\\w|\\d)*)\\s*=\\s*" + specialhoblibfunc[i] + "(.*?;)", Pattern.DOTALL);
|
return addincludefile(wholeline, "\\<DxeDepex.h\\>");
|
||||||
mtrhobstatus = ptnhobstatus.matcher(templine);
|
}
|
||||||
if (!mtrhobstatus.find()) {
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
String captureIndent = mtrhobstatus.group(1);
|
|
||||||
String captureStatus = mtrhobstatus.group(2);
|
|
||||||
String replaceString = captureIndent + specialhoblibfunc[i] + mtrhobstatus.group(3) + "\n";
|
|
||||||
replaceString += captureIndent + MigrationTool.MIGRATIONCOMMENT + "R9 Hob-building library functions will assert if build failure.\n";
|
|
||||||
replaceString += captureIndent + captureStatus + " = EFI_SUCCESS;";
|
|
||||||
templine = mtrhobstatus.replaceFirst(replaceString);
|
|
||||||
} while (true);
|
|
||||||
}
|
|
||||||
return templine;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String replaceMacro (String wholeline, Set<String> symbolSet) {
|
public boolean recognize(String filename) {
|
||||||
String r8thing;
|
return filename.contains(".dxs");
|
||||||
String r9thing;
|
}
|
||||||
Iterator<String> it;
|
|
||||||
|
|
||||||
it = symbolSet.iterator();
|
public String namechange(String oldname) {
|
||||||
while (it.hasNext()) { //macros are all assumed MdePkg currently
|
return oldname;
|
||||||
r8thing = it.next();
|
}
|
||||||
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
}
|
||||||
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
|
||||||
if (wholeline.contains(r8thing)) {
|
|
||||||
String findString = "(?<!(?:\\d|\\w))" + r8thing + "(?!(?:\\d|\\w))";
|
|
||||||
wholeline = wholeline.replaceAll(findString, r9thing);
|
|
||||||
filemacro.add(new r8tor9(r8thing, r9thing));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return wholeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String replaceLibrary (String wholeline, Set<String> symbolSet) {
|
private class CLaplace extends Common.Laplace {
|
||||||
boolean addr8 = false;
|
public String operation(String wholeline) {
|
||||||
// start replacing names
|
// remove EFI_DRIVER_ENTRY_POINT
|
||||||
String r8thing;
|
wholeline = wholeline.replaceAll(
|
||||||
String r9thing;
|
"(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*\\w(\\w|\\d)*\\s*\\))",
|
||||||
Iterator<String> it;
|
MigrationTool.MIGRATIONCOMMENT + " $1");
|
||||||
// Converting non-locla function
|
// redefine module entry point for some self-relocated modules
|
||||||
it = symbolSet.iterator();
|
wholeline = wholeline.replaceAll(mi.entrypoint + "([^{]*?})",
|
||||||
while (it.hasNext()) {
|
"_ModuleEntryPoint" + "$1");
|
||||||
r8thing = it.next();
|
// remove R8 library contractor
|
||||||
mi.addLibraryClass(MigrationTool.db.getR9Lib(r8thing), UsageTypes.ALWAYS_CONSUMED);
|
wholeline = wholeline.replaceAll(
|
||||||
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here
|
"(\\b(?:Efi|Dxe)InitializeDriverLib\\b)",
|
||||||
|
MigrationTool.MIGRATIONCOMMENT + " $1");
|
||||||
r8tor9 temp;
|
// Add Library Class for potential reference of gBS, gRT & gDS.
|
||||||
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
if (Common.find(wholeline, "\\bg?BS\\b")) {
|
||||||
if (!r8thing.equals(r9thing)) {
|
mi.hashrequiredr9libs.add("UefiBootServicesTableLib");
|
||||||
if (wholeline.contains(r8thing)) {
|
}
|
||||||
String findString = "(?<!(?:\\d|\\w))" + r8thing + "(?!(?:\\d|\\w))";
|
if (Common.find(wholeline, "\\bg?RT\\b")) {
|
||||||
wholeline = wholeline.replaceAll(findString, r9thing);
|
mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");
|
||||||
filefunc.add(new r8tor9(r8thing, r9thing));
|
}
|
||||||
Iterator<r8tor9> rt = filefunc.iterator();
|
if (Common.find(wholeline, "\\bgDS\\b")) {
|
||||||
while (rt.hasNext()) {
|
mi.hashrequiredr9libs.add("DxeServicesTableLib");
|
||||||
temp = rt.next();
|
}
|
||||||
if (MigrationTool.db.r8only.contains(temp.r8thing)) {
|
|
||||||
filer8only.add(r8thing);
|
|
||||||
mi.hashr8only.add(r8thing);
|
|
||||||
addr8 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //is any of the guids changed?
|
|
||||||
if (addr8 == true) {
|
|
||||||
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
|
||||||
}
|
|
||||||
return wholeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String replaceObsoleteMacro (String wholeline) {
|
wholeline = replaceLibrary(wholeline, mi.hashnonlocalfunc);
|
||||||
Matcher mtrmac;
|
wholeline = replaceLibrary(wholeline, mi.hashmacro);
|
||||||
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);
|
// Converting macro
|
||||||
if (mtrmac.find()) {
|
wholeline = replaceMacro(wholeline, mi.hashnonlocalmacro);
|
||||||
wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
|
||||||
}
|
|
||||||
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
|
||||||
if (mtrmac.find()) {
|
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
|
||||||
}
|
|
||||||
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
|
||||||
if (mtrmac.find()) {
|
|
||||||
wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
|
||||||
}
|
|
||||||
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);
|
|
||||||
if (mtrmac.find()) {
|
|
||||||
wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
|
||||||
}
|
|
||||||
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
|
||||||
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");
|
|
||||||
}
|
|
||||||
return wholeline;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final void addr8only() throws Exception {
|
// Converting guid
|
||||||
String paragraph = null;
|
replaceGuid(wholeline, mi.guids, "guid", fileguid);
|
||||||
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");
|
replaceGuid(wholeline, mi.ppis, "ppi", fileppi);
|
||||||
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + "R8Lib.c")));
|
replaceGuid(wholeline, mi.protocols, "protocol", fileprotocol);
|
||||||
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 mtrr8onlyhead;
|
|
||||||
|
|
||||||
//add head comment
|
|
||||||
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT.matcher(line);
|
|
||||||
if (mtrr8onlyheadcomment.find()) {
|
|
||||||
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
|
||||||
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
//add functions body
|
|
||||||
while (mtrr8only.find()) {
|
|
||||||
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
|
||||||
paragraph = mtrr8only.group(2);
|
|
||||||
outfile1.append(paragraph + "\n\n");
|
|
||||||
if (mtrr8only.group(1).length() != 0) {
|
|
||||||
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
|
||||||
}
|
|
||||||
//generate R8lib.h
|
|
||||||
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) {
|
|
||||||
paragraph = mtrr8onlyhead.replaceAll(";");
|
|
||||||
}
|
|
||||||
outfile2.append(paragraph + "\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outfile1.flush();
|
|
||||||
outfile1.close();
|
|
||||||
outfile2.flush();
|
|
||||||
outfile2.close();
|
|
||||||
|
|
||||||
mi.localmodulesources.add("R8Lib.h");
|
|
||||||
mi.localmodulesources.add("R8Lib.c");
|
|
||||||
}
|
|
||||||
//-------------------------------------process functions-------------------------------------//
|
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
|
||||||
public void run(String filepath) throws Exception {
|
|
||||||
String inname = filepath.replace(mi.temppath + File.separator, "");
|
|
||||||
String tempinpath = mi.temppath + File.separator;
|
|
||||||
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
|
||||||
|
|
||||||
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
// Converting Pei
|
||||||
while (itLaplace.hasNext()) {
|
if (mi.getModuleType().matches("PEIM")) {
|
||||||
Common.Laplace lap = itLaplace.next();
|
//
|
||||||
if (lap.recognize(inname)) {
|
// Try to remove PeiServicesTablePointer;
|
||||||
MigrationTool.ui.println("\nHandling file: " + inname);
|
//
|
||||||
lap.transform(tempinpath + inname, tempoutpath + lap.namechange(inname));
|
wholeline = dropPeiServicesPointer(wholeline);
|
||||||
}
|
//
|
||||||
}
|
// Drop the possible return Status of Hob building function.
|
||||||
}
|
//
|
||||||
|
wholeline = drophobLibReturnStatus(wholeline);
|
||||||
public boolean filter(File dir) {
|
}
|
||||||
return true;
|
//
|
||||||
}
|
// Expand obsolete R8 macro.
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
//
|
||||||
|
wholeline = replaceObsoleteMacro(wholeline);
|
||||||
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
|
||||||
mi = moduleinfo;
|
show(filefunc, "function");
|
||||||
}
|
show(filemacro, "macro");
|
||||||
|
show(fileguid, "guid");
|
||||||
private final void start() throws Exception {
|
show(fileppi, "ppi");
|
||||||
Laplaces.add(new DxsLaplace());
|
show(fileprotocol, "protocol");
|
||||||
Laplaces.add(new CLaplace());
|
if (!filer8only.isEmpty()) {
|
||||||
Laplaces.add(new IdleLaplace());
|
MigrationTool.ui.println("Converting r8only : " + filer8only);
|
||||||
|
}
|
||||||
Common.toDoAll(mi.temppath, this, Common.FILE);
|
|
||||||
|
filefunc.clear();
|
||||||
if (!mi.hashr8only.isEmpty()) {
|
filemacro.clear();
|
||||||
addr8only();
|
fileguid.clear();
|
||||||
}
|
fileppi.clear();
|
||||||
|
fileprotocol.clear();
|
||||||
Laplaces.clear();
|
filer8only.clear();
|
||||||
}
|
|
||||||
|
return wholeline;
|
||||||
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
}
|
||||||
SFReplacer.setModuleInfo(moduleinfo);
|
|
||||||
SFReplacer.start();
|
public boolean recognize(String filename) {
|
||||||
}
|
return filename.contains(".c") || filename.contains(".C");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String namechange(String oldname) {
|
||||||
|
if (oldname.contains(".C")) {
|
||||||
|
return oldname.replaceFirst(".C", ".c");
|
||||||
|
} else {
|
||||||
|
return oldname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------inner
|
||||||
|
// classes---------------------------------------//
|
||||||
|
|
||||||
|
// -------------------------------------process
|
||||||
|
// functions-------------------------------------//
|
||||||
|
private static final String addincludefile(String wholeline, String hfile) {
|
||||||
|
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile
|
||||||
|
+ "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final void show(Set<r8tor9> hash, String sh) {
|
||||||
|
Iterator<r8tor9> it = hash.iterator();
|
||||||
|
r8tor9 temp;
|
||||||
|
if (!hash.isEmpty()) {
|
||||||
|
MigrationTool.ui.print("Converting " + sh + " : ");
|
||||||
|
while (it.hasNext()) {
|
||||||
|
temp = it.next();
|
||||||
|
MigrationTool.ui.print("[" + temp.r8thing + "->" + temp.r9thing
|
||||||
|
+ "] ");
|
||||||
|
}
|
||||||
|
MigrationTool.ui.println("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final void replaceGuid(String line, Set<String> hash,
|
||||||
|
String kind, Set<r8tor9> filehash) {
|
||||||
|
Iterator<String> it;
|
||||||
|
String r8thing;
|
||||||
|
String r9thing;
|
||||||
|
it = hash.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
r8thing = it.next();
|
||||||
|
if ((r9thing = MigrationTool.db.getR9Guidname(r8thing)) != null) {
|
||||||
|
if (!r8thing.equals(r9thing)) {
|
||||||
|
if (line.contains(r8thing)) {
|
||||||
|
line = line.replaceAll(r8thing, r9thing);
|
||||||
|
filehash.add(new r8tor9(r8thing, r9thing));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String dropPeiServicesPointer(String wholeline) {
|
||||||
|
String peiServicesTablePointer;
|
||||||
|
String peiServicesTableCaller;
|
||||||
|
String regPeiServices;
|
||||||
|
Pattern ptnPei;
|
||||||
|
Matcher mtrPei;
|
||||||
|
|
||||||
|
peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*";
|
||||||
|
peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer
|
||||||
|
+ ")\\s*\\)[.-]>?\\s*";
|
||||||
|
for (int i = 0; i < peiserviceslibfunc.length; i++) {
|
||||||
|
regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i]
|
||||||
|
+ "\\s*\\(\\s*\\1\\s*,(\\t| )*";
|
||||||
|
ptnPei = Pattern.compile(regPeiServices);
|
||||||
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
|
if (mtrPei.find()) {
|
||||||
|
wholeline = mtrPei.replaceAll("PeiServices"
|
||||||
|
+ peiserviceslibfunc[i] + " (");
|
||||||
|
mi.hashrequiredr9libs.add("PeiServicesLib");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)"
|
||||||
|
+ "\\s*\\((\\t| )*";
|
||||||
|
ptnPei = Pattern.compile(regPeiServices);
|
||||||
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
|
if (mtrPei.find()) {
|
||||||
|
wholeline = mtrPei.replaceAll("$2 (");
|
||||||
|
mi.hashrequiredr9libs.add("BaseMemoryLib");
|
||||||
|
}
|
||||||
|
|
||||||
|
ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer
|
||||||
|
+ "\\s*,\\s*", Pattern.MULTILINE);
|
||||||
|
mtrPei = ptnPei.matcher(wholeline);
|
||||||
|
while (mtrPei.find()) {
|
||||||
|
wholeline = mtrPei.replaceAll("$1");
|
||||||
|
}
|
||||||
|
|
||||||
|
return wholeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String drophobLibReturnStatus(String wholeline) { // or use
|
||||||
|
// regex to
|
||||||
|
// find
|
||||||
|
// pattern
|
||||||
|
// "Status =
|
||||||
|
// ..."
|
||||||
|
Pattern ptnhobstatus;
|
||||||
|
Matcher mtrhobstatus;
|
||||||
|
String templine = wholeline;
|
||||||
|
for (int i = 0; i < specialhoblibfunc.length; i++) {
|
||||||
|
do {
|
||||||
|
ptnhobstatus = Pattern.compile(
|
||||||
|
"((?:\t| )*)(\\w(?:\\w|\\d)*)\\s*=\\s*"
|
||||||
|
+ specialhoblibfunc[i] + "(.*?;)",
|
||||||
|
Pattern.DOTALL);
|
||||||
|
mtrhobstatus = ptnhobstatus.matcher(templine);
|
||||||
|
if (!mtrhobstatus.find()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String captureIndent = mtrhobstatus.group(1);
|
||||||
|
String captureStatus = mtrhobstatus.group(2);
|
||||||
|
String replaceString = captureIndent + specialhoblibfunc[i]
|
||||||
|
+ mtrhobstatus.group(3) + "\n";
|
||||||
|
replaceString += captureIndent
|
||||||
|
+ MigrationTool.MIGRATIONCOMMENT
|
||||||
|
+ "R9 Hob-building library functions will assert if build failure.\n";
|
||||||
|
replaceString += captureIndent + captureStatus
|
||||||
|
+ " = EFI_SUCCESS;";
|
||||||
|
templine = mtrhobstatus.replaceFirst(replaceString);
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
return templine;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String replaceMacro(String wholeline, Set<String> symbolSet) {
|
||||||
|
String r8thing;
|
||||||
|
String r9thing;
|
||||||
|
Iterator<String> it;
|
||||||
|
|
||||||
|
it = symbolSet.iterator();
|
||||||
|
while (it.hasNext()) { // macros are all assumed MdePkg currently
|
||||||
|
r8thing = it.next();
|
||||||
|
// mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing));
|
||||||
|
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {
|
||||||
|
if (wholeline.contains(r8thing)) {
|
||||||
|
String findString = "(?<!(?:\\d|\\w))" + r8thing
|
||||||
|
+ "(?!(?:\\d|\\w))";
|
||||||
|
wholeline = wholeline.replaceAll(findString, r9thing);
|
||||||
|
filemacro.add(new r8tor9(r8thing, r9thing));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wholeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String replaceLibrary(String wholeline, Set<String> symbolSet) {
|
||||||
|
boolean addr8 = false;
|
||||||
|
// start replacing names
|
||||||
|
String r8thing;
|
||||||
|
String r9thing;
|
||||||
|
Iterator<String> it;
|
||||||
|
// Converting non-locla function
|
||||||
|
it = symbolSet.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
r8thing = it.next();
|
||||||
|
mi.addLibraryClass(MigrationTool.db.getR9Lib(r8thing),
|
||||||
|
UsageTypes.ALWAYS_CONSUMED);
|
||||||
|
// mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); //
|
||||||
|
// add a library here
|
||||||
|
|
||||||
|
r8tor9 temp;
|
||||||
|
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {
|
||||||
|
if (!r8thing.equals(r9thing)) {
|
||||||
|
if (wholeline.contains(r8thing)) {
|
||||||
|
String findString = "(?<!(?:\\d|\\w))" + r8thing
|
||||||
|
+ "(?!(?:\\d|\\w))";
|
||||||
|
wholeline = wholeline.replaceAll(findString, r9thing);
|
||||||
|
filefunc.add(new r8tor9(r8thing, r9thing));
|
||||||
|
Iterator<r8tor9> rt = filefunc.iterator();
|
||||||
|
while (rt.hasNext()) {
|
||||||
|
temp = rt.next();
|
||||||
|
if (MigrationTool.db.r8only.contains(temp.r8thing)) {
|
||||||
|
filer8only.add(r8thing);
|
||||||
|
mi.hashr8only.add(r8thing);
|
||||||
|
addr8 = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // is any of the guids changed?
|
||||||
|
if (addr8 == true) {
|
||||||
|
wholeline = addincludefile(wholeline, "\"R8Lib.h\"");
|
||||||
|
}
|
||||||
|
return wholeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String replaceObsoleteMacro(String wholeline) {
|
||||||
|
Matcher mtrmac;
|
||||||
|
mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(
|
||||||
|
wholeline);
|
||||||
|
if (mtrmac.find()) {
|
||||||
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");
|
||||||
|
}
|
||||||
|
mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
|
if (mtrmac.find()) {
|
||||||
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");
|
||||||
|
}
|
||||||
|
mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);
|
||||||
|
if (mtrmac.find()) {
|
||||||
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");
|
||||||
|
}
|
||||||
|
mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(
|
||||||
|
wholeline);
|
||||||
|
if (mtrmac.find()) {
|
||||||
|
wholeline = mtrmac
|
||||||
|
.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");
|
||||||
|
}
|
||||||
|
if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {
|
||||||
|
wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK",
|
||||||
|
"(sizeof (UINTN) - 1)");
|
||||||
|
}
|
||||||
|
return wholeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void addr8only() throws Exception {
|
||||||
|
String paragraph = null;
|
||||||
|
String line = Common.file2string(MigrationTool.db.DatabasePath
|
||||||
|
+ File.separator + "R8Lib.c");
|
||||||
|
PrintWriter outfile1 = new PrintWriter(new BufferedWriter(
|
||||||
|
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 mtrr8onlyhead;
|
||||||
|
|
||||||
|
// add head comment
|
||||||
|
Matcher mtrr8onlyheadcomment = Critic.PTN_NEW_HEAD_COMMENT
|
||||||
|
.matcher(line);
|
||||||
|
if (mtrr8onlyheadcomment.find()) {
|
||||||
|
outfile1.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
|
outfile2.append(mtrr8onlyheadcomment.group() + "\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// add functions body
|
||||||
|
while (mtrr8only.find()) {
|
||||||
|
if (mi.hashr8only.contains(mtrr8only.group(3))) {
|
||||||
|
paragraph = mtrr8only.group(2);
|
||||||
|
outfile1.append(paragraph + "\n\n");
|
||||||
|
if (mtrr8only.group(1).length() != 0) {
|
||||||
|
mi.hashrequiredr9libs.add(mtrr8only.group(1));
|
||||||
|
}
|
||||||
|
// generate R8lib.h
|
||||||
|
while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph))
|
||||||
|
.find()) {
|
||||||
|
paragraph = mtrr8onlyhead.replaceAll(";");
|
||||||
|
}
|
||||||
|
outfile2.append(paragraph + "\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outfile1.flush();
|
||||||
|
outfile1.close();
|
||||||
|
outfile2.flush();
|
||||||
|
outfile2.close();
|
||||||
|
|
||||||
|
mi.localmodulesources.add("R8Lib.h");
|
||||||
|
mi.localmodulesources.add("R8Lib.c");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------process
|
||||||
|
// functions-------------------------------------//
|
||||||
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
public void run(String filepath) throws Exception {
|
||||||
|
String inname = filepath.replace(mi.temppath + File.separator, "");
|
||||||
|
String tempinpath = mi.temppath + File.separator;
|
||||||
|
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi)
|
||||||
|
+ File.separator + "Migration_" + mi.modulename
|
||||||
|
+ File.separator;
|
||||||
|
|
||||||
|
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
||||||
|
while (itLaplace.hasNext()) {
|
||||||
|
Common.Laplace lap = itLaplace.next();
|
||||||
|
if (lap.recognize(inname)) {
|
||||||
|
MigrationTool.ui.println("\nHandling file: " + inname);
|
||||||
|
lap.transform(tempinpath + inname, tempoutpath
|
||||||
|
+ lap.namechange(inname));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean filter(File dir) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------ForDoAll-----------------------------------//
|
||||||
|
|
||||||
|
private final void setModuleInfo(ModuleInfo moduleinfo) {
|
||||||
|
mi = moduleinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void start() throws Exception {
|
||||||
|
Laplaces.add(new DxsLaplace());
|
||||||
|
Laplaces.add(new CLaplace());
|
||||||
|
Laplaces.add(new IdleLaplace());
|
||||||
|
|
||||||
|
Common.toDoAll(mi.temppath, this, Common.FILE);
|
||||||
|
|
||||||
|
if (!mi.hashr8only.isEmpty()) {
|
||||||
|
addr8only();
|
||||||
|
}
|
||||||
|
|
||||||
|
Laplaces.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
||||||
|
SFReplacer.setModuleInfo(moduleinfo);
|
||||||
|
SFReplacer.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,21 +12,21 @@
|
|||||||
**/
|
**/
|
||||||
package org.tianocore.migration;
|
package org.tianocore.migration;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface UI {
|
public interface UI {
|
||||||
|
|
||||||
public boolean yesOrNo(String question);
|
public boolean yesOrNo(String question);
|
||||||
|
|
||||||
public void print(String message);
|
public void print(String message);
|
||||||
|
|
||||||
public void println(String message);
|
public void println(String message);
|
||||||
|
|
||||||
public void println(Set<String> hash);
|
public void println(Set<String> hash);
|
||||||
|
|
||||||
public String choose(String message, Object[] choicelist);
|
public String choose(String message, Object[] choicelist);
|
||||||
|
|
||||||
public String getInput(String message);
|
public String getInput(String message);
|
||||||
|
|
||||||
public String getFilepath(String title, int mode); // necessary ?
|
public String getFilepath(String title, int mode); // necessary ?
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user