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

HotDog hotdog_x at hotmail.com
Wed Oct 10 11:03:47 PDT 2012


In fact, I shorten the example C++ code to easy reading : )
The full code, I have "using namespace std;", as well.
So I try with full call "std::for_each", too. But it's still not work.

But.. Good new, I try to change the clang environment to MinGW32 instead of 
MSVC2010.
It's work !!
1. I newly compile clang library with MinGW32
2. My program is compile with MinGW32. (C++ header come from MinGW32)
3. OS is the same = Windows 7 x64
4. My program is unmodified !

Now, my program can visit STL function call : )

I don't know the reason.
But I guess that there are some of special syntax in MSVC2010 STL header 
that clang can not understand ?


-----Original Message----- 
From: Jordan Rose
Sent: Wednesday, October 10, 2012 11:44 PM
To: HotDog
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] Problem with visiting AST to find STL function call

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