LLVM 22.0.0git
Record.h
Go to the documentation of this file.
1//===- llvm/TextAPI/Record.h - TAPI Record ----------------------*- 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 Types.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TEXTAPI_RECORD_H
15#define LLVM_TEXTAPI_RECORD_H
16
17#include "llvm/ADT/MapVector.h"
18#include "llvm/ADT/StringRef.h"
21#include "llvm/TextAPI/Symbol.h"
22#include <string>
23
24namespace llvm {
25namespace MachO {
26
28
29class RecordsSlice;
30
31// Defines lightweight source location for records.
32struct RecordLoc {
33 RecordLoc() = default;
34 RecordLoc(std::string File, unsigned Line)
35 : File(std::move(File)), Line(Line) {}
36
37 /// Whether there is source location tied to the RecordLoc object.
38 bool isValid() const { return !File.empty(); }
39
40 bool operator==(const RecordLoc &O) const {
41 return std::tie(File, Line) == std::tie(O.File, O.Line);
42 }
43
44 const std::string File;
45 const unsigned Line = 0;
46};
47
48// Defines a list of linkage types.
49enum class RecordLinkage : uint8_t {
50 // Unknown linkage.
52
53 // Local, hidden or private extern linkage.
55
56 // Undefined linkage, it represents usage of external interface.
58
59 // Re-exported linkage, record is defined in external interface.
61
62 // Exported linkage.
64};
65
66/// Define Record. They represent API's in binaries that could be linkable
67/// symbols.
68class Record {
69public:
70 Record() = default;
74
78
82
87
88 bool isData() const {
90 }
91
92 bool isText() const {
94 }
95
96 bool isInternal() const { return Linkage == RecordLinkage::Internal; }
97 bool isUndefined() const { return Linkage == RecordLinkage::Undefined; }
98 bool isExported() const { return Linkage >= RecordLinkage::Rexported; }
99 bool isRexported() const { return Linkage == RecordLinkage::Rexported; }
100
101 bool isVerified() const { return Verified; }
102 void setVerify(bool V = true) { Verified = V; }
103
104 StringRef getName() const { return Name; }
105 SymbolFlags getFlags() const { return Flags; }
106
107private:
109
110protected:
115
116 friend class RecordsSlice;
117};
118
119// Defines broadly non-objc records, categorized as variables or functions.
120class GlobalRecord : public Record {
121public:
122 enum class Kind : uint8_t {
126 };
127
129 Kind GV, bool Inlined)
130 : Record({Name, Linkage, Flags}), GV(GV), Inlined(Inlined) {}
131
132 bool isFunction() const { return GV == Kind::Function; }
133 bool isVariable() const { return GV == Kind::Variable; }
134 void setKind(const Kind &V) {
135 if (GV == Kind::Unknown)
136 GV = V;
137 }
138 bool isInlined() const { return Inlined; }
139
140private:
141 Kind GV;
142 bool Inlined = false;
143};
144
145// Define Objective-C instance variable records.
146class ObjCIVarRecord : public Record {
147public:
150
151 static std::string createScopedName(StringRef SuperClass, StringRef IVar) {
152 return (SuperClass + "." + IVar).str();
153 }
154};
155
156template <typename V, typename K = StringRef,
157 typename std::enable_if<std::is_base_of<Record, V>::value>::type * =
158 nullptr>
160
161// Defines Objective-C record types that have assigned methods, properties,
162// instance variable (ivars) and protocols.
164public:
167
168 LLVM_ABI ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
169 LLVM_ABI ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
170 LLVM_ABI std::vector<ObjCIVarRecord *> getObjCIVars() const;
171 RecordLinkage getLinkage() const { return Linkage; }
172
173private:
175};
176
177// Define Objective-C category types. They don't generate linkable symbols, but
178// they have assigned ivars that do.
180public:
183 ClassToExtend(ClassToExtend) {}
184
185 StringRef getSuperClassName() const { return ClassToExtend; }
186
187private:
188 StringRef ClassToExtend;
189};
190
191// Define Objective-C Interfaces or class types.
193public:
199
201 return Linkages.EHType != RecordLinkage::Unknown;
202 }
203 bool isCompleteInterface() const {
204 return Linkages.Class >= RecordLinkage::Rexported &&
205 Linkages.MetaClass >= RecordLinkage::Rexported;
206 }
207 bool isExportedSymbol(ObjCIFSymbolKind CurrType) const {
209 }
210
213 RecordLinkage Link);
214
216 LLVM_ABI std::vector<ObjCCategoryRecord *> getObjCCategories() const;
217
218private:
219 /// Linkage level for each symbol represented in ObjCInterfaceRecord.
220 struct Linkages {
224 bool operator==(const Linkages &other) const {
225 return std::tie(Class, MetaClass, EHType) ==
226 std::tie(other.Class, other.MetaClass, other.EHType);
227 }
228 bool operator!=(const Linkages &other) const { return !(*this == other); }
229 };
230 Linkages Linkages;
231
232 // Non-owning containers of categories that extend the class.
233 llvm::MapVector<StringRef, ObjCCategoryRecord *> Categories;
234};
235
236} // end namespace MachO.
237} // end namespace llvm.
238
239#endif // LLVM_TEXTAPI_RECORD_H
#define LLVM_ABI
Definition Compiler.h:213
DXIL Finalize Linkage
This file implements a map that provides insertion order iteration.
GlobalRecord(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags, Kind GV, bool Inlined)
Definition Record.h:128
void setKind(const Kind &V)
Definition Record.h:134
bool isFunction() const
Definition Record.h:132
bool isInlined() const
Definition Record.h:138
bool isVariable() const
Definition Record.h:133
ObjCCategoryRecord(StringRef ClassToExtend, StringRef Name)
Definition Record.h:181
StringRef getSuperClassName() const
Definition Record.h:185
LLVM_ABI ObjCIVarRecord * addObjCIVar(StringRef IVar, RecordLinkage Linkage)
LLVM_ABI ObjCIVarRecord * findObjCIVar(StringRef IVar) const
ObjCContainerRecord(StringRef Name, RecordLinkage Linkage)
Definition Record.h:165
RecordLinkage getLinkage() const
Definition Record.h:171
LLVM_ABI std::vector< ObjCIVarRecord * > getObjCIVars() const
ObjCIVarRecord(StringRef Name, RecordLinkage Linkage)
Definition Record.h:148
static std::string createScopedName(StringRef SuperClass, StringRef IVar)
Definition Record.h:151
LLVM_ABI RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const
ObjCInterfaceRecord(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType)
Definition Record.h:194
LLVM_ABI std::vector< ObjCCategoryRecord * > getObjCCategories() const
LLVM_ABI bool addObjCCategory(ObjCCategoryRecord *Record)
LLVM_ABI void updateLinkageForSymbols(ObjCIFSymbolKind SymType, RecordLinkage Link)
bool isExportedSymbol(ObjCIFSymbolKind CurrType) const
Definition Record.h:207
bool hasExceptionAttribute() const
Definition Record.h:200
Define Record.
Definition Record.h:68
bool isUndefined() const
Definition Record.h:97
bool isInternal() const
Definition Record.h:96
StringRef getName() const
Definition Record.h:104
bool isThreadLocalValue() const
Definition Record.h:83
Record(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags)
Definition Record.h:71
SymbolFlags getFlags() const
Definition Record.h:105
bool isVerified() const
Definition Record.h:101
bool isWeakDefined() const
Definition Record.h:75
bool isData() const
Definition Record.h:88
friend class RecordsSlice
Definition Record.h:116
bool isRexported() const
Definition Record.h:99
RecordLinkage Linkage
Definition Record.h:112
bool isExported() const
Definition Record.h:98
void setVerify(bool V=true)
Definition Record.h:102
StringRef Name
Definition Record.h:111
bool isWeakReferenced() const
Definition Record.h:79
SymbolFlags Flags
Definition Record.h:113
bool isText() const
Definition Record.h:92
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:36
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool operator==(const Target &LHS, const Target &RHS)
Definition Target.h:48
llvm::MapVector< K, std::unique_ptr< V > > RecordMap
Definition Record.h:159
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition Symbol.h:70
@ EHType
Is OBJC_EHTYPE* symbol.
Definition Symbol.h:77
@ Class
Is OBJC_CLASS* symbol.
Definition Symbol.h:73
@ MetaClass
Is OBJC_METACLASS* symbol.
Definition Symbol.h:75
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
SymbolFlags
Symbol flags.
Definition Symbol.h:25
@ ThreadLocalValue
Thread-local value symbol.
Definition Symbol.h:30
@ WeakReferenced
Weak referenced symbol.
Definition Symbol.h:36
@ WeakDefined
Weak defined symbol.
Definition Symbol.h:33
@ Text
Text Segment.
Definition Symbol.h:48
@ Data
Data Segment.
Definition Symbol.h:45
This is an optimization pass for GlobalISel generic memory operations.
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2113
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1847
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
bool operator==(const RecordLoc &O) const
Definition Record.h:40
const std::string File
Definition Record.h:44
const unsigned Line
Definition Record.h:45
bool isValid() const
Whether there is source location tied to the RecordLoc object.
Definition Record.h:38
RecordLoc(std::string File, unsigned Line)
Definition Record.h:34