class Subroutines.SubroutineImpl {
/*
* Satisfies Subroutine.getAccessedLocalIndices().
*/
@Override
public int[] getAccessedLocalsIndices(){
//TODO: Implement caching.
Set<Integer> acc = new HashSet<>();
if (theRET == null && this != getTopLevel()){
throw new AssertionViolatedException(
"This subroutine object must be built up completely before calculating accessed locals.");
}
{
for (InstructionHandle ih : instructions) {
// RET is not a LocalVariableInstruction in the current version of BCEL.
if (ih.getInstruction() instanceof LocalVariableInstruction || ih.getInstruction() instanceof RET){
int idx = ((IndexedInstruction) (ih.getInstruction())).getIndex();
acc.add(Integer.valueOf(idx));
// LONG? DOUBLE?.
try{
// LocalVariableInstruction instances are typed without the need to look into
// the constant pool.
if (ih.getInstruction() instanceof LocalVariableInstruction){
int s = ((LocalVariableInstruction) ih.getInstruction()).getType(null).getSize();
if (s==2) {
acc.add(Integer.valueOf(idx+1));
}
}
}
catch(RuntimeException re){
throw new AssertionViolatedException("Oops. BCEL did not like NULL as a ConstantPoolGen object.", re);
}
}
}
}
{
int[] ret = new int[acc.size()];
int j=-1;
for (Integer accessedLocal : acc) {
j++;
ret[j] = accessedLocal.intValue();
}
return ret;
}
}
}