[flang-commits] [flang] [flang][OpenMP] Parse strictly- and loosely-structured blocks (PR #150298)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Thu Jul 24 04:12:38 PDT 2025


================
@@ -1208,6 +1208,54 @@ TYPE_PARSER(sourced(
         maybe(Parser<OmpClauseList>{}),
         pure(OmpDirectiveSpecification::Flags::None))))
 
+static bool IsFortranBlockConstruct(const ExecutionPartConstruct &epc) {
+  // ExecutionPartConstruct -> ExecutableConstruct
+  //   -> Indirection<BlockConstruct>
+  if (auto *ec{std::get_if<ExecutableConstruct>(&epc.u)}) {
+    return std::holds_alternative<common::Indirection<BlockConstruct>>(ec->u);
+  } else {
+    return false;
+  }
+}
+
+struct StrictlyStructuredBlockParser {
+  using resultType = Block;
+
+  std::optional<resultType> Parse(ParseState &state) const {
+    if (auto epc{Parser<ExecutionPartConstruct>{}.Parse(state)}) {
+      if (IsFortranBlockConstruct(*epc)) {
+        Block block;
+        block.emplace_back(std::move(*epc));
+        return std::move(block);
+      }
+    }
+    return std::nullopt;
+  }
+};
+
+struct LooselyStructuredBlockParser {
+  using resultType = Block;
+
+  std::optional<resultType> Parse(ParseState &state) const {
+    Block body;
+    if (auto epc{attempt(Parser<ExecutionPartConstruct>{}).Parse(state)}) {
+      if (!IsFortranBlockConstruct(*epc)) {
+        body.emplace_back(std::move(*epc));
+        if (auto &&blk{attempt(block).Parse(state)}) {
----------------
tblah wrote:

Sorry if this is a silly question - where is `block` defined?

https://github.com/llvm/llvm-project/pull/150298


More information about the flang-commits mailing list