Example #1
0
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;
	}
Example #2
0
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);
		
		}
	}
Example #3
0
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;
	}
Example #4
0
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;
}