2009-10-24 06:13:42 +08:00
|
|
|
//===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===//
|
2009-02-05 03:02:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the C++ related Decl classes for templates.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2009-02-10 02:46:07 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-02-05 03:02:06 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2009-10-29 16:12:44 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2009-02-05 03:02:06 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateParameterList Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-07 06:42:48 +08:00
|
|
|
TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
|
|
|
|
SourceLocation LAngleLoc,
|
2009-09-16 00:23:51 +08:00
|
|
|
NamedDecl **Params, unsigned NumParams,
|
2009-02-07 06:42:48 +08:00
|
|
|
SourceLocation RAngleLoc)
|
|
|
|
: TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
|
|
|
|
NumParams(NumParams) {
|
2009-02-05 03:02:06 +08:00
|
|
|
for (unsigned Idx = 0; Idx < NumParams; ++Idx)
|
|
|
|
begin()[Idx] = Params[Idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateParameterList *
|
2009-02-07 06:42:48 +08:00
|
|
|
TemplateParameterList::Create(ASTContext &C, SourceLocation TemplateLoc,
|
2009-09-16 00:23:51 +08:00
|
|
|
SourceLocation LAngleLoc, NamedDecl **Params,
|
2009-02-07 06:42:48 +08:00
|
|
|
unsigned NumParams, SourceLocation RAngleLoc) {
|
2009-09-16 00:23:51 +08:00
|
|
|
unsigned Size = sizeof(TemplateParameterList)
|
|
|
|
+ sizeof(NamedDecl *) * NumParams;
|
2009-02-05 03:02:06 +08:00
|
|
|
unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment;
|
|
|
|
void *Mem = C.Allocate(Size, Align);
|
2009-09-09 23:08:12 +08:00
|
|
|
return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
|
2009-02-07 06:42:48 +08:00
|
|
|
NumParams, RAngleLoc);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 02:16:40 +08:00
|
|
|
unsigned TemplateParameterList::getMinRequiredArguments() const {
|
|
|
|
unsigned NumRequiredArgs = size();
|
2009-09-09 23:08:12 +08:00
|
|
|
iterator Param = const_cast<TemplateParameterList *>(this)->end(),
|
2009-02-12 02:16:40 +08:00
|
|
|
ParamBegin = const_cast<TemplateParameterList *>(this)->begin();
|
|
|
|
while (Param != ParamBegin) {
|
|
|
|
--Param;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-13 10:08:00 +08:00
|
|
|
if (!(*Param)->isTemplateParameterPack() &&
|
2009-09-09 23:08:12 +08:00
|
|
|
!(isa<TemplateTypeParmDecl>(*Param) &&
|
2009-02-12 02:16:40 +08:00
|
|
|
cast<TemplateTypeParmDecl>(*Param)->hasDefaultArgument()) &&
|
|
|
|
!(isa<NonTypeTemplateParmDecl>(*Param) &&
|
|
|
|
cast<NonTypeTemplateParmDecl>(*Param)->hasDefaultArgument()) &&
|
|
|
|
!(isa<TemplateTemplateParmDecl>(*Param) &&
|
|
|
|
cast<TemplateTemplateParmDecl>(*Param)->hasDefaultArgument()))
|
|
|
|
break;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-12 02:16:40 +08:00
|
|
|
--NumRequiredArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NumRequiredArgs;
|
|
|
|
}
|
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
unsigned TemplateParameterList::getDepth() const {
|
|
|
|
if (size() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const NamedDecl *FirstParm = getParam(0);
|
|
|
|
if (const TemplateTypeParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTypeParmDecl>(FirstParm))
|
|
|
|
return TTP->getDepth();
|
|
|
|
else if (const NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
|
|
|
|
return NTTP->getDepth();
|
|
|
|
else
|
|
|
|
return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TemplateDecl::~TemplateDecl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FunctionTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
DeclarationName Name,
|
2009-06-30 04:59:39 +08:00
|
|
|
TemplateParameterList *Params,
|
2009-02-05 03:02:06 +08:00
|
|
|
NamedDecl *Decl) {
|
|
|
|
return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
|
|
|
|
}
|
|
|
|
|
2009-06-30 04:59:39 +08:00
|
|
|
void FunctionTemplateDecl::Destroy(ASTContext &C) {
|
|
|
|
if (Common *CommonPtr = CommonOrPrev.dyn_cast<Common*>()) {
|
|
|
|
for (llvm::FoldingSet<FunctionTemplateSpecializationInfo>::iterator
|
|
|
|
Spec = CommonPtr->Specializations.begin(),
|
|
|
|
SpecEnd = CommonPtr->Specializations.end();
|
|
|
|
Spec != SpecEnd; ++Spec)
|
|
|
|
C.Deallocate(&*Spec);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-30 04:59:39 +08:00
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-07-18 08:34:07 +08:00
|
|
|
FunctionTemplateDecl *FunctionTemplateDecl::getCanonicalDecl() {
|
|
|
|
FunctionTemplateDecl *FunTmpl = this;
|
|
|
|
while (FunTmpl->getPreviousDeclaration())
|
|
|
|
FunTmpl = FunTmpl->getPreviousDeclaration();
|
|
|
|
return FunTmpl;
|
|
|
|
}
|
|
|
|
|
2009-06-30 04:59:39 +08:00
|
|
|
FunctionTemplateDecl::Common *FunctionTemplateDecl::getCommonPtr() {
|
|
|
|
// Find the first declaration of this function template.
|
|
|
|
FunctionTemplateDecl *First = this;
|
|
|
|
while (First->getPreviousDeclaration())
|
|
|
|
First = First->getPreviousDeclaration();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-30 04:59:39 +08:00
|
|
|
if (First->CommonOrPrev.isNull()) {
|
|
|
|
// FIXME: Allocate with the ASTContext
|
|
|
|
First->CommonOrPrev = new Common;
|
|
|
|
}
|
|
|
|
return First->CommonOrPrev.get<Common*>();
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-18 08:34:07 +08:00
|
|
|
ClassTemplateDecl *ClassTemplateDecl::getCanonicalDecl() {
|
|
|
|
ClassTemplateDecl *Template = this;
|
|
|
|
while (Template->getPreviousDeclaration())
|
|
|
|
Template = Template->getPreviousDeclaration();
|
|
|
|
return Template;
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
DeclarationName Name,
|
|
|
|
TemplateParameterList *Params,
|
Introduce a new expression type, UnresolvedDeclRefExpr, that describes
dependent qualified-ids such as
Fibonacci<N - 1>::value
where N is a template parameter. These references are "unresolved"
because the name is dependent and, therefore, cannot be resolved to a
declaration node (as we would do for a DeclRefExpr or
QualifiedDeclRefExpr). UnresolvedDeclRefExprs instantiate to
DeclRefExprs, QualifiedDeclRefExprs, etc.
Also, be a bit more careful about keeping only a single set of
specializations for a class template, and instantiating from the
definition of that template rather than a previous declaration. In
general, we need a better solution for this for all TagDecls, because
it's too easy to accidentally look at a declaration that isn't the
definition.
We can now process a simple Fibonacci computation described as a
template metaprogram.
llvm-svn: 67308
2009-03-20 01:26:29 +08:00
|
|
|
NamedDecl *Decl,
|
|
|
|
ClassTemplateDecl *PrevDecl) {
|
|
|
|
Common *CommonPtr;
|
|
|
|
if (PrevDecl)
|
|
|
|
CommonPtr = PrevDecl->CommonPtr;
|
|
|
|
else
|
|
|
|
CommonPtr = new (C) Common;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
return new (C) ClassTemplateDecl(DC, L, Name, Params, Decl, PrevDecl,
|
Introduce a new expression type, UnresolvedDeclRefExpr, that describes
dependent qualified-ids such as
Fibonacci<N - 1>::value
where N is a template parameter. These references are "unresolved"
because the name is dependent and, therefore, cannot be resolved to a
declaration node (as we would do for a DeclRefExpr or
QualifiedDeclRefExpr). UnresolvedDeclRefExprs instantiate to
DeclRefExprs, QualifiedDeclRefExprs, etc.
Also, be a bit more careful about keeping only a single set of
specializations for a class template, and instantiating from the
definition of that template rather than a previous declaration. In
general, we need a better solution for this for all TagDecls, because
it's too easy to accidentally look at a declaration that isn't the
definition.
We can now process a simple Fibonacci computation described as a
template metaprogram.
llvm-svn: 67308
2009-03-20 01:26:29 +08:00
|
|
|
CommonPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassTemplateDecl::~ClassTemplateDecl() {
|
|
|
|
assert(CommonPtr == 0 && "ClassTemplateDecl must be explicitly destroyed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassTemplateDecl::Destroy(ASTContext& C) {
|
|
|
|
if (!PreviousDeclaration) {
|
|
|
|
CommonPtr->~Common();
|
|
|
|
C.Deallocate((void*)CommonPtr);
|
|
|
|
}
|
|
|
|
CommonPtr = 0;
|
|
|
|
|
|
|
|
this->~ClassTemplateDecl();
|
|
|
|
C.Deallocate((void*)this);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2009-07-31 01:40:51 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findPartialSpecialization(QualType T) {
|
|
|
|
ASTContext &Context = getASTContext();
|
|
|
|
typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
|
|
|
|
partial_spec_iterator;
|
|
|
|
for (partial_spec_iterator P = getPartialSpecializations().begin(),
|
|
|
|
PEnd = getPartialSpecializations().end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (Context.hasSameType(Context.getTypeDeclType(&*P), T))
|
|
|
|
return &*P;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-31 01:40:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-11 06:57:19 +08:00
|
|
|
QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) {
|
|
|
|
if (!CommonPtr->InjectedClassNameType.isNull())
|
|
|
|
return CommonPtr->InjectedClassNameType;
|
|
|
|
|
|
|
|
// FIXME: n2800 14.6.1p1 should say how the template arguments
|
|
|
|
// corresponding to template parameter packs should be pack
|
|
|
|
// expansions. We already say that in 14.6.2.1p2, so it would be
|
|
|
|
// better to fix that redundancy.
|
|
|
|
|
|
|
|
TemplateParameterList *Params = getTemplateParameters();
|
|
|
|
llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
|
|
|
|
TemplateArgs.reserve(Params->size());
|
2009-09-09 23:08:12 +08:00
|
|
|
for (TemplateParameterList::iterator Param = Params->begin(),
|
|
|
|
ParamEnd = Params->end();
|
2009-05-11 06:57:19 +08:00
|
|
|
Param != ParamEnd; ++Param) {
|
|
|
|
if (isa<TemplateTypeParmDecl>(*Param)) {
|
|
|
|
QualType ParamType = Context.getTypeDeclType(cast<TypeDecl>(*Param));
|
2009-10-29 16:12:44 +08:00
|
|
|
TemplateArgs.push_back(TemplateArgument(ParamType));
|
2009-09-09 23:08:12 +08:00
|
|
|
} else if (NonTypeTemplateParmDecl *NTTP =
|
2009-05-11 06:57:19 +08:00
|
|
|
dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
|
|
|
|
Expr *E = new (Context) DeclRefExpr(NTTP, NTTP->getType(),
|
|
|
|
NTTP->getLocation(),
|
|
|
|
NTTP->getType()->isDependentType(),
|
|
|
|
/*Value-dependent=*/true);
|
|
|
|
TemplateArgs.push_back(TemplateArgument(E));
|
2009-09-09 23:08:12 +08:00
|
|
|
} else {
|
2009-05-11 06:57:19 +08:00
|
|
|
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
|
2009-10-29 16:12:44 +08:00
|
|
|
TemplateArgs.push_back(TemplateArgument(TTP));
|
2009-05-11 06:57:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CommonPtr->InjectedClassNameType
|
2009-07-29 07:00:59 +08:00
|
|
|
= Context.getTemplateSpecializationType(TemplateName(this),
|
2009-05-11 06:57:19 +08:00
|
|
|
&TemplateArgs[0],
|
2009-07-29 07:00:59 +08:00
|
|
|
TemplateArgs.size());
|
2009-05-11 06:57:19 +08:00
|
|
|
return CommonPtr->InjectedClassNameType;
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateTypeParm Allocation/Deallocation Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TemplateTypeParmDecl *
|
|
|
|
TemplateTypeParmDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, unsigned D, unsigned P,
|
2009-06-13 06:23:22 +08:00
|
|
|
IdentifierInfo *Id, bool Typename,
|
|
|
|
bool ParameterPack) {
|
2009-06-16 08:30:48 +08:00
|
|
|
QualType Type = C.getTemplateTypeParmType(D, P, ParameterPack, Id);
|
2009-06-13 06:23:22 +08:00
|
|
|
return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type, ParameterPack);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:44 +08:00
|
|
|
SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
|
|
|
|
return DefaultArgument->getTypeLoc().getFullSourceRange().getBegin();
|
|
|
|
}
|
|
|
|
|
2009-10-29 08:04:11 +08:00
|
|
|
unsigned TemplateTypeParmDecl::getDepth() const {
|
|
|
|
return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned TemplateTypeParmDecl::getIndex() const {
|
|
|
|
return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex();
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NonTypeTemplateParmDecl Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
NonTypeTemplateParmDecl *
|
|
|
|
NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, unsigned D, unsigned P,
|
|
|
|
IdentifierInfo *Id, QualType T,
|
2009-08-21 08:31:54 +08:00
|
|
|
DeclaratorInfo *DInfo) {
|
|
|
|
return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, DInfo);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2009-02-11 03:49:53 +08:00
|
|
|
SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
|
|
|
|
return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
|
2009-09-09 23:08:12 +08:00
|
|
|
: SourceLocation();
|
2009-02-11 03:49:53 +08:00
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateTemplateParmDecl Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TemplateTemplateParmDecl *
|
|
|
|
TemplateTemplateParmDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, unsigned D, unsigned P,
|
|
|
|
IdentifierInfo *Id,
|
|
|
|
TemplateParameterList *Params) {
|
|
|
|
return new (C) TemplateTemplateParmDecl(DC, L, D, P, Id, Params);
|
|
|
|
}
|
|
|
|
|
2009-02-11 03:49:53 +08:00
|
|
|
SourceLocation TemplateTemplateParmDecl::getDefaultArgumentLoc() const {
|
|
|
|
return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
|
2009-09-09 23:08:12 +08:00
|
|
|
: SourceLocation();
|
2009-02-11 03:49:53 +08:00
|
|
|
}
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
|
2009-06-05 13:31:27 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateArgumentListBuilder Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-23 09:26:57 +08:00
|
|
|
|
|
|
|
void TemplateArgumentListBuilder::Append(const TemplateArgument& Arg) {
|
2009-06-05 13:31:27 +08:00
|
|
|
switch (Arg.getKind()) {
|
2009-06-23 09:26:57 +08:00
|
|
|
default: break;
|
|
|
|
case TemplateArgument::Type:
|
2009-10-23 04:10:53 +08:00
|
|
|
assert(Arg.getAsType().isCanonical() && "Type must be canonical!");
|
2009-06-23 09:26:57 +08:00
|
|
|
break;
|
2009-06-05 13:31:27 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
assert(NumFlatArgs < MaxFlatArgs && "Argument list builder is full!");
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(!StructuredArgs &&
|
2009-06-23 09:26:57 +08:00
|
|
|
"Can't append arguments when an argument pack has been added!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
if (!FlatArgs)
|
|
|
|
FlatArgs = new TemplateArgument[MaxFlatArgs];
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
FlatArgs[NumFlatArgs++] = Arg;
|
2009-06-05 13:31:27 +08:00
|
|
|
}
|
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
void TemplateArgumentListBuilder::BeginPack() {
|
|
|
|
assert(!AddingToPack && "Already adding to pack!");
|
|
|
|
assert(!StructuredArgs && "Argument list already contains a pack!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
AddingToPack = true;
|
|
|
|
PackBeginIndex = NumFlatArgs;
|
2009-06-13 08:08:58 +08:00
|
|
|
}
|
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
void TemplateArgumentListBuilder::EndPack() {
|
|
|
|
assert(AddingToPack && "Not adding to pack!");
|
|
|
|
assert(!StructuredArgs && "Argument list already contains a pack!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
AddingToPack = false;
|
2009-06-16 01:56:45 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
StructuredArgs = new TemplateArgument[MaxStructuredArgs];
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
// First copy the flat entries over to the list (if any)
|
|
|
|
for (unsigned I = 0; I != PackBeginIndex; ++I) {
|
|
|
|
NumStructuredArgs++;
|
|
|
|
StructuredArgs[I] = FlatArgs[I];
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
// Next, set the pack.
|
|
|
|
TemplateArgument *PackArgs = 0;
|
|
|
|
unsigned NumPackArgs = NumFlatArgs - PackBeginIndex;
|
|
|
|
if (NumPackArgs)
|
|
|
|
PackArgs = &FlatArgs[PackBeginIndex];
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
StructuredArgs[NumStructuredArgs++].setArgumentPack(PackArgs, NumPackArgs,
|
2009-06-23 09:26:57 +08:00
|
|
|
/*CopyArgs=*/false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TemplateArgumentListBuilder::ReleaseArgs() {
|
|
|
|
FlatArgs = 0;
|
|
|
|
NumFlatArgs = 0;
|
|
|
|
MaxFlatArgs = 0;
|
|
|
|
StructuredArgs = 0;
|
|
|
|
NumStructuredArgs = 0;
|
|
|
|
MaxStructuredArgs = 0;
|
|
|
|
}
|
2009-06-13 08:08:58 +08:00
|
|
|
|
2009-05-12 07:53:27 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateArgumentList Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
TemplateArgumentList::TemplateArgumentList(ASTContext &Context,
|
2009-06-05 12:47:51 +08:00
|
|
|
TemplateArgumentListBuilder &Builder,
|
2009-06-23 09:26:57 +08:00
|
|
|
bool TakeArgs)
|
2009-09-09 23:08:12 +08:00
|
|
|
: FlatArguments(Builder.getFlatArguments(), TakeArgs),
|
|
|
|
NumFlatArguments(Builder.flatSize()),
|
2009-06-23 09:26:57 +08:00
|
|
|
StructuredArguments(Builder.getStructuredArguments(), TakeArgs),
|
|
|
|
NumStructuredArguments(Builder.structuredSize()) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
if (!TakeArgs)
|
|
|
|
return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-23 09:26:57 +08:00
|
|
|
if (Builder.getStructuredArguments() == Builder.getFlatArguments())
|
|
|
|
StructuredArguments.setInt(0);
|
|
|
|
Builder.ReleaseArgs();
|
2009-05-12 07:53:27 +08:00
|
|
|
}
|
|
|
|
|
2009-09-25 07:14:47 +08:00
|
|
|
TemplateArgumentList::TemplateArgumentList(const TemplateArgumentList &Other)
|
|
|
|
: FlatArguments(Other.FlatArguments.getPointer(), 1),
|
|
|
|
NumFlatArguments(Other.flat_size()),
|
|
|
|
StructuredArguments(Other.StructuredArguments.getPointer(), 1),
|
|
|
|
NumStructuredArguments(Other.NumStructuredArguments) { }
|
|
|
|
|
2009-05-12 07:53:27 +08:00
|
|
|
TemplateArgumentList::~TemplateArgumentList() {
|
|
|
|
// FIXME: Deallocate template arguments
|
|
|
|
}
|
|
|
|
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassTemplateSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
ClassTemplateSpecializationDecl::
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK,
|
2009-05-12 07:53:27 +08:00
|
|
|
DeclContext *DC, SourceLocation L,
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
ClassTemplateDecl *SpecializedTemplate,
|
2009-07-30 07:36:44 +08:00
|
|
|
TemplateArgumentListBuilder &Builder,
|
|
|
|
ClassTemplateSpecializationDecl *PrevDecl)
|
2009-09-09 23:08:12 +08:00
|
|
|
: CXXRecordDecl(DK,
|
|
|
|
SpecializedTemplate->getTemplatedDecl()->getTagKind(),
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
DC, L,
|
|
|
|
// FIXME: Should we use DeclarationName for the name of
|
|
|
|
// class template specializations?
|
2009-07-30 07:36:44 +08:00
|
|
|
SpecializedTemplate->getIdentifier(),
|
|
|
|
PrevDecl),
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
SpecializedTemplate(SpecializedTemplate),
|
2009-06-23 09:26:57 +08:00
|
|
|
TemplateArgs(Context, Builder, /*TakeArgs=*/true),
|
2009-05-12 07:53:27 +08:00
|
|
|
SpecializationKind(TSK_Undeclared) {
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
ClassTemplateSpecializationDecl *
|
2009-09-09 23:08:12 +08:00
|
|
|
ClassTemplateSpecializationDecl::Create(ASTContext &Context,
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
DeclContext *DC, SourceLocation L,
|
|
|
|
ClassTemplateDecl *SpecializedTemplate,
|
2009-06-05 12:06:48 +08:00
|
|
|
TemplateArgumentListBuilder &Builder,
|
2009-02-18 07:15:12 +08:00
|
|
|
ClassTemplateSpecializationDecl *PrevDecl) {
|
|
|
|
ClassTemplateSpecializationDecl *Result
|
2009-09-09 23:08:12 +08:00
|
|
|
= new (Context)ClassTemplateSpecializationDecl(Context,
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplateSpecialization,
|
2009-09-09 23:08:12 +08:00
|
|
|
DC, L,
|
2009-05-12 07:53:27 +08:00
|
|
|
SpecializedTemplate,
|
2009-07-30 07:36:44 +08:00
|
|
|
Builder,
|
|
|
|
PrevDecl);
|
2009-02-18 07:15:12 +08:00
|
|
|
Context.getTypeDeclType(Result, PrevDecl);
|
|
|
|
return Result;
|
Added ClassTemplateSpecializationDecl, which is a subclass of
CXXRecordDecl that is used to represent class template
specializations. These are canonical declarations that can refer to
either an actual class template specialization in the code, e.g.,
template<> class vector<bool> { };
or to a template instantiation. However, neither of these features is
actually implemented yet, so really we're just using (and uniqing) the
declarations to make sure that, e.g., A<int> is a different type from
A<float>. Note that we carefully distinguish between what the user
wrote in the source code (e.g., "A<FLOAT>") and the semantic entity it
represents (e.g., "A<float, int>"); the former is in the sugared Type,
the latter is an actual Decl.
llvm-svn: 64716
2009-02-17 09:05:43 +08:00
|
|
|
}
|
2009-05-31 17:31:02 +08:00
|
|
|
|
2009-08-03 07:24:31 +08:00
|
|
|
void ClassTemplateSpecializationDecl::Destroy(ASTContext &C) {
|
2009-09-09 23:08:12 +08:00
|
|
|
if (SpecializedPartialSpecialization *PartialSpec
|
2009-08-03 07:24:31 +08:00
|
|
|
= SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
|
|
|
|
C.Deallocate(PartialSpec);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-03 07:24:31 +08:00
|
|
|
CXXRecordDecl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-09-11 14:45:03 +08:00
|
|
|
void
|
|
|
|
ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S,
|
|
|
|
const PrintingPolicy &Policy,
|
|
|
|
bool Qualified) const {
|
|
|
|
NamedDecl::getNameForDiagnostic(S, Policy, Qualified);
|
|
|
|
|
|
|
|
const TemplateArgumentList &TemplateArgs = getTemplateArgs();
|
|
|
|
S += TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
TemplateArgs.getFlatArgumentList(),
|
|
|
|
TemplateArgs.flat_size(),
|
|
|
|
Policy);
|
|
|
|
}
|
|
|
|
|
2009-08-03 07:24:31 +08:00
|
|
|
ClassTemplateDecl *
|
2009-09-09 23:08:12 +08:00
|
|
|
ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
|
|
|
|
if (SpecializedPartialSpecialization *PartialSpec
|
2009-08-03 07:24:31 +08:00
|
|
|
= SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
|
|
|
|
return PartialSpec->PartialSpecialization->getSpecializedTemplate();
|
|
|
|
return SpecializedTemplate.get<ClassTemplateDecl*>();
|
|
|
|
}
|
|
|
|
|
2009-05-31 17:31:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassTemplatePartialSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplatePartialSpecializationDecl::
|
|
|
|
Create(ASTContext &Context, DeclContext *DC, SourceLocation L,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
ClassTemplateDecl *SpecializedTemplate,
|
2009-06-05 12:06:48 +08:00
|
|
|
TemplateArgumentListBuilder &Builder,
|
2009-10-29 16:12:44 +08:00
|
|
|
TemplateArgumentLoc *ArgInfos, unsigned N,
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *PrevDecl) {
|
2009-10-29 16:12:44 +08:00
|
|
|
TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N];
|
|
|
|
for (unsigned I = 0; I != N; ++I)
|
|
|
|
ClonedArgs[I] = ArgInfos[I];
|
|
|
|
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *Result
|
2009-09-09 23:08:12 +08:00
|
|
|
= new (Context)ClassTemplatePartialSpecializationDecl(Context,
|
2009-05-31 17:31:02 +08:00
|
|
|
DC, L, Params,
|
|
|
|
SpecializedTemplate,
|
2009-10-29 16:12:44 +08:00
|
|
|
Builder,
|
|
|
|
ClonedArgs, N,
|
|
|
|
PrevDecl);
|
2009-05-31 17:31:02 +08:00
|
|
|
Result->setSpecializationKind(TSK_ExplicitSpecialization);
|
|
|
|
Context.getTypeDeclType(Result, PrevDecl);
|
|
|
|
return Result;
|
|
|
|
}
|
2009-09-17 06:47:08 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FriendTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
unsigned NParams,
|
|
|
|
TemplateParameterList **Params,
|
|
|
|
FriendUnion Friend,
|
|
|
|
SourceLocation FLoc) {
|
|
|
|
FriendTemplateDecl *Result
|
|
|
|
= new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc);
|
|
|
|
return Result;
|
|
|
|
}
|