Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 1 | //===- llvm/TextAPI/MachO/IntefaceFile.h - TAPI Interface File --*- 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 | // A generic and abstract interface representation for linkable objects. This |
| 10 | // could be an MachO executable, bundle, dylib, or text-based stub file. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_TEXTAPI_MACHO_INTERFACE_FILE_H |
| 15 | #define LLVM_TEXTAPI_MACHO_INTERFACE_FILE_H |
| 16 | |
| 17 | #include "llvm/ADT/BitmaskEnum.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/Hashing.h" |
| 20 | #include "llvm/ADT/StringRef.h" |
| 21 | #include "llvm/ADT/iterator.h" |
| 22 | #include "llvm/BinaryFormat/MachO.h" |
| 23 | #include "llvm/BinaryFormat/Magic.h" |
| 24 | #include "llvm/Support/Allocator.h" |
| 25 | #include "llvm/Support/Error.h" |
| 26 | #include "llvm/TextAPI/MachO/Architecture.h" |
| 27 | #include "llvm/TextAPI/MachO/ArchitectureSet.h" |
| 28 | #include "llvm/TextAPI/MachO/PackedVersion.h" |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 29 | #include "llvm/TextAPI/MachO/Platform.h" |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 30 | #include "llvm/TextAPI/MachO/Symbol.h" |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 31 | #include "llvm/TextAPI/MachO/Target.h" |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 32 | |
| 33 | namespace llvm { |
| 34 | namespace MachO { |
| 35 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 36 | /// Defines a list of Objective-C constraints. |
| 37 | enum class ObjCConstraintType : unsigned { |
| 38 | /// No constraint. |
| 39 | None = 0, |
| 40 | |
| 41 | /// Retain/Release. |
| 42 | Retain_Release = 1, |
| 43 | |
| 44 | /// Retain/Release for Simulator. |
| 45 | Retain_Release_For_Simulator = 2, |
| 46 | |
| 47 | /// Retain/Release or Garbage Collection. |
| 48 | Retain_Release_Or_GC = 3, |
| 49 | |
| 50 | /// Garbage Collection. |
| 51 | GC = 4, |
| 52 | }; |
| 53 | |
| 54 | // clang-format off |
| 55 | |
| 56 | /// Defines the file type this file represents. |
| 57 | enum FileType : unsigned { |
| 58 | /// Invalid file type. |
| 59 | Invalid = 0U, |
| 60 | |
| 61 | /// Text-based stub file (.tbd) version 1.0 |
| 62 | TBD_V1 = 1U << 0, |
| 63 | |
| 64 | /// Text-based stub file (.tbd) version 2.0 |
| 65 | TBD_V2 = 1U << 1, |
| 66 | |
| 67 | /// Text-based stub file (.tbd) version 3.0 |
| 68 | TBD_V3 = 1U << 2, |
| 69 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 70 | /// Text-based stub file (.tbd) version 4.0 |
| 71 | TBD_V4 = 1U << 3, |
| 72 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 73 | All = ~0U, |
| 74 | |
| 75 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/All), |
| 76 | }; |
| 77 | |
| 78 | // clang-format on |
| 79 | |
| 80 | /// Reference to an interface file. |
| 81 | class InterfaceFileRef { |
| 82 | public: |
| 83 | InterfaceFileRef() = default; |
| 84 | |
| 85 | InterfaceFileRef(StringRef InstallName) : InstallName(InstallName) {} |
| 86 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 87 | InterfaceFileRef(StringRef InstallName, const TargetList Targets) |
| 88 | : InstallName(InstallName), Targets(std::move(Targets)) {} |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 89 | |
| 90 | StringRef getInstallName() const { return InstallName; }; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 91 | |
| 92 | void addTarget(const Target &Target); |
| 93 | template <typename RangeT> void addTargets(RangeT &&Targets) { |
| 94 | for (const auto &Target : Targets) |
| 95 | addTarget(Target(Target)); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 98 | using const_target_iterator = TargetList::const_iterator; |
| 99 | using const_target_range = llvm::iterator_range<const_target_iterator>; |
| 100 | const_target_range targets() const { return {Targets}; } |
| 101 | |
| 102 | ArchitectureSet getArchitectures() const { |
| 103 | return mapToArchitectureSet(Targets); |
| 104 | } |
| 105 | |
| 106 | PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); } |
| 107 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 108 | bool operator==(const InterfaceFileRef &O) const { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 109 | return std::tie(InstallName, Targets) == std::tie(O.InstallName, O.Targets); |
| 110 | } |
| 111 | |
| 112 | bool operator!=(const InterfaceFileRef &O) const { |
| 113 | return std::tie(InstallName, Targets) != std::tie(O.InstallName, O.Targets); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | bool operator<(const InterfaceFileRef &O) const { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 117 | return std::tie(InstallName, Targets) < std::tie(O.InstallName, O.Targets); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private: |
| 121 | std::string InstallName; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 122 | TargetList Targets; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // end namespace MachO. |
| 126 | |
| 127 | struct SymbolsMapKey { |
| 128 | MachO::SymbolKind Kind; |
| 129 | StringRef Name; |
| 130 | |
| 131 | SymbolsMapKey(MachO::SymbolKind Kind, StringRef Name) |
| 132 | : Kind(Kind), Name(Name) {} |
| 133 | }; |
| 134 | template <> struct DenseMapInfo<SymbolsMapKey> { |
| 135 | static inline SymbolsMapKey getEmptyKey() { |
| 136 | return SymbolsMapKey(MachO::SymbolKind::GlobalSymbol, StringRef{}); |
| 137 | } |
| 138 | |
| 139 | static inline SymbolsMapKey getTombstoneKey() { |
| 140 | return SymbolsMapKey(MachO::SymbolKind::ObjectiveCInstanceVariable, |
| 141 | StringRef{}); |
| 142 | } |
| 143 | |
| 144 | static unsigned getHashValue(const SymbolsMapKey &Key) { |
| 145 | return hash_combine(hash_value(Key.Kind), hash_value(Key.Name)); |
| 146 | } |
| 147 | |
| 148 | static bool isEqual(const SymbolsMapKey &LHS, const SymbolsMapKey &RHS) { |
| 149 | return std::tie(LHS.Kind, LHS.Name) == std::tie(RHS.Kind, RHS.Name); |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | namespace MachO { |
| 154 | |
| 155 | /// Defines the interface file. |
| 156 | class InterfaceFile { |
| 157 | public: |
| 158 | /// Set the path from which this file was generated (if applicable). |
| 159 | /// |
| 160 | /// \param Path_ The path to the source file. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 161 | void setPath(StringRef Path_) { Path = std::string(Path_); } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 162 | |
| 163 | /// Get the path from which this file was generated (if applicable). |
| 164 | /// |
| 165 | /// \return The path to the source file or empty. |
| 166 | StringRef getPath() const { return Path; } |
| 167 | |
| 168 | /// Set the file type. |
| 169 | /// |
| 170 | /// This is used by the YAML writer to identify the specification it should |
| 171 | /// use for writing the file. |
| 172 | /// |
| 173 | /// \param Kind The file type. |
| 174 | void setFileType(FileType Kind) { FileKind = Kind; } |
| 175 | |
| 176 | /// Get the file type. |
| 177 | /// |
| 178 | /// \return The file type. |
| 179 | FileType getFileType() const { return FileKind; } |
| 180 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 181 | /// Get the architectures. |
| 182 | /// |
| 183 | /// \return The applicable architectures. |
| 184 | ArchitectureSet getArchitectures() const { |
| 185 | return mapToArchitectureSet(Targets); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 188 | /// Get the platforms. |
| 189 | /// |
| 190 | /// \return The applicable platforms. |
| 191 | PlatformSet getPlatforms() const { return mapToPlatformSet(Targets); } |
| 192 | |
| 193 | /// Set and add target. |
| 194 | /// |
| 195 | /// \param Target the target to add into. |
| 196 | void addTarget(const Target &Target); |
| 197 | |
| 198 | /// Set and add targets. |
| 199 | /// |
| 200 | /// Add the subset of llvm::triples that is supported by Tapi |
| 201 | /// |
| 202 | /// \param Targets the collection of targets. |
| 203 | template <typename RangeT> void addTargets(RangeT &&Targets) { |
| 204 | for (const auto &Target_ : Targets) |
| 205 | addTarget(Target(Target_)); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 208 | using const_target_iterator = TargetList::const_iterator; |
| 209 | using const_target_range = llvm::iterator_range<const_target_iterator>; |
| 210 | const_target_range targets() const { return {Targets}; } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 211 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 212 | using const_filtered_target_iterator = |
| 213 | llvm::filter_iterator<const_target_iterator, |
| 214 | std::function<bool(const Target &)>>; |
| 215 | using const_filtered_target_range = |
| 216 | llvm::iterator_range<const_filtered_target_iterator>; |
| 217 | const_filtered_target_range targets(ArchitectureSet Archs) const; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 218 | |
| 219 | /// Set the install name of the library. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 220 | void setInstallName(StringRef InstallName_) { |
| 221 | InstallName = std::string(InstallName_); |
| 222 | } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 223 | |
| 224 | /// Get the install name of the library. |
| 225 | StringRef getInstallName() const { return InstallName; } |
| 226 | |
| 227 | /// Set the current version of the library. |
| 228 | void setCurrentVersion(PackedVersion Version) { CurrentVersion = Version; } |
| 229 | |
| 230 | /// Get the current version of the library. |
| 231 | PackedVersion getCurrentVersion() const { return CurrentVersion; } |
| 232 | |
| 233 | /// Set the compatibility version of the library. |
| 234 | void setCompatibilityVersion(PackedVersion Version) { |
| 235 | CompatibilityVersion = Version; |
| 236 | } |
| 237 | |
| 238 | /// Get the compatibility version of the library. |
| 239 | PackedVersion getCompatibilityVersion() const { return CompatibilityVersion; } |
| 240 | |
| 241 | /// Set the Swift ABI version of the library. |
| 242 | void setSwiftABIVersion(uint8_t Version) { SwiftABIVersion = Version; } |
| 243 | |
| 244 | /// Get the Swift ABI version of the library. |
| 245 | uint8_t getSwiftABIVersion() const { return SwiftABIVersion; } |
| 246 | |
| 247 | /// Specify if the library uses two-level namespace (or flat namespace). |
| 248 | void setTwoLevelNamespace(bool V = true) { IsTwoLevelNamespace = V; } |
| 249 | |
| 250 | /// Check if the library uses two-level namespace. |
| 251 | bool isTwoLevelNamespace() const { return IsTwoLevelNamespace; } |
| 252 | |
| 253 | /// Specify if the library is application extension safe (or not). |
| 254 | void setApplicationExtensionSafe(bool V = true) { IsAppExtensionSafe = V; } |
| 255 | |
| 256 | /// Check if the library is application extension safe. |
| 257 | bool isApplicationExtensionSafe() const { return IsAppExtensionSafe; } |
| 258 | |
| 259 | /// Set the Objective-C constraint. |
| 260 | void setObjCConstraint(ObjCConstraintType Constraint) { |
| 261 | ObjcConstraint = Constraint; |
| 262 | } |
| 263 | |
| 264 | /// Get the Objective-C constraint. |
| 265 | ObjCConstraintType getObjCConstraint() const { return ObjcConstraint; } |
| 266 | |
| 267 | /// Specify if this file was generated during InstallAPI (or not). |
| 268 | void setInstallAPI(bool V = true) { IsInstallAPI = V; } |
| 269 | |
| 270 | /// Check if this file was generated during InstallAPI. |
| 271 | bool isInstallAPI() const { return IsInstallAPI; } |
| 272 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 273 | /// Set the parent umbrella frameworks. |
| 274 | /// \param Target_ The target applicable to Parent |
| 275 | /// \param Parent The name of Parent |
| 276 | void addParentUmbrella(const Target &Target_, StringRef Parent); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 277 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 278 | /// Get the list of Parent Umbrella frameworks. |
| 279 | /// |
| 280 | /// \return Returns a list of target information and install name of parent |
| 281 | /// umbrellas. |
| 282 | const std::vector<std::pair<Target, std::string>> &umbrellas() const { |
| 283 | return ParentUmbrellas; |
| 284 | } |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 285 | |
| 286 | /// Add an allowable client. |
| 287 | /// |
| 288 | /// Mach-O Dynamic libraries have the concept of allowable clients that are |
| 289 | /// checked during static link time. The name of the application or library |
| 290 | /// that is being generated needs to match one of the allowable clients or the |
| 291 | /// linker refuses to link this library. |
| 292 | /// |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 293 | /// \param InstallName The name of the client that is allowed to link this library. |
| 294 | /// \param Target The target triple for which this applies. |
| 295 | void addAllowableClient(StringRef InstallName, const Target &Target); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 296 | |
| 297 | /// Get the list of allowable clients. |
| 298 | /// |
| 299 | /// \return Returns a list of allowable clients. |
| 300 | const std::vector<InterfaceFileRef> &allowableClients() const { |
| 301 | return AllowableClients; |
| 302 | } |
| 303 | |
| 304 | /// Add a re-exported library. |
| 305 | /// |
| 306 | /// \param InstallName The name of the library to re-export. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 307 | /// \param Target The target triple for which this applies. |
| 308 | void addReexportedLibrary(StringRef InstallName, const Target &Target); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 309 | |
| 310 | /// Get the list of re-exported libraries. |
| 311 | /// |
| 312 | /// \return Returns a list of re-exported libraries. |
| 313 | const std::vector<InterfaceFileRef> &reexportedLibraries() const { |
| 314 | return ReexportedLibraries; |
| 315 | } |
| 316 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 317 | /// Add an Target/UUID pair. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 318 | /// |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 319 | /// \param Target The target triple for which this applies. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 320 | /// \param UUID The UUID of the library for the specified architecture. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 321 | void addUUID(const Target &Target, StringRef UUID); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 322 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 323 | /// Add an Target/UUID pair. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 324 | /// |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 325 | /// \param Target The target triple for which this applies. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 326 | /// \param UUID The UUID of the library for the specified architecture. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 327 | void addUUID(const Target &Target, uint8_t UUID[16]); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 328 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 329 | /// Get the list of Target/UUID pairs. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 330 | /// |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 331 | /// \return Returns a list of Target/UUID pairs. |
| 332 | const std::vector<std::pair<Target, std::string>> &uuids() const { |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 333 | return UUIDs; |
| 334 | } |
| 335 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 336 | /// Add a library for inlining to top level library. |
| 337 | /// |
| 338 | ///\param Document The library to inline with top level library. |
| 339 | void addDocument(std::shared_ptr<InterfaceFile> &&Document) { |
| 340 | Documents.emplace_back(std::move(Document)); |
| 341 | } |
| 342 | |
| 343 | /// Get the list of inlined libraries. |
| 344 | /// |
| 345 | /// \return Returns a list of the inlined frameworks. |
| 346 | const std::vector<std::shared_ptr<InterfaceFile>> &documents() const { |
| 347 | return Documents; |
| 348 | } |
| 349 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 350 | /// Add a symbol to the symbols list or extend an existing one. |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 351 | void addSymbol(SymbolKind Kind, StringRef Name, const TargetList &Targets, |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 352 | SymbolFlags Flags = SymbolFlags::None); |
| 353 | |
| 354 | using SymbolMapType = DenseMap<SymbolsMapKey, Symbol *>; |
| 355 | struct const_symbol_iterator |
| 356 | : public iterator_adaptor_base< |
| 357 | const_symbol_iterator, SymbolMapType::const_iterator, |
| 358 | std::forward_iterator_tag, const Symbol *, ptrdiff_t, |
| 359 | const Symbol *, const Symbol *> { |
| 360 | const_symbol_iterator() = default; |
| 361 | |
| 362 | template <typename U> |
| 363 | const_symbol_iterator(U &&u) |
| 364 | : iterator_adaptor_base(std::forward<U &&>(u)) {} |
| 365 | |
| 366 | reference operator*() const { return I->second; } |
| 367 | pointer operator->() const { return I->second; } |
| 368 | }; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 369 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 370 | using const_symbol_range = iterator_range<const_symbol_iterator>; |
| 371 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 372 | using const_filtered_symbol_iterator = |
| 373 | filter_iterator<const_symbol_iterator, |
| 374 | std::function<bool(const Symbol *)>>; |
| 375 | using const_filtered_symbol_range = |
| 376 | iterator_range<const_filtered_symbol_iterator>; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 377 | |
| 378 | const_symbol_range symbols() const { |
| 379 | return {Symbols.begin(), Symbols.end()}; |
| 380 | } |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 381 | |
| 382 | const_filtered_symbol_range exports() const { |
| 383 | std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) { |
| 384 | return !Symbol->isUndefined(); |
| 385 | }; |
| 386 | return make_filter_range( |
| 387 | make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}), |
| 388 | fn); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 389 | } |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 390 | |
| 391 | const_filtered_symbol_range undefineds() const { |
| 392 | std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) { |
| 393 | return Symbol->isUndefined(); |
| 394 | }; |
| 395 | return make_filter_range( |
| 396 | make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}), |
| 397 | fn); |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | private: |
| 401 | llvm::BumpPtrAllocator Allocator; |
| 402 | StringRef copyString(StringRef String) { |
| 403 | if (String.empty()) |
| 404 | return {}; |
| 405 | |
| 406 | void *Ptr = Allocator.Allocate(String.size(), 1); |
| 407 | memcpy(Ptr, String.data(), String.size()); |
| 408 | return StringRef(reinterpret_cast<const char *>(Ptr), String.size()); |
| 409 | } |
| 410 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 411 | TargetList Targets; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 412 | std::string Path; |
| 413 | FileType FileKind; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 414 | std::string InstallName; |
| 415 | PackedVersion CurrentVersion; |
| 416 | PackedVersion CompatibilityVersion; |
| 417 | uint8_t SwiftABIVersion{0}; |
| 418 | bool IsTwoLevelNamespace{false}; |
| 419 | bool IsAppExtensionSafe{false}; |
| 420 | bool IsInstallAPI{false}; |
| 421 | ObjCConstraintType ObjcConstraint = ObjCConstraintType::None; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 422 | std::vector<std::pair<Target, std::string>> ParentUmbrellas; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 423 | std::vector<InterfaceFileRef> AllowableClients; |
| 424 | std::vector<InterfaceFileRef> ReexportedLibraries; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 425 | std::vector<std::shared_ptr<InterfaceFile>> Documents; |
| 426 | std::vector<std::pair<Target, std::string>> UUIDs; |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 427 | SymbolMapType Symbols; |
| 428 | }; |
| 429 | |
| 430 | } // end namespace MachO. |
| 431 | } // end namespace llvm. |
| 432 | |
| 433 | #endif // LLVM_TEXTAPI_MACHO_INTERFACE_FILE_H |