本文整理汇总了C++中DiagnosticEngine类的典型用法代码示例。如果您正苦于以下问题:C++ DiagnosticEngine类的具体用法?C++ DiagnosticEngine怎么用?C++ DiagnosticEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DiagnosticEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verifyInputs
bool FrontendInputs::verifyInputs(DiagnosticEngine &diags, bool treatAsSIL,
bool isREPLRequested,
bool isNoneRequested) const {
if (isREPLRequested) {
if (hasInputs()) {
diags.diagnose(SourceLoc(), diag::error_repl_requires_no_input_files);
return true;
}
} else if (treatAsSIL) {
if (isWholeModule()) {
if (inputCount() != 1) {
diags.diagnose(SourceLoc(), diag::error_mode_requires_one_input_file);
return true;
}
} else {
assertMustNotBeMoreThanOnePrimaryInput();
// If we have the SIL as our primary input, we can waive the one file
// requirement as long as all the other inputs are SIBs.
if (!areAllNonPrimariesSIB()) {
diags.diagnose(SourceLoc(),
diag::error_mode_requires_one_sil_multi_sib);
return true;
}
}
} else if (!isNoneRequested && !hasInputs()) {
diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file);
return true;
}
return false;
}
示例2: if
OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
const llvm::opt::ArgList &Args,
const llvm::opt::Arg *A,
const llvm::Triple &Triple,
DiagnosticEngine &Diags,
llvm::function_ref<bool(llvm::StringRef)> sanitizerRuntimeLibExists) {
OptionSet<SanitizerKind> sanitizerSet;
// Find the sanitizer kind.
for (int i = 0, n = A->getNumValues(); i != n; ++i) {
StringRef opt = A->getValue(i);
if (opt == "address") {
sanitizerSet |= SanitizerKind::Address;
} else if (opt == "thread") {
sanitizerSet |= SanitizerKind::Thread;
} else if (opt == "fuzzer") {
sanitizerSet |= SanitizerKind::Fuzzer;
} else {
Diags.diagnose(SourceLoc(), diag::error_unsupported_option_argument,
A->getOption().getPrefixedName(), A->getValue(i));
}
}
// Sanitizers are only supported on Linux or Darwin.
if (!(Triple.isOSDarwin() || Triple.isOSLinux())) {
SmallString<128> b;
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
(A->getOption().getPrefixedName() +
StringRef(A->getAsString(Args))).toStringRef(b),
Triple.getTriple());
}
// Address and thread sanitizers can not be enabled concurrently.
if ((sanitizerSet & SanitizerKind::Thread)
&& (sanitizerSet & SanitizerKind::Address)) {
SmallString<128> b1;
SmallString<128> b2;
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
(A->getOption().getPrefixedName()
+ toStringRef(SanitizerKind::Address)).toStringRef(b1),
(A->getOption().getPrefixedName()
+ toStringRef(SanitizerKind::Thread)).toStringRef(b2));
}
// Thread Sanitizer only works on OS X and the simulators. It's only supported
// on 64 bit architectures.
if ((sanitizerSet & SanitizerKind::Thread) &&
!isTSanSupported(Triple, sanitizerRuntimeLibExists)) {
SmallString<128> b;
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
(A->getOption().getPrefixedName()
+ toStringRef(SanitizerKind::Thread)).toStringRef(b),
Triple.getTriple());
}
return sanitizerSet;
}
示例3: parseSanitizerArgValues
SanitizerKind swift::parseSanitizerArgValues(const llvm::opt::Arg *A,
const llvm::Triple &Triple,
DiagnosticEngine &Diags) {
SanitizerKind kind = SanitizerKind::None;
// Find the sanitizer kind.
SanitizerKind pKind = SanitizerKind::None;
for (int i = 0, n = A->getNumValues(); i != n; ++i) {
kind =
llvm::StringSwitch<SanitizerKind>(A->getValue(i))
.Case("address", SanitizerKind::Address)
.Case("thread", SanitizerKind::Thread)
.Default(SanitizerKind::None);
if (kind == SanitizerKind::None) {
Diags.diagnose(SourceLoc(), diag::error_unsupported_option_argument,
A->getOption().getPrefixedName(), A->getValue(i));
return kind;
}
// Currently, more than one sanitizer cannot be enabled at the same time.
if (pKind != SanitizerKind::None && pKind != kind) {
SmallString<128> pb;
SmallString<128> b;
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
(A->getOption().getPrefixedName() + toStringRef(pKind)).toStringRef(pb),
(A->getOption().getPrefixedName() + toStringRef(kind)).toStringRef(b));
}
pKind = kind;
}
if (kind == SanitizerKind::None)
return kind;
// Check if the target is supported for this sanitizer.
// None of the sanitizers work on Linux right now.
if (!Triple.isOSDarwin()) {
SmallString<128> b;
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
(A->getOption().getPrefixedName() + toStringRef(kind)).toStringRef(b),
Triple.getTriple());
}
// Thread Sanitizer only works on OS X and the simulators. It's only supported
// on 64 bit architectures.
if (kind == SanitizerKind::Thread &&
(!(Triple.isMacOSX() || tripleIsAnySimulator(Triple)) ||
!Triple.isArch64Bit())) {
SmallString<128> b;
Diags.diagnose(SourceLoc(), diag::error_unsupported_opt_for_target,
(A->getOption().getPrefixedName() + toStringRef(kind)).toStringRef(b),
Triple.getTriple());
}
return kind;
}
示例4: validateSymbolSet
static bool validateSymbolSet(DiagnosticEngine &diags,
llvm::StringSet<> symbols, llvm::Module &IRModule,
bool diagnoseExtraSymbolsInTBD) {
auto error = false;
// Diff the two sets of symbols, flagging anything outside their intersection.
// Delay the emission of errors for things in the IR but not TBD, so we can
// sort them to get a stable order.
std::vector<StringRef> irNotTBD;
for (auto &nameValue : IRModule.getValueSymbolTable()) {
auto name = nameValue.getKey();
auto value = nameValue.getValue();
if (auto GV = dyn_cast<llvm::GlobalValue>(value)) {
// Is this a symbol that should be listed?
auto externallyVisible =
GV->hasExternalLinkage() && !GV->hasHiddenVisibility();
if (!GV->isDeclaration() && externallyVisible) {
// Is it listed?
if (!symbols.erase(name))
irNotTBD.push_back(name);
}
} else {
assert(symbols.find(name) == symbols.end() &&
"non-global value in value symbol table");
}
}
std::sort(irNotTBD.begin(), irNotTBD.end());
for (auto &name : irNotTBD) {
diags.diagnose(SourceLoc(), diag::symbol_in_ir_not_in_tbd, name,
Demangle::demangleSymbolAsString(name));
error = true;
}
if (diagnoseExtraSymbolsInTBD) {
// Look for any extra symbols.
for (auto &name : sortSymbols(symbols)) {
diags.diagnose(SourceLoc(), diag::symbol_in_tbd_not_in_ir, name,
Demangle::demangleSymbolAsString(name));
error = true;
}
}
if (error) {
diags.diagnose(SourceLoc(), diag::tbd_validation_failure);
}
return error;
}
示例5: parseArgs
int parseArgs(llvm::ArrayRef<const char *> Args, DiagnosticEngine &Diags) {
using namespace options;
// Parse frontend command line options using Swift's option table.
std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable();
unsigned MissingIndex;
unsigned MissingCount;
llvm::opt::InputArgList ParsedArgs =
Table->ParseArgs(Args, MissingIndex, MissingCount,
ModuleWrapOption);
if (MissingCount) {
Diags.diagnose(SourceLoc(), diag::error_missing_arg_value,
ParsedArgs.getArgString(MissingIndex), MissingCount);
return 1;
}
if (const Arg *A = ParsedArgs.getLastArg(options::OPT_target))
TargetTriple = llvm::Triple(llvm::Triple::normalize(A->getValue()));
else
TargetTriple = llvm::Triple(llvm::sys::getDefaultTargetTriple());
if (ParsedArgs.hasArg(OPT_UNKNOWN)) {
for (const Arg *A : ParsedArgs.filtered(OPT_UNKNOWN)) {
Diags.diagnose(SourceLoc(), diag::error_unknown_arg,
A->getAsString(ParsedArgs));
}
return true;
}
if (ParsedArgs.getLastArg(OPT_help)) {
std::string ExecutableName = llvm::sys::path::stem(MainExecutablePath);
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
"Swift Module Wrapper", options::ModuleWrapOption, 0);
return 1;
}
for (const Arg *A : ParsedArgs.filtered(OPT_INPUT)) {
InputFilenames.push_back(A->getValue());
}
if (InputFilenames.empty()) {
Diags.diagnose(SourceLoc(), diag::error_mode_requires_an_input_file);
return 1;
}
if (const Arg *A = ParsedArgs.getLastArg(OPT_o)) {
OutputFilename = A->getValue();
}
return 0;
}
示例6: TheDriver
std::unique_ptr<CompilerInvocation>
swift::driver::createCompilerInvocation(ArrayRef<const char *> ArgList,
DiagnosticEngine &Diags) {
SmallVector<const char *, 16> Args;
Args.push_back("<swiftc>"); // FIXME: Remove dummy argument.
Args.insert(Args.end(), ArgList.begin(), ArgList.end());
// When creating a CompilerInvocation, ensure that the driver creates a single
// frontend command.
Args.push_back("-force-single-frontend-invocation");
// Force the driver into batch mode by specifying "swiftc" as the name.
Driver TheDriver("swiftc", "swiftc", Args, Diags);
// Don't check for the existence of input files, since the user of the
// CompilerInvocation may wish to remap inputs to source buffers.
TheDriver.setCheckInputFilesExist(false);
std::unique_ptr<Compilation> C = TheDriver.buildCompilation(Args);
if (!C || C->getJobs().empty())
return nullptr; // Don't emit an error; one should already have been emitted
SmallPtrSet<const Job *, 4> CompileCommands;
for (const Job *Cmd : C->getJobs())
if (isa<CompileJobAction>(Cmd->getSource()))
CompileCommands.insert(Cmd);
if (CompileCommands.size() != 1) {
// TODO: include Jobs in the diagnostic.
Diags.diagnose(SourceLoc(), diag::error_expected_one_frontend_job);
return nullptr;
}
const Job *Cmd = *CompileCommands.begin();
if (StringRef("-frontend") != Cmd->getArguments().front()) {
Diags.diagnose(SourceLoc(), diag::error_expected_frontend_command);
return nullptr;
}
std::unique_ptr<CompilerInvocation> Invocation(new CompilerInvocation());
const llvm::opt::ArgStringList &BaseFrontendArgs = Cmd->getArguments();
ArrayRef<const char *> FrontendArgs =
llvm::makeArrayRef(BaseFrontendArgs.data() + 1,
BaseFrontendArgs.data() + BaseFrontendArgs.size());
if (Invocation->parseArgs(FrontendArgs, Diags))
return nullptr; // Don't emit an error; one should already have been emitted
return Invocation;
}
示例7: parseExclusivityEnforcementOptions
/// Parse -enforce-exclusivity=... options
void parseExclusivityEnforcementOptions(const llvm::opt::Arg *A,
SILOptions &Opts,
DiagnosticEngine &Diags) {
StringRef Argument = A->getValue();
if (Argument == "unchecked") {
// This option is analogous to the -Ounchecked optimization setting.
// It will disable dynamic checking but still diagnose statically.
Opts.EnforceExclusivityStatic = true;
Opts.EnforceExclusivityDynamic = false;
} else if (Argument == "checked") {
Opts.EnforceExclusivityStatic = true;
Opts.EnforceExclusivityDynamic = true;
} else if (Argument == "dynamic-only") {
// This option is intended for staging purposes. The intent is that
// it will eventually be removed.
Opts.EnforceExclusivityStatic = false;
Opts.EnforceExclusivityDynamic = true;
} else if (Argument == "none") {
// This option is for staging purposes.
Opts.EnforceExclusivityStatic = false;
Opts.EnforceExclusivityDynamic = false;
} else {
Diags.diagnose(SourceLoc(), diag::error_unsupported_option_argument,
A->getOption().getPrefixedName(), A->getValue());
}
}
示例8: getTokensFromFile
int getTokensFromFile(unsigned BufferID,
LangOptions &LangOpts,
SourceManager &SourceMgr,
DiagnosticEngine &Diags,
std::vector<std::pair<RC<syntax::TokenSyntax>,
syntax::AbsolutePosition>> &Tokens) {
Tokens = tokenizeWithTrivia(LangOpts, SourceMgr, BufferID);
return Diags.hadAnyError() ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例9: diagnoseSwiftVersion
static void diagnoseSwiftVersion(Optional<version::Version> &vers, Arg *verArg,
ArgList &Args, DiagnosticEngine &diags) {
// General invalid version error
diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
verArg->getAsString(Args), verArg->getValue());
// Check for an unneeded minor version, otherwise just list valid versions
if (vers.hasValue() && !vers.getValue().empty() &&
vers.getValue().asMajorVersion().getEffectiveLanguageVersion()) {
diags.diagnose(SourceLoc(), diag::note_swift_version_major,
vers.getValue()[0]);
} else {
// Note valid versions instead
auto validVers = version::Version::getValidEffectiveVersions();
auto versStr =
"'" + llvm::join(validVers.begin(), validVers.end(), "', '") + "'";
diags.diagnose(SourceLoc(), diag::note_valid_swift_versions, versStr);
}
}
示例10: generateOptimizationRemarkRegex
/// \brief Create a new Regex instance out of the string value in \p RpassArg.
/// It returns a pointer to the newly generated Regex instance.
static std::shared_ptr<llvm::Regex>
generateOptimizationRemarkRegex(DiagnosticEngine &Diags, ArgList &Args,
Arg *RpassArg) {
StringRef Val = RpassArg->getValue();
std::string RegexError;
std::shared_ptr<llvm::Regex> Pattern = std::make_shared<llvm::Regex>(Val);
if (!Pattern->isValid(RegexError)) {
Diags.diagnose(SourceLoc(), diag::error_optimization_remark_pattern,
RegexError, RpassArg->getAsString(Args));
Pattern.reset();
}
return Pattern;
}
示例11: checkForOutOfDateInputs
static void checkForOutOfDateInputs(DiagnosticEngine &diags,
const InputInfoMap &inputs) {
for (const auto &inputPair : inputs) {
auto recordedModTime = inputPair.second.previousModTime;
if (recordedModTime == llvm::sys::TimeValue::MaxTime())
continue;
const char *input = inputPair.first->getValue();
llvm::sys::fs::file_status inputStatus;
if (auto statError = llvm::sys::fs::status(input, inputStatus)) {
diags.diagnose(SourceLoc(), diag::warn_cannot_stat_input,
llvm::sys::path::filename(input), statError.message());
continue;
}
if (recordedModTime != inputStatus.getLastModificationTime()) {
diags.diagnose(SourceLoc(), diag::error_input_changed_during_build,
llvm::sys::path::filename(input));
}
}
}
示例12: readFileList
/// Try to read a file list file.
///
/// Returns false on error.
static bool readFileList(DiagnosticEngine &diags,
std::vector<std::string> &inputFiles,
const llvm::opt::Arg *filelistPath,
const llvm::opt::Arg *primaryFileArg = nullptr,
unsigned *primaryFileIndex = nullptr) {
assert((primaryFileArg == nullptr) || (primaryFileIndex != nullptr) &&
"did not provide argument for primary file index");
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
llvm::MemoryBuffer::getFile(filelistPath->getValue());
if (!buffer) {
diags.diagnose(SourceLoc(), diag::cannot_open_file,
filelistPath->getValue(), buffer.getError().message());
return false;
}
bool foundPrimaryFile = false;
if (primaryFileIndex) *primaryFileIndex = 0;
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
inputFiles.push_back(line);
if (foundPrimaryFile || primaryFileArg == nullptr)
continue;
if (line == primaryFileArg->getValue())
foundPrimaryFile = true;
else
++*primaryFileIndex;
}
if (primaryFileArg && !foundPrimaryFile) {
diags.diagnose(SourceLoc(), diag::error_primary_file_not_found,
primaryFileArg->getValue(), filelistPath->getValue());
return false;
}
return true;
}
示例13: emitMakeDependencies
/// Emits a Make-style dependencies file.
static bool emitMakeDependencies(DiagnosticEngine &diags,
DependencyTracker &depTracker,
const FrontendOptions &opts) {
std::error_code EC;
llvm::raw_fd_ostream out(opts.DependenciesFilePath, EC,
llvm::sys::fs::F_None);
if (out.has_error() || EC) {
diags.diagnose(SourceLoc(), diag::error_opening_output,
opts.DependenciesFilePath, EC.message());
out.clear_error();
return true;
}
// Declare a helper for escaping file names for use in Makefiles.
llvm::SmallString<256> pathBuf;
auto escape = [&](StringRef raw) -> StringRef {
pathBuf.clear();
static const char badChars[] = " $#:\n";
size_t prev = 0;
for (auto index = raw.find_first_of(badChars); index != StringRef::npos;
index = raw.find_first_of(badChars, index+1)) {
pathBuf.append(raw.slice(prev, index));
if (raw[index] == '$')
pathBuf.push_back('$');
else
pathBuf.push_back('\\');
prev = index;
}
pathBuf.append(raw.substr(prev));
return pathBuf;
};
// FIXME: Xcode can't currently handle multiple targets in a single
// dependency line.
opts.forAllOutputPaths([&](StringRef targetName) {
out << escape(targetName) << " :";
// First include all other files in the module. Make-style dependencies
// need to be conservative!
for (StringRef path : opts.InputFilenames)
out << ' ' << escape(path);
// Then print dependencies we've picked up during compilation.
for (StringRef path : depTracker.getDependencies())
out << ' ' << escape(path);
out << '\n';
});
return false;
}
示例14: recordSourceFileUnit
static bool
recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
StringRef indexStorePath, bool indexSystemModules,
bool isDebugCompilation, StringRef targetTriple,
ArrayRef<const clang::FileEntry *> fileDependencies,
const clang::CompilerInstance &clangCI,
DiagnosticEngine &diags) {
auto &fileMgr = clangCI.getFileManager();
auto *module = primarySourceFile->getParentModule();
bool isSystem = module->isSystemModule();
auto *mainFile = fileMgr.getFile(primarySourceFile->getFilename());
// FIXME: Get real values for the following.
StringRef swiftVersion;
StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;
IndexUnitWriter unitWriter(fileMgr, indexStorePath,
"swift", swiftVersion, indexUnitToken, module->getNameStr(),
mainFile, isSystem, /*isModuleUnit=*/false, isDebugCompilation,
targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);
// Module dependencies.
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Public;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
SmallVector<ModuleDecl::ImportedModule, 8> imports;
primarySourceFile->getImportedModules(imports, importFilter);
StringScratchSpace moduleNameScratch;
addModuleDependencies(imports, indexStorePath, indexSystemModules,
targetTriple, clangCI, diags, unitWriter, moduleNameScratch);
// File dependencies.
for (auto *F : fileDependencies)
unitWriter.addFileDependency(F, /*FIXME:isSystem=*/false, /*Module=*/nullptr);
recordSourceFile(primarySourceFile, indexStorePath, diags,
[&](StringRef recordFile, StringRef filename) {
unitWriter.addRecordFile(recordFile, fileMgr.getFile(filename),
module->isSystemModule(), /*Module=*/nullptr);
});
std::string error;
if (unitWriter.write(error)) {
diags.diagnose(SourceLoc(), diag::error_write_index_unit, error);
return true;
}
return false;
}
示例15:
Optional<std::vector<std::string>>
ArgsToFrontendOutputsConverter::readOutputFileList(const StringRef filelistPath,
DiagnosticEngine &diags) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
llvm::MemoryBuffer::getFile(filelistPath);
if (!buffer) {
diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath,
buffer.getError().message());
return None;
}
std::vector<std::string> outputFiles;
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
outputFiles.push_back(line.str());
}
return outputFiles;
}