[cfe-commits] r89638 - in /cfe/trunk: include/clang/AST/ lib/AST/ lib/Sema/

John McCall rjmccall at apple.com
Sun Nov 22 17:53:49 PST 2009


Author: rjmccall
Date: Sun Nov 22 19:53:49 2009
New Revision: 89638

URL: http://llvm.org/viewvc/llvm-project?rev=89638&view=rev
Log:
Encapsulate "an array of TemplateArgumentLocs and two angle bracket locations" into
a new class.  Use it pervasively throughout Sema.

My fingers hurt.


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

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Nov 22 19:53:49 2009
@@ -532,8 +532,7 @@
                                          QualType Canon = QualType());
 
   QualType getTemplateSpecializationType(TemplateName T,
-                                         const TemplateArgumentLoc *Args,
-                                         unsigned NumArgs,
+                                         const TemplateArgumentListInfo &Args,
                                          QualType Canon = QualType());
 
   QualType getQualifiedNameType(NestedNameSpecifier *NNS,

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Nov 22 19:53:49 2009
@@ -54,6 +54,30 @@
   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;

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Nov 22 19:53:49 2009
@@ -88,28 +88,6 @@
 
 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.

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Sun Nov 22 19:53:49 2009
@@ -955,8 +955,7 @@
          TemplateParameterList *Params,
          ClassTemplateDecl *SpecializedTemplate,
          TemplateArgumentListBuilder &Builder,
-         TemplateArgumentLoc *ArgInfos,
-         unsigned NumArgInfos,
+         const TemplateArgumentListInfo &ArgInfos,
          ClassTemplatePartialSpecializationDecl *PrevDecl);
 
   /// Get the list of template parameters

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Nov 22 19:53:49 2009
@@ -35,6 +35,7 @@
   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 @@
   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 @@
   
   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 @@
                              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 @@
   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 @@
 
   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 @@
                             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 @@
 
   /// \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 {

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun Nov 22 19:53:49 2009
@@ -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 @@
   class CXXDestructorDecl;
   class CXXMethodDecl;
   class CXXTemporary;
+  class TemplateArgumentListInfo;
 
 //===--------------------------------------------------------------------===//
 // C++ Expressions.
@@ -1215,10 +1216,7 @@
   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 @@
   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 @@
   /// 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 @@
                           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 @@
          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 @@
 
   /// \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 {

Modified: cfe/trunk/include/clang/AST/TemplateBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/TemplateBase.h (original)
+++ cfe/trunk/include/clang/AST/TemplateBase.h Sun Nov 22 19:53:49 2009
@@ -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 @@
   }  
 };
 
+/// 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

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Nov 22 19:53:49 2009
@@ -82,6 +82,7 @@
   class StmtIteratorBase;
   class TemplateArgument;
   class TemplateArgumentLoc;
+  class TemplateArgumentListInfo;
   class QualifiedNameType;
   struct PrintingPolicy;
 
@@ -2280,6 +2281,8 @@
   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 @@
                                                unsigned NumArgs,
                                                const PrintingPolicy &Policy);
 
+  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
+                                               const PrintingPolicy &Policy);
+
   typedef const TemplateArgument * iterator;
 
   iterator begin() const { return getArgs(); }

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Nov 22 19:53:49 2009
@@ -1832,9 +1832,10 @@
 
 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)

Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Sun Nov 22 19:53:49 2009
@@ -453,8 +453,9 @@
        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];

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Nov 22 19:53:49 2009
@@ -31,20 +31,40 @@
 // 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 @@
     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 @@
                                  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 @@
                                  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 @@
 
 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 @@
   }
 
   // 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 @@
                                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 {

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Sun Nov 22 19:53:49 2009
@@ -150,20 +150,19 @@
                                      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 @@
                           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 @@
                                           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 @@
                                 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() {

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Nov 22 19:53:49 2009
@@ -866,6 +866,11 @@
 }
 
 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)
     if (isDependent(Args[i].getArgument()))

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Sun Nov 22 19:53:49 2009
@@ -601,6 +601,14 @@
   }
 }
 
