From c79b9a8aac7066823312c90403fbbcacc3bc5a69 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 29 Apr 2010 07:17:38 +0200 Subject: [PATCH] Fixed #1631 (Tokenizer: remove register keyword) --- lib/tokenize.cpp | 90 ++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cb4537668..76488c372 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1325,19 +1325,57 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s Token::createMutualLinks(tok->tokAt(2), tok->tokAt(3)); } - // Remove "volatile" and "inline" - while (Token::Match(_tokens, "volatile|inline")) + // Remove "volatile", "inline" and register + while (Token::Match(_tokens, "volatile|inline|register")) { _tokens->deleteThis(); } for (Token *tok = _tokens; tok; tok = tok->next()) { - while (Token::Match(tok->next(), "volatile|inline")) + while (Token::Match(tok->next(), "volatile|inline|register")) { tok->deleteNext(); } } + // Remove __builtin_expect, likely and unlikely + for (Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::simpleMatch(tok->next(), "__builtin_expect (")) + { + unsigned int parlevel = 0; + for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) + { + if (tok2->str() == "(") + ++parlevel; + else if (tok2->str() == ")") + { + if (parlevel <= 1) + break; + --parlevel; + } + if (parlevel == 1 && tok2->str() == ",") + { + if (Token::Match(tok2, ", %num% )")) + { + tok->deleteNext(); + Token::eraseTokens(tok2->previous(), tok2->tokAt(2)); + } + break; + } + } + } + else if (Token::Match(tok->next(), "likely|unlikely (")) + { + // remove closing ')' + tok->tokAt(2)->link()->previous()->deleteNext(); + + // remove "likely|unlikely (" + tok->deleteNext(); + tok->deleteNext(); + } + } + // colapse compound standard types into a single token // unsigned long long int => long _isUnsigned=true,_isLong=true simplifyStdType(); @@ -3005,52 +3043,6 @@ bool Tokenizer::simplifyTokenList() // Convert e.g. atol("0") into 0 simplifyMathFunctions(); - // Remove unwanted keywords - 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++) - { - if (tok->next()->str() == unwantedWords[ui]) - { - tok->deleteNext(); - break; - } - } - if (Token::simpleMatch(tok->next(), "__builtin_expect (")) - { - unsigned int parlevel = 0; - for (Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) - { - if (tok2->str() == "(") - ++parlevel; - else if (tok2->str() == ")") - { - if (parlevel <= 1) - break; - --parlevel; - } - if (parlevel == 1 && tok2->str() == ",") - { - if (Token::Match(tok2, ", %num% )")) - { - tok->deleteNext(); - Token::eraseTokens(tok2->previous(), tok2->tokAt(2)); - } - break; - } - } - } - } - // Convert + + into + and + - into - for (Token *tok = _tokens; tok; tok = tok->next()) {