[cfe-dev] How to get the AST of a single cpp file with clang?

Jason Haslam jason.haslam at gmail.com
Wed Nov 13 21:47:38 PST 2013


This is not possible as far as I understand. Parsing and semantic analysis can’t be done as separate steps. Invalid nodes may be omitted from the AST.

Jason


On Nov 13, 2013, at 10:56 AM, ruben <rdealba at codicesoftware.com> wrote:

> I know that it will never be fully accurate without the headers because C++
> isn't context free. 
> 
> Using the classic example of 'A B(C);', it means that it can be recognized
> as a function declaration or an object definition. Either is fine for me. I
> just need the file totally parsed.
> 
> I am not interested in the semantic analysis of the code, just in the
> syntactic one and AFAIK the grammar of clang is one of the best.
> 
> The problem is that in some scenarios clang is avoiding some declarations
> when it doesn't know the types although I guess it can correctly parse it.
> 
> See the following case. Content of class.cpp:
> 
> /      A::A() { }
> 
>      A::~A() { }
> 
>      void A::B() { }
> 
>      A::C() { }/
> 
> Executing the clang command line application:
> 
> /    $ clang -Xclang -ast-dump -fsyntax-only class.cpp/
> 
> it's just recognizing as AST nodes the constructor and the last method.
> 
> /     typedef char *__builtin_va_list;
> 
>     int A() (CompoundStmt 0x9a6a570 <class.cpp:3:8, col:10>)
> 
>     int C() (CompoundStmt 0x9a6a600 <class.cpp:9:8, col:10>)/
> 
> Is there any way to get the complete AST tree?
> 
> Thanks!
> 
> 
> 
> 
> 
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/How-to-get-the-AST-of-a-single-cpp-file-with-clang-tp4036017.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> 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