small fixes

This commit is contained in:
Honfika
2013-10-16 23:11:01 +02:00
parent d73f2bf3ac
commit 908e73e0b3
10 changed files with 20 additions and 52 deletions

View File

@@ -670,16 +670,14 @@ public class SWF {
public Void call() throws Exception {
for (MyEntry<ClassPath, ScriptPack> item : packs) {
ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, exportMode, parallel);
try {
ret.add(task.call());
} catch (Exception ex) {
Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during ABC export", ex);
}
ret.add(task.call());
}
return null;
}
}, Configuration.DECOMPILATION_TIMEOUT, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
} catch (ExecutionException ex) {
Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "Error during ABC export", ex);
} catch (InterruptedException | TimeoutException ex) {
Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, Helper.formatTimeToText(Configuration.DECOMPILATION_TIMEOUT) + " ActionScript export limit reached", ex);
}
} else {

View File

@@ -744,35 +744,6 @@ public class ABC {
}
return ret;
}
/*public List<File> export(String directory, ExportMode exportMode, List<ABCContainerTag> abcList, String abcStr, boolean parallel) throws IOException {
ExecutorService executor = Executors.newFixedThreadPool(20);
List<Future<File>> futureResults = new ArrayList<>();
AtomicInteger cnt = new AtomicInteger(1);
for (int i = 0; i < script_info.length; i++) {
HashMap<ClassPath, ScriptPack> packs = script_info[i].getPacks(this, i);
for (Entry<ClassPath, ScriptPack> entry : packs.entrySet()) {
Future<File> future = executor.submit(new ExportPackTask(cnt, script_info.length, entry.getKey(), entry.getValue(), directory, abcList, pcode, abcStr, parallel));
futureResults.add(future);
}
}
List<File> ret = new ArrayList<>();
for (int f = 0; f < futureResults.size(); f++) {
try {
ret.add(futureResults.get(f).get());
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during ABC export", ex);
}
}
try {
executor.shutdown();
executor.awaitTermination(30, TimeUnit.MINUTES);
} catch (InterruptedException ex) {
Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "30 minutes ActionScript export limit reached", ex);
}
return ret;
}*/
public void dump(OutputStream os) {
PrintStream output;

View File

@@ -127,7 +127,7 @@ public class ScriptPack {
} else {
abc.script_info[scriptIndex].traits.traits[t].convert(null, "", abcList, abc, false, exportMode, scriptIndex, -1, writer, new ArrayList<String>(), parallel);
}
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString());
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), false);
s = Helper.hexToComments(s);
fos.write(s.getBytes("utf-8"));
}

View File

@@ -114,7 +114,7 @@ public class MethodBody implements Cloneable, Serializable {
HilightedTextWriter writer = new HilightedTextWriter(false);
toString(path, exportMode, isStatic, scriptIndex, classIndex, abc, trait, constants, method_info, scopeStack, isStaticInitializer, writer, fullyQualifiedNames, initTraits);
String src = writer.toString();
src = Graph.removeNonRefenrencedLoopLabels(src);
src = Graph.removeNonRefenrencedLoopLabels(src, false);
return src;
}

View File

@@ -176,8 +176,8 @@ public abstract class Trait implements Serializable {
try (FileOutputStream fos = new FileOutputStream(fileName)) {
HilightedTextWriter writer = new HilightedTextWriter(false);
convertPackaged(parent, "", abcList, abc, isStatic, exportMode, scriptIndex, classIndex, writer, new ArrayList<String>(), parallel);
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString());
fos.write(s.getBytes());
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), false);
fos.write(s.getBytes("utf-8"));
}
}
}

View File

