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" |
| 18 | #include "clang/Parse/DeclSpec.h" |
| 19 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Compiler.h" |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace clang; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===/ |
| 25 | // Template Instantiation for Types |
| 26 | //===----------------------------------------------------------------------===/ |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 27 | namespace { |
| 28 | class VISIBILITY_HIDDEN TemplateTypeInstantiator { |
| 29 | Sema &SemaRef; |
| 30 | const TemplateArgument *TemplateArgs; |
| 31 | unsigned NumTemplateArgs; |
| 32 | SourceLocation Loc; |
| 33 | DeclarationName Entity; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 35 | public: |
| 36 | TemplateTypeInstantiator(Sema &SemaRef, |
| 37 | const TemplateArgument *TemplateArgs, |
| 38 | unsigned NumTemplateArgs, |
| 39 | SourceLocation Loc, |
| 40 | DeclarationName Entity) |
| 41 | : SemaRef(SemaRef), TemplateArgs(TemplateArgs), |
| 42 | NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { } |
| 43 | |
| 44 | QualType operator()(QualType T) const { return Instantiate(T); } |
| 45 | |
| 46 | QualType Instantiate(QualType T) const; |
| 47 | |
| 48 | // Declare instantiate functions for each type. |
| 49 | #define TYPE(Class, Base) \ |
| 50 | QualType Instantiate##Class##Type(const Class##Type *T, \ |
| 51 | unsigned Quals) const; |
| 52 | #define ABSTRACT_TYPE(Class, Base) |
| 53 | #include "clang/AST/TypeNodes.def" |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | QualType |
| 58 | TemplateTypeInstantiator::InstantiateExtQualType(const ExtQualType *T, |
| 59 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 60 | // FIXME: Implement this |
| 61 | assert(false && "Cannot instantiate ExtQualType yet"); |
| 62 | return QualType(); |
| 63 | } |
| 64 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 65 | QualType |
| 66 | TemplateTypeInstantiator::InstantiateBuiltinType(const BuiltinType *T, |
| 67 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame^] | 68 | assert(false && "Builtin types are not dependent and cannot be instantiated"); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 69 | return QualType(T, Quals); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 72 | QualType |
| 73 | TemplateTypeInstantiator:: |
| 74 | InstantiateFixedWidthIntType(const FixedWidthIntType *T, unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 75 | // FIXME: Implement this |
| 76 | assert(false && "Cannot instantiate FixedWidthIntType yet"); |
| 77 | return QualType(); |
| 78 | } |
| 79 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 80 | QualType |
| 81 | TemplateTypeInstantiator::InstantiateComplexType(const ComplexType *T, |
| 82 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 83 | // FIXME: Implement this |
| 84 | assert(false && "Cannot instantiate ComplexType yet"); |
| 85 | return QualType(); |
| 86 | } |
| 87 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 88 | QualType |
| 89 | TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T, |
| 90 | unsigned Quals) const { |
| 91 | QualType PointeeType = Instantiate(T->getPointeeType()); |
| 92 | if (PointeeType.isNull()) |
| 93 | return QualType(); |
| 94 | |
| 95 | return SemaRef.BuildPointerType(PointeeType, Quals, Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 98 | QualType |
| 99 | TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T, |
| 100 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 101 | // FIXME: Implement this |
| 102 | assert(false && "Cannot instantiate BlockPointerType yet"); |
| 103 | return QualType(); |
| 104 | } |
| 105 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 106 | QualType |
| 107 | TemplateTypeInstantiator::InstantiateReferenceType(const ReferenceType *T, |
| 108 | unsigned Quals) const { |
| 109 | QualType ReferentType = Instantiate(T->getPointeeType()); |
| 110 | if (ReferentType.isNull()) |
| 111 | return QualType(); |
| 112 | |
| 113 | return SemaRef.BuildReferenceType(ReferentType, Quals, Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 116 | QualType |
| 117 | TemplateTypeInstantiator:: |
| 118 | InstantiateMemberPointerType(const MemberPointerType *T, |
| 119 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 120 | // FIXME: Implement this |
| 121 | assert(false && "Cannot instantiate MemberPointerType yet"); |
| 122 | return QualType(); |
| 123 | } |
| 124 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 125 | QualType |
| 126 | TemplateTypeInstantiator:: |
| 127 | InstantiateConstantArrayType(const ConstantArrayType *T, |
| 128 | unsigned Quals) const { |
| 129 | QualType ElementType = Instantiate(T->getElementType()); |
| 130 | if (ElementType.isNull()) |
| 131 | return ElementType; |
| 132 | |
| 133 | // Build a temporary integer literal to specify the size for |
| 134 | // BuildArrayType. Since we have already checked the size as part of |
| 135 | // creating the dependent array type in the first place, we know |
| 136 | // there aren't any errors. |
| 137 | IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc); |
| 138 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 139 | &ArraySize, T->getIndexTypeQualifier(), |
| 140 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 143 | QualType |
| 144 | TemplateTypeInstantiator:: |
| 145 | InstantiateIncompleteArrayType(const IncompleteArrayType *T, |
| 146 | unsigned Quals) const { |
| 147 | QualType ElementType = Instantiate(T->getElementType()); |
| 148 | if (ElementType.isNull()) |
| 149 | return ElementType; |
| 150 | |
| 151 | return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(), |
| 152 | 0, T->getIndexTypeQualifier(), |
| 153 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 156 | QualType |
| 157 | TemplateTypeInstantiator:: |
| 158 | InstantiateVariableArrayType(const VariableArrayType *T, |
| 159 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 160 | // FIXME: Implement this |
| 161 | assert(false && "Cannot instantiate VariableArrayType yet"); |
| 162 | return QualType(); |
| 163 | } |
| 164 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 165 | QualType |
| 166 | TemplateTypeInstantiator:: |
| 167 | InstantiateDependentSizedArrayType(const DependentSizedArrayType *T, |
| 168 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 169 | // FIXME: Implement this |
| 170 | assert(false && "Cannot instantiate DependentSizedArrayType yet"); |
| 171 | return QualType(); |
| 172 | } |
| 173 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 174 | QualType |
| 175 | TemplateTypeInstantiator::InstantiateVectorType(const VectorType *T, |
| 176 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 177 | // FIXME: Implement this |
| 178 | assert(false && "Cannot instantiate VectorType yet"); |
| 179 | return QualType(); |
| 180 | } |
| 181 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 182 | QualType |
| 183 | TemplateTypeInstantiator::InstantiateExtVectorType(const ExtVectorType *T, |
| 184 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 185 | // FIXME: Implement this |
| 186 | assert(false && "Cannot instantiate ExtVectorType yet"); |
| 187 | return QualType(); |
| 188 | } |
| 189 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 190 | QualType |
| 191 | TemplateTypeInstantiator:: |
| 192 | InstantiateFunctionProtoType(const FunctionProtoType *T, |
| 193 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame^] | 194 | QualType ResultType = Instantiate(T->getResultType()); |
| 195 | if (ResultType.isNull()) |
| 196 | return ResultType; |
| 197 | |
| 198 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 199 | for (FunctionProtoType::arg_type_iterator Param = T->arg_type_begin(), |
| 200 | ParamEnd = T->arg_type_end(); |
| 201 | Param != ParamEnd; ++Param) { |
| 202 | QualType P = Instantiate(*Param); |
| 203 | if (P.isNull()) |
| 204 | return P; |
| 205 | |
| 206 | ParamTypes.push_back(P); |
| 207 | } |
| 208 | |
| 209 | return SemaRef.BuildFunctionType(ResultType, &ParamTypes[0], |
| 210 | ParamTypes.size(), |
| 211 | T->isVariadic(), T->getTypeQuals(), |
| 212 | Loc, Entity); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 215 | QualType |
| 216 | TemplateTypeInstantiator:: |
| 217 | InstantiateFunctionNoProtoType(const FunctionNoProtoType *T, |
| 218 | unsigned Quals) const { |
Douglas Gregor | 724651c | 2009-02-28 01:04:19 +0000 | [diff] [blame^] | 219 | assert(false && "Functions without prototypes cannot be dependent."); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 220 | return QualType(); |
| 221 | } |
| 222 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 223 | QualType |
| 224 | TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T, |
| 225 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 226 | // FIXME: Implement this |
| 227 | assert(false && "Cannot instantiate TypedefType yet"); |
| 228 | return QualType(); |
| 229 | } |
| 230 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 231 | QualType |
| 232 | TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T, |
| 233 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 234 | // FIXME: Implement this |
| 235 | assert(false && "Cannot instantiate TypeOfExprType yet"); |
| 236 | return QualType(); |
| 237 | } |
| 238 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 239 | QualType |
| 240 | TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T, |
| 241 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 242 | // FIXME: Implement this |
| 243 | assert(false && "Cannot instantiate TypeOfType yet"); |
| 244 | return QualType(); |
| 245 | } |
| 246 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 247 | QualType |
| 248 | TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T, |
| 249 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 250 | // FIXME: Implement this |
| 251 | assert(false && "Cannot instantiate RecordType yet"); |
| 252 | return QualType(); |
| 253 | } |
| 254 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 255 | QualType |
| 256 | TemplateTypeInstantiator::InstantiateCXXRecordType(const CXXRecordType *T, |
| 257 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 258 | // FIXME: Implement this |
| 259 | assert(false && "Cannot instantiate CXXRecordType yet"); |
| 260 | return QualType(); |
| 261 | } |
| 262 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 263 | QualType |
| 264 | TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T, |
| 265 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 266 | // FIXME: Implement this |
| 267 | assert(false && "Cannot instantiate EnumType yet"); |
| 268 | return QualType(); |
| 269 | } |
| 270 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 271 | QualType |
| 272 | TemplateTypeInstantiator:: |
| 273 | InstantiateTemplateTypeParmType(const TemplateTypeParmType *T, |
| 274 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 275 | if (T->getDepth() == 0) { |
| 276 | // Replace the template type parameter with its corresponding |
| 277 | // template argument. |
| 278 | assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args"); |
| 279 | assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type && |
| 280 | "Template argument kind mismatch"); |
| 281 | QualType Result = TemplateArgs[T->getIndex()].getAsType(); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 282 | if (Result.isNull() || !Quals) |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 283 | return Result; |
| 284 | |
| 285 | // C++ [dcl.ref]p1: |
| 286 | // [...] Cv-qualified references are ill-formed except when |
| 287 | // the cv-qualifiers are introduced through the use of a |
| 288 | // typedef (7.1.3) or of a template type argument (14.3), in |
| 289 | // which case the cv-qualifiers are ignored. |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 290 | if (Quals && Result->isReferenceType()) |
| 291 | Quals = 0; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 292 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 293 | return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers()); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // The template type parameter comes from an inner template (e.g., |
| 297 | // the template parameter list of a member template inside the |
| 298 | // template we are instantiating). Create a new template type |
| 299 | // parameter with the template "level" reduced by one. |
| 300 | return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1, |
| 301 | T->getIndex(), |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 302 | T->getName()) |
| 303 | .getQualifiedType(Quals); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 306 | QualType |
| 307 | TemplateTypeInstantiator:: |
| 308 | InstantiateClassTemplateSpecializationType( |
| 309 | const ClassTemplateSpecializationType *T, |
| 310 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 311 | // FIXME: Implement this |
| 312 | assert(false && "Cannot instantiate ClassTemplateSpecializationType yet"); |
| 313 | return QualType(); |
| 314 | } |
| 315 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 316 | QualType |
| 317 | TemplateTypeInstantiator:: |
| 318 | InstantiateObjCInterfaceType(const ObjCInterfaceType *T, |
| 319 | unsigned Quals) const { |
| 320 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 321 | return QualType(); |
| 322 | } |
| 323 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 324 | QualType |
| 325 | TemplateTypeInstantiator:: |
| 326 | InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T, |
| 327 | unsigned Quals) const { |
| 328 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 329 | return QualType(); |
| 330 | } |
| 331 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 332 | QualType |
| 333 | TemplateTypeInstantiator:: |
| 334 | InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T, |
| 335 | unsigned Quals) const { |
| 336 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 337 | return QualType(); |
| 338 | } |
| 339 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 340 | QualType |
| 341 | TemplateTypeInstantiator:: |
| 342 | InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T, |
| 343 | unsigned Quals) const { |
| 344 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 345 | return QualType(); |
| 346 | } |
| 347 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 348 | /// \brief The actual implementation of Sema::InstantiateType(). |
| 349 | QualType TemplateTypeInstantiator::Instantiate(QualType T) const { |
| 350 | // If T is not a dependent type, there is nothing to do. |
| 351 | if (!T->isDependentType()) |
| 352 | return T; |
| 353 | |
| 354 | switch (T->getTypeClass()) { |
| 355 | #define TYPE(Class, Base) \ |
| 356 | case Type::Class: \ |
| 357 | return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \ |
| 358 | T.getCVRQualifiers()); |
| 359 | #define ABSTRACT_TYPE(Class, Base) |
| 360 | #include "clang/AST/TypeNodes.def" |
| 361 | } |
| 362 | |
| 363 | assert(false && "Not all types have been decoded for instantiation"); |
| 364 | return QualType(); |
| 365 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 366 | |
| 367 | /// \brief Instantiate the type T with a given set of template arguments. |
| 368 | /// |
| 369 | /// This routine substitutes the given template arguments into the |
| 370 | /// type T and produces the instantiated type. |
| 371 | /// |
| 372 | /// \param T the type into which the template arguments will be |
| 373 | /// substituted. If this type is not dependent, it will be returned |
| 374 | /// immediately. |
| 375 | /// |
| 376 | /// \param TemplateArgs the template arguments that will be |
| 377 | /// substituted for the top-level template parameters within T. |
| 378 | /// |
| 379 | /// \param NumTemplateArgs the number of template arguments provided |
| 380 | /// by TemplateArgs. |
| 381 | /// |
| 382 | /// \param Loc the location in the source code where this substitution |
| 383 | /// is being performed. It will typically be the location of the |
| 384 | /// declarator (if we're instantiating the type of some declaration) |
| 385 | /// or the location of the type in the source code (if, e.g., we're |
| 386 | /// instantiating the type of a cast expression). |
| 387 | /// |
| 388 | /// \param Entity the name of the entity associated with a declaration |
| 389 | /// being instantiated (if any). May be empty to indicate that there |
| 390 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 391 | /// a cast expression) or that the entity has no name (e.g., an |
| 392 | /// unnamed function parameter). |
| 393 | /// |
| 394 | /// \returns If the instantiation succeeds, the instantiated |
| 395 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
| 396 | QualType Sema::InstantiateType(QualType T, |
| 397 | const TemplateArgument *TemplateArgs, |
| 398 | unsigned NumTemplateArgs, |
| 399 | SourceLocation Loc, DeclarationName Entity) { |
| 400 | // If T is not a dependent type, there is nothing to do. |
| 401 | if (!T->isDependentType()) |
| 402 | return T; |
| 403 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 404 | TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs, |
| 405 | Loc, Entity); |
| 406 | return Instantiator(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 407 | } |