blob: 79c51aca3159f192c2c3b2d876a98eee6b57cb13 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
Argiris Kirtzidise7dfca12008-06-04 13:04:04 +000010// This file implements the Decl subclasses.
Chris Lattner4b009652007-07-25 00:24:17 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
Douglas Gregor7a7be652009-02-03 19:21:40 +000015#include "clang/AST/DeclCXX.h"
Steve Naroffd85ba922009-02-22 19:35:57 +000016#include "clang/AST/DeclObjC.h"
Chris Lattnere4650482008-03-15 06:12:44 +000017#include "clang/AST/ASTContext.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000018#include "clang/AST/Stmt.h"
Nuno Lopesc98406e2008-12-17 23:39:55 +000019#include "clang/AST/Expr.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000020#include "clang/Basic/IdentifierTable.h"
Douglas Gregor09be81b2009-02-04 17:27:36 +000021#include <vector>
Ted Kremenekafdf8112008-05-20 00:43:19 +000022
Chris Lattner4b009652007-07-25 00:24:17 +000023using namespace clang;
24
Chris Lattnera8344c32008-03-15 05:43:15 +000025//===----------------------------------------------------------------------===//
Chris Lattnere4650482008-03-15 06:12:44 +000026// Decl Allocation/Deallocation Method Implementations
27//===----------------------------------------------------------------------===//
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +000028
Argiris Kirtzidisd3586002008-04-17 14:40:12 +000029TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
Steve Naroff5abb0282009-01-27 21:25:57 +000030 return new (C) TranslationUnitDecl();
Argiris Kirtzidisd3586002008-04-17 14:40:12 +000031}
32
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +000033NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
34 SourceLocation L, IdentifierInfo *Id) {
Steve Naroff5abb0282009-01-27 21:25:57 +000035 return new (C) NamespaceDecl(DC, L, Id);
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +000036}
37
Ted Kremenek5be49242008-05-20 04:49:55 +000038void NamespaceDecl::Destroy(ASTContext& C) {
39 // NamespaceDecl uses "NextDeclarator" to chain namespace declarations
40 // together. They are all top-level Decls.
41
Ted Kremenek0f433842008-05-24 15:09:56 +000042 this->~NamespaceDecl();
Steve Naroff5abb0282009-01-27 21:25:57 +000043 C.Deallocate((void *)this);
Ted Kremenek5be49242008-05-20 04:49:55 +000044}
45
46
Chris Lattner8c7c6a12008-06-17 18:05:57 +000047ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000048 SourceLocation L, IdentifierInfo *Id, QualType T) {
Steve Naroff5abb0282009-01-27 21:25:57 +000049 return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T);
Chris Lattner8c7c6a12008-06-17 18:05:57 +000050}
51
Chris Lattneref87a202008-04-22 18:39:57 +000052ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnereee57c02008-04-04 06:12:32 +000053 SourceLocation L, IdentifierInfo *Id,
54 QualType T, StorageClass S,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000055 Expr *DefArg) {
Steve Naroff5abb0282009-01-27 21:25:57 +000056 return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg);
Fariborz Jahaniane26cb432008-12-20 23:29:59 +000057}
58
59QualType ParmVarDecl::getOriginalType() const {
Douglas Gregor469fc9a2009-02-02 23:39:07 +000060 if (const OriginalParmVarDecl *PVD =
61 dyn_cast<OriginalParmVarDecl>(this))
Fariborz Jahaniane26cb432008-12-20 23:29:59 +000062 return PVD->OriginalType;
63 return getType();
Chris Lattner48d225c2008-03-15 21:10:16 +000064}
65
Douglas Gregor469fc9a2009-02-02 23:39:07 +000066OriginalParmVarDecl *OriginalParmVarDecl::Create(
Fariborz Jahanian160e8812008-12-20 20:56:12 +000067 ASTContext &C, DeclContext *DC,
68 SourceLocation L, IdentifierInfo *Id,
69 QualType T, QualType OT, StorageClass S,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000070 Expr *DefArg) {
Douglas Gregor469fc9a2009-02-02 23:39:07 +000071 return new (C) OriginalParmVarDecl(DC, L, Id, T, OT, S, DefArg);
Fariborz Jahanian160e8812008-12-20 20:56:12 +000072}
73
Chris Lattneref87a202008-04-22 18:39:57 +000074FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnereee57c02008-04-04 06:12:32 +000075 SourceLocation L,
Douglas Gregor6704b312008-11-17 22:58:34 +000076 DeclarationName N, QualType T,
Chris Lattner4c7802b2008-03-15 21:24:04 +000077 StorageClass S, bool isInline,
Steve Naroff71cd7762008-10-03 00:02:03 +000078 SourceLocation TypeSpecStartLoc) {
Steve Naroff5abb0282009-01-27 21:25:57 +000079 return new (C) FunctionDecl(Function, DC, L, N, T, S, isInline,
Steve Naroff71cd7762008-10-03 00:02:03 +000080 TypeSpecStartLoc);
Chris Lattner4c7802b2008-03-15 21:24:04 +000081}
82
Steve Naroff52059382008-10-10 01:28:17 +000083BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
Steve Naroff5abb0282009-01-27 21:25:57 +000084 return new (C) BlockDecl(DC, L);
Steve Naroff9ac456d2008-10-08 17:01:13 +000085}
86
Douglas Gregor8acb7272008-12-11 16:49:14 +000087FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
88 IdentifierInfo *Id, QualType T, Expr *BW,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000089 bool Mutable) {
Steve Naroff5abb0282009-01-27 21:25:57 +000090 return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable);
Chris Lattner81db64a2008-03-16 00:16:02 +000091}
92
Douglas Gregorc7f01612009-01-07 19:46:03 +000093bool FieldDecl::isAnonymousStructOrUnion() const {
94 if (!isImplicit() || getDeclName())
95 return false;
96
97 if (const RecordType *Record = getType()->getAsRecordType())
98 return Record->getDecl()->isAnonymousStructOrUnion();
99
100 return false;
101}
Chris Lattner4c7802b2008-03-15 21:24:04 +0000102
Chris Lattnereee57c02008-04-04 06:12:32 +0000103EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
104 SourceLocation L,
Chris Lattner58114f02008-03-15 21:32:50 +0000105 IdentifierInfo *Id, QualType T,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000106 Expr *E, const llvm::APSInt &V) {
Steve Naroff5abb0282009-01-27 21:25:57 +0000107 return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
Chris Lattnere4650482008-03-15 06:12:44 +0000108}
109
Ted Kremenek5be49242008-05-20 04:49:55 +0000110void EnumConstantDecl::Destroy(ASTContext& C) {
111 if (Init) Init->Destroy(C);
112 Decl::Destroy(C);
113}
114
Chris Lattneref87a202008-04-22 18:39:57 +0000115TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnereee57c02008-04-04 06:12:32 +0000116 SourceLocation L,
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000117 IdentifierInfo *Id, QualType T) {
Steve Naroff5abb0282009-01-27 21:25:57 +0000118 return new (C) TypedefDecl(DC, L, Id, T);
Chris Lattnere4650482008-03-15 06:12:44 +0000119}
120
Chris Lattneref87a202008-04-22 18:39:57 +0000121EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
Chris Lattnereee57c02008-04-04 06:12:32 +0000122 IdentifierInfo *Id,
Douglas Gregorae644892008-12-15 16:32:14 +0000123 EnumDecl *PrevDecl) {
Steve Naroff207b9ec2009-01-27 23:20:32 +0000124 EnumDecl *Enum = new (C) EnumDecl(DC, L, Id);
Douglas Gregorae644892008-12-15 16:32:14 +0000125 C.getTypeDeclType(Enum, PrevDecl);
126 return Enum;
Chris Lattnere4650482008-03-15 06:12:44 +0000127}
128
Ted Kremenek25d8be12008-09-02 20:13:32 +0000129void EnumDecl::Destroy(ASTContext& C) {
Ted Kremenek25d8be12008-09-02 20:13:32 +0000130 Decl::Destroy(C);
131}
132
Douglas Gregor8acb7272008-12-11 16:49:14 +0000133void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) {
134 assert(!isDefinition() && "Cannot redefine enums!");
Douglas Gregor8acb7272008-12-11 16:49:14 +0000135 IntegerType = NewType;
Douglas Gregor98b27542009-01-17 00:42:38 +0000136 TagDecl::completeDefinition();
Douglas Gregor8acb7272008-12-11 16:49:14 +0000137}
138
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000139FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnereee57c02008-04-04 06:12:32 +0000140 SourceLocation L,
Chris Lattner81db64a2008-03-16 00:16:02 +0000141 StringLiteral *Str) {
Steve Naroff5abb0282009-01-27 21:25:57 +0000142 return new (C) FileScopeAsmDecl(DC, L, Str);
Chris Lattner81db64a2008-03-16 00:16:02 +0000143}
144
Chris Lattnere4650482008-03-15 06:12:44 +0000145//===----------------------------------------------------------------------===//
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000146// NamedDecl Implementation
Argiris Kirtzidis881964b2008-11-09 23:41:00 +0000147//===----------------------------------------------------------------------===//
148
Douglas Gregor09be81b2009-02-04 17:27:36 +0000149std::string NamedDecl::getQualifiedNameAsString() const {
150 std::vector<std::string> Names;
151 std::string QualName;
152 const DeclContext *Ctx = getDeclContext();
153
154 if (Ctx->isFunctionOrMethod())
155 return getNameAsString();
156
157 while (Ctx) {
158 if (Ctx->isFunctionOrMethod())
159 // FIXME: That probably will happen, when D was member of local
160 // scope class/struct/union. How do we handle this case?
161 break;
162
163 if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
164 Names.push_back(ND->getNameAsString());
165 else
166 break;
167
168 Ctx = Ctx->getParent();
169 }
170
171 std::vector<std::string>::reverse_iterator
172 I = Names.rbegin(),
173 End = Names.rend();
174
175 for (; I!=End; ++I)
176 QualName += *I + "::";
177
178 QualName += getNameAsString();
179
180 return QualName;
181}
182
183
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000184bool NamedDecl::declarationReplaces(NamedDecl *OldD) const {
Douglas Gregor6e71edc2008-12-23 21:05:05 +0000185 assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
186
Douglas Gregor7a7be652009-02-03 19:21:40 +0000187 // UsingDirectiveDecl's are not really NamedDecl's, and all have same name.
188 // We want to keep it, unless it nominates same namespace.
189 if (getKind() == Decl::UsingDirective) {
190 return cast<UsingDirectiveDecl>(this)->getNominatedNamespace() ==
191 cast<UsingDirectiveDecl>(OldD)->getNominatedNamespace();
192 }
193
Douglas Gregor6e71edc2008-12-23 21:05:05 +0000194 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
195 // For function declarations, we keep track of redeclarations.
196 return FD->getPreviousDeclaration() == OldD;
197
Steve Naroffd85ba922009-02-22 19:35:57 +0000198 // For method declarations, we keep track of redeclarations.
199 if (isa<ObjCMethodDecl>(this))
200 return false;
201
Douglas Gregor6e71edc2008-12-23 21:05:05 +0000202 // For non-function declarations, if the declarations are of the
203 // same kind then this must be a redeclaration, or semantic analysis
204 // would not have given us the new declaration.
205 return this->getKind() == OldD->getKind();
206}
207
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000208
Argiris Kirtzidis881964b2008-11-09 23:41:00 +0000209//===----------------------------------------------------------------------===//
Nuno Lopesc98406e2008-12-17 23:39:55 +0000210// VarDecl Implementation
211//===----------------------------------------------------------------------===//
212
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000213VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
214 IdentifierInfo *Id, QualType T, StorageClass S,
Nuno Lopesc98406e2008-12-17 23:39:55 +0000215 SourceLocation TypeSpecStartLoc) {
Steve Naroff5abb0282009-01-27 21:25:57 +0000216 return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc);
Nuno Lopesc98406e2008-12-17 23:39:55 +0000217}
218
219void VarDecl::Destroy(ASTContext& C) {
Sebastian Redl2ee55612009-02-05 15:12:41 +0000220 Expr *Init = getInit();
221 if (Init)
222 Init->Destroy(C);
Nuno Lopesc98406e2008-12-17 23:39:55 +0000223 this->~VarDecl();
Steve Naroff5abb0282009-01-27 21:25:57 +0000224 C.Deallocate((void *)this);
Nuno Lopesc98406e2008-12-17 23:39:55 +0000225}
226
227VarDecl::~VarDecl() {
Nuno Lopesc98406e2008-12-17 23:39:55 +0000228}
229
230//===----------------------------------------------------------------------===//
Chris Lattnerc72d22d2008-03-31 00:36:02 +0000231// FunctionDecl Implementation
232//===----------------------------------------------------------------------===//
233
Ted Kremenekafdf8112008-05-20 00:43:19 +0000234void FunctionDecl::Destroy(ASTContext& C) {
Ted Kremenek345b93d2008-05-20 03:56:00 +0000235 if (Body)
236 Body->Destroy(C);
237
238 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
239 (*I)->Destroy(C);
Nuno Lopescb8cc5b2009-01-18 19:57:27 +0000240
Steve Naroff5abb0282009-01-27 21:25:57 +0000241 C.Deallocate(ParamInfo);
Nuno Lopescb8cc5b2009-01-18 19:57:27 +0000242
Ted Kremenekafdf8112008-05-20 00:43:19 +0000243 Decl::Destroy(C);
244}
245
246
Douglas Gregor42214c52008-04-21 02:02:58 +0000247Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
248 for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
249 if (FD->Body) {
250 Definition = FD;
251 return FD->Body;
252 }
253 }
254
255 return 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000256}
257
Douglas Gregoraf682022009-02-24 01:23:02 +0000258bool FunctionDecl::isMain() const {
259 return getDeclContext()->getLookupContext()->isTranslationUnit() &&
260 getIdentifier() && getIdentifier()->isStr("main");
261}
262
Douglas Gregor411889e2009-02-13 23:20:09 +0000263/// \brief Returns a value indicating whether this function
264/// corresponds to a builtin function.
265///
266/// The function corresponds to a built-in function if it is
267/// declared at translation scope or within an extern "C" block and
268/// its name matches with the name of a builtin. The returned value
269/// will be 0 for functions that do not correspond to a builtin, a
270/// value of type \c Builtin::ID if in the target-independent range
271/// \c [1,Builtin::First), or a target-specific builtin value.
Douglas Gregorb5af7382009-02-14 18:57:46 +0000272unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
273 if (!getIdentifier() || !getIdentifier()->getBuiltinID())
274 return 0;
275
276 unsigned BuiltinID = getIdentifier()->getBuiltinID();
277 if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
278 return BuiltinID;
279
280 // This function has the name of a known C library
281 // function. Determine whether it actually refers to the C library
282 // function or whether it just has the same name.
283
Douglas Gregor4d6b1022009-02-17 03:23:10 +0000284 // If this is a static function, it's not a builtin.
285 if (getStorageClass() == Static)
286 return 0;
287
Douglas Gregorb5af7382009-02-14 18:57:46 +0000288 // If this function is at translation-unit scope and we're not in
289 // C++, it refers to the C library function.
290 if (!Context.getLangOptions().CPlusPlus &&
291 getDeclContext()->isTranslationUnit())
292 return BuiltinID;
293
294 // If the function is in an extern "C" linkage specification and is
295 // not marked "overloadable", it's the real function.
296 if (isa<LinkageSpecDecl>(getDeclContext()) &&
297 cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
298 == LinkageSpecDecl::lang_c &&
299 !getAttr<OverloadableAttr>())
300 return BuiltinID;
301
302 // Not a builtin
Douglas Gregor411889e2009-02-13 23:20:09 +0000303 return 0;
304}
305
306
Ted Kremeneka6ded352008-10-29 18:41:34 +0000307// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams()
308static unsigned getNumTypeParams(QualType T) {
309 const FunctionType *FT = T->getAsFunctionType();
Chris Lattnere8733592008-04-06 23:09:52 +0000310 if (isa<FunctionTypeNoProto>(FT))
Chris Lattnera8344c32008-03-15 05:43:15 +0000311 return 0;
Chris Lattnere8733592008-04-06 23:09:52 +0000312 return cast<FunctionTypeProto>(FT)->getNumArgs();
Chris Lattner4b009652007-07-25 00:24:17 +0000313}
314
Ted Kremeneka6ded352008-10-29 18:41:34 +0000315unsigned FunctionDecl::getNumParams() const {
316 // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar;
317 if (!ParamInfo)
318 return 0;
319
320 return getNumTypeParams(getType());
321}
322
Ted Kremenek8494c962009-01-14 00:42:25 +0000323void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
324 unsigned NumParams) {
Chris Lattner4b009652007-07-25 00:24:17 +0000325 assert(ParamInfo == 0 && "Already has param info!");
Ted Kremeneka6ded352008-10-29 18:41:34 +0000326 assert(NumParams == getNumTypeParams(getType()) &&
327 "Parameter count mismatch!");
Chris Lattner4b009652007-07-25 00:24:17 +0000328
329 // Zero params -> null pointer.
330 if (NumParams) {
Steve Naroff207b9ec2009-01-27 23:20:32 +0000331 void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
Ted Kremenek8494c962009-01-14 00:42:25 +0000332 ParamInfo = new (Mem) ParmVarDecl*[NumParams];
Chris Lattner4b009652007-07-25 00:24:17 +0000333 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
334 }
335}
336
Chris Lattner97316c02008-04-10 02:22:51 +0000337/// getMinRequiredArguments - Returns the minimum number of arguments
338/// needed to call this function. This may be fewer than the number of
339/// function parameters, if some of the parameters have default
Chris Lattnerb1856db2008-04-12 23:52:44 +0000340/// arguments (in C++).
Chris Lattner97316c02008-04-10 02:22:51 +0000341unsigned FunctionDecl::getMinRequiredArguments() const {
342 unsigned NumRequiredArgs = getNumParams();
343 while (NumRequiredArgs > 0
344 && getParamDecl(NumRequiredArgs-1)->getDefaultArg())
345 --NumRequiredArgs;
346
347 return NumRequiredArgs;
348}
349
Douglas Gregore60e5d32008-11-06 22:13:31 +0000350/// getOverloadedOperator - Which C++ overloaded operator this
351/// function represents, if any.
352OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
Douglas Gregor96a32dd2008-11-18 14:39:36 +0000353 if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
354 return getDeclName().getCXXOverloadedOperator();
Douglas Gregore60e5d32008-11-06 22:13:31 +0000355 else
356 return OO_None;
357}
358
Chris Lattnerc72d22d2008-03-31 00:36:02 +0000359//===----------------------------------------------------------------------===//
Douglas Gregor723d3332009-01-07 00:43:41 +0000360// TagDecl Implementation
Ted Kremenek46a837c2008-09-05 17:16:31 +0000361//===----------------------------------------------------------------------===//
362
Douglas Gregor98b27542009-01-17 00:42:38 +0000363void TagDecl::startDefinition() {
364 cast<TagType>(TypeForDecl)->decl.setPointer(this);
365 cast<TagType>(TypeForDecl)->decl.setInt(1);
366}
367
368void TagDecl::completeDefinition() {
369 assert((!TypeForDecl ||
370 cast<TagType>(TypeForDecl)->decl.getPointer() == this) &&
371 "Attempt to redefine a tag definition?");
372 IsDefinition = true;
373 cast<TagType>(TypeForDecl)->decl.setPointer(this);
374 cast<TagType>(TypeForDecl)->decl.setInt(0);
375}
376
Ted Kremenek46a837c2008-09-05 17:16:31 +0000377TagDecl* TagDecl::getDefinition(ASTContext& C) const {
378 QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this));
379 TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl());
380 return D->isDefinition() ? D : 0;
381}
382
383//===----------------------------------------------------------------------===//
Chris Lattnerc72d22d2008-03-31 00:36:02 +0000384// RecordDecl Implementation
385//===----------------------------------------------------------------------===//
Chris Lattner4b009652007-07-25 00:24:17 +0000386
Argiris Kirtzidis2538a8c2008-10-15 00:42:39 +0000387RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
Ted Kremenek2c984042008-09-05 01:34:33 +0000388 IdentifierInfo *Id)
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000389 : TagDecl(DK, TK, DC, L, Id) {
Ted Kremenek6f0a2412008-09-02 21:12:32 +0000390 HasFlexibleArrayMember = false;
Douglas Gregor723d3332009-01-07 00:43:41 +0000391 AnonymousStructOrUnion = false;
Ted Kremenek6f0a2412008-09-02 21:12:32 +0000392 assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
Ted Kremenek6f0a2412008-09-02 21:12:32 +0000393}
394
395RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
Ted Kremenek46a837c2008-09-05 17:16:31 +0000396 SourceLocation L, IdentifierInfo *Id,
397 RecordDecl* PrevDecl) {
Ted Kremenek2c984042008-09-05 01:34:33 +0000398
Steve Naroff5abb0282009-01-27 21:25:57 +0000399 RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id);
Ted Kremenek46a837c2008-09-05 17:16:31 +0000400 C.getTypeDeclType(R, PrevDecl);
401 return R;
Ted Kremenek6f0a2412008-09-02 21:12:32 +0000402}
403
Argiris Kirtzidisd64c1112008-08-08 14:08:55 +0000404RecordDecl::~RecordDecl() {
Argiris Kirtzidisd64c1112008-08-08 14:08:55 +0000405}
406
407void RecordDecl::Destroy(ASTContext& C) {
Argiris Kirtzidisd64c1112008-08-08 14:08:55 +0000408 TagDecl::Destroy(C);
409}
410
Douglas Gregor8acb7272008-12-11 16:49:14 +0000411/// completeDefinition - Notes that the definition of this type is now
412/// complete.
413void RecordDecl::completeDefinition(ASTContext& C) {
Chris Lattner4b009652007-07-25 00:24:17 +0000414 assert(!isDefinition() && "Cannot redefine record!");
Douglas Gregor98b27542009-01-17 00:42:38 +0000415 TagDecl::completeDefinition();
Chris Lattner4b009652007-07-25 00:24:17 +0000416}
417
Steve Naroff9ac456d2008-10-08 17:01:13 +0000418//===----------------------------------------------------------------------===//
419// BlockDecl Implementation
420//===----------------------------------------------------------------------===//
421
422BlockDecl::~BlockDecl() {
423}
424
425void BlockDecl::Destroy(ASTContext& C) {
426 if (Body)
427 Body->Destroy(C);
428
429 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
430 (*I)->Destroy(C);
431
432 Decl::Destroy(C);
433}