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" |
Anders Carlsson | c17fb7b | 2009-09-01 05:12:24 +0000 | [diff] [blame] | 18 | #include "clang/Basic/PrettyStackTrace.h" |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 19 | #include "clang/Lex/Preprocessor.h" |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
| 21 | |
| 22 | using namespace clang; |
| 23 | |
| 24 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 25 | class VISIBILITY_HIDDEN TemplateDeclInstantiator |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 26 | : public DeclVisitor<TemplateDeclInstantiator, Decl *> { |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 27 | Sema &SemaRef; |
| 28 | DeclContext *Owner; |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 29 | const MultiLevelTemplateArgumentList &TemplateArgs; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 30 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 31 | public: |
| 32 | typedef Sema::OwningExprResult OwningExprResult; |
| 33 | |
| 34 | TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 35 | const MultiLevelTemplateArgumentList &TemplateArgs) |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 36 | : SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs) { } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 38 | // FIXME: Once we get closer to completion, replace these manually-written |
| 39 | // declarations with automatically-generated ones from |
| 40 | // clang/AST/DeclNodes.def. |
Douglas Gregor | 4f722be | 2009-03-25 15:45:12 +0000 | [diff] [blame] | 41 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 42 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 43 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 44 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 45 | Decl *VisitFieldDecl(FieldDecl *D); |
| 46 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
| 47 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 48 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 49 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 50 | Decl *VisitFunctionDecl(FunctionDecl *D, |
| 51 | TemplateParameterList *TemplateParams = 0); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 52 | Decl *VisitCXXRecordDecl(CXXRecordDecl *D); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 53 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D, |
| 54 | TemplateParameterList *TemplateParams = 0); |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 55 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 56 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 57 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 58 | ParmVarDecl *VisitParmVarDecl(ParmVarDecl *D); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 59 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | 7974c3b | 2009-10-07 17:21:34 +0000 | [diff] [blame] | 60 | Decl *VisitClassTemplatePartialSpecializationDecl( |
| 61 | ClassTemplatePartialSpecializationDecl *D); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 62 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 63 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Douglas Gregor | 33642df | 2009-10-23 23:25:44 +0000 | [diff] [blame] | 64 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
Anders Carlsson | 0dde18e | 2009-08-28 15:18:15 +0000 | [diff] [blame] | 65 | Decl *VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 66 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 67 | // Base case. FIXME: Remove once we can instantiate everything. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | Decl *VisitDecl(Decl *) { |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 69 | assert(false && "Template instantiation of unknown declaration kind!"); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | } |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 72 | |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 73 | const LangOptions &getLangOptions() { |
| 74 | return SemaRef.getLangOptions(); |
| 75 | } |
| 76 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 77 | // Helper functions for instantiating methods. |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 78 | QualType SubstFunctionType(FunctionDecl *D, |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 79 | llvm::SmallVectorImpl<ParmVarDecl *> &Params); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 80 | bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 81 | bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 82 | |
| 83 | TemplateParameterList * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 84 | SubstTemplateParams(TemplateParameterList *List); |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 85 | |
| 86 | bool InstantiateClassTemplatePartialSpecialization( |
| 87 | ClassTemplateDecl *ClassTemplate, |
| 88 | ClassTemplatePartialSpecializationDecl *PartialSpec); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 89 | }; |
| 90 | } |
| 91 | |
Douglas Gregor | 4f722be | 2009-03-25 15:45:12 +0000 | [diff] [blame] | 92 | Decl * |
| 93 | TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 94 | assert(false && "Translation units cannot be instantiated"); |
| 95 | return D; |
| 96 | } |
| 97 | |
| 98 | Decl * |
| 99 | TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) { |
| 100 | assert(false && "Namespaces cannot be instantiated"); |
| 101 | return D; |
| 102 | } |
| 103 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 104 | Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { |
| 105 | bool Invalid = false; |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 106 | DeclaratorInfo *DI = D->getTypeDeclaratorInfo(); |
| 107 | if (DI->getType()->isDependentType()) { |
| 108 | DI = SemaRef.SubstType(DI, TemplateArgs, |
| 109 | D->getLocation(), D->getDeclName()); |
| 110 | if (!DI) { |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 111 | Invalid = true; |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 112 | DI = SemaRef.Context.getTrivialDeclaratorInfo(SemaRef.Context.IntTy); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 116 | // Create the new typedef |
| 117 | TypedefDecl *Typedef |
| 118 | = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
John McCall | ba6a9bd | 2009-10-24 08:00:42 +0000 | [diff] [blame] | 119 | D->getIdentifier(), DI); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 120 | if (Invalid) |
| 121 | Typedef->setInvalidDecl(); |
| 122 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 123 | Owner->addDecl(Typedef); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 125 | return Typedef; |
| 126 | } |
| 127 | |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 128 | Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 129 | // Do substitution on the type of the declaration |
John McCall | 0a5fa06 | 2009-10-21 02:39:02 +0000 | [diff] [blame] | 130 | DeclaratorInfo *DI = SemaRef.SubstType(D->getDeclaratorInfo(), |
| 131 | TemplateArgs, |
| 132 | D->getTypeSpecStartLoc(), |
| 133 | D->getDeclName()); |
| 134 | if (!DI) |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 135 | return 0; |
| 136 | |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 137 | // Build the instantiated declaration |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 138 | VarDecl *Var = VarDecl::Create(SemaRef.Context, Owner, |
| 139 | D->getLocation(), D->getIdentifier(), |
John McCall | 0a5fa06 | 2009-10-21 02:39:02 +0000 | [diff] [blame] | 140 | DI->getType(), DI, |
Argyrios Kyrtzidis | a5d8200 | 2009-08-21 00:31:54 +0000 | [diff] [blame] | 141 | D->getStorageClass()); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 142 | Var->setThreadSpecified(D->isThreadSpecified()); |
| 143 | Var->setCXXDirectInitializer(D->hasCXXDirectInitializer()); |
| 144 | Var->setDeclaredInCondition(D->isDeclaredInCondition()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
| 146 | // If we are instantiating a static data member defined |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 147 | // out-of-line, the instantiation will have the same lexical |
| 148 | // context (which will be a namespace scope) as the template. |
| 149 | if (D->isOutOfLine()) |
| 150 | Var->setLexicalDeclContext(D->getLexicalDeclContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 152 | // FIXME: In theory, we could have a previous declaration for variables that |
| 153 | // are not static data members. |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 154 | bool Redeclaration = false; |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 155 | SemaRef.CheckVariableDeclaration(Var, 0, Redeclaration); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 157 | if (D->isOutOfLine()) { |
| 158 | D->getLexicalDeclContext()->addDecl(Var); |
| 159 | Owner->makeDeclVisibleInContext(Var); |
| 160 | } else { |
| 161 | Owner->addDecl(Var); |
| 162 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 164 | // Link instantiations of static data members back to the template from |
| 165 | // which they were instantiated. |
| 166 | if (Var->isStaticDataMember()) |
| 167 | SemaRef.Context.setInstantiatedFromStaticDataMember(Var, D, |
| 168 | TSK_ImplicitInstantiation); |
| 169 | |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 170 | if (D->getInit()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | OwningExprResult Init |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 172 | = SemaRef.SubstExpr(D->getInit(), TemplateArgs); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 173 | if (Init.isInvalid()) |
| 174 | Var->setInvalidDecl(); |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 175 | else if (ParenListExpr *PLE = dyn_cast<ParenListExpr>((Expr *)Init.get())) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | // FIXME: We're faking all of the comma locations, which is suboptimal. |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 177 | // Do we even need these comma locations? |
| 178 | llvm::SmallVector<SourceLocation, 4> FakeCommaLocs; |
| 179 | if (PLE->getNumExprs() > 0) { |
| 180 | FakeCommaLocs.reserve(PLE->getNumExprs() - 1); |
| 181 | for (unsigned I = 0, N = PLE->getNumExprs() - 1; I != N; ++I) { |
| 182 | Expr *E = PLE->getExpr(I)->Retain(); |
| 183 | FakeCommaLocs.push_back( |
| 184 | SemaRef.PP.getLocForEndOfToken(E->getLocEnd())); |
| 185 | } |
Douglas Gregor | e9f8eb6 | 2009-08-26 23:26:04 +0000 | [diff] [blame] | 186 | PLE->getExpr(PLE->getNumExprs() - 1)->Retain(); |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 187 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 189 | // Add the direct initializer to the declaration. |
| 190 | SemaRef.AddCXXDirectInitializerToDecl(Sema::DeclPtrTy::make(Var), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 191 | PLE->getLParenLoc(), |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 192 | Sema::MultiExprArg(SemaRef, |
| 193 | (void**)PLE->getExprs(), |
| 194 | PLE->getNumExprs()), |
| 195 | FakeCommaLocs.data(), |
| 196 | PLE->getRParenLoc()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Douglas Gregor | 83ddad3 | 2009-08-26 21:14:46 +0000 | [diff] [blame] | 198 | // When Init is destroyed, it will destroy the instantiated ParenListExpr; |
| 199 | // we've explicitly retained all of its subexpressions already. |
| 200 | } else |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 201 | SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init), |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 202 | D->hasCXXDirectInitializer()); |
Douglas Gregor | 65b9005 | 2009-07-27 17:43:39 +0000 | [diff] [blame] | 203 | } else if (!Var->isStaticDataMember() || Var->isOutOfLine()) |
| 204 | SemaRef.ActOnUninitializedDecl(Sema::DeclPtrTy::make(Var), false); |
Douglas Gregor | 3d7a12a | 2009-03-25 23:32:15 +0000 | [diff] [blame] | 205 | |
| 206 | return Var; |
| 207 | } |
| 208 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 209 | Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) { |
| 210 | bool Invalid = false; |
John McCall | 07fb6be | 2009-10-22 23:33:21 +0000 | [diff] [blame] | 211 | DeclaratorInfo *DI = D->getDeclaratorInfo(); |
| 212 | if (DI->getType()->isDependentType()) { |
| 213 | DI = SemaRef.SubstType(DI, TemplateArgs, |
| 214 | D->getLocation(), D->getDeclName()); |
| 215 | if (!DI) { |
| 216 | DI = D->getDeclaratorInfo(); |
| 217 | Invalid = true; |
| 218 | } else if (DI->getType()->isFunctionType()) { |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 219 | // C++ [temp.arg.type]p3: |
| 220 | // If a declaration acquires a function type through a type |
| 221 | // dependent on a template-parameter and this causes a |
| 222 | // declaration that does not use the syntactic form of a |
| 223 | // function declarator to have function type, the program is |
| 224 | // ill-formed. |
| 225 | SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function) |
John McCall | 07fb6be | 2009-10-22 23:33:21 +0000 | [diff] [blame] | 226 | << DI->getType(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 227 | Invalid = true; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | Expr *BitWidth = D->getBitWidth(); |
| 232 | if (Invalid) |
| 233 | BitWidth = 0; |
| 234 | else if (BitWidth) { |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 235 | // The bit-width expression is not potentially evaluated. |
| 236 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 237 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 238 | OwningExprResult InstantiatedBitWidth |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 239 | = SemaRef.SubstExpr(BitWidth, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 240 | if (InstantiatedBitWidth.isInvalid()) { |
| 241 | Invalid = true; |
| 242 | BitWidth = 0; |
| 243 | } else |
Anders Carlsson | e9146f2 | 2009-05-01 19:49:17 +0000 | [diff] [blame] | 244 | BitWidth = InstantiatedBitWidth.takeAs<Expr>(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 245 | } |
| 246 | |
John McCall | 07fb6be | 2009-10-22 23:33:21 +0000 | [diff] [blame] | 247 | FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), |
| 248 | DI->getType(), DI, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | cast<RecordDecl>(Owner), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 250 | D->getLocation(), |
| 251 | D->isMutable(), |
| 252 | BitWidth, |
Steve Naroff | ea218b8 | 2009-07-14 14:58:18 +0000 | [diff] [blame] | 253 | D->getTypeSpecStartLoc(), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 254 | D->getAccess(), |
| 255 | 0); |
Douglas Gregor | 663b5a0 | 2009-10-14 20:14:33 +0000 | [diff] [blame] | 256 | if (!Field) { |
| 257 | cast<Decl>(Owner)->setInvalidDecl(); |
Anders Carlsson | f4b5f5c | 2009-09-02 19:17:55 +0000 | [diff] [blame] | 258 | return 0; |
Douglas Gregor | 663b5a0 | 2009-10-14 20:14:33 +0000 | [diff] [blame] | 259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 260 | |
Anders Carlsson | f4b5f5c | 2009-09-02 19:17:55 +0000 | [diff] [blame] | 261 | if (Invalid) |
| 262 | Field->setInvalidDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | |
Anders Carlsson | f4b5f5c | 2009-09-02 19:17:55 +0000 | [diff] [blame] | 264 | if (!Field->getDeclName()) { |
| 265 | // Keep track of where this decl came from. |
| 266 | SemaRef.Context.setInstantiatedFromUnnamedFieldDecl(Field, D); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Anders Carlsson | f4b5f5c | 2009-09-02 19:17:55 +0000 | [diff] [blame] | 269 | Field->setImplicit(D->isImplicit()); |
| 270 | Owner->addDecl(Field); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 271 | |
| 272 | return Field; |
| 273 | } |
| 274 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 275 | Decl *TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) { |
| 276 | FriendDecl::FriendUnion FU; |
| 277 | |
| 278 | // Handle friend type expressions by simply substituting template |
| 279 | // parameters into the pattern type. |
| 280 | if (Type *Ty = D->getFriendType()) { |
| 281 | QualType T = SemaRef.SubstType(QualType(Ty,0), TemplateArgs, |
| 282 | D->getLocation(), DeclarationName()); |
| 283 | if (T.isNull()) return 0; |
| 284 | |
| 285 | assert(getLangOptions().CPlusPlus0x || T->isRecordType()); |
| 286 | FU = T.getTypePtr(); |
| 287 | |
| 288 | // Handle everything else by appropriate substitution. |
| 289 | } else { |
| 290 | NamedDecl *ND = D->getFriendDecl(); |
| 291 | assert(ND && "friend decl must be a decl or a type!"); |
| 292 | |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 293 | // FIXME: We have a problem here, because the nested call to Visit(ND) |
| 294 | // will inject the thing that the friend references into the current |
| 295 | // owner, which is wrong. |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 296 | Decl *NewND = Visit(ND); |
| 297 | if (!NewND) return 0; |
| 298 | |
| 299 | FU = cast<NamedDecl>(NewND); |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 302 | FriendDecl *FD = |
| 303 | FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), FU, |
| 304 | D->getFriendLoc()); |
John McCall | 5fee110 | 2009-08-29 03:50:18 +0000 | [diff] [blame] | 305 | FD->setAccess(AS_public); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 306 | Owner->addDecl(FD); |
| 307 | return FD; |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 310 | Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 311 | Expr *AssertExpr = D->getAssertExpr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 313 | // The expression in a static assertion is not potentially evaluated. |
| 314 | EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 316 | OwningExprResult InstantiatedAssertExpr |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 317 | = SemaRef.SubstExpr(AssertExpr, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 318 | if (InstantiatedAssertExpr.isInvalid()) |
| 319 | return 0; |
| 320 | |
Douglas Gregor | 43d9d92 | 2009-08-08 01:41:12 +0000 | [diff] [blame] | 321 | OwningExprResult Message(SemaRef, D->getMessage()); |
| 322 | D->getMessage()->Retain(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | Decl *StaticAssert |
| 324 | = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(), |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 325 | move(InstantiatedAssertExpr), |
| 326 | move(Message)).getAs<Decl>(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 327 | return StaticAssert; |
| 328 | } |
| 329 | |
| 330 | Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 332 | D->getLocation(), D->getIdentifier(), |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 333 | D->getTagKeywordLoc(), |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 334 | /*PrevDecl=*/0); |
Douglas Gregor | 8dbc3c6 | 2009-05-27 17:20:35 +0000 | [diff] [blame] | 335 | Enum->setInstantiationOfMemberEnum(D); |
Douglas Gregor | 06c0fec | 2009-03-25 22:00:53 +0000 | [diff] [blame] | 336 | Enum->setAccess(D->getAccess()); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 337 | Owner->addDecl(Enum); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 338 | Enum->startDefinition(); |
| 339 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 340 | llvm::SmallVector<Sema::DeclPtrTy, 4> Enumerators; |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 341 | |
| 342 | EnumConstantDecl *LastEnumConst = 0; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 343 | for (EnumDecl::enumerator_iterator EC = D->enumerator_begin(), |
| 344 | ECEnd = D->enumerator_end(); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 345 | EC != ECEnd; ++EC) { |
| 346 | // The specified value for the enumerator. |
| 347 | OwningExprResult Value = SemaRef.Owned((Expr *)0); |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 348 | if (Expr *UninstValue = EC->getInitExpr()) { |
| 349 | // The enumerator's value expression is not potentially evaluated. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | EnterExpressionEvaluationContext Unevaluated(SemaRef, |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 351 | Action::Unevaluated); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 353 | Value = SemaRef.SubstExpr(UninstValue, TemplateArgs); |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 354 | } |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 355 | |
| 356 | // Drop the initial value and continue. |
| 357 | bool isInvalid = false; |
| 358 | if (Value.isInvalid()) { |
| 359 | Value = SemaRef.Owned((Expr *)0); |
| 360 | isInvalid = true; |
| 361 | } |
| 362 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | EnumConstantDecl *EnumConst |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 364 | = SemaRef.CheckEnumConstant(Enum, LastEnumConst, |
| 365 | EC->getLocation(), EC->getIdentifier(), |
| 366 | move(Value)); |
| 367 | |
| 368 | if (isInvalid) { |
| 369 | if (EnumConst) |
| 370 | EnumConst->setInvalidDecl(); |
| 371 | Enum->setInvalidDecl(); |
| 372 | } |
| 373 | |
| 374 | if (EnumConst) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 375 | Enum->addDecl(EnumConst); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 376 | Enumerators.push_back(Sema::DeclPtrTy::make(EnumConst)); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 377 | LastEnumConst = EnumConst; |
| 378 | } |
| 379 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 380 | |
Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 381 | // FIXME: Fixup LBraceLoc and RBraceLoc |
Edward O'Callaghan | fee1381 | 2009-08-08 14:36:57 +0000 | [diff] [blame] | 382 | // FIXME: Empty Scope and AttributeList (required to handle attribute packed). |
Mike Stump | c6e35aa | 2009-05-16 07:06:02 +0000 | [diff] [blame] | 383 | SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(), SourceLocation(), |
| 384 | Sema::DeclPtrTy::make(Enum), |
Edward O'Callaghan | fee1381 | 2009-08-08 14:36:57 +0000 | [diff] [blame] | 385 | &Enumerators[0], Enumerators.size(), |
| 386 | 0, 0); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 387 | |
| 388 | return Enum; |
| 389 | } |
| 390 | |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 391 | Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 392 | assert(false && "EnumConstantDecls can only occur within EnumDecls."); |
| 393 | return 0; |
| 394 | } |
| 395 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 396 | namespace { |
| 397 | class SortDeclByLocation { |
| 398 | SourceManager &SourceMgr; |
| 399 | |
| 400 | public: |
| 401 | explicit SortDeclByLocation(SourceManager &SourceMgr) |
| 402 | : SourceMgr(SourceMgr) { } |
| 403 | |
| 404 | bool operator()(const Decl *X, const Decl *Y) const { |
| 405 | return SourceMgr.isBeforeInTranslationUnit(X->getLocation(), |
| 406 | Y->getLocation()); |
| 407 | } |
| 408 | }; |
| 409 | } |
| 410 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 411 | Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 412 | // Create a local instantiation scope for this class template, which |
| 413 | // will contain the instantiations of the template parameters. |
| 414 | Sema::LocalInstantiationScope Scope(SemaRef); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 415 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 416 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | if (!InstParams) |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 418 | return NULL; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 419 | |
| 420 | CXXRecordDecl *Pattern = D->getTemplatedDecl(); |
| 421 | CXXRecordDecl *RecordInst |
| 422 | = CXXRecordDecl::Create(SemaRef.Context, Pattern->getTagKind(), Owner, |
| 423 | Pattern->getLocation(), Pattern->getIdentifier(), |
Douglas Gregor | f0510d4 | 2009-10-12 23:11:44 +0000 | [diff] [blame] | 424 | Pattern->getTagKeywordLoc(), /*PrevDecl=*/ NULL, |
| 425 | /*DelayTypeCreation=*/true); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 426 | |
| 427 | ClassTemplateDecl *Inst |
| 428 | = ClassTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 429 | D->getIdentifier(), InstParams, RecordInst, 0); |
| 430 | RecordInst->setDescribedClassTemplate(Inst); |
Douglas Gregor | e8c01bd | 2009-10-30 21:07:27 +0000 | [diff] [blame] | 431 | if (D->getFriendObjectKind()) |
| 432 | Inst->setObjectOfFriendDecl(true); |
| 433 | else |
| 434 | Inst->setAccess(D->getAccess()); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 435 | Inst->setInstantiatedFromMemberTemplate(D); |
Douglas Gregor | f0510d4 | 2009-10-12 23:11:44 +0000 | [diff] [blame] | 436 | |
| 437 | // Trigger creation of the type for the instantiation. |
| 438 | SemaRef.Context.getTypeDeclType(RecordInst); |
| 439 | |
Douglas Gregor | 259571e | 2009-10-30 22:42:42 +0000 | [diff] [blame] | 440 | // Finish handling of friends. |
| 441 | if (Inst->getFriendObjectKind()) { |
Douglas Gregor | e8c01bd | 2009-10-30 21:07:27 +0000 | [diff] [blame] | 442 | return Inst; |
Douglas Gregor | 259571e | 2009-10-30 22:42:42 +0000 | [diff] [blame] | 443 | } |
Douglas Gregor | e8c01bd | 2009-10-30 21:07:27 +0000 | [diff] [blame] | 444 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 445 | Owner->addDecl(Inst); |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 446 | |
| 447 | // First, we sort the partial specializations by location, so |
| 448 | // that we instantiate them in the order they were declared. |
| 449 | llvm::SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; |
| 450 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 451 | P = D->getPartialSpecializations().begin(), |
| 452 | PEnd = D->getPartialSpecializations().end(); |
| 453 | P != PEnd; ++P) |
| 454 | PartialSpecs.push_back(&*P); |
| 455 | std::sort(PartialSpecs.begin(), PartialSpecs.end(), |
| 456 | SortDeclByLocation(SemaRef.SourceMgr)); |
| 457 | |
| 458 | // Instantiate all of the partial specializations of this member class |
| 459 | // template. |
| 460 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) |
| 461 | InstantiateClassTemplatePartialSpecialization(Inst, PartialSpecs[I]); |
| 462 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 463 | return Inst; |
| 464 | } |
| 465 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 466 | Decl * |
Douglas Gregor | 7974c3b | 2009-10-07 17:21:34 +0000 | [diff] [blame] | 467 | TemplateDeclInstantiator::VisitClassTemplatePartialSpecializationDecl( |
| 468 | ClassTemplatePartialSpecializationDecl *D) { |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 469 | ClassTemplateDecl *ClassTemplate = D->getSpecializedTemplate(); |
| 470 | |
| 471 | // Lookup the already-instantiated declaration in the instantiation |
| 472 | // of the class template and return that. |
| 473 | DeclContext::lookup_result Found |
| 474 | = Owner->lookup(ClassTemplate->getDeclName()); |
| 475 | if (Found.first == Found.second) |
| 476 | return 0; |
| 477 | |
| 478 | ClassTemplateDecl *InstClassTemplate |
| 479 | = dyn_cast<ClassTemplateDecl>(*Found.first); |
| 480 | if (!InstClassTemplate) |
| 481 | return 0; |
| 482 | |
| 483 | Decl *DCanon = D->getCanonicalDecl(); |
| 484 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 485 | P = InstClassTemplate->getPartialSpecializations().begin(), |
| 486 | PEnd = InstClassTemplate->getPartialSpecializations().end(); |
| 487 | P != PEnd; ++P) { |
| 488 | if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon) |
| 489 | return &*P; |
| 490 | } |
| 491 | |
Douglas Gregor | 7974c3b | 2009-10-07 17:21:34 +0000 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | Decl * |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 496 | TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 497 | // Create a local instantiation scope for this function template, which |
| 498 | // will contain the instantiations of the template parameters and then get |
| 499 | // merged with the local instantiation scope for the function template |
| 500 | // itself. |
| 501 | Sema::LocalInstantiationScope Scope(SemaRef); |
| 502 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 503 | TemplateParameterList *TempParams = D->getTemplateParameters(); |
| 504 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 505 | if (!InstParams) |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 506 | return NULL; |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 508 | FunctionDecl *Instantiated = 0; |
| 509 | if (CXXMethodDecl *DMethod = dyn_cast<CXXMethodDecl>(D->getTemplatedDecl())) |
| 510 | Instantiated = cast_or_null<FunctionDecl>(VisitCXXMethodDecl(DMethod, |
| 511 | InstParams)); |
| 512 | else |
| 513 | Instantiated = cast_or_null<FunctionDecl>(VisitFunctionDecl( |
| 514 | D->getTemplatedDecl(), |
| 515 | InstParams)); |
| 516 | |
| 517 | if (!Instantiated) |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 518 | return 0; |
| 519 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | // Link the instantiated function template declaration to the function |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 521 | // template from which it was instantiated. |
Douglas Gregor | 37d68185 | 2009-10-12 22:27:17 +0000 | [diff] [blame] | 522 | FunctionTemplateDecl *InstTemplate |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 523 | = Instantiated->getDescribedFunctionTemplate(); |
Douglas Gregor | 37d68185 | 2009-10-12 22:27:17 +0000 | [diff] [blame] | 524 | InstTemplate->setAccess(D->getAccess()); |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 525 | assert(InstTemplate && |
| 526 | "VisitFunctionDecl/CXXMethodDecl didn't create a template!"); |
| 527 | if (!InstTemplate->getInstantiatedFromMemberTemplate()) |
| 528 | InstTemplate->setInstantiatedFromMemberTemplate(D); |
| 529 | |
| 530 | // Add non-friends into the owner. |
| 531 | if (!InstTemplate->getFriendObjectKind()) |
| 532 | Owner->addDecl(InstTemplate); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 533 | return InstTemplate; |
| 534 | } |
| 535 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 536 | Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { |
| 537 | CXXRecordDecl *PrevDecl = 0; |
| 538 | if (D->isInjectedClassName()) |
| 539 | PrevDecl = cast<CXXRecordDecl>(Owner); |
| 540 | |
| 541 | CXXRecordDecl *Record |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner, |
Douglas Gregor | 741dd9a | 2009-07-21 14:46:17 +0000 | [diff] [blame] | 543 | D->getLocation(), D->getIdentifier(), |
| 544 | D->getTagKeywordLoc(), PrevDecl); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 545 | Record->setImplicit(D->isImplicit()); |
Eli Friedman | eaba1af | 2009-08-27 19:11:42 +0000 | [diff] [blame] | 546 | // FIXME: Check against AS_none is an ugly hack to work around the issue that |
| 547 | // the tag decls introduced by friend class declarations don't have an access |
| 548 | // specifier. Remove once this area of the code gets sorted out. |
| 549 | if (D->getAccess() != AS_none) |
| 550 | Record->setAccess(D->getAccess()); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 551 | if (!D->isInjectedClassName()) |
Douglas Gregor | f6b1185 | 2009-10-08 15:14:33 +0000 | [diff] [blame] | 552 | Record->setInstantiationOfMemberClass(D, TSK_ImplicitInstantiation); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 553 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 554 | // If the original function was part of a friend declaration, |
| 555 | // inherit its namespace state. |
| 556 | if (Decl::FriendObjectKind FOK = D->getFriendObjectKind()) |
| 557 | Record->setObjectOfFriendDecl(FOK == Decl::FOK_Declared); |
| 558 | |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 559 | Record->setAnonymousStructOrUnion(D->isAnonymousStructOrUnion()); |
| 560 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 561 | Owner->addDecl(Record); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 562 | return Record; |
| 563 | } |
| 564 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 565 | /// Normal class members are of more specific types and therefore |
| 566 | /// don't make it here. This function serves two purposes: |
| 567 | /// 1) instantiating function templates |
| 568 | /// 2) substituting friend declarations |
| 569 | /// FIXME: preserve function definitions in case #2 |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 570 | Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, |
| 571 | TemplateParameterList *TemplateParams) { |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 572 | // Check whether there is already a function template specialization for |
| 573 | // this declaration. |
| 574 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
| 575 | void *InsertPos = 0; |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 576 | if (FunctionTemplate && !TemplateParams) { |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 577 | llvm::FoldingSetNodeID ID; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | FunctionTemplateSpecializationInfo::Profile(ID, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 579 | TemplateArgs.getInnermost().getFlatArgumentList(), |
| 580 | TemplateArgs.getInnermost().flat_size(), |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 581 | SemaRef.Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
| 583 | FunctionTemplateSpecializationInfo *Info |
| 584 | = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 585 | InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 587 | // If we already have a function template specialization, return it. |
| 588 | if (Info) |
| 589 | return Info->Function; |
| 590 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 592 | Sema::LocalInstantiationScope Scope(SemaRef, TemplateParams != 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 594 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 595 | QualType T = SubstFunctionType(D, Params); |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 596 | if (T.isNull()) |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 597 | return 0; |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 598 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 599 | // Build the instantiated method declaration. |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 600 | DeclContext *DC = SemaRef.FindInstantiatedContext(D->getDeclContext(), |
| 601 | TemplateArgs); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 602 | FunctionDecl *Function = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(), |
Argyrios Kyrtzidis | a1d5662 | 2009-08-19 01:27:57 +0000 | [diff] [blame] | 604 | D->getDeclName(), T, D->getDeclaratorInfo(), |
| 605 | D->getStorageClass(), |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 606 | D->isInlineSpecified(), D->hasWrittenPrototype()); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 607 | Function->setLexicalDeclContext(Owner); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 609 | // Attach the parameters |
| 610 | for (unsigned P = 0; P < Params.size(); ++P) |
| 611 | Params[P]->setOwningFunction(Function); |
| 612 | Function->setParams(SemaRef.Context, Params.data(), Params.size()); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 614 | if (TemplateParams) { |
| 615 | // Our resulting instantiation is actually a function template, since we |
| 616 | // are substituting only the outer template parameters. For example, given |
| 617 | // |
| 618 | // template<typename T> |
| 619 | // struct X { |
| 620 | // template<typename U> friend void f(T, U); |
| 621 | // }; |
| 622 | // |
| 623 | // X<int> x; |
| 624 | // |
| 625 | // We are instantiating the friend function template "f" within X<int>, |
| 626 | // which means substituting int for T, but leaving "f" as a friend function |
| 627 | // template. |
| 628 | // Build the function template itself. |
| 629 | FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Owner, |
| 630 | Function->getLocation(), |
| 631 | Function->getDeclName(), |
| 632 | TemplateParams, Function); |
| 633 | Function->setDescribedFunctionTemplate(FunctionTemplate); |
| 634 | FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 635 | } |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 636 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 637 | if (InitFunctionInstantiation(Function, D)) |
| 638 | Function->setInvalidDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 639 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 640 | bool Redeclaration = false; |
| 641 | bool OverloadableAttrRequired = false; |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 643 | NamedDecl *PrevDecl = 0; |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 644 | if (TemplateParams || !FunctionTemplate) { |
| 645 | // Look only into the namespace where the friend would be declared to |
| 646 | // find a previous declaration. This is the innermost enclosing namespace, |
| 647 | // as described in ActOnFriendFunctionDecl. |
| 648 | Sema::LookupResult R; |
| 649 | SemaRef.LookupQualifiedName(R, DC, Function->getDeclName(), |
| 650 | Sema::LookupOrdinaryName, true); |
| 651 | |
| 652 | PrevDecl = R.getAsSingleDecl(SemaRef.Context); |
| 653 | |
| 654 | // In C++, the previous declaration we find might be a tag type |
| 655 | // (class or enum). In this case, the new declaration will hide the |
| 656 | // tag type. Note that this does does not apply if we're declaring a |
| 657 | // typedef (C++ [dcl.typedef]p4). |
| 658 | if (PrevDecl && PrevDecl->getIdentifierNamespace() == Decl::IDNS_Tag) |
| 659 | PrevDecl = 0; |
| 660 | } |
| 661 | |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 662 | SemaRef.CheckFunctionDeclaration(Function, PrevDecl, false, Redeclaration, |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 663 | /*FIXME:*/OverloadableAttrRequired); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 664 | |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 665 | // If the original function was part of a friend declaration, |
| 666 | // inherit its namespace state and add it to the owner. |
| 667 | NamedDecl *FromFriendD |
| 668 | = TemplateParams? cast<NamedDecl>(D->getDescribedFunctionTemplate()) : D; |
| 669 | if (FromFriendD->getFriendObjectKind()) { |
| 670 | NamedDecl *ToFriendD = 0; |
| 671 | if (TemplateParams) { |
| 672 | ToFriendD = cast<NamedDecl>(FunctionTemplate); |
| 673 | PrevDecl = FunctionTemplate->getPreviousDeclaration(); |
| 674 | } else { |
| 675 | ToFriendD = Function; |
| 676 | PrevDecl = Function->getPreviousDeclaration(); |
| 677 | } |
| 678 | ToFriendD->setObjectOfFriendDecl(PrevDecl != NULL); |
| 679 | if (!Owner->isDependentContext() && !PrevDecl) |
| 680 | DC->makeDeclVisibleInContext(ToFriendD, /* Recoverable = */ false); |
| 681 | |
| 682 | if (!TemplateParams) |
| 683 | Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); |
| 684 | } |
| 685 | |
| 686 | if (FunctionTemplate && !TemplateParams) { |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 687 | // Record this function template specialization. |
| 688 | Function->setFunctionTemplateSpecialization(SemaRef.Context, |
| 689 | FunctionTemplate, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 690 | &TemplateArgs.getInnermost(), |
Douglas Gregor | 127102b | 2009-06-29 20:59:39 +0000 | [diff] [blame] | 691 | InsertPos); |
John McCall | fd810b1 | 2009-08-14 02:03:10 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 694 | return Function; |
| 695 | } |
| 696 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 697 | Decl * |
| 698 | TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, |
| 699 | TemplateParameterList *TemplateParams) { |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 700 | FunctionTemplateDecl *FunctionTemplate = D->getDescribedFunctionTemplate(); |
| 701 | void *InsertPos = 0; |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 702 | if (FunctionTemplate && !TemplateParams) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | // We are creating a function template specialization from a function |
| 704 | // template. Check whether there is already a function template |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 705 | // specialization for this particular set of template arguments. |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 706 | llvm::FoldingSetNodeID ID; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | FunctionTemplateSpecializationInfo::Profile(ID, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 708 | TemplateArgs.getInnermost().getFlatArgumentList(), |
| 709 | TemplateArgs.getInnermost().flat_size(), |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 710 | SemaRef.Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
| 712 | FunctionTemplateSpecializationInfo *Info |
| 713 | = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 714 | InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 716 | // If we already have a function template specialization, return it. |
| 717 | if (Info) |
| 718 | return Info->Function; |
| 719 | } |
| 720 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 721 | Sema::LocalInstantiationScope Scope(SemaRef, TemplateParams != 0); |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 722 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 723 | llvm::SmallVector<ParmVarDecl *, 4> Params; |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 724 | QualType T = SubstFunctionType(D, Params); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 725 | if (T.isNull()) |
| 726 | return 0; |
| 727 | |
| 728 | // Build the instantiated method declaration. |
| 729 | CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 730 | CXXMethodDecl *Method = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 732 | DeclarationName Name = D->getDeclName(); |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 733 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 734 | QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); |
| 735 | Name = SemaRef.Context.DeclarationNames.getCXXConstructorName( |
| 736 | SemaRef.Context.getCanonicalType(ClassTy)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | Method = CXXConstructorDecl::Create(SemaRef.Context, Record, |
| 738 | Constructor->getLocation(), |
| 739 | Name, T, |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 740 | Constructor->getDeclaratorInfo(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | Constructor->isExplicit(), |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 742 | Constructor->isInlineSpecified(), false); |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 743 | } else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) { |
| 744 | QualType ClassTy = SemaRef.Context.getTypeDeclType(Record); |
| 745 | Name = SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 746 | SemaRef.Context.getCanonicalType(ClassTy)); |
| 747 | Method = CXXDestructorDecl::Create(SemaRef.Context, Record, |
| 748 | Destructor->getLocation(), Name, |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 749 | T, Destructor->isInlineSpecified(), false); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 750 | } else if (CXXConversionDecl *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | CanQualType ConvTy |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 752 | = SemaRef.Context.getCanonicalType( |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 753 | T->getAs<FunctionType>()->getResultType()); |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 754 | Name = SemaRef.Context.DeclarationNames.getCXXConversionFunctionName( |
| 755 | ConvTy); |
| 756 | Method = CXXConversionDecl::Create(SemaRef.Context, Record, |
| 757 | Conversion->getLocation(), Name, |
| 758 | T, Conversion->getDeclaratorInfo(), |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 759 | Conversion->isInlineSpecified(), |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 760 | Conversion->isExplicit()); |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 761 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | Method = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(), |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 763 | D->getDeclName(), T, D->getDeclaratorInfo(), |
Douglas Gregor | 0130f3c | 2009-10-27 21:01:01 +0000 | [diff] [blame] | 764 | D->isStatic(), D->isInlineSpecified()); |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 765 | } |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 766 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 767 | if (TemplateParams) { |
| 768 | // Our resulting instantiation is actually a function template, since we |
| 769 | // are substituting only the outer template parameters. For example, given |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 770 | // |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 771 | // template<typename T> |
| 772 | // struct X { |
| 773 | // template<typename U> void f(T, U); |
| 774 | // }; |
| 775 | // |
| 776 | // X<int> x; |
| 777 | // |
| 778 | // We are instantiating the member template "f" within X<int>, which means |
| 779 | // substituting int for T, but leaving "f" as a member function template. |
| 780 | // Build the function template itself. |
| 781 | FunctionTemplate = FunctionTemplateDecl::Create(SemaRef.Context, Record, |
| 782 | Method->getLocation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 783 | Method->getDeclName(), |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 784 | TemplateParams, Method); |
| 785 | if (D->isOutOfLine()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 787 | Method->setDescribedFunctionTemplate(FunctionTemplate); |
| 788 | } else if (!FunctionTemplate) |
Douglas Gregor | 2db3232 | 2009-10-07 23:56:10 +0000 | [diff] [blame] | 789 | Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 790 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 791 | // If we are instantiating a member function defined |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 792 | // out-of-line, the instantiation will have the same lexical |
| 793 | // context (which will be a namespace scope) as the template. |
| 794 | if (D->isOutOfLine()) |
| 795 | Method->setLexicalDeclContext(D->getLexicalDeclContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 797 | // Attach the parameters |
| 798 | for (unsigned P = 0; P < Params.size(); ++P) |
| 799 | Params[P]->setOwningFunction(Method); |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 800 | Method->setParams(SemaRef.Context, Params.data(), Params.size()); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 801 | |
| 802 | if (InitMethodInstantiation(Method, D)) |
| 803 | Method->setInvalidDecl(); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 805 | NamedDecl *PrevDecl = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 807 | if (!FunctionTemplate || TemplateParams) { |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 808 | Sema::LookupResult R; |
| 809 | SemaRef.LookupQualifiedName(R, Owner, Name, Sema::LookupOrdinaryName, true); |
| 810 | PrevDecl = R.getAsSingleDecl(SemaRef.Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 812 | // In C++, the previous declaration we find might be a tag type |
| 813 | // (class or enum). In this case, the new declaration will hide the |
| 814 | // tag type. Note that this does does not apply if we're declaring a |
| 815 | // typedef (C++ [dcl.typedef]p4). |
| 816 | if (PrevDecl && PrevDecl->getIdentifierNamespace() == Decl::IDNS_Tag) |
| 817 | PrevDecl = 0; |
| 818 | } |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 819 | |
Douglas Gregor | d60e105 | 2009-08-27 16:57:43 +0000 | [diff] [blame] | 820 | if (FunctionTemplate && !TemplateParams) |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 821 | // Record this function template specialization. |
| 822 | Method->setFunctionTemplateSpecialization(SemaRef.Context, |
| 823 | FunctionTemplate, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 824 | &TemplateArgs.getInnermost(), |
Douglas Gregor | 6b90686 | 2009-08-21 00:16:32 +0000 | [diff] [blame] | 825 | InsertPos); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 827 | bool Redeclaration = false; |
| 828 | bool OverloadableAttrRequired = false; |
Douglas Gregor | fd056bc | 2009-10-13 16:30:37 +0000 | [diff] [blame] | 829 | SemaRef.CheckFunctionDeclaration(Method, PrevDecl, false, Redeclaration, |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 830 | /*FIXME:*/OverloadableAttrRequired); |
| 831 | |
Douglas Gregor | a735b20 | 2009-10-13 14:39:41 +0000 | [diff] [blame] | 832 | if (!FunctionTemplate && (!Method->isInvalidDecl() || !PrevDecl) && |
| 833 | !Method->getFriendObjectKind()) |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 834 | Owner->addDecl(Method); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 836 | return Method; |
| 837 | } |
| 838 | |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 839 | Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | dec0666 | 2009-08-21 18:42:58 +0000 | [diff] [blame] | 840 | return VisitCXXMethodDecl(D); |
Douglas Gregor | 615c5d4 | 2009-03-24 16:43:20 +0000 | [diff] [blame] | 841 | } |
| 842 | |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 843 | Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 17e32f3 | 2009-08-21 22:43:28 +0000 | [diff] [blame] | 844 | return VisitCXXMethodDecl(D); |
Douglas Gregor | 03b2b07 | 2009-03-24 00:15:49 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 847 | Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 65ec1fd | 2009-08-21 23:19:43 +0000 | [diff] [blame] | 848 | return VisitCXXMethodDecl(D); |
Douglas Gregor | bb969ed | 2009-03-25 00:34:44 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 851 | ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) { |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 852 | QualType T; |
| 853 | DeclaratorInfo *DI = D->getDeclaratorInfo(); |
| 854 | if (DI) { |
| 855 | DI = SemaRef.SubstType(DI, TemplateArgs, D->getLocation(), |
| 856 | D->getDeclName()); |
| 857 | if (DI) T = DI->getType(); |
| 858 | } else { |
| 859 | T = SemaRef.SubstType(D->getType(), TemplateArgs, D->getLocation(), |
| 860 | D->getDeclName()); |
| 861 | DI = 0; |
| 862 | } |
| 863 | |
| 864 | if (T.isNull()) |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 865 | return 0; |
| 866 | |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 867 | T = SemaRef.adjustParameterType(T); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 868 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 869 | // Allocate the parameter |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 870 | ParmVarDecl *Param |
| 871 | = ParmVarDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 872 | D->getIdentifier(), T, DI, D->getStorageClass(), 0); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 873 | |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 874 | // Mark the default argument as being uninstantiated. |
Douglas Gregor | f43d0b3 | 2009-09-25 06:56:31 +0000 | [diff] [blame] | 875 | if (D->hasUninstantiatedDefaultArg()) |
| 876 | Param->setUninstantiatedDefaultArg(D->getUninstantiatedDefaultArg()); |
Douglas Gregor | 0ed0930 | 2009-09-25 07:03:22 +0000 | [diff] [blame] | 877 | else if (Expr *Arg = D->getDefaultArg()) |
| 878 | Param->setUninstantiatedDefaultArg(Arg); |
| 879 | |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 880 | // Note: we don't try to instantiate function parameters until after |
| 881 | // we've instantiated the function's type. Therefore, we don't have |
| 882 | // to check for 'void' parameter types here. |
Douglas Gregor | 48dd19b | 2009-05-14 21:44:34 +0000 | [diff] [blame] | 883 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param); |
Douglas Gregor | 2dc0e64 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 884 | return Param; |
| 885 | } |
| 886 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 887 | Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( |
| 888 | TemplateTypeParmDecl *D) { |
| 889 | // TODO: don't always clone when decls are refcounted. |
| 890 | const Type* T = D->getTypeForDecl(); |
| 891 | assert(T->isTemplateTypeParmType()); |
| 892 | const TemplateTypeParmType *TTPT = T->getAs<TemplateTypeParmType>(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 894 | TemplateTypeParmDecl *Inst = |
| 895 | TemplateTypeParmDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 896 | TTPT->getDepth() - 1, TTPT->getIndex(), |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 897 | TTPT->getName(), |
| 898 | D->wasDeclaredWithTypename(), |
| 899 | D->isParameterPack()); |
| 900 | |
Douglas Gregor | 33642df | 2009-10-23 23:25:44 +0000 | [diff] [blame] | 901 | // FIXME: Do we actually want to perform substitution here? I don't think |
| 902 | // we do. |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 903 | if (D->hasDefaultArgument()) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 904 | DeclaratorInfo *DefaultPattern = D->getDefaultArgumentInfo(); |
| 905 | DeclaratorInfo *DefaultInst |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 906 | = SemaRef.SubstType(DefaultPattern, TemplateArgs, |
| 907 | D->getDefaultArgumentLoc(), |
| 908 | D->getDeclName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 910 | Inst->setDefaultArgument(DefaultInst, |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 911 | D->defaultArgumentWasInherited() /* preserve? */); |
| 912 | } |
| 913 | |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 914 | // Introduce this template parameter's instantiation into the instantiation |
| 915 | // scope. |
| 916 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 917 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 918 | return Inst; |
| 919 | } |
| 920 | |
Douglas Gregor | 33642df | 2009-10-23 23:25:44 +0000 | [diff] [blame] | 921 | Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( |
| 922 | NonTypeTemplateParmDecl *D) { |
| 923 | // Substitute into the type of the non-type template parameter. |
| 924 | QualType T; |
| 925 | DeclaratorInfo *DI = D->getDeclaratorInfo(); |
| 926 | if (DI) { |
| 927 | DI = SemaRef.SubstType(DI, TemplateArgs, D->getLocation(), |
| 928 | D->getDeclName()); |
| 929 | if (DI) T = DI->getType(); |
| 930 | } else { |
| 931 | T = SemaRef.SubstType(D->getType(), TemplateArgs, D->getLocation(), |
| 932 | D->getDeclName()); |
| 933 | DI = 0; |
| 934 | } |
| 935 | if (T.isNull()) |
| 936 | return 0; |
| 937 | |
| 938 | // Check that this type is acceptable for a non-type template parameter. |
| 939 | bool Invalid = false; |
| 940 | T = SemaRef.CheckNonTypeTemplateParameterType(T, D->getLocation()); |
| 941 | if (T.isNull()) { |
| 942 | T = SemaRef.Context.IntTy; |
| 943 | Invalid = true; |
| 944 | } |
| 945 | |
| 946 | NonTypeTemplateParmDecl *Param |
| 947 | = NonTypeTemplateParmDecl::Create(SemaRef.Context, Owner, D->getLocation(), |
| 948 | D->getDepth() - 1, D->getPosition(), |
| 949 | D->getIdentifier(), T, DI); |
| 950 | if (Invalid) |
| 951 | Param->setInvalidDecl(); |
| 952 | |
| 953 | Param->setDefaultArgument(D->getDefaultArgument()); |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 954 | |
| 955 | // Introduce this template parameter's instantiation into the instantiation |
| 956 | // scope. |
| 957 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param); |
Douglas Gregor | 33642df | 2009-10-23 23:25:44 +0000 | [diff] [blame] | 958 | return Param; |
| 959 | } |
| 960 | |
Anders Carlsson | 0dde18e | 2009-08-28 15:18:15 +0000 | [diff] [blame] | 961 | Decl * |
| 962 | TemplateDeclInstantiator::VisitUnresolvedUsingDecl(UnresolvedUsingDecl *D) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | NestedNameSpecifier *NNS = |
| 964 | SemaRef.SubstNestedNameSpecifier(D->getTargetNestedNameSpecifier(), |
| 965 | D->getTargetNestedNameRange(), |
Anders Carlsson | 0dde18e | 2009-08-28 15:18:15 +0000 | [diff] [blame] | 966 | TemplateArgs); |
| 967 | if (!NNS) |
| 968 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Anders Carlsson | 0dde18e | 2009-08-28 15:18:15 +0000 | [diff] [blame] | 970 | CXXScopeSpec SS; |
| 971 | SS.setRange(D->getTargetNestedNameRange()); |
| 972 | SS.setScopeRep(NNS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
| 974 | NamedDecl *UD = |
| 975 | SemaRef.BuildUsingDeclaration(D->getLocation(), SS, |
| 976 | D->getTargetNameLocation(), |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 977 | D->getTargetName(), 0, D->isTypeName()); |
| 978 | if (UD) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | SemaRef.Context.setInstantiatedFromUnresolvedUsingDecl(cast<UsingDecl>(UD), |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 980 | D); |
| 981 | return UD; |
Anders Carlsson | 0dde18e | 2009-08-28 15:18:15 +0000 | [diff] [blame] | 982 | } |
| 983 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 984 | Decl *Sema::SubstDecl(Decl *D, DeclContext *Owner, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 985 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 986 | TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs); |
Douglas Gregor | 8dbc269 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 987 | return Instantiator.Visit(D); |
| 988 | } |
| 989 | |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 990 | /// \brief Instantiates a nested template parameter list in the current |
| 991 | /// instantiation context. |
| 992 | /// |
| 993 | /// \param L The parameter list to instantiate |
| 994 | /// |
| 995 | /// \returns NULL if there was an error |
| 996 | TemplateParameterList * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 997 | TemplateDeclInstantiator::SubstTemplateParams(TemplateParameterList *L) { |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 998 | // Get errors for all the parameters before bailing out. |
| 999 | bool Invalid = false; |
| 1000 | |
| 1001 | unsigned N = L->size(); |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1002 | typedef llvm::SmallVector<NamedDecl *, 8> ParamVector; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 1003 | ParamVector Params; |
| 1004 | Params.reserve(N); |
| 1005 | for (TemplateParameterList::iterator PI = L->begin(), PE = L->end(); |
| 1006 | PI != PE; ++PI) { |
Douglas Gregor | bf4ea56 | 2009-09-15 16:23:51 +0000 | [diff] [blame] | 1007 | NamedDecl *D = cast_or_null<NamedDecl>(Visit(*PI)); |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 1008 | Params.push_back(D); |
| 1009 | Invalid = Invalid || !D; |
| 1010 | } |
| 1011 | |
| 1012 | // Clean up if we had an error. |
| 1013 | if (Invalid) { |
| 1014 | for (ParamVector::iterator PI = Params.begin(), PE = Params.end(); |
| 1015 | PI != PE; ++PI) |
| 1016 | if (*PI) |
| 1017 | (*PI)->Destroy(SemaRef.Context); |
| 1018 | return NULL; |
| 1019 | } |
| 1020 | |
| 1021 | TemplateParameterList *InstL |
| 1022 | = TemplateParameterList::Create(SemaRef.Context, L->getTemplateLoc(), |
| 1023 | L->getLAngleLoc(), &Params.front(), N, |
| 1024 | L->getRAngleLoc()); |
| 1025 | return InstL; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | } |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 1027 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1028 | /// \brief Instantiate the declaration of a class template partial |
| 1029 | /// specialization. |
| 1030 | /// |
| 1031 | /// \param ClassTemplate the (instantiated) class template that is partially |
| 1032 | // specialized by the instantiation of \p PartialSpec. |
| 1033 | /// |
| 1034 | /// \param PartialSpec the (uninstantiated) class template partial |
| 1035 | /// specialization that we are instantiating. |
| 1036 | /// |
| 1037 | /// \returns true if there was an error, false otherwise. |
| 1038 | bool |
| 1039 | TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization( |
| 1040 | ClassTemplateDecl *ClassTemplate, |
| 1041 | ClassTemplatePartialSpecializationDecl *PartialSpec) { |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 1042 | // Create a local instantiation scope for this class template partial |
| 1043 | // specialization, which will contain the instantiations of the template |
| 1044 | // parameters. |
| 1045 | Sema::LocalInstantiationScope Scope(SemaRef); |
| 1046 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1047 | // Substitute into the template parameters of the class template partial |
| 1048 | // specialization. |
| 1049 | TemplateParameterList *TempParams = PartialSpec->getTemplateParameters(); |
| 1050 | TemplateParameterList *InstParams = SubstTemplateParams(TempParams); |
| 1051 | if (!InstParams) |
| 1052 | return true; |
| 1053 | |
| 1054 | // Substitute into the template arguments of the class template partial |
| 1055 | // specialization. |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1056 | const TemplateArgumentLoc *PartialSpecTemplateArgs |
| 1057 | = PartialSpec->getTemplateArgsAsWritten(); |
| 1058 | unsigned N = PartialSpec->getNumTemplateArgsAsWritten(); |
| 1059 | |
| 1060 | llvm::SmallVector<TemplateArgumentLoc, 4> InstTemplateArgs(N); |
| 1061 | for (unsigned I = 0; I != N; ++I) { |
| 1062 | if (SemaRef.Subst(PartialSpecTemplateArgs[I], InstTemplateArgs[I], |
| 1063 | TemplateArgs)) |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1064 | return true; |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | // Check that the template argument list is well-formed for this |
| 1069 | // class template. |
| 1070 | TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(), |
| 1071 | InstTemplateArgs.size()); |
| 1072 | if (SemaRef.CheckTemplateArgumentList(ClassTemplate, |
| 1073 | PartialSpec->getLocation(), |
| 1074 | /*FIXME:*/PartialSpec->getLocation(), |
| 1075 | InstTemplateArgs.data(), |
| 1076 | InstTemplateArgs.size(), |
| 1077 | /*FIXME:*/PartialSpec->getLocation(), |
| 1078 | false, |
| 1079 | Converted)) |
| 1080 | return true; |
| 1081 | |
| 1082 | // Figure out where to insert this class template partial specialization |
| 1083 | // in the member template's set of class template partial specializations. |
| 1084 | llvm::FoldingSetNodeID ID; |
| 1085 | ClassTemplatePartialSpecializationDecl::Profile(ID, |
| 1086 | Converted.getFlatArguments(), |
| 1087 | Converted.flatSize(), |
| 1088 | SemaRef.Context); |
| 1089 | void *InsertPos = 0; |
| 1090 | ClassTemplateSpecializationDecl *PrevDecl |
| 1091 | = ClassTemplate->getPartialSpecializations().FindNodeOrInsertPos(ID, |
| 1092 | InsertPos); |
| 1093 | |
| 1094 | // Build the canonical type that describes the converted template |
| 1095 | // arguments of the class template partial specialization. |
| 1096 | QualType CanonType |
| 1097 | = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate), |
| 1098 | Converted.getFlatArguments(), |
| 1099 | Converted.flatSize()); |
| 1100 | |
| 1101 | // Build the fully-sugared type for this class template |
| 1102 | // specialization as the user wrote in the specialization |
| 1103 | // itself. This means that we'll pretty-print the type retrieved |
| 1104 | // from the specialization's declaration the way that the user |
| 1105 | // actually wrote the specialization, rather than formatting the |
| 1106 | // name based on the "canonical" representation used to store the |
| 1107 | // template arguments in the specialization. |
| 1108 | QualType WrittenTy |
| 1109 | = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate), |
| 1110 | InstTemplateArgs.data(), |
| 1111 | InstTemplateArgs.size(), |
| 1112 | CanonType); |
| 1113 | |
| 1114 | if (PrevDecl) { |
| 1115 | // We've already seen a partial specialization with the same template |
| 1116 | // parameters and template arguments. This can happen, for example, when |
| 1117 | // substituting the outer template arguments ends up causing two |
| 1118 | // class template partial specializations of a member class template |
| 1119 | // to have identical forms, e.g., |
| 1120 | // |
| 1121 | // template<typename T, typename U> |
| 1122 | // struct Outer { |
| 1123 | // template<typename X, typename Y> struct Inner; |
| 1124 | // template<typename Y> struct Inner<T, Y>; |
| 1125 | // template<typename Y> struct Inner<U, Y>; |
| 1126 | // }; |
| 1127 | // |
| 1128 | // Outer<int, int> outer; // error: the partial specializations of Inner |
| 1129 | // // have the same signature. |
| 1130 | SemaRef.Diag(PartialSpec->getLocation(), diag::err_partial_spec_redeclared) |
| 1131 | << WrittenTy; |
| 1132 | SemaRef.Diag(PrevDecl->getLocation(), diag::note_prev_partial_spec_here) |
| 1133 | << SemaRef.Context.getTypeDeclType(PrevDecl); |
| 1134 | return true; |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | // Create the class template partial specialization declaration. |
| 1139 | ClassTemplatePartialSpecializationDecl *InstPartialSpec |
| 1140 | = ClassTemplatePartialSpecializationDecl::Create(SemaRef.Context, Owner, |
| 1141 | PartialSpec->getLocation(), |
| 1142 | InstParams, |
| 1143 | ClassTemplate, |
| 1144 | Converted, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1145 | InstTemplateArgs.data(), |
| 1146 | InstTemplateArgs.size(), |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1147 | 0); |
| 1148 | InstPartialSpec->setInstantiatedFromMember(PartialSpec); |
| 1149 | InstPartialSpec->setTypeAsWritten(WrittenTy); |
| 1150 | |
| 1151 | // Add this partial specialization to the set of class template partial |
| 1152 | // specializations. |
| 1153 | ClassTemplate->getPartialSpecializations().InsertNode(InstPartialSpec, |
| 1154 | InsertPos); |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1158 | /// \brief Does substitution on the type of the given function, including |
| 1159 | /// all of the function parameters. |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1160 | /// |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1161 | /// \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] | 1162 | /// |
| 1163 | /// \param Params the instantiated parameter declarations |
| 1164 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1165 | /// \returns the instantiated function's type if successful, a NULL |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1166 | /// type if there was an error. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | QualType |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1168 | TemplateDeclInstantiator::SubstFunctionType(FunctionDecl *D, |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1169 | llvm::SmallVectorImpl<ParmVarDecl *> &Params) { |
| 1170 | bool InvalidDecl = false; |
| 1171 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1172 | // Substitute all of the function's formal parameter types. |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1173 | TemplateDeclInstantiator ParamInstantiator(SemaRef, 0, TemplateArgs); |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 1174 | llvm::SmallVector<QualType, 4> ParamTys; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1175 | for (FunctionDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1176 | PEnd = D->param_end(); |
| 1177 | P != PEnd; ++P) { |
Douglas Gregor | 6477b69 | 2009-03-25 15:04:13 +0000 | [diff] [blame] | 1178 | if (ParmVarDecl *PInst = ParamInstantiator.VisitParmVarDecl(*P)) { |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1179 | if (PInst->getType()->isVoidType()) { |
| 1180 | SemaRef.Diag(PInst->getLocation(), diag::err_param_with_void_type); |
| 1181 | PInst->setInvalidDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1182 | } else if (SemaRef.RequireNonAbstractType(PInst->getLocation(), |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 1183 | PInst->getType(), |
| 1184 | diag::err_abstract_type_in_decl, |
| 1185 | Sema::AbstractParamType)) |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1186 | PInst->setInvalidDecl(); |
| 1187 | |
| 1188 | Params.push_back(PInst); |
| 1189 | ParamTys.push_back(PInst->getType()); |
| 1190 | |
| 1191 | if (PInst->isInvalidDecl()) |
| 1192 | InvalidDecl = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | } else |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1194 | InvalidDecl = true; |
| 1195 | } |
| 1196 | |
| 1197 | // FIXME: Deallocate dead declarations. |
| 1198 | if (InvalidDecl) |
| 1199 | return QualType(); |
| 1200 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1201 | const FunctionProtoType *Proto = D->getType()->getAs<FunctionProtoType>(); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1202 | assert(Proto && "Missing prototype?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1203 | QualType ResultType |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1204 | = SemaRef.SubstType(Proto->getResultType(), TemplateArgs, |
| 1205 | D->getLocation(), D->getDeclName()); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1206 | if (ResultType.isNull()) |
| 1207 | return QualType(); |
| 1208 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1209 | return SemaRef.BuildFunctionType(ResultType, ParamTys.data(), ParamTys.size(), |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1210 | Proto->isVariadic(), Proto->getTypeQuals(), |
| 1211 | D->getLocation(), D->getDeclName()); |
| 1212 | } |
| 1213 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | /// \brief Initializes the common fields of an instantiation function |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 1215 | /// declaration (New) from the corresponding fields of its template (Tmpl). |
| 1216 | /// |
| 1217 | /// \returns true if there was an error |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | bool |
| 1219 | TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 1220 | FunctionDecl *Tmpl) { |
| 1221 | if (Tmpl->isDeleted()) |
| 1222 | New->setDeleted(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 1224 | // If we are performing substituting explicitly-specified template arguments |
| 1225 | // or deduced template arguments into a function template and we reach this |
| 1226 | // point, we are now past the point where SFINAE applies and have committed |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | // to keeping the new function template specialization. We therefore |
| 1228 | // convert the active template instantiation for the function template |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 1229 | // into a template instantiation for this specific function template |
| 1230 | // specialization, which is not a SFINAE context, so that we diagnose any |
| 1231 | // further errors in the declaration itself. |
| 1232 | typedef Sema::ActiveTemplateInstantiation ActiveInstType; |
| 1233 | ActiveInstType &ActiveInst = SemaRef.ActiveTemplateInstantiations.back(); |
| 1234 | if (ActiveInst.Kind == ActiveInstType::ExplicitTemplateArgumentSubstitution || |
| 1235 | ActiveInst.Kind == ActiveInstType::DeducedTemplateArgumentSubstitution) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | if (FunctionTemplateDecl *FunTmpl |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 1237 | = dyn_cast<FunctionTemplateDecl>((Decl *)ActiveInst.Entity)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | assert(FunTmpl->getTemplatedDecl() == Tmpl && |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 1239 | "Deduction from the wrong function template?"); |
Daniel Dunbar | bcbb8bd | 2009-07-16 22:10:11 +0000 | [diff] [blame] | 1240 | (void) FunTmpl; |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 1241 | ActiveInst.Kind = ActiveInstType::TemplateInstantiation; |
| 1242 | ActiveInst.Entity = reinterpret_cast<uintptr_t>(New); |
| 1243 | } |
| 1244 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 1246 | return false; |
| 1247 | } |
| 1248 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1249 | /// \brief Initializes common fields of an instantiated method |
| 1250 | /// declaration (New) from the corresponding fields of its template |
| 1251 | /// (Tmpl). |
| 1252 | /// |
| 1253 | /// \returns true if there was an error |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1254 | bool |
| 1255 | TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New, |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1256 | CXXMethodDecl *Tmpl) { |
Douglas Gregor | e53060f | 2009-06-25 22:08:12 +0000 | [diff] [blame] | 1257 | if (InitFunctionInstantiation(New, Tmpl)) |
| 1258 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1260 | CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner); |
| 1261 | New->setAccess(Tmpl->getAccess()); |
Anders Carlsson | 77b7f1d | 2009-05-14 22:15:41 +0000 | [diff] [blame] | 1262 | if (Tmpl->isVirtualAsWritten()) { |
| 1263 | New->setVirtualAsWritten(true); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1264 | Record->setAggregate(false); |
| 1265 | Record->setPOD(false); |
Eli Friedman | 1d954f6 | 2009-08-15 21:55:26 +0000 | [diff] [blame] | 1266 | Record->setEmpty(false); |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1267 | Record->setPolymorphic(true); |
| 1268 | } |
Douglas Gregor | 5545e16 | 2009-03-24 00:38:23 +0000 | [diff] [blame] | 1269 | if (Tmpl->isPure()) { |
| 1270 | New->setPure(); |
| 1271 | Record->setAbstract(true); |
| 1272 | } |
| 1273 | |
| 1274 | // FIXME: attributes |
| 1275 | // FIXME: New needs a pointer to Tmpl |
| 1276 | return false; |
| 1277 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1278 | |
| 1279 | /// \brief Instantiate the definition of the given function from its |
| 1280 | /// template. |
| 1281 | /// |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1282 | /// \param PointOfInstantiation the point at which the instantiation was |
| 1283 | /// required. Note that this is not precisely a "point of instantiation" |
| 1284 | /// for the function, but it's close. |
| 1285 | /// |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1286 | /// \param Function the already-instantiated declaration of a |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1287 | /// function template specialization or member function of a class template |
| 1288 | /// specialization. |
| 1289 | /// |
| 1290 | /// \param Recursive if true, recursively instantiates any functions that |
| 1291 | /// are required by this instantiation. |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1292 | /// |
| 1293 | /// \param DefinitionRequired if true, then we are performing an explicit |
| 1294 | /// instantiation where the body of the function is required. Complain if |
| 1295 | /// there is no such body. |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 1296 | void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1297 | FunctionDecl *Function, |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1298 | bool Recursive, |
| 1299 | bool DefinitionRequired) { |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 1300 | if (Function->isInvalidDecl()) |
| 1301 | return; |
| 1302 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1303 | assert(!Function->getBody() && "Already instantiated!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1305 | // Never instantiate an explicit specialization. |
| 1306 | if (Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) |
| 1307 | return; |
| 1308 | |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1309 | // Find the function body that we'll be substituting. |
Douglas Gregor | 3b846b6 | 2009-10-27 20:53:28 +0000 | [diff] [blame] | 1310 | const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern(); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1311 | Stmt *Pattern = 0; |
| 1312 | if (PatternDecl) |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1313 | Pattern = PatternDecl->getBody(PatternDecl); |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1314 | |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1315 | if (!Pattern) { |
| 1316 | if (DefinitionRequired) { |
| 1317 | if (Function->getPrimaryTemplate()) |
| 1318 | Diag(PointOfInstantiation, |
| 1319 | diag::err_explicit_instantiation_undefined_func_template) |
| 1320 | << Function->getPrimaryTemplate(); |
| 1321 | else |
| 1322 | Diag(PointOfInstantiation, |
| 1323 | diag::err_explicit_instantiation_undefined_member) |
| 1324 | << 1 << Function->getDeclName() << Function->getDeclContext(); |
| 1325 | |
| 1326 | if (PatternDecl) |
| 1327 | Diag(PatternDecl->getLocation(), |
| 1328 | diag::note_explicit_instantiation_here); |
| 1329 | } |
| 1330 | |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1331 | return; |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1332 | } |
Douglas Gregor | 1eee0e7 | 2009-05-14 21:06:31 +0000 | [diff] [blame] | 1333 | |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1334 | // C++0x [temp.explicit]p9: |
| 1335 | // Except for inline functions, other explicit instantiation declarations |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1336 | // have the effect of suppressing the implicit instantiation of the entity |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1337 | // to which they refer. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | if (Function->getTemplateSpecializationKind() |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1339 | == TSK_ExplicitInstantiationDeclaration && |
Douglas Gregor | 7ced9c8 | 2009-10-27 21:11:48 +0000 | [diff] [blame] | 1340 | !PatternDecl->isInlined()) |
Douglas Gregor | d0e3daf | 2009-09-04 22:48:11 +0000 | [diff] [blame] | 1341 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1342 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 1343 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Function); |
| 1344 | if (Inst) |
| 1345 | return; |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1347 | // If we're performing recursive template instantiation, create our own |
| 1348 | // queue of pending implicit instantiations that we will instantiate later, |
| 1349 | // while we're still within our own instantiation context. |
| 1350 | std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; |
| 1351 | if (Recursive) |
| 1352 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 1354 | ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function)); |
| 1355 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 1356 | // Introduce a new scope where local variable instantiations will be |
| 1357 | // recorded. |
| 1358 | LocalInstantiationScope Scope(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 1360 | // Introduce the instantiated function parameters into the local |
| 1361 | // instantiation scope. |
| 1362 | for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I) |
| 1363 | Scope.InstantiatedLocal(PatternDecl->getParamDecl(I), |
| 1364 | Function->getParamDecl(I)); |
| 1365 | |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 1366 | // Enter the scope of this instantiation. We don't use |
| 1367 | // PushDeclContext because we don't have a scope. |
| 1368 | DeclContext *PreviousContext = CurContext; |
| 1369 | CurContext = Function; |
| 1370 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | MultiLevelTemplateArgumentList TemplateArgs = |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1372 | getTemplateInstantiationArgs(Function); |
| 1373 | |
| 1374 | // If this is a constructor, instantiate the member initializers. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | if (const CXXConstructorDecl *Ctor = |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1376 | dyn_cast<CXXConstructorDecl>(PatternDecl)) { |
| 1377 | InstantiateMemInitializers(cast<CXXConstructorDecl>(Function), Ctor, |
| 1378 | TemplateArgs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 1381 | // Instantiate the function body. |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1382 | OwningStmtResult Body = SubstStmt(Pattern, TemplateArgs); |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 1383 | |
Douglas Gregor | 52604ab | 2009-09-11 21:19:12 +0000 | [diff] [blame] | 1384 | if (Body.isInvalid()) |
| 1385 | Function->setInvalidDecl(); |
| 1386 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1387 | ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body), |
Douglas Gregor | e2c31ff | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 1388 | /*IsInstantiation=*/true); |
Douglas Gregor | b9f1b8d | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 1389 | |
| 1390 | CurContext = PreviousContext; |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 1391 | |
| 1392 | DeclGroupRef DG(Function); |
| 1393 | Consumer.HandleTopLevelDecl(DG); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1395 | if (Recursive) { |
| 1396 | // Instantiate any pending implicit instantiations found during the |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | // instantiation of this template. |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1398 | PerformPendingImplicitInstantiations(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1400 | // Restore the set of pending implicit instantiations. |
| 1401 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
| 1402 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | /// \brief Instantiate the definition of the given variable from its |
| 1406 | /// template. |
| 1407 | /// |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1408 | /// \param PointOfInstantiation the point at which the instantiation was |
| 1409 | /// required. Note that this is not precisely a "point of instantiation" |
| 1410 | /// for the function, but it's close. |
| 1411 | /// |
| 1412 | /// \param Var the already-instantiated declaration of a static member |
| 1413 | /// variable of a class template specialization. |
| 1414 | /// |
| 1415 | /// \param Recursive if true, recursively instantiates any functions that |
| 1416 | /// are required by this instantiation. |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1417 | /// |
| 1418 | /// \param DefinitionRequired if true, then we are performing an explicit |
| 1419 | /// instantiation where an out-of-line definition of the member variable |
| 1420 | /// is required. Complain if there is no such definition. |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1421 | void Sema::InstantiateStaticDataMemberDefinition( |
| 1422 | SourceLocation PointOfInstantiation, |
| 1423 | VarDecl *Var, |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1424 | bool Recursive, |
| 1425 | bool DefinitionRequired) { |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1426 | if (Var->isInvalidDecl()) |
| 1427 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1429 | // Find the out-of-line definition of this static data member. |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1430 | VarDecl *Def = Var->getInstantiatedFromStaticDataMember(); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1431 | assert(Def && "This data member was not instantiated from a template?"); |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1432 | assert(Def->isStaticDataMember() && "Not a static data member?"); |
| 1433 | Def = Def->getOutOfLineDefinition(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1434 | |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1435 | if (!Def) { |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1436 | // We did not find an out-of-line definition of this static data member, |
| 1437 | // so we won't perform any instantiation. Rather, we rely on the user to |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1438 | // instantiate this definition (or provide a specialization for it) in |
| 1439 | // another translation unit. |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1440 | if (DefinitionRequired) { |
Douglas Gregor | 0d03514 | 2009-10-27 18:42:08 +0000 | [diff] [blame] | 1441 | Def = Var->getInstantiatedFromStaticDataMember(); |
Douglas Gregor | e2d3a3d | 2009-10-15 14:05:49 +0000 | [diff] [blame] | 1442 | Diag(PointOfInstantiation, |
| 1443 | diag::err_explicit_instantiation_undefined_member) |
| 1444 | << 2 << Var->getDeclName() << Var->getDeclContext(); |
| 1445 | Diag(Def->getLocation(), diag::note_explicit_instantiation_here); |
| 1446 | } |
| 1447 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1448 | return; |
| 1449 | } |
| 1450 | |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1451 | // Never instantiate an explicit specialization. |
Douglas Gregor | 1028c9f | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1452 | if (Var->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1453 | return; |
| 1454 | |
| 1455 | // C++0x [temp.explicit]p9: |
| 1456 | // Except for inline functions, other explicit instantiation declarations |
| 1457 | // have the effect of suppressing the implicit instantiation of the entity |
| 1458 | // to which they refer. |
Douglas Gregor | 1028c9f | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1459 | if (Var->getTemplateSpecializationKind() |
Douglas Gregor | 251b4ff | 2009-10-08 07:24:58 +0000 | [diff] [blame] | 1460 | == TSK_ExplicitInstantiationDeclaration) |
| 1461 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1462 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1463 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Var); |
| 1464 | if (Inst) |
| 1465 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1466 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1467 | // If we're performing recursive template instantiation, create our own |
| 1468 | // queue of pending implicit instantiations that we will instantiate later, |
| 1469 | // while we're still within our own instantiation context. |
| 1470 | std::deque<PendingImplicitInstantiation> SavedPendingImplicitInstantiations; |
| 1471 | if (Recursive) |
| 1472 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1474 | // Enter the scope of this instantiation. We don't use |
| 1475 | // PushDeclContext because we don't have a scope. |
| 1476 | DeclContext *PreviousContext = CurContext; |
| 1477 | CurContext = Var->getDeclContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1478 | |
Douglas Gregor | 1028c9f | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1479 | VarDecl *OldVar = Var; |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 1480 | Var = cast_or_null<VarDecl>(SubstDecl(Def, Var->getDeclContext(), |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1481 | getTemplateInstantiationArgs(Var))); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1482 | CurContext = PreviousContext; |
| 1483 | |
| 1484 | if (Var) { |
Douglas Gregor | 1028c9f | 2009-10-14 21:29:40 +0000 | [diff] [blame] | 1485 | Var->setPreviousDeclaration(OldVar); |
Douglas Gregor | 583f33b | 2009-10-15 18:07:02 +0000 | [diff] [blame] | 1486 | MemberSpecializationInfo *MSInfo = OldVar->getMemberSpecializationInfo(); |
| 1487 | assert(MSInfo && "Missing member specialization information?"); |
| 1488 | Var->setTemplateSpecializationKind(MSInfo->getTemplateSpecializationKind(), |
| 1489 | MSInfo->getPointOfInstantiation()); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1490 | DeclGroupRef DG(Var); |
| 1491 | Consumer.HandleTopLevelDecl(DG); |
| 1492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1494 | if (Recursive) { |
| 1495 | // Instantiate any pending implicit instantiations found during the |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1496 | // instantiation of this template. |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1497 | PerformPendingImplicitInstantiations(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1499 | // Restore the set of pending implicit instantiations. |
| 1500 | PendingImplicitInstantiations.swap(SavedPendingImplicitInstantiations); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 1502 | } |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1503 | |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1504 | void |
| 1505 | Sema::InstantiateMemInitializers(CXXConstructorDecl *New, |
| 1506 | const CXXConstructorDecl *Tmpl, |
| 1507 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1508 | |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1509 | llvm::SmallVector<MemInitTy*, 4> NewInits; |
| 1510 | |
| 1511 | // Instantiate all the initializers. |
| 1512 | for (CXXConstructorDecl::init_const_iterator Inits = Tmpl->init_begin(), |
Douglas Gregor | 72f6d67 | 2009-09-01 21:04:42 +0000 | [diff] [blame] | 1513 | InitsEnd = Tmpl->init_end(); |
| 1514 | Inits != InitsEnd; ++Inits) { |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1515 | CXXBaseOrMemberInitializer *Init = *Inits; |
| 1516 | |
| 1517 | ASTOwningVector<&ActionBase::DeleteExpr> NewArgs(*this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1518 | |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1519 | // Instantiate all the arguments. |
| 1520 | for (ExprIterator Args = Init->arg_begin(), ArgsEnd = Init->arg_end(); |
| 1521 | Args != ArgsEnd; ++Args) { |
| 1522 | OwningExprResult NewArg = SubstExpr(*Args, TemplateArgs); |
| 1523 | |
| 1524 | if (NewArg.isInvalid()) |
| 1525 | New->setInvalidDecl(); |
| 1526 | else |
| 1527 | NewArgs.push_back(NewArg.takeAs<Expr>()); |
| 1528 | } |
| 1529 | |
| 1530 | MemInitResult NewInit; |
| 1531 | |
| 1532 | if (Init->isBaseInitializer()) { |
Eli Friedman | c5573a8 | 2009-08-29 22:22:07 +0000 | [diff] [blame] | 1533 | QualType BaseType(Init->getBaseClass(), 0); |
| 1534 | BaseType = SubstType(BaseType, TemplateArgs, Init->getSourceLocation(), |
| 1535 | New->getDeclName()); |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1536 | |
| 1537 | NewInit = BuildBaseInitializer(BaseType, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | (Expr **)NewArgs.data(), |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1539 | NewArgs.size(), |
| 1540 | Init->getSourceLocation(), |
| 1541 | Init->getRParenLoc(), |
| 1542 | New->getParent()); |
| 1543 | } else if (Init->isMemberInitializer()) { |
Anders Carlsson | 9988d5d | 2009-09-01 04:31:02 +0000 | [diff] [blame] | 1544 | FieldDecl *Member; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | |
Anders Carlsson | 9988d5d | 2009-09-01 04:31:02 +0000 | [diff] [blame] | 1546 | // Is this an anonymous union? |
| 1547 | if (FieldDecl *UnionInit = Init->getAnonUnionMember()) |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1548 | Member = cast<FieldDecl>(FindInstantiatedDecl(UnionInit, TemplateArgs)); |
Anders Carlsson | 9988d5d | 2009-09-01 04:31:02 +0000 | [diff] [blame] | 1549 | else |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1550 | Member = cast<FieldDecl>(FindInstantiatedDecl(Init->getMember(), |
| 1551 | TemplateArgs)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1552 | |
| 1553 | NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(), |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1554 | NewArgs.size(), |
| 1555 | Init->getSourceLocation(), |
| 1556 | Init->getRParenLoc()); |
| 1557 | } |
| 1558 | |
| 1559 | if (NewInit.isInvalid()) |
| 1560 | New->setInvalidDecl(); |
| 1561 | else { |
| 1562 | // FIXME: It would be nice if ASTOwningVector had a release function. |
| 1563 | NewArgs.take(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1564 | |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1565 | NewInits.push_back((MemInitTy *)NewInit.get()); |
| 1566 | } |
| 1567 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1568 | |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1569 | // Assign all the initializers to the new constructor. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1570 | ActOnMemInitializers(DeclPtrTy::make(New), |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1571 | /*FIXME: ColonLoc */ |
| 1572 | SourceLocation(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1573 | NewInits.data(), NewInits.size()); |
Anders Carlsson | 0902531 | 2009-08-29 05:16:22 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1576 | // TODO: this could be templated if the various decl types used the |
| 1577 | // same method name. |
| 1578 | static bool isInstantiationOf(ClassTemplateDecl *Pattern, |
| 1579 | ClassTemplateDecl *Instance) { |
| 1580 | Pattern = Pattern->getCanonicalDecl(); |
| 1581 | |
| 1582 | do { |
| 1583 | Instance = Instance->getCanonicalDecl(); |
| 1584 | if (Pattern == Instance) return true; |
| 1585 | Instance = Instance->getInstantiatedFromMemberTemplate(); |
| 1586 | } while (Instance); |
| 1587 | |
| 1588 | return false; |
| 1589 | } |
| 1590 | |
Douglas Gregor | 0d69653 | 2009-09-28 06:34:35 +0000 | [diff] [blame] | 1591 | static bool isInstantiationOf(FunctionTemplateDecl *Pattern, |
| 1592 | FunctionTemplateDecl *Instance) { |
| 1593 | Pattern = Pattern->getCanonicalDecl(); |
| 1594 | |
| 1595 | do { |
| 1596 | Instance = Instance->getCanonicalDecl(); |
| 1597 | if (Pattern == Instance) return true; |
| 1598 | Instance = Instance->getInstantiatedFromMemberTemplate(); |
| 1599 | } while (Instance); |
| 1600 | |
| 1601 | return false; |
| 1602 | } |
| 1603 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1604 | static bool |
| 1605 | isInstantiationOf(ClassTemplatePartialSpecializationDecl *Pattern, |
| 1606 | ClassTemplatePartialSpecializationDecl *Instance) { |
| 1607 | Pattern |
| 1608 | = cast<ClassTemplatePartialSpecializationDecl>(Pattern->getCanonicalDecl()); |
| 1609 | do { |
| 1610 | Instance = cast<ClassTemplatePartialSpecializationDecl>( |
| 1611 | Instance->getCanonicalDecl()); |
| 1612 | if (Pattern == Instance) |
| 1613 | return true; |
| 1614 | Instance = Instance->getInstantiatedFromMember(); |
| 1615 | } while (Instance); |
| 1616 | |
| 1617 | return false; |
| 1618 | } |
| 1619 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1620 | static bool isInstantiationOf(CXXRecordDecl *Pattern, |
| 1621 | CXXRecordDecl *Instance) { |
| 1622 | Pattern = Pattern->getCanonicalDecl(); |
| 1623 | |
| 1624 | do { |
| 1625 | Instance = Instance->getCanonicalDecl(); |
| 1626 | if (Pattern == Instance) return true; |
| 1627 | Instance = Instance->getInstantiatedFromMemberClass(); |
| 1628 | } while (Instance); |
| 1629 | |
| 1630 | return false; |
| 1631 | } |
| 1632 | |
| 1633 | static bool isInstantiationOf(FunctionDecl *Pattern, |
| 1634 | FunctionDecl *Instance) { |
| 1635 | Pattern = Pattern->getCanonicalDecl(); |
| 1636 | |
| 1637 | do { |
| 1638 | Instance = Instance->getCanonicalDecl(); |
| 1639 | if (Pattern == Instance) return true; |
| 1640 | Instance = Instance->getInstantiatedFromMemberFunction(); |
| 1641 | } while (Instance); |
| 1642 | |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | static bool isInstantiationOf(EnumDecl *Pattern, |
| 1647 | EnumDecl *Instance) { |
| 1648 | Pattern = Pattern->getCanonicalDecl(); |
| 1649 | |
| 1650 | do { |
| 1651 | Instance = Instance->getCanonicalDecl(); |
| 1652 | if (Pattern == Instance) return true; |
| 1653 | Instance = Instance->getInstantiatedFromMemberEnum(); |
| 1654 | } while (Instance); |
| 1655 | |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 1659 | static bool isInstantiationOf(UnresolvedUsingDecl *Pattern, |
| 1660 | UsingDecl *Instance, |
| 1661 | ASTContext &C) { |
| 1662 | return C.getInstantiatedFromUnresolvedUsingDecl(Instance) == Pattern; |
| 1663 | } |
| 1664 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1665 | static bool isInstantiationOfStaticDataMember(VarDecl *Pattern, |
| 1666 | VarDecl *Instance) { |
| 1667 | assert(Instance->isStaticDataMember()); |
| 1668 | |
| 1669 | Pattern = Pattern->getCanonicalDecl(); |
| 1670 | |
| 1671 | do { |
| 1672 | Instance = Instance->getCanonicalDecl(); |
| 1673 | if (Pattern == Instance) return true; |
| 1674 | Instance = Instance->getInstantiatedFromStaticDataMember(); |
| 1675 | } while (Instance); |
| 1676 | |
| 1677 | return false; |
| 1678 | } |
| 1679 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1680 | static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) { |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 1681 | if (D->getKind() != Other->getKind()) { |
| 1682 | if (UnresolvedUsingDecl *UUD = dyn_cast<UnresolvedUsingDecl>(D)) { |
| 1683 | if (UsingDecl *UD = dyn_cast<UsingDecl>(Other)) { |
| 1684 | return isInstantiationOf(UUD, UD, Ctx); |
| 1685 | } |
| 1686 | } |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1687 | |
Anders Carlsson | 0d8df78 | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 1688 | return false; |
| 1689 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1691 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other)) |
| 1692 | return isInstantiationOf(cast<CXXRecordDecl>(D), Record); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1694 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other)) |
| 1695 | return isInstantiationOf(cast<FunctionDecl>(D), Function); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1696 | |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1697 | if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other)) |
| 1698 | return isInstantiationOf(cast<EnumDecl>(D), Enum); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1699 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1700 | if (VarDecl *Var = dyn_cast<VarDecl>(Other)) |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1701 | if (Var->isStaticDataMember()) |
| 1702 | return isInstantiationOfStaticDataMember(cast<VarDecl>(D), Var); |
| 1703 | |
| 1704 | if (ClassTemplateDecl *Temp = dyn_cast<ClassTemplateDecl>(Other)) |
| 1705 | return isInstantiationOf(cast<ClassTemplateDecl>(D), Temp); |
Douglas Gregor | a5bf7f1 | 2009-08-28 22:03:51 +0000 | [diff] [blame] | 1706 | |
Douglas Gregor | 0d69653 | 2009-09-28 06:34:35 +0000 | [diff] [blame] | 1707 | if (FunctionTemplateDecl *Temp = dyn_cast<FunctionTemplateDecl>(Other)) |
| 1708 | return isInstantiationOf(cast<FunctionTemplateDecl>(D), Temp); |
| 1709 | |
Douglas Gregor | ed9c0f9 | 2009-10-29 00:04:11 +0000 | [diff] [blame] | 1710 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 1711 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(Other)) |
| 1712 | return isInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(D), |
| 1713 | PartialSpec); |
| 1714 | |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1715 | if (FieldDecl *Field = dyn_cast<FieldDecl>(Other)) { |
| 1716 | if (!Field->getDeclName()) { |
| 1717 | // This is an unnamed field. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1718 | return Ctx.getInstantiatedFromUnnamedFieldDecl(Field) == |
Anders Carlsson | d8b285f | 2009-09-01 04:26:58 +0000 | [diff] [blame] | 1719 | cast<FieldDecl>(D); |
| 1720 | } |
| 1721 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1723 | return D->getDeclName() && isa<NamedDecl>(Other) && |
| 1724 | D->getDeclName() == cast<NamedDecl>(Other)->getDeclName(); |
| 1725 | } |
| 1726 | |
| 1727 | template<typename ForwardIterator> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1728 | static NamedDecl *findInstantiationOf(ASTContext &Ctx, |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1729 | NamedDecl *D, |
| 1730 | ForwardIterator first, |
| 1731 | ForwardIterator last) { |
| 1732 | for (; first != last; ++first) |
| 1733 | if (isInstantiationOf(Ctx, D, *first)) |
| 1734 | return cast<NamedDecl>(*first); |
| 1735 | |
| 1736 | return 0; |
| 1737 | } |
| 1738 | |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 1739 | /// \brief Finds the instantiation of the given declaration context |
| 1740 | /// within the current instantiation. |
| 1741 | /// |
| 1742 | /// \returns NULL if there was an error |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1743 | DeclContext *Sema::FindInstantiatedContext(DeclContext* DC, |
| 1744 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 1745 | if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) { |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1746 | Decl* ID = FindInstantiatedDecl(D, TemplateArgs); |
John McCall | 02cace7 | 2009-08-28 07:59:38 +0000 | [diff] [blame] | 1747 | return cast_or_null<DeclContext>(ID); |
| 1748 | } else return DC; |
| 1749 | } |
| 1750 | |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1751 | /// \brief Find the instantiation of the given declaration within the |
| 1752 | /// current instantiation. |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1753 | /// |
| 1754 | /// This routine is intended to be used when \p D is a declaration |
| 1755 | /// referenced from within a template, that needs to mapped into the |
| 1756 | /// corresponding declaration within an instantiation. For example, |
| 1757 | /// given: |
| 1758 | /// |
| 1759 | /// \code |
| 1760 | /// template<typename T> |
| 1761 | /// struct X { |
| 1762 | /// enum Kind { |
| 1763 | /// KnownValue = sizeof(T) |
| 1764 | /// }; |
| 1765 | /// |
| 1766 | /// bool getKind() const { return KnownValue; } |
| 1767 | /// }; |
| 1768 | /// |
| 1769 | /// template struct X<int>; |
| 1770 | /// \endcode |
| 1771 | /// |
| 1772 | /// In the instantiation of X<int>::getKind(), we need to map the |
| 1773 | /// EnumConstantDecl for KnownValue (which refers to |
| 1774 | /// X<T>::<Kind>::KnownValue) to its instantiation |
Douglas Gregor | ed961e7 | 2009-05-27 17:54:46 +0000 | [diff] [blame] | 1775 | /// (X<int>::<Kind>::KnownValue). InstantiateCurrentDeclRef() performs |
| 1776 | /// this mapping from within the instantiation of X<int>. |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1777 | NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D, |
| 1778 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1779 | if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { |
| 1780 | // Transform all of the elements of the overloaded function set. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1781 | OverloadedFunctionDecl *Result |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1782 | = OverloadedFunctionDecl::Create(Context, CurContext, Ovl->getDeclName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1784 | for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(), |
| 1785 | FEnd = Ovl->function_end(); |
| 1786 | F != FEnd; ++F) { |
| 1787 | Result->addOverload( |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1788 | AnyFunctionDecl::getFromNamedDecl(FindInstantiatedDecl(*F, |
| 1789 | TemplateArgs))); |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1790 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1792 | return Result; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1795 | DeclContext *ParentDC = D->getDeclContext(); |
Douglas Gregor | 550d9b2 | 2009-10-31 17:21:17 +0000 | [diff] [blame^] | 1796 | if (isa<ParmVarDecl>(D) || isa<NonTypeTemplateParmDecl>(D) || |
| 1797 | isa<TemplateTypeParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || |
| 1798 | ParentDC->isFunctionOrMethod()) { |
Douglas Gregor | 2bba76b | 2009-05-27 17:07:49 +0000 | [diff] [blame] | 1799 | // D is a local of some kind. Look into the map of local |
| 1800 | // declarations to their instantiations. |
| 1801 | return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D)); |
| 1802 | } |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1804 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 1805 | if (!Record->isDependentContext()) |
| 1806 | return D; |
| 1807 | |
| 1808 | // If the RecordDecl is actually the injected-class-name or a "templated" |
| 1809 | // declaration for a class template or class template partial |
| 1810 | // specialization, substitute into the injected-class-name of the |
| 1811 | // class template or partial specialization to find the new DeclContext. |
| 1812 | QualType T; |
| 1813 | ClassTemplateDecl *ClassTemplate = Record->getDescribedClassTemplate(); |
| 1814 | |
| 1815 | if (ClassTemplate) { |
| 1816 | T = ClassTemplate->getInjectedClassNameType(Context); |
| 1817 | } else if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 1818 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(Record)) { |
| 1819 | T = Context.getTypeDeclType(Record); |
| 1820 | ClassTemplate = PartialSpec->getSpecializedTemplate(); |
| 1821 | } |
| 1822 | |
| 1823 | if (!T.isNull()) { |
| 1824 | // Substitute into the injected-class-name to get the type corresponding |
| 1825 | // to the instantiation we want. This substitution should never fail, |
| 1826 | // since we know we can instantiate the injected-class-name or we wouldn't |
| 1827 | // have gotten to the injected-class-name! |
| 1828 | // FIXME: Can we use the CurrentInstantiationScope to avoid this extra |
| 1829 | // instantiation in the common case? |
| 1830 | T = SubstType(T, TemplateArgs, SourceLocation(), DeclarationName()); |
| 1831 | assert(!T.isNull() && "Instantiation of injected-class-name cannot fail."); |
| 1832 | |
| 1833 | if (!T->isDependentType()) { |
| 1834 | assert(T->isRecordType() && "Instantiation must produce a record type"); |
| 1835 | return T->getAs<RecordType>()->getDecl(); |
| 1836 | } |
| 1837 | |
| 1838 | // We are performing "partial" template instantiation to create the |
| 1839 | // member declarations for the members of a class template |
| 1840 | // specialization. Therefore, D is actually referring to something in |
| 1841 | // the current instantiation. Look through the current context, |
| 1842 | // which contains actual instantiations, to find the instantiation of |
| 1843 | // the "current instantiation" that D refers to. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1844 | for (DeclContext *DC = CurContext; !DC->isFileContext(); |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1845 | DC = DC->getParent()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1846 | if (ClassTemplateSpecializationDecl *Spec |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1847 | = dyn_cast<ClassTemplateSpecializationDecl>(DC)) |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1848 | if (isInstantiationOf(ClassTemplate, |
| 1849 | Spec->getSpecializedTemplate())) |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1850 | return Spec; |
| 1851 | } |
| 1852 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1853 | assert(false && |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1854 | "Unable to find declaration for the current instantiation"); |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1855 | return Record; |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1856 | } |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1857 | |
| 1858 | // Fall through to deal with other dependent record types (e.g., |
| 1859 | // anonymous unions in class templates). |
| 1860 | } |
John McCall | 52a575a | 2009-08-29 08:11:13 +0000 | [diff] [blame] | 1861 | |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 1862 | if (!ParentDC->isDependentContext()) |
| 1863 | return D; |
| 1864 | |
| 1865 | ParentDC = FindInstantiatedContext(ParentDC, TemplateArgs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1866 | if (!ParentDC) |
Douglas Gregor | 44c7384 | 2009-09-01 17:53:10 +0000 | [diff] [blame] | 1867 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1869 | if (ParentDC != D->getDeclContext()) { |
| 1870 | // We performed some kind of instantiation in the parent context, |
| 1871 | // so now we need to look into the instantiated parent context to |
| 1872 | // find the instantiation of the declaration D. |
| 1873 | NamedDecl *Result = 0; |
| 1874 | if (D->getDeclName()) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1875 | DeclContext::lookup_result Found = ParentDC->lookup(D->getDeclName()); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1876 | Result = findInstantiationOf(Context, D, Found.first, Found.second); |
| 1877 | } else { |
| 1878 | // Since we don't have a name for the entity we're looking for, |
| 1879 | // our only option is to walk through all of the declarations to |
| 1880 | // find that name. This will occur in a few cases: |
| 1881 | // |
| 1882 | // - anonymous struct/union within a template |
| 1883 | // - unnamed class/struct/union/enum within a template |
| 1884 | // |
| 1885 | // FIXME: Find a better way to find these instantiations! |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1886 | Result = findInstantiationOf(Context, D, |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1887 | ParentDC->decls_begin(), |
| 1888 | ParentDC->decls_end()); |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1889 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1890 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1891 | assert(Result && "Unable to find instantiation of declaration!"); |
| 1892 | D = Result; |
| 1893 | } |
| 1894 | |
Douglas Gregor | 815215d | 2009-05-27 05:35:12 +0000 | [diff] [blame] | 1895 | return D; |
| 1896 | } |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1897 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1898 | /// \brief Performs template instantiation for all implicit template |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1899 | /// instantiations we have seen until this point. |
| 1900 | void Sema::PerformPendingImplicitInstantiations() { |
| 1901 | while (!PendingImplicitInstantiations.empty()) { |
| 1902 | PendingImplicitInstantiation Inst = PendingImplicitInstantiations.front(); |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1903 | PendingImplicitInstantiations.pop_front(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1904 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1905 | // Instantiate function definitions |
| 1906 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1907 | PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Function), |
Anders Carlsson | c17fb7b | 2009-09-01 05:12:24 +0000 | [diff] [blame] | 1908 | Function->getLocation(), *this, |
| 1909 | Context.getSourceManager(), |
| 1910 | "instantiating function definition"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1911 | |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 1912 | if (!Function->getBody()) |
Douglas Gregor | b33fe2f | 2009-06-30 17:20:14 +0000 | [diff] [blame] | 1913 | InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true); |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1914 | continue; |
| 1915 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1917 | // Instantiate static data member definitions. |
| 1918 | VarDecl *Var = cast<VarDecl>(Inst.first); |
| 1919 | assert(Var->isStaticDataMember() && "Not a static data member?"); |
Anders Carlsson | c17fb7b | 2009-09-01 05:12:24 +0000 | [diff] [blame] | 1920 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1921 | PrettyStackTraceActionsDecl CrashInfo(DeclPtrTy::make(Var), |
Anders Carlsson | c17fb7b | 2009-09-01 05:12:24 +0000 | [diff] [blame] | 1922 | Var->getLocation(), *this, |
| 1923 | Context.getSourceManager(), |
| 1924 | "instantiating static data member " |
| 1925 | "definition"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 1927 | InstantiateStaticDataMemberDefinition(/*FIXME:*/Inst.second, Var, true); |
Douglas Gregor | d7f37bf | 2009-06-22 23:06:13 +0000 | [diff] [blame] | 1928 | } |
| 1929 | } |