Fabian Keßler
Fabian Keßler

Reputation: 683

clang AST Matcher: Whats the best way to match the current Matcher over hasParent()

I am trying to search for ifStmts, which aren't an else if. To accomplish that, I want to test if the Stmt has a Parent, which is not an ifStmt(hasElse(ifStmt(equals(<myCurrentNode>))))

The following obviously does not work, but I could not find a better solution.

clang-query> m ifStmt(<myMatcherforMyNode>, unless(hasParent(ifStmt(hasElse(ifStmt(equalsBoundNode("ifelse"))))))).bind("ifelse")

Upvotes: 1

Views: 811

Answers (1)

Fabian Ke&#223;ler
Fabian Ke&#223;ler

Reputation: 683

Ok just found it out myself by searching the source of clang-tidy:

Just use something like ifStmt(ifStmt().bind("if"), <myMatcherForMyNode>, unless(hasParent(ifStmt(hasElse(ifStmt(equalsBoundNode("if"))))))).

Also, ifStmt(stmt().bind("if"), <myMatcherForMyNode>, unless(hasParent(ifStmt(hasElse(ifStmt(equalsBoundNode("if"))))))) will do the job

Upvotes: 2

Related Questions