[cfe-dev] clang api in qt5.2
Manuel Klimek
klimek at google.com
Tue Feb 25 04:30:03 PST 2014
I'd suggest to use libtooling (http://clang.llvm.org/docs/LibTooling.html)
instead of setting up your own compiler instance.
On Sat, Feb 22, 2014 at 9:43 PM, serg3091 <serg3091 at mail.ru> wrote:
> I'm a novice developer, use clang api for astdump. I use
> clang-check --version
> LLVM (http://llvm.org/):
> LLVM version 3.4
>
> Optimized build.
> Built Jul 31 2013 (18:59:40).
> Default target: x86_64-pc-linux-gnu
> Host CPU: core-avx-i
>
> but as I can not get through ast.
> here is my code,
>
> #include <QCoreApplication>
> #include <vector>
> #include <iostream>
> #include <QDebug>
> #include <clang/Basic/Diagnostic.h>
> #include <clang/Basic/DiagnosticOptions.h>
> #include <clang/Frontend/CompilerInstance.h>
> #include <clang/Frontend/CompilerInvocation.h>
> #include <clang/Frontend/Utils.h>
> #include <clang/Frontend/ASTUnit.h>
> #include <clang/Frontend/TextDiagnosticBuffer.h>
> #include <clang/Frontend/VerifyDiagnosticConsumer.h>
> #include <clang/Frontend/FrontendActions.h>
>
>
> using namespace clang ;
> using namespace llvm ;
>
> int main(int argc, char *argv[])
> {
> QCoreApplication a(argc, argv);
> DiagnosticOptions* diagOpts = new DiagnosticOptions();
> CodeGenOptions* codeGenOpts = new CodeGenOptions();
> CompilerInstance compiler;
> compiler.createDiagnostics(
> diagOpts,
> false,
> false,
> codeGenOpts
> ); // to stdout
> assert(compiler.hasDiagnostics());
> const char *args[] =
> {
> "-cc1", // вызов LLVM Clang
> "a.cpp" // входной файл
> };
>
> clang::CompilerInvocation::CreateFromArgs(
> compiler.getInvocation(),
> args,
> args + 2,
> compiler.getDiagnostics());
> assert(0 == compiler.getDiagnostics().getErrorsAsFatal());
> FrontendAction *action = new ASTDumpAction;
> if(compiler.ExecuteAction(action)){
> std::cout << "ok:";
> }else{
> std::cout << "error:";
> }
> std::cout << "8" << std::endl;
> assert(0 == compiler.getDiagnostics().getNumWarnings());
> assert(actionSuccessful);
> return a.exec();
> }
>
> please do not abuse for the code and my English
>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/clang-api-in-qt5-2-tp4038002.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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140225/5f5b0cbc/attachment.html>
More information about the cfe-dev
mailing list