Esempio n. 1
0
void SkinContext::updateVariables(const QDomNode& node) {
    QDomNode child = node.firstChild();
    while (!child.isNull()) {
        if (child.isElement() && child.nodeName() == "SetVariable") {
            updateVariable(child.toElement());
        }
        child = child.nextSibling();
    }
}
void AffectEngine::run() {

	// if it's procedure and variable combination
	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	

	FastSearchInteger second;
	FastSearchInteger first;

	// there is no need to check if both is underscore
	if (astParam1->getParameterType() == VT_UNDERSCORE && astParam2->getParameterType() == VT_UNDERSCORE) {
		/*if (pkbManager->getFollows()->IsThereFollow) 
		failed = false;
		else
		failed true;*/
		failed = !pkbManager->getAffects()->exists();

		return;
	}



	if (astParam1->getParameterType() == VT_UNDERSCORE) 
		CommonUtility::convertToMap(myQM->getAllStatementList(), first);
	else
		loadVariable(0, first);



	if (astParam2->getParameterType() == VT_UNDERSCORE) 
		CommonUtility::convertToMap(myQM->getAllStatementList(), second);
	else 
		loadVariable(1, second);



	FastSearchString finalListOne;
	FastSearchString finalListTwo; 

	FastSearchInteger::iterator iter;
	vector<int>::const_iterator iterParentList;
	FastSearchInteger::iterator iterSecond;

	bool exist;
	bool keepRelationship = astParam1->updateAble() && astParam2->updateAble() ;

	vector<pair<string, string>> resultList;

	if (first.size() < second.size()) {
		for (iter = first.begin();  iter != first.end(); iter++) { // for every statement find the modified value

			vector<int> &childList = pkbManager->getAffects()->getAffects(iter->first);
			exist = false;

			for (iterParentList = childList.begin(); iterParentList  != childList.end(); iterParentList++) { // for each variable returned check against the variable list
				iterSecond = second.find(*iterParentList);

				if (iterSecond != second.end()) {
					exist = true;

					if (keepRelationship)
						resultList.push_back(pair<string, string>(CommonUtility::NumberToString(iter->first), CommonUtility::NumberToString(iterSecond->first)));					
					else if (astParam2->updateAble()) 
						finalListTwo[CommonUtility::NumberToString(iterSecond->first)] = true;
					else if (!astParam1->updateAble()) {
						return; // both are not updatable. 
					}								
				}
			}
			if (exist && !keepRelationship && astParam1->updateAble()) 
				finalListOne[CommonUtility::NumberToString(iter->first)] = true;


		}
	} else {
			for (iterSecond = second.begin();  iterSecond != second.end(); iterSecond++) { // for every statement find the modified value

				vector<int> &childList = pkbManager->getAffects()->getAffected(iterSecond->first);
			exist = false;

			for (iterParentList = childList.begin(); iterParentList  != childList.end(); iterParentList++) { // for each variable returned check against the variable list
				iter = first.find(*iterParentList);

				if (iter != first.end()) {
					exist = true;

					if (keepRelationship)
						resultList.push_back(pair<string, string>(CommonUtility::NumberToString(iter->first), CommonUtility::NumberToString(iterSecond->first)));					
					else if (astParam1->updateAble()) 
						finalListOne[CommonUtility::NumberToString(iter->first)] = true;
					else if (!astParam2->updateAble()) {
						return; // both are not updatable. 
					}								
				}
			}
			if (exist && !keepRelationship && astParam2->updateAble()) 
				finalListTwo[CommonUtility::NumberToString(iterSecond->first)] = true;


		}
	}


	updateVariable(resultList, finalListOne, finalListTwo, keepRelationship);

	failed = (finalListOne.size() == 0 && finalListTwo.size() == 0 && resultList.size() == 0);

}
void UsesEngine::handleProcedureVariable() {
	// special case 1:
	// Modifies(procedure p , _);

	// declare necessary variable 
	bool keepRelationship = QueryClass::keepRelationship();
	vector<pair<string, string>> relationship;

	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	

	FastSearchString procedureList;
	FastSearchString second;

	if (astParam2->getParameterType() == VT_UNDERSCORE) 
		CommonUtility::convertToMap(myQM->getAllVariable(), second);
	else 
		loadVariable(1, second);

	if (astParam1->getParameterType() == VT_UNDERSCORE) 
		procedureList = myQM->getAllProcedureList();
	else {
		loadVariable(0, procedureList);
	}


	FastSearchString finalProcedureList;
	FastSearchString finalVariableList; 

	FastSearchString::const_iterator iter;

	bool exist = false;


	if (second.size() < procedureList.size()) {

		vector<string>::const_iterator iterProcedureResult;

		for (iter = second.begin();  iter != second.end(); iter++) {
			vector<string> &procedureListResult = pkbManager->getUses()->getUsesProc(iter->first);

			exist = false;
			for (iterProcedureResult = procedureListResult.begin(); iterProcedureResult  != procedureListResult.end(); iterProcedureResult++) {
				if (procedureList.find(*iterProcedureResult) != procedureList.end()) {  // found
					exist = true;

					if (keepRelationship)
						relationship.push_back(pair<string, string>(*iterProcedureResult, iter->first));
					else if (astParam1->updateAble()) {
						finalProcedureList[*iterProcedureResult] = true;
					} else { // if the first one is not updateable, just need to care for second one 
						if (!astParam2->updateAble()) 
							return; // we have got what we come for. 

						break;	

					}

				}			
			}
			if (exist && !keepRelationship && astParam2->updateAble()) 
				finalVariableList[iter->first] = true;

		}
	} else {
		vector<string>::iterator iterVarResult;

		for (iter = procedureList.begin();  iter != procedureList.end(); iter++) {
			vector<string> &varListResult = pkbManager->getUses()->getUsedVar(iter->first);

			exist = false;
			for (iterVarResult = varListResult.begin(); iterVarResult  != varListResult.end(); iterVarResult++) {
				if (second.find(*iterVarResult) != second.end()) {  // found
					exist = true;

					if (keepRelationship)
						relationship.push_back(pair<string, string>(iter->first, *iterVarResult));
					else if (astParam2->updateAble()) {
						finalVariableList[*iterVarResult] = true;

					} else { // if the first one is not updateable, just need to care for second one 
						if (!astParam1->updateAble()) 
							return; // we have got what we come for. 

						// if param2 is not updatable, super unlikely after the optimization
						break;	

					}

				}			
			}
			if (exist && !keepRelationship && astParam1->updateAble()) 
				finalProcedureList[iter->first] = true;

		}
	}


	updateVariable(relationship, finalProcedureList, finalVariableList, keepRelationship);

	// both constant already handled above
	failed = (finalProcedureList.size() == 0 && finalVariableList.size() == 0&& relationship.size() == 0);



}
void UsesEngine::handleStatementListVariable() {
	vector<pair<string, string>> relationship;

	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	

	FastSearchString variableList;
	if (astParam2->getParameterType() == VT_CONSTANTSTRING) 	
		variableList[astParam2->getVariableName()] = true;
	else if (astParam2->getParameterType() == VT_UNDERSCORE ) 
		CommonUtility::convertToMap(myQM->getAllVariable(), variableList);
	else 
		variableList= myQM->getValueListMap (astParam2->getVariableName());


	FastSearchInteger statementList;

	if (astParam1->getParameterType() == VT_CONSTANTINTEGER) 
		statementList[atoi(astParam1->getVariableName().c_str())] = true;
	else if (astParam1->getParameterType() == VT_UNDERSCORE) { // temporary hack. REMOVE away after youli fixes his error
		CommonUtility::convertToMap(myQM->getAllStatementList(), statementList);
	} else
		statementList = myQM->getValueListIntegerMap (astParam1->getVariableName());

	FastSearchString finalStatementList;
	FastSearchString  finalVariableList; 


	bool exist = false;
	bool keepRelationship = this->keepRelationship();

	if (statementList.size() >  variableList.size()) {
		FastSearchString::const_iterator iter;	
		vector<int>::const_iterator iterStatementList;
		FastSearchInteger::const_iterator iterStatementFast;

		//using variable check against statementlist

		for (iter = variableList .begin();  iter != variableList.end(); iter++) { // for every statement find the modified value
			vector<int> statementListResult = pkbManager->getUses()->getUsesStmt(iter->first);				

			exist = false		;
			for (iterStatementList= statementListResult.begin(); iterStatementList != statementListResult.end(); iterStatementList++) { // for each variable returned check against the variable list
				// try to find 
				iterStatementFast = statementList.find(*iterStatementList);
				if (iterStatementFast != statementList.end()) {
					exist = true;

					if (keepRelationship)
						relationship.push_back(pair<string, string>(CommonUtility::NumberToString(*iterStatementList),iter->first));
					else if (astParam1->updateAble()) 
						finalStatementList[CommonUtility::NumberToString(*iterStatementList)] = true;
					else { 
						if (!astParam2->updateAble()) 
							return; // we have got what we come for. 					
						break;
					}
				}
			}


			if (exist && !keepRelationship && astParam2->updateAble()) 
				finalVariableList[iter->first] = true;
		}
	} else  {
		FastSearchInteger::const_iterator iter;	
		vector<string>::const_iterator iterVariableResult;
		FastSearchString::const_iterator iterVariable;

		for (iter = statementList.begin();  iter != statementList.end(); iter++) { // for every statement find the modified value
			vector<string> variableResult = pkbManager->getUses()->getUsedVar(iter->first);				
			exist = false;
			for (iterVariableResult = variableResult.begin(); iterVariableResult  != variableResult.end(); iterVariableResult++) { // for each variable returned check against the variable list
				iterVariable = variableList.find(*iterVariableResult);
				if (iterVariable != variableList.end()) {
					exist = true; // at least one result found for a given statement
					if (keepRelationship)
						relationship.push_back(pair<string, string>(CommonUtility::NumberToString(iter->first),*iterVariableResult));
					else if (astParam2->updateAble()) 
						finalVariableList[*iterVariableResult] = true;
					else { 
						if (!astParam1->updateAble()) 
							return; // we have got what we come for. 					
						break;
					}
				}
			}

			if (exist && !keepRelationship && astParam1->updateAble()) 
				finalStatementList[CommonUtility::NumberToString(iter->first)] = true;
		}
	}

	updateVariable(relationship, finalStatementList, finalVariableList, keepRelationship);


	// both constant already handled above
	failed = (finalStatementList.size() == 0 && finalVariableList.size() == 0 && relationship.size() == 0);



}
bool ProjectFileConverter::convertFile(Core::GeneratedFile &file, QString &errorMessage)
{
    if (!FileConverter::convertFile(file, errorMessage))
        return false;

    ImportLog &log = convertedProjectContext().importLog();
    QMap<QString, QString> origProjectVariables = scanForDefinedVariables(file);
    QString fileContent;

    QLatin1String path( ":/qnx/cascadesimport/resources/templates/project.pro");
    QByteArray ba = loadFileContent(path, errorMessage);
    if (!errorMessage.isEmpty())
        return false;
    fileContent = QString::fromUtf8(ba);

    QStringList headers;
    QStringList sources;
    QStringList resources;
    QStringList otherFiles;

    QSet<QString> entries;
    foreach (const QString &filePath, convertedProjectContext().collectedFiles()) {
        QString ext = filePath.section(QLatin1Char('.'), -1);
        if (ext.compare(QLatin1String("c"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("cc"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("cpp"), Qt::CaseInsensitive) == 0)
            sources << filePath;
        else if (ext.compare(QLatin1String("h"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("hh"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("hpp"), Qt::CaseInsensitive) == 0)
            headers << filePath;
        else if (ext.compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0)
            resources << filePath;
        else if (ext.compare(QLatin1String("qml"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("js"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("ts"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("pro"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (filePath.compare(QLatin1String("bar-descriptor.xml"), Qt::CaseInsensitive) == 0)
            otherFiles << filePath;
        else if (filePath.startsWith(QLatin1String("assets/"), Qt::CaseInsensitive))
            // include all the content of the assets directory
            otherFiles << filePath;
        else if (filePath.startsWith(QLatin1String("src/"), Qt::CaseInsensitive))
            // include all the content of the src directory
            otherFiles << filePath;
        else if (ext.compare(QLatin1String("log"), Qt::CaseInsensitive) != 0)
                log.logWarning(tr("File '%1' not listed in '%2' file, should it be?")
                        .arg(filePath).arg(file.path()));
    }

    fileContent.replace(QLatin1String("%HEADERS%"), headers.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%SOURCES%"), sources.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%RESOURCES%"), resources.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%OTHER_FILES%"), otherFiles.join(QLatin1String(" \\\n    ")));
    fileContent.replace(QLatin1String("%PROJECT_NAME%"), convertedProjectContext().projectName());
    fileContent.replace(QLatin1String("%TARGET%"), origProjectVariables.value(QLatin1String("TARGET"),
                                      convertedProjectContext().projectName()));
    fileContent.replace(QLatin1String("%EXTRA_LIBS%"), origProjectVariables.value(QLatin1String("LIBS")));
    fileContent.replace(QLatin1String("%IMPORTER_VERSION%"),
                        QLatin1String(Qnx::Constants::QNX_BLACKBERRY_CASCADESIMPORTER_VERSION));
    fileContent.replace(QLatin1String("%DATE_TIME%"),
                                      QDateTime::currentDateTime().toString(Qt::ISODate));
    fileContent.replace(QLatin1String("%QT%"),
            updateVariable(origProjectVariables.value(QLatin1String("QT")),
                           QLatin1String("declarative script svg sql network xml xmlpatterns"),
                           QString()
    ));
    fileContent.replace(QLatin1String("%CONFIG%"),
            updateVariable(origProjectVariables.value(QLatin1String("CONFIG")),
                           QLatin1String("qt warn_on"),
                           QLatin1String("debug release debug_and_release cascades cascades10")
    ));
    fileContent.replace(QLatin1String("%MOBILITY%"), origProjectVariables.value(QLatin1String("MOBILITY")));
    file.setContents(fileContent);
    file.setAttributes(file.attributes() | Core::GeneratedFile::OpenProjectAttribute);
    return errorMessage.isEmpty();
}
void BinaryRelationEngine::handleCall(vector<string> &first, vector<string> &second) {

	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	
	vector<pair<string, string>> relationship;
	bool keepRelation  = keepRelationship();
	FastSearchString result1; 
	FastSearchString result2; 

	if (astParam1->getParameterType() == VT_CALL) {
		if (astParam2->getParameterType() == VT_CALL) {					
			FastSearchInteger secondMap  = myQM->getValueListIntegerMap(astParam2->getVariableName());
			FastSearchInteger::iterator iterSecond;
			vector<string>::iterator iter;

			for (iter = first.begin(); iter != first.end(); iter++) {

				string procedure = pkbManager->getAST()->getCalledProcedure(atoi(iter->c_str())); // called what procedure
				vector<int> stmtList = pkbManager->getCalls()->getCallsStmt(procedure); // get call statement list of that procedure
				vector<int>::iterator iterStmtList;

				for (iterStmtList = stmtList.begin(); iterStmtList != stmtList.end(); iterStmtList++) {
					iterSecond = secondMap.find(*iterStmtList); // check if it's exists
					if (iterSecond != secondMap.end()) { 
						relationship.push_back(pair<string, string>(*iter, CommonUtility::NumberToString(iterSecond->first)));
					}
				}												
			}

		} else {// first one VT CALL second not VT_CALL

			vector<string>::iterator iter;
			FastSearchString::iterator iterFound;
			FastSearchString secondMap;
			CommonUtility::convertToMap(second, secondMap);

			bool exist;
			for (iter = first.begin(); iter != first.end(); iter++) {

				string procedure = pkbManager->getAST()->getCalledProcedure(atoi(iter->c_str()));
				exist = false;
				iterFound = secondMap.find(procedure) ;
				if (iterFound != secondMap.end()){
					exist = true;
					if (keepRelation) 
						relationship.push_back(pair<string, string>(*iter, iterFound->first));

				}


				if (exist & !keepRelation) 
					result1[*iter] = true;
			}
		}
	} else if (astParam2->getParameterType() == VT_CALL) { // second VT_CALL
			vector<string>::iterator iter;
			FastSearchString::iterator iterFound;
			FastSearchString firstMap;
			CommonUtility::convertToMap(first, firstMap);

			bool exist;
			for (iter = second.begin(); iter != second.end(); iter++) {

				string procedure = pkbManager->getAST()->getCalledProcedure(atoi(iter->c_str()));
				exist = false;
				iterFound = firstMap.find(procedure) ;
				if (iterFound != firstMap.end()){
					exist = true;
					if (keepRelation) 
						relationship.push_back(pair<string, string>(iterFound->first, *iter));

				}


				if (exist & !keepRelation) 
					result2[*iter] = true;
			}
	}

	updateVariable(relationship, result1, result2, keepRelation);

	failed = (result1.size() == 0 && result2.size() == 0 && relationship.size() == 0);

}
void BinaryRelationEngine::run() {	
	// handle call differently

	ASTParameter *astParam1 = parameterList.at(0);
	ASTParameter *astParam2 = parameterList.at(1);	

	vector<string> first;

	if (astParam1->getParameterType() == VT_CONSTANTSTRING 
		||astParam1->getParameterType() == VT_CONSTANTINTEGER) {
			first.push_back(astParam1->getVariableName());
	} else if (myQM->getVariableType(astParam1->getVariableName()).compare("integer") == 0) {
		CommonUtility::convertIntVectorToString(myQM->getValueListInteger (astParam1->getVariableName()), first);
	} else {
		first = myQM->getValueList(astParam1->getVariableName());
	}

	vector<string> second;

	if (astParam2->getParameterType() == VT_CONSTANTSTRING 
		||astParam2->getParameterType() == VT_CONSTANTINTEGER) {
			second.push_back(astParam2->getVariableName());
	} else if (myQM->getVariableType(astParam2->getVariableName()).compare("integer") == 0){
		CommonUtility::convertIntVectorToString(myQM->getValueListInteger (astParam2->getVariableName()), second);
	} else {
		second= myQM->getValueList(astParam2->getVariableName());
	}

	if (astParam1->getParameterType() == VT_CALL ||
		astParam2->getParameterType() == VT_CALL) {
			handleCall(first, second);
			return;
	}


	FastSearchString secondList;
	FastSearchString firstList;




	vector<pair<string, string>> relationship;

	bool keepRelation = keepRelationship();
	bool exist;

	if (first.size() < second.size()) {
		vector<string>::iterator iterFirst;

		FastSearchString secondFast;
		CommonUtility::convertToMap(second, secondFast);

		for (iterFirst = first.begin(); iterFirst != first.end(); iterFirst++){
			exist = false;
			if (secondFast.find(*iterFirst) != secondFast.end() ) {
				exist = true;

				if (keepRelation) 
					relationship.push_back(VectorRelation(*iterFirst, *iterFirst));		// they are the same. make no mistake here
				else if (astParam2->updateAble()) 
					secondList[*iterFirst] = true;
				else if (!astParam1->updateAble()) 
					return; // we have got what we come for. 
			}

			if (exist && !keepRelation && astParam1->updateAble()) 
				firstList[*iterFirst] = true;
		}
	} else {
		vector<string>::iterator iterSecond;

		FastSearchString firstFast;
		CommonUtility::convertToMap(first, firstFast);

		for (iterSecond = second.begin(); iterSecond != second.end(); iterSecond++){
			exist = false;
			if (firstFast.find(*iterSecond) != firstFast.end() ) {
				exist = true;

				if (keepRelation) 
					relationship.push_back(VectorRelation(*iterSecond, *iterSecond));		// they are the same. make no mistake here
				else if (astParam1->updateAble()) 
					firstList[*iterSecond] = true;
				else if (!astParam1->updateAble()) 
					return; // we have got what we come for. 
			}

			if (exist && !keepRelation && astParam2->updateAble()) 
				secondList[*iterSecond] = true;
		}
	}

	updateVariable( relationship, firstList, secondList, keepRelation);

	failed = (firstList.size() == 0 && secondList.size() == 0 && relationship.size() == 0);



}