TokenList: Better handling of '1++a' and 'a++1'
This commit is contained in:
parent
908bc664a4
commit
f09dded7b1
|
@ -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++)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue