| 1 | |
package org.apache.commons.javaflow.bytecode.transformation.bcel.analyser; |
| 2 | |
|
| 3 | |
import org.apache.bcel.generic.Instruction; |
| 4 | |
import org.apache.bcel.generic.RET; |
| 5 | |
import org.apache.bcel.generic.JsrInstruction; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
public final class ExecutionPath { |
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | 0 | public static final ExecutionPath EMPTY = new ExecutionPath(null,null); |
| 22 | |
|
| 23 | |
private final ExecutionPath prev; |
| 24 | |
private final InstructionContext last; |
| 25 | |
|
| 26 | 0 | private ExecutionPath(ExecutionPath prev, InstructionContext last) { |
| 27 | 0 | this.prev = prev; |
| 28 | 0 | this.last = last; |
| 29 | 0 | } |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public ExecutionPath append(InstructionContext ins) { |
| 36 | 0 | return new ExecutionPath(this,ins); |
| 37 | |
} |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public InstructionContext lastExecutionJSR(){ |
| 47 | 0 | int retcount = 0; |
| 48 | |
|
| 49 | 0 | for( ExecutionPath ptr = this; ptr!=EMPTY; ptr=ptr.prev) { |
| 50 | 0 | Instruction i = ptr.last.getInstruction().getInstruction(); |
| 51 | 0 | if (i instanceof RET) retcount++; |
| 52 | 0 | if (i instanceof JsrInstruction){ |
| 53 | 0 | retcount--; |
| 54 | 0 | if (retcount == -1) |
| 55 | 0 | return ptr.last; |
| 56 | |
} |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | return null; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public String toString() { |
| 66 | 0 | if(this==EMPTY) |
| 67 | 0 | return ""; |
| 68 | |
else { |
| 69 | 0 | return prev.toString()+"\n"+last.toString(); |
| 70 | |
} |
| 71 | |
} |
| 72 | |
} |