Efficient convenience methods for IfThenElseBlock, LoopBlock
Brought to you by:
hoenicke
In IfThenElseBlock, there is no obvious mechanism for checking whether it has an "else" part. The only way is to check whether getSubBlocks() returns an array of length 1 or 2, but that allocates memory on every call. That's why it would be nice to have the following method added to IfThenElseBlock:
public boolean hasElse() {
return elseBlock != null;
}
Along those same lines, you can't obtain a handle to a LoopBlock's body without allocating memory (on each call to getSubBlocks()). Therefore, it would be nice to have the following method in LoopBlock.java:
public StructuredBlock getBody() {
return bodyBlock;
}
Thanks!
Logged In: YES
user_id=720008
Originator: YES
I forgot a couple more. IfThenElseBlock has setters but no getters for thenBlock and elseBlock. You could obtain them with getSubBlocks(), but again, that allocates memory on each call. Instead, it would be nice to see the following:
public StructuredBlock getThenBlock() {
return thenBlock;
}
public StructuredBlock getElseBlock() {
return elseBlock;
}
Not only are these more efficient than getSubBlocks(), but they also make the calling code more readable.
Logged In: YES
user_id=720008
Originator: YES
It would be nice to have a few more accessor methods in LoopBlock:
public Expression getInitInstr() {
return initInstr;
}
public InstructionBlock getInitBlock() {
return initBlock;
}
public Expression getIncrInstr() {
return incrInstr;
}
public InstructionBlock getIncrBlock() {
return incrBlock;
}
There isn't any memory allocation problem here, but the methods are needed for public access to some important fields.