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

Ric Klaren klaren at cs.utwente.nl
Thu Jun 19 03:18:45 PDT 2003


Hi,

On Wed, Jun 18, 2003 at 04:15:16PM -0400, Tiller, Michael (M.M.) wrote:
> 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);
>      }

It looks like you're modifying the tree while you're stepping through it?
I'm not sure if that will work... Try turning off AST generation for the
declaration rule. Then collect the trees generated by prefix/type/comp_list
(basically what you're already doing now). Then use a loop to insert copies
of all the parts you are glueing together. Something like (abbreviated the
duptrees):

RefAST nchild = #( duptree(cur), duptree(#pre), duptree(#type) );
#declaration = #( nullAST, #declaration, nchild );

The above may need some tweaking. I'm not a big star in writing AST
construction stuff. The nullAST thing adds them as siblings to the returned
tree if I recall right.

Also grab the print_tree template from

http://wwwhome.cs.utwente.nl/~klaren/antlr/print_tree.h

It prints out a more or less readable dump of an AST tree so you can see
what happens while copying, or between operations.

Other idea is to open up the component_list rule safes you the manual
traversal of the list:

declaration!
  : pre:prefix type:type ( comp:component
		{
			#declaration = #( nullAST, #declaration,
						#( duptree(#pre), duptree(#type), duptree(#comp) ) );
		}
		)+
  ;

> 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'm afraid we have to live with those in the 2.x.x series.

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

The dev snapshot contains some fixes to the RefCounter. So I'd definitely
grab it (non serious though only memory leak if I recall right). Might look
at a diff between the release version you have now and the support lib and
manually port over.

Add default comment about bugreports. Compiler/system/error output. This is
not helping I'm afraid.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at 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