From ffeadbdde425fb898c7be0a80a7ac2d5d20c4986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 10 Apr 2017 07:25:18 +0200 Subject: [PATCH] AST: improved handling for struct initialization 's = { [0] = 123 }' --- lib/tokenlist.cpp | 6 +++++- test/testtokenize.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a43e23f91..0aa0ee7c5 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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 { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 58ed76be0..2ae5a19b6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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++;;(",