Skip to content

[clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… #115775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Loading