G Gill
G Gill

Reputation: 1107

Writing Clang AST Matchers

Is it possible to use the bind string on one expression in the other like the following code:

expr(declRefExpr().bind("id"), hasDesendent(declRefExpr(has("id")));

Basically to use bind id string of one node to find the other node.

Upvotes: 0

Views: 1219

Answers (2)

G Gill
G Gill

Reputation: 1107

Yes, it is possible using equalsBoundNode

Usage:

expr(declRefExpr().bind("id"), hasDesendent(declRefExpr(equalsBoundNode("id")));

Upvotes: 2

Mehrnoosh EP
Mehrnoosh EP

Reputation: 161

The best way to compare 2 nodes is to bind in different id strings and then compare them in the callback method.

This is explained in this tutorial.

In the above link you can find the following code:

const VarDecl *IncVar = Result.Nodes.getNodeAs<VarDecl>("incVarName");
const VarDecl *CondVar = Result.Nodes.getNodeAs<VarDecl>("condVarName");
if (!areSameVariable(IncVar, CondVar))
    return;

This code aims to compare nodes that are bind in variables incVarName and condVarName in the call back function.

Upvotes: 2

Related Questions