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/DeclTemplate.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-02-10 02:46:07 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2011-01-04 10:33:52 +08:00
|
|
|
#include "clang/AST/ExprCXX.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"
|
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),
|
2012-09-07 10:06:42 +08:00
|
|
|
NumParams(NumParams), ContainsUnexpandedParameterPack(false) {
|
|
|
|
assert(this->NumParams == NumParams && "Too many template parameters");
|
|
|
|
for (unsigned Idx = 0; Idx < NumParams; ++Idx) {
|
|
|
|
NamedDecl *P = Params[Idx];
|
|
|
|
begin()[Idx] = P;
|
|
|
|
|
|
|
|
if (!P->isTemplateParameterPack()) {
|
|
|
|
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(P))
|
|
|
|
if (NTTP->getType()->containsUnexpandedParameterPack())
|
|
|
|
ContainsUnexpandedParameterPack = true;
|
|
|
|
|
|
|
|
if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(P))
|
|
|
|
if (TTP->getTemplateParameters()->containsUnexpandedParameterPack())
|
|
|
|
ContainsUnexpandedParameterPack = true;
|
|
|
|
|
|
|
|
// FIXME: If a default argument contains an unexpanded parameter pack, the
|
|
|
|
// template parameter list does too.
|
|
|
|
}
|
|
|
|
}
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TemplateParameterList *
|
2011-01-12 17:06:06 +08:00
|
|
|
TemplateParameterList::Create(const 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;
|
2012-08-17 06:51:34 +08:00
|
|
|
unsigned Align = std::max(llvm::alignOf<TemplateParameterList>(),
|
|
|
|
llvm::alignOf<NamedDecl*>());
|
2009-02-05 03:02:06 +08:00
|
|
|
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 {
|
2011-01-20 04:10:05 +08:00
|
|
|
unsigned NumRequiredArgs = 0;
|
|
|
|
for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
|
|
|
|
PEnd = const_cast<TemplateParameterList *>(this)->end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if ((*P)->isTemplateParameterPack()) {
|
|
|
|
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
|
|
|
|
if (NTTP->isExpandedParameterPack()) {
|
|
|
|
NumRequiredArgs += NTTP->getNumExpansionTypes();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-02-12 02:16:40 +08:00
|
|
|
break;
|
2011-01-20 04:10:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
|
|
|
|
if (TTP->hasDefaultArgument())
|
|
|
|
break;
|
|
|
|
} else if (NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(*P)) {
|
|
|
|
if (NTTP->hasDefaultArgument())
|
|
|
|
break;
|
|
|
|
} else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
|
|
|
|
break;
|
|
|
|
|
|
|
|
++NumRequiredArgs;
|
2009-02-12 02:16:40 +08:00
|
|
|
}
|
2011-01-20 04:10:05 +08:00
|
|
|
|
2009-02-12 02:16:40 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-03-05 02:32:38 +08:00
|
|
|
static void AdoptTemplateParameterList(TemplateParameterList *Params,
|
|
|
|
DeclContext *Owner) {
|
|
|
|
for (TemplateParameterList::iterator P = Params->begin(),
|
|
|
|
PEnd = Params->end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
(*P)->setDeclContext(Owner);
|
|
|
|
|
|
|
|
if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
|
|
|
|
AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 00:11:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RedeclarableTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-24 00:52:57 +08:00
|
|
|
RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() const {
|
2012-01-14 23:13:49 +08:00
|
|
|
if (!Common) {
|
|
|
|
// Walk the previous-declaration chain until we either find a declaration
|
|
|
|
// with a common pointer or we run out of previous declarations.
|
2013-01-24 00:52:57 +08:00
|
|
|
SmallVector<const RedeclarableTemplateDecl *, 2> PrevDecls;
|
|
|
|
for (const RedeclarableTemplateDecl *Prev = getPreviousDecl(); Prev;
|
2012-01-15 00:38:05 +08:00
|
|
|
Prev = Prev->getPreviousDecl()) {
|
2012-01-14 23:13:49 +08:00
|
|
|
if (Prev->Common) {
|
|
|
|
Common = Prev->Common;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrevDecls.push_back(Prev);
|
|
|
|
}
|
2010-07-30 00:11:51 +08:00
|
|
|
|
2012-01-14 23:13:49 +08:00
|
|
|
// If we never found a common pointer, allocate one now.
|
2012-01-14 23:30:55 +08:00
|
|
|
if (!Common) {
|
|
|
|
// FIXME: If any of the declarations is from an AST file, we probably
|
|
|
|
// need an update record to add the common data.
|
|
|
|
|
2012-01-14 23:13:49 +08:00
|
|
|
Common = newCommon(getASTContext());
|
2012-01-14 23:30:55 +08:00
|
|
|
}
|
2012-01-14 23:13:49 +08:00
|
|
|
|
|
|
|
// Update any previous declarations we saw with the common pointer.
|
|
|
|
for (unsigned I = 0, N = PrevDecls.size(); I != N; ++I)
|
|
|
|
PrevDecls[I]->Common = Common;
|
2010-07-30 00:12:01 +08:00
|
|
|
}
|
|
|
|
|
2012-01-14 23:13:49 +08:00
|
|
|
return Common;
|
2010-07-30 00:12:09 +08:00
|
|
|
}
|
|
|
|
|
2010-07-31 01:09:04 +08:00
|
|
|
template <class EntryType>
|
|
|
|
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
|
|
|
|
RedeclarableTemplateDecl::findSpecializationImpl(
|
2012-05-04 07:49:05 +08:00
|
|
|
llvm::FoldingSetVector<EntryType> &Specs,
|
2010-07-31 01:09:04 +08:00
|
|
|
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);
|
2012-01-15 00:38:05 +08:00
|
|
|
return Entry ? SETraits::getMostRecentDecl(Entry) : 0;
|
2010-07-31 01:09:04 +08:00
|
|
|
}
|
|
|
|
|
2011-03-06 01:54:25 +08:00
|
|
|
/// \brief Generate the injected template arguments for the given template
|
|
|
|
/// parameter list, e.g., for the injected-class-name of a class template.
|
|
|
|
static void GenerateInjectedTemplateArgs(ASTContext &Context,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
TemplateArgument *Args) {
|
|
|
|
for (TemplateParameterList::iterator Param = Params->begin(),
|
|
|
|
ParamEnd = Params->end();
|
|
|
|
Param != ParamEnd; ++Param) {
|
|
|
|
TemplateArgument Arg;
|
|
|
|
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
|
|
|
|
QualType ArgType = Context.getTypeDeclType(TTP);
|
|
|
|
if (TTP->isParameterPack())
|
2013-02-21 09:47:18 +08:00
|
|
|
ArgType = Context.getPackExpansionType(ArgType, None);
|
2013-02-21 06:23:23 +08:00
|
|
|
|
2011-03-06 01:54:25 +08:00
|
|
|
Arg = TemplateArgument(ArgType);
|
|
|
|
} else if (NonTypeTemplateParmDecl *NTTP =
|
|
|
|
dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
|
2012-03-10 17:33:50 +08:00
|
|
|
Expr *E = new (Context) DeclRefExpr(NTTP, /*enclosing*/ false,
|
2011-03-06 01:54:25 +08:00
|
|
|
NTTP->getType().getNonLValueExprType(Context),
|
|
|
|
Expr::getValueKindForType(NTTP->getType()),
|
|
|
|
NTTP->getLocation());
|
|
|
|
|
|
|
|
if (NTTP->isParameterPack())
|
2013-02-21 09:47:18 +08:00
|
|
|
E = new (Context) PackExpansionExpr(Context.DependentTy, E,
|
|
|
|
NTTP->getLocation(), None);
|
2011-03-06 01:54:25 +08:00
|
|
|
Arg = TemplateArgument(E);
|
|
|
|
} else {
|
|
|
|
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
|
|
|
|
if (TTP->isParameterPack())
|
2013-02-21 06:23:23 +08:00
|
|
|
Arg = TemplateArgument(TemplateName(TTP), Optional<unsigned>());
|
2011-03-06 01:54:25 +08:00
|
|
|
else
|
|
|
|
Arg = TemplateArgument(TemplateName(TTP));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*Param)->isTemplateParameterPack())
|
|
|
|
Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
|
|
|
|
|
|
|
|
*Args++ = Arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2011-03-05 02:32:38 +08:00
|
|
|
AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
|
2009-02-05 03:02:06 +08:00
|
|
|
return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
|
|
|
|
}
|
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl));
|
|
|
|
return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
|
|
|
|
0, 0);
|
2011-03-05 01:52:15 +08:00
|
|
|
}
|
|
|
|
|
2010-09-09 03:31:22 +08:00
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
2013-01-24 00:52:57 +08:00
|
|
|
FunctionTemplateDecl::newCommon(ASTContext &C) const {
|
2010-09-09 03:31:22 +08:00
|
|
|
Common *CommonPtr = new (C) Common;
|
|
|
|
C.AddDeallocation(DeallocateCommon, CommonPtr);
|
2010-07-30 00:11:51 +08:00
|
|
|
return CommonPtr;
|
|
|
|
}
|
|
|
|
|
2013-06-28 12:37:53 +08:00
|
|
|
void FunctionTemplateDecl::LoadLazySpecializations() const {
|
|
|
|
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::FoldingSetVector<FunctionTemplateSpecializationInfo> &
|
|
|
|
FunctionTemplateDecl::getSpecializations() const {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->Specializations;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-04-14 22:07:59 +08:00
|
|
|
void FunctionTemplateDecl::addSpecialization(
|
|
|
|
FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
|
2012-03-28 22:34:23 +08:00
|
|
|
if (InsertPos)
|
|
|
|
getSpecializations().InsertNode(Info, InsertPos);
|
|
|
|
else
|
|
|
|
getSpecializations().GetOrInsertNode(Info);
|
2011-04-14 22:07:59 +08:00
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, Info->Function);
|
|
|
|
}
|
|
|
|
|
2013-05-17 11:04:50 +08:00
|
|
|
ArrayRef<TemplateArgument> FunctionTemplateDecl::getInjectedTemplateArgs() {
|
2011-03-06 01:54:25 +08:00
|
|
|
TemplateParameterList *Params = getTemplateParameters();
|
|
|
|
Common *CommonPtr = getCommonPtr();
|
|
|
|
if (!CommonPtr->InjectedArgs) {
|
|
|
|
CommonPtr->InjectedArgs
|
2013-05-17 11:04:50 +08:00
|
|
|
= new (getASTContext()) TemplateArgument[Params->size()];
|
|
|
|
GenerateInjectedTemplateArgs(getASTContext(), Params,
|
2011-03-06 01:54:25 +08:00
|
|
|
CommonPtr->InjectedArgs);
|
|
|
|
}
|
2013-05-17 11:04:50 +08:00
|
|
|
|
|
|
|
return llvm::makeArrayRef(CommonPtr->InjectedArgs, Params->size());
|
2011-03-06 01:54:25 +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) {
|
2011-03-05 02:32:38 +08:00
|
|
|
AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
|
2010-06-20 03:29:09 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl));
|
|
|
|
return new (Mem) ClassTemplateDecl(EmptyShell());
|
2011-03-05 01:52:15 +08:00
|
|
|
}
|
|
|
|
|
2013-02-14 21:20:36 +08:00
|
|
|
void ClassTemplateDecl::LoadLazySpecializations() const {
|
2010-10-28 06:21:36 +08:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 07:49:05 +08:00
|
|
|
llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
|
2013-02-14 21:20:36 +08:00
|
|
|
ClassTemplateDecl::getSpecializations() const {
|
2010-10-28 06:21:36 +08:00
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->Specializations;
|
|
|
|
}
|
|
|
|
|
2012-05-04 07:49:05 +08:00
|
|
|
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
|
2010-10-28 06:21:36 +08:00
|
|
|
ClassTemplateDecl::getPartialSpecializations() {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->PartialSpecializations;
|
|
|
|
}
|
|
|
|
|
2010-09-09 03:31:22 +08:00
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
2013-01-24 00:52:57 +08:00
|
|
|
ClassTemplateDecl::newCommon(ASTContext &C) const {
|
2010-09-09 03:31:22 +08:00
|
|
|
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) {
|
2012-03-28 22:34:23 +08:00
|
|
|
if (InsertPos)
|
|
|
|
getSpecializations().InsertNode(D, InsertPos);
|
|
|
|
else {
|
|
|
|
ClassTemplateSpecializationDecl *Existing
|
|
|
|
= getSpecializations().GetOrInsertNode(D);
|
|
|
|
(void)Existing;
|
|
|
|
assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
|
|
|
|
}
|
2010-10-28 15:38:42 +08:00
|
|
|
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) {
|
2012-03-28 22:34:23 +08:00
|
|
|
if (InsertPos)
|
|
|
|
getPartialSpecializations().InsertNode(D, InsertPos);
|
|
|
|
else {
|
|
|
|
ClassTemplatePartialSpecializationDecl *Existing
|
|
|
|
= getPartialSpecializations().GetOrInsertNode(D);
|
|
|
|
(void)Existing;
|
|
|
|
assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
|
|
|
|
}
|
|
|
|
|
2010-10-28 15:38:42 +08:00
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, D);
|
|
|
|
}
|
|
|
|
|
2010-04-30 13:56:50 +08:00
|
|
|
void ClassTemplateDecl::getPartialSpecializations(
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
|
2012-05-04 07:49:05 +08:00
|
|
|
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &PartialSpecs
|
2010-06-21 18:57:41 +08:00
|
|
|
= getPartialSpecializations();
|
2010-04-30 13:56:50 +08:00
|
|
|
PS.clear();
|
2013-08-23 07:27:37 +08:00
|
|
|
PS.reserve(PartialSpecs.size());
|
2012-05-04 07:49:05 +08:00
|
|
|
for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
|
2010-04-30 13:56:50 +08:00
|
|
|
P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
|
2013-08-23 07:27:37 +08:00
|
|
|
P != PEnd; ++P)
|
|
|
|
PS.push_back(P->getMostRecentDecl());
|
2010-04-30 13:56:50 +08:00
|
|
|
}
|
|
|
|
|
2009-07-31 01:40:51 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findPartialSpecialization(QualType T) {
|
|
|
|
ASTContext &Context = getASTContext();
|
2012-05-04 07:49:05 +08:00
|
|
|
using llvm::FoldingSetVector;
|
|
|
|
typedef FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
|
2009-07-31 01:40:51 +08:00
|
|
|
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))
|
2012-01-15 00:38:05 +08:00
|
|
|
return P->getMostRecentDecl();
|
2010-07-20 21:59:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
|
|
|
|
ClassTemplatePartialSpecializationDecl *D) {
|
|
|
|
Decl *DCanon = D->getCanonicalDecl();
|
2012-05-04 07:49:05 +08:00
|
|
|
for (llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl>::iterator
|
2010-07-20 21:59:28 +08:00
|
|
|
P = getPartialSpecializations().begin(),
|
|
|
|
PEnd = getPartialSpecializations().end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
|
2012-01-15 00:38:05 +08:00
|
|
|
return P->getMostRecentDecl();
|
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;
|
|
|
|
|
2010-12-24 00:00:30 +08:00
|
|
|
// C++0x [temp.dep.type]p2:
|
|
|
|
// The template argument list of a primary template is a template argument
|
|
|
|
// list in which the nth template argument has the value of the nth template
|
|
|
|
// parameter of the class template. If the nth template parameter is a
|
|
|
|
// template parameter pack (14.5.3), the nth template argument is a pack
|
|
|
|
// expansion (14.5.3) whose pattern is the name of the template parameter
|
|
|
|
// pack.
|
2010-07-09 02:37:38 +08:00
|
|
|
ASTContext &Context = getASTContext();
|
2009-05-11 06:57:19 +08:00
|
|
|
TemplateParameterList *Params = getTemplateParameters();
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<TemplateArgument, 16> TemplateArgs;
|
2011-03-06 01:54:25 +08:00
|
|
|
TemplateArgs.resize(Params->size());
|
|
|
|
GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
|
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 *
|
2011-01-12 17:06:06 +08:00
|
|
|
TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
|
2011-03-06 23:48:19 +08:00
|
|
|
SourceLocation KeyLoc, SourceLocation NameLoc,
|
|
|
|
unsigned D, unsigned P, IdentifierInfo *Id,
|
|
|
|
bool Typename, bool ParameterPack) {
|
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
llvm-svn: 130628
2011-05-01 08:51:33 +08:00
|
|
|
TemplateTypeParmDecl *TTPDecl =
|
|
|
|
new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
|
|
|
|
QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
|
|
|
|
TTPDecl->TypeForDecl = TTPType.getTypePtr();
|
|
|
|
return TTPDecl;
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2010-07-02 19:54:55 +08:00
|
|
|
TemplateTypeParmDecl *
|
2012-01-06 05:55:30 +08:00
|
|
|
TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl));
|
|
|
|
return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
|
|
|
|
0, false);
|
2010-07-02 19:54:55 +08:00
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:44 +08:00
|
|
|
SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
|
2011-03-04 20:42:03 +08:00
|
|
|
return hasDefaultArgument()
|
|
|
|
? DefaultArgument->getTypeLoc().getBeginLoc()
|
|
|
|
: SourceLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange TemplateTypeParmDecl::getSourceRange() const {
|
|
|
|
if (hasDefaultArgument() && !defaultArgumentWasInherited())
|
2011-03-06 23:48:19 +08:00
|
|
|
return SourceRange(getLocStart(),
|
2011-03-04 20:42:03 +08:00
|
|
|
DefaultArgument->getTypeLoc().getEndLoc());
|
|
|
|
else
|
2011-03-06 23:48:19 +08:00
|
|
|
return TypeDecl::getSourceRange();
|
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();
|
|
|
|
}
|
|
|
|
|
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
llvm-svn: 130628
2011-05-01 08:51:33 +08:00
|
|
|
bool TemplateTypeParmDecl::isParameterPack() const {
|
|
|
|
return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack();
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NonTypeTemplateParmDecl Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
|
2011-03-08 16:55:46 +08:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc,
|
|
|
|
unsigned D, unsigned P,
|
|
|
|
IdentifierInfo *Id,
|
2011-01-20 04:10:05 +08:00
|
|
|
QualType T,
|
|
|
|
TypeSourceInfo *TInfo,
|
|
|
|
const QualType *ExpandedTypes,
|
|
|
|
unsigned NumExpandedTypes,
|
|
|
|
TypeSourceInfo **ExpandedTInfos)
|
2011-03-08 16:55:46 +08:00
|
|
|
: DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
|
2011-01-20 04:10:05 +08:00
|
|
|
TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false),
|
|
|
|
ParameterPack(true), ExpandedParameterPack(true),
|
|
|
|
NumExpandedTypes(NumExpandedTypes)
|
|
|
|
{
|
|
|
|
if (ExpandedTypes && ExpandedTInfos) {
|
|
|
|
void **TypesAndInfos = reinterpret_cast<void **>(this + 1);
|
|
|
|
for (unsigned I = 0; I != NumExpandedTypes; ++I) {
|
|
|
|
TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr();
|
|
|
|
TypesAndInfos[2*I + 1] = ExpandedTInfos[I];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
NonTypeTemplateParmDecl *
|
2011-01-12 17:06:06 +08:00
|
|
|
NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
|
2011-03-08 16:55:46 +08:00
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
unsigned D, unsigned P, IdentifierInfo *Id,
|
|
|
|
QualType T, bool ParameterPack,
|
|
|
|
TypeSourceInfo *TInfo) {
|
|
|
|
return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
|
|
|
|
T, ParameterPack, TInfo);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2011-01-20 04:10:05 +08:00
|
|
|
NonTypeTemplateParmDecl *
|
|
|
|
NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
|
2011-03-08 16:55:46 +08:00
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
unsigned D, unsigned P,
|
2011-01-20 04:10:05 +08:00
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
TypeSourceInfo *TInfo,
|
|
|
|
const QualType *ExpandedTypes,
|
|
|
|
unsigned NumExpandedTypes,
|
|
|
|
TypeSourceInfo **ExpandedTInfos) {
|
|
|
|
unsigned Size = sizeof(NonTypeTemplateParmDecl)
|
|
|
|
+ NumExpandedTypes * 2 * sizeof(void*);
|
|
|
|
void *Mem = C.Allocate(Size);
|
2011-03-08 16:55:46 +08:00
|
|
|
return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc,
|
|
|
|
D, P, Id, T, TInfo,
|
2011-01-20 04:10:05 +08:00
|
|
|
ExpandedTypes, NumExpandedTypes,
|
|
|
|
ExpandedTInfos);
|
|
|
|
}
|
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
NonTypeTemplateParmDecl *
|
|
|
|
NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl));
|
|
|
|
return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(),
|
|
|
|
SourceLocation(), 0, 0, 0,
|
|
|
|
QualType(), false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NonTypeTemplateParmDecl *
|
|
|
|
NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
|
|
|
|
unsigned NumExpandedTypes) {
|
|
|
|
unsigned Size = sizeof(NonTypeTemplateParmDecl)
|
|
|
|
+ NumExpandedTypes * 2 * sizeof(void*);
|
|
|
|
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, Size);
|
|
|
|
return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(),
|
|
|
|
SourceLocation(), 0, 0, 0,
|
|
|
|
QualType(), 0, 0, NumExpandedTypes,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2011-02-09 09:13:10 +08:00
|
|
|
SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
|
2011-03-04 19:03:48 +08:00
|
|
|
if (hasDefaultArgument() && !defaultArgumentWasInherited())
|
2011-03-09 00:41:52 +08:00
|
|
|
return SourceRange(getOuterLocStart(),
|
|
|
|
getDefaultArgument()->getSourceRange().getEnd());
|
|
|
|
return DeclaratorDecl::getSourceRange();
|
2011-02-09 09:13:10 +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
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void TemplateTemplateParmDecl::anchor() { }
|
|
|
|
|
2012-09-07 10:06:42 +08:00
|
|
|
TemplateTemplateParmDecl::TemplateTemplateParmDecl(
|
|
|
|
DeclContext *DC, SourceLocation L, unsigned D, unsigned P,
|
|
|
|
IdentifierInfo *Id, TemplateParameterList *Params,
|
|
|
|
unsigned NumExpansions, TemplateParameterList * const *Expansions)
|
|
|
|
: TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
|
|
|
|
TemplateParmPosition(D, P), DefaultArgument(),
|
|
|
|
DefaultArgumentWasInherited(false), ParameterPack(true),
|
|
|
|
ExpandedParameterPack(true), NumExpandedParams(NumExpansions) {
|
|
|
|
if (Expansions)
|
|
|
|
std::memcpy(reinterpret_cast<void*>(this + 1), Expansions,
|
|
|
|
sizeof(TemplateParameterList*) * NumExpandedParams);
|
|
|
|
}
|
|
|
|
|
2009-02-05 03:02:06 +08:00
|
|
|
TemplateTemplateParmDecl *
|
2011-01-12 17:06:06 +08:00
|
|
|
TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
|
2009-02-05 03:02:06 +08:00
|
|
|
SourceLocation L, unsigned D, unsigned P,
|
2011-01-05 23:48:55 +08:00
|
|
|
bool ParameterPack, IdentifierInfo *Id,
|
2009-02-05 03:02:06 +08:00
|
|
|
TemplateParameterList *Params) {
|
2011-01-05 23:48:55 +08:00
|
|
|
return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
|
|
|
|
Params);
|
2009-02-05 03:02:06 +08:00
|
|
|
}
|
|
|
|
|
2012-09-07 10:06:42 +08:00
|
|
|
TemplateTemplateParmDecl *
|
|
|
|
TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, unsigned D, unsigned P,
|
|
|
|
IdentifierInfo *Id,
|
|
|
|
TemplateParameterList *Params,
|
2013-01-13 03:30:44 +08:00
|
|
|
ArrayRef<TemplateParameterList *> Expansions) {
|
2012-09-07 10:06:42 +08:00
|
|
|
void *Mem = C.Allocate(sizeof(TemplateTemplateParmDecl) +
|
|
|
|
sizeof(TemplateParameterList*) * Expansions.size());
|
|
|
|
return new (Mem) TemplateTemplateParmDecl(DC, L, D, P, Id, Params,
|
|
|
|
Expansions.size(),
|
|
|
|
Expansions.data());
|
|
|
|
}
|
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
TemplateTemplateParmDecl *
|
|
|
|
TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl));
|
|
|
|
return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false,
|
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
|
2012-09-07 10:06:42 +08:00
|
|
|
TemplateTemplateParmDecl *
|
|
|
|
TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
|
|
|
|
unsigned NumExpansions) {
|
|
|
|
unsigned Size = sizeof(TemplateTemplateParmDecl) +
|
|
|
|
sizeof(TemplateParameterList*) * NumExpansions;
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, Size);
|
|
|
|
return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0,
|
|
|
|
NumExpansions, 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-23 04:07:09 +08:00
|
|
|
FunctionTemplateSpecializationInfo *
|
|
|
|
FunctionTemplateSpecializationInfo::Create(ASTContext &C, FunctionDecl *FD,
|
|
|
|
FunctionTemplateDecl *Template,
|
|
|
|
TemplateSpecializationKind TSK,
|
|
|
|
const TemplateArgumentList *TemplateArgs,
|
|
|
|
const TemplateArgumentListInfo *TemplateArgsAsWritten,
|
|
|
|
SourceLocation POI) {
|
|
|
|
const ASTTemplateArgumentListInfo *ArgsAsWritten = 0;
|
|
|
|
if (TemplateArgsAsWritten)
|
|
|
|
ArgsAsWritten = ASTTemplateArgumentListInfo::Create(C,
|
|
|
|
*TemplateArgsAsWritten);
|
|
|
|
|
|
|
|
return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
|
|
|
|
TemplateArgs,
|
|
|
|
ArgsAsWritten,
|
|
|
|
POI);
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void TemplateDecl::anchor() { }
|
|
|
|
|
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,
|
2011-03-09 22:09:51 +08:00
|
|
|
DeclContext *DC, SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc,
|
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)
|
2011-03-09 22:09:51 +08:00
|
|
|
: CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc,
|
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)
|
2011-03-09 22:09:51 +08:00
|
|
|
: CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0),
|
2010-06-23 21:48:23 +08:00
|
|
|
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,
|
2011-03-09 22:09:51 +08:00
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc,
|
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-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,
|
2011-03-09 22:09:51 +08:00
|
|
|
TK, DC, StartLoc, IdLoc,
|
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);
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
Result->MayHaveOutOfDateDef = false;
|
|
|
|
|
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 *
|
2012-01-06 05:55:30 +08:00
|
|
|
ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID,
|
|
|
|
sizeof(ClassTemplateSpecializationDecl));
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
ClassTemplateSpecializationDecl *Result =
|
|
|
|
new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
|
|
|
|
Result->MayHaveOutOfDateDef = false;
|
|
|
|
return Result;
|
2010-06-23 21:48:23 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 23:46:01 +08:00
|
|
|
void ClassTemplateSpecializationDecl::getNameForDiagnostic(
|
|
|
|
raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
|
|
|
|
NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
|
2011-02-20 02:51:44 +08:00
|
|
|
|
|
|
|
const TemplateArgumentList &TemplateArgs = getTemplateArgs();
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
|
2011-02-20 02:51:44 +08:00
|
|
|
}
|
|
|
|
|
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*>();
|
|
|
|
}
|
|
|
|
|
2011-03-04 22:20:30 +08:00
|
|
|
SourceRange
|
|
|
|
ClassTemplateSpecializationDecl::getSourceRange() const {
|
2011-10-04 04:34:03 +08:00
|
|
|
if (ExplicitInfo) {
|
2012-10-16 05:06:42 +08:00
|
|
|
SourceLocation Begin = getTemplateKeywordLoc();
|
|
|
|
if (Begin.isValid()) {
|
|
|
|
// Here we have an explicit (partial) specialization or instantiation.
|
|
|
|
assert(getSpecializationKind() == TSK_ExplicitSpecialization ||
|
|
|
|
getSpecializationKind() == TSK_ExplicitInstantiationDeclaration ||
|
|
|
|
getSpecializationKind() == TSK_ExplicitInstantiationDefinition);
|
|
|
|
if (getExternLoc().isValid())
|
|
|
|
Begin = getExternLoc();
|
|
|
|
SourceLocation End = getRBraceLoc();
|
|
|
|
if (End.isInvalid())
|
|
|
|
End = getTypeAsWritten()->getTypeLoc().getEndLoc();
|
|
|
|
return SourceRange(Begin, End);
|
|
|
|
}
|
|
|
|
// An implicit instantiation of a class template partial specialization
|
|
|
|
// uses ExplicitInfo to record the TypeAsWritten, but the source
|
|
|
|
// locations should be retrieved from the instantiation pattern.
|
|
|
|
typedef ClassTemplatePartialSpecializationDecl CTPSDecl;
|
|
|
|
CTPSDecl *ctpsd = const_cast<CTPSDecl*>(cast<CTPSDecl>(this));
|
|
|
|
CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember();
|
|
|
|
assert(inst_from != 0);
|
|
|
|
return inst_from->getSourceRange();
|
2011-10-04 04:34:03 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No explicit info available.
|
|
|
|
llvm::PointerUnion<ClassTemplateDecl *,
|
|
|
|
ClassTemplatePartialSpecializationDecl *>
|
|
|
|
inst_from = getInstantiatedFrom();
|
|
|
|
if (inst_from.isNull())
|
|
|
|
return getSpecializedTemplate()->getSourceRange();
|
|
|
|
if (ClassTemplateDecl *ctd = inst_from.dyn_cast<ClassTemplateDecl*>())
|
|
|
|
return ctd->getSourceRange();
|
|
|
|
return inst_from.get<ClassTemplatePartialSpecializationDecl*>()
|
|
|
|
->getSourceRange();
|
|
|
|
}
|
2011-03-04 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2009-05-31 17:31:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassTemplatePartialSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-12-20 10:48:34 +08:00
|
|
|
void ClassTemplatePartialSpecializationDecl::anchor() { }
|
|
|
|
|
2011-03-05 01:52:15 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl::
|
|
|
|
ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
|
2011-03-09 22:09:51 +08:00
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc,
|
2011-03-05 01:52:15 +08:00
|
|
|
TemplateParameterList *Params,
|
|
|
|
ClassTemplateDecl *SpecializedTemplate,
|
|
|
|
const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs,
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *ArgInfos,
|
2013-08-23 07:27:37 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *PrevDecl)
|
2011-03-05 01:52:15 +08:00
|
|
|
: ClassTemplateSpecializationDecl(Context,
|
|
|
|
ClassTemplatePartialSpecialization,
|
2011-03-09 22:09:51 +08:00
|
|
|
TK, DC, StartLoc, IdLoc,
|
|
|
|
SpecializedTemplate,
|
2011-03-05 01:52:15 +08:00
|
|
|
Args, NumArgs, PrevDecl),
|
|
|
|
TemplateParams(Params), ArgsAsWritten(ArgInfos),
|
2013-08-23 07:27:37 +08:00
|
|
|
InstantiatedFromMember(0, false)
|
2013-08-10 15:24:53 +08:00
|
|
|
{
|
2011-03-05 02:32:38 +08:00
|
|
|
AdoptTemplateParameterList(Params, this);
|
2011-03-05 01:52:15 +08:00
|
|
|
}
|
|
|
|
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *
|
|
|
|
ClassTemplatePartialSpecializationDecl::
|
2011-03-09 22:09:51 +08:00
|
|
|
Create(ASTContext &Context, TagKind TK,DeclContext *DC,
|
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
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,
|
2013-08-23 07:27:37 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *PrevDecl) {
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *ASTArgInfos =
|
|
|
|
ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
|
2009-10-29 16:12:44 +08:00
|
|
|
|
2009-05-31 17:31:02 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *Result
|
2011-03-09 22:09:51 +08:00
|
|
|
= new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC,
|
|
|
|
StartLoc, IdLoc,
|
|
|
|
Params,
|
2009-05-31 17:31:02 +08:00
|
|
|
SpecializedTemplate,
|
2010-11-08 07:05:16 +08:00
|
|
|
Args, NumArgs,
|
2013-08-10 15:24:53 +08:00
|
|
|
ASTArgInfos,
|
2013-08-23 07:27:37 +08:00
|
|
|
PrevDecl);
|
2009-05-31 17:31:02 +08:00
|
|
|
Result->setSpecializationKind(TSK_ExplicitSpecialization);
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
Result->MayHaveOutOfDateDef = false;
|
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 *
|
2012-01-06 05:55:30 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID,
|
|
|
|
sizeof(ClassTemplatePartialSpecializationDecl));
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
ClassTemplatePartialSpecializationDecl *Result
|
|
|
|
= new (Mem) ClassTemplatePartialSpecializationDecl();
|
|
|
|
Result->MayHaveOutOfDateDef = false;
|
|
|
|
return Result;
|
2010-06-23 21:48:23 +08:00
|
|
|
}
|
|
|
|
|
2009-09-17 06:47:08 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FriendTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void FriendTemplateDecl::anchor() { }
|
|
|
|
|
2009-09-17 06:47:08 +08:00
|
|
|
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
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl));
|
|
|
|
return new (Mem) FriendTemplateDecl(EmptyShell());
|
2010-07-23 00:04:10 +08:00
|
|
|
}
|
2011-05-06 05:57:07 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TypeAliasTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
|
|
|
|
DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
DeclarationName Name,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
NamedDecl *Decl) {
|
|
|
|
AdoptTemplateParameterList(Params, DC);
|
|
|
|
return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
|
|
|
|
}
|
|
|
|
|
2012-01-06 05:55:30 +08:00
|
|
|
TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl));
|
|
|
|
return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
|
|
|
|
0, 0);
|
2011-05-06 05:57:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
|
|
|
|
static_cast<Common *>(Ptr)->~Common();
|
|
|
|
}
|
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
2013-01-24 00:52:57 +08:00
|
|
|
TypeAliasTemplateDecl::newCommon(ASTContext &C) const {
|
2011-05-06 05:57:07 +08:00
|
|
|
Common *CommonPtr = new (C) Common;
|
|
|
|
C.AddDeallocation(DeallocateCommon, CommonPtr);
|
|
|
|
return CommonPtr;
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassScopeFunctionSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ClassScopeFunctionSpecializationDecl::anchor() { }
|
2012-01-06 05:55:30 +08:00
|
|
|
|
|
|
|
ClassScopeFunctionSpecializationDecl *
|
|
|
|
ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID,
|
|
|
|
sizeof(ClassScopeFunctionSpecializationDecl));
|
2012-06-26 01:21:05 +08:00
|
|
|
return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0,
|
|
|
|
false, TemplateArgumentListInfo());
|
2012-01-06 05:55:30 +08:00
|
|
|
}
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VarTemplateDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void VarTemplateDecl::DeallocateCommon(void *Ptr) {
|
|
|
|
static_cast<Common *>(Ptr)->~Common();
|
|
|
|
}
|
|
|
|
|
2013-08-13 10:02:26 +08:00
|
|
|
VarTemplateDecl *VarTemplateDecl::getDefinition() {
|
|
|
|
VarTemplateDecl *CurD = this;
|
|
|
|
while (CurD) {
|
|
|
|
if (CurD->isThisDeclarationADefinition())
|
|
|
|
return CurD;
|
|
|
|
CurD = CurD->getPreviousDecl();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-06 09:03:05 +08:00
|
|
|
VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L, DeclarationName Name,
|
|
|
|
TemplateParameterList *Params,
|
|
|
|
NamedDecl *Decl,
|
|
|
|
VarTemplateDecl *PrevDecl) {
|
|
|
|
VarTemplateDecl *New = new (C) VarTemplateDecl(DC, L, Name, Params, Decl);
|
|
|
|
New->setPreviousDeclaration(PrevDecl);
|
|
|
|
return New;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(C, ID, sizeof(VarTemplateDecl));
|
|
|
|
return new (Mem) VarTemplateDecl(EmptyShell());
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Should this be unified accross class, function and variable
|
|
|
|
// templates? Perhaps also moved to RedeclarableTemplateDecl?
|
|
|
|
void VarTemplateDecl::LoadLazySpecializations() const {
|
|
|
|
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::FoldingSetVector<VarTemplateSpecializationDecl> &
|
|
|
|
VarTemplateDecl::getSpecializations() const {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->Specializations;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
|
|
|
|
VarTemplateDecl::getPartialSpecializations() {
|
|
|
|
LoadLazySpecializations();
|
|
|
|
return getCommonPtr()->PartialSpecializations;
|
|
|
|
}
|
|
|
|
|
|
|
|
RedeclarableTemplateDecl::CommonBase *
|
|
|
|
VarTemplateDecl::newCommon(ASTContext &C) const {
|
|
|
|
Common *CommonPtr = new (C) Common;
|
|
|
|
C.AddDeallocation(DeallocateCommon, CommonPtr);
|
|
|
|
return CommonPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplateSpecializationDecl *
|
|
|
|
VarTemplateDecl::findSpecialization(const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs, void *&InsertPos) {
|
|
|
|
return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D,
|
|
|
|
void *InsertPos) {
|
|
|
|
if (InsertPos)
|
|
|
|
getSpecializations().InsertNode(D, InsertPos);
|
|
|
|
else {
|
|
|
|
VarTemplateSpecializationDecl *Existing =
|
|
|
|
getSpecializations().GetOrInsertNode(D);
|
|
|
|
(void)Existing;
|
|
|
|
assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
|
|
|
|
}
|
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl *
|
|
|
|
VarTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs, void *&InsertPos) {
|
|
|
|
return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
|
|
|
|
InsertPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarTemplateDecl::AddPartialSpecialization(
|
|
|
|
VarTemplatePartialSpecializationDecl *D, void *InsertPos) {
|
|
|
|
if (InsertPos)
|
|
|
|
getPartialSpecializations().InsertNode(D, InsertPos);
|
|
|
|
else {
|
|
|
|
VarTemplatePartialSpecializationDecl *Existing =
|
|
|
|
getPartialSpecializations().GetOrInsertNode(D);
|
|
|
|
(void)Existing;
|
|
|
|
assert(Existing->isCanonicalDecl() && "Non-canonical specialization?");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->AddedCXXTemplateSpecialization(this, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarTemplateDecl::getPartialSpecializations(
|
|
|
|
SmallVectorImpl<VarTemplatePartialSpecializationDecl *> &PS) {
|
|
|
|
llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &PartialSpecs =
|
|
|
|
getPartialSpecializations();
|
|
|
|
PS.clear();
|
2013-08-23 07:27:37 +08:00
|
|
|
PS.reserve(PartialSpecs.size());
|
2013-08-06 09:03:05 +08:00
|
|
|
for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
|
|
|
|
P = PartialSpecs.begin(),
|
|
|
|
PEnd = PartialSpecs.end();
|
2013-08-23 07:27:37 +08:00
|
|
|
P != PEnd; ++P)
|
|
|
|
PS.push_back(P->getMostRecentDecl());
|
2013-08-06 09:03:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl *
|
|
|
|
VarTemplateDecl::findPartialSpecInstantiatedFromMember(
|
|
|
|
VarTemplatePartialSpecializationDecl *D) {
|
|
|
|
Decl *DCanon = D->getCanonicalDecl();
|
|
|
|
for (llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl>::iterator
|
|
|
|
P = getPartialSpecializations().begin(),
|
|
|
|
PEnd = getPartialSpecializations().end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
|
|
|
|
return P->getMostRecentDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VarTemplateSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(
|
|
|
|
ASTContext &Context, Kind DK, DeclContext *DC, SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
|
|
|
|
TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs)
|
|
|
|
: VarDecl(DK, DC, StartLoc, IdLoc, SpecializedTemplate->getIdentifier(), T,
|
|
|
|
TInfo, S),
|
|
|
|
SpecializedTemplate(SpecializedTemplate), ExplicitInfo(0),
|
|
|
|
TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
|
|
|
|
SpecializationKind(TSK_Undeclared) {}
|
|
|
|
|
|
|
|
VarTemplateSpecializationDecl::VarTemplateSpecializationDecl(Kind DK)
|
|
|
|
: VarDecl(DK, 0, SourceLocation(), SourceLocation(), 0, QualType(), 0,
|
|
|
|
SC_None),
|
|
|
|
ExplicitInfo(0), SpecializationKind(TSK_Undeclared) {}
|
|
|
|
|
|
|
|
VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create(
|
|
|
|
ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
|
|
|
|
TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
|
|
|
|
unsigned NumArgs) {
|
|
|
|
VarTemplateSpecializationDecl *Result = new (Context)
|
|
|
|
VarTemplateSpecializationDecl(Context, VarTemplateSpecialization, DC,
|
|
|
|
StartLoc, IdLoc, SpecializedTemplate, T,
|
|
|
|
TInfo, S, Args, NumArgs);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplateSpecializationDecl *
|
|
|
|
VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
|
|
|
|
void *Mem =
|
|
|
|
AllocateDeserializedDecl(C, ID, sizeof(VarTemplateSpecializationDecl));
|
|
|
|
VarTemplateSpecializationDecl *Result =
|
|
|
|
new (Mem) VarTemplateSpecializationDecl(VarTemplateSpecialization);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarTemplateSpecializationDecl::getNameForDiagnostic(
|
|
|
|
raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const {
|
|
|
|
NamedDecl::getNameForDiagnostic(OS, Policy, Qualified);
|
|
|
|
|
|
|
|
const TemplateArgumentList &TemplateArgs = getTemplateArgs();
|
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, TemplateArgs.data(), TemplateArgs.size(), Policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const {
|
|
|
|
if (SpecializedPartialSpecialization *PartialSpec =
|
|
|
|
SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization *>())
|
|
|
|
return PartialSpec->PartialSpecialization->getSpecializedTemplate();
|
|
|
|
return SpecializedTemplate.get<VarTemplateDecl *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarTemplateSpecializationDecl::setTemplateArgsInfo(
|
|
|
|
const TemplateArgumentListInfo &ArgsInfo) {
|
|
|
|
unsigned N = ArgsInfo.size();
|
|
|
|
TemplateArgsInfo.setLAngleLoc(ArgsInfo.getLAngleLoc());
|
|
|
|
TemplateArgsInfo.setRAngleLoc(ArgsInfo.getRAngleLoc());
|
|
|
|
for (unsigned I = 0; I != N; ++I)
|
|
|
|
TemplateArgsInfo.addArgument(ArgsInfo[I]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VarTemplatePartialSpecializationDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void VarTemplatePartialSpecializationDecl::anchor() {}
|
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl::VarTemplatePartialSpecializationDecl(
|
|
|
|
ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, TemplateParameterList *Params,
|
|
|
|
VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
|
|
|
|
StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
|
2013-08-23 07:27:37 +08:00
|
|
|
const ASTTemplateArgumentListInfo *ArgInfos)
|
2013-08-06 09:03:05 +08:00
|
|
|
: VarTemplateSpecializationDecl(Context, VarTemplatePartialSpecialization,
|
|
|
|
DC, StartLoc, IdLoc, SpecializedTemplate, T,
|
|
|
|
TInfo, S, Args, NumArgs),
|
|
|
|
TemplateParams(Params), ArgsAsWritten(ArgInfos),
|
2013-08-23 07:27:37 +08:00
|
|
|
InstantiatedFromMember(0, false) {
|
2013-08-06 09:03:05 +08:00
|
|
|
// TODO: The template parameters should be in DC by now. Verify.
|
|
|
|
// AdoptTemplateParameterList(Params, DC);
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl *
|
|
|
|
VarTemplatePartialSpecializationDecl::Create(
|
|
|
|
ASTContext &Context, DeclContext *DC, SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, TemplateParameterList *Params,
|
|
|
|
VarTemplateDecl *SpecializedTemplate, QualType T, TypeSourceInfo *TInfo,
|
|
|
|
StorageClass S, const TemplateArgument *Args, unsigned NumArgs,
|
2013-08-23 07:27:37 +08:00
|
|
|
const TemplateArgumentListInfo &ArgInfos) {
|
2013-08-10 15:24:53 +08:00
|
|
|
const ASTTemplateArgumentListInfo *ASTArgInfos
|
|
|
|
= ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
|
2013-08-06 09:03:05 +08:00
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl *Result =
|
|
|
|
new (Context) VarTemplatePartialSpecializationDecl(
|
|
|
|
Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
|
2013-08-23 07:27:37 +08:00
|
|
|
S, Args, NumArgs, ASTArgInfos);
|
2013-08-06 09:03:05 +08:00
|
|
|
Result->setSpecializationKind(TSK_ExplicitSpecialization);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarTemplatePartialSpecializationDecl *
|
|
|
|
VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
|
|
|
|
unsigned ID) {
|
|
|
|
void *Mem = AllocateDeserializedDecl(
|
|
|
|
C, ID, sizeof(VarTemplatePartialSpecializationDecl));
|
|
|
|
VarTemplatePartialSpecializationDecl *Result =
|
|
|
|
new (Mem) VarTemplatePartialSpecializationDecl();
|
|
|
|
return Result;
|
|
|
|
}
|