aboutsummaryrefslogtreecommitdiff
path: root/lib/Basic/Diagnostic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Basic/Diagnostic.cpp')
-rw-r--r--lib/Basic/Diagnostic.cpp121
1 files changed, 71 insertions, 50 deletions
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 78b8b0a85597..4a29997a2ccc 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -49,7 +49,7 @@ struct StaticDiagInfoRec {
bool SFINAE : 1;
const char *Description;
const char *OptionGroup;
-
+
bool operator<(const StaticDiagInfoRec &RHS) const {
return DiagID < RHS.DiagID;
}
@@ -88,16 +88,16 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
IsFirst = false;
}
#endif
-
+
// Search the diagnostic table with a binary search.
StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0 };
-
+
const StaticDiagInfoRec *Found =
std::lower_bound(StaticDiagInfo, StaticDiagInfo + NumDiagEntries, Find);
if (Found == StaticDiagInfo + NumDiagEntries ||
Found->DiagID != DiagID)
return 0;
-
+
return Found;
}
@@ -141,7 +141,7 @@ namespace clang {
std::vector<DiagDesc> DiagInfo;
std::map<DiagDesc, unsigned> DiagIDs;
public:
-
+
/// getDescription - Return the description of the specified custom
/// diagnostic.
const char *getDescription(unsigned DiagID) const {
@@ -149,14 +149,14 @@ namespace clang {
"Invalid diagnosic ID");
return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str();
}
-
+
/// getLevel - Return the level of the specified custom diagnostic.
Diagnostic::Level getLevel(unsigned DiagID) const {
assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
"Invalid diagnosic ID");
return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
}
-
+
unsigned getOrCreateDiagID(Diagnostic::Level L, const char *Message,
Diagnostic &Diags) {
DiagDesc D(L, Message);
@@ -164,7 +164,7 @@ namespace clang {
std::map<DiagDesc, unsigned>::iterator I = DiagIDs.lower_bound(D);
if (I != DiagIDs.end() && I->first == D)
return I->second;
-
+
// If not, assign a new ID.
unsigned ID = DiagInfo.size()+DIAG_UPPER_LIMIT;
DiagIDs.insert(std::make_pair(D, ID));
@@ -172,9 +172,9 @@ namespace clang {
return ID;
}
};
-
- } // end diag namespace
-} // end clang namespace
+
+ } // end diag namespace
+} // end clang namespace
//===----------------------------------------------------------------------===//
@@ -196,32 +196,48 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
IgnoreAllWarnings = false;
WarningsAsErrors = false;
SuppressSystemWarnings = false;
+ SuppressAllDiagnostics = false;
ExtBehavior = Ext_Ignore;
-
+
ErrorOccurred = false;
FatalErrorOccurred = false;
NumDiagnostics = 0;
+
NumErrors = 0;
CustomDiagInfo = 0;
CurDiagID = ~0U;
LastDiagLevel = Ignored;
-
+
ArgToStringFn = DummyArgToStringFn;
ArgToStringCookie = 0;
-
+
// Set all mappings to 'unset'.
- memset(DiagMappings, 0, sizeof(DiagMappings));
+ DiagMappings BlankDiags(diag::DIAG_UPPER_LIMIT/2, 0);
+ DiagMappingsStack.push_back(BlankDiags);
}
Diagnostic::~Diagnostic() {
delete CustomDiagInfo;
}
+
+void Diagnostic::pushMappings() {
+ DiagMappingsStack.push_back(DiagMappingsStack.back());
+}
+
+bool Diagnostic::popMappings() {
+ if (DiagMappingsStack.size() == 1)
+ return false;
+
+ DiagMappingsStack.pop_back();
+ return true;
+}
+
/// getCustomDiagID - Return an ID for a diagnostic with the specified message
/// and level. If this is the first request for this diagnosic, it is
/// registered and created, otherwise the existing ID is returned.
unsigned Diagnostic::getCustomDiagID(Level L, const char *Message) {
- if (CustomDiagInfo == 0)
+ if (CustomDiagInfo == 0)
CustomDiagInfo = new diag::CustomDiagInfo();
return CustomDiagInfo->getOrCreateDiagID(L, Message, *this);
}
@@ -267,7 +283,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
// Handle custom diagnostics, which cannot be mapped.
if (DiagID >= diag::DIAG_UPPER_LIMIT)
return CustomDiagInfo->getLevel(DiagID);
-
+
unsigned DiagClass = getBuiltinDiagClass(DiagID);
assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
return getDiagnosticLevel(DiagID, DiagClass);
@@ -281,14 +297,14 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error. Errors can only be mapped to fatal.
Diagnostic::Level Result = Diagnostic::Fatal;
-
+
// Get the mapping information, if unset, compute it lazily.
unsigned MappingInfo = getDiagnosticMappingInfo((diag::kind)DiagID);
if (MappingInfo == 0) {
MappingInfo = GetDefaultDiagMapping(DiagID);
setDiagnosticMappingInternal(DiagID, MappingInfo, false);
}
-
+
switch (MappingInfo & 7) {
default: assert(0 && "Unknown mapping!");
case diag::MAP_IGNORE:
@@ -311,29 +327,29 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
// If warnings are globally mapped to ignore or error, do it.
if (IgnoreAllWarnings)
return Diagnostic::Ignored;
-
+
Result = Diagnostic::Warning;
-
+
// If this is an extension diagnostic and we're in -pedantic-error mode, and
// if the user didn't explicitly map it, upgrade to an error.
if (ExtBehavior == Ext_Error &&
(MappingInfo & 8) == 0 &&
isBuiltinExtensionDiag(DiagID))
Result = Diagnostic::Error;
-
+
if (WarningsAsErrors)
Result = Diagnostic::Error;
break;
-
+
case diag::MAP_WARNING_NO_WERROR:
// Diagnostics specified with -Wno-error=foo should be set to warnings, but
// not be adjusted by -Werror or -pedantic-errors.
Result = Diagnostic::Warning;
-
+
// If warnings are globally mapped to ignore or error, do it.
if (IgnoreAllWarnings)
return Diagnostic::Ignored;
-
+
break;
}
@@ -342,7 +358,7 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const {
// block, silence it.
if (AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID))
return Diagnostic::Ignored;
-
+
return Result;
}
@@ -377,7 +393,7 @@ static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping,
for (; *Member != -1; ++Member)
Diags.setDiagnosticMapping(*Member, Mapping);
}
-
+
// Enable/disable all subgroups along with this one.
if (const char *SubGroups = Group->SubGroups) {
for (; *SubGroups != (char)-1; ++SubGroups)
@@ -390,7 +406,7 @@ static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping,
/// ignores the request if "Group" was unknown, false otherwise.
bool Diagnostic::setDiagnosticGroupMapping(const char *Group,
diag::Mapping Map) {
-
+
WarningOption Key = { Group, 0, 0 };
const WarningOption *Found =
std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
@@ -398,7 +414,7 @@ bool Diagnostic::setDiagnosticGroupMapping(const char *Group,
if (Found == OptionTable + OptionTableSize ||
strcmp(Found->Name, Group) != 0)
return true; // Option not found.
-
+
MapGroupMembers(Found, Map, *this);
return false;
}
@@ -408,19 +424,22 @@ bool Diagnostic::setDiagnosticGroupMapping(const char *Group,
/// finally fully formed.
bool Diagnostic::ProcessDiag() {
DiagnosticInfo Info(this);
-
+
+ if (SuppressAllDiagnostics)
+ return false;
+
// Figure out the diagnostic level of this message.
Diagnostic::Level DiagLevel;
unsigned DiagID = Info.getID();
-
+
// ShouldEmitInSystemHeader - True if this diagnostic should be produced even
// in a system header.
bool ShouldEmitInSystemHeader;
-
+
if (DiagID >= diag::DIAG_UPPER_LIMIT) {
// Handle custom diagnostics, which cannot be mapped.
DiagLevel = CustomDiagInfo->getLevel(DiagID);
-
+
// Custom diagnostics always are emitted in system headers.
ShouldEmitInSystemHeader = true;
} else {
@@ -432,12 +451,12 @@ bool Diagnostic::ProcessDiag() {
DiagLevel = Diagnostic::Note;
ShouldEmitInSystemHeader = false; // extra consideration is needed
} else {
- // If this is not an error and we are in a system header, we ignore it.
+ // If this is not an error and we are in a system header, we ignore it.
// Check the original Diag ID here, because we also want to ignore
// extensions and warnings in -Werror and -pedantic-errors modes, which
// *map* warnings/extensions to errors.
ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR;
-
+
DiagLevel = getDiagnosticLevel(DiagID, DiagClass);
}
}
@@ -451,7 +470,7 @@ bool Diagnostic::ProcessDiag() {
FatalErrorOccurred = true;
LastDiagLevel = DiagLevel;
- }
+ }
// If a fatal error has already been emitted, silence all subsequent
// diagnostics.
@@ -478,7 +497,7 @@ bool Diagnostic::ProcessDiag() {
ErrorOccurred = true;
++NumErrors;
}
-
+
// Finally, report it.
Client->HandleDiagnostic(DiagLevel, Info);
if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
@@ -508,7 +527,7 @@ static void HandleSelectModifier(unsigned ValNo,
const char *Argument, unsigned ArgumentLen,
llvm::SmallVectorImpl<char> &OutStr) {
const char *ArgumentEnd = Argument+ArgumentLen;
-
+
// Skip over 'ValNo' |'s.
while (ValNo) {
const char *NextVal = std::find(Argument, ArgumentEnd, '|');
@@ -517,7 +536,7 @@ static void HandleSelectModifier(unsigned ValNo,
Argument = NextVal+1; // Skip this string.
--ValNo;
}
-
+
// Get the end of the value. This is either the } or the |.
const char *EndPtr = std::find(Argument, ArgumentEnd, '|');
// Add the value to the output string.
@@ -590,7 +609,7 @@ static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) {
// Scan for next or-expr part.
Start = std::find(Start, End, ',');
- if(Start == End)
+ if (Start == End)
break;
++Start;
}
@@ -659,7 +678,7 @@ void DiagnosticInfo::
FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
const char *DiagStr = getDiags()->getDescription(getID());
const char *DiagEnd = DiagStr+strlen(DiagStr);
-
+
while (DiagStr != DiagEnd) {
if (DiagStr[0] != '%') {
// Append non-%0 substrings to Str if we have one.
@@ -672,10 +691,10 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
DiagStr += 2;
continue;
}
-
+
// Skip the %.
++DiagStr;
-
+
// This must be a placeholder for a diagnostic argument. The format for a
// placeholder is one of "%0", "%modifier0", or "%modifier{arguments}0".
// The digit is a number from 0-9 indicating which argument this comes from.
@@ -683,7 +702,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
// brace enclosed string.
const char *Modifier = 0, *Argument = 0;
unsigned ModifierLen = 0, ArgumentLen = 0;
-
+
// Check to see if we have a modifier. If so eat it.
if (!isdigit(DiagStr[0])) {
Modifier = DiagStr;
@@ -696,14 +715,14 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
if (DiagStr[0] == '{') {
++DiagStr; // Skip {.
Argument = DiagStr;
-
+
for (; DiagStr[0] != '}'; ++DiagStr)
assert(DiagStr[0] && "Mismatched {}'s in diagnostic string!");
ArgumentLen = DiagStr-Argument;
++DiagStr; // Skip }.
}
}
-
+
assert(isdigit(*DiagStr) && "Invalid format for argument in diagnostic");
unsigned ArgNo = *DiagStr++ - '0';
@@ -722,14 +741,14 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
// Don't crash if get passed a null pointer by accident.
if (!S)
S = "(null)";
-
+
OutStr.append(S, S + strlen(S));
break;
}
// ---- INTEGERS ----
case Diagnostic::ak_sint: {
int Val = getArgSInt(ArgNo);
-
+
if (ModifierIs(Modifier, ModifierLen, "select")) {
HandleSelectModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
} else if (ModifierIs(Modifier, ModifierLen, "s")) {
@@ -746,7 +765,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
}
case Diagnostic::ak_uint: {
unsigned Val = getArgUInt(ArgNo);
-
+
if (ModifierIs(Modifier, ModifierLen, "select")) {
HandleSelectModifier(Val, Argument, ArgumentLen, OutStr);
} else if (ModifierIs(Modifier, ModifierLen, "s")) {
@@ -755,7 +774,7 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
HandlePluralModifier((unsigned)Val, Argument, ArgumentLen, OutStr);
} else {
assert(ModifierLen == 0 && "Unknown integer modifier");
-
+
// FIXME: Optimize
std::string S = llvm::utostr_32(Val);
OutStr.append(S.begin(), S.end());
@@ -782,6 +801,8 @@ FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
case Diagnostic::ak_qualtype:
case Diagnostic::ak_declarationname:
case Diagnostic::ak_nameddecl:
+ case Diagnostic::ak_nestednamespec:
+ case Diagnostic::ak_declcontext:
getDiags()->ConvertArgToString(getArgKind(ArgNo), getRawArg(ArgNo),
Modifier, ModifierLen,
Argument, ArgumentLen, OutStr);