forked from OSchip/llvm-project
Encapsulate template arguments lists in a new class,
TemplateArgumentList. This avoids the need to pass around pointer/length pairs of template arguments lists, and will eventually make it easier to introduce member templates and variadic templates. llvm-svn: 71517
This commit is contained in:
parent
5fb7847fbf
commit
d002c7bc58
|
@ -554,6 +554,64 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// \brief A template argument list.
|
||||
///
|
||||
/// FIXME: In the future, this class will be extended to support
|
||||
/// variadic templates and member templates, which will make some of
|
||||
/// the function names below make more sense.
|
||||
class TemplateArgumentList {
|
||||
/// \brief The template argument list.
|
||||
///
|
||||
/// The integer value will be non-zero to indicate that this
|
||||
/// template argument list does not own the pointer.
|
||||
llvm::PointerIntPair<TemplateArgument *, 1> Arguments;
|
||||
|
||||
/// \brief The number of template arguments in this template
|
||||
/// argument list.
|
||||
unsigned NumArguments;
|
||||
|
||||
|
||||
public:
|
||||
TemplateArgumentList(ASTContext &Context,
|
||||
TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
bool CopyArgs);
|
||||
|
||||
~TemplateArgumentList();
|
||||
|
||||
/// \brief Retrieve the template argument at a given index.
|
||||
const TemplateArgument &get(unsigned Idx) const {
|
||||
assert(Idx < NumArguments && "Invalid template argument index");
|
||||
return getFlatArgumentList()[Idx];
|
||||
}
|
||||
|
||||
/// \brief Retrieve the template argument at a given index.
|
||||
TemplateArgument &get(unsigned Idx) {
|
||||
assert(Idx < NumArguments && "Invalid template argument index");
|
||||
return getFlatArgumentList()[Idx];
|
||||
}
|
||||
|
||||
/// \brief Retrieve the template argument at a given index.
|
||||
TemplateArgument &operator[](unsigned Idx) { return get(Idx); }
|
||||
const TemplateArgument &operator[](unsigned Idx) const { return get(Idx); }
|
||||
|
||||
/// \brief Retrieve the number of template arguments in this
|
||||
/// template argument list.
|
||||
unsigned size() const { return NumArguments; }
|
||||
|
||||
/// \brief Retrieve the number of template arguments in the
|
||||
/// flattened template argument list.
|
||||
unsigned flat_size() const { return NumArguments; }
|
||||
|
||||
/// \brief Retrieve the flattened template argument list.
|
||||
TemplateArgument *getFlatArgumentList() {
|
||||
return Arguments.getPointer();
|
||||
}
|
||||
const TemplateArgument *getFlatArgumentList() const {
|
||||
return Arguments.getPointer();
|
||||
}
|
||||
};
|
||||
|
||||
// \brief Describes the kind of template specialization that a
|
||||
// particular template specialization declaration represents.
|
||||
enum TemplateSpecializationKind {
|
||||
|
@ -589,17 +647,17 @@ class ClassTemplateSpecializationDecl
|
|||
/// \brief The template that this specialization specializes
|
||||
ClassTemplateDecl *SpecializedTemplate;
|
||||
|
||||
/// \brief The number of template arguments. The actual arguments
|
||||
/// are allocated after the ClassTemplateSpecializationDecl object.
|
||||
unsigned NumTemplateArgs : 16;
|
||||
/// \brief The template arguments used to describe this specialization.
|
||||
TemplateArgumentList TemplateArgs;
|
||||
|
||||
/// \brief The kind of specialization this declaration refers to.
|
||||
/// Really a value of type TemplateSpecializationKind.
|
||||
unsigned SpecializationKind : 2;
|
||||
|
||||
ClassTemplateSpecializationDecl(DeclContext *DC, SourceLocation L,
|
||||
ClassTemplateSpecializationDecl(ASTContext &Context,
|
||||
DeclContext *DC, SourceLocation L,
|
||||
ClassTemplateDecl *SpecializedTemplate,
|
||||
TemplateArgument *TemplateArgs,
|
||||
TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
|
||||
public:
|
||||
|
@ -614,21 +672,10 @@ public:
|
|||
return SpecializedTemplate;
|
||||
}
|
||||
|
||||
typedef const TemplateArgument * template_arg_iterator;
|
||||
template_arg_iterator template_arg_begin() const {
|
||||
return reinterpret_cast<template_arg_iterator>(this + 1);
|
||||
const TemplateArgumentList &getTemplateArgs() const {
|
||||
return TemplateArgs;
|
||||
}
|
||||
|
||||
template_arg_iterator template_arg_end() const {
|
||||
return template_arg_begin() + NumTemplateArgs;
|
||||
}
|
||||
|
||||
const TemplateArgument *getTemplateArgs() const {
|
||||
return template_arg_begin();
|
||||
}
|
||||
|
||||
unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
|
||||
|
||||
/// \brief Determine the kind of specialization that this
|
||||
/// declaration represents.
|
||||
TemplateSpecializationKind getSpecializationKind() const {
|
||||
|
@ -640,7 +687,7 @@ public:
|
|||
}
|
||||
|
||||
void Profile(llvm::FoldingSetNodeID &ID) const {
|
||||
Profile(ID, template_arg_begin(), getNumTemplateArgs());
|
||||
Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size());
|
||||
}
|
||||
|
||||
/// \brief Sets the type of this specialization as it was written by
|
||||
|
|
|
@ -235,13 +235,43 @@ TemplateArgument::TemplateArgument(Expr *E) : Kind(Expression) {
|
|||
StartLoc = E->getSourceRange().getBegin();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// TemplateArgumentList Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
TemplateArgumentList::TemplateArgumentList(ASTContext &Context,
|
||||
TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
bool CopyArgs)
|
||||
: NumArguments(NumTemplateArgs) {
|
||||
if (!CopyArgs) {
|
||||
Arguments.setPointer(TemplateArgs);
|
||||
Arguments.setInt(1);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned Size = sizeof(TemplateArgument) * NumTemplateArgs;
|
||||
unsigned Align = llvm::AlignOf<TemplateArgument>::Alignment;
|
||||
void *Mem = Context.Allocate(Size, Align);
|
||||
Arguments.setPointer((TemplateArgument *)Mem);
|
||||
Arguments.setInt(0);
|
||||
|
||||
TemplateArgument *Args = (TemplateArgument *)Mem;
|
||||
for (unsigned I = 0; I != NumTemplateArgs; ++I)
|
||||
new (Args + I) TemplateArgument(TemplateArgs[I]);
|
||||
}
|
||||
|
||||
TemplateArgumentList::~TemplateArgumentList() {
|
||||
// FIXME: Deallocate template arguments
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ClassTemplateSpecializationDecl Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
ClassTemplateSpecializationDecl::
|
||||
ClassTemplateSpecializationDecl(DeclContext *DC, SourceLocation L,
|
||||
ClassTemplateSpecializationDecl(ASTContext &Context,
|
||||
DeclContext *DC, SourceLocation L,
|
||||
ClassTemplateDecl *SpecializedTemplate,
|
||||
TemplateArgument *TemplateArgs,
|
||||
TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs)
|
||||
: CXXRecordDecl(ClassTemplateSpecialization,
|
||||
SpecializedTemplate->getTemplatedDecl()->getTagKind(),
|
||||
|
@ -250,10 +280,8 @@ ClassTemplateSpecializationDecl(DeclContext *DC, SourceLocation L,
|
|||
// class template specializations?
|
||||
SpecializedTemplate->getIdentifier()),
|
||||
SpecializedTemplate(SpecializedTemplate),
|
||||
NumTemplateArgs(NumTemplateArgs), SpecializationKind(TSK_Undeclared) {
|
||||
TemplateArgument *Arg = reinterpret_cast<TemplateArgument *>(this + 1);
|
||||
for (unsigned ArgIdx = 0; ArgIdx < NumTemplateArgs; ++ArgIdx, ++Arg)
|
||||
new (Arg) TemplateArgument(TemplateArgs[ArgIdx]);
|
||||
TemplateArgs(Context, TemplateArgs, NumTemplateArgs, /*CopyArgs=*/true),
|
||||
SpecializationKind(TSK_Undeclared) {
|
||||
}
|
||||
|
||||
ClassTemplateSpecializationDecl *
|
||||
|
@ -263,13 +291,11 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context,
|
|||
TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
ClassTemplateSpecializationDecl *PrevDecl) {
|
||||
unsigned Size = sizeof(ClassTemplateSpecializationDecl) +
|
||||
sizeof(TemplateArgument) * NumTemplateArgs;
|
||||
unsigned Align = llvm::AlignOf<ClassTemplateSpecializationDecl>::Alignment;
|
||||
void *Mem = Context.Allocate(Size, Align);
|
||||
ClassTemplateSpecializationDecl *Result
|
||||
= new (Mem) ClassTemplateSpecializationDecl(DC, L, SpecializedTemplate,
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
= new (Context)ClassTemplateSpecializationDecl(Context, DC, L,
|
||||
SpecializedTemplate,
|
||||
TemplateArgs,
|
||||
NumTemplateArgs);
|
||||
Context.getTypeDeclType(Result, PrevDecl);
|
||||
return Result;
|
||||
}
|
||||
|
|
|
@ -1565,11 +1565,12 @@ void TagType::getAsStringInternal(std::string &InnerString,
|
|||
// arguments.
|
||||
if (ClassTemplateSpecializationDecl *Spec
|
||||
= dyn_cast<ClassTemplateSpecializationDecl>(getDecl())) {
|
||||
std::string TemplateArgs
|
||||
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
|
||||
std::string TemplateArgsStr
|
||||
= TemplateSpecializationType::PrintTemplateArgumentList(
|
||||
Spec->getTemplateArgs(),
|
||||
Spec->getNumTemplateArgs());
|
||||
InnerString = TemplateArgs + InnerString;
|
||||
TemplateArgs.getFlatArgumentList(),
|
||||
TemplateArgs.flat_size());
|
||||
InnerString = TemplateArgsStr + InnerString;
|
||||
}
|
||||
|
||||
if (Kind) {
|
||||
|
@ -1584,11 +1585,12 @@ void TagType::getAsStringInternal(std::string &InnerString,
|
|||
MyPart = NS->getNameAsString();
|
||||
} else if (ClassTemplateSpecializationDecl *Spec
|
||||
= dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
|
||||
std::string TemplateArgs
|
||||
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
|
||||
std::string TemplateArgsStr
|
||||
= TemplateSpecializationType::PrintTemplateArgumentList(
|
||||
Spec->getTemplateArgs(),
|
||||
Spec->getNumTemplateArgs());
|
||||
MyPart = Spec->getIdentifier()->getName() + TemplateArgs;
|
||||
TemplateArgs.getFlatArgumentList(),
|
||||
TemplateArgs.flat_size());
|
||||
MyPart = Spec->getIdentifier()->getName() + TemplateArgsStr;
|
||||
} else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
|
||||
if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl())
|
||||
MyPart = Typedef->getIdentifier()->getName();
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace clang {
|
|||
class TypedefDecl;
|
||||
class TemplateDecl;
|
||||
class TemplateArgument;
|
||||
class TemplateArgumentList;
|
||||
class TemplateParameterList;
|
||||
class TemplateTemplateParmDecl;
|
||||
class ClassTemplateDecl;
|
||||
|
@ -1974,7 +1975,7 @@ public:
|
|||
uintptr_t Entity;
|
||||
|
||||
// \brief If this the instantiation of a default template
|
||||
// argument, the list of tempalte arguments.
|
||||
// argument, the list of template arguments.
|
||||
const TemplateArgument *TemplateArgs;
|
||||
|
||||
/// \brief The number of template arguments in TemplateArgs.
|
||||
|
@ -2074,29 +2075,24 @@ public:
|
|||
|
||||
void PrintInstantiationStack();
|
||||
|
||||
QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
QualType InstantiateType(QualType T, const TemplateArgumentList &TemplateArgs,
|
||||
SourceLocation Loc, DeclarationName Entity);
|
||||
|
||||
OwningExprResult InstantiateExpr(Expr *E,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
Decl *InstantiateDecl(Decl *D, DeclContext *Owner,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
bool
|
||||
InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation,
|
||||
CXXRecordDecl *Pattern,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
bool
|
||||
InstantiateClass(SourceLocation PointOfInstantiation,
|
||||
CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
bool
|
||||
InstantiateClassTemplateSpecialization(
|
||||
|
@ -2106,13 +2102,11 @@ public:
|
|||
NestedNameSpecifier *
|
||||
InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
|
||||
SourceRange Range,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
TemplateName
|
||||
InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs);
|
||||
|
||||
// Simple function for cloning expressions.
|
||||
template<typename T>
|
||||
|
|
|
@ -993,7 +993,11 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
|
|||
Template, &Converted[0],
|
||||
Converted.size(),
|
||||
SourceRange(TemplateLoc, RAngleLoc));
|
||||
ArgType = InstantiateType(ArgType, &Converted[0], Converted.size(),
|
||||
|
||||
TemplateArgumentList TemplateArgs(Context, &Converted[0],
|
||||
Converted.size(),
|
||||
/*CopyArgs=*/false);
|
||||
ArgType = InstantiateType(ArgType, TemplateArgs,
|
||||
TTP->getDefaultArgumentLoc(),
|
||||
TTP->getDeclName());
|
||||
}
|
||||
|
@ -1061,8 +1065,10 @@ bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
|
|||
Converted.size(),
|
||||
SourceRange(TemplateLoc, RAngleLoc));
|
||||
|
||||
NTTPType = InstantiateType(NTTPType,
|
||||
&Converted[0], Converted.size(),
|
||||
TemplateArgumentList TemplateArgs(Context, &Converted[0],
|
||||
Converted.size(),
|
||||
/*CopyArgs=*/false);
|
||||
NTTPType = InstantiateType(NTTPType, TemplateArgs,
|
||||
NTTP->getLocation(),
|
||||
NTTP->getDeclName());
|
||||
// If that worked, check the non-type template parameter type
|
||||
|
|
|
@ -133,19 +133,17 @@ void Sema::PrintInstantiationStack() {
|
|||
namespace {
|
||||
class VISIBILITY_HIDDEN TemplateTypeInstantiator {
|
||||
Sema &SemaRef;
|
||||
const TemplateArgument *TemplateArgs;
|
||||
unsigned NumTemplateArgs;
|
||||
const TemplateArgumentList &TemplateArgs;
|
||||
SourceLocation Loc;
|
||||
DeclarationName Entity;
|
||||
|
||||
public:
|
||||
TemplateTypeInstantiator(Sema &SemaRef,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
const TemplateArgumentList &TemplateArgs,
|
||||
SourceLocation Loc,
|
||||
DeclarationName Entity)
|
||||
: SemaRef(SemaRef), TemplateArgs(TemplateArgs),
|
||||
NumTemplateArgs(NumTemplateArgs), Loc(Loc), Entity(Entity) { }
|
||||
Loc(Loc), Entity(Entity) { }
|
||||
|
||||
QualType operator()(QualType T) const { return Instantiate(T); }
|
||||
|
||||
|
@ -298,7 +296,7 @@ InstantiateDependentSizedArrayType(const DependentSizedArrayType *T,
|
|||
|
||||
// Instantiate the size expression
|
||||
Sema::OwningExprResult InstantiatedArraySize =
|
||||
SemaRef.InstantiateExpr(ArraySize, TemplateArgs, NumTemplateArgs);
|
||||
SemaRef.InstantiateExpr(ArraySize, TemplateArgs);
|
||||
if (InstantiatedArraySize.isInvalid())
|
||||
return QualType();
|
||||
|
||||
|
@ -403,7 +401,6 @@ InstantiateTemplateTypeParmType(const TemplateTypeParmType *T,
|
|||
if (T->getDepth() == 0) {
|
||||
// Replace the template type parameter with its corresponding
|
||||
// template argument.
|
||||
assert(T->getIndex() < NumTemplateArgs && "Wrong # of template args");
|
||||
assert(TemplateArgs[T->getIndex()].getKind() == TemplateArgument::Type &&
|
||||
"Template argument kind mismatch");
|
||||
QualType Result = TemplateArgs[T->getIndex()].getAsType();
|
||||
|
@ -443,7 +440,7 @@ InstantiateTemplateSpecializationType(
|
|||
switch (Arg->getKind()) {
|
||||
case TemplateArgument::Type: {
|
||||
QualType T = SemaRef.InstantiateType(Arg->getAsType(),
|
||||
TemplateArgs, NumTemplateArgs,
|
||||
TemplateArgs,
|
||||
Arg->getLocation(),
|
||||
DeclarationName());
|
||||
if (T.isNull())
|
||||
|
@ -461,8 +458,7 @@ InstantiateTemplateSpecializationType(
|
|||
|
||||
case TemplateArgument::Expression:
|
||||
Sema::OwningExprResult E
|
||||
= SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs,
|
||||
NumTemplateArgs);
|
||||
= SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs);
|
||||
if (E.isInvalid())
|
||||
return QualType();
|
||||
InstantiatedTemplateArgs.push_back(E.takeAs<Expr>());
|
||||
|
@ -475,8 +471,7 @@ InstantiateTemplateSpecializationType(
|
|||
|
||||
TemplateName Name = SemaRef.InstantiateTemplateName(T->getTemplateName(),
|
||||
Loc,
|
||||
TemplateArgs,
|
||||
NumTemplateArgs);
|
||||
TemplateArgs);
|
||||
|
||||
return SemaRef.CheckTemplateIdType(Name, Loc, SourceLocation(),
|
||||
&InstantiatedTemplateArgs[0],
|
||||
|
@ -509,7 +504,7 @@ InstantiateTypenameType(const TypenameType *T, unsigned Quals) const {
|
|||
NestedNameSpecifier *NNS
|
||||
= SemaRef.InstantiateNestedNameSpecifier(T->getQualifier(),
|
||||
SourceRange(Loc),
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
TemplateArgs);
|
||||
if (!NNS)
|
||||
return QualType();
|
||||
|
||||
|
@ -571,9 +566,6 @@ QualType TemplateTypeInstantiator::Instantiate(QualType T) const {
|
|||
/// \param TemplateArgs the template arguments that will be
|
||||
/// substituted for the top-level template parameters within T.
|
||||
///
|
||||
/// \param NumTemplateArgs the number of template arguments provided
|
||||
/// by TemplateArgs.
|
||||
///
|
||||
/// \param Loc the location in the source code where this substitution
|
||||
/// is being performed. It will typically be the location of the
|
||||
/// declarator (if we're instantiating the type of some declaration)
|
||||
|
@ -589,8 +581,7 @@ QualType TemplateTypeInstantiator::Instantiate(QualType T) const {
|
|||
/// \returns If the instantiation succeeds, the instantiated
|
||||
/// type. Otherwise, produces diagnostics and returns a NULL type.
|
||||
QualType Sema::InstantiateType(QualType T,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs,
|
||||
const TemplateArgumentList &TemplateArgs,
|
||||
SourceLocation Loc, DeclarationName Entity) {
|
||||
assert(!ActiveTemplateInstantiations.empty() &&
|
||||
"Cannot perform an instantiation without some context on the "
|
||||
|
@ -600,8 +591,7 @@ QualType Sema::InstantiateType(QualType T,
|
|||
if (!T->isDependentType())
|
||||
return T;
|
||||
|
||||
TemplateTypeInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs,
|
||||
Loc, Entity);
|
||||
TemplateTypeInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
|
||||
return Instantiator(T);
|
||||
}
|
||||
|
||||
|
@ -614,8 +604,7 @@ QualType Sema::InstantiateType(QualType T,
|
|||
bool
|
||||
Sema::InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation,
|
||||
CXXRecordDecl *Pattern,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
const TemplateArgumentList &TemplateArgs) {
|
||||
bool Invalid = false;
|
||||
llvm::SmallVector<CXXBaseSpecifier*, 8> InstantiatedBases;
|
||||
for (ClassTemplateSpecializationDecl::base_class_iterator
|
||||
|
@ -628,7 +617,7 @@ Sema::InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation,
|
|||
}
|
||||
|
||||
QualType BaseType = InstantiateType(Base->getType(),
|
||||
TemplateArgs, NumTemplateArgs,
|
||||
TemplateArgs,
|
||||
Base->getSourceRange().getBegin(),
|
||||
DeclarationName());
|
||||
if (BaseType.isNull()) {
|
||||
|
@ -673,15 +662,11 @@ Sema::InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation,
|
|||
/// \param TemplateArgs The template arguments to be substituted into
|
||||
/// the pattern.
|
||||
///
|
||||
/// \param NumTemplateArgs The number of templates arguments in
|
||||
/// TemplateArgs.
|
||||
///
|
||||
/// \returns true if an error occurred, false otherwise.
|
||||
bool
|
||||
Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
||||
CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
const TemplateArgumentList &TemplateArgs) {
|
||||
bool Invalid = false;
|
||||
|
||||
CXXRecordDecl *PatternDef
|
||||
|
@ -715,16 +700,14 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
|||
Instantiation->startDefinition();
|
||||
|
||||
// Instantiate the base class specifiers.
|
||||
if (InstantiateBaseSpecifiers(Instantiation, Pattern, TemplateArgs,
|
||||
NumTemplateArgs))
|
||||
if (InstantiateBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
|
||||
Invalid = true;
|
||||
|
||||
llvm::SmallVector<DeclPtrTy, 32> Fields;
|
||||
for (RecordDecl::decl_iterator Member = Pattern->decls_begin(Context),
|
||||
MemberEnd = Pattern->decls_end(Context);
|
||||
Member != MemberEnd; ++Member) {
|
||||
Decl *NewMember = InstantiateDecl(*Member, Instantiation,
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
Decl *NewMember = InstantiateDecl(*Member, Instantiation, TemplateArgs);
|
||||
if (NewMember) {
|
||||
if (NewMember->isInvalidDecl())
|
||||
Invalid = true;
|
||||
|
@ -783,21 +766,18 @@ Sema::InstantiateClassTemplateSpecialization(
|
|||
|
||||
return InstantiateClass(ClassTemplateSpec->getLocation(),
|
||||
ClassTemplateSpec, Pattern,
|
||||
ClassTemplateSpec->getTemplateArgs(),
|
||||
ClassTemplateSpec->getNumTemplateArgs());
|
||||
ClassTemplateSpec->getTemplateArgs());
|
||||
}
|
||||
|
||||
/// \brief Instantiate a nested-name-specifier.
|
||||
NestedNameSpecifier *
|
||||
Sema::InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
|
||||
SourceRange Range,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
const TemplateArgumentList &TemplateArgs) {
|
||||
// Instantiate the prefix of this nested name specifier.
|
||||
NestedNameSpecifier *Prefix = NNS->getPrefix();
|
||||
if (Prefix) {
|
||||
Prefix = InstantiateNestedNameSpecifier(Prefix, Range, TemplateArgs,
|
||||
NumTemplateArgs);
|
||||
Prefix = InstantiateNestedNameSpecifier(Prefix, Range, TemplateArgs);
|
||||
if (!Prefix)
|
||||
return 0;
|
||||
}
|
||||
|
@ -828,8 +808,7 @@ Sema::InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
|
|||
if (!T->isDependentType())
|
||||
return NNS;
|
||||
|
||||
T = InstantiateType(T, TemplateArgs, NumTemplateArgs, Range.getBegin(),
|
||||
DeclarationName());
|
||||
T = InstantiateType(T, TemplateArgs, Range.getBegin(), DeclarationName());
|
||||
if (T.isNull())
|
||||
return 0;
|
||||
|
||||
|
@ -852,14 +831,12 @@ Sema::InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
|
|||
|
||||
TemplateName
|
||||
Sema::InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
const TemplateArgumentList &TemplateArgs) {
|
||||
if (TemplateTemplateParmDecl *TTP
|
||||
= dyn_cast_or_null<TemplateTemplateParmDecl>(
|
||||
Name.getAsTemplateDecl())) {
|
||||
assert(TTP->getDepth() == 0 &&
|
||||
"Cannot reduce depth of a template template parameter");
|
||||
assert(TTP->getPosition() < NumTemplateArgs && "Wrong # of template args");
|
||||
assert(TemplateArgs[TTP->getPosition()].getAsDecl() &&
|
||||
"Wrong kind of template template argument");
|
||||
ClassTemplateDecl *ClassTemplate
|
||||
|
@ -870,7 +847,7 @@ Sema::InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
|
|||
NestedNameSpecifier *NNS
|
||||
= InstantiateNestedNameSpecifier(QTN->getQualifier(),
|
||||
/*FIXME=*/SourceRange(Loc),
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
TemplateArgs);
|
||||
if (NNS)
|
||||
return Context.getQualifiedTemplateName(NNS,
|
||||
QTN->hasTemplateKeyword(),
|
||||
|
@ -882,7 +859,7 @@ Sema::InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
|
|||
NestedNameSpecifier *NNS
|
||||
= InstantiateNestedNameSpecifier(DTN->getQualifier(),
|
||||
/*FIXME=*/SourceRange(Loc),
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
TemplateArgs);
|
||||
|
||||
if (!NNS) // FIXME: Not the best recovery strategy.
|
||||
return Name;
|
||||
|
|
|
@ -23,17 +23,14 @@ namespace {
|
|||
: public DeclVisitor<TemplateDeclInstantiator, Decl *> {
|
||||
Sema &SemaRef;
|
||||
DeclContext *Owner;
|
||||
const TemplateArgument *TemplateArgs;
|
||||
unsigned NumTemplateArgs;
|
||||
const TemplateArgumentList &TemplateArgs;
|
||||
|
||||
public:
|
||||
typedef Sema::OwningExprResult OwningExprResult;
|
||||
|
||||
TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs)
|
||||
: SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs),
|
||||
NumTemplateArgs(NumTemplateArgs) { }
|
||||
const TemplateArgumentList &TemplateArgs)
|
||||
: SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs) { }
|
||||
|
||||
// FIXME: Once we get closer to completion, replace these
|
||||
// manually-written declarations with automatically-generated ones
|
||||
|
@ -83,8 +80,7 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
|
|||
bool Invalid = false;
|
||||
QualType T = D->getUnderlyingType();
|
||||
if (T->isDependentType()) {
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
|
||||
D->getLocation(),
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, D->getLocation(),
|
||||
D->getDeclName());
|
||||
if (T.isNull()) {
|
||||
Invalid = true;
|
||||
|
@ -106,7 +102,6 @@ Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
|
|||
Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
|
||||
// Instantiate the type of the declaration
|
||||
QualType T = SemaRef.InstantiateType(D->getType(), TemplateArgs,
|
||||
NumTemplateArgs,
|
||||
D->getTypeSpecStartLoc(),
|
||||
D->getDeclName());
|
||||
if (T.isNull())
|
||||
|
@ -129,7 +124,7 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
|
|||
|
||||
if (D->getInit()) {
|
||||
OwningExprResult Init
|
||||
= SemaRef.InstantiateExpr(D->getInit(), TemplateArgs, NumTemplateArgs);
|
||||
= SemaRef.InstantiateExpr(D->getInit(), TemplateArgs);
|
||||
if (Init.isInvalid())
|
||||
Var->setInvalidDecl();
|
||||
else
|
||||
|
@ -144,8 +139,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
|
|||
bool Invalid = false;
|
||||
QualType T = D->getType();
|
||||
if (T->isDependentType()) {
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
|
||||
D->getLocation(),
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, D->getLocation(),
|
||||
D->getDeclName());
|
||||
if (!T.isNull() && T->isFunctionType()) {
|
||||
// C++ [temp.arg.type]p3:
|
||||
|
@ -166,7 +160,7 @@ Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
|
|||
BitWidth = 0;
|
||||
else if (BitWidth) {
|
||||
OwningExprResult InstantiatedBitWidth
|
||||
= SemaRef.InstantiateExpr(BitWidth, TemplateArgs, NumTemplateArgs);
|
||||
= SemaRef.InstantiateExpr(BitWidth, TemplateArgs);
|
||||
if (InstantiatedBitWidth.isInvalid()) {
|
||||
Invalid = true;
|
||||
BitWidth = 0;
|
||||
|
@ -195,7 +189,7 @@ Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) {
|
|||
Expr *AssertExpr = D->getAssertExpr();
|
||||
|
||||
OwningExprResult InstantiatedAssertExpr
|
||||
= SemaRef.InstantiateExpr(AssertExpr, TemplateArgs, NumTemplateArgs);
|
||||
= SemaRef.InstantiateExpr(AssertExpr, TemplateArgs);
|
||||
if (InstantiatedAssertExpr.isInvalid())
|
||||
return 0;
|
||||
|
||||
|
@ -224,8 +218,7 @@ Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
|
|||
// The specified value for the enumerator.
|
||||
OwningExprResult Value = SemaRef.Owned((Expr *)0);
|
||||
if (Expr *UninstValue = EC->getInitExpr())
|
||||
Value = SemaRef.InstantiateExpr(UninstValue,
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
Value = SemaRef.InstantiateExpr(UninstValue, TemplateArgs);
|
||||
|
||||
// Drop the initial value and continue.
|
||||
bool isInvalid = false;
|
||||
|
@ -425,8 +418,7 @@ Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) {
|
|||
|
||||
ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
|
||||
QualType OrigT = SemaRef.InstantiateType(D->getOriginalType(), TemplateArgs,
|
||||
NumTemplateArgs, D->getLocation(),
|
||||
D->getDeclName());
|
||||
D->getLocation(), D->getDeclName());
|
||||
if (OrigT.isNull())
|
||||
return 0;
|
||||
|
||||
|
@ -469,10 +461,8 @@ TemplateDeclInstantiator::VisitOriginalParmVarDecl(OriginalParmVarDecl *D) {
|
|||
}
|
||||
|
||||
Decl *Sema::InstantiateDecl(Decl *D, DeclContext *Owner,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs,
|
||||
NumTemplateArgs);
|
||||
const TemplateArgumentList &TemplateArgs) {
|
||||
TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
|
||||
return Instantiator.Visit(D);
|
||||
}
|
||||
|
||||
|
@ -491,8 +481,7 @@ TemplateDeclInstantiator::InstantiateFunctionType(FunctionDecl *D,
|
|||
bool InvalidDecl = false;
|
||||
|
||||
// Instantiate the function parameters
|
||||
TemplateDeclInstantiator ParamInstantiator(SemaRef, 0,
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
TemplateDeclInstantiator ParamInstantiator(SemaRef, 0, TemplateArgs);
|
||||
llvm::SmallVector<QualType, 16> ParamTys;
|
||||
for (FunctionDecl::param_iterator P = D->param_begin(),
|
||||
PEnd = D->param_end();
|
||||
|
@ -524,8 +513,7 @@ TemplateDeclInstantiator::InstantiateFunctionType(FunctionDecl *D,
|
|||
const FunctionProtoType *Proto = D->getType()->getAsFunctionProtoType();
|
||||
assert(Proto && "Missing prototype?");
|
||||
QualType ResultType
|
||||
= SemaRef.InstantiateType(Proto->getResultType(),
|
||||
TemplateArgs, NumTemplateArgs,
|
||||
= SemaRef.InstantiateType(Proto->getResultType(), TemplateArgs,
|
||||
D->getLocation(), D->getDeclName());
|
||||
if (ResultType.isNull())
|
||||
return QualType();
|
||||
|
|
|
@ -24,17 +24,14 @@ namespace {
|
|||
class VISIBILITY_HIDDEN TemplateExprInstantiator
|
||||
: public StmtVisitor<TemplateExprInstantiator, Sema::OwningExprResult> {
|
||||
Sema &SemaRef;
|
||||
const TemplateArgument *TemplateArgs;
|
||||
unsigned NumTemplateArgs;
|
||||
const TemplateArgumentList &TemplateArgs;
|
||||
|
||||
public:
|
||||
typedef Sema::OwningExprResult OwningExprResult;
|
||||
|
||||
TemplateExprInstantiator(Sema &SemaRef,
|
||||
const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs)
|
||||
: SemaRef(SemaRef), TemplateArgs(TemplateArgs),
|
||||
NumTemplateArgs(NumTemplateArgs) { }
|
||||
const TemplateArgumentList &TemplateArgs)
|
||||
: SemaRef(SemaRef), TemplateArgs(TemplateArgs) { }
|
||||
|
||||
// FIXME: Once we get closer to completion, replace these
|
||||
// manually-written declarations with automatically-generated ones
|
||||
|
@ -294,7 +291,7 @@ TemplateExprInstantiator::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
|
|||
if (E->isArgumentType()) {
|
||||
QualType T = E->getArgumentType();
|
||||
if (T->isDependentType()) {
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs,
|
||||
/*FIXME*/E->getOperatorLoc(),
|
||||
&SemaRef.PP.getIdentifierTable().get("sizeof"));
|
||||
if (T.isNull())
|
||||
|
@ -324,7 +321,7 @@ TemplateExprInstantiator::VisitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *E) {
|
|||
NestedNameSpecifier *NNS
|
||||
= SemaRef.InstantiateNestedNameSpecifier(E->getQualifier(),
|
||||
E->getQualifierRange(),
|
||||
TemplateArgs, NumTemplateArgs);
|
||||
TemplateArgs);
|
||||
if (!NNS)
|
||||
return SemaRef.ExprError();
|
||||
|
||||
|
@ -348,7 +345,7 @@ TemplateExprInstantiator::VisitCXXTemporaryObjectExpr(
|
|||
CXXTemporaryObjectExpr *E) {
|
||||
QualType T = E->getType();
|
||||
if (T->isDependentType()) {
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs, NumTemplateArgs,
|
||||
T = SemaRef.InstantiateType(T, TemplateArgs,
|
||||
E->getTypeBeginLoc(), DeclarationName());
|
||||
if (T.isNull())
|
||||
return SemaRef.ExprError();
|
||||
|
@ -413,8 +410,7 @@ Sema::OwningExprResult TemplateExprInstantiator::VisitImplicitCastExpr(
|
|||
}
|
||||
|
||||
Sema::OwningExprResult
|
||||
Sema::InstantiateExpr(Expr *E, const TemplateArgument *TemplateArgs,
|
||||
unsigned NumTemplateArgs) {
|
||||
TemplateExprInstantiator Instantiator(*this, TemplateArgs, NumTemplateArgs);
|
||||
Sema::InstantiateExpr(Expr *E, const TemplateArgumentList &TemplateArgs) {
|
||||
TemplateExprInstantiator Instantiator(*this, TemplateArgs);
|
||||
return Instantiator.Visit(E);
|
||||
}
|
||||
|
|
|
@ -1115,9 +1115,7 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
|
|||
Parent && !Spec; Parent = Parent->getParent())
|
||||
Spec = dyn_cast<ClassTemplateSpecializationDecl>(Parent);
|
||||
assert(Spec && "Not a member of a class template specialization?");
|
||||
return InstantiateClass(Loc, Rec, Pattern,
|
||||
Spec->getTemplateArgs(),
|
||||
Spec->getNumTemplateArgs());
|
||||
return InstantiateClass(Loc, Rec, Pattern, Spec->getTemplateArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue