This commit is contained in:
Zorgovskiy 2020-04-20 08:59:35 +02:00 committed by GitHub
parent 5626d22835
commit 08fc956990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View File

@ -3115,7 +3115,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
{
Token *tok = *tok1;
if (Token::Match(tok, "%name% = { . %name% =")) {
if (Token::Match(tok, "%name% = { . %name% =|{")) {
const int struct_varid = tok->varId();
if (struct_varid == 0)
return;
@ -3126,7 +3126,7 @@ void Tokenizer::setVarIdStructMembers(Token **tok1,
while (tok->str() != "}") {
if (Token::Match(tok, "{|[|("))
tok = tok->link();
if (Token::Match(tok->previous(), "[,{] . %name% =")) {
if (Token::Match(tok->previous(), "[,{] . %name% =|{")) {
tok = tok->next();
const std::map<std::string, int>::iterator it = members.find(tok->str());
if (it == members.end()) {
@ -9365,7 +9365,7 @@ void Tokenizer::reportUnknownMacros()
for (const Token *inner = tok->tokAt(2); inner != endTok; inner = inner->next()) {
if (Token::Match(inner, "[[({]"))
inner = inner->link();
else if (Token::Match(inner->previous(), "[,(] . %name% ="))
else if (Token::Match(inner->previous(), "[,(] . %name% =|{"))
unknownMacroError(tok);
}
}
@ -9637,7 +9637,7 @@ void Tokenizer::findGarbageCode() const
if (Token::simpleMatch(tok, ".") &&
!Token::simpleMatch(tok->previous(), ".") &&
!Token::simpleMatch(tok->next(), ".") &&
!Token::Match(tok->previous(), "{|, . %name% =|.|[") &&
!Token::Match(tok->previous(), "{|, . %name% =|.|[|{") &&
!Token::Match(tok->previous(), ", . %name%")) {
if (!Token::Match(tok->previous(), "%name%|)|]|>|}"))
syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1));

View File

@ -783,7 +783,7 @@ static void compileTerm(Token *&tok, AST_state& state)
tok = tok->next();
if (tok->str() == "<")
tok = tok->link()->next();
if (Token::Match(tok, "{ . %name% =")) {
if (Token::Match(tok, "{ . %name% =|{")) {
const int inArrayAssignment = state.inArrayAssignment;
state.inArrayAssignment = 1;
compileBinOp(tok, state, compileExpression);

View File

@ -7705,6 +7705,7 @@ private:
ASSERT_EQUALS("xB[1y.z.1={(&=,{={=", testAst("x = { [B] = {1, .y = &(struct s) { .z=1 } } };"));
ASSERT_EQUALS("xab,c,{=", testAst("x={a,b,(c)};"));
ASSERT_EQUALS("x0fSa.1=b.2=,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = 1, .b = 2, .c = \"\" });"));
ASSERT_EQUALS("x0fSa.1{=b.2{,c.\"\"=,{(||=", testAst("x = 0 || f(S{.a = { 1 }, .b { 2 }, .c = \"\" });"));
// struct initialization hang
ASSERT_EQUALS("sbar.1{,{(={= fcmd( forfieldfield++;;(",
@ -8038,6 +8039,9 @@ private:
// op op
ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), InternalError, "syntax error: == >");
// Ticket #9664
ASSERT_NO_THROW(tokenizeAndStringify("S s = { .x { 2 }, .y[0] { 3 } };"));
}

View File

@ -2497,6 +2497,13 @@ private:
tokenize("void foo() {\n"
" struct ABC abc = {.a=abc.a,.b=abc.b};\n"
"}"));
ASSERT_EQUALS("1: void foo ( ) {\n"
"2: struct ABC abc@1 ; abc@1 = { . a@2 { abc@1 . a@2 } , . b@3 = { abc@1 . b@3 } } ;\n"
"3: }\n",
tokenize("void foo() {\n"
" struct ABC abc = {.a { abc.a },.b= { abc.b } };\n"
"}"));
}
void varid_arrayinit() { // #7579 - no variable declaration in rhs