diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp | 229 |
1 files changed, 56 insertions, 173 deletions
diff --git a/contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp b/contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp index 9481287..8c33a96 100644 --- a/contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp +++ b/contrib/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp @@ -11,16 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/ASTDiagnostic.h" -#include "clang/Analysis/AnalysisDiagnostic.h" #include "clang/Basic/DiagnosticIDs.h" +#include "clang/Basic/AllDiagnostics.h" #include "clang/Basic/DiagnosticCategories.h" #include "clang/Basic/SourceManager.h" -#include "clang/Driver/DriverDiagnostic.h" -#include "clang/Frontend/FrontendDiagnostic.h" -#include "clang/Lex/LexDiagnostic.h" -#include "clang/Parse/ParseDiagnostic.h" -#include "clang/Sema/SemaDiagnostic.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" @@ -51,107 +45,49 @@ struct StaticDiagInfoRec { unsigned WarnShowInSystemHeader : 1; unsigned Category : 5; - uint8_t NameLen; - uint8_t OptionGroupLen; + uint16_t OptionGroupIndex; uint16_t DescriptionLen; - uint16_t BriefExplanationLen; - uint16_t FullExplanationLen; - - const char *NameStr; - const char *OptionGroupStr; - const char *DescriptionStr; - const char *BriefExplanationStr; - const char *FullExplanationStr; - StringRef getName() const { - return StringRef(NameStr, NameLen); - } - StringRef getOptionGroup() const { - return StringRef(OptionGroupStr, OptionGroupLen); + unsigned getOptionGroupIndex() const { + return OptionGroupIndex; } StringRef getDescription() const { return StringRef(DescriptionStr, DescriptionLen); } - StringRef getBriefExplanation() const { - return StringRef(BriefExplanationStr, BriefExplanationLen); - } - StringRef getFullExplanation() const { - return StringRef(FullExplanationStr, FullExplanationLen); - } bool operator<(const StaticDiagInfoRec &RHS) const { return DiagID < RHS.DiagID; } }; -struct StaticDiagNameIndexRec { - const char *NameStr; - unsigned short DiagID; - uint8_t NameLen; - - StringRef getName() const { - return StringRef(NameStr, NameLen); - } - - bool operator<(const StaticDiagNameIndexRec &RHS) const { - return getName() < RHS.getName(); - } - - bool operator==(const StaticDiagNameIndexRec &RHS) const { - return getName() == RHS.getName(); - } -}; - -template <size_t SizeOfStr, typename FieldType> -class StringSizerHelper { - char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1]; -public: - enum { Size = SizeOfStr }; -}; - } // namespace anonymous -#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size - static const StaticDiagInfoRec StaticDiagInfo[] = { #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \ SFINAE,ACCESS,NOWERROR,SHOWINSYSHEADER, \ - CATEGORY,BRIEF,FULL) \ + CATEGORY) \ { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \ - NOWERROR, SHOWINSYSHEADER, CATEGORY, \ - STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t), \ - STR_SIZE(DESC, uint16_t), STR_SIZE(BRIEF, uint16_t), \ - STR_SIZE(FULL, uint16_t), \ - #ENUM, GROUP, DESC, BRIEF, FULL }, + NOWERROR, SHOWINSYSHEADER, CATEGORY, GROUP, \ + STR_SIZE(DESC, uint16_t), DESC }, #include "clang/Basic/DiagnosticCommonKinds.inc" #include "clang/Basic/DiagnosticDriverKinds.inc" #include "clang/Basic/DiagnosticFrontendKinds.inc" +#include "clang/Basic/DiagnosticSerializationKinds.inc" #include "clang/Basic/DiagnosticLexKinds.inc" #include "clang/Basic/DiagnosticParseKinds.inc" #include "clang/Basic/DiagnosticASTKinds.inc" #include "clang/Basic/DiagnosticSemaKinds.inc" #include "clang/Basic/DiagnosticAnalysisKinds.inc" #undef DIAG - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; static const unsigned StaticDiagInfoSize = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1; -/// To be sorted before first use (since it's splitted among multiple files) -static const StaticDiagNameIndexRec StaticDiagNameIndex[] = { -#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, -#include "clang/Basic/DiagnosticIndexName.inc" -#undef DIAG_NAME_INDEX - { 0, 0, 0 } -}; - -static const unsigned StaticDiagNameIndexSize = - sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1; - /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, /// or null if the ID is invalid. static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { @@ -173,7 +109,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { // Search the diagnostic table with a binary search. StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const StaticDiagInfoRec *Found = std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find); @@ -207,15 +143,6 @@ static DiagnosticMappingInfo GetDefaultDiagMappingInfo(unsigned DiagID) { return Info; } -/// getWarningOptionForDiag - Return the lowest-level warning option that -/// enables the specified diagnostic. If there is no -Wfoo flag that controls -/// the diagnostic, this returns null. -StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return Info->getOptionGroup(); - return StringRef(); -} - /// getCategoryNumberForDiag - Return the category number that a specified /// DiagID belongs to, or 0 if no category. unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) { @@ -295,50 +222,6 @@ DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) { return SFINAE_Report; } -/// getName - Given a diagnostic ID, return its name -StringRef DiagnosticIDs::getName(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return Info->getName(); - return StringRef(); -} - -/// getIdFromName - Given a diagnostic name, return its ID, or 0 -unsigned DiagnosticIDs::getIdFromName(StringRef Name) { - const StaticDiagNameIndexRec *StaticDiagNameIndexEnd = - StaticDiagNameIndex + StaticDiagNameIndexSize; - - if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; } - - assert(Name.size() == static_cast<uint8_t>(Name.size()) && - "Name is too long"); - StaticDiagNameIndexRec Find = { Name.data(), 0, - static_cast<uint8_t>(Name.size()) }; - - const StaticDiagNameIndexRec *Found = - std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find); - if (Found == StaticDiagNameIndexEnd || - Found->getName() != Name) - return diag::DIAG_UPPER_LIMIT; - - return Found->DiagID; -} - -/// getBriefExplanation - Given a diagnostic ID, return a brief explanation -/// of the issue -StringRef DiagnosticIDs::getBriefExplanation(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return Info->getBriefExplanation(); - return StringRef(); -} - -/// getFullExplanation - Given a diagnostic ID, return a full explanation -/// of the issue -StringRef DiagnosticIDs::getFullExplanation(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return Info->getFullExplanation(); - return StringRef(); -} - /// getBuiltinDiagClass - Return the class field of the diagnostic. /// static unsigned getBuiltinDiagClass(unsigned DiagID) { @@ -348,35 +231,6 @@ static unsigned getBuiltinDiagClass(unsigned DiagID) { } //===----------------------------------------------------------------------===// -// diag_iterator -//===----------------------------------------------------------------------===// - -llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const { - return static_cast<const StaticDiagNameIndexRec*>(impl)->getName(); -} - -unsigned DiagnosticIDs::diag_iterator::getDiagID() const { - return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID; -} - -DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() { - const StaticDiagNameIndexRec* ptr = - static_cast<const StaticDiagNameIndexRec*>(impl);; - ++ptr; - impl = ptr; - return *this; -} - -DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() { - return DiagnosticIDs::diag_iterator(StaticDiagNameIndex); -} - -DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() { - return DiagnosticIDs::diag_iterator(StaticDiagNameIndex + - StaticDiagNameIndexSize); -} - -//===----------------------------------------------------------------------===// // Custom Diagnostic information //===----------------------------------------------------------------------===// @@ -530,7 +384,6 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, (diag::kind)DiagID); switch (MappingInfo.getMapping()) { - default: llvm_unreachable("Unknown mapping!"); case diag::MAP_IGNORE: Result = DiagnosticIDs::Ignored; break; @@ -553,7 +406,7 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass, // Ignore -pedantic diagnostics inside __extension__ blocks. // (The diagnostics controlled by -pedantic are the extension diagnostics // that are not enabled by default.) - bool EnabledByDefault; + bool EnabledByDefault = false; bool IsExtensionDiag = isBuiltinExtensionDiag(DiagID, EnabledByDefault); if (Diag.AllExtensionsSilenced && IsExtensionDiag && !EnabledByDefault) return DiagnosticIDs::Ignored; @@ -648,6 +501,15 @@ static bool WarningOptionCompare(const WarningOption &LHS, return LHS.getName() < RHS.getName(); } +/// getWarningOptionForDiag - Return the lowest-level warning option that +/// enables the specified diagnostic. If there is no -Wfoo flag that controls +/// the diagnostic, this returns null. +StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) { + if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) + return OptionTable[Info->getOptionGroupIndex()].getName(); + return StringRef(); +} + void DiagnosticIDs::getDiagnosticsInGroup( const WarningOption *Group, llvm::SmallVectorImpl<diag::kind> &Diags) const @@ -681,6 +543,35 @@ bool DiagnosticIDs::getDiagnosticsInGroup( return false; } +void DiagnosticIDs::getAllDiagnostics( + llvm::SmallVectorImpl<diag::kind> &Diags) const { + for (unsigned i = 0; i != StaticDiagInfoSize; ++i) + Diags.push_back(StaticDiagInfo[i].DiagID); +} + +StringRef DiagnosticIDs::getNearestWarningOption(StringRef Group) { + StringRef Best; + unsigned BestDistance = Group.size() + 1; // Sanity threshold. + for (const WarningOption *i = OptionTable, *e = OptionTable + OptionTableSize; + i != e; ++i) { + // Don't suggest ignored warning flags. + if (!i->Members && !i->SubGroups) + continue; + + unsigned Distance = i->getName().edit_distance(Group, true, BestDistance); + if (Distance == BestDistance) { + // Two matches with the same distance, don't prefer one over the other. + Best = ""; + } else if (Distance < BestDistance) { + // This is a better match. + Best = i->getName(); + BestDistance = Distance; + } + } + + return Best; +} + /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const { @@ -766,19 +657,6 @@ bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const { } } - // If we have any Fix-Its, make sure that all of the Fix-Its point into - // source locations that aren't macro expansions. If any point into macro - // expansions, remove all of the Fix-Its. - for (unsigned I = 0, N = Diag.NumFixItHints; I != N; ++I) { - const FixItHint &FixIt = Diag.FixItHints[I]; - if (FixIt.RemoveRange.isInvalid() || - FixIt.RemoveRange.getBegin().isMacroID() || - FixIt.RemoveRange.getEnd().isMacroID()) { - Diag.NumFixItHints = 0; - break; - } - } - // Finally, report it. Diag.Client->HandleDiagnostic((DiagnosticsEngine::Level)DiagLevel, Info); if (Diag.Client->IncludeInDiagnosticCounts()) { @@ -806,9 +684,14 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const { return false; // Currently we consider all ARC errors as recoverable. - if (getCategoryNumberForDiag(DiagID) == - diag::DiagCat_Automatic_Reference_Counting_Issue) + if (isARCDiagnostic(DiagID)) return false; return true; } + +bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) { + unsigned cat = getCategoryNumberForDiag(DiagID); + return DiagnosticIDs::getCategoryNameFromID(cat).startswith("ARC "); +} + |