Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 1 | //===--- SemaTemplateInstantiateDecl.cpp - C++ Template Decl Instantiation ===/ |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | //===----------------------------------------------------------------------===/ |
| 8 | // |
| 9 | // This file implements C++ template instantiation for declarations. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===/ |
| 12 | #include "Sema.h" |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 13 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/DeclTemplate.h" |
| 16 | #include "clang/AST/DeclVisitor.h" |
| 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 18 | #include "clang/Lex/Preprocessor.h" |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Compiler.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | |
| 23 | namespace { |
| 24 | class VISIBILITY_HIDDEN TemplateDeclInstantiator |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 25 | : public DeclVisitor<TemplateDeclInstantiator, Decl *> { |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 26 | Sema &SemaRef; |
| 27 | DeclContext *Owner; |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 28 | const TemplateArgumentList &TemplateArgs; |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 29 | |
| 30 | public: |
| 31 | typedef Sema::OwningExprResult OwningExprResult; |
| 32 | |
| 33 | TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 34 | const TemplateArgumentList &TemplateArgs) |
| 35 | : SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs) { } |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 36 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 37 | // FIXME: Once we get closer to completion, replace these manually-written |
| 38 | // declarations with automatically-generated ones from |
| 39 | // clang/AST/DeclNodes.def. |
Douglas Gregor | 4f722be | 2009-03-25 15:45:12 +0000 | [diff] [blame] | 40 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 41 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 42 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 43 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 44 | Decl *VisitFieldDecl(FieldDecl *D); |
| 45 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
| 46 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 47 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 48 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 49 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 50 | Decl *VisitCXXRecordDecl(CXXRecordDecl *D); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 51 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D, |
| 52 | TemplateParameterList *TemplateParams = 0); |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 53 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 54 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 55 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 56 | ParmVarDecl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 57 | Decl *VisitOriginalParmVarDecl(OriginalParmVarDecl *D); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 58 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 59 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 60 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 61 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 62 | // Base case. FIXME: Remove once we can instantiate everything. |
| 63 | Decl *VisitDecl(Decl *) { |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 64 | assert(false && "Template instantiation of unknown declaration kind!"); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 65 | return 0; |
| 66 | } |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 67 | |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 68 | const LangOptions &getLangOptions() { |
| 69 | return SemaRef.getLangOptions(); |
| 70 | } |
| 71 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 72 | // Helper functions for instantiating methods. |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 73 | QualType SubstFunctionType(FunctionDecl *D, |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 74 | llvm::SmallVectorImpl<ParmVarDecl *> &Params); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 75 | bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 76 | bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 77 | |
| 78 | TemplateParameterList * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 79 | SubstTemplateParams(TemplateParameterList *List); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 80 | }; |
| 81 | } |
| 82 | |
Douglas Gregor | 4f722be | 2009-03-25 15:45:12 +0000 | [diff] [blame] | 83 | Decl * |
| 84 | TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 85 | assert(false && "Translation units cannot be instantiated"); |
| 86 | return D; |
| 87 | } |
| 88 | |
| 89 | Decl * |
| 90 | TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { |
| 91 | assert(false && "Namespaces cannot be instantiated"); |
| 92 | return D; |
| 93 | } |
| 94 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 95 | Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { |
| 96 | bool Invalid = false; |
| 97 | QualType T = D->getUnderlyingType(); |
| 98 | if (T->isDependentType()) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 99 | T = SemaRef.SubstType(T, TemplateArgs, |
| 100 | D->getLocation(), D->getDeclName()); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 101 | if (T.isNull()) { |
| 102 | Invalid = true; |
| 103 | T = SemaRef.Context.IntTy; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Create the new typedef |
| 108 | TypedefDecl *Typedef |
| 109 | = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 110 | D->getIdentifier(), T); |
| 111 | if (Invalid) |
| 112 | Typedef->setInvalidDecl(); |
| 113 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 114 | Owner->addDecl(Typedef); |
Douglas Gregor | bc22163 | 2009-05-28 16:34:51 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 116 | return Typedef; |
| 117 | } |
| 118 | |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 119 | Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 120 | // Do substitution on the type of the declaration |
| 121 | QualType T = SemaRef.SubstType(D->getType(), TemplateArgs, |
| 122 | D->getTypeSpecStartLoc(), |
| 123 | D->getDeclName()); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 124 | if (T.isNull()) |
| 125 | return 0; |
| 126 | |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 127 | // Build the instantiated declaration |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 128 | VarDecl *Var = VarDecl::Create(SemaRef.Context, Owner, |
| 129 | D->getLocation(), D->getIdentifier(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 130 | T, D->getDeclaratorInfo(), |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 131 | D->getStorageClass()); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 132 | Var->setThreadSpecified(D->isThreadSpecified()); |
| 133 | Var->setCXXDirectInitializer(D->hasCXXDirectInitializer()); |
| 134 | Var->setDeclaredInCondition(D->isDeclaredInCondition()); |
| 135 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 136 | // If we are instantiating a static data member defined |
| 137 | // out-of-line, the instantiation will have the same lexical |
| 138 | // context (which will be a namespace scope) as the template. |
| 139 | if (D->isOutOfLine()) |
| 140 | Var->setLexicalDeclContext(D->getLexicalDeclContext()); |
| 141 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 142 | // FIXME: In theory, we could have a previous declaration for variables that |
| 143 | // are not static data members. |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 144 | bool Redeclaration = false; |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 145 | SemaRef.CheckVariableDeclaration(Var, 0, Redeclaration); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 146 | |
| 147 | if (D->isOutOfLine()) { |
| 148 | D->getLexicalDeclContext()->addDecl(Var); |
| 149 | Owner->makeDeclVisibleInContext(Var); |
| 150 | } else { |
| 151 | Owner->addDecl(Var); |
| 152 | } |
| 153 | |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 154 | if (D->getInit()) { |
| 155 | OwningExprResult Init |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 156 | = SemaRef.SubstExpr(D->getInit(), TemplateArgs); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 157 | if (Init.isInvalid()) |
| 158 | Var->setInvalidDecl(); |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 159 | else if (ParenListExpr *PLE = dyn_cast<ParenListExpr>((Expr *)Init.get())) { |
| 160 | // FIXME: We're faking all of the comma locations, which is suboptimal. |
| 161 | // Do we even need these comma locations? |
| 162 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 163 | if (PLE->getNumExprs() > 0) { |
| 164 | FakeCommaLocs.reserve(PLE->getNumExprs() - 1); |
| 165 | for (unsigned I = 0, N = PLE->getNumExprs() - 1; I != N; ++I) { |
| 166 | Expr *E = PLE->getExpr(I)->Retain(); |
| 167 | FakeCommaLocs.push_back( |
| 168 | SemaRef.PP.getLocForEndOfToken(E->getLocEnd())); |
| 169 | } |
Douglas Gregor | e9f8eb6 | 2009-08-26 23:26:04 +0000 | [diff] [blame] | 170 | PLE->getExpr(PLE->getNumExprs() - 1)->Retain(); |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // Add the direct initializer to the declaration. |
| 174 | SemaRef.AddCXXDirectInitializerToDecl(Sema::DeclPtrTy::make(Var), |
| 175 | PLE->getLParenLoc(), |
| 176 | Sema::MultiExprArg(SemaRef, |
| 177 | (void**)PLE->getExprs(), |
| 178 | PLE->getNumExprs()), |
| 179 | FakeCommaLocs.data(), |
| 180 | PLE->getRParenLoc()); |
| 181 | |
| 182 | // When Init is destroyed, it will destroy the instantiated ParenListExpr; |
| 183 | // we've explicitly retained all of its subexpressions already. |
| 184 | } else |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 185 | SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init), |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 186 | D->hasCXXDirectInitializer()); |
Douglas Gregor | 65b9005 | 2009-07-27 17:43:39 +0000 | [diff] [blame] | 187 | } else if (!Var->isStaticDataMember() || Var->isOutOfLine()) |
| 188 | SemaRef.ActOnUninitializedDecl(Sema::DeclPtrTy::make(Var), false); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 189 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 190 | // Link instantiations of static data members back to the template from |
| 191 | // which they were instantiated. |
| 192 | if (Var->isStaticDataMember()) |
| 193 | SemaRef.Context.setInstantiatedFromStaticDataMember(Var, D); |
| 194 | |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 195 | return Var; |
| 196 | } |
| 197 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 198 | Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { |
| 199 | bool Invalid = false; |
| 200 | QualType T = D->getType(); |
| 201 | if (T->isDependentType()) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 202 | T = SemaRef.SubstType(T, TemplateArgs, |
| 203 | D->getLocation(), D->getDeclName()); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 204 | if (!T.isNull() && T->isFunctionType()) { |
| 205 | // C++ [temp.arg.type]p3: |
| 206 | // If a declaration acquires a function type through a type |
| 207 | // dependent on a template-parameter and this causes a |
| 208 | // declaration that does not use the syntactic form of a |
| 209 | // function declarator to have function type, the program is |
| 210 | // ill-formed. |
| 211 | SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) |
| 212 | << T; |
| 213 | T = QualType(); |
| 214 | Invalid = true; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | Expr *BitWidth = D->getBitWidth(); |
| 219 | if (Invalid) |
| 220 | BitWidth = 0; |
| 221 | else if (BitWidth) { |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 222 | // The bit-width expression is not potentially evaluated. |
| 223 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 224 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 225 | OwningExprResult InstantiatedBitWidth |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 226 | = SemaRef.SubstExpr(BitWidth, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 227 | if (InstantiatedBitWidth.isInvalid()) { |
| 228 | Invalid = true; |
| 229 | BitWidth = 0; |
| 230 | } else |
Anders Carlsson | e9146f2 | 2009-05-01 19:49:17 +0000 | [diff] [blame] | 231 | BitWidth = InstantiatedBitWidth.takeAs<Expr>(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T, |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 235 | D->getDeclaratorInfo(), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 236 | cast<RecordDecl>(Owner), |
| 237 | D->getLocation(), |
| 238 | D->isMutable(), |
| 239 | BitWidth, |
Steve Naroff | ea218b8 | 2009-07-14 14:58:18 +0000 | [diff] [blame] | 240 | D->getTypeSpecStartLoc(), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 241 | D->getAccess(), |
| 242 | 0); |
| 243 | if (Field) { |
| 244 | if (Invalid) |
| 245 | Field->setInvalidDecl(); |
| 246 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 247 | Owner->addDecl(Field); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | return Field; |
| 251 | } |
| 252 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 253 | Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { |
| 254 | FriendDecl::FriendUnion FU; |
| 255 | |
| 256 | // Handle friend type expressions by simply substituting template |
| 257 | // parameters into the pattern type. |
| 258 | if (Type *Ty = D->getFriendType()) { |
| 259 | QualType T = SemaRef.SubstType(QualType(Ty,0), TemplateArgs, |
| 260 | D->getLocation(), DeclarationName()); |
| 261 | if (T.isNull()) return 0; |
| 262 | |
| 263 | assert(getLangOptions().CPlusPlus0x || T->isRecordType()); |
| 264 | FU = T.getTypePtr(); |
| 265 | |
| 266 | // Handle everything else by appropriate substitution. |
| 267 | } else { |
| 268 | NamedDecl *ND = D->getFriendDecl(); |
| 269 | assert(ND && "friend decl must be a decl or a type!"); |
| 270 | |
| 271 | Decl *NewND = Visit(ND); |
| 272 | if (!NewND) return 0; |
| 273 | |
| 274 | FU = cast<NamedDecl>(NewND); |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 275 | } |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 276 | |
| 277 | FriendDecl *FD = |
| 278 | FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), FU, |
| 279 | D->getFriendLoc()); |
| 280 | Owner->addDecl(FD); |
| 281 | return FD; |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 284 | Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 285 | Expr *AssertExpr = D->getAssertExpr(); |
| 286 | |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 287 | // The expression in a static assertion is not potentially evaluated. |
| 288 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
| 289 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 290 | OwningExprResult InstantiatedAssertExpr |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 291 | = SemaRef.SubstExpr(AssertExpr, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 292 | if (InstantiatedAssertExpr.isInvalid()) |
| 293 | return 0; |
| 294 | |
Douglas Gregor | 43d9d92 | 2009-08-08 01:41:12 +0000 | [diff] [blame] | 295 | OwningExprResult Message(SemaRef, D->getMessage()); |
| 296 | D->getMessage()->Retain(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 297 | Decl *StaticAssert |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 298 | = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(), |
| 299 | move(InstantiatedAssertExpr), |
| 300 | move(Message)).getAs<Decl>(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 301 | return StaticAssert; |
| 302 | } |
| 303 | |
| 304 | Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { |
| 305 | EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, |
| 306 | D->getLocation(), D->getIdentifier(), |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 307 | D->getTagKeywordLoc(), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 308 | /*PrevDecl=*/0); |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 309 | Enum->setInstantiationOfMemberEnum(D); |
Douglas Gregor | 06c0fec | 2009-03-25 22:00:53 +0000 | [diff] [blame] | 310 | Enum->setAccess(D->getAccess()); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 311 | Owner->addDecl(Enum); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 312 | Enum->startDefinition(); |
| 313 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 314 | llvm::SmallVector<Sema::DeclPtrTy, 4> Enumerators; |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 315 | |
| 316 | EnumConstantDecl *LastEnumConst = 0; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 317 | for (EnumDecl::enumerator_iterator EC = D->enumerator_begin(), |
| 318 | ECEnd = D->enumerator_end(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 319 | EC != ECEnd; ++EC) { |
| 320 | // The specified value for the enumerator. |
| 321 | OwningExprResult Value = SemaRef.Owned((Expr *)0); |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 322 | if (Expr *UninstValue = EC->getInitExpr()) { |
| 323 | // The enumerator's value expression is not potentially evaluated. |
| 324 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
| 325 | Action::Unevaluated); |
| 326 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 327 | Value = SemaRef.SubstExpr(UninstValue, TemplateArgs); |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 328 | } |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 329 | |
| 330 | // Drop the initial value and continue. |
| 331 | bool isInvalid = false; |
| 332 | if (Value.isInvalid()) { |
| 333 | Value = SemaRef.Owned((Expr *)0); |
| 334 | isInvalid = true; |
| 335 | } |
| 336 | |
| 337 | EnumConstantDecl *EnumConst |
| 338 | = SemaRef.CheckEnumConstant(Enum, LastEnumConst, |
| 339 | EC->getLocation(), EC->getIdentifier(), |
| 340 | move(Value)); |
| 341 | |
| 342 | if (isInvalid) { |
| 343 | if (EnumConst) |
| 344 | EnumConst->setInvalidDecl(); |
| 345 | Enum->setInvalidDecl(); |
| 346 | } |
| 347 | |
| 348 | if (EnumConst) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 349 | Enum->addDecl(EnumConst); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 350 | Enumerators.push_back(Sema::DeclPtrTy::make(EnumConst)); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 351 | LastEnumConst = EnumConst; |
| 352 | } |
| 353 | } |
| 354 | |
Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 355 | // FIXME: Fixup LBraceLoc and RBraceLoc |
Edward O'Callaghan | fee1381 | 2009-08-08 14:36:57 +0000 | [diff] [blame] | 356 | // FIXME: Empty Scope and AttributeList (required to handle attribute packed). |
Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 357 | SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(), SourceLocation(), |
| 358 | Sema::DeclPtrTy::make(Enum), |
Edward O'Callaghan | fee1381 | 2009-08-08 14:36:57 +0000 | [diff] [blame] | 359 | &Enumerators[0], Enumerators.size(), |
| 360 | 0, 0); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 361 | |
| 362 | return Enum; |
| 363 | } |
| 364 | |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 365 | Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 366 | assert(false && "EnumConstantDecls can only occur within EnumDecls."); |
| 367 | return 0; |
| 368 | } |
| 369 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 370 | Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 371 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 372 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 373 | if (!InstParams) |
| 374 | return NULL; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 375 | |
| 376 | CXXRecordDecl *Pattern = D->getTemplatedDecl(); |
| 377 | CXXRecordDecl *RecordInst |
| 378 | = CXXRecordDecl::Create(SemaRef.Context, Pattern->getTagKind(), Owner, |
| 379 | Pattern->getLocation(), Pattern->getIdentifier(), |
| 380 | Pattern->getTagKeywordLoc(), /*PrevDecl=*/ NULL); |
| 381 | |
| 382 | ClassTemplateDecl *Inst |
| 383 | = ClassTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 384 | D->getIdentifier(), InstParams, RecordInst, 0); |
| 385 | RecordInst->setDescribedClassTemplate(Inst); |
| 386 | Inst->setAccess(D->getAccess()); |
| 387 | Inst->setInstantiatedFromMemberTemplate(D); |
| 388 | |
| 389 | Owner->addDecl(Inst); |
| 390 | return Inst; |
| 391 | } |
| 392 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 393 | Decl * |
| 394 | TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 395 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
| 396 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
| 397 | if (!InstParams) |
| 398 | return NULL; |
| 399 | |
| 400 | // FIXME: Handle instantiation of nested function templates that aren't |
| 401 | // member function templates. This could happen inside a FriendDecl. |
| 402 | assert(isa<CXXMethodDecl>(D->getTemplatedDecl())); |
| 403 | CXXMethodDecl *InstMethod |
| 404 | = cast_or_null<CXXMethodDecl>( |
| 405 | VisitCXXMethodDecl(cast<CXXMethodDecl>(D->getTemplatedDecl()), |
| 406 | InstParams)); |
| 407 | if (!InstMethod) |
| 408 | return 0; |
| 409 | |
| 410 | // Link the instantiated function template declaration to the function |
| 411 | // template from which it was instantiated. |
| 412 | FunctionTemplateDecl *InstTemplate = InstMethod->getDescribedFunctionTemplate(); |
| 413 | assert(InstTemplate && "VisitCXXMethodDecl didn't create a template!"); |
| 414 | InstTemplate->setInstantiatedFromMemberTemplate(D); |
| 415 | Owner->addDecl(InstTemplate); |
| 416 | return InstTemplate; |
| 417 | } |
| 418 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 419 | Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 420 | CXXRecordDecl *PrevDecl = 0; |
| 421 | if (D->isInjectedClassName()) |
| 422 | PrevDecl = cast<CXXRecordDecl>(Owner); |
| 423 | |
| 424 | CXXRecordDecl *Record |
| 425 | = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 426 | D->getLocation(), D->getIdentifier(), |
| 427 | D->getTagKeywordLoc(), PrevDecl); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 428 | Record->setImplicit(D->isImplicit()); |
Eli Friedman | eaba1af | 2009-08-27 19:11:42 +0000 | [diff] [blame] | 429 | // FIXME: Check against AS_none is an ugly hack to work around the issue that |
| 430 | // the tag decls introduced by friend class declarations don't have an access |
| 431 | // specifier. Remove once this area of the code gets sorted out. |
| 432 | if (D->getAccess() != AS_none) |
| 433 | Record->setAccess(D->getAccess()); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 434 | if (!D->isInjectedClassName()) |
| 435 | Record->setInstantiationOfMemberClass(D); |
| 436 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 437 | // If the original function was part of a friend declaration, |
| 438 | // inherit its namespace state. |
| 439 | if (Decl::FriendObjectKind FOK = D->getFriendObjectKind()) |
| 440 | Record->setObjectOfFriendDecl(FOK == Decl::FOK_Declared); |
| 441 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 442 | Owner->addDecl(Record); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 443 | return Record; |
| 444 | } |
| 445 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 446 | /// Normal class members are of more specific types and therefore |
| 447 | /// don't make it here. This function serves two purposes: |
| 448 | /// 1) instantiating function templates |
| 449 | /// 2) substituting friend declarations |
| 450 | /// FIXME: preserve function definitions in case #2 |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 451 | Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) { |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 452 | // Check whether there is already a function template specialization for |
| 453 | // this declaration. |
| 454 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
| 455 | void *InsertPos = 0; |
| 456 | if (FunctionTemplate) { |
| 457 | llvm::FoldingSetNodeID ID; |
| 458 | FunctionTemplateSpecializationInfo::Profile(ID, |
| 459 | TemplateArgs.getFlatArgumentList(), |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 460 | TemplateArgs.flat_size(), |
| 461 | SemaRef.Context); |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 462 | |
| 463 | FunctionTemplateSpecializationInfo *Info |
| 464 | = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, |
| 465 | InsertPos); |
| 466 | |
| 467 | // If we already have a function template specialization, return it. |
| 468 | if (Info) |
| 469 | return Info->Function; |
| 470 | } |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 471 | |
| 472 | Sema::LocalInstantiationScope Scope(SemaRef); |
| 473 | |
| 474 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 475 | QualType T = SubstFunctionType(D, Params); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 476 | if (T.isNull()) |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 477 | return 0; |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 478 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 479 | // Build the instantiated method declaration. |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 480 | DeclContext *DC = SemaRef.FindInstantiatedContext(D->getDeclContext()); |
| 481 | FunctionDecl *Function = |
| 482 | FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 483 | D->getDeclName(), T, D->getDeclaratorInfo(), |
| 484 | D->getStorageClass(), |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 485 | D->isInline(), D->hasWrittenPrototype()); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 486 | Function->setLexicalDeclContext(Owner); |
| 487 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 488 | // Attach the parameters |
| 489 | for (unsigned P = 0; P < Params.size(); ++P) |
| 490 | Params[P]->setOwningFunction(Function); |
| 491 | Function->setParams(SemaRef.Context, Params.data(), Params.size()); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 492 | |
| 493 | // If the original function was part of a friend declaration, |
| 494 | // inherit its namespace state and add it to the owner. |
| 495 | if (Decl::FriendObjectKind FOK = D->getFriendObjectKind()) { |
| 496 | bool WasDeclared = (FOK == Decl::FOK_Declared); |
| 497 | Function->setObjectOfFriendDecl(WasDeclared); |
| 498 | if (!Owner->isDependentContext()) |
| 499 | DC->makeDeclVisibleInContext(Function); |
| 500 | } |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 501 | |
| 502 | if (InitFunctionInstantiation(Function, D)) |
| 503 | Function->setInvalidDecl(); |
| 504 | |
| 505 | bool Redeclaration = false; |
| 506 | bool OverloadableAttrRequired = false; |
| 507 | NamedDecl *PrevDecl = 0; |
| 508 | SemaRef.CheckFunctionDeclaration(Function, PrevDecl, Redeclaration, |
| 509 | /*FIXME:*/OverloadableAttrRequired); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 510 | |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 511 | if (FunctionTemplate) { |
| 512 | // Record this function template specialization. |
| 513 | Function->setFunctionTemplateSpecialization(SemaRef.Context, |
| 514 | FunctionTemplate, |
| 515 | &TemplateArgs, |
| 516 | InsertPos); |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 519 | return Function; |
| 520 | } |
| 521 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 522 | Decl * |
| 523 | TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, |
| 524 | TemplateParameterList *TemplateParams) { |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 525 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
| 526 | void *InsertPos = 0; |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 527 | if (FunctionTemplate && !TemplateParams) { |
| 528 | // We are creating a function template specialization from a function |
| 529 | // template. Check whether there is already a function template |
| 530 | // specialization for this particular set of template arguments. |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 531 | llvm::FoldingSetNodeID ID; |
| 532 | FunctionTemplateSpecializationInfo::Profile(ID, |
| 533 | TemplateArgs.getFlatArgumentList(), |
| 534 | TemplateArgs.flat_size(), |
| 535 | SemaRef.Context); |
| 536 | |
| 537 | FunctionTemplateSpecializationInfo *Info |
| 538 | = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, |
| 539 | InsertPos); |
| 540 | |
| 541 | // If we already have a function template specialization, return it. |
| 542 | if (Info) |
| 543 | return Info->Function; |
| 544 | } |
| 545 | |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 546 | Sema::LocalInstantiationScope Scope(SemaRef); |
| 547 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 548 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 549 | QualType T = SubstFunctionType(D, Params); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 550 | if (T.isNull()) |
| 551 | return 0; |
| 552 | |
| 553 | // Build the instantiated method declaration. |
| 554 | CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 555 | CXXMethodDecl *Method = 0; |
| 556 | |
| 557 | DeclarationName Name = D->getDeclName(); |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 558 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 559 | QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); |
| 560 | Name = SemaRef.Context.DeclarationNames.getCXXConstructorName( |
| 561 | SemaRef.Context.getCanonicalType(ClassTy)); |
| 562 | Method = CXXConstructorDecl::Create(SemaRef.Context, Record, |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 563 | Constructor->getLocation(), |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 564 | Name, T, |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 565 | Constructor->getDeclaratorInfo(), |
| 566 | Constructor->isExplicit(), |
| 567 | Constructor->isInline(), false); |
| 568 | } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { |
| 569 | QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); |
| 570 | Name = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 571 | SemaRef.Context.getCanonicalType(ClassTy)); |
| 572 | Method = CXXDestructorDecl::Create(SemaRef.Context, Record, |
| 573 | Destructor->getLocation(), Name, |
| 574 | T, Destructor->isInline(), false); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 575 | } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
| 576 | CanQualType ConvTy |
| 577 | = SemaRef.Context.getCanonicalType( |
| 578 | T->getAsFunctionType()->getResultType()); |
| 579 | Name = SemaRef.Context.DeclarationNames.getCXXConversionFunctionName( |
| 580 | ConvTy); |
| 581 | Method = CXXConversionDecl::Create(SemaRef.Context, Record, |
| 582 | Conversion->getLocation(), Name, |
| 583 | T, Conversion->getDeclaratorInfo(), |
| 584 | Conversion->isInline(), |
| 585 | Conversion->isExplicit()); |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 586 | } else { |
| 587 | Method = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(), |
| 588 | D->getDeclName(), T, D->getDeclaratorInfo(), |
| 589 | D->isStatic(), D->isInline()); |
| 590 | } |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 591 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 592 | if (TemplateParams) { |
| 593 | // Our resulting instantiation is actually a function template, since we |
| 594 | // are substituting only the outer template parameters. For example, given |
| 595 | // |
| 596 | // template<typename T> |
| 597 | // struct X { |
| 598 | // template<typename U> void f(T, U); |
| 599 | // }; |
| 600 | // |
| 601 | // X<int> x; |
| 602 | // |
| 603 | // We are instantiating the member template "f" within X<int>, which means |
| 604 | // substituting int for T, but leaving "f" as a member function template. |
| 605 | // Build the function template itself. |
| 606 | FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record, |
| 607 | Method->getLocation(), |
| 608 | Method->getDeclName(), |
| 609 | TemplateParams, Method); |
| 610 | if (D->isOutOfLine()) |
| 611 | FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); |
| 612 | Method->setDescribedFunctionTemplate(FunctionTemplate); |
| 613 | } else if (!FunctionTemplate) |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 614 | Method->setInstantiationOfMemberFunction(D); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 615 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 616 | // If we are instantiating a member function defined |
| 617 | // out-of-line, the instantiation will have the same lexical |
| 618 | // context (which will be a namespace scope) as the template. |
| 619 | if (D->isOutOfLine()) |
| 620 | Method->setLexicalDeclContext(D->getLexicalDeclContext()); |
| 621 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 622 | // Attach the parameters |
| 623 | for (unsigned P = 0; P < Params.size(); ++P) |
| 624 | Params[P]->setOwningFunction(Method); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 625 | Method->setParams(SemaRef.Context, Params.data(), Params.size()); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 626 | |
| 627 | if (InitMethodInstantiation(Method, D)) |
| 628 | Method->setInvalidDecl(); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 629 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 630 | NamedDecl *PrevDecl = 0; |
| 631 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 632 | if (!FunctionTemplate || TemplateParams) { |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 633 | PrevDecl = SemaRef.LookupQualifiedName(Owner, Name, |
| 634 | Sema::LookupOrdinaryName, true); |
| 635 | |
| 636 | // In C++, the previous declaration we find might be a tag type |
| 637 | // (class or enum). In this case, the new declaration will hide the |
| 638 | // tag type. Note that this does does not apply if we're declaring a |
| 639 | // typedef (C++ [dcl.typedef]p4). |
| 640 | if (PrevDecl && PrevDecl->getIdentifierNamespace() == Decl::IDNS_Tag) |
| 641 | PrevDecl = 0; |
| 642 | } |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 643 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 644 | if (FunctionTemplate && !TemplateParams) |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 645 | // Record this function template specialization. |
| 646 | Method->setFunctionTemplateSpecialization(SemaRef.Context, |
| 647 | FunctionTemplate, |
| 648 | &TemplateArgs, |
| 649 | InsertPos); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 650 | |
| 651 | bool Redeclaration = false; |
| 652 | bool OverloadableAttrRequired = false; |
| 653 | SemaRef.CheckFunctionDeclaration(Method, PrevDecl, Redeclaration, |
| 654 | /*FIXME:*/OverloadableAttrRequired); |
| 655 | |
| 656 | if (!FunctionTemplate && (!Method->isInvalidDecl() || !PrevDecl)) |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 657 | Owner->addDecl(Method); |
| 658 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 659 | return Method; |
| 660 | } |
| 661 | |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 662 | Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 663 | return VisitCXXMethodDecl(D); |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 666 | Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 667 | return VisitCXXMethodDecl(D); |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 670 | Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 671 | return VisitCXXMethodDecl(D); |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 674 | ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 675 | QualType OrigT = SemaRef.SubstType(D->getOriginalType(), TemplateArgs, |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 676 | D->getLocation(), D->getDeclName()); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 677 | if (OrigT.isNull()) |
| 678 | return 0; |
| 679 | |
| 680 | QualType T = SemaRef.adjustParameterType(OrigT); |
| 681 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 682 | // Allocate the parameter |
| 683 | ParmVarDecl *Param = 0; |
| 684 | if (T == OrigT) |
| 685 | Param = ParmVarDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 686 | D->getIdentifier(), T, D->getDeclaratorInfo(), |
| 687 | D->getStorageClass(), 0); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 688 | else |
| 689 | Param = OriginalParmVarDecl::Create(SemaRef.Context, Owner, |
| 690 | D->getLocation(), D->getIdentifier(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 691 | T, D->getDeclaratorInfo(), OrigT, |
| 692 | D->getStorageClass(), 0); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 693 | |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 694 | // Mark the default argument as being uninstantiated. |
| 695 | if (Expr *Arg = D->getDefaultArg()) |
| 696 | Param->setUninstantiatedDefaultArg(Arg); |
| 697 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 698 | // Note: we don't try to instantiate function parameters until after |
| 699 | // we've instantiated the function's type. Therefore, we don't have |
| 700 | // to check for 'void' parameter types here. |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 701 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 702 | return Param; |
| 703 | } |
| 704 | |
| 705 | Decl * |
| 706 | TemplateDeclInstantiator::VisitOriginalParmVarDecl(OriginalParmVarDecl *D) { |
| 707 | // Since parameter types can decay either before or after |
| 708 | // instantiation, we simply treat OriginalParmVarDecls as |
| 709 | // ParmVarDecls the same way, and create one or the other depending |
| 710 | // on what happens after template instantiation. |
| 711 | return VisitParmVarDecl(D); |
| 712 | } |
| 713 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 714 | Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( |
| 715 | TemplateTypeParmDecl *D) { |
| 716 | // TODO: don't always clone when decls are refcounted. |
| 717 | const Type* T = D->getTypeForDecl(); |
| 718 | assert(T->isTemplateTypeParmType()); |
| 719 | const TemplateTypeParmType *TTPT = T->getAs<TemplateTypeParmType>(); |
| 720 | |
| 721 | TemplateTypeParmDecl *Inst = |
| 722 | TemplateTypeParmDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 723 | TTPT->getDepth(), TTPT->getIndex(), |
| 724 | TTPT->getName(), |
| 725 | D->wasDeclaredWithTypename(), |
| 726 | D->isParameterPack()); |
| 727 | |
| 728 | if (D->hasDefaultArgument()) { |
| 729 | QualType DefaultPattern = D->getDefaultArgument(); |
| 730 | QualType DefaultInst |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 731 | = SemaRef.SubstType(DefaultPattern, TemplateArgs, |
| 732 | D->getDefaultArgumentLoc(), |
| 733 | D->getDeclName()); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 734 | |
| 735 | Inst->setDefaultArgument(DefaultInst, |
| 736 | D->getDefaultArgumentLoc(), |
| 737 | D->defaultArgumentWasInherited() /* preserve? */); |
| 738 | } |
| 739 | |
| 740 | return Inst; |
| 741 | } |
| 742 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 743 | Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner, |
| 744 | const TemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 745 | TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 746 | return Instantiator.Visit(D); |
| 747 | } |
| 748 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 749 | /// \brief Instantiates a nested template parameter list in the current |
| 750 | /// instantiation context. |
| 751 | /// |
| 752 | /// \param L The parameter list to instantiate |
| 753 | /// |
| 754 | /// \returns NULL if there was an error |
| 755 | TemplateParameterList * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 756 | TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 757 | // Get errors for all the parameters before bailing out. |
| 758 | bool Invalid = false; |
| 759 | |
| 760 | unsigned N = L->size(); |
| 761 | typedef llvm::SmallVector<Decl*,8> ParamVector; |
| 762 | ParamVector Params; |
| 763 | Params.reserve(N); |
| 764 | for (TemplateParameterList::iterator PI = L->begin(), PE = L->end(); |
| 765 | PI != PE; ++PI) { |
| 766 | Decl *D = Visit(*PI); |
| 767 | Params.push_back(D); |
| 768 | Invalid = Invalid || !D; |
| 769 | } |
| 770 | |
| 771 | // Clean up if we had an error. |
| 772 | if (Invalid) { |
| 773 | for (ParamVector::iterator PI = Params.begin(), PE = Params.end(); |
| 774 | PI != PE; ++PI) |
| 775 | if (*PI) |
| 776 | (*PI)->Destroy(SemaRef.Context); |
| 777 | return NULL; |
| 778 | } |
| 779 | |
| 780 | TemplateParameterList *InstL |
| 781 | = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(), |
| 782 | L->getLAngleLoc(), &Params.front(), N, |
| 783 | L->getRAngleLoc()); |
| 784 | return InstL; |
| 785 | } |
| 786 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 787 | /// \brief Does substitution on the type of the given function, including |
| 788 | /// all of the function parameters. |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 789 | /// |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 790 | /// \param D The function whose type will be the basis of the substitution |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 791 | /// |
| 792 | /// \param Params the instantiated parameter declarations |
| 793 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 794 | /// \returns the instantiated function's type if successful, a NULL |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 795 | /// type if there was an error. |
| 796 | QualType |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 797 | TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 798 | llvm::SmallVectorImpl<ParmVarDecl *> &Params) { |
| 799 | bool InvalidDecl = false; |
| 800 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 801 | // Substitute all of the function's formal parameter types. |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 802 | TemplateDeclInstantiator ParamInstantiator(SemaRef, 0, TemplateArgs); |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 803 | llvm::SmallVector<QualType, 4> ParamTys; |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 804 | for (FunctionDecl::param_iterator P = D->param_begin(), |
| 805 | PEnd = D->param_end(); |
| 806 | P != PEnd; ++P) { |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 807 | if (ParmVarDecl *PInst = ParamInstantiator.VisitParmVarDecl(*P)) { |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 808 | if (PInst->getType()->isVoidType()) { |
| 809 | SemaRef.Diag(PInst->getLocation(), diag::err_param_with_void_type); |
| 810 | PInst->setInvalidDecl(); |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 811 | } else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), |
| 812 | PInst->getType(), |
| 813 | diag::err_abstract_type_in_decl, |
| 814 | Sema::AbstractParamType)) |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 815 | PInst->setInvalidDecl(); |
| 816 | |
| 817 | Params.push_back(PInst); |
| 818 | ParamTys.push_back(PInst->getType()); |
| 819 | |
| 820 | if (PInst->isInvalidDecl()) |
| 821 | InvalidDecl = true; |
| 822 | } else |
| 823 | InvalidDecl = true; |
| 824 | } |
| 825 | |
| 826 | // FIXME: Deallocate dead declarations. |
| 827 | if (InvalidDecl) |
| 828 | return QualType(); |
| 829 | |
| 830 | const FunctionProtoType *Proto = D->getType()->getAsFunctionProtoType(); |
| 831 | assert(Proto && "Missing prototype?"); |
| 832 | QualType ResultType |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 833 | = SemaRef.SubstType(Proto->getResultType(), TemplateArgs, |
| 834 | D->getLocation(), D->getDeclName()); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 835 | if (ResultType.isNull()) |
| 836 | return QualType(); |
| 837 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 838 | return SemaRef.BuildFunctionType(ResultType, ParamTys.data(), ParamTys.size(), |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 839 | Proto->isVariadic(), Proto->getTypeQuals(), |
| 840 | D->getLocation(), D->getDeclName()); |
| 841 | } |
| 842 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 843 | /// \brief Initializes the common fields of an instantiation function |
| 844 | /// declaration (New) from the corresponding fields of its template (Tmpl). |
| 845 | /// |
| 846 | /// \returns true if there was an error |
| 847 | bool |
| 848 | TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, |
| 849 | FunctionDecl *Tmpl) { |
| 850 | if (Tmpl->isDeleted()) |
| 851 | New->setDeleted(); |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 852 | |
| 853 | // If we are performing substituting explicitly-specified template arguments |
| 854 | // or deduced template arguments into a function template and we reach this |
| 855 | // point, we are now past the point where SFINAE applies and have committed |
| 856 | // to keeping the new function template specialization. We therefore |
| 857 | // convert the active template instantiation for the function template |
| 858 | // into a template instantiation for this specific function template |
| 859 | // specialization, which is not a SFINAE context, so that we diagnose any |
| 860 | // further errors in the declaration itself. |
| 861 | typedef Sema::ActiveTemplateInstantiation ActiveInstType; |
| 862 | ActiveInstType &ActiveInst = SemaRef.ActiveTemplateInstantiations.back(); |
| 863 | if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution || |
| 864 | ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) { |
| 865 | if (FunctionTemplateDecl *FunTmpl |
| 866 | = dyn_cast<FunctionTemplateDecl>((Decl *)ActiveInst.Entity)) { |
| 867 | assert(FunTmpl->getTemplatedDecl() == Tmpl && |
| 868 | "Deduction from the wrong function template?"); |
Daniel Dunbar | bcbb8bd | 2009-07-16 22:10:11 +0000 | [diff] [blame] | 869 | (void) FunTmpl; |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 870 | ActiveInst.Kind = ActiveInstType::TemplateInstantiation; |
| 871 | ActiveInst.Entity = reinterpret_cast<uintptr_t>(New); |
| 872 | } |
| 873 | } |
| 874 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 875 | return false; |
| 876 | } |
| 877 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 878 | /// \brief Initializes common fields of an instantiated method |
| 879 | /// declaration (New) from the corresponding fields of its template |
| 880 | /// (Tmpl). |
| 881 | /// |
| 882 | /// \returns true if there was an error |
| 883 | bool |
| 884 | TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, |
| 885 | CXXMethodDecl *Tmpl) { |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 886 | if (InitFunctionInstantiation(New, Tmpl)) |
| 887 | return true; |
| 888 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 889 | CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); |
| 890 | New->setAccess(Tmpl->getAccess()); |
Anders Carlsson | 77b7f1d | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 891 | if (Tmpl->isVirtualAsWritten()) { |
| 892 | New->setVirtualAsWritten(true); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 893 | Record->setAggregate(false); |
| 894 | Record->setPOD(false); |
Eli Friedman | 1d954f6 | 2009-08-15 21:55:26 +0000 | [diff] [blame] | 895 | Record->setEmpty(false); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 896 | Record->setPolymorphic(true); |
| 897 | } |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 898 | if (Tmpl->isPure()) { |
| 899 | New->setPure(); |
| 900 | Record->setAbstract(true); |
| 901 | } |
| 902 | |
| 903 | // FIXME: attributes |
| 904 | // FIXME: New needs a pointer to Tmpl |
| 905 | return false; |
| 906 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 907 | |
| 908 | /// \brief Instantiate the definition of the given function from its |
| 909 | /// template. |
| 910 | /// |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 911 | /// \param PointOfInstantiation the point at which the instantiation was |
| 912 | /// required. Note that this is not precisely a "point of instantiation" |
| 913 | /// for the function, but it's close. |
| 914 | /// |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 915 | /// \param Function the already-instantiated declaration of a |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 916 | /// function template specialization or member function of a class template |
| 917 | /// specialization. |
| 918 | /// |
| 919 | /// \param Recursive if true, recursively instantiates any functions that |
| 920 | /// are required by this instantiation. |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 921 | void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 922 | FunctionDecl *Function, |
| 923 | bool Recursive) { |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 924 | if (Function->isInvalidDecl()) |
| 925 | return; |
| 926 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 927 | assert(!Function->getBody() && "Already instantiated!"); |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 928 | |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 929 | // Find the function body that we'll be substituting. |
Douglas Gregor | 1637be7 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 930 | const FunctionDecl *PatternDecl = 0; |
| 931 | if (FunctionTemplateDecl *Primary = Function->getPrimaryTemplate()) |
| 932 | PatternDecl = Primary->getTemplatedDecl(); |
| 933 | else |
| 934 | PatternDecl = Function->getInstantiatedFromMemberFunction(); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 935 | Stmt *Pattern = 0; |
| 936 | if (PatternDecl) |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 937 | Pattern = PatternDecl->getBody(PatternDecl); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 938 | |
| 939 | if (!Pattern) |
| 940 | return; |
| 941 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 942 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Function); |
| 943 | if (Inst) |
| 944 | return; |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 945 | |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 946 | // If we're performing recursive template instantiation, create our own |
| 947 | // queue of pending implicit instantiations that we will instantiate later, |
| 948 | // while we're still within our own instantiation context. |
| 949 | std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; |
| 950 | if (Recursive) |
| 951 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 952 | |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 953 | ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function)); |
| 954 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 955 | // Introduce a new scope where local variable instantiations will be |
| 956 | // recorded. |
| 957 | LocalInstantiationScope Scope(*this); |
| 958 | |
| 959 | // Introduce the instantiated function parameters into the local |
| 960 | // instantiation scope. |
| 961 | for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) |
| 962 | Scope.InstantiatedLocal(PatternDecl->getParamDecl(I), |
| 963 | Function->getParamDecl(I)); |
| 964 | |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 965 | // Enter the scope of this instantiation. We don't use |
| 966 | // PushDeclContext because we don't have a scope. |
| 967 | DeclContext *PreviousContext = CurContext; |
| 968 | CurContext = Function; |
| 969 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 970 | // Instantiate the function body. |
| 971 | OwningStmtResult Body |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 972 | = SubstStmt(Pattern, getTemplateInstantiationArgs(Function)); |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 973 | |
| 974 | ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body), |
| 975 | /*IsInstantiation=*/true); |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 976 | |
| 977 | CurContext = PreviousContext; |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 978 | |
| 979 | DeclGroupRef DG(Function); |
| 980 | Consumer.HandleTopLevelDecl(DG); |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 981 | |
| 982 | if (Recursive) { |
| 983 | // Instantiate any pending implicit instantiations found during the |
| 984 | // instantiation of this template. |
| 985 | PerformPendingImplicitInstantiations(); |
| 986 | |
| 987 | // Restore the set of pending implicit instantiations. |
| 988 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 989 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | /// \brief Instantiate the definition of the given variable from its |
| 993 | /// template. |
| 994 | /// |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 995 | /// \param PointOfInstantiation the point at which the instantiation was |
| 996 | /// required. Note that this is not precisely a "point of instantiation" |
| 997 | /// for the function, but it's close. |
| 998 | /// |
| 999 | /// \param Var the already-instantiated declaration of a static member |
| 1000 | /// variable of a class template specialization. |
| 1001 | /// |
| 1002 | /// \param Recursive if true, recursively instantiates any functions that |
| 1003 | /// are required by this instantiation. |
| 1004 | void Sema::InstantiateStaticDataMemberDefinition( |
| 1005 | SourceLocation PointOfInstantiation, |
| 1006 | VarDecl *Var, |
| 1007 | bool Recursive) { |
| 1008 | if (Var->isInvalidDecl()) |
| 1009 | return; |
| 1010 | |
| 1011 | // Find the out-of-line definition of this static data member. |
| 1012 | // FIXME: Do we have to look for specializations separately? |
| 1013 | VarDecl *Def = Var->getInstantiatedFromStaticDataMember(); |
| 1014 | bool FoundOutOfLineDef = false; |
| 1015 | assert(Def && "This data member was not instantiated from a template?"); |
| 1016 | assert(Def->isStaticDataMember() && "Not a static data member?"); |
| 1017 | for (VarDecl::redecl_iterator RD = Def->redecls_begin(), |
| 1018 | RDEnd = Def->redecls_end(); |
| 1019 | RD != RDEnd; ++RD) { |
| 1020 | if (RD->getLexicalDeclContext()->isFileContext()) { |
| 1021 | Def = *RD; |
| 1022 | FoundOutOfLineDef = true; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if (!FoundOutOfLineDef) { |
| 1027 | // We did not find an out-of-line definition of this static data member, |
| 1028 | // so we won't perform any instantiation. Rather, we rely on the user to |
| 1029 | // instantiate this definition (or provide a specialization for it) in |
| 1030 | // another translation unit. |
| 1031 | return; |
| 1032 | } |
| 1033 | |
| 1034 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); |
| 1035 | if (Inst) |
| 1036 | return; |
| 1037 | |
| 1038 | // If we're performing recursive template instantiation, create our own |
| 1039 | // queue of pending implicit instantiations that we will instantiate later, |
| 1040 | // while we're still within our own instantiation context. |
| 1041 | std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; |
| 1042 | if (Recursive) |
| 1043 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 1044 | |
| 1045 | // Enter the scope of this instantiation. We don't use |
| 1046 | // PushDeclContext because we don't have a scope. |
| 1047 | DeclContext *PreviousContext = CurContext; |
| 1048 | CurContext = Var->getDeclContext(); |
| 1049 | |
| 1050 | #if 0 |
| 1051 | // Instantiate the initializer of this static data member. |
| 1052 | OwningExprResult Init |
| 1053 | = InstantiateExpr(Def->getInit(), getTemplateInstantiationArgs(Var)); |
| 1054 | if (Init.isInvalid()) { |
| 1055 | // If instantiation of the initializer failed, mark the declaration invalid |
| 1056 | // and don't instantiate anything else that was triggered by this |
| 1057 | // instantiation. |
| 1058 | Var->setInvalidDecl(); |
| 1059 | |
| 1060 | // Restore the set of pending implicit instantiations. |
| 1061 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 1062 | |
| 1063 | return; |
| 1064 | } |
| 1065 | |
| 1066 | // Type-check the initializer. |
| 1067 | if (Init.get()) |
| 1068 | AddInitializerToDecl(DeclPtrTy::make(Var), move(Init), |
| 1069 | Def->hasCXXDirectInitializer()); |
| 1070 | else |
| 1071 | ActOnUninitializedDecl(DeclPtrTy::make(Var), false); |
| 1072 | #else |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1073 | Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(), |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1074 | getTemplateInstantiationArgs(Var))); |
| 1075 | #endif |
| 1076 | |
| 1077 | CurContext = PreviousContext; |
| 1078 | |
| 1079 | if (Var) { |
| 1080 | DeclGroupRef DG(Var); |
| 1081 | Consumer.HandleTopLevelDecl(DG); |
| 1082 | } |
| 1083 | |
| 1084 | if (Recursive) { |
| 1085 | // Instantiate any pending implicit instantiations found during the |
| 1086 | // instantiation of this template. |
| 1087 | PerformPendingImplicitInstantiations(); |
| 1088 | |
| 1089 | // Restore the set of pending implicit instantiations. |
| 1090 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 1091 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1092 | } |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1093 | |
| 1094 | static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { |
| 1095 | if (D->getKind() != Other->getKind()) |
| 1096 | return false; |
| 1097 | |
| 1098 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 1099 | return Record->getInstantiatedFromMemberClass()->getCanonicalDecl() |
| 1100 | == D->getCanonicalDecl(); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1101 | |
| 1102 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 1103 | return Function->getInstantiatedFromMemberFunction()->getCanonicalDecl() |
| 1104 | == D->getCanonicalDecl(); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1105 | |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 1106 | if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 1107 | return Enum->getInstantiatedFromMemberEnum()->getCanonicalDecl() |
| 1108 | == D->getCanonicalDecl(); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1109 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1110 | if (VarDecl *Var = dyn_cast<VarDecl>(Other)) |
| 1111 | if (Var->isStaticDataMember()) |
| 1112 | return Var->getInstantiatedFromStaticDataMember()->getCanonicalDecl() |
| 1113 | == D->getCanonicalDecl(); |
| 1114 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1115 | // FIXME: How can we find instantiations of anonymous unions? |
| 1116 | |
| 1117 | return D->getDeclName() && isa<NamedDecl>(Other) && |
| 1118 | D->getDeclName() == cast<NamedDecl>(Other)->getDeclName(); |
| 1119 | } |
| 1120 | |
| 1121 | template<typename ForwardIterator> |
| 1122 | static NamedDecl *findInstantiationOf(ASTContext &Ctx, |
| 1123 | NamedDecl *D, |
| 1124 | ForwardIterator first, |
| 1125 | ForwardIterator last) { |
| 1126 | for (; first != last; ++first) |
| 1127 | if (isInstantiationOf(Ctx, D, *first)) |
| 1128 | return cast<NamedDecl>(*first); |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 1133 | /// \brief Finds the instantiation of the given declaration context |
| 1134 | /// within the current instantiation. |
| 1135 | /// |
| 1136 | /// \returns NULL if there was an error |
| 1137 | DeclContext *Sema::FindInstantiatedContext(DeclContext* DC) { |
| 1138 | if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) { |
| 1139 | Decl* ID = FindInstantiatedDecl(D); |
| 1140 | return cast_or_null<DeclContext>(ID); |
| 1141 | } else return DC; |
| 1142 | } |
| 1143 | |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1144 | /// \brief Find the instantiation of the given declaration within the |
| 1145 | /// current instantiation. |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1146 | /// |
| 1147 | /// This routine is intended to be used when \p D is a declaration |
| 1148 | /// referenced from within a template, that needs to mapped into the |
| 1149 | /// corresponding declaration within an instantiation. For example, |
| 1150 | /// given: |
| 1151 | /// |
| 1152 | /// \code |
| 1153 | /// template<typename T> |
| 1154 | /// struct X { |
| 1155 | /// enum Kind { |
| 1156 | /// KnownValue = sizeof(T) |
| 1157 | /// }; |
| 1158 | /// |
| 1159 | /// bool getKind() const { return KnownValue; } |
| 1160 | /// }; |
| 1161 | /// |
| 1162 | /// template struct X<int>; |
| 1163 | /// \endcode |
| 1164 | /// |
| 1165 | /// In the instantiation of X<int>::getKind(), we need to map the |
| 1166 | /// EnumConstantDecl for KnownValue (which refers to |
| 1167 | /// X<T>::<Kind>::KnownValue) to its instantiation |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1168 | /// (X<int>::<Kind>::KnownValue). InstantiateCurrentDeclRef() performs |
| 1169 | /// this mapping from within the instantiation of X<int>. |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1170 | NamedDecl * Sema::FindInstantiatedDecl(NamedDecl *D) { |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1171 | DeclContext *ParentDC = D->getDeclContext(); |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 1172 | if (isa<ParmVarDecl>(D) || ParentDC->isFunctionOrMethod()) { |
| 1173 | // D is a local of some kind. Look into the map of local |
| 1174 | // declarations to their instantiations. |
| 1175 | return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D)); |
| 1176 | } |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1177 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 1178 | ParentDC = FindInstantiatedContext(ParentDC); |
| 1179 | if (!ParentDC) return 0; |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1180 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1181 | if (ParentDC != D->getDeclContext()) { |
| 1182 | // We performed some kind of instantiation in the parent context, |
| 1183 | // so now we need to look into the instantiated parent context to |
| 1184 | // find the instantiation of the declaration D. |
| 1185 | NamedDecl *Result = 0; |
| 1186 | if (D->getDeclName()) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1187 | DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName()); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1188 | Result = findInstantiationOf(Context, D, Found.first, Found.second); |
| 1189 | } else { |
| 1190 | // Since we don't have a name for the entity we're looking for, |
| 1191 | // our only option is to walk through all of the declarations to |
| 1192 | // find that name. This will occur in a few cases: |
| 1193 | // |
| 1194 | // - anonymous struct/union within a template |
| 1195 | // - unnamed class/struct/union/enum within a template |
| 1196 | // |
| 1197 | // FIXME: Find a better way to find these instantiations! |
| 1198 | Result = findInstantiationOf(Context, D, |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1199 | ParentDC->decls_begin(), |
| 1200 | ParentDC->decls_end()); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1201 | } |
| 1202 | assert(Result && "Unable to find instantiation of declaration!"); |
| 1203 | D = Result; |
| 1204 | } |
| 1205 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1206 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1207 | if (ClassTemplateDecl *ClassTemplate |
| 1208 | = Record->getDescribedClassTemplate()) { |
| 1209 | // When the declaration D was parsed, it referred to the current |
| 1210 | // instantiation. Therefore, look through the current context, |
| 1211 | // which contains actual instantiations, to find the |
| 1212 | // instantiation of the "current instantiation" that D refers |
| 1213 | // to. Alternatively, we could just instantiate the |
| 1214 | // injected-class-name with the current template arguments, but |
| 1215 | // such an instantiation is far more expensive. |
| 1216 | for (DeclContext *DC = CurContext; !DC->isFileContext(); |
| 1217 | DC = DC->getParent()) { |
| 1218 | if (ClassTemplateSpecializationDecl *Spec |
| 1219 | = dyn_cast<ClassTemplateSpecializationDecl>(DC)) |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 1220 | if (Spec->getSpecializedTemplate()->getCanonicalDecl() |
| 1221 | == ClassTemplate->getCanonicalDecl()) |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1222 | return Spec; |
| 1223 | } |
| 1224 | |
| 1225 | assert(false && |
| 1226 | "Unable to find declaration for the current instantiation"); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | return D; |
| 1230 | } |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1231 | |
| 1232 | /// \brief Performs template instantiation for all implicit template |
| 1233 | /// instantiations we have seen until this point. |
| 1234 | void Sema::PerformPendingImplicitInstantiations() { |
| 1235 | while (!PendingImplicitInstantiations.empty()) { |
| 1236 | PendingImplicitInstantiation Inst = PendingImplicitInstantiations.front(); |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1237 | PendingImplicitInstantiations.pop_front(); |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1238 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1239 | // Instantiate function definitions |
| 1240 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) { |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1241 | if (!Function->getBody()) |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1242 | InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1243 | continue; |
| 1244 | } |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1245 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1246 | // Instantiate static data member definitions. |
| 1247 | VarDecl *Var = cast<VarDecl>(Inst.first); |
| 1248 | assert(Var->isStaticDataMember() && "Not a static data member?"); |
| 1249 | InstantiateStaticDataMemberDefinition(/*FIXME:*/Inst.second, Var, true); |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1250 | } |
| 1251 | } |