Results* ParentClause::addParentPairToResult(set<Statement*> containerStmts, NodeType type) { Results* resultsObj = new Results(); for (set<Statement*>::iterator containerIter = containerStmts.begin(); containerIter != containerStmts.end(); containerIter++) { Statement* containerStmt = *containerIter; string containerStmtNo = boost::lexical_cast<string>(containerStmt->getStmtNum()); set<int> children; if (type == NULL_) { children = containerStmt->getChildren(); } else { children = Utils::filterStatements(containerStmt->getChildren(), type); } if (!children.empty()) { resultsObj->setClausePassed(true); for (set<int>::iterator childrenIter = children.begin(); childrenIter != children.end(); childrenIter++) { string childStmtNo = boost::lexical_cast<string>(*childrenIter); resultsObj->addPairResult(containerStmtNo, childStmtNo); } } } return resultsObj; }
// PRIVATE FUNCTIONS // Case: Uses(s,v) - stmt wild, var wild Results UsesClause::evaluateStmtWildVarWild() { Results res = Results(); // set synonyms 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(!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; res.addPairResult(stmtNum, var); } } // checks if result is empty if(res.getPairResults().size() != 0) { res.setClausePassed(true); } return res; }
// 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; }