+std::string TemplateSpecializationType::
+  PrintTemplateArgumentList(const TemplateArgumentListInfo &Args,
+                            const PrintingPolicy &Policy) {
+  return PrintTemplateArgumentList(Args.getArgumentArray(),
+                                   Args.size(),
+                                   Policy);
+}
+
 std::string
 TemplateSpecializationType::PrintTemplateArgumentList(
                                                 const TemplateArgument *Args,

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Nov 22 19:53:49 2009
@@ -894,17 +894,13 @@
                           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 @@
                                     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 @@
   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 @@
   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 @@
     // 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 @@
                                             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 @@
                                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 @@
                                 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 @@
                                        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 @@
                                          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 @@
   
   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 @@
 
   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 @@
 
   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);

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Sun Nov 22 19:53:49 2009
@@ -1474,13 +1474,11 @@
   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 @@
   // 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);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Nov 22 19:53:49 2009
@@ -2974,10 +2974,11 @@
   // 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 @@
     TemplateArgsPtr.release();
     
     HasExplicitTemplateArgs = true;
-    LAngleLoc = TemplateId->LAngleLoc;
-    RAngleLoc = TemplateId->RAngleLoc;
     
     if (FunctionTemplate) {
       // FIXME: Diagnose function template with explicit template
@@ -3009,9 +3008,8 @@
   }
 
   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) &&

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Nov 22 19:53:49 2009
@@ -3489,7 +3489,8 @@
          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);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Nov 22 19:53:49 2009
@@ -910,8 +910,7 @@
                               (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 @@
 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 @@
                                                    FirstQualifierInScope,
                                                    MemberName,
                                                    MemberLoc,
-                                                   HasExplicitTemplateArgs,
-                                                   LAngleLoc,
-                                                   ExplicitTemplateArgs,
-                                                   NumExplicitTemplateArgs,
-                                                   RAngleLoc));
+                                                   ExplicitTemplateArgs));
     }
     else if (const PointerType *PT = BaseType->getAs<PointerType>())
       BaseType = PT->getPointeeType();
@@ -2032,11 +2023,7 @@
                                                      FirstQualifierInScope,
                                                      MemberName,
                                                      MemberLoc,
-                                                     HasExplicitTemplateArgs,
-                                                     LAngleLoc,
-                                                     ExplicitTemplateArgs,
-                                                     NumExplicitTemplateArgs,
-                                                     RAngleLoc));
+                                                     ExplicitTemplateArgs));
       }
     }
 
@@ -2157,13 +2144,12 @@
           = 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 @@
     }
     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 @@
                                        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 @@
                                    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 @@
       }
       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 @@
   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 @@
 #endif
 
     FDecl = ResolveOverloadedCallFn(Fn, Fns, UnqualifiedName,
-                                    HasExplicitTemplateArgs,
-                                    ExplicitTemplateArgs,
-                                    NumExplicitTemplateArgs,
+                       (HasExplicitTemplateArgs ? &ExplicitTemplateArgs : 0),
                                     LParenLoc, Args, NumArgs, CommaLocs,
                                     RParenLoc, ADL);
     if (!FDecl)

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Nov 22 19:53:49 2009
@@ -1419,8 +1419,8 @@
         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 @@
       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 @@
   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 @@
 /// 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 @@
   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 @@
 /// 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 @@
   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 @@
 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 @@
                           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 @@
   }
 
   bool HasExplicitTemplateArgs = false;
-  const TemplateArgumentLoc *ExplicitTemplateArgs = 0;
-  unsigned NumExplicitTemplateArgs = 0;
+  TemplateArgumentListInfo ExplicitTemplateArgs;
 
   llvm::SmallVector<NamedDecl*,8> Fns;
   
