Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class CPPCHECKLIB Token {
Token* mAstOperand1{};
Token* mAstOperand2{};
Token* mAstParent{};
Token* mAstTop{};

// symbol database information
const Scope* mScope{};
Expand Down Expand Up @@ -1557,6 +1558,9 @@ class CPPCHECKLIB Token {
* @throws InternalError thrown on cyclic dependency
*/
void astParent(Token* tok);
void astTop(Token * tok) {
mImpl->mAstTop = tok;
}

Token * astOperand1() {
return mImpl->mAstOperand1;
Expand Down Expand Up @@ -1597,13 +1601,19 @@ class CPPCHECKLIB Token {

}
RET_NONNULL Token *astTop() {
if (mImpl->mAstTop) {
return mImpl->mAstTop;
}
Token *ret = this;
while (ret->mImpl->mAstParent)
ret = ret->mImpl->mAstParent;
return ret;
}

RET_NONNULL const Token *astTop() const {
if (mImpl->mAstTop) {
return mImpl->mAstTop;
}
const Token *ret = this;
while (ret->mImpl->mAstParent)
ret = ret->mImpl->mAstParent;
Expand Down
10 changes: 10 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,16 @@ void TokenList::createAst() const
throw InternalError(tok, "Syntax Error: Infinite loop when creating AST.", InternalError::AST);
tok = nextTok;
}
for (Token *tok = mTokensFrontBack->front; tok; tok = tok ? tok->next() : nullptr) {
if (tok->astParent())
continue;
if (!tok->astOperand1() && !tok->astOperand2())
continue;
visitAstNodes(tok, [&](Token* child) {
child->astTop(tok);
return ChildrenToVisit::op1_and_op2;
});
}
}

namespace {
Expand Down
Loading