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