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