|
|
|||
File indexing completed on 2026-05-10 08:44:37
0001 //===- llvm/TextAPI/RecordSlice.h - TAPI RecordSlice ------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// 0009 /// \file 0010 /// \brief Implements the TAPI Record Collection Type. 0011 /// 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_TEXTAPI_RECORDSLICE_H 0015 #define LLVM_TEXTAPI_RECORDSLICE_H 0016 0017 #include "llvm/Support/Allocator.h" 0018 #include "llvm/TextAPI/FileTypes.h" 0019 #include "llvm/TextAPI/PackedVersion.h" 0020 #include "llvm/TextAPI/Record.h" 0021 #include "llvm/TextAPI/RecordVisitor.h" 0022 0023 namespace llvm { 0024 namespace MachO { 0025 0026 // Define collection of records for a library that are tied to a darwin target 0027 // triple. 0028 class RecordsSlice { 0029 public: 0030 RecordsSlice(const llvm::Triple &T) : TargetTriple(T), TAPITarget(T) {} 0031 /// Get target triple. 0032 const llvm::Triple &getTriple() const { return TargetTriple; } 0033 /// Get TAPI converted target. 0034 const Target &getTarget() const { return TAPITarget; } 0035 0036 /// Add unspecified record to slice. 0037 /// 0038 /// Assign specific record type based on properties and symbol name. 0039 /// 0040 /// \param Name The name of symbol. 0041 /// \param Flags The flags that describe attributes of the symbol. 0042 /// \param GV The kind of global, if this represents a non obj-c global 0043 /// symbol. 0044 /// \param Linkage The linkage of symbol. 0045 /// \return The non-owning pointer to added record in slice. 0046 Record *addRecord(StringRef Name, SymbolFlags Flags, 0047 GlobalRecord::Kind GV = GlobalRecord::Kind::Unknown, 0048 RecordLinkage Linkage = RecordLinkage::Unknown); 0049 0050 /// Add non-ObjC global record. 0051 /// 0052 /// \param Name The name of symbol. 0053 /// \param Linkage The linkage of symbol. 0054 /// \param GV The kind of global. 0055 /// \param Flags The flags that describe attributes of the symbol. 0056 /// \param Inlined Whether declaration is inlined, only applicable to 0057 /// functions. 0058 /// \return The non-owning pointer to added record in slice. 0059 GlobalRecord *addGlobal(StringRef Name, RecordLinkage Linkage, 0060 GlobalRecord::Kind GV, 0061 SymbolFlags Flags = SymbolFlags::None, 0062 bool Inlined = false); 0063 0064 /// Add ObjC Class record. 0065 /// 0066 /// \param Name The name of class, not symbol. 0067 /// \param Linkage The linkage of symbol. 0068 /// \param SymType The symbols this class represents. 0069 /// \return The non-owning pointer to added record in slice. 0070 ObjCInterfaceRecord *addObjCInterface(StringRef Name, RecordLinkage Linkage, 0071 ObjCIFSymbolKind SymType); 0072 0073 /// Add ObjC IVar record. 0074 /// 0075 /// \param Container Owning pointer for instance variable. 0076 /// \param Name The name of ivar, not symbol. 0077 /// \param Linkage The linkage of symbol. 0078 /// \return The non-owning pointer to added record in slice. 0079 ObjCIVarRecord *addObjCIVar(ObjCContainerRecord *Container, StringRef Name, 0080 RecordLinkage Linkage); 0081 0082 /// Add ObjC Category record. 0083 /// 0084 /// \param ClassToExtend The name of class that is being extended by the 0085 /// category, not symbol. 0086 /// \param Category The name of category. 0087 /// \return The non-owning pointer to added record in slice. 0088 ObjCCategoryRecord *addObjCCategory(StringRef ClassToExtend, 0089 StringRef Category); 0090 0091 /// Find ObjC Class. 0092 /// 0093 /// \param Name name of class, not full symbol name. 0094 /// \return The non-owning pointer to record in slice. 0095 ObjCInterfaceRecord *findObjCInterface(StringRef Name) const; 0096 0097 /// Find ObjC Category. 0098 /// 0099 /// \param ClassToExtend The name of class, not full symbol name. 0100 /// \param Category The name of category. 0101 /// \return The non-owning pointer to record in slice. 0102 ObjCCategoryRecord *findObjCCategory(StringRef ClassToExtend, 0103 StringRef Category) const; 0104 0105 /// Find ObjC Container. This is commonly used for assigning for looking up 0106 /// instance variables that are assigned to either a category or class. 0107 /// 0108 /// \param IsIVar If true, the name is the name of the IVar, otherwise it will 0109 /// be looked up as the name of the container. 0110 /// \param Name Either the name of ivar or name of container. 0111 /// \return The non-owning pointer to record in 0112 /// slice. 0113 ObjCContainerRecord *findContainer(bool IsIVar, StringRef Name) const; 0114 0115 /// Find ObjC instance variable. 0116 /// 0117 /// \param IsScopedName This is used to determine how to parse the name. 0118 /// \param Name Either the full name of the symbol or just the ivar. 0119 /// \return The non-owning pointer to record in slice. 0120 ObjCIVarRecord *findObjCIVar(bool IsScopedName, StringRef Name) const; 0121 0122 /// Find non-objc global. 0123 /// 0124 /// \param Name The name of symbol. 0125 /// \param GV The Kind of global to find. 0126 /// \return The non-owning pointer to record in slice. 0127 GlobalRecord * 0128 findGlobal(StringRef Name, 0129 GlobalRecord::Kind GV = GlobalRecord::Kind::Unknown) const; 0130 0131 // Determine if library attributes were assigned. 0132 bool hasBinaryAttrs() const { return BA.get(); } 0133 0134 // Determine if record slice is unassigned. 0135 bool empty() const { 0136 return !hasBinaryAttrs() && Globals.empty() && Classes.empty() && 0137 Categories.empty(); 0138 } 0139 0140 // Visit all records known to RecordsSlice. 0141 void visit(RecordVisitor &V) const; 0142 0143 struct BinaryAttrs { 0144 std::vector<StringRef> AllowableClients; 0145 std::vector<StringRef> RexportedLibraries; 0146 std::vector<StringRef> RPaths; 0147 StringRef ParentUmbrella; 0148 StringRef InstallName; 0149 StringRef UUID; 0150 StringRef Path; 0151 FileType File = FileType::Invalid; 0152 llvm::MachO::PackedVersion CurrentVersion; 0153 llvm::MachO::PackedVersion CompatVersion; 0154 uint8_t SwiftABI = 0; 0155 bool TwoLevelNamespace = false; 0156 bool AppExtensionSafe = false; 0157 bool OSLibNotForSharedCache = false; 0158 }; 0159 0160 /// Return reference to BinaryAttrs. 0161 BinaryAttrs &getBinaryAttrs(); 0162 0163 /// Store any strings owned by RecordSlice into allocator and return back 0164 /// reference to that. 0165 StringRef copyString(StringRef String); 0166 0167 private: 0168 const llvm::Triple TargetTriple; 0169 // Hold tapi converted triple to avoid unecessary casts. 0170 const Target TAPITarget; 0171 0172 /// BumpPtrAllocator to store generated/copied strings. 0173 llvm::BumpPtrAllocator StringAllocator; 0174 0175 /// Promote linkage of requested record. It is no-op if linkage type is lower 0176 /// than the current assignment. 0177 /// 0178 /// \param R The record to update. 0179 /// \param L Linkage type to update to. 0180 void updateLinkage(Record *R, RecordLinkage L) { 0181 R->Linkage = std::max(R->Linkage, L); 0182 } 0183 0184 /// Update set flags of requested record. 0185 /// 0186 /// \param R The record to update. 0187 /// \param F Flags to update to. 0188 void updateFlags(Record *R, SymbolFlags F) { R->Flags |= F; } 0189 0190 RecordMap<GlobalRecord> Globals; 0191 RecordMap<ObjCInterfaceRecord> Classes; 0192 RecordMap<ObjCCategoryRecord, std::pair<StringRef, StringRef>> Categories; 0193 0194 std::unique_ptr<BinaryAttrs> BA{nullptr}; 0195 }; 0196 0197 using Records = llvm::SmallVector<std::shared_ptr<RecordsSlice>, 4>; 0198 class InterfaceFile; 0199 std::unique_ptr<InterfaceFile> convertToInterfaceFile(const Records &Slices); 0200 0201 } // namespace MachO 0202 } // namespace llvm 0203 #endif // LLVM_TEXTAPI_RECORDSLICE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|