本文整理汇总了C++中DiagnosticsEngine类的典型用法代码示例。如果您正苦于以下问题:C++ DiagnosticsEngine类的具体用法?C++ DiagnosticsEngine怎么用?C++ DiagnosticsEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DiagnosticsEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: allCheckers
std::unique_ptr<CheckerManager> ento::createCheckerManager(
ASTContext &context,
AnalyzerOptions &opts,
ArrayRef<std::string> plugins,
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,
DiagnosticsEngine &diags) {
auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts);
ClangCheckerRegistry allCheckers(plugins, &diags);
for (const auto &Fn : checkerRegistrationFns)
Fn(allCheckers);
allCheckers.initializeManager(*checkerMgr, checkerOpts);
allCheckers.validateCheckerOptions(opts, diags);
checkerMgr->finishedCheckerRegistration();
for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
if (checkerOpts[i].isUnclaimed()) {
diags.Report(diag::err_unknown_analyzer_checker)
<< checkerOpts[i].getName();
diags.Report(diag::note_suggest_disabling_all_checkers);
}
}
return checkerMgr;
}
示例2:
bool
Bytecode::Finalize(DiagnosticsEngine& diags)
{
for (std::vector<Fixup>::iterator i=m_fixed_fixups.begin(),
end=m_fixed_fixups.end(); i != end; ++i)
{
if (!i->Finalize(diags, i->isJumpTarget() ? diag::err_too_complex_jump :
diag::err_too_complex_expression))
return false;
if (i->isJumpTarget() && i->isComplexRelative())
{
diags.Report(i->getSource().getBegin(),
diag::err_invalid_jump_target);
return false;
}
// Do curpos subtraction for IP-relative flagged values.
if (i->isIPRelative())
{
Location sub_loc = {this, i->getOffset()};
if (!i->SubRelative(m_container->getSection()->getObject(),
sub_loc))
diags.Report(i->getSource().getBegin(),
diag::err_too_complex_expression);
}
}
if (m_contents.get() != 0)
return m_contents->Finalize(*this, diags);
return true;
}
示例3: runThinLTOBackend
void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
const CodeGenOptions &CGOpts,
const clang::TargetOptions &TOpts,
const LangOptions &LOpts, const llvm::DataLayout &TDesc,
Module *M, BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS) {
if (!CGOpts.ThinLTOIndexFile.empty()) {
runThinLTOBackend(CGOpts, M, std::move(OS));
return;
}
EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M);
AsmHelper.EmitAssembly(Action, std::move(OS));
// Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's
// DataLayout.
if (AsmHelper.TM) {
std::string DLDesc = M->getDataLayout().getStringRepresentation();
if (DLDesc != TDesc.getStringRepresentation()) {
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error, "backend data layout '%0' does not match "
"expected target description '%1'");
Diags.Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
}
}
}
示例4: CheckerManager
std::unique_ptr<CheckerManager>
ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts,
ArrayRef<std::string> plugins,
DiagnosticsEngine &diags) {
std::unique_ptr<CheckerManager> checkerMgr(
new CheckerManager(langOpts, &opts));
SmallVector<CheckerOptInfo, 8> checkerOpts;
for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) {
const std::pair<std::string, bool> &opt = opts.CheckersControlList[i];
checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second));
}
ClangCheckerRegistry allCheckers(plugins, &diags);
allCheckers.initializeManager(*checkerMgr, checkerOpts);
checkerMgr->finishedCheckerRegistration();
for (unsigned i = 0, e = checkerOpts.size(); i != e; ++i) {
if (checkerOpts[i].isUnclaimed()) {
diags.Report(diag::err_unknown_analyzer_checker)
<< checkerOpts[i].getName();
diags.Report(diag::note_suggest_disabling_all_checkers);
}
}
return checkerMgr;
}
示例5: assert
bool C2Builder::checkMainFunction(DiagnosticsEngine& Diags) {
assert(mainComponent);
Decl* mainDecl = 0;
const ModuleList& mods = mainComponent->getModules();
for (unsigned m=0; m<mods.size(); m++) {
const Module* M = mods[m];
Decl* decl = M->findSymbol("main");
if (decl) {
if (mainDecl) {
// TODO multiple main functions
} else {
mainDecl = decl;
}
}
}
if (recipe.type == Component::EXECUTABLE) {
// bin: must have main
if (options.testMode) return true;
if (!mainDecl) {
Diags.Report(diag::err_main_missing);
return false;
}
} else {
// lib: cannot have main
if (mainDecl) {
Diags.Report(mainDecl->getLocation(), diag::err_lib_has_main);
return false;
}
}
return true;
}
示例6: SetUpDiagnosticLog
static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
const CodeGenOptions *CodeGenOpts,
DiagnosticsEngine &Diags) {
std::string ErrorInfo;
bool OwnsStream = false;
raw_ostream *OS = &llvm::errs();
if (DiagOpts->DiagnosticLogFile != "-") {
// Create the output stream.
llvm::raw_fd_ostream *FileOS(
new llvm::raw_fd_ostream(DiagOpts->DiagnosticLogFile.c_str(),
ErrorInfo, llvm::raw_fd_ostream::F_Append));
if (!ErrorInfo.empty()) {
Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
<< DiagOpts->DumpBuildInformation << ErrorInfo;
} else {
FileOS->SetUnbuffered();
FileOS->SetUseAtomicWrites(true);
OS = FileOS;
OwnsStream = true;
}
}
// Chain in the diagnostic client which will log the diagnostics.
LogDiagnosticPrinter *Logger = new LogDiagnosticPrinter(*OS, DiagOpts,
OwnsStream);
if (CodeGenOpts)
Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags);
Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), Logger));
}
示例7: report
bool FileRemapper::report(const Twine &err, DiagnosticsEngine &Diag) {
SmallString<128> buf;
unsigned ID = Diag.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Error,
err.toStringRef(buf));
Diag.Report(ID);
return true;
}
示例8: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(StringRef InputFile,
SrcMgr::CharacteristicKind Kind,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例9: InitializeFileRemapping
// Initialize the remapping of files to alternative contents, e.g.,
// those specified through other files.
static void InitializeFileRemapping(DiagnosticsEngine &Diags,
SourceManager &SourceMgr,
FileManager &FileMgr,
const PreprocessorOptions &InitOpts) {
// Remap files in the source manager (with buffers).
for (PreprocessorOptions::const_remapped_file_buffer_iterator
Remap = InitOpts.remapped_file_buffer_begin(),
RemapEnd = InitOpts.remapped_file_buffer_end();
Remap != RemapEnd;
++Remap) {
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
Remap->second->getBufferSize(),
0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
if (!InitOpts.RetainRemappedFileBuffers)
delete Remap->second;
continue;
}
// Override the contents of the "from" file with the contents of
// the "to" file.
SourceMgr.overrideFileContents(FromFile, Remap->second,
InitOpts.RetainRemappedFileBuffers);
}
// Remap files in the source manager (with other files).
for (PreprocessorOptions::const_remapped_file_iterator
Remap = InitOpts.remapped_file_begin(),
RemapEnd = InitOpts.remapped_file_end();
Remap != RemapEnd;
++Remap) {
// Find the file that we're mapping to.
const FileEntry *ToFile = FileMgr.getFile(Remap->second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file)
<< Remap->first << Remap->second;
continue;
}
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
ToFile->getSize(), 0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file)
<< Remap->first;
continue;
}
// Override the contents of the "from" file with the contents of
// the "to" file.
SourceMgr.overrideFileContents(FromFile, ToFile);
}
SourceMgr.setOverridenFilesKeepOriginalName(
InitOpts.RemappedFilesKeepOriginalName);
}
示例10: InitializeSourceManager
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
const FrontendOptions &Opts) {
SrcMgr::CharacteristicKind
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
if (Input.isBuffer()) {
SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind);
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
StringRef InputFile = Input.getFile();
// Figure out where to get and map in the main file.
if (InputFile != "-") {
const FileEntry *File = FileMgr.getFile(InputFile);
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
}
// The natural SourceManager infrastructure can't currently handle named
// pipes, but we would at least like to accept them for the main
// file. Detect them here, read them with the more generic MemoryBuffer
// function, and simply override their contents as we do for STDIN.
if (File->isNamedPipe()) {
OwningPtr<llvm::MemoryBuffer> MB;
if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
return false;
}
// Create a new virtual file that will have the correct size.
File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
SourceMgr.overrideFileContents(File, MB.take());
}
SourceMgr.createMainFileID(File, Kind);
} else {
OwningPtr<llvm::MemoryBuffer> SB;
if (llvm::MemoryBuffer::getSTDIN(SB)) {
// FIXME: Give ec.message() in this diag.
Diags.Report(diag::err_fe_error_reading_stdin);
return false;
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
SourceMgr.createMainFileID(File, Kind);
SourceMgr.overrideFileContents(File, SB.take());
}
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
}
示例11: Diags
VerifyDiagnosticConsumer::VerifyDiagnosticConsumer(DiagnosticsEngine &Diags)
: Diags(Diags),
PrimaryClient(Diags.getClient()), OwnsPrimaryClient(Diags.ownsClient()),
Buffer(new TextDiagnosticBuffer()),
SrcManager(0), Status(HasNoDirectives)
{
Diags.takeClient();
assert(Diags.hasSourceManager());
setSourceManager(Diags.getSourceManager());
}
示例12: Diags
FixItRewriter::FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
const LangOptions &LangOpts,
FixItOptions *FixItOpts)
: Diags(Diags),
Rewrite(SourceMgr, LangOpts),
FixItOpts(FixItOpts),
NumFailures(0),
PrevDiagSilenced(false) {
OwnsClient = Diags.ownsClient();
Client = Diags.takeClient();
Diags.setClient(this);
}
示例13: logAllUnhandledErrors
void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
const HeaderSearchOptions &HeaderOpts,
const CodeGenOptions &CGOpts,
const clang::TargetOptions &TOpts,
const LangOptions &LOpts,
const llvm::DataLayout &TDesc, Module *M,
BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS) {
if (!CGOpts.ThinLTOIndexFile.empty()) {
// If we are performing a ThinLTO importing compile, load the function index
// into memory and pass it into runThinLTOBackend, which will run the
// function importer and invoke LTO passes.
Expected<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr =
llvm::getModuleSummaryIndexForFile(CGOpts.ThinLTOIndexFile,
/*IgnoreEmptyThinLTOIndexFile*/true);
if (!IndexOrErr) {
logAllUnhandledErrors(IndexOrErr.takeError(), errs(),
"Error loading index file '" +
CGOpts.ThinLTOIndexFile + "': ");
return;
}
std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr);
// A null CombinedIndex means we should skip ThinLTO compilation
// (LLVM will optionally ignore empty index files, returning null instead
// of an error).
bool DoThinLTOBackend = CombinedIndex != nullptr;
if (DoThinLTOBackend) {
runThinLTOBackend(CombinedIndex.get(), M, HeaderOpts, CGOpts, TOpts,
LOpts, std::move(OS), CGOpts.SampleProfileFile, Action);
return;
}
}
EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
if (CGOpts.ExperimentalNewPassManager)
AsmHelper.EmitAssemblyWithNewPassManager(Action, std::move(OS));
else
AsmHelper.EmitAssembly(Action, std::move(OS));
// Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's
// DataLayout.
if (AsmHelper.TM) {
std::string DLDesc = M->getDataLayout().getStringRepresentation();
if (DLDesc != TDesc.getStringRepresentation()) {
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error, "backend data layout '%0' does not match "
"expected target description '%1'");
Diags.Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
}
}
}
示例14: EmitUnknownDiagWarning
// EmitUnknownDiagWarning - Emit a warning and typo hint for unknown warning opts
static void EmitUnknownDiagWarning(DiagnosticsEngine &Diags,
StringRef Prefix, StringRef Opt,
bool isPositive) {
StringRef Suggestion = DiagnosticIDs::getNearestWarningOption(Opt);
if (!Suggestion.empty())
Diags.Report(isPositive? diag::warn_unknown_warning_option_suggest :
diag::warn_unknown_negative_warning_option_suggest)
<< (Prefix.str() += Opt) << (Prefix.str() += Suggestion);
else
Diags.Report(isPositive? diag::warn_unknown_warning_option :
diag::warn_unknown_negative_warning_option)
<< (Prefix.str() += Opt);
}
示例15: if
bool
yasm::CalcFloat(APFloat* lhs,
Op::Op op,
const APFloat& rhs,
SourceLocation source,
DiagnosticsEngine& diags)
{
APFloat::opStatus status;
switch (op)
{
case Op::ADD:
status = lhs->add(rhs, APFloat::rmNearestTiesToEven);
break;
case Op::SUB:
status = lhs->subtract(rhs, APFloat::rmNearestTiesToEven);
break;
case Op::MUL:
status = lhs->multiply(rhs, APFloat::rmNearestTiesToEven);
break;
case Op::DIV:
case Op::SIGNDIV:
status = lhs->divide(rhs, APFloat::rmNearestTiesToEven);
break;
case Op::MOD:
case Op::SIGNMOD:
status = lhs->mod(rhs, APFloat::rmNearestTiesToEven);
break;
default:
status = APFloat::opInvalidOp;
break;
}
if (status & APFloat::opInvalidOp)
{
diags.Report(source, diag::err_float_invalid_op);
return false;
}
if (status & APFloat::opDivByZero)
{
diags.Report(source, diag::err_divide_by_zero);
return false;
}
if (status & APFloat::opOverflow)
diags.Report(source, diag::warn_float_overflow);
else if (status & APFloat::opUnderflow)
diags.Report(source, diag::warn_float_underflow);
else if (status & APFloat::opInexact)
diags.Report(source, diag::warn_float_inexact);
return true;
}