From 1f4b84379d1e069ee10cf6c7cb2c2afc44fd6d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 17 May 2017 21:58:46 +0200 Subject: [PATCH] Fix for #pragma asm --- lib/cppcheck.cpp | 1 + lib/preprocessor.cpp | 12 ++++++++---- lib/preprocessor.h | 4 +++- test/testpreprocessor.cpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index e7472ad39..b33c1dba6 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -212,6 +212,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin // Get directives preprocessor.setDirectives(tokens1); + preprocessor.simplifyPragmaAsm(&tokens1); preprocessor.setPlatformInfo(&tokens1); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index ea2916553..9fb0b3382 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -566,10 +566,6 @@ void Preprocessor::loadFiles(const simplecpp::TokenList &rawtokens, std::vector< simplecpp::OutputList outputList; tokenlists = simplecpp::load(rawtokens, files, dui, &outputList); - - for (std::map::iterator it = tokenlists.begin(); it != tokenlists.end(); ++it) { - Preprocessor::simplifyPragmaAsm(it->second); - } } void Preprocessor::removeComments() @@ -886,6 +882,14 @@ unsigned int Preprocessor::calculateChecksum(const simplecpp::TokenList &tokens1 } void Preprocessor::simplifyPragmaAsm(simplecpp::TokenList *tokenList) +{ + Preprocessor::simplifyPragmaAsmPrivate(tokenList); + for (std::map::iterator it = tokenlists.begin(); it != tokenlists.end(); ++it) { + Preprocessor::simplifyPragmaAsmPrivate(it->second); + } +} + +void Preprocessor::simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList) { // assembler code.. for (simplecpp::Token *tok = tokenList->front(); tok; tok = tok->next) { diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a17cd4ea7..36f85b475 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -171,10 +171,12 @@ public: */ unsigned int calculateChecksum(const simplecpp::TokenList &tokens1, const std::string &toolinfo) const; - static void simplifyPragmaAsm(simplecpp::TokenList *tokenList); + void simplifyPragmaAsm(simplecpp::TokenList *tokenList); private: + static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList); + /** * Remove space that has new line character on left or right side of it. * diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index f2eb7886b..f772574c7 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -253,7 +253,7 @@ private: std::vector files; simplecpp::TokenList tokens(istr, files, filename, &outputList); tokens.removeComments(); - Preprocessor::simplifyPragmaAsm(&tokens); + preprocessor0.simplifyPragmaAsm(&tokens); const std::set configs(preprocessor0.getConfigs(tokens)); preprocessor0.setDirectives(tokens); for (std::set::const_iterator it = configs.begin(); it != configs.end(); ++it) {