mirror of https://github.com/acidanthera/audk.git
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:
parent
adb6105a5a
commit
2887f99b7c
|
@ -178,10 +178,18 @@ public final class Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class Laplace {
|
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);
|
Common.string2file(operation(Common.file2string(src)), des);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public abstract String operation(String wholeline);
|
public abstract String operation(String wholeline);
|
||||||
|
|
||||||
|
public abstract boolean recognize(String filename);
|
||||||
|
|
||||||
|
public abstract String namechange(String oldname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,7 @@ import java.util.regex.Pattern;
|
||||||
public final class SourceFileReplacer implements Common.ForDoAll {
|
public final class SourceFileReplacer implements Common.ForDoAll {
|
||||||
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
private static final SourceFileReplacer SFReplacer = new SourceFileReplacer();
|
||||||
private ModuleInfo mi;
|
private ModuleInfo mi;
|
||||||
//private static boolean showdetails = true; // set this as default now, may be changed in the future
|
private static final Set<Common.Laplace> Laplaces = new HashSet<Common.Laplace>();
|
||||||
|
|
||||||
private static class r8tor9 {
|
|
||||||
r8tor9(String r8, String r9) {
|
|
||||||
r8thing = r8;
|
|
||||||
r9thing = r9;
|
|
||||||
}
|
|
||||||
public String r8thing;
|
|
||||||
public String r9thing;
|
|
||||||
}
|
|
||||||
|
|
||||||
// these sets are used only for printing log of the changes in current file
|
// these sets are used only for printing log of the changes in current file
|
||||||
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
private static final Set<r8tor9> filefunc = new HashSet<r8tor9>();
|
||||||
|
@ -39,8 +30,53 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
||||||
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
private static final Set<r8tor9> fileprotocol = new HashSet<r8tor9>();
|
||||||
private static final Set<String> filer8only = new HashSet<String>();
|
private static final Set<String> filer8only = new HashSet<String>();
|
||||||
|
|
||||||
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!
|
//---------------------------------------inner classes---------------------------------------//
|
||||||
private final String sourcefilereplace(String wholeline) throws Exception {
|
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;
|
boolean addr8 = false;
|
||||||
|
|
||||||
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !
|
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;
|
return wholeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String addincludefile(String wholeline, String hfile) {
|
public boolean recognize(String filename) {
|
||||||
return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");
|
return filename.contains(".c") || filename.contains(".C");
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String convertdxs(String wholeline) {
|
public String namechange(String oldname) {
|
||||||
if (mi.getModuleType().equals("PEIM")) {
|
if (oldname.contains(".C")) {
|
||||||
return addincludefile(wholeline, "\\<PeimDepex.h\\>");
|
return oldname.replaceFirst(".C", ".c");
|
||||||
} else {
|
} 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) {
|
private static final void show(Set<r8tor9> hash, String sh) {
|
||||||
Iterator<r8tor9> it = hash.iterator();
|
Iterator<r8tor9> it = hash.iterator();
|
||||||
|
@ -267,31 +309,17 @@ public final class SourceFileReplacer implements Common.ForDoAll {
|
||||||
|
|
||||||
//-----------------------------------ForDoAll-----------------------------------//
|
//-----------------------------------ForDoAll-----------------------------------//
|
||||||
public void run(String filepath) throws Exception {
|
public void run(String filepath) throws Exception {
|
||||||
String outname = null;
|
|
||||||
String inname = filepath.replace(mi.modulepath + File.separator, "");
|
String inname = filepath.replace(mi.modulepath + File.separator, "");
|
||||||
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
|
String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;
|
||||||
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;
|
||||||
|
|
||||||
if (inname.contains(".c") || inname.contains(".C")) {
|
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();
|
||||||
if (inname.contains(".C")) {
|
while (itLaplace.hasNext()) {
|
||||||
outname = inname.replaceFirst(".C", ".c");
|
Common.Laplace lap = itLaplace.next();
|
||||||
} else {
|
if (lap.recognize(inname)) {
|
||||||
outname = 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 {
|
private final void start() throws Exception {
|
||||||
|
Laplaces.add(new DxsLaplace());
|
||||||
|
Laplaces.add(new CLaplace());
|
||||||
|
Laplaces.add(new IdleLaplace());
|
||||||
|
|
||||||
Common.toDoAll(mi.localmodulesources, this);
|
Common.toDoAll(mi.localmodulesources, this);
|
||||||
|
|
||||||
if (!mi.hashr8only.isEmpty()) {
|
if (!mi.hashr8only.isEmpty()) {
|
||||||
addr8only();
|
addr8only();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laplaces.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
public static final void fireAt(ModuleInfo moduleinfo) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue