This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Extending gcjx visitor pattern
>>>>> "Mike" == Mike Emmel <mike.emmel@gmail.com> writes:
Mike> The only issue here is if I get into a situation where I need to
Mike> start pushing state onto a stack so far thats not come up. Then
Mike> I need at least and object to save the current visitors state
Mike> in.
What I do in this sort of situation is define a new helper class that
uses the RAII idiom to save the old value of some field and push a new
value. This is kind of wordy, which I dislike, but on the other hand
it is type safe and it means I don't have to remember to pop the value
when returning.
If code in the visitor needs to be able to see the entire stack of
values, and not just the most recent one, I use a list or deque or
something and have the helper class push/pop the last element.
There are plenty of examples of this in the code, eg look at
push_expr_target in gcjx/bytecode/generate.hh. (This is used to keep
track of where the enclosing expression expects to see the results of
computing some subexpression.)
Tom