Skip to content

Commit e4d2793

Browse files
committed
[NFC, Refactor] Rename the (scoped) enum DeclaratorContext's enumerators to remove duplication
Since these are scoped enumerators, they have to be prefixed by DeclaratorContext, so lets remove Context from the name, and return some characters to the multiverse. Patch was reviewed here: https://reviews.llvm.org/D91011 Thank you to aaron, bruno, wyatt and barry for indulging me.
1 parent b8a8ef3 commit e4d2793

18 files changed

+496
-521
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,12 +2579,11 @@ class Parser : public CodeCompletionHandler {
25792579
bool TrySkipAttributes();
25802580

25812581
public:
2582-
TypeResult ParseTypeName(SourceRange *Range = nullptr,
2583-
DeclaratorContext Context
2584-
= DeclaratorContext::TypeNameContext,
2585-
AccessSpecifier AS = AS_none,
2586-
Decl **OwnedType = nullptr,
2587-
ParsedAttributes *Attrs = nullptr);
2582+
TypeResult
2583+
ParseTypeName(SourceRange *Range = nullptr,
2584+
DeclaratorContext Context = DeclaratorContext::TypeName,
2585+
AccessSpecifier AS = AS_none, Decl **OwnedType = nullptr,
2586+
ParsedAttributes *Attrs = nullptr);
25882587

25892588
private:
25902589
void ParseBlockId(SourceLocation CaretLoc);

clang/include/clang/Sema/DeclSpec.h

Lines changed: 197 additions & 199 deletions
Large diffs are not rendered by default.

clang/lib/Parse/ParseDecl.cpp

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,12 +1773,11 @@ bool Parser::MightBeDeclarator(DeclaratorContext Context) {
17731773
return getLangOpts().CPlusPlus;
17741774

17751775
case tok::l_square: // Might be an attribute on an unnamed bit-field.
1776-
return Context == DeclaratorContext::MemberContext &&
1777-
getLangOpts().CPlusPlus11 && NextToken().is(tok::l_square);
1776+
return Context == DeclaratorContext::Member && getLangOpts().CPlusPlus11 &&
1777+
NextToken().is(tok::l_square);
17781778

17791779
case tok::colon: // Might be a typo for '::' or an unnamed bit-field.
1780-
return Context == DeclaratorContext::MemberContext ||
1781-
getLangOpts().CPlusPlus;
1780+
return Context == DeclaratorContext::Member || getLangOpts().CPlusPlus;
17821781

17831782
case tok::identifier:
17841783
switch (NextToken().getKind()) {
@@ -1804,9 +1803,8 @@ bool Parser::MightBeDeclarator(DeclaratorContext Context) {
18041803
// At namespace scope, 'identifier:' is probably a typo for 'identifier::'
18051804
// and in block scope it's probably a label. Inside a class definition,
18061805
// this is a bit-field.
1807-
return Context == DeclaratorContext::MemberContext ||
1808-
(getLangOpts().CPlusPlus &&
1809-
Context == DeclaratorContext::FileContext);
1806+
return Context == DeclaratorContext::Member ||
1807+
(getLangOpts().CPlusPlus && Context == DeclaratorContext::File);
18101808

18111809
case tok::identifier: // Possible virt-specifier.
18121810
return getLangOpts().CPlusPlus11 && isCXX11VirtSpecifier(NextToken());
@@ -1964,7 +1962,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
19641962
// Function definitions are only allowed at file scope and in C++ classes.
19651963
// The C++ inline method definition case is handled elsewhere, so we only
19661964
// need to handle the file scope definition case.
1967-
if (Context == DeclaratorContext::FileContext) {
1965+
if (Context == DeclaratorContext::File) {
19681966
if (isStartOfFunctionDefinition(D)) {
19691967
if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
19701968
Diag(Tok, diag::err_function_declared_typedef);
@@ -2043,7 +2041,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
20432041
if (FirstDecl)
20442042
DeclsInGroup.push_back(FirstDecl);
20452043

2046-
bool ExpectSemi = Context != DeclaratorContext::ForContext;
2044+
bool ExpectSemi = Context != DeclaratorContext::ForInit;
20472045

20482046
// If we don't have a comma, it is either the end of the list (a ';') or an
20492047
// error, bail out.
@@ -2094,10 +2092,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
20942092
if (DeclEnd)
20952093
*DeclEnd = Tok.getLocation();
20962094

2097-
if (ExpectSemi &&
2098-
ExpectAndConsumeSemi(Context == DeclaratorContext::FileContext
2099-
? diag::err_invalid_token_after_toplevel_declarator
2100-
: diag::err_expected_semi_declaration)) {
2095+
if (ExpectSemi && ExpectAndConsumeSemi(
2096+
Context == DeclaratorContext::File
2097+
? diag::err_invalid_token_after_toplevel_declarator
2098+
: diag::err_expected_semi_declaration)) {
21012099
// Okay, there was no semicolon and one was expected. If we see a
21022100
// declaration specifier, just assume it was missing and continue parsing.
21032101
// Otherwise things are very confused and we skip to recover.
@@ -2303,8 +2301,8 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(
23032301
if (Init.isInvalid()) {
23042302
SmallVector<tok::TokenKind, 2> StopTokens;
23052303
StopTokens.push_back(tok::comma);
2306-
if (D.getContext() == DeclaratorContext::ForContext ||
2307-
D.getContext() == DeclaratorContext::InitStmtContext)
2304+
if (D.getContext() == DeclaratorContext::ForInit ||
2305+
D.getContext() == DeclaratorContext::SelectionInit)
23082306
StopTokens.push_back(tok::r_paren);
23092307
SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch);
23102308
Actions.ActOnInitializerError(ThisDecl);
@@ -2710,20 +2708,20 @@ bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS,
27102708
/// DeclaratorContext enumerator values.
27112709
Parser::DeclSpecContext
27122710
Parser::getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context) {
2713-
if (Context == DeclaratorContext::MemberContext)
2711+
if (Context == DeclaratorContext::Member)
27142712
return DeclSpecContext::DSC_class;
2715-
if (Context == DeclaratorContext::FileContext)
2713+
if (Context == DeclaratorContext::File)
27162714
return DeclSpecContext::DSC_top_level;
2717-
if (Context == DeclaratorContext::TemplateParamContext)
2715+
if (Context == DeclaratorContext::TemplateParam)
27182716
return DeclSpecContext::DSC_template_param;
2719-
if (Context == DeclaratorContext::TemplateArgContext ||
2720-
Context == DeclaratorContext::TemplateTypeArgContext)
2717+
if (Context == DeclaratorContext::TemplateArg ||
2718+
Context == DeclaratorContext::TemplateTypeArg)
27212719
return DeclSpecContext::DSC_template_type_arg;
2722-
if (Context == DeclaratorContext::TrailingReturnContext ||
2723-
Context == DeclaratorContext::TrailingReturnVarContext)
2720+
if (Context == DeclaratorContext::TrailingReturn ||
2721+
Context == DeclaratorContext::TrailingReturnVar)
27242722
return DeclSpecContext::DSC_trailing;
2725-
if (Context == DeclaratorContext::AliasDeclContext ||
2726-
Context == DeclaratorContext::AliasTemplateContext)
2723+
if (Context == DeclaratorContext::AliasDecl ||
2724+
Context == DeclaratorContext::AliasTemplate)
27272725
return DeclSpecContext::DSC_alias_declaration;
27282726
return DeclSpecContext::DSC_normal;
27292727
}
@@ -4474,7 +4472,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
44744472
// declares 'enum E : int; E *p;' not 'enum E : int*; E p;'.
44754473
DeclSpec DS(AttrFactory);
44764474
ParseSpecifierQualifierList(DS, AS, DeclSpecContext::DSC_type_specifier);
4477-
Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext);
4475+
Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName);
44784476
BaseType = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
44794477

44804478
BaseRange = SourceRange(ColonLoc, DeclaratorInfo.getSourceRange().getEnd());
@@ -5574,9 +5572,8 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
55745572
// (The same thing can in theory happen after a trailing-return-type, but
55755573
// since those are a C++11 feature, there is no rejects-valid issue there.)
55765574
if (Kind == tok::ampamp)
5577-
return Lang.CPlusPlus11 ||
5578-
(TheContext != DeclaratorContext::ConversionIdContext &&
5579-
TheContext != DeclaratorContext::CXXNewContext);
5575+
return Lang.CPlusPlus11 || (TheContext != DeclaratorContext::ConversionId &&
5576+
TheContext != DeclaratorContext::CXXNew);
55805577

55815578
return false;
55825579
}
@@ -5630,9 +5627,8 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
56305627
(Tok.is(tok::identifier) &&
56315628
(NextToken().is(tok::coloncolon) || NextToken().is(tok::less))) ||
56325629
Tok.is(tok::annot_cxxscope))) {
5633-
bool EnteringContext =
5634-
D.getContext() == DeclaratorContext::FileContext ||
5635-
D.getContext() == DeclaratorContext::MemberContext;
5630+
bool EnteringContext = D.getContext() == DeclaratorContext::File ||
5631+
D.getContext() == DeclaratorContext::Member;
56365632
CXXScopeSpec SS;
56375633
ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
56385634
/*ObjectHadErrors=*/false, EnteringContext);
@@ -5704,7 +5700,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
57045700
// GNU attributes are not allowed here in a new-type-id, but Declspec and
57055701
// C++11 attributes are allowed.
57065702
unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed |
5707-
((D.getContext() != DeclaratorContext::CXXNewContext)
5703+
((D.getContext() != DeclaratorContext::CXXNew)
57085704
? AR_GNUAttributesParsed
57095705
: AR_GNUAttributesParsedAndRejected);
57105706
ParseTypeQualifierListOpt(DS, Reqs, true, !D.mayOmitIdentifier());
@@ -5854,15 +5850,14 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
58545850
// this context it is a bitfield. Also in range-based for statement colon
58555851
// may delimit for-range-declaration.
58565852
ColonProtectionRAIIObject X(
5857-
*this, D.getContext() == DeclaratorContext::MemberContext ||
5858-
(D.getContext() == DeclaratorContext::ForContext &&
5853+
*this, D.getContext() == DeclaratorContext::Member ||
5854+
(D.getContext() == DeclaratorContext::ForInit &&
58595855
getLangOpts().CPlusPlus11));
58605856

58615857
// ParseDeclaratorInternal might already have parsed the scope.
58625858
if (D.getCXXScopeSpec().isEmpty()) {
5863-
bool EnteringContext =
5864-
D.getContext() == DeclaratorContext::FileContext ||
5865-
D.getContext() == DeclaratorContext::MemberContext;
5859+
bool EnteringContext = D.getContext() == DeclaratorContext::File ||
5860+
D.getContext() == DeclaratorContext::Member;
58665861
ParseOptionalCXXScopeSpecifier(
58675862
D.getCXXScopeSpec(), /*ObjectType=*/nullptr,
58685863
/*ObjectHadErrors=*/false, EnteringContext);
@@ -5892,11 +5887,10 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
58925887
// been expanded or contains auto; otherwise, it is parsed as part of the
58935888
// parameter-declaration-clause.
58945889
if (Tok.is(tok::ellipsis) && D.getCXXScopeSpec().isEmpty() &&
5895-
!((D.getContext() == DeclaratorContext::PrototypeContext ||
5896-
D.getContext() == DeclaratorContext::LambdaExprParameterContext ||
5897-
D.getContext() == DeclaratorContext::BlockLiteralContext) &&
5898-
NextToken().is(tok::r_paren) &&
5899-
!D.hasGroupingParens() &&
5890+
!((D.getContext() == DeclaratorContext::Prototype ||
5891+
D.getContext() == DeclaratorContext::LambdaExprParameter ||
5892+
D.getContext() == DeclaratorContext::BlockLiteral) &&
5893+
NextToken().is(tok::r_paren) && !D.hasGroupingParens() &&
59005894
!Actions.containsUnexpandedParameterPacks(D) &&
59015895
D.getDeclSpec().getTypeSpecType() != TST_auto)) {
59025896
SourceLocation EllipsisLoc = ConsumeToken();
@@ -5925,16 +5919,13 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
59255919
AllowConstructorName = false;
59265920
AllowDeductionGuide = false;
59275921
} else if (D.getCXXScopeSpec().isSet()) {
5928-
AllowConstructorName =
5929-
(D.getContext() == DeclaratorContext::FileContext ||
5930-
D.getContext() == DeclaratorContext::MemberContext);
5922+
AllowConstructorName = (D.getContext() == DeclaratorContext::File ||
5923+
D.getContext() == DeclaratorContext::Member);
59315924
AllowDeductionGuide = false;
59325925
} else {
5933-
AllowConstructorName =
5934-
(D.getContext() == DeclaratorContext::MemberContext);
5935-
AllowDeductionGuide =
5936-
(D.getContext() == DeclaratorContext::FileContext ||
5937-
D.getContext() == DeclaratorContext::MemberContext);
5926+
AllowConstructorName = (D.getContext() == DeclaratorContext::Member);
5927+
AllowDeductionGuide = (D.getContext() == DeclaratorContext::File ||
5928+
D.getContext() == DeclaratorContext::Member);
59385929
}
59395930

59405931
bool HadScope = D.getCXXScopeSpec().isValid();
@@ -5990,16 +5981,16 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
59905981
// An identifier within parens is unlikely to be intended to be anything
59915982
// other than a name being "declared".
59925983
DiagnoseIdentifier = true;
5993-
else if (D.getContext() == DeclaratorContext::TemplateArgContext)
5984+
else if (D.getContext() == DeclaratorContext::TemplateArg)
59945985
// T<int N> is an accidental identifier; T<int N indicates a missing '>'.
59955986
DiagnoseIdentifier =
59965987
NextToken().isOneOf(tok::comma, tok::greater, tok::greatergreater);
5997-
else if (D.getContext() == DeclaratorContext::AliasDeclContext ||
5998-
D.getContext() == DeclaratorContext::AliasTemplateContext)
5988+
else if (D.getContext() == DeclaratorContext::AliasDecl ||
5989+
D.getContext() == DeclaratorContext::AliasTemplate)
59995990
// The most likely error is that the ';' was forgotten.
60005991
DiagnoseIdentifier = NextToken().isOneOf(tok::comma, tok::semi);
6001-
else if ((D.getContext() == DeclaratorContext::TrailingReturnContext ||
6002-
D.getContext() == DeclaratorContext::TrailingReturnVarContext) &&
5992+
else if ((D.getContext() == DeclaratorContext::TrailingReturn ||
5993+
D.getContext() == DeclaratorContext::TrailingReturnVar) &&
60035994
!isCXX11VirtSpecifier(Tok))
60045995
DiagnoseIdentifier = NextToken().isOneOf(
60055996
tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try);
@@ -6058,7 +6049,7 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
60586049
LLVM_BUILTIN_TRAP;
60596050
if (Tok.is(tok::l_square))
60606051
return ParseMisplacedBracketDeclarator(D);
6061-
if (D.getContext() == DeclaratorContext::MemberContext) {
6052+
if (D.getContext() == DeclaratorContext::Member) {
60626053
// Objective-C++: Detect C++ keywords and try to prevent further errors by
60636054
// treating these keyword as valid member names.
60646055
if (getLangOpts().ObjC && getLangOpts().CPlusPlus &&
@@ -6349,13 +6340,14 @@ void Parser::InitCXXThisScopeForDeclaratorIfRelevant(
63496340
// and the end of the function-definition, member-declarator, or
63506341
// declarator.
63516342
// FIXME: currently, "static" case isn't handled correctly.
6352-
bool IsCXX11MemberFunction = getLangOpts().CPlusPlus11 &&
6353-
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
6354-
(D.getContext() == DeclaratorContext::MemberContext
6355-
? !D.getDeclSpec().isFriendSpecified()
6356-
: D.getContext() == DeclaratorContext::FileContext &&
6357-
D.getCXXScopeSpec().isValid() &&
6358-
Actions.CurContext->isRecord());
6343+
bool IsCXX11MemberFunction =
6344+
getLangOpts().CPlusPlus11 &&
6345+
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
6346+
(D.getContext() == DeclaratorContext::Member
6347+
? !D.getDeclSpec().isFriendSpecified()
6348+
: D.getContext() == DeclaratorContext::File &&
6349+
D.getCXXScopeSpec().isValid() &&
6350+
Actions.CurContext->isRecord());
63596351
if (!IsCXX11MemberFunction)
63606352
return;
63616353

@@ -6757,11 +6749,11 @@ void Parser::ParseParameterDeclarationClause(
67576749
// "LambdaExprParameterContext", because we must accept either
67586750
// 'declarator' or 'abstract-declarator' here.
67596751
Declarator ParmDeclarator(
6760-
DS, DeclaratorCtx == DeclaratorContext::RequiresExprContext
6761-
? DeclaratorContext::RequiresExprContext
6762-
: DeclaratorCtx == DeclaratorContext::LambdaExprContext
6763-
? DeclaratorContext::LambdaExprParameterContext
6764-
: DeclaratorContext::PrototypeContext);
6752+
DS, DeclaratorCtx == DeclaratorContext::RequiresExpr
6753+
? DeclaratorContext::RequiresExpr
6754+
: DeclaratorCtx == DeclaratorContext::LambdaExpr
6755+
? DeclaratorContext::LambdaExprParameter
6756+
: DeclaratorContext::Prototype);
67656757
ParseDeclarator(ParmDeclarator);
67666758

67676759
// Parse GNU attributes, if present.
@@ -6840,7 +6832,7 @@ void Parser::ParseParameterDeclarationClause(
68406832
SourceLocation EqualLoc = Tok.getLocation();
68416833

68426834
// Parse the default argument
6843-
if (DeclaratorCtx == DeclaratorContext::MemberContext) {
6835+
if (DeclaratorCtx == DeclaratorContext::Member) {
68446836
// If we're inside a class definition, cache the tokens
68456837
// corresponding to the default argument. We'll actually parse
68466838
// them when we see the end of the class definition.

0 commit comments

Comments
 (0)