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