@all: Hi again, 
@Matthew Wilson: thx for your comments

It is my 5th month now I'm working fulltime on an academic project that is 
based on BCEL. The problem discussed here is an important one for me. I try to 
solve it, but weeks pass and I'm still not satisfied with the solution. Maybe 
you can provide some more comment on this topic in order to propose a better 
solution and maybe to better understand the design issue I try to explain.

The design problem is the following.
We have an InstructionList, we want to insert new instructions at certain 
points. We are using a visitor class implementing the visitor interface to 
visit the whole instruction list and do the changes to it.

Let's say our loop over the InstructionList is in a class A, our Visitor is 
class B.
In A the loop looks the following:

for(InstructionHandle currIH: iList.getInstructionHandles() )
{
      currIH.accept(instanceOfVisitorClassB);
}


one certain method in the( visitor ) class B looks  something like this:
  public void visitASTORE( ASTORE obj ) {
      ...
      InstructionList il = new InstructionList();
      ... // fill the new il
      // insert instructions before actual ASTORE instruction
      iList.insert( obj, il );
      iList.setPositions();
      super.visitASTORE( obj );
    }

So if the ASTORE instruction is visited we call the method 
insert(Instruction, InstructionList) which causes the error described before 
(insertion point may be wrong because of == equal refrence match on 
instructions).

Therefore we shouldn't visit the INSTRUCTIONS but the INSTRUCTIONHANDLES but as 
far as I know there isnt' a visitor which has the interface 
visitASTORE( ASTOREHANDLE obj ) or something like that.

My dirty, quickfix, hack is the following:
Class B I put as inner class into A, the loop in class A sets a public field 
currentVisitedInstructionHandle, then the visitor method I changed to:
     public void visitASTORE( ASTORE obj ) {
      ...
     // insert instructions before actual ASTORE instruction
      _textsegment_il.insert( currentVisitedInstructionHandle, il );
      _textsegment_il.setPositions();
     }
THE DIFFERENCE IS:
insert(InstructionHandle, InstructionList) is called, and because 
InstructionHandles are unique our insertion is correct.

NOW: I think this is somehow ugly, right?
I tried to write an InstructionHandle visitor, I already wrapped all the 
Instruction class automatically, but then I realized that it is far too much 
work for one guy.

Do you see my point? I think the design of the visitor (which is a great 
concept!) should be somehow changed to better address a problem like that.

If you have any better solution, or if I'm doing something wrong, please let me 
now!

@Matthew: do you have an idea?


kind regards
zagi
 


-- 
NUR NOCH BIS 31.01.! GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 EURO/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to