[cfe-dev] Clang AST Matcher - Matching nested function and method calls
David Lai via cfe-dev
cfe-dev at lists.llvm.org
Tue Mar 27 10:30:22 PDT 2018
Hi,
I am quite new to clang AST matchers and wondering if you could help me with a match. I am writing a matcher to generate replacements.
Consider this,
SomeClientBuilder SCB(Foo& f) {
return SomeClientBuilder.setFoo(f);
}
class SomeClientBuilder {
Fruit apple(…);
Fruit pear(…);
};
I would like to change
“return SCB(foo).apple(req).get(…)”
to
“return SCB().pear(req).via(foo).get(…)”
I would like to create a matcher that:
- matches SCB so it has 1 argument of type Foo
- matches method named apple() and is a method in SomeClientBuilder
After many attempts, I came up with two matchers.
1. cxxMemberCallExpr(callee(cxxMethodDecl(hasName("apple"), ofClass(cxxRecordDecl(hasName("SomeClientBuilder "))))))
- this matcher does not restrict SCB to have 1 argument of type Foo
2. callExpr(callee(functionDecl(hasName("SCB"))), argumentCountIs(1), hasArgument(0, hasType(cxxRecordDecl(hasName("Foo")))))
- this matcher does not match the “apple()” methods
I have tried combining the matchers together with no success. What do you think would be the best way to accomplish what I want to do?
Thanks,
David Lai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180327/b5db690b/attachment.html>
More information about the cfe-dev
mailing list