AST: Fixed AST for struct cast '(struct T){...}'
This commit is contained in:
parent
f7612fd1a9
commit
cdee62c032
|
@ -528,6 +528,12 @@ static bool iscast(const Token *tok)
|
||||||
if (tok2->str() == ")") {
|
if (tok2->str() == ")") {
|
||||||
if (Token::simpleMatch(tok2, ") (") && Token::simpleMatch(tok2->linkAt(1), ") ."))
|
if (Token::simpleMatch(tok2, ") (") && Token::simpleMatch(tok2->linkAt(1), ") ."))
|
||||||
return true;
|
return true;
|
||||||
|
if (Token::simpleMatch(tok2, ") {") && !type) {
|
||||||
|
const Token *tok3 = tok2->linkAt(1);
|
||||||
|
while (tok3 != tok2 && Token::Match(tok3, "[{}]"))
|
||||||
|
tok3 = tok3->previous();
|
||||||
|
return tok3 != tok2 && tok3->str() != ";";
|
||||||
|
}
|
||||||
return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") ||
|
return type || tok2->strAt(-1) == "*" || Token::simpleMatch(tok2, ") ~") ||
|
||||||
(Token::Match(tok2, ") %any%") &&
|
(Token::Match(tok2, ") %any%") &&
|
||||||
!tok2->next()->isOp() &&
|
!tok2->next()->isOp() &&
|
||||||
|
@ -987,7 +993,11 @@ static void compilePrecedence3(Token *&tok, AST_state& state)
|
||||||
Token* castTok = tok;
|
Token* castTok = tok;
|
||||||
castTok->isCast(true);
|
castTok->isCast(true);
|
||||||
tok = tok->link()->next();
|
tok = tok->link()->next();
|
||||||
|
const int inArrayAssignment = state.inArrayAssignment;
|
||||||
|
if (Token::Match(tok, "{ . %name% ="))
|
||||||
|
state.inArrayAssignment = 1;
|
||||||
compilePrecedence3(tok, state);
|
compilePrecedence3(tok, state);
|
||||||
|
state.inArrayAssignment = inArrayAssignment;
|
||||||
compileUnaryOp(castTok, state, nullptr);
|
compileUnaryOp(castTok, state, nullptr);
|
||||||
} else if (state.cpp && Token::Match(tok, "new %name%|::|(")) {
|
} else if (state.cpp && Token::Match(tok, "new %name%|::|(")) {
|
||||||
Token* newtok = tok;
|
Token* newtok = tok;
|
||||||
|
|
|
@ -2952,8 +2952,6 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void symboldatabase45() {
|
void symboldatabase45() {
|
||||||
// TODO: Do not throw AST validation exception
|
|
||||||
/*
|
|
||||||
GET_SYMBOL_DB("typedef struct {\n"
|
GET_SYMBOL_DB("typedef struct {\n"
|
||||||
" unsigned long bits;\n"
|
" unsigned long bits;\n"
|
||||||
"} S;\n"
|
"} S;\n"
|
||||||
|
@ -2982,7 +2980,6 @@ private:
|
||||||
ASSERT_EQUALS(Scope::eStruct, scope->type);
|
ASSERT_EQUALS(Scope::eStruct, scope->type);
|
||||||
++scope;
|
++scope;
|
||||||
ASSERT_EQUALS(Scope::eFunction, scope->type);
|
ASSERT_EQUALS(Scope::eFunction, scope->type);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void symboldatabase46() { // #6171 (anonymous namespace)
|
void symboldatabase46() { // #6171 (anonymous namespace)
|
||||||
|
|
Loading…
Reference in New Issue