Author: Vlad Serebrennikov Date: 2025-04-30T07:14:31+03:00 New Revision: 78a1d92870b596c67ee301b96d3a7864bafaab92
URL: https://github.com/llvm/llvm-project/commit/78a1d92870b596c67ee301b96d3a7864bafaab92 DIFF: https://github.com/llvm/llvm-project/commit/78a1d92870b596c67ee301b96d3a7864bafaab92.diff LOG: [clang][NFC] Convert `Parser::TentativeCXXTypeIdContext` to scoped enum Added: Modified: clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseTemplate.cpp clang/lib/Parse/ParseTentative.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 5b68447274c70..1c31ec7c89715 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -128,6 +128,16 @@ enum class IfExistsBehavior { Dependent }; +/// Specifies the context in which type-id/expression +/// disambiguation will occur. +enum class TentativeCXXTypeIdContext { + InParens, + Unambiguous, + AsTemplateArgument, + InTrailingReturnType, + AsGenericSelectionArgument, +}; + /// 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. @@ -2628,22 +2638,12 @@ class Parser : public CodeCompletionHandler { DeclSpec::FriendSpecified IsFriend = DeclSpec::FriendSpecified::No, const ParsedTemplateInfo *TemplateInfo = nullptr); - /// Specifies the context in which type-id/expression - /// disambiguation will occur. - enum TentativeCXXTypeIdContext { - TypeIdInParens, - TypeIdUnambiguous, - TypeIdAsTemplateArgument, - TypeIdInTrailingReturnType, - TypeIdAsGenericSelectionArgument, - }; - /// isTypeIdInParens - Assumes that a '(' was parsed and now we want to know /// whether the parens contain an expression or a type-id. /// Returns true for a type-id and false for an expression. bool isTypeIdInParens(bool &isAmbiguous) { if (getLangOpts().CPlusPlus) - return isCXXTypeId(TypeIdInParens, isAmbiguous); + return isCXXTypeId(TentativeCXXTypeIdContext::InParens, isAmbiguous); isAmbiguous = false; return isTypeSpecifierQualifier(); } @@ -2662,7 +2662,8 @@ class Parser : public CodeCompletionHandler { bool isTypeIdForGenericSelection() { if (getLangOpts().CPlusPlus) { bool isAmbiguous; - return isCXXTypeId(TypeIdAsGenericSelectionArgument, isAmbiguous); + return isCXXTypeId(TentativeCXXTypeIdContext::AsGenericSelectionArgument, + isAmbiguous); } return isTypeSpecifierQualifier(); } @@ -2673,7 +2674,7 @@ class Parser : public CodeCompletionHandler { bool isTypeIdUnambiguously() { if (getLangOpts().CPlusPlus) { bool isAmbiguous; - return isCXXTypeId(TypeIdUnambiguous, isAmbiguous); + return isCXXTypeId(TentativeCXXTypeIdContext::Unambiguous, isAmbiguous); } return isTypeSpecifierQualifier(); } diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 34c68ae9ccea6..dbe5e94747c67 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -1506,7 +1506,7 @@ ParsedTemplateArgument Parser::ParseTemplateArgument() { Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated, /*LambdaContextDecl=*/nullptr, /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); - if (isCXXTypeId(TypeIdAsTemplateArgument)) { + if (isCXXTypeId(TentativeCXXTypeIdContext::AsTemplateArgument)) { TypeResult TypeArg = ParseTypeName( /*Range=*/nullptr, DeclaratorContext::TemplateArg); return Actions.ActOnTemplateTypeArgument(TypeArg); diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 0994ff126e7e5..ce538532dc4f4 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -607,23 +607,23 @@ Parser::isCXXConditionDeclarationOrInitStatement(bool CanBeInitStatement, return ConditionOrInitStatement::Expression; } - /// Determine whether the next set of tokens contains a type-id. - /// - /// The context parameter states what context we're parsing right - /// now, which affects how this routine copes with the token - /// following the type-id. If the context is TypeIdInParens, we have - /// already parsed the '(' and we will cease lookahead when we hit - /// the corresponding ')'. If the context is - /// TypeIdAsTemplateArgument, we've already parsed the '<' or ',' - /// before this template argument, and will cease lookahead when we - /// hit a '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately - /// preceding such. Returns true for a type-id and false for an expression. - /// If during the disambiguation process a parsing error is encountered, - /// the function returns true to let the declaration parsing code handle it. - /// - /// type-id: - /// type-specifier-seq abstract-declarator[opt] - /// +/// Determine whether the next set of tokens contains a type-id. +/// +/// The context parameter states what context we're parsing right +/// now, which affects how this routine copes with the token +/// following the type-id. If the context is +/// TentativeCXXTypeIdContext::InParens, we have already parsed the '(' and we +/// will cease lookahead when we hit the corresponding ')'. If the context is +/// TentativeCXXTypeIdContext::AsTemplateArgument, we've already parsed the '<' +/// or ',' before this template argument, and will cease lookahead when we hit a +/// '>', '>>' (in C++0x), or ','; or, in C++0x, an ellipsis immediately +/// preceding such. Returns true for a type-id and false for an expression. +/// If during the disambiguation process a parsing error is encountered, +/// the function returns true to let the declaration parsing code handle it. +/// +/// type-id: +/// type-specifier-seq abstract-declarator[opt] +/// bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) { isAmbiguous = false; @@ -665,20 +665,23 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) { if (TPR == TPResult::Ambiguous) { // We are supposed to be inside parens, so if after the abstract declarator // we encounter a ')' this is a type-id, otherwise it's an expression. - if (Context == TypeIdInParens && Tok.is(tok::r_paren)) { + if (Context == TentativeCXXTypeIdContext::InParens && + Tok.is(tok::r_paren)) { TPR = TPResult::True; isAmbiguous = true; // We are supposed to be inside the first operand to a _Generic selection // expression, so if we find a comma after the declarator, we've found a // type and not an expression. - } else if (Context == TypeIdAsGenericSelectionArgument && Tok.is(tok::comma)) { + } else if (Context == + TentativeCXXTypeIdContext::AsGenericSelectionArgument && + Tok.is(tok::comma)) { TPR = TPResult::True; isAmbiguous = true; // We are supposed to be inside a template argument, so if after // the abstract declarator we encounter a '>', '>>' (in C++0x), or // ','; or, in C++0x, an ellipsis immediately preceding such, this // is a type-id. Otherwise, it's an expression. - } else if (Context == TypeIdAsTemplateArgument && + } else if (Context == TentativeCXXTypeIdContext::AsTemplateArgument && (Tok.isOneOf(tok::greater, tok::comma) || (getLangOpts().CPlusPlus11 && (Tok.isOneOf(tok::greatergreater, @@ -690,7 +693,7 @@ bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) { TPR = TPResult::True; isAmbiguous = true; - } else if (Context == TypeIdInTrailingReturnType) { + } else if (Context == TentativeCXXTypeIdContext::InTrailingReturnType) { TPR = TPResult::True; isAmbiguous = true; } else @@ -2246,7 +2249,7 @@ Parser::TryParseFunctionDeclarator(bool MayHaveTrailingReturnType) { if (Tok.is(tok::identifier) && NameAfterArrowIsNonType()) { return TPResult::False; } - if (isCXXTypeId(TentativeCXXTypeIdContext::TypeIdInTrailingReturnType)) + if (isCXXTypeId(TentativeCXXTypeIdContext::InTrailingReturnType)) return TPResult::True; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits