Skip to content

Commit 78a1d92

Browse files
committed
[clang][NFC] Convert Parser::TentativeCXXTypeIdContext to scoped enum
1 parent 5f22b84 commit 78a1d92

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

clang/include/clang/Parse/Parser.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ enum class IfExistsBehavior {
128128
Dependent
129129
};
130130

131+
/// Specifies the context in which type-id/expression
132+
/// disambiguation will occur.
133+
enum class TentativeCXXTypeIdContext {
134+
InParens,
135+
Unambiguous,
136+
AsTemplateArgument,
137+
InTrailingReturnType,
138+
AsGenericSelectionArgument,
139+
};
140+
131141
/// Parser - This implements a parser for the C family of languages. After
132142
/// parsing units of the grammar, productions are invoked to handle whatever has
133143
/// been read.
@@ -2628,22 +2638,12 @@ class Parser : public CodeCompletionHandler {
26282638
DeclSpec::FriendSpecified IsFriend = DeclSpec::FriendSpecified::No,
26292639
const ParsedTemplateInfo *TemplateInfo = nullptr);
26302640

2631-
/// Specifies the context in which type-id/expression
2632-
/// disambiguation will occur.
2633-
enum TentativeCXXTypeIdContext {
2634-
TypeIdInParens,
2635-
TypeIdUnambiguous,
2636-
TypeIdAsTemplateArgument,
2637-
TypeIdInTrailingReturnType,
2638-
TypeIdAsGenericSelectionArgument,
2639-
};
2640-
26412641
/// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know
26422642
/// whether the parens contain an expression or a type-id.
26432643
/// Returns true for a type-id and false for an expression.
26442644
bool isTypeIdInParens(bool &isAmbiguous) {
26452645
if (getLangOpts().CPlusPlus)
2646-
return isCXXTypeId(TypeIdInParens, isAmbiguous);
2646+
return isCXXTypeId(TentativeCXXTypeIdContext::InParens, isAmbiguous);
26472647
isAmbiguous = false;
26482648
return isTypeSpecifierQualifier();
26492649
}
@@ -2662,7 +2662,8 @@ class Parser : public CodeCompletionHandler {
26622662
bool isTypeIdForGenericSelection() {
26632663
if (getLangOpts().CPlusPlus) {
26642664
bool isAmbiguous;
2665-
return isCXXTypeId(TypeIdAsGenericSelectionArgument, isAmbiguous);
2665+
return isCXXTypeId(TentativeCXXTypeIdContext::AsGenericSelectionArgument,
2666+
isAmbiguous);
26662667
}
26672668
return isTypeSpecifierQualifier();
26682669
}
@@ -2673,7 +2674,7 @@ class Parser : public CodeCompletionHandler {
26732674
bool isTypeIdUnambiguously() {
26742675
if (getLangOpts().CPlusPlus) {
26752676
bool isAmbiguous;
2676-
return isCXXTypeId(TypeIdUnambiguous, isAmbiguous);
2677+
return isCXXTypeId(TentativeCXXTypeIdContext::Unambiguous, isAmbiguous);
26772678
}
26782679
return isTypeSpecifierQualifier();
26792680
}

clang/lib/Parse/ParseTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() {
15061506
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
15071507
/*LambdaContextDecl=*/nullptr,
15081508
/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
1509-
if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1509+
if (isCXXTypeId(TentativeCXXTypeIdContext::AsTemplateArgument)) {
15101510
TypeResult TypeArg = ParseTypeName(
15111511
/*Range=*/nullptr, DeclaratorContext::TemplateArg);
15121512
return Actions.ActOnTemplateTypeArgument(TypeArg);

clang/lib/Parse/ParseTentative.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,23 @@ Parser::isCXXConditionDeclarationOrInitStatement(bool CanBeInitStatement,
607607
return ConditionOrInitStatement::Expression;
608608
}
609609

610-
/// Determine whether the next set of tokens contains a type-id.
611-
///
612-
/// The context parameter states what context we're parsing right
613-
/// now, which affects how this routine copes with the token
614-
/// following the type-id. If the context is TypeIdInParens, we have
615-
/// already parsed the '(' and we will cease lookahead when we hit
616-
/// the corresponding ')'. If the context is
617-
/// TypeIdAsTemplateArgument, we've already parsed the '<' or ','
618-
/// before this template argument, and will cease lookahead when we
619-
/// hit a '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately
620-
/// preceding such. Returns true for a type-id and false for an expression.
621-
/// If during the disambiguation process a parsing error is encountered,
622-
/// the function returns true to let the declaration parsing code handle it.
623-
///
624-
/// type-id:
625-
/// type-specifier-seq abstract-declarator[opt]
626-
///
610+
/// Determine whether the next set of tokens contains a type-id.
611+
///
612+
/// The context parameter states what context we're parsing right
613+
/// now, which affects how this routine copes with the token
614+
/// following the type-id. If the context is
615+
/// TentativeCXXTypeIdContext::InParens, we have already parsed the '(' and we
616+
/// will cease lookahead when we hit the corresponding ')'. If the context is
617+
/// TentativeCXXTypeIdContext::AsTemplateArgument, we've already parsed the '<'
618+
/// or ',' before this template argument, and will cease lookahead when we hit a
619+
/// '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately
620+
/// preceding such. Returns true for a type-id and false for an expression.
621+
/// If during the disambiguation process a parsing error is encountered,
622+
/// the function returns true to let the declaration parsing code handle it.
623+
///
624+
/// type-id:
625+
/// type-specifier-seq abstract-declarator[opt]
626+
///
627627
bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
628628

629629
isAmbiguous = false;
@@ -665,20 +665,23 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
665665
if (TPR == TPResult::Ambiguous) {
666666
// We are supposed to be inside parens, so if after the abstract declarator
667667
// we encounter a ')' this is a type-id, otherwise it's an expression.
668-
if (Context == TypeIdInParens && Tok.is(tok::r_paren)) {
668+
if (Context == TentativeCXXTypeIdContext::InParens &&
669+
Tok.is(tok::r_paren)) {
669670
TPR = TPResult::True;
670671
isAmbiguous = true;
671672
// We are supposed to be inside the first operand to a _Generic selection
672673
// expression, so if we find a comma after the declarator, we've found a
673674
// type and not an expression.
674-
} else if (Context == TypeIdAsGenericSelectionArgument && Tok.is(tok::comma)) {
675+
} else if (Context ==
676+
TentativeCXXTypeIdContext::AsGenericSelectionArgument &&
677+
Tok.is(tok::comma)) {
675678
TPR = TPResult::True;
676679
isAmbiguous = true;
677680
// We are supposed to be inside a template argument, so if after
678681
// the abstract declarator we encounter a '>', '>>' (in C++0x), or
679682
// ','; or, in C++0x, an ellipsis immediately preceding such, this
680683
// is a type-id. Otherwise, it's an expression.
681-
} else if (Context == TypeIdAsTemplateArgument &&
684+
} else if (Context == TentativeCXXTypeIdContext::AsTemplateArgument &&
682685
(Tok.isOneOf(tok::greater, tok::comma) ||
683686
(getLangOpts().CPlusPlus11 &&
684687
(Tok.isOneOf(tok::greatergreater,
@@ -690,7 +693,7 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
690693
TPR = TPResult::True;
691694
isAmbiguous = true;
692695

693-
} else if (Context == TypeIdInTrailingReturnType) {
696+
} else if (Context == TentativeCXXTypeIdContext::InTrailingReturnType) {
694697
TPR = TPResult::True;
695698
isAmbiguous = true;
696699
} else
@@ -2246,7 +2249,7 @@ Parser::TryParseFunctionDeclarator(bool MayHaveTrailingReturnType) {
22462249
if (Tok.is(tok::identifier) && NameAfterArrowIsNonType()) {
22472250
return TPResult::False;
22482251
}
2249-
if (isCXXTypeId(TentativeCXXTypeIdContext::TypeIdInTrailingReturnType))
2252+
if (isCXXTypeId(TentativeCXXTypeIdContext::InTrailingReturnType))
22502253
return TPResult::True;
22512254
}
22522255

0 commit comments

Comments
 (0)