Added inherited info to template and non-type arguments of templates.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105716 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Abramo Bagnara 2010-06-09 09:26:05 +00:00
Родитель dfc35e3317
Коммит d92f7a297c
4 изменённых файлов: 72 добавлений и 28 удалений

Просмотреть файл

@ -734,15 +734,16 @@ public:
/// @endcode
class NonTypeTemplateParmDecl
: public VarDecl, protected TemplateParmPosition {
/// \brief The default template argument, if any.
Expr *DefaultArgument;
/// \brief The default template argument, if any, and whether or not
/// it was inherited.
llvm::PointerIntPair<Expr*, 1, bool> DefaultArgumentAndInherited;
NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D,
unsigned P, IdentifierInfo *Id, QualType T,
TypeSourceInfo *TInfo)
: VarDecl(NonTypeTemplateParm, DC, L, Id, T, TInfo, VarDecl::None,
VarDecl::None),
TemplateParmPosition(D, P), DefaultArgument(0)
TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false)
{ }
public:
@ -756,17 +757,36 @@ public:
/// \brief Determine whether this template parameter has a default
/// argument.
bool hasDefaultArgument() const { return DefaultArgument; }
bool hasDefaultArgument() const {
return DefaultArgumentAndInherited.getPointer() != 0;
}
/// \brief Retrieve the default argument, if any.
Expr *getDefaultArgument() const { return DefaultArgument; }
Expr *getDefaultArgument() const {
return DefaultArgumentAndInherited.getPointer();
}
/// \brief Retrieve the location of the default argument, if any.
SourceLocation getDefaultArgumentLoc() const;
/// \brief Set the default argument for this template parameter.
void setDefaultArgument(Expr *DefArg) {
DefaultArgument = DefArg;
/// \brief Determines whether the default argument was inherited
/// from a previous declaration of this template.
bool defaultArgumentWasInherited() const {
return DefaultArgumentAndInherited.getInt();
}
/// \brief Set the default argument for this template parameter, and
/// whether that default argument was inherited from another
/// declaration.
void setDefaultArgument(Expr *DefArg, bool Inherited) {
DefaultArgumentAndInherited.setPointer(DefArg);
DefaultArgumentAndInherited.setInt(Inherited);
}
/// \brief Removes the default argument of this template parameter.
void removeDefaultArgument() {
DefaultArgumentAndInherited.setPointer(0);
DefaultArgumentAndInherited.setInt(false);
}
// Implement isa/cast/dyncast/etc.
@ -785,14 +805,17 @@ public:
class TemplateTemplateParmDecl
: public TemplateDecl, protected TemplateParmPosition {
/// \brief The default template argument, if any.
/// DefaultArgument - The default template argument, if any.
TemplateArgumentLoc DefaultArgument;
/// Whether or not the default argument was inherited.
bool DefaultArgumentWasInherited;
TemplateTemplateParmDecl(DeclContext *DC, SourceLocation L,
unsigned D, unsigned P,
IdentifierInfo *Id, TemplateParameterList *Params)
: TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
TemplateParmPosition(D, P), DefaultArgument()
TemplateParmPosition(D, P), DefaultArgument(),
DefaultArgumentWasInherited(false)
{ }
public:
@ -807,18 +830,36 @@ public:
/// \brief Determine whether this template parameter has a default
/// argument.
bool hasDefaultArgument() const {
return !DefaultArgument.getArgument().isNull();
bool hasDefaultArgument() const {
return !DefaultArgument.getArgument().isNull();
}
/// \brief Retrieve the default argument, if any.
const TemplateArgumentLoc &getDefaultArgument() const {
return DefaultArgument;
const TemplateArgumentLoc &getDefaultArgument() const {
return DefaultArgument;
}
/// \brief Set the default argument for this template parameter.
void setDefaultArgument(const TemplateArgumentLoc &DefArg) {
/// \brief Retrieve the location of the default argument, if any.
SourceLocation getDefaultArgumentLoc() const;
/// \brief Determines whether the default argument was inherited
/// from a previous declaration of this template.
bool defaultArgumentWasInherited() const {
return DefaultArgumentWasInherited;
}
/// \brief Set the default argument for this template parameter, and
/// whether that default argument was inherited from another
/// declaration.
void setDefaultArgument(const TemplateArgumentLoc &DefArg, bool Inherited) {
DefaultArgument = DefArg;
DefaultArgumentWasInherited = Inherited;
}
/// \brief Removes the default argument of this template parameter.
void removeDefaultArgument() {
DefaultArgument = TemplateArgumentLoc();
DefaultArgumentWasInherited = false;
}
// Implement isa/cast/dyncast/etc.

Просмотреть файл

@ -294,8 +294,9 @@ NonTypeTemplateParmDecl::Create(ASTContext &C, DeclContext *DC,
}
SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
return DefaultArgument? DefaultArgument->getSourceRange().getBegin()
: SourceLocation();
return hasDefaultArgument()
? getDefaultArgument()->getSourceRange().getBegin()
: SourceLocation();
}
//===----------------------------------------------------------------------===//

Просмотреть файл

@ -646,7 +646,7 @@ void Sema::ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParamD,
return;
}
TemplateParm->setDefaultArgument(DefaultE.takeAs<Expr>());
TemplateParm->setDefaultArgument(DefaultE.takeAs<Expr>(), false);
}
@ -715,7 +715,7 @@ void Sema::ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParamD,
return;
}
TemplateParm->setDefaultArgument(DefaultArg);
TemplateParm->setDefaultArgument(DefaultArg, false);
}
/// ActOnTemplateParameterList - Builds a TemplateParameterList that
@ -1145,7 +1145,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
NewNonTypeParm->getLocation(),
NewNonTypeParm->getDefaultArgument()->getSourceRange())) {
NewNonTypeParm->getDefaultArgument()->Destroy(Context);
NewNonTypeParm->setDefaultArgument(0);
NewNonTypeParm->removeDefaultArgument();
}
// Merge default arguments for non-type template parameters
@ -1166,7 +1166,8 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// expression that points to a previous template template
// parameter.
NewNonTypeParm->setDefaultArgument(
OldNonTypeParm->getDefaultArgument());
OldNonTypeParm->getDefaultArgument(),
/*Inherited=*/ true);
PreviousDefaultArgLoc = OldNonTypeParm->getDefaultArgumentLoc();
} else if (NewNonTypeParm->hasDefaultArgument()) {
SawDefaultArgument = true;
@ -1181,7 +1182,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
DiagnoseDefaultTemplateArgument(*this, TPC,
NewTemplateParm->getLocation(),
NewTemplateParm->getDefaultArgument().getSourceRange()))
NewTemplateParm->setDefaultArgument(TemplateArgumentLoc());
NewTemplateParm->removeDefaultArgument();
// Merge default arguments for template template parameters
TemplateTemplateParmDecl *OldTemplateParm
@ -1200,7 +1201,8 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams,
// FIXME: We need to create a new kind of "default argument" expression
// that points to a previous template template parameter.
NewTemplateParm->setDefaultArgument(
OldTemplateParm->getDefaultArgument());
OldTemplateParm->getDefaultArgument(),
/*Inherited=*/ true);
PreviousDefaultArgLoc
= OldTemplateParm->getDefaultArgument().getLocation();
} else if (NewTemplateParm->hasDefaultArgument()) {
@ -3684,7 +3686,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
Diag(NTTP->getDefaultArgumentLoc(),
diag::err_default_arg_in_partial_spec)
<< DefArg->getSourceRange();
NTTP->setDefaultArgument(0);
NTTP->removeDefaultArgument();
DefArg->Destroy(Context);
}
} else {
@ -3693,7 +3695,7 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec,
Diag(TTP->getDefaultArgument().getLocation(),
diag::err_default_arg_in_partial_spec)
<< TTP->getDefaultArgument().getSourceRange();
TTP->setDefaultArgument(TemplateArgumentLoc());
TTP->removeDefaultArgument();
}
}
}

Просмотреть файл

@ -1495,7 +1495,7 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(
if (Invalid)
Param->setInvalidDecl();
Param->setDefaultArgument(D->getDefaultArgument());
Param->setDefaultArgument(D->getDefaultArgument(), false);
// Introduce this template parameter's instantiation into the instantiation
// scope.
@ -1523,7 +1523,7 @@ TemplateDeclInstantiator::VisitTemplateTemplateParmDecl(
= TemplateTemplateParmDecl::Create(SemaRef.Context, Owner, D->getLocation(),
D->getDepth() - 1, D->getPosition(),
D->getIdentifier(), InstParams);
Param->setDefaultArgument(D->getDefaultArgument());
Param->setDefaultArgument(D->getDefaultArgument(), false);
// Introduce this template parameter's instantiation into the instantiation
// scope.