//===--- DiagnosticIDs.cpp - Diagnostic IDs Handling ----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the Diagnostic IDs-related interfaces. // //===----------------------------------------------------------------------===// #include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/AllDiagnostics.h" #include "clang/Basic/DiagnosticCategories.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" #include <map> #include <optional> usingnamespaceclang; //===----------------------------------------------------------------------===// // Builtin Diagnostic information //===----------------------------------------------------------------------===// namespace … // namespace static const unsigned StaticDiagInfoSize = …; /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, /// or null if the ID is invalid. static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { … } DiagnosticMapping DiagnosticIDs::getDefaultMapping(unsigned DiagID) { … } /// getCategoryNumberForDiag - Return the category number that a specified /// DiagID belongs to, or 0 if no category. unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) { … } namespace { // The diagnostic category names. struct StaticDiagCategoryRec { … }; } static const StaticDiagCategoryRec CategoryNameTable[] = …; /// getNumberOfCategories - Return the number of categories unsigned DiagnosticIDs::getNumberOfCategories() { … } /// getCategoryNameFromID - Given a category ID, return the name of the /// category, an empty string if CategoryID is zero, or null if CategoryID is /// invalid. StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) { … } DiagnosticIDs::SFINAEResponse DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) { … } bool DiagnosticIDs::isDeferrable(unsigned DiagID) { … } /// getBuiltinDiagClass - Return the class field of the diagnostic. /// static unsigned getBuiltinDiagClass(unsigned DiagID) { … } //===----------------------------------------------------------------------===// // Custom Diagnostic information //===----------------------------------------------------------------------===// namespace clang { namespace diag { class CustomDiagInfo { … }; } // end diag namespace } // end clang namespace //===----------------------------------------------------------------------===// // Common Diagnostic implementation //===----------------------------------------------------------------------===// DiagnosticIDs::DiagnosticIDs() { … } DiagnosticIDs::~DiagnosticIDs() { … } /// getCustomDiagID - Return an ID for a diagnostic with the specified message /// and level. If this is the first request for this diagnostic, it is /// registered and created, otherwise the existing ID is returned. /// /// \param FormatString A fixed diagnostic format string that will be hashed and /// mapped to a unique DiagID. unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef FormatString) { … } /// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic /// level of the specified diagnostic ID is a Warning or Extension. /// This only works on builtin diagnostics, not custom ones, and is not legal to /// call on NOTEs. bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) { … } /// Determine whether the given built-in diagnostic ID is a /// Note. bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) { … } /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic /// ID is for an extension of some sort. This also returns EnabledByDefault, /// which is set to indicate whether the diagnostic is ignored by default (in /// which case -pedantic enables it) or treated as a warning/error by default. /// bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault) { … } bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) { … } /// getDescription - Given a diagnostic ID, return a description of the /// issue. StringRef DiagnosticIDs::getDescription(unsigned DiagID) const { … } static DiagnosticIDs::Level toLevel(diag::Severity SV) { … } /// getDiagnosticLevel - Based on the way the client configured the /// DiagnosticsEngine object, classify the specified diagnostic ID into a Level, /// by consumable the DiagnosticClient. DiagnosticIDs::Level DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, const DiagnosticsEngine &Diag) const { … } /// 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, SourceLocation Loc, const DiagnosticsEngine &Diag) const { … } #define GET_DIAG_ARRAYS #include "clang/Basic/DiagnosticGroups.inc" #undef GET_DIAG_ARRAYS namespace { struct WarningOption { … }; } // Second the table of options, sorted by name for fast binary lookup. static const WarningOption OptionTable[] = …; /// Given a diagnostic group ID, return its documentation. StringRef DiagnosticIDs::getWarningOptionDocumentation(diag::Group Group) { … } StringRef DiagnosticIDs::getWarningOptionForGroup(diag::Group Group) { … } std::optional<diag::Group> DiagnosticIDs::getGroupForWarningOption(StringRef Name) { … } std::optional<diag::Group> DiagnosticIDs::getGroupForDiag(unsigned DiagID) { … } /// 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) { … } std::vector<std::string> DiagnosticIDs::getDiagnosticFlags() { … } /// Return \c true if any diagnostics were found in this group, even if they /// were filtered out due to having the wrong flavor. static bool getDiagnosticsInGroup(diag::Flavor Flavor, const WarningOption *Group, SmallVectorImpl<diag::kind> &Diags) { … } bool DiagnosticIDs::getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group, SmallVectorImpl<diag::kind> &Diags) const { … } void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor, std::vector<diag::kind> &Diags) { … } StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor, StringRef Group) { … } /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag, const DiagnosticBuilder &DiagBuilder) const { … } void DiagnosticIDs::EmitDiag(DiagnosticsEngine &Diag, const DiagnosticBuilder &DiagBuilder, Level DiagLevel) const { … } bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const { … } bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) { … } bool DiagnosticIDs::isCodegenABICheckDiagnostic(unsigned DiagID) { … }