Skip to content

Commit f1a57ed

Browse files
author
emmanue1
committed
Works on try-catch-finally statements
1 parent 8efb011 commit f1a57ed

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

src/main/java/org/jd/core/v1/service/converter/classfiletojavasyntax/util/ControlFlowGraphReducer.java

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ protected static boolean reduceTryDeclaration(BitSet visited, BasicBlock basicBl
759759
exceptionHandler.setBasicBlock(END);
760760
} else {
761761
int offset = (bb.getFromOffset() == maxOffset) ? end.getFromOffset() : maxOffset;
762+
763+
if (offset == 0) {
764+
offset = Integer.MAX_VALUE;
765+
}
766+
762767
BasicBlock last = updateBlock(bb, end, offset);
763768

764769
if (toOffset < last.getToOffset()) {
@@ -847,44 +852,69 @@ protected static BasicBlock searchJsrTarget(BasicBlock basicBlock, BitSet jsrTar
847852
}
848853

849854
protected static BasicBlock searchEndBlock(BasicBlock basicBlock, int maxOffset) {
855+
BasicBlock end = null;
850856
BasicBlock last = splitSequence(basicBlock.getNext(), maxOffset);
851-
BasicBlock next = last.getNext();
852857

853-
if (!next.matchType(TYPE_END|TYPE_LOOP_START|TYPE_LOOP_CONTINUE|TYPE_LOOP_END|TYPE_JUMP) && ((next.getFromOffset() >= maxOffset) || (next.getToOffset() < basicBlock.getFromOffset()))) {
854-
return next;
858+
if (!last.matchType(GROUP_END)) {
859+
BasicBlock next = last.getNext();
860+
861+
if ((next.getFromOffset() >= maxOffset) || (!next.matchType(TYPE_END|TYPE_RETURN|TYPE_SWITCH_BREAK|TYPE_LOOP_START|TYPE_LOOP_CONTINUE|TYPE_LOOP_END) && (next.getToOffset() < basicBlock.getFromOffset()))) {
862+
return next;
863+
}
864+
865+
end = next;
855866
}
856867

857868
for (BasicBlock.ExceptionHandler exceptionHandler : basicBlock.getExceptionHandlers()) {
858869
BasicBlock bb = exceptionHandler.getBasicBlock();
859870

860871
if (bb.getFromOffset() < maxOffset) {
861872
last = splitSequence(bb, maxOffset);
862-
next = last.getNext();
863873

864-
if (!next.matchType(TYPE_END|TYPE_LOOP_START|TYPE_LOOP_CONTINUE|TYPE_LOOP_END|TYPE_JUMP) && ((next.getFromOffset() >= maxOffset) || (next.getToOffset() < basicBlock.getFromOffset()))) {
865-
return next;
874+
if (!last.matchType(GROUP_END)) {
875+
BasicBlock next = last.getNext();
876+
877+
if ((next.getFromOffset() >= maxOffset) || (!next.matchType(TYPE_END | TYPE_RETURN | TYPE_SWITCH_BREAK | TYPE_LOOP_START | TYPE_LOOP_CONTINUE | TYPE_LOOP_END) && (next.getToOffset() < basicBlock.getFromOffset()))) {
878+
return next;
879+
}
880+
881+
if (end == null) {
882+
end = next;
883+
} else if (end != next) {
884+
end = END;
885+
}
866886
}
867887
} else {
868888
// Last handler block
869889
ControlFlowGraph cfg = bb.getControlFlowGraph();
870890
int lineNumber = cfg.getLineNumber(bb.getFromOffset());
871891
WatchDog watchdog = new WatchDog();
892+
BasicBlock next = bb.getNext();
872893

873894
last = bb;
874-
next = bb.getNext();
875895

876896
while ((last != next) && last.matchType(GROUP_SINGLE_SUCCESSOR) && (next.getPredecessors().size() == 1) && (lineNumber <= cfg.getLineNumber(next.getFromOffset()))) {
877897
watchdog.check(next, next.getNext());
878898
last = next;
879899
next = next.getNext();
880900
}
881901

882-
if ((last != next) && ((next.getPredecessors().size() > 1) || !next.matchType(GROUP_END))) {
883-
return next;
902+
if (!last.matchType(GROUP_END)) {
903+
if ((last != next) && ((next.getPredecessors().size() > 1) || !next.matchType(GROUP_END))) {
904+
return next;
905+
}
906+
907+
if ((end != next) && (exceptionHandler.getInternalThrowableName() != null)) {
908+
end = END;
909+
}
884910
}
885911
}
886912
}
887913

914+
if ((end != null) && end.matchType(TYPE_SWITCH_BREAK|TYPE_LOOP_START|TYPE_LOOP_CONTINUE|TYPE_LOOP_END)) {
915+
return end;
916+
}
917+
888918
return END;
889919
}
890920

@@ -920,24 +950,17 @@ protected static BasicBlock splitSequence(BasicBlock basicBlock, int maxOffset)
920950
protected static BasicBlock updateBlock(BasicBlock basicBlock, BasicBlock end, int maxOffset) {
921951
WatchDog watchdog = new WatchDog();
922952

923-
if (end == END) {
924-
while (basicBlock.matchType(GROUP_SINGLE_SUCCESSOR)) {
925-
watchdog.check(basicBlock, basicBlock.getNext());
926-
basicBlock = basicBlock.getNext();
927-
}
928-
} else {
929-
while (basicBlock.matchType(GROUP_SINGLE_SUCCESSOR)) {
930-
watchdog.check(basicBlock, basicBlock.getNext());
931-
BasicBlock next = basicBlock.getNext();
932-
933-
if ((next == end) || (next.getFromOffset() > maxOffset)) {
934-
next.getPredecessors().remove(basicBlock);
935-
basicBlock.setNext(END);
936-
break;
937-
}
953+
while (basicBlock.matchType(GROUP_SINGLE_SUCCESSOR)) {
954+
watchdog.check(basicBlock, basicBlock.getNext());
955+
BasicBlock next = basicBlock.getNext();
938956

939-
basicBlock = next;
957+
if ((next == end) || (next.getFromOffset() > maxOffset)) {
958+
next.getPredecessors().remove(basicBlock);
959+
basicBlock.setNext(END);
960+
break;
940961
}
962+
963+
basicBlock = next;
941964
}
942965

943966
return basicBlock;

0 commit comments

Comments
 (0)