@@ -4345,8 +4334,8 @@
     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 @@
     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 @@
       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 @@
       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 @@
 /// \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 @@
     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 @@
 
   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 @@
 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 @@
 
   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 @@
 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 @@
   // 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 @@
         
         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 @@
     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 @@
             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 @@
     // 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);    
   } 

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sun Nov 22 19:53:49 2009
@@ -317,12 +317,11 @@
                                                      
 /// \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 @@
 
 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 @@
 
   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 @@
   // 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 @@
   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 @@
                                                  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 @@
     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 @@
   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 @@
 /// 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 @@
   }
 
   // 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 @@
                                                        TemplateParams,
                                                        ClassTemplate,
                                                        Converted,
-                                                       TemplateArgs.data(),
-                                                       TemplateArgs.size(),
+                                                       TemplateArgs,
                                                        PrevPartial);
 
     if (PrevPartial) {
@@ -3268,10 +3248,7 @@
   // 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 @@
 /// \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 @@
       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 @@
                   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 @@
                            : 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 @@
   // 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 @@
   // 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 @@
     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;

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Sun Nov 22 19:53:49 2009
@@ -1050,35 +1050,34 @@
   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 @@
 /// \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 @@
 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 @@
   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 @@
   //   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 @@
     return TDK_InstantiationDepth;
 
   if (CheckTemplateArgumentList(FunctionTemplate,
-                                SourceLocation(), SourceLocation(),
-                                ExplicitTemplateArgs,
-                                NumExplicitTemplateArgs,
                                 SourceLocation(),
+                                ExplicitTemplateArgs,
                                 true,
                                 Builder) || Trap.hasErrorOccurred())
     return TDK_InvalidExplicitArguments;
@@ -1368,9 +1361,7 @@
 /// \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 @@
     = 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 @@
 /// \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 @@
   // 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;

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sun Nov 22 19:53:49 2009
@@ -1153,11 +1153,12 @@
     = 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 @@
                                         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 @@
   // template arguments in the specialization.
   QualType WrittenTy
     = SemaRef.Context.getTemplateSpecializationType(TemplateName(ClassTemplate),
-                                                    InstTemplateArgs.data(),
-                                                    InstTemplateArgs.size(),
+                                                    InstTemplateArgs,
                                                     CanonType);
   
   if (PrevDecl) {
@@ -1238,8 +1235,7 @@
                                                      InstParams,
                                                      ClassTemplate, 
                                                      Converted,
-                                                     InstTemplateArgs.data(),
-                                                     InstTemplateArgs.size(),
+                                                     InstTemplateArgs,
                                                      0);
   InstPartialSpec->setInstantiatedFromMember(PartialSpec);
   InstPartialSpec->setTypeAsWritten(WrittenTy);

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=89638&r1=89637&r2=89638&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Sun Nov 22 19:53:49 2009
@@ -503,10 +503,7 @@
   /// 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 @@
                                      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 @@
                                               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 @@
                                          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 @@
                                                   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 @@
         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 @@
   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 @@
       !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 @@
                                         E->getQualifierRange(),
                                         E->getMemberLoc(),
                                         Member,
-                                        E->hasExplicitTemplateArgumentList(),
-                                        E->getLAngleLoc(),
-                                        TransArgs.data(),
-                                        TransArgs.size(),
-                                        E->getRAngleLoc(),
+                                        (E->hasExplicitTemplateArgumentList()
+                                           ? &TransArgs : 0),
                                         0);
 }
 
@@ -4636,12 +4616,13 @@
     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 @@
   // 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 @@
   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 @@
                                                      Template,
                                                      E->getMemberLoc(),
                                                      FirstQualifierInScope,
-                                                     E->getLAngleLoc(),
-                                                     TransArgs.data(),
-                                                     TransArgs.size(),
-                                                     E->getRAngleLoc());
+                                                     TransArgs);
 }
 
 template<typename Derived>
@@ -5266,12 +5242,8 @@
 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 @@
                                                    SourceRange Range,
                                                    IdentifierInfo &II,
                                                    QualType ObjectType,
-                                             NamedDecl *FirstQualifierInScope) {
+                                                   NamedDecl *FirstQualifierInScope) {
   CXXScopeSpec SS;
   // FIXME: The source location information is all wrong.
   SS.setRange(Range);





More information about the cfe-commits mailing list