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 | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 68 | assert(false && "BuiltinType is never 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 | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 194 | // FIXME: Implement this |
| 195 | assert(false && "Cannot instantiate FunctionProtoType yet"); |
| 196 | return QualType(); |
| 197 | } |
| 198 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 199 | QualType |
| 200 | TemplateTypeInstantiator:: |
| 201 | InstantiateFunctionNoProtoType(const FunctionNoProtoType *T, |
| 202 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 203 | // FIXME: Implement this |
| 204 | assert(false && "Cannot instantiate FunctionNoProtoType yet"); |
| 205 | return QualType(); |
| 206 | } |
| 207 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 208 | QualType |
| 209 | TemplateTypeInstantiator::InstantiateTypedefType(const TypedefType *T, |
| 210 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 211 | // FIXME: Implement this |
| 212 | assert(false && "Cannot instantiate TypedefType yet"); |
| 213 | return QualType(); |
| 214 | } |
| 215 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 216 | QualType |
| 217 | TemplateTypeInstantiator::InstantiateTypeOfExprType(const TypeOfExprType *T, |
| 218 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 219 | // FIXME: Implement this |
| 220 | assert(false && "Cannot instantiate TypeOfExprType yet"); |
| 221 | return QualType(); |
| 222 | } |
| 223 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 224 | QualType |
| 225 | TemplateTypeInstantiator::InstantiateTypeOfType(const TypeOfType *T, |
| 226 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 227 | // FIXME: Implement this |
| 228 | assert(false && "Cannot instantiate TypeOfType yet"); |
| 229 | return QualType(); |
| 230 | } |
| 231 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 232 | QualType |
| 233 | TemplateTypeInstantiator::InstantiateRecordType(const RecordType *T, |
| 234 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 235 | // FIXME: Implement this |
| 236 | assert(false && "Cannot instantiate RecordType yet"); |
| 237 | return QualType(); |
| 238 | } |
| 239 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 240 | QualType |
| 241 | TemplateTypeInstantiator::InstantiateCXXRecordType(const CXXRecordType *T, |
| 242 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 243 | // FIXME: Implement this |
| 244 | assert(false && "Cannot instantiate CXXRecordType yet"); |
| 245 | return QualType(); |
| 246 | } |
| 247 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 248 | QualType |
| 249 | TemplateTypeInstantiator::InstantiateEnumType(const EnumType *T, |
| 250 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 251 | // FIXME: Implement this |
| 252 | assert(false && "Cannot instantiate EnumType yet"); |
| 253 | return QualType(); |
| 254 | } |
| 255 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 256 | QualType |
| 257 | TemplateTypeInstantiator:: |
| 258 | InstantiateTemplateTypeParmType(const TemplateTypeParmType *T, |
| 259 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 260 | if (T->getDepth() == 0) { |
| 261 | // Replace the template type parameter with its corresponding |
| 262 | // template argument. |
| 263 | assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args"); |
| 264 | assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type && |
| 265 | "Template argument kind mismatch"); |
| 266 | QualType Result = TemplateArgs[T->getIndex()].getAsType(); |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 267 | if (Result.isNull() || !Quals) |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 268 | return Result; |
| 269 | |
| 270 | // C++ [dcl.ref]p1: |
| 271 | // [...] Cv-qualified references are ill-formed except when |
| 272 | // the cv-qualifiers are introduced through the use of a |
| 273 | // typedef (7.1.3) or of a template type argument (14.3), in |
| 274 | // which case the cv-qualifiers are ignored. |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 275 | if (Quals && Result->isReferenceType()) |
| 276 | Quals = 0; |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 277 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 278 | return QualType(Result.getTypePtr(), Quals | Result.getCVRQualifiers()); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // The template type parameter comes from an inner template (e.g., |
| 282 | // the template parameter list of a member template inside the |
| 283 | // template we are instantiating). Create a new template type |
| 284 | // parameter with the template "level" reduced by one. |
| 285 | return SemaRef.Context.getTemplateTypeParmType(T->getDepth() - 1, |
| 286 | T->getIndex(), |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 287 | T->getName()) |
| 288 | .getQualifiedType(Quals); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 291 | QualType |
| 292 | TemplateTypeInstantiator:: |
| 293 | InstantiateClassTemplateSpecializationType( |
| 294 | const ClassTemplateSpecializationType *T, |
| 295 | unsigned Quals) const { |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 296 | // FIXME: Implement this |
| 297 | assert(false && "Cannot instantiate ClassTemplateSpecializationType yet"); |
| 298 | return QualType(); |
| 299 | } |
| 300 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 301 | QualType |
| 302 | TemplateTypeInstantiator:: |
| 303 | InstantiateObjCInterfaceType(const ObjCInterfaceType *T, |
| 304 | unsigned Quals) const { |
| 305 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 306 | return QualType(); |
| 307 | } |
| 308 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 309 | QualType |
| 310 | TemplateTypeInstantiator:: |
| 311 | InstantiateObjCQualifiedInterfaceType(const ObjCQualifiedInterfaceType *T, |
| 312 | unsigned Quals) const { |
| 313 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 314 | return QualType(); |
| 315 | } |
| 316 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 317 | QualType |
| 318 | TemplateTypeInstantiator:: |
| 319 | InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T, |
| 320 | unsigned Quals) const { |
| 321 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 322 | return QualType(); |
| 323 | } |
| 324 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 325 | QualType |
| 326 | TemplateTypeInstantiator:: |
| 327 | InstantiateObjCQualifiedClassType(const ObjCQualifiedClassType *T, |
| 328 | unsigned Quals) const { |
| 329 | assert(false && "Objective-C types cannot be dependent"); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 330 | return QualType(); |
| 331 | } |
| 332 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 333 | /// \brief The actual implementation of Sema::InstantiateType(). |
| 334 | QualType TemplateTypeInstantiator::Instantiate(QualType T) const { |
| 335 | // If T is not a dependent type, there is nothing to do. |
| 336 | if (!T->isDependentType()) |
| 337 | return T; |
| 338 | |
| 339 | switch (T->getTypeClass()) { |
| 340 | #define TYPE(Class, Base) \ |
| 341 | case Type::Class: \ |
| 342 | return Instantiate##Class##Type(cast<Class##Type>(T.getTypePtr()), \ |
| 343 | T.getCVRQualifiers()); |
| 344 | #define ABSTRACT_TYPE(Class, Base) |
| 345 | #include "clang/AST/TypeNodes.def" |
| 346 | } |
| 347 | |
| 348 | assert(false && "Not all types have been decoded for instantiation"); |
| 349 | return QualType(); |
| 350 | } |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 351 | |
| 352 | /// \brief Instantiate the type T with a given set of template arguments. |
| 353 | /// |
| 354 | /// This routine substitutes the given template arguments into the |
| 355 | /// type T and produces the instantiated type. |
| 356 | /// |
| 357 | /// \param T the type into which the template arguments will be |
| 358 | /// substituted. If this type is not dependent, it will be returned |
| 359 | /// immediately. |
| 360 | /// |
| 361 | /// \param TemplateArgs the template arguments that will be |
| 362 | /// substituted for the top-level template parameters within T. |
| 363 | /// |
| 364 | /// \param NumTemplateArgs the number of template arguments provided |
| 365 | /// by TemplateArgs. |
| 366 | /// |
| 367 | /// \param Loc the location in the source code where this substitution |
| 368 | /// is being performed. It will typically be the location of the |
| 369 | /// declarator (if we're instantiating the type of some declaration) |
| 370 | /// or the location of the type in the source code (if, e.g., we're |
| 371 | /// instantiating the type of a cast expression). |
| 372 | /// |
| 373 | /// \param Entity the name of the entity associated with a declaration |
| 374 | /// being instantiated (if any). May be empty to indicate that there |
| 375 | /// is no such entity (if, e.g., this is a type that occurs as part of |
| 376 | /// a cast expression) or that the entity has no name (e.g., an |
| 377 | /// unnamed function parameter). |
| 378 | /// |
| 379 | /// \returns If the instantiation succeeds, the instantiated |
| 380 | /// type. Otherwise, produces diagnostics and returns a NULL type. |
| 381 | QualType Sema::InstantiateType(QualType T, |
| 382 | const TemplateArgument *TemplateArgs, |
| 383 | unsigned NumTemplateArgs, |
| 384 | SourceLocation Loc, DeclarationName Entity) { |
| 385 | // If T is not a dependent type, there is nothing to do. |
| 386 | if (!T->isDependentType()) |
| 387 | return T; |
| 388 | |
Douglas Gregor | cd281c3 | 2009-02-28 00:25:32 +0000 | [diff] [blame] | 389 | TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs, |
| 390 | Loc, Entity); |
| 391 | return Instantiator(T); |
Douglas Gregor | 99ebf65 | 2009-02-27 19:31:52 +0000 | [diff] [blame] | 392 | } |