From 17fbab018cb3ac6fa8754c014939002ef5c39f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 14 Feb 2009 06:11:37 +0000 Subject: [PATCH] simplify known value: insert known variable value into calculations --- src/cppcheck.cpp | 4 ++++ src/tokenize.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index 714fc4464..7d15edcce 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -37,6 +37,7 @@ #include #include #include +#include //--------------------------------------------------------------------------- @@ -333,6 +334,9 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) _tokenizer.simplifyTokenList(); + // Write simplified token list to a file.. + std::cout << _tokenizer.tokens()->stringifyList(true) << std::endl; + if (_settings._unusedFunctions) _checkFunctionUsage.parseTokens(_tokenizer); diff --git a/src/tokenize.cpp b/src/tokenize.cpp index a9fee5e40..4e1918043 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -1570,6 +1570,14 @@ bool Tokenizer::simplifyKnownVariables() tok3->str(tok2->strAt(2)); ret = true; } + + // Variable is used in calculation.. + if (Token::Match(tok3, "[=+-*/] %varid% [+-*/;]", varid)) + { + tok3 = tok3->next(); + tok3->str(tok2->strAt(2)); + ret = true; + } } } }