[antlr-interest] Re: Should dup() and dupXXXX() have shallow or deep clone semantics?
Ric Klaren
klaren at cs.utwente.nl
Tue Nov 12 08:55:56 PST 2002
Hi,
On Tue, Nov 12, 2002 at 04:12:05PM -0000, micheal_jor wrote:
> 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?
2.7.2a2 should have it.. Maybe a small bugfix here and there not sure.
> 1. the nodes have direct or indirect links (via object reference
> chains) to really big object graphs such as the symbol table.
In that case the user would have to supply a good copy constructor that
does the right thing. The dupXXX's in C++ just call the clone method of a
AST and that one generally uses a copy constructor.
> 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.
Hmmm standard antlr has no back links. And probably the dup algorithms
can't handle those properly. And I don't know what the use is of dupping to
a level higher than the node you are starting the duplicate with. Generally
when you dup a bit I'd suspect you're only interested in the subtree.
Anyway on a different line of thought the dup methods IMHO don't belong in
the factory anyway. No part of antlr's generated code uses them as well
(AFAIK). It's a bunch of convenience functions. The combination of 2.7.0/1,
dupXXX and heterogeneous ASTs was even pretty much broken anyway (C++ maybe
even other codegen).
> 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.
That's one of the risks of duplicating stuff. Then again ANTLR generated
code doesn't use the dup methods. And it's probably not a good idea to
invest a lot of time in making them 100% idiot proof, they should be
AST/BaseAST/CommonAST proof (well at least that's my view of them), then
again it's not my time ;)
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
Chaos often breeds life, when order breeds habit.
--- Henry B. Adams, The Education of Henry Adams
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list