rogerw
rogerw

Reputation: 75

Uniquely identify function definition node

Is there a way to uniquely identify function definition nodes in CDT AST?

void g() { ... }

void f() {
    g();
}

I need to store the function definition nodes for f and g in some structure and then, when I come to the function call node for g, I need to check if that node corresponds to the function definition node for g.

Right now I'm doing that by storing function's name. The problem is that I cannot correctly handle the following case:

void f() {}

class F {
    void f() {}
}; 

Upvotes: 2

Views: 99

Answers (1)

HighCommander4
HighCommander4

Reputation: 52779

I would suggest the following:

  • Resolve the name to the function binding via IASTName.resolveBinding()
  • The binding will be an instance of ICPPFunction, which extends ICPPBinding. (I'm assuming this is C++ code as you mention a class.)
  • Use ICPPBinding.getQualifiedName() as the unique identifier for the function. In your example, the two functions would have different qualified names, f vs. F::f.

Upvotes: 2

Related Questions