[antlr-interest] Re: How to copy/reference hidden tokens in transformations
Bryan
ewbank at synopsys.com
Tue Nov 16 10:24:39 PST 2004
Monty Zukowski said:
> There is a method to override called initialize(AST node) which is
> called to let you copy your stuff over. For example see
> TNode.java in the GCC toolkit distribution.
There's a minor gotcha, at least in C++. You need to match the
prototype exactly -- the argument for initialize must be the same
as that in the base class, not your new node type; otherwise, it is
not overloaded and the new function is bypassed.
I'd originally used my new class as the argument to the initialize()
function, but that doesn't work - it does not correctly overload the
function in the base class. You must use the same prototype.
Once I realized that, my iniitalize function worked, but it's a bit
more obsure:
95 // overload base class - prototype must match exactly to
96 // intercept generated calls.
97 virtual void
98 TreeNode::initialize(ANTLR_USE_NAMESPACE(antlr)RefAST node)
99 {
100 CommonAST::initialize(node);
101 // need to change the type to get at the new members
102 RefTreeNode t = RefTreeNode(node);
103 setSubtype(t->getSubtype());
104 }
I'm sure there are other, and better, ways to deal with this, but
this seems to be working for me..
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list