[antlr-interest] Re: Should dup() and dupXXXX() have shallow or deep clone semantics?

micheal_jor open.zone at virgin.net
Tue Nov 12 08:12:05 PST 2002


--- In antlr-interest at y..., Ric Klaren <klaren at c...> wrote:
> On Mon, Nov 11, 2002 at 11:24:08PM -0000, micheal_jor wrote:
> > Just wondering aloud about this. I mean should object references
> > inside the AST nodes just be copied or should the objects be 
cloned
> > as well?
> >
> > What about object references to non-ANTLR types like String etc?
> >
> > I presume each call to dup()/dupXXX() be considered as making a
> > separate clone of the object/object-graph so all cloned objects 
and
> > cloned referenced objects must be unique across calls.
> 
> C++ mode uses deep copies in these modes. Also string are deep 
copied. If
> you don't clone you may get funny things. (loops, trees that modify 
by
> 'themselves' etc.)

OK. I'll have a quick look at how C++ does this. Was this feature 
already present in 2.7.2a2 or should I be looking at 2.7.2a4 only?

I guess I was worried about situations such as:

1. the nodes have direct or indirect links (via object reference 
chains) to really big object graphs such as the symbol table.

2. the nodes have bidirectional links - i.e. parent<->child and 
sibling1<->sibling2..<->..siblingN - that will effectively turn every 
dup()/dupXXX() into a full tree copy.

It's a worry that the use of these methods will incur a severe 
memory/space cost essentially. A deep clone would always deep copy 
all such linked objects too. 

>>From our initial investigations, it seems that implementing deep 
cloning semantics will have to be an all or nothing proposition in C# 
else the level of support needed in *all* classes becomes a real 
headache.

Micheal



 

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



More information about the antlr-interest mailing list