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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
//===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the C++ Decl subclasses.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_DECLCXX_H
#define LLVM_CLANG_AST_DECLCXX_H
#include "clang/AST/Decl.h"
#include "llvm/ADT/SmallVector.h"
namespace clang {
class CXXRecordDecl;
/// CXXFieldDecl - Represents an instance field of a C++ struct/union/class.
class CXXFieldDecl : public FieldDecl {
CXXRecordDecl *Parent;
CXXFieldDecl(CXXRecordDecl *RD, SourceLocation L, IdentifierInfo *Id,
QualType T, Expr *BW = NULL)
: FieldDecl(CXXField, L, Id, T, BW), Parent(RD) {}
public:
static CXXFieldDecl *Create(ASTContext &C, CXXRecordDecl *RD,SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *BW = NULL);
void setAccess(AccessSpecifier AS) { Access = AS; }
AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
CXXRecordDecl *getParent() const { return Parent; }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == CXXField; }
static bool classof(const CXXFieldDecl *D) { return true; }
};
/// CXXRecordDecl - Represents a C++ struct/union/class.
/// The only difference with RecordDecl is that CXXRecordDecl is a DeclContext.
class CXXRecordDecl : public RecordDecl, public DeclContext {
CXXRecordDecl(TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id)
: RecordDecl(CXXRecord, TK, DC, L, Id), DeclContext(CXXRecord) {}
public:
static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
CXXRecordDecl* PrevDecl=0);
const CXXFieldDecl *getMember(unsigned i) const {
return cast<const CXXFieldDecl>(RecordDecl::getMember(i));
}
CXXFieldDecl *getMember(unsigned i) {
return cast<CXXFieldDecl>(RecordDecl::getMember(i));
}
/// getMember - If the member doesn't exist, or there are no members, this
/// function will return 0;
CXXFieldDecl *getMember(IdentifierInfo *name) {
return cast_or_null<CXXFieldDecl>(RecordDecl::getMember(name));
}
static bool classof(const Decl *D) { return D->getKind() == CXXRecord; }
static bool classof(const CXXRecordDecl *D) { return true; }
static DeclContext *castToDeclContext(const CXXRecordDecl *D) {
return static_cast<DeclContext *>(const_cast<CXXRecordDecl*>(D));
}
static CXXRecordDecl *castFromDeclContext(const DeclContext *DC) {
return static_cast<CXXRecordDecl *>(const_cast<DeclContext*>(DC));
}
protected:
/// EmitImpl - Serialize this CXXRecordDecl. Called by Decl::Emit.
// FIXME: Implement this.
//virtual void EmitImpl(llvm::Serializer& S) const;
/// CreateImpl - Deserialize a CXXRecordDecl. Called by Decl::Create.
// FIXME: Implement this.
static CXXRecordDecl* CreateImpl(Kind DK, llvm::Deserializer& D, ASTContext& C);
friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
};
/// CXXMethodDecl - Represents a static or instance method of a
/// struct/union/class.
class CXXMethodDecl : public FunctionDecl {
CXXMethodDecl(CXXRecordDecl *RD, SourceLocation L,
IdentifierInfo *Id, QualType T,
bool isStatic, bool isInline, ScopedDecl *PrevDecl)
: FunctionDecl(CXXMethod, RD, L, Id, T, (isStatic ? Static : None),
isInline, PrevDecl) {}
public:
static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, IdentifierInfo *Id,
QualType T, bool isStatic = false,
bool isInline = false, ScopedDecl *PrevDecl = 0);
bool isStatic() const { return getStorageClass() == Static; }
bool isInstance() const { return !isStatic(); }
void setAccess(AccessSpecifier AS) { Access = AS; }
AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
/// getThisType - Returns the type of 'this' pointer.
/// Should only be called for instance methods.
QualType getThisType(ASTContext &C) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == CXXMethod; }
static bool classof(const CXXMethodDecl *D) { return true; }
protected:
/// EmitImpl - Serialize this CXXMethodDecl. Called by Decl::Emit.
// FIXME: Implement this.
//virtual void EmitImpl(llvm::Serializer& S) const;
/// CreateImpl - Deserialize a CXXMethodDecl. Called by Decl::Create.
// FIXME: Implement this.
static CXXMethodDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
};
/// CXXClassVarDecl - Represents a static data member of a struct/union/class.
class CXXClassVarDecl : public VarDecl {
CXXClassVarDecl(CXXRecordDecl *RD, SourceLocation L,
IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl)
: VarDecl(CXXClassVar, RD, L, Id, T, None, PrevDecl) {}
public:
static CXXClassVarDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L,IdentifierInfo *Id,
QualType T, ScopedDecl *PrevDecl);
void setAccess(AccessSpecifier AS) { Access = AS; }
AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == CXXClassVar; }
static bool classof(const CXXClassVarDecl *D) { return true; }
protected:
/// EmitImpl - Serialize this CXXClassVarDecl. Called by Decl::Emit.
// FIXME: Implement this.
//virtual void EmitImpl(llvm::Serializer& S) const;
/// CreateImpl - Deserialize a CXXClassVarDecl. Called by Decl::Create.
// FIXME: Implement this.
static CXXClassVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
};
/// CXXClassMemberWrapper - A wrapper class for C++ class member decls.
/// Common functions like set/getAccess are included here to avoid bloating
/// the interface of non-C++ specific decl classes, like NamedDecl.
class CXXClassMemberWrapper {
Decl *MD;
public:
CXXClassMemberWrapper(Decl *D) : MD(D) {
assert(isMember(D) && "Not a C++ class member!");
}
AccessSpecifier getAccess() const {
return AccessSpecifier(MD->Access);
}
void setAccess(AccessSpecifier AS) {
assert(AS != AS_none && "Access must be specified.");
MD->Access = AS;
}
CXXRecordDecl *getParent() const {
if (ScopedDecl *SD = dyn_cast<ScopedDecl>(MD)) {
return cast<CXXRecordDecl>(SD->getDeclContext());
}
return cast<CXXFieldDecl>(MD)->getParent();
}
static bool isMember(Decl *D) {
if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
return isa<CXXRecordDecl>(SD->getDeclContext());
}
return isa<CXXFieldDecl>(D);
}
};
/// OverloadedFunctionDecl - An instance of this class represents a
/// set of overloaded functions. All of the functions have the same
/// name and occur within the same scope.
///
/// An OverloadedFunctionDecl has no ownership over the FunctionDecl
/// nodes it contains. Rather, the FunctionDecls are owned by the
/// enclosing scope (which also owns the OverloadedFunctionDecl
/// node). OverloadedFunctionDecl is used primarily to store a set of
/// overloaded functions for name lookup.
class OverloadedFunctionDecl : public NamedDecl {
protected:
OverloadedFunctionDecl(DeclContext *DC, IdentifierInfo *Id)
: NamedDecl(OverloadedFunction, SourceLocation(), Id) { }
/// Functions - the set of overloaded functions contained in this
/// overload set.
llvm::SmallVector<FunctionDecl *, 4> Functions;
public:
typedef llvm::SmallVector<FunctionDecl *, 4>::iterator function_iterator;
typedef llvm::SmallVector<FunctionDecl *, 4>::const_iterator
function_const_iterator;
static OverloadedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
IdentifierInfo *Id);
/// addOverload - Add an overloaded function FD to this set of
/// overloaded functions.
void addOverload(FunctionDecl *FD) {
assert((!getNumFunctions() || (FD->getDeclContext() ==
|