[llvm] [TextAPI] Introduce Records & RecordSlice Types (PR #74115)

Juergen Ributzka via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 12:30:53 PST 2023


================
@@ -0,0 +1,231 @@
+//===- RecordsSlice.cpp --------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the Records Slice APIs.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/TextAPI/RecordsSlice.h"
+#include "llvm/TextAPI/Record.h"
+#include "llvm/TextAPI/Symbol.h"
+#include <utility>
+
+using namespace llvm;
+using namespace llvm::MachO;
+
+Record *RecordsSlice::addRecord(StringRef Name, SymbolFlags Flags,
+                                GlobalRecord::Kind GV, RecordLinkage Linkage) {
+  // Find a specific Record type to capture.
+  auto [APIName, SymKind] = parseSymbol(Name, Flags);
+  Name = APIName;
+  switch (SymKind) {
+  case SymbolKind::GlobalSymbol:
+    return addGlobal(Name, Linkage, GV, Flags);
+  case SymbolKind::ObjectiveCClass:
+    return addObjCInterface(Name, Linkage);
+  case SymbolKind::ObjectiveCClassEHType:
+    return addObjCInterface(Name, Linkage, /*IsEHType=*/true);
+  case SymbolKind::ObjectiveCInstanceVariable: {
+    auto [Super, IVar] = Name.split('.');
+    // Attempt to find super class.
+    ObjCContainerRecord *Container = findContainer(/*isIVar=*/false, Super);
+    // If not found, create extension since there is no mapped class symbol.
+    if (Container == nullptr)
+      Container = addObjCCategory(Super, {});
+    return addObjCIVar(Container, IVar, Linkage);
+  }
+  }
+
+  llvm_unreachable("unexpected symbol kind when adding to Record Slice");
+}
+
+bool RecordsSlice::updateLinkage(Record *R, RecordLinkage L) {
----------------
ributzka wrote:

The return value of the method is never used, so this could be simplified to `max()`.

https://github.com/llvm/llvm-project/pull/74115


More information about the llvm-commits mailing list