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) { |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 121 | void *Mem = C.getAllocator().Allocate<EnumDecl>(); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 122 | EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id); |
Douglas Gregor | 7df7b6b | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 123 | C.getTypeDeclType(Enum, PrevDecl); |
| 124 | return Enum; |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 127 | void EnumDecl::Destroy(ASTContext& C) { |
Ted Kremenek | df91eca | 2008-09-02 20:13:32 +0000 | [diff] [blame] | 128 | Decl::Destroy(C); |
| 129 | } |
| 130 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 131 | void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) { |
| 132 | assert(!isDefinition() && "Cannot redefine enums!"); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 133 | IntegerType = NewType; |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 134 | TagDecl::completeDefinition(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 137 | FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC, |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 138 | SourceLocation L, |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 139 | StringLiteral *Str) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame^] | 140 | return new (C) FileScopeAsmDecl(DC, L, Str); |
Chris Lattner | 8e25d86 | 2008-03-16 00:16:02 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Chris Lattner | 6c2b6eb | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 143 | //===----------------------------------------------------------------------===// |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 144 | // NamedDecl Implementation |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 145 | //===----------------------------------------------------------------------===// |
| 146 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 147 | bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { |
Douglas Gregor | 6ed40e3 | 2008-12-23 21:05:05 +0000 | [diff] [blame] | 148 | assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch"); |
| 149 | |
| 150 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) |
| 151 | // For function declarations, we keep track of redeclarations. |
| 152 | return FD->getPreviousDeclaration() == OldD; |
| 153 | |
| 154 | // For non-function declarations, if the declarations are of the |
| 155 | // same kind then this must be a redeclaration, or semantic analysis |
| 156 | // would not have given us the new declaration. |
| 157 | return this->getKind() == OldD->getKind(); |
| 158 | } |
| 159 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 160 | |
Argyrios Kyrtzidis | 5239304 | 2008-11-09 23:41:00 +0000 | [diff] [blame] | 161 | //===----------------------------------------------------------------------===// |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 162 | // VarDecl Implementation |
| 163 | //===----------------------------------------------------------------------===// |
| 164 | |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 165 | VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, |
| 166 | IdentifierInfo *Id, QualType T, StorageClass S, |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 167 | SourceLocation TypeSpecStartLoc) { |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame^] | 168 | return new (C) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void VarDecl::Destroy(ASTContext& C) { |
| 172 | this->~VarDecl(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame^] | 173 | C.Deallocate((void *)this); |
Nuno Lopes | 99f06ba | 2008-12-17 23:39:55 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | VarDecl::~VarDecl() { |
| 177 | delete getInit(); |
| 178 | } |
| 179 | |
| 180 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 181 | // FunctionDecl Implementation |
| 182 | //===----------------------------------------------------------------------===// |
| 183 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 184 | void FunctionDecl::Destroy(ASTContext& C) { |
Ted Kremenek | b65cf41 | 2008-05-20 03:56:00 +0000 | [diff] [blame] | 185 | if (Body) |
| 186 | Body->Destroy(C); |
| 187 | |
| 188 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 189 | (*I)->Destroy(C); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 190 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame^] | 191 | C.Deallocate(ParamInfo); |
Nuno Lopes | 460b0ac | 2009-01-18 19:57:27 +0000 | [diff] [blame] | 192 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 193 | Decl::Destroy(C); |
| 194 | } |
| 195 | |
| 196 | |
Douglas Gregor | f009795 | 2008-04-21 02:02:58 +0000 | [diff] [blame] | 197 | Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const { |
| 198 | for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) { |
| 199 | if (FD->Body) { |
| 200 | Definition = FD; |
| 201 | return FD->Body; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 208 | // Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams() |
| 209 | static unsigned getNumTypeParams(QualType T) { |
| 210 | const FunctionType *FT = T->getAsFunctionType(); |
Chris Lattner | d8bdba5 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 211 | if (isa<FunctionTypeNoProto>(FT)) |
Chris Lattner | d3b9065 | 2008-03-15 05:43:15 +0000 | [diff] [blame] | 212 | return 0; |
Chris Lattner | d8bdba5 | 2008-04-06 23:09:52 +0000 | [diff] [blame] | 213 | return cast<FunctionTypeProto>(FT)->getNumArgs(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 216 | unsigned FunctionDecl::getNumParams() const { |
| 217 | // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar; |
| 218 | if (!ParamInfo) |
| 219 | return 0; |
| 220 | |
| 221 | return getNumTypeParams(getType()); |
| 222 | } |
| 223 | |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 224 | void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, |
| 225 | unsigned NumParams) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 226 | assert(ParamInfo == 0 && "Already has param info!"); |
Ted Kremenek | 4f03fd6 | 2008-10-29 18:41:34 +0000 | [diff] [blame] | 227 | assert(NumParams == getNumTypeParams(getType()) && |
| 228 | "Parameter count mismatch!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 229 | |
| 230 | // Zero params -> null pointer. |
| 231 | if (NumParams) { |
Ted Kremenek | fc76761 | 2009-01-14 00:42:25 +0000 | [diff] [blame] | 232 | void *Mem = C.getAllocator().Allocate<ParmVarDecl*>(NumParams); |
| 233 | ParamInfo = new (Mem) ParmVarDecl*[NumParams]; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 234 | memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams); |
| 235 | } |
| 236 | } |
| 237 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 238 | /// getMinRequiredArguments - Returns the minimum number of arguments |
| 239 | /// needed to call this function. This may be fewer than the number of |
| 240 | /// function parameters, if some of the parameters have default |
Chris Lattner | 9e97955 | 2008-04-12 23:52:44 +0000 | [diff] [blame] | 241 | /// arguments (in C++). |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 242 | unsigned FunctionDecl::getMinRequiredArguments() const { |
| 243 | unsigned NumRequiredArgs = getNumParams(); |
| 244 | while (NumRequiredArgs > 0 |
| 245 | && getParamDecl(NumRequiredArgs-1)->getDefaultArg()) |
| 246 | --NumRequiredArgs; |
| 247 | |
| 248 | return NumRequiredArgs; |
| 249 | } |
| 250 | |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 251 | /// getOverloadedOperator - Which C++ overloaded operator this |
| 252 | /// function represents, if any. |
| 253 | OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 254 | if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) |
| 255 | return getDeclName().getCXXOverloadedOperator(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 256 | else |
| 257 | return OO_None; |
| 258 | } |
| 259 | |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 260 | //===----------------------------------------------------------------------===// |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 261 | // TagDecl Implementation |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 262 | //===----------------------------------------------------------------------===// |
| 263 | |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 264 | void TagDecl::startDefinition() { |
| 265 | cast<TagType>(TypeForDecl)->decl.setPointer(this); |
| 266 | cast<TagType>(TypeForDecl)->decl.setInt(1); |
| 267 | } |
| 268 | |
| 269 | void TagDecl::completeDefinition() { |
| 270 | assert((!TypeForDecl || |
| 271 | cast<TagType>(TypeForDecl)->decl.getPointer() == this) && |
| 272 | "Attempt to redefine a tag definition?"); |
| 273 | IsDefinition = true; |
| 274 | cast<TagType>(TypeForDecl)->decl.setPointer(this); |
| 275 | cast<TagType>(TypeForDecl)->decl.setInt(0); |
| 276 | } |
| 277 | |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 278 | TagDecl* TagDecl::getDefinition(ASTContext& C) const { |
| 279 | QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this)); |
| 280 | TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl()); |
| 281 | return D->isDefinition() ? D : 0; |
| 282 | } |
| 283 | |
| 284 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8a93423 | 2008-03-31 00:36:02 +0000 | [diff] [blame] | 285 | // RecordDecl Implementation |
| 286 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 287 | |
Argyrios Kyrtzidis | 35bc082 | 2008-10-15 00:42:39 +0000 | [diff] [blame] | 288 | RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L, |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 289 | IdentifierInfo *Id) |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 290 | : TagDecl(DK, TK, DC, L, Id) { |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 291 | HasFlexibleArrayMember = false; |
Douglas Gregor | bcbffc4 | 2009-01-07 00:43:41 +0000 | [diff] [blame] | 292 | AnonymousStructOrUnion = false; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 293 | assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!"); |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC, |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 297 | SourceLocation L, IdentifierInfo *Id, |
| 298 | RecordDecl* PrevDecl) { |
Ted Kremenek | df042e6 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 299 | |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame^] | 300 | RecordDecl* R = new (C) RecordDecl(Record, TK, DC, L, Id); |
Ted Kremenek | 4b7c983 | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 301 | C.getTypeDeclType(R, PrevDecl); |
| 302 | return R; |
Ted Kremenek | 6359792 | 2008-09-02 21:12:32 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 305 | RecordDecl::~RecordDecl() { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void RecordDecl::Destroy(ASTContext& C) { |
Argyrios Kyrtzidis | 997b6c6 | 2008-08-08 14:08:55 +0000 | [diff] [blame] | 309 | TagDecl::Destroy(C); |
| 310 | } |
| 311 | |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 312 | /// completeDefinition - Notes that the definition of this type is now |
| 313 | /// complete. |
| 314 | void RecordDecl::completeDefinition(ASTContext& C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 315 | assert(!isDefinition() && "Cannot redefine record!"); |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 316 | TagDecl::completeDefinition(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Steve Naroff | 56ee689 | 2008-10-08 17:01:13 +0000 | [diff] [blame] | 319 | //===----------------------------------------------------------------------===// |
| 320 | // BlockDecl Implementation |
| 321 | //===----------------------------------------------------------------------===// |
| 322 | |
| 323 | BlockDecl::~BlockDecl() { |
| 324 | } |
| 325 | |
| 326 | void BlockDecl::Destroy(ASTContext& C) { |
| 327 | if (Body) |
| 328 | Body->Destroy(C); |
| 329 | |
| 330 | for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I) |
| 331 | (*I)->Destroy(C); |
| 332 | |
| 333 | Decl::Destroy(C); |
| 334 | } |