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.
Open
Changes from 1 commit
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
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
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.util.output.Dumper; | ||
|
||
import java.util.List; | ||
|
||
public class NamedVariableMethodParameter implements NamedVariable { | ||
private String name; | ||
private boolean forced = false; | ||
private List<MethodParameterEntry> parameters; | ||
|
||
public NamedVariableMethodParameter(List<MethodParameterEntry> parameters, String name) { | ||
this.name = name; | ||
this.parameters = parameters; | ||
} | ||
|
||
@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) { | ||
return d.parameterName(forced ? name : parameters.get(index).name.getValue(), this, prototype, index, defines); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, will NPE on |
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
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.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 Map<LocalVariableEntry, NamedVariable> cache = MapFactory.newMap(); | ||
|
||
public VariableNamerMethodParameter(List<MethodParameterEntry> parameters) { | ||
this.parameters = parameters; | ||
} | ||
|
||
@Override | ||
public NamedVariable getName(int originalRawOffset, Ident ident, long stackPosition, boolean clashed) { | ||
return new NamedVariableMethodParameter(parameters, null); | ||
} | ||
|
||
@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(cp.getEntry(nameIndex), accessFlags)); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
} | ||||
} | ||||
|
||||
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; | ||||
} | ||||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
package org.benf.cfr.reader.entities.attributes; | ||
|
||
import org.benf.cfr.reader.entities.constantpool.ConstantPoolEntry; | ||
import org.benf.cfr.reader.entities.constantpool.ConstantPoolEntryUTF8; | ||
|
||
public class MethodParameterEntry { | ||
public final ConstantPoolEntryUTF8 name; | ||
public final int accessFlags; | ||
|
||
public MethodParameterEntry(ConstantPoolEntry name, int accessFlags) { | ||
this.name = (ConstantPoolEntryUTF8) name; | ||
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...