1//===- RecordVisitor.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// Implements the TAPI Record Visitor.
10///
11//===----------------------------------------------------------------------===//
12
13#include "llvm/TextAPI/RecordVisitor.h"
14
15using namespace llvm;
16using namespace llvm::MachO;
17
18RecordVisitor::~RecordVisitor() {}
19void RecordVisitor::visitObjCInterface(const ObjCInterfaceRecord &) {}
20void RecordVisitor::visitObjCCategory(const ObjCCategoryRecord &) {}
21
22static bool shouldSkipRecord(const Record &R, const bool RecordUndefs) {
23  if (R.isExported())
24    return false;
25
26  // Skip non exported symbols unless for flat namespace libraries.
27  return !(RecordUndefs && R.isUndefined());
28}
29
30void SymbolConverter::visitGlobal(const GlobalRecord &GR) {
31  auto [SymName, SymKind] = parseSymbol(GR.getName(), GR.getFlags());
32  if (shouldSkipRecord(GR, RecordUndefs))
33    return;
34  Symbols->addGlobal(SymKind, SymName, GR.getFlags(), Targ);
35}
36
37void SymbolConverter::addIVars(const ArrayRef<ObjCIVarRecord *> IVars,
38                               StringRef ContainerName) {
39  for (auto *IV : IVars) {
40    if (shouldSkipRecord(*IV, RecordUndefs))
41      continue;
42    std::string Name =
43        ObjCIVarRecord::createScopedName(ContainerName, IV->getName());
44    Symbols->addGlobal(SymbolKind::ObjectiveCInstanceVariable, Name,
45                       IV->getFlags(), Targ);
46  }
47}
48
49void SymbolConverter::visitObjCInterface(const ObjCInterfaceRecord &ObjCR) {
50  if (!shouldSkipRecord(ObjCR, RecordUndefs)) {
51    Symbols->addGlobal(SymbolKind::ObjectiveCClass, ObjCR.getName(),
52                       ObjCR.getFlags(), Targ);
53    if (ObjCR.hasExceptionAttribute())
54      Symbols->addGlobal(SymbolKind::ObjectiveCClassEHType, ObjCR.getName(),
55                         ObjCR.getFlags(), Targ);
56  }
57
58  addIVars(ObjCR.getObjCIVars(), ObjCR.getName());
59  for (const auto *Cat : ObjCR.getObjCCategories())
60    addIVars(Cat->getObjCIVars(), ObjCR.getName());
61}
62
63void SymbolConverter::visitObjCCategory(const ObjCCategoryRecord &Cat) {
64  addIVars(Cat.getObjCIVars(), Cat.getName());
65}
66