AST: Somewhat better handling of '{x}' function parameters

This commit is contained in:
Daniel Marjamäki 2019-10-27 12:00:08 +01:00
parent ec521fba36
commit 2c1905cc2b
2 changed files with 15 additions and 4 deletions

View File

@ -709,6 +709,16 @@ static void compileTerm(Token *&tok, AST_state& state)
compileBinOp(tok, state, compileExpression);
if (Token::Match(tok, "} ,|:"))
tok = tok->next();
} else if (state.cpp && Token::Match(tok->tokAt(-2), "%name% ( {")) {
if (Token::simpleMatch(tok, "{ }"))
tok = tok->tokAt(2);
else {
Token *tok1 = tok;
state.inArrayAssignment++;
compileUnaryOp(tok, state, compileExpression);
state.inArrayAssignment--;
tok = tok1->link()->next();
}
} else if (!state.inArrayAssignment && !Token::simpleMatch(prev, "=")) {
state.op.push(tok);
tok = tok->link()->next();

View File

@ -7441,12 +7441,12 @@ private:
// ({..})
ASSERT_EQUALS("a{+d+ bc+", testAst("a+({b+c;})+d"));
ASSERT_EQUALS("a{d*+ bc+", testAst("a+({b+c;})*d"));
ASSERT_EQUALS("xa{((= bc( yd{((= ef(",
ASSERT_EQUALS("xabc({((= ydef({((=",
testAst("x=(int)(a({b(c);}));" // don't hang
"y=(int)(d({e(f);}));"));
ASSERT_EQUALS("QT_WA{{,( x0= QT_WA{{,( x1= x2=",
testAst("QT_WA({},{x=0;});" // don't hang
"QT_WA({x=1;},{x=2;});"));
ASSERT_EQUALS("A{,( x0= Bx1={{,( x2=", // TODO: This is not perfect!!
testAst("A({},{x=0;});" // don't hang
"B({x=1;},{x=2;});"));
ASSERT_EQUALS("xMACROtype.T=value.1=,{({=",
testAst("x = { MACRO( { .type=T, .value=1 } ) }")); // don't hang: MACRO({..})
ASSERT_EQUALS("fori10=i{;;( i--", testAst("for (i=10;i;({i--;}) ) {}"));
@ -7486,6 +7486,7 @@ private:
ASSERT_EQUALS("Abc({newreturn", testAst("return new A {b(c)};"));
ASSERT_EQUALS("a{{return", testAst("return{{a}};"));
ASSERT_EQUALS("a{b{,{return", testAst("return{{a},{b}};"));
ASSERT_EQUALS("abc{d{,{(=", testAst("a = b({ c{}, d{} });"));
}
void astbrackets() { // []