[cfe-commits] r123289 - in /cfe/trunk: include/clang/AST/TemplateBase.h lib/AST/DeclTemplate.cpp lib/AST/TemplateBase.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp
Douglas Gregor
dgregor at apple.com
Tue Jan 11 15:09:57 PST 2011
Author: dgregor
Date: Tue Jan 11 17:09:57 2011
New Revision: 123289
URL: http://llvm.org/viewvc/llvm-project?rev=123289&view=rev
Log:
Add TemplateArgument::CreatePackCopy() to create a new parameter pack
in ASTContext-allocated memory, copying the provided template
arguments. Use this new routine where we can. No functionality change.
Modified:
cfe/trunk/include/clang/AST/TemplateBase.h
cfe/trunk/lib/AST/DeclTemplate.cpp
cfe/trunk/lib/AST/TemplateBase.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
Modified: cfe/trunk/include/clang/AST/TemplateBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=123289&r1=123288&r2=123289&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TemplateBase.h (original)
+++ cfe/trunk/include/clang/AST/TemplateBase.h Tue Jan 11 17:09:57 2011
@@ -191,6 +191,12 @@
getAsIntegral()->~APSInt();
}
+ /// \brief Create a new template argument pack by copying the given set of
+ /// template arguments.
+ static TemplateArgument CreatePackCopy(ASTContext &Context,
+ const TemplateArgument *Args,
+ unsigned NumArgs);
+
/// \brief Return the kind of stored template argument.
ArgKind getKind() const { return (ArgKind)Kind; }
Modified: cfe/trunk/lib/AST/DeclTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=123289&r1=123288&r2=123289&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclTemplate.cpp (original)
+++ cfe/trunk/lib/AST/DeclTemplate.cpp Tue Jan 11 17:09:57 2011
@@ -338,11 +338,8 @@
Arg = TemplateArgument(TemplateName(TTP), TTP->isParameterPack());
}
- if ((*Param)->isTemplateParameterPack()) {
- TemplateArgument *Pack = new (Context) TemplateArgument [1];
- *Pack = Arg;
- Arg = TemplateArgument(Pack, 1);
- }
+ if ((*Param)->isTemplateParameterPack())
+ Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
TemplateArgs.push_back(Arg);
}
Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=123289&r1=123288&r2=123289&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Tue Jan 11 17:09:57 2011
@@ -21,6 +21,7 @@
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/FoldingSet.h"
+#include <algorithm>
using namespace clang;
@@ -28,6 +29,17 @@
// TemplateArgument Implementation
//===----------------------------------------------------------------------===//
+TemplateArgument TemplateArgument::CreatePackCopy(ASTContext &Context,
+ const TemplateArgument *Args,
+ unsigned NumArgs) {
+ if (NumArgs == 0)
+ return TemplateArgument(0, 0);
+
+ TemplateArgument *Storage = new (Context) TemplateArgument [NumArgs];
+ std::copy(Args, Args + NumArgs, Storage);
+ return TemplateArgument(Storage, NumArgs);
+}
+
bool TemplateArgument::isDependent() const {
switch (getKind()) {
case Null:
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=123289&r1=123288&r2=123289&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Jan 11 17:09:57 2011
@@ -2556,13 +2556,12 @@
if ((*Param)->isTemplateParameterPack()) {
if (PartialTemplateArgs && ArgumentPack.empty()) {
Converted.push_back(TemplateArgument());
- } else if (ArgumentPack.empty()) {
+ } else if (ArgumentPack.empty())
Converted.push_back(TemplateArgument(0, 0));
- } else {
- TemplateArgument *PackedArgs
- = new (Context) TemplateArgument [ArgumentPack.size()];
- std::copy(ArgumentPack.begin(), ArgumentPack.end(), PackedArgs);
- Converted.push_back(TemplateArgument(PackedArgs, ArgumentPack.size()));
+ else {
+ Converted.push_back(TemplateArgument::CreatePackCopy(Context,
+ ArgumentPack.data(),
+ ArgumentPack.size()));
ArgumentPack.clear();
}
}
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=123289&r1=123288&r2=123289&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jan 11 17:09:57 2011
@@ -585,13 +585,13 @@
NewPack = DeducedTemplateArgument(TemplateArgument(0, 0));
} else {
TemplateArgument *ArgumentPack
- = new (S.Context) TemplateArgument [NewlyDeducedPacks[I].size()];
+ = new (S.Context) TemplateArgument [NewlyDeducedPacks[I].size()];
std::copy(NewlyDeducedPacks[I].begin(), NewlyDeducedPacks[I].end(),
ArgumentPack);
NewPack
- = DeducedTemplateArgument(TemplateArgument(ArgumentPack,
- NewlyDeducedPacks[I].size()),
- NewlyDeducedPacks[I][0].wasDeducedFromArrayBound());
+ = DeducedTemplateArgument(TemplateArgument(ArgumentPack,
+ NewlyDeducedPacks[I].size()),
+ NewlyDeducedPacks[I][0].wasDeducedFromArrayBound());
}
DeducedTemplateArgument Result
@@ -1726,12 +1726,9 @@
}
// Create the resulting argument pack.
- TemplateArgument *PackedArgs = 0;
- if (!PackedArgsBuilder.empty()) {
- PackedArgs = new (S.Context) TemplateArgument[PackedArgsBuilder.size()];
- std::copy(PackedArgsBuilder.begin(), PackedArgsBuilder.end(), PackedArgs);
- }
- Output.push_back(TemplateArgument(PackedArgs, PackedArgsBuilder.size()));
+ Output.push_back(TemplateArgument::CreatePackCopy(S.Context,
+ PackedArgsBuilder.data(),
+ PackedArgsBuilder.size()));
return false;
}
More information about the cfe-commits
mailing list