Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Decl.cpp - Declaration AST Node Implementation -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Argyrios Kyrtzidis | e184bae | 2008-06-04 13:04:04 +0000 | [diff] [blame] | 10 | // This file implements the Decl subclasses. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Decl.h" |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclCXX.h" |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 19 | #include "clang/AST/Stmt.h" |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 21 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 22 | #include <vector> |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 23 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
Chris Lattner | 0b2b6e1 | 2009-03-04 06:34:08 +0000 | [diff] [blame] | 26 | void Attr::Destroy(ASTContext &C) { |
| 27 | if (Next) { |
| 28 | Next->Destroy(C); |
| 29 | Next = 0; |
| 30 | } |
| 31 | this->~Attr(); |
| 32 | C.Deallocate((void*)this); |
| 33 | } |
| 34 | |
| 35 | |
Chris Lattner | d3b9065 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 37 | // Decl Allocation/Deallocation Method Implementations |
| 38 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 0b2b6e1 | 2009-03-04 06:34:08 +0000 | [diff] [blame] | 40 | |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 41 | TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 42 | return new (C) TranslationUnitDecl(); |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 45 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
| 46 | SourceLocation L, IdentifierInfo *Id) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 47 | return new (C) NamespaceDecl(DC, L, Id); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 50 | void NamespaceDecl::Destroy(ASTContext& C) { |
| 51 | // NamespaceDecl uses "NextDeclarator" to chain namespace declarations |
| 52 | // together. They are all top-level Decls. |
| 53 | |
Ted Kremenek | ebf27b1 | 2008-05-24 15:09:56 +0000 | [diff] [blame] | 54 | this->~NamespaceDecl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 55 | C.Deallocate((void *)this); |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 59 | ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 60 | SourceLocation L, IdentifierInfo *Id, QualType T) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 61 | return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Daniel Dunbar | b286a78 | 2009-04-14 02:08:49 +0000 | [diff] [blame] | 64 | const char *VarDecl::getStorageClassSpecifierString(StorageClass SC) { |
| 65 | switch (SC) { |
| 66 | case VarDecl::None: break; |
| 67 | case VarDecl::Auto: return "auto"; break; |
| 68 | case VarDecl::Extern: return "extern"; break; |
| 69 | case VarDecl::PrivateExtern: return "__private_extern__"; break; |
| 70 | case VarDecl::Register: return "register"; break; |
| 71 | case VarDecl::Static: return "static"; break; |
| 72 | } |
| 73 | |
| 74 | assert(0 && "Invalid storage class"); |
| 75 | return 0; |
| 76 | } |
| 77 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 78 | ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 79 | SourceLocation L, IdentifierInfo *Id, |
| 80 | QualType T, StorageClass S, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 81 | Expr *DefArg) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 82 | return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg); |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | QualType ParmVarDecl::getOriginalType() const { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 86 | if (const OriginalParmVarDecl *PVD = |
| 87 | dyn_cast<OriginalParmVarDecl>(this)) |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 88 | return PVD->OriginalType; |
| 89 | return getType(); |
Chris Lattner | 9e151e1 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Douglas Gregor | 78d1583 | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 92 | void VarDecl::setInit(ASTContext &C, Expr *I) { |
| 93 | if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) { |
| 94 | Eval->~EvaluatedStmt(); |
| 95 | C.Deallocate(Eval); |
| 96 | } |
| 97 | |
| 98 | Init = I; |
| 99 | } |
| 100 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 101 | bool VarDecl::isExternC(ASTContext &Context) const { |
| 102 | if (!Context.getLangOptions().CPlusPlus) |
| 103 | return (getDeclContext()->isTranslationUnit() && |
| 104 | getStorageClass() != Static) || |
| 105 | (getDeclContext()->isFunctionOrMethod() && hasExternalStorage()); |
| 106 | |
| 107 | for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); |
| 108 | DC = DC->getParent()) { |
| 109 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { |
| 110 | if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) |
| 111 | return getStorageClass() != Static; |
| 112 | |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | if (DC->isFunctionOrMethod()) |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | return false; |
| 121 | } |
| 122 | |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 123 | OriginalParmVarDecl *OriginalParmVarDecl::Create( |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 124 | ASTContext &C, DeclContext *DC, |
| 125 | SourceLocation L, IdentifierInfo *Id, |
| 126 | QualType T, QualType OT, StorageClass S, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 127 | Expr *DefArg) { |
Douglas Gregor | 64650af | 2009-02-02 23:39:07 +0000 | [diff] [blame] | 128 | return new (C) OriginalParmVarDecl(DC, L, Id, T, OT, S, DefArg); |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 131 | FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 132 | SourceLocation L, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 133 | DeclarationName N, QualType T, |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 134 | StorageClass S, bool isInline, |
Anders Carlsson | a75e853 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 135 | bool hasWrittenPrototype, |
Steve Naroff | 0eb07bf | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 136 | SourceLocation TypeSpecStartLoc) { |
Douglas Gregor | 2224f84 | 2009-02-25 16:33:18 +0000 | [diff] [blame] | 137 | FunctionDecl *New |
| 138 | = new (C) FunctionDecl(Function, DC, L, N, T, S, isInline, |
| 139 | TypeSpecStartLoc); |
Anders Carlsson | a75e853 | 2009-05-14 21:46:00 +0000 | [diff] [blame] | 140 | New->HasWrittenPrototype = hasWrittenPrototype; |
Douglas Gregor | 2224f84 | 2009-02-25 16:33:18 +0000 | [diff] [blame] | 141 | return New; |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Steve Naroff | 090276f | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 144 | BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 145 | return new (C) BlockDecl(DC, L); |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 148 | FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 149 | IdentifierInfo *Id, QualType T, Expr *BW, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 150 | bool Mutable) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 151 | return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable); |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 154 | bool FieldDecl::isAnonymousStructOrUnion() const { |
| 155 | if (!isImplicit() || getDeclName()) |
| 156 | return false; |
| 157 | |
| 158 | if (const RecordType *Record = getType()->getAsRecordType()) |
| 159 | return Record->getDecl()->isAnonymousStructOrUnion(); |
| 160 | |
| 161 | return false; |
| 162 | } |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 163 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 164 | EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, |
| 165 | SourceLocation L, |
Chris Lattner | c63e660 | 2008-03-15 21:32:50 +0000 | [diff] [blame] | 166 | IdentifierInfo *Id, QualType T, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 167 | Expr *E, const llvm::APSInt &V) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 168 | return new (C) EnumConstantDecl(CD, L, Id, T, E, V); |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 171 | void EnumConstantDecl::Destroy(ASTContext& C) { |
| 172 | if (Init) Init->Destroy(C); |
| 173 | Decl::Destroy(C); |
| 174 | } |
| 175 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 176 | TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 177 | SourceLocation L, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 178 | IdentifierInfo *Id, QualType T) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 179 | return new (C) TypedefDecl(DC, L, Id, T); |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 182 | EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 183 | IdentifierInfo *Id, |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 184 | EnumDecl *PrevDecl) { |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 185 | EnumDecl *Enum = new (C) EnumDecl(DC, L, Id); |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 186 | C.getTypeDeclType(Enum, PrevDecl); |
| 187 | return Enum; |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 190 | void EnumDecl::Destroy(ASTContext& C) { |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 191 | Decl::Destroy(C); |
| 192 | } |
| 193 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 194 | void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { |
| 195 | assert(!isDefinition() && "Cannot redefine enums!"); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 196 | IntegerType = NewType; |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 197 | TagDecl::completeDefinition(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 200 | FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 201 | SourceLocation L, |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 202 | StringLiteral *Str) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 203 | return new (C) FileScopeAsmDecl(DC, L, Str); |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 206 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 207 | // NamedDecl Implementation |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 208 | //===----------------------------------------------------------------------===// |
| 209 | |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 210 | std::string NamedDecl::getQualifiedNameAsString() const { |
| 211 | std::vector<std::string> Names; |
| 212 | std::string QualName; |
| 213 | const DeclContext *Ctx = getDeclContext(); |
| 214 | |
| 215 | if (Ctx->isFunctionOrMethod()) |
| 216 | return getNameAsString(); |
| 217 | |
| 218 | while (Ctx) { |
| 219 | if (Ctx->isFunctionOrMethod()) |
| 220 | // FIXME: That probably will happen, when D was member of local |
| 221 | // scope class/struct/union. How do we handle this case? |
| 222 | break; |
| 223 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 224 | if (const ClassTemplateSpecializationDecl *Spec |
| 225 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 226 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); |
| 227 | std::string TemplateArgsStr |
| 228 | = TemplateSpecializationType::PrintTemplateArgumentList( |
| 229 | TemplateArgs.getFlatArgumentList(), |
| 230 | TemplateArgs.flat_size()); |
| 231 | Names.push_back(Spec->getIdentifier()->getName() + TemplateArgsStr); |
| 232 | } else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx)) |
Douglas Gregor | 47b9a1c | 2009-02-04 17:27:36 +0000 | [diff] [blame] | 233 | Names.push_back(ND->getNameAsString()); |
| 234 | else |
| 235 | break; |
| 236 | |
| 237 | Ctx = Ctx->getParent(); |
| 238 | } |
| 239 | |
| 240 | std::vector<std::string>::reverse_iterator |
| 241 | I = Names.rbegin(), |
| 242 | End = Names.rend(); |
| 243 | |
| 244 | for (; I!=End; ++I) |
| 245 | QualName += *I + "::"; |
| 246 | |
| 247 | QualName += getNameAsString(); |
| 248 | |
| 249 | return QualName; |
| 250 | } |
| 251 | |
| 252 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 253 | bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 254 | assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); |
| 255 | |
Douglas Gregor | 2a3009a | 2009-02-03 19:21:40 +0000 | [diff] [blame] | 256 | // UsingDirectiveDecl's are not really NamedDecl's, and all have same name. |
| 257 | // We want to keep it, unless it nominates same namespace. |
| 258 | if (getKind() == Decl::UsingDirective) { |
| 259 | return cast<UsingDirectiveDecl>(this)->getNominatedNamespace() == |
| 260 | cast<UsingDirectiveDecl>(OldD)->getNominatedNamespace(); |
| 261 | } |
| 262 | |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 263 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 264 | // For function declarations, we keep track of redeclarations. |
| 265 | return FD->getPreviousDeclaration() == OldD; |
| 266 | |
Steve Naroff | 0de21fd | 2009-02-22 19:35:57 +0000 | [diff] [blame] | 267 | // For method declarations, we keep track of redeclarations. |
| 268 | if (isa<ObjCMethodDecl>(this)) |
| 269 | return false; |
| 270 | |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 271 | // For non-function declarations, if the declarations are of the |
| 272 | // same kind then this must be a redeclaration, or semantic analysis |
| 273 | // would not have given us the new declaration. |
| 274 | return this->getKind() == OldD->getKind(); |
| 275 | } |
| 276 | |
Douglas Gregor | d6f7e9d | 2009-02-24 20:03:32 +0000 | [diff] [blame] | 277 | bool NamedDecl::hasLinkage() const { |
| 278 | if (const VarDecl *VD = dyn_cast<VarDecl>(this)) |
| 279 | return VD->hasExternalStorage() || VD->isFileVarDecl(); |
| 280 | |
| 281 | if (isa<FunctionDecl>(this) && !isa<CXXMethodDecl>(this)) |
| 282 | return true; |
| 283 | |
| 284 | return false; |
| 285 | } |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 286 | |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 287 | //===----------------------------------------------------------------------===// |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 288 | // VarDecl Implementation |
| 289 | //===----------------------------------------------------------------------===// |
| 290 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 291 | VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 292 | IdentifierInfo *Id, QualType T, StorageClass S, |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 293 | SourceLocation TypeSpecStartLoc) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 294 | return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | void VarDecl::Destroy(ASTContext& C) { |
Sebastian Redl | df2d3cf | 2009-02-05 15:12:41 +0000 | [diff] [blame] | 298 | Expr *Init = getInit(); |
Douglas Gregor | 78d1583 | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 299 | if (Init) { |
Sebastian Redl | df2d3cf | 2009-02-05 15:12:41 +0000 | [diff] [blame] | 300 | Init->Destroy(C); |
Douglas Gregor | 78d1583 | 2009-05-26 18:54:04 +0000 | [diff] [blame] | 301 | if (EvaluatedStmt *Eval = this->Init.dyn_cast<EvaluatedStmt *>()) { |
| 302 | Eval->~EvaluatedStmt(); |
| 303 | C.Deallocate(Eval); |
| 304 | } |
| 305 | } |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 306 | this->~VarDecl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 307 | C.Deallocate((void *)this); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | VarDecl::~VarDecl() { |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Douglas Gregor | 275a369 | 2009-03-10 23:43:53 +0000 | [diff] [blame] | 313 | bool VarDecl::isTentativeDefinition(ASTContext &Context) const { |
| 314 | if (!isFileVarDecl() || Context.getLangOptions().CPlusPlus) |
| 315 | return false; |
| 316 | |
Douglas Gregor | b6c8c8b | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 317 | const VarDecl *Def = 0; |
| 318 | return (!getDefinition(Def) && |
Douglas Gregor | 275a369 | 2009-03-10 23:43:53 +0000 | [diff] [blame] | 319 | (getStorageClass() == None || getStorageClass() == Static)); |
| 320 | } |
| 321 | |
Ted Kremenek | 082d936 | 2009-03-20 21:35:28 +0000 | [diff] [blame] | 322 | const Expr *VarDecl::getDefinition(const VarDecl *&Def) const { |
Douglas Gregor | 275a369 | 2009-03-10 23:43:53 +0000 | [diff] [blame] | 323 | Def = this; |
| 324 | while (Def && !Def->getInit()) |
| 325 | Def = Def->getPreviousDeclaration(); |
| 326 | |
| 327 | return Def? Def->getInit() : 0; |
| 328 | } |
| 329 | |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 330 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 331 | // FunctionDecl Implementation |
| 332 | //===----------------------------------------------------------------------===// |
| 333 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 334 | void FunctionDecl::Destroy(ASTContext& C) { |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 335 | if (Body && Body.isOffset()) |
| 336 | Body.get(C.getExternalSource())->Destroy(C); |
Ted Kremenek | b65cf41 | 2008-05-20 03:56:00 +0000 | [diff] [blame] | 337 | |
| 338 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 339 | (*I)->Destroy(C); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 340 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 341 | C.Deallocate(ParamInfo); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 342 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 343 | Decl::Destroy(C); |
| 344 | } |
| 345 | |
| 346 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 347 | Stmt *FunctionDecl::getBody(ASTContext &Context, |
| 348 | const FunctionDecl *&Definition) const { |
Douglas Gregor | f009795 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 349 | for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) { |
| 350 | if (FD->Body) { |
| 351 | Definition = FD; |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 352 | return FD->Body.get(Context.getExternalSource()); |
Douglas Gregor | f009795 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 359 | Stmt *FunctionDecl::getBodyIfAvailable() const { |
Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 360 | for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) { |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 361 | if (FD->Body && !FD->Body.isOffset()) { |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 362 | return FD->Body.get(0); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 363 | } |
Douglas Gregor | 7297134 | 2009-04-18 00:02:19 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Douglas Gregor | 04495c8 | 2009-02-24 01:23:02 +0000 | [diff] [blame] | 369 | bool FunctionDecl::isMain() const { |
| 370 | return getDeclContext()->getLookupContext()->isTranslationUnit() && |
| 371 | getIdentifier() && getIdentifier()->isStr("main"); |
| 372 | } |
| 373 | |
Douglas Gregor | 6393519 | 2009-03-02 00:19:53 +0000 | [diff] [blame] | 374 | bool FunctionDecl::isExternC(ASTContext &Context) const { |
| 375 | // In C, any non-static, non-overloadable function has external |
| 376 | // linkage. |
| 377 | if (!Context.getLangOptions().CPlusPlus) |
| 378 | return getStorageClass() != Static && !getAttr<OverloadableAttr>(); |
| 379 | |
| 380 | for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); |
| 381 | DC = DC->getParent()) { |
| 382 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { |
| 383 | if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) |
| 384 | return getStorageClass() != Static && !getAttr<OverloadableAttr>(); |
| 385 | |
| 386 | break; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return false; |
| 391 | } |
| 392 | |
Douglas Gregor | 8499f3f | 2009-03-31 16:35:03 +0000 | [diff] [blame] | 393 | bool FunctionDecl::isGlobal() const { |
| 394 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(this)) |
| 395 | return Method->isStatic(); |
| 396 | |
| 397 | if (getStorageClass() == Static) |
| 398 | return false; |
| 399 | |
| 400 | for (const DeclContext *DC = getDeclContext(); |
| 401 | DC->isNamespace(); |
| 402 | DC = DC->getParent()) { |
| 403 | if (const NamespaceDecl *Namespace = cast<NamespaceDecl>(DC)) { |
| 404 | if (!Namespace->getDeclName()) |
| 405 | return false; |
| 406 | break; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return true; |
| 411 | } |
| 412 | |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 413 | /// \brief Returns a value indicating whether this function |
| 414 | /// corresponds to a builtin function. |
| 415 | /// |
| 416 | /// The function corresponds to a built-in function if it is |
| 417 | /// declared at translation scope or within an extern "C" block and |
| 418 | /// its name matches with the name of a builtin. The returned value |
| 419 | /// will be 0 for functions that do not correspond to a builtin, a |
| 420 | /// value of type \c Builtin::ID if in the target-independent range |
| 421 | /// \c [1,Builtin::First), or a target-specific builtin value. |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 422 | unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const { |
| 423 | if (!getIdentifier() || !getIdentifier()->getBuiltinID()) |
| 424 | return 0; |
| 425 | |
| 426 | unsigned BuiltinID = getIdentifier()->getBuiltinID(); |
| 427 | if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) |
| 428 | return BuiltinID; |
| 429 | |
| 430 | // This function has the name of a known C library |
| 431 | // function. Determine whether it actually refers to the C library |
| 432 | // function or whether it just has the same name. |
| 433 | |
Douglas Gregor | 9add317 | 2009-02-17 03:23:10 +0000 | [diff] [blame] | 434 | // If this is a static function, it's not a builtin. |
| 435 | if (getStorageClass() == Static) |
| 436 | return 0; |
| 437 | |
Douglas Gregor | 3c385e5 | 2009-02-14 18:57:46 +0000 | [diff] [blame] | 438 | // If this function is at translation-unit scope and we're not in |
| 439 | // C++, it refers to the C library function. |
| 440 | if (!Context.getLangOptions().CPlusPlus && |
| 441 | getDeclContext()->isTranslationUnit()) |
| 442 | return BuiltinID; |
| 443 | |
| 444 | // If the function is in an extern "C" linkage specification and is |
| 445 | // not marked "overloadable", it's the real function. |
| 446 | if (isa<LinkageSpecDecl>(getDeclContext()) && |
| 447 | cast<LinkageSpecDecl>(getDeclContext())->getLanguage() |
| 448 | == LinkageSpecDecl::lang_c && |
| 449 | !getAttr<OverloadableAttr>()) |
| 450 | return BuiltinID; |
| 451 | |
| 452 | // Not a builtin |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | |
Chris Lattner | 1ad9b28 | 2009-04-25 06:03:53 +0000 | [diff] [blame] | 457 | /// getNumParams - Return the number of parameters this function must have |
Chris Lattner | 2dbd285 | 2009-04-25 06:12:16 +0000 | [diff] [blame] | 458 | /// based on its FunctionType. This is the length of the PararmInfo array |
Chris Lattner | 1ad9b28 | 2009-04-25 06:03:53 +0000 | [diff] [blame] | 459 | /// after it has been created. |
| 460 | unsigned FunctionDecl::getNumParams() const { |
Chris Lattner | 11ddb7d | 2009-04-25 05:56:45 +0000 | [diff] [blame] | 461 | const FunctionType *FT = getType()->getAsFunctionType(); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 462 | if (isa<FunctionNoProtoType>(FT)) |
Chris Lattner | d3b9065 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 463 | return 0; |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 464 | return cast<FunctionProtoType>(FT)->getNumArgs(); |
Chris Lattner | 11ddb7d | 2009-04-25 05:56:45 +0000 | [diff] [blame] | 465 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 468 | void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, |
| 469 | unsigned NumParams) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 470 | assert(ParamInfo == 0 && "Already has param info!"); |
Chris Lattner | 2dbd285 | 2009-04-25 06:12:16 +0000 | [diff] [blame] | 471 | assert(NumParams == getNumParams() && "Parameter count mismatch!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 472 | |
| 473 | // Zero params -> null pointer. |
| 474 | if (NumParams) { |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame] | 475 | void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams); |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 476 | ParamInfo = new (Mem) ParmVarDecl*[NumParams]; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 477 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 478 | } |
| 479 | } |
| 480 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 481 | /// getMinRequiredArguments - Returns the minimum number of arguments |
| 482 | /// needed to call this function. This may be fewer than the number of |
| 483 | /// function parameters, if some of the parameters have default |
Chris Lattner | 9e97955 | 2008-04-12 23:52:44 +0000 | [diff] [blame] | 484 | /// arguments (in C++). |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 485 | unsigned FunctionDecl::getMinRequiredArguments() const { |
| 486 | unsigned NumRequiredArgs = getNumParams(); |
| 487 | while (NumRequiredArgs > 0 |
| 488 | && getParamDecl(NumRequiredArgs-1)->getDefaultArg()) |
| 489 | --NumRequiredArgs; |
| 490 | |
| 491 | return NumRequiredArgs; |
| 492 | } |
| 493 | |
Douglas Gregor | 9f9bf25 | 2009-04-28 06:37:30 +0000 | [diff] [blame] | 494 | bool FunctionDecl::hasActiveGNUInlineAttribute() const { |
| 495 | if (!isInline() || !hasAttr<GNUInlineAttr>()) |
| 496 | return false; |
| 497 | |
| 498 | for (const FunctionDecl *FD = getPreviousDeclaration(); FD; |
| 499 | FD = FD->getPreviousDeclaration()) { |
| 500 | if (FD->isInline() && !FD->hasAttr<GNUInlineAttr>()) |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | return true; |
| 505 | } |
| 506 | |
| 507 | bool FunctionDecl::isExternGNUInline() const { |
| 508 | if (!hasActiveGNUInlineAttribute()) |
| 509 | return false; |
| 510 | |
| 511 | for (const FunctionDecl *FD = this; FD; FD = FD->getPreviousDeclaration()) |
| 512 | if (FD->getStorageClass() == Extern && FD->hasAttr<GNUInlineAttr>()) |
| 513 | return true; |
| 514 | |
| 515 | return false; |
| 516 | } |
| 517 | |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 518 | /// getOverloadedOperator - Which C++ overloaded operator this |
| 519 | /// function represents, if any. |
| 520 | OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 521 | if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) |
| 522 | return getDeclName().getCXXOverloadedOperator(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 523 | else |
| 524 | return OO_None; |
| 525 | } |
| 526 | |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 527 | //===----------------------------------------------------------------------===// |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 528 | // TagDecl Implementation |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 529 | //===----------------------------------------------------------------------===// |
| 530 | |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 531 | void TagDecl::startDefinition() { |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 532 | TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType()); |
| 533 | TagT->decl.setPointer(this); |
| 534 | TagT->getAsTagType()->decl.setInt(1); |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void TagDecl::completeDefinition() { |
| 538 | assert((!TypeForDecl || |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 539 | TypeForDecl->getAsTagType()->decl.getPointer() == this) && |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 540 | "Attempt to redefine a tag definition?"); |
| 541 | IsDefinition = true; |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 542 | TagType *TagT = const_cast<TagType *>(TypeForDecl->getAsTagType()); |
| 543 | TagT->decl.setPointer(this); |
| 544 | TagT->decl.setInt(0); |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 547 | TagDecl* TagDecl::getDefinition(ASTContext& C) const { |
| 548 | QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this)); |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 549 | TagDecl* D = cast<TagDecl>(T->getAsTagType()->getDecl()); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 550 | return D->isDefinition() ? D : 0; |
| 551 | } |
| 552 | |
| 553 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 554 | // RecordDecl Implementation |
| 555 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 556 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 557 | RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 558 | IdentifierInfo *Id) |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 559 | : TagDecl(DK, TK, DC, L, Id) { |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 560 | HasFlexibleArrayMember = false; |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 561 | AnonymousStructOrUnion = false; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 562 | assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 566 | SourceLocation L, IdentifierInfo *Id, |
| 567 | RecordDecl* PrevDecl) { |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 568 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 569 | RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 570 | C.getTypeDeclType(R, PrevDecl); |
| 571 | return R; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 574 | RecordDecl::~RecordDecl() { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void RecordDecl::Destroy(ASTContext& C) { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 578 | TagDecl::Destroy(C); |
| 579 | } |
| 580 | |
Douglas Gregor | c9b5b40 | 2009-03-25 15:59:44 +0000 | [diff] [blame] | 581 | bool RecordDecl::isInjectedClassName() const { |
| 582 | return isImplicit() && getDeclName() && getDeclContext()->isRecord() && |
| 583 | cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName(); |
| 584 | } |
| 585 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 586 | /// completeDefinition - Notes that the definition of this type is now |
| 587 | /// complete. |
| 588 | void RecordDecl::completeDefinition(ASTContext& C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 589 | assert(!isDefinition() && "Cannot redefine record!"); |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 590 | TagDecl::completeDefinition(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 593 | //===----------------------------------------------------------------------===// |
| 594 | // BlockDecl Implementation |
| 595 | //===----------------------------------------------------------------------===// |
| 596 | |
| 597 | BlockDecl::~BlockDecl() { |
| 598 | } |
| 599 | |
| 600 | void BlockDecl::Destroy(ASTContext& C) { |
| 601 | if (Body) |
| 602 | Body->Destroy(C); |
| 603 | |
| 604 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 605 | (*I)->Destroy(C); |
Ted Kremenek | 879d27a | 2009-03-13 23:17:24 +0000 | [diff] [blame] | 606 | |
| 607 | C.Deallocate(ParamInfo); |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 608 | Decl::Destroy(C); |
| 609 | } |
Steve Naroff | e78b809 | 2009-03-13 16:56:44 +0000 | [diff] [blame] | 610 | |
| 611 | void BlockDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, |
| 612 | unsigned NParms) { |
| 613 | assert(ParamInfo == 0 && "Already has param info!"); |
| 614 | |
| 615 | // Zero params -> null pointer. |
| 616 | if (NParms) { |
| 617 | NumParams = NParms; |
| 618 | void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams); |
| 619 | ParamInfo = new (Mem) ParmVarDecl*[NumParams]; |
| 620 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | unsigned BlockDecl::getNumParams() const { |
| 625 | return NumParams; |
| 626 | } |