llvm-project
92 строки · 3.6 Кб
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) {23if (R.isExported())24return false;25
26// Skip non exported symbols unless for flat namespace libraries.27return !(RecordUndefs && R.isUndefined());28}
29
30void SymbolConverter::visitGlobal(const GlobalRecord &GR) {31auto [SymName, SymKind, InterfaceType] = parseSymbol(GR.getName());32if (shouldSkipRecord(GR, RecordUndefs))33return;34Symbols->addGlobal(SymKind, SymName, GR.getFlags(), Targ);35
36if (InterfaceType == ObjCIFSymbolKind::None) {37Symbols->addGlobal(SymKind, SymName, GR.getFlags(), Targ);38return;39}40
41// It is impossible to hold a complete ObjCInterface with a single42// GlobalRecord, so continue to treat this symbol a generic global.43Symbols->addGlobal(EncodeKind::GlobalSymbol, GR.getName(), GR.getFlags(),44Targ);45}
46
47void SymbolConverter::addIVars(const ArrayRef<ObjCIVarRecord *> IVars,48StringRef ContainerName) {49for (auto *IV : IVars) {50if (shouldSkipRecord(*IV, RecordUndefs))51continue;52std::string Name =53ObjCIVarRecord::createScopedName(ContainerName, IV->getName());54Symbols->addGlobal(EncodeKind::ObjectiveCInstanceVariable, Name,55IV->getFlags(), Targ);56}57}
58
59void SymbolConverter::visitObjCInterface(const ObjCInterfaceRecord &ObjCR) {60if (!shouldSkipRecord(ObjCR, RecordUndefs)) {61if (ObjCR.isCompleteInterface()) {62Symbols->addGlobal(EncodeKind::ObjectiveCClass, ObjCR.getName(),63ObjCR.getFlags(), Targ);64if (ObjCR.hasExceptionAttribute())65Symbols->addGlobal(EncodeKind::ObjectiveCClassEHType, ObjCR.getName(),66ObjCR.getFlags(), Targ);67} else {68// Because there is not a complete interface, visit individual symbols69// instead.70if (ObjCR.isExportedSymbol(ObjCIFSymbolKind::EHType))71Symbols->addGlobal(EncodeKind::GlobalSymbol,72(ObjC2EHTypePrefix + ObjCR.getName()).str(),73ObjCR.getFlags(), Targ);74if (ObjCR.isExportedSymbol(ObjCIFSymbolKind::Class))75Symbols->addGlobal(EncodeKind::GlobalSymbol,76(ObjC2ClassNamePrefix + ObjCR.getName()).str(),77ObjCR.getFlags(), Targ);78if (ObjCR.isExportedSymbol(ObjCIFSymbolKind::MetaClass))79Symbols->addGlobal(EncodeKind::GlobalSymbol,80(ObjC2MetaClassNamePrefix + ObjCR.getName()).str(),81ObjCR.getFlags(), Targ);82}83}84
85addIVars(ObjCR.getObjCIVars(), ObjCR.getName());86for (const auto *Cat : ObjCR.getObjCCategories())87addIVars(Cat->getObjCIVars(), ObjCR.getName());88}
89
90void SymbolConverter::visitObjCCategory(const ObjCCategoryRecord &Cat) {91addIVars(Cat.getObjCIVars(), Cat.getSuperClassName());92}
93