blob: f7608529d4838d3a9c273d1ed0b22632af85c472 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Argyrios Kyrtzidise184bae2008-06-04 13:04:04 +000010// This file implements the Decl subclasses.
Reid Spencer5f016e22007-07-11 17:01:13 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
Douglas Gregor2a3009a2009-02-03 19:21:40 +000015#include "clang/AST/DeclCXX.h"
Steve Naroff0de21fd2009-02-22 19:35:57 +000016#include "clang/AST/DeclObjC.h"
Chris Lattner6c2b6eb2008-03-15 06:12:44 +000017#include "clang/AST/ASTContext.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000018#include "clang/AST/Stmt.h"
Nuno Lopes99f06ba2008-12-17 23:39:55 +000019#include "clang/AST/Expr.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000020#include "clang/Basic/IdentifierTable.h"
Douglas Gregor47b9a1c2009-02-04 17:27:36 +000021#include <vector>
Ted Kremenek27f8a282008-05-20 00:43:19 +000022
Reid Spencer5f016e22007-07-11 17:01:13 +000023using namespace clang;
24
Chris Lattnerd3b90652008-03-15 05:43:15 +000025//===----------------------------------------------------------------------===//
Chris Lattner6c2b6eb2008-03-15 06:12:44 +000026// Decl Allocation/Deallocation Method Implementations
27//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000028
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000029TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
Steve Naroff3e970492009-01-27 21:25:57 +000030 return new (C) TranslationUnitDecl();
Argyrios Kyrtzidisef177822008-04-17 14:40:12 +000031}
32
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000033NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
34 SourceLocation L, IdentifierInfo *Id) {
Steve Naroff3e970492009-01-27 21:25:57 +000035 return new (C) NamespaceDecl(DC, L, Id);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000036}
37
Ted Kremenekd1ac17a2008-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 Kremenekebf27b12008-05-24 15:09:56 +000042 this->~NamespaceDecl();
Steve Naroff3e970492009-01-27 21:25:57 +000043 C.Deallocate((void *)this);
Ted Kremenekd1ac17a2008-05-20 04:49:55 +000044}
45
46
Chris Lattner41110242008-06-17 18:05:57 +000047ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor4afa39d2009-01-20 01:17:11 +000048 SourceLocation L, IdentifierInfo *Id, QualType T) {
Steve Naroff3e970492009-01-27 21:25:57 +000049 return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T);
Chris Lattner41110242008-06-17 18:05:57 +000050}
51
Chris Lattner9fdf9c62008-04-22 18:39:57 +000052ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattner0ed844b2008-04-04 06:12:32 +000053 SourceLocation L, IdentifierInfo *Id,
54 QualType T, StorageClass S,
Douglas Gregor4afa39d2009-01-20 01:17:11 +000055 Expr *DefArg) {
Steve Naroff3e970492009-01-27 21:25:57 +000056 return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg);
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +000057}
58
59QualType ParmVarDecl::getOriginalType() const {
Douglas Gregor64650af2009-02-02 23:39:07 +000060 if (const OriginalParmVarDecl *PVD =
61 dyn_cast<OriginalParmVarDecl>(this))
Fariborz Jahanian4306d3c2008-12-20 23:29:59 +000062 return PVD->OriginalType;
63 return getType();
Chris Lattner9e151e12008-03-15 21:10:16 +000064}
65
Douglas Gregor64650af2009-02-02 23:39:07 +000066OriginalParmVarDecl *OriginalParmVarDecl::Create(
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000067 ASTContext &C, DeclContext *DC,
68 SourceLocation L, IdentifierInfo *Id,
69 QualType T, QualType OT, StorageClass S,
Douglas Gregor4afa39d2009-01-20 01:17:11 +000070 Expr *DefArg) {
Douglas Gregor64650af2009-02-02 23:39:07 +000071 return new (C) OriginalParmVarDecl(DC, L, Id, T, OT, S, DefArg);
Fariborz Jahanian73da9e42008-12-20 20:56:12 +000072}
73
Chris Lattner9fdf9c62008-04-22 18:39:57 +000074FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattner0ed844b2008-04-04 06:12:32 +000075 SourceLocation L,
Douglas Gregor10bd3682008-11-17 22:58:34 +000076 DeclarationName N, QualType T,
Chris Lattnera98e58d2008-03-15 21:24:04 +000077 StorageClass S, bool isInline,
Steve Naroff0eb07bf2008-10-03 00:02:03 +000078 SourceLocation TypeSpecStartLoc) {
Steve Naroff3e970492009-01-27 21:25:57 +000079 return new (C) FunctionDecl(Function, DC, L, N, T, S, isInline,
Steve Naroff0eb07bf2008-10-03 00:02:03 +000080 TypeSpecStartLoc);
Chris Lattnera98e58d2008-03-15 21:24:04 +000081}
82
Steve Naroff090276f2008-10-10 01:28:17 +000083BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
Steve Naroff3e970492009-01-27 21:25:57 +000084 return new (C) BlockDecl(DC, L);
Steve Naroff56ee6892008-10-08 17:01:13 +000085}
86
Douglas Gregor44b43212008-12-11 16:49:14 +000087FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
88 IdentifierInfo *Id, QualType T, Expr *BW,
Douglas Gregor4afa39d2009-01-20 01:17:11 +000089 bool Mutable) {
Steve Naroff3e970492009-01-27 21:25:57 +000090 return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable);
Chris Lattner8e25d862008-03-16 00:16:02 +000091}
92
Douglas Gregor6b3945f2009-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 Lattnera98e58d2008-03-15 21:24:04 +0000102
Chris Lattner0ed844b2008-04-04 06:12:32 +0000103EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
104 SourceLocation L,
Chris Lattnerc63e6602008-03-15 21:32:50 +0000105 IdentifierInfo *Id, QualType T,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000106 Expr *E, const llvm::APSInt &V) {
Steve Naroff3e970492009-01-27 21:25:57 +0000107 return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000108}
109
Ted Kremenekd1ac17a2008-05-20 04:49:55 +0000110void EnumConstantDecl::Destroy(ASTContext& C) {
111 if (Init) Init->Destroy(C);
112 Decl::Destroy(C);
113}
114
Chris Lattner9fdf9c62008-04-22 18:39:57 +0000115TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattner0ed844b2008-04-04 06:12:32 +0000116 SourceLocation L,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000117 IdentifierInfo *Id, QualType T) {
Steve Naroff3e970492009-01-27 21:25:57 +0000118 return new (C) TypedefDecl(DC, L, Id, T);
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000119}
120
Chris Lattner9fdf9c62008-04-22 18:39:57 +0000121EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
Chris Lattner0ed844b2008-04-04 06:12:32 +0000122 IdentifierInfo *Id,
Douglas Gregor7df7b6b2008-12-15 16:32:14 +0000123 EnumDecl *PrevDecl) {
Steve Naroffc0ac4922009-01-27 23:20:32 +0000124 EnumDecl *Enum = new (C) EnumDecl(DC, L, Id);
Douglas Gregor7df7b6b2008-12-15 16:32:14 +0000125 C.getTypeDeclType(Enum, PrevDecl);
126 return Enum;
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000127}
128
Ted Kremenekdf91eca2008-09-02 20:13:32 +0000129void EnumDecl::Destroy(ASTContext& C) {
Ted Kremenekdf91eca2008-09-02 20:13:32 +0000130 Decl::Destroy(C);
131}
132
Douglas Gregor44b43212008-12-11 16:49:14 +0000133void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) {
134 assert(!isDefinition() && "Cannot redefine enums!");
Douglas Gregor44b43212008-12-11 16:49:14 +0000135 IntegerType = NewType;
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000136 TagDecl::completeDefinition();
Douglas Gregor44b43212008-12-11 16:49:14 +0000137}
138
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000139FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattner0ed844b2008-04-04 06:12:32 +0000140 SourceLocation L,
Chris Lattner8e25d862008-03-16 00:16:02 +0000141 StringLiteral *Str) {
Steve Naroff3e970492009-01-27 21:25:57 +0000142 return new (C) FileScopeAsmDecl(DC, L, Str);
Chris Lattner8e25d862008-03-16 00:16:02 +0000143}
144
Chris Lattner6c2b6eb2008-03-15 06:12:44 +0000145//===----------------------------------------------------------------------===//
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000146// NamedDecl Implementation
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +0000147//===----------------------------------------------------------------------===//
148
Douglas Gregor47b9a1c2009-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 Gregor4afa39d2009-01-20 01:17:11 +0000184bool NamedDecl::declarationReplaces(NamedDecl *OldD) const {
Douglas Gregor6ed40e32008-12-23 21:05:05 +0000185 assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
186
Douglas Gregor2a3009a2009-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 Gregor6ed40e32008-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 Naroff0de21fd2009-02-22 19:35:57 +0000198 // For method declarations, we keep track of redeclarations.
199 if (isa<ObjCMethodDecl>(this))
200 return false;
201
Douglas Gregor6ed40e32008-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 Gregor4afa39d2009-01-20 01:17:11 +0000208
Argyrios Kyrtzidis52393042008-11-09 23:41:00 +0000209//===----------------------------------------------------------------------===//
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000210// VarDecl Implementation
211//===----------------------------------------------------------------------===//
212
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000213VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
214 IdentifierInfo *Id, QualType T, StorageClass S,
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000215 SourceLocation TypeSpecStartLoc) {
Steve Naroff3e970492009-01-27 21:25:57 +0000216 return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc);
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000217}
218
219void VarDecl::Destroy(ASTContext& C) {
Sebastian Redldf2d3cf2009-02-05 15:12:41 +0000220 Expr *Init = getInit();
221 if (Init)
222 Init->Destroy(C);
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000223 this->~VarDecl();
Steve Naroff3e970492009-01-27 21:25:57 +0000224 C.Deallocate((void *)this);
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000225}
226
227VarDecl::~VarDecl() {
Nuno Lopes99f06ba2008-12-17 23:39:55 +0000228}
229
230//===----------------------------------------------------------------------===//
Chris Lattner8a934232008-03-31 00:36:02 +0000231// FunctionDecl Implementation
232//===----------------------------------------------------------------------===//
233
Ted Kremenek27f8a282008-05-20 00:43:19 +0000234void FunctionDecl::Destroy(ASTContext& C) {
Ted Kremenekb65cf412008-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 Lopes460b0ac2009-01-18 19:57:27 +0000240
Steve Naroff3e970492009-01-27 21:25:57 +0000241 C.Deallocate(ParamInfo);
Nuno Lopes460b0ac2009-01-18 19:57:27 +0000242
Ted Kremenek27f8a282008-05-20 00:43:19 +0000243 Decl::Destroy(C);
244}
245
246
Douglas Gregorf0097952008-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;
Reid Spencer5f016e22007-07-11 17:01:13 +0000256}
257
Douglas Gregor3e41d602009-02-13 23:20:09 +0000258/// \brief Returns a value indicating whether this function
259/// corresponds to a builtin function.
260///
261/// The function corresponds to a built-in function if it is
262/// declared at translation scope or within an extern "C" block and
263/// its name matches with the name of a builtin. The returned value
264/// will be 0 for functions that do not correspond to a builtin, a
265/// value of type \c Builtin::ID if in the target-independent range
266/// \c [1,Builtin::First), or a target-specific builtin value.
Douglas Gregor3c385e52009-02-14 18:57:46 +0000267unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
268 if (!getIdentifier() || !getIdentifier()->getBuiltinID())
269 return 0;
270
271 unsigned BuiltinID = getIdentifier()->getBuiltinID();
272 if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
273 return BuiltinID;
274
275 // This function has the name of a known C library
276 // function. Determine whether it actually refers to the C library
277 // function or whether it just has the same name.
278
Douglas Gregor9add3172009-02-17 03:23:10 +0000279 // If this is a static function, it's not a builtin.
280 if (getStorageClass() == Static)
281 return 0;
282
Douglas Gregor3c385e52009-02-14 18:57:46 +0000283 // If this function is at translation-unit scope and we're not in
284 // C++, it refers to the C library function.
285 if (!Context.getLangOptions().CPlusPlus &&
286 getDeclContext()->isTranslationUnit())
287 return BuiltinID;
288
289 // If the function is in an extern "C" linkage specification and is
290 // not marked "overloadable", it's the real function.
291 if (isa<LinkageSpecDecl>(getDeclContext()) &&
292 cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
293 == LinkageSpecDecl::lang_c &&
294 !getAttr<OverloadableAttr>())
295 return BuiltinID;
296
297 // Not a builtin
Douglas Gregor3e41d602009-02-13 23:20:09 +0000298 return 0;
299}
300
301
Ted Kremenek4f03fd62008-10-29 18:41:34 +0000302// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams()
303static unsigned getNumTypeParams(QualType T) {
304 const FunctionType *FT = T->getAsFunctionType();
Chris Lattnerd8bdba52008-04-06 23:09:52 +0000305 if (isa<FunctionTypeNoProto>(FT))
Chris Lattnerd3b90652008-03-15 05:43:15 +0000306 return 0;
Chris Lattnerd8bdba52008-04-06 23:09:52 +0000307 return cast<FunctionTypeProto>(FT)->getNumArgs();
Reid Spencer5f016e22007-07-11 17:01:13 +0000308}
309
Ted Kremenek4f03fd62008-10-29 18:41:34 +0000310unsigned FunctionDecl::getNumParams() const {
311 // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar;
312 if (!ParamInfo)
313 return 0;
314
315 return getNumTypeParams(getType());
316}
317
Ted Kremenekfc767612009-01-14 00:42:25 +0000318void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
319 unsigned NumParams) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000320 assert(ParamInfo == 0 && "Already has param info!");
Ted Kremenek4f03fd62008-10-29 18:41:34 +0000321 assert(NumParams == getNumTypeParams(getType()) &&
322 "Parameter count mismatch!");
Reid Spencer5f016e22007-07-11 17:01:13 +0000323
324 // Zero params -> null pointer.
325 if (NumParams) {
Steve Naroffc0ac4922009-01-27 23:20:32 +0000326 void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
Ted Kremenekfc767612009-01-14 00:42:25 +0000327 ParamInfo = new (Mem) ParmVarDecl*[NumParams];
Reid Spencer5f016e22007-07-11 17:01:13 +0000328 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
329 }
330}
331
Chris Lattner8123a952008-04-10 02:22:51 +0000332/// getMinRequiredArguments - Returns the minimum number of arguments
333/// needed to call this function. This may be fewer than the number of
334/// function parameters, if some of the parameters have default
Chris Lattner9e979552008-04-12 23:52:44 +0000335/// arguments (in C++).
Chris Lattner8123a952008-04-10 02:22:51 +0000336unsigned FunctionDecl::getMinRequiredArguments() const {
337 unsigned NumRequiredArgs = getNumParams();
338 while (NumRequiredArgs > 0
339 && getParamDecl(NumRequiredArgs-1)->getDefaultArg())
340 --NumRequiredArgs;
341
342 return NumRequiredArgs;
343}
344
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +0000345/// getOverloadedOperator - Which C++ overloaded operator this
346/// function represents, if any.
347OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
Douglas Gregore94ca9e42008-11-18 14:39:36 +0000348 if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
349 return getDeclName().getCXXOverloadedOperator();
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +0000350 else
351 return OO_None;
352}
353
Chris Lattner8a934232008-03-31 00:36:02 +0000354//===----------------------------------------------------------------------===//
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000355// TagDecl Implementation
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000356//===----------------------------------------------------------------------===//
357
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000358void TagDecl::startDefinition() {
359 cast<TagType>(TypeForDecl)->decl.setPointer(this);
360 cast<TagType>(TypeForDecl)->decl.setInt(1);
361}
362
363void TagDecl::completeDefinition() {
364 assert((!TypeForDecl ||
365 cast<TagType>(TypeForDecl)->decl.getPointer() == this) &&
366 "Attempt to redefine a tag definition?");
367 IsDefinition = true;
368 cast<TagType>(TypeForDecl)->decl.setPointer(this);
369 cast<TagType>(TypeForDecl)->decl.setInt(0);
370}
371
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000372TagDecl* TagDecl::getDefinition(ASTContext& C) const {
373 QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this));
374 TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl());
375 return D->isDefinition() ? D : 0;
376}
377
378//===----------------------------------------------------------------------===//
Chris Lattner8a934232008-03-31 00:36:02 +0000379// RecordDecl Implementation
380//===----------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +0000381
Argyrios Kyrtzidis35bc0822008-10-15 00:42:39 +0000382RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
Ted Kremenekdf042e62008-09-05 01:34:33 +0000383 IdentifierInfo *Id)
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000384 : TagDecl(DK, TK, DC, L, Id) {
Ted Kremenek63597922008-09-02 21:12:32 +0000385 HasFlexibleArrayMember = false;
Douglas Gregorbcbffc42009-01-07 00:43:41 +0000386 AnonymousStructOrUnion = false;
Ted Kremenek63597922008-09-02 21:12:32 +0000387 assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
Ted Kremenek63597922008-09-02 21:12:32 +0000388}
389
390RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000391 SourceLocation L, IdentifierInfo *Id,
392 RecordDecl* PrevDecl) {
Ted Kremenekdf042e62008-09-05 01:34:33 +0000393
Steve Naroff3e970492009-01-27 21:25:57 +0000394 RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000395 C.getTypeDeclType(R, PrevDecl);
396 return R;
Ted Kremenek63597922008-09-02 21:12:32 +0000397}
398
Argyrios Kyrtzidis997b6c62008-08-08 14:08:55 +0000399RecordDecl::~RecordDecl() {
Argyrios Kyrtzidis997b6c62008-08-08 14:08:55 +0000400}
401
402void RecordDecl::Destroy(ASTContext& C) {
Argyrios Kyrtzidis997b6c62008-08-08 14:08:55 +0000403 TagDecl::Destroy(C);
404}
405
Douglas Gregor44b43212008-12-11 16:49:14 +0000406/// completeDefinition - Notes that the definition of this type is now
407/// complete.
408void RecordDecl::completeDefinition(ASTContext& C) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000409 assert(!isDefinition() && "Cannot redefine record!");
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000410 TagDecl::completeDefinition();
Reid Spencer5f016e22007-07-11 17:01:13 +0000411}
412
Steve Naroff56ee6892008-10-08 17:01:13 +0000413//===----------------------------------------------------------------------===//
414// BlockDecl Implementation
415//===----------------------------------------------------------------------===//
416
417BlockDecl::~BlockDecl() {
418}
419
420void BlockDecl::Destroy(ASTContext& C) {
421 if (Body)
422 Body->Destroy(C);
423
424 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
425 (*I)->Destroy(C);
426
427 Decl::Destroy(C);
428}