Skip to content

Commit e8c4842

Browse files
authored
[clang][OpenMP][NFC] Move 'allocate' clause modifier parsing into fun… (#115775)
…ction Parsing of 'allocate' clause modifier ('allocator') has been moved into a separate function in anticipation of adding another modifier ('align').
1 parent 375bb38 commit e8c4842

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,6 +4519,36 @@ static bool parseStepSize(Parser &P, SemaOpenMP::OpenMPVarListDataTy &Data,
45194519
return false;
45204520
}
45214521

4522+
/// Parse 'allocate' clause modifiers.
4523+
/// If allocator-modifier exists, return an expression for it and set
4524+
/// Data field noting modifier was specified.
4525+
///
4526+
static ExprResult
4527+
parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind,
4528+
SemaOpenMP::OpenMPVarListDataTy &Data) {
4529+
const Token &Tok = P.getCurToken();
4530+
Preprocessor &PP = P.getPreprocessor();
4531+
ExprResult Tail;
4532+
auto Modifier = static_cast<OpenMPAllocateClauseModifier>(
4533+
getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), P.getLangOpts()));
4534+
if (Modifier == OMPC_ALLOCATE_allocator) {
4535+
Data.AllocClauseModifier = Modifier;
4536+
P.ConsumeToken();
4537+
BalancedDelimiterTracker AllocateT(P, tok::l_paren,
4538+
tok::annot_pragma_openmp_end);
4539+
if (Tok.is(tok::l_paren)) {
4540+
AllocateT.consumeOpen();
4541+
Tail = P.ParseAssignmentExpression();
4542+
AllocateT.consumeClose();
4543+
} else {
4544+
P.Diag(Tok, diag::err_expected) << tok::l_paren;
4545+
}
4546+
} else {
4547+
Tail = P.ParseAssignmentExpression();
4548+
}
4549+
return Tail;
4550+
}
4551+
45224552
/// Parses clauses with list.
45234553
bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
45244554
OpenMPClauseKind Kind,
@@ -4800,23 +4830,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
48004830
// iterator(iterators-definition)
48014831
ExprResult Tail;
48024832
if (Kind == OMPC_allocate) {
4803-
auto Modifier = static_cast<OpenMPAllocateClauseModifier>(
4804-
getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok), getLangOpts()));
4805-
if (Modifier == OMPC_ALLOCATE_allocator) {
4806-
Data.AllocClauseModifier = Modifier;
4807-
ConsumeToken();
4808-
BalancedDelimiterTracker AllocateT(*this, tok::l_paren,
4809-
tok::annot_pragma_openmp_end);
4810-
if (Tok.is(tok::l_paren)) {
4811-
AllocateT.consumeOpen();
4812-
Tail = ParseAssignmentExpression();
4813-
AllocateT.consumeClose();
4814-
} else {
4815-
Diag(Tok, diag::err_expected) << tok::l_paren;
4816-
}
4817-
} else {
4818-
Tail = ParseAssignmentExpression();
4819-
}
4833+
Tail = parseOpenMPAllocateClauseModifiers(*this, Kind, Data);
48204834
} else {
48214835
HasIterator = true;
48224836
EnterScope(Scope::OpenMPDirectiveScope | Scope::DeclScope);

0 commit comments

Comments
 (0)