Fixed #8016 (AST: wrong ast for 'x=(s){...};')
This commit is contained in:
parent
5027810a79
commit
902eb87a8a
|
@ -475,6 +475,9 @@ static bool iscast(const Token *tok)
|
||||||
if (Token::Match(tok, "( (| typeof (") && Token::Match(tok->link(), ") %num%"))
|
if (Token::Match(tok, "( (| typeof (") && Token::Match(tok->link(), ") %num%"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (Token::Match(tok->previous(), "= ( %name% ) {") && tok->next()->varId() == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
bool type = false;
|
bool type = false;
|
||||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
while (tok2->link() && Token::Match(tok2, "(|[|<"))
|
while (tok2->link() && Token::Match(tok2, "(|[|<"))
|
||||||
|
@ -620,11 +623,14 @@ static void compileTerm(Token *&tok, AST_state& state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (tok->str() == "{") {
|
} else if (tok->str() == "{") {
|
||||||
|
const Token *prev = tok->previous();
|
||||||
|
if (prev && prev->str() == ")")
|
||||||
|
prev = prev->link()->previous();
|
||||||
if (Token::simpleMatch(tok->link(),"} [")) {
|
if (Token::simpleMatch(tok->link(),"} [")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
} else if (tok->previous() && tok->previous()->isName()) {
|
} else if (tok->previous() && tok->previous()->isName()) {
|
||||||
compileBinOp(tok, state, compileExpression);
|
compileBinOp(tok, state, compileExpression);
|
||||||
} else if (!state.inArrayAssignment && tok->strAt(-1) != "=") {
|
} else if (!state.inArrayAssignment && (!prev || prev->str() != "=")) {
|
||||||
state.op.push(tok);
|
state.op.push(tok);
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8076,7 +8076,6 @@ private:
|
||||||
ASSERT_EQUALS("ab2[a0=b0=,{a0=b0=,{,{=", testAst("struct AB ab[2] = { { .a=0, .b=0 }, { .a=0, .b=0 } };"));
|
ASSERT_EQUALS("ab2[a0=b0=,{a0=b0=,{,{=", testAst("struct AB ab[2] = { { .a=0, .b=0 }, { .a=0, .b=0 } };"));
|
||||||
ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};"));
|
ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};"));
|
||||||
ASSERT_EQUALS("s1a&,{2b&,{,{=", testAst("s = { {1, &a}, {2, &b} };"));
|
ASSERT_EQUALS("s1a&,{2b&,{,{=", testAst("s = { {1, &a}, {2, &b} };"));
|
||||||
TODO_ASSERT_EQUALS("xatoistr({(=", "x{(= atoistr(", testAst("x = (struct X){atoi(str)};"));
|
|
||||||
ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};"));
|
ASSERT_EQUALS("s0[L.2[x={=", testAst("s = { [0].L[2] = x};"));
|
||||||
|
|
||||||
// struct initialization hang
|
// struct initialization hang
|
||||||
|
@ -8162,6 +8161,8 @@ private:
|
||||||
ASSERT_EQUALS("ab-(=", testAst("a = ((int)-b)")); // Multiple subsequent unary operators (cast and -)
|
ASSERT_EQUALS("ab-(=", testAst("a = ((int)-b)")); // Multiple subsequent unary operators (cast and -)
|
||||||
ASSERT_EQUALS("xdouble123(i*(=", testAst("x = (int)(double(123)*i);"));
|
ASSERT_EQUALS("xdouble123(i*(=", testAst("x = (int)(double(123)*i);"));
|
||||||
ASSERT_EQUALS("ac(=", testAst("a = (::b)c;"));
|
ASSERT_EQUALS("ac(=", testAst("a = (::b)c;"));
|
||||||
|
ASSERT_EQUALS("abcd,({(=", testAst("a = (s){b(c, d)};"));
|
||||||
|
ASSERT_EQUALS("xatoistr({(=", testAst("x = (struct X){atoi(str)};"));
|
||||||
|
|
||||||
// not cast
|
// not cast
|
||||||
ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
|
ASSERT_EQUALS("AB||", testAst("(A)||(B)"));
|
||||||
|
|
Loading…
Reference in New Issue