@@ -73,7 +73,7 @@ public class Traits implements Serializable {
return s;
}
private class TraitConvertTask implements Callable<String> {
private class TraitConvertTask implements Callable<HilightedTextWriter> {
Trait trait;
boolean makePackages;
@@ -108,7 +108,7 @@ public class Traits implements Serializable {
}
@Override
public String call() {
public HilightedTextWriter call() {
int h = traitIndex;
if (classIndex != -1) {
if (!isStatic) {
@@ -130,7 +130,7 @@ public class Traits implements Serializable {
} else {
writer.endTrait();
}
return writer.toString();
return writer;
}
}
@@ -146,13 +146,13 @@ public class Traits implements Serializable {
}
} else {
ExecutorService executor = Executors.newFixedThreadPool(20);
List<Future<String>> futureResults = null;
List<Future<HilightedTextWriter>> futureResults = null;
futureResults = new ArrayList<>();
for (int t = 0; t < traits.length; t++) {
HilightedTextWriter writer2 = new HilightedTextWriter(writer.getIsHighlighted(), writer.getIndent());
TraitConvertTask task = new TraitConvertTask(traits[t], parent, makePackages, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer2, fullyQualifiedNames, t, parallel);
Future<String> future = executor.submit(task);
Future<HilightedTextWriter> future = executor.submit(task);
futureResults.add(future);
}
@@ -161,8 +161,8 @@ public class Traits implements Serializable {
writer.newLine();
}
try {
String taskResult = futureResults.get(f).get();
writer.appendWithoutIndent(taskResult);
HilightedTextWriter taskResult = futureResults.get(f).get();
writer.appendWithoutIndent(taskResult.toString());
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during traits converting", ex);
}

View File

@@ -723,7 +723,7 @@ public class Action implements GraphSourceItem {
public static String actionsToSource(List<Action> actions, int version, String path, boolean highlight, int indent) {
HilightedTextWriter writer = new HilightedTextWriter(highlight, indent);
Action.actionsToSource(actions, SWF.DEFAULT_VERSION, ""/*FIXME*/, writer);
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString());
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), highlight);
return s;
}

View File

@@ -47,7 +47,6 @@ public class WithActionItem extends ActionItem {
@Override
protected HilightedTextWriter appendTo(HilightedTextWriter writer, LocalData localData) {
String ret;
writer.append("with(");
scope.toString(writer, localData);
writer.append(")").newLine();

View File

@@ -456,7 +456,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
for (int scriptTraitIndex : scriptLeaf.traitIndices) {
script.traits.traits[scriptTraitIndex].convertPackaged(null, scriptLeaf.getPath().toString(), abcList, abc, false, ExportMode.SOURCE, scriptIndex, -1, writer, new ArrayList<String>(), Configuration.getConfig("parallelSpeedUp", true));
}
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString());
String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), true);
hilightedCode = s;
cache.put(scriptLeaf, new CachedDecompilation(hilightedCode));
}

View File

@@ -2156,17 +2156,17 @@ public class Graph {
return writer;
}
public static String removeNonRefenrencedLoopLabels(String source) {
public static String removeNonRefenrencedLoopLabels(String source, boolean hilighted) {
String[] parts = source.split("\r\n");
String labelPattern = "loop(switch)?[0-9]*:";
StringBuilder ret = new StringBuilder();
for (int p = 0; p < parts.length; p++) {
String strippedP = Highlighting.stripHilights(parts[p]).trim();
String strippedP = (hilighted ? Highlighting.stripHilights(parts[p]) : parts[p]).trim();
if (strippedP.matches(labelPattern)) {//endsWith(":") && (!strippedP.startsWith("case ")) && (!strippedP.equals("default:"))) {
String loopname = strippedP.substring(0, strippedP.length() - 1);
boolean dorefer = false;
for (int q = p + 1; q < parts.length; q++) {
String strippedQ = Highlighting.stripHilights(parts[q]).trim();
String strippedQ = (hilighted ? Highlighting.stripHilights(parts[q]) : parts[q]).trim();
if (strippedQ.equals("break " + loopname.replace("switch", "") + ";")) {
dorefer = true;
break;