//===-- lib/Semantics/canonicalize-do.cpp ---------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "canonicalize-do.h" #include "flang/Parser/parse-tree-visitor.h" namespace Fortran::parser { class CanonicalizationOfDoLoops { struct LabelInfo { Block::iterator iter; Label label; }; public: template bool Pre(T &) { return true; } template void Post(T &) {} void Post(Block &block) { std::vector stack; for (auto i{block.begin()}, end{block.end()}; i != end; ++i) { if (auto *executableConstruct{std::get_if(&i->u)}) { std::visit( common::visitors{ [](auto &) {}, // Labels on end-stmt of constructs are accepted by f18 as an // extension. [&](common::Indirection &associate) { CanonicalizeIfMatch(block, stack, i, std::get>( associate.value().t)); }, [&](common::Indirection &blockConstruct) { CanonicalizeIfMatch(block, stack, i, std::get>( blockConstruct.value().t)); }, [&](common::Indirection &changeTeam) { CanonicalizeIfMatch(block, stack, i, std::get>( changeTeam.value().t)); }, [&](common::Indirection &critical) { CanonicalizeIfMatch(block, stack, i, std::get>(critical.value().t)); }, [&](common::Indirection &doConstruct) { CanonicalizeIfMatch(block, stack, i, std::get>(doConstruct.value().t)); }, [&](common::Indirection &ifConstruct) { CanonicalizeIfMatch(block, stack, i, std::get>(ifConstruct.value().t)); }, [&](common::Indirection &caseConstruct) { CanonicalizeIfMatch(block, stack, i, std::get>( caseConstruct.value().t)); }, [&](common::Indirection &selectRank) { CanonicalizeIfMatch(block, stack, i, std::get>(selectRank.value().t)); }, [&](common::Indirection &selectType) { CanonicalizeIfMatch(block, stack, i, std::get>(selectType.value().t)); }, [&](common::Indirection &forall) { CanonicalizeIfMatch(block, stack, i, std::get>(forall.value().t)); }, [&](common::Indirection &where) { CanonicalizeIfMatch(block, stack, i, std::get>(where.value().t)); }, [&](Statement> &labelDoStmt) { auto &label{std::get