[antlr-interest] Changes in ASTFactory breaks custom AST classes
Ric Klaren
klaren at cs.utwente.nl
Mon Dec 9 02:16:41 PST 2002
Hi,
On Sun, Dec 08, 2002 at 02:44:46PM +0100, Marco Hunsicker wrote:
> class was expanded, but this is the one change that has bitten me).
>
>
> 2.7.2a2 looked like
> <pre>
> public AST dup(AST t) {
> return create(t); // if t==null, create returns null}
> }
> </pre>
>
>
> 2.7.2a6 does
> <pre>
> public AST dup(AST t) {
> if ( t==null ) {
> return null;
> }
> // don't just call
> AST dup_t = create(t.getClass());
> dup_t.initialize(t.getType(), t.getText());
> // ^
> // why not use initialize(t) ???
> return dup_t;
> }
> </pre>
>
>
> The problem (at least for me) lies in the fact that the duplicated
> node gets only initialized with the type and text! All other
> information stored in the original node is lost. I now simply
> override dup(AST) too, changing it back to the old behavior (I only
> use homogenous trees) but I'd rather expect dup(AST) to initialize the
> duplicated node via dup_t.initialize(t) or am I missing something here?
Hmmm I really think that should not be an initialize in there. A (near)
complete copy of the object should be made (in C++ mode I use a clone
method for it that goes through the copy constructor. Dunno if the java
clone does the same thing) The semantics of the clone in C++ are to copy
the object except for the down/right links.
This breaks all tree duplication in java mode. Terence?
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- klaren at cs.utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
Wit is cultured insolence. --- Aristotle
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list