How to use RecursiveASTVisitor of clang to visit the functions implementation in c++?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use RecursiveASTVisitor of clang to visit the functions implementation in c++?

lotay
For example: the entry file of filemanager is "testcase.cpp", which including "#include test01.h", and "test01.h" has a class "Test", which a method declaration "void sayHi();", and implementation of "sayHi" locates in "test01.cpp".

For the above assumption, how can I use the the VisitCXXMethodDecl in RecursiveASTVisitor to get the implementation of sayHi(), and When invoke the method hasBody() of VisitCXXMethodDecl when visiting the sayHi() function, hasBody() return false.

The puzzle is how I can get the implementation of the sayHi() with "testcase.cpp" as the file entry of the source manager in the current CompilerInstance.

For the constructor and deconstructor, the puzzles also arise....

Thanks in advance!!


Reply | Threaded
Open this post in threaded view
|

Re: How to use RecursiveASTVisitor of clang to visit the functions implementation in c++?

Manuel Klimek
On Thu, Dec 19, 2013 at 12:27 PM, lotay <[hidden email]> wrote:
For example: the entry file of filemanager is "testcase.cpp", which including
"#include test01.h", and "test01.h" has a class "Test", which a method
declaration "void sayHi();", and implementation of "sayHi" locates in
"test01.cpp".

For the above assumption, how can I use the the VisitCXXMethodDecl in
RecursiveASTVisitor to get the implementation of sayHi(), and When invoke
the method hasBody() of VisitCXXMethodDecl when visiting the sayHi()
function, hasBody() return false.

You'll get a callback per declaration - in this case, you should get 2 calls of VisitCXXMethodDecl, and the second declaration is also a definition, which will have hasBody() return true.
 

The puzzle is how I can get the implementation of the sayHi() with
"testcase.cpp" as the file entry of the source manager in the current
CompilerInstance.

For the constructor and deconstructor, the puzzles also arise....

Thanks in advance!!






--
View this message in context: http://clang-developers.42468.n3.nabble.com/How-to-use-RecursiveASTVisitor-of-clang-to-visit-the-functions-implementation-in-c-tp4036699.html
Sent from the Clang Developers mailing list archive at Nabble.com.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev