本文整理汇总了C++中TextDiagnosticBuffer::FlushDiagnostics方法的典型用法代码示例。如果您正苦于以下问题:C++ TextDiagnosticBuffer::FlushDiagnostics方法的具体用法?C++ TextDiagnosticBuffer::FlushDiagnostics怎么用?C++ TextDiagnosticBuffer::FlushDiagnostics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextDiagnosticBuffer
的用法示例。
在下文中一共展示了TextDiagnosticBuffer::FlushDiagnostics方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DiagnosticsEngine
static IntrusiveRefCntPtr<DiagnosticsEngine>
createDiagnostics(unsigned int argc, char **argv) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(new DiagnosticIDs());
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
IntrusiveRefCntPtr<DiagnosticsEngine> InterimDiags(
new DiagnosticsEngine(DiagIDs, new DiagnosticOptions(), DiagsBuffer));
// Try to build a CompilerInvocation.
OwningPtr<CompilerInvocation> Invocation(
createInvocationFromCommandLine(ArrayRef<const char *>(argv, argc),
InterimDiags));
if (!Invocation)
return NULL;
// Build the diagnostics parser
IntrusiveRefCntPtr<DiagnosticsEngine> FinalDiags =
CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(),
argc, argv);
if (!FinalDiags)
return NULL;
// Flush any errors created when initializing everything. This could happen
// for invalid command lines, which will probably give non-sensical results.
DiagsBuffer->FlushDiagnostics(*FinalDiags);
return FinalDiags;
}
示例2: main
int main(int argc, const char **argv) {
// Only do front-end stuff
llvm::SmallVector<const char *, 16> Args(argv + 1, argv + argc);
Args.push_back("-fsyntax-only");
std::unique_ptr<CompilerInstance> Clang(new CompilerInstance());
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
DiagnosticOptions *DiagOpts = new DiagnosticOptions;
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
DiagnosticsEngine Diags(DiagID, DiagOpts, DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Args.begin(), Args.end(),
Diags);
// Infer the builtin include path if unspecified.
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
Clang->getHeaderSearchOpts().ResourceDir.empty())
Clang->getHeaderSearchOpts().ResourceDir =
CompilerInvocation::GetResourcesPath(argv[0], (void*) (intptr_t) foo);
// Create the actual diagnostics engine.
ASTTextDiagnosticPrinter *DiagPrinter =
new ASTTextDiagnosticPrinter(llvm::errs(), &Clang->getDiagnosticOpts());
Clang->createDiagnostics(DiagPrinter);
if (!Clang->hasDiagnostics()) {
return EXIT_FAILURE;
}
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
// If there were errors in processing arguments, don't do anything else.
if (Clang->getDiagnostics().hasErrorOccurred()) {
return EXIT_FAILURE;
}
// We can emit custom diagnostic messages that must be registered here.
registerCustomDiagnostics(Clang->getDiagnostics());
std::unique_ptr<FrontendAction> WalkAct(new ASTWalkerAction(Clang->getDiagnostics()));
if(!Clang->ExecuteAction(*WalkAct)) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例3: run
int csabase::run(int argc_, const char **argv_)
{
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc_, argv_);
SmallVector<const char *, 1024> argv;
SpecificBumpPtrAllocator<char> ArgAllocator;
StringSetSaver Saver;
sys::Process::GetArgumentVector(argv,
ArrayRef<const char *>(argv_, argc_),
ArgAllocator);
cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, argv);
argv.insert(argv.begin() == argv.end() ? argv.begin() : argv.begin() + 1,
"-xc++");
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmParser();
CompilerInstance Clang;
TextDiagnosticBuffer DiagsBuffer;
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions());
DiagnosticsEngine Diags(DiagID, &*DiagOpts, &DiagsBuffer, false);
bool Success = CompilerInvocation::CreateFromArgs(
Clang.getInvocation(),
argv.data() + 1,
argv.data() + argv.size(),
Diags);
Clang.createDiagnostics();
install_fatal_error_handler(LLVMErrorHandler, &Clang.getDiagnostics());
DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
if (Success) {
Success = ExecuteCompilerInvocation(&Clang);
}
remove_fatal_error_handler();
llvm::llvm_shutdown();
return !Success;
}
示例4: cc1_main
int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr) {
llvm::OwningPtr<CompilerInstance> Clang(new CompilerInstance());
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
// Run clang -cc1 test.
if (ArgBegin != ArgEnd && StringRef(ArgBegin[0]) == "-cc1test") {
Diagnostic Diags(DiagID, new TextDiagnosticPrinter(llvm::errs(),
DiagnosticOptions()));
return cc1_test(Diags, ArgBegin + 1, ArgEnd);
}
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
Diagnostic Diags(DiagID, DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang->getInvocation(), ArgBegin, ArgEnd,
Diags);
// Infer the builtin include path if unspecified.
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
Clang->getHeaderSearchOpts().ResourceDir.empty())
Clang->getHeaderSearchOpts().ResourceDir =
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
// Create the actual diagnostics engine.
Clang->createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang->hasDiagnostics())
return 1;
// Set an error handler, so that any LLVM backend diagnostics go through our
// error handler.
llvm::install_fatal_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang->getDiagnostics()));
DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
// Execute the frontend actions.
bool Success = ExecuteCompilerInvocation(Clang.get());
// If any timers were active but haven't been destroyed yet, print their
// results now. This happens in -disable-free mode.
llvm::TimerGroup::printAll(llvm::errs());
// Our error handler depends on the Diagnostics object, which we're
// potentially about to delete. Uninstall the handler now so that any
// later errors use the default handling behavior instead.
llvm::remove_fatal_error_handler();
// When running with -disable-free, don't do any destruction or shutdown.
if (Clang->getFrontendOpts().DisableFree) {
if (llvm::AreStatisticsEnabled() || Clang->getFrontendOpts().ShowStats)
llvm::PrintStatistics();
Clang.take();
return !Success;
}
// Managed static deconstruction. Useful for making things like
// -time-passes usable.
llvm::llvm_shutdown();
return !Success;
}
示例5: CompileSubprocess
static int CompileSubprocess(const char **argv, int argc,
sys::Path &ResourceDir, bool bugreport,
bool versionOnly, sys::Path &apiMapPath)
{
std::vector<char*> llvmArgs;
char apim[] = "-clam-apimap";
llvmArgs.push_back((char*)argv[0]);
llvmArgs.push_back(apim);
llvmArgs.push_back((char*)apiMapPath.c_str());
// Split args into cc1 and LLVM args, separator is --
int cc1_argc;
for (cc1_argc=1;cc1_argc<argc;cc1_argc++) {
if (StringRef(argv[cc1_argc]) == "--") {
for (int i=cc1_argc+1;i<argc;i++) {
llvmArgs.push_back((char*)argv[i]);
}
break;
}
}
// Initialize CompilerInstance from commandline args
CompilerInstance Clang;
Clang.setLLVMContext(new llvm::LLVMContext);
LLVMInitializeClamBCTargetInfo();
LLVMInitializeClamBCTarget();
TextDiagnosticBuffer DiagsBuffer;
Diagnostic Diags(&DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang.getInvocation(), argv+1,
argv+cc1_argc, Diags);
FrontendOptions &FrontendOpts = Clang.getInvocation().getFrontendOpts();
// Handle --version
if (FrontendOpts.ShowVersion || versionOnly) {
printVersion(outs(), true);
exit(0);
}
DiagnosticOptions &DiagOpts = Clang.getInvocation().getDiagnosticOpts();
DiagOpts.ShowOptionNames = DiagOpts.ShowColors = 1;
DiagOpts.MessageLength = 80;// we are writing to a file
DiagOpts.Warnings.push_back("all");
DiagOpts.Warnings.push_back("no-pointer-sign");
Clang.createDiagnostics(argc-1, const_cast<char**>(argv+1));
if (!Clang.hasDiagnostics())
return 2;
Clang.getInvocation().getHeaderSearchOpts().ResourceDir = ResourceDir.str();
// Set default options
LangOptions &LangOpts = Clang.getInvocation().getLangOpts();
// This is a freestanding environment, without libc, etc.
LangOpts.Freestanding = 1;
HeaderSearchOptions &HeaderSearchOpts =
Clang.getInvocation().getHeaderSearchOpts();
HeaderSearchOpts.UseStandardIncludes = 0;
if (bugreport)
HeaderSearchOpts.Verbose = 1;
if (FrontendOpts.ProgramAction != frontend::PrintPreprocessedInput)
FrontendOpts.ProgramAction = frontend::EmitBC;
if (bugreport)
FrontendOpts.ProgramAction = frontend::PrintPreprocessedInput;
// Don't bother freeing of memory on exit
FrontendOpts.DisableFree = 1;
CodeGenOptions &Opts = Clang.getInvocation().getCodeGenOpts();
Opts.Inlining = CodeGenOptions::OnlyAlwaysInlining;
// always generate debug info, so that ClamBC backend can output sourcelevel
// diagnostics.
Opts.DebugInfo = true;
// FIXME: once the verifier can work w/o targetdata, and targetdate opts set
// DisableLLVMOpts to true!
// This is needed to avoid target-specific optimizations
Opts.DisableLLVMOpts = false;
AnalyzerOptions &AOpts = Clang.getInvocation().getAnalyzerOpts();
AOpts.AnalysisList.push_back(WarnDeadStores);
AOpts.AnalysisList.push_back(WarnUninitVals);
AOpts.AnalysisList.push_back(SecuritySyntacticChecks);
AOpts.AnalysisList.push_back(WarnSizeofPointer);
// Set triple
Clang.getInvocation().getTargetOpts().Triple = "clambc-generic-generic";
// Set default include
Clang.getInvocation().getPreprocessorOpts().Includes.push_back("bytecode.h");
// Set an LLVM error handler.
llvm::llvm_install_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang.getDiagnostics()));
DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
// If there were any errors in processing arguments, exit now.
if (Clang.getDiagnostics().getNumErrors())
return 1;
// Create the target instance.
//TODO: directly create a clambc target
Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
//.........这里部分代码省略.........
示例6: cc1_main
int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr) {
CompilerInstance Clang;
Clang.setLLVMContext(new llvm::LLVMContext);
// Run clang -cc1 test.
if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
Diagnostic Diags(&DiagClient);
return cc1_test(Diags, ArgBegin + 1, ArgEnd);
}
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer DiagsBuffer;
Diagnostic Diags(&DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
Diags);
// Infer the builtin include path if unspecified.
if (Clang.getHeaderSearchOpts().UseBuiltinIncludes &&
Clang.getHeaderSearchOpts().ResourceDir.empty())
Clang.getHeaderSearchOpts().ResourceDir =
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
// Honor -help.
if (Clang.getFrontendOpts().ShowHelp) {
llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable());
Opts->PrintHelp(llvm::outs(), "clang -cc1",
"LLVM 'Clang' Compiler: http://clang.llvm.org");
return 0;
}
// Honor -version.
//
// FIXME: Use a better -version message?
if (Clang.getFrontendOpts().ShowVersion) {
llvm::cl::PrintVersionMessage();
return 0;
}
// Create the actual diagnostics engine.
Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang.hasDiagnostics())
return 1;
// Set an error handler, so that any LLVM backend diagnostics go through our
// error handler.
llvm::llvm_install_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang.getDiagnostics()));
DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
// Load any requested plugins.
for (unsigned i = 0,
e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
const std::string &Path = Clang.getFrontendOpts().Plugins[i];
std::string Error;
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
}
// If there were errors in processing arguments, don't do anything else.
bool Success = false;
if (!Clang.getDiagnostics().getNumErrors()) {
// Create and execute the frontend action.
llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(Clang));
if (Act)
Success = Clang.ExecuteAction(*Act);
}
// Managed static deconstruction. Useful for making things like
// -time-passes usable.
llvm::llvm_shutdown();
return !Success;
}
示例7: cc1_main
int cc1_main(const char **ArgBegin, const char **ArgEnd,
const char *Argv0, void *MainAddr) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(ArgBegin - ArgEnd, ArgBegin);
CompilerInstance Clang(&llvm::getGlobalContext(), false);
// Run clang -cc1 test.
if (ArgBegin != ArgEnd && llvm::StringRef(ArgBegin[0]) == "-cc1test") {
TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions());
Diagnostic Diags(&DiagClient);
return cc1_test(Diags, ArgBegin + 1, ArgEnd);
}
// Initialize targets first, so that --version shows registered targets.
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
// Buffer diagnostics from argument parsing so that we can output them using a
// well formed diagnostic object.
TextDiagnosticBuffer DiagsBuffer;
Diagnostic Diags(&DiagsBuffer);
CompilerInvocation::CreateFromArgs(Clang.getInvocation(), ArgBegin, ArgEnd,
Diags);
// Infer the builtin include path if unspecified.
if (Clang.getInvocation().getHeaderSearchOpts().UseBuiltinIncludes &&
Clang.getInvocation().getHeaderSearchOpts().ResourceDir.empty())
Clang.getInvocation().getHeaderSearchOpts().ResourceDir =
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
// Honor -help.
if (Clang.getInvocation().getFrontendOpts().ShowHelp) {
llvm::OwningPtr<driver::OptTable> Opts(driver::createCC1OptTable());
Opts->PrintHelp(llvm::outs(), "clang -cc1",
"LLVM 'Clang' Compiler: http://clang.llvm.org");
return 0;
}
// Honor -version.
//
// FIXME: Use a better -version message?
if (Clang.getInvocation().getFrontendOpts().ShowVersion) {
llvm::cl::PrintVersionMessage();
return 0;
}
// Create the actual diagnostics engine.
Clang.createDiagnostics(ArgEnd - ArgBegin, const_cast<char**>(ArgBegin));
if (!Clang.hasDiagnostics())
return 1;
// Set an error handler, so that any LLVM backend diagnostics go through our
// error handler.
llvm::llvm_install_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang.getDiagnostics()));
DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
// Load any requested plugins.
for (unsigned i = 0,
e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
const std::string &Path = Clang.getFrontendOpts().Plugins[i];
std::string Error;
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
}
// If there were any errors in processing arguments, exit now.
if (Clang.getDiagnostics().getNumErrors())
return 1;
// Create the target instance.
Clang.setTarget(TargetInfo::CreateTargetInfo(Clang.getDiagnostics(),
Clang.getTargetOpts()));
if (!Clang.hasTarget())
return 1;
// Inform the target of the language options
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
Clang.getTarget().setForcedLangOptions(Clang.getLangOpts());
// Validate/process some options
if (Clang.getHeaderSearchOpts().Verbose)
llvm::errs() << "clang -cc1 version " CLANG_VERSION_STRING
<< " based upon " << PACKAGE_STRING
<< " hosted on " << llvm::sys::getHostTriple() << "\n";
if (Clang.getFrontendOpts().ShowTimers)
Clang.createFrontendTimer();
for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
// If we aren't using an AST file, setup the file and source managers and
// the preprocessor.
bool IsAST =
Clang.getFrontendOpts().Inputs[i].first == FrontendOptions::IK_AST;
if (!IsAST) {
//.........这里部分代码省略.........