Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dumping of locals #20

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
sourceCompatibility = 1.8
targetCompatibility = 1.8

version = '0.2.2'
version = '0.3.0-SNAPSHOT'

def ENV = System.getenv()
version = version + (ENV.GITHUB_ACTIONS ? "" : "+local")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ public Dumper dumpInner(Dumper d) {
d.separator("(");
}
List<String> args = ListFactory.newList(n);
for (int x = 0; x < n; ++x) {
if (x > 0) d.separator(", ");
String arg = "arg_" + x;
for (int argPosition = 0; argPosition < n; ++argPosition) {
if (argPosition > 0) d.separator(", ");
String arg = "arg_" + argPosition;
args.add(arg);
d.parameterName(arg, arg, lambdaFn, x, true);
d.parameterName(arg, arg, lambdaFn, argPosition, lambdaFn.getParameterLValues().get(argPosition).localVariable.getIdx(), true);
}
if (multi) {
d.separator(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

public class LambdaParameter extends LocalVariable {
public final MethodPrototype originalMethod;
public final int index; // index in method params, not slot
public final int argPosition; // index in method params, not slot

public LambdaParameter(String name, InferredJavaType inferredJavaType, MethodPrototype originalMethod, int index) {
super(name, inferredJavaType);
this.index = index;
this.argPosition = index;
this.originalMethod = originalMethod;
}

@Override
public Dumper dump(Dumper d, boolean defines) {
getName().dumpParameter(d, originalMethod, index, defines);
getName().dumpParameter(d, originalMethod, argPosition, originalMethod.getParameterLValues().get(argPosition).localVariable.getIdx(), defines);
return d;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ public Precedence getPrecedence() {

@Override
public Dumper dump(Dumper d, boolean defines) {
return name.dump(d, defines); // todo pass lv, lvt, start offset
if (ident != null && originalRawOffset != ident.getStackPos()) {
int i = 0;
}

return name.dumpLocalVariable(d, idx, -1, originalRawOffset, defines);
}

@Override
public Dumper dumpInner(Dumper d) {
name.dump(d);
name.dumpLocalVariable(d, idx, -1, originalRawOffset, false);
// Note that this print is only decorating when we have bad data.
d.print(typeToString());
return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Dumper dump(Dumper d, boolean defines) {
}

@Override
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int index, boolean defines) {
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int argPosition, int lvIndex, boolean defines) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void dumpDeclarationSignature(Dumper d, String methName, Method.MethodCon
annotationsHelper.dumpParamType(arg, paramIdx, d);
}
d.print(" ");
param.getName().dumpParameter(d, this, paramIdx, true);
param.getName().dumpParameter(d, this, paramIdx, getParameterLValues().get(paramIdx).localVariable.getIdx(), true);
}
d.separator(")");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public boolean equals(Object o) {
return true;
}

public int getStackPos() {
return stackpos;
}

public int getIdx() {
return idx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public interface NamedVariable extends Dumpable {
Dumper dump(Dumper d, boolean defines);

// fabric start
default Dumper dumpParameter(Dumper d, MethodPrototype prototype, int index, boolean defines) {
default Dumper dumpParameter(Dumper d, MethodPrototype prototype, int argPosition, int lvIndex, boolean defines) {
return dump(d, defines);
}

// start offset measured in instructions, not bytes
default Dumper dumpLocalVariable(Dumper d, int localVarIndex, Ident ident, int tableIndex, int startOffset, boolean defines) {
default Dumper dumpLocalVariable(Dumper d, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
return dump(d, defines);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ public Dumper dump(Dumper d) {

@Override
public Dumper dump(Dumper d, boolean defines) {
return d.variableName(name, this, defines);
return d.variableName(name, -1, -1, -1, defines);
}

@Override
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int index, boolean defines) {
return d.parameterName(name, this, methodPrototype, index, defines);
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int argPosition, int lvIndex, boolean defines) {
return d.parameterName(name, this, methodPrototype, argPosition, lvIndex, defines);
}

@Override
public Dumper dumpLocalVariable(Dumper d, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
return d.variableName(name, lvIndex, lvtRowIndex, startOpIndex, defines);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public Dumper dump(Dumper d) {

@Override
public Dumper dump(Dumper d, boolean defines) {
return d.variableName(name, this, defines);
return d.variableName(name, slot, -1, -1, defines);
}

@Override
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int index, boolean defines) {
return d.parameterName(name, this, methodPrototype, index, defines);
public Dumper dumpParameter(Dumper d, MethodPrototype methodPrototype, int argPosition, int lvIndex, boolean defines) {
return d.parameterName(name, this, methodPrototype, argPosition, lvIndex, defines);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public NamedVariable getName(int originalRawOffset, Ident ident, long stackPosit
// if used in a legit location, however we should also track if this
// is an instance method.
if (name.equals(MiscConstants.THIS) && ident.getIdx() == 0) {
namedVariable = new NamedVariableFromHint(name, 0, -1);
namedVariable.forceName(MiscConstants.THIS);
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/org/benf/cfr/reader/state/TypeUsageCollectingDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.types.TypeConstants;
import org.benf.cfr.reader.bytecode.analysis.variables.Ident;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.ClassFile;
import org.benf.cfr.reader.entities.Field;
Expand Down Expand Up @@ -108,12 +109,12 @@ public Dumper methodName(String name, MethodPrototype method, boolean special, b
}

@Override
public Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines) {
public Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines) {
return this;
}

@Override
public Dumper variableName(String name, NamedVariable variable, boolean defines) {
public Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
return this;
}

Expand Down
9 changes: 5 additions & 4 deletions src/org/benf/cfr/reader/util/output/DelegatingDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.variables.Ident;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.Field;
import org.benf.cfr.reader.entities.Method;
Expand Down Expand Up @@ -95,14 +96,14 @@ public Dumper methodName(String name, MethodPrototype method, boolean special, b
}

@Override
public Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines) {
delegate.parameterName(name, ref, method, index, defines);
public Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines) {
delegate.parameterName(name, ref, method, argPosition, lvIndex, defines);
return this;
}

@Override
public Dumper variableName(String name, NamedVariable variable, boolean defines) {
delegate.variableName(name, variable, defines);
public Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
delegate.variableName(name, lvIndex, lvtRowIndex, startOpIndex, defines);
return this;
}

Expand Down
7 changes: 3 additions & 4 deletions src/org/benf/cfr/reader/util/output/Dumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.variables.Ident;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.Field;
import org.benf.cfr.reader.entities.Method;
Expand Down Expand Up @@ -52,12 +53,10 @@ public interface Dumper extends MethodErrorCollector {

Dumper methodName(String name, MethodPrototype method, boolean special, boolean defines);

Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines);

@Deprecated // todo add lv, lvt indices and start offset
Dumper variableName(String name, NamedVariable variable, boolean defines);
Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines);

// fabric
Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines);
default Dumper dumpClassDoc(JavaTypeInstance owner) { return this; }
default Dumper dumpMethodDoc(MethodPrototype method) { return this; }
default Dumper dumpFieldDoc(Field field, JavaTypeInstance owner) { return this; }
Expand Down
7 changes: 4 additions & 3 deletions src/org/benf/cfr/reader/util/output/StreamDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.variables.Ident;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.Field;
import org.benf.cfr.reader.mapping.NullMapping;
Expand Down Expand Up @@ -88,14 +89,14 @@ public Dumper methodName(String name, MethodPrototype method, boolean special, b
}

@Override
public Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines) {
public Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines) {
identifier(name, ref, defines);
return this;
}

@Override
public Dumper variableName(String name, NamedVariable variable, boolean defines) {
identifier(name, variable, defines);
public Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
identifier(name, null, defines);
return this;
}

Expand Down
7 changes: 4 additions & 3 deletions src/org/benf/cfr/reader/util/output/ToStringDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.variables.Ident;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.Field;
import org.benf.cfr.reader.entities.Method;
Expand Down Expand Up @@ -64,13 +65,13 @@ public Dumper methodName(String name, MethodPrototype method, boolean special, b
}

@Override
public Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines) {
public Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines) {
return identifier(name, ref, defines);
}

@Override
public Dumper variableName(String name, NamedVariable variable, boolean defines) {
return identifier(name, variable, defines);
public Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
return identifier(name, null, defines);
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions src/org/benf/cfr/reader/util/output/TokenStreamDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import org.benf.cfr.reader.api.OutputSinkFactory;
import org.benf.cfr.reader.api.SinkReturns;
import org.benf.cfr.reader.bytecode.analysis.loc.HasByteCodeLoc;
import org.benf.cfr.reader.bytecode.analysis.types.JavaRefTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.JavaTypeInstance;
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype;
import org.benf.cfr.reader.bytecode.analysis.variables.NamedVariable;
import org.benf.cfr.reader.entities.Field;
import org.benf.cfr.reader.entities.Method;
import org.benf.cfr.reader.mapping.NullMapping;
import org.benf.cfr.reader.mapping.ObfuscationMapping;
Expand Down Expand Up @@ -287,12 +284,12 @@ public Dumper methodName(String s, MethodPrototype method, boolean special, bool
}

@Override
public Dumper parameterName(String name, Object ref, MethodPrototype method, int index, boolean defines) {
public Dumper parameterName(String name, Object ref, MethodPrototype method, int argPosition, int lvIndex, boolean defines) {
return identifier(name, ref, defines);
}

@Override
public Dumper variableName(String name, NamedVariable variable, boolean defines) {
public Dumper variableName(String name, int lvIndex, int lvtRowIndex, int startOpIndex, boolean defines) {
return identifier(name, null, defines);
}

Expand Down
Loading