Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Decl.cpp - Declaration AST Node Implementation -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 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. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Argiris Kirtzidis | e7dfca1 | 2008-06-04 13:04:04 +0000 | [diff] [blame] | 10 | // This file implements the Decl subclasses. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Decl.h" |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/Stmt.h" |
Nuno Lopes | c98406e | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" |
Ted Kremenek | afdf811 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Chris Lattner | a8344c3 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 23 | // Decl Allocation/Deallocation Method Implementations |
| 24 | //===----------------------------------------------------------------------===// |
Argiris Kirtzidis | 03e6aaf | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 25 | |
Argiris Kirtzidis | d358600 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 26 | TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { |
| 27 | void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>(); |
| 28 | return new (Mem) TranslationUnitDecl(); |
| 29 | } |
| 30 | |
Argiris Kirtzidis | 03e6aaf | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 31 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
| 32 | SourceLocation L, IdentifierInfo *Id) { |
| 33 | void *Mem = C.getAllocator().Allocate<NamespaceDecl>(); |
| 34 | return new (Mem) NamespaceDecl(DC, L, Id); |
| 35 | } |
| 36 | |
Ted Kremenek | 5be4924 | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 37 | void NamespaceDecl::Destroy(ASTContext& C) { |
| 38 | // NamespaceDecl uses "NextDeclarator" to chain namespace declarations |
| 39 | // together. They are all top-level Decls. |
| 40 | |
Ted Kremenek | 0f43384 | 2008-05-24 15:09:56 +0000 | [diff] [blame] | 41 | this->~NamespaceDecl(); |
Ted Kremenek | 5be4924 | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 42 | C.getAllocator().Deallocate((void *)this); |
| 43 | } |
| 44 | |
| 45 | |
Chris Lattner | 8c7c6a1 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 46 | ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, |
| 47 | SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl) { |
| 48 | void *Mem = C.getAllocator().Allocate<ImplicitParamDecl>(); |
| 49 | return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T, PrevDecl); |
| 50 | } |
| 51 | |
Chris Lattner | ef87a20 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 52 | ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 53 | SourceLocation L, IdentifierInfo *Id, |
| 54 | QualType T, StorageClass S, |
Chris Lattner | 3e254fb | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 55 | Expr *DefArg, ScopedDecl *PrevDecl) { |
Chris Lattner | 48d225c | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 56 | void *Mem = C.getAllocator().Allocate<ParmVarDecl>(); |
Fariborz Jahanian | e26cb43 | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 57 | return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg, PrevDecl); |
| 58 | } |
| 59 | |
| 60 | QualType ParmVarDecl::getOriginalType() const { |
| 61 | if (const ParmVarWithOriginalTypeDecl *PVD = |
| 62 | dyn_cast<ParmVarWithOriginalTypeDecl>(this)) |
| 63 | return PVD->OriginalType; |
| 64 | return getType(); |
Chris Lattner | 48d225c | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Fariborz Jahanian | 160e881 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 67 | ParmVarWithOriginalTypeDecl *ParmVarWithOriginalTypeDecl::Create( |
| 68 | ASTContext &C, DeclContext *DC, |
| 69 | SourceLocation L, IdentifierInfo *Id, |
| 70 | QualType T, QualType OT, StorageClass S, |
| 71 | Expr *DefArg, ScopedDecl *PrevDecl) { |
| 72 | void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>(); |
| 73 | return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, |
| 74 | DefArg, PrevDecl); |
| 75 | } |
| 76 | |
Chris Lattner | ef87a20 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 77 | FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 78 | SourceLocation L, |
Douglas Gregor | 6704b31 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 79 | DeclarationName N, QualType T, |
Chris Lattner | 4c7802b | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 80 | StorageClass S, bool isInline, |
Steve Naroff | 71cd776 | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 81 | ScopedDecl *PrevDecl, |
| 82 | SourceLocation TypeSpecStartLoc) { |
Chris Lattner | 4c7802b | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 83 | void *Mem = C.getAllocator().Allocate<FunctionDecl>(); |
Douglas Gregor | 6704b31 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 84 | return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, PrevDecl, |
Steve Naroff | 71cd776 | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 85 | TypeSpecStartLoc); |
Chris Lattner | 4c7802b | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Steve Naroff | 5205938 | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 88 | BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { |
Steve Naroff | 9ac456d | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 89 | void *Mem = C.getAllocator().Allocate<BlockDecl>(); |
Steve Naroff | 5205938 | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 90 | return new (Mem) BlockDecl(DC, L); |
Steve Naroff | 9ac456d | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 93 | FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 94 | IdentifierInfo *Id, QualType T, Expr *BW, |
| 95 | bool Mutable, ScopedDecl *PrevDecl) { |
Chris Lattner | 81db64a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 96 | void *Mem = C.getAllocator().Allocate<FieldDecl>(); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 97 | return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable, PrevDecl); |
Chris Lattner | 81db64a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Douglas Gregor | c7f0161 | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 100 | bool FieldDecl::isAnonymousStructOrUnion() const { |
| 101 | if (!isImplicit() || getDeclName()) |
| 102 | return false; |
| 103 | |
| 104 | if (const RecordType *Record = getType()->getAsRecordType()) |
| 105 | return Record->getDecl()->isAnonymousStructOrUnion(); |
| 106 | |
| 107 | return false; |
| 108 | } |
Chris Lattner | 4c7802b | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 109 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 110 | EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, |
| 111 | SourceLocation L, |
Chris Lattner | 58114f0 | 2008-03-15 21:32:50 +0000 | [diff] [blame] | 112 | IdentifierInfo *Id, QualType T, |
| 113 | Expr *E, const llvm::APSInt &V, |
| 114 | ScopedDecl *PrevDecl){ |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 115 | void *Mem = C.getAllocator().Allocate<EnumConstantDecl>(); |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 116 | return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl); |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Ted Kremenek | 5be4924 | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 119 | void EnumConstantDecl::Destroy(ASTContext& C) { |
| 120 | if (Init) Init->Destroy(C); |
| 121 | Decl::Destroy(C); |
| 122 | } |
| 123 | |
Chris Lattner | ef87a20 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 124 | TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 125 | SourceLocation L, |
Chris Lattner | 58114f0 | 2008-03-15 21:32:50 +0000 | [diff] [blame] | 126 | IdentifierInfo *Id, QualType T, |
| 127 | ScopedDecl *PD) { |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 128 | void *Mem = C.getAllocator().Allocate<TypedefDecl>(); |
Chris Lattner | ef87a20 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 129 | return new (Mem) TypedefDecl(DC, L, Id, T, PD); |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Chris Lattner | ef87a20 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 132 | EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 133 | IdentifierInfo *Id, |
Douglas Gregor | ae64489 | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 134 | EnumDecl *PrevDecl) { |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 135 | void *Mem = C.getAllocator().Allocate<EnumDecl>(); |
Douglas Gregor | ae64489 | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 136 | EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id, 0); |
| 137 | C.getTypeDeclType(Enum, PrevDecl); |
| 138 | return Enum; |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Ted Kremenek | 25d8be1 | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 141 | void EnumDecl::Destroy(ASTContext& C) { |
Ted Kremenek | 25d8be1 | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 142 | Decl::Destroy(C); |
| 143 | } |
| 144 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 145 | void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { |
| 146 | assert(!isDefinition() && "Cannot redefine enums!"); |
| 147 | setDefinition(true); |
| 148 | |
| 149 | IntegerType = NewType; |
| 150 | |
| 151 | // Let ASTContext know that this is the defining EnumDecl for this |
| 152 | // type. |
| 153 | C.setTagDefinition(this); |
| 154 | } |
| 155 | |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 156 | FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, |
| 157 | SourceLocation L, |
Chris Lattner | 81db64a | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 158 | StringLiteral *Str) { |
| 159 | void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>(); |
| 160 | return new (Mem) FileScopeAsmDecl(L, Str); |
| 161 | } |
| 162 | |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 163 | //===----------------------------------------------------------------------===// |
Argiris Kirtzidis | 881964b | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 164 | // ScopedDecl Implementation |
| 165 | //===----------------------------------------------------------------------===// |
| 166 | |
| 167 | void ScopedDecl::setLexicalDeclContext(DeclContext *DC) { |
| 168 | if (DC == getLexicalDeclContext()) |
| 169 | return; |
| 170 | |
| 171 | if (isInSemaDC()) { |
| 172 | MultipleDC *MDC = new MultipleDC(); |
| 173 | MDC->SemanticDC = getDeclContext(); |
| 174 | MDC->LexicalDC = DC; |
| 175 | DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1; |
| 176 | } else { |
| 177 | getMultipleDC()->LexicalDC = DC; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | ScopedDecl::~ScopedDecl() { |
| 182 | if (isOutOfSemaDC()) |
| 183 | delete getMultipleDC(); |
| 184 | } |
| 185 | |
Douglas Gregor | 6e71edc | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 186 | bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const { |
| 187 | assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); |
| 188 | |
| 189 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 190 | // For function declarations, we keep track of redeclarations. |
| 191 | return FD->getPreviousDeclaration() == OldD; |
| 192 | |
| 193 | // For non-function declarations, if the declarations are of the |
| 194 | // same kind then this must be a redeclaration, or semantic analysis |
| 195 | // would not have given us the new declaration. |
| 196 | return this->getKind() == OldD->getKind(); |
| 197 | } |
| 198 | |
Argiris Kirtzidis | 881964b | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 199 | //===----------------------------------------------------------------------===// |
Nuno Lopes | c98406e | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 200 | // VarDecl Implementation |
| 201 | //===----------------------------------------------------------------------===// |
| 202 | |
| 203 | VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, |
| 204 | SourceLocation L, |
| 205 | IdentifierInfo *Id, QualType T, |
| 206 | StorageClass S, ScopedDecl *PrevDecl, |
| 207 | SourceLocation TypeSpecStartLoc) { |
| 208 | void *Mem = C.getAllocator().Allocate<VarDecl>(); |
| 209 | return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc); |
| 210 | } |
| 211 | |
| 212 | void VarDecl::Destroy(ASTContext& C) { |
| 213 | this->~VarDecl(); |
| 214 | C.getAllocator().Deallocate((void *)this); |
| 215 | } |
| 216 | |
| 217 | VarDecl::~VarDecl() { |
| 218 | delete getInit(); |
| 219 | } |
| 220 | |
| 221 | //===----------------------------------------------------------------------===// |
Chris Lattner | c72d22d | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 222 | // FunctionDecl Implementation |
| 223 | //===----------------------------------------------------------------------===// |
| 224 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 225 | FunctionDecl::~FunctionDecl() { |
| 226 | delete[] ParamInfo; |
Douglas Gregor | 42214c5 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Ted Kremenek | afdf811 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 229 | void FunctionDecl::Destroy(ASTContext& C) { |
Ted Kremenek | 345b93d | 2008-05-20 03:56:00 +0000 | [diff] [blame] | 230 | if (Body) |
| 231 | Body->Destroy(C); |
| 232 | |
| 233 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 234 | (*I)->Destroy(C); |
| 235 | |
Ted Kremenek | afdf811 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 236 | Decl::Destroy(C); |
| 237 | } |
| 238 | |
| 239 | |
Douglas Gregor | 42214c5 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 240 | Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { |
| 241 | for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) { |
| 242 | if (FD->Body) { |
| 243 | Definition = FD; |
| 244 | return FD->Body; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Ted Kremenek | a6ded35 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 251 | // Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams() |
| 252 | static unsigned getNumTypeParams(QualType T) { |
| 253 | const FunctionType *FT = T->getAsFunctionType(); |
Chris Lattner | e873359 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 254 | if (isa<FunctionTypeNoProto>(FT)) |
Chris Lattner | a8344c3 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 255 | return 0; |
Chris Lattner | e873359 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 256 | return cast<FunctionTypeProto>(FT)->getNumArgs(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Ted Kremenek | a6ded35 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 259 | unsigned FunctionDecl::getNumParams() const { |
| 260 | // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar; |
| 261 | if (!ParamInfo) |
| 262 | return 0; |
| 263 | |
| 264 | return getNumTypeParams(getType()); |
| 265 | } |
| 266 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 267 | void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { |
| 268 | assert(ParamInfo == 0 && "Already has param info!"); |
Ted Kremenek | a6ded35 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 269 | assert(NumParams == getNumTypeParams(getType()) && |
| 270 | "Parameter count mismatch!"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 271 | |
| 272 | // Zero params -> null pointer. |
| 273 | if (NumParams) { |
| 274 | ParamInfo = new ParmVarDecl*[NumParams]; |
| 275 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 276 | } |
| 277 | } |
| 278 | |
Chris Lattner | 97316c0 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 279 | /// getMinRequiredArguments - Returns the minimum number of arguments |
| 280 | /// needed to call this function. This may be fewer than the number of |
| 281 | /// function parameters, if some of the parameters have default |
Chris Lattner | b1856db | 2008-04-12 23:52:44 +0000 | [diff] [blame] | 282 | /// arguments (in C++). |
Chris Lattner | 97316c0 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 283 | unsigned FunctionDecl::getMinRequiredArguments() const { |
| 284 | unsigned NumRequiredArgs = getNumParams(); |
| 285 | while (NumRequiredArgs > 0 |
| 286 | && getParamDecl(NumRequiredArgs-1)->getDefaultArg()) |
| 287 | --NumRequiredArgs; |
| 288 | |
| 289 | return NumRequiredArgs; |
| 290 | } |
| 291 | |
Douglas Gregor | e60e5d3 | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 292 | /// getOverloadedOperator - Which C++ overloaded operator this |
| 293 | /// function represents, if any. |
| 294 | OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { |
Douglas Gregor | 96a32dd | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 295 | if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) |
| 296 | return getDeclName().getCXXOverloadedOperator(); |
Douglas Gregor | e60e5d3 | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 297 | else |
| 298 | return OO_None; |
| 299 | } |
| 300 | |
Chris Lattner | c72d22d | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 301 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 723d333 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 302 | // TagDecl Implementation |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 303 | //===----------------------------------------------------------------------===// |
| 304 | |
| 305 | TagDecl* TagDecl::getDefinition(ASTContext& C) const { |
| 306 | QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this)); |
| 307 | TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl()); |
| 308 | return D->isDefinition() ? D : 0; |
| 309 | } |
| 310 | |
| 311 | //===----------------------------------------------------------------------===// |
Chris Lattner | c72d22d | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 312 | // RecordDecl Implementation |
| 313 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 314 | |
Argiris Kirtzidis | 2538a8c | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 315 | RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, |
Ted Kremenek | 2c98404 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 316 | IdentifierInfo *Id) |
Douglas Gregor | db568cf | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 317 | : TagDecl(DK, TK, DC, L, Id, 0) { |
Ted Kremenek | 6f0a241 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 318 | HasFlexibleArrayMember = false; |
Douglas Gregor | 723d333 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 319 | AnonymousStructOrUnion = false; |
Ted Kremenek | 6f0a241 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 320 | assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); |
Ted Kremenek | 6f0a241 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 324 | SourceLocation L, IdentifierInfo *Id, |
| 325 | RecordDecl* PrevDecl) { |
Ted Kremenek | 2c98404 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 326 | |
Ted Kremenek | 6f0a241 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 327 | void *Mem = C.getAllocator().Allocate<RecordDecl>(); |
Argiris Kirtzidis | 2538a8c | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 328 | RecordDecl* R = new (Mem) RecordDecl(Record, TK, DC, L, Id); |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 329 | C.getTypeDeclType(R, PrevDecl); |
| 330 | return R; |
Ted Kremenek | 6f0a241 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Argiris Kirtzidis | d64c111 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 333 | RecordDecl::~RecordDecl() { |
Argiris Kirtzidis | d64c111 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | void RecordDecl::Destroy(ASTContext& C) { |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 337 | DeclContext::DestroyDecls(C); |
Argiris Kirtzidis | d64c111 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 338 | TagDecl::Destroy(C); |
| 339 | } |
| 340 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 341 | /// completeDefinition - Notes that the definition of this type is now |
| 342 | /// complete. |
| 343 | void RecordDecl::completeDefinition(ASTContext& C) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 344 | assert(!isDefinition() && "Cannot redefine record!"); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 345 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 346 | setDefinition(true); |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 347 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 348 | // Let ASTContext know that this is the defining RecordDecl for this |
| 349 | // type. |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 350 | C.setTagDefinition(this); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Steve Naroff | 9ac456d | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 353 | //===----------------------------------------------------------------------===// |
| 354 | // BlockDecl Implementation |
| 355 | //===----------------------------------------------------------------------===// |
| 356 | |
| 357 | BlockDecl::~BlockDecl() { |
| 358 | } |
| 359 | |
| 360 | void BlockDecl::Destroy(ASTContext& C) { |
| 361 | if (Body) |
| 362 | Body->Destroy(C); |
| 363 | |
| 364 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 365 | (*I)->Destroy(C); |
| 366 | |
| 367 | Decl::Destroy(C); |
| 368 | } |