[cfe-dev] clang api in qt5.2
serg3091
serg3091 at mail.ru
Sat Feb 22 12:43:24 PST 2014
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.
More information about the cfe-dev
mailing list