[cfe-dev] PPCallbacks problem
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Apr 22 16:39:58 PDT 2013
Look into ASTUnit::LoadFromCompilerInvocationAction that accepts a ASTFrontendAction, giving you more control over the parsing process.
On Apr 22, 2013, at 2:01 AM, boba2001 <asasasdd at mail.ru> wrote:
> Hi! I faced with following problem. I want to get information about macros. I
> understood that its possible with class PPCallbacks. I created my class
> MacroFinder, which was inherited from PPCallbacks, defined method
> MacroFinder::Ifdef and used the class in following code. However method
> MacroFinder::Ifdef weren`t calling. As I understood, it happens because an
> instance of Preprocessor is created inside
> ASTUnit::LoadFromCompilerInvocation(), and my callbacks are set after
> parsing was finished. Can you teel me please how to install a callbacks?
>
> ClangParser::ClangParser(std::vector< const char *> & args_) :
> args(args_)
> {
> const char ** opts = &args.front();
> int opts_num = args.size();
>
> CompilerInstance oCompilerInstance;
> oCompilerInstance.createDiagnostics(
> opts_num, // Argc
> opts, // Argv
> 0, // Client
> true, // ShouldOwnClient
> false // ShouldCloneClient
> );
>
> IntrusiveRefCntPtr< DiagnosticsEngine >
> diags(&oCompilerInstance.getDiagnostics());
>
> IntrusiveRefCntPtr< CompilerInvocation > compInvoke =
> clang::createInvocationFromCommandLine(
> makeArrayRef(opts, opts + opts_num), // Args
> diags // Diags
> );
>
> if (!compInvoke) {
> std::cout << "Can't create compiler invocation for given args" ;
> return -1;
> } else {
> tu = ASTUnit::LoadFromCompilerInvocation(
> compInvoke.getPtr(), // CI
> diags, // Diags
> false, // OnlyLocalDecls
> true, // CaptureDiagnostics
> false, // PrecompilePreamble
> TU_Prefix, // TUKind
> false, // CacheCodeCompletionResults
> false, // IncludeBriefCommentsInCodeCompletion
> false // UserFilesAreVolatile
> );
>
> MacroFinder oMacroFinder;
> tu -> getPreprocessor().addPPCallbacks(&oMacroFinder);
> }
> }
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/PPCallbacks-problem-tp4031625.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