[antlr-interest] Cloning/dup* seriously broken for C++???

Tiller, Michael (M.M.) mtiller at ford.com
Wed Jun 18 13:15:16 PDT 2003


I have spent my entire day trying to figure out how to do something that should be really simple.  I've got a declaration statement, essentially it looks like this:
 
declaration
  : pre:prefix type:type list:component_list
  ;
 
Now I need to iterate over component_list and add a *COPY* of prefix and type as children of each node in component_list.  I have tried a dozen ways of doing this and none of them have worked.  Here are a few examples:
 
     for(antlr::RefAST cur=#list;cur!=antlr::nullAST;cur=cur->getNextSibling()) {
                cur->addChild(#([DECL_TYPE_INFO, "TypeInfo"],
                        astFactory->dupTree(#pre),
                        astFactory->dupTree(#type))));
     }
 
     for(antlr::RefAST cur=#list;cur!=antlr::nullAST;cur=cur->getNextSibling()) {
                cur->addChild(#pre->clone());
                cur->addChild(#type->clone());
     }
 
     for(antlr::RefAST cur=#list;cur!=antlr::nullAST;cur=cur->getNextSibling()) {
                cur->addChild(#pre);
                cur->addChild(#type);
     }
 
    ...etc...
 
All these problems see to stem from the (sorry I have to say it) extremely complicated family of types including (but not limited to): ASTRef, ASTRefCount, RefAST, RefMyCustomNodeAST, AST, BaseAST, CommonAST, etc. :-)
 
I can certainly understand why the ASTRefCount class keeps a count on the references to a particular pointer.  I'm familiar with this kind of "smart pointer".  What I found very strange is that the pointer has to keep a pointer back to ASTRefCount?!?!?!?  This seems to be the cause of my tremendous confusion (I would create an ASTRef and pass a pointer into its constructor and then when I did a get() on the reference, it gave me a pointer to a completely different object!!!!).
 
I tried the recently announced development snapshot but I couldn't get it to run.  Does anybody have a fix for this issue?!?  I'm completely stuck!!!  I cannot move forward on this project until I have some kind of workaround.
 
Thanks for any help.
 
--
Mike
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030618/68bdd6e2/attachment.html


More information about the antlr-interest mailing list