Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 1 | //===------- SemaTemplateInstantiate.cpp - C++ Template 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. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===/ |
| 12 | |
| 13 | #include "Sema.h" |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Expr.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
| 19 | #include "clang/Parse/DeclSpec.h" |
| 20 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===/ |
| 26 | // Template Instantiation Support |
| 27 | //===----------------------------------------------------------------------===/ |
| 28 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 29 | /// \brief Retrieve the template argument list(s) that should be used to |
| 30 | /// instantiate the definition of the given declaration. |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 31 | MultiLevelTemplateArgumentList |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 32 | Sema::getTemplateInstantiationArgs(NamedDecl *D) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 33 | // Accumulate the set of template argument lists in this structure. |
| 34 | MultiLevelTemplateArgumentList Result; |
| 35 | |
| 36 | DeclContext *Ctx = dyn_cast<DeclContext>(D); |
| 37 | if (!Ctx) |
| 38 | Ctx = D->getDeclContext(); |
| 39 | |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 40 | while (!Ctx->isFileContext()) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 41 | // Add template arguments from a class template instantiation. |
| 42 | if (ClassTemplateSpecializationDecl *Spec |
| 43 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) { |
| 44 | // We're done when we hit an explicit specialization. |
| 45 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization) |
| 46 | break; |
Douglas Gregor | 1637be7 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 47 | |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 48 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Add template arguments from a function template specialization. |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 52 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 53 | // FIXME: Check whether this is an explicit specialization. |
| 54 | if (const TemplateArgumentList *TemplateArgs |
| 55 | = Function->getTemplateSpecializationArgs()) |
| 56 | Result.addOuterTemplateArguments(TemplateArgs); |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 57 | |
| 58 | // If this is a friend declaration and it declares an entity at |
| 59 | // namespace scope, take arguments from its lexical parent |
| 60 | // instead of its semantic parent. |
| 61 | if (Function->getFriendObjectKind() && |
| 62 | Function->getDeclContext()->isFileContext()) { |
| 63 | Ctx = Function->getLexicalDeclContext(); |
| 64 | continue; |
| 65 | } |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 66 | } |
John McCall | f181d8a | 2009-08-29 03:16:09 +0000 | [diff] [blame] | 67 | |
| 68 | Ctx = Ctx->getParent(); |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 69 | } |
Douglas Gregor | d110243 | 2009-08-28 17:37:35 +0000 | [diff] [blame] | 70 | |
| 71 | return Result; |
Douglas Gregor | 54dabfc | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 74 | Sema::InstantiatingTemplate:: |
| 75 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 76 | Decl *Entity, |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 77 | SourceRange InstantiationRange) |
| 78 | : SemaRef(SemaRef) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 79 | |
| 80 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 81 | InstantiationRange); |
| 82 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 83 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 84 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 85 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 86 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 87 | Inst.TemplateArgs = 0; |
| 88 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 89 | Inst.InstantiationRange = InstantiationRange; |
| 90 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 91 | Invalid = false; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 96 | SourceLocation PointOfInstantiation, |
| 97 | TemplateDecl *Template, |
| 98 | const TemplateArgument *TemplateArgs, |
| 99 | unsigned NumTemplateArgs, |
| 100 | SourceRange InstantiationRange) |
| 101 | : SemaRef(SemaRef) { |
| 102 | |
| 103 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 104 | InstantiationRange); |
| 105 | if (!Invalid) { |
| 106 | ActiveTemplateInstantiation Inst; |
| 107 | Inst.Kind |
| 108 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 109 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 110 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 111 | Inst.TemplateArgs = TemplateArgs; |
| 112 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 113 | Inst.InstantiationRange = InstantiationRange; |
| 114 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 115 | Invalid = false; |
| 116 | } |
| 117 | } |
| 118 | |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 119 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 120 | SourceLocation PointOfInstantiation, |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 121 | FunctionTemplateDecl *FunctionTemplate, |
| 122 | const TemplateArgument *TemplateArgs, |
| 123 | unsigned NumTemplateArgs, |
| 124 | ActiveTemplateInstantiation::InstantiationKind Kind, |
| 125 | SourceRange InstantiationRange) |
| 126 | : SemaRef(SemaRef) { |
| 127 | |
| 128 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 129 | InstantiationRange); |
| 130 | if (!Invalid) { |
| 131 | ActiveTemplateInstantiation Inst; |
| 132 | Inst.Kind = Kind; |
| 133 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 134 | Inst.Entity = reinterpret_cast<uintptr_t>(FunctionTemplate); |
| 135 | Inst.TemplateArgs = TemplateArgs; |
| 136 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 137 | Inst.InstantiationRange = InstantiationRange; |
| 138 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 139 | Invalid = false; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 144 | SourceLocation PointOfInstantiation, |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 145 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 146 | const TemplateArgument *TemplateArgs, |
| 147 | unsigned NumTemplateArgs, |
| 148 | SourceRange InstantiationRange) |
| 149 | : SemaRef(SemaRef) { |
| 150 | |
| 151 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 152 | InstantiationRange); |
| 153 | if (!Invalid) { |
| 154 | ActiveTemplateInstantiation Inst; |
| 155 | Inst.Kind |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 156 | = ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 157 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 158 | Inst.Entity = reinterpret_cast<uintptr_t>(PartialSpec); |
| 159 | Inst.TemplateArgs = TemplateArgs; |
| 160 | Inst.NumTemplateArgs = NumTemplateArgs; |
| 161 | Inst.InstantiationRange = InstantiationRange; |
| 162 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 163 | Invalid = false; |
| 164 | } |
| 165 | } |
| 166 | |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 167 | void Sema::InstantiatingTemplate::Clear() { |
| 168 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 169 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 170 | Invalid = true; |
| 171 | } |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 174 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 175 | SourceLocation PointOfInstantiation, |
| 176 | SourceRange InstantiationRange) { |
| 177 | if (SemaRef.ActiveTemplateInstantiations.size() |
| 178 | <= SemaRef.getLangOptions().InstantiationDepth) |
| 179 | return false; |
| 180 | |
| 181 | SemaRef.Diag(PointOfInstantiation, |
| 182 | diag::err_template_recursion_depth_exceeded) |
| 183 | << SemaRef.getLangOptions().InstantiationDepth |
| 184 | << InstantiationRange; |
| 185 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 186 | << SemaRef.getLangOptions().InstantiationDepth; |
| 187 | return true; |
| 188 | } |
| 189 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 190 | /// \brief Prints the current instantiation stack through a series of |
| 191 | /// notes. |
| 192 | void Sema::PrintInstantiationStack() { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 193 | // FIXME: In all of these cases, we need to show the template arguments |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 194 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 195 | Active = ActiveTemplateInstantiations.rbegin(), |
| 196 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 197 | Active != ActiveEnd; |
| 198 | ++Active) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 199 | switch (Active->Kind) { |
| 200 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 201 | Decl *D = reinterpret_cast<Decl *>(Active->Entity); |
| 202 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { |
| 203 | unsigned DiagID = diag::note_template_member_class_here; |
| 204 | if (isa<ClassTemplateSpecializationDecl>(Record)) |
| 205 | DiagID = diag::note_template_class_instantiation_here; |
| 206 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 207 | DiagID) |
| 208 | << Context.getTypeDeclType(Record) |
| 209 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 210 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { |
Douglas Gregor | 1637be7 | 2009-06-26 00:10:03 +0000 | [diff] [blame] | 211 | unsigned DiagID; |
| 212 | if (Function->getPrimaryTemplate()) |
| 213 | DiagID = diag::note_function_template_spec_here; |
| 214 | else |
| 215 | DiagID = diag::note_template_member_function_here; |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 216 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 217 | DiagID) |
| 218 | << Function |
| 219 | << Active->InstantiationRange; |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 220 | } else { |
| 221 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 222 | diag::note_template_static_data_member_def_here) |
| 223 | << cast<VarDecl>(D) |
| 224 | << Active->InstantiationRange; |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 225 | } |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 226 | break; |
| 227 | } |
| 228 | |
| 229 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 230 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 231 | std::string TemplateArgsStr |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 232 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 233 | Active->TemplateArgs, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 234 | Active->NumTemplateArgs, |
| 235 | Context.PrintingPolicy); |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 236 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 237 | diag::note_default_arg_instantiation_here) |
| 238 | << (Template->getNameAsString() + TemplateArgsStr) |
| 239 | << Active->InstantiationRange; |
| 240 | break; |
| 241 | } |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 242 | |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 243 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: { |
| 244 | FunctionTemplateDecl *FnTmpl |
| 245 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 246 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 247 | diag::note_explicit_template_arg_substitution_here) |
| 248 | << FnTmpl << Active->InstantiationRange; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 249 | break; |
| 250 | } |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 251 | |
| 252 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 253 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 254 | = dyn_cast<ClassTemplatePartialSpecializationDecl>( |
| 255 | (Decl *)Active->Entity)) { |
| 256 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 257 | diag::note_partial_spec_deduct_instantiation_here) |
| 258 | << Context.getTypeDeclType(PartialSpec) |
| 259 | << Active->InstantiationRange; |
| 260 | } else { |
| 261 | FunctionTemplateDecl *FnTmpl |
| 262 | = cast<FunctionTemplateDecl>((Decl *)Active->Entity); |
| 263 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 264 | diag::note_function_template_deduction_instantiation_here) |
| 265 | << FnTmpl << Active->InstantiationRange; |
| 266 | } |
| 267 | break; |
Douglas Gregor | 637a409 | 2009-06-10 23:47:09 +0000 | [diff] [blame] | 268 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 269 | } |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 273 | bool Sema::isSFINAEContext() const { |
| 274 | using llvm::SmallVector; |
| 275 | for (SmallVector<ActiveTemplateInstantiation, 16>::const_reverse_iterator |
| 276 | Active = ActiveTemplateInstantiations.rbegin(), |
| 277 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 278 | Active != ActiveEnd; |
| 279 | ++Active) { |
| 280 | |
| 281 | switch(Active->Kind) { |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 282 | case ActiveTemplateInstantiation::TemplateInstantiation: |
| 283 | // This is a template instantiation, so there is no SFINAE. |
| 284 | return false; |
| 285 | |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 286 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: |
| 287 | // A default template argument instantiation may or may not be a |
| 288 | // SFINAE context; look further up the stack. |
| 289 | break; |
Douglas Gregor | cca9e96 | 2009-07-01 22:01:06 +0000 | [diff] [blame] | 290 | |
| 291 | case ActiveTemplateInstantiation::ExplicitTemplateArgumentSubstitution: |
| 292 | case ActiveTemplateInstantiation::DeducedTemplateArgumentSubstitution: |
| 293 | // We're either substitution explicitly-specified template arguments |
| 294 | // or deduced template arguments, so SFINAE applies. |
| 295 | return true; |
Douglas Gregor | 5e9f35c | 2009-06-14 07:33:30 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | return false; |
| 300 | } |
| 301 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 302 | //===----------------------------------------------------------------------===/ |
| 303 | // Template Instantiation for Types |
| 304 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 305 | namespace { |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 306 | class VISIBILITY_HIDDEN TemplateInstantiator |
| 307 | : public TreeTransform<TemplateInstantiator> |
| 308 | { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 309 | const MultiLevelTemplateArgumentList &TemplateArgs; |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 310 | SourceLocation Loc; |
| 311 | DeclarationName Entity; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 312 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 313 | public: |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 314 | typedef TreeTransform<TemplateInstantiator> inherited; |
| 315 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 316 | TemplateInstantiator(Sema &SemaRef, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 317 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 318 | SourceLocation Loc, |
| 319 | DeclarationName Entity) |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 320 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), |
| 321 | Entity(Entity) { } |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 322 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 323 | /// \brief Determine whether the given type \p T has already been |
| 324 | /// transformed. |
| 325 | /// |
| 326 | /// For the purposes of template instantiation, a type has already been |
| 327 | /// transformed if it is NULL or if it is not dependent. |
| 328 | bool AlreadyTransformed(QualType T) { |
| 329 | return T.isNull() || !T->isDependentType(); |
Douglas Gregor | ff66803 | 2009-05-13 18:28:20 +0000 | [diff] [blame] | 330 | } |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 331 | |
| 332 | /// \brief Returns the location of the entity being instantiated, if known. |
| 333 | SourceLocation getBaseLocation() { return Loc; } |
| 334 | |
| 335 | /// \brief Returns the name of the entity being instantiated, if any. |
| 336 | DeclarationName getBaseEntity() { return Entity; } |
| 337 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 338 | /// \brief Transform the given declaration by instantiating a reference to |
| 339 | /// this declaration. |
| 340 | Decl *TransformDecl(Decl *D); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 341 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 342 | /// \brief Transform the definition of the given declaration by |
| 343 | /// instantiating it. |
| 344 | Decl *TransformDefinition(Decl *D); |
| 345 | |
| 346 | /// \brief Rebuild the exception declaration and register the declaration |
| 347 | /// as an instantiated local. |
| 348 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T, |
| 349 | DeclaratorInfo *Declarator, |
| 350 | IdentifierInfo *Name, |
| 351 | SourceLocation Loc, SourceRange TypeRange); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 352 | |
| 353 | Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E); |
| 354 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 355 | /// \brief Transforms a template type parameter type by performing |
| 356 | /// substitution of the corresponding template type argument. |
| 357 | QualType TransformTemplateTypeParmType(const TemplateTypeParmType *T); |
| 358 | }; |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 361 | Decl *TemplateInstantiator::TransformDecl(Decl *D) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 362 | if (TemplateTemplateParmDecl *TTP |
| 363 | = dyn_cast_or_null<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 364 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { |
| 365 | assert(TemplateArgs(TTP->getDepth(), TTP->getPosition()).getAsDecl() && |
| 366 | "Wrong kind of template template argument"); |
| 367 | return cast<TemplateDecl>(TemplateArgs(TTP->getDepth(), |
| 368 | TTP->getPosition()).getAsDecl()); |
| 369 | } |
| 370 | |
| 371 | // If the corresponding template argument is NULL or non-existent, it's |
| 372 | // because we are performing instantiation from explicitly-specified |
| 373 | // template arguments in a function template, but there were some |
| 374 | // arguments left unspecified. |
| 375 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), |
| 376 | TTP->getPosition())) |
| 377 | return D; |
| 378 | |
| 379 | // FIXME: Implement depth reduction of template template parameters |
| 380 | assert(false && |
| 381 | "Reducing depth of template template parameters is not yet implemented"); |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 382 | } |
| 383 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 384 | return SemaRef.FindInstantiatedDecl(cast_or_null<NamedDecl>(D)); |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 387 | Decl *TemplateInstantiator::TransformDefinition(Decl *D) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 388 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 389 | if (!Inst) |
| 390 | return 0; |
| 391 | |
| 392 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); |
| 393 | return Inst; |
| 394 | } |
| 395 | |
| 396 | VarDecl * |
| 397 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 398 | QualType T, |
| 399 | DeclaratorInfo *Declarator, |
| 400 | IdentifierInfo *Name, |
| 401 | SourceLocation Loc, |
| 402 | SourceRange TypeRange) { |
| 403 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, T, Declarator, |
| 404 | Name, Loc, TypeRange); |
| 405 | if (Var && !Var->isInvalidDecl()) |
| 406 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); |
| 407 | return Var; |
| 408 | } |
| 409 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 410 | Sema::OwningExprResult |
| 411 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { |
| 412 | // FIXME: Clean this up a bit |
| 413 | NamedDecl *D = E->getDecl(); |
| 414 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 415 | if (NTTP->getDepth() >= TemplateArgs.getNumLevels()) { |
| 416 | assert(false && "Cannot reduce non-type template parameter depth yet"); |
| 417 | return getSema().ExprError(); |
| 418 | } |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 419 | |
| 420 | // If the corresponding template argument is NULL or non-existent, it's |
| 421 | // because we are performing instantiation from explicitly-specified |
| 422 | // template arguments in a function template, but there were some |
| 423 | // arguments left unspecified. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 424 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), |
| 425 | NTTP->getPosition())) |
| 426 | return SemaRef.Owned(E->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 427 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 428 | const TemplateArgument &Arg = TemplateArgs(NTTP->getDepth(), |
| 429 | NTTP->getPosition()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 430 | |
| 431 | // The template argument itself might be an expression, in which |
| 432 | // case we just return that expression. |
| 433 | if (Arg.getKind() == TemplateArgument::Expression) |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 434 | return SemaRef.Owned(Arg.getAsExpr()->Retain()); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 435 | |
| 436 | if (Arg.getKind() == TemplateArgument::Declaration) { |
| 437 | ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); |
| 438 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 439 | VD = cast_or_null<ValueDecl>(getSema().FindInstantiatedDecl(VD)); |
| 440 | if (!VD) |
| 441 | return SemaRef.ExprError(); |
| 442 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 443 | return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 444 | /*FIXME:*/false, /*FIXME:*/false); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | assert(Arg.getKind() == TemplateArgument::Integral); |
| 448 | QualType T = Arg.getIntegralType(); |
| 449 | if (T->isCharType() || T->isWideCharType()) |
| 450 | return SemaRef.Owned(new (SemaRef.Context) CharacterLiteral( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 451 | Arg.getAsIntegral()->getZExtValue(), |
| 452 | T->isWideCharType(), |
| 453 | T, |
| 454 | E->getSourceRange().getBegin())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 455 | if (T->isBooleanType()) |
| 456 | return SemaRef.Owned(new (SemaRef.Context) CXXBoolLiteralExpr( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 457 | Arg.getAsIntegral()->getBoolValue(), |
| 458 | T, |
| 459 | E->getSourceRange().getBegin())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 460 | |
| 461 | assert(Arg.getAsIntegral()->getBitWidth() == SemaRef.Context.getIntWidth(T)); |
| 462 | return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 463 | *Arg.getAsIntegral(), |
| 464 | T, |
| 465 | E->getSourceRange().getBegin())); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) { |
| 469 | // FIXME: instantiate each decl in the overload set |
| 470 | return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Ovl, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 471 | SemaRef.Context.OverloadTy, |
| 472 | E->getLocation(), |
| 473 | false, false)); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 474 | } |
| 475 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 476 | NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D); |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 477 | if (!InstD) |
| 478 | return SemaRef.ExprError(); |
| 479 | |
| 480 | // FIXME: nested-name-specifier for QualifiedDeclRefExpr |
| 481 | return SemaRef.BuildDeclarationNameExpr(E->getLocation(), InstD, |
| 482 | /*FIXME:*/false, |
| 483 | /*FIXME:*/0, |
| 484 | /*FIXME:*/false); |
| 485 | } |
| 486 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 487 | QualType |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 488 | TemplateInstantiator::TransformTemplateTypeParmType( |
| 489 | const TemplateTypeParmType *T) { |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 490 | if (T->getDepth() < TemplateArgs.getNumLevels()) { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 491 | // Replace the template type parameter with its corresponding |
| 492 | // template argument. |
Douglas Gregor | 16134c6 | 2009-07-01 00:28:38 +0000 | [diff] [blame] | 493 | |
| 494 | // If the corresponding template argument is NULL or doesn't exist, it's |
| 495 | // because we are performing instantiation from explicitly-specified |
| 496 | // template arguments in a function template class, but there were some |
| 497 | // arguments left unspecified. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 498 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) |
| 499 | return QualType(T, 0); |
| 500 | |
| 501 | assert(TemplateArgs(T->getDepth(), T->getIndex()).getKind() |
| 502 | == TemplateArgument::Type && |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 503 | "Template argument kind mismatch"); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 504 | |
| 505 | return TemplateArgs(T->getDepth(), T->getIndex()).getAsType(); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | // The template type parameter comes from an inner template (e.g., |
| 509 | // the template parameter list of a member template inside the |
| 510 | // template we are instantiating). Create a new template type |
| 511 | // parameter with the template "level" reduced by one. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 512 | return getSema().Context.getTemplateTypeParmType( |
| 513 | T->getDepth() - TemplateArgs.getNumLevels(), |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 514 | T->getIndex(), |
| 515 | T->isParameterPack(), |
| 516 | T->getName()); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 517 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 518 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 519 | /// \brief Perform substitution on the type T with a given set of template |
| 520 | /// arguments. |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 521 | /// |
| 522 | /// This routine substitutes the given template arguments into the |
| 523 | /// type T and produces the instantiated type. |
| 524 | /// |
| 525 | /// \param T the type into which the template arguments will be |
| 526 | /// substituted. If this type is not dependent, it will be returned |
| 527 | /// immediately. |
| 528 | /// |
| 529 | /// \param TemplateArgs the template arguments that will be |
| 530 | /// substituted for the top-level template parameters within T. |
| 531 | /// |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 532 | /// \param Loc the location in the source code where this substitution |
| 533 | /// is being performed. It will typically be the location of the |
| 534 | /// declarator (if we're instantiating the type of some declaration) |
| 535 | /// or the location of the type in the source code (if, e.g., we're |
| 536 | /// instantiating the type of a cast expression). |
| 537 | /// |
| 538 | /// \param Entity the name of the entity associated with a declaration |
| 539 | /// being instantiated (if any). May be empty to indicate that there |
| 540 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 541 | /// a cast expression) or that the entity has no name (e.g., an |
| 542 | /// unnamed function parameter). |
| 543 | /// |
| 544 | /// \returns If the instantiation succeeds, the instantiated |
| 545 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 546 | QualType Sema::SubstType(QualType T, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 547 | const MultiLevelTemplateArgumentList &TemplateArgs, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 548 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 549 | assert(!ActiveTemplateInstantiations.empty() && |
| 550 | "Cannot perform an instantiation without some context on the " |
| 551 | "instantiation stack"); |
| 552 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 553 | // If T is not a dependent type, there is nothing to do. |
| 554 | if (!T->isDependentType()) |
| 555 | return T; |
| 556 | |
Douglas Gregor | 577f75a | 2009-08-04 16:50:30 +0000 | [diff] [blame] | 557 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); |
| 558 | return Instantiator.TransformType(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 559 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 560 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 561 | /// \brief Perform substitution on the base class specifiers of the |
| 562 | /// given class template specialization. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 563 | /// |
| 564 | /// Produces a diagnostic and returns true on error, returns false and |
| 565 | /// attaches the instantiated base classes to the class template |
| 566 | /// specialization if successful. |
| 567 | bool |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 568 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 569 | CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 570 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 571 | bool Invalid = false; |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 572 | llvm::SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 573 | for (ClassTemplateSpecializationDecl::base_class_iterator |
| 574 | Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 575 | Base != BaseEnd; ++Base) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 576 | if (!Base->getType()->isDependentType()) { |
Fariborz Jahanian | 71c6e71 | 2009-07-22 17:41:53 +0000 | [diff] [blame] | 577 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base)); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 578 | continue; |
| 579 | } |
| 580 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 581 | QualType BaseType = SubstType(Base->getType(), |
| 582 | TemplateArgs, |
| 583 | Base->getSourceRange().getBegin(), |
| 584 | DeclarationName()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 585 | if (BaseType.isNull()) { |
| 586 | Invalid = true; |
| 587 | continue; |
| 588 | } |
| 589 | |
| 590 | if (CXXBaseSpecifier *InstantiatedBase |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 591 | = CheckBaseSpecifier(Instantiation, |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 592 | Base->getSourceRange(), |
| 593 | Base->isVirtual(), |
| 594 | Base->getAccessSpecifierAsWritten(), |
| 595 | BaseType, |
| 596 | /*FIXME: Not totally accurate */ |
| 597 | Base->getSourceRange().getBegin())) |
| 598 | InstantiatedBases.push_back(InstantiatedBase); |
| 599 | else |
| 600 | Invalid = true; |
| 601 | } |
| 602 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 603 | if (!Invalid && |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 604 | AttachBaseSpecifiers(Instantiation, InstantiatedBases.data(), |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 605 | InstantiatedBases.size())) |
| 606 | Invalid = true; |
| 607 | |
| 608 | return Invalid; |
| 609 | } |
| 610 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 611 | /// \brief Instantiate the definition of a class from a given pattern. |
| 612 | /// |
| 613 | /// \param PointOfInstantiation The point of instantiation within the |
| 614 | /// source code. |
| 615 | /// |
| 616 | /// \param Instantiation is the declaration whose definition is being |
| 617 | /// instantiated. This will be either a class template specialization |
| 618 | /// or a member class of a class template specialization. |
| 619 | /// |
| 620 | /// \param Pattern is the pattern from which the instantiation |
| 621 | /// occurs. This will be either the declaration of a class template or |
| 622 | /// the declaration of a member class of a class template. |
| 623 | /// |
| 624 | /// \param TemplateArgs The template arguments to be substituted into |
| 625 | /// the pattern. |
| 626 | /// |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 627 | /// \param ExplicitInstantiation whether this is an explicit instantiation |
| 628 | /// (otherwise, it is an implicit instantiation). |
| 629 | /// |
| 630 | /// \param Complain whether to complain if the class cannot be instantiated due |
| 631 | /// to the lack of a definition. |
| 632 | /// |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 633 | /// \returns true if an error occurred, false otherwise. |
| 634 | bool |
| 635 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, |
| 636 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 637 | const MultiLevelTemplateArgumentList &TemplateArgs, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 638 | bool ExplicitInstantiation, |
| 639 | bool Complain) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 640 | bool Invalid = false; |
John McCall | e29ba20 | 2009-08-20 01:44:21 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 642 | CXXRecordDecl *PatternDef |
| 643 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition(Context)); |
| 644 | if (!PatternDef) { |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 645 | if (!Complain) { |
| 646 | // Say nothing |
| 647 | } else if (Pattern == Instantiation->getInstantiatedFromMemberClass()) { |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 648 | Diag(PointOfInstantiation, |
| 649 | diag::err_implicit_instantiate_member_undefined) |
| 650 | << Context.getTypeDeclType(Instantiation); |
| 651 | Diag(Pattern->getLocation(), diag::note_member_of_template_here); |
| 652 | } else { |
Douglas Gregor | 93dfdb1 | 2009-05-13 00:25:59 +0000 | [diff] [blame] | 653 | Diag(PointOfInstantiation, diag::err_template_instantiate_undefined) |
| 654 | << ExplicitInstantiation |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 655 | << Context.getTypeDeclType(Instantiation); |
| 656 | Diag(Pattern->getLocation(), diag::note_template_decl_here); |
| 657 | } |
| 658 | return true; |
| 659 | } |
| 660 | Pattern = PatternDef; |
| 661 | |
Douglas Gregor | d048bb7 | 2009-03-25 21:23:52 +0000 | [diff] [blame] | 662 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 663 | if (Inst) |
| 664 | return true; |
| 665 | |
| 666 | // Enter the scope of this instantiation. We don't use |
| 667 | // PushDeclContext because we don't have a scope. |
| 668 | DeclContext *PreviousContext = CurContext; |
| 669 | CurContext = Instantiation; |
| 670 | |
| 671 | // Start the definition of this instantiation. |
| 672 | Instantiation->startDefinition(); |
| 673 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 674 | // Do substitution on the base class specifiers. |
| 675 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 676 | Invalid = true; |
| 677 | |
Douglas Gregor | 0ca20ac | 2009-05-29 18:27:38 +0000 | [diff] [blame] | 678 | llvm::SmallVector<DeclPtrTy, 4> Fields; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 679 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
| 680 | MemberEnd = Pattern->decls_end(); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 681 | Member != MemberEnd; ++Member) { |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 682 | Decl *NewMember = SubstDecl(*Member, Instantiation, TemplateArgs); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 683 | if (NewMember) { |
| 684 | if (NewMember->isInvalidDecl()) |
| 685 | Invalid = true; |
| 686 | else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 687 | Fields.push_back(DeclPtrTy::make(Field)); |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 688 | } else { |
| 689 | // FIXME: Eventually, a NULL return will mean that one of the |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 690 | // instantiations was a semantic disaster, and we'll want to set Invalid = |
| 691 | // true. For now, we expect to skip some members that we can't yet handle. |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | // Finish checking fields. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 696 | ActOnFields(0, Instantiation->getLocation(), DeclPtrTy::make(Instantiation), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 697 | Fields.data(), Fields.size(), SourceLocation(), SourceLocation(), |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 698 | 0); |
| 699 | |
| 700 | // Add any implicitly-declared members that we might need. |
| 701 | AddImplicitlyDeclaredMembersToClass(Instantiation); |
| 702 | |
| 703 | // Exit the scope of this instantiation. |
| 704 | CurContext = PreviousContext; |
| 705 | |
Douglas Gregor | aba43bb | 2009-05-26 20:50:29 +0000 | [diff] [blame] | 706 | if (!Invalid) |
| 707 | Consumer.HandleTagDeclDefinition(Instantiation); |
| 708 | |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 709 | // If this is an explicit instantiation, instantiate our members, too. |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 710 | if (!Invalid && ExplicitInstantiation) { |
| 711 | Inst.Clear(); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 712 | InstantiateClassMembers(PointOfInstantiation, Instantiation, TemplateArgs); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 713 | } |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 714 | |
Douglas Gregor | d475b8d | 2009-03-25 21:17:03 +0000 | [diff] [blame] | 715 | return Invalid; |
| 716 | } |
| 717 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 718 | bool |
| 719 | Sema::InstantiateClassTemplateSpecialization( |
| 720 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 721 | bool ExplicitInstantiation, |
| 722 | bool Complain) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 723 | // Perform the actual instantiation on the canonical declaration. |
| 724 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
Argyrios Kyrtzidis | 97fbaa2 | 2009-07-18 00:34:25 +0000 | [diff] [blame] | 725 | ClassTemplateSpec->getCanonicalDecl()); |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 726 | |
| 727 | // We can only instantiate something that hasn't already been |
| 728 | // instantiated or specialized. Fail without any diagnostics: our |
| 729 | // caller will provide an error message. |
| 730 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) |
| 731 | return true; |
| 732 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 733 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 734 | CXXRecordDecl *Pattern = 0; |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 735 | |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 736 | // C++ [temp.class.spec.match]p1: |
| 737 | // When a class template is used in a context that requires an |
| 738 | // instantiation of the class, it is necessary to determine |
| 739 | // whether the instantiation is to be generated using the primary |
| 740 | // template or one of the partial specializations. This is done by |
| 741 | // matching the template arguments of the class template |
| 742 | // specialization with the template argument lists of the partial |
| 743 | // specializations. |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 744 | typedef std::pair<ClassTemplatePartialSpecializationDecl *, |
| 745 | TemplateArgumentList *> MatchResult; |
| 746 | llvm::SmallVector<MatchResult, 4> Matched; |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 747 | for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator |
| 748 | Partial = Template->getPartialSpecializations().begin(), |
| 749 | PartialEnd = Template->getPartialSpecializations().end(); |
| 750 | Partial != PartialEnd; |
| 751 | ++Partial) { |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 752 | TemplateDeductionInfo Info(Context); |
| 753 | if (TemplateDeductionResult Result |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 754 | = DeduceTemplateArguments(&*Partial, |
Douglas Gregor | f67875d | 2009-06-12 18:26:56 +0000 | [diff] [blame] | 755 | ClassTemplateSpec->getTemplateArgs(), |
| 756 | Info)) { |
| 757 | // FIXME: Store the failed-deduction information for use in |
| 758 | // diagnostics, later. |
| 759 | (void)Result; |
| 760 | } else { |
| 761 | Matched.push_back(std::make_pair(&*Partial, Info.take())); |
| 762 | } |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | if (Matched.size() == 1) { |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 766 | // -- If exactly one matching specialization is found, the |
| 767 | // instantiation is generated from that specialization. |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 768 | Pattern = Matched[0].first; |
Douglas Gregor | 37d93e9 | 2009-08-02 23:24:31 +0000 | [diff] [blame] | 769 | ClassTemplateSpec->setInstantiationOf(Matched[0].first, Matched[0].second); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 770 | } else if (Matched.size() > 1) { |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 771 | // -- If more than one matching specialization is found, the |
| 772 | // partial order rules (14.5.4.2) are used to determine |
| 773 | // whether one of the specializations is more specialized |
| 774 | // than the others. If none of the specializations is more |
| 775 | // specialized than all of the other matching |
| 776 | // specializations, then the use of the class template is |
| 777 | // ambiguous and the program is ill-formed. |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 778 | // FIXME: Implement partial ordering of class template partial |
| 779 | // specializations. |
| 780 | Diag(ClassTemplateSpec->getLocation(), |
| 781 | diag::unsup_template_partial_spec_ordering); |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 782 | |
| 783 | // FIXME: Temporary hack to fall back to the primary template |
| 784 | ClassTemplateDecl *OrigTemplate = Template; |
| 785 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) |
| 786 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
| 787 | |
| 788 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | c1efb3f | 2009-06-12 22:31:52 +0000 | [diff] [blame] | 789 | } else { |
| 790 | // -- If no matches are found, the instantiation is generated |
| 791 | // from the primary template. |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 792 | ClassTemplateDecl *OrigTemplate = Template; |
| 793 | while (OrigTemplate->getInstantiatedFromMemberTemplate()) |
| 794 | OrigTemplate = OrigTemplate->getInstantiatedFromMemberTemplate(); |
| 795 | |
| 796 | Pattern = OrigTemplate->getTemplatedDecl(); |
Douglas Gregor | c8ab256 | 2009-05-31 09:31:02 +0000 | [diff] [blame] | 797 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 798 | |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 799 | // Note that this is an instantiation. |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 800 | ClassTemplateSpec->setSpecializationKind( |
| 801 | ExplicitInstantiation? TSK_ExplicitInstantiation |
| 802 | : TSK_ImplicitInstantiation); |
| 803 | |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 804 | bool Result = InstantiateClass(ClassTemplateSpec->getLocation(), |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 805 | ClassTemplateSpec, Pattern, |
| 806 | getTemplateInstantiationArgs(ClassTemplateSpec), |
Douglas Gregor | 5842ba9 | 2009-08-24 15:23:48 +0000 | [diff] [blame] | 807 | ExplicitInstantiation, |
| 808 | Complain); |
Douglas Gregor | 199d991 | 2009-06-05 00:53:49 +0000 | [diff] [blame] | 809 | |
| 810 | for (unsigned I = 0, N = Matched.size(); I != N; ++I) { |
| 811 | // FIXME: Implement TemplateArgumentList::Destroy! |
| 812 | // if (Matched[I].first != Pattern) |
| 813 | // Matched[I].second->Destroy(Context); |
| 814 | } |
| 815 | |
| 816 | return Result; |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 817 | } |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 818 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 819 | /// \brief Instantiates the definitions of all of the member |
| 820 | /// of the given class, which is an instantiation of a class template |
| 821 | /// or a member class of a template. |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 822 | void |
| 823 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 824 | CXXRecordDecl *Instantiation, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 825 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 826 | for (DeclContext::decl_iterator D = Instantiation->decls_begin(), |
| 827 | DEnd = Instantiation->decls_end(); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 828 | D != DEnd; ++D) { |
| 829 | if (FunctionDecl *Function = dyn_cast<FunctionDecl>(*D)) { |
Argyrios Kyrtzidis | 6fb0aee | 2009-06-30 02:35:26 +0000 | [diff] [blame] | 830 | if (!Function->getBody()) |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 831 | InstantiateFunctionDefinition(PointOfInstantiation, Function); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 832 | } else if (VarDecl *Var = dyn_cast<VarDecl>(*D)) { |
Douglas Gregor | 7caa682 | 2009-07-24 20:34:43 +0000 | [diff] [blame] | 833 | if (Var->isStaticDataMember()) |
| 834 | InstantiateStaticDataMemberDefinition(PointOfInstantiation, Var); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 835 | } else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(*D)) { |
| 836 | if (!Record->isInjectedClassName() && !Record->getDefinition(Context)) { |
| 837 | assert(Record->getInstantiatedFromMemberClass() && |
| 838 | "Missing instantiated-from-template information"); |
Douglas Gregor | f3e7ce4 | 2009-05-18 17:01:57 +0000 | [diff] [blame] | 839 | InstantiateClass(PointOfInstantiation, Record, |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 840 | Record->getInstantiatedFromMemberClass(), |
| 841 | TemplateArgs, true); |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | /// \brief Instantiate the definitions of all of the members of the |
| 848 | /// given class template specialization, which was named as part of an |
| 849 | /// explicit instantiation. |
| 850 | void Sema::InstantiateClassTemplateSpecializationMembers( |
| 851 | SourceLocation PointOfInstantiation, |
| 852 | ClassTemplateSpecializationDecl *ClassTemplateSpec) { |
| 853 | // C++0x [temp.explicit]p7: |
| 854 | // An explicit instantiation that names a class template |
| 855 | // specialization is an explicit instantion of the same kind |
| 856 | // (declaration or definition) of each of its members (not |
| 857 | // including members inherited from base classes) that has not |
| 858 | // been previously explicitly specialized in the translation unit |
| 859 | // containing the explicit instantiation, except as described |
| 860 | // below. |
| 861 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 862 | getTemplateInstantiationArgs(ClassTemplateSpec)); |
Douglas Gregor | a58861f | 2009-05-13 20:28:22 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 865 | Sema::OwningStmtResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 866 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 43959a9 | 2009-08-20 07:17:43 +0000 | [diff] [blame] | 867 | if (!S) |
| 868 | return Owned(S); |
| 869 | |
| 870 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 871 | SourceLocation(), |
| 872 | DeclarationName()); |
| 873 | return Instantiator.TransformStmt(S); |
| 874 | } |
| 875 | |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 876 | Sema::OwningExprResult |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 877 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | b98b199 | 2009-08-11 05:31:07 +0000 | [diff] [blame] | 878 | if (!E) |
| 879 | return Owned(E); |
| 880 | |
| 881 | TemplateInstantiator Instantiator(*this, TemplateArgs, |
| 882 | SourceLocation(), |
| 883 | DeclarationName()); |
| 884 | return Instantiator.TransformExpr(E); |
| 885 | } |
| 886 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 887 | /// \brief Do template substitution on a nested-name-specifier. |
Douglas Gregor | ab452ba | 2009-03-26 23:50:42 +0000 | [diff] [blame] | 888 | NestedNameSpecifier * |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 889 | Sema::SubstNestedNameSpecifier(NestedNameSpecifier *NNS, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 890 | SourceRange Range, |
| 891 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | dcee1a1 | 2009-08-06 05:28:30 +0000 | [diff] [blame] | 892 | TemplateInstantiator Instantiator(*this, TemplateArgs, Range.getBegin(), |
| 893 | DeclarationName()); |
| 894 | return Instantiator.TransformNestedNameSpecifier(NNS, Range); |
Douglas Gregor | 5953d8b | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 895 | } |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 896 | |
| 897 | TemplateName |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 898 | Sema::SubstTemplateName(TemplateName Name, SourceLocation Loc, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 899 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | d1067e5 | 2009-08-06 06:41:21 +0000 | [diff] [blame] | 900 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, |
| 901 | DeclarationName()); |
| 902 | return Instantiator.TransformTemplateName(Name); |
Douglas Gregor | de650ae | 2009-03-31 18:38:02 +0000 | [diff] [blame] | 903 | } |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 904 | |
John McCall | ce3ff2b | 2009-08-25 22:02:44 +0000 | [diff] [blame] | 905 | TemplateArgument Sema::Subst(TemplateArgument Arg, |
Douglas Gregor | d6350ae | 2009-08-28 20:31:08 +0000 | [diff] [blame] | 906 | const MultiLevelTemplateArgumentList &TemplateArgs) { |
Douglas Gregor | 670444e | 2009-08-04 22:27:00 +0000 | [diff] [blame] | 907 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), |
| 908 | DeclarationName()); |
| 909 | return Instantiator.TransformTemplateArgument(Arg); |
Douglas Gregor | 9133300 | 2009-06-11 00:06:24 +0000 | [diff] [blame] | 910 | } |