当前位置: 首页>>代码示例>>C++>>正文


C++ AST::getRootStatementNum方法代码示例

本文整理汇总了C++中AST::getRootStatementNum方法的典型用法代码示例。如果您正苦于以下问题:C++ AST::getRootStatementNum方法的具体用法?C++ AST::getRootStatementNum怎么用?C++ AST::getRootStatementNum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AST的用法示例。


在下文中一共展示了AST::getRootStatementNum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getSiblingUnknown

RELATION_LIST EvaluateSibling::getSiblingUnknown(TYPE type1,TYPE type2){
	RELATION_LIST returnList;
	if(type1==PROCEDURE&&type2==PROCEDURE){ //1. sibling ( p1,p2)
		int procTableSize = pkb->getProceTableSize();

		for(int i =1;i<=procTableSize;i++){
			for(int j =1;j<=procTableSize;j++){
				if(i!=j) returnList.push_back(pair<int,int>(i,j));
			}
		}
	}
	if(Helper::isStatement(type1)&&Helper::isStatement(type2)){//2. sibling(stmt/a/w/if/call,stmt/a/w/if/call)
		//get sequential sibling from Follows*
		returnList = EvaluateFollows::getFollowsStarResult(type1,type2);
		RELATION_LIST tempList;
		if(type1!=type2){
			tempList = EvaluateFollows::getFollowsStarResult(type2,type1);
		}else{
			tempList = returnList;
		}
		//insert reversed sibling list
		for(RELATION_LIST::iterator itr=tempList.begin();itr!=tempList.end();itr++){
			returnList.push_back(pair<int,int>(itr->second,itr->first));
		}
	}
	if(type1==VARIABLE&&type2==STMT_LIST){//3. a. sibling( x, stmtList)
		//get all the whiles
		DATA_LIST * whileList = pkb->getAllWhiles();
		for(DATA_LIST::iterator itr=whileList->begin();itr!=whileList->end();itr++){
			returnList.push_back(pair<int,int>(pkb->getWhileCtrVar(*itr),*itr+1)); // No. of stmtList = stmtNo of while+1
		}
		delete whileList;

		//get all the ifs
		DATA_LIST * ifList = pkb->getAllIfs();
		for(DATA_LIST::iterator itr=ifList->begin();itr!=ifList->end();itr++){
			AST * ifNode = NULL;
			AST_LIST * nodeList = pkb->getASTBy(*itr);
			for(AST_LIST::iterator astItr=nodeList->begin();astItr!=nodeList->end();astItr++){
				if((**astItr).getRootType()==IF){
					ifNode = *astItr;
					break;
				}
			} 

			AST * ifVarNode = ifNode->getFirstDescendant();
			AST * elseNode = ifVarNode->getRightSibling();
			AST * thenNode = elseNode->getRightSibling();

			returnList.push_back(pair<int,int>(ifVarNode->getRootData(),elseNode->getRootStatementNum()));
			returnList.push_back(pair<int,int>(ifVarNode->getRootData(),thenNode->getRootStatementNum()));
		}
		delete ifList;
	}
	if(type1==STMT_LIST&&type2==VARIABLE){ //3.b sibling(stmtList,x)
		//get all the whiles
		DATA_LIST * whileList = pkb->getAllWhiles();
		for(DATA_LIST::iterator itr=whileList->begin();itr!=whileList->end();itr++){
			returnList.push_back(pair<int,int>(*itr+1,pkb->getWhileCtrVar(*itr)));
		}
		delete whileList;

		//get all the ifs
		DATA_LIST * ifList = pkb->getAllIfs();
		for(DATA_LIST::iterator itr=ifList->begin();itr!=ifList->end();itr++){
			AST * ifNode = NULL;
			AST_LIST * nodeList = pkb->getASTBy(*itr);
			for(AST_LIST::iterator astItr=nodeList->begin();astItr!=nodeList->end();astItr++){
				if((**astItr).getRootType()==IF){
					ifNode = *astItr;
					break;
				}
			} 

			AST * ifVarNode = ifNode->getFirstDescendant();
			AST * thenNode = ifVarNode->getRightSibling();
			AST * elseNode = thenNode->getRightSibling();

			returnList.push_back(pair<int,int>(elseNode->getRootStatementNum(),ifVarNode->getRootData()));
			returnList.push_back(pair<int,int>(thenNode->getRootStatementNum(),ifVarNode->getRootData()));
		}
		delete ifList;
	}
	if(type1==STMT_LIST&&type2==STMT_LIST){ //sibling (stmtList,stmtList),only possible in If stmts
		//get all the ifs
		DATA_LIST * ifList = pkb->getAllIfs();
		for(DATA_LIST::iterator itr=ifList->begin();itr!=ifList->end();itr++){
			AST * ifNode = NULL;
			AST_LIST * nodeList = pkb->getASTBy(*itr);
			for(AST_LIST::iterator astItr=nodeList->begin();astItr!=nodeList->end();astItr++){
				if((**astItr).getRootType()==IF){
					ifNode = *astItr;
					break;
				}
			} 

			AST * ifVarNode = ifNode->getFirstDescendant();
			AST * thenNode = ifVarNode->getRightSibling();
			AST * elseNode = thenNode->getRightSibling();

//.........这里部分代码省略.........
开发者ID:benchisa,项目名称:BasicProgram,代码行数:101,代码来源:EvaluateSibling.cpp

示例2: getOneSibling

RELATION_LIST EvaluateSibling::getOneSibling(TYPE known,TYPE unknown,INDEX knownIndex,int knownPos){
	RELATION_LIST returnList;
	if(known==PROCEDURE&&unknown==PROCEDURE){ //1. sibling ( "procName",p) or sibling ( p,"procName")
		int procTableSize = pkb->getProceTableSize();

		for(int i =1;i<=procTableSize;i++){
			if(knownIndex!=i){
				if(knownPos==1){ //sibling (known,unknown)
					returnList.push_back(pair<int,int>(knownIndex,i));
				}else{ //sibling(unknown,known)
					returnList.push_back(pair<int,int>(i,knownIndex));
				}
			} 
		}
	}
	if(Helper::isStatement(known)&&Helper::isStatement(unknown)){//2. sibling(stmt/a/w/if/call,stmt/a/w/if/call), either field is unknown
		if(knownPos==1){
			//get sequential sibling from Follows*
			returnList = EvaluateFollows::getFollowsStarResult(unknown,knownIndex,0);
			//get sibling in front of the knownIndex
			RELATION_LIST tempList = EvaluateFollows::getFollowsStarResult(unknown,0,knownIndex);
			for(RELATION_LIST::iterator itr=tempList.begin();itr!=tempList.end();itr++){
				returnList.push_back(pair<int,int>(knownIndex,itr->first));
			}
		}else{
			//get sibling before current index from Follows*
			returnList = EvaluateFollows::getFollowsStarResult(unknown,0,knownIndex);
			//get sequential siblings
			RELATION_LIST tempList = EvaluateFollows::getFollowsStarResult(unknown,knownIndex,0);
			for(RELATION_LIST::iterator itr=tempList.begin();itr!=tempList.end();itr++){
				returnList.push_back(pair<int,int>(itr->second,knownIndex));
			}
		}
	}
	if(known==VARIABLE&&unknown==STMT_LIST){//3. a. sibling( "x", stmtList) or sibling(stmtList,"x")
		//sibling("x",stmtList)
		//get all the whiles
		DATA_LIST * whileList = pkb->getAllWhiles();
		for(DATA_LIST::iterator itr=whileList->begin();itr!=whileList->end();itr++){
			if(pkb->getWhileCtrVar(*itr)==knownIndex){
				if(knownPos==1)	
					returnList.push_back(pair<int,int>(knownIndex,*itr+1));
				else
					returnList.push_back(pair<int,int>(*itr+1,knownIndex));
			}
		}
		delete whileList;

		//get all the ifs
		DATA_LIST * ifList = pkb->getAllIfs();
		for(DATA_LIST::iterator itr=ifList->begin();itr!=ifList->end();itr++){
			AST * ifNode = NULL;
				AST_LIST * nodeList = pkb->getASTBy(*itr);
				for(AST_LIST::iterator astItr=nodeList->begin();astItr!=nodeList->end();astItr++){
					if((**astItr).getRootType()==IF){
						ifNode = *astItr;
						break;
					}
				} 

			AST * ifVarNode = ifNode->getFirstDescendant(); 
			AST * thenNode = ifVarNode->getRightSibling();
			AST * elseNode = thenNode->getRightSibling();

			if(ifVarNode->getRootData()==knownIndex){
				if(knownIndex==1){
					returnList.push_back(pair<int,int>(knownIndex,thenNode->getRootStatementNum()));
					returnList.push_back(pair<int,int>(knownIndex,elseNode->getRootStatementNum()));
				}else{
					returnList.push_back(pair<int,int>(thenNode->getRootStatementNum(),knownIndex));
					returnList.push_back(pair<int,int>(elseNode->getRootStatementNum(),knownIndex));
				}
			}
		}
		delete ifList;
		
	}
	if(known==STMT_LIST&&unknown==VARIABLE){//3.b sibling(x,2) or sibling(2,x) where 2 is stmtList no.
		AST * stmtListNode = NULL;
		AST_LIST * nodeList = pkb->getASTBy(knownIndex);
		for(AST_LIST::iterator astItr=nodeList->begin();astItr!=nodeList->end();astItr++){
			if((**astItr).getRootType()==STMT_LIST){
				stmtListNode = *astItr;
				break;
			}
		} 
		if(stmtListNode!=NULL){
			AST * varNode = stmtListNode->getFirstDescendant();

			if(varNode->getRootType()==VARIABLE){
				if(knownPos==1)
					returnList.push_back(pair<int,int>(knownIndex,varNode->getRootData()));
				else
					returnList.push_back(pair<int,int>(varNode->getRootData(),knownIndex));
			}
		}
	}
	if(known==STMT_LIST&&unknown==STMT_LIST){ //sibling (stmtList,2) or sibling(2,stmtList)
		//get all the ifs
			DATA_LIST * ifList = pkb->getAllIfs();
//.........这里部分代码省略.........
开发者ID:benchisa,项目名称:BasicProgram,代码行数:101,代码来源:EvaluateSibling.cpp


注:本文中的AST::getRootStatementNum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。