[clang] e8c684a - [clang][NFC] Convert `Parser::ParenParseOption` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 29 21:01:08 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-04-30T07:01:01+03:00
New Revision: e8c684a0e4299077904892d11b1906f8e660eb01
URL: https://github.com/llvm/llvm-project/commit/e8c684a0e4299077904892d11b1906f8e660eb01
DIFF: https://github.com/llvm/llvm-project/commit/e8c684a0e4299077904892d11b1906f8e660eb01.diff
LOG: [clang][NFC] Convert `Parser::ParenParseOption` to scoped enum
Added:
Modified:
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/Parser.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 5248cb2219d73..01862e4534664 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -107,6 +107,15 @@ enum class TypeCastState { NotTypeCast = 0, MaybeTypeCast, IsTypeCast };
/// Control what ParseCastExpression will parse.
enum class CastParseKind { AnyCastExpr = 0, UnaryExprOnly, PrimaryExprOnly };
+/// ParenParseOption - Control what ParseParenExpression will parse.
+enum class ParenParseOption {
+ SimpleExpr, // Only parse '(' expression ')'
+ FoldExpr, // Also allow fold-expression <anything>
+ CompoundStmt, // Also allow '(' compound-statement ')'
+ CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
+ CastExpr // Also allow '(' type-name ')' <anything>
+};
+
/// Parser - This implements a parser for the C family of languages. After
/// parsing units of the grammar, productions are invoked to handle whatever has
/// been read.
@@ -1951,14 +1960,6 @@ class Parser : public CodeCompletionHandler {
/// used for misc language extensions.
bool ParseSimpleExpressionList(SmallVectorImpl<Expr *> &Exprs);
- /// ParenParseOption - Control what ParseParenExpression will parse.
- enum ParenParseOption {
- SimpleExpr, // Only parse '(' expression ')'
- FoldExpr, // Also allow fold-expression <anything>
- CompoundStmt, // Also allow '(' compound-statement ')'
- CompoundLiteral, // Also allow '(' type-name ')' '{' ... '}'
- CastExpr // Also allow '(' type-name ')' <anything>
- };
ExprResult ParseParenExpression(ParenParseOption &ExprType,
bool stopIfCastExpr,
bool isTypeCast,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 8c821ef0c95bf..a5dd08529cf37 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1105,7 +1105,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
ParenExprType = ParenParseOption::CastExpr;
break;
case CastParseKind::PrimaryExprOnly:
- ParenExprType = FoldExpr;
+ ParenExprType = ParenParseOption::FoldExpr;
break;
}
ParsedType CastTy;
@@ -1121,17 +1121,19 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
return Res;
switch (ParenExprType) {
- case SimpleExpr: break; // Nothing else to do.
- case CompoundStmt: break; // Nothing else to do.
- case CompoundLiteral:
+ case ParenParseOption::SimpleExpr:
+ break; // Nothing else to do.
+ case ParenParseOption::CompoundStmt:
+ break; // Nothing else to do.
+ case ParenParseOption::CompoundLiteral:
// We parsed '(' type-name ')' '{' ... '}'. If any suffixes of
// postfix-expression exist, parse them now.
break;
- case CastExpr:
+ case ParenParseOption::CastExpr:
// We have parsed the cast-expression and no postfix-expr pieces are
// following.
return Res;
- case FoldExpr:
+ case ParenParseOption::FoldExpr:
// We only parsed a fold-expression. There might be postfix-expr pieces
// afterwards; parse them now.
break;
@@ -2528,7 +2530,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
// type-name, or it is a unary-expression that starts with a compound
// literal, or starts with a primary-expression that is a parenthesized
// expression.
- ParenParseOption ExprType = CastExpr;
+ ParenParseOption ExprType = ParenParseOption::CastExpr;
SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
Operand = ParseParenExpression(ExprType, true/*stopIfCastExpr*/,
@@ -2537,7 +2539,7 @@ Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok,
// If ParseParenExpression parsed a '(typename)' sequence only, then this is
// a type.
- if (ExprType == CastExpr) {
+ if (ExprType == ParenParseOption::CastExpr) {
isCastExpr = true;
return ExprEmpty();
}
@@ -3095,7 +3097,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
cutOffParsing();
Actions.CodeCompletion().CodeCompleteExpression(
getCurScope(), PreferredType.get(Tok.getLocation()),
- /*IsParenthesized=*/ExprType >= CompoundLiteral);
+ /*IsParenthesized=*/ExprType >= ParenParseOption::CompoundLiteral);
return ExprError();
}
@@ -3119,7 +3121,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
// None of these cases should fall through with an invalid Result
// unless they've already reported an error.
- if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) {
+ if (ExprType >= ParenParseOption::CompoundStmt && Tok.is(tok::l_brace)) {
Diag(Tok, OpenLoc.isMacroID() ? diag::ext_gnu_statement_expr_macro
: diag::ext_gnu_statement_expr);
@@ -3142,7 +3144,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
Actions.ActOnStartStmtExpr();
StmtResult Stmt(ParseCompoundStatement(true));
- ExprType = CompoundStmt;
+ ExprType = ParenParseOption::CompoundStmt;
// If the substmt parsed correctly, build the AST node.
if (!Stmt.isInvalid()) {
@@ -3152,7 +3154,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
Actions.ActOnStmtExprError();
}
}
- } else if (ExprType >= CompoundLiteral && BridgeCast) {
+ } else if (ExprType >= ParenParseOption::CompoundLiteral && BridgeCast) {
tok::TokenKind tokenKind = Tok.getKind();
SourceLocation BridgeKeywordLoc = ConsumeToken();
@@ -3189,7 +3191,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
return Actions.ObjC().ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
BridgeKeywordLoc, Ty.get(),
RParenLoc, SubExpr.get());
- } else if (ExprType >= CompoundLiteral &&
+ } else if (ExprType >= ParenParseOption::CompoundLiteral &&
isTypeIdInParens(isAmbiguousTypeId)) {
// Otherwise, this is a compound literal expression or cast expression.
@@ -3233,7 +3235,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
ColonProtection.restore();
RParenLoc = T.getCloseLocation();
if (Tok.is(tok::l_brace)) {
- ExprType = CompoundLiteral;
+ ExprType = ParenParseOption::CompoundLiteral;
TypeResult Ty;
{
InMessageExpressionRAIIObject InMessage(*this, false);
@@ -3285,7 +3287,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
}
}
- if (ExprType == CastExpr) {
+ if (ExprType == ParenParseOption::CastExpr) {
// We parsed '(' type-name ')' and the thing after it wasn't a '{'.
if (DeclaratorInfo.isInvalidType())
@@ -3331,9 +3333,9 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
Diag(Tok, diag::err_expected_lbrace_in_compound_literal);
return ExprError();
}
- } else if (ExprType >= FoldExpr && Tok.is(tok::ellipsis) &&
+ } else if (ExprType >= ParenParseOption::FoldExpr && Tok.is(tok::ellipsis) &&
isFoldOperator(NextToken().getKind())) {
- ExprType = FoldExpr;
+ ExprType = ParenParseOption::FoldExpr;
return ParseFoldExpression(ExprResult(), T);
} else if (isTypeCast) {
// Parse the expression-list.
@@ -3343,18 +3345,18 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
if (!ParseSimpleExpressionList(ArgExprs)) {
// FIXME: If we ever support comma expressions as operands to
// fold-expressions, we'll need to allow multiple ArgExprs here.
- if (ExprType >= FoldExpr && ArgExprs.size() == 1 &&
+ if (ExprType >= ParenParseOption::FoldExpr && ArgExprs.size() == 1 &&
isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) {
- ExprType = FoldExpr;
+ ExprType = ParenParseOption::FoldExpr;
return ParseFoldExpression(ArgExprs[0], T);
}
- ExprType = SimpleExpr;
+ ExprType = ParenParseOption::SimpleExpr;
Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
ArgExprs);
}
} else if (getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
- ExprType == CastExpr && Tok.is(tok::l_square) &&
+ ExprType == ParenParseOption::CastExpr && Tok.is(tok::l_square) &&
tryParseOpenMPArrayShapingCastPart()) {
bool ErrorFound = false;
SmallVector<Expr *, 4> OMPDimensions;
@@ -3395,12 +3397,12 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
Result = Actions.CorrectDelayedTyposInExpr(Result);
}
- if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) &&
- NextToken().is(tok::ellipsis)) {
- ExprType = FoldExpr;
+ if (ExprType >= ParenParseOption::FoldExpr &&
+ isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) {
+ ExprType = ParenParseOption::FoldExpr;
return ParseFoldExpression(Result, T);
}
- ExprType = SimpleExpr;
+ ExprType = ParenParseOption::SimpleExpr;
// Don't build a paren expression unless we actually match a ')'.
if (!Result.isInvalid() && Tok.is(tok::r_paren))
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index a11af84274dc1..de25fd50b43c1 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -4085,7 +4085,8 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
BalancedDelimiterTracker &Tracker,
ColonProtectionRAIIObject &ColonProt) {
assert(getLangOpts().CPlusPlus && "Should only be called for C++!");
- assert(ExprType == CastExpr && "Compound literals are not ambiguous!");
+ assert(ExprType == ParenParseOption::CastExpr &&
+ "Compound literals are not ambiguous!");
assert(isTypeIdInParens() && "Not a type-id!");
ExprResult Result(true);
@@ -4122,7 +4123,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
}
if (Tok.is(tok::l_brace)) {
- ParseAs = CompoundLiteral;
+ ParseAs = ParenParseOption::CompoundLiteral;
} else {
bool NotCastExpr;
if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) {
@@ -4140,7 +4141,8 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
// If we parsed a cast-expression, it's really a type-id, otherwise it's
// an expression.
- ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
+ ParseAs =
+ NotCastExpr ? ParenParseOption::SimpleExpr : ParenParseOption::CastExpr;
}
// Create a fake EOF to mark end of Toks buffer.
@@ -4161,7 +4163,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
// as when we entered this function.
ConsumeAnyToken();
- if (ParseAs >= CompoundLiteral) {
+ if (ParseAs >= ParenParseOption::CompoundLiteral) {
// Parse the type declarator.
DeclSpec DS(AttrFactory);
Declarator DeclaratorInfo(DS, ParsedAttributesView::none(),
@@ -4180,8 +4182,8 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
ConsumeAnyToken();
- if (ParseAs == CompoundLiteral) {
- ExprType = CompoundLiteral;
+ if (ParseAs == ParenParseOption::CompoundLiteral) {
+ ExprType = ParenParseOption::CompoundLiteral;
if (DeclaratorInfo.isInvalidType())
return ExprError();
@@ -4192,7 +4194,7 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
}
// We parsed '(' type-id ')' and the thing after it wasn't a '{'.
- assert(ParseAs == CastExpr);
+ assert(ParseAs == ParenParseOption::CastExpr);
if (DeclaratorInfo.isInvalidType())
return ExprError();
@@ -4206,9 +4208,9 @@ Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
}
// Not a compound literal, and not followed by a cast-expression.
- assert(ParseAs == SimpleExpr);
+ assert(ParseAs == ParenParseOption::SimpleExpr);
- ExprType = SimpleExpr;
+ ExprType = ParenParseOption::SimpleExpr;
Result = ParseExpression();
if (!Result.isInvalid() && Tok.is(tok::r_paren))
Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(),
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 44d33a7d31ad6..183181fd3bac7 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1712,7 +1712,7 @@ ExprResult Parser::ParseAsmStringLiteral(bool ForAsmLabel) {
}
} else if (!ForAsmLabel && getLangOpts().CPlusPlus11 &&
Tok.is(tok::l_paren)) {
- ParenParseOption ExprType = SimpleExpr;
+ ParenParseOption ExprType = ParenParseOption::SimpleExpr;
SourceLocation RParenLoc;
ParsedType CastTy;
More information about the cfe-commits
mailing list