Laplace take over SourceFileReplacer.java

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1472 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
alfred 2006-09-06 04:39:31 +00:00
parent adb6105a5a
commit 2887f99b7c
2 changed files with 209 additions and 167 deletions

View File

@ -178,10 +178,18 @@ public final class Common {
}
public static abstract class Laplace {
public final void transform(String src, String des) throws Exception {
public void transform(String src, String des) throws Exception {
Common.string2file(operation(Common.file2string(src)), des);
}
public void run() {
}
public abstract String operation(String wholeline);
public abstract boolean recognize(String filename);
public abstract String namechange(String oldname);
}
}

View File

@ -20,16 +20,7 @@ import java.util.regex.Pattern;
public final class SourceFileReplacer implements Common.ForDoAll {
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
private ModuleInfo mi;
//private static boolean showdetails = true; // set this as default now, may be changed in the future
private static class r8tor9 {
r8tor9(String r8, String r9) {
r8thing = r8;
r9thing = r9;
}
public String r8thing;
public String r9thing;
}
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 static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
@ -39,8 +30,53 @@ public final class SourceFileReplacer implements Common.ForDoAll {
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
private static final Set<String> filer8only = new HashSet<String>();
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!
private final String sourcefilereplace(String wholeline) throws Exception {
//---------------------------------------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 wholeline;
}
public boolean recognize(String filename) {
return filename.contains(".h") || filename.contains(".H") || filename.contains(".uni");
}
public String namechange(String oldname) {
if (oldname.contains(".H")) {
return oldname.replaceFirst(".H", ".h");
} else {
return oldname;
}
}
}
private class DxsLaplace extends Common.Laplace {
public String operation(String wholeline) {
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) {
return oldname;
}
}
private class CLaplace extends Common.Laplace {
public String operation(String wholeline) {
boolean addr8 = false;
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !
@ -191,17 +227,23 @@ public final class SourceFileReplacer implements Common.ForDoAll {
return wholeline;
}
private static final String addincludefile(String wholeline, String hfile) {
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
public boolean recognize(String filename) {
return filename.contains(".c") || filename.contains(".C");
}
private final String convertdxs(String wholeline) {
if (mi.getModuleType().equals("PEIM")) {
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
public String namechange(String oldname) {
if (oldname.contains(".C")) {
return oldname.replaceFirst(".C", ".c");
} else {
return addincludefile(wholeline, "\\<DxeDepex.h\\>");
return oldname;
}
}
}
//---------------------------------------inner classes---------------------------------------//
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();
@ -267,31 +309,17 @@ public final class SourceFileReplacer implements Common.ForDoAll {
//-----------------------------------ForDoAll-----------------------------------//
public void run(String filepath) throws Exception {
String outname = null;
String inname = filepath.replace(mi.modulepath + File.separator, "");
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
if (inname.contains(".c") || inname.contains(".C")) {
if (inname.contains(".C")) {
outname = inname.replaceFirst(".C", ".c");
} else {
outname = inname;
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));
}
MigrationTool.ui.println("\nModifying file: " + inname);
Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);
} else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {
if (inname.contains(".H")) {
outname = inname.replaceFirst(".H", ".h");
} else {
outname = inname;
}
MigrationTool.ui.println("\nCopying file: " + inname);
Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);
} else if (inname.contains(".dxs")) {
outname = inname;
MigrationTool.ui.println("\nModifying file: " + inname);
Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);
}
}
@ -305,11 +333,17 @@ public final class SourceFileReplacer implements Common.ForDoAll {
}
private final void start() throws Exception {
Laplaces.add(new DxsLaplace());
Laplaces.add(new CLaplace());
Laplaces.add(new IdleLaplace());
Common.toDoAll(mi.localmodulesources, this);
if (!mi.hashr8only.isEmpty()) {
addr8only();
}
Laplaces.clear();
}
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {