TokenList: Better handling of '1++a' and 'a++1'

This commit is contained in:
Daniel Marjamäki 2015-12-27 14:57:22 +01:00
parent 908bc664a4
commit f09dded7b1
2 changed files with 25 additions and 0 deletions

View File

@ -381,6 +381,18 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0)
addtoken(CurrentToken, lineno, FileIndex, true);
if (!CurrentToken.empty())
_back->isExpandedMacro(expandedMacro);
// Split up ++ and --..
for (Token *tok = _front; tok; tok = tok->next()) {
if (!Token::Match(tok, "++|--"))
continue;
if (Token::Match(tok->previous(), "%num% ++|--") ||
Token::Match(tok, "++|-- %num%")) {
tok->str(tok->str()[0]);
tok->insertToken(tok->str());
}
}
Token::assignProgressValues(_front);
for (std::size_t i = 1; i < _files.size(); i++)

View File

@ -37,6 +37,7 @@ private:
TEST_CASE(line1); // Ticket #4408
TEST_CASE(line2); // Ticket #5423
TEST_CASE(testaddtoken);
TEST_CASE(inc);
}
// inspired by #5895
@ -102,6 +103,18 @@ private:
ASSERT_EQUALS(Path::toNativeSeparators("[c:\\a.h:8]"), tokenlist.fileLine(tokenlist.front()));
}
void inc() const {
const char code[] = "a++1;1++b;";
errout.str("");
// tokenize..
TokenList tokenlist(&settings);
std::istringstream istr(code);
tokenlist.createTokens(istr, "a.cpp");
ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;"));
}
};
REGISTER_TEST(TestTokenList)