本文整理汇总了C++中DiagnosticsEngine::getSourceManager方法的典型用法代码示例。如果您正苦于以下问题:C++ DiagnosticsEngine::getSourceManager方法的具体用法?C++ DiagnosticsEngine::getSourceManager怎么用?C++ DiagnosticsEngine::getSourceManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiagnosticsEngine
的用法示例。
在下文中一共展示了DiagnosticsEngine::getSourceManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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());
}
示例2: assert
/// \brief Based on the way the client configured the Diagnostic
/// object, classify the specified diagnostic ID into a Level, consumable by
/// the DiagnosticClient.
///
/// \param Loc The source location we are interested in finding out the
/// diagnostic state. Can be null in order to query the latest state.
diag::Severity
DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, unsigned DiagClass,
SourceLocation Loc,
const DiagnosticsEngine &Diag) const {
assert(DiagClass != CLASS_NOTE);
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error. Errors can only be mapped to fatal.
diag::Severity Result = diag::Severity::Fatal;
DiagnosticsEngine::DiagStatePointsTy::iterator
Pos = Diag.GetDiagStatePointForLoc(Loc);
DiagnosticsEngine::DiagState *State = Pos->State;
// Get the mapping information, or compute it lazily.
DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID);
// TODO: Can a null severity really get here?
if (Mapping.getSeverity() != diag::Severity())
Result = Mapping.getSeverity();
// Upgrade ignored diagnostics if -Weverything is enabled.
if (Diag.EnableAllWarnings && Result == diag::Severity::Ignored &&
!Mapping.isUser())
Result = diag::Severity::Warning;
// Diagnostics of class REMARK are either printed as remarks or in case they
// have been added to -Werror they are printed as errors.
if (DiagClass == CLASS_REMARK && Result == diag::Severity::Warning)
Result = diag::Severity::Remark;
// Ignore -pedantic diagnostics inside __extension__ blocks.
// (The diagnostics controlled by -pedantic are the extension diagnostics
// that are not enabled by default.)
bool EnabledByDefault = false;
bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault);
if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault)
return diag::Severity::Ignored;
// For extension diagnostics that haven't been explicitly mapped, check if we
// should upgrade the diagnostic.
if (IsExtensionDiag && !Mapping.isUser()) {
switch (Diag.ExtBehavior) {
case DiagnosticsEngine::Ext_Ignore:
break;
case DiagnosticsEngine::Ext_Warn:
// Upgrade ignored diagnostics to warnings.
if (Result == diag::Severity::Ignored)
Result = diag::Severity::Warning;
break;
case DiagnosticsEngine::Ext_Error:
// Upgrade ignored or warning diagnostics to errors.
if (Result == diag::Severity::Ignored ||
Result == diag::Severity::Warning)
Result = diag::Severity::Error;
break;
}
}
// At this point, ignored errors can no longer be upgraded.
if (Result == diag::Severity::Ignored)
return Result;
// Honor -w, which is lower in priority than pedantic-errors, but higher than
// -Werror.
if (Result == diag::Severity::Warning && Diag.IgnoreAllWarnings)
return diag::Severity::Ignored;
// If -Werror is enabled, map warnings to errors unless explicitly disabled.
if (Result == diag::Severity::Warning) {
if (Diag.WarningsAsErrors && !Mapping.hasNoWarningAsError())
Result = diag::Severity::Error;
}
// If -Wfatal-errors is enabled, map errors to fatal unless explicity
// disabled.
if (Result == diag::Severity::Error) {
if (Diag.ErrorsAsFatal && !Mapping.hasNoErrorAsFatal())
Result = diag::Severity::Fatal;
}
// Custom diagnostics always are emitted in system headers.
bool ShowInSystemHeader =
!GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
// If we are in a system header, we ignore it. We look at the diagnostic class
// because we also want to ignore extensions and warnings in -Werror and
// -pedantic-errors modes, which *map* warnings/extensions to errors.
if (Result >= diag::Severity::Warning && DiagClass != CLASS_ERROR &&
!ShowInSystemHeader && Diag.SuppressSystemWarnings && Loc.isValid() &&
Diag.getSourceManager().isInSystemHeader(
Diag.getSourceManager().getExpansionLoc(Loc)))
return diag::Severity::Ignored;
//.........这里部分代码省略.........
示例3: switch
//.........这里部分代码省略.........
SourceLocation Loc,
const DiagnosticsEngine &Diag) const {
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error. Errors can only be mapped to fatal.
DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
DiagnosticsEngine::DiagStatePointsTy::iterator
Pos = Diag.GetDiagStatePointForLoc(Loc);
DiagnosticsEngine::DiagState *State = Pos->State;
// Get the mapping information, or compute it lazily.
DiagnosticMappingInfo &MappingInfo = State->getOrAddMappingInfo(
(diag::kind)DiagID);
switch (MappingInfo.getMapping()) {
default: llvm_unreachable("Unknown mapping!");
case diag::MAP_IGNORE:
Result = DiagnosticIDs::Ignored;
break;
case diag::MAP_WARNING:
Result = DiagnosticIDs::Warning;
break;
case diag::MAP_ERROR:
Result = DiagnosticIDs::Error;
break;
case diag::MAP_FATAL:
Result = DiagnosticIDs::Fatal;
break;
}
// Upgrade ignored diagnostics if -Weverything is enabled.
if (Diag.EnableAllWarnings && Result == DiagnosticIDs::Ignored &&
!MappingInfo.isUser())
Result = DiagnosticIDs::Warning;
// Ignore -pedantic diagnostics inside __extension__ blocks.
// (The diagnostics controlled by -pedantic are the extension diagnostics
// that are not enabled by default.)
bool EnabledByDefault = false;
bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault);
if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault)
return DiagnosticIDs::Ignored;
// For extension diagnostics that haven't been explicitly mapped, check if we
// should upgrade the diagnostic.
if (IsExtensionDiag && !MappingInfo.isUser()) {
switch (Diag.ExtBehavior) {
case DiagnosticsEngine::Ext_Ignore:
break;
case DiagnosticsEngine::Ext_Warn:
// Upgrade ignored diagnostics to warnings.
if (Result == DiagnosticIDs::Ignored)
Result = DiagnosticIDs::Warning;
break;
case DiagnosticsEngine::Ext_Error:
// Upgrade ignored or warning diagnostics to errors.
if (Result == DiagnosticIDs::Ignored || Result == DiagnosticIDs::Warning)
Result = DiagnosticIDs::Error;
break;
}
}
// At this point, ignored errors can no longer be upgraded.
if (Result == DiagnosticIDs::Ignored)
return Result;
// Honor -w, which is lower in priority than pedantic-errors, but higher than
// -Werror.
if (Result == DiagnosticIDs::Warning && Diag.IgnoreAllWarnings)
return DiagnosticIDs::Ignored;
// If -Werror is enabled, map warnings to errors unless explicitly disabled.
if (Result == DiagnosticIDs::Warning) {
if (Diag.WarningsAsErrors && !MappingInfo.hasNoWarningAsError())
Result = DiagnosticIDs::Error;
}
// If -Wfatal-errors is enabled, map errors to fatal unless explicity
// disabled.
if (Result == DiagnosticIDs::Error) {
if (Diag.ErrorsAsFatal && !MappingInfo.hasNoErrorAsFatal())
Result = DiagnosticIDs::Fatal;
}
// If we are in a system header, we ignore it. We look at the diagnostic class
// because we also want to ignore extensions and warnings in -Werror and
// -pedantic-errors modes, which *map* warnings/extensions to errors.
if (Result >= DiagnosticIDs::Warning &&
DiagClass != CLASS_ERROR &&
// Custom diagnostics always are emitted in system headers.
DiagID < diag::DIAG_UPPER_LIMIT &&
!MappingInfo.hasShowInSystemHeader() &&
Diag.SuppressSystemWarnings &&
Loc.isValid() &&
Diag.getSourceManager().isInSystemHeader(
Diag.getSourceManager().getExpansionLoc(Loc)))
return DiagnosticIDs::Ignored;
return Result;
}