From 31528166194615609b98453af8ab99f5622b65d1 Mon Sep 17 00:00:00 2001 From: Zachary Blair Date: Sat, 10 Apr 2010 09:58:09 +0200 Subject: [PATCH] Fixed #779 (Tokenizer: delete register keyword everywhere) --- lib/tokenize.cpp | 10 +++++++++- test/testsimplifytokens.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 38e7adef2..eca13211a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2917,7 +2917,15 @@ bool Tokenizer::simplifyTokenList() simplifyMathFunctions(); // Remove unwanted keywords - static const char * const unwantedWords[] = { "unsigned", "unlikely", "likely" }; + static const char * const unwantedWords[] = { "unsigned", "unlikely", "likely", "register", "inline" }; + for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && _tokens; ui++) + { + if (_tokens->str() == unwantedWords[ui]) + { + _tokens->deleteThis(); + break; + } + } for (Token *tok = _tokens; tok; tok = tok->next()) { for (unsigned ui = 0; ui < sizeof(unwantedWords) / sizeof(unwantedWords[0]) && tok->next(); ui++) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 51dffaddb..e2783b13f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -229,6 +229,10 @@ private: // struct ABC { } abc; => struct ABC { }; ABC abc; TEST_CASE(simplifyStructDecl); + + // register int var; => int var; + // inline int foo() {} => int foo() {} + TEST_CASE(removeUnwantedKeywords); } std::string tok(const char code[], bool simplify = true) @@ -4376,6 +4380,15 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } } + + void removeUnwantedKeywords() + { + ASSERT_EQUALS("int var ;", tok("register int var ;", true)); + ASSERT_EQUALS("short var ;", tok("register short int var ;", true)); + ASSERT_EQUALS("int foo ( ) { }", tok("inline int foo ( ) { }", true)); + ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true)); + ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true)); + } }; REGISTER_TEST(TestSimplifyTokens)