decompiler: map dummy return line to the method closing bracket

This commit is contained in:
Egor.Ushakov
2015-03-24 17:56:33 +03:00
parent 07e1d66a53
commit 500f8b12d8
34 changed files with 565 additions and 128 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,8 +46,7 @@ public class DomHelper {
// head statement
Statement firstst = stats.getWithKey(firstblock.id);
// dummy exit statement
Statement dummyexit = new Statement();
dummyexit.type = Statement.TYPE_DUMMYEXIT;
DummyExitStatement dummyexit = new DummyExitStatement();
Statement general;
if (stats.size() > 1 || firstblock.isSuccessor(firstblock)) { // multiple basic blocks or an infinite loop of one block

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -247,7 +247,9 @@ public class ExitHelper {
boolean res = false;
for (StatEdge edge : root.getDummyExit().getAllPredecessorEdges()) {
DummyExitStatement dummyExit = root.getDummyExit();
for (StatEdge edge : dummyExit.getAllPredecessorEdges()) {
if (!edge.explicit) {
Statement source = edge.getSource();
List<Exprent> lstExpr = source.getExprents();
@@ -257,6 +259,7 @@ public class ExitHelper {
ExitExprent ex = (ExitExprent)expr;
if (ex.getExitType() == ExitExprent.EXIT_RETURN && ex.getValue() == null) {
// remove redundant return
dummyExit.addBytecodeOffsets(ex.bytecode);
lstExpr.remove(lstExpr.size() - 1);
res = true;
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.java.decompiler.modules.decompiler.stats;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @author egor
*/
public class DummyExitStatement extends Statement {
public Set<Integer> bytecode = null; // offsets of bytecode instructions mapped to dummy exit
public DummyExitStatement() {
type = Statement.TYPE_DUMMYEXIT;
}
public void addBytecodeOffsets(Collection<Integer> bytecodeOffsets) {
if (bytecodeOffsets != null && !bytecodeOffsets.isEmpty()) {
if (bytecode == null) {
bytecode = new HashSet<Integer>(bytecodeOffsets);
}
else {
bytecode.addAll(bytecodeOffsets);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@ import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
public class RootStatement extends Statement {
private Statement dummyExit;
private DummyExitStatement dummyExit;
public RootStatement(Statement head, Statement dummyExit) {
public RootStatement(Statement head, DummyExitStatement dummyExit) {
type = Statement.TYPE_ROOT;
@@ -39,11 +39,11 @@ public class RootStatement extends Statement {
return ExprProcessor.listToJava(varDefinitions, indent, tracer).append(first.toJava(indent, tracer));
}
public Statement getDummyExit() {
public DummyExitStatement getDummyExit() {
return dummyExit;
}
public void setDummyExit(Statement dummyExit) {
public void setDummyExit(DummyExitStatement dummyExit) {
this.dummyExit = dummyExit;
}
}