Issue #842 For reconstruction if debug line info present

Spaces added between parts of for
This commit is contained in:
Jindra Petřík
2015-04-26 08:21:50 +02:00
parent fdda766be5
commit af31f85c49
12 changed files with 205 additions and 39 deletions
@@ -461,6 +461,64 @@ public class Graph {
}
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
//For detection based on debug line information
Set<Integer> removeFromList = new HashSet<>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof ForItem) {
ForItem fori = (ForItem) list.get(i);
int exprLine = fori.getLine();
if (exprLine > 0) {
List<GraphTargetItem> forFirstCommands = new ArrayList<>();
for (int j = i - 1; j >= 0; j--) {
if (list.get(j).getLine() == exprLine) {
forFirstCommands.add(0, list.get(j));
removeFromList.add(j);
} else {
break;
}
}
fori.firstCommands.addAll(0, forFirstCommands);
}
}
if (list.get(i) instanceof WhileItem) {
WhileItem whi = (WhileItem) list.get(i);
int whileExprLine = whi.getLine();
if (whileExprLine > 0) {
List<GraphTargetItem> forFirstCommands = new ArrayList<>();
List<GraphTargetItem> forFinalCommands = new ArrayList<>();
for (int j = i - 1; j >= 0; j--) {
if (list.get(j).getLine() == whileExprLine) {
forFirstCommands.add(0, list.get(j));
removeFromList.add(j);
} else {
break;
}
}
for (int j = whi.commands.size() - 1; j >= 0; j--) {
if (whi.commands.get(j).getLine() == whileExprLine) {
forFinalCommands.add(0, whi.commands.remove(j));
} else {
break;
}
}
if (!forFirstCommands.isEmpty() || !forFinalCommands.isEmpty()) {
GraphTargetItem lastExpr = whi.expression.remove(whi.expression.size() - 1);
forFirstCommands.addAll(whi.expression);
list.set(i, new ForItem(whi.src, whi.loop, forFirstCommands, lastExpr, forFinalCommands, whi.commands));
}
}
}
}
for (int i = list.size() - 1; i >= 0; i--) {
if (removeFromList.contains(i)) {
list.remove(i);
}
}
}
private void processIfs(List<GraphTargetItem> list) {
@@ -1752,9 +1810,9 @@ public class Graph {
checkContinueAtTheEnd(finalComm, currentLoop);
}
if (!finalComm.isEmpty()) {
ret.add(index, li = new ForItem(null, currentLoop, new ArrayList<GraphTargetItem>(), exprList.get(exprList.size() - 1), finalComm, commands));
ret.add(index, li = new ForItem(expr.src, currentLoop, new ArrayList<GraphTargetItem>(), exprList.get(exprList.size() - 1), finalComm, commands));
} else {
ret.add(index, li = new WhileItem(null, currentLoop, exprList, commands));
ret.add(index, li = new WhileItem(expr.src, currentLoop, exprList, commands));
}
loopTypeFound = true;
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.BaseLocalData;
@@ -44,4 +45,8 @@ public interface GraphSourceItem extends Serializable {
public void setIgnored(boolean ignored, int pos);
public boolean isDeobfuscatePop();
public int getLine();
public String getFile();
}
@@ -83,6 +83,20 @@ public abstract class GraphTargetItem implements Serializable {
protected HighlightData srcData = new HighlightData();
public int getLine() {
if (src != null) {
return src.getLine();
}
return 0;
}
public String getFile() {
if (src != null) {
return src.getFile();
}
return null;
}
public GraphPart getFirstPart() {
if (value == null) {
return firstPart;
@@ -90,9 +90,9 @@ public class ForItem extends LoopItem implements Block {
firstCommands.get(i).toString(writer, localData);
p++;
}
writer.append(";");
writer.append("; ");
expression.toString(writer, localData);
writer.append(";");
writer.append("; ");
p = 0;
for (int i = 0; i < finalCommands.size(); i++) {
if (finalCommands.get(i).isEmpty()) {