]> granicus.if.org Git - clang/commitdiff
Encapsulate "an array of TemplateArgumentLocs and two angle bracket locations" into
authorJohn McCall <rjmccall@apple.com>
Mon, 23 Nov 2009 01:53:49 +0000 (01:53 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 23 Nov 2009 01:53:49 +0000 (01:53 +0000)
a new class.  Use it pervasively throughout Sema.

My fingers hurt.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89638 91177308-0d34-0410-b5e6-96231b3b80d8

24 files changed:
include/clang/AST/ASTContext.h
include/clang/AST/Decl.h
include/clang/AST/DeclCXX.h
include/clang/AST/DeclTemplate.h
include/clang/AST/Expr.h
include/clang/AST/ExprCXX.h
include/clang/AST/TemplateBase.h
include/clang/AST/Type.h
lib/AST/ASTContext.cpp
lib/AST/DeclTemplate.cpp
lib/AST/Expr.cpp
lib/AST/ExprCXX.cpp
lib/AST/Type.cpp
lib/AST/TypePrinter.cpp
lib/Sema/Sema.h
lib/Sema/SemaCodeComplete.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaOverload.cpp
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateDeduction.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Sema/TreeTransform.h

index df5a7150b01c2bd10fafa0b126c38663607b18db..d6c32c27b9d58ee61bfba52432e464dbd5dece38 100644 (file)
@@ -532,8 +532,7 @@ public:
                                          QualType Canon = QualType());
 
   QualType getTemplateSpecializationType(TemplateName T,
-                                         const TemplateArgumentLoc *Args,
-                                         unsigned NumArgs,
+                                         const TemplateArgumentListInfo &Args,
                                          QualType Canon = QualType());
 
   QualType getQualifiedNameType(NestedNameSpecifier *NNS,
index ac79a91792d7136f064e004587cddc69c180c6a7..d3113d11929a173b0182a52a0544c1c8b1f10745 100644 (file)
@@ -54,6 +54,30 @@ public:
   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;
index 66c8174bbac8913c6e1f04bd85d5bb3ffaf98e5c..2c43e960859f4b346c6245a6b79ba47b83e8e1f5 100644 (file)
@@ -88,28 +88,6 @@ namespace llvm {
 
 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.
index 14f666005cd6266ee8d6e85eb580f853e2e887ab..3ecc4bb52b4cad6db7e1c8d488acf9ec5b8a7e58 100644 (file)
@@ -955,8 +955,7 @@ public:
          TemplateParameterList *Params,
          ClassTemplateDecl *SpecializedTemplate,
          TemplateArgumentListBuilder &Builder,
-         TemplateArgumentLoc *ArgInfos,
-         unsigned NumArgInfos,
+         const TemplateArgumentListInfo &ArgInfos,
          ClassTemplatePartialSpecializationDecl *PrevDecl);
 
   /// Get the list of template parameters
index dfc5b13f28d3044505f76516a6ba94c629b94952..47404fa7bfb678e1ddbeaeeaf8e1806230df903d 100644 (file)
@@ -35,6 +35,7 @@ namespace clang {
   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
@@ -366,6 +367,10 @@ struct ExplicitTemplateArgumentList {
   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,
@@ -423,11 +428,7 @@ class DeclRefExpr : public Expr {
   
   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:
@@ -465,11 +466,7 @@ public:
                              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(); }
@@ -508,6 +505,13 @@ public:
   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.
@@ -1313,9 +1317,7 @@ class MemberExpr : public Expr {
 
   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,
@@ -1334,11 +1336,7 @@ public:
                             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; }
@@ -1378,10 +1376,17 @@ public:
 
   /// \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 {
index a180c7c32b3b668be65e8cb2a243aed7e2f942ec..055926f03d746a0ac325487a7e0de1d4922d7dbe 100644 (file)
@@ -17,7 +17,7 @@
 #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 {
 
@@ -25,6 +25,7 @@ namespace clang {
   class CXXDestructorDecl;
   class CXXMethodDecl;
   class CXXTemporary;
+  class TemplateArgumentListInfo;
 
 //===--------------------------------------------------------------------===//
 // C++ Expressions.
@@ -1215,10 +1216,7 @@ class TemplateIdRefExpr : public Expr {
   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);
 
@@ -1227,8 +1225,7 @@ public:
   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
@@ -1261,6 +1258,15 @@ public:
   /// 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; }
@@ -1496,11 +1502,7 @@ class CXXDependentScopeMemberExpr : public Expr {
                           NamedDecl *FirstQualifierFoundInScope,
                           DeclarationName Member,
                           SourceLocation MemberLoc,
-                          bool HasExplicitTemplateArgs,
-                          SourceLocation LAngleLoc,
-                          const TemplateArgumentLoc *TemplateArgs,
-                          unsigned NumTemplateArgs,
-                          SourceLocation RAngleLoc);
+                          const TemplateArgumentListInfo *TemplateArgs);
 
 public:
   CXXDependentScopeMemberExpr(ASTContext &C,
@@ -1527,11 +1529,7 @@ public:
          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.
@@ -1582,10 +1580,17 @@ public:
 
   /// \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 {
index 6db095872b0e8138c3d776829ac89f44cf2153e4..b46b3dc5d2d2916c8ed4dd6005c12a6daa875969 100644 (file)
@@ -16,6 +16,7 @@
 #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"
@@ -437,6 +438,41 @@ public:
   }  
 };
 
+/// 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
index 89b3f592181f18e8bc6d6d72684dd7f412d41ecb..5b09ef08ecfd04a569a6ec2cc49fdfbc9a7b1edc 100644 (file)
@@ -82,6 +82,7 @@ namespace clang {
   class StmtIteratorBase;
   class TemplateArgument;
   class TemplateArgumentLoc;
+  class TemplateArgumentListInfo;
   class QualifiedNameType;
   struct PrintingPolicy;
 
@@ -2280,6 +2281,8 @@ public:
   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,
@@ -2290,6 +2293,9 @@ public:
                                                unsigned NumArgs,
                                                const PrintingPolicy &Policy);
 
+  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
+                                               const PrintingPolicy &Policy);
+
   typedef const TemplateArgument * iterator;
 
   iterator begin() const { return getArgs(); }
index 12b1092b1a230655b2e06db8df8233ccc4e9e864..dc92afdd111bb2a2f969126dee7ca3aebf2f05a1 100644 (file)
@@ -1832,9 +1832,10 @@ QualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index,
 
 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)
index 0c14714812f5aa2852d04f8a8eea6b59b43eb48e..2d2851036c1eb566f0ea514d6304711efb2a8c0a 100644 (file)
@@ -453,8 +453,9 @@ Create(ASTContext &Context, DeclContext *DC, SourceLocation L,
        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];
index be613dc823005edaba9facf280449ee2fc41cc5d..61492694fcb420419c5e1dc8858c461a8f55ea19 100644 (file)
@@ -31,20 +31,40 @@ using namespace clang;
 // 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) {
@@ -53,17 +73,8 @@ DeclRefExpr::DeclRefExpr(NestedNameSpecifier *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,
@@ -73,8 +84,7 @@ 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,
@@ -82,28 +92,18 @@ 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 {
@@ -428,15 +428,13 @@ QualType CallExpr::getCallReturnType() 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();
@@ -445,17 +443,8 @@ MemberExpr::MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual,
   }
 
   // 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,
@@ -463,24 +452,18 @@ 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 {
index cf75838692743cf087d0edb02015c07d92b934f2..3f49dc622192fb6a875736e2eff0439b55f4e973 100644 (file)
@@ -150,20 +150,19 @@ TemplateIdRefExpr::TemplateIdRefExpr(QualType T,
                                      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)
@@ -175,14 +174,11 @@ TemplateIdRefExpr::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) {
   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) {
@@ -534,29 +530,16 @@ CXXDependentScopeMemberExpr::CXXDependentScopeMemberExpr(ASTContext &C,
                                           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 *
@@ -568,31 +551,24 @@ CXXDependentScopeMemberExpr::Create(ASTContext &C,
                                 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() {
index 297534eaf1fc98b918e556381b464080ddd18eb5..7a8d3af2a06f03dd8ac2cf0d73dbbe6533aae71f 100644 (file)
@@ -865,6 +865,11 @@ static bool isDependent(const TemplateArgument &Arg) {
   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)
index 6e66fbf0e0399a6905d74272ee8f3cdf8cb38b1c..562e830b367eb160a88c215810c04b0f8d3d6e61 100644 (file)
@@ -601,6 +601,14 @@ static void PrintTemplateArgument(std::string &Buffer,
   }
 }
 
+std::string TemplateSpecializationType::
+  PrintTemplateArgumentList(const TemplateArgumentListInfo &Args,
+                            const PrintingPolicy &Policy) {
+  return PrintTemplateArgumentList(Args.getArgumentArray(),
+                                   Args.size(),
+                                   Policy);
+}
+
 std::string
 TemplateSpecializationType::PrintTemplateArgumentList(
                                                 const TemplateArgument *Args,
index c28bb362b24c6e1ca2e156a784c38c83b2603603..472efc48cb9e096d3e396dba0f5ce2ece0ed4566 100644 (file)
@@ -894,17 +894,13 @@ public:
                           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,
@@ -940,9 +936,7 @@ public:
                                     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,
@@ -962,9 +956,7 @@ public:
   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);
@@ -972,9 +964,7 @@ public:
   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,
@@ -1496,8 +1486,7 @@ public:
     // 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);
   }
 
@@ -1506,11 +1495,7 @@ public:
                                             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);
@@ -1537,9 +1522,8 @@ public:
                                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
@@ -2273,15 +2257,12 @@ public:
                                 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,
@@ -2298,10 +2279,7 @@ public:
                                        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,
@@ -2350,11 +2328,7 @@ public:
                                          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);
     
@@ -2397,10 +2371,7 @@ public:
   
   bool CheckTemplateArgumentList(TemplateDecl *Template,
                                  SourceLocation TemplateLoc,
-                                 SourceLocation LAngleLoc,
-                                 const TemplateArgumentLoc *TemplateArgs,
-                                 unsigned NumTemplateArgs,
-                                 SourceLocation RAngleLoc,
+                                 const TemplateArgumentListInfo &TemplateArgs,
                                  bool PartialTemplateArgs,
                                  TemplateArgumentListBuilder &Converted);
 
@@ -2626,8 +2597,7 @@ public:
 
   TemplateDeductionResult
   SubstituteExplicitTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
-                             const TemplateArgumentLoc *ExplicitTemplateArgs,
-                                      unsigned NumExplicitTemplateArgs,
+                        const TemplateArgumentListInfo &ExplicitTemplateArgs,
                             llvm::SmallVectorImpl<TemplateArgument> &Deduced,
                                  llvm::SmallVectorImpl<QualType> &ParamTypes,
                                       QualType *FunctionType,
@@ -2641,18 +2611,14 @@ public:
 
   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);
index 6bf38e0233b07bbabb2b49a3e2d0a3f5b12b8165..a555a64ddffe67b23b9e5960920e13419018ff06 100644 (file)
@@ -1474,13 +1474,11 @@ void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
   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?
@@ -1490,8 +1488,8 @@ void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
   // 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);
index 9c60bf3a649b428595a11721dc6c2ba3bcd6d35a..a160f3e6f314732f52798e07c0b15bdafde2c5d4 100644 (file)
@@ -2974,10 +2974,11 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   // 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);
@@ -2986,8 +2987,6 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
     TemplateArgsPtr.release();
     
     HasExplicitTemplateArgs = true;
-    LAngleLoc = TemplateId->LAngleLoc;
-    RAngleLoc = TemplateId->RAngleLoc;
     
     if (FunctionTemplate) {
       // FIXME: Diagnose function template with explicit template
@@ -3009,9 +3008,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   }
 
   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) &&
index 95a57436e1f88aa511ca9af78942e4d8f935b5a6..5becd8b66237b91f76e7c011c8c7884e03e02558 100644 (file)
@@ -3489,7 +3489,8 @@ static void AddConstructorInitializationCandidates(Sema &SemaRef,
          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);
index fd79935fbd9fb7d486db1b4c83ba9a72980ec1d0..42b49c5d0b5ee16864c5546abacc76d687f44f6b 100644 (file)
@@ -910,8 +910,7 @@ static MemberExpr *BuildMemberExpr(ASTContext &C, Expr *Base, bool isArrow,
                               (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);
 }
@@ -1853,11 +1852,7 @@ Action::OwningExprResult
 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())
@@ -1990,11 +1985,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
                                                    FirstQualifierInScope,
                                                    MemberName,
                                                    MemberLoc,
-                                                   HasExplicitTemplateArgs,
-                                                   LAngleLoc,
-                                                   ExplicitTemplateArgs,
-                                                   NumExplicitTemplateArgs,
-                                                   RAngleLoc));
+                                                   ExplicitTemplateArgs));
     }
     else if (const PointerType *PT = BaseType->getAs<PointerType>())
       BaseType = PT->getPointeeType();
@@ -2032,11 +2023,7 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
                                                      FirstQualifierInScope,
                                                      MemberName,
                                                      MemberLoc,
-                                                     HasExplicitTemplateArgs,
-                                                     LAngleLoc,
-                                                     ExplicitTemplateArgs,
-                                                     NumExplicitTemplateArgs,
-                                                     RAngleLoc));
+                                                     ExplicitTemplateArgs));
       }
     }
 
@@ -2157,13 +2144,12 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
           = 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,
@@ -2172,13 +2158,11 @@ Sema::BuildMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
     }
     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,
@@ -2481,17 +2465,16 @@ Sema::OwningExprResult Sema::ActOnMemberAccessExpr(Scope *S, ExprArg Base,
                                        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);
   }
   
@@ -2680,8 +2663,7 @@ void Sema::DeconstructCallFunction(Expr *FnExpr,
                                    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;
@@ -2739,8 +2721,7 @@ void Sema::DeconstructCallFunction(Expr *FnExpr,
       }
       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)
@@ -2878,13 +2859,12 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
   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
@@ -2917,9 +2897,7 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
 #endif
 
     FDecl = ResolveOverloadedCallFn(Fn, Fns, UnqualifiedName,
-                                    HasExplicitTemplateArgs,
-                                    ExplicitTemplateArgs,
-                                    NumExplicitTemplateArgs,
+                       (HasExplicitTemplateArgs ? &ExplicitTemplateArgs : 0),
                                     LParenLoc, Args, NumArgs, CommaLocs,
                                     RParenLoc, ADL);
     if (!FDecl)
index 7d238f316fa5d5b92668b6778eea757f95bf17f1..591144d81d797dac4ea08f83fd276e220b3711c7 100644 (file)
@@ -1419,8 +1419,8 @@ Sema::OverloadingResult Sema::IsUserDefinedConversion(
         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
@@ -2351,13 +2351,13 @@ void Sema::AddFunctionCandidates(const FunctionSet &Functions,
       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);
     }
