[antlr-interest] Re: Changes in ASTFactory breaks custom AST classes

micheal_jor <open.zone at virgin.net> open.zone at virgin.net
Tue Dec 10 05:06:24 PST 2002


> > The only problem is that in java, clone will dup the thing bit-by-
bit
> > and then I'll have to wack the pointers to null and also it won't 
go
> > thru the create() method of the factory.
> 
> Yeah, that's why the copy constructor in C++ does not copy the 
left/right
> pointers.

ASTFactory in C# uses copy constructors as well but the down/right 
pointers are copied due to my [misguided?] believe that since only 
dupTree()/dupList() use dup() and, they already set the down/right 
pointers, there's no problem there. I'll change this to ignore these 
fields (or perhaps simply reset them in dup() after the full clone. 
What do you think?

As for going through a create(), we are cloning an instance rather 
than creating one right....

> > Gotta be consistent I'd say. Make sense?
> 
> Hmmm C++ mode does not go through create for the dups but does 
straight
> clones. Consistency is a point yes. Then again I don't really like 
the dups
> in the factory. I'll have a look one of these days.

Cloning-by-copy-construction ensures that the semantics of cloning 
(specified in the copy constructor chain) are separated from the 
semantics of initialization (specified in initialize() methods) -- 
e.g. clone() wouldn't normally copy any AST node pointers (including 
down/right) to avoid aliasing issues with tree parser transformations 
but initialize() might normally copy such nodes (but not down/right).

The semi-deep cloning semantics of dupXXX() are trouble enough to be 
worth isolating in my opinion.

Micheal



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list