Getting Started

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Getting Started

Joe Ranieri
Hi, is there any documentation on getting started using the Clang
libraries in a project? A few months back, I had it working with the
code below, but it has since broken. I looked a bit and it's non-obvious
how to do this correctly (I simply want to run an ASTConsumer over a
source file).

-- Joe Ranieri

TextDiagnosticBuffer diagClient;
Diagnostic diags(&diagClient);
LangOptions opts;
opts.ObjC1 = true;
opts.ObjC2 = true;
opts.ObjCNonFragileABI = true;
opts.Blocks = true;

FileManager fm;
SourceManager sm;
HeaderSearch headers(fm);
InitHeaderSearch init(headers);

const FileEntry* file = fm.getFile(argv[1]);
sm.createMainFileID(file, SourceLocation());

OwningPtr<TargetInfo> target(TargetInfo::CreateTargetInfo(LLVM_HOSTTRIPLE));
Preprocessor pp(diags, opts, *target, sm, headers);
ASTContext context(pp.getLangOptions(),

TestConsumer consumer;
ParseAST(pp, &consumer, context, false);
cfe-dev mailing list
[hidden email]