[cfe-dev] how to add objectlike macro?
    huc1985 
    huc1985 at 163.com
       
    Thu Apr 11 19:53:30 PDT 2013
    
    
  
Thank you for reply.
I'm not using the command line. I just want to define macro programatically. 
This is my code: 
    DiagnosticOptions diagnosticOptions;
    TextDiagnosticPrinter *printer = new
TextDiagnosticPrinter(llvm::nulls(), diagnosticOptions);
    llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs;
    DiagnosticsEngine diagnostics(diagIDs, printer);
    LangOptions languageOptions;
    FileSystemOptions fileSystemOptions;
    FileManager fileManager(fileSystemOptions);    
    SourceManager sourceManager(diagnostics, fileManager);
    TargetOptions targetOptions;	
    targetOptions.Triple = llvm::sys::getDefaultTargetTriple();	
    TargetInfo *pTargetInfo =
clang::TargetInfo::CreateTargetInfo(diagnostics, targetOptions);
    HeaderSearch headerSearch(fileManager, diagnostics, languageOptions,
pTargetInfo);
    HeaderSearchOptions headerSearchOptions;
    for (set<string>::iterator it =
filefold.begin();it!=filefold.end();it++)
    {
        headerSearchOptions.AddPath(*it,frontend::Quoted,false,false,false);
    }
    ApplyHeaderSearchOptions(headerSearch, headerSearchOptions,
languageOptions, pTargetInfo->getTriple());
    CompilerInstance* ci = new CompilerInstance;
    CompilerInstance& theCompInst = *ci;
    Preprocessor *ppp = new Preprocessor(diagnostics, languageOptions,
pTargetInfo, sourceManager, headerSearch, theCompInst);
    Preprocessor& pp = *ppp;
    PreprocessorOptions preprocessorOptions;
    FrontendOptions frontendOptions;
    InitializePreprocessor(pp,  preprocessorOptions, headerSearchOptions,
frontendOptions);
    
*    for (int i=0;i<(int)compile_define.size();i++)
    {
        RegisterMacro(ppp, compile_define[i]);   <<<<<============== add
Preprocessor define
    }*
    const FileEntry *pFile = fileManager.getFile(file_name);
    sourceManager.createMainFileID(pFile);
  
    theCompInst.setDiagnostics(&diagnostics);
   
theCompInst.getDiagnosticClient().BeginSourceFile(theCompInst.getLangOpts(),&pp);
    theCompInst.setPreprocessor(&pp);
    theCompInst.setSourceManager(&sourceManager);
    theCompInst.setTarget(pTargetInfo);
    theCompInst.setDiagnostics(&diagnostics);
    SourceManager &sourceMgr = theCompInst.getSourceManager();
    theCompInst.createASTContext();
    Rewriter rewriter;
    rewriter.setSourceMgr(sourceMgr,languageOptions);
    MemoryMonitorASTConsumer consumer(rewriter);
    consumer.mVisitor.SetCheckFunctionName(function);
    consumer.mVisitor.SetCheckFunctionArgumentIndex(arg_index);
    ParseAST(theCompInst.getPreprocessor(), &consumer,
theCompInst.getASTContext());
    theCompInst.getDiagnosticClient().EndSourceFile();
--
View this message in context: http://clang-developers.42468.n3.nabble.com/how-to-add-objectlike-macro-tp4031430p4031447.html
Sent from the Clang Developers mailing list archive at Nabble.com.
    
    
More information about the cfe-dev
mailing list