0

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.

G Gill
  • 1,087
  • 1
  • 12
  • 24

2 Answers2

2

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.

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
Mehrnoosh EP
  • 161
  • 7
2

Yes, it is possible using equalsBoundNode

Usage:

expr(declRefExpr().bind("id"), hasDesendent(declRefExpr(equalsBoundNode("id")));
G Gill
  • 1,087
  • 1
  • 12
  • 24