[cfe-dev] PPCallbacks problem

boba2001 asasasdd at mail.ru
Mon Apr 22 02:01:17 PDT 2013


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.



More information about the cfe-dev mailing list