From 1b3a5ed0be34c8a86484a17825f816240448a6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 6 Jan 2011 20:16:14 +0100 Subject: [PATCH] Tokenizer: simplify NULL to 0 in the normal token list --- lib/tokenize.cpp | 34 ++++++++++++++++++---------------- test/testtokenize.cpp | 12 ++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 21c1519a0..8cca03e7d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2029,6 +2029,22 @@ bool Tokenizer::tokenize(std::istream &code, } } + // Replace NULL with 0.. + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (tok->str() == "NULL" || tok->str() == "'\\0'" || tok->str() == "'\\x0'") + { + tok->str("0"); + } + else if (tok->isNumber() && + MathLib::isInt(tok->str()) && + MathLib::toLongNumber(tok->str()) == 0) + { + tok->str("0"); + } + } + + // remove inline SQL (Oracle PRO*C). Ticket: #1959 for (Token *tok = _tokens; tok; tok = tok->next()) { @@ -2422,6 +2438,8 @@ bool Tokenizer::tokenize(std::istream &code, // Change initialisation of variable to assignment simplifyInitVar(); + + if (!preprocessorCondition) { setVarId(); @@ -3987,22 +4005,6 @@ bool Tokenizer::simplifyTokenList() tok->deleteNext(); } - - // Replace NULL with 0.. - for (Token *tok = _tokens; tok; tok = tok->next()) - { - if (tok->str() == "NULL" || tok->str() == "'\\0'" || tok->str() == "'\\x0'") - { - tok->str("0"); - } - else if (tok->isNumber() && - MathLib::isInt(tok->str()) && - MathLib::toLongNumber(tok->str()) == 0) - { - tok->str("0"); - } - } - // simplify references simplifyReference(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 82460bbf6..18db0f6fb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3776,19 +3776,19 @@ private: // ticket #346 const char code1[] = "void *p = NULL;"; - const char res1[] = "void * p ; p = NULL ;"; + const char res1[] = "void * p ; p = 0 ;"; ASSERT_EQUALS(res1, tokenizeAndStringify(code1)); const char code2[] = "const void *p = NULL;"; - const char res2[] = "const void * p ; p = NULL ;"; + const char res2[] = "const void * p ; p = 0 ;"; ASSERT_EQUALS(res2, tokenizeAndStringify(code2)); const char code3[] = "void * const p = NULL;"; - const char res3[] = "void * const p ; p = NULL ;"; + const char res3[] = "void * const p ; p = 0 ;"; ASSERT_EQUALS(res3, tokenizeAndStringify(code3)); const char code4[] = "const void * const p = NULL;"; - const char res4[] = "const void * const p ; p = NULL ;"; + const char res4[] = "const void * const p ; p = 0 ;"; ASSERT_EQUALS(res4, tokenizeAndStringify(code4)); } @@ -3909,7 +3909,7 @@ private: { // ticket #696 const char code[] = "char a[10]={'\\0'}, b[10]={'\\0'};"; - const char res[] = "char a [ 10 ] = { '\\0' } ; char b [ 10 ] = { '\\0' } ;"; + const char res[] = "char a [ 10 ] = { 0 } ; char b [ 10 ] = { 0 } ;"; ASSERT_EQUALS(res, tokenizeAndStringify(code)); } @@ -3917,7 +3917,7 @@ private: void vardecl9() { const char code[] = "char a[2] = {'A', '\\0'}, b[2] = {'B', '\\0'};"; - const char res[] = "char a [ 2 ] = { 'A' , '\\0' } ; char b [ 2 ] = { 'B' , '\\0' } ;"; + const char res[] = "char a [ 2 ] = { 'A' , 0 } ; char b [ 2 ] = { 'B' , 0 } ;"; ASSERT_EQUALS(res, tokenizeAndStringify(code)); }