blob: fc19e61a0997deddea59088880238bc0536c2d7a [file] [log] [blame]
Chris Lattnera11999d2006-10-15 22:34:45 +00001//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-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 Lattnera11999d2006-10-15 22:34:45 +00007//
8//===----------------------------------------------------------------------===//
9//
Argyrios Kyrtzidis63018842008-06-04 13:04:04 +000010// This file implements the Decl subclasses.
Chris Lattnera11999d2006-10-15 22:34:45 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Decl.h"
Douglas Gregor889ceb72009-02-03 19:21:40 +000015#include "clang/AST/DeclCXX.h"
Steve Naroffc4173fa2009-02-22 19:35:57 +000016#include "clang/AST/DeclObjC.h"
Douglas Gregore362cea2009-05-10 22:57:19 +000017#include "clang/AST/DeclTemplate.h"
Chris Lattnera7b32872008-03-15 06:12:44 +000018#include "clang/AST/ASTContext.h"
Argyrios Kyrtzidis3f79ad72009-08-19 01:27:32 +000019#include "clang/AST/TypeLoc.h"
Daniel Dunbar221fa942008-08-11 04:54:23 +000020#include "clang/AST/Stmt.h"
Nuno Lopes394ec982008-12-17 23:39:55 +000021#include "clang/AST/Expr.h"
Douglas Gregor7de59662009-05-29 20:38:28 +000022#include "clang/AST/PrettyPrinter.h"
Chris Lattner15ba9492009-06-14 01:54:56 +000023#include "clang/Basic/Builtins.h"
Daniel Dunbar221fa942008-08-11 04:54:23 +000024#include "clang/Basic/IdentifierTable.h"
Douglas Gregor2ada0482009-02-04 17:27:36 +000025#include <vector>
Ted Kremenekce20e8f2008-05-20 00:43:19 +000026
Chris Lattner6d9a6852006-10-25 05:11:20 +000027using namespace clang;
Chris Lattnera11999d2006-10-15 22:34:45 +000028
Chris Lattner9631e182009-03-04 06:34:08 +000029void Attr::Destroy(ASTContext &C) {
30 if (Next) {
31 Next->Destroy(C);
32 Next = 0;
33 }
34 this->~Attr();
35 C.Deallocate((void*)this);
36}
37
Argyrios Kyrtzidis3f79ad72009-08-19 01:27:32 +000038/// \brief Return the TypeLoc wrapper for the type source info.
39TypeLoc DeclaratorInfo::getTypeLoc() const {
40 return TypeLoc::Create(Ty, (void*)(this + 1));
41}
Chris Lattner9631e182009-03-04 06:34:08 +000042
Chris Lattner88f70d62008-03-15 05:43:15 +000043//===----------------------------------------------------------------------===//
Chris Lattnera7b32872008-03-15 06:12:44 +000044// Decl Allocation/Deallocation Method Implementations
45//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +000046
Chris Lattner9631e182009-03-04 06:34:08 +000047
Argyrios Kyrtzidisc3b69ae2008-04-17 14:40:12 +000048TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
Argyrios Kyrtzidis743e7db2009-06-29 17:38:40 +000049 return new (C) TranslationUnitDecl(C);
Argyrios Kyrtzidisc3b69ae2008-04-17 14:40:12 +000050}
51
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +000052NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
53 SourceLocation L, IdentifierInfo *Id) {
Steve Naroff13ae6f42009-01-27 21:25:57 +000054 return new (C) NamespaceDecl(DC, L, Id);
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +000055}
56
Ted Kremenek78aa98f2008-05-20 04:49:55 +000057void NamespaceDecl::Destroy(ASTContext& C) {
58 // NamespaceDecl uses "NextDeclarator" to chain namespace declarations
59 // together. They are all top-level Decls.
60
Ted Kremeneka08154d2008-05-24 15:09:56 +000061 this->~NamespaceDecl();
Steve Naroff13ae6f42009-01-27 21:25:57 +000062 C.Deallocate((void *)this);
Ted Kremenek78aa98f2008-05-20 04:49:55 +000063}
64
65
Chris Lattner5696e7b2008-06-17 18:05:57 +000066ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
Douglas Gregor6e6ad602009-01-20 01:17:11 +000067 SourceLocation L, IdentifierInfo *Id, QualType T) {
Steve Naroff13ae6f42009-01-27 21:25:57 +000068 return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T);
Chris Lattner5696e7b2008-06-17 18:05:57 +000069}
70
Daniel Dunbarb76b7452009-04-14 02:08:49 +000071const char *VarDecl::getStorageClassSpecifierString(StorageClass SC) {
72 switch (SC) {
73 case VarDecl::None: break;
74 case VarDecl::Auto: return "auto"; break;
75 case VarDecl::Extern: return "extern"; break;
76 case VarDecl::PrivateExtern: return "__private_extern__"; break;
77 case VarDecl::Register: return "register"; break;
78 case VarDecl::Static: return "static"; break;
79 }
80
81 assert(0 && "Invalid storage class");
82 return 0;
83}
84
Chris Lattnerbec41342008-04-22 18:39:57 +000085ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerc5ffed42008-04-04 06:12:32 +000086 SourceLocation L, IdentifierInfo *Id,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +000087 QualType T, DeclaratorInfo *DInfo,
88 StorageClass S, Expr *DefArg) {
89 return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, DInfo, S, DefArg);
Fariborz Jahaniana0befc02008-12-20 23:29:59 +000090}
91
92QualType ParmVarDecl::getOriginalType() const {
Douglas Gregor8bd3c2e2009-02-02 23:39:07 +000093 if (const OriginalParmVarDecl *PVD =
94 dyn_cast<OriginalParmVarDecl>(this))
Fariborz Jahaniana0befc02008-12-20 23:29:59 +000095 return PVD->OriginalType;
96 return getType();
Chris Lattner4b08ca82008-03-15 21:10:16 +000097}
98
Douglas Gregor31cf12c2009-05-26 18:54:04 +000099void VarDecl::setInit(ASTContext &C, Expr *I) {
100 if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) {
101 Eval->~EvaluatedStmt();
102 C.Deallocate(Eval);
103 }
104
105 Init = I;
106 }
107
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000108bool VarDecl::isExternC(ASTContext &Context) const {
109 if (!Context.getLangOptions().CPlusPlus)
110 return (getDeclContext()->isTranslationUnit() &&
111 getStorageClass() != Static) ||
112 (getDeclContext()->isFunctionOrMethod() && hasExternalStorage());
113
114 for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit();
115 DC = DC->getParent()) {
116 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
117 if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
118 return getStorageClass() != Static;
119
120 break;
121 }
122
123 if (DC->isFunctionOrMethod())
124 return false;
125 }
126
127 return false;
128}
129
Douglas Gregor8bd3c2e2009-02-02 23:39:07 +0000130OriginalParmVarDecl *OriginalParmVarDecl::Create(
Fariborz Jahanian7664ffb2008-12-20 20:56:12 +0000131 ASTContext &C, DeclContext *DC,
132 SourceLocation L, IdentifierInfo *Id,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000133 QualType T, DeclaratorInfo *DInfo,
134 QualType OT, StorageClass S, Expr *DefArg) {
135 return new (C) OriginalParmVarDecl(DC, L, Id, T, DInfo, OT, S, DefArg);
Fariborz Jahanian7664ffb2008-12-20 20:56:12 +0000136}
137
Chris Lattnerbec41342008-04-22 18:39:57 +0000138FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000139 SourceLocation L,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000140 DeclarationName N, QualType T,
141 DeclaratorInfo *DInfo,
Chris Lattner5072bae2008-03-15 21:24:04 +0000142 StorageClass S, bool isInline,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000143 bool hasWrittenPrototype) {
Douglas Gregor739ef0c2009-02-25 16:33:18 +0000144 FunctionDecl *New
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000145 = new (C) FunctionDecl(Function, DC, L, N, T, DInfo, S, isInline);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000146 New->HasWrittenPrototype = hasWrittenPrototype;
Douglas Gregor739ef0c2009-02-25 16:33:18 +0000147 return New;
Chris Lattner5072bae2008-03-15 21:24:04 +0000148}
149
Steve Naroff1d95e5a2008-10-10 01:28:17 +0000150BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000151 return new (C) BlockDecl(DC, L);
Steve Naroff415d3d52008-10-08 17:01:13 +0000152}
153
Douglas Gregor91f84212008-12-11 16:49:14 +0000154FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000155 IdentifierInfo *Id, QualType T,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000156 DeclaratorInfo *DInfo, Expr *BW, bool Mutable) {
157 return new (C) FieldDecl(Decl::Field, DC, L, Id, T, DInfo, BW, Mutable);
Chris Lattneree1284a2008-03-16 00:16:02 +0000158}
159
Douglas Gregorf4d33272009-01-07 19:46:03 +0000160bool FieldDecl::isAnonymousStructOrUnion() const {
161 if (!isImplicit() || getDeclName())
162 return false;
163
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000164 if (const RecordType *Record = getType()->getAs<RecordType>())
Douglas Gregorf4d33272009-01-07 19:46:03 +0000165 return Record->getDecl()->isAnonymousStructOrUnion();
166
167 return false;
168}
Chris Lattner5072bae2008-03-15 21:24:04 +0000169
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000170EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
171 SourceLocation L,
Chris Lattner96c460d2008-03-15 21:32:50 +0000172 IdentifierInfo *Id, QualType T,
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000173 Expr *E, const llvm::APSInt &V) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000174 return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
Chris Lattnera7b32872008-03-15 06:12:44 +0000175}
176
Ted Kremenek78aa98f2008-05-20 04:49:55 +0000177void EnumConstantDecl::Destroy(ASTContext& C) {
178 if (Init) Init->Destroy(C);
179 Decl::Destroy(C);
180}
181
Chris Lattnerbec41342008-04-22 18:39:57 +0000182TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000183 SourceLocation L,
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000184 IdentifierInfo *Id, QualType T) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000185 return new (C) TypedefDecl(DC, L, Id, T);
Chris Lattnera7b32872008-03-15 06:12:44 +0000186}
187
Chris Lattnerbec41342008-04-22 18:39:57 +0000188EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000189 IdentifierInfo *Id, SourceLocation TKL,
Douglas Gregorc811d8f2008-12-15 16:32:14 +0000190 EnumDecl *PrevDecl) {
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000191 EnumDecl *Enum = new (C) EnumDecl(DC, L, Id, PrevDecl, TKL);
Douglas Gregorc811d8f2008-12-15 16:32:14 +0000192 C.getTypeDeclType(Enum, PrevDecl);
193 return Enum;
Chris Lattnera7b32872008-03-15 06:12:44 +0000194}
195
Ted Kremenek123f0252008-09-02 20:13:32 +0000196void EnumDecl::Destroy(ASTContext& C) {
Ted Kremenek123f0252008-09-02 20:13:32 +0000197 Decl::Destroy(C);
198}
199
Douglas Gregor91f84212008-12-11 16:49:14 +0000200void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) {
201 assert(!isDefinition() && "Cannot redefine enums!");
Douglas Gregor91f84212008-12-11 16:49:14 +0000202 IntegerType = NewType;
Douglas Gregordee1be82009-01-17 00:42:38 +0000203 TagDecl::completeDefinition();
Douglas Gregor91f84212008-12-11 16:49:14 +0000204}
205
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000206FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000207 SourceLocation L,
Chris Lattneree1284a2008-03-16 00:16:02 +0000208 StringLiteral *Str) {
Steve Naroff13ae6f42009-01-27 21:25:57 +0000209 return new (C) FileScopeAsmDecl(DC, L, Str);
Chris Lattneree1284a2008-03-16 00:16:02 +0000210}
211
Chris Lattnera7b32872008-03-15 06:12:44 +0000212//===----------------------------------------------------------------------===//
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000213// NamedDecl Implementation
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +0000214//===----------------------------------------------------------------------===//
215
Douglas Gregor2ada0482009-02-04 17:27:36 +0000216std::string NamedDecl::getQualifiedNameAsString() const {
217 std::vector<std::string> Names;
218 std::string QualName;
219 const DeclContext *Ctx = getDeclContext();
220
221 if (Ctx->isFunctionOrMethod())
222 return getNameAsString();
223
224 while (Ctx) {
225 if (Ctx->isFunctionOrMethod())
226 // FIXME: That probably will happen, when D was member of local
227 // scope class/struct/union. How do we handle this case?
228 break;
229
Douglas Gregor85673582009-05-18 17:01:57 +0000230 if (const ClassTemplateSpecializationDecl *Spec
231 = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
232 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
Chris Lattnerc61089a2009-06-30 01:26:17 +0000233 PrintingPolicy Policy(getASTContext().getLangOptions());
Douglas Gregor85673582009-05-18 17:01:57 +0000234 std::string TemplateArgsStr
235 = TemplateSpecializationType::PrintTemplateArgumentList(
236 TemplateArgs.getFlatArgumentList(),
Douglas Gregor7de59662009-05-29 20:38:28 +0000237 TemplateArgs.flat_size(),
238 Policy);
Douglas Gregor85673582009-05-18 17:01:57 +0000239 Names.push_back(Spec->getIdentifier()->getName() + TemplateArgsStr);
240 } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
Douglas Gregor2ada0482009-02-04 17:27:36 +0000241 Names.push_back(ND->getNameAsString());
242 else
243 break;
244
245 Ctx = Ctx->getParent();
246 }
247
248 std::vector<std::string>::reverse_iterator
249 I = Names.rbegin(),
250 End = Names.rend();
251
252 for (; I!=End; ++I)
253 QualName += *I + "::";
254
255 QualName += getNameAsString();
256
257 return QualName;
258}
259
260
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000261bool NamedDecl::declarationReplaces(NamedDecl *OldD) const {
Douglas Gregor8b9ccca2008-12-23 21:05:05 +0000262 assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
263
Douglas Gregor889ceb72009-02-03 19:21:40 +0000264 // UsingDirectiveDecl's are not really NamedDecl's, and all have same name.
265 // We want to keep it, unless it nominates same namespace.
266 if (getKind() == Decl::UsingDirective) {
267 return cast<UsingDirectiveDecl>(this)->getNominatedNamespace() ==
268 cast<UsingDirectiveDecl>(OldD)->getNominatedNamespace();
269 }
270
Douglas Gregor8b9ccca2008-12-23 21:05:05 +0000271 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
272 // For function declarations, we keep track of redeclarations.
273 return FD->getPreviousDeclaration() == OldD;
274
Douglas Gregorad3f2fc2009-06-25 22:08:12 +0000275 // For function templates, the underlying function declarations are linked.
276 if (const FunctionTemplateDecl *FunctionTemplate
277 = dyn_cast<FunctionTemplateDecl>(this))
278 if (const FunctionTemplateDecl *OldFunctionTemplate
279 = dyn_cast<FunctionTemplateDecl>(OldD))
280 return FunctionTemplate->getTemplatedDecl()
281 ->declarationReplaces(OldFunctionTemplate->getTemplatedDecl());
282
Steve Naroffc4173fa2009-02-22 19:35:57 +0000283 // For method declarations, we keep track of redeclarations.
284 if (isa<ObjCMethodDecl>(this))
285 return false;
286
Douglas Gregor8b9ccca2008-12-23 21:05:05 +0000287 // For non-function declarations, if the declarations are of the
288 // same kind then this must be a redeclaration, or semantic analysis
289 // would not have given us the new declaration.
290 return this->getKind() == OldD->getKind();
291}
292
Douglas Gregoreddf4332009-02-24 20:03:32 +0000293bool NamedDecl::hasLinkage() const {
294 if (const VarDecl *VD = dyn_cast<VarDecl>(this))
295 return VD->hasExternalStorage() || VD->isFileVarDecl();
296
297 if (isa<FunctionDecl>(this) && !isa<CXXMethodDecl>(this))
298 return true;
299
300 return false;
301}
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000302
Anders Carlsson6915bf62009-06-26 06:29:23 +0000303NamedDecl *NamedDecl::getUnderlyingDecl() {
304 NamedDecl *ND = this;
305 while (true) {
306 if (UsingDecl *UD = dyn_cast<UsingDecl>(ND))
307 ND = UD->getTargetDecl();
308 else if (ObjCCompatibleAliasDecl *AD
309 = dyn_cast<ObjCCompatibleAliasDecl>(ND))
310 return AD->getClassInterface();
311 else
312 return ND;
313 }
314}
315
Argyrios Kyrtzidis9e59b572008-11-09 23:41:00 +0000316//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000317// DeclaratorDecl Implementation
318//===----------------------------------------------------------------------===//
319
320SourceLocation DeclaratorDecl::getTypeSpecStartLoc() const {
321 if (DeclInfo)
322 return DeclInfo->getTypeLoc().getTypeSpecRange().getBegin();
323 return SourceLocation();
324}
325
326//===----------------------------------------------------------------------===//
Nuno Lopes394ec982008-12-17 23:39:55 +0000327// VarDecl Implementation
328//===----------------------------------------------------------------------===//
329
Douglas Gregor6e6ad602009-01-20 01:17:11 +0000330VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +0000331 IdentifierInfo *Id, QualType T, DeclaratorInfo *DInfo,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +0000332 StorageClass S) {
333 return new (C) VarDecl(Var, DC, L, Id, T, DInfo, S);
Nuno Lopes394ec982008-12-17 23:39:55 +0000334}
335
336void VarDecl::Destroy(ASTContext& C) {
Sebastian Redl0fb63472009-02-05 15:12:41 +0000337 Expr *Init = getInit();
Douglas Gregor31cf12c2009-05-26 18:54:04 +0000338 if (Init) {
Sebastian Redl0fb63472009-02-05 15:12:41 +0000339 Init->Destroy(C);
Douglas Gregor31cf12c2009-05-26 18:54:04 +0000340 if (EvaluatedStmt *Eval = this->Init.dyn_cast<EvaluatedStmt *>()) {
341 Eval->~EvaluatedStmt();
342 C.Deallocate(Eval);
343 }
344 }
Nuno Lopes394ec982008-12-17 23:39:55 +0000345 this->~VarDecl();
Steve Naroff13ae6f42009-01-27 21:25:57 +0000346 C.Deallocate((void *)this);
Nuno Lopes394ec982008-12-17 23:39:55 +0000347}
348
349VarDecl::~VarDecl() {
Nuno Lopes394ec982008-12-17 23:39:55 +0000350}
351
Argyrios Kyrtzidisa3aeb5a2009-06-20 08:09:14 +0000352SourceRange VarDecl::getSourceRange() const {
353 if (getInit())
354 return SourceRange(getLocation(), getInit()->getLocEnd());
355 return SourceRange(getLocation(), getLocation());
356}
357
Douglas Gregora6ef8f02009-07-24 20:34:43 +0000358VarDecl *VarDecl::getInstantiatedFromStaticDataMember() {
359 return getASTContext().getInstantiatedFromStaticDataMember(this);
360}
361
Douglas Gregor0760fa12009-03-10 23:43:53 +0000362bool VarDecl::isTentativeDefinition(ASTContext &Context) const {
363 if (!isFileVarDecl() || Context.getLangOptions().CPlusPlus)
364 return false;
365
Douglas Gregorbeecd582009-04-21 17:11:58 +0000366 const VarDecl *Def = 0;
367 return (!getDefinition(Def) &&
Douglas Gregor0760fa12009-03-10 23:43:53 +0000368 (getStorageClass() == None || getStorageClass() == Static));
369}
370
Ted Kremenekdfd72c22009-03-20 21:35:28 +0000371const Expr *VarDecl::getDefinition(const VarDecl *&Def) const {
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000372 redecl_iterator I = redecls_begin(), E = redecls_end();
373 while (I != E && !I->getInit())
374 ++I;
Douglas Gregor0760fa12009-03-10 23:43:53 +0000375
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000376 if (I != E) {
377 Def = *I;
378 return I->getInit();
379 }
380 return 0;
Douglas Gregor0760fa12009-03-10 23:43:53 +0000381}
382
Argyrios Kyrtzidis5614aef2009-07-18 00:34:07 +0000383VarDecl *VarDecl::getCanonicalDecl() {
Argyrios Kyrtzidisfad334c2009-07-18 08:50:13 +0000384 return getFirstDeclaration();
Argyrios Kyrtzidis02dd4f92009-07-05 22:21:56 +0000385}
386
Nuno Lopes394ec982008-12-17 23:39:55 +0000387//===----------------------------------------------------------------------===//
Chris Lattner59a25942008-03-31 00:36:02 +0000388// FunctionDecl Implementation
389//===----------------------------------------------------------------------===//
390
Ted Kremenekce20e8f2008-05-20 00:43:19 +0000391void FunctionDecl::Destroy(ASTContext& C) {
Douglas Gregor3c3aa612009-04-18 00:07:54 +0000392 if (Body && Body.isOffset())
393 Body.get(C.getExternalSource())->Destroy(C);
Ted Kremenekfa8a09e2008-05-20 03:56:00 +0000394
395 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
396 (*I)->Destroy(C);
Nuno Lopes9018ca72009-01-18 19:57:27 +0000397
Steve Naroff13ae6f42009-01-27 21:25:57 +0000398 C.Deallocate(ParamInfo);
Nuno Lopes9018ca72009-01-18 19:57:27 +0000399
Ted Kremenekce20e8f2008-05-20 00:43:19 +0000400 Decl::Destroy(C);
401}
402
403
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000404Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000405 for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
406 if (I->Body) {
407 Definition = *I;
408 return I->Body.get(getASTContext().getExternalSource());
Douglas Gregor89f238c2008-04-21 02:02:58 +0000409 }
410 }
411
412 return 0;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000413}
414
Sebastian Redla7b98a72009-04-26 20:35:05 +0000415Stmt *FunctionDecl::getBodyIfAvailable() const {
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000416 for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
417 if (I->Body && !I->Body.isOffset()) {
418 return I->Body.get(0);
Douglas Gregor3c3aa612009-04-18 00:07:54 +0000419 }
Douglas Gregore3dcb2d2009-04-18 00:02:19 +0000420 }
421
422 return 0;
423}
424
Argyrios Kyrtzidisa3aeb5a2009-06-20 08:09:14 +0000425void FunctionDecl::setBody(Stmt *B) {
426 Body = B;
Argyrios Kyrtzidis49abd4d2009-06-22 17:13:31 +0000427 if (B)
Argyrios Kyrtzidisa3aeb5a2009-06-20 08:09:14 +0000428 EndRangeLoc = B->getLocEnd();
429}
430
John McCalldeb84482009-08-15 02:09:25 +0000431bool FunctionDecl::isMain(ASTContext &Context) const {
432 return !Context.getLangOptions().Freestanding &&
433 getDeclContext()->getLookupContext()->isTranslationUnit() &&
Douglas Gregore62c0a42009-02-24 01:23:02 +0000434 getIdentifier() && getIdentifier()->isStr("main");
435}
436
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000437bool FunctionDecl::isExternC(ASTContext &Context) const {
438 // In C, any non-static, non-overloadable function has external
439 // linkage.
440 if (!Context.getLangOptions().CPlusPlus)
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000441 return getStorageClass() != Static && !getAttr<OverloadableAttr>();
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000442
443 for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit();
444 DC = DC->getParent()) {
445 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
446 if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
Douglas Gregor78bd61f2009-06-18 16:11:24 +0000447 return getStorageClass() != Static &&
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000448 !getAttr<OverloadableAttr>();
Douglas Gregor5a80bd12009-03-02 00:19:53 +0000449
450 break;
451 }
452 }
453
454 return false;
455}
456
Douglas Gregorf1b876d2009-03-31 16:35:03 +0000457bool FunctionDecl::isGlobal() const {
458 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(this))
459 return Method->isStatic();
460
461 if (getStorageClass() == Static)
462 return false;
463
464 for (const DeclContext *DC = getDeclContext();
465 DC->isNamespace();
466 DC = DC->getParent()) {
467 if (const NamespaceDecl *Namespace = cast<NamespaceDecl>(DC)) {
468 if (!Namespace->getDeclName())
469 return false;
470 break;
471 }
472 }
473
474 return true;
475}
476
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000477/// \brief Returns a value indicating whether this function
478/// corresponds to a builtin function.
479///
480/// The function corresponds to a built-in function if it is
481/// declared at translation scope or within an extern "C" block and
482/// its name matches with the name of a builtin. The returned value
483/// will be 0 for functions that do not correspond to a builtin, a
484/// value of type \c Builtin::ID if in the target-independent range
485/// \c [1,Builtin::First), or a target-specific builtin value.
Douglas Gregore711f702009-02-14 18:57:46 +0000486unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const {
487 if (!getIdentifier() || !getIdentifier()->getBuiltinID())
488 return 0;
489
490 unsigned BuiltinID = getIdentifier()->getBuiltinID();
491 if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
492 return BuiltinID;
493
494 // This function has the name of a known C library
495 // function. Determine whether it actually refers to the C library
496 // function or whether it just has the same name.
497
Douglas Gregora908e7f2009-02-17 03:23:10 +0000498 // If this is a static function, it's not a builtin.
499 if (getStorageClass() == Static)
500 return 0;
501
Douglas Gregore711f702009-02-14 18:57:46 +0000502 // If this function is at translation-unit scope and we're not in
503 // C++, it refers to the C library function.
504 if (!Context.getLangOptions().CPlusPlus &&
505 getDeclContext()->isTranslationUnit())
506 return BuiltinID;
507
508 // If the function is in an extern "C" linkage specification and is
509 // not marked "overloadable", it's the real function.
510 if (isa<LinkageSpecDecl>(getDeclContext()) &&
511 cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
512 == LinkageSpecDecl::lang_c &&
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000513 !getAttr<OverloadableAttr>())
Douglas Gregore711f702009-02-14 18:57:46 +0000514 return BuiltinID;
515
516 // Not a builtin
Douglas Gregorb9063fc2009-02-13 23:20:09 +0000517 return 0;
518}
519
520
Chris Lattner47c0d002009-04-25 06:03:53 +0000521/// getNumParams - Return the number of parameters this function must have
Chris Lattner9af40c12009-04-25 06:12:16 +0000522/// based on its FunctionType. This is the length of the PararmInfo array
Chris Lattner47c0d002009-04-25 06:03:53 +0000523/// after it has been created.
524unsigned FunctionDecl::getNumParams() const {
Chris Lattnerdfd637f22009-04-25 05:56:45 +0000525 const FunctionType *FT = getType()->getAsFunctionType();
Douglas Gregordeaad8c2009-02-26 23:50:07 +0000526 if (isa<FunctionNoProtoType>(FT))
Chris Lattner88f70d62008-03-15 05:43:15 +0000527 return 0;
Douglas Gregordeaad8c2009-02-26 23:50:07 +0000528 return cast<FunctionProtoType>(FT)->getNumArgs();
Chris Lattnerdfd637f22009-04-25 05:56:45 +0000529
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000530}
531
Ted Kremenek4ba36fc2009-01-14 00:42:25 +0000532void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
533 unsigned NumParams) {
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000534 assert(ParamInfo == 0 && "Already has param info!");
Chris Lattner9af40c12009-04-25 06:12:16 +0000535 assert(NumParams == getNumParams() && "Parameter count mismatch!");
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000536
Chris Lattner8f5bf2f2007-01-21 19:04:10 +0000537 // Zero params -> null pointer.
538 if (NumParams) {
Steve Naroff99c0cdf2009-01-27 23:20:32 +0000539 void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
Ted Kremenek4ba36fc2009-01-14 00:42:25 +0000540 ParamInfo = new (Mem) ParmVarDecl*[NumParams];
Chris Lattner53621a52007-06-13 20:44:40 +0000541 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
Argyrios Kyrtzidisa3aeb5a2009-06-20 08:09:14 +0000542
Argyrios Kyrtzidis53aeec32009-06-23 00:42:00 +0000543 // Update source range. The check below allows us to set EndRangeLoc before
544 // setting the parameters.
Argyrios Kyrtzidisdfc5dca2009-06-23 00:42:15 +0000545 if (EndRangeLoc.isInvalid() || EndRangeLoc == getLocation())
Argyrios Kyrtzidisa3aeb5a2009-06-20 08:09:14 +0000546 EndRangeLoc = NewParamInfo[NumParams-1]->getLocEnd();
Chris Lattner8f5bf2f2007-01-21 19:04:10 +0000547 }
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000548}
Chris Lattner41943152007-01-25 04:52:46 +0000549
Chris Lattner58258242008-04-10 02:22:51 +0000550/// getMinRequiredArguments - Returns the minimum number of arguments
551/// needed to call this function. This may be fewer than the number of
552/// function parameters, if some of the parameters have default
Chris Lattnerb0d38442008-04-12 23:52:44 +0000553/// arguments (in C++).
Chris Lattner58258242008-04-10 02:22:51 +0000554unsigned FunctionDecl::getMinRequiredArguments() const {
555 unsigned NumRequiredArgs = getNumParams();
556 while (NumRequiredArgs > 0
Anders Carlsson85446472009-06-06 04:14:07 +0000557 && getParamDecl(NumRequiredArgs-1)->hasDefaultArg())
Chris Lattner58258242008-04-10 02:22:51 +0000558 --NumRequiredArgs;
559
560 return NumRequiredArgs;
561}
562
Douglas Gregor78bd61f2009-06-18 16:11:24 +0000563bool FunctionDecl::hasActiveGNUInlineAttribute(ASTContext &Context) const {
Argyrios Kyrtzidisb4b64ca2009-06-30 02:34:44 +0000564 if (!isInline() || !hasAttr<GNUInlineAttr>())
Douglas Gregor76fe50c2009-04-28 06:37:30 +0000565 return false;
566
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000567 for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I)
568 if (I->isInline() && !I->hasAttr<GNUInlineAttr>())
Douglas Gregor76fe50c2009-04-28 06:37:30 +0000569 return false;
Douglas Gregor76fe50c2009-04-28 06:37:30 +0000570
571 return true;
572}
573
Douglas Gregor78bd61f2009-06-18 16:11:24 +0000574bool FunctionDecl::isExternGNUInline(ASTContext &Context) const {
575 if (!hasActiveGNUInlineAttribute(Context))
Douglas Gregor76fe50c2009-04-28 06:37:30 +0000576 return false;
577
Argyrios Kyrtzidis1506d9b2009-07-14 03:20:21 +0000578 for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I)
579 if (I->getStorageClass() == Extern && I->hasAttr<GNUInlineAttr>())
Douglas Gregor76fe50c2009-04-28 06:37:30 +0000580 return true;
581
582 return false;
583}
584
Douglas Gregor8f5d4422009-06-29 20:59:39 +0000585void
586FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
Argyrios Kyrtzidis05898da2009-07-18 08:50:35 +0000587 redeclarable_base::setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidisfad334c2009-07-18 08:50:13 +0000588
Douglas Gregor8f5d4422009-06-29 20:59:39 +0000589 if (FunctionTemplateDecl *FunTmpl = getDescribedFunctionTemplate()) {
590 FunctionTemplateDecl *PrevFunTmpl
591 = PrevDecl? PrevDecl->getDescribedFunctionTemplate() : 0;
592 assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch");
593 FunTmpl->setPreviousDeclaration(PrevFunTmpl);
594 }
595}
596
Argyrios Kyrtzidis5614aef2009-07-18 00:34:07 +0000597FunctionDecl *FunctionDecl::getCanonicalDecl() {
Argyrios Kyrtzidisfad334c2009-07-18 08:50:13 +0000598 return getFirstDeclaration();
Argyrios Kyrtzidis02dd4f92009-07-05 22:21:56 +0000599}
600
Douglas Gregor11d0c4c2008-11-06 22:13:31 +0000601/// getOverloadedOperator - Which C++ overloaded operator this
602/// function represents, if any.
603OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
Douglas Gregor163c5852008-11-18 14:39:36 +0000604 if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
605 return getDeclName().getCXXOverloadedOperator();
Douglas Gregor11d0c4c2008-11-06 22:13:31 +0000606 else
607 return OO_None;
608}
609
Douglas Gregor70d83e22009-06-29 17:30:29 +0000610FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const {
611 if (FunctionTemplateSpecializationInfo *Info
612 = TemplateOrSpecialization
613 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
Douglas Gregore8925db2009-06-29 22:39:32 +0000614 return Info->Template.getPointer();
Douglas Gregor70d83e22009-06-29 17:30:29 +0000615 }
616 return 0;
617}
618
619const TemplateArgumentList *
620FunctionDecl::getTemplateSpecializationArgs() const {
621 if (FunctionTemplateSpecializationInfo *Info
622 = TemplateOrSpecialization
623 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
624 return Info->TemplateArguments;
625 }
626 return 0;
627}
628
Douglas Gregor4adbc6d2009-06-26 00:10:03 +0000629void
630FunctionDecl::setFunctionTemplateSpecialization(ASTContext &Context,
631 FunctionTemplateDecl *Template,
Douglas Gregor8f5d4422009-06-29 20:59:39 +0000632 const TemplateArgumentList *TemplateArgs,
633 void *InsertPos) {
Douglas Gregor70d83e22009-06-29 17:30:29 +0000634 FunctionTemplateSpecializationInfo *Info
635 = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
Douglas Gregor4adbc6d2009-06-26 00:10:03 +0000636 if (!Info)
Douglas Gregor70d83e22009-06-29 17:30:29 +0000637 Info = new (Context) FunctionTemplateSpecializationInfo;
Douglas Gregor4adbc6d2009-06-26 00:10:03 +0000638
Douglas Gregor8f5d4422009-06-29 20:59:39 +0000639 Info->Function = this;
Douglas Gregore8925db2009-06-29 22:39:32 +0000640 Info->Template.setPointer(Template);
641 Info->Template.setInt(0); // Implicit instantiation, unless told otherwise
Douglas Gregor4adbc6d2009-06-26 00:10:03 +0000642 Info->TemplateArguments = TemplateArgs;
643 TemplateOrSpecialization = Info;
Douglas Gregor8f5d4422009-06-29 20:59:39 +0000644
645 // Insert this function template specialization into the set of known
646 // function template specialiations.
647 Template->getSpecializations().InsertNode(Info, InsertPos);
Douglas Gregor4adbc6d2009-06-26 00:10:03 +0000648}
649
Douglas Gregore8925db2009-06-29 22:39:32 +0000650bool FunctionDecl::isExplicitSpecialization() const {
651 // FIXME: check this property for explicit specializations of member
652 // functions of class templates.
653 FunctionTemplateSpecializationInfo *Info
654 = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
655 if (!Info)
656 return false;
657
658 return Info->isExplicitSpecialization();
659}
660
661void FunctionDecl::setExplicitSpecialization(bool ES) {
662 // FIXME: set this property for explicit specializations of member functions
663 // of class templates.
664 FunctionTemplateSpecializationInfo *Info
665 = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
666 if (Info)
667 Info->setExplicitSpecialization(ES);
668}
669
Chris Lattner59a25942008-03-31 00:36:02 +0000670//===----------------------------------------------------------------------===//
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000671// TagDecl Implementation
Ted Kremenek21475702008-09-05 17:16:31 +0000672//===----------------------------------------------------------------------===//
673
Argyrios Kyrtzidis575fa052009-07-14 03:17:17 +0000674SourceRange TagDecl::getSourceRange() const {
675 SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000676 return SourceRange(TagKeywordLoc, E);
Argyrios Kyrtzidis575fa052009-07-14 03:17:17 +0000677}
678
Argyrios Kyrtzidis5614aef2009-07-18 00:34:07 +0000679TagDecl* TagDecl::getCanonicalDecl() {
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000680 return getFirstDeclaration();
Argyrios Kyrtzidis5614aef2009-07-18 00:34:07 +0000681}
682
Douglas Gregordee1be82009-01-17 00:42:38 +0000683void TagDecl::startDefinition() {
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000684 if (TagType *TagT = const_cast<TagType *>(TypeForDecl->getAs<TagType>())) {
685 TagT->decl.setPointer(this);
686 TagT->decl.setInt(1);
687 }
Douglas Gregordee1be82009-01-17 00:42:38 +0000688}
689
690void TagDecl::completeDefinition() {
Douglas Gregordee1be82009-01-17 00:42:38 +0000691 IsDefinition = true;
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000692 if (TagType *TagT = const_cast<TagType *>(TypeForDecl->getAs<TagType>())) {
693 assert(TagT->decl.getPointer() == this &&
694 "Attempt to redefine a tag definition?");
695 TagT->decl.setInt(0);
696 }
Douglas Gregordee1be82009-01-17 00:42:38 +0000697}
698
Ted Kremenek21475702008-09-05 17:16:31 +0000699TagDecl* TagDecl::getDefinition(ASTContext& C) const {
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000700 if (isDefinition())
701 return const_cast<TagDecl *>(this);
702
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000703 for (redecl_iterator R = redecls_begin(), REnd = redecls_end();
704 R != REnd; ++R)
705 if (R->isDefinition())
706 return *R;
707
708 return 0;
Ted Kremenek21475702008-09-05 17:16:31 +0000709}
710
711//===----------------------------------------------------------------------===//
Chris Lattner59a25942008-03-31 00:36:02 +0000712// RecordDecl Implementation
713//===----------------------------------------------------------------------===//
Chris Lattner41943152007-01-25 04:52:46 +0000714
Argyrios Kyrtzidis88e1b972008-10-15 00:42:39 +0000715RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000716 IdentifierInfo *Id, RecordDecl *PrevDecl,
717 SourceLocation TKL)
718 : TagDecl(DK, TK, DC, L, Id, PrevDecl, TKL) {
Ted Kremenek52baf502008-09-02 21:12:32 +0000719 HasFlexibleArrayMember = false;
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000720 AnonymousStructOrUnion = false;
Fariborz Jahanian5f21d2f2009-07-08 01:18:33 +0000721 HasObjectMember = false;
Ted Kremenek52baf502008-09-02 21:12:32 +0000722 assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
Ted Kremenek52baf502008-09-02 21:12:32 +0000723}
724
725RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
Ted Kremenek21475702008-09-05 17:16:31 +0000726 SourceLocation L, IdentifierInfo *Id,
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000727 SourceLocation TKL, RecordDecl* PrevDecl) {
Ted Kremenek47923c72008-09-05 01:34:33 +0000728
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000729 RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id, PrevDecl, TKL);
Ted Kremenek21475702008-09-05 17:16:31 +0000730 C.getTypeDeclType(R, PrevDecl);
731 return R;
Ted Kremenek52baf502008-09-02 21:12:32 +0000732}
733
Argyrios Kyrtzidis6bd44af2008-08-08 14:08:55 +0000734RecordDecl::~RecordDecl() {
Argyrios Kyrtzidis6bd44af2008-08-08 14:08:55 +0000735}
736
737void RecordDecl::Destroy(ASTContext& C) {
Argyrios Kyrtzidis6bd44af2008-08-08 14:08:55 +0000738 TagDecl::Destroy(C);
739}
740
Douglas Gregordfcad112009-03-25 15:59:44 +0000741bool RecordDecl::isInjectedClassName() const {
742 return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
743 cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
744}
745
Douglas Gregor91f84212008-12-11 16:49:14 +0000746/// completeDefinition - Notes that the definition of this type is now
747/// complete.
748void RecordDecl::completeDefinition(ASTContext& C) {
Chris Lattner41943152007-01-25 04:52:46 +0000749 assert(!isDefinition() && "Cannot redefine record!");
Douglas Gregordee1be82009-01-17 00:42:38 +0000750 TagDecl::completeDefinition();
Chris Lattner41943152007-01-25 04:52:46 +0000751}
Steve Naroffcc321422007-03-26 23:09:51 +0000752
Steve Naroff415d3d52008-10-08 17:01:13 +0000753//===----------------------------------------------------------------------===//
754// BlockDecl Implementation
755//===----------------------------------------------------------------------===//
756
757BlockDecl::~BlockDecl() {
758}
759
760void BlockDecl::Destroy(ASTContext& C) {
761 if (Body)
762 Body->Destroy(C);
763
764 for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
765 (*I)->Destroy(C);
Ted Kremenek6483bc22009-03-13 23:17:24 +0000766
767 C.Deallocate(ParamInfo);
Steve Naroff415d3d52008-10-08 17:01:13 +0000768 Decl::Destroy(C);
769}
Steve Naroffc4b30e52009-03-13 16:56:44 +0000770
771void BlockDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
772 unsigned NParms) {
773 assert(ParamInfo == 0 && "Already has param info!");
774
775 // Zero params -> null pointer.
776 if (NParms) {
777 NumParams = NParms;
778 void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
779 ParamInfo = new (Mem) ParmVarDecl*[NumParams];
780 memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
781 }
782}
783
784unsigned BlockDecl::getNumParams() const {
785 return NumParams;
786}