[cfe-commits] r73395 - in /cfe/trunk: include/clang/AST/DeclTemplate.h lib/AST/DeclTemplate.cpp lib/Sema/SemaTemplate.cpp

Anders Carlsson andersca at mac.com
Mon Jun 15 10:56:46 PDT 2009


Author: andersca
Date: Mon Jun 15 12:56:45 2009
New Revision: 73395

URL: http://llvm.org/viewvc/llvm-project?rev=73395&view=rev
Log:
More parameter pack work.

Modified:
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/lib/AST/DeclTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jun 15 12:56:45 2009
@@ -470,14 +470,18 @@
 
   /// \brief Construct a template argument pack.
   TemplateArgument(SourceLocation Loc, TemplateArgument *Args, 
-                   unsigned NumArgs, bool OwnsArgs);
+                   unsigned NumArgs, bool CopyArgs);
   
   /// \brief Copy constructor for a template argument.
   TemplateArgument(const TemplateArgument &Other) : Kind(Other.Kind) {
-    assert(Kind != Pack && "FIXME: Handle packs");
     if (Kind == Integral) {
       new (Integer.Value) llvm::APSInt(*Other.getAsIntegral());
       Integer.Type = Other.Integer.Type;
+    } else if (Kind == Pack) {
+      Args.NumArgs = Other.Args.NumArgs;
+      Args.Args = new TemplateArgument[Args.NumArgs];
+      for (unsigned I = 0; I != Args.NumArgs; ++I)
+            Args.Args[I] = Other.Args.Args[I];
     }
     else
       TypeOrValue = Other.TypeOrValue;
@@ -617,28 +621,33 @@
 
 /// \brief A helper class for making template argument lists.
 class TemplateArgumentListBuilder {
-  /// Args - contains the template arguments.
-  llvm::SmallVector<TemplateArgument, 16> Args;
+  /// FlatArgs - contains the template arguments in flat form.
+  llvm::SmallVector<TemplateArgument, 16> FlatArgs;
   
-  llvm::SmallVector<unsigned, 32> Indices;
+  llvm::SmallVector<TemplateArgument, 16> StructuredArgs;
 
   ASTContext &Context;
   
+  unsigned PackBeginIndex;
+
   /// isAddingFromParameterPack - Returns whether we're adding arguments from
   /// a parameter pack.
-  bool isAddingFromParameterPack() const { return Indices.size() % 2; }
+  bool isAddingFromParameterPack() const { 
+    return PackBeginIndex != std::numeric_limits<unsigned>::max();
+  }
   
 public:
-  TemplateArgumentListBuilder(ASTContext &Context) : Context(Context) { }
+  TemplateArgumentListBuilder(ASTContext &Context) : Context(Context),
+    PackBeginIndex(std::numeric_limits<unsigned>::max()) { }
   
-  size_t size() const { 
+  size_t structuredSize() const { 
     assert(!isAddingFromParameterPack() && 
            "Size is not valid when adding from a parameter pack");
     
-    return Indices.size() / 2;
+    return StructuredArgs.size();
   }
   
-  size_t flatSize() const { return Args.size(); }
+  size_t flatSize() const { return FlatArgs.size(); }
 
   void push_back(const TemplateArgument& Arg);
   
@@ -648,8 +657,12 @@
   /// EndParameterPack - Finish adding arguments from a parameter pack.
   void EndParameterPack();
   
-  const TemplateArgument *getFlatArgumentList() const { return Args.data(); }
-  TemplateArgument *getFlatArgumentList() { return Args.data(); }
+  const TemplateArgument *getFlatArgumentList() const { 
+      return FlatArgs.data();
+  }
+  TemplateArgument *getFlatArgumentList() { 
+      return FlatArgs.data();
+  }
 };
 
 /// \brief A template argument list.

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

==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Mon Jun 15 12:56:45 2009
@@ -265,25 +265,28 @@
     break;
   }
   
-  if (!isAddingFromParameterPack()) {
-    // Add begin and end indicies.
-    Indices.push_back(Args.size());
-    Indices.push_back(Args.size());
-  }
-
-  Args.push_back(Arg);
+  FlatArgs.push_back(Arg);
+  
+  if (!isAddingFromParameterPack())
+    StructuredArgs.push_back(Arg);
 }
 
 void TemplateArgumentListBuilder::BeginParameterPack() {
   assert(!isAddingFromParameterPack() && "Already adding to parameter pack!");
-  
-  Indices.push_back(Args.size());
+
+  PackBeginIndex = FlatArgs.size();
 }
 
 void TemplateArgumentListBuilder::EndParameterPack() {
   assert(isAddingFromParameterPack() && "Not adding to parameter pack!");
+
+  unsigned NumArgs = FlatArgs.size() - PackBeginIndex;
+  TemplateArgument *Args = NumArgs ? &FlatArgs[PackBeginIndex] : 0;
+  
+  StructuredArgs.push_back(TemplateArgument(SourceLocation(), Args, NumArgs,
+                                            /*CopyArgs=*/false));
   
-  Indices.push_back(Args.size());
+  PackBeginIndex = std::numeric_limits<unsigned>::max();
 }  
 
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Jun 15 12:56:45 2009
@@ -850,7 +850,7 @@
                                 ConvertedTemplateArgs))
     return QualType();
 
-  assert((ConvertedTemplateArgs.size() == 
+  assert((ConvertedTemplateArgs.structuredSize() == 
             Template->getTemplateParameters()->size()) &&
          "Converted template argument list is too short!");
 
@@ -2301,7 +2301,7 @@
                                 RAngleLoc, ConvertedTemplateArgs))
     return true;
 
-  assert((ConvertedTemplateArgs.size() == 
+  assert((ConvertedTemplateArgs.structuredSize() == 
             ClassTemplate->getTemplateParameters()->size()) &&
          "Converted template argument list is too short!");
   
@@ -2562,7 +2562,7 @@
                                 RAngleLoc, ConvertedTemplateArgs))
     return true;
 
-  assert((ConvertedTemplateArgs.size() == 
+  assert((ConvertedTemplateArgs.structuredSize() == 
             ClassTemplate->getTemplateParameters()->size()) &&
          "Converted template argument list is too short!");
   





More information about the cfe-commits mailing list