[clang] d3d5a30 - [clang][NFC] Remove `const_cast` from `ParseClassSpecifier`
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri May 17 06:41:27 PDT 2024
Author: Vlad Serebrennikov
Date: 2024-05-17T16:41:20+03:00
New Revision: d3d5a30021b8df26ac4b2b01e659ab8487fb4080
URL: https://github.com/llvm/llvm-project/commit/d3d5a30021b8df26ac4b2b01e659ab8487fb4080
DIFF: https://github.com/llvm/llvm-project/commit/d3d5a30021b8df26ac4b2b01e659ab8487fb4080.diff
LOG: [clang][NFC] Remove `const_cast` from `ParseClassSpecifier`
Added:
Modified:
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/Parser.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 7a8c2bcde804e..c7d75985ce8bb 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2480,24 +2480,23 @@ class Parser : public CodeCompletionHandler {
bool trySkippingFunctionBody();
bool ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
- const ParsedTemplateInfo &TemplateInfo,
- AccessSpecifier AS, DeclSpecContext DSC,
- ParsedAttributes &Attrs);
+ ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS,
+ DeclSpecContext DSC, ParsedAttributes &Attrs);
DeclSpecContext
getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context);
- void ParseDeclarationSpecifiers(
- DeclSpec &DS,
- const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
- AccessSpecifier AS = AS_none,
- DeclSpecContext DSC = DeclSpecContext::DSC_normal,
- LateParsedAttrList *LateAttrs = nullptr) {
+ void
+ ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
+ AccessSpecifier AS = AS_none,
+ DeclSpecContext DSC = DeclSpecContext::DSC_normal,
+ LateParsedAttrList *LateAttrs = nullptr) {
return ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, LateAttrs,
getImplicitTypenameContext(DSC));
}
- void ParseDeclarationSpecifiers(
- DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS,
- DeclSpecContext DSC, LateParsedAttrList *LateAttrs,
- ImplicitTypenameContext AllowImplicitTypename);
+ void
+ ParseDeclarationSpecifiers(DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
+ AccessSpecifier AS, DeclSpecContext DSC,
+ LateParsedAttrList *LateAttrs,
+ ImplicitTypenameContext AllowImplicitTypename);
SourceLocation ParsePackIndexingType(DeclSpec &DS);
void AnnotateExistingIndexedTypeNamePack(ParsedType T,
@@ -3308,7 +3307,7 @@ class Parser : public CodeCompletionHandler {
// C++ 9: classes [class] and C structs/unions.
bool isValidAfterTypeSpecifier(bool CouldBeBitfield);
void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc,
- DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo,
+ DeclSpec &DS, ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS, bool EnteringContext,
DeclSpecContext DSC, ParsedAttributes &Attributes);
void SkipCXXMemberSpecification(SourceLocation StartLoc,
@@ -3330,7 +3329,7 @@ class Parser : public CodeCompletionHandler {
VirtSpecifiers &VS);
DeclGroupPtrTy ParseCXXClassMemberDeclaration(
AccessSpecifier AS, ParsedAttributes &Attr,
- const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo(),
+ ParsedTemplateInfo &TemplateInfo,
ParsingDeclRAIIObject *DiagsFromTParams = nullptr);
DeclGroupPtrTy
ParseCXXClassMemberDeclarationWithPragmas(AccessSpecifier &AS,
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 6d026878d3276..179564ae41a39 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2845,10 +2845,11 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
void Parser::ParseSpecifierQualifierList(
DeclSpec &DS, ImplicitTypenameContext AllowImplicitTypename,
AccessSpecifier AS, DeclSpecContext DSC) {
+ ParsedTemplateInfo TemplateInfo;
/// specifier-qualifier-list is a subset of declaration-specifiers. Just
/// parse declaration-specifiers and complain about extra stuff.
/// TODO: diagnose attribute-specifiers and alignment-specifiers.
- ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC, nullptr,
+ ParseDeclarationSpecifiers(DS, TemplateInfo, AS, DSC, nullptr,
AllowImplicitTypename);
// Validate declspec for type-name.
@@ -2927,7 +2928,7 @@ static bool isValidAfterIdentifierInDeclarator(const Token &T) {
/// other pieces of declspec after it, it returns true.
///
bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
- const ParsedTemplateInfo &TemplateInfo,
+ ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS, DeclSpecContext DSC,
ParsedAttributes &Attrs) {
assert(Tok.is(tok::identifier) && "should have identifier");
@@ -3489,7 +3490,7 @@ Parser::DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS,
/// 'friend': [C++ dcl.friend]
/// 'constexpr': [C++0x dcl.constexpr]
void Parser::ParseDeclarationSpecifiers(
- DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS,
+ DeclSpec &DS, ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS,
DeclSpecContext DSContext, LateParsedAttrList *LateAttrs,
ImplicitTypenameContext AllowImplicitTypename) {
if (DS.getSourceRange().isInvalid()) {
@@ -7736,8 +7737,9 @@ void Parser::ParseParameterDeclarationClause(
Diag(ThisLoc, diag::err_requires_expr_explicit_object_parameter);
}
- ParseDeclarationSpecifiers(DS, /*TemplateInfo=*/ParsedTemplateInfo(),
- AS_none, DeclSpecContext::DSC_normal,
+ ParsedTemplateInfo TemplateInfo;
+ ParseDeclarationSpecifiers(DS, TemplateInfo, AS_none,
+ DeclSpecContext::DSC_normal,
/*LateAttrs=*/nullptr, AllowImplicitTypename);
DS.takeAttributesFrom(ArgDeclSpecAttrs);
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 32c4e923243a9..3caad5c75d7df 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1661,7 +1661,7 @@ bool Parser::isValidAfterTypeSpecifier(bool CouldBeBitfield) {
/// 'union'
void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
SourceLocation StartLoc, DeclSpec &DS,
- const ParsedTemplateInfo &TemplateInfo,
+ ParsedTemplateInfo &TemplateInfo,
AccessSpecifier AS, bool EnteringContext,
DeclSpecContext DSC,
ParsedAttributes &Attributes) {
@@ -1861,18 +1861,14 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
TemplateParams->pop_back();
} else {
TemplateParams = nullptr;
- const_cast<ParsedTemplateInfo &>(TemplateInfo).Kind =
- ParsedTemplateInfo::NonTemplate;
+ TemplateInfo.Kind = ParsedTemplateInfo::NonTemplate;
}
} else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
// Pretend this is just a forward declaration.
TemplateParams = nullptr;
- const_cast<ParsedTemplateInfo &>(TemplateInfo).Kind =
- ParsedTemplateInfo::NonTemplate;
- const_cast<ParsedTemplateInfo &>(TemplateInfo).TemplateLoc =
- SourceLocation();
- const_cast<ParsedTemplateInfo &>(TemplateInfo).ExternLoc =
- SourceLocation();
+ TemplateInfo.Kind = ParsedTemplateInfo::NonTemplate;
+ TemplateInfo.TemplateLoc = SourceLocation();
+ TemplateInfo.ExternLoc = SourceLocation();
}
};
@@ -2804,11 +2800,9 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
/// constant-initializer:
/// '=' constant-expression
///
-Parser::DeclGroupPtrTy
-Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
- ParsedAttributes &AccessAttrs,
- const ParsedTemplateInfo &TemplateInfo,
- ParsingDeclRAIIObject *TemplateDiags) {
+Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
+ AccessSpecifier AS, ParsedAttributes &AccessAttrs,
+ ParsedTemplateInfo &TemplateInfo, ParsingDeclRAIIObject *TemplateDiags) {
assert(getLangOpts().CPlusPlus &&
"ParseCXXClassMemberDeclaration should only be called in C++ mode");
if (Tok.is(tok::at)) {
@@ -3525,8 +3519,10 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclarationWithPragmas(
case tok::kw_private:
// FIXME: We don't accept GNU attributes on access specifiers in OpenCL mode
// yet.
- if (getLangOpts().OpenCL && !NextToken().is(tok::colon))
- return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
+ if (getLangOpts().OpenCL && !NextToken().is(tok::colon)) {
+ ParsedTemplateInfo TemplateInfo;
+ return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
+ }
[[fallthrough]];
case tok::kw_public:
case tok::kw_protected: {
@@ -3582,7 +3578,8 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclarationWithPragmas(
ConsumeAnnotationToken();
return nullptr;
}
- return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
+ ParsedTemplateInfo TemplateInfo;
+ return ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo);
}
}
@@ -5167,8 +5164,9 @@ void Parser::ParseMicrosoftIfExistsClassDeclaration(
continue;
}
+ ParsedTemplateInfo TemplateInfo;
// Parse all the comma separated declarators.
- ParseCXXClassMemberDeclaration(CurAS, AccessAttrs);
+ ParseCXXClassMemberDeclaration(CurAS, AccessAttrs, TemplateInfo);
}
Braces.consumeClose();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 4cb04b3534738..263aea2e5524b 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -1533,7 +1533,8 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
cStyleParamWarned = true;
}
DeclSpec DS(AttrFactory);
- ParseDeclarationSpecifiers(DS);
+ ParsedTemplateInfo TemplateInfo;
+ ParseDeclarationSpecifiers(DS, TemplateInfo);
// Parse the declarator.
Declarator ParmDecl(DS, ParsedAttributesView::none(),
DeclaratorContext::Prototype);
@@ -2588,7 +2589,8 @@ StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
Scope::AtCatchScope);
if (Tok.isNot(tok::ellipsis)) {
DeclSpec DS(AttrFactory);
- ParseDeclarationSpecifiers(DS);
+ ParsedTemplateInfo TemplateInfo;
+ ParseDeclarationSpecifiers(DS, TemplateInfo);
Declarator ParmDecl(DS, ParsedAttributesView::none(),
DeclaratorContext::ObjCCatch);
ParseDeclarator(ParmDecl);
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index 8f841be422dd8..22ef44aaa0877 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -907,7 +907,8 @@ Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
// FIXME: The type should probably be restricted in some way... Not all
// declarators (parts of declarators?) are accepted for parameters.
DeclSpec DS(AttrFactory);
- ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none,
+ ParsedTemplateInfo TemplateInfo;
+ ParseDeclarationSpecifiers(DS, TemplateInfo, AS_none,
DeclSpecContext::DSC_template_param);
// Parse this as a typename.
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 869b9c6669c27..e3e72a441ca64 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1562,7 +1562,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
// Parse the common declaration-specifiers piece.
DeclSpec DS(AttrFactory);
- ParseDeclarationSpecifiers(DS);
+ ParsedTemplateInfo TemplateInfo;
+ ParseDeclarationSpecifiers(DS, TemplateInfo);
// C99 6.9.1p6: 'each declaration in the declaration list shall have at
// least one declarator'.
More information about the cfe-commits
mailing list