Skip to content

Commit 0cc1699

Browse files
committed
Simplify parsing of OmpCancellationConstructTypeClause
1 parent 2243137 commit 0cc1699

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ template <typename Parser> constexpr auto unwrap(const Parser &p) {
5050
return UnwrapParser<Parser>(p);
5151
}
5252

53+
// Check (without advancing the parsing location) if the next thing in the
54+
// input would be accepted by the "checked" parser, and if so, run the "parser"
55+
// parser.
56+
// The intended use is with the "checker" parser being some token, followed
57+
// by a more complex parser that consumes the token plus more things, e.g.
58+
// "PARALLEL"_id >= Parser<OmpDirectiveSpecification>{}.
59+
//
60+
// The >= has a higher precedence than ||, so it can be used just like >>
61+
// in an alternatives parser without parentheses.
62+
template <typename PA, typename PB>
63+
constexpr auto operator>=(PA checker, PB parser) {
64+
return lookAhead(checker) >> parser;
65+
}
66+
5367
/// Parse OpenMP directive name (this includes compound directives).
5468
struct OmpDirectiveNameParser {
5569
using resultType = OmpDirectiveName;
@@ -575,6 +589,9 @@ TYPE_PARSER(construct<OmpAffinityClause>(
575589
maybe(nonemptyList(Parser<OmpAffinityClause::Modifier>{}) / ":"),
576590
Parser<OmpObjectList>{}))
577591

592+
TYPE_PARSER(construct<OmpCancellationConstructTypeClause>(
593+
OmpDirectiveNameParser{}, maybe(parenthesized(scalarLogicalExpr))))
594+
578595
// 2.15.3.1 DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE)
579596
TYPE_PARSER(construct<OmpDefaultClause::DataSharingAttribute>(
580597
"PRIVATE" >> pure(OmpDefaultClause::DataSharingAttribute::Private) ||
@@ -985,22 +1002,18 @@ TYPE_PARSER( //
9851002
"WHEN" >> construct<OmpClause>(construct<OmpClause::When>(
9861003
parenthesized(Parser<OmpWhenClause>{}))) ||
9871004
// Cancellable constructs
988-
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
989-
construct<OmpCancellationConstructTypeClause>( //
990-
construct<OmpDirectiveName>(verbatim("DO"_id)),
991-
maybe(parenthesized(scalarLogicalExpr))))) ||
992-
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
993-
construct<OmpCancellationConstructTypeClause>( //
994-
construct<OmpDirectiveName>(verbatim("PARALLEL"_id)),
995-
maybe(parenthesized(scalarLogicalExpr))))) ||
996-
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
997-
construct<OmpCancellationConstructTypeClause>( //
998-
construct<OmpDirectiveName>(verbatim("SECTIONS"_id)),
999-
maybe(parenthesized(scalarLogicalExpr))))) ||
1000-
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
1001-
construct<OmpCancellationConstructTypeClause>( //
1002-
construct<OmpDirectiveName>(verbatim("TASKGROUP"_id)),
1003-
maybe(parenthesized(scalarLogicalExpr))))))
1005+
"DO"_id >=
1006+
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
1007+
Parser<OmpCancellationConstructTypeClause>{})) ||
1008+
"PARALLEL"_id >=
1009+
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
1010+
Parser<OmpCancellationConstructTypeClause>{})) ||
1011+
"SECTIONS"_id >=
1012+
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
1013+
Parser<OmpCancellationConstructTypeClause>{})) ||
1014+
"TASKGROUP"_id >=
1015+
construct<OmpClause>(construct<OmpClause::CancellationConstructType>(
1016+
Parser<OmpCancellationConstructTypeClause>{})))
10041017

10051018
// [Clause, [Clause], ...]
10061019
TYPE_PARSER(sourced(construct<OmpClauseList>(

0 commit comments

Comments
 (0)