From 49fc53165cd2320114b824b8574b84d900f395d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Jan 2011 08:34:58 +0100 Subject: [PATCH] Tokenizer: remove some unhandled macros in the global scope. ticket: #2523 --- lib/tokenize.cpp | 22 +++++++++++++++++++++- lib/tokenize.h | 3 +++ test/testtokenize.cpp | 9 +++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 576dacb84..75ff66b60 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2083,7 +2083,7 @@ bool Tokenizer::tokenize(std::istream &code, } - // remove inline SQL (Oracle PRO*C). Ticket: #1959 + // replace inline SQL with "asm()" (Oracle PRO*C). Ticket: #1959 for (Token *tok = _tokens; tok; tok = tok->next()) { if (Token::simpleMatch(tok, "EXEC SQL")) @@ -2123,6 +2123,9 @@ bool Tokenizer::tokenize(std::istream &code, } } + // remove some unhandled macros in global scope + removeMacrosInGlobalScope(); + // specify array size.. arraySize(); @@ -4383,6 +4386,23 @@ bool Tokenizer::simplifyTokenList() } //--------------------------------------------------------------------------- +void Tokenizer::removeMacrosInGlobalScope() +{ + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (tok->str() == "(") + { + tok = tok->link(); + if (Token::Match(tok, ") %type% {") && tok->strAt(1) != "const") + tok->deleteNext(); + } + + if (tok->str() == "{") + tok = tok->link(); + } +} +//--------------------------------------------------------------------------- + void Tokenizer::removeRedundantAssignment() { for (Token *tok = _tokens; tok; tok = tok->next()) diff --git a/lib/tokenize.h b/lib/tokenize.h index 8dacc345a..5662d7843 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -186,6 +186,9 @@ public: /** Simplify labels */ void labels(); + /** Remove macros in global scope */ + void removeMacrosInGlobalScope(); + /** Remove redundant assignment */ void removeRedundantAssignment(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f2f827fb5..da56bdfa7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -298,6 +298,9 @@ private: TEST_CASE(java); TEST_CASE(simplifyOperatorName); + + // Some simple cleanups of unhandled macros in the global scope + TEST_CASE(removeMacrosInGlobalScope); } @@ -5247,6 +5250,12 @@ private: ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false)); } + + void removeMacrosInGlobalScope() + { + // remove some unhandled macros in the global scope. + ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }")); + } }; REGISTER_TEST(TestTokenizer)