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