1 | //===- lib/TextAPI/SymbolSet.cpp - TAPI Symbol Set ------------*- 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 | #include "llvm/TextAPI/SymbolSet.h" |
10 | |
11 | using namespace llvm; |
12 | using namespace llvm::MachO; |
13 | |
14 | Symbol *SymbolSet::addGlobalImpl(EncodeKind Kind, StringRef Name, |
15 | SymbolFlags Flags) { |
16 | Name = copyString(String: Name); |
17 | auto Result = Symbols.try_emplace(Key: SymbolsMapKey{Kind, Name}, Args: nullptr); |
18 | if (Result.second) |
19 | Result.first->second = |
20 | new (Allocator) Symbol{Kind, Name, TargetList(), Flags}; |
21 | return Result.first->second; |
22 | } |
23 | |
24 | Symbol *SymbolSet::addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags, |
25 | const Target &Targ) { |
26 | auto *Sym = addGlobalImpl(Kind, Name, Flags); |
27 | Sym->addTarget(InputTarget: Targ); |
28 | return Sym; |
29 | } |
30 | |
31 | const Symbol *SymbolSet::findSymbol(EncodeKind Kind, StringRef Name, |
32 | ObjCIFSymbolKind ObjCIF) const { |
33 | if (auto result = Symbols.lookup(Val: {Kind, Name})) |
34 | return result; |
35 | if ((ObjCIF == ObjCIFSymbolKind::None) || (ObjCIF > ObjCIFSymbolKind::EHType)) |
36 | return nullptr; |
37 | assert(ObjCIF <= ObjCIFSymbolKind::EHType && |
38 | "expected single ObjCIFSymbolKind enum value" ); |
39 | // Non-complete ObjC Interfaces are represented as global symbols. |
40 | if (ObjCIF == ObjCIFSymbolKind::Class) |
41 | return Symbols.lookup( |
42 | Val: {EncodeKind::GlobalSymbol, (ObjC2ClassNamePrefix + Name).str()}); |
43 | if (ObjCIF == ObjCIFSymbolKind::MetaClass) |
44 | return Symbols.lookup( |
45 | Val: {EncodeKind::GlobalSymbol, (ObjC2MetaClassNamePrefix + Name).str()}); |
46 | return Symbols.lookup( |
47 | Val: {EncodeKind::GlobalSymbol, (ObjC2EHTypePrefix + Name).str()}); |
48 | } |
49 | |