本文整理汇总了C++中DiagnosticEngine::diagnose方法的典型用法代码示例。如果您正苦于以下问题:C++ DiagnosticEngine::diagnose方法的具体用法?C++ DiagnosticEngine::diagnose怎么用?C++ DiagnosticEngine::diagnose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiagnosticEngine
的用法示例。
在下文中一共展示了DiagnosticEngine::diagnose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/// \returns true if an error occurred.
static bool
emitDataForSwiftSerializedModule(ModuleDecl *module,
StringRef indexStorePath,
bool indexSystemModules,
StringRef targetTriple,
const clang::CompilerInstance &clangCI,
DiagnosticEngine &diags,
IndexUnitWriter &parentUnitWriter) {
StringRef filename = module->getModuleFilename();
std::string moduleName = module->getNameStr();
std::string error;
auto isUptodateOpt = parentUnitWriter.isUnitUpToDateForOutputFile(/*FilePath=*/filename,
/*TimeCompareFilePath=*/filename, error);
if (!isUptodateOpt.hasValue()) {
diags.diagnose(SourceLoc(), diag::error_index_failed_status_check, error);
return true;
}
if (*isUptodateOpt)
return false;
// FIXME: Would be useful for testing if swift had clang's -Rremark system so
// we could output a remark here that we are going to create index data for
// a module file.
// Pairs of (recordFile, groupName).
std::vector<std::pair<std::string, std::string>> records;
if (!module->isStdlibModule()) {
std::string recordFile;
bool failed = false;
auto consumer = makeRecordingConsumer(filename, indexStorePath,
&diags, &recordFile, &failed);
indexModule(module, /*Hash=*/"", *consumer);
if (failed)
return true;
records.emplace_back(recordFile, moduleName);
} else {
// Record stdlib groups as if they were submodules.
auto makeSubmoduleNameFromGroupName = [](StringRef groupName, SmallString<128> &buf) {
buf += "Swift";
if (groupName.empty())
return;
buf += '.';
for (char ch : groupName) {
if (ch == '/')
buf += '.';
else if (ch == ' ' || ch == '-')
buf += '_';
else
buf += ch;
}
};
auto appendGroupNameForFilename = [](StringRef groupName, SmallString<256> &buf) {
if (groupName.empty())
return;
buf += '_';
for (char ch : groupName) {
if (ch == '/' || ch ==' ')
buf += '_';
else
buf += ch;
}
};
bool failed = false;
StdlibGroupsIndexRecordingConsumer groupIndexConsumer([&](StringRef groupName, SymbolTracker &tracker) -> bool {
SmallString<128> moduleName;
makeSubmoduleNameFromGroupName(groupName, moduleName);
SmallString<256> fileNameWithGroup = filename;
appendGroupNameForFilename(groupName, fileNameWithGroup);
std::string outRecordFile;
failed = failed || writeRecord(tracker, fileNameWithGroup.str(), indexStorePath, &diags, outRecordFile);
if (failed)
return false;
records.emplace_back(outRecordFile, moduleName.str());
return true;
});
indexModule(module, /*Hash=*/"", groupIndexConsumer);
if (failed)
return true;
}
auto &fileMgr = clangCI.getFileManager();
bool isSystem = module->isSystemModule();
// FIXME: Get real values for the following.
StringRef swiftVersion;
StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;
std::string indexUnitToken = module->getModuleFilename();
// For indexing serialized modules 'debug compilation' is irrelevant, so
// set it to true by default.
bool isDebugCompilation = true;
IndexUnitWriter unitWriter(fileMgr, indexStorePath,
"swift", swiftVersion, indexUnitToken, moduleName,
//.........这里部分代码省略.........
示例2: performLLVM
/// Run the LLVM passes. In multi-threaded compilation this will be done for
/// multiple LLVM modules in parallel.
static bool performLLVM(IRGenOptions &Opts, DiagnosticEngine &Diags,
llvm::sys::Mutex *DiagMutex,
llvm::Module *Module,
llvm::TargetMachine *TargetMachine,
StringRef OutputFilename) {
llvm::SmallString<0> Buffer;
std::unique_ptr<raw_pwrite_stream> RawOS;
if (!OutputFilename.empty()) {
// Try to open the output file. Clobbering an existing file is fine.
// Open in binary mode if we're doing binary output.
llvm::sys::fs::OpenFlags OSFlags = llvm::sys::fs::F_None;
std::error_code EC;
auto *FDOS = new raw_fd_ostream(OutputFilename, EC, OSFlags);
RawOS.reset(FDOS);
if (FDOS->has_error() || EC) {
if (DiagMutex)
DiagMutex->lock();
Diags.diagnose(SourceLoc(), diag::error_opening_output,
OutputFilename, EC.message());
if (DiagMutex)
DiagMutex->unlock();
FDOS->clear_error();
return true;
}
// Most output kinds want a formatted output stream. It's not clear
// why writing an object file does.
//if (Opts.OutputKind != IRGenOutputKind::LLVMBitcode)
// FormattedOS.setStream(*RawOS, formatted_raw_ostream::PRESERVE_STREAM);
} else {
RawOS.reset(new raw_svector_ostream(Buffer));
}
performLLVMOptimizations(Opts, Module, TargetMachine);
legacy::PassManager EmitPasses;
// Set up the final emission passes.
switch (Opts.OutputKind) {
case IRGenOutputKind::Module:
break;
case IRGenOutputKind::LLVMAssembly:
EmitPasses.add(createPrintModulePass(*RawOS));
break;
case IRGenOutputKind::LLVMBitcode:
EmitPasses.add(createBitcodeWriterPass(*RawOS));
break;
case IRGenOutputKind::NativeAssembly:
case IRGenOutputKind::ObjectFile: {
llvm::TargetMachine::CodeGenFileType FileType;
FileType = (Opts.OutputKind == IRGenOutputKind::NativeAssembly
? llvm::TargetMachine::CGFT_AssemblyFile
: llvm::TargetMachine::CGFT_ObjectFile);
EmitPasses.add(createTargetTransformInfoWrapperPass(
TargetMachine->getTargetIRAnalysis()));
// Make sure we do ARC contraction under optimization. We don't
// rely on any other LLVM ARC transformations, but we do need ARC
// contraction to add the objc_retainAutoreleasedReturnValue
// assembly markers.
if (Opts.Optimize)
EmitPasses.add(createObjCARCContractPass());
bool fail = TargetMachine->addPassesToEmitFile(EmitPasses, *RawOS,
FileType, !Opts.Verify);
if (fail) {
if (DiagMutex)
DiagMutex->lock();
Diags.diagnose(SourceLoc(), diag::error_codegen_init_fail);
if (DiagMutex)
DiagMutex->unlock();
return true;
}
break;
}
}
EmitPasses.run(*Module);
return false;
}