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

Ric Klaren klaren at cs.utwente.nl
Fri Dec 13 05:13:18 PST 2002


Hi,

On Tue, Dec 10, 2002 at 01:06:24PM -0000, micheal_jor <open.zone at virgin.net> wrote:
> 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?

This was also my first implementation. There were problems with it exact
circumstances I'd have to look up. But it went wrong somewhere. Of course
this may depend a bit on actual implementations YMMV etc. In general it
doesn't make sense to copy the down/right pointers since they will point
into another tree. And doing a recursive copy is probably also not what you
want (in the general case).

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

This is also a bit more my feel about it. It may be that this is a 'taste'
question. So far I don't really feel like routing the C++ clone's through
the initialize stuff. In general in C++ doing clone's via copy constructors
is the right-thing (tm), so I'll go with what a C++ user expects from these
beasts. We'll probably see more digression between C++ and Java in the
future anyway.

> > > 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.

I'm thinking of putting them into the antlr namespace as normal functions.
They're not really factory things.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  "You know how to use that thing?" [pointing to the sword]
  "Sure.. The pointy end goes into the other guy."
  --- The Mask of Zorro


 

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



More information about the antlr-interest mailing list