AST: Adjust AST for variable declaration 'char var[] = str;'
This commit is contained in:
parent
6cf571af97
commit
376860f796
|
@ -1553,8 +1553,22 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
typecount++;
|
||||
typetok = typetok->next();
|
||||
}
|
||||
if (Token::Match(typetok, "%var% =") && typetok->varId())
|
||||
tok = typetok;
|
||||
if (Token::Match(typetok, "%var% =|[") && typetok->varId()) {
|
||||
Token *tok2 = typetok->next();
|
||||
while (Token::simpleMatch(tok2, "["))
|
||||
tok2 = tok2->link()->next();
|
||||
if (Token::simpleMatch(tok2, "=")) {
|
||||
AST_state state(cpp);
|
||||
state.op.push(typetok);
|
||||
Token * const start = tok2;
|
||||
compileBinOp(tok2, state, compileAssignTernary);
|
||||
if (tok2 == start || !tok2)
|
||||
return start;
|
||||
createAstAtTokenInner(start->next(), tok2, cpp);
|
||||
return tok2;
|
||||
} else if (Token::simpleMatch(tok2, ";"))
|
||||
return tok;
|
||||
}
|
||||
|
||||
// Do not create AST for function declaration
|
||||
if (typetok &&
|
||||
|
|
|
@ -7857,7 +7857,7 @@ private:
|
|||
|
||||
void astvardecl() {
|
||||
// Variable declaration
|
||||
ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";"));
|
||||
ASSERT_EQUALS("var\"\"=", testAst("char var[1]=\"\";"));
|
||||
ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];"));
|
||||
ASSERT_EQUALS("varp=", testAst("const int *var = p;"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue