[AST] Use ArrayRef in more interfaces

ArrayRef is a little better than passing around a pointer/length
pair.

No functional change is intended.

llvm-svn: 274732
This commit is contained in:
David Majnemer 2016-07-07 04:43:07 +00:00
parent 00639bc529
commit 6fbeee307e
23 changed files with 179 additions and 202 deletions

View File

@ -1237,13 +1237,12 @@ public:
TemplateTypeParmDecl *ParmDecl = nullptr) const; TemplateTypeParmDecl *ParmDecl = nullptr) const;
QualType getTemplateSpecializationType(TemplateName T, QualType getTemplateSpecializationType(TemplateName T,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs,
QualType Canon = QualType()) const; QualType Canon = QualType()) const;
QualType getCanonicalTemplateSpecializationType(TemplateName T, QualType
const TemplateArgument *Args, getCanonicalTemplateSpecializationType(TemplateName T,
unsigned NumArgs) const; ArrayRef<TemplateArgument> Args) const;
QualType getTemplateSpecializationType(TemplateName T, QualType getTemplateSpecializationType(TemplateName T,
const TemplateArgumentListInfo &Args, const TemplateArgumentListInfo &Args,
@ -1268,11 +1267,9 @@ public:
NestedNameSpecifier *NNS, NestedNameSpecifier *NNS,
const IdentifierInfo *Name, const IdentifierInfo *Name,
const TemplateArgumentListInfo &Args) const; const TemplateArgumentListInfo &Args) const;
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, QualType getDependentTemplateSpecializationType(
NestedNameSpecifier *NNS, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
const IdentifierInfo *Name, const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args) const;
unsigned NumArgs,
const TemplateArgument *Args) const;
QualType getPackExpansionType(QualType Pattern, QualType getPackExpansionType(QualType Pattern,
Optional<unsigned> NumExpansions); Optional<unsigned> NumExpansions);

View File

