1f4a2713aSLionel Sambuc //===- DiagnosticNames.h - Defines a table of all builtin diagnostics ------==// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc 10*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H 11*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H 12*0a6a1f1dSLionel Sambuc 13f4a2713aSLionel Sambuc #include "llvm/ADT/ArrayRef.h" 14f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h" 15f4a2713aSLionel Sambuc #include "llvm/Support/DataTypes.h" 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc namespace diagtool { 18f4a2713aSLionel Sambuc 19f4a2713aSLionel Sambuc struct DiagnosticRecord { 20f4a2713aSLionel Sambuc const char *NameStr; 21f4a2713aSLionel Sambuc short DiagID; 22f4a2713aSLionel Sambuc uint8_t NameLen; 23f4a2713aSLionel Sambuc getNameDiagnosticRecord24f4a2713aSLionel Sambuc llvm::StringRef getName() const { 25f4a2713aSLionel Sambuc return llvm::StringRef(NameStr, NameLen); 26f4a2713aSLionel Sambuc } 27f4a2713aSLionel Sambuc 28f4a2713aSLionel Sambuc bool operator<(const DiagnosticRecord &Other) const { 29f4a2713aSLionel Sambuc return getName() < Other.getName(); 30f4a2713aSLionel Sambuc } 31f4a2713aSLionel Sambuc }; 32f4a2713aSLionel Sambuc 33f4a2713aSLionel Sambuc /// \brief Get every diagnostic in the system, sorted by name. 34f4a2713aSLionel Sambuc llvm::ArrayRef<DiagnosticRecord> getBuiltinDiagnosticsByName(); 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc /// \brief Get a diagnostic by its ID. 37f4a2713aSLionel Sambuc const DiagnosticRecord &getDiagnosticForID(short DiagID); 38f4a2713aSLionel Sambuc 39f4a2713aSLionel Sambuc 40f4a2713aSLionel Sambuc struct GroupRecord { 41f4a2713aSLionel Sambuc uint16_t NameOffset; 42f4a2713aSLionel Sambuc uint16_t Members; 43f4a2713aSLionel Sambuc uint16_t SubGroups; 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc llvm::StringRef getName() const; 46f4a2713aSLionel Sambuc 47f4a2713aSLionel Sambuc template<typename RecordType> 48f4a2713aSLionel Sambuc class group_iterator { 49f4a2713aSLionel Sambuc const short *CurrentID; 50f4a2713aSLionel Sambuc 51f4a2713aSLionel Sambuc friend struct GroupRecord; group_iteratorGroupRecord52f4a2713aSLionel Sambuc group_iterator(const short *Start) : CurrentID(Start) { 53f4a2713aSLionel Sambuc if (CurrentID && *CurrentID == -1) 54*0a6a1f1dSLionel Sambuc CurrentID = nullptr; 55f4a2713aSLionel Sambuc } 56f4a2713aSLionel Sambuc 57f4a2713aSLionel Sambuc public: 58f4a2713aSLionel Sambuc typedef RecordType value_type; 59f4a2713aSLionel Sambuc typedef const value_type & reference; 60f4a2713aSLionel Sambuc typedef const value_type * pointer; 61f4a2713aSLionel Sambuc typedef std::forward_iterator_tag iterator_category; 62f4a2713aSLionel Sambuc typedef std::ptrdiff_t difference_type; 63f4a2713aSLionel Sambuc 64f4a2713aSLionel Sambuc inline reference operator*() const; 65f4a2713aSLionel Sambuc inline pointer operator->() const { 66f4a2713aSLionel Sambuc return &operator*(); 67f4a2713aSLionel Sambuc } 68f4a2713aSLionel Sambuc getIDGroupRecord69f4a2713aSLionel Sambuc inline short getID() const { 70f4a2713aSLionel Sambuc return *CurrentID; 71f4a2713aSLionel Sambuc } 72f4a2713aSLionel Sambuc 73f4a2713aSLionel Sambuc group_iterator &operator++() { 74f4a2713aSLionel Sambuc ++CurrentID; 75f4a2713aSLionel Sambuc if (*CurrentID == -1) 76*0a6a1f1dSLionel Sambuc CurrentID = nullptr; 77f4a2713aSLionel Sambuc return *this; 78f4a2713aSLionel Sambuc } 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc bool operator==(group_iterator &Other) const { 81f4a2713aSLionel Sambuc return CurrentID == Other.CurrentID; 82f4a2713aSLionel Sambuc } 83f4a2713aSLionel Sambuc 84f4a2713aSLionel Sambuc bool operator!=(group_iterator &Other) const { 85f4a2713aSLionel Sambuc return CurrentID != Other.CurrentID; 86f4a2713aSLionel Sambuc } 87f4a2713aSLionel Sambuc }; 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc typedef group_iterator<GroupRecord> subgroup_iterator; 90f4a2713aSLionel Sambuc subgroup_iterator subgroup_begin() const; 91f4a2713aSLionel Sambuc subgroup_iterator subgroup_end() const; 92f4a2713aSLionel Sambuc 93f4a2713aSLionel Sambuc typedef group_iterator<DiagnosticRecord> diagnostics_iterator; 94f4a2713aSLionel Sambuc diagnostics_iterator diagnostics_begin() const; 95f4a2713aSLionel Sambuc diagnostics_iterator diagnostics_end() const; 96f4a2713aSLionel Sambuc 97f4a2713aSLionel Sambuc bool operator<(llvm::StringRef Other) const { 98f4a2713aSLionel Sambuc return getName() < Other; 99f4a2713aSLionel Sambuc } 100f4a2713aSLionel Sambuc }; 101f4a2713aSLionel Sambuc 102f4a2713aSLionel Sambuc /// \brief Get every diagnostic group in the system, sorted by name. 103f4a2713aSLionel Sambuc llvm::ArrayRef<GroupRecord> getDiagnosticGroups(); 104f4a2713aSLionel Sambuc 105f4a2713aSLionel Sambuc template<> 106f4a2713aSLionel Sambuc inline GroupRecord::subgroup_iterator::reference 107f4a2713aSLionel Sambuc GroupRecord::subgroup_iterator::operator*() const { 108f4a2713aSLionel Sambuc return getDiagnosticGroups()[*CurrentID]; 109f4a2713aSLionel Sambuc } 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambuc template<> 112f4a2713aSLionel Sambuc inline GroupRecord::diagnostics_iterator::reference 113f4a2713aSLionel Sambuc GroupRecord::diagnostics_iterator::operator*() const { 114f4a2713aSLionel Sambuc return getDiagnosticForID(*CurrentID); 115f4a2713aSLionel Sambuc } 116f4a2713aSLionel Sambuc } // end namespace diagtool 117f4a2713aSLionel Sambuc 118*0a6a1f1dSLionel Sambuc #endif 119