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"
|
2010-10-28 15:38:42 +08:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
2009-02-05 03:02:06 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2010-11-08 07:05:16 +08:00
|
|
|
#include <memory>
|
2009-02-05 03:02:06 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-07-30 00:11:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RedeclarableTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() {
|
|
|
|
// Find the first declaration of this function template.
|
|
|
|
RedeclarableTemplateDecl *First = getCanonicalDecl();
|
|
|
|
|
|
|
|
if (First->CommonOrPrev.isNull()) {
|
2010-09-09 03:31:22 +08:00
|
|
|
CommonBase *CommonPtr = First->newCommon(getASTContext());
|
2010-07-30 00:11:51 +08:00
|
|
|
First->CommonOrPrev = CommonPtr;
|
2010-07-30 00:12:01 +08:00
|
|
|
CommonPtr->Latest = First;
|
2010-07-30 00:11:51 +08:00
|
|
|
}
|
|
|
|
return First->CommonOrPrev.get<CommonBase*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() {
|
|
|
|
RedeclarableTemplateDecl *Tmpl = this;
|
|
|
|
while (Tmpl->getPreviousDeclaration())
|
|
|
|
Tmpl = Tmpl->getPreviousDeclaration();
|
|
|
|
return Tmpl;
|
|
|
|
}
|
|
|
|
|
2010-07-30 00:12:01 +08:00
|
|
|
void RedeclarableTemplateDecl::setPreviousDeclarationImpl(
|
|
|
|
RedeclarableTemplateDecl *Prev) {
|
|
|
|
if (Prev) {
|
|
|
|
CommonBase *Common = Prev->getCommonPtr();
|
|
|
|
Prev = Common->Latest;
|
|
|
|
Common->Latest = this;
|
|
|
|
CommonOrPrev = Prev;
|
|
|
|
} else {
|
|
|
|
assert(CommonOrPrev.is<CommonBase*>() && "Cannot reset TemplateDecl Prev");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 00:12:09 +08:00
|
|
|
RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() {
|
|
|
|
if (CommonOrPrev.is<RedeclarableTemplateDecl*>())
|
|
|
|
return CommonOrPrev.get<RedeclarableTemplateDecl*>();
|
|
|
|
CommonBase *Common = CommonOrPrev.get<CommonBase*>();
|
|
|
|
return Common ? Common->Latest : this;
|
|
|
|
}
|
|
|
|
|
2010-07-31 01:09:04 +08:00
|
|
|
template <class EntryType>
|
|
|
|
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
|
|
|
|
RedeclarableTemplateDecl::findSpecializationImpl(
|
|
|
|
llvm::FoldingSet<EntryType> &Specs,
|
|
|
|
const TemplateArgument *Args, unsigned NumArgs,
|
|
|
|
void *&InsertPos) {
|
|
|
|
typedef SpecEntryTraits<EntryType> SETraits;
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
EntryType::Profile(ID,Args,NumArgs, getASTContext());
|
|
|
|
EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0;
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FunctionTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-24 02:26:36 +08:00
|
|
|
void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
|
|
|
|
static_cast<Common *>(Ptr)->~Common();
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-09-09 03:31:22 +08:00
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
|
|
|
FunctionTemplateDecl::newCommon(ASTContext &C) {
|
|
|
|
Common *CommonPtr = new (C) Common;
|
|
|
|
C.AddDeallocation(DeallocateCommon, CommonPtr);
|
2010-07-30 00:11:51 +08:00
|
|
|
return CommonPtr;
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:59:58 +08:00
|
|
|
FunctionDecl *
|
|
|
|
FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs, void *&InsertPos) {
|
2010-07-31 01:09:04 +08:00
|
|
|
return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
|
2010-07-20 21:59:58 +08:00
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-24 02:26:36 +08:00
|
|
|
void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
|
|
|
|
static_cast<Common *>(Ptr)->~Common();
|
|
|
|
}
|
|
|
|
|
2010-06-20 03:29:09 +08:00
|
|
|
ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
DeclarationName Name,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
NamedDecl *Decl,
|
|
|
|
ClassTemplateDecl *PrevDecl) {
|
|
|
|
ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl);
|
2010-06-21 18:57:41 +08:00
|
|
|
New->setPreviousDeclaration(PrevDecl);
|
2010-06-20 03:29:09 +08:00
|
|
|
return New;
|
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
|
|
|
}
|
|
|
|
|
2010-10-28 06:21:36 +08:00
|
|
|
void ClassTemplateDecl::LoadLazySpecializations() {
|
|
|
|
Common *CommonPtr = getCommonPtr();
|
|
|
|
if (CommonPtr->LazySpecializations) {
|
|
|
|
ASTContext &Context = getASTContext();
|
|
|
|
uint32_t *Specs = CommonPtr->LazySpecializations;
|
|
|
|
CommonPtr->LazySpecializations = 0;
|
|
|
|
for (uint32_t I = 0, N = *Specs++; I != N; ++I)
|
|
|
|
(void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::FoldingSet<ClassTemplateSpecializationDecl> &
|
|
|
|
ClassTemplateDecl::getSpecializations() {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->Specializations;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
|
|
|
|
ClassTemplateDecl::getPartialSpecializations() {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->PartialSpecializations;
|
|
|
|
}
|
|
|
|
|
2010-09-09 03:31:22 +08:00
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
|
|
|
ClassTemplateDecl::newCommon(ASTContext &C) {
|
|
|
|
Common *CommonPtr = new (C) Common;
|
|
|
|
C.AddDeallocation(DeallocateCommon, CommonPtr);
|
2010-07-30 00:11:51 +08:00
|
|
|
return CommonPtr;
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:59:28 +08:00
|
|
|
ClassTemplateSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs, void *&InsertPos) {
|
2010-07-31 01:09:04 +08:00
|
|
|
return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
|
2010-07-20 21:59:28 +08:00
|
|
|
}
|
|
|
|
|
2010-10-28 15:38:42 +08:00
|
|
|
void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
|
|
|
|
void *InsertPos) {
|
|
|
|
getSpecializations().InsertNode(D, InsertPos);
|
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, D);
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:59:28 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs,
|
|
|
|
void *&InsertPos) {
|
2010-07-31 01:09:04 +08:00
|
|
|
return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
|
|
|
|
InsertPos);
|
2010-07-20 21:59:28 +08:00
|
|
|
}
|
|
|
|
|
2010-10-28 15:38:42 +08:00
|
|
|
void ClassTemplateDecl::AddPartialSpecialization(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D,
|
|
|
|
void *InsertPos) {
|
|
|
|
getPartialSpecializations().InsertNode(D, InsertPos);
|
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, D);
|
|
|
|
}
|
|
|
|
|
2010-04-30 13:56:50 +08:00
|
|
|
void ClassTemplateDecl::getPartialSpecializations(
|
|
|
|
llvm::SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
|
|
|
|
llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs
|
2010-06-21 18:57:41 +08:00
|
|
|
= getPartialSpecializations();
|
2010-04-30 13:56:50 +08:00
|
|
|
PS.clear();
|
|
|
|
PS.resize(PartialSpecs.size());
|
|
|
|
for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
|
|
|
|
P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
assert(!PS[P->getSequenceNumber()]);
|
2010-07-20 21:59:28 +08:00
|
|
|
PS[P->getSequenceNumber()] = P->getMostRecentDeclaration();
|
2010-04-30 13:56:50 +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) {
|
2010-04-27 08:57:59 +08:00
|
|
|
if (Context.hasSameType(P->getInjectedSpecializationType(), T))
|
2010-07-20 21:59:28 +08:00
|
|
|
return P->getMostRecentDeclaration();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
|
|
|
Decl *DCanon = D->getCanonicalDecl();
|
|
|
|
for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
|
|
|
|
P = getPartialSpecializations().begin(),
|
|
|
|
PEnd = getPartialSpecializations().end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
|
|
|
|
return P->getMostRecentDeclaration();
|
2009-07-31 01:40:51 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-31 01:40:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:28:59 +08:00
|
|
|
QualType
|
2010-07-09 02:37:38 +08:00
|
|
|
ClassTemplateDecl::getInjectedClassNameSpecialization() {
|
2010-06-21 18:57:41 +08:00
|
|
|
Common *CommonPtr = getCommonPtr();
|
2009-05-11 06:57:19 +08:00
|
|
|
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.
|
2010-07-09 02:37:38 +08:00
|
|
|
ASTContext &Context = getASTContext();
|
2009-05-11 06:57:19 +08:00
|
|
|
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)) {
|
2010-01-31 15:24:03 +08:00
|
|
|
Expr *E = new (Context) DeclRefExpr(NTTP,
|
2010-07-14 02:40:04 +08:00
|
|
|
NTTP->getType().getNonLValueExprType(Context),
|
2010-11-18 14:31:45 +08:00
|
|
|
Expr::getValueKindForType(NTTP->getType()),
|
2009-11-23 19:41:28 +08:00
|
|
|
NTTP->getLocation());
|
2009-05-11 06:57:19 +08:00
|
|
|
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-11-11 09:00:40 +08:00
|
|
|
TemplateArgs.push_back(TemplateArgument(TemplateName(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) {
|
2010-06-16 23:23:05 +08:00
|
|
|
QualType Type = C.getTemplateTypeParmType(D, P, ParameterPack, Id);
|
|
|
|
return new (C) TemplateTypeParmDecl(DC, L, Id, Typename, Type, ParameterPack);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2010-07-02 19:54:55 +08:00
|
|
|
TemplateTypeParmDecl *
|
|
|
|
TemplateTypeParmDecl::Create(ASTContext &C, EmptyShell Empty) {
|
|
|
|
return new (C) TemplateTypeParmDecl(0, SourceLocation(), 0, false,
|
|
|
|
QualType(), false);
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:44 +08:00
|
|
|
SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
|
2010-05-20 18:00:11 +08:00
|
|
|
return DefaultArgument->getTypeLoc().getSourceRange().getBegin();
|
2009-10-29 16:12:44 +08:00
|
|
|
}
|
|
|
|
|
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-12-07 10:54:59 +08:00
|
|
|
TypeSourceInfo *TInfo) {
|
|
|
|
return new (C) NonTypeTemplateParmDecl(DC, L, D, P, Id, T, TInfo);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2009-02-11 03:49:53 +08:00
|
|
|
SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
|
2010-06-09 17:26:05 +08:00
|
|
|
return hasDefaultArgument()
|
|
|
|
? getDefaultArgument()->getSourceRange().getBegin()
|
|
|
|
: 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-05-12 07:53:27 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateArgumentList Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-11-08 07:05:16 +08:00
|
|
|
TemplateArgumentList *
|
|
|
|
TemplateArgumentList::CreateCopy(ASTContext &Context,
|
|
|
|
const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs) {
|
|
|
|
std::size_t Size = sizeof(TemplateArgumentList)
|
|
|
|
+ NumArgs * sizeof(TemplateArgument);
|
|
|
|
void *Mem = Context.Allocate(Size);
|
|
|
|
TemplateArgument *StoredArgs
|
|
|
|
= reinterpret_cast<TemplateArgument *>(
|
|
|
|
static_cast<TemplateArgumentList *>(Mem) + 1);
|
|
|
|
std::uninitialized_copy(Args, Args + NumArgs, StoredArgs);
|
|
|
|
return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true);
|
2010-06-23 21:48:23 +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 Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
ClassTemplateSpecializationDecl::
|
2010-05-06 08:28:52 +08:00
|
|
|
ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
|
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,
|
2010-11-08 07:05:16 +08:00
|
|
|
const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs,
|
2009-07-30 07:36:44 +08:00
|
|
|
ClassTemplateSpecializationDecl *PrevDecl)
|
2010-05-06 08:28:52 +08:00
|
|
|
: CXXRecordDecl(DK, TK, DC, L,
|
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),
|
2010-06-12 15:44:57 +08:00
|
|
|
ExplicitInfo(0),
|
2010-11-08 07:05:16 +08:00
|
|
|
TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
|
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
|
|
|
|
2010-06-23 21:48:23 +08:00
|
|
|
ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK)
|
|
|
|
: CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), 0, 0),
|
|
|
|
ExplicitInfo(0),
|
|
|
|
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
|
|
|
ClassTemplateSpecializationDecl *
|
2010-05-06 08:28:52 +08:00
|
|
|
ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
|
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,
|
2010-11-08 07:05:16 +08:00
|
|
|
const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs,
|
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,
|
2010-05-06 08:28:52 +08:00
|
|
|
TK, DC, L,
|
2009-05-12 07:53:27 +08:00
|
|
|
SpecializedTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
Args, NumArgs,
|
2009-07-30 07:36:44 +08:00
|
|
|
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
|
|
|
|
2010-06-23 21:48:23 +08:00
|
|
|
ClassTemplateSpecializationDecl *
|
2010-07-02 19:54:55 +08:00
|
|
|
ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) {
|
2010-06-23 21:48:23 +08:00
|
|
|
return
|
|
|
|
new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
|
|
|
|
}
|
|
|
|
|
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(
|
2010-11-08 07:05:16 +08:00
|
|
|
TemplateArgs.data(),
|
|
|
|
TemplateArgs.size(),
|
2009-09-11 14:45:03 +08:00
|
|
|
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::
|
2010-05-06 08:28:52 +08:00
|
|
|
Create(ASTContext &Context, TagKind TK,DeclContext *DC, SourceLocation L,
|
2009-05-31 17:31:02 +08:00
|
|
|
TemplateParameterList *Params,
|
|
|
|
ClassTemplateDecl *SpecializedTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs,
|
2009-11-23 09:53:49 +08:00
|
|
|
const TemplateArgumentListInfo &ArgInfos,
|
2010-03-10 11:28:59 +08:00
|
|
|
QualType CanonInjectedType,
|
2010-04-30 13:56:50 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *PrevDecl,
|
|
|
|
unsigned SequenceNumber) {
|
2009-11-23 09:53:49 +08:00
|
|
|
unsigned N = ArgInfos.size();
|
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
|
2010-05-06 08:28:52 +08:00
|
|
|
= new (Context)ClassTemplatePartialSpecializationDecl(Context, TK,
|
2009-05-31 17:31:02 +08:00
|
|
|
DC, L, Params,
|
|
|
|
SpecializedTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
Args, NumArgs,
|
2009-10-29 16:12:44 +08:00
|
|
|
ClonedArgs, N,
|
2010-04-30 13:56:50 +08:00
|
|
|
PrevDecl,
|
|
|
|
SequenceNumber);
|
2009-05-31 17:31:02 +08:00
|
|
|
Result->setSpecializationKind(TSK_ExplicitSpecialization);
|
2010-03-10 11:28:59 +08:00
|
|
|
|
|
|
|
Context.getInjectedClassNameType(Result, CanonInjectedType);
|
2009-05-31 17:31:02 +08:00
|
|
|
return Result;
|
|
|
|
}
|
2009-09-17 06:47:08 +08:00
|
|
|
|
2010-06-23 21:48:23 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *
|
2010-07-02 19:54:55 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl::Create(ASTContext &Context,
|
|
|
|
EmptyShell Empty) {
|
2010-06-23 21:48:23 +08:00
|
|
|
return new (Context)ClassTemplatePartialSpecializationDecl();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2010-07-23 00:04:10 +08:00
|
|
|
|
|
|
|
FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
|
|
|
|
EmptyShell Empty) {
|
|
|
|
return new (Context) FriendTemplateDecl(Empty);
|
|
|
|
}
|