1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//===- llvm/TextAPI/Record.h - TAPI Record ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Implements the TAPI Record Types.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_TEXTAPI_RECORD_H
#define LLVM_TEXTAPI_RECORD_H
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/TextAPI/Symbol.h"
#include <string>
namespace llvm {
namespace MachO {
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
class RecordsSlice;
// Defines a list of linkage types.
enum class RecordLinkage : uint8_t {
// Unknown linkage.
Unknown = 0,
// Local, hidden or private extern linkage.
Internal = 1,
// Undefined linkage, it represents usage of external interface.
Undefined = 2,
// Re-exported linkage, record is defined in external interface.
Rexported = 3,
// Exported linkage.
Exported = 4,
};
/// Define Record. They represent API's in binaries that could be linkable
/// symbols.
class Record {
public:
Record() = default;
Record(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags)
: Name(Name), Linkage(Linkage), Flags(mergeFlags(Flags, Linkage)) {}
bool isWeakDefined() const {
return (Flags & SymbolFlags::WeakDefined) == SymbolFlags::WeakDefined;
}
bool isWeakReferenced() const {
return (Flags & SymbolFlags::WeakReferenced) == SymbolFlags::WeakReferenced;
}
bool isThreadLocalValue() const {
return (Flags & SymbolFlags::ThreadLocalValue) ==
SymbolFlags::ThreadLocalValue;
}
bool isData() const {
return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
}
bool isText() const {
return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
}
bool isInternal() const { return Linkage == RecordLinkage::Internal; }
bool isUndefined() const { return Linkage == RecordLinkage::Undefined; }
bool isExported() const { return Linkage >= RecordLinkage::Rexported; }
bool isRexported() const { return Linkage == RecordLinkage::Rexported; }
StringRef getName() const { return Name; }
SymbolFlags getFlags() const { return Flags; }
private:
SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage);
protected:
StringRef Name;
RecordLinkage Linkage;
SymbolFlags Flags;
friend class RecordsSlice;
};
// Defines broadly non-objc records, categorized as variables or functions.
class GlobalRecord : public Record {
public:
enum class Kind : uint8_t {
Unknown = 0,
Variable = 1,
Function = 2,
};
GlobalRecord(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags,
Kind GV)
: Record({Name, Linkage, Flags}), GV(GV) {}
bool isFunction() const { return GV == Kind::Function; }
bool isVariable() const { return GV == Kind::Variable; }
void setKind(const Kind &V) {
if (GV == Kind::Unknown)
GV = V;
}
private:
Kind GV;
};
// Define Objective-C instance variable records.
class ObjCIVarRecord : public Record {
public:
ObjCIVarRecord(StringRef Name, RecordLinkage Linkage)
: Record({Name, Linkage, SymbolFlags::Data}) {}
static std::string createScopedName(StringRef SuperClass, StringRef IVar) {
return (SuperClass + "." + IVar).str();
}
};
template <typename V, typename K = StringRef,
typename std::enable_if<std::is_base_of<Record, V>::value>::type * =
nullptr>
using RecordMap = llvm::MapVector<K, std::unique_ptr<V>>;
// Defines Objective-C record types that have assigned methods, properties,
// instance variable (ivars) and protocols.
class ObjCContainerRecord : public Record {
public:
ObjCContainerRecord(StringRef Name, RecordLinkage Linkage)
: Record({Name, Linkage, SymbolFlags::Data}) {}
ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage);
ObjCIVarRecord *findObjCIVar(StringRef IVar) const;
std::vector<ObjCIVarRecord *> getObjCIVars() const;
private:
RecordMap<ObjCIVarRecord> IVars;
};
// Define Objective-C category types. They don't generate linkable symbols, but
// they have assigned ivars that do.
class ObjCCategoryRecord : public ObjCContainerRecord {
public:
ObjCCategoryRecord(StringRef ClassToExtend, StringRef Name)
: ObjCContainerRecord(Name, RecordLinkage::Unknown),
ClassToExtend(ClassToExtend) {}
private:
StringRef ClassToExtend;
};
// Define Objective-C Interfaces or class types.
class ObjCInterfaceRecord : public ObjCContainerRecord {
public:
ObjCInterfaceRecord(StringRef Name, RecordLinkage Linkage,
bool HasEHType = false)
: ObjCContainerRecord(Name, Linkage), HasEHType(HasEHType) {}
bool hasExceptionAttribute() const { return HasEHType; }
bool addObjCCategory(ObjCCategoryRecord *Record);
std::vector<ObjCCategoryRecord *> getObjCCategories() const;
private:
bool HasEHType;
// Non-owning containers of categories that extend the class.
llvm::MapVector<StringRef, ObjCCategoryRecord *> Categories;
};
} // end namespace MachO.
} // end namespace llvm.
#endif // LLVM_TEXTAPI_RECORD_H
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|