forked from OSchip/llvm-project
Improvements to TemplateArgumentListBuilder to make it work better with parameter packs.
llvm-svn: 73272
This commit is contained in:
parent
77444cba6d
commit
aa73b9135a
|
@ -298,9 +298,13 @@ public:
|
|||
static bool CollectingStats(bool Enable = false);
|
||||
static void PrintStats();
|
||||
|
||||
/// isTemplateParameter - Determines whether this declartion is a
|
||||
/// isTemplateParameter - Determines whether this declaration is a
|
||||
/// template parameter.
|
||||
bool isTemplateParameter() const;
|
||||
|
||||
/// isTemplateParameter - Determines whether this declaration is a
|
||||
/// template parameter pack.
|
||||
bool isTemplateParameterPack() const;
|
||||
|
||||
// Implement isa/cast/dyncast/etc.
|
||||
static bool classof(const Decl *) { return true; }
|
||||
|
|
|
@ -592,17 +592,37 @@ public:
|
|||
|
||||
/// \brief A helper class for making template argument lists.
|
||||
class TemplateArgumentListBuilder {
|
||||
/// Args - contains the template arguments.
|
||||
llvm::SmallVector<TemplateArgument, 16> Args;
|
||||
|
||||
llvm::SmallVector<unsigned, 32> Indices;
|
||||
|
||||
ASTContext &Context;
|
||||
|
||||
/// isAddingFromParameterPack - Returns whether we're adding arguments from
|
||||
/// a parameter pack.
|
||||
bool isAddingFromParameterPack() const { return Indices.size() % 2; }
|
||||
|
||||
public:
|
||||
TemplateArgumentListBuilder(ASTContext &Context) : Context(Context) { }
|
||||
|
||||
// FIXME: Should use the index array size.
|
||||
size_t size() const { return Args.size(); }
|
||||
size_t size() const {
|
||||
assert(!isAddingFromParameterPack() &&
|
||||
"Size is not valid when adding from a parameter pack");
|
||||
|
||||
return Args.size();
|
||||
}
|
||||
|
||||
size_t flatSize() const { return Args.size(); }
|
||||
|
||||
void push_back(const TemplateArgument& Arg);
|
||||
|
||||
/// BeginParameterPack - Start adding arguments from a parameter pack.
|
||||
void BeginParameterPack();
|
||||
|
||||
/// EndParameterPack - Finish adding arguments from a parameter pack.
|
||||
void EndParameterPack();
|
||||
|
||||
TemplateArgument *getFlatArgumentList() { return Args.data(); }
|
||||
};
|
||||
|
||||
|
|
|
@ -95,6 +95,13 @@ void Decl::addDeclKind(Kind k) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Decl::isTemplateParameterPack() const {
|
||||
if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(this))
|
||||
return TTP->isParameterPack();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PrettyStackTraceDecl Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -247,9 +247,27 @@ void TemplateArgumentListBuilder::push_back(const TemplateArgument& Arg) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (!isAddingFromParameterPack()) {
|
||||
// Add begin and end indicies.
|
||||
Indices.push_back(Args.size());
|
||||
Indices.push_back(Args.size());
|
||||
}
|
||||
|
||||
Args.push_back(Arg);
|
||||
}
|
||||
|
||||
void TemplateArgumentListBuilder::BeginParameterPack() {
|
||||
assert(!isAddingFromParameterPack() && "Already adding to parameter pack!");
|
||||
|
||||
Indices.push_back(Args.size());
|
||||
}
|
||||
|
||||
void TemplateArgumentListBuilder::EndParameterPack() {
|
||||
assert(isAddingFromParameterPack() && "Not adding to parameter pack!");
|
||||
|
||||
Indices.push_back(Args.size());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// TemplateArgumentList Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
Loading…
Reference in New Issue