forked from leibnitz27/cfr
-
Notifications
You must be signed in to change notification settings - Fork 11
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
use MethodParameter attribute if code attribute is missing #19
Open
char3210
wants to merge
2
commits into
FabricMC:master
Choose a base branch
from
char3210:method-parameters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/org/benf/cfr/reader/bytecode/analysis/variables/NamedVariableMethodParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.benf.cfr.reader.bytecode.analysis.variables; | ||
|
||
import org.benf.cfr.reader.bytecode.analysis.types.MethodPrototype; | ||
import org.benf.cfr.reader.entities.attributes.MethodParameterEntry; | ||
import org.benf.cfr.reader.entities.constantpool.ConstantPool; | ||
import org.benf.cfr.reader.entities.constantpool.ConstantPoolEntryUTF8; | ||
import org.benf.cfr.reader.util.output.Dumper; | ||
|
||
import java.util.List; | ||
|
||
public class NamedVariableMethodParameter implements NamedVariable { | ||
private String name; | ||
private boolean forced = false; | ||
private final List<MethodParameterEntry> parameters; | ||
private final ConstantPool cp; | ||
|
||
public NamedVariableMethodParameter(List<MethodParameterEntry> parameters, String name, ConstantPool cp) { | ||
this.name = name; | ||
this.parameters = parameters; | ||
this.cp = cp; | ||
} | ||
|
||
@Override | ||
public void forceName(String name) { | ||
this.name = name; | ||
forced = true; | ||
} | ||
|
||
@Override | ||
public String getStringName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public boolean isGoodName() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Dumper dump(Dumper d) { | ||
return dump(d, false); | ||
} | ||
|
||
@Override | ||
public Dumper dump(Dumper d, boolean defines) { | ||
return d.variableName(name, this, defines); | ||
} | ||
|
||
@Override | ||
public Dumper dumpParameter(Dumper d, MethodPrototype prototype, int index, boolean defines) { | ||
if (forced) { | ||
return d.parameterName(name, this, prototype, index, defines); | ||
} | ||
int nameIndex = parameters.get(index).nameIndex; | ||
if (nameIndex == 0) { | ||
return d.parameterName(name, this, prototype, index, defines); | ||
} | ||
return d.parameterName(((ConstantPoolEntryUTF8)cp.getEntry(nameIndex)).getValue(), this, prototype, index, defines); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/org/benf/cfr/reader/bytecode/analysis/variables/VariableNamerMethodParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.benf.cfr.reader.bytecode.analysis.variables; | ||
|
||
import org.benf.cfr.reader.entities.attributes.LocalVariableEntry; | ||
import org.benf.cfr.reader.entities.attributes.MethodParameterEntry; | ||
import org.benf.cfr.reader.entities.constantpool.ConstantPool; | ||
import org.benf.cfr.reader.util.collections.MapFactory; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class VariableNamerMethodParameter implements VariableNamer { | ||
private final VariableNamer missingNamer = new VariableNamerDefault(); | ||
private final List<MethodParameterEntry> parameters; | ||
private final ConstantPool cp; | ||
|
||
public VariableNamerMethodParameter(List<MethodParameterEntry> parameters, ConstantPool cp) { | ||
this.parameters = parameters; | ||
this.cp = cp; | ||
} | ||
|
||
@Override | ||
public NamedVariable getName(int originalRawOffset, Ident ident, long stackPosition, boolean clashed) { | ||
return new NamedVariableMethodParameter(parameters, null, cp); | ||
} | ||
|
||
@Override | ||
public List<NamedVariable> getNamedVariables() { | ||
return missingNamer.getNamedVariables(); | ||
} | ||
|
||
@Override | ||
public void mutatingRenameUnClash(NamedVariable toRename) { | ||
missingNamer.mutatingRenameUnClash(toRename); | ||
} | ||
|
||
@Override | ||
public void forceName(Ident ident, long stackPosition, String name) { | ||
missingNamer.forceName(ident, stackPosition, name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/org/benf/cfr/reader/entities/attributes/AttributeMethodParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.benf.cfr.reader.entities.attributes; | ||
|
||
import org.benf.cfr.reader.entities.constantpool.ConstantPool; | ||
import org.benf.cfr.reader.util.bytestream.ByteData; | ||
import org.benf.cfr.reader.util.collections.ListFactory; | ||
import org.benf.cfr.reader.util.output.Dumper; | ||
|
||
import java.util.List; | ||
|
||
public class AttributeMethodParameters extends Attribute { | ||
public static final String ATTRIBUTE_NAME = "MethodParameters"; | ||
|
||
private static final long OFFSET_OF_ATTRIBUTE_LENGTH = 2; | ||
private static final long OFFSET_OF_REMAINDER = 6; | ||
private static final long OFFSET_OF_PARAMETERS_COUNT = 6; | ||
private static final long OFFSET_OF_PARAMETERS = 7; | ||
|
||
private final int length; | ||
private final int count; | ||
private final List<MethodParameterEntry> parameters = ListFactory.newList(); | ||
|
||
public AttributeMethodParameters(ByteData raw, ConstantPool cp) { | ||
this.length = raw.getS4At(OFFSET_OF_ATTRIBUTE_LENGTH); | ||
this.count = raw.getU1At(OFFSET_OF_PARAMETERS_COUNT); | ||
long offset = OFFSET_OF_PARAMETERS; | ||
for (long i = 0; i < count; i++) { | ||
int nameIndex = raw.getU2At(offset); | ||
int accessFlags = raw.getU2At(offset + 2); | ||
parameters.add(new MethodParameterEntry(nameIndex, accessFlags)); | ||
} | ||
} | ||
|
||
public int getParameterCount() { | ||
return count; | ||
} | ||
|
||
public List<MethodParameterEntry> getParameters() { | ||
return parameters; | ||
} | ||
|
||
@Override | ||
public Dumper dump(Dumper d) { | ||
return d.print(ATTRIBUTE_NAME); | ||
} | ||
|
||
@Override | ||
public String getRawName() { | ||
return ATTRIBUTE_NAME; | ||
} | ||
|
||
@Override | ||
public long getRawByteLength() { | ||
return OFFSET_OF_REMAINDER + length; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/org/benf/cfr/reader/entities/attributes/MethodParameterEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.benf.cfr.reader.entities.attributes; | ||
|
||
import org.benf.cfr.reader.entities.constantpool.ConstantPoolEntryUTF8; | ||
|
||
public class MethodParameterEntry { | ||
public final int nameIndex; | ||
public final int accessFlags; | ||
|
||
public MethodParameterEntry(int nameIndex, int accessFlags) { | ||
this.nameIndex = nameIndex; | ||
this.accessFlags = accessFlags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, no good if it's 0-name; it's totally legal to have null name in MethodParameters (storing parameter flags only) but valid name in LocalVariableTable/LocalVariableTypeTable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what exactly isGoodName is supposed to represent, but I don't see a very easy way to fix this currently since this doesn't know which parameter it is until dumpParameter is called...