Esempio n. 1
0
void DesignExtractor::computeCFGBip(){
	//take exsiting graph and insert into new graph
	vector<vector<CFGLink>> graphBip;
	int numOfProc = procTable->getNoOfProc();
	PROCLIST procList = procTable->getAllProcNames();
	vector<pair<int,int>> * graphCFG = procTable->getCFG(1)->getCFG();
	int numOfStmt = procTable->getLastStmt(*(procList.end()-1));

	//translate old graph into new graph
	for(int i = 0; i < graphCFG->size(); i++){
		int firstLink = graphCFG->at(i).first;
		int secondLink = graphCFG->at(i).second;
		
		vector<CFGLink> currStmt;

		if(firstLink != 0){
			currStmt.push_back(CFGLink(firstLink, 0));
		}

		if(secondLink != 0){
			currStmt.push_back(CFGLink(secondLink, 0));
		}

		graphBip.push_back(currStmt);
	}

	//set dummy nodes
	vector<CFGLink> aLink;
	for(int i = 0; i < numOfProc; i++){
		graphBip.push_back(aLink);
	}

	//procedure's corresponding dummy node is
	//lastStmtNum + procIndex + 1
	for(int i = 0; i < graphCFG->size(); i++){
		int firstLink = graphCFG->at(i).first;
		int secondLink = graphCFG->at(i).second;

		if(firstLink == -1 || secondLink == -1){
			//get procedure's corresponding dummy node
			PROCINDEX procIndex = procTable->getProcIndex(getProcedure(i));

			//point curr stmt to dummy node instead
			if(firstLink == -1){
				graphBip.at(i).at(0).setLinkTo(numOfStmt + procIndex + 1);
			}
			else{
				graphBip.at(i).at(1).setLinkTo(numOfStmt + procIndex + 1);
			}
		}
	}

	//by now, we have a CFG Bip graph that is equivalent of CFG graph, but with links that are (stmt,0), and dummy nodes 
	//now we go thru 1 pass to link call nodes and dummy nodes
	for(int i = 1; i <= numOfStmt; i++){
		//if it's a call node
		if(ast->getNodeType(i) == "callNode"){
			//we store the curr next link
			int currNextLink = graphBip.at(i).at(0).getLinkTo();

			//we connect curr link to the corresponding procedure node
			TNode currNode = ast->getStmtNode(i);
			PROCNAME calledProc = currNode.getNodeValue();
			int firstStmt = procTable->getFirstStmt(calledProc);
			graphBip.at(i).at(0).setLinkTo(firstStmt);
			graphBip.at(i).at(0).setEdgeNumber(i);

			//we check if procedure has a dummy, if so we connect using the dummy
			if(hasDummy(calledProc, numOfStmt, graphCFG)){
				PROCINDEX procIndex = procTable->getProcIndex(calledProc);
				graphBip.at(numOfStmt+procIndex+1).push_back(CFGLink(currNextLink, i));
			}
			else{
			//otherwise we use the current procedure's last statement
				int procLastStmt = procTable->getLastStmt(calledProc);
				graphBip.at(procLastStmt).push_back(CFGLink(currNextLink, i));
			}
		}
	}

	//this->cfgBip = graphBip;

	pkb->setCFGBip(graphBip);

	//printing for debugging
	//print graphCFG
	for(int i = 0; i < graphCFG->size(); i++){
		cout << i << " -> " << graphCFG->at(i).first << " " << graphCFG->at(i).second << endl;
	}

	//print graphBip
	for(int i = 0; i < graphBip.size(); i++){
		cout << i << " -> |";
		for(int j = 0; j < graphBip.at(i).size(); j++){
			cout << graphBip.at(i).at(j).getLinkTo() << "," << graphBip.at(i).at(j).getEdgeNumber() << "|";
		}
		cout << endl;
	}
}
void TPlayerInterface::init(TPlayerHandle playerModuleHandle)
{
	if(m_IsInitialized) return;
	KASSERT(playerModuleHandle != NULL, "Player module handle was not set.", "Set a valid player module handle.", ET_PROGENGINE, SL_ERROR);

	m_PlayerHandle = playerModuleHandle;

	m_RequestBalance = (TRequestBalance)getProcedure(m_PlayerHandle, "requestBalance");
	if(m_RequestBalance == NULL) handleError("requestBalance");
	m_GetPPMState = (TGetPPMState)getProcedure(m_PlayerHandle, "getPPMState");
	if(m_GetPPMState == NULL) handleError("getPPMState");
	m_StartPPM = (TStartPPM)getProcedure(m_PlayerHandle, "startPPM");
	if(m_StartPPM == NULL) handleError("startPPM");
	m_StopPPM = (TStopPPM)getProcedure(m_PlayerHandle, "stopPPM");
	if(m_StopPPM == NULL) handleError("stopPPM");
	m_GetPPMCost = (TGetPPMCost)getProcedure(m_PlayerHandle, "getPPMCost");
	if(m_GetPPMCost == NULL) handleError("getPPMCost");
	m_GetUserInfo = (TGetUserInfo)getProcedure(m_PlayerHandle, "getUserInfo");
	if(m_GetUserInfo == NULL) handleError("getUserInfo");
	m_GetApplicationInfo = (TGetApplicationInfo)getProcedure(m_PlayerHandle, "getApplicationInfo");
	if(m_GetApplicationInfo == NULL) handleError("getApplicationInfo");
	m_GetSessionInfo = (TGetSessionInfo)getProcedure(m_PlayerHandle, "getSessionInfo");
	if(m_GetSessionInfo == NULL) handleError("getSessionInfo");
	m_SendAppStatistics = (TSendAppStatistics)getProcedure(m_PlayerHandle, "sendAppStatistics");
	if(m_SendAppStatistics == NULL) handleError("sendAppStatistics");
	m_SendXmlData = (TSendXmlData)getProcedure(m_PlayerHandle, "sendXmlData");
	if(m_SendXmlData == NULL) handleError("sendXmlData");
	m_RequestXmlData = (TRequestXmlData)getProcedure(m_PlayerHandle, "requestXmlData");
	if(m_RequestXmlData == NULL) handleError("requestXmlData");
	m_RequestAppQuantityRatio = (TRequestAppQuantityRatio)getProcedure(m_PlayerHandle, "requestAppQuantityRatio");
	if(m_RequestAppQuantityRatio == NULL) handleError("requestAppQuantityRatio");
	m_RequestUserInfo = (TRequestUserInfo)getProcedure(m_PlayerHandle, "requestUserInfo");
	if(m_RequestUserInfo == NULL) handleError("requestUserInfo");
	m_AddCallback = (TAddCallback)getProcedure(m_PlayerHandle, "addCallback");
	if(m_AddCallback == NULL) handleError("addCallback");
	m_CallBrowser = (TCallBrowser)getProcedure(m_PlayerHandle, "call");
	if(m_CallBrowser == NULL) handleError("call");
	m_RequestPackage = (TRequestPackage)getProcedure(m_PlayerHandle, "requestPackage");
	if(m_RequestPackage == NULL) handleError("requestPackage");
	m_RequestPackageCheck = (TRequestPackageCheck)getProcedure(m_PlayerHandle, "requestPackageCheck");
	if(m_RequestPackageCheck == NULL) handleError("requestPackageCheck");
	m_HasPackage = (THasPackage)getProcedure(m_PlayerHandle, "hasPackage");
	if(m_HasPackage == NULL) handleError("hasPackage");
	m_GetRequestedPackagesSize = (TGetRequestedPackagesSize)getProcedure(m_PlayerHandle, "getRequestedPackagesSize");
	if(m_GetRequestedPackagesSize == NULL) handleError("getRequestedPackagesSize");
	m_AddLogFileName = (TAddLogFileName)getProcedure(m_PlayerHandle, "addLogFileName");
	if(m_AddLogFileName == NULL) handleError("addLogFileName");
	m_RequestCredentials = (TRequestCredentials)getProcedure(m_PlayerHandle, "requestCredentials");
	if(m_RequestCredentials == NULL) handleError("requestCredentials");	
	m_RequestCredentialsFrom = (TRequestCredentialsFrom)getProcedure(m_PlayerHandle, "requestCredentialsFrom");
	if(m_RequestCredentialsFrom == NULL) handleError("requestCredentialsFrom");
	m_RequestAdvertisement = (TRequestAdvertisement)getProcedure(m_PlayerHandle, "requestAdvertisement");
	if(m_RequestAdvertisement == NULL) handleError("requestAdvertisement");	
	m_DownloadKCPFile = (TDownloadKCPFilePtr)getProcedure(m_PlayerHandle, "downloadKCPFile");
	if(m_DownloadKCPFile == NULL) handleError("downloadKCPFile");	
	m_SetPackagePriority = (TSetPackagePriority)getProcedure(m_PlayerHandle, "setPackagePriority");
	if(m_SetPackagePriority == NULL) handleError("setPackagePriority");
	m_SetDefaultPackagePriority = (TSetDefaultPackagePriority)getProcedure(m_PlayerHandle, "setDefaultPackagePriority");
	if(m_SetDefaultPackagePriority == NULL) handleError("setDefaultPackagePriority");
	m_SetReservedAppBandwidth = (TSetReservedAppBandwidth)getProcedure(m_PlayerHandle, "setReservedAppBandwidth");
	if(m_SetReservedAppBandwidth == NULL) handleError("setReservedAppBandwidth");
	m_CancelPackageRequest = (TCancelPackageRequest)getProcedure(m_PlayerHandle, "cancelPackageRequest");
	if(m_CancelPackageRequest == NULL) handleError("cancelPackageRequest");
	m_PausePackageRequest = (TPausePackageRequest)getProcedure(m_PlayerHandle, "pausePackageRequest");
	if(m_PausePackageRequest == NULL) handleError("pausePackageRequest");
	m_ResumePackageRequest = (TResumePackageRequest)getProcedure(m_PlayerHandle, "resumePackageRequest");
	if(m_ResumePackageRequest == NULL) handleError("resumePackageRequest");
	m_CallOnAppThread = (TCallOnAppThreadPtr)getProcedure(m_PlayerHandle, "callOnAppThread");
	if(m_CallOnAppThread == NULL) handleError("callOnAppThread");

	m_IsInitialized = true;
}