[cfe-dev] Problem with visiting AST to find STL function call

Jordan Rose jordan_rose at apple.com
Wed Oct 10 09:44:04 PDT 2012


This is just a guess, but did you try actually using the 'std' namespace? The code you've posted doesn't even compile (even if I put something in the "...") unless I say 'std::vector'.

The call to std::for_each should definitely show up as a CallExpr.

Jordan


On Oct 9, 2012, at 5:28 , HotDog <hotdog_x at hotmail.com> wrote:

> I’m writing a small program with clang library to find function call in any C++ code.
> It’s work well on user defined function.
> But it’s 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 clang’s 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;
>     }
> }
> --------------------------------------
>  
> I’ve 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. (I’ve 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.
>  
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list