SgNode* SgNode::CopyTree() const { SgNode* newNode = new SgNode(); if (newNode) { newNode->CopyAllPropsFrom(*this); CopySubtree(this, newNode); } return newNode; }
void SgNode::CopySubtree(const SgNode* node, SgNode* copy) { for (const SgNode* son = node->LeftMostSon(); son; son = son->RightBrother()) { SgNode* sonCopy = copy->NewRightMostSon(); sonCopy->CopyAllPropsFrom(*son); CopySubtree(son, sonCopy); } }