[cfe-commits] r73391 - in /cfe/trunk: include/clang/AST/DeclTemplate.h lib/AST/DeclTemplate.cpp lib/AST/Type.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiate.cpp

Anders Carlsson andersca at mac.com
Mon Jun 15 10:04:54 PDT 2009


Author: andersca
Date: Mon Jun 15 12:04:53 2009
New Revision: 73391

URL: http://llvm.org/viewvc/llvm-project?rev=73391&view=rev
Log:
Add a new 'Pack' argument kind to TemplateArgument. This is not yet used.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jun 15 12:04:53 2009
@@ -404,6 +404,11 @@
       char Value[sizeof(llvm::APSInt)];
       void *Type;
     } Integer;
+    struct {
+      TemplateArgument *Args;
+      unsigned NumArgs;
+      bool CopyArgs;
+    } Args;
   };
 
   /// \brief Location of the beginning of this template argument.
@@ -413,7 +418,7 @@
   /// \brief The type of template argument we're storing.
   enum ArgKind {
     Null = 0,
-    /// The template argument is a type. It's value is stored in the
+    /// The template argument is a type. Its value is stored in the
     /// TypeOrValue field.
     Type = 1,
     /// The template argument is a declaration
@@ -422,7 +427,11 @@
     Integral = 3,
     /// The template argument is a value- or type-dependent expression
     /// stored in an Expr*.
-    Expression = 4
+    Expression = 4,
+
+    /// The template argument is actually a parameter pack. Arguments are stored
+    /// in the Args struct.
+    Pack = 5
   } Kind;
 
   /// \brief Construct an empty, invalid template argument.
@@ -459,8 +468,13 @@
   /// occur in a non-dependent, canonical template argument list.
   TemplateArgument(Expr *E);
 
+  /// \brief Construct a template argument pack.
+  TemplateArgument(SourceLocation Loc, TemplateArgument *Args, 
+                   unsigned NumArgs, bool OwnsArgs);
+  
   /// \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;
@@ -475,6 +489,10 @@
     // safety.
     using llvm::APSInt;
 
+    // FIXME: Handle Packs
+    assert(Kind != Pack && "FIXME: Handle packs");
+    assert(Other.Kind != Pack && "FIXME: Handle packs");
+
     if (Kind == Other.Kind && Kind == Integral) {
       // Copy integral values.
       *this->getAsIntegral() = *Other.getAsIntegral();
@@ -502,6 +520,8 @@
 
     if (Kind == Integral)
       getAsIntegral()->~APSInt();
+    else if (Kind == Pack && Args.CopyArgs)
+      delete[] Args.Args;
   }
 
   /// \brief Return the kind of stored template argument.
@@ -586,6 +606,11 @@
       // FIXME: We need a canonical representation of expressions.
       ID.AddPointer(getAsExpr());
       break;
+    
+    case Pack:
+      ID.AddInteger(Args.NumArgs);
+      for (unsigned I = 0; I != Args.NumArgs; ++I)
+        Args.Args[I].Profile(ID);
     }
   }
 };

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

==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Mon Jun 15 12:04:53 2009
@@ -238,6 +238,22 @@
   StartLoc = E->getSourceRange().getBegin();
 }
 
+/// \brief Construct a template argument pack.
+TemplateArgument::TemplateArgument(SourceLocation Loc, TemplateArgument *args, 
+                                   unsigned NumArgs, bool CopyArgs) 
+  : Kind(Pack) {
+    Args.NumArgs = NumArgs;
+    Args.CopyArgs = CopyArgs;
+    if (!Args.CopyArgs) {
+      Args.Args = args;
+      return;
+    }
+
+    Args.Args = new TemplateArgument[NumArgs];
+    for (unsigned I = 0; I != NumArgs; ++I)
+      Args.Args[I] = args[I];
+}
+
 //===----------------------------------------------------------------------===//
 // TemplateArgumentListBuilder Implementation
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Jun 15 12:04:53 2009
@@ -1068,6 +1068,10 @@
           Args[Idx].getAsExpr()->isValueDependent())
         return true;
       break;
+        
+    case TemplateArgument::Pack:
+      assert(0 && "FIXME: Implement!");
+      break;
     }
   }
 
@@ -1476,6 +1480,9 @@
       Args[Arg].getAsExpr()->printPretty(s, 0, Policy);
       break;
     }
+    case TemplateArgument::Pack:
+      assert(0 && "FIXME: Implement!");
+      break;
     }
 
     // If this is the first argument and its string representation

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Jun 15 12:04:53 2009
@@ -806,6 +806,10 @@
       Canonical.push_back(TemplateArgument(SourceLocation(), CanonType));
       break;
     }
+    
+    case TemplateArgument::Pack:
+      assert(0 && "FIXME: Implement!");
+      break;
     }
   }
 }
@@ -1207,6 +1211,11 @@
           Diag(Arg.getLocation(), diag::err_template_arg_must_be_expr);
         Diag((*Param)->getLocation(), diag::note_template_param_here);
         Invalid = true;
+        break;
+      
+      case TemplateArgument::Pack:
+        assert(0 && "FIXME: Implement!");
+        break;
       }
     } else { 
       // Check template template parameters.
@@ -1251,6 +1260,10 @@
       case TemplateArgument::Integral:
         assert(false && "Integral argument with template template parameter");
         break;
+      
+      case TemplateArgument::Pack:
+        assert(0 && "FIXME: Implement!");
+        break;
       }
     }
   }

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Jun 15 12:04:53 2009
@@ -597,6 +597,9 @@
     // Can't deduce anything, but that's okay.
     return Sema::TDK_Success;
   }
+  case TemplateArgument::Pack:
+    assert(0 && "FIXME: Implement!");
+    break;
   }
       
   return Sema::TDK_Success;
@@ -898,6 +901,9 @@
   case TemplateArgument::Expression:
     MarkDeducedTemplateParameters(TemplateArg.getAsExpr(), Deduced);
     break;
+  case TemplateArgument::Pack:
+    assert(0 && "FIXME: Implement!");
+    break;
   }
 }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Jun 15 12:04:53 2009
@@ -1153,6 +1153,10 @@
       return TemplateArgument();
     return TemplateArgument(E.takeAs<Expr>());
   }
+  
+  case TemplateArgument::Pack:
+    assert(0 && "FIXME: Implement!");
+    break;
   }
 
   assert(false && "Unhandled template argument kind");





More information about the cfe-commits mailing list