AST: Fixed handling of '(((typeof(x))*)0)'

This commit is contained in:
Daniel Marjamäki 2014-05-04 18:36:04 +02:00
parent 42b85088c5
commit 7d583e639c
3 changed files with 15 additions and 0 deletions

View File

@ -6990,6 +6990,11 @@ bool Tokenizer::simplifyRedundantParentheses()
if (tok->str() != "(")
continue;
if (Token::Match(tok->link(), ") %num%")) {
tok = tok->link();
continue;
}
// !!operator = ( x ) ;
if (tok->strAt(-2) != "operator" &&
tok->previous() && tok->previous()->str() == "=" &&

View File

@ -392,6 +392,9 @@ static bool iscast(const Token *tok)
if (!Token::Match(tok, "( %var%"))
return false;
if (Token::Match(tok, "( (| typeof (") && Token::Match(tok->link(), ") %num%"))
return true;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == ")")
return tok2->previous()->str() == "*" ||

View File

@ -367,6 +367,7 @@ private:
TEST_CASE(removeParentheses16); // Ticket #4423 '*(x.y)='
TEST_CASE(removeParentheses17); // Don't remove parentheses in 'a ? b : (c>0 ? d : e);'
TEST_CASE(removeParentheses18); // 'float(*a)[2]' => 'float *a[2]'
TEST_CASE(removeParentheses19); // ((typeof(x) *)0)
TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
@ -5640,6 +5641,10 @@ private:
ASSERT_EQUALS("float * a [ 2 ] ;", tokenizeAndStringify("float(*a)[2];", false));
}
void removeParentheses19() {
ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 )", tokenizeAndStringify("(((typeof(X))*)0)", false));
}
void tokenize_double() {
const char code[] = "void f()\n"
"{\n"
@ -10326,6 +10331,8 @@ private:
ASSERT_EQUALS("123*+", testAst("1+2*3"));
ASSERT_EQUALS("12*34*+", testAst("1*2+3*4"));
ASSERT_EQUALS("12*34*5*+", testAst("1*2+3*4*5"));
ASSERT_EQUALS("0(r.&", testAst("(&((typeof(x))0).r);"));
ASSERT_EQUALS("0(r.&", testAst("&((typeof(x))0).r;"));
// Various tests of precedence
ASSERT_EQUALS("ab::c+", testAst("a::b+c"));