@ -1120,6 +1120,10 @@ public:
return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
} }
ArrayRef<TemplateArgumentLoc> template_arguments() const {
return {getTemplateArgs(), getNumTemplateArgs()};
}
/// \brief Returns true if this expression refers to a function that /// \brief Returns true if this expression refers to a function that
/// was resolved from an overloaded set having size greater than 1. /// was resolved from an overloaded set having size greater than 1.
bool hadMultipleCandidates() const { bool hadMultipleCandidates() const {
@ -2491,6 +2495,10 @@ public:
return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
} }
ArrayRef<TemplateArgumentLoc> template_arguments() const {
return {getTemplateArgs(), getNumTemplateArgs()};
}
/// \brief Retrieve the member declaration name info. /// \brief Retrieve the member declaration name info.
DeclarationNameInfo getMemberNameInfo() const { DeclarationNameInfo getMemberNameInfo() const {
return DeclarationNameInfo(MemberDecl->getDeclName(), return DeclarationNameInfo(MemberDecl->getDeclName(),

View File

@ -2638,6 +2638,10 @@ public:
return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs; return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs;
} }
ArrayRef<TemplateArgumentLoc> template_arguments() const {
return {getTemplateArgs(), getNumTemplateArgs()};
}
/// \brief Copies the template arguments into the given structure. /// \brief Copies the template arguments into the given structure.
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
if (hasExplicitTemplateArgs()) if (hasExplicitTemplateArgs())
@ -2891,6 +2895,10 @@ public:
return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
} }
ArrayRef<TemplateArgumentLoc> template_arguments() const {
return {getTemplateArgs(), getNumTemplateArgs()};
}
/// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr, /// Note: getLocStart() is the start of the whole DependentScopeDeclRefExpr,
/// and differs from getLocation().getStart(). /// and differs from getLocation().getStart().
SourceLocation getLocStart() const LLVM_READONLY { SourceLocation getLocStart() const LLVM_READONLY {
@ -3306,6 +3314,10 @@ public:
return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
} }
ArrayRef<TemplateArgumentLoc> template_arguments() const {
return {getTemplateArgs(), getNumTemplateArgs()};
}
SourceLocation getLocStart() const LLVM_READONLY { SourceLocation getLocStart() const LLVM_READONLY {
if (!isImplicitAccess()) if (!isImplicitAccess())
return Base->getLocStart(); return Base->getLocStart();

View File

@ -4171,16 +4171,15 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) TemplateSpecializationType
bool TypeAlias : 1; bool TypeAlias : 1;
TemplateSpecializationType(TemplateName T, TemplateSpecializationType(TemplateName T,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs, QualType Canon, QualType Canon,
QualType Aliased); QualType Aliased);
friend class ASTContext; // ASTContext creates these friend class ASTContext; // ASTContext creates these
public: public:
/// Determine whether any of the given template arguments are dependent. /// Determine whether any of the given template arguments are dependent.
static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args, static bool anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
unsigned NumArgs,
bool &InstantiationDependent); bool &InstantiationDependent);
static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &, static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
@ -4189,14 +4188,12 @@ public:
/// \brief Print a template argument list, including the '<' and '>' /// \brief Print a template argument list, including the '<' and '>'
/// enclosing the template arguments. /// enclosing the template arguments.
static void PrintTemplateArgumentList(raw_ostream &OS, static void PrintTemplateArgumentList(raw_ostream &OS,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs,
const PrintingPolicy &Policy, const PrintingPolicy &Policy,
bool SkipBrackets = false); bool SkipBrackets = false);
static void PrintTemplateArgumentList(raw_ostream &OS, static void PrintTemplateArgumentList(raw_ostream &OS,
const TemplateArgumentLoc *Args, ArrayRef<TemplateArgumentLoc> Args,
unsigned NumArgs,
const PrintingPolicy &Policy); const PrintingPolicy &Policy);
static void PrintTemplateArgumentList(raw_ostream &OS, static void PrintTemplateArgumentList(raw_ostream &OS,
@ -4253,20 +4250,23 @@ public:
/// \pre \c isArgType(Arg) /// \pre \c isArgType(Arg)
const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
ArrayRef<TemplateArgument> template_arguments() const {
return {getArgs(), NumArgs};
}
bool isSugared() const { bool isSugared() const {
return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
} }
QualType desugar() const { return getCanonicalTypeInternal(); } QualType desugar() const { return getCanonicalTypeInternal(); }
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
Profile(ID, Template, getArgs(), NumArgs, Ctx); Profile(ID, Template, template_arguments(), Ctx);
if (isTypeAlias()) if (isTypeAlias())
getAliasedType().Profile(ID); getAliasedType().Profile(ID);
} }
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs,
const ASTContext &Context); const ASTContext &Context);
static bool classof(const Type *T) { static bool classof(const Type *T) {
@ -4570,8 +4570,7 @@ class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) DependentTemplateSpecializationType
DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS, NestedNameSpecifier *NNS,
const IdentifierInfo *Name, const IdentifierInfo *Name,
unsigned NumArgs, ArrayRef<TemplateArgument> Args,
const TemplateArgument *Args,
QualType Canon); QualType Canon);
friend class ASTContext; // ASTContext creates these friend class ASTContext; // ASTContext creates these
@ -4590,6 +4589,10 @@ public:
const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
ArrayRef<TemplateArgument> template_arguments() const {
return {getArgs(), NumArgs};
}
typedef const TemplateArgument * iterator; typedef const TemplateArgument * iterator;
iterator begin() const { return getArgs(); } iterator begin() const { return getArgs(); }
iterator end() const; // inline in TemplateBase.h iterator end() const; // inline in TemplateBase.h
@ -4598,7 +4601,7 @@ public:
QualType desugar() const { return QualType(this, 0); } QualType desugar() const { return QualType(this, 0); }
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs()); Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), NumArgs});
} }
static void Profile(llvm::FoldingSetNodeID &ID, static void Profile(llvm::FoldingSetNodeID &ID,
@ -4606,8 +4609,7 @@ public:
ElaboratedTypeKeyword Keyword, ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *Qualifier, NestedNameSpecifier *Qualifier,
const IdentifierInfo *Name, const IdentifierInfo *Name,
unsigned NumArgs, ArrayRef<TemplateArgument> Args);
const TemplateArgument *Args);
static bool classof(const Type *T) { static bool classof(const Type *T) {
return T->getTypeClass() == DependentTemplateSpecialization; return T->getTypeClass() == DependentTemplateSpecialization;

View File

@ -6662,6 +6662,10 @@ public:
/// \brief The number of template arguments in TemplateArgs. /// \brief The number of template arguments in TemplateArgs.
unsigned NumTemplateArgs; unsigned NumTemplateArgs;
ArrayRef<TemplateArgument> template_arguments() const {
return {TemplateArgs, NumTemplateArgs};
}
/// \brief The template deduction info object associated with the /// \brief The template deduction info object associated with the
/// substitution or checking of explicit or deduced template arguments. /// substitution or checking of explicit or deduced template arguments.
sema::TemplateDeductionInfo *DeductionInfo; sema::TemplateDeductionInfo *DeductionInfo;

View File

@ -3393,23 +3393,19 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,
QualType Underlying) const { QualType Underlying) const {
assert(!Template.getAsDependentTemplateName() && assert(!Template.getAsDependentTemplateName() &&
"No dependent template names here!"); "No dependent template names here!");
unsigned NumArgs = Args.size();
SmallVector<TemplateArgument, 4> ArgVec; SmallVector<TemplateArgument, 4> ArgVec;
ArgVec.reserve(NumArgs); ArgVec.reserve(Args.size());
for (unsigned i = 0; i != NumArgs; ++i) for (const TemplateArgumentLoc &Arg : Args.arguments())
ArgVec.push_back(Args[i].getArgument()); ArgVec.push_back(Arg.getArgument());
return getTemplateSpecializationType(Template, ArgVec.data(), NumArgs, return getTemplateSpecializationType(Template, ArgVec, Underlying);
Underlying);
} }
#ifndef NDEBUG #ifndef NDEBUG
static bool hasAnyPackExpansions(const TemplateArgument *Args, static bool hasAnyPackExpansions(ArrayRef<TemplateArgument> Args) {
unsigned NumArgs) { for (const TemplateArgument &Arg : Args)
for (unsigned I = 0; I != NumArgs; ++I) if (Arg.isPackExpansion())
if (Args[I].isPackExpansion())
return true; return true;
return true; return true;
@ -3418,8 +3414,7 @@ static bool hasAnyPackExpansions(const TemplateArgument *Args,
QualType QualType
ASTContext::getTemplateSpecializationType(TemplateName Template, ASTContext::getTemplateSpecializationType(TemplateName Template,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs,
QualType Underlying) const { QualType Underlying) const {
assert(!Template.getAsDependentTemplateName() && assert(!Template.getAsDependentTemplateName() &&
"No dependent template names here!"); "No dependent template names here!");
@ -3436,32 +3431,29 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,
else { else {
// We can get here with an alias template when the specialization contains // We can get here with an alias template when the specialization contains
// a pack expansion that does not match up with a parameter pack. // a pack expansion that does not match up with a parameter pack.
assert((!IsTypeAlias || hasAnyPackExpansions(Args, NumArgs)) && assert((!IsTypeAlias || hasAnyPackExpansions(Args)) &&
"Caller must compute aliased type"); "Caller must compute aliased type");
IsTypeAlias = false; IsTypeAlias = false;
CanonType = getCanonicalTemplateSpecializationType(Template, Args, CanonType = getCanonicalTemplateSpecializationType(Template, Args);
NumArgs);
} }
// Allocate the (non-canonical) template specialization type, but don't // Allocate the (non-canonical) template specialization type, but don't
// try to unique it: these types typically have location information that // try to unique it: these types typically have location information that
// we don't unique and don't want to lose. // we don't unique and don't want to lose.
void *Mem = Allocate(sizeof(TemplateSpecializationType) + void *Mem = Allocate(sizeof(TemplateSpecializationType) +
sizeof(TemplateArgument) * NumArgs + sizeof(TemplateArgument) * Args.size() +
(IsTypeAlias? sizeof(QualType) : 0), (IsTypeAlias? sizeof(QualType) : 0),
TypeAlignment); TypeAlignment);
TemplateSpecializationType *Spec TemplateSpecializationType *Spec
= new (Mem) TemplateSpecializationType(Template, Args, NumArgs, CanonType, = new (Mem) TemplateSpecializationType(Template, Args, CanonType,
IsTypeAlias ? Underlying : QualType()); IsTypeAlias ? Underlying : QualType());
Types.push_back(Spec); Types.push_back(Spec);
return QualType(Spec, 0); return QualType(Spec, 0);
} }
QualType QualType ASTContext::getCanonicalTemplateSpecializationType(
ASTContext::getCanonicalTemplateSpecializationType(TemplateName Template, TemplateName Template, ArrayRef<TemplateArgument> Args) const {
const TemplateArgument *Args,
unsigned NumArgs) const {
assert(!Template.getAsDependentTemplateName() && assert(!Template.getAsDependentTemplateName() &&
"No dependent template names here!"); "No dependent template names here!");
@ -3472,15 +3464,16 @@ ASTContext::getCanonicalTemplateSpecializationType(TemplateName Template,
// Build the canonical template specialization type. // Build the canonical template specialization type.
TemplateName CanonTemplate = getCanonicalTemplateName(Template); TemplateName CanonTemplate = getCanonicalTemplateName(Template);
SmallVector<TemplateArgument, 4> CanonArgs; SmallVector<TemplateArgument, 4> CanonArgs;
unsigned NumArgs = Args.size();
CanonArgs.reserve(NumArgs); CanonArgs.reserve(NumArgs);
for (unsigned I = 0; I != NumArgs; ++I) for (const TemplateArgument &Arg : Args)
CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); CanonArgs.push_back(getCanonicalTemplateArgument(Arg));
// Determine whether this canonical template specialization type already // Determine whether this canonical template specialization type already
// exists. // exists.
llvm::FoldingSetNodeID ID; llvm::FoldingSetNodeID ID;
TemplateSpecializationType::Profile(ID, CanonTemplate, TemplateSpecializationType::Profile(ID, CanonTemplate,
CanonArgs.data(), NumArgs, *this); CanonArgs, *this);
void *InsertPos = nullptr; void *InsertPos = nullptr;
TemplateSpecializationType *Spec TemplateSpecializationType *Spec
@ -3492,7 +3485,7 @@ ASTContext::getCanonicalTemplateSpecializationType(TemplateName Template,
sizeof(TemplateArgument) * NumArgs), sizeof(TemplateArgument) * NumArgs),
TypeAlignment); TypeAlignment);
Spec = new (Mem) TemplateSpecializationType(CanonTemplate, Spec = new (Mem) TemplateSpecializationType(CanonTemplate,
CanonArgs.data(), NumArgs, CanonArgs,
QualType(), QualType()); QualType(), QualType());
Types.push_back(Spec); Types.push_back(Spec);
TemplateSpecializationTypes.InsertNode(Spec, InsertPos); TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
@ -3592,9 +3585,7 @@ ASTContext::getDependentTemplateSpecializationType(
SmallVector<TemplateArgument, 16> ArgCopy; SmallVector<TemplateArgument, 16> ArgCopy;
for (unsigned I = 0, E = Args.size(); I != E; ++I) for (unsigned I = 0, E = Args.size(); I != E; ++I)
ArgCopy.push_back(Args[I].getArgument()); ArgCopy.push_back(Args[I].getArgument());
return getDependentTemplateSpecializationType(Keyword, NNS, Name, return getDependentTemplateSpecializationType(Keyword, NNS, Name, ArgCopy);
ArgCopy.size(),
ArgCopy.data());
} }
QualType QualType
@ -3602,14 +3593,13 @@ ASTContext::getDependentTemplateSpecializationType(
ElaboratedTypeKeyword Keyword, ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS, NestedNameSpecifier *NNS,
const IdentifierInfo *Name, const IdentifierInfo *Name,
unsigned NumArgs, ArrayRef<TemplateArgument> Args) const {
const TemplateArgument *Args) const {
assert((!NNS || NNS->isDependent()) && assert((!NNS || NNS->isDependent()) &&
"nested-name-specifier must be dependent"); "nested-name-specifier must be dependent");
llvm::FoldingSetNodeID ID; llvm::FoldingSetNodeID ID;
DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS, DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS,
Name, NumArgs, Args); Name, Args);
void *InsertPos = nullptr; void *InsertPos = nullptr;
DependentTemplateSpecializationType *T DependentTemplateSpecializationType *T
@ -3623,6 +3613,7 @@ ASTContext::getDependentTemplateSpecializationType(
if (Keyword == ETK_None) CanonKeyword = ETK_Typename; if (Keyword == ETK_None) CanonKeyword = ETK_Typename;
bool AnyNonCanonArgs = false; bool AnyNonCanonArgs = false;
unsigned NumArgs = Args.size();
SmallVector<TemplateArgument, 16> CanonArgs(NumArgs); SmallVector<TemplateArgument, 16> CanonArgs(NumArgs);
for (unsigned I = 0; I != NumArgs; ++I) { for (unsigned I = 0; I != NumArgs; ++I) {
CanonArgs[I] = getCanonicalTemplateArgument(Args[I]); CanonArgs[I] = getCanonicalTemplateArgument(Args[I]);
@ -3633,8 +3624,8 @@ ASTContext::getDependentTemplateSpecializationType(
QualType Canon; QualType Canon;
if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) { if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) {
Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS, Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS,
Name, NumArgs, Name,
CanonArgs.data()); CanonArgs);
// Find the insert position again. // Find the insert position again.
DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
@ -3644,7 +3635,7 @@ ASTContext::getDependentTemplateSpecializationType(
sizeof(TemplateArgument) * NumArgs), sizeof(TemplateArgument) * NumArgs),
TypeAlignment); TypeAlignment);
T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS, T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS,
Name, NumArgs, Args, Canon); Name, Args, Canon);
Types.push_back(T); Types.push_back(T);
DependentTemplateSpecializationTypes.InsertNode(T, InsertPos); DependentTemplateSpecializationTypes.InsertNode(T, InsertPos);
return QualType(T, 0); return QualType(T, 0);
@ -5756,8 +5747,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S,
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
llvm::raw_string_ostream OS(S); llvm::raw_string_ostream OS(S);
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(OS,
TemplateArgs.data(), TemplateArgs.asArray(),
TemplateArgs.size(),
(*this).getPrintingPolicy()); (*this).getPrintingPolicy());
} }
} else { } else {

View File

@ -119,7 +119,7 @@ static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) {
if (DesugarArgument) { if (DesugarArgument) {
ShouldAKA = true; ShouldAKA = true;
QT = Context.getTemplateSpecializationType( QT = Context.getTemplateSpecializationType(
TST->getTemplateName(), Args.data(), Args.size(), QT); TST->getTemplateName(), Args, QT);
} }
break; break;
} }
@ -1060,8 +1060,7 @@ class TemplateDiff {
Ty = Context.getTemplateSpecializationType( Ty = Context.getTemplateSpecializationType(
TemplateName(CTSD->getSpecializedTemplate()), TemplateName(CTSD->getSpecializedTemplate()),
CTSD->getTemplateArgs().data(), CTSD->getTemplateArgs().asArray(),
CTSD->getTemplateArgs().size(),
Ty.getLocalUnqualifiedType().getCanonicalType()); Ty.getLocalUnqualifiedType().getCanonicalType());
return Ty->getAs<TemplateSpecializationType>(); return Ty->getAs<TemplateSpecializationType>();

View File

@ -1909,8 +1909,7 @@ QualType ASTNodeImporter::VisitTemplateSpecializationType(
return QualType(); return QualType();
} }
return Importer.getToContext().getTemplateSpecializationType(ToTemplate, return Importer.getToContext().getTemplateSpecializationType(ToTemplate,
ToTemplateArgs.data(), ToTemplateArgs,
ToTemplateArgs.size(),
ToCanonType); ToCanonType);
} }

View File

@ -1428,10 +1428,8 @@ void NamedDecl::printQualifiedName(raw_ostream &OS,
if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
OS << Spec->getName(); OS << Spec->getName();
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
TemplateArgs.data(), OS, TemplateArgs.asArray(), P);
TemplateArgs.size(),
P);
} else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) { } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
if (P.SuppressUnwrittenScope && if (P.SuppressUnwrittenScope &&
(ND->isAnonymousNamespace() || ND->isInline())) (ND->isAnonymousNamespace() || ND->isInline()))
@ -2444,7 +2442,7 @@ void FunctionDecl::getNameForDiagnostic(
const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs(); const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs();
if (TemplateArgs) if (TemplateArgs)
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, TemplateArgs->data(), TemplateArgs->size(), Policy); OS, TemplateArgs->asArray(), Policy);
} }
bool FunctionDecl::isVariadic() const { bool FunctionDecl::isVariadic() const {

View File

@ -461,8 +461,7 @@ ClassTemplateDecl::getInjectedClassNameSpecialization() {
GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data()); GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
CommonPtr->InjectedClassNameType CommonPtr->InjectedClassNameType
= Context.getTemplateSpecializationType(TemplateName(this), = Context.getTemplateSpecializationType(TemplateName(this),
&TemplateArgs[0], TemplateArgs);
TemplateArgs.size());
return CommonPtr->InjectedClassNameType; return CommonPtr->InjectedClassNameType;
} }
@ -757,7 +756,7 @@ void ClassTemplateSpecializationDecl::getNameForDiagnostic(
const TemplateArgumentList &TemplateArgs = getTemplateArgs(); const TemplateArgumentList &TemplateArgs = getTemplateArgs();
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, TemplateArgs.data(), TemplateArgs.size(), Policy); OS, TemplateArgs.asArray(), Policy);
} }
ClassTemplateDecl * ClassTemplateDecl *
@ -1089,7 +1088,7 @@ void VarTemplateSpecializationDecl::getNameForDiagnostic(
const TemplateArgumentList &TemplateArgs = getTemplateArgs(); const TemplateArgumentList &TemplateArgs = getTemplateArgs();
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, TemplateArgs.data(), TemplateArgs.size(), Policy); OS, TemplateArgs.asArray(), Policy);
} }
VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {

View File

@ -315,7 +315,7 @@ NestedNameSpecifier::print(raw_ostream &OS,
// Print the template argument list. // Print the template argument list.
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, SpecType->getArgs(), SpecType->getNumArgs(), InnerPolicy); OS, SpecType->template_arguments(), InnerPolicy);
} else { } else {
// Print the type normally // Print the type normally
QualType(T, 0).print(OS, InnerPolicy); QualType(T, 0).print(OS, InnerPolicy);

View File

@ -1187,7 +1187,7 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
OS << Node->getNameInfo(); OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
void StmtPrinter::VisitDependentScopeDeclRefExpr( void StmtPrinter::VisitDependentScopeDeclRefExpr(
@ -1199,7 +1199,7 @@ void StmtPrinter::VisitDependentScopeDeclRefExpr(
OS << Node->getNameInfo(); OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
@ -1210,7 +1210,7 @@ void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
OS << Node->getNameInfo(); OS << Node->getNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
@ -1537,7 +1537,7 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) {
OS << Node->getMemberNameInfo(); OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) { void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) {
PrintExpr(Node->getBase()); PrintExpr(Node->getBase());
@ -1917,7 +1917,7 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) {
if (Args->size() != 1) { if (Args->size() != 1) {
OS << "operator\"\"" << Node->getUDSuffix()->getName(); OS << "operator\"\"" << Node->getUDSuffix()->getName();
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Args->data(), Args->size(), Policy); OS, Args->asArray(), Policy);
OS << "()"; OS << "()";
return; return;
} }
@ -2242,7 +2242,7 @@ void StmtPrinter::VisitCXXDependentScopeMemberExpr(
OS << Node->getMemberNameInfo(); OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) { void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
@ -2257,7 +2257,7 @@ void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) {
OS << Node->getMemberNameInfo(); OS << Node->getMemberNameInfo();
if (Node->hasExplicitTemplateArgs()) if (Node->hasExplicitTemplateArgs())
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Node->getTemplateArgs(), Node->getNumTemplateArgs(), Policy); OS, Node->template_arguments(), Policy);
} }
static const char *getTypeTraitName(TypeTrait TT) { static const char *getTypeTraitName(TypeTrait TT) {

View File

@ -2460,19 +2460,20 @@ StringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) {
DependentTemplateSpecializationType::DependentTemplateSpecializationType( DependentTemplateSpecializationType::DependentTemplateSpecializationType(
ElaboratedTypeKeyword Keyword, ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS, const IdentifierInfo *Name, NestedNameSpecifier *NNS, const IdentifierInfo *Name,
unsigned NumArgs, const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
QualType Canon) QualType Canon)
: TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true, : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true,
/*VariablyModified=*/false, /*VariablyModified=*/false,
NNS && NNS->containsUnexpandedParameterPack()), NNS && NNS->containsUnexpandedParameterPack()),
NNS(NNS), Name(Name), NumArgs(NumArgs) { NNS(NNS), Name(Name), NumArgs(Args.size()) {
assert((!NNS || NNS->isDependent()) && assert((!NNS || NNS->isDependent()) &&
"DependentTemplateSpecializatonType requires dependent qualifier"); "DependentTemplateSpecializatonType requires dependent qualifier");
for (unsigned I = 0; I != NumArgs; ++I) { TemplateArgument *ArgBuffer = getArgBuffer();
if (Args[I].containsUnexpandedParameterPack()) for (const TemplateArgument &Arg : Args) {
if (Arg.containsUnexpandedParameterPack())
setContainsUnexpandedParameterPack(); setContainsUnexpandedParameterPack();
new (&getArgBuffer()[I]) TemplateArgument(Args[I]); new (ArgBuffer++) TemplateArgument(Arg);
} }
} }
@ -2482,13 +2483,12 @@ DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
ElaboratedTypeKeyword Keyword, ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *Qualifier, NestedNameSpecifier *Qualifier,
const IdentifierInfo *Name, const IdentifierInfo *Name,
unsigned NumArgs, ArrayRef<TemplateArgument> Args) {
const TemplateArgument *Args) {
ID.AddInteger(Keyword); ID.AddInteger(Keyword);
ID.AddPointer(Qualifier); ID.AddPointer(Qualifier);
ID.AddPointer(Name); ID.AddPointer(Name);
for (unsigned Idx = 0; Idx < NumArgs; ++Idx) for (const TemplateArgument &Arg : Args)
Args[Idx].Profile(ID, Context); Arg.Profile(ID, Context);
} }
bool Type::isElaboratedTypeSpecifier() const { bool Type::isElaboratedTypeSpecifier() const {
@ -3100,20 +3100,20 @@ void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
bool TemplateSpecializationType:: bool TemplateSpecializationType::
anyDependentTemplateArguments(const TemplateArgumentListInfo &Args, anyDependentTemplateArguments(const TemplateArgumentListInfo &Args,
bool &InstantiationDependent) { bool &InstantiationDependent) {
return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size(), return anyDependentTemplateArguments(Args.arguments(),
InstantiationDependent); InstantiationDependent);
} }
bool TemplateSpecializationType:: bool TemplateSpecializationType::
anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N, anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
bool &InstantiationDependent) { bool &InstantiationDependent) {
for (unsigned i = 0; i != N; ++i) { for (const TemplateArgumentLoc &ArgLoc : Args) {
if (Args[i].getArgument().isDependent()) { if (ArgLoc.getArgument().isDependent()) {
InstantiationDependent = true; InstantiationDependent = true;
return true; return true;
} }
if (Args[i].getArgument().isInstantiationDependent()) if (ArgLoc.getArgument().isInstantiationDependent())
InstantiationDependent = true; InstantiationDependent = true;
} }
return false; return false;
@ -3121,7 +3121,7 @@ anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N,
TemplateSpecializationType:: TemplateSpecializationType::
TemplateSpecializationType(TemplateName T, TemplateSpecializationType(TemplateName T,
const TemplateArgument *Args, unsigned NumArgs, ArrayRef<TemplateArgument> Args,
QualType Canon, QualType AliasedType) QualType Canon, QualType AliasedType)
: Type(TemplateSpecialization, : Type(TemplateSpecialization,
Canon.isNull()? QualType(this, 0) : Canon, Canon.isNull()? QualType(this, 0) : Canon,
@ -3129,7 +3129,7 @@ TemplateSpecializationType(TemplateName T,
Canon.isNull()? true : Canon->isInstantiationDependentType(), Canon.isNull()? true : Canon->isInstantiationDependentType(),
false, false,
T.containsUnexpandedParameterPack()), T.containsUnexpandedParameterPack()),
Template(T), NumArgs(NumArgs), TypeAlias(!AliasedType.isNull()) { Template(T), NumArgs(Args.size()), TypeAlias(!AliasedType.isNull()) {
assert(!T.getAsDependentTemplateName() && assert(!T.getAsDependentTemplateName() &&
"Use DependentTemplateSpecializationType for dependent template-name"); "Use DependentTemplateSpecializationType for dependent template-name");
assert((T.getKind() == TemplateName::Template || assert((T.getKind() == TemplateName::Template ||
@ -3139,7 +3139,7 @@ TemplateSpecializationType(TemplateName T,
TemplateArgument *TemplateArgs TemplateArgument *TemplateArgs
= reinterpret_cast<TemplateArgument *>(this + 1); = reinterpret_cast<TemplateArgument *>(this + 1);
for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { for (const TemplateArgument &Arg : Args) {
// Update instantiation-dependent and variably-modified bits. // Update instantiation-dependent and variably-modified bits.
// If the canonical type exists and is non-dependent, the template // If the canonical type exists and is non-dependent, the template
// specialization type can be non-dependent even if one of the type // specialization type can be non-dependent even if one of the type
@ -3148,14 +3148,14 @@ TemplateSpecializationType(TemplateName T,
// U<T> is always non-dependent, irrespective of the type T. // U<T> is always non-dependent, irrespective of the type T.
// However, U<Ts> contains an unexpanded parameter pack, even though // However, U<Ts> contains an unexpanded parameter pack, even though
// its expansion (and thus its desugared type) doesn't. // its expansion (and thus its desugared type) doesn't.
if (Args[Arg].isInstantiationDependent()) if (Arg.isInstantiationDependent())
setInstantiationDependent(); setInstantiationDependent();
if (Args[Arg].getKind() == TemplateArgument::Type && if (Arg.getKind() == TemplateArgument::Type &&
Args[Arg].getAsType()->isVariablyModifiedType()) Arg.getAsType()->isVariablyModifiedType())
setVariablyModified(); setVariablyModified();
if (Args[Arg].containsUnexpandedParameterPack()) if (Arg.containsUnexpandedParameterPack())
setContainsUnexpandedParameterPack(); setContainsUnexpandedParameterPack();
new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); new (TemplateArgs++) TemplateArgument(Arg);
} }
// Store the aliased type if this is a type alias template specialization. // Store the aliased type if this is a type alias template specialization.
@ -3168,12 +3168,11 @@ TemplateSpecializationType(TemplateName T,
void void
TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
TemplateName T, TemplateName T,
const TemplateArgument *Args, ArrayRef<TemplateArgument> Args,
unsigned NumArgs,
const ASTContext &Context) { const ASTContext &Context) {
T.Profile(ID); T.Profile(ID);
for (unsigned Idx = 0; Idx < NumArgs; ++Idx) for (const TemplateArgument &Arg : Args)
Args[Idx].Profile(ID, Context); Arg.Profile(ID, Context);
} }
QualType QualType

View File

@ -923,10 +923,8 @@ void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy); IncludeStrongLifetimeRAII Strong(Policy);
OS << Spec->getIdentifier()->getName(); OS << Spec->getIdentifier()->getName();
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
TemplateArgs.data(), OS, TemplateArgs.asArray(), Policy);
TemplateArgs.size(),
Policy);
OS << "::"; OS << "::";
} else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) { } else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) {
if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl()) if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl())
@ -1003,22 +1001,17 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
// arguments. // arguments.
if (ClassTemplateSpecializationDecl *Spec if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(D)) { = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
const TemplateArgument *Args; ArrayRef<TemplateArgument> Args;
unsigned NumArgs;
if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
const TemplateSpecializationType *TST = const TemplateSpecializationType *TST =
cast<TemplateSpecializationType>(TAW->getType()); cast<TemplateSpecializationType>(TAW->getType());
Args = TST->getArgs(); Args = TST->template_arguments();
NumArgs = TST->getNumArgs();
} else { } else {
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
Args = TemplateArgs.data(); Args = TemplateArgs.asArray();
NumArgs = TemplateArgs.size();
} }
IncludeStrongLifetimeRAII Strong(Policy); IncludeStrongLifetimeRAII Strong(Policy);
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, Policy);
Args, NumArgs,
Policy);
} }
spaceBeforePlaceHolder(OS); spaceBeforePlaceHolder(OS);
@ -1076,11 +1069,9 @@ void TypePrinter::printTemplateSpecializationBefore(
raw_ostream &OS) { raw_ostream &OS) {
IncludeStrongLifetimeRAII Strong(Policy); IncludeStrongLifetimeRAII Strong(Policy);
T->getTemplateName().print(OS, Policy); T->getTemplateName().print(OS, Policy);
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
T->getArgs(), OS, T->template_arguments(), Policy);
T->getNumArgs(),
Policy);
spaceBeforePlaceHolder(OS); spaceBeforePlaceHolder(OS);
} }
void TypePrinter::printTemplateSpecializationAfter( void TypePrinter::printTemplateSpecializationAfter(
@ -1157,8 +1148,7 @@ void TypePrinter::printDependentTemplateSpecializationBefore(
T->getQualifier()->print(OS, Policy); T->getQualifier()->print(OS, Policy);
OS << T->getIdentifier()->getName(); OS << T->getIdentifier()->getName();
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(OS,
T->getArgs(), T->template_arguments(),
T->getNumArgs(),
Policy); Policy);
spaceBeforePlaceHolder(OS); spaceBeforePlaceHolder(OS);
} }
@ -1445,50 +1435,46 @@ void TemplateSpecializationType::
const TemplateArgumentListInfo &Args, const TemplateArgumentListInfo &Args,
const PrintingPolicy &Policy) { const PrintingPolicy &Policy) {
return PrintTemplateArgumentList(OS, return PrintTemplateArgumentList(OS,
Args.getArgumentArray(), Args.arguments(),
Args.size(),
Policy); Policy);
} }
void void TemplateSpecializationType::PrintTemplateArgumentList(
TemplateSpecializationType::PrintTemplateArgumentList( raw_ostream &OS, ArrayRef<TemplateArgument> Args,
raw_ostream &OS, const PrintingPolicy &Policy, bool SkipBrackets) {
const TemplateArgument *Args,
unsigned NumArgs,
const PrintingPolicy &Policy,
bool SkipBrackets) {
const char *Comma = Policy.MSVCFormatting ? "," : ", "; const char *Comma = Policy.MSVCFormatting ? "," : ", ";
if (!SkipBrackets) if (!SkipBrackets)
OS << '<'; OS << '<';
bool needSpace = false; bool needSpace = false;
for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { bool FirstArg = true;
for (const TemplateArgument &Arg : Args) {
// Print the argument into a string. // Print the argument into a string.
SmallString<128> Buf; SmallString<128> Buf;
llvm::raw_svector_ostream ArgOS(Buf); llvm::raw_svector_ostream ArgOS(Buf);
if (Args[Arg].getKind() == TemplateArgument::Pack) { if (Arg.getKind() == TemplateArgument::Pack) {
if (Args[Arg].pack_size() && Arg > 0) if (Arg.pack_size() && !FirstArg)
OS << Comma; OS << Comma;
PrintTemplateArgumentList(ArgOS, PrintTemplateArgumentList(ArgOS,
Args[Arg].pack_begin(), Arg.getPackAsArray(),
Args[Arg].pack_size(),
Policy, true); Policy, true);
} else { } else {
if (Arg > 0) if (!FirstArg)
OS << Comma; OS << Comma;
Args[Arg].print(Policy, ArgOS); Arg.print(Policy, ArgOS);
} }
StringRef ArgString = ArgOS.str(); StringRef ArgString = ArgOS.str();
// If this is the first argument and its string representation // If this is the first argument and its string representation
// begins with the global scope specifier ('::foo'), add a space // begins with the global scope specifier ('::foo'), add a space
// to avoid printing the diagraph '<:'. // to avoid printing the diagraph '<:'.
if (!Arg && !ArgString.empty() && ArgString[0] == ':') if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
OS << ' '; OS << ' ';
OS << ArgString; OS << ArgString;
needSpace = (!ArgString.empty() && ArgString.back() == '>'); needSpace = (!ArgString.empty() && ArgString.back() == '>');
FirstArg = false;
} }
// If the last character of our string is '>', add another space to // If the last character of our string is '>', add another space to
@ -1504,40 +1490,41 @@ TemplateSpecializationType::PrintTemplateArgumentList(
// Sadly, repeat all that with TemplateArgLoc. // Sadly, repeat all that with TemplateArgLoc.
void TemplateSpecializationType:: void TemplateSpecializationType::
PrintTemplateArgumentList(raw_ostream &OS, PrintTemplateArgumentList(raw_ostream &OS,
const TemplateArgumentLoc *Args, unsigned NumArgs, ArrayRef<TemplateArgumentLoc> Args,
const PrintingPolicy &Policy) { const PrintingPolicy &Policy) {
OS << '<'; OS << '<';
const char *Comma = Policy.MSVCFormatting ? "," : ", "; const char *Comma = Policy.MSVCFormatting ? "," : ", ";
bool needSpace = false; bool needSpace = false;
for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { bool FirstArg = true;
if (Arg > 0) for (const TemplateArgumentLoc &Arg : Args) {
if (!FirstArg)
OS << Comma; OS << Comma;
// Print the argument into a string. // Print the argument into a string.
SmallString<128> Buf; SmallString<128> Buf;
llvm::raw_svector_ostream ArgOS(Buf); llvm::raw_svector_ostream ArgOS(Buf);
if (Args[Arg].getArgument().getKind() == TemplateArgument::Pack) { if (Arg.getArgument().getKind() == TemplateArgument::Pack) {
PrintTemplateArgumentList(ArgOS, PrintTemplateArgumentList(ArgOS,
Args[Arg].getArgument().pack_begin(), Arg.getArgument().getPackAsArray(),
Args[Arg].getArgument().pack_size(),
Policy, true); Policy, true);
} else { } else {
Args[Arg].getArgument().print(Policy, ArgOS); Arg.getArgument().print(Policy, ArgOS);
} }
StringRef ArgString = ArgOS.str(); StringRef ArgString = ArgOS.str();
// If this is the first argument and its string representation // If this is the first argument and its string representation
// begins with the global scope specifier ('::foo'), add a space // begins with the global scope specifier ('::foo'), add a space
// to avoid printing the diagraph '<:'. // to avoid printing the diagraph '<:'.
if (!Arg && !ArgString.empty() && ArgString[0] == ':') if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
OS << ' '; OS << ' ';
OS << ArgString; OS << ArgString;
needSpace = (!ArgString.empty() && ArgString.back() == '>'); needSpace = (!ArgString.empty() && ArgString.back() == '>');
FirstArg = false;
} }
// If the last character of our string is '>', add another space to // If the last character of our string is '>', add another space to
// keep the two '>''s separate tokens. We don't *have* to do this in // keep the two '>''s separate tokens. We don't *have* to do this in
// C++0x, but it's still good hygiene. // C++0x, but it's still good hygiene.

View File

@ -209,9 +209,7 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
// Add any template specialization args. // Add any template specialization args.
if (Info) { if (Info) {
const TemplateArgumentList *TArgs = Info->TemplateArguments; const TemplateArgumentList *TArgs = Info->TemplateArguments;
const TemplateArgument *Args = TArgs->data(); TemplateSpecializationType::PrintTemplateArgumentList(OS, TArgs->asArray(),
unsigned NumArgs = TArgs->size();
TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, NumArgs,
Policy); Policy);
} }
@ -845,7 +843,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
/*qualified*/ false); /*qualified*/ false);
TemplateSpecializationType::PrintTemplateArgumentList( TemplateSpecializationType::PrintTemplateArgumentList(
OS, Ty->getArgs(), Ty->getNumArgs(), OS, Ty->template_arguments(),
CGM.getContext().getPrintingPolicy()); CGM.getContext().getPrintingPolicy());
TypeAliasDecl *AliasDecl = cast<TypeAliasTemplateDecl>( TypeAliasDecl *AliasDecl = cast<TypeAliasTemplateDecl>(

View File

@ -8307,7 +8307,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (isFunctionTemplateSpecialization && isFriend && if (isFunctionTemplateSpecialization && isFriend &&
(NewFD->getType()->isDependentType() || DC->isDependentContext() || (NewFD->getType()->isDependentType() || DC->isDependentContext() ||
TemplateSpecializationType::anyDependentTemplateArguments( TemplateSpecializationType::anyDependentTemplateArguments(
TemplateArgs.getArgumentArray(), TemplateArgs.size(), TemplateArgs,
InstantiationDependent))) { InstantiationDependent))) {
assert(HasExplicitTemplateArgs && assert(HasExplicitTemplateArgs &&
"friend function specialization without template args"); "friend function specialization without template args");

View File

@ -2189,8 +2189,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
// template<typename T, typename U = T> struct A; // template<typename T, typename U = T> struct A;
TemplateName CanonName = Context.getCanonicalTemplateName(Name); TemplateName CanonName = Context.getCanonicalTemplateName(Name);
CanonType = Context.getTemplateSpecializationType(CanonName, CanonType = Context.getTemplateSpecializationType(CanonName,
Converted.data(), Converted);
Converted.size());
// FIXME: CanonType is not actually the canonical type, and unfortunately // FIXME: CanonType is not actually the canonical type, and unfortunately
// it is a TemplateSpecializationType that we will never use again. // it is a TemplateSpecializationType that we will never use again.
@ -2576,7 +2575,7 @@ DeclResult Sema::ActOnVarTemplateSpecialization(
bool InstantiationDependent; bool InstantiationDependent;
if (!Name.isDependent() && if (!Name.isDependent() &&
!TemplateSpecializationType::anyDependentTemplateArguments( !TemplateSpecializationType::anyDependentTemplateArguments(
TemplateArgs.getArgumentArray(), TemplateArgs.size(), TemplateArgs.arguments(),
InstantiationDependent)) { InstantiationDependent)) {
Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized) Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
<< VarTemplate->getDeclName(); << VarTemplate->getDeclName();
@ -6319,9 +6318,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
bool InstantiationDependent; bool InstantiationDependent;
if (!Name.isDependent() && if (!Name.isDependent() &&
!TemplateSpecializationType::anyDependentTemplateArguments( !TemplateSpecializationType::anyDependentTemplateArguments(
TemplateArgs.getArgumentArray(), TemplateArgs.arguments(), InstantiationDependent)) {
TemplateArgs.size(),
InstantiationDependent)) {
Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized) Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
<< ClassTemplate->getDeclName(); << ClassTemplate->getDeclName();
isPartialSpecialization = false; isPartialSpecialization = false;
@ -6354,8 +6351,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
// arguments of the class template partial specialization. // arguments of the class template partial specialization.
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name); TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
CanonType = Context.getTemplateSpecializationType(CanonTemplate, CanonType = Context.getTemplateSpecializationType(CanonTemplate,
Converted.data(), Converted);
Converted.size());
if (Context.hasSameType(CanonType, if (Context.hasSameType(CanonType,
ClassTemplate->getInjectedClassNameSpecialization())) { ClassTemplate->getInjectedClassNameSpecialization())) {
@ -6459,7 +6455,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
"Only possible with -fms-extensions!"); "Only possible with -fms-extensions!");
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name); TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
CanonType = Context.getTemplateSpecializationType( CanonType = Context.getTemplateSpecializationType(
CanonTemplate, Converted.data(), Converted.size()); CanonTemplate, Converted);
} else { } else {
CanonType = Context.getTypeDeclType(Specialization); CanonType = Context.getTypeDeclType(Specialization);
} }

View File

@ -4596,11 +4596,9 @@ Sema::getMoreSpecializedPartialSpecialization(
TemplateName Name(PS1->getSpecializedTemplate()); TemplateName Name(PS1->getSpecializedTemplate());
TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name); TemplateName CanonTemplate = Context.getCanonicalTemplateName(Name);
QualType PT1 = Context.getTemplateSpecializationType( QualType PT1 = Context.getTemplateSpecializationType(
CanonTemplate, PS1->getTemplateArgs().data(), CanonTemplate, PS1->getTemplateArgs().asArray());
PS1->getTemplateArgs().size());
QualType PT2 = Context.getTemplateSpecializationType( QualType PT2 = Context.getTemplateSpecializationType(
CanonTemplate, PS2->getTemplateArgs().data(), CanonTemplate, PS2->getTemplateArgs().asArray());
PS2->getTemplateArgs().size());
// Determine whether PS1 is at least as specialized as PS2 // Determine whether PS1 is at least as specialized as PS2
Deduced.resize(PS2->getTemplateParameters()->size()); Deduced.resize(PS2->getTemplateParameters()->size());

View File

@ -447,10 +447,8 @@ void Sema::PrintInstantiationStack() {
SmallVector<char, 128> TemplateArgsStr; SmallVector<char, 128> TemplateArgsStr;
llvm::raw_svector_ostream OS(TemplateArgsStr); llvm::raw_svector_ostream OS(TemplateArgsStr);
Template->printName(OS); Template->printName(OS);
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs, OS, Active->template_arguments(), getPrintingPolicy());
Active->NumTemplateArgs,
getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation, Diags.Report(Active->PointOfInstantiation,
diag::note_default_arg_instantiation_here) diag::note_default_arg_instantiation_here)
<< OS.str() << OS.str()
@ -501,10 +499,8 @@ void Sema::PrintInstantiationStack() {
SmallVector<char, 128> TemplateArgsStr; SmallVector<char, 128> TemplateArgsStr;
llvm::raw_svector_ostream OS(TemplateArgsStr); llvm::raw_svector_ostream OS(TemplateArgsStr);
FD->printName(OS); FD->printName(OS);
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
Active->TemplateArgs, OS, Active->template_arguments(), getPrintingPolicy());
Active->NumTemplateArgs,
getPrintingPolicy());
Diags.Report(Active->PointOfInstantiation, Diags.Report(Active->PointOfInstantiation,
diag::note_default_function_arg_instantiation_here) diag::note_default_function_arg_instantiation_here)
<< OS.str() << OS.str()

View File

@ -2763,7 +2763,7 @@ TemplateDeclInstantiator::VisitClassTemplateSpecializationDecl(
// Build the canonical type that describes the converted template // Build the canonical type that describes the converted template
// arguments of the class template explicit specialization. // arguments of the class template explicit specialization.
QualType CanonType = SemaRef.Context.getTemplateSpecializationType( QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
TemplateName(InstClassTemplate), Converted.data(), Converted.size(), TemplateName(InstClassTemplate), Converted,
SemaRef.Context.getRecordType(InstD)); SemaRef.Context.getRecordType(InstD));
// Build the fully-sugared type for this class template // Build the fully-sugared type for this class template
@ -2989,8 +2989,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
// arguments of the class template partial specialization. // arguments of the class template partial specialization.
QualType CanonType QualType CanonType
= SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate), = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
Converted.data(), Converted);
Converted.size());
// Build the fully-sugared type for this class template // Build the fully-sugared type for this class template
// specialization as the user wrote in the specialization // specialization as the user wrote in the specialization
@ -3111,7 +3110,7 @@ TemplateDeclInstantiator::InstantiateVarTemplatePartialSpecialization(
// Build the canonical type that describes the converted template // Build the canonical type that describes the converted template
// arguments of the variable template partial specialization. // arguments of the variable template partial specialization.
QualType CanonType = SemaRef.Context.getTemplateSpecializationType( QualType CanonType = SemaRef.Context.getTemplateSpecializationType(
TemplateName(VarTemplate), Converted.data(), Converted.size()); TemplateName(VarTemplate), Converted);
// Build the fully-sugared type for this variable template // Build the fully-sugared type for this variable template
// specialization as the user wrote in the specialization // specialization as the user wrote in the specialization

View File

@ -5624,7 +5624,7 @@ QualType ASTReader::readTypeRecord(unsigned Index) {
while (NumArgs--) while (NumArgs--)
Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx));
return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name,
Args.size(), Args.data()); Args);
} }
case TYPE_DEPENDENT_SIZED_ARRAY: { case TYPE_DEPENDENT_SIZED_ARRAY: {
@ -5653,11 +5653,9 @@ QualType ASTReader::readTypeRecord(unsigned Index) {
QualType Underlying = readType(*Loc.F, Record, Idx); QualType Underlying = readType(*Loc.F, Record, Idx);
QualType T; QualType T;
if (Underlying.isNull()) if (Underlying.isNull())
T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), T = Context.getCanonicalTemplateSpecializationType(Name, Args);
Args.size());
else else
T = Context.getTemplateSpecializationType(Name, Args.data(), T = Context.getTemplateSpecializationType(Name, Args, Underlying);
Args.size(), Underlying);
const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent);
return T; return T;
} }

View File

@ -155,7 +155,7 @@ static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
// allocate new type in the AST. // allocate new type in the AST.
if (MightHaveChanged) { if (MightHaveChanged) {
QualType QT = Ctx.getTemplateSpecializationType( QualType QT = Ctx.getTemplateSpecializationType(
TST->getTemplateName(), FQArgs.data(), FQArgs.size(), TST->getTemplateName(), FQArgs,
TST->getCanonicalTypeInternal()); TST->getCanonicalTypeInternal());
// getTemplateSpecializationType returns a fully qualified // getTemplateSpecializationType returns a fully qualified
// version of the specialization itself, so no need to qualify // version of the specialization itself, so no need to qualify
@ -187,7 +187,7 @@ static const Type *getFullyQualifiedTemplateType(const ASTContext &Ctx,
if (MightHaveChanged) { if (MightHaveChanged) {
TemplateName TN(TSTDecl->getSpecializedTemplate()); TemplateName TN(TSTDecl->getSpecializedTemplate());
QualType QT = Ctx.getTemplateSpecializationType( QualType QT = Ctx.getTemplateSpecializationType(
TN, FQArgs.data(), FQArgs.size(), TN, FQArgs,
TSTRecord->getCanonicalTypeInternal()); TSTRecord->getCanonicalTypeInternal());
// getTemplateSpecializationType returns a fully qualified // getTemplateSpecializationType returns a fully qualified
// version of the specialization itself, so no need to qualify // version of the specialization itself, so no need to qualify

View File

@ -4458,10 +4458,8 @@ CXString clang_getCursorDisplayName(CXCursor C) {
SmallString<128> Str; SmallString<128> Str;
llvm::raw_svector_ostream OS(Str); llvm::raw_svector_ostream OS(Str);
OS << *ClassSpec; OS << *ClassSpec;
TemplateSpecializationType::PrintTemplateArgumentList(OS, TemplateSpecializationType::PrintTemplateArgumentList(
ClassSpec->getTemplateArgs().data(), OS, ClassSpec->getTemplateArgs().asArray(), Policy);
ClassSpec->getTemplateArgs().size(),
Policy);
return cxstring::createDup(OS.str()); return cxstring::createDup(OS.str());
} }