#47 branch analyzer needs better "else" detection

GroboUtils v4
open
Matt Albrecht
3
2004-02-27
2004-02-27
Matt Albrecht
No

If no "else" statement exists in the Java source, the
branch analyzer should alter the code to make an "else"
statement.

That is, if the code looks like:
1: if (a) {
2: if (b) {
3: doIt();
4: }
5: }
6: doAnother();
The "else" destination bytecode should NOT be
"doAnother();". Rather, the branch analyzer needs the
smarts to understand that line 1 doesn't have a "GOTO"
instruction right before the destination of the IF
instruction. Likewise with line 2.

The analyzer needs to change the code from:
aload (something)
IFEQ -> line 6
<probe for 1if>
aload (something)
IFEQ -> line 6
<probe for 2if>
invokestatic (or whatever)
**line 6:
<probe for 1else and 2else>
invokestatic (or whatever)
to:
aload (something)
IFEQ -> line 1else
<probe for 1if>
aload (something)
IFEQ -> line 2else
<probe for 2if>
invokestatic (or whatever)
GOTO -> line 6
**line 1else:
<probe for 1else>
GOTO -> line 6
**line 2else:
<probe for 2else>
GOTO -> line 6
**line 6:
invokestatic (or whatever)

That's a lot of work, though.

Discussion