Why does astFactory-dupTree(...) work like astFactory-dupList(...)?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tobias_Lindig
Posted On:   Tuesday, February 4, 2003 09:41 AM

I need a copy of a tree (a node and his subnodes) and used the methode astFactory->dupTree(...). But in antlr2.7.2 it do not ignore the the siblings of root node and do not make a copy. I got e never ending tree. I guess the reason is the use of clone() in the astFactory->dup(...) methode. after i implemented my own copy-methode it works well. here it is: RefMy_AST copyTree(RefMy_AST source) { RefMy_AST newTree = antlr::nullAST; RefMy_AST child = antlr::nullAST; RefMy_AST childCopy = antlr::nullAST; if(source != antlr::nullAST) { //copy root-node newTree = astFactory->create(static_cast (source)); //copy subnodes chi   More>>

I need a copy of a tree (a node and his subnodes) and used the methode astFactory->dupTree(...). But in antlr2.7.2 it do not ignore the the siblings of root node and do not make a copy. I got e never ending tree. I guess the reason is the use of clone() in the astFactory->dup(...) methode.


after i implemented my own copy-methode it works well.
here it is:


			
RefMy_AST copyTree(RefMy_AST source)
{
RefMy_AST newTree = antlr::nullAST;
RefMy_AST child = antlr::nullAST;
RefMy_AST childCopy = antlr::nullAST;

if(source != antlr::nullAST)
{
//copy root-node
newTree = astFactory->create(static_cast (source));

//copy subnodes
child = source->getFirstChild();
antlr::ASTPair currentAST;
currentAST.root = newTree;
while(child != antlr::nullAST)
{
childCopy = copyTree(child);
astFactory->addASTChild( currentAST, antlr::RefAST(childCopy));

//currentAST.child = childCopy;
//this is still made in the Factory

child = child->getNextSibling();
}//END while
}

return newTree;
}


so long,

tob    <<Less
About | Sitemap | Contact