[cfe-dev] Matching method defined outside a class declaration
Jesper Eskilson
jesper.eskilson at iar.com
Tue Sep 17 05:24:37 PDT 2013
Hello,
I'm trying to write an AST matcher rule which is able to match method
definitions. Given the following C++ source code:
> class B
> {
> void foo();
> void bar() {
> int a_local_variable_in_bar;
> }
> };
>
> void B::foo()
> {
> int a_local_variable_in_foo;
> }
>
> B b
>
> int main()
> {
> }
I would like a matcher which can tell me where instances of B are
created and also give me the definitions of its methods (in this case
"foo" and "bar").
> StatementMatcher m = constructExpr(
> hasType(
> recordDecl(isSameOrDerivedFrom("B"),
> hasMethod(methodDecl(isDefinition()).bind("method")))));
But it will only give me the definition of "bar", and not the defintion
of "foo" which is declared outside the class.
If I cannot do this with matchers, is there a way to get to the
definition of "foo" given the declaration of the class B?
Thanks,
--
*Jesper Eskilson* /Development Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
Website: www.iar.com
<http://www.iar.com> Twitter: www.twitter.com/iarsystems
<http://www.twitter.com/iarsystems>
More information about the cfe-dev
mailing list