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" |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 16 | #include "clang/AST/Stmt.h" |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 19 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Chris Lattner | d3b9065 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 23 | // Decl Allocation/Deallocation Method Implementations |
| 24 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 25 | |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 26 | TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 27 | return new (C) TranslationUnitDecl(); |
Argyrios Kyrtzidis | ef17782 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 30 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
| 31 | SourceLocation L, IdentifierInfo *Id) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 32 | return new (C) NamespaceDecl(DC, L, Id); |
Argyrios Kyrtzidis | 2d1c5d3 | 2008-04-27 13:50:30 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 35 | void NamespaceDecl::Destroy(ASTContext& C) { |
| 36 | // NamespaceDecl uses "NextDeclarator" to chain namespace declarations |
| 37 | // together. They are all top-level Decls. |
| 38 | |
Ted Kremenek | ebf27b1 | 2008-05-24 15:09:56 +0000 | [diff] [blame] | 39 | this->~NamespaceDecl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 40 | C.Deallocate((void *)this); |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 44 | ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 45 | SourceLocation L, IdentifierInfo *Id, QualType T) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 46 | return new (C) ImplicitParamDecl(ImplicitParam, DC, L, Id, T); |
Chris Lattner | 4111024 | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 49 | ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 50 | SourceLocation L, IdentifierInfo *Id, |
| 51 | QualType T, StorageClass S, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 52 | Expr *DefArg) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 53 | return new (C) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg); |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | QualType ParmVarDecl::getOriginalType() const { |
| 57 | if (const ParmVarWithOriginalTypeDecl *PVD = |
| 58 | dyn_cast<ParmVarWithOriginalTypeDecl>(this)) |
| 59 | return PVD->OriginalType; |
| 60 | return getType(); |
Chris Lattner | 9e151e1 | 2008-03-15 21:10:16 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 63 | ParmVarWithOriginalTypeDecl *ParmVarWithOriginalTypeDecl::Create( |
| 64 | ASTContext &C, DeclContext *DC, |
| 65 | SourceLocation L, IdentifierInfo *Id, |
| 66 | QualType T, QualType OT, StorageClass S, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 67 | Expr *DefArg) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 68 | return new (C) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, DefArg); |
Fariborz Jahanian | 73da9e4 | 2008-12-20 20:56:12 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 71 | FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 72 | SourceLocation L, |
Douglas Gregor | 10bd368 | 2008-11-17 22:58:34 +0000 | [diff] [blame] | 73 | DeclarationName N, QualType T, |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 74 | StorageClass S, bool isInline, |
Steve Naroff | 0eb07bf | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 75 | SourceLocation TypeSpecStartLoc) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 76 | return new (C) FunctionDecl(Function, DC, L, N, T, S, isInline, |
Steve Naroff | 0eb07bf | 2008-10-03 00:02:03 +0000 | [diff] [blame] | 77 | TypeSpecStartLoc); |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Steve Naroff | 090276f | 2008-10-10 01:28:17 +0000 | [diff] [blame] | 80 | BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 81 | return new (C) BlockDecl(DC, L); |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 84 | FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 85 | IdentifierInfo *Id, QualType T, Expr *BW, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 86 | bool Mutable) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 87 | return new (C) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable); |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Douglas Gregor | 6b3945f | 2009-01-07 19:46:03 +0000 | [diff] [blame] | 90 | bool FieldDecl::isAnonymousStructOrUnion() const { |
| 91 | if (!isImplicit() || getDeclName()) |
| 92 | return false; |
| 93 | |
| 94 | if (const RecordType *Record = getType()->getAsRecordType()) |
| 95 | return Record->getDecl()->isAnonymousStructOrUnion(); |
| 96 | |
| 97 | return false; |
| 98 | } |
Chris Lattner | a98e58d | 2008-03-15 21:24:04 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 100 | EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, |
| 101 | SourceLocation L, |
Chris Lattner | c63e660 | 2008-03-15 21:32:50 +0000 | [diff] [blame] | 102 | IdentifierInfo *Id, QualType T, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 103 | Expr *E, const llvm::APSInt &V) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 104 | return new (C) EnumConstantDecl(CD, L, Id, T, E, V); |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Ted Kremenek | d1ac17a | 2008-05-20 04:49:55 +0000 | [diff] [blame] | 107 | void EnumConstantDecl::Destroy(ASTContext& C) { |
| 108 | if (Init) Init->Destroy(C); |
| 109 | Decl::Destroy(C); |
| 110 | } |
| 111 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 112 | TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 113 | SourceLocation L, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 114 | IdentifierInfo *Id, QualType T) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 115 | return new (C) TypedefDecl(DC, L, Id, T); |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Chris Lattner | 9fdf9c6 | 2008-04-22 18:39:57 +0000 | [diff] [blame] | 118 | EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 119 | IdentifierInfo *Id, |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 120 | EnumDecl *PrevDecl) { |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame^] | 121 | EnumDecl *Enum = new (C) EnumDecl(DC, L, Id); |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 122 | C.getTypeDeclType(Enum, PrevDecl); |
| 123 | return Enum; |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 126 | void EnumDecl::Destroy(ASTContext& C) { |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 127 | Decl::Destroy(C); |
| 128 | } |
| 129 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 130 | void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { |
| 131 | assert(!isDefinition() && "Cannot redefine enums!"); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 132 | IntegerType = NewType; |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 133 | TagDecl::completeDefinition(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 136 | FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 137 | SourceLocation L, |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 138 | StringLiteral *Str) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 139 | return new (C) FileScopeAsmDecl(DC, L, Str); |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 142 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 143 | // NamedDecl Implementation |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 144 | //===----------------------------------------------------------------------===// |
| 145 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 146 | bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 147 | assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); |
| 148 | |
| 149 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 150 | // For function declarations, we keep track of redeclarations. |
| 151 | return FD->getPreviousDeclaration() == OldD; |
| 152 | |
| 153 | // For non-function declarations, if the declarations are of the |
| 154 | // same kind then this must be a redeclaration, or semantic analysis |
| 155 | // would not have given us the new declaration. |
| 156 | return this->getKind() == OldD->getKind(); |
| 157 | } |
| 158 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 159 | |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 160 | //===----------------------------------------------------------------------===// |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 161 | // VarDecl Implementation |
| 162 | //===----------------------------------------------------------------------===// |
| 163 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 164 | VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 165 | IdentifierInfo *Id, QualType T, StorageClass S, |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 166 | SourceLocation TypeSpecStartLoc) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 167 | return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void VarDecl::Destroy(ASTContext& C) { |
| 171 | this->~VarDecl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 172 | C.Deallocate((void *)this); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | VarDecl::~VarDecl() { |
| 176 | delete getInit(); |
| 177 | } |
| 178 | |
| 179 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 180 | // FunctionDecl Implementation |
| 181 | //===----------------------------------------------------------------------===// |
| 182 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 183 | void FunctionDecl::Destroy(ASTContext& C) { |
Ted Kremenek | b65cf41 | 2008-05-20 03:56:00 +0000 | [diff] [blame] | 184 | if (Body) |
| 185 | Body->Destroy(C); |
| 186 | |
| 187 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 188 | (*I)->Destroy(C); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 189 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 190 | C.Deallocate(ParamInfo); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 191 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 192 | Decl::Destroy(C); |
| 193 | } |
| 194 | |
| 195 | |
Douglas Gregor | f009795 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 196 | Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { |
| 197 | for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) { |
| 198 | if (FD->Body) { |
| 199 | Definition = FD; |
| 200 | return FD->Body; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 207 | // Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams() |
| 208 | static unsigned getNumTypeParams(QualType T) { |
| 209 | const FunctionType *FT = T->getAsFunctionType(); |
Chris Lattner | d8bdba5 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 210 | if (isa<FunctionTypeNoProto>(FT)) |
Chris Lattner | d3b9065 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 211 | return 0; |
Chris Lattner | d8bdba5 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 212 | return cast<FunctionTypeProto>(FT)->getNumArgs(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 215 | unsigned FunctionDecl::getNumParams() const { |
| 216 | // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar; |
| 217 | if (!ParamInfo) |
| 218 | return 0; |
| 219 | |
| 220 | return getNumTypeParams(getType()); |
| 221 | } |
| 222 | |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 223 | void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, |
| 224 | unsigned NumParams) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 225 | assert(ParamInfo == 0 && "Already has param info!"); |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 226 | assert(NumParams == getNumTypeParams(getType()) && |
| 227 | "Parameter count mismatch!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 228 | |
| 229 | // Zero params -> null pointer. |
| 230 | if (NumParams) { |
Steve Naroff | c0ac492 | 2009-01-27 23:20:32 +0000 | [diff] [blame^] | 231 | void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams); |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 232 | ParamInfo = new (Mem) ParmVarDecl*[NumParams]; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 233 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 234 | } |
| 235 | } |
| 236 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 237 | /// getMinRequiredArguments - Returns the minimum number of arguments |
| 238 | /// needed to call this function. This may be fewer than the number of |
| 239 | /// function parameters, if some of the parameters have default |
Chris Lattner | 9e97955 | 2008-04-12 23:52:44 +0000 | [diff] [blame] | 240 | /// arguments (in C++). |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 241 | unsigned FunctionDecl::getMinRequiredArguments() const { |
| 242 | unsigned NumRequiredArgs = getNumParams(); |
| 243 | while (NumRequiredArgs > 0 |
| 244 | && getParamDecl(NumRequiredArgs-1)->getDefaultArg()) |
| 245 | --NumRequiredArgs; |
| 246 | |
| 247 | return NumRequiredArgs; |
| 248 | } |
| 249 | |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 250 | /// getOverloadedOperator - Which C++ overloaded operator this |
| 251 | /// function represents, if any. |
| 252 | OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 253 | if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) |
| 254 | return getDeclName().getCXXOverloadedOperator(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 255 | else |
| 256 | return OO_None; |
| 257 | } |
| 258 | |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 259 | //===----------------------------------------------------------------------===// |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 260 | // TagDecl Implementation |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 261 | //===----------------------------------------------------------------------===// |
| 262 | |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 263 | void TagDecl::startDefinition() { |
| 264 | cast<TagType>(TypeForDecl)->decl.setPointer(this); |
| 265 | cast<TagType>(TypeForDecl)->decl.setInt(1); |
| 266 | } |
| 267 | |
| 268 | void TagDecl::completeDefinition() { |
| 269 | assert((!TypeForDecl || |
| 270 | cast<TagType>(TypeForDecl)->decl.getPointer() == this) && |
| 271 | "Attempt to redefine a tag definition?"); |
| 272 | IsDefinition = true; |
| 273 | cast<TagType>(TypeForDecl)->decl.setPointer(this); |
| 274 | cast<TagType>(TypeForDecl)->decl.setInt(0); |
| 275 | } |
| 276 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 277 | TagDecl* TagDecl::getDefinition(ASTContext& C) const { |
| 278 | QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this)); |
| 279 | TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl()); |
| 280 | return D->isDefinition() ? D : 0; |
| 281 | } |
| 282 | |
| 283 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 284 | // RecordDecl Implementation |
| 285 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 286 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 287 | RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 288 | IdentifierInfo *Id) |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 289 | : TagDecl(DK, TK, DC, L, Id) { |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 290 | HasFlexibleArrayMember = false; |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 291 | AnonymousStructOrUnion = false; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 292 | assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 296 | SourceLocation L, IdentifierInfo *Id, |
| 297 | RecordDecl* PrevDecl) { |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 298 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 299 | RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 300 | C.getTypeDeclType(R, PrevDecl); |
| 301 | return R; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 304 | RecordDecl::~RecordDecl() { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void RecordDecl::Destroy(ASTContext& C) { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 308 | TagDecl::Destroy(C); |
| 309 | } |
| 310 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 311 | /// completeDefinition - Notes that the definition of this type is now |
| 312 | /// complete. |
| 313 | void RecordDecl::completeDefinition(ASTContext& C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 314 | assert(!isDefinition() && "Cannot redefine record!"); |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 315 | TagDecl::completeDefinition(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 318 | //===----------------------------------------------------------------------===// |
| 319 | // BlockDecl Implementation |
| 320 | //===----------------------------------------------------------------------===// |
| 321 | |
| 322 | BlockDecl::~BlockDecl() { |
| 323 | } |
| 324 | |
| 325 | void BlockDecl::Destroy(ASTContext& C) { |
| 326 | if (Body) |
| 327 | Body->Destroy(C); |
| 328 | |
| 329 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 330 | (*I)->Destroy(C); |
| 331 | |
| 332 | Decl::Destroy(C); |
| 333 | } |