[clang] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (PR #115775)
David Pagan via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 11 14:02:50 PST 2024
https://github.com/ddpagan created https://github.com/llvm/llvm-project/pull/115775
…ction
Parsing of 'allocate' clause modifier ('allocator') has been moved into a separate function in anticipation of adding another modifier ('align').
>From 78e9809b743f74207dfab2e2271d91a04b2f75ca Mon Sep 17 00:00:00 2001
From: Dave Pagan <dave.pagan at amd.com>
Date: Mon, 11 Nov 2024 14:41:47 -0600
Subject: [PATCH] [clang][OpenMP][NFC] Move 'allocate' clause modifier parsing
into function
Parsing of 'allocate' clause modifier ('allocator') has been moved into
a separate function in anticipation of adding another modifier ('align').
---
clang/lib/Parse/ParseOpenMP.cpp | 48 +++++++++++++++++++++------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 59a33eafa6be4f..c253133f611b0b 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4519,6 +4519,36 @@ static bool parseStepSize(Parser &P, SemaOpenMP::OpenMPVarListDataTy &Data,
return false;
}
+/// Parse 'allocate' clause modifiers.
+/// If allocator-modifier exists, return an expression for it and set
+/// Data field noting modifier was specified.
+///
+static ExprResult
+parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind,
+ SemaOpenMP::OpenMPVarListDataTy &Data) {
+ const Token &Tok = P.getCurToken();
+ Preprocessor &PP = P.getPreprocessor();
+ ExprResult Tail;
+ auto Modifier = static_cast<OpenMPAllocateClauseModifier>(
+ getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), P.getLangOpts()));
+ if (Modifier == OMPC_ALLOCATE_allocator) {
+ Data.AllocClauseModifier = Modifier;
+ P.ConsumeToken();
+ BalancedDelimiterTracker AllocateT(P, tok::l_paren,
+ tok::annot_pragma_openmp_end);
+ if (Tok.is(tok::l_paren)) {
+ AllocateT.consumeOpen();
+ Tail = P.ParseAssignmentExpression();
+ AllocateT.consumeClose();
+ } else {
+ P.Diag(Tok, diag::err_expected) << tok::l_paren;
+ }
+ } else {
+ Tail = P.ParseAssignmentExpression();
+ }
+ return Tail;
+}
+
/// Parses clauses with list.
bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
OpenMPClauseKind Kind,
@@ -4800,23 +4830,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
// iterator(iterators-definition)
ExprResult Tail;
if (Kind == OMPC_allocate) {
- auto Modifier = static_cast<OpenMPAllocateClauseModifier>(
- getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), getLangOpts()));
- if (Modifier == OMPC_ALLOCATE_allocator) {
- Data.AllocClauseModifier = Modifier;
- ConsumeToken();
- BalancedDelimiterTracker AllocateT(*this, tok::l_paren,
- tok::annot_pragma_openmp_end);
- if (Tok.is(tok::l_paren)) {
- AllocateT.consumeOpen();
- Tail = ParseAssignmentExpression();
- AllocateT.consumeClose();
- } else {
- Diag(Tok, diag::err_expected) << tok::l_paren;
- }
- } else {
- Tail = ParseAssignmentExpression();
- }
+ Tail = parseOpenMPAllocateClauseModifiers(*this, Kind, Data);
} else {
HasIterator = true;
EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);
More information about the cfe-commits
mailing list