From 95e917b27f150cc4694020b40ebc93a664d34a5f Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 5 Feb 2011 09:03:31 +0100 Subject: [PATCH] Tokenizer: Replace __null with 0 (gcc constant) --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5c7cfaf2d..1ca735e53 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2071,7 +2071,8 @@ 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'") + if (tok->str() == "NULL" || tok->str() == "__null" || + tok->str() == "'\\0'" || tok->str() == "'\\x0'") { tok->str("0"); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 77f464776..ae11bd0ed 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -213,6 +213,7 @@ private: TEST_CASE(simplify_constants); TEST_CASE(simplify_constants2); TEST_CASE(simplify_constants3); + TEST_CASE(simplify_null); TEST_CASE(vardecl1); TEST_CASE(vardecl2); @@ -3879,6 +3880,16 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); } + void simplify_null() + { + const char code[] = + "int * p = NULL;\n" + "int * q = __null;\n"; + const char expected[] = + "int * p ; p = 0 ;\nint * q ; q = 0 ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); + } + void vardecl1() { const char code[] = "unsigned int a, b;";