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" |
| 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/Expr.h" |
| 16 | #include "clang/AST/ExprCXX.h" |
| 17 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 18 | #include "clang/AST/StmtVisitor.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 19 | #include "clang/Parse/DeclSpec.h" |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 20 | #include "clang/Lex/Preprocessor.h" // for the identifier table |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 21 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace clang; |
| 25 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===/ |
| 27 | // Template Instantiation Support |
| 28 | //===----------------------------------------------------------------------===/ |
| 29 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 30 | Sema::InstantiatingTemplate:: |
| 31 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 32 | ClassTemplateSpecializationDecl *Entity, |
| 33 | SourceRange InstantiationRange) |
| 34 | : SemaRef(SemaRef) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 35 | |
| 36 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 37 | InstantiationRange); |
| 38 | if (!Invalid) { |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 39 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 40 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 41 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 42 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 43 | Inst.TemplateArgs = 0; |
| 44 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 45 | Inst.InstantiationRange = InstantiationRange; |
| 46 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 47 | Invalid = false; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 52 | SourceLocation PointOfInstantiation, |
| 53 | TemplateDecl *Template, |
| 54 | const TemplateArgument *TemplateArgs, |
| 55 | unsigned NumTemplateArgs, |
| 56 | SourceRange InstantiationRange) |
| 57 | : SemaRef(SemaRef) { |
| 58 | |
| 59 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 60 | InstantiationRange); |
| 61 | if (!Invalid) { |
| 62 | ActiveTemplateInstantiation Inst; |
| 63 | Inst.Kind |
| 64 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 65 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 66 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 67 | Inst.TemplateArgs = TemplateArgs; |
| 68 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 69 | Inst.InstantiationRange = InstantiationRange; |
| 70 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 71 | Invalid = false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | Sema::InstantiatingTemplate::~InstantiatingTemplate() { |
| 76 | if (!Invalid) |
| 77 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
| 78 | } |
| 79 | |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 80 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 81 | SourceLocation PointOfInstantiation, |
| 82 | SourceRange InstantiationRange) { |
| 83 | if (SemaRef.ActiveTemplateInstantiations.size() |
| 84 | <= SemaRef.getLangOptions().InstantiationDepth) |
| 85 | return false; |
| 86 | |
| 87 | SemaRef.Diag(PointOfInstantiation, |
| 88 | diag::err_template_recursion_depth_exceeded) |
| 89 | << SemaRef.getLangOptions().InstantiationDepth |
| 90 | << InstantiationRange; |
| 91 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 92 | << SemaRef.getLangOptions().InstantiationDepth; |
| 93 | return true; |
| 94 | } |
| 95 | |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 96 | /// \brief Post-diagnostic hook for printing the instantiation stack. |
| 97 | void Sema::PrintInstantiationStackHook(unsigned, void *Cookie) { |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 98 | Sema &SemaRef = *static_cast<Sema*>(Cookie); |
| 99 | SemaRef.PrintInstantiationStack(); |
| 100 | SemaRef.LastTemplateInstantiationErrorContext |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 101 | = SemaRef.ActiveTemplateInstantiations.back(); |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /// \brief Prints the current instantiation stack through a series of |
| 105 | /// notes. |
| 106 | void Sema::PrintInstantiationStack() { |
| 107 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 108 | Active = ActiveTemplateInstantiations.rbegin(), |
| 109 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 110 | Active != ActiveEnd; |
| 111 | ++Active) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 112 | switch (Active->Kind) { |
| 113 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
| 114 | ClassTemplateSpecializationDecl *Spec |
| 115 | = cast<ClassTemplateSpecializationDecl>((Decl*)Active->Entity); |
| 116 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 117 | diag::note_template_class_instantiation_here) |
| 118 | << Context.getTypeDeclType(Spec) |
| 119 | << Active->InstantiationRange; |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 124 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 125 | std::string TemplateArgsStr |
| 126 | = ClassTemplateSpecializationType::PrintTemplateArgumentList( |
| 127 | Active->TemplateArgs, |
| 128 | Active->NumTemplateArgs); |
| 129 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 130 | diag::note_default_arg_instantiation_here) |
| 131 | << (Template->getNameAsString() + TemplateArgsStr) |
| 132 | << Active->InstantiationRange; |
| 133 | break; |
| 134 | } |
| 135 | } |
Douglas Gregor | ee1828a | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 139 | //===----------------------------------------------------------------------===/ |
| 140 | // Template Instantiation for Types |
| 141 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 142 | namespace { |
| 143 | class VISIBILITY_HIDDEN TemplateTypeInstantiator { |
| 144 | Sema &SemaRef; |
| 145 | const TemplateArgument *TemplateArgs; |
| 146 | unsigned NumTemplateArgs; |
| 147 | SourceLocation Loc; |
| 148 | DeclarationName Entity; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 149 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 150 | public: |
| 151 | TemplateTypeInstantiator(Sema &SemaRef, |
| 152 | const TemplateArgument *TemplateArgs, |
| 153 | unsigned NumTemplateArgs, |
| 154 | SourceLocation Loc, |
| 155 | DeclarationName Entity) |
| 156 | : SemaRef(SemaRef), TemplateArgs(TemplateArgs), |
| 157 | NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { } |
| 158 | |
| 159 | QualType operator()(QualType T) const { return Instantiate(T); } |
| 160 | |
| 161 | QualType Instantiate(QualType T) const; |
| 162 | |
| 163 | // Declare instantiate functions for each type. |
| 164 | #define TYPE(Class, Base) \ |
| 165 | QualType Instantiate##Class##Type(const Class##Type *T, \ |
| 166 | unsigned Quals) const; |
| 167 | #define ABSTRACT_TYPE(Class, Base) |
| 168 | #include "clang/AST/TypeNodes.def" |
| 169 | }; |
| 170 | } |
| 171 | |
| 172 | QualType |
| 173 | TemplateTypeInstantiator::InstantiateExtQualType(const ExtQualType *T, |
| 174 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 175 | // FIXME: Implement this |
| 176 | assert(false && "Cannot instantiate ExtQualType yet"); |
| 177 | return QualType(); |
| 178 | } |
| 179 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 180 | QualType |
| 181 | TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T, |
| 182 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 183 | assert(false && "Builtin types are not dependent and cannot be instantiated"); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 184 | return QualType(T, Quals); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 187 | QualType |
| 188 | TemplateTypeInstantiator:: |
| 189 | InstantiateFixedWidthIntType(const FixedWidthIntType *T, unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 190 | // FIXME: Implement this |
| 191 | assert(false && "Cannot instantiate FixedWidthIntType yet"); |
| 192 | return QualType(); |
| 193 | } |
| 194 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 195 | QualType |
| 196 | TemplateTypeInstantiator::InstantiateComplexType(const ComplexType *T, |
| 197 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 198 | // FIXME: Implement this |
| 199 | assert(false && "Cannot instantiate ComplexType yet"); |
| 200 | return QualType(); |
| 201 | } |
| 202 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 203 | QualType |
| 204 | TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T, |
| 205 | unsigned Quals) const { |
| 206 | QualType PointeeType = Instantiate(T->getPointeeType()); |
| 207 | if (PointeeType.isNull()) |
| 208 | return QualType(); |
| 209 | |
| 210 | return SemaRef.BuildPointerType(PointeeType, Quals, Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 213 | QualType |
| 214 | TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T, |
| 215 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 216 | // FIXME: Implement this |
| 217 | assert(false && "Cannot instantiate BlockPointerType yet"); |
| 218 | return QualType(); |
| 219 | } |
| 220 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame^] | 221 | QualType |
| 222 | TemplateTypeInstantiator::InstantiateLValueReferenceType( |
| 223 | const LValueReferenceType *T, unsigned Quals) const { |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 224 | QualType ReferentType = Instantiate(T->getPointeeType()); |
| 225 | if (ReferentType.isNull()) |
| 226 | return QualType(); |
| 227 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame^] | 228 | return SemaRef.BuildReferenceType(ReferentType, true, Quals, Loc, Entity); |
| 229 | } |
| 230 | |
| 231 | QualType |
| 232 | TemplateTypeInstantiator::InstantiateRValueReferenceType( |
| 233 | const RValueReferenceType *T, unsigned Quals) const { |
| 234 | QualType ReferentType = Instantiate(T->getPointeeType()); |
| 235 | if (ReferentType.isNull()) |
| 236 | return QualType(); |
| 237 | |
| 238 | return SemaRef.BuildReferenceType(ReferentType, false, Quals, Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 241 | QualType |
| 242 | TemplateTypeInstantiator:: |
| 243 | InstantiateMemberPointerType(const MemberPointerType *T, |
| 244 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 245 | // FIXME: Implement this |
| 246 | assert(false && "Cannot instantiate MemberPointerType yet"); |
| 247 | return QualType(); |
| 248 | } |
| 249 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 250 | QualType |
| 251 | TemplateTypeInstantiator:: |
| 252 | InstantiateConstantArrayType(const ConstantArrayType *T, |
| 253 | unsigned Quals) const { |
| 254 | QualType ElementType = Instantiate(T->getElementType()); |
| 255 | if (ElementType.isNull()) |
| 256 | return ElementType; |
| 257 | |
| 258 | // Build a temporary integer literal to specify the size for |
| 259 | // BuildArrayType. Since we have already checked the size as part of |
| 260 | // creating the dependent array type in the first place, we know |
| 261 | // there aren't any errors. |
Douglas Gregor | 8d21721 | 2009-03-09 20:07:22 +0000 | [diff] [blame] | 262 | // FIXME: Is IntTy big enough? Maybe not, but LongLongTy causes |
| 263 | // problems that I have yet to investigate. |
| 264 | IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 265 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 266 | &ArraySize, T->getIndexTypeQualifier(), |
| 267 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 270 | QualType |
| 271 | TemplateTypeInstantiator:: |
| 272 | InstantiateIncompleteArrayType(const IncompleteArrayType *T, |
| 273 | unsigned Quals) const { |
| 274 | QualType ElementType = Instantiate(T->getElementType()); |
| 275 | if (ElementType.isNull()) |
| 276 | return ElementType; |
| 277 | |
| 278 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 279 | 0, T->getIndexTypeQualifier(), |
| 280 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 283 | QualType |
| 284 | TemplateTypeInstantiator:: |
| 285 | InstantiateVariableArrayType(const VariableArrayType *T, |
| 286 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 287 | // FIXME: Implement this |
| 288 | assert(false && "Cannot instantiate VariableArrayType yet"); |
| 289 | return QualType(); |
| 290 | } |
| 291 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 292 | QualType |
| 293 | TemplateTypeInstantiator:: |
| 294 | InstantiateDependentSizedArrayType(const DependentSizedArrayType *T, |
| 295 | unsigned Quals) const { |
Anders Carlsson | 76b1c84 | 2009-03-15 20:12:13 +0000 | [diff] [blame] | 296 | Expr *ArraySize = T->getSizeExpr(); |
| 297 | assert(ArraySize->isValueDependent() && |
| 298 | "dependent sized array types must have value dependent size expr"); |
| 299 | |
| 300 | // Instantiate the element type if needed |
| 301 | QualType ElementType = T->getElementType(); |
| 302 | if (ElementType->isDependentType()) { |
| 303 | ElementType = Instantiate(ElementType); |
| 304 | if (ElementType.isNull()) |
| 305 | return QualType(); |
| 306 | } |
| 307 | |
| 308 | // Instantiate the size expression |
| 309 | Sema::OwningExprResult InstantiatedArraySize = |
| 310 | SemaRef.InstantiateExpr(ArraySize, TemplateArgs, NumTemplateArgs); |
| 311 | if (InstantiatedArraySize.isInvalid()) |
| 312 | return QualType(); |
| 313 | |
| 314 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 315 | (Expr *)InstantiatedArraySize.release(), |
| 316 | T->getIndexTypeQualifier(), Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 319 | QualType |
| 320 | TemplateTypeInstantiator::InstantiateVectorType(const VectorType *T, |
| 321 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 322 | // FIXME: Implement this |
| 323 | assert(false && "Cannot instantiate VectorType yet"); |
| 324 | return QualType(); |
| 325 | } |
| 326 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 327 | QualType |
| 328 | TemplateTypeInstantiator::InstantiateExtVectorType(const ExtVectorType *T, |
| 329 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 330 | // FIXME: Implement this |
| 331 | assert(false && "Cannot instantiate ExtVectorType yet"); |
| 332 | return QualType(); |
| 333 | } |
| 334 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 335 | QualType |
| 336 | TemplateTypeInstantiator:: |
| 337 | InstantiateFunctionProtoType(const FunctionProtoType *T, |
| 338 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 339 | QualType ResultType = Instantiate(T->getResultType()); |
| 340 | if (ResultType.isNull()) |
| 341 | return ResultType; |
| 342 | |
| 343 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 344 | for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(), |
| 345 | ParamEnd = T->arg_type_end(); |
| 346 | Param != ParamEnd; ++Param) { |
| 347 | QualType P = Instantiate(*Param); |
| 348 | if (P.isNull()) |
| 349 | return P; |
| 350 | |
| 351 | ParamTypes.push_back(P); |
| 352 | } |
| 353 | |
| 354 | return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0], |
| 355 | ParamTypes.size(), |
| 356 | T->isVariadic(), T->getTypeQuals(), |
| 357 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 360 | QualType |
| 361 | TemplateTypeInstantiator:: |
| 362 | InstantiateFunctionNoProtoType(const FunctionNoProtoType *T, |
| 363 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 364 | assert(false && "Functions without prototypes cannot be dependent."); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 365 | return QualType(); |
| 366 | } |
| 367 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 368 | QualType |
| 369 | TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T, |
| 370 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 371 | // FIXME: Implement this |
| 372 | assert(false && "Cannot instantiate TypedefType yet"); |
| 373 | return QualType(); |
| 374 | } |
| 375 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 376 | QualType |
| 377 | TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T, |
| 378 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 379 | // FIXME: Implement this |
| 380 | assert(false && "Cannot instantiate TypeOfExprType yet"); |
| 381 | return QualType(); |
| 382 | } |
| 383 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 384 | QualType |
| 385 | TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T, |
| 386 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 387 | // FIXME: Implement this |
| 388 | assert(false && "Cannot instantiate TypeOfType yet"); |
| 389 | return QualType(); |
| 390 | } |
| 391 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 392 | QualType |
| 393 | TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T, |
| 394 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 395 | // FIXME: Implement this |
| 396 | assert(false && "Cannot instantiate RecordType yet"); |
| 397 | return QualType(); |
| 398 | } |
| 399 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 400 | QualType |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 401 | TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T, |
| 402 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 403 | // FIXME: Implement this |
| 404 | assert(false && "Cannot instantiate EnumType yet"); |
| 405 | return QualType(); |
| 406 | } |
| 407 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 408 | QualType |
| 409 | TemplateTypeInstantiator:: |
| 410 | InstantiateTemplateTypeParmType(const TemplateTypeParmType *T, |
| 411 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 412 | if (T->getDepth() == 0) { |
| 413 | // Replace the template type parameter with its corresponding |
| 414 | // template argument. |
| 415 | assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args"); |
| 416 | assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type && |
| 417 | "Template argument kind mismatch"); |
| 418 | QualType Result = TemplateArgs[T->getIndex()].getAsType(); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 419 | if (Result.isNull() || !Quals) |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 420 | return Result; |
| 421 | |
| 422 | // C++ [dcl.ref]p1: |
| 423 | // [...] Cv-qualified references are ill-formed except when |
| 424 | // the cv-qualifiers are introduced through the use of a |
| 425 | // typedef (7.1.3) or of a template type argument (14.3), in |
| 426 | // which case the cv-qualifiers are ignored. |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 427 | if (Quals && Result->isReferenceType()) |
| 428 | Quals = 0; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 430 | return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers()); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // The template type parameter comes from an inner template (e.g., |
| 434 | // the template parameter list of a member template inside the |
| 435 | // template we are instantiating). Create a new template type |
| 436 | // parameter with the template "level" reduced by one. |
| 437 | return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1, |
| 438 | T->getIndex(), |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 439 | T->getName()) |
| 440 | .getQualifiedType(Quals); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 443 | QualType |
| 444 | TemplateTypeInstantiator:: |
| 445 | InstantiateClassTemplateSpecializationType( |
| 446 | const ClassTemplateSpecializationType *T, |
| 447 | unsigned Quals) const { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 448 | llvm::SmallVector<TemplateArgument, 16> InstantiatedTemplateArgs; |
| 449 | InstantiatedTemplateArgs.reserve(T->getNumArgs()); |
| 450 | for (ClassTemplateSpecializationType::iterator Arg = T->begin(), |
| 451 | ArgEnd = T->end(); |
| 452 | Arg != ArgEnd; ++Arg) { |
| 453 | switch (Arg->getKind()) { |
| 454 | case TemplateArgument::Type: { |
| 455 | QualType T = SemaRef.InstantiateType(Arg->getAsType(), |
| 456 | TemplateArgs, NumTemplateArgs, |
| 457 | Arg->getLocation(), |
| 458 | DeclarationName()); |
| 459 | if (T.isNull()) |
| 460 | return QualType(); |
| 461 | |
| 462 | InstantiatedTemplateArgs.push_back( |
| 463 | TemplateArgument(Arg->getLocation(), T)); |
| 464 | break; |
| 465 | } |
| 466 | |
| 467 | case TemplateArgument::Declaration: |
| 468 | case TemplateArgument::Integral: |
| 469 | InstantiatedTemplateArgs.push_back(*Arg); |
| 470 | break; |
| 471 | |
| 472 | case TemplateArgument::Expression: |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 473 | Sema::OwningExprResult E |
| 474 | = SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs, |
| 475 | NumTemplateArgs); |
| 476 | if (E.isInvalid()) |
| 477 | return QualType(); |
| 478 | InstantiatedTemplateArgs.push_back((Expr *)E.release()); |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 479 | break; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | // FIXME: We're missing the locations of the template name, '<', and |
| 484 | // '>'. |
| 485 | return SemaRef.CheckClassTemplateId(cast<ClassTemplateDecl>(T->getTemplate()), |
| 486 | Loc, |
| 487 | SourceLocation(), |
| 488 | &InstantiatedTemplateArgs[0], |
| 489 | InstantiatedTemplateArgs.size(), |
| 490 | SourceLocation()); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 493 | QualType |
| 494 | TemplateTypeInstantiator:: |
| 495 | InstantiateObjCInterfaceType(const ObjCInterfaceType *T, |
| 496 | unsigned Quals) const { |
| 497 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 498 | return QualType(); |
| 499 | } |
| 500 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 501 | QualType |
| 502 | TemplateTypeInstantiator:: |
| 503 | InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T, |
| 504 | unsigned Quals) const { |
| 505 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 506 | return QualType(); |
| 507 | } |
| 508 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 509 | QualType |
| 510 | TemplateTypeInstantiator:: |
| 511 | InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T, |
| 512 | unsigned Quals) const { |
| 513 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 514 | return QualType(); |
| 515 | } |
| 516 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 517 | QualType |
| 518 | TemplateTypeInstantiator:: |
| 519 | InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T, |
| 520 | unsigned Quals) const { |
| 521 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 522 | return QualType(); |
| 523 | } |
| 524 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 525 | /// \brief The actual implementation of Sema::InstantiateType(). |
| 526 | QualType TemplateTypeInstantiator::Instantiate(QualType T) const { |
| 527 | // If T is not a dependent type, there is nothing to do. |
| 528 | if (!T->isDependentType()) |
| 529 | return T; |
| 530 | |
| 531 | switch (T->getTypeClass()) { |
| 532 | #define TYPE(Class, Base) \ |
| 533 | case Type::Class: \ |
| 534 | return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \ |
| 535 | T.getCVRQualifiers()); |
| 536 | #define ABSTRACT_TYPE(Class, Base) |
| 537 | #include "clang/AST/TypeNodes.def" |
| 538 | } |
| 539 | |
| 540 | assert(false && "Not all types have been decoded for instantiation"); |
| 541 | return QualType(); |
| 542 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 543 | |
| 544 | /// \brief Instantiate the type T with a given set of template arguments. |
| 545 | /// |
| 546 | /// This routine substitutes the given template arguments into the |
| 547 | /// type T and produces the instantiated type. |
| 548 | /// |
| 549 | /// \param T the type into which the template arguments will be |
| 550 | /// substituted. If this type is not dependent, it will be returned |
| 551 | /// immediately. |
| 552 | /// |
| 553 | /// \param TemplateArgs the template arguments that will be |
| 554 | /// substituted for the top-level template parameters within T. |
| 555 | /// |
| 556 | /// \param NumTemplateArgs the number of template arguments provided |
| 557 | /// by TemplateArgs. |
| 558 | /// |
| 559 | /// \param Loc the location in the source code where this substitution |
| 560 | /// is being performed. It will typically be the location of the |
| 561 | /// declarator (if we're instantiating the type of some declaration) |
| 562 | /// or the location of the type in the source code (if, e.g., we're |
| 563 | /// instantiating the type of a cast expression). |
| 564 | /// |
| 565 | /// \param Entity the name of the entity associated with a declaration |
| 566 | /// being instantiated (if any). May be empty to indicate that there |
| 567 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 568 | /// a cast expression) or that the entity has no name (e.g., an |
| 569 | /// unnamed function parameter). |
| 570 | /// |
| 571 | /// \returns If the instantiation succeeds, the instantiated |
| 572 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
| 573 | QualType Sema::InstantiateType(QualType T, |
| 574 | const TemplateArgument *TemplateArgs, |
| 575 | unsigned NumTemplateArgs, |
| 576 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | df667e7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 577 | assert(!ActiveTemplateInstantiations.empty() && |
| 578 | "Cannot perform an instantiation without some context on the " |
| 579 | "instantiation stack"); |
| 580 | |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 581 | // If T is not a dependent type, there is nothing to do. |
| 582 | if (!T->isDependentType()) |
| 583 | return T; |
| 584 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 585 | TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs, |
| 586 | Loc, Entity); |
| 587 | return Instantiator(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 588 | } |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 589 | |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 590 | //===----------------------------------------------------------------------===/ |
| 591 | // Template Instantiation for Expressions |
| 592 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 593 | namespace { |
| 594 | class VISIBILITY_HIDDEN TemplateExprInstantiator |
| 595 | : public StmtVisitor<TemplateExprInstantiator, Sema::OwningExprResult> { |
| 596 | Sema &SemaRef; |
| 597 | const TemplateArgument *TemplateArgs; |
| 598 | unsigned NumTemplateArgs; |
| 599 | |
| 600 | public: |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 601 | typedef Sema::OwningExprResult OwningExprResult; |
| 602 | |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 603 | TemplateExprInstantiator(Sema &SemaRef, |
| 604 | const TemplateArgument *TemplateArgs, |
| 605 | unsigned NumTemplateArgs) |
| 606 | : SemaRef(SemaRef), TemplateArgs(TemplateArgs), |
| 607 | NumTemplateArgs(NumTemplateArgs) { } |
| 608 | |
| 609 | // FIXME: Once we get closer to completion, replace these |
| 610 | // manually-written declarations with automatically-generated ones |
| 611 | // from clang/AST/StmtNodes.def. |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 612 | OwningExprResult VisitIntegerLiteral(IntegerLiteral *E); |
| 613 | OwningExprResult VisitDeclRefExpr(DeclRefExpr *E); |
| 614 | OwningExprResult VisitParenExpr(ParenExpr *E); |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 615 | OwningExprResult VisitUnaryOperator(UnaryOperator *E); |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 616 | OwningExprResult VisitBinaryOperator(BinaryOperator *E); |
| 617 | OwningExprResult VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E); |
| 618 | OwningExprResult VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E); |
| 619 | OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 620 | |
| 621 | // Base case. I'm supposed to ignore this. |
Anders Carlsson | a135fb4 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 622 | Sema::OwningExprResult VisitStmt(Stmt *S) { |
| 623 | S->dump(); |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 624 | assert(false && "Cannot instantiate this kind of expression"); |
| 625 | return SemaRef.ExprError(); |
| 626 | } |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 627 | }; |
| 628 | } |
| 629 | |
| 630 | Sema::OwningExprResult |
| 631 | TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) { |
Anders Carlsson | a135fb4 | 2009-03-15 18:34:13 +0000 | [diff] [blame] | 632 | return SemaRef.Clone(E); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | Sema::OwningExprResult |
| 636 | TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) { |
| 637 | Decl *D = E->getDecl(); |
| 638 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { |
| 639 | assert(NTTP->getDepth() == 0 && "No nested templates yet"); |
Douglas Gregor | c971f86 | 2009-03-12 22:20:26 +0000 | [diff] [blame] | 640 | const TemplateArgument &Arg = TemplateArgs[NTTP->getPosition()]; |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 641 | return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral( |
Douglas Gregor | c971f86 | 2009-03-12 22:20:26 +0000 | [diff] [blame] | 642 | *Arg.getAsIntegral(), |
| 643 | Arg.getIntegralType(), |
| 644 | E->getSourceRange().getBegin())); |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 645 | } else |
| 646 | assert(false && "Can't handle arbitrary declaration references"); |
| 647 | |
| 648 | return SemaRef.ExprError(); |
| 649 | } |
| 650 | |
| 651 | Sema::OwningExprResult |
| 652 | TemplateExprInstantiator::VisitParenExpr(ParenExpr *E) { |
| 653 | Sema::OwningExprResult SubExpr |
| 654 | = SemaRef.InstantiateExpr(E->getSubExpr(), TemplateArgs, NumTemplateArgs); |
| 655 | if (SubExpr.isInvalid()) |
| 656 | return SemaRef.ExprError(); |
| 657 | |
| 658 | return SemaRef.Owned(new (SemaRef.Context) ParenExpr( |
| 659 | E->getLParen(), E->getRParen(), |
| 660 | (Expr *)SubExpr.release())); |
| 661 | } |
| 662 | |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 663 | Sema::OwningExprResult |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 664 | TemplateExprInstantiator::VisitUnaryOperator(UnaryOperator *E) { |
| 665 | Sema::OwningExprResult Arg = Visit(E->getSubExpr()); |
| 666 | if (Arg.isInvalid()) |
| 667 | return SemaRef.ExprError(); |
| 668 | |
| 669 | return SemaRef.CreateBuiltinUnaryOp(E->getOperatorLoc(), |
| 670 | E->getOpcode(), |
| 671 | move(Arg)); |
| 672 | } |
| 673 | |
| 674 | Sema::OwningExprResult |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 675 | TemplateExprInstantiator::VisitBinaryOperator(BinaryOperator *E) { |
| 676 | Sema::OwningExprResult LHS = Visit(E->getLHS()); |
| 677 | if (LHS.isInvalid()) |
| 678 | return SemaRef.ExprError(); |
| 679 | |
| 680 | Sema::OwningExprResult RHS = Visit(E->getRHS()); |
| 681 | if (RHS.isInvalid()) |
| 682 | return SemaRef.ExprError(); |
| 683 | |
| 684 | Sema::OwningExprResult Result |
| 685 | = SemaRef.CreateBuiltinBinOp(E->getOperatorLoc(), |
| 686 | E->getOpcode(), |
| 687 | (Expr *)LHS.get(), |
| 688 | (Expr *)RHS.get()); |
| 689 | if (Result.isInvalid()) |
| 690 | return SemaRef.ExprError(); |
| 691 | |
| 692 | LHS.release(); |
| 693 | RHS.release(); |
| 694 | return move(Result); |
| 695 | } |
| 696 | |
| 697 | Sema::OwningExprResult |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 698 | TemplateExprInstantiator::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 699 | Sema::OwningExprResult First = Visit(E->getArg(0)); |
| 700 | if (First.isInvalid()) |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 701 | return SemaRef.ExprError(); |
| 702 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 703 | Expr *Args[2] = { (Expr *)First.get(), 0 }; |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 704 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 705 | Sema::OwningExprResult Second(SemaRef); |
| 706 | if (E->getNumArgs() == 2) { |
| 707 | Second = Visit(E->getArg(1)); |
| 708 | |
| 709 | if (Second.isInvalid()) |
| 710 | return SemaRef.ExprError(); |
| 711 | |
| 712 | Args[1] = (Expr *)Second.get(); |
| 713 | } |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 714 | |
| 715 | if (!E->isTypeDependent()) { |
| 716 | // Since our original expression was not type-dependent, we do not |
| 717 | // perform lookup again at instantiation time (C++ [temp.dep]p1). |
| 718 | // Instead, we just build the new overloaded operator call |
| 719 | // expression. |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 720 | First.release(); |
| 721 | Second.release(); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 722 | return SemaRef.Owned(new (SemaRef.Context) CXXOperatorCallExpr( |
| 723 | SemaRef.Context, |
| 724 | E->getOperator(), |
| 725 | E->getCallee(), |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 726 | Args, E->getNumArgs(), |
| 727 | E->getType(), |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 728 | E->getOperatorLoc())); |
| 729 | } |
| 730 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 731 | bool isPostIncDec = E->getNumArgs() == 2 && |
| 732 | (E->getOperator() == OO_PlusPlus || E->getOperator() == OO_MinusMinus); |
| 733 | if (E->getNumArgs() == 1 || isPostIncDec) { |
| 734 | if (!Args[0]->getType()->isOverloadableType()) { |
| 735 | // The argument is not of overloadable type, so try to create a |
| 736 | // built-in unary operation. |
| 737 | UnaryOperator::Opcode Opc |
| 738 | = UnaryOperator::getOverloadedOpcode(E->getOperator(), isPostIncDec); |
| 739 | |
| 740 | return SemaRef.CreateBuiltinUnaryOp(E->getOperatorLoc(), Opc, |
| 741 | move(First)); |
| 742 | } |
| 743 | |
| 744 | // Fall through to perform overload resolution |
| 745 | } else { |
| 746 | assert(E->getNumArgs() == 2 && "Expected binary operation"); |
| 747 | |
| 748 | Sema::OwningExprResult Result(SemaRef); |
| 749 | if (!Args[0]->getType()->isOverloadableType() && |
| 750 | !Args[1]->getType()->isOverloadableType()) { |
| 751 | // Neither of the arguments is an overloadable type, so try to |
| 752 | // create a built-in binary operation. |
| 753 | BinaryOperator::Opcode Opc = |
| 754 | BinaryOperator::getOverloadedOpcode(E->getOperator()); |
| 755 | Result = SemaRef.CreateBuiltinBinOp(E->getOperatorLoc(), Opc, |
| 756 | Args[0], Args[1]); |
| 757 | if (Result.isInvalid()) |
| 758 | return SemaRef.ExprError(); |
| 759 | |
| 760 | First.release(); |
| 761 | Second.release(); |
| 762 | return move(Result); |
| 763 | } |
| 764 | |
| 765 | // Fall through to perform overload resolution. |
| 766 | } |
| 767 | |
| 768 | // Compute the set of functions that were found at template |
| 769 | // definition time. |
| 770 | Sema::FunctionSet Functions; |
| 771 | DeclRefExpr *DRE = cast<DeclRefExpr>(E->getCallee()); |
| 772 | OverloadedFunctionDecl *Overloads |
| 773 | = cast<OverloadedFunctionDecl>(DRE->getDecl()); |
| 774 | |
| 775 | // FIXME: Do we have to check |
| 776 | // IsAcceptableNonMemberOperatorCandidate for each of these? |
| 777 | for (OverloadedFunctionDecl::function_iterator |
| 778 | F = Overloads->function_begin(), |
| 779 | FEnd = Overloads->function_end(); |
| 780 | F != FEnd; ++F) |
| 781 | Functions.insert(*F); |
| 782 | |
| 783 | // Add any functions found via argument-dependent lookup. |
| 784 | DeclarationName OpName |
| 785 | = SemaRef.Context.DeclarationNames.getCXXOperatorName(E->getOperator()); |
| 786 | SemaRef.ArgumentDependentLookup(OpName, Args, E->getNumArgs(), Functions); |
| 787 | |
| 788 | // Create the overloaded operator invocation. |
| 789 | if (E->getNumArgs() == 1 || isPostIncDec) { |
| 790 | UnaryOperator::Opcode Opc |
| 791 | = UnaryOperator::getOverloadedOpcode(E->getOperator(), isPostIncDec); |
| 792 | return SemaRef.CreateOverloadedUnaryOp(E->getOperatorLoc(), Opc, |
| 793 | Functions, move(First)); |
| 794 | } |
| 795 | |
| 796 | // FIXME: This would be far less ugly if CreateOverloadedBinOp took |
| 797 | // in ExprArg arguments! |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 798 | BinaryOperator::Opcode Opc = |
| 799 | BinaryOperator::getOverloadedOpcode(E->getOperator()); |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 800 | OwningExprResult Result |
| 801 | = SemaRef.CreateOverloadedBinOp(E->getOperatorLoc(), Opc, |
| 802 | Functions, Args[0], Args[1]); |
Douglas Gregor | 063daf6 | 2009-03-13 18:40:31 +0000 | [diff] [blame] | 803 | |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 804 | if (Result.isInvalid()) |
| 805 | return SemaRef.ExprError(); |
| 806 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 807 | First.release(); |
| 808 | Second.release(); |
Douglas Gregor | 3fd95ce | 2009-03-13 00:33:25 +0000 | [diff] [blame] | 809 | return move(Result); |
| 810 | } |
| 811 | |
| 812 | Sema::OwningExprResult |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 813 | TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { |
| 814 | bool isSizeOf = E->isSizeOf(); |
| 815 | |
| 816 | if (E->isArgumentType()) { |
| 817 | QualType T = E->getArgumentType(); |
| 818 | if (T->isDependentType()) { |
| 819 | T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs, |
| 820 | /*FIXME*/E->getOperatorLoc(), |
| 821 | &SemaRef.PP.getIdentifierTable().get("sizeof")); |
| 822 | if (T.isNull()) |
| 823 | return SemaRef.ExprError(); |
| 824 | } |
| 825 | |
| 826 | return SemaRef.CreateSizeOfAlignOfExpr(T, E->getOperatorLoc(), isSizeOf, |
| 827 | E->getSourceRange()); |
| 828 | } |
| 829 | |
| 830 | Sema::OwningExprResult Arg = Visit(E->getArgumentExpr()); |
| 831 | if (Arg.isInvalid()) |
| 832 | return SemaRef.ExprError(); |
| 833 | |
| 834 | Sema::OwningExprResult Result |
| 835 | = SemaRef.CreateSizeOfAlignOfExpr((Expr *)Arg.get(), E->getOperatorLoc(), |
| 836 | isSizeOf, E->getSourceRange()); |
| 837 | if (Result.isInvalid()) |
| 838 | return SemaRef.ExprError(); |
| 839 | |
| 840 | Arg.release(); |
| 841 | return move(Result); |
| 842 | } |
| 843 | |
| 844 | Sema::OwningExprResult |
| 845 | TemplateExprInstantiator::VisitCXXTemporaryObjectExpr( |
| 846 | CXXTemporaryObjectExpr *E) { |
| 847 | QualType T = E->getType(); |
| 848 | if (T->isDependentType()) { |
| 849 | T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs, |
| 850 | E->getTypeBeginLoc(), DeclarationName()); |
| 851 | if (T.isNull()) |
| 852 | return SemaRef.ExprError(); |
| 853 | } |
| 854 | |
| 855 | llvm::SmallVector<Expr *, 16> Args; |
| 856 | Args.reserve(E->getNumArgs()); |
| 857 | bool Invalid = false; |
| 858 | for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(), |
| 859 | ArgEnd = E->arg_end(); |
| 860 | Arg != ArgEnd; ++Arg) { |
| 861 | OwningExprResult InstantiatedArg = Visit(*Arg); |
| 862 | if (InstantiatedArg.isInvalid()) { |
| 863 | Invalid = true; |
| 864 | break; |
| 865 | } |
| 866 | |
| 867 | Args.push_back((Expr *)InstantiatedArg.release()); |
| 868 | } |
| 869 | |
| 870 | if (!Invalid) { |
| 871 | SourceLocation CommaLoc; |
| 872 | // FIXME: HACK! |
| 873 | if (Args.size() > 1) |
| 874 | CommaLoc |
| 875 | = SemaRef.PP.getLocForEndOfToken(Args[0]->getSourceRange().getEnd()); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 876 | Sema::OwningExprResult Result( |
| 877 | SemaRef.ActOnCXXTypeConstructExpr(SourceRange(E->getTypeBeginLoc() |
| 878 | /*, FIXME*/), |
| 879 | T.getAsOpaquePtr(), |
| 880 | /*FIXME*/E->getTypeBeginLoc(), |
| 881 | Sema::MultiExprArg(SemaRef, |
| 882 | (void**)&Args[0], |
| 883 | Args.size()), |
| 884 | /*HACK*/&CommaLoc, |
| 885 | E->getSourceRange().getEnd())); |
| 886 | // At this point, Args no longer owns the arguments, no matter what. |
| 887 | return move(Result); |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | // Clean up the instantiated arguments. |
| 891 | // FIXME: Would rather do this with RAII. |
| 892 | for (unsigned Idx = 0; Idx < Args.size(); ++Idx) |
| 893 | SemaRef.DeleteExpr(Args[Idx]); |
| 894 | |
| 895 | return SemaRef.ExprError(); |
| 896 | } |
| 897 | |
| 898 | Sema::OwningExprResult |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 899 | Sema::InstantiateExpr(Expr *E, const TemplateArgument *TemplateArgs, |
| 900 | unsigned NumTemplateArgs) { |
Douglas Gregor | 313a81d | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 901 | TemplateExprInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs); |
| 902 | return Instantiator.Visit(E); |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 905 | /// \brief Instantiate the base class specifiers of the given class |
| 906 | /// template specialization. |
| 907 | /// |
| 908 | /// Produces a diagnostic and returns true on error, returns false and |
| 909 | /// attaches the instantiated base classes to the class template |
| 910 | /// specialization if successful. |
| 911 | bool |
| 912 | Sema::InstantiateBaseSpecifiers( |
| 913 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 914 | ClassTemplateDecl *ClassTemplate) { |
| 915 | bool Invalid = false; |
| 916 | llvm::SmallVector<CXXBaseSpecifier*, 8> InstantiatedBases; |
| 917 | for (ClassTemplateSpecializationDecl::base_class_iterator |
| 918 | Base = ClassTemplate->getTemplatedDecl()->bases_begin(), |
| 919 | BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end(); |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 920 | Base != BaseEnd; ++Base) { |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 921 | if (!Base->getType()->isDependentType()) { |
| 922 | // FIXME: Allocate via ASTContext |
| 923 | InstantiatedBases.push_back(new CXXBaseSpecifier(*Base)); |
| 924 | continue; |
| 925 | } |
| 926 | |
| 927 | QualType BaseType = InstantiateType(Base->getType(), |
| 928 | ClassTemplateSpec->getTemplateArgs(), |
| 929 | ClassTemplateSpec->getNumTemplateArgs(), |
| 930 | Base->getSourceRange().getBegin(), |
| 931 | DeclarationName()); |
| 932 | if (BaseType.isNull()) { |
| 933 | Invalid = true; |
| 934 | continue; |
| 935 | } |
| 936 | |
| 937 | if (CXXBaseSpecifier *InstantiatedBase |
| 938 | = CheckBaseSpecifier(ClassTemplateSpec, |
| 939 | Base->getSourceRange(), |
| 940 | Base->isVirtual(), |
| 941 | Base->getAccessSpecifierAsWritten(), |
| 942 | BaseType, |
| 943 | /*FIXME: Not totally accurate */ |
| 944 | Base->getSourceRange().getBegin())) |
| 945 | InstantiatedBases.push_back(InstantiatedBase); |
| 946 | else |
| 947 | Invalid = true; |
| 948 | } |
| 949 | |
Douglas Gregor | 27b152f | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 950 | if (!Invalid && |
| 951 | AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0], |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 952 | InstantiatedBases.size())) |
| 953 | Invalid = true; |
| 954 | |
| 955 | return Invalid; |
| 956 | } |
| 957 | |
| 958 | bool |
| 959 | Sema::InstantiateClassTemplateSpecialization( |
| 960 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 961 | bool ExplicitInstantiation) { |
| 962 | // Perform the actual instantiation on the canonical declaration. |
| 963 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
| 964 | Context.getCanonicalDecl(ClassTemplateSpec)); |
| 965 | |
| 966 | // We can only instantiate something that hasn't already been |
| 967 | // instantiated or specialized. Fail without any diagnostics: our |
| 968 | // caller will provide an error message. |
| 969 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) |
| 970 | return true; |
| 971 | |
| 972 | // FIXME: Push this class template instantiation onto the |
| 973 | // instantiation stack, checking for recursion that exceeds a |
| 974 | // certain depth. |
| 975 | |
| 976 | // FIXME: Perform class template partial specialization to select |
| 977 | // the best template. |
| 978 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
| 979 | |
| 980 | if (!Template->getTemplatedDecl()->getDefinition(Context)) { |
| 981 | Diag(ClassTemplateSpec->getLocation(), |
| 982 | diag::err_template_implicit_instantiate_undefined) |
| 983 | << Context.getTypeDeclType(ClassTemplateSpec); |
| 984 | Diag(Template->getTemplatedDecl()->getLocation(), |
| 985 | diag::note_template_decl_here); |
| 986 | return true; |
| 987 | } |
| 988 | |
| 989 | // Note that this is an instantiation. |
| 990 | ClassTemplateSpec->setSpecializationKind( |
| 991 | ExplicitInstantiation? TSK_ExplicitInstantiation |
| 992 | : TSK_ImplicitInstantiation); |
| 993 | |
| 994 | |
| 995 | bool Invalid = false; |
| 996 | |
Douglas Gregor | 26dce44 | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 997 | InstantiatingTemplate Inst(*this, ClassTemplateSpec->getLocation(), |
| 998 | ClassTemplateSpec); |
| 999 | if (Inst) |
| 1000 | return true; |
| 1001 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1002 | // Enter the scope of this instantiation. We don't use |
| 1003 | // PushDeclContext because we don't have a scope. |
| 1004 | DeclContext *PreviousContext = CurContext; |
| 1005 | CurContext = ClassTemplateSpec; |
| 1006 | |
| 1007 | // Start the definition of this instantiation. |
| 1008 | ClassTemplateSpec->startDefinition(); |
| 1009 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1010 | |
| 1011 | // Instantiate the base class specifiers. |
| 1012 | if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template)) |
| 1013 | Invalid = true; |
| 1014 | |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 1015 | // FIXME: Create the injected-class-name for the |
| 1016 | // instantiation. Should this be a typedef or something like it? |
| 1017 | |
| 1018 | RecordDecl *Pattern = Template->getTemplatedDecl(); |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1019 | llvm::SmallVector<DeclTy *, 32> Fields; |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 1020 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
| 1021 | MemberEnd = Pattern->decls_end(); |
| 1022 | Member != MemberEnd; ++Member) { |
| 1023 | if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(*Member)) { |
| 1024 | // FIXME: Simplified instantiation of typedefs needs to be made |
| 1025 | // "real". |
| 1026 | QualType T = Typedef->getUnderlyingType(); |
| 1027 | if (T->isDependentType()) { |
| 1028 | T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(), |
| 1029 | ClassTemplateSpec->getNumTemplateArgs(), |
| 1030 | Typedef->getLocation(), |
| 1031 | Typedef->getDeclName()); |
| 1032 | if (T.isNull()) { |
| 1033 | Invalid = true; |
| 1034 | T = Context.IntTy; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | // Create the new typedef |
| 1039 | TypedefDecl *New |
| 1040 | = TypedefDecl::Create(Context, ClassTemplateSpec, |
| 1041 | Typedef->getLocation(), |
| 1042 | Typedef->getIdentifier(), |
| 1043 | T); |
| 1044 | ClassTemplateSpec->addDecl(New); |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1045 | } |
| 1046 | else if (FieldDecl *Field = dyn_cast<FieldDecl>(*Member)) { |
| 1047 | // FIXME: Simplified instantiation of fields needs to be made |
| 1048 | // "real". |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1049 | bool InvalidDecl = false; |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1050 | QualType T = Field->getType(); |
| 1051 | if (T->isDependentType()) { |
| 1052 | T = InstantiateType(T, ClassTemplateSpec->getTemplateArgs(), |
| 1053 | ClassTemplateSpec->getNumTemplateArgs(), |
| 1054 | Field->getLocation(), |
| 1055 | Field->getDeclName()); |
| 1056 | if (!T.isNull() && T->isFunctionType()) { |
| 1057 | // C++ [temp.arg.type]p3: |
| 1058 | // If a declaration acquires a function type through a type |
| 1059 | // dependent on a template-parameter and this causes a |
| 1060 | // declaration that does not use the syntactic form of a |
| 1061 | // function declarator to have function type, the program is |
| 1062 | // ill-formed. |
| 1063 | Diag(Field->getLocation(), diag::err_field_instantiates_to_function) |
| 1064 | << T; |
| 1065 | T = QualType(); |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1066 | InvalidDecl = true; |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1070 | Expr *BitWidth = Field->getBitWidth(); |
| 1071 | if (InvalidDecl) |
| 1072 | BitWidth = 0; |
Douglas Gregor | 3e287c2 | 2009-03-15 17:43:26 +0000 | [diff] [blame] | 1073 | else if (BitWidth) { |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1074 | OwningExprResult InstantiatedBitWidth |
| 1075 | = InstantiateExpr(BitWidth, |
| 1076 | ClassTemplateSpec->getTemplateArgs(), |
| 1077 | ClassTemplateSpec->getNumTemplateArgs()); |
| 1078 | if (InstantiatedBitWidth.isInvalid()) { |
| 1079 | Invalid = InvalidDecl = true; |
| 1080 | BitWidth = 0; |
| 1081 | } else |
| 1082 | BitWidth = (Expr *)InstantiatedBitWidth.release(); |
| 1083 | } |
| 1084 | |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1085 | FieldDecl *New = CheckFieldDecl(Field->getDeclName(), T, |
| 1086 | ClassTemplateSpec, |
| 1087 | Field->getLocation(), |
| 1088 | Field->isMutable(), |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1089 | BitWidth, |
Douglas Gregor | 4dd55f5 | 2009-03-11 20:50:30 +0000 | [diff] [blame] | 1090 | Field->getAccess(), |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1091 | 0); |
| 1092 | if (New) { |
| 1093 | ClassTemplateSpec->addDecl(New); |
| 1094 | Fields.push_back(New); |
| 1095 | |
Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1096 | if (InvalidDecl) |
| 1097 | New->setInvalidDecl(); |
| 1098 | |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1099 | if (New->isInvalidDecl()) |
| 1100 | Invalid = true; |
| 1101 | } |
Anders Carlsson | 94b15fb | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 1102 | } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(*Member)) { |
| 1103 | Expr *AssertExpr = SA->getAssertExpr(); |
| 1104 | |
| 1105 | OwningExprResult InstantiatedAssertExpr |
| 1106 | = InstantiateExpr(AssertExpr, |
| 1107 | ClassTemplateSpec->getTemplateArgs(), |
| 1108 | ClassTemplateSpec->getNumTemplateArgs()); |
| 1109 | if (!InstantiatedAssertExpr.isInvalid()) { |
| 1110 | OwningExprResult Message = Clone(SA->getMessage()); |
| 1111 | |
| 1112 | Decl *New = |
| 1113 | (Decl *)ActOnStaticAssertDeclaration(SA->getLocation(), |
| 1114 | move(InstantiatedAssertExpr), |
| 1115 | move(Message)); |
| 1116 | if (New->isInvalidDecl()) |
| 1117 | Invalid = true; |
| 1118 | |
| 1119 | } else |
| 1120 | Invalid = true; |
Douglas Gregor | 4fdf1fa | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 1124 | // Finish checking fields. |
| 1125 | ActOnFields(0, ClassTemplateSpec->getLocation(), ClassTemplateSpec, |
| 1126 | &Fields[0], Fields.size(), SourceLocation(), SourceLocation(), |
| 1127 | 0); |
| 1128 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1129 | // Add any implicitly-declared members that we might need. |
| 1130 | AddImplicitlyDeclaredMembersToClass(ClassTemplateSpec); |
| 1131 | |
Douglas Gregor | 2943aed | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 1132 | // Exit the scope of this instantiation. |
| 1133 | CurContext = PreviousContext; |
| 1134 | |
| 1135 | return Invalid; |
| 1136 | } |