|
| 1 | +//===- llvm/TextAPI/RecordSlice.h - TAPI RecordSlice ------------*- C++ -*-===// |
| 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 | +/// \file |
| 10 | +/// \brief Implements the TAPI Record Collection Type. |
| 11 | +/// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#ifndef LLVM_TEXTAPI_RECORDSLICE_H |
| 15 | +#define LLVM_TEXTAPI_RECORDSLICE_H |
| 16 | + |
| 17 | +#include "llvm/ADT/MapVector.h" |
| 18 | +#include "llvm/Support/Allocator.h" |
| 19 | +#include "llvm/TextAPI/InterfaceFile.h" |
| 20 | +#include "llvm/TextAPI/PackedVersion.h" |
| 21 | +#include "llvm/TextAPI/Record.h" |
| 22 | + |
| 23 | +namespace llvm { |
| 24 | +namespace MachO { |
| 25 | + |
| 26 | +// Define collection of records for a library that are tied to a darwin target |
| 27 | +// triple. |
| 28 | +class RecordsSlice { |
| 29 | +public: |
| 30 | + RecordsSlice(const llvm::Triple &T) : TargetTriple(T), Target(T) {} |
| 31 | + /// Get target triple. |
| 32 | + const llvm::Triple &getTriple() const { return TargetTriple; } |
| 33 | + /// Get TAPI converted target. |
| 34 | + const Target &getTarget() const { return Target; } |
| 35 | + |
| 36 | + /// Add unspecified record to slice. |
| 37 | + /// |
| 38 | + /// Assign specific record type based on properties and symbol name. |
| 39 | + /// |
| 40 | + /// \param Name The name of symbol. |
| 41 | + /// \param Flags The flags that describe attributes of the symbol. |
| 42 | + /// \param GV The kind of global, if this represents a non obj-c global |
| 43 | + /// symbol. |
| 44 | + /// \param Linkage The linkage of symbol. |
| 45 | + /// \return The non-owning pointer to added record in slice. |
| 46 | + Record *addRecord(StringRef Name, SymbolFlags Flags, |
| 47 | + GlobalRecord::Kind GV = GlobalRecord::Kind::Unknown, |
| 48 | + RecordLinkage Linkage = RecordLinkage::Unknown); |
| 49 | + |
| 50 | + /// Add non-ObjC global record. |
| 51 | + /// |
| 52 | + /// \param Name The name of symbol. |
| 53 | + /// \param Flags The flags that describe attributes of the symbol. |
| 54 | + /// \param GV The kind of global. |
| 55 | + /// \param Linkage The linkage of symbol. |
| 56 | + /// \return The non-owning pointer to added record in slice. |
| 57 | + GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage, |
| 58 | + GlobalRecord::Kind GV, |
| 59 | + SymbolFlags Flags = SymbolFlags::None); |
| 60 | + |
| 61 | + /// Add ObjC Class record. |
| 62 | + /// |
| 63 | + /// \param Name The name of class, not symbol. |
| 64 | + /// \param Linkage The linkage of symbol. |
| 65 | + /// \param HasEHType Whether symbol represents an eh_type. |
| 66 | + /// \return The non-owning pointer to added record in slice. |
| 67 | + ObjCInterfaceRecord *addObjCInterface(StringRef Name, RecordLinkage Linkage, |
| 68 | + bool HasEHType = false); |
| 69 | + |
| 70 | + /// Add ObjC IVar record. |
| 71 | + /// |
| 72 | + /// \param Name The name of ivar, not symbol. |
| 73 | + /// \param Linkage The linkage of symbol. |
| 74 | + /// \return The non-owning pointer to added record in slice. |
| 75 | + ObjCIVarRecord *addObjCIVar(ObjCContainerRecord *Container, StringRef Name, |
| 76 | + RecordLinkage Linkage); |
| 77 | + |
| 78 | + /// Add ObjC Category record. |
| 79 | + /// |
| 80 | + /// \param ClassToExtend The name of class that is being extended by the |
| 81 | + /// category, not symbol. |
| 82 | + /// \param Category The name of category. |
| 83 | + /// \return The non-owning pointer to added record in slice. |
| 84 | + ObjCCategoryRecord *addObjCCategory(StringRef ClassToExtend, |
| 85 | + StringRef Category); |
| 86 | + |
| 87 | + /// Find ObjC Class. |
| 88 | + /// |
| 89 | + /// \param Name name of class, not full symbol name. |
| 90 | + /// \return The non-owning pointer to record in slice. |
| 91 | + ObjCInterfaceRecord *findObjCInterface(StringRef Name) const; |
| 92 | + |
| 93 | + /// Find ObjC Category. |
| 94 | + /// |
| 95 | + /// \param ClassToExtend The name of class, not full symbol name. |
| 96 | + /// \param Categories The name of category. |
| 97 | + /// \return The non-owning pointer to record in slice. |
| 98 | + ObjCCategoryRecord *findObjCCategory(StringRef ClassToExtend, |
| 99 | + StringRef Category) const; |
| 100 | + |
| 101 | + /// Find ObjC Container. This is commonly used for assigning for looking up |
| 102 | + /// instance variables that are assigned to either a category or class. |
| 103 | + /// |
| 104 | + /// \param IsIVar If true, the name is the name of the IVar, otherwise it will |
| 105 | + /// be looked up as the name of the container. |
| 106 | + /// \param Name Either the name of ivar or name of container. |
| 107 | + /// \return The non-owning pointer to record in |
| 108 | + /// slice. |
| 109 | + ObjCContainerRecord *findContainer(bool IsIVar, StringRef Name) const; |
| 110 | + |
| 111 | + /// Find ObjC instance variable. |
| 112 | + /// |
| 113 | + /// \param IsScopedName This is used to determine how to parse the name. |
| 114 | + /// \param Name Either the full name of the symbol or just the ivar. |
| 115 | + /// \return The non-owning pointer to record in slice. |
| 116 | + ObjCIVarRecord *findObjCIVar(bool IsScopedName, StringRef Name) const; |
| 117 | + |
| 118 | + /// Find non-objc global. |
| 119 | + /// |
| 120 | + /// \param Name The name of symbol. |
| 121 | + /// \param GV The Kind of global to find. |
| 122 | + /// \return The non-owning pointer to record in slice. |
| 123 | + GlobalRecord * |
| 124 | + findGlobal(StringRef Name, |
| 125 | + GlobalRecord::Kind GV = GlobalRecord::Kind::Unknown) const; |
| 126 | + |
| 127 | + // Determine if library attributes were assigned. |
| 128 | + bool hasBinaryAttrs() const { return BA.get(); } |
| 129 | + |
| 130 | + // Determine if record slice is unassigned. |
| 131 | + bool isEmpty() const { |
| 132 | + return !hasBinaryAttrs() && Globals.empty() && Classes.empty() && |
| 133 | + Categories.empty(); |
| 134 | + } |
| 135 | + |
| 136 | + struct BinaryAttrs { |
| 137 | + std::vector<StringRef> AllowableClients; |
| 138 | + std::vector<StringRef> RexportedLibraries; |
| 139 | + std::vector<StringRef> RPaths; |
| 140 | + StringRef ParentUmbrella; |
| 141 | + StringRef InstallName; |
| 142 | + StringRef UUID; |
| 143 | + StringRef Path; |
| 144 | + FileType fileType = FileType::Invalid; |
| 145 | + llvm::MachO::PackedVersion CurrentVersion; |
| 146 | + llvm::MachO::PackedVersion CompatVersion; |
| 147 | + uint8_t SwiftABI = 0; |
| 148 | + bool TwoLevelNamespace = false; |
| 149 | + bool AppExtensionSafe = false; |
| 150 | + bool OSLibNotForSharedCache = false; |
| 151 | + }; |
| 152 | + |
| 153 | + /// Return reference to BinaryAttrs. |
| 154 | + BinaryAttrs &getBinaryAttrs(); |
| 155 | + |
| 156 | +private: |
| 157 | + const llvm::Triple TargetTriple; |
| 158 | + // Hold tapi converted triple to avoid unecessary casts. |
| 159 | + const Target Target; |
| 160 | + |
| 161 | + /// BumpPtrAllocator to store generated/copied strings. |
| 162 | + llvm::BumpPtrAllocator StringAllocator; |
| 163 | + StringRef copyString(StringRef String); |
| 164 | + |
| 165 | + /// Promote linkage of requested record. It is no-op if linkage type is lower |
| 166 | + /// than the current assignment. |
| 167 | + /// |
| 168 | + /// \param R The record to update. |
| 169 | + /// \param L Linkage type to update to. |
| 170 | + void updateLinkage(Record *R, RecordLinkage L) { |
| 171 | + R->Linkage = std::max(R->Linkage, L); |
| 172 | + } |
| 173 | + |
| 174 | + RecordMap<GlobalRecord> Globals; |
| 175 | + RecordMap<ObjCInterfaceRecord> Classes; |
| 176 | + RecordMap<ObjCCategoryRecord, std::pair<StringRef, StringRef>> Categories; |
| 177 | + |
| 178 | + std::unique_ptr<BinaryAttrs> BA{nullptr}; |
| 179 | +}; |
| 180 | + |
| 181 | +} // namespace MachO |
| 182 | +} // namespace llvm |
| 183 | +#endif // LLVM_TEXTAPI_RECORDSLICE_H |
0 commit comments