isPrime
isPrime

Reputation: 141

ASTMatcher for class instance with Initialization and the member function call

I'm having difficulty getting the ASTMatcher for the following entities. The first one is the instance of a class.

Vec v1(1.0,1.0,1.0);
Vec v2(2.0,2.0,2.0);

Ideally, I can have a matcher that can match both instances.

The second is to capture the call of a member function vec_add and its implicit argumentv1 and explicit argumentv2.

Vec v3 = v1.vec_add(v1);
Vec v4 = v1.vec_add(v2);

Upvotes: 1

Views: 193

Answers (1)

isPrime
isPrime

Reputation: 141

I figured out the solution for the first kind:

declStmt(containsDeclaration(0, varDecl(hasInitializer(cxxConstructExpr(argumentCountIs(3))))))

The solution to the second kind is

callExpr(callee(namedDecl(hasName("vec_add"))))

Now I kinda know how to think about the design now. Stay tuned for my blog on this!

Upvotes: 1

Related Questions