AST: improved handling for struct initialization 's = { [0] = 123 }'

This commit is contained in:
Daniel Marjamäki 2017-04-10 07:25:18 +02:00
parent d92c529aa6
commit ffeadbdde4
2 changed files with 6 additions and 1 deletions

View File

@ -581,7 +581,11 @@ static void compileTerm(Token *&tok, AST_state& state)
tok = tok->next();
if (state.inArrayAssignment && tok->str() == "." && Token::Match(tok->previous(), ",|{")) // Jump over . in C style struct initialization
tok = tok->next();
if (state.inArrayAssignment && Token::Match(tok->previous(), "[,{] [ %num% ]")) {
state.op.push(tok);
tok->astOperand1(tok->next());
tok = tok->tokAt(3);
}
if (tok->isLiteral()) {
state.op.push(tok);
do {

View File

@ -8070,6 +8070,7 @@ private:
ASSERT_EQUALS("tset{=", testAst("struct cgroup_taskset tset = {};"));
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};"));
// struct initialization hang
ASSERT_EQUALS("sbar1{,{(={= fcmd( forfieldfield++;;(",