[cfe-dev] Problem with visiting AST to find STL function call
HotDog
hotdog_x at hotmail.com
Tue Oct 9 05:28:51 PDT 2012
Im writing a small program with clang library to find function call in any C++ code.
Its work well on user defined function.
But its not work if C++ code call the built-in STL function.
This is an example C++ code
I want to visit for_each() function call
--------------------------------------
#include <vector>
#include <algorithm>
int main() {
vector<int> my_vector;
for_each(my_vector.begin(), my_vector.end(), ...);
return 0;
}
--------------------------------------
This is my clangs AST consumer class
--------------------------------------
class MyASTConsumer :
public ASTConsumer,
public RecursiveASTVisitor<MyASTConsumer> {
void HandleTranslationUnit(ASTContext &Ctx) {
TraverseDecl(Ctx.getTranslationUnitDecl());
}
bool VisitCallExpr(CallExpr *E) {
E->dump(); // just print this function call to screen
return true;
}
}
--------------------------------------
Ive checked my program that
- User defined function call is work well.
- Standard C function call is work well. (such as printf(), time(), abs(), ...)
- STL function call is NOT work.
- My clang have successfully detected the included STL header. (Ive checked by printing function declaration such as for_each(), find_if(), swap(), ...)
My clang environment are
- Clang library 3.1 complied with MSVC 2010.
- My program is written on MSVC 2010. (STL header is MSVC 2010)
- My computer is Windows 7 x64
Thank you for any suggestions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121009/21b2335d/attachment.html>
More information about the cfe-dev
mailing list