@@ -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).
5468struct 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)
579596TYPE_PARSER(construct<OmpDefaultClause::DataSharingAttribute>(
580597 "PRIVATE" >> pure(OmpDefaultClause::DataSharingAttribute::Private) ||
@@ -804,8 +821,9 @@ TYPE_PARSER(construct<OmpAbsentClause>(many(maybe(","_tok) >>
804821TYPE_PARSER(construct<OmpContainsClause>(many(maybe(","_tok) >>
805822 construct<llvm::omp::Directive>(unwrap(OmpDirectiveNameParser{})))))
806823
807- TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
808- parenthesized(Parser<OmpAbsentClause>{}))) ||
824+ TYPE_PARSER( //
825+ "ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
826+ parenthesized(Parser<OmpAbsentClause>{}))) ||
809827 "ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
810828 "ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
811829 "AFFINITY" >> construct<OmpClause>(construct<OmpClause::Affinity>(
@@ -982,7 +1000,20 @@ TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
9821000 "UPDATE" >> construct<OmpClause>(construct<OmpClause::Update>(
9831001 parenthesized(Parser<OmpUpdateClause>{}))) ||
9841002 "WHEN" >> construct<OmpClause>(construct<OmpClause::When>(
985- parenthesized(Parser<OmpWhenClause>{}))))
1003+ parenthesized(Parser<OmpWhenClause>{}))) ||
1004+ // Cancellable constructs
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>{})))
9861017
9871018// [Clause, [Clause], ...]
9881019TYPE_PARSER(sourced(construct<OmpClauseList>(
@@ -1096,20 +1127,13 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
10961127TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>(
10971128 sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{})))
10981129
1099- // 2.14.1 construct-type-clause -> PARALLEL | SECTIONS | DO | TASKGROUP
1100- TYPE_PARSER(sourced(construct<OmpCancelType>(
1101- first("PARALLEL" >> pure(OmpCancelType::Type::Parallel),
1102- "SECTIONS" >> pure(OmpCancelType::Type::Sections),
1103- "DO" >> pure(OmpCancelType::Type::Do),
1104- "TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup)))))
1105-
11061130// 2.14.2 Cancellation Point construct
11071131TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>(
1108- verbatim("CANCELLATION POINT"_tok), Parser<OmpCancelType >{})))
1132+ verbatim("CANCELLATION POINT"_tok), Parser<OmpClauseList >{})))
11091133
11101134// 2.14.1 Cancel construct
1111- TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(verbatim("CANCEL"_tok),
1112- Parser<OmpCancelType>{}, maybe("IF" >> parenthesized(scalarLogicalExpr)) )))
1135+ TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(
1136+ verbatim("CANCEL"_tok), Parser<OmpClauseList>{} )))
11131137
11141138TYPE_PARSER(sourced(construct<OmpFailClause>(
11151139 parenthesized(indirect(Parser<OmpMemoryOrderClause>{})))))
@@ -1193,9 +1217,10 @@ TYPE_PARSER(
11931217 sourced(construct<OpenMPStandaloneConstruct>(
11941218 Parser<OpenMPSimpleStandaloneConstruct>{}) ||
11951219 construct<OpenMPStandaloneConstruct>(Parser<OpenMPFlushConstruct>{}) ||
1196- construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) ||
1220+ // Try CANCELLATION POINT before CANCEL.
11971221 construct<OpenMPStandaloneConstruct>(
11981222 Parser<OpenMPCancellationPointConstruct>{}) ||
1223+ construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) ||
11991224 construct<OpenMPStandaloneConstruct>(
12001225 Parser<OmpMetadirectiveDirective>{}) ||
12011226 construct<OpenMPStandaloneConstruct>(Parser<OpenMPDepobjConstruct>{})) /
0 commit comments