From 35d04cd2d390a01210c72d585e0845b751b63b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 1 Nov 2019 09:05:45 +0100 Subject: [PATCH] AST: non-standard handling of ; in argument list for unknown macro --- lib/tokenlist.cpp | 7 ++++++- test/testgarbage.cpp | 2 +- test/testtokenize.cpp | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index d059a9ad7..15879d813 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -440,7 +440,8 @@ struct AST_state { bool cpp; int assign; bool inCase; // true from case to : - explicit AST_state(bool cpp) : depth(0), inArrayAssignment(0), cpp(cpp), assign(0), inCase(false) {} + const Token *functionCallEndPar; + explicit AST_state(bool cpp) : depth(0), inArrayAssignment(0), cpp(cpp), assign(0), inCase(false), functionCallEndPar(nullptr) {} }; static Token * skipDecl(Token *tok) @@ -1119,6 +1120,8 @@ static void compileComma(Token *&tok, AST_state& state) tok = tok->next(); else compileBinOp(tok, state, compileAssignTernary); + } else if (tok->str() == ";" && state.functionCallEndPar && tok->index() < state.functionCallEndPar->index()) { + compileBinOp(tok, state, compileAssignTernary); } else break; } } @@ -1356,6 +1359,8 @@ static Token * createAstAtToken(Token *tok, bool cpp) Token * const tok1 = tok; AST_state state(cpp); + if (Token::Match(tok, "%name% (")) + state.functionCallEndPar = tok->linkAt(1); compileExpression(tok, state); const Token * const endToken = tok; if (endToken == tok1 || !endToken) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 8791b7e41..492be63a3 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -316,7 +316,7 @@ private: void wrong_syntax1() { { const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; - ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", checkCode(code)); + ASSERT_THROW(checkCode(code), InternalError); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 90027e914..564591f51 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7122,6 +7122,7 @@ private: tokenList.combineOperators(); tokenList.createLinks(); tokenList.createLinks2(); + tokenList.list.front()->assignIndexes(); // set varid.. for (Token *tok = tokenList.list.front(); tok; tok = tok->next()) { @@ -7423,7 +7424,7 @@ private: "y=(int)(d({e(f);}));")); ASSERT_EQUALS("A{,( x0= Bx1={{,( x2=", // TODO: This is not perfect!! testAst("A({},{x=0;});" // don't hang - "B({x=1;},{x=2;});")); + "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--;}) ) {}")); @@ -7520,6 +7521,7 @@ private: ASSERT_EQUALS("for_each_commit_graftint((void,(", testAst("extern int for_each_commit_graft(int (*)(int*), void *);")); ASSERT_EQUALS("for;;(", testAst("for (;;) {}")); ASSERT_EQUALS("xsizeofvoid(=", testAst("x=sizeof(void*)")); + ASSERT_EQUALS("abc;(", testAst("a(b;c)")); } void asttemplate() { // uninstantiated templates will have <,>,etc..