Propagated bytecode-to-source tracer

This commit is contained in:
Stiver
2014-10-06 04:27:26 +02:00
parent 0c8508ff8a
commit 9723ab4475
21 changed files with 142 additions and 37 deletions

View File

@@ -331,6 +331,7 @@ public class ExprProcessor implements CodeConstants {
for (int i = 0; i < seq.length(); i++) {
Instruction instr = seq.getInstr(i);
Integer bytecode_offset = block.getOldOffset(i);
switch (instr.opcode) {
case opc_aconst_null:

View File

@@ -96,6 +96,8 @@ public class ArrayExprent extends Exprent {
res = "((" + ExprProcessor.getCastTypeName(objarr) + ")" + res + ")";
}
tracer.addMapping(bytecode);
return res + "[" + index.toJava(indent, tracer) + "]";
}

View File

@@ -38,12 +38,15 @@ public class AssertExprent extends Exprent {
buffer.append("assert ");
tracer.addMapping(bytecode);
if (parameters.get(0) == null) {
buffer.append("false");
}
else {
buffer.append(parameters.get(0).toJava(indent, tracer));
}
if (parameters.size() > 1) {
buffer.append(" : ");
buffer.append(parameters.get(1).toJava(indent, tracer));

View File

@@ -153,6 +153,8 @@ public class AssignmentExprent extends Exprent {
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
tracer.addMapping(bytecode);
return buffer.toString();
}

View File

@@ -112,6 +112,8 @@ public class ConstExprent extends Exprent {
boolean literal = DecompilerContext.getOption(IFernflowerPreferences.LITERALS_AS_IS);
boolean ascii = DecompilerContext.getOption(IFernflowerPreferences.ASCII_STRING_CHARACTERS);
tracer.addMapping(bytecode);
if (consttype.type != CodeConstants.TYPE_NULL && value == null) {
return ExprProcessor.getCastTypeName(consttype);
}

View File

@@ -77,6 +77,9 @@ public class ExitExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
if (exittype == EXIT_RETURN) {
StringBuilder buffer = new StringBuilder();

View File

@@ -54,6 +54,9 @@ public class Exprent {
public int id;
//offsets of bytecode instructions decompiled to this exprent
public Set<Integer> bytecode = new HashSet<Integer>();
{
// set exprent id
id = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.EXPRENT_COUNTER);

View File

@@ -159,6 +159,8 @@ public class FieldExprent extends Exprent {
buf.append(name);
tracer.addMapping(bytecode);
return buf.toString();
}

View File

@@ -450,6 +450,8 @@ public class FunctionExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
if (functype <= FUNCTION_USHR) {
return wrapOperandString(lstOperands.get(0), false, indent, tracer) + operators[functype] +
wrapOperandString(lstOperands.get(1), true, indent, tracer);

View File

@@ -114,6 +114,7 @@ public class IfExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
return "if(" + condition.toJava(indent, tracer) + ")";
}

View File

@@ -194,6 +194,8 @@ public class InvocationExprent extends Exprent {
String super_qualifier = null;
boolean isInstanceThis = false;
tracer.addMapping(bytecode);
if (invocationTyp == INVOKE_DYNAMIC) {
// ClassNode node = (ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASSNODE);
//

View File

@@ -52,6 +52,9 @@ public class MonitorExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
if (montype == MONITOR_ENTER) {
return "synchronized(" + value.toJava(indent, tracer) + ")";
}

View File

@@ -84,6 +84,7 @@ public class SwitchExprent extends Exprent {
@Override
public String toJava(int indent, BytecodeMappingTracer tracer) {
tracer.addMapping(bytecode);
return "switch(" + value.toJava(indent, tracer) + ")";
}

View File

@@ -85,6 +85,8 @@ public class VarExprent extends Exprent {
public String toJava(int indent, BytecodeMappingTracer tracer) {
StringBuilder buffer = new StringBuilder();
tracer.addMapping(bytecode);
if (classdef) {
ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(vartype.value);
new ClassWriter().classToJava(child, buffer, indent);

View File

@@ -489,9 +489,9 @@ public class Statement {
}
// to be overwritten
//public String toJava() {
// return toJava(0);
//}
public String toJava() {
return toJava(0, new BytecodeMappingTracer());
}
public String toJava(int indent, BytecodeMappingTracer tracer) {
throw new RuntimeException("not implemented");