Simplify 0[foo] to *(foo) (fixes #4083)
This commit is contained in:
parent
9fa7e15fb4
commit
662b0d2dbe
|
@ -1693,6 +1693,15 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
}
|
||||
|
||||
// Simplify: 0[foo] -> *(foo)
|
||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, "0 [") && tok->linkAt(1)) {
|
||||
tok->str("*");
|
||||
tok->next()->str("(");
|
||||
tok->linkAt(1)->str(")");
|
||||
}
|
||||
}
|
||||
|
||||
// Remove "volatile", "inline", "register", and "restrict"
|
||||
simplifyKeyword();
|
||||
|
||||
|
|
|
@ -424,6 +424,8 @@ private:
|
|||
TEST_CASE(simplifyOperatorName5);
|
||||
TEST_CASE(simplifyOperatorName6); // ticket #3194
|
||||
|
||||
TEST_CASE(simplifyNullArray);
|
||||
|
||||
// Some simple cleanups of unhandled macros in the global scope
|
||||
TEST_CASE(removeMacrosInGlobalScope);
|
||||
|
||||
|
@ -6700,6 +6702,10 @@ private:
|
|||
ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false));
|
||||
}
|
||||
|
||||
void simplifyNullArray() {
|
||||
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
|
||||
}
|
||||
|
||||
void removeMacrosInGlobalScope() {
|
||||
// remove some unhandled macros in the global scope.
|
||||
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }"));
|
||||
|
|
Loading…
Reference in New Issue