void KTREE::preorder_traversal() { TNode *tmp; //pre order tmp=top; if (top==0) cout <<"empty tree !!!"<<endl; else { cout <<tmp->getElement()<<" "; for (int i=0;i<MAX;i++) if (top->getChild(i)!=0) preorder_traversal(top->getChild(i)); } cout<<endl; }
void KTREE::insert (TNode* node,int ch) { TNode* tmp; //insert to tree point=top; if (top==0) { top=new TNode(); top->setElement(node->getElement()); top->setParent(0); for (int i=0;i<MAX;i++) top->setChild(node->getChild(i),i); point=top; } else { while (point!=0) { tmp=point; point=point->getChild(ch); } point=tmp; addLeaf(node,ch); } }
void KTREE::postorder_traversal() { //postorder TNode *tmp; tmp=top; int i; if (top==0) cout <<"empty tree !!!"<<endl; else { for (i=0;i<MAX;i++) { if (top->getChild(i)!=0) postorder_traversal(top->getChild(i)); } cout <<" "<<top->getElement(); } cout<<endl; }
vector<std::shared_ptr<CFG>> NextExtractor::constructCFG() { int numOfProc = procTable->getSize(); for(int i =0; i < numOfProc; i++) { TNode* curTNode = this->procTable->getASTRootNode(i); shared_ptr<GNode> curGNodeParent = std::make_shared<GNode>(0, "PROC_NODE"); //create a CFG ROOT node nodeMap.insert(pair<int, shared_ptr<GNode>>(curGNodeParent->getStmtNum(), curGNodeParent)); shared_ptr<CFG> cfg = std::make_shared<CFG>(curGNodeParent); //create a CFG with procedure node as parameters shared_ptr<stack<shared_ptr<GNode>>> level = std::make_shared<stack<shared_ptr<GNode>>>(); shared_ptr<GNode> lastNode = converseAST(cfg,curTNode->getChild(0),curGNodeParent,level); //conversing start with node below procedure CFGTable.push_back(cfg); } return CFGTable; }