Update Qt to support Markup structure

This commit is contained in:
Sam Truscott 2014-01-02 18:18:24 +01:00 committed by Daniel Marjamäki
parent b08880f20f
commit 4333dd3c75
4 changed files with 27 additions and 11 deletions

View File

@ -187,7 +187,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
std::size_t processedsize = 0;
unsigned int c = 0;
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
if (!_settings->library.markupFile(i->first)) {
if (!_settings->library.markupFile(i->first)
|| !_settings->library.processMarkupAfterCode(i->first)) {
returnValue += cppCheck.check(i->first);
processedsize += i->second;
if (!settings._errorsOnly)
@ -199,7 +200,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
// second loop to parse all markup files which may not work until all
// c/cpp files have been parsed and checked
for (std::map<std::string, std::size_t>::const_iterator i = _files.begin(); i != _files.end(); ++i) {
if (_settings->library.markupFile(i->first)) {
if (_settings->library.markupFile(i->first) && _settings->library.processMarkupAfterCode(i->first)) {
returnValue += cppCheck.check(i->first);
processedsize += i->second;
if (!settings._errorsOnly)

View File

@ -99,20 +99,27 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
// parsing of library code to find called functions
if (settings->library.isexecutableblock(FileName, tok->str())) {
const Token * qmlVarToken = tok->tokAt(settings->library.blockstartoffset(FileName));
const Token * markupVarToken = tok->tokAt(settings->library.blockstartoffset(FileName));
int scope = 1;
// find all function calls in library code (starts with '(', not if or while etc)
while (scope) {
if (qmlVarToken->str() == settings->library.blockstart(FileName)) {
if (markupVarToken->str() == settings->library.blockstart(FileName)) {
scope++;
} else if (qmlVarToken->str() == settings->library.blockend(FileName))
} else if (markupVarToken->str() == settings->library.blockend(FileName))
scope--;
else if (qmlVarToken->next()->str() == "(" &&
(!settings->library.iskeyword(FileName, qmlVarToken->str()))) {
if (_functions.find(qmlVarToken->str()) != _functions.end())
_functions[qmlVarToken->str()].usedOtherFile = true;
else if (!settings->library.iskeyword(FileName, markupVarToken->str())) {
if (_functions.find(markupVarToken->str()) != _functions.end())
_functions[markupVarToken->str()].usedOtherFile = true;
else if (markupVarToken->next()->str() == "("){
FunctionUsage &func = _functions[markupVarToken->str()];
func.filename = tokenizer.getSourceFilePath();
if (func.filename.empty() || func.filename == "+")
func.usedOtherFile = true;
else
func.usedSameFile = true;
}
}
qmlVarToken = qmlVarToken->next();
markupVarToken = markupVarToken->next();
}
}

View File

@ -193,6 +193,8 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
const char * const reporterrors = node->Attribute("reporterrors");
_reporterrors[extension] = (reporterrors && strcmp(reporterrors, "true") == 0);
const char * const aftercode = node->Attribute("aftercode");
_processAfterCode[extension] = (aftercode && strcmp(aftercode, "true") == 0);
for (const tinyxml2::XMLElement *markupnode = node->FirstChildElement(); markupnode; markupnode = markupnode->NextSiblingElement()) {
if (strcmp(markupnode->Name(), "keywords") == 0) {
@ -205,7 +207,7 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
}
else if (strcmp(markupnode->Name(), "exported") == 0) {
for (const tinyxml2::XMLElement *exporter = node->FirstChildElement(); exporter; exporter = exporter->NextSiblingElement()) {
for (const tinyxml2::XMLElement *exporter = markupnode->FirstChildElement(); exporter; exporter = exporter->NextSiblingElement()) {
if (strcmp(exporter->Name(), "exporter") != 0)
return false;

View File

@ -149,6 +149,11 @@ public:
return _markupExtensions.find(Path::getFilenameExtensionInLowerCase(path)) != _markupExtensions.end();
}
bool processMarkupAfterCode(const std::string &path) const {
const std::map<std::string, bool>::const_iterator it = _processAfterCode.find(Path::getFilenameExtensionInLowerCase(path));
return (it == _processAfterCode.end() || it->second);
}
const std::set<std::string> &markupExtensions() const {
return _markupExtensions;
}
@ -309,6 +314,7 @@ private:
std::map<std::string, bool> _noreturn; // is function noreturn?
std::set<std::string> _ignorefunction; // ignore functions/macros from a library (gtk, qt etc)
std::map<std::string, bool> _reporterrors;
std::map<std::string, bool> _processAfterCode;
std::set<std::string> _markupExtensions; // file extensions of markup files
std::map<std::string, std::set<std::string> > _keywords; // keywords for code in the library
std::map<std::string, CodeBlock> _executableblocks; // keywords for blocks of executable code