Improve 'Tokenizer::elseif' code in order to not touch 'else if' inside a macro parenthesis.

This commit is contained in:
Edoardo Prezioso 2012-02-26 02:44:16 +01:00
parent bbfae8e3ae
commit 4d3013d43d
2 changed files with 9 additions and 7 deletions

View File

@ -6611,16 +6611,17 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
void Tokenizer::elseif()
{
for (Token *tok = _tokens; tok; tok = tok->next()) {
if (tok->str() == "(" || tok->str() == "[" ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "="))
tok = tok->link();
if (!Token::simpleMatch(tok, "else if"))
continue;
int indent = 0;
for (Token *tok2 = tok; indent >= 0 && tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "(|{"))
++indent;
else if (Token::Match(tok2, ")|}"))
--indent;
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "(|{|["))
tok2 = tok2->link();
if (indent == 0 && Token::Match(tok2, "}|;")) {
if (Token::Match(tok2, "}|;")) {
if (tok2->next() && tok2->next()->str() != "else") {
tok->insertToken("{");
tok2->insertToken("}");

View File

@ -869,6 +869,7 @@ private:
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.createTokens(istr);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.elseif();
return tokenizer.tokens()->stringifyList(false);
}