Exemplo n.º 1
0
// Case: Uses(s,'x') - stmt wild, var fixed
Results UsesClause::evaluateStmtWildVarFixed() {
	Results res = Results();
	// set synonyms
	res.setNumOfSyn(1);
	res.setFirstClauseSyn(this->getFirstArg());

	// get the fixed var and usedby
	Variable* fixedVar = varTable->getVariable(this->getSecondArg());
	set<int>::iterator stmtIter;
	if(fixedVar == NULL) {
		res.setClausePassed(false);
		return res;
	}
	set<int> stmtSet = fixedVar->getUsedByStmts();

	// check set for results
	if(stmtSet.size() != 0) {
		res.setClausePassed(true);
		for(stmtIter=stmtSet.begin(); stmtIter!=stmtSet.end(); stmtIter++) {
			Statement* currentStmt = stmtTable->getStmtObj(*stmtIter);
			// check if current stmt conforms to specific stmt type
			if(Utils::isSameType(this->firstArgType, currentStmt->getType())) {
				res.addSingleResult(lexical_cast<string>(*stmtIter));
			}
		}
	}

	return res;
}
Exemplo n.º 2
0
// Case: Uses(1,v) - stmt fixed, var wild
Results UsesClause::evaluateStmtFixedVarWild() {
	Results res = Results();
	// set synonyms
	if(this->getSecondArgType() == ARG_GENERIC) {
		res.setNumOfSyn(0);
	} else {
		res.setNumOfSyn(1);
		res.setFirstClauseSyn(this->getSecondArg());
	}

	// get relevant stmts
	string firstArgType = this->getFirstArgType();
	set<Statement*>::iterator stmtIter;
	set<Statement*> stmtSet;
	if(firstArgType == ARG_WHILE) {				// only while stmts
		stmtSet = stmtTable->getWhileStmts();
	} else if(firstArgType == ARG_ASSIGN) {		// only assign stmts
		stmtSet = stmtTable->getAssgStmts();
	} else {													// all types of stmts
		stmtSet = stmtTable->getAllStmts();
	}

	int stmtNum = lexical_cast<int>(this->getFirstArg());

	// check stmts
	for(stmtIter=stmtSet.begin(); stmtIter!=stmtSet.end(); stmtIter++) {
		// current stmt
		Statement* currentStmt = *stmtIter;
		if(currentStmt->getStmtNum() == stmtNum) {
			// get set of variables current stmt uses
			Statement::UsesSet currentUses = currentStmt->getUses();

			// check if stmt uses any variable
			if(currentUses.size() != 0) {
				res.setClausePassed(true);

				if(this->getSecondArgType() != ARG_GENERIC) {
					// add all pairs into results
					Statement::UsesSet::iterator setIter;
					for(setIter=currentUses.begin(); setIter!=currentUses.end(); setIter++) {
						res.addSingleResult(*setIter);
					}
				}
			}
		}
	}

	vector<string> temp1 = res.getSinglesResults();
	vector<pair<string,string>> temp2 = res.getPairResults();
	Utils::removeVectorDupes(temp1);
	Utils::removeVectorDupes(temp2);
	res.setSingleResult(temp1);
	res.setPairResult(temp2);

	return res;
}
Exemplo n.º 3
0
Results* ParentClause::evaluateS1WildS2Fixed(string firstArgSyn, string secondArgSyn) {
	Results* resultsObj = new Results();
	int stmt1 = getParent(atoi(secondArgSyn.c_str()));
	if (stmt1 != -1) {
		resultsObj->setClausePassed(true);
		resultsObj->setNumOfSyn(1);
		resultsObj->setFirstClauseSyn(firstArgSyn);
		resultsObj->addSingleResult(boost::lexical_cast<string>(stmt1));
	}
	return resultsObj;
}
Exemplo n.º 4
0
Results* ParentClause::evaluateS1FixedS2Wild(string firstArgSyn, string secondArgSyn, string secondArgType) {
	Results* resultsObj = new Results();
	set<int> children = getChildren(firstArgSyn, secondArgType);
	if (!children.empty()) {
		resultsObj->setClausePassed(true);
		resultsObj->setNumOfSyn(1);
		resultsObj->setFirstClauseSyn(secondArgSyn);
		for (set<int>::iterator it = children.begin(); it != children.end(); ++it) {
			resultsObj->addSingleResult(boost::lexical_cast<string>(*it));
		}
	}
	return resultsObj;
}
Exemplo n.º 5
0
// Case: Uses(s,'x') - stmt wild, var fixed
Results UsesClause::evaluateStmtWildVarFixed() {
	Results res = Results();
	// set synonyms
	if(this->getFirstArgType() == ARG_GENERIC) {
		res.setNumOfSyn(0);
	} else {
		res.setNumOfSyn(1);
		res.setFirstClauseSyn(this->getFirstArg());
	}

	// get the fixed var and usedby
	Variable* fixedVar = varTable->getVariable(this->getSecondArg());
	set<int>::iterator stmtIter;
	if(fixedVar == NULL) {
		res.setClausePassed(false);
		return res;
	}
	set<int> stmtSet = fixedVar->getUsedByStmts();

	// check set for results
	if(stmtSet.size() != 0) {
		res.setClausePassed(true);

		if(this->getFirstArgType() != ARG_GENERIC) {
			for(stmtIter=stmtSet.begin(); stmtIter!=stmtSet.end(); stmtIter++) {
				Statement* currentStmt = stmtTable->getStmtObj(*stmtIter);
				// check if current stmt conforms to specific stmt type
				if((this->firstArgType==ARG_GENERIC) || (Utils::isSameType(this->firstArgType, currentStmt->getType()))) {
					res.addSingleResult(lexical_cast<string>(*stmtIter));
				}
			}
		}
	}

	vector<string> temp1 = res.getSinglesResults();
	vector<pair<string,string>> temp2 = res.getPairResults();
	Utils::removeVectorDupes(temp1);
	Utils::removeVectorDupes(temp2);
	res.setSingleResult(temp1);
	res.setPairResult(temp2);

	return res;
}
Exemplo n.º 6
0
// PRIVATE FUNCTIONS
// Case: Uses(s,v) - stmt wild, var wild
Results UsesClause::evaluateStmtWildVarWild() {
	Results res = Results();
	// set synonyms
	string firstType = this->getFirstArgType();
	string secondType = this->getSecondArgType();
	if(firstType==ARG_GENERIC && secondType==ARG_GENERIC) {
		res.setNumOfSyn(0);
	} else if(firstType==ARG_GENERIC || secondType==ARG_GENERIC) {
		res.setNumOfSyn(1);
		if(firstType!=ARG_GENERIC) {
			res.setFirstClauseSyn(this->getFirstArg());
		} else {
			res.setFirstClauseSyn(this->getSecondArg());
		}
	} else {
		res.setNumOfSyn(2);
		res.setFirstClauseSyn(this->getFirstArg());
		res.setSecondClauseSyn(this->getSecondArg());
	}

	// generate all possible combinations using stmtTable as reference
	set<Statement*> allStmts = stmtTable->getAllStmts();
	set<Statement*>::iterator stmtIter;
	
	// iterate through stmt table
	for(stmtIter=allStmts.begin(); stmtIter!=allStmts.end(); stmtIter++) {
		Statement* currentStmt = *stmtIter;

		// check if current stmt conforms to specific stmt type, if not, skip to next statement
		if((this->firstArgType!=ARG_GENERIC) && !Utils::isSameType(this->firstArgType, currentStmt->getType())) {
			continue;
		}
		
		// for each stmt generate result pair for vars that it uses
		Statement::UsesSet currentUseSet = currentStmt->getUses();
		Statement::UsesSet::iterator useIter;

		for(useIter=currentUseSet.begin(); useIter!=currentUseSet.end(); useIter++) {
			string stmtNum = lexical_cast<string>(currentStmt->getStmtNum());
			string var = *useIter;

			// add results depending on whether generics are present
			if(firstType == ARG_GENERIC && secondType != ARG_GENERIC) {
				res.addSingleResult(var);
			} else if(firstType != ARG_GENERIC && secondType == ARG_GENERIC) {
				res.addSingleResult(stmtNum);
			} else if(firstType != ARG_GENERIC && secondType != ARG_GENERIC) {
				res.addPairResult(stmtNum, var);
			}

			res.setClausePassed(true);
		}
	}

	vector<string> temp1 = res.getSinglesResults();
	vector<pair<string,string>> temp2 = res.getPairResults();
	Utils::removeVectorDupes(temp1);
	Utils::removeVectorDupes(temp2);
	res.setSingleResult(temp1);
	res.setPairResult(temp2);

	return res;
}