@@ -50,6 +50,20 @@ template <typename Parser> constexpr auto unwrap(const Parser &p) {
50
50
return UnwrapParser<Parser>(p);
51
51
}
52
52
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
+
53
67
/// Parse OpenMP directive name (this includes compound directives).
54
68
struct OmpDirectiveNameParser {
55
69
using resultType = OmpDirectiveName;
@@ -575,6 +589,9 @@ TYPE_PARSER(construct<OmpAffinityClause>(
575
589
maybe(nonemptyList(Parser<OmpAffinityClause::Modifier>{}) / ":"),
576
590
Parser<OmpObjectList>{}))
577
591
592
+ TYPE_PARSER(construct<OmpCancellationConstructTypeClause>(
593
+ OmpDirectiveNameParser{}, maybe(parenthesized(scalarLogicalExpr))))
594
+
578
595
// 2.15.3.1 DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE)
579
596
TYPE_PARSER(construct<OmpDefaultClause::DataSharingAttribute>(
580
597
"PRIVATE" >> pure(OmpDefaultClause::DataSharingAttribute::Private) ||
@@ -804,8 +821,9 @@ TYPE_PARSER(construct<OmpAbsentClause>(many(maybe(","_tok) >>
804
821
TYPE_PARSER(construct<OmpContainsClause>(many(maybe(","_tok) >>
805
822
construct<llvm::omp::Directive>(unwrap(OmpDirectiveNameParser{})))))
806
823
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>{}))) ||
809
827
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
810
828
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
811
829
"AFFINITY" >> construct<OmpClause>(construct<OmpClause::Affinity>(
@@ -982,7 +1000,20 @@ TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
982
1000
"UPDATE" >> construct<OmpClause>(construct<OmpClause::Update>(
983
1001
parenthesized(Parser<OmpUpdateClause>{}))) ||
984
1002
"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>{})))
986
1017
987
1018
// [Clause, [Clause], ...]
988
1019
TYPE_PARSER(sourced(construct<OmpClauseList>(
@@ -1096,20 +1127,13 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
1096
1127
TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>(
1097
1128
sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{})))
1098
1129
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
-
1106
1130
// 2.14.2 Cancellation Point construct
1107
1131
TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>(
1108
- verbatim("CANCELLATION POINT"_tok), Parser<OmpCancelType >{})))
1132
+ verbatim("CANCELLATION POINT"_tok), Parser<OmpClauseList >{})))
1109
1133
1110
1134
// 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>{} )))
1113
1137
1114
1138
TYPE_PARSER(sourced(construct<OmpFailClause>(
1115
1139
parenthesized(indirect(Parser<OmpMemoryOrderClause>{})))))
@@ -1193,9 +1217,10 @@ TYPE_PARSER(
1193
1217
sourced(construct<OpenMPStandaloneConstruct>(
1194
1218
Parser<OpenMPSimpleStandaloneConstruct>{}) ||
1195
1219
construct<OpenMPStandaloneConstruct>(Parser<OpenMPFlushConstruct>{}) ||
1196
- construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) ||
1220
+ // Try CANCELLATION POINT before CANCEL.
1197
1221
construct<OpenMPStandaloneConstruct>(
1198
1222
Parser<OpenMPCancellationPointConstruct>{}) ||
1223
+ construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) ||
1199
1224
construct<OpenMPStandaloneConstruct>(
1200
1225
Parser<OmpMetadirectiveDirective>{}) ||
1201
1226
construct<OpenMPStandaloneConstruct>(Parser<OpenMPDepobjConstruct>{})) /
0 commit comments