Douglas Gregor | 7429654 | 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" |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/Parse/DeclSpec.h" |
| 18 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace clang; |
| 22 | |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===/ |
| 24 | // Template Instantiation Support |
| 25 | //===----------------------------------------------------------------------===/ |
| 26 | |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 27 | Sema::InstantiatingTemplate:: |
| 28 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 29 | ClassTemplateSpecializationDecl *Entity, |
| 30 | SourceRange InstantiationRange) |
| 31 | : SemaRef(SemaRef) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 32 | |
| 33 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 34 | InstantiationRange); |
| 35 | if (!Invalid) { |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 36 | ActiveTemplateInstantiation Inst; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 37 | Inst.Kind = ActiveTemplateInstantiation::TemplateInstantiation; |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 38 | Inst.PointOfInstantiation = PointOfInstantiation; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 39 | Inst.Entity = reinterpret_cast<uintptr_t>(Entity); |
Douglas Gregor | 95ba128 | 2009-03-12 18:36:18 +0000 | [diff] [blame] | 40 | Inst.TemplateArgs = 0; |
| 41 | Inst.NumTemplateArgs = 0; |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 42 | Inst.InstantiationRange = InstantiationRange; |
| 43 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 44 | Invalid = false; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, |
| 49 | SourceLocation PointOfInstantiation, |
| 50 | TemplateDecl *Template, |
| 51 | const TemplateArgument *TemplateArgs, |
| 52 | unsigned NumTemplateArgs, |
| 53 | SourceRange InstantiationRange) |
| 54 | : SemaRef(SemaRef) { |
| 55 | |
| 56 | Invalid = CheckInstantiationDepth(PointOfInstantiation, |
| 57 | InstantiationRange); |
| 58 | if (!Invalid) { |
| 59 | ActiveTemplateInstantiation Inst; |
| 60 | Inst.Kind |
| 61 | = ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation; |
| 62 | Inst.PointOfInstantiation = PointOfInstantiation; |
| 63 | Inst.Entity = reinterpret_cast<uintptr_t>(Template); |
| 64 | Inst.TemplateArgs = TemplateArgs; |
| 65 | Inst.NumTemplateArgs = NumTemplateArgs; |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 66 | Inst.InstantiationRange = InstantiationRange; |
| 67 | SemaRef.ActiveTemplateInstantiations.push_back(Inst); |
| 68 | Invalid = false; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | Sema::InstantiatingTemplate::~InstantiatingTemplate() { |
| 73 | if (!Invalid) |
| 74 | SemaRef.ActiveTemplateInstantiations.pop_back(); |
| 75 | } |
| 76 | |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 77 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( |
| 78 | SourceLocation PointOfInstantiation, |
| 79 | SourceRange InstantiationRange) { |
| 80 | if (SemaRef.ActiveTemplateInstantiations.size() |
| 81 | <= SemaRef.getLangOptions().InstantiationDepth) |
| 82 | return false; |
| 83 | |
| 84 | SemaRef.Diag(PointOfInstantiation, |
| 85 | diag::err_template_recursion_depth_exceeded) |
| 86 | << SemaRef.getLangOptions().InstantiationDepth |
| 87 | << InstantiationRange; |
| 88 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) |
| 89 | << SemaRef.getLangOptions().InstantiationDepth; |
| 90 | return true; |
| 91 | } |
| 92 | |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 93 | /// \brief Prints the current instantiation stack through a series of |
| 94 | /// notes. |
| 95 | void Sema::PrintInstantiationStack() { |
| 96 | for (llvm::SmallVector<ActiveTemplateInstantiation, 16>::reverse_iterator |
| 97 | Active = ActiveTemplateInstantiations.rbegin(), |
| 98 | ActiveEnd = ActiveTemplateInstantiations.rend(); |
| 99 | Active != ActiveEnd; |
| 100 | ++Active) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 101 | switch (Active->Kind) { |
| 102 | case ActiveTemplateInstantiation::TemplateInstantiation: { |
| 103 | ClassTemplateSpecializationDecl *Spec |
| 104 | = cast<ClassTemplateSpecializationDecl>((Decl*)Active->Entity); |
| 105 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 106 | diag::note_template_class_instantiation_here) |
| 107 | << Context.getTypeDeclType(Spec) |
| 108 | << Active->InstantiationRange; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | case ActiveTemplateInstantiation::DefaultTemplateArgumentInstantiation: { |
| 113 | TemplateDecl *Template = cast<TemplateDecl>((Decl *)Active->Entity); |
| 114 | std::string TemplateArgsStr |
| 115 | = ClassTemplateSpecializationType::PrintTemplateArgumentList( |
| 116 | Active->TemplateArgs, |
| 117 | Active->NumTemplateArgs); |
| 118 | Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr), |
| 119 | diag::note_default_arg_instantiation_here) |
| 120 | << (Template->getNameAsString() + TemplateArgsStr) |
| 121 | << Active->InstantiationRange; |
| 122 | break; |
| 123 | } |
| 124 | } |
Douglas Gregor | fee85d6 | 2009-03-10 18:03:33 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 128 | //===----------------------------------------------------------------------===/ |
| 129 | // Template Instantiation for Types |
| 130 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 131 | namespace { |
| 132 | class VISIBILITY_HIDDEN TemplateTypeInstantiator { |
| 133 | Sema &SemaRef; |
| 134 | const TemplateArgument *TemplateArgs; |
| 135 | unsigned NumTemplateArgs; |
| 136 | SourceLocation Loc; |
| 137 | DeclarationName Entity; |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 138 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 139 | public: |
| 140 | TemplateTypeInstantiator(Sema &SemaRef, |
| 141 | const TemplateArgument *TemplateArgs, |
| 142 | unsigned NumTemplateArgs, |
| 143 | SourceLocation Loc, |
| 144 | DeclarationName Entity) |
| 145 | : SemaRef(SemaRef), TemplateArgs(TemplateArgs), |
| 146 | NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { } |
| 147 | |
| 148 | QualType operator()(QualType T) const { return Instantiate(T); } |
| 149 | |
| 150 | QualType Instantiate(QualType T) const; |
| 151 | |
| 152 | // Declare instantiate functions for each type. |
| 153 | #define TYPE(Class, Base) \ |
| 154 | QualType Instantiate##Class##Type(const Class##Type *T, \ |
| 155 | unsigned Quals) const; |
| 156 | #define ABSTRACT_TYPE(Class, Base) |
| 157 | #include "clang/AST/TypeNodes.def" |
| 158 | }; |
| 159 | } |
| 160 | |
| 161 | QualType |
| 162 | TemplateTypeInstantiator::InstantiateExtQualType(const ExtQualType *T, |
| 163 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 164 | // FIXME: Implement this |
| 165 | assert(false && "Cannot instantiate ExtQualType yet"); |
| 166 | return QualType(); |
| 167 | } |
| 168 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 169 | QualType |
| 170 | TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T, |
| 171 | unsigned Quals) const { |
Douglas Gregor | c0139ca | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 172 | assert(false && "Builtin types are not dependent and cannot be instantiated"); |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 173 | return QualType(T, Quals); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 176 | QualType |
| 177 | TemplateTypeInstantiator:: |
| 178 | InstantiateFixedWidthIntType(const FixedWidthIntType *T, unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 179 | // FIXME: Implement this |
| 180 | assert(false && "Cannot instantiate FixedWidthIntType yet"); |
| 181 | return QualType(); |
| 182 | } |
| 183 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 184 | QualType |
| 185 | TemplateTypeInstantiator::InstantiateComplexType(const ComplexType *T, |
| 186 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 187 | // FIXME: Implement this |
| 188 | assert(false && "Cannot instantiate ComplexType yet"); |
| 189 | return QualType(); |
| 190 | } |
| 191 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 192 | QualType |
| 193 | TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T, |
| 194 | unsigned Quals) const { |
| 195 | QualType PointeeType = Instantiate(T->getPointeeType()); |
| 196 | if (PointeeType.isNull()) |
| 197 | return QualType(); |
| 198 | |
| 199 | return SemaRef.BuildPointerType(PointeeType, Quals, Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 202 | QualType |
| 203 | TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T, |
| 204 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 205 | // FIXME: Implement this |
| 206 | assert(false && "Cannot instantiate BlockPointerType yet"); |
| 207 | return QualType(); |
| 208 | } |
| 209 | |
Sebastian Redl | ce6fff0 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 210 | QualType |
| 211 | TemplateTypeInstantiator::InstantiateLValueReferenceType( |
| 212 | const LValueReferenceType *T, unsigned Quals) const { |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 213 | QualType ReferentType = Instantiate(T->getPointeeType()); |
| 214 | if (ReferentType.isNull()) |
| 215 | return QualType(); |
| 216 | |
Sebastian Redl | ce6fff0 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 217 | return SemaRef.BuildReferenceType(ReferentType, true, Quals, Loc, Entity); |
| 218 | } |
| 219 | |
| 220 | QualType |
| 221 | TemplateTypeInstantiator::InstantiateRValueReferenceType( |
| 222 | const RValueReferenceType *T, unsigned Quals) const { |
| 223 | QualType ReferentType = Instantiate(T->getPointeeType()); |
| 224 | if (ReferentType.isNull()) |
| 225 | return QualType(); |
| 226 | |
| 227 | return SemaRef.BuildReferenceType(ReferentType, false, Quals, Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 230 | QualType |
| 231 | TemplateTypeInstantiator:: |
| 232 | InstantiateMemberPointerType(const MemberPointerType *T, |
| 233 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 234 | // FIXME: Implement this |
| 235 | assert(false && "Cannot instantiate MemberPointerType yet"); |
| 236 | return QualType(); |
| 237 | } |
| 238 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 239 | QualType |
| 240 | TemplateTypeInstantiator:: |
| 241 | InstantiateConstantArrayType(const ConstantArrayType *T, |
| 242 | unsigned Quals) const { |
| 243 | QualType ElementType = Instantiate(T->getElementType()); |
| 244 | if (ElementType.isNull()) |
| 245 | return ElementType; |
| 246 | |
| 247 | // Build a temporary integer literal to specify the size for |
| 248 | // BuildArrayType. Since we have already checked the size as part of |
| 249 | // creating the dependent array type in the first place, we know |
| 250 | // there aren't any errors. |
Douglas Gregor | 448fcd3 | 2009-03-09 20:07:22 +0000 | [diff] [blame] | 251 | // FIXME: Is IntTy big enough? Maybe not, but LongLongTy causes |
| 252 | // problems that I have yet to investigate. |
| 253 | IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc); |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 254 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 255 | &ArraySize, T->getIndexTypeQualifier(), |
| 256 | Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 259 | QualType |
| 260 | TemplateTypeInstantiator:: |
| 261 | InstantiateIncompleteArrayType(const IncompleteArrayType *T, |
| 262 | unsigned Quals) const { |
| 263 | QualType ElementType = Instantiate(T->getElementType()); |
| 264 | if (ElementType.isNull()) |
| 265 | return ElementType; |
| 266 | |
| 267 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 268 | 0, T->getIndexTypeQualifier(), |
| 269 | Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 272 | QualType |
| 273 | TemplateTypeInstantiator:: |
| 274 | InstantiateVariableArrayType(const VariableArrayType *T, |
| 275 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 276 | // FIXME: Implement this |
| 277 | assert(false && "Cannot instantiate VariableArrayType yet"); |
| 278 | return QualType(); |
| 279 | } |
| 280 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 281 | QualType |
| 282 | TemplateTypeInstantiator:: |
| 283 | InstantiateDependentSizedArrayType(const DependentSizedArrayType *T, |
| 284 | unsigned Quals) const { |
Anders Carlsson | 149f278 | 2009-03-15 20:12:13 +0000 | [diff] [blame] | 285 | Expr *ArraySize = T->getSizeExpr(); |
| 286 | assert(ArraySize->isValueDependent() && |
| 287 | "dependent sized array types must have value dependent size expr"); |
| 288 | |
| 289 | // Instantiate the element type if needed |
| 290 | QualType ElementType = T->getElementType(); |
| 291 | if (ElementType->isDependentType()) { |
| 292 | ElementType = Instantiate(ElementType); |
| 293 | if (ElementType.isNull()) |
| 294 | return QualType(); |
| 295 | } |
| 296 | |
| 297 | // Instantiate the size expression |
| 298 | Sema::OwningExprResult InstantiatedArraySize = |
| 299 | SemaRef.InstantiateExpr(ArraySize, TemplateArgs, NumTemplateArgs); |
| 300 | if (InstantiatedArraySize.isInvalid()) |
| 301 | return QualType(); |
| 302 | |
| 303 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 304 | (Expr *)InstantiatedArraySize.release(), |
| 305 | T->getIndexTypeQualifier(), Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 308 | QualType |
| 309 | TemplateTypeInstantiator::InstantiateVectorType(const VectorType *T, |
| 310 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 311 | // FIXME: Implement this |
| 312 | assert(false && "Cannot instantiate VectorType yet"); |
| 313 | return QualType(); |
| 314 | } |
| 315 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 316 | QualType |
| 317 | TemplateTypeInstantiator::InstantiateExtVectorType(const ExtVectorType *T, |
| 318 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 319 | // FIXME: Implement this |
| 320 | assert(false && "Cannot instantiate ExtVectorType yet"); |
| 321 | return QualType(); |
| 322 | } |
| 323 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 324 | QualType |
| 325 | TemplateTypeInstantiator:: |
| 326 | InstantiateFunctionProtoType(const FunctionProtoType *T, |
| 327 | unsigned Quals) const { |
Douglas Gregor | c0139ca | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 328 | QualType ResultType = Instantiate(T->getResultType()); |
| 329 | if (ResultType.isNull()) |
| 330 | return ResultType; |
| 331 | |
| 332 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 333 | for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(), |
| 334 | ParamEnd = T->arg_type_end(); |
| 335 | Param != ParamEnd; ++Param) { |
| 336 | QualType P = Instantiate(*Param); |
| 337 | if (P.isNull()) |
| 338 | return P; |
| 339 | |
| 340 | ParamTypes.push_back(P); |
| 341 | } |
| 342 | |
| 343 | return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0], |
| 344 | ParamTypes.size(), |
| 345 | T->isVariadic(), T->getTypeQuals(), |
| 346 | Loc, Entity); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 349 | QualType |
| 350 | TemplateTypeInstantiator:: |
| 351 | InstantiateFunctionNoProtoType(const FunctionNoProtoType *T, |
| 352 | unsigned Quals) const { |
Douglas Gregor | c0139ca | 2009-02-28 01:04:19 +0000 | [diff] [blame] | 353 | assert(false && "Functions without prototypes cannot be dependent."); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 354 | return QualType(); |
| 355 | } |
| 356 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 357 | QualType |
| 358 | TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T, |
| 359 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 360 | // FIXME: Implement this |
| 361 | assert(false && "Cannot instantiate TypedefType yet"); |
| 362 | return QualType(); |
| 363 | } |
| 364 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 365 | QualType |
| 366 | TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T, |
| 367 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 368 | // FIXME: Implement this |
| 369 | assert(false && "Cannot instantiate TypeOfExprType yet"); |
| 370 | return QualType(); |
| 371 | } |
| 372 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 373 | QualType |
| 374 | TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T, |
| 375 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 376 | // FIXME: Implement this |
| 377 | assert(false && "Cannot instantiate TypeOfType yet"); |
| 378 | return QualType(); |
| 379 | } |
| 380 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 381 | QualType |
| 382 | TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T, |
| 383 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 384 | // FIXME: Implement this |
| 385 | assert(false && "Cannot instantiate RecordType yet"); |
| 386 | return QualType(); |
| 387 | } |
| 388 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 389 | QualType |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 390 | TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T, |
| 391 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 392 | // FIXME: Implement this |
| 393 | assert(false && "Cannot instantiate EnumType yet"); |
| 394 | return QualType(); |
| 395 | } |
| 396 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 397 | QualType |
| 398 | TemplateTypeInstantiator:: |
| 399 | InstantiateTemplateTypeParmType(const TemplateTypeParmType *T, |
| 400 | unsigned Quals) const { |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 401 | if (T->getDepth() == 0) { |
| 402 | // Replace the template type parameter with its corresponding |
| 403 | // template argument. |
| 404 | assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args"); |
| 405 | assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type && |
| 406 | "Template argument kind mismatch"); |
| 407 | QualType Result = TemplateArgs[T->getIndex()].getAsType(); |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 408 | if (Result.isNull() || !Quals) |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 409 | return Result; |
| 410 | |
| 411 | // C++ [dcl.ref]p1: |
| 412 | // [...] Cv-qualified references are ill-formed except when |
| 413 | // the cv-qualifiers are introduced through the use of a |
| 414 | // typedef (7.1.3) or of a template type argument (14.3), in |
| 415 | // which case the cv-qualifiers are ignored. |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 416 | if (Quals && Result->isReferenceType()) |
| 417 | Quals = 0; |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 418 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 419 | return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers()); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | // The template type parameter comes from an inner template (e.g., |
| 423 | // the template parameter list of a member template inside the |
| 424 | // template we are instantiating). Create a new template type |
| 425 | // parameter with the template "level" reduced by one. |
| 426 | return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1, |
| 427 | T->getIndex(), |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 428 | T->getName()) |
| 429 | .getQualifiedType(Quals); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 432 | QualType |
| 433 | TemplateTypeInstantiator:: |
| 434 | InstantiateClassTemplateSpecializationType( |
| 435 | const ClassTemplateSpecializationType *T, |
| 436 | unsigned Quals) const { |
Douglas Gregor | f9ff4b1 | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 437 | llvm::SmallVector<TemplateArgument, 16> InstantiatedTemplateArgs; |
| 438 | InstantiatedTemplateArgs.reserve(T->getNumArgs()); |
| 439 | for (ClassTemplateSpecializationType::iterator Arg = T->begin(), |
| 440 | ArgEnd = T->end(); |
| 441 | Arg != ArgEnd; ++Arg) { |
| 442 | switch (Arg->getKind()) { |
| 443 | case TemplateArgument::Type: { |
| 444 | QualType T = SemaRef.InstantiateType(Arg->getAsType(), |
| 445 | TemplateArgs, NumTemplateArgs, |
| 446 | Arg->getLocation(), |
| 447 | DeclarationName()); |
| 448 | if (T.isNull()) |
| 449 | return QualType(); |
| 450 | |
| 451 | InstantiatedTemplateArgs.push_back( |
| 452 | TemplateArgument(Arg->getLocation(), T)); |
| 453 | break; |
| 454 | } |
| 455 | |
| 456 | case TemplateArgument::Declaration: |
| 457 | case TemplateArgument::Integral: |
| 458 | InstantiatedTemplateArgs.push_back(*Arg); |
| 459 | break; |
| 460 | |
| 461 | case TemplateArgument::Expression: |
Douglas Gregor | 396f114 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 462 | Sema::OwningExprResult E |
| 463 | = SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs, |
| 464 | NumTemplateArgs); |
| 465 | if (E.isInvalid()) |
| 466 | return QualType(); |
| 467 | InstantiatedTemplateArgs.push_back((Expr *)E.release()); |
Douglas Gregor | f9ff4b1 | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | // FIXME: We're missing the locations of the template name, '<', and |
| 473 | // '>'. |
| 474 | return SemaRef.CheckClassTemplateId(cast<ClassTemplateDecl>(T->getTemplate()), |
| 475 | Loc, |
| 476 | SourceLocation(), |
| 477 | &InstantiatedTemplateArgs[0], |
| 478 | InstantiatedTemplateArgs.size(), |
| 479 | SourceLocation()); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 482 | QualType |
| 483 | TemplateTypeInstantiator:: |
Douglas Gregor | 734b4ba | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 484 | InstantiateQualifiedNameType(const QualifiedNameType *T, |
| 485 | unsigned Quals) const { |
| 486 | assert(false && "Cannot have dependent qualified name types (yet)"); |
| 487 | return QualType(); |
| 488 | } |
| 489 | |
| 490 | QualType |
| 491 | TemplateTypeInstantiator:: |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 492 | InstantiateObjCInterfaceType(const ObjCInterfaceType *T, |
| 493 | unsigned Quals) const { |
| 494 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 495 | return QualType(); |
| 496 | } |
| 497 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 498 | QualType |
| 499 | TemplateTypeInstantiator:: |
| 500 | InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T, |
| 501 | unsigned Quals) const { |
| 502 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 503 | return QualType(); |
| 504 | } |
| 505 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 506 | QualType |
| 507 | TemplateTypeInstantiator:: |
| 508 | InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T, |
| 509 | unsigned Quals) const { |
| 510 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 511 | return QualType(); |
| 512 | } |
| 513 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 514 | QualType |
| 515 | TemplateTypeInstantiator:: |
| 516 | InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T, |
| 517 | unsigned Quals) const { |
| 518 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 519 | return QualType(); |
| 520 | } |
| 521 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 522 | /// \brief The actual implementation of Sema::InstantiateType(). |
| 523 | QualType TemplateTypeInstantiator::Instantiate(QualType T) const { |
| 524 | // If T is not a dependent type, there is nothing to do. |
| 525 | if (!T->isDependentType()) |
| 526 | return T; |
| 527 | |
| 528 | switch (T->getTypeClass()) { |
| 529 | #define TYPE(Class, Base) \ |
| 530 | case Type::Class: \ |
| 531 | return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \ |
| 532 | T.getCVRQualifiers()); |
| 533 | #define ABSTRACT_TYPE(Class, Base) |
| 534 | #include "clang/AST/TypeNodes.def" |
| 535 | } |
| 536 | |
| 537 | assert(false && "Not all types have been decoded for instantiation"); |
| 538 | return QualType(); |
| 539 | } |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 540 | |
| 541 | /// \brief Instantiate the type T with a given set of template arguments. |
| 542 | /// |
| 543 | /// This routine substitutes the given template arguments into the |
| 544 | /// type T and produces the instantiated type. |
| 545 | /// |
| 546 | /// \param T the type into which the template arguments will be |
| 547 | /// substituted. If this type is not dependent, it will be returned |
| 548 | /// immediately. |
| 549 | /// |
| 550 | /// \param TemplateArgs the template arguments that will be |
| 551 | /// substituted for the top-level template parameters within T. |
| 552 | /// |
| 553 | /// \param NumTemplateArgs the number of template arguments provided |
| 554 | /// by TemplateArgs. |
| 555 | /// |
| 556 | /// \param Loc the location in the source code where this substitution |
| 557 | /// is being performed. It will typically be the location of the |
| 558 | /// declarator (if we're instantiating the type of some declaration) |
| 559 | /// or the location of the type in the source code (if, e.g., we're |
| 560 | /// instantiating the type of a cast expression). |
| 561 | /// |
| 562 | /// \param Entity the name of the entity associated with a declaration |
| 563 | /// being instantiated (if any). May be empty to indicate that there |
| 564 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 565 | /// a cast expression) or that the entity has no name (e.g., an |
| 566 | /// unnamed function parameter). |
| 567 | /// |
| 568 | /// \returns If the instantiation succeeds, the instantiated |
| 569 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
| 570 | QualType Sema::InstantiateType(QualType T, |
| 571 | const TemplateArgument *TemplateArgs, |
| 572 | unsigned NumTemplateArgs, |
| 573 | SourceLocation Loc, DeclarationName Entity) { |
Douglas Gregor | 56d25a7 | 2009-03-10 20:44:00 +0000 | [diff] [blame] | 574 | assert(!ActiveTemplateInstantiations.empty() && |
| 575 | "Cannot perform an instantiation without some context on the " |
| 576 | "instantiation stack"); |
| 577 | |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 578 | // If T is not a dependent type, there is nothing to do. |
| 579 | if (!T->isDependentType()) |
| 580 | return T; |
| 581 | |
Douglas Gregor | f57dcd0 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 582 | TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs, |
| 583 | Loc, Entity); |
| 584 | return Instantiator(T); |
Douglas Gregor | 7429654 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 585 | } |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 586 | |
| 587 | /// \brief Instantiate the base class specifiers of the given class |
| 588 | /// template specialization. |
| 589 | /// |
| 590 | /// Produces a diagnostic and returns true on error, returns false and |
| 591 | /// attaches the instantiated base classes to the class template |
| 592 | /// specialization if successful. |
| 593 | bool |
| 594 | Sema::InstantiateBaseSpecifiers( |
| 595 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 596 | ClassTemplateDecl *ClassTemplate) { |
| 597 | bool Invalid = false; |
| 598 | llvm::SmallVector<CXXBaseSpecifier*, 8> InstantiatedBases; |
| 599 | for (ClassTemplateSpecializationDecl::base_class_iterator |
| 600 | Base = ClassTemplate->getTemplatedDecl()->bases_begin(), |
| 601 | BaseEnd = ClassTemplate->getTemplatedDecl()->bases_end(); |
Douglas Gregor | d9572a1 | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 602 | Base != BaseEnd; ++Base) { |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 603 | if (!Base->getType()->isDependentType()) { |
| 604 | // FIXME: Allocate via ASTContext |
| 605 | InstantiatedBases.push_back(new CXXBaseSpecifier(*Base)); |
| 606 | continue; |
| 607 | } |
| 608 | |
| 609 | QualType BaseType = InstantiateType(Base->getType(), |
| 610 | ClassTemplateSpec->getTemplateArgs(), |
| 611 | ClassTemplateSpec->getNumTemplateArgs(), |
| 612 | Base->getSourceRange().getBegin(), |
| 613 | DeclarationName()); |
| 614 | if (BaseType.isNull()) { |
| 615 | Invalid = true; |
| 616 | continue; |
| 617 | } |
| 618 | |
| 619 | if (CXXBaseSpecifier *InstantiatedBase |
| 620 | = CheckBaseSpecifier(ClassTemplateSpec, |
| 621 | Base->getSourceRange(), |
| 622 | Base->isVirtual(), |
| 623 | Base->getAccessSpecifierAsWritten(), |
| 624 | BaseType, |
| 625 | /*FIXME: Not totally accurate */ |
| 626 | Base->getSourceRange().getBegin())) |
| 627 | InstantiatedBases.push_back(InstantiatedBase); |
| 628 | else |
| 629 | Invalid = true; |
| 630 | } |
| 631 | |
Douglas Gregor | d9572a1 | 2009-03-10 18:52:44 +0000 | [diff] [blame] | 632 | if (!Invalid && |
| 633 | AttachBaseSpecifiers(ClassTemplateSpec, &InstantiatedBases[0], |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 634 | InstantiatedBases.size())) |
| 635 | Invalid = true; |
| 636 | |
| 637 | return Invalid; |
| 638 | } |
| 639 | |
| 640 | bool |
| 641 | Sema::InstantiateClassTemplateSpecialization( |
| 642 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 643 | bool ExplicitInstantiation) { |
| 644 | // Perform the actual instantiation on the canonical declaration. |
| 645 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( |
| 646 | Context.getCanonicalDecl(ClassTemplateSpec)); |
| 647 | |
| 648 | // We can only instantiate something that hasn't already been |
| 649 | // instantiated or specialized. Fail without any diagnostics: our |
| 650 | // caller will provide an error message. |
| 651 | if (ClassTemplateSpec->getSpecializationKind() != TSK_Undeclared) |
| 652 | return true; |
| 653 | |
| 654 | // FIXME: Push this class template instantiation onto the |
| 655 | // instantiation stack, checking for recursion that exceeds a |
| 656 | // certain depth. |
| 657 | |
| 658 | // FIXME: Perform class template partial specialization to select |
| 659 | // the best template. |
| 660 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); |
| 661 | |
Douglas Gregor | 47bde7c | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 662 | RecordDecl *Pattern = cast_or_null<RecordDecl>( |
| 663 | Template->getTemplatedDecl()->getDefinition(Context)); |
| 664 | if (!Pattern) { |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 665 | Diag(ClassTemplateSpec->getLocation(), |
| 666 | diag::err_template_implicit_instantiate_undefined) |
| 667 | << Context.getTypeDeclType(ClassTemplateSpec); |
| 668 | Diag(Template->getTemplatedDecl()->getLocation(), |
| 669 | diag::note_template_decl_here); |
| 670 | return true; |
| 671 | } |
| 672 | |
| 673 | // Note that this is an instantiation. |
| 674 | ClassTemplateSpec->setSpecializationKind( |
| 675 | ExplicitInstantiation? TSK_ExplicitInstantiation |
| 676 | : TSK_ImplicitInstantiation); |
| 677 | |
| 678 | |
| 679 | bool Invalid = false; |
| 680 | |
Douglas Gregor | 375733c | 2009-03-10 00:06:19 +0000 | [diff] [blame] | 681 | InstantiatingTemplate Inst(*this, ClassTemplateSpec->getLocation(), |
| 682 | ClassTemplateSpec); |
| 683 | if (Inst) |
| 684 | return true; |
| 685 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 686 | // Enter the scope of this instantiation. We don't use |
| 687 | // PushDeclContext because we don't have a scope. |
| 688 | DeclContext *PreviousContext = CurContext; |
| 689 | CurContext = ClassTemplateSpec; |
| 690 | |
| 691 | // Start the definition of this instantiation. |
| 692 | ClassTemplateSpec->startDefinition(); |
| 693 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 694 | // Instantiate the base class specifiers. |
| 695 | if (InstantiateBaseSpecifiers(ClassTemplateSpec, Template)) |
| 696 | Invalid = true; |
| 697 | |
Douglas Gregor | 6e7c27c | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 698 | // FIXME: Create the injected-class-name for the |
| 699 | // instantiation. Should this be a typedef or something like it? |
| 700 | |
Douglas Gregor | 0e518af | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 701 | llvm::SmallVector<DeclTy *, 32> Fields; |
Douglas Gregor | 6e7c27c | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 702 | for (RecordDecl::decl_iterator Member = Pattern->decls_begin(), |
| 703 | MemberEnd = Pattern->decls_end(); |
| 704 | Member != MemberEnd; ++Member) { |
Douglas Gregor | 1b39ef4 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 705 | Decl *NewMember = InstantiateDecl(*Member, ClassTemplateSpec, |
| 706 | ClassTemplateSpec->getTemplateArgs(), |
| 707 | ClassTemplateSpec->getNumTemplateArgs()); |
| 708 | if (NewMember) { |
| 709 | if (NewMember->isInvalidDecl()) |
Anders Carlsson | c45057a | 2009-03-15 18:44:04 +0000 | [diff] [blame] | 710 | Invalid = true; |
Douglas Gregor | 1b39ef4 | 2009-03-17 21:15:40 +0000 | [diff] [blame] | 711 | else if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) |
| 712 | Fields.push_back(Field); |
| 713 | } else { |
| 714 | // FIXME: Eventually, a NULL return will mean that one of the |
| 715 | // instantiations was a semantic disaster, and we'll want to set |
| 716 | // Invalid = true. For now, we expect to skip some members that |
| 717 | // we can't yet handle. |
Douglas Gregor | 6e7c27c | 2009-03-11 16:48:53 +0000 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
Douglas Gregor | 0e518af | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 721 | // Finish checking fields. |
| 722 | ActOnFields(0, ClassTemplateSpec->getLocation(), ClassTemplateSpec, |
| 723 | &Fields[0], Fields.size(), SourceLocation(), SourceLocation(), |
| 724 | 0); |
| 725 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 726 | // Add any implicitly-declared members that we might need. |
| 727 | AddImplicitlyDeclaredMembersToClass(ClassTemplateSpec); |
| 728 | |
Douglas Gregor | ed3a398 | 2009-03-03 04:44:36 +0000 | [diff] [blame] | 729 | // Exit the scope of this instantiation. |
| 730 | CurContext = PreviousContext; |
| 731 | |
| 732 | return Invalid; |
| 733 | } |
Douglas Gregor | 47bde7c | 2009-03-19 17:26:29 +0000 | [diff] [blame] | 734 | |
| 735 | /// \brief Instantiate a sequence of nested-name-specifiers into a |
| 736 | /// scope specifier. |
| 737 | CXXScopeSpec |
| 738 | Sema::InstantiateScopeSpecifier(const NestedNameSpecifier *Components, |
| 739 | unsigned NumComponents, |
| 740 | SourceRange Range, |
| 741 | const TemplateArgument *TemplateArgs, |
| 742 | unsigned NumTemplateArgs) { |
| 743 | CXXScopeSpec SS; |
| 744 | for (unsigned Comp = 0; Comp < NumComponents; ++Comp) { |
| 745 | if (Type *T = Components[Comp].getAsType()) { |
| 746 | QualType NewT = InstantiateType(QualType(T, 0), TemplateArgs, |
| 747 | NumTemplateArgs, Range.getBegin(), |
| 748 | DeclarationName()); |
| 749 | if (NewT.isNull()) |
| 750 | return SS; |
| 751 | NestedNameSpecifier NNS(NewT.getTypePtr()); |
| 752 | SS.addScopeRep(NNS.getAsOpaquePtr()); |
| 753 | } else { |
| 754 | DeclContext *DC = Components[Comp].getAsDeclContext(); |
| 755 | // FIXME: injected-class-name might be dependent, and therefore |
| 756 | // would need instantiation. |
| 757 | NestedNameSpecifier NNS(DC); |
| 758 | SS.addScopeRep(NNS.getAsOpaquePtr()); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | SS.setRange(Range); |
| 763 | return SS; |
| 764 | } |