================
@@ -1672,6 +1673,144 @@ void clang::EmitClangDiagsEnums(const RecordKeeper
&Records, raw_ostream &OS,
}
}
+//===----------------------------------------------------------------------===//
+// Stable ID Tables generation
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+/// Holds the string table for all Stable IDs, plus the arrays of legacy Stable
+/// IDs for renamed diagnostics.
+class DiagStableIDsMap {
+ StringToOffsetTable StableIDs;
+ std::vector<uint32_t> LegacyStableIDs;
+ std::map<StringRef, uint32_t> LegacyStableIDsStartOffsets;
+
+public:
+ DiagStableIDsMap(const RecordKeeper &Records) {
+ LegacyStableIDs.push_back(0); // Empty array at offset 0
+
+ for (const Record *Diag : Records.getAllDerivedDefinitions("Diagnostic")) {
+ StringRef StableID = getStableID(*Diag);
+ // Memoize the Stable ID
+ StableIDs.GetOrAddStringOffset(StableID);
+
+ auto LegacyIDList = Diag->getValueAsListOfStrings("LegacyStableIds");
+ if (!LegacyIDList.empty()) {
+ // Memoize any Legacy Stable IDs, and list their offsets in an array.
+ size_t StartOffset = LegacyStableIDs.size();
+ LegacyStableIDsStartOffsets.insert(
+ std::make_pair(Diag->getName(), StartOffset));
+ for (const auto LegacyID : LegacyIDList) {
+ unsigned Offset = StableIDs.GetOrAddStringOffset(LegacyID);
+ LegacyStableIDs.push_back(Offset);
+ }
+ LegacyStableIDs.push_back(0); // Terminate the array.
+ }
+ }
+ }
+
+ /// Gets the string table offset of the Stable ID for the specified
Diagnostic
+ /// record.
+ uint32_t getStableIDOffset(const Record &R) const {
+ return StableIDs.GetStringOffset(getStableID(R)).value();
+ }
+
+ /// Gets the offset in the DiagLegacyStableIDs array of the first element of
+ /// the diagnostic's list of legacy Stable IDs.
+ uint32_t getLegacyStableIDsStartOffset(StringRef Name) const {
+ auto found = LegacyStableIDsStartOffsets.find(Name);
+ if (found != LegacyStableIDsStartOffsets.cend()) {
+ return found->second;
+ } else {
+ return 0;
+ }
+ }
+
+ /// Emit diagnostic stable ID arrays and related data structures.
+ ///
+ /// This creates the table of stable IDs, plus the array of arrays of old
+ /// stable IDs.
+ ///
+ /// \code
+ /// #ifdef GET_DIAG_STABLE_ID_ARRAYS
+ /// static const int32_t DiagOldStableIds[];
+ /// static constexpr llvm::StringTable DiagStableIds;
+ /// #endif
+ /// \endcode
+ void emit(raw_ostream &OS) const {
+ OS << "\n#ifdef GET_DIAG_STABLE_ID_ARRAYS\n";
+ emitStableIDs(OS);
+ emitLegacyStableIDs(OS);
+ OS << "#endif // GET_DIAG_STABLE_ID_ARRAYS\n\n";
+ }
+
+private:
+ /// Gets the Stable ID for the specified Diagnostic record.
+ /// The Stable ID can be explicitly specified via the "StableId"
+ /// property. If not specified explicitly, the Stable ID defaults
+ /// to the name of the diagnostic.
+ static StringRef getStableID(const Record &R) {
+ StringRef StableID = R.getValueAsString("StableId");
+ if (!StableID.empty()) {
+ return StableID;
+ } else {
+ return R.getName();
+ }
----------------
steakhal wrote:
```suggestion
return StableID.empty() ? R.getName() : StableID;
```
https://github.com/llvm/llvm-project/pull/168153
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits