diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 1a4d37055..a9052ad15 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1806,7 +1806,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string Tokenizer tokenizer(_settings, _errorLogger); line.erase(0, sizeof("#pragma endasm")); std::istringstream tempIstr(line); - tokenizer.tokenize(tempIstr, ""); + tokenizer.tokenize(tempIstr, "", "", true); if (Token::Match(tokenizer.tokens(), "( %var% = %any% )")) { ret << "asm(" << tokenizer.tokens()->strAt(1) << ");"; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ca9cea406..ffb230b51 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1581,7 +1581,8 @@ void Tokenizer::simplifyMulAndParens() bool Tokenizer::tokenize(std::istream &code, const char FileName[], - const std::string &configuration) + const std::string &configuration, + bool noSymbolDB_AST) { // make sure settings specified assert(_settings); @@ -1598,22 +1599,23 @@ bool Tokenizer::tokenize(std::istream &code, Token::isCPP(isCPP()); if (simplifyTokenList1(FileName)) { - createSymbolDatabase(); + if (!noSymbolDB_AST) { + createSymbolDatabase(); - // Use symbol database to identify rvalue references. Split && to & &. This is safe, since it doesn't delete any tokens (which might be referenced by symbol database) - for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) { - const Variable* var = _symbolDatabase->getVariableFromVarId(i); - if (var && var->isRValueReference()) { - const_cast(var->typeEndToken())->str("&"); - const_cast(var->typeEndToken())->insertToken("&"); - const_cast(var->typeEndToken()->next())->scope(var->typeEndToken()->scope()); + // Use symbol database to identify rvalue references. Split && to & &. This is safe, since it doesn't delete any tokens (which might be referenced by symbol database) + for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) { + const Variable* var = _symbolDatabase->getVariableFromVarId(i); + if (var && var->isRValueReference()) { + const_cast(var->typeEndToken())->str("&"); + const_cast(var->typeEndToken())->insertToken("&"); + const_cast(var->typeEndToken()->next())->scope(var->typeEndToken()->scope()); + } } + + list.createAst(); + ValueFlow::setValues(&list, _errorLogger, _settings); } - list.createAst(); - - ValueFlow::setValues(&list, _errorLogger, _settings); - return true; } return false; diff --git a/lib/tokenize.h b/lib/tokenize.h index 4b98c1804..83f78ff01 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -85,12 +85,13 @@ public: * * @param FileName The filename * @param configuration E.g. "A" for code where "#ifdef A" is true + * @param noSymbolDB_AST Disable creation of SymbolDatabase and AST * @return false if source code contains syntax errors */ bool tokenize(std::istream &code, const char FileName[], - const std::string &configuration = ""); - + const std::string &configuration = "", + bool noSymbolDB_AST = false); /** * tokenize condition and run simple simplifications on it * @param code code diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 614e28817..9a4d69d92 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2581,7 +2581,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); + tokenizer.tokenize(istr, "test.cpp", "", true); return TemplateSimplifier::templateParameters(tokenizer.tokens()); }