Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Preserving InstructionBlocks in LoopBlock

Help
2007-01-24
2013-05-02
  • Trevor Harmon
    Trevor Harmon
    2007-01-24

    The patch for JODE bug #1633932 preserves bytecodes during StructuredBlock transformations. With this patch, the original bytecodes for any StructuredBlock can be obtained by calling StructuredBlock.getBytecodeInstructions(). It works great except for one thing: When a LoopBlock object represents a FOR loop, the StructuredBlock objects for the initialization and increment steps are nulled out, leaving only Expression objects and no way to get the original bytecodes.

    I believe I've found a simple solution. Only two changes are necessary. (There are more efficient ways of doing this, but this solution is the simplest.)

    First, in LoopBlock.setInit(), the line "this.initBlock = initBlock;" needs to execute for the FOR type as well as the POSSFOR type. This ensures that the initBlock is initialized.

    Second, in LoopBlock.setCondition(), the line "initBlock = incrBlock = null;" needs to be removed. This prevents the blocks from disappearing.

    I've tested these changes, and they appear to have the desired effect of preserving the initBlock and incrBlock fields with their bytecode instructions intact.

    So, is this a valid solution? (I realize that removing the "= null" line prevents the objects from being garbage collected, but I think that's a small thing.)