@@ -2380,7 +2380,7 @@ void Sema::AddMethodCandidate(NamedDecl *Decl, Expr *Object,
   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,
@@ -2495,9 +2495,7 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, Expr *Object,
 /// 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,
@@ -2517,8 +2515,7 @@ Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
   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.
@@ -2540,9 +2537,7 @@ Sema::AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl,
 /// 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,
@@ -2562,8 +2557,7 @@ Sema::AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate,
   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.
@@ -3941,9 +3935,7 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
 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;
@@ -3982,16 +3974,14 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
                           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);
   }
 }
@@ -4333,8 +4323,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
   }
 
   bool HasExplicitTemplateArgs = false;
-  const TemplateArgumentLoc *ExplicitTemplateArgs = 0;
-  unsigned NumExplicitTemplateArgs = 0;
+  TemplateArgumentListInfo ExplicitTemplateArgs;
 
   llvm::SmallVector<NamedDecl*,8> Fns;
   
@@ -4345,8 +4334,8 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
     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());
@@ -4354,8 +4343,8 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
     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();
@@ -4363,8 +4352,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
       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());
@@ -4408,9 +4396,8 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
       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;
@@ -4509,9 +4496,7 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
 /// \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) {
@@ -4519,7 +4504,7 @@ static void AddOverloadedCallCandidate(Sema &S,
     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;
@@ -4527,9 +4512,7 @@ static void AddOverloadedCallCandidate(Sema &S,
 
   if (FunctionTemplateDecl *FuncTemplate
       = dyn_cast<FunctionTemplateDecl>(Callee)) {
-    S.AddTemplateOverloadCandidate(FuncTemplate, HasExplicitTemplateArgs,
-                                   ExplicitTemplateArgs,
-                                   NumExplicitTemplateArgs,
+    S.AddTemplateOverloadCandidate(FuncTemplate, ExplicitTemplateArgs,
                                    Args, NumArgs, CandidateSet);
     return;
   }
@@ -4544,9 +4527,7 @@ static void AddOverloadedCallCandidate(Sema &S,
 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) {
@@ -4581,16 +4562,13 @@ void Sema::AddOverloadedCallCandidates(llvm::SmallVectorImpl<NamedDecl*> &Fns,
 
   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);  
 }
@@ -4605,9 +4583,7 @@ void Sema::AddOverloadedCallCandidates(llvm::SmallVectorImpl<NamedDecl*> &Fns,
 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,
@@ -4618,8 +4594,7 @@ FunctionDecl *Sema::ResolveOverloadedCallFn(Expr *Fn,
   // 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)) {
@@ -5178,14 +5153,19 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
         
         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;
@@ -5657,16 +5637,18 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
     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());
@@ -5689,17 +5671,19 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
             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());
   }
   
@@ -5707,14 +5691,15 @@ Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
     // 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);    
   } 
index f013343894179b6b65ecfd223e1a53de56bbeb64..096289fa35d8e48b7996b45b6be925de754a6dec 100644 (file)
@@ -317,12 +317,11 @@ static TemplateArgumentLoc translateTemplateArgument(Sema &SemaRef,
                                                      
 /// \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
@@ -1161,24 +1160,19 @@ Sema::MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc,
 
 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();
 
@@ -1190,8 +1184,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
 
   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
@@ -1240,8 +1233,7 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
   // 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
@@ -1252,13 +1244,10 @@ Sema::ActOnTemplateIdType(TemplateTy TemplateD, SourceLocation TemplateLoc,
   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())
@@ -1314,10 +1303,7 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(NestedNameSpecifier *Qualifier,
                                                  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,
@@ -1337,17 +1323,14 @@ Sema::OwningExprResult Sema::BuildTemplateIdExpr(NestedNameSpecifier *Qualifier,
     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,
@@ -1359,15 +1342,13 @@ 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.
@@ -1799,17 +1780,16 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
 /// 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();
 
@@ -3047,16 +3027,17 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
   }
 
   // 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() ==
@@ -3155,8 +3136,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
                                                        TemplateParams,
                                                        ClassTemplate,
                                                        Converted,
-                                                       TemplateArgs.data(),
-                                                       TemplateArgs.size(),
+                                                       TemplateArgs,
                                                        PrevPartial);
 
     if (PrevPartial) {
@@ -3268,10 +3248,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
   // 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();
@@ -3534,11 +3511,7 @@ Sema::CheckSpecializationInstantiationRedecl(SourceLocation NewLoc,
 /// \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.
@@ -3565,9 +3538,7 @@ Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD,
       TemplateDeductionInfo Info(Context);
       FunctionDecl *Specialization = 0;
       if (TemplateDeductionResult TDK
-            = DeduceTemplateArguments(FunTmpl, HasExplicitTemplateArgs,
-                                      ExplicitTemplateArgs, 
-                                      NumExplicitTemplateArgs,
+            = DeduceTemplateArguments(FunTmpl, ExplicitTemplateArgs,
                                       FD->getType(),
                                       Specialization,
                                       Info)) {
@@ -3590,7 +3561,7 @@ Sema::CheckFunctionTemplateSpecialization(FunctionDecl *FD,
                   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;
@@ -3902,16 +3873,15 @@ Sema::ActOnExplicitInstantiation(Scope *S,
                            : 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() ==
@@ -3992,9 +3962,7 @@ Sema::ActOnExplicitInstantiation(Scope *S,
   // 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();
@@ -4278,14 +4246,15 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
   // 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();
   }
@@ -4316,8 +4285,8 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
     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;
index 10594c728fbefc2be827b626aa8eae867c8bf031..c5571d16436292abc0fd2141eaa7fc92352d3520 100644 (file)
@@ -1050,35 +1050,34 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
   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));
@@ -1130,9 +1129,6 @@ static bool isSimpleTemplateIdType(QualType T) {
 /// \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.
 ///
@@ -1151,8 +1147,7 @@ static bool isSimpleTemplateIdType(QualType T) {
 Sema::TemplateDeductionResult
 Sema::SubstituteExplicitTemplateArguments(
                                       FunctionTemplateDecl *FunctionTemplate,
-                             const TemplateArgumentLoc *ExplicitTemplateArgs,
-                                          unsigned NumExplicitTemplateArgs,
+                        const TemplateArgumentListInfo &ExplicitTemplateArgs,
                             llvm::SmallVectorImpl<TemplateArgument> &Deduced,
                                  llvm::SmallVectorImpl<QualType> &ParamTypes,
                                           QualType *FunctionType,
@@ -1161,7 +1156,7 @@ Sema::SubstituteExplicitTemplateArguments(
   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(),
@@ -1185,7 +1180,7 @@ Sema::SubstituteExplicitTemplateArguments(
   //   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,
@@ -1197,10 +1192,8 @@ Sema::SubstituteExplicitTemplateArguments(
     return TDK_InstantiationDepth;
 
   if (CheckTemplateArgumentList(FunctionTemplate,
-                                SourceLocation(), SourceLocation(),
-                                ExplicitTemplateArgs,
-                                NumExplicitTemplateArgs,
                                 SourceLocation(),
+                                ExplicitTemplateArgs,
                                 true,
                                 Builder) || Trap.hasErrorOccurred())
     return TDK_InvalidExplicitArguments;
@@ -1368,9 +1361,7 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
 /// \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) {
@@ -1398,11 +1389,10 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
     = 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,
@@ -1538,9 +1528,7 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
 /// \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) {
@@ -1552,11 +1540,10 @@ Sema::DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate,
   // 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;
index 3f40ffcdc17817883a69d0c58502f0005b55caf2..34dc947422a418df3fa93a760215e6cb854319b3 100644 (file)
@@ -1153,11 +1153,12 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
     = 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);
   }
   
 
@@ -1167,10 +1168,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
                                         InstTemplateArgs.size());
   if (SemaRef.CheckTemplateArgumentList(ClassTemplate, 
                                         PartialSpec->getLocation(),
-                                        /*FIXME:*/PartialSpec->getLocation(),
-                                        InstTemplateArgs.data(), 
-                                        InstTemplateArgs.size(),
-                                        /*FIXME:*/PartialSpec->getLocation(), 
+                                        InstTemplateArgs, 
                                         false,
                                         Converted))
     return true;
@@ -1203,8 +1201,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
   // template arguments in the specialization.
   QualType WrittenTy
     = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
-                                                    InstTemplateArgs.data(),
-                                                    InstTemplateArgs.size(),
+                                                    InstTemplateArgs,
                                                     CanonType);
   
   if (PrevDecl) {
@@ -1238,8 +1235,7 @@ TemplateDeclInstantiator::InstantiateClassTemplatePartialSpecialization(
                                                      InstParams,
                                                      ClassTemplate, 
                                                      Converted,
-                                                     InstTemplateArgs.data(),
-                                                     InstTemplateArgs.size(),
+                                                     InstTemplateArgs,
                                                      0);
   InstPartialSpec->setInstantiatedFromMember(PartialSpec);
   InstPartialSpec->setTypeAsWritten(WrittenTy);
index 101690a2c8a7a0412742d2f3f67058a508819dd0..dcc0d184a1411a2c233ae80c0ce386651deadd0a 100644 (file)
@@ -503,10 +503,7 @@ public:
   /// 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.
   ///
@@ -942,11 +939,7 @@ public:
                                      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.
@@ -969,11 +962,7 @@ public:
                                               isArrow? tok::arrow : tok::period,
                                               MemberLoc,
                                               Member->getDeclName(),
-                                              HasExplicitTemplateArgs,
-                                              LAngleLoc,
                                               ExplicitTemplateArgs,
-                                              NumExplicitTemplateArgs,
-                                              RAngleLoc,
                                      /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
                                               &SS,
                                               FirstQualifierInScope);
@@ -1480,15 +1469,9 @@ public:
                                          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.
@@ -1583,10 +1566,7 @@ public:
                                                   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;
 
@@ -1610,12 +1590,11 @@ public:
         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.
@@ -2879,21 +2858,23 @@ QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
   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
@@ -3695,13 +3676,15 @@ TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
       !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);
     }
   }
   
@@ -3715,11 +3698,8 @@ TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
                                         E->getQualifierRange(),
                                         E->getMemberLoc(),
                                         Member,
-                                        E->hasExplicitTemplateArgumentList(),
-                                        E->getLAngleLoc(),
-                                        TransArgs.data(),
-                                        TransArgs.size(),
-                                        E->getRAngleLoc(),
+                                        (E->hasExplicitTemplateArgumentList()
+                                           ? &TransArgs : 0),
                                         0);
 }
 
@@ -4636,12 +4616,13 @@ TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E,
     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
@@ -4652,10 +4633,7 @@ TreeTransform<Derived>::TransformTemplateIdRefExpr(TemplateIdRefExpr *E,
   // 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>
@@ -4905,11 +4883,12 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
   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),
@@ -4920,10 +4899,7 @@ TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
                                                      Template,
                                                      E->getMemberLoc(),
                                                      FirstQualifierInScope,
-                                                     E->getLAngleLoc(),
-                                                     TransArgs.data(),
-                                                     TransArgs.size(),
-                                                     E->getRAngleLoc());
+                                                     TransArgs);
 }
 
 template<typename Derived>
@@ -5266,12 +5242,8 @@ 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>
@@ -5280,7 +5252,7 @@ TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
                                                    SourceRange Range,
                                                    IdentifierInfo &II,
                                                    QualType ObjectType,
-                                             NamedDecl *FirstQualifierInScope) {
+                                                   NamedDecl *FirstQualifierInScope) {
   CXXScopeSpec SS;
   // FIXME: The source location information is all wrong.
   SS.setRange(Range);