QualType Canon = QualType());
QualType getTemplateSpecializationType(TemplateName T,
- const TemplateArgumentLoc *Args,
- unsigned NumArgs,
+ const TemplateArgumentListInfo &Args,
QualType Canon = QualType());
QualType getQualifiedNameType(NestedNameSpecifier *NNS,
TypeLoc getTypeLoc() const;
};
+/// UnresolvedSet - A set of unresolved declarations. This is needed
+/// in a lot of places, but isn't really worth breaking into its own
+/// header right now.
+class UnresolvedSet {
+ typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy;
+ DeclsTy Decls;
+
+public:
+ void addDecl(NamedDecl *D) {
+ Decls.push_back(D);
+ }
+
+ bool replace(const NamedDecl* Old, NamedDecl *New) {
+ for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I)
+ if (*I == Old)
+ return (*I = New, true);
+ return false;
+ }
+
+ typedef DeclsTy::const_iterator iterator;
+ iterator begin() const { return Decls.begin(); }
+ iterator end() const { return Decls.end(); }
+};
+
/// TranslationUnitDecl - The top declaration context.
class TranslationUnitDecl : public Decl, public DeclContext {
ASTContext &Ctx;
namespace clang {
-/// UnresolvedSet - A set of unresolved declarations.
-class UnresolvedSet {
- typedef llvm::SmallVector<NamedDecl*, 4> DeclsTy;
- DeclsTy Decls;
-
-public:
- void addDecl(NamedDecl *D) {
- Decls.push_back(D);
- }
-
- bool replace(const NamedDecl* Old, NamedDecl *New) {
- for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I)
- if (*I == Old)
- return (*I = New, true);
- return false;
- }
-
- typedef DeclsTy::const_iterator iterator;
- iterator begin() const { return Decls.begin(); }
- iterator end() const { return Decls.end(); }
-};
-
/// OverloadedFunctionDecl - An instance of this class represents a
/// set of overloaded functions. All of the functions have the same
/// name and occur within the same scope.
TemplateParameterList *Params,
ClassTemplateDecl *SpecializedTemplate,
TemplateArgumentListBuilder &Builder,
- TemplateArgumentLoc *ArgInfos,
- unsigned NumArgInfos,
+ const TemplateArgumentListInfo &ArgInfos,
ClassTemplatePartialSpecializationDecl *PrevDecl);
/// Get the list of template parameters
class CXXOperatorCallExpr;
class CXXMemberCallExpr;
class TemplateArgumentLoc;
+ class TemplateArgumentListInfo;
/// Expr - This represents one expression. Note that Expr's are subclasses of
/// Stmt. This allows an expression to be transparently used any place a Stmt
const TemplateArgumentLoc *getTemplateArgs() const {
return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
}
+
+ void initializeFrom(const TemplateArgumentListInfo &List);
+ void copyInto(TemplateArgumentListInfo &List) const;
+ static std::size_t sizeFor(const TemplateArgumentListInfo &List);
};
/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
NamedDecl *D, SourceLocation NameLoc,
- bool HasExplicitTemplateArgumentList,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *TemplateArgs,
QualType T, bool TD, bool VD);
protected:
SourceRange QualifierRange,
NamedDecl *D,
SourceLocation NameLoc,
- bool HasExplicitTemplateArgumentList,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *TemplateArgs,
QualType T, bool TD, bool VD);
NamedDecl *getDecl() { return DecoratedD.getPointer(); }
bool hasExplicitTemplateArgumentList() const {
return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
}
+
+ /// \brief Copies the template arguments (if present) into the given
+ /// structure.
+ void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
+ if (hasExplicitTemplateArgumentList())
+ getExplicitTemplateArgumentList()->copyInto(List);
+ }
/// \brief Retrieve the location of the left angle bracket following the
/// member name ('<'), if any.
MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
SourceRange qualrange, NamedDecl *memberdecl, SourceLocation l,
- bool has_explicit, SourceLocation langle,
- const TemplateArgumentLoc *targs, unsigned numtargs,
- SourceLocation rangle, QualType ty);
+ const TemplateArgumentListInfo *targs, QualType ty);
public:
MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
NestedNameSpecifier *qual, SourceRange qualrange,
NamedDecl *memberdecl,
SourceLocation l,
- bool has_explicit,
- SourceLocation langle,
- const TemplateArgumentLoc *targs,
- unsigned numtargs,
- SourceLocation rangle,
+ const TemplateArgumentListInfo *targs,
QualType ty);
void setBase(Expr *E) { Base = E; }
/// \brief Determines whether this member expression actually had a C++
/// template argument list explicitly specified, e.g., x.f<int>.
- bool hasExplicitTemplateArgumentList() {
+ bool hasExplicitTemplateArgumentList() const {
return HasExplicitTemplateArgumentList;
}
+ /// \brief Copies the template arguments (if present) into the given
+ /// structure.
+ void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
+ if (hasExplicitTemplateArgumentList())
+ getExplicitTemplateArgumentList()->copyInto(List);
+ }
+
/// \brief Retrieve the location of the left angle bracket following the
/// member name ('<'), if any.
SourceLocation getLAngleLoc() const {
#include "clang/Basic/TypeTraits.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Decl.h"
-#include "clang/AST/DeclCXX.h"
+#include "clang/AST/TemplateBase.h"
namespace clang {
class CXXDestructorDecl;
class CXXMethodDecl;
class CXXTemporary;
+ class TemplateArgumentListInfo;
//===--------------------------------------------------------------------===//
// C++ Expressions.
TemplateIdRefExpr(QualType T,
NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
TemplateName Template, SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo &TemplateArgs);
virtual void DoDestroy(ASTContext &Context);
Create(ASTContext &Context, QualType T,
NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
TemplateName Template, SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc, const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs, SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo &TemplateArgs);
/// \brief Retrieve the nested name specifier used to qualify the name of
/// this template-id, e.g., the "std::sort" in @c std::sort<int>, or NULL
/// template-id.
unsigned getNumTemplateArgs() const { return NumTemplateArgs; }
+ /// \brief Copies the template-argument information into the given
+ /// structure.
+ void copyTemplateArgumentsInto(TemplateArgumentListInfo &Info) const {
+ Info.setLAngleLoc(LAngleLoc);
+ Info.setRAngleLoc(RAngleLoc);
+ for (unsigned i = 0; i < NumTemplateArgs; ++i)
+ Info.addArgument(getTemplateArgs()[i]);
+ }
+
/// \brief Retrieve the location of the right angle bracket following the
/// template arguments ('>').
SourceLocation getRAngleLoc() const { return RAngleLoc; }
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo *TemplateArgs);
public:
CXXDependentScopeMemberExpr(ASTContext &C,
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo *TemplateArgs);
/// \brief Retrieve the base object of this member expressions,
/// e.g., the \c x in \c x.m.
/// \brief Determines whether this member expression actually had a C++
/// template argument list explicitly specified, e.g., x.f<int>.
- bool hasExplicitTemplateArgumentList() {
+ bool hasExplicitTemplateArgumentList() const {
return HasExplicitTemplateArgumentList;
}
+ /// \brief Copies the template arguments (if present) into the given
+ /// structure.
+ void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
+ if (hasExplicitTemplateArgumentList())
+ getExplicitTemplateArgumentList()->copyInto(List);
+ }
+
/// \brief Retrieve the location of the left angle bracket following the
/// member name ('<'), if any.
SourceLocation getLAngleLoc() const {
#define LLVM_CLANG_AST_TEMPLATEBASE_H
#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/ErrorHandling.h"
#include "clang/AST/Type.h"
#include "clang/AST/TemplateName.h"
}
};
+/// A convenient class for passing around template argument
+/// information. Designed to be passed by reference.
+class TemplateArgumentListInfo {
+ llvm::SmallVector<TemplateArgumentLoc, 8> Arguments;
+ SourceLocation LAngleLoc;
+ SourceLocation RAngleLoc;
+
+public:
+ TemplateArgumentListInfo() {}
+
+ TemplateArgumentListInfo(SourceLocation LAngleLoc,
+ SourceLocation RAngleLoc)
+ : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
+
+ SourceLocation getLAngleLoc() const { return LAngleLoc; }
+ SourceLocation getRAngleLoc() const { return RAngleLoc; }
+
+ void setLAngleLoc(SourceLocation Loc) { LAngleLoc = Loc; }
+ void setRAngleLoc(SourceLocation Loc) { RAngleLoc = Loc; }
+
+ unsigned size() const { return Arguments.size(); }
+
+ const TemplateArgumentLoc *getArgumentArray() const {
+ return Arguments.data();
+ }
+
+ const TemplateArgumentLoc &operator[](unsigned I) const {
+ return Arguments[I];
+ }
+
+ void addArgument(const TemplateArgumentLoc &Loc) {
+ Arguments.push_back(Loc);
+ }
+};
+
}
#endif
class StmtIteratorBase;
class TemplateArgument;
class TemplateArgumentLoc;
+ class TemplateArgumentListInfo;
class QualifiedNameType;
struct PrintingPolicy;
static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
unsigned NumArgs);
+ static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &);
+
/// \brief Print a template argument list, including the '<' and '>'
/// enclosing the template arguments.
static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
unsigned NumArgs,
const PrintingPolicy &Policy);
+ static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
+ const PrintingPolicy &Policy);
+
typedef const TemplateArgument * iterator;
iterator begin() const { return getArgs(); }
QualType
ASTContext::getTemplateSpecializationType(TemplateName Template,
- const TemplateArgumentLoc *Args,
- unsigned NumArgs,
+ const TemplateArgumentListInfo &Args,
QualType Canon) {
+ unsigned NumArgs = Args.size();
+
llvm::SmallVector<TemplateArgument, 4> ArgVec;
ArgVec.reserve(NumArgs);
for (unsigned i = 0; i != NumArgs; ++i)
TemplateParameterList *Params,
ClassTemplateDecl *SpecializedTemplate,
TemplateArgumentListBuilder &Builder,
- TemplateArgumentLoc *ArgInfos, unsigned N,
+ const TemplateArgumentListInfo &ArgInfos,
ClassTemplatePartialSpecializationDecl *PrevDecl) {
+ unsigned N = ArgInfos.size();
TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N];
for (unsigned I = 0; I != N; ++I)
ClonedArgs[I] = ArgInfos[I];
// Primary Expressions.
//===----------------------------------------------------------------------===//
+void ExplicitTemplateArgumentList::initializeFrom(
+ const TemplateArgumentListInfo &Info) {
+ LAngleLoc = Info.getLAngleLoc();
+ RAngleLoc = Info.getRAngleLoc();
+ NumTemplateArgs = Info.size();
+
+ TemplateArgumentLoc *ArgBuffer = getTemplateArgs();
+ for (unsigned i = 0; i != NumTemplateArgs; ++i)
+ new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]);
+}
+
+void ExplicitTemplateArgumentList::copyInto(
+ TemplateArgumentListInfo &Info) const {
+ Info.setLAngleLoc(LAngleLoc);
+ Info.setRAngleLoc(RAngleLoc);
+ for (unsigned I = 0; I != NumTemplateArgs; ++I)
+ Info.addArgument(getTemplateArgs()[I]);
+}
+
+std::size_t ExplicitTemplateArgumentList::sizeFor(
+ const TemplateArgumentListInfo &Info) {
+ return sizeof(ExplicitTemplateArgumentList) +
+ sizeof(TemplateArgumentLoc) * Info.size();
+}
+
DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
NamedDecl *D, SourceLocation NameLoc,
- bool HasExplicitTemplateArgumentList,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *TemplateArgs,
QualType T, bool TD, bool VD)
: Expr(DeclRefExprClass, T, TD, VD),
DecoratedD(D,
(Qualifier? HasQualifierFlag : 0) |
- (HasExplicitTemplateArgumentList?
- HasExplicitTemplateArgumentListFlag : 0)),
+ (TemplateArgs ? HasExplicitTemplateArgumentListFlag : 0)),
Loc(NameLoc) {
assert(!isa<OverloadedFunctionDecl>(D));
if (Qualifier) {
NQ->Range = QualifierRange;
}
- if (HasExplicitTemplateArgumentList) {
- ExplicitTemplateArgumentList *ETemplateArgs
- = getExplicitTemplateArgumentList();
- ETemplateArgs->LAngleLoc = LAngleLoc;
- ETemplateArgs->RAngleLoc = RAngleLoc;
- ETemplateArgs->NumTemplateArgs = NumExplicitTemplateArgs;
-
- TemplateArgumentLoc *TemplateArgs = ETemplateArgs->getTemplateArgs();
- for (unsigned I = 0; I < NumExplicitTemplateArgs; ++I)
- new (TemplateArgs + I) TemplateArgumentLoc(ExplicitTemplateArgs[I]);
- }
+ if (TemplateArgs)
+ getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs);
}
DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
SourceLocation NameLoc,
QualType T, bool TD, bool VD) {
return Create(Context, Qualifier, QualifierRange, D, NameLoc,
- false, SourceLocation(), 0, 0, SourceLocation(),
- T, TD, VD);
+ /*TemplateArgs*/ 0, T, TD, VD);
}
DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
SourceRange QualifierRange,
NamedDecl *D,
SourceLocation NameLoc,
- bool HasExplicitTemplateArgumentList,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *TemplateArgs,
QualType T, bool TD, bool VD) {
std::size_t Size = sizeof(DeclRefExpr);
if (Qualifier != 0)
Size += sizeof(NameQualifier);
- if (HasExplicitTemplateArgumentList)
- Size += sizeof(ExplicitTemplateArgumentList) +
- sizeof(TemplateArgumentLoc) * NumExplicitTemplateArgs;
+ if (TemplateArgs)
+ Size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
void *Mem = Context.Allocate(Size, llvm::alignof<DeclRefExpr>());
return new (Mem) DeclRefExpr(Qualifier, QualifierRange, D, NameLoc,
- HasExplicitTemplateArgumentList,
- LAngleLoc,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
- RAngleLoc,
- T, TD, VD);
+ TemplateArgs, T, TD, VD);
}
SourceRange DeclRefExpr::getSourceRange() const {
MemberExpr::MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
SourceRange qualrange, NamedDecl *memberdecl,
- SourceLocation l, bool has_explicit,
- SourceLocation langle,
- const TemplateArgumentLoc *targs, unsigned numtargs,
- SourceLocation rangle, QualType ty)
+ SourceLocation l, const TemplateArgumentListInfo *targs,
+ QualType ty)
: Expr(MemberExprClass, ty,
base->isTypeDependent() || (qual && qual->isDependent()),
base->isValueDependent() || (qual && qual->isDependent())),
Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
- HasQualifier(qual != 0), HasExplicitTemplateArgumentList(has_explicit) {
+ HasQualifier(qual != 0), HasExplicitTemplateArgumentList(targs) {
// Initialize the qualifier, if any.
if (HasQualifier) {
NameQualifier *NQ = getMemberQualifier();
}
// Initialize the explicit template argument list, if any.
- if (HasExplicitTemplateArgumentList) {
- ExplicitTemplateArgumentList *ETemplateArgs
- = getExplicitTemplateArgumentList();
- ETemplateArgs->LAngleLoc = langle;
- ETemplateArgs->RAngleLoc = rangle;
- ETemplateArgs->NumTemplateArgs = numtargs;
-
- TemplateArgumentLoc *TemplateArgs = ETemplateArgs->getTemplateArgs();
- for (unsigned I = 0; I < numtargs; ++I)
- new (TemplateArgs + I) TemplateArgumentLoc(targs[I]);
- }
+ if (targs)
+ getExplicitTemplateArgumentList()->initializeFrom(*targs);
}
MemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow,
SourceRange qualrange,
NamedDecl *memberdecl,
SourceLocation l,
- bool has_explicit,
- SourceLocation langle,
- const TemplateArgumentLoc *targs,
- unsigned numtargs,
- SourceLocation rangle,
+ const TemplateArgumentListInfo *targs,
QualType ty) {
std::size_t Size = sizeof(MemberExpr);
if (qual != 0)
Size += sizeof(NameQualifier);
- if (has_explicit)
- Size += sizeof(ExplicitTemplateArgumentList) +
- sizeof(TemplateArgumentLoc) * numtargs;
+ if (targs)
+ Size += ExplicitTemplateArgumentList::sizeFor(*targs);
void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>());
return new (Mem) MemberExpr(base, isarrow, qual, qualrange, memberdecl, l,
- has_explicit, langle, targs, numtargs, rangle,
- ty);
+ targs, ty);
}
const char *CastExpr::getCastKindName() const {
SourceRange QualifierRange,
TemplateName Template,
SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc)
+ const TemplateArgumentListInfo &TemplateArgs)
: Expr(TemplateIdRefExprClass, T,
(Template.isDependent() ||
- TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, NumTemplateArgs)),
+ TemplateSpecializationType
+ ::anyDependentTemplateArguments(TemplateArgs)),
(Template.isDependent() ||
- TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs, NumTemplateArgs))),
+ TemplateSpecializationType
+ ::anyDependentTemplateArguments(TemplateArgs))),
Qualifier(Qualifier), QualifierRange(QualifierRange), Template(Template),
- TemplateNameLoc(TemplateNameLoc), LAngleLoc(LAngleLoc),
- RAngleLoc(RAngleLoc), NumTemplateArgs(NumTemplateArgs) {
+ TemplateNameLoc(TemplateNameLoc),
+ LAngleLoc(TemplateArgs.getLAngleLoc()),
+ RAngleLoc(TemplateArgs.getRAngleLoc()),
+ NumTemplateArgs(TemplateArgs.size()) {
TemplateArgumentLoc *StoredTemplateArgs
= reinterpret_cast<TemplateArgumentLoc *> (this+1);
for (unsigned I = 0; I != NumTemplateArgs; ++I)
NestedNameSpecifier *Qualifier,
SourceRange QualifierRange,
TemplateName Template, SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs, SourceLocation RAngleLoc) {
+ const TemplateArgumentListInfo &TemplateArgs) {
void *Mem = Context.Allocate(sizeof(TemplateIdRefExpr) +
- sizeof(TemplateArgumentLoc) * NumTemplateArgs);
+ sizeof(TemplateArgumentLoc) * TemplateArgs.size());
return new (Mem) TemplateIdRefExpr(T, Qualifier, QualifierRange, Template,
- TemplateNameLoc, LAngleLoc, TemplateArgs,
- NumTemplateArgs, RAngleLoc);
+ TemplateNameLoc, TemplateArgs);
}
void TemplateIdRefExpr::DoDestroy(ASTContext &Context) {
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc)
+ const TemplateArgumentListInfo *TemplateArgs)
: Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
Base(Base), IsArrow(IsArrow),
- HasExplicitTemplateArgumentList(HasExplicitTemplateArgs),
+ HasExplicitTemplateArgumentList(TemplateArgs),
OperatorLoc(OperatorLoc),
Qualifier(Qualifier), QualifierRange(QualifierRange),
FirstQualifierFoundInScope(FirstQualifierFoundInScope),
Member(Member), MemberLoc(MemberLoc) {
- if (HasExplicitTemplateArgumentList) {
- ExplicitTemplateArgumentList *ETemplateArgs
- = getExplicitTemplateArgumentList();
- ETemplateArgs->LAngleLoc = LAngleLoc;
- ETemplateArgs->RAngleLoc = RAngleLoc;
- ETemplateArgs->NumTemplateArgs = NumTemplateArgs;
-
- TemplateArgumentLoc *SavedTemplateArgs = ETemplateArgs->getTemplateArgs();
- for (unsigned I = 0; I < NumTemplateArgs; ++I)
- new (SavedTemplateArgs + I) TemplateArgumentLoc(TemplateArgs[I]);
- }
+ if (TemplateArgs)
+ getExplicitTemplateArgumentList()->initializeFrom(*TemplateArgs);
}
CXXDependentScopeMemberExpr *
NamedDecl *FirstQualifierFoundInScope,
DeclarationName Member,
SourceLocation MemberLoc,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc) {
- if (!HasExplicitTemplateArgs)
+ const TemplateArgumentListInfo *TemplateArgs) {
+ if (!TemplateArgs)
return new (C) CXXDependentScopeMemberExpr(C, Base, IsArrow, OperatorLoc,
Qualifier, QualifierRange,
FirstQualifierFoundInScope,
Member, MemberLoc);
- void *Mem = C.Allocate(sizeof(CXXDependentScopeMemberExpr) +
- sizeof(ExplicitTemplateArgumentList) +
- sizeof(TemplateArgumentLoc) * NumTemplateArgs,
- llvm::alignof<CXXDependentScopeMemberExpr>());
+ std::size_t size = sizeof(CXXDependentScopeMemberExpr);
+ if (TemplateArgs)
+ size += ExplicitTemplateArgumentList::sizeFor(*TemplateArgs);
+
+ void *Mem = C.Allocate(size, llvm::alignof<CXXDependentScopeMemberExpr>());
return new (Mem) CXXDependentScopeMemberExpr(C, Base, IsArrow, OperatorLoc,
Qualifier, QualifierRange,
FirstQualifierFoundInScope,
Member,
MemberLoc,
- HasExplicitTemplateArgs,
- LAngleLoc,
- TemplateArgs,
- NumTemplateArgs,
- RAngleLoc);
+ TemplateArgs);
}
Stmt::child_iterator CXXDependentScopeMemberExpr::child_begin() {
return false;
}
+bool TemplateSpecializationType::
+anyDependentTemplateArguments(const TemplateArgumentListInfo &Args) {
+ return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size());
+}
+
bool TemplateSpecializationType::
anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) {
for (unsigned i = 0; i != N; ++i)
}
}
+std::string TemplateSpecializationType::
+ PrintTemplateArgumentList(const TemplateArgumentListInfo &Args,
+ const PrintingPolicy &Policy) {
+ return PrintTemplateArgumentList(Args.getArgumentArray(),
+ Args.size(),
+ Policy);
+}
+
std::string
TemplateSpecializationType::PrintTemplateArgumentList(
const TemplateArgument *Args,
bool SuppressUserConversions = false,
bool ForceRValue = false);
void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr *Object, Expr **Args, unsigned NumArgs,
OverloadCandidateSet& CandidateSet,
bool SuppressUserConversions = false,
bool ForceRValue = false);
void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
OverloadCandidateSet& CandidateSet,
bool SuppressUserConversions = false,
OverloadCandidateSet& CandidateSet);
void AddArgumentDependentLookupCandidates(DeclarationName Name,
Expr **Args, unsigned NumArgs,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
OverloadCandidateSet& CandidateSet,
bool PartialOverloading = false);
bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
void AddOverloadedCallCandidates(llvm::SmallVectorImpl<NamedDecl*>& Callees,
DeclarationName &UnqualifiedName,
bool ArgumentDependentLookup,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
OverloadCandidateSet &CandidateSet,
bool PartialOverloading = false);
FunctionDecl *ResolveOverloadedCallFn(Expr *Fn,
llvm::SmallVectorImpl<NamedDecl*> &Fns,
DeclarationName UnqualifiedName,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
SourceLocation LParenLoc,
Expr **Args, unsigned NumArgs,
SourceLocation *CommaLocs,
// BuildMemberReferenceExpr to support explicitly-specified template
// arguments.
return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind, MemberLoc,
- MemberName, false, SourceLocation(), 0, 0,
- SourceLocation(), ImplDecl, SS,
+ MemberName, 0, ImplDecl, SS,
FirstQualifierInScope);
}
tok::TokenKind OpKind,
SourceLocation MemberLoc,
DeclarationName MemberName,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
DeclPtrTy ImplDecl,
const CXXScopeSpec *SS,
NamedDecl *FirstQualifierInScope = 0);
SourceRange &QualifierRange,
bool &ArgumentDependentLookup,
bool &Overloaded,
- bool &HasExplicitTemplateArguments,
- const TemplateArgumentLoc *&ExplicitTemplateArgs,
- unsigned &NumExplicitTemplateArgs);
+ bool &HasExplicitTemplateArgs,
+ TemplateArgumentListInfo &ExplicitTemplateArgs);
/// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
/// This provides the location of the left/right parens and a list of comma
TemplateParameterList *TemplateParams,
AccessSpecifier AS);
- void translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn,
- llvm::SmallVectorImpl<TemplateArgumentLoc> &TempArgs);
+ void translateTemplateArguments(const ASTTemplateArgsPtr &In,
+ TemplateArgumentListInfo &Out);
QualType CheckTemplateIdType(TemplateName Template,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo &TemplateArgs);
virtual TypeResult
ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
SourceRange QualifierRange,
TemplateName Template,
SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo &TemplateArgs);
OwningExprResult ActOnTemplateIdExpr(const CXXScopeSpec &SS,
TemplateTy Template,
bool &SuppressNew);
bool CheckFunctionTemplateSpecialization(FunctionDecl *FD,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
LookupResult &Previous);
bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous);
bool CheckTemplateArgumentList(TemplateDecl *Template,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo &TemplateArgs,
bool PartialTemplateArgs,
TemplateArgumentListBuilder &Converted);
TemplateDeductionResult
SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo &ExplicitTemplateArgs,
llvm::SmallVectorImpl<TemplateArgument> &Deduced,
llvm::SmallVectorImpl<QualType> &ParamTypes,
QualType *FunctionType,
TemplateDeductionResult
DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
FunctionDecl *&Specialization,
TemplateDeductionInfo &Info);
TemplateDeductionResult
DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
QualType ArgFunctionType,
FunctionDecl *&Specialization,
TemplateDeductionInfo &Info);
bool ArgumentDependentLookup;
bool Overloaded;
bool HasExplicitTemplateArgs;
- const TemplateArgumentLoc *ExplicitTemplateArgs;
- unsigned NumExplicitTemplateArgs;
+ TemplateArgumentListInfo ExplicitTemplateArgs;
DeconstructCallFunction(Fn, Fns, UnqualifiedName, Qualifier, QualifierRange,
ArgumentDependentLookup, Overloaded,
- HasExplicitTemplateArgs, ExplicitTemplateArgs,
- NumExplicitTemplateArgs);
+ HasExplicitTemplateArgs, ExplicitTemplateArgs);
// FIXME: What if we're calling something that isn't a function declaration?
// Build an overload candidate set based on the functions we find.
OverloadCandidateSet CandidateSet;
AddOverloadedCallCandidates(Fns, UnqualifiedName,
- ArgumentDependentLookup, HasExplicitTemplateArgs,
- ExplicitTemplateArgs, NumExplicitTemplateArgs,
+ ArgumentDependentLookup,
+ (HasExplicitTemplateArgs ? &ExplicitTemplateArgs : 0),
Args, NumArgs,
CandidateSet,
/*PartialOverloading=*/true);
// If the declarator is a template-id, translate the parser's template
// argument list into our AST format.
bool HasExplicitTemplateArgs = false;
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
- SourceLocation LAngleLoc, RAngleLoc;
+ TemplateArgumentListInfo TemplateArgs;
if (D.getName().getKind() == UnqualifiedId::IK_TemplateId) {
TemplateIdAnnotation *TemplateId = D.getName().TemplateId;
+ TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc);
+ TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc);
ASTTemplateArgsPtr TemplateArgsPtr(*this,
TemplateId->getTemplateArgs(),
TemplateId->NumArgs);
TemplateArgsPtr.release();
HasExplicitTemplateArgs = true;
- LAngleLoc = TemplateId->LAngleLoc;
- RAngleLoc = TemplateId->RAngleLoc;
if (FunctionTemplate) {
// FIXME: Diagnose function template with explicit template
}
if (isFunctionTemplateSpecialization) {
- if (CheckFunctionTemplateSpecialization(NewFD, HasExplicitTemplateArgs,
- LAngleLoc, TemplateArgs.data(),
- TemplateArgs.size(), RAngleLoc,
+ if (CheckFunctionTemplateSpecialization(NewFD,
+ (HasExplicitTemplateArgs ? &TemplateArgs : 0),
Previous))
NewFD->setInvalidDecl();
} else if (isExplicitSpecialization && isa<CXXMethodDecl>(NewFD) &&
Constructor->isConvertingConstructor(/*AllowExplicit=*/false)) ||
(Kind == Sema::IK_Default && Constructor->isDefaultConstructor())) {
if (ConstructorTmpl)
- SemaRef.AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0,
+ SemaRef.AddTemplateOverloadCandidate(ConstructorTmpl,
+ /*ExplicitArgs*/ 0,
Args, NumArgs, CandidateSet);
else
SemaRef.AddOverloadCandidate(Constructor, Args, NumArgs, CandidateSet);
(NestedNameSpecifier *)SS->getScopeRep(),
SS->getRange(), Member, Loc,
// FIXME: Explicit template argument lists
- false, SourceLocation(), 0, 0, SourceLocation(),
- Ty);
+ 0, Ty);
return new (C) MemberExpr(Base, isArrow, Member, Loc, Ty);
}
Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
tok::TokenKind OpKind, SourceLocation MemberLoc,
DeclarationName MemberName,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
DeclPtrTy ObjCImpDecl, const CXXScopeSpec *SS,
NamedDecl *FirstQualifierInScope) {
if (SS && SS->isInvalid())
FirstQualifierInScope,
MemberName,
MemberLoc,
- HasExplicitTemplateArgs,
- LAngleLoc,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
- RAngleLoc));
+ ExplicitTemplateArgs));
}
else if (const PointerType *PT = BaseType->getAs<PointerType>())
BaseType = PT->getPointeeType();
FirstQualifierInScope,
MemberName,
MemberLoc,
- HasExplicitTemplateArgs,
- LAngleLoc,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
- RAngleLoc));
+ ExplicitTemplateArgs));
}
}
= dyn_cast<FunctionTemplateDecl>(MemberDecl)) {
MarkDeclarationReferenced(MemberLoc, MemberDecl);
- if (HasExplicitTemplateArgs)
+ if (ExplicitTemplateArgs)
return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow,
(NestedNameSpecifier *)(SS? SS->getScopeRep() : 0),
SS? SS->getRange() : SourceRange(),
- FunTmpl, MemberLoc, true,
- LAngleLoc, ExplicitTemplateArgs,
- NumExplicitTemplateArgs, RAngleLoc,
+ FunTmpl, MemberLoc,
+ ExplicitTemplateArgs,
Context.OverloadTy));
return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS,
}
if (OverloadedFunctionDecl *Ovl
= dyn_cast<OverloadedFunctionDecl>(MemberDecl)) {
- if (HasExplicitTemplateArgs)
+ if (ExplicitTemplateArgs)
return Owned(MemberExpr::Create(Context, BaseExpr, OpKind == tok::arrow,
(NestedNameSpecifier *)(SS? SS->getScopeRep() : 0),
SS? SS->getRange() : SourceRange(),
- Ovl, MemberLoc, true,
- LAngleLoc, ExplicitTemplateArgs,
- NumExplicitTemplateArgs, RAngleLoc,
+ Ovl, MemberLoc, ExplicitTemplateArgs,
Context.OverloadTy));
return Owned(BuildMemberExpr(Context, BaseExpr, OpKind == tok::arrow, SS,
Member.TemplateId->getTemplateArgs(),
Member.TemplateId->NumArgs);
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
- translateTemplateArguments(TemplateArgsPtr,
- TemplateArgs);
+ TemplateArgumentListInfo TemplateArgs;
+ TemplateArgs.setLAngleLoc(Member.TemplateId->LAngleLoc);
+ TemplateArgs.setRAngleLoc(Member.TemplateId->RAngleLoc);
+ translateTemplateArguments(TemplateArgsPtr, TemplateArgs);
TemplateArgsPtr.release();
// Do we have the save the actual template name? We might need it...
return BuildMemberReferenceExpr(S, move(Base), OpLoc, OpKind,
Member.TemplateId->TemplateNameLoc,
- Name, true, Member.TemplateId->LAngleLoc,
- TemplateArgs.data(), TemplateArgs.size(),
- Member.TemplateId->RAngleLoc, DeclPtrTy(),
+ Name, &TemplateArgs, DeclPtrTy(),
&SS);
}
bool &ArgumentDependentLookup,
bool &Overloaded,
bool &HasExplicitTemplateArguments,
- const TemplateArgumentLoc *&ExplicitTemplateArgs,
- unsigned &NumExplicitTemplateArgs) {
+ TemplateArgumentListInfo &ExplicitTemplateArgs) {
// Set defaults for all of the output parameters.
Name = DeclarationName();
Qualifier = 0;
}
Overloaded = true;
HasExplicitTemplateArguments = true;
- ExplicitTemplateArgs = TemplateIdRef->getTemplateArgs();
- NumExplicitTemplateArgs = TemplateIdRef->getNumTemplateArgs();
+ TemplateIdRef->copyTemplateArgumentsInto(ExplicitTemplateArgs);
// C++ [temp.arg.explicit]p6:
// [Note: For simple function names, argument dependent lookup (3.4.2)
bool Overloaded;
bool ADL;
bool HasExplicitTemplateArgs = 0;
- const TemplateArgumentLoc *ExplicitTemplateArgs = 0;
- unsigned NumExplicitTemplateArgs = 0;
+ TemplateArgumentListInfo ExplicitTemplateArgs;
NestedNameSpecifier *Qualifier = 0;
SourceRange QualifierRange;
DeconstructCallFunction(Fn, Fns, UnqualifiedName, Qualifier, QualifierRange,
ADL, Overloaded, HasExplicitTemplateArgs,
- ExplicitTemplateArgs, NumExplicitTemplateArgs);
+ ExplicitTemplateArgs);
NamedDecl *NDecl; // the specific declaration we're calling, if applicable
FunctionDecl *FDecl; // same, if it's known to be a function
#endif
FDecl = ResolveOverloadedCallFn(Fn, Fns, UnqualifiedName,
- HasExplicitTemplateArgs,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ (HasExplicitTemplateArgs ? &ExplicitTemplateArgs : 0),
LParenLoc, Args, NumArgs, CommaLocs,
RParenLoc, ADL);
if (!FDecl)
if (!Constructor->isInvalidDecl() &&
Constructor->isConvertingConstructor(AllowExplicit)) {
if (ConstructorTmpl)
- AddTemplateOverloadCandidate(ConstructorTmpl, false, 0, 0, &From,
- 1, CandidateSet,
+ AddTemplateOverloadCandidate(ConstructorTmpl, /*ExplicitArgs*/ 0,
+ &From, 1, CandidateSet,
SuppressUserConversions, ForceRValue);
else
// Allow one user-defined conversion when user specifies a
if (isa<CXXMethodDecl>(FunTmpl->getTemplatedDecl()) &&
!cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl())->isStatic())
AddMethodTemplateCandidate(FunTmpl,
- /*FIXME: explicit args */false, 0, 0,
+ /*FIXME: explicit args */ 0,
Args[0], Args + 1, NumArgs - 1,
CandidateSet,
SuppressUserConversions);
else
AddTemplateOverloadCandidate(FunTmpl,
- /*FIXME: explicit args */false, 0, 0,
+ /*FIXME: explicit args */ 0,
Args, NumArgs, CandidateSet,
SuppressUserConversions);
}
if (FunctionTemplateDecl *TD = dyn_cast<FunctionTemplateDecl>(Decl)) {
assert(isa<CXXMethodDecl>(TD->getTemplatedDecl()) &&
"Expected a member function template");
- AddMethodTemplateCandidate(TD, false, 0, 0,
+ AddMethodTemplateCandidate(TD, /*ExplicitArgs*/ 0,
Object, Args, NumArgs,
CandidateSet,
SuppressUserConversions,
/// function template specialization.
void
Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr *Object, Expr **Args, unsigned NumArgs,
OverloadCandidateSet& CandidateSet,
bool SuppressUserConversions,
TemplateDeductionInfo Info(Context);
FunctionDecl *Specialization = 0;
if (TemplateDeductionResult Result
- = DeduceTemplateArguments(MethodTmpl, HasExplicitTemplateArgs,
- ExplicitTemplateArgs, NumExplicitTemplateArgs,
+ = DeduceTemplateArguments(MethodTmpl, ExplicitTemplateArgs,
Args, NumArgs, Specialization, Info)) {
// FIXME: Record what happened with template argument deduction, so
// that we can give the user a beautiful diagnostic.
/// an appropriate function template specialization.
void
Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
OverloadCandidateSet& CandidateSet,
bool SuppressUserConversions,
TemplateDeductionInfo Info(Context);
FunctionDecl *Specialization = 0;
if (TemplateDeductionResult Result
- = DeduceTemplateArguments(FunctionTemplate, HasExplicitTemplateArgs,
- ExplicitTemplateArgs, NumExplicitTemplateArgs,
+ = DeduceTemplateArguments(FunctionTemplate, ExplicitTemplateArgs,
Args, NumArgs, Specialization, Info)) {
// FIXME: Record what happened with template argument deduction, so
// that we can give the user a beautiful diagnostic.
void
Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
Expr **Args, unsigned NumArgs,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
OverloadCandidateSet& CandidateSet,
bool PartialOverloading) {
FunctionSet Functions;
FuncEnd = Functions.end();
Func != FuncEnd; ++Func) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*Func)) {
- if (HasExplicitTemplateArgs)
+ if (ExplicitTemplateArgs)
continue;
AddOverloadCandidate(FD, Args, NumArgs, CandidateSet,
false, false, PartialOverloading);
} else
AddTemplateOverloadCandidate(cast<FunctionTemplateDecl>(*Func),
- HasExplicitTemplateArgs,
ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
Args, NumArgs, CandidateSet);
}
}
}
bool HasExplicitTemplateArgs = false;
- const TemplateArgumentLoc *ExplicitTemplateArgs = 0;
- unsigned NumExplicitTemplateArgs = 0;
+ TemplateArgumentListInfo ExplicitTemplateArgs;
llvm::SmallVector<NamedDecl*,8> Fns;
assert(!isa<OverloadedFunctionDecl>(DR->getDecl()));
FunctionTemplate = dyn_cast<FunctionTemplateDecl>(DR->getDecl());
HasExplicitTemplateArgs = DR->hasExplicitTemplateArgumentList();
- ExplicitTemplateArgs = DR->getTemplateArgs();
- NumExplicitTemplateArgs = DR->getNumTemplateArgs();
+ if (HasExplicitTemplateArgs)
+ DR->copyTemplateArgumentsInto(ExplicitTemplateArgs);
} else if (UnresolvedLookupExpr *UL
= dyn_cast<UnresolvedLookupExpr>(OvlExpr)) {
Fns.append(UL->decls_begin(), UL->decls_end());
Ovl = dyn_cast<OverloadedFunctionDecl>(ME->getMemberDecl());
FunctionTemplate = dyn_cast<FunctionTemplateDecl>(ME->getMemberDecl());
HasExplicitTemplateArgs = ME->hasExplicitTemplateArgumentList();
- ExplicitTemplateArgs = ME->getTemplateArgs();
- NumExplicitTemplateArgs = ME->getNumTemplateArgs();
+ if (HasExplicitTemplateArgs)
+ ME->copyTemplateArgumentsInto(ExplicitTemplateArgs);
} else if (TemplateIdRefExpr *TIRE = dyn_cast<TemplateIdRefExpr>(OvlExpr)) {
TemplateName Name = TIRE->getTemplateName();
Ovl = Name.getAsOverloadedFunctionDecl();
dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
HasExplicitTemplateArgs = true;
- ExplicitTemplateArgs = TIRE->getTemplateArgs();
- NumExplicitTemplateArgs = TIRE->getNumTemplateArgs();
+ TIRE->copyTemplateArgumentsInto(ExplicitTemplateArgs);
}
if (Ovl) Fns.append(Ovl->function_begin(), Ovl->function_end());
FunctionDecl *Specialization = 0;
TemplateDeductionInfo Info(Context);
if (TemplateDeductionResult Result
- = DeduceTemplateArguments(FunctionTemplate, HasExplicitTemplateArgs,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ = DeduceTemplateArguments(FunctionTemplate,
+ (HasExplicitTemplateArgs ? &ExplicitTemplateArgs : 0),
FunctionType, Specialization, Info)) {
// FIXME: make a note of the failed deduction for diagnostics.
(void)Result;
/// \brief Add a single candidate to the overload set.
static void AddOverloadedCallCandidate(Sema &S,
NamedDecl *Callee,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
OverloadCandidateSet &CandidateSet,
bool PartialOverloading) {
Callee = cast<UsingShadowDecl>(Callee)->getTargetDecl();
if (FunctionDecl *Func = dyn_cast<FunctionDecl>(Callee)) {
- assert(!HasExplicitTemplateArgs && "Explicit template arguments?");
+ assert(!ExplicitTemplateArgs && "Explicit template arguments?");
S.AddOverloadCandidate(Func, Args, NumArgs, CandidateSet, false, false,
PartialOverloading);
return;
if (FunctionTemplateDecl *FuncTemplate
= dyn_cast<FunctionTemplateDecl>(Callee)) {
- S.AddTemplateOverloadCandidate(FuncTemplate, HasExplicitTemplateArgs,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ S.AddTemplateOverloadCandidate(FuncTemplate, ExplicitTemplateArgs,
Args, NumArgs, CandidateSet);
return;
}
void Sema::AddOverloadedCallCandidates(llvm::SmallVectorImpl<NamedDecl*> &Fns,
DeclarationName &UnqualifiedName,
bool ArgumentDependentLookup,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
OverloadCandidateSet &CandidateSet,
bool PartialOverloading) {
for (llvm::SmallVectorImpl<NamedDecl*>::iterator I = Fns.begin(),
E = Fns.end(); I != E; ++I)
- AddOverloadedCallCandidate(*this, *I, HasExplicitTemplateArgs,
- ExplicitTemplateArgs, NumExplicitTemplateArgs,
+ AddOverloadedCallCandidate(*this, *I, ExplicitTemplateArgs,
Args, NumArgs, CandidateSet,
PartialOverloading);
if (ArgumentDependentLookup)
AddArgumentDependentLookupCandidates(UnqualifiedName, Args, NumArgs,
- HasExplicitTemplateArgs,
ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
CandidateSet,
PartialOverloading);
}
FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn,
llvm::SmallVectorImpl<NamedDecl*> &Fns,
DeclarationName UnqualifiedName,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
SourceLocation LParenLoc,
Expr **Args, unsigned NumArgs,
SourceLocation *CommaLocs,
// Add the functions denoted by Callee to the set of candidate
// functions.
AddOverloadedCallCandidates(Fns, UnqualifiedName, ArgumentDependentLookup,
- HasExplicitTemplateArgs, ExplicitTemplateArgs,
- NumExplicitTemplateArgs, Args, NumArgs,
+ ExplicitTemplateArgs, Args, NumArgs,
CandidateSet);
OverloadCandidateSet::iterator Best;
switch (BestViableFunction(CandidateSet, Fn->getLocStart(), Best)) {
AddMethodCandidate(Method, ObjectArg, Args, NumArgs, CandidateSet,
/*SuppressUserConversions=*/false);
- } else
+ } else {
+ // FIXME: avoid copy.
+ TemplateArgumentListInfo TemplateArgs;
+ if (MemExpr->hasExplicitTemplateArgumentList())
+ MemExpr->copyTemplateArgumentsInto(TemplateArgs);
+
AddMethodTemplateCandidate(cast<FunctionTemplateDecl>(*Func),
- MemExpr->hasExplicitTemplateArgumentList(),
- MemExpr->getTemplateArgs(),
- MemExpr->getNumTemplateArgs(),
+ (MemExpr->hasExplicitTemplateArgumentList()
+ ? &TemplateArgs : 0),
ObjectArg, Args, NumArgs,
CandidateSet,
/*SuppressUsedConversions=*/false);
+ }
}
OverloadCandidateSet::iterator Best;
assert((isa<FunctionTemplateDecl>(DRE->getDecl()) ||
isa<FunctionDecl>(DRE->getDecl())) &&
"Expected function or function template");
+ // FIXME: avoid copy.
+ TemplateArgumentListInfo TemplateArgs;
+ if (DRE->hasExplicitTemplateArgumentList())
+ DRE->copyTemplateArgumentsInto(TemplateArgs);
+
return DeclRefExpr::Create(Context,
DRE->getQualifier(),
DRE->getQualifierRange(),
Fn,
DRE->getLocation(),
- DRE->hasExplicitTemplateArgumentList(),
- DRE->getLAngleLoc(),
- DRE->getTemplateArgs(),
- DRE->getNumTemplateArgs(),
- DRE->getRAngleLoc(),
+ (DRE->hasExplicitTemplateArgumentList()
+ ? &TemplateArgs : 0),
Fn->getType(),
DRE->isTypeDependent(),
DRE->isValueDependent());
isa<FunctionTemplateDecl>(MemExpr->getMemberDecl()) ||
isa<FunctionDecl>(MemExpr->getMemberDecl())) &&
"Expected member function or member function template");
+ // FIXME: avoid copy.
+ TemplateArgumentListInfo TemplateArgs;
+ if (MemExpr->hasExplicitTemplateArgumentList())
+ MemExpr->copyTemplateArgumentsInto(TemplateArgs);
+
return MemberExpr::Create(Context, MemExpr->getBase()->Retain(),
MemExpr->isArrow(),
MemExpr->getQualifier(),
MemExpr->getQualifierRange(),
Fn,
- MemExpr->getMemberLoc(),
- MemExpr->hasExplicitTemplateArgumentList(),
- MemExpr->getLAngleLoc(),
- MemExpr->getTemplateArgs(),
- MemExpr->getNumTemplateArgs(),
- MemExpr->getRAngleLoc(),
+ MemExpr->getMemberLoc(),
+ (MemExpr->hasExplicitTemplateArgumentList()
+ ? &TemplateArgs : 0),
Fn->getType());
}
// FIXME: Don't destroy TID here, since we need its template arguments
// to survive.
// TID->Destroy(Context);
+
+ // FIXME: avoid copy.
+ TemplateArgumentListInfo TemplateArgs;
+ TID->copyTemplateArgumentsInto(TemplateArgs);
+
return DeclRefExpr::Create(Context,
TID->getQualifier(), TID->getQualifierRange(),
Fn, TID->getTemplateNameLoc(),
- true,
- TID->getLAngleLoc(),
- TID->getTemplateArgs(),
- TID->getNumTemplateArgs(),
- TID->getRAngleLoc(),
+ &TemplateArgs,
Fn->getType(),
/*FIXME?*/false, /*FIXME?*/false);
}
/// \brief Translates template arguments as provided by the parser
/// into template arguments used by semantic analysis.
-void Sema::translateTemplateArguments(ASTTemplateArgsPtr &TemplateArgsIn,
- llvm::SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs) {
- TemplateArgs.reserve(TemplateArgsIn.size());
-
+void Sema::translateTemplateArguments(const ASTTemplateArgsPtr &TemplateArgsIn,
+ TemplateArgumentListInfo &TemplateArgs) {
for (unsigned I = 0, Last = TemplateArgsIn.size(); I != Last; ++I)
- TemplateArgs.push_back(translateTemplateArgument(*this, TemplateArgsIn[I]));
+ TemplateArgs.addArgument(translateTemplateArgument(*this,
+ TemplateArgsIn[I]));
}
/// ActOnTypeParameter - Called when a C++ template type parameter
QualType Sema::CheckTemplateIdType(TemplateName Name,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc) {
+ const TemplateArgumentListInfo &TemplateArgs) {
TemplateDecl *Template = Name.getAsTemplateDecl();
if (!Template) {
// The template name does not resolve to a template, so we just
// build a dependent template-id type.
- return Context.getTemplateSpecializationType(Name, TemplateArgs,
- NumTemplateArgs);
+ return Context.getTemplateSpecializationType(Name, TemplateArgs);
}
// Check that the template argument list is well-formed for this
// template.
TemplateArgumentListBuilder Converted(Template->getTemplateParameters(),
- NumTemplateArgs);
- if (CheckTemplateArgumentList(Template, TemplateLoc, LAngleLoc,
- TemplateArgs, NumTemplateArgs, RAngleLoc,
+ TemplateArgs.size());
+ if (CheckTemplateArgumentList(Template, TemplateLoc, TemplateArgs,
false, Converted))
return QualType();
if (Name.isDependent() ||
TemplateSpecializationType::anyDependentTemplateArguments(
- TemplateArgs,
- NumTemplateArgs)) {
+ TemplateArgs)) {
// This class template specialization is a dependent
// type. Therefore, its canonical type is another class template
// specialization type that contains all of the converted
// Build the fully-sugared type for this class template
// specialization, which refers back to the class template
// specialization we created or found.
- return Context.getTemplateSpecializationType(Name, TemplateArgs,
- NumTemplateArgs, CanonType);
+ return Context.getTemplateSpecializationType(Name, TemplateArgs, CanonType);
}
Action::TypeResult
TemplateName Template = TemplateD.getAsVal<TemplateName>();
// Translate the parser's template argument list in our AST format.
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
+ TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
translateTemplateArguments(TemplateArgsIn, TemplateArgs);
- QualType Result = CheckTemplateIdType(Template, TemplateLoc, LAngleLoc,
- TemplateArgs.data(),
- TemplateArgs.size(),
- RAngleLoc);
+ QualType Result = CheckTemplateIdType(Template, TemplateLoc, TemplateArgs);
TemplateArgsIn.release();
if (Result.isNull())
SourceRange QualifierRange,
TemplateName Template,
SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc) {
+ const TemplateArgumentListInfo &TemplateArgs) {
// FIXME: Can we do any checking at this point? I guess we could check the
// template arguments that we have against the template name, if the template
// name refers to a single template. That's not a terribly common case,
Expr *This = new (Context) CXXThisExpr(SourceLocation(), ThisType);
return Owned(MemberExpr::Create(Context, This, true,
Qualifier, QualifierRange,
- D, TemplateNameLoc, true,
- LAngleLoc, TemplateArgs,
- NumTemplateArgs, RAngleLoc,
+ D, TemplateNameLoc, &TemplateArgs,
Context.OverloadTy));
}
return Owned(TemplateIdRefExpr::Create(Context, Context.OverloadTy,
Qualifier, QualifierRange,
- Template, TemplateNameLoc, LAngleLoc,
- TemplateArgs,
- NumTemplateArgs, RAngleLoc));
+ Template, TemplateNameLoc,
+ TemplateArgs));
}
Sema::OwningExprResult Sema::ActOnTemplateIdExpr(const CXXScopeSpec &SS,
TemplateName Template = TemplateD.getAsVal<TemplateName>();
// Translate the parser's template argument list in our AST format.
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
+ TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
translateTemplateArguments(TemplateArgsIn, TemplateArgs);
TemplateArgsIn.release();
return BuildTemplateIdExpr((NestedNameSpecifier *)SS.getScopeRep(),
SS.getRange(),
- Template, TemplateNameLoc, LAngleLoc,
- TemplateArgs.data(), TemplateArgs.size(),
- RAngleLoc);
+ Template, TemplateNameLoc, TemplateArgs);
}
/// \brief Form a dependent template name.
/// for specializing the given template.
bool Sema::CheckTemplateArgumentList(TemplateDecl *Template,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo &TemplateArgs,
bool PartialTemplateArgs,
TemplateArgumentListBuilder &Converted) {
TemplateParameterList *Params = Template->getTemplateParameters();
unsigned NumParams = Params->size();
- unsigned NumArgs = NumTemplateArgs;
+ unsigned NumArgs = TemplateArgs.size();
bool Invalid = false;
+ SourceLocation RAngleLoc = TemplateArgs.getRAngleLoc();
+
bool HasParameterPack =
NumParams > 0 && Params->getParam(NumParams - 1)->isTemplateParameterPack();
}
// Translate the parser's template argument list in our AST format.
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
+ TemplateArgumentListInfo TemplateArgs;
+ TemplateArgs.setLAngleLoc(LAngleLoc);
+ TemplateArgs.setRAngleLoc(RAngleLoc);
translateTemplateArguments(TemplateArgsIn, TemplateArgs);
// Check that the template argument list is well-formed for this
// template.
TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
TemplateArgs.size());
- if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
- TemplateArgs.data(), TemplateArgs.size(),
- RAngleLoc, false, Converted))
+ if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc,
+ TemplateArgs, false, Converted))
return true;
assert((Converted.structuredSize() ==
TemplateParams,
ClassTemplate,
Converted,
- TemplateArgs.data(),
- TemplateArgs.size(),
+ TemplateArgs,
PrevPartial);
if (PrevPartial) {
// name based on the "canonical" representation used to store the
// template arguments in the specialization.
QualType WrittenTy
- = Context.getTemplateSpecializationType(Name,
- TemplateArgs.data(),
- TemplateArgs.size(),
- CanonType);
+ = Context.getTemplateSpecializationType(Name, TemplateArgs, CanonType);
if (TUK != TUK_Friend)
Specialization->setTypeAsWritten(WrittenTy);
TemplateArgsIn.release();
/// \param PrevDecl the set of declarations that
bool
Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
LookupResult &Previous) {
// The set of function template specializations that could match this
// explicit function template specialization.
TemplateDeductionInfo Info(Context);
FunctionDecl *Specialization = 0;
if (TemplateDeductionResult TDK
- = DeduceTemplateArguments(FunTmpl, HasExplicitTemplateArgs,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ = DeduceTemplateArguments(FunTmpl, ExplicitTemplateArgs,
FD->getType(),
Specialization,
Info)) {
PartialDiagnostic(diag::err_function_template_spec_no_match)
<< FD->getDeclName(),
PartialDiagnostic(diag::err_function_template_spec_ambiguous)
- << FD->getDeclName() << HasExplicitTemplateArgs,
+ << FD->getDeclName() << (ExplicitTemplateArgs != 0),
PartialDiagnostic(diag::note_function_template_spec_matched));
if (!Specialization)
return true;
: TSK_ExplicitInstantiationDeclaration;
// Translate the parser's template argument list in our AST format.
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
+ TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
translateTemplateArguments(TemplateArgsIn, TemplateArgs);
// Check that the template argument list is well-formed for this
// template.
TemplateArgumentListBuilder Converted(ClassTemplate->getTemplateParameters(),
TemplateArgs.size());
- if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc, LAngleLoc,
- TemplateArgs.data(), TemplateArgs.size(),
- RAngleLoc, false, Converted))
+ if (CheckTemplateArgumentList(ClassTemplate, TemplateNameLoc,
+ TemplateArgs, false, Converted))
return true;
assert((Converted.structuredSize() ==
// on the "canonical" representation used to store the template
// arguments in the specialization.
QualType WrittenTy
- = Context.getTemplateSpecializationType(Name,
- TemplateArgs.data(),
- TemplateArgs.size(),
+ = Context.getTemplateSpecializationType(Name, TemplateArgs,
Context.getTypeDeclType(Specialization));
Specialization->setTypeAsWritten(WrittenTy);
TemplateArgsIn.release();
// If the declarator is a template-id, translate the parser's template
// argument list into our AST format.
bool HasExplicitTemplateArgs = false;
- llvm::SmallVector<TemplateArgumentLoc, 16> TemplateArgs;
+ TemplateArgumentListInfo TemplateArgs;
if (D.getName().getKind() == UnqualifiedId::IK_TemplateId) {
TemplateIdAnnotation *TemplateId = D.getName().TemplateId;
+ TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc);
+ TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc);
ASTTemplateArgsPtr TemplateArgsPtr(*this,
TemplateId->getTemplateArgs(),
TemplateId->NumArgs);
- translateTemplateArguments(TemplateArgsPtr,
- TemplateArgs);
+ translateTemplateArguments(TemplateArgsPtr, TemplateArgs);
HasExplicitTemplateArgs = true;
TemplateArgsPtr.release();
}
TemplateDeductionInfo Info(Context);
FunctionDecl *Specialization = 0;
if (TemplateDeductionResult TDK
- = DeduceTemplateArguments(FunTmpl, HasExplicitTemplateArgs,
- TemplateArgs.data(), TemplateArgs.size(),
+ = DeduceTemplateArguments(FunTmpl,
+ (HasExplicitTemplateArgs ? &TemplateArgs : 0),
R, Specialization, Info)) {
// FIXME: Keep track of almost-matches?
(void)TDK;
const TemplateArgumentLoc *PartialTemplateArgs
= Partial->getTemplateArgsAsWritten();
unsigned N = Partial->getNumTemplateArgsAsWritten();
- llvm::SmallVector<TemplateArgumentLoc, 16> InstArgs(N);
+
+ // Note that we don't provide the langle and rangle locations.
+ TemplateArgumentListInfo InstArgs;
+
for (unsigned I = 0; I != N; ++I) {
Decl *Param = const_cast<NamedDecl *>(
ClassTemplate->getTemplateParameters()->getParam(I));
- if (Subst(PartialTemplateArgs[I], InstArgs[I],
+ TemplateArgumentLoc InstArg;
+ if (Subst(PartialTemplateArgs[I], InstArg,
MultiLevelTemplateArgumentList(*DeducedArgumentList))) {
Info.Param = makeTemplateParameter(Param);
Info.FirstArg = PartialTemplateArgs[I].getArgument();
return TDK_SubstitutionFailure;
}
+ InstArgs.addArgument(InstArg);
}
TemplateArgumentListBuilder ConvertedInstArgs(
ClassTemplate->getTemplateParameters(), N);
if (CheckTemplateArgumentList(ClassTemplate, Partial->getLocation(),
- /*LAngle*/ SourceLocation(),
- InstArgs.data(), N,
- /*RAngle*/ SourceLocation(),
- false, ConvertedInstArgs)) {
+ InstArgs, false, ConvertedInstArgs)) {
// FIXME: fail with more useful information?
return TDK_SubstitutionFailure;
}
for (unsigned I = 0, E = ConvertedInstArgs.flatSize(); I != E; ++I) {
- // We don't really care if we overwrite the internal structures of
- // the arg list builder, because we're going to throw it all away.
- TemplateArgument &InstArg
- = const_cast<TemplateArgument&>(ConvertedInstArgs.getFlatArguments()[I]);
+ TemplateArgument InstArg = ConvertedInstArgs.getFlatArguments()[I];
Decl *Param = const_cast<NamedDecl *>(
ClassTemplate->getTemplateParameters()->getParam(I));
/// \param ExplicitTemplateArguments the explicitly-specified template
/// arguments.
///
-/// \param NumExplicitTemplateArguments the number of explicitly-specified
-/// template arguments in @p ExplicitTemplateArguments. This value may be zero.
-///
/// \param Deduced the deduced template arguments, which will be populated
/// with the converted and checked explicit template arguments.
///
Sema::TemplateDeductionResult
Sema::SubstituteExplicitTemplateArguments(
FunctionTemplateDecl *FunctionTemplate,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo &ExplicitTemplateArgs,
llvm::SmallVectorImpl<TemplateArgument> &Deduced,
llvm::SmallVectorImpl<QualType> &ParamTypes,
QualType *FunctionType,
TemplateParameterList *TemplateParams
= FunctionTemplate->getTemplateParameters();
- if (NumExplicitTemplateArgs == 0) {
+ if (ExplicitTemplateArgs.size() == 0) {
// No arguments to substitute; just copy over the parameter types and
// fill in the function type.
for (FunctionDecl::param_iterator P = Function->param_begin(),
// template argument list shall not specify more template-arguments than
// there are corresponding template-parameters.
TemplateArgumentListBuilder Builder(TemplateParams,
- NumExplicitTemplateArgs);
+ ExplicitTemplateArgs.size());
// Enter a new template instantiation context where we check the
// explicitly-specified template arguments against this function template,
return TDK_InstantiationDepth;
if (CheckTemplateArgumentList(FunctionTemplate,
- SourceLocation(), SourceLocation(),
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
SourceLocation(),
+ ExplicitTemplateArgs,
true,
Builder) || Trap.hasErrorOccurred())
return TDK_InvalidExplicitArguments;
/// \returns the result of template argument deduction.
Sema::TemplateDeductionResult
Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
Expr **Args, unsigned NumArgs,
FunctionDecl *&Specialization,
TemplateDeductionInfo &Info) {
= FunctionTemplate->getTemplateParameters();
llvm::SmallVector<TemplateArgument, 4> Deduced;
llvm::SmallVector<QualType, 4> ParamTypes;
- if (NumExplicitTemplateArgs) {
+ if (ExplicitTemplateArgs) {
TemplateDeductionResult Result =
SubstituteExplicitTemplateArguments(FunctionTemplate,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ *ExplicitTemplateArgs,
Deduced,
ParamTypes,
0,
/// \returns the result of template argument deduction.
Sema::TemplateDeductionResult
Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
- bool HasExplicitTemplateArgs,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
QualType ArgFunctionType,
FunctionDecl *&Specialization,
TemplateDeductionInfo &Info) {
// Substitute any explicit template arguments.
llvm::SmallVector<TemplateArgument, 4> Deduced;
llvm::SmallVector<QualType, 4> ParamTypes;
- if (HasExplicitTemplateArgs) {
+ if (ExplicitTemplateArgs) {
if (TemplateDeductionResult Result
= SubstituteExplicitTemplateArguments(FunctionTemplate,
- ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
+ *ExplicitTemplateArgs,
Deduced, ParamTypes,
&FunctionType, Info))
return Result;
= PartialSpec->getTemplateArgsAsWritten();
unsigned N = PartialSpec->getNumTemplateArgsAsWritten();
- llvm::SmallVector<TemplateArgumentLoc, 4> InstTemplateArgs(N);
+ TemplateArgumentListInfo InstTemplateArgs; // no angle locations
for (unsigned I = 0; I != N; ++I) {
- if (SemaRef.Subst(PartialSpecTemplateArgs[I], InstTemplateArgs[I],
- TemplateArgs))
+ TemplateArgumentLoc Loc;
+ if (SemaRef.Subst(PartialSpecTemplateArgs[I], Loc, TemplateArgs))
return true;
+ InstTemplateArgs.addArgument(Loc);
}
InstTemplateArgs.size());
if (SemaRef.CheckTemplateArgumentList(ClassTemplate,
PartialSpec->getLocation(),
- /*FIXME:*/PartialSpec->getLocation(),
- InstTemplateArgs.data(),
- InstTemplateArgs.size(),
- /*FIXME:*/PartialSpec->getLocation(),
+ InstTemplateArgs,
false,
Converted))
return true;
// template arguments in the specialization.
QualType WrittenTy
= SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
- InstTemplateArgs.data(),
- InstTemplateArgs.size(),
+ InstTemplateArgs,
CanonType);
if (PrevDecl) {
InstParams,
ClassTemplate,
Converted,
- InstTemplateArgs.data(),
- InstTemplateArgs.size(),
+ InstTemplateArgs,
0);
InstPartialSpec->setInstantiatedFromMember(PartialSpec);
InstPartialSpec->setTypeAsWritten(WrittenTy);
/// different behavior.
QualType RebuildTemplateSpecializationType(TemplateName Template,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *Args,
- unsigned NumArgs,
- SourceLocation RAngleLoc);
+ const TemplateArgumentListInfo &Args);
/// \brief Build a new qualified name type.
///
SourceRange QualifierRange,
SourceLocation MemberLoc,
NamedDecl *Member,
- bool HasExplicitTemplateArgs,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *ExplicitTemplateArgs,
- unsigned NumExplicitTemplateArgs,
- SourceLocation RAngleLoc,
+ const TemplateArgumentListInfo *ExplicitTemplateArgs,
NamedDecl *FirstQualifierInScope) {
if (!Member->getDeclName()) {
// We have a reference to an unnamed field.
isArrow? tok::arrow : tok::period,
MemberLoc,
Member->getDeclName(),
- HasExplicitTemplateArgs,
- LAngleLoc,
ExplicitTemplateArgs,
- NumExplicitTemplateArgs,
- RAngleLoc,
/*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
&SS,
FirstQualifierInScope);
SourceRange QualifierRange,
TemplateName Template,
SourceLocation TemplateLoc,
- SourceLocation LAngleLoc,
- TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc) {
+ const TemplateArgumentListInfo &TemplateArgs) {
return getSema().BuildTemplateIdExpr(Qualifier, QualifierRange,
- Template, TemplateLoc,
- LAngleLoc,
- TemplateArgs, NumTemplateArgs,
- RAngleLoc);
+ Template, TemplateLoc, TemplateArgs);
}
/// \brief Build a new object-construction expression.
TemplateName Template,
SourceLocation TemplateNameLoc,
NamedDecl *FirstQualifierInScope,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *TemplateArgs,
- unsigned NumTemplateArgs,
- SourceLocation RAngleLoc) {
+ const TemplateArgumentListInfo &TemplateArgs) {
OwningExprResult Base = move(BaseE);
tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Name = SemaRef.Context.DeclarationNames.getCXXOperatorName(
DTN->getOperator());
}
- return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
- OperatorLoc, OpKind,
- TemplateNameLoc, Name, true,
- LAngleLoc, TemplateArgs,
- NumTemplateArgs, RAngleLoc,
- Sema::DeclPtrTy(), &SS);
+ return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
+ OperatorLoc, OpKind,
+ TemplateNameLoc, Name,
+ &TemplateArgs,
+ Sema::DeclPtrTy(), &SS);
}
/// \brief Build a new Objective-C @encode expression.
if (Template.isNull())
return QualType();
- llvm::SmallVector<TemplateArgumentLoc, 4> NewTemplateArgs(T->getNumArgs());
- for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i)
- if (getDerived().TransformTemplateArgument(TL.getArgLoc(i),
- NewTemplateArgs[i]))
+ TemplateArgumentListInfo NewTemplateArgs;
+ NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
+ NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
+
+ for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
+ TemplateArgumentLoc Loc;
+ if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
return QualType();
+ NewTemplateArgs.addArgument(Loc);
+ }
// FIXME: maybe don't rebuild if all the template arguments are the same.
QualType Result =
getDerived().RebuildTemplateSpecializationType(Template,
TL.getTemplateNameLoc(),
- TL.getLAngleLoc(),
- NewTemplateArgs.data(),
- NewTemplateArgs.size(),
- TL.getRAngleLoc());
+ NewTemplateArgs);
if (!Result.isNull()) {
TemplateSpecializationTypeLoc NewTL
!E->hasExplicitTemplateArgumentList())
return SemaRef.Owned(E->Retain());
- llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs;
+ TemplateArgumentListInfo TransArgs;
if (E->hasExplicitTemplateArgumentList()) {
- TransArgs.resize(E->getNumTemplateArgs());
+ TransArgs.setLAngleLoc(E->getLAngleLoc());
+ TransArgs.setRAngleLoc(E->getRAngleLoc());
for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
- if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
- TransArgs[I]))
+ TemplateArgumentLoc Loc;
+ if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
return SemaRef.ExprError();
+ TransArgs.addArgument(Loc);
}
}
E->getQualifierRange(),
E->getMemberLoc(),
Member,
- E->hasExplicitTemplateArgumentList(),
- E->getLAngleLoc(),
- TransArgs.data(),
- TransArgs.size(),
- E->getRAngleLoc(),
+ (E->hasExplicitTemplateArgumentList()
+ ? &TransArgs : 0),
0);
}
if (!Qualifier)
return SemaRef.ExprError();
}
-
- llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
+
+ TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
- if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
- TransArgs[I]))
+ TemplateArgumentLoc Loc;
+ if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
return SemaRef.ExprError();
+ TransArgs.addArgument(Loc);
}
// FIXME: Would like to avoid rebuilding if nothing changed, but we can't
// with a functional cast. Give a reasonable error message!
return getDerived().RebuildTemplateIdExpr(Qualifier, E->getQualifierRange(),
Template, E->getTemplateNameLoc(),
- E->getLAngleLoc(),
- TransArgs.data(),
- TransArgs.size(),
- E->getRAngleLoc());
+ TransArgs);
}
template<typename Derived>
if (Template.isNull())
return SemaRef.ExprError();
- llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
+ TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
- if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
- TransArgs[I]))
+ TemplateArgumentLoc Loc;
+ if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
return SemaRef.ExprError();
+ TransArgs.addArgument(Loc);
}
return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Template,
E->getMemberLoc(),
FirstQualifierInScope,
- E->getLAngleLoc(),
- TransArgs.data(),
- TransArgs.size(),
- E->getRAngleLoc());
+ TransArgs);
}
template<typename Derived>
QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
TemplateName Template,
SourceLocation TemplateNameLoc,
- SourceLocation LAngleLoc,
- const TemplateArgumentLoc *Args,
- unsigned NumArgs,
- SourceLocation RAngleLoc) {
- return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, LAngleLoc,
- Args, NumArgs, RAngleLoc);
+ const TemplateArgumentListInfo &TemplateArgs) {
+ return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
}
template<typename Derived>
SourceRange Range,
IdentifierInfo &II,
QualType ObjectType,
- NamedDecl *FirstQualifierInScope) {
+ NamedDecl *FirstQualifierInScope) {
CXXScopeSpec SS;
// FIXME: The source location information is all wrong.
SS.setRange(Range);