[cfe-dev] ASTContext: how to get an object or pointer of ASTContext

Jiandong Wang computerhenu at gmail.com
Tue May 18 06:09:05 PDT 2010


Hi all:
    now I am trying to run my own ASTConsumer against AST, but not quite
sure how to do it, especially how to get an object or pointer of ASTContext.
BTW, ASTContext is required by ParseAST.
here is my code snippet:
_______________________________________

        MyDiagnosticClient DiagClient(llvm::errs());
Diagnostic Diags(&DiagClient);
 LangOptions Opts;
        TargetOptions TargetOpts;
        TargetInfo* Target = TargetInfo::CreateTargetInfo(Diags,
TargetOpts);
 SourceManager SM;
FileManager FM;
HeaderSearch Headers(FM);

llvm::StringRef filename("input.c");
const FileEntry* File = FM.getFile(filename);
 if (!File) {
  llvm::errs() << "Failed to open \'" << filename << "\'\n" ;
  return 1;
}

SM.createMainFileID(File, SourceLocation());
 Preprocessor PP(Diags, Opts, *Target, SM, Headers);
ASTConsumer* AstConsumer = new MyASTConsumer;
 ParseAST(PP, AstConsumer, *here need the third parameter ASTContext*);
//<------------------------- see here
 delete Target;
______________________________________

any ideas? Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100518/632bee5d/attachment.html>


More information about the cfe-dev mailing list