[NFC] Update the template-parameter parsers and analyzers to return NamedDecl (vs Decl)

This patch addresses a FIXME and has the template-parameter processing functions return a more derived common type NamedDecl (as opposed to a type needlessly higher up in the inheritance hierarchy : Decl).  

llvm-svn: 321409
This commit is contained in:
Faisal Vali 2017-12-23 18:56:34 +00:00
parent 06dad14797
commit be29403633
4 changed files with 16 additions and 16 deletions

View File

@ -2748,10 +2748,10 @@ private:
bool ParseTemplateParameterList(unsigned Depth, bool ParseTemplateParameterList(unsigned Depth,
SmallVectorImpl<NamedDecl*> &TemplateParams); SmallVectorImpl<NamedDecl*> &TemplateParams);
bool isStartOfTemplateTypeParameter(); bool isStartOfTemplateTypeParameter();
Decl *ParseTemplateParameter(unsigned Depth, unsigned Position); NamedDecl *ParseTemplateParameter(unsigned Depth, unsigned Position);
Decl *ParseTypeParameter(unsigned Depth, unsigned Position); NamedDecl *ParseTypeParameter(unsigned Depth, unsigned Position);
Decl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position); NamedDecl *ParseTemplateTemplateParameter(unsigned Depth, unsigned Position);
Decl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position); NamedDecl *ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position);
void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc, void DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
SourceLocation CorrectLoc, SourceLocation CorrectLoc,
bool AlreadyHasEllipsis, bool AlreadyHasEllipsis,

View File

@ -6064,7 +6064,7 @@ public:
void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
Decl *ActOnTypeParameter(Scope *S, bool Typename, NamedDecl *ActOnTypeParameter(Scope *S, bool Typename,
SourceLocation EllipsisLoc, SourceLocation EllipsisLoc,
SourceLocation KeyLoc, SourceLocation KeyLoc,
IdentifierInfo *ParamName, IdentifierInfo *ParamName,
@ -6077,12 +6077,12 @@ public:
SourceLocation Loc); SourceLocation Loc);
QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Decl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
unsigned Depth, unsigned Depth,
unsigned Position, unsigned Position,
SourceLocation EqualLoc, SourceLocation EqualLoc,
Expr *DefaultArg); Expr *DefaultArg);
Decl *ActOnTemplateTemplateParameter(Scope *S, NamedDecl *ActOnTemplateTemplateParameter(Scope *S,
SourceLocation TmpLoc, SourceLocation TmpLoc,
TemplateParameterList *Params, TemplateParameterList *Params,
SourceLocation EllipsisLoc, SourceLocation EllipsisLoc,

View File

@ -372,8 +372,8 @@ bool
Parser::ParseTemplateParameterList(unsigned Depth, Parser::ParseTemplateParameterList(unsigned Depth,
SmallVectorImpl<NamedDecl*> &TemplateParams) { SmallVectorImpl<NamedDecl*> &TemplateParams) {
while (1) { while (1) {
// FIXME: ParseTemplateParameter should probably just return a NamedDecl.
if (Decl *TmpParam if (NamedDecl *TmpParam
= ParseTemplateParameter(Depth, TemplateParams.size())) { = ParseTemplateParameter(Depth, TemplateParams.size())) {
TemplateParams.push_back(dyn_cast<NamedDecl>(TmpParam)); TemplateParams.push_back(dyn_cast<NamedDecl>(TmpParam));
} else { } else {
@ -480,7 +480,7 @@ bool Parser::isStartOfTemplateTypeParameter() {
/// 'class' ...[opt] identifier[opt] /// 'class' ...[opt] identifier[opt]
/// 'template' '<' template-parameter-list '>' 'class' identifier[opt] /// 'template' '<' template-parameter-list '>' 'class' identifier[opt]
/// = id-expression /// = id-expression
Decl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) { NamedDecl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
if (isStartOfTemplateTypeParameter()) if (isStartOfTemplateTypeParameter())
return ParseTypeParameter(Depth, Position); return ParseTypeParameter(Depth, Position);
@ -502,7 +502,7 @@ Decl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
/// 'class' identifier[opt] '=' type-id /// 'class' identifier[opt] '=' type-id
/// 'typename' ...[opt][C++0x] identifier[opt] /// 'typename' ...[opt][C++0x] identifier[opt]
/// 'typename' identifier[opt] '=' type-id /// 'typename' identifier[opt] '=' type-id
Decl *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) { NamedDecl *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) {
assert(Tok.isOneOf(tok::kw_class, tok::kw_typename) && assert(Tok.isOneOf(tok::kw_class, tok::kw_typename) &&
"A type-parameter starts with 'class' or 'typename'"); "A type-parameter starts with 'class' or 'typename'");
@ -564,7 +564,7 @@ Decl *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) {
/// type-parameter-key: /// type-parameter-key:
/// 'class' /// 'class'
/// 'typename' [C++1z] /// 'typename' [C++1z]
Decl * NamedDecl *
Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) { Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
assert(Tok.is(tok::kw_template) && "Expected 'template' keyword"); assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
@ -669,7 +669,7 @@ Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
/// template-parameter: /// template-parameter:
/// ... /// ...
/// parameter-declaration /// parameter-declaration
Decl * NamedDecl *
Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) { Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
// Parse the declaration-specifiers (i.e., the type). // Parse the declaration-specifiers (i.e., the type).
// FIXME: The type should probably be restricted in some way... Not all // FIXME: The type should probably be restricted in some way... Not all

View File

@ -792,7 +792,7 @@ static void maybeDiagnoseTemplateParameterShadow(Sema &SemaRef, Scope *S,
/// ParamNameLoc is the location of the parameter name (if any). /// ParamNameLoc is the location of the parameter name (if any).
/// If the type parameter has a default argument, it will be added /// If the type parameter has a default argument, it will be added
/// later via ActOnTypeParameterDefault. /// later via ActOnTypeParameterDefault.
Decl *Sema::ActOnTypeParameter(Scope *S, bool Typename, NamedDecl *Sema::ActOnTypeParameter(Scope *S, bool Typename,
SourceLocation EllipsisLoc, SourceLocation EllipsisLoc,
SourceLocation KeyLoc, SourceLocation KeyLoc,
IdentifierInfo *ParamName, IdentifierInfo *ParamName,
@ -922,7 +922,7 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType T,
return QualType(); return QualType();
} }
Decl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
unsigned Depth, unsigned Depth,
unsigned Position, unsigned Position,
SourceLocation EqualLoc, SourceLocation EqualLoc,
@ -1053,7 +1053,7 @@ Decl *Sema::ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
/// ActOnTemplateTemplateParameter - Called when a C++ template template /// ActOnTemplateTemplateParameter - Called when a C++ template template
/// parameter (e.g. T in template <template \<typename> class T> class array) /// parameter (e.g. T in template <template \<typename> class T> class array)
/// has been parsed. S is the current scope. /// has been parsed. S is the current scope.
Decl *Sema::ActOnTemplateTemplateParameter(Scope* S, NamedDecl *Sema::ActOnTemplateTemplateParameter(Scope* S,
SourceLocation TmpLoc, SourceLocation TmpLoc,
TemplateParameterList *Params, TemplateParameterList *Params,
SourceLocation EllipsisLoc, SourceLocation EllipsisLoc,