[cfe-dev] Using the clang::SourceManager's after calling clang::ParseAST()

Paolo Bolzoni bolzoni at cs.unipr.it
Thu Oct 30 04:43:13 PDT 2008


I'd like to use clang's AST for global (i.e., compilation-unit-wide)
analyses.  Thus, I plan to make a clang::ASTConsumer derived class
that collects everything I need and finally analyze the data as a
whole.

After the analysis, in order to produce interesting output messages
I need to refer to the source files using the clang::SourceLocation.

As far as I understand, the clang::SourceLocation(s) are just integers
references that only make sense with respect to the clang::SourceManager,
which is part of the preprocessor I have to make to parse the file and
obtain the AST.

Now, if I use: clang::ParseAST(&PP, *C, false, false) (overriding the
FreeMemory default parameter) after completing parsing is it true
that the clang::SourceManager inside PP will still contains all the
info about the last parsed compilation unit?

If so, can I just to keep copies of clang::SourceLocation(s) and use
them with that source manager?

pb



More information about the cfe-dev mailing list