LLVM 19.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"
20#include "llvm/TextAPI/Symbol.h"
21#include <string>
22
23namespace llvm {
24namespace MachO {
25
27
28class RecordsSlice;
29
30// Defines lightweight source location for records.
31struct RecordLoc {
32 RecordLoc() = default;
33 RecordLoc(std::string File, unsigned Line)
34 : File(std::move(File)), Line(Line) {}
35
36 /// Whether there is source location tied to the RecordLoc object.
37 bool isValid() const { return !File.empty(); }
38
39 bool operator==(const RecordLoc &O) const {
40 return std::tie(File, Line) == std::tie(O.File, O.Line);
41 }
42
43 const std::string File;
44 const unsigned Line = 0;
45};
46
47// Defines a list of linkage types.
48enum class RecordLinkage : uint8_t {
49 // Unknown linkage.
50 Unknown = 0,
51
52 // Local, hidden or private extern linkage.
53 Internal = 1,
54
55 // Undefined linkage, it represents usage of external interface.
56 Undefined = 2,
57
58 // Re-exported linkage, record is defined in external interface.
59 Rexported = 3,
60
61 // Exported linkage.
62 Exported = 4,
63};
64
65/// Define Record. They represent API's in binaries that could be linkable
66/// symbols.
67class Record {
68public:
69 Record() = default;
71 : Name(Name), Linkage(Linkage), Flags(mergeFlags(Flags, Linkage)),
72 Verified(false) {}
73
74 bool isWeakDefined() const {
76 }
77
78 bool isWeakReferenced() const {
80 }
81
82 bool isThreadLocalValue() const {
85 }
86
87 bool isData() const {
89 }
90
91 bool isText() const {
93 }
94
95 bool isInternal() const { return Linkage == RecordLinkage::Internal; }
96 bool isUndefined() const { return Linkage == RecordLinkage::Undefined; }
97 bool isExported() const { return Linkage >= RecordLinkage::Rexported; }
98 bool isRexported() const { return Linkage == RecordLinkage::Rexported; }
99
100 bool isVerified() const { return Verified; }
101 void setVerify(bool V = true) { Verified = V; }
102
103 StringRef getName() const { return Name; }
104 SymbolFlags getFlags() const { return Flags; }
105
106private:
108
109protected:
114
115 friend class RecordsSlice;
116};
117
118// Defines broadly non-objc records, categorized as variables or functions.
119class GlobalRecord : public Record {
120public:
121 enum class Kind : uint8_t {
122 Unknown = 0,
123 Variable = 1,
124 Function = 2,
125 };
126
128 Kind GV, bool Inlined)
129 : Record({Name, Linkage, Flags}), GV(GV), Inlined(Inlined) {}
130
131 bool isFunction() const { return GV == Kind::Function; }
132 bool isVariable() const { return GV == Kind::Variable; }
133 void setKind(const Kind &V) {
134 if (GV == Kind::Unknown)
135 GV = V;
136 }
137 bool isInlined() const { return Inlined; }
138
139private:
140 Kind GV;
141 bool Inlined = false;
142};
143
144// Define Objective-C instance variable records.
145class ObjCIVarRecord : public Record {
146public:
149
150 static std::string createScopedName(StringRef SuperClass, StringRef IVar) {
151 return (SuperClass + "." + IVar).str();
152 }
153};
154
155template <typename V, typename K = StringRef,
156 typename std::enable_if<std::is_base_of<Record, V>::value>::type * =
157 nullptr>
159
160// Defines Objective-C record types that have assigned methods, properties,
161// instance variable (ivars) and protocols.
163public:
166
167 ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
168 ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
169 std::vector<ObjCIVarRecord *> getObjCIVars() const;
170 RecordLinkage getLinkage() const { return Linkage; }
171
172private:
174};
175
176// Define Objective-C category types. They don't generate linkable symbols, but
177// they have assigned ivars that do.
179public:
182 ClassToExtend(ClassToExtend) {}
183
184 StringRef getSuperClassName() const { return ClassToExtend; }
185
186private:
187 StringRef ClassToExtend;
188};
189
190// Define Objective-C Interfaces or class types.
192public:
194 ObjCIFSymbolKind SymType)
197 }
198
200 return Linkages.EHType != RecordLinkage::Unknown;
201 }
202 bool isCompleteInterface() const {
203 return Linkages.Class >= RecordLinkage::Rexported &&
204 Linkages.MetaClass >= RecordLinkage::Rexported;
205 }
206 bool isExportedSymbol(ObjCIFSymbolKind CurrType) const {
208 }
209
212
214 std::vector<ObjCCategoryRecord *> getObjCCategories() const;
215
216private:
217 /// Linkage level for each symbol represented in ObjCInterfaceRecord.
218 struct Linkages {
222 bool operator==(const Linkages &other) const {
223 return std::tie(Class, MetaClass, EHType) ==
224 std::tie(other.Class, other.MetaClass, other.EHType);
225 }
226 bool operator!=(const Linkages &other) const { return !(*this == other); }
227 };
228 Linkages Linkages;
229
230 // Non-owning containers of categories that extend the class.
232};
233
234} // end namespace MachO.
235} // end namespace llvm.
236
237#endif // LLVM_TEXTAPI_RECORD_H
This file implements a map that provides insertion order iteration.
GlobalRecord(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags, Kind GV, bool Inlined)
Definition: Record.h:127
void setKind(const Kind &V)
Definition: Record.h:133
bool isFunction() const
Definition: Record.h:131
bool isInlined() const
Definition: Record.h:137
bool isVariable() const
Definition: Record.h:132
ObjCCategoryRecord(StringRef ClassToExtend, StringRef Name)
Definition: Record.h:180
StringRef getSuperClassName() const
Definition: Record.h:184
ObjCIVarRecord * addObjCIVar(StringRef IVar, RecordLinkage Linkage)
ObjCIVarRecord * findObjCIVar(StringRef IVar) const
ObjCContainerRecord(StringRef Name, RecordLinkage Linkage)
Definition: Record.h:164
RecordLinkage getLinkage() const
Definition: Record.h:170
std::vector< ObjCIVarRecord * > getObjCIVars() const
ObjCIVarRecord(StringRef Name, RecordLinkage Linkage)
Definition: Record.h:147
static std::string createScopedName(StringRef SuperClass, StringRef IVar)
Definition: Record.h:150
RecordLinkage getLinkageForSymbol(ObjCIFSymbolKind CurrType) const
ObjCInterfaceRecord(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType)
Definition: Record.h:193
std::vector< ObjCCategoryRecord * > getObjCCategories() const
bool addObjCCategory(ObjCCategoryRecord *Record)
void updateLinkageForSymbols(ObjCIFSymbolKind SymType, RecordLinkage Link)
bool isCompleteInterface() const
Definition: Record.h:202
bool isExportedSymbol(ObjCIFSymbolKind CurrType) const
Definition: Record.h:206
bool hasExceptionAttribute() const
Definition: Record.h:199
Define Record.
Definition: Record.h:67
bool isUndefined() const
Definition: Record.h:96
bool isInternal() const
Definition: Record.h:95
StringRef getName() const
Definition: Record.h:103
bool isThreadLocalValue() const
Definition: Record.h:82
Record(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags)
Definition: Record.h:70
SymbolFlags getFlags() const
Definition: Record.h:104
bool isVerified() const
Definition: Record.h:100
bool isWeakDefined() const
Definition: Record.h:74
bool isData() const
Definition: Record.h:87
bool isRexported() const
Definition: Record.h:98
RecordLinkage Linkage
Definition: Record.h:111
bool isExported() const
Definition: Record.h:97
void setVerify(bool V=true)
Definition: Record.h:101
StringRef Name
Definition: Record.h:110
bool isWeakReferenced() const
Definition: Record.h:78
SymbolFlags Flags
Definition: Record.h:112
bool isText() const
Definition: Record.h:91
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:50
RecordLinkage
Definition: Record.h:48
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition: Symbol.h:69
@ EHType
Is OBJC_EHTYPE* symbol.
@ MetaClass
Is OBJC_METACLASS* symbol.
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2043
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
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:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
bool operator==(const RecordLoc &O) const
Definition: Record.h:39
const std::string File
Definition: Record.h:43
const unsigned Line
Definition: Record.h:44
bool isValid() const
Whether there is source location tied to the RecordLoc object.
Definition: Record.h:37
RecordLoc(std::string File, unsigned Line)
Definition: Record.h:33