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

Release 1.9.2 #298

Merged
merged 18 commits into from
Aug 4, 2023
Merged
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
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ compileJava {
group = 'org.vineflower'
archivesBaseName = 'vineflower'

version = '1.9.1'
version = '1.9.2'

def ENV = System.getenv()
version = version + (ENV.GITHUB_ACTIONS ? "" : "+local")
Expand Down Expand Up @@ -242,9 +242,11 @@ nexusPublishing {
}

signing {
def signingKey = ENV.SIGNING_KEY
def signingPassword = ENV.SIGNING_KEY_PASSPHRASE
if (ENV.SIGNING_KEY) {
def signingKey = ENV.SIGNING_KEY
def signingPassword = ENV.SIGNING_KEY_PASSPHRASE

useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
}
}
28 changes: 22 additions & 6 deletions src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ private static boolean invokeProcessors(TextBuffer buffer, ClassNode node) {
EnumProcessor.clearEnum(wrapper);
}

// FIXME: when 1.10 merge, this needs to be removed
for (MethodWrapper mw : wrapper.getMethods()) {
if (mw.root != null) {
mw.varproc.rerunClashing(mw.root);
}
}

if (DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ASSERTIONS)) {
AssertProcessor.buildAssertions(node);
}
Expand Down Expand Up @@ -189,9 +196,14 @@ public void classLambdaToJava(ClassNode node, TextBuffer buffer, Exprent method_
if (!firstParameter) {
buffer.append(", ");
}
VarType type = md_content.params[i];

String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors
if (parameterName == null) {
parameterName = "param" + index; // null iff decompiled with errors
}
parameterName = methodWrapper.methodStruct.getVariableNamer().renameParameter(mt.getAccessFlags(), ExprProcessor.getCastTypeName(type), parameterName, index);
buffer.append(parameterName);

firstParameter = false;
}
Expand Down Expand Up @@ -835,7 +847,11 @@ private static void methodLambdaToJava(ClassNode lambdaNode,
buffer.append(" ");

String parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors
if (parameterName == null) {
parameterName = "param" + index; // null iff decompiled with errors
}
parameterName = methodWrapper.methodStruct.getVariableNamer().renameParameter(mt.getAccessFlags(), typeName, parameterName, index);
buffer.append(parameterName);

firstParameter = false;
}
Expand Down Expand Up @@ -1104,11 +1120,11 @@ else if (methodWrapper.varproc.getVarFinal(new VarVersionPair(index, 0)) == VarT
parameterName = methodWrapper.varproc.getVarName(new VarVersionPair(index, 0));
}

if ((flags & (CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_NATIVE)) != 0) {
String newParameterName = methodWrapper.methodStruct.getVariableNamer().renameAbstractParameter(parameterName, index);
parameterName = !newParameterName.equals(parameterName) ? newParameterName : DecompilerContext.getStructContext().renameAbstractParameter(methodWrapper.methodStruct.getClassQualifiedName(), mt.getName(), mt.getDescriptor(), index - (((flags & CodeConstants.ACC_STATIC) == 0) ? 1 : 0), parameterName);

String newParameterName = methodWrapper.methodStruct.getVariableNamer().renameParameter(flags, typeName, parameterName, index);
if ((flags & (CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_NATIVE)) != 0 && Objects.equals(newParameterName, parameterName)) {
newParameterName = DecompilerContext.getStructContext().renameAbstractParameter(methodWrapper.methodStruct.getClassQualifiedName(), mt.getName(), mt.getDescriptor(), index - (((flags & CodeConstants.ACC_STATIC) == 0) ? 1 : 0), parameterName);
}
parameterName = newParameterName;

buffer.append(parameterName == null ? "param" + index : parameterName); // null iff decompiled with errors

Expand Down
5 changes: 5 additions & 0 deletions src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ public int compareTo(ClassNode o) {
return this.classStruct.qualifiedName.compareTo(o.classStruct.qualifiedName);
}

@Override
public String toString() {
return type + " class " + classStruct.qualifiedName;
}

public static class LambdaInformation {
public String method_name;
public String method_descriptor;
Expand Down
3 changes: 2 additions & 1 deletion src/org/jetbrains/java/decompiler/main/Fernflower.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public Fernflower(IBytecodeProvider provider, IResultSaver saver, Map<String, Ob
}
if (renamerFactory == null) {
if("1".equals(properties.get(IFernflowerPreferences.USE_JAD_VARNAMING))) {
renamerFactory = new JADNameProvider.JADNameProviderFactory();
boolean renameParams = "1".equals(properties.get(IFernflowerPreferences.USE_JAD_PARAMETER_NAMING));
renamerFactory = new JADNameProvider.JADNameProviderFactory(renameParams);
} else {
renamerFactory = new IdentityRenamerFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ public interface IFernflowerPreferences {
String LINE_SEPARATOR_UNX = "\n";

@Name("JAD-Style Variable Naming")
@Description("Use JAD-style variable naming for local variables, instead of var<index>_<version>A.")
@Description("Use JAD-style variable naming for local variables, instead of var<index>_<version>.")
String USE_JAD_VARNAMING = "jvn";

@Name("JAD-Style Parameter Naming")
@Description("Use JAD-style variable naming for parameters.")
String USE_JAD_PARAMETER_NAMING = "jpr";

@Name("Skip Extra Files")
@Description("Skip copying non-class files from the input folder or file to the output")
String SKIP_EXTRA_FILES = "sef";
Expand Down Expand Up @@ -319,6 +323,7 @@ static Map<String, Object> getDefaults() {
defaults.put(DUMP_ORIGINAL_LINES, "0");
defaults.put(THREADS, String.valueOf(Runtime.getRuntime().availableProcessors()));
defaults.put(USE_JAD_VARNAMING, "0");
defaults.put(USE_JAD_PARAMETER_NAMING, "0");
defaults.put(SKIP_EXTRA_FILES, "0");
defaults.put(WARN_INCONSISTENT_INNER_CLASSES, "1");
defaults.put(DUMP_BYTECODE_ON_ERROR, "1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@

import java.util.Map;

import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPair;

public interface IVariableNameProvider {
public Map<VarVersionPair,String> rename(Map<VarVersionPair,String> variables);
public String renameAbstractParameter(String abstractParam, int index);
default String renameAbstractParameter(String name, int index) {
return name;
}

default String renameParameter(int flags, String type, String name, int index) {
if ((flags & (CodeConstants.ACC_ABSTRACT | CodeConstants.ACC_NATIVE)) != 0) {
return renameAbstractParameter(name, index);
}

return name;
}
public void addParentContext(IVariableNameProvider renamer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,20 @@ private static void setLambdaVars(ClassNode parent, ClassNode child) {

// rename colliding local variables
for (VarVersionPair local : varProc.getUsedVarVersions()) {
String name = varProc.getVarName(local);
String name = null;
LocalVariable lvt = varProc.getVarLVT(local);
if (lvt != null) {
name = lvt.getName();
}
if (name == null) {
name = varProc.getVarName(local);
}
if (usedBefore.contains(name) && !"this".equals(name)) {
mapNewNames.put(local, enclosingCollector.getFreeName(name));
name = enclosingCollector.getFreeName(name);
mapNewNames.put(local, name);
if (lvt != null) {
lvts.put(local, lvt.rename(name));
}
}
}

Expand Down Expand Up @@ -332,7 +343,7 @@ else if (!mapNewNames.containsKey(varVersion)) {
VarVersionPair pair = entry.getKey();
LocalVariable lvt = lvts.get(pair);

varProc.setVarName(pair, entry.getValue());
varProc.setInheritedName(pair, entry.getValue());
if (lvt != null) {
varProc.setVarLVT(pair, lvt);
}
Expand Down Expand Up @@ -723,7 +734,7 @@ private static void insertLocalVars(ClassNode parent, ClassNode child) {
VarType type = mapNewTypes.get(pair);
LocalVariable lvt = mapNewLVTs.get(pair);

method.varproc.setVarName(pair, entry.getValue());
method.varproc.setInheritedName(pair, entry.getValue());
if (type != null) {
method.varproc.setVarType(pair, type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ private boolean compareBasicBlocksEx(ControlFlowGraph graph,
List<int[]> lstStoreVars) {
InstructionSequence seqPattern = pattern.getSeq();
InstructionSequence seqSample = sample.getSeq();
List<Integer> instrOldOffsetsSample = sample.getInstrOldOffsets();

if (type != 0) {
seqPattern = seqPattern.clone();
Expand Down Expand Up @@ -822,6 +823,9 @@ private boolean compareBasicBlocksEx(ControlFlowGraph graph,
seq.addInstruction(0, seqSample.getInstr(i), -1);
oldOffsets.addFirst(sample.getOldOffset(i));
seqSample.removeInstruction(i);
if (i < instrOldOffsetsSample.size()) {
instrOldOffsetsSample.remove(i);
}
}

BasicBlock newblock = new BasicBlock(++graph.last_id);
Expand Down Expand Up @@ -1010,26 +1014,31 @@ private static void deleteArea(ControlFlowGraph graph, Area area) {

private static void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) {
InstructionSequence seq = block.getSeq();
List<Integer> instrOldOffsets = block.getInstrOldOffsets();

if (finallytype == 3) { // empty finally handler
for (int i = seq.length() - 1; i >= 0; i--) {
seq.removeInstruction(i);
instrOldOffsets.remove(i);
}
}
else {
if ((blocktype & 1) > 0) { // first
if (finallytype == 2 || finallytype == 1) { // astore or pop
seq.removeInstruction(0);
instrOldOffsets.remove(0);
}
}

if ((blocktype & 2) > 0) { // last
if (finallytype == 2 || finallytype == 0) {
seq.removeLast();
instrOldOffsets.remove(instrOldOffsets.size() - 1);
}

if (finallytype == 2) { // astore
seq.removeLast();
instrOldOffsets.remove(instrOldOffsets.size() - 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static void identifyLabels(RootStatement root) {

setExplicitEdges(root);

hideDefaultSwitchEdges(root);
// TODO: is this correct? we don't want to mess with case statements while processing still happens!
// hideDefaultSwitchEdges(root);

processStatementLabel(root);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) {
return false;
}

if (!tryStatement.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) {
return false;
}

Statement inner = tryStatement.getStats().get(1); // Get catch block

VarExprent closeable = null;
Expand All @@ -125,6 +129,11 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) {
return false;
}

CatchStatement innerTry = (CatchStatement)inner;
if (!innerTry.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) {
return false;
}

Statement inTry = inner.getStats().get(0);

// Catch block contains a basic block inside which has the closeable invocation
Expand Down Expand Up @@ -164,6 +173,15 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) {

// Process try catch inside of if statement
if (inner instanceof CatchStatement && !inner.getStats().isEmpty()) {
if (inner.getStats().isEmpty()) {
return false;
}

CatchStatement innerTry = (CatchStatement)inner;
if (!innerTry.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) {
return false;
}

Statement inTry = inner.getStats().get(0);

if (inTry instanceof BasicBlockStatement && !inTry.getExprents().isEmpty()) {
Expand Down Expand Up @@ -192,6 +210,9 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) {
}

Set<Statement> destinations = findExitpoints(tryStatement);
if (destinations.isEmpty()) {
return false;
}

Statement check = tryStatement;
List<StatEdge> preds = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public TextBuffer toJava(int indent) {
TextBuffer res = array.toJava(indent);

if (array.getPrecedence() > getPrecedence() && !canSkipParenEnclose(array)) { // array precedence equals 0
res.enclose("(", ")");
res.encloseWithParens();
}

VarType arrType = array.getExprType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void wrapInCast(VarType left, VarType right, TextBuffer buf, int precede
}

if (precedence >= FunctionExprent.FunctionType.CAST.precedence) {
buf.enclose("(", ")");
buf.encloseWithParens();
}

buf.prepend("(" + ExprProcessor.getCastTypeName(left) + ")");
Expand Down
Loading
Loading