Fixed ticket #539 (Tokenizer: don't replace constants variables with varid 0)
http://sourceforge.net/apps/trac/cppcheck/ticket/539
This commit is contained in:
parent
b5d172b6e9
commit
0e2273833e
|
@ -1400,6 +1400,12 @@ void Tokenizer::simplifyTokenList()
|
|||
if (Token::Match(tok, "const %type% %var% = %num% ;"))
|
||||
{
|
||||
unsigned int varId = tok->tokAt(2)->varId();
|
||||
if (varId == 0)
|
||||
{
|
||||
tok = tok->tokAt(5);
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *num = tok->strAt(4);
|
||||
int indent = 1;
|
||||
for (Token *tok2 = tok->tokAt(6); tok2; tok2 = tok2->next())
|
||||
|
|
|
@ -98,6 +98,7 @@ private:
|
|||
TEST_CASE(simplifyKnownVariables9);
|
||||
TEST_CASE(simplifyKnownVariables10);
|
||||
TEST_CASE(simplifyKnownVariables11);
|
||||
TEST_CASE(simplifyKnownVariables12);
|
||||
|
||||
TEST_CASE(match1);
|
||||
|
||||
|
@ -864,6 +865,25 @@ private:
|
|||
ASSERT_EQUALS(" const int foo = 0 ; int main ( ) { int foo ; foo = 0 ; }", ostr.str());
|
||||
}
|
||||
|
||||
void simplifyKnownVariables12()
|
||||
{
|
||||
const char code[] = "ENTER_NAMESPACE(project_namespace)\n"
|
||||
"const double pi = 3.14;\n"
|
||||
"int main(){}\n";
|
||||
// tokenize..
|
||||
OurTokenizer tokenizer;
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
tokenizer.setVarId();
|
||||
tokenizer.simplifyTokenList();
|
||||
|
||||
std::ostringstream ostr;
|
||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||
ostr << " " << tok->str();
|
||||
ASSERT_EQUALS(" ENTER_NAMESPACE ( project_namespace ) const double pi = 3.14 ; int main ( ) { }", ostr.str());
|
||||
}
|
||||
|
||||
void match1()
|
||||
{
|
||||
// Match "%var% | %var%"
|
||||
|
|
Loading…
Reference in New Issue