From 06f9d7901af20e65635adf8df95eccbc00115c46 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Wed, 18 Apr 2018 16:49:42 -0700 Subject: [PATCH] [flang] Merge parse-tree-mutator.h into parse-tree-visitor.h Use the latter for visiting and mutating and delete the former. Original-commit: flang-compiler/f18@ac5a098ca7187eeb5d5bd2104c8d29363075b368 Reviewed-on: https://github.com/flang-compiler/f18/pull/60 Tree-same-pre-rewrite: false --- flang/lib/parser/parse-tree-mutator.h | 358 ------------------------------ flang/lib/parser/parse-tree-visitor.h | 309 ++++++++++++++++++++++++++ flang/lib/semantics/resolve-names.cc | 2 +- flang/lib/semantics/rewrite-parse-tree.cc | 2 +- 4 files changed, 311 insertions(+), 360 deletions(-) delete mode 100644 flang/lib/parser/parse-tree-mutator.h diff --git a/flang/lib/parser/parse-tree-mutator.h b/flang/lib/parser/parse-tree-mutator.h deleted file mode 100644 index b3aff6d..0000000 --- a/flang/lib/parser/parse-tree-mutator.h +++ /dev/null @@ -1,358 +0,0 @@ -#ifndef FORTRAN_PARSER_PARSE_TREE_MUTATOR_H_ -#define FORTRAN_PARSER_PARSE_TREE_MUTATOR_H_ - -#include "parse-tree.h" -#include -#include -#include -#include -#include - -/// Parse tree mutator -/// Call Walk(x, mutator) to visit x and, by default, each node under x, -/// optionally rewriting it in place. -/// -/// mutator.Pre(x) is called before visiting x and its children are not -/// visited if it returns false. -/// -/// mutator.Post(x) is called after visiting x. - -namespace Fortran { -namespace parser { - -// Default case for visitation of non-class data members and strings -template -typename std::enable_if || - std::is_same_v>::type -Walk(A &x, M &mutator) { - if (mutator.Pre(x)) { - mutator.Post(x); - } -} - -template void Walk(format::ControlEditDesc &, M &); -template void Walk(format::DerivedTypeDataEditDesc &, M &); -template void Walk(format::FormatItem &, M &); -template void Walk(format::FormatSpecification &, M &); -template void Walk(format::IntrinsicTypeDataEditDesc &, M &); - -// Traversal of needed STL template classes (optional, list, tuple, variant) -template -void Walk(std::optional &x, M &mutator) { - if (x) { - Walk(*x, mutator); - } -} -template void Walk(std::list &x, M &mutator) { - for (auto &elem : x) { - Walk(elem, mutator); - } -} -template -void ForEachInTuple(T &tuple, Func func) { - if constexpr (I < std::tuple_size_v) { - func(std::get(tuple)); - ForEachInTuple(tuple, func); - } -} -template -void Walk(std::tuple &x, M &mutator) { - if (mutator.Pre(x)) { - ForEachInTuple(x, [&](auto &y) { Walk(y, mutator); }); - mutator.Post(x); - } -} -template -void Walk(std::variant &x, M &mutator) { - if (mutator.Pre(x)) { - std::visit([&](auto &y) { Walk(y, mutator); }, x); - mutator.Post(x); - } -} -template -void Walk(std::pair &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.first, mutator); - Walk(x.second, mutator); - } -} - -// Trait-determined traversal of empty, tuple, union, and wrapper classes. -template -typename std::enable_if>::type Walk(A &x, M &mutator) { - if (mutator.Pre(x)) { - mutator.Post(x); - } -} - -template -typename std::enable_if>::type Walk(A &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.t, mutator); - mutator.Post(x); - } -} - -template -typename std::enable_if>::type Walk(A &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.u, mutator); - mutator.Post(x); - } -} - -template -typename std::enable_if>::type Walk(A &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.v, mutator); - mutator.Post(x); - } -} - -template -void Walk(Indirection &x, M &mutator) { - Walk(*x, mutator); -} - -// Walk a class with a single field 'thing'. -template void Walk(Scalar &x, M &mutator) { - Walk(x.thing, mutator); -} -template void Walk(Constant &x, M &mutator) { - Walk(x.thing, mutator); -} -template void Walk(Integer &x, M &mutator) { - Walk(x.thing, mutator); -} -template void Walk(Logical &x, M &mutator) { - Walk(x.thing, mutator); -} -template -void Walk(DefaultChar &x, M &mutator) { - Walk(x.thing, mutator); -} - -template void Walk(Statement &x, M &mutator) { - if (mutator.Pre(x)) { - // N.B. the label is not traversed - Walk(x.statement, mutator); - mutator.Post(x); - } -} - -template void Walk(Name &x, M &mutator) { - if (mutator.Pre(x)) { - mutator.Post(x); - } -} - -template void Walk(AcSpec &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.type, mutator); - Walk(x.values, mutator); - mutator.Post(x); - } -} -template void Walk(ArrayElement &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.base, mutator); - Walk(x.subscripts, mutator); - mutator.Post(x); - } -} -template -void Walk(CharSelector::LengthAndKind &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.length, mutator); - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template void Walk(CaseValueRange::Range &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.lower, mutator); - Walk(x.upper, mutator); - mutator.Post(x); - } -} -template void Walk(CoindexedNamedObject &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.base, mutator); - Walk(x.imageSelector, mutator); - mutator.Post(x); - } -} -template -void Walk(DeclarationTypeSpec::Class &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.derived, mutator); - mutator.Post(x); - } -} -template void Walk(DeclarationTypeSpec::Type &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.derived, mutator); - mutator.Post(x); - } -} -template void Walk(ImportStmt &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.names, mutator); - mutator.Post(x); - } -} -template -void Walk(IntrinsicTypeSpec::Character &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.selector, mutator); - mutator.Post(x); - } -} -template -void Walk(IntrinsicTypeSpec::Complex &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template -void Walk(IntrinsicTypeSpec::Logical &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template void Walk(IntrinsicTypeSpec::Real &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template void Walk(LoopBounds &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.name, mutator); - Walk(x.lower, mutator); - Walk(x.upper, mutator); - Walk(x.step, mutator); - mutator.Post(x); - } -} -template void Walk(PartRef &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.name, mutator); - Walk(x.subscripts, mutator); - Walk(x.imageSelector, mutator); - mutator.Post(x); - } -} -template void Walk(ReadStmt &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.iounit, mutator); - Walk(x.format, mutator); - Walk(x.controls, mutator); - Walk(x.items, mutator); - mutator.Post(x); - } -} -template void Walk(RealLiteralConstant &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.real, mutator); - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template void Walk(RealLiteralConstant::Real &x, M &mutator) { - if (mutator.Pre(x)) { - mutator.Post(x); - } -} -template void Walk(StructureComponent &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.base, mutator); - Walk(x.component, mutator); - mutator.Post(x); - } -} -template void Walk(Suffix &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.binding, mutator); - Walk(x.resultName, mutator); - mutator.Post(x); - } -} -template -void Walk(TypeBoundProcedureStmt::WithInterface &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.interfaceName, mutator); - Walk(x.attributes, mutator); - Walk(x.bindingNames, mutator); - mutator.Post(x); - } -} -template -void Walk(TypeBoundProcedureStmt::WithoutInterface &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.attributes, mutator); - Walk(x.declarations, mutator); - mutator.Post(x); - } -} -template void Walk(UseStmt &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.nature, mutator); - Walk(x.moduleName, mutator); - Walk(x.u, mutator); - mutator.Post(x); - } -} -template void Walk(WriteStmt &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.iounit, mutator); - Walk(x.format, mutator); - Walk(x.controls, mutator); - Walk(x.items, mutator); - mutator.Post(x); - } -} -template void Walk(format::ControlEditDesc &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.kind, mutator); - mutator.Post(x); - } -} -template -void Walk(format::DerivedTypeDataEditDesc &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.type, mutator); - Walk(x.parameters, mutator); - mutator.Post(x); - } -} -template void Walk(format::FormatItem &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.repeatCount, mutator); - Walk(x.u, mutator); - mutator.Post(x); - } -} -template -void Walk(format::FormatSpecification &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.items, mutator); - Walk(x.unlimitedItems, mutator); - mutator.Post(x); - } -} -template -void Walk(format::IntrinsicTypeDataEditDesc &x, M &mutator) { - if (mutator.Pre(x)) { - Walk(x.kind, mutator); - Walk(x.width, mutator); - Walk(x.digits, mutator); - Walk(x.exponentWidth, mutator); - mutator.Post(x); - } -} -} // namespace parser -} // namespace Fortran -#endif // FORTRAN_PARSER_PARSE_TREE_MUTATOR_H_ diff --git a/flang/lib/parser/parse-tree-visitor.h b/flang/lib/parser/parse-tree-visitor.h index 26c7c60..cd3bc19 100644 --- a/flang/lib/parser/parse-tree-visitor.h +++ b/flang/lib/parser/parse-tree-visitor.h @@ -10,6 +10,7 @@ /// Parse tree visitor /// Call Walk(x, visitor) to visit x and, by default, each node under x. +/// If x is non-const, the visitor member functions can modify the tree. /// /// visitor.Pre(x) is called before visiting x and its children are not /// visited if it returns false. @@ -28,12 +29,25 @@ Walk(const A &x, V &visitor) { visitor.Post(x); } } +template +typename std::enable_if || + std::is_same_v>::type +Walk(A &x, M &mutator) { + if (mutator.Pre(x)) { + mutator.Post(x); + } +} template void Walk(const format::ControlEditDesc &, V &); +template void Walk(format::ControlEditDesc &, M &); template void Walk(const format::DerivedTypeDataEditDesc &, V &); +template void Walk(format::DerivedTypeDataEditDesc &, M &); template void Walk(const format::FormatItem &, V &); +template void Walk(format::FormatItem &, M &); template void Walk(const format::FormatSpecification &, V &); +template void Walk(format::FormatSpecification &, M &); template void Walk(const format::IntrinsicTypeDataEditDesc &, V &); +template void Walk(format::IntrinsicTypeDataEditDesc &, M &); // Traversal of needed STL template classes (optional, list, tuple, variant) template @@ -42,11 +56,21 @@ void Walk(const std::optional &x, V &visitor) { Walk(*x, visitor); } } +template void Walk(std::optional &x, M &mutator) { + if (x) { + Walk(*x, mutator); + } +} template void Walk(const std::list &x, V &visitor) { for (const auto &elem : x) { Walk(elem, visitor); } } +template void Walk(std::list &x, M &mutator) { + for (auto &elem : x) { + Walk(elem, mutator); + } +} template void ForEachInTuple(const T &tuple, Func func) { if constexpr (I < std::tuple_size_v) { @@ -61,6 +85,19 @@ void Walk(const std::tuple &x, V &visitor) { visitor.Post(x); } } +template +void ForEachInTuple(T &tuple, Func func) { + if constexpr (I < std::tuple_size_v) { + func(std::get(tuple)); + ForEachInTuple(tuple, func); + } +} +template void Walk(std::tuple &x, M &mutator) { + if (mutator.Pre(x)) { + ForEachInTuple(x, [&](auto &y) { Walk(y, mutator); }); + mutator.Post(x); + } +} template void Walk(const std::variant &x, V &visitor) { if (visitor.Pre(x)) { @@ -68,6 +105,13 @@ void Walk(const std::variant &x, V &visitor) { visitor.Post(x); } } +template +void Walk(std::variant &x, M &mutator) { + if (mutator.Pre(x)) { + std::visit([&](auto &y) { Walk(y, mutator); }, x); + mutator.Post(x); + } +} template void Walk(const std::pair &x, V &visitor) { if (visitor.Pre(x)) { @@ -75,6 +119,13 @@ void Walk(const std::pair &x, V &visitor) { Walk(x.second, visitor); } } +template +void Walk(std::pair &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.first, mutator); + Walk(x.second, mutator); + } +} // Trait-determined traversal of empty, tuple, union, and wrapper classes. template @@ -83,6 +134,12 @@ typename std::enable_if>::type Walk(const A &x, V &visitor) { visitor.Post(x); } } +template +typename std::enable_if>::type Walk(A &x, M &mutator) { + if (mutator.Pre(x)) { + mutator.Post(x); + } +} template typename std::enable_if>::type Walk(const A &x, V &visitor) { @@ -91,6 +148,13 @@ typename std::enable_if>::type Walk(const A &x, V &visitor) { visitor.Post(x); } } +template +typename std::enable_if>::type Walk(A &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.t, mutator); + mutator.Post(x); + } +} template typename std::enable_if>::type Walk(const A &x, V &visitor) { @@ -99,6 +163,13 @@ typename std::enable_if>::type Walk(const A &x, V &visitor) { visitor.Post(x); } } +template +typename std::enable_if>::type Walk(A &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.u, mutator); + mutator.Post(x); + } +} template typename std::enable_if>::type Walk(const A &x, V &visitor) { @@ -107,29 +178,54 @@ typename std::enable_if>::type Walk(const A &x, V &visitor) { visitor.Post(x); } } +template +typename std::enable_if>::type Walk(A &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.v, mutator); + mutator.Post(x); + } +} template void Walk(const Indirection &x, V &visitor) { Walk(*x, visitor); } +template void Walk(Indirection &x, M &mutator) { + Walk(*x, mutator); +} // Walk a class with a single field 'thing'. template void Walk(const Scalar &x, V &visitor) { Walk(x.thing, visitor); } +template void Walk(Scalar &x, M &mutator) { + Walk(x.thing, mutator); +} template void Walk(const Constant &x, V &visitor) { Walk(x.thing, visitor); } +template void Walk(Constant &x, M &mutator) { + Walk(x.thing, mutator); +} template void Walk(const Integer &x, V &visitor) { Walk(x.thing, visitor); } +template void Walk(Integer &x, M &mutator) { + Walk(x.thing, mutator); +} template void Walk(const Logical &x, V &visitor) { Walk(x.thing, visitor); } +template void Walk(Logical &x, M &mutator) { + Walk(x.thing, mutator); +} template void Walk(const DefaultChar &x, V &visitor) { Walk(x.thing, visitor); } +template void Walk(DefaultChar &x, M &mutator) { + Walk(x.thing, mutator); +} template void Walk(const Statement &x, V &visitor) { if (visitor.Pre(x)) { @@ -138,12 +234,24 @@ template void Walk(const Statement &x, V &visitor) { visitor.Post(x); } } +template void Walk(Statement &x, M &mutator) { + if (mutator.Pre(x)) { + // N.B. the label is not traversed + Walk(x.statement, mutator); + mutator.Post(x); + } +} template void Walk(const Name &x, V &visitor) { if (visitor.Pre(x)) { visitor.Post(x); } } +template void Walk(Name &x, M &mutator) { + if (mutator.Pre(x)) { + mutator.Post(x); + } +} template void Walk(const AcSpec &x, V &visitor) { if (visitor.Pre(x)) { @@ -152,6 +260,13 @@ template void Walk(const AcSpec &x, V &visitor) { visitor.Post(x); } } +template void Walk(AcSpec &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.type, mutator); + Walk(x.values, mutator); + mutator.Post(x); + } +} template void Walk(const ArrayElement &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.base, visitor); @@ -159,6 +274,13 @@ template void Walk(const ArrayElement &x, V &visitor) { visitor.Post(x); } } +template void Walk(ArrayElement &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.base, mutator); + Walk(x.subscripts, mutator); + mutator.Post(x); + } +} template void Walk(const CharSelector::LengthAndKind &x, V &visitor) { if (visitor.Pre(x)) { @@ -167,6 +289,13 @@ void Walk(const CharSelector::LengthAndKind &x, V &visitor) { visitor.Post(x); } } +template void Walk(CharSelector::LengthAndKind &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.length, mutator); + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const CaseValueRange::Range &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.lower, visitor); @@ -174,6 +303,13 @@ template void Walk(const CaseValueRange::Range &x, V &visitor) { visitor.Post(x); } } +template void Walk(CaseValueRange::Range &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.lower, mutator); + Walk(x.upper, mutator); + mutator.Post(x); + } +} template void Walk(const CoindexedNamedObject &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.base, visitor); @@ -181,6 +317,13 @@ template void Walk(const CoindexedNamedObject &x, V &visitor) { visitor.Post(x); } } +template void Walk(CoindexedNamedObject &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.base, mutator); + Walk(x.imageSelector, mutator); + mutator.Post(x); + } +} template void Walk(const DeclarationTypeSpec::Class &x, V &visitor) { if (visitor.Pre(x)) { @@ -188,18 +331,36 @@ void Walk(const DeclarationTypeSpec::Class &x, V &visitor) { visitor.Post(x); } } +template void Walk(DeclarationTypeSpec::Class &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.derived, mutator); + mutator.Post(x); + } +} template void Walk(const DeclarationTypeSpec::Type &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.derived, visitor); visitor.Post(x); } } +template void Walk(DeclarationTypeSpec::Type &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.derived, mutator); + mutator.Post(x); + } +} template void Walk(const ImportStmt &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.names, visitor); visitor.Post(x); } } +template void Walk(ImportStmt &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.names, mutator); + mutator.Post(x); + } +} template void Walk(const IntrinsicTypeSpec::Character &x, V &visitor) { if (visitor.Pre(x)) { @@ -207,6 +368,12 @@ void Walk(const IntrinsicTypeSpec::Character &x, V &visitor) { visitor.Post(x); } } +template void Walk(IntrinsicTypeSpec::Character &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.selector, mutator); + mutator.Post(x); + } +} template void Walk(const IntrinsicTypeSpec::Complex &x, V &visitor) { if (visitor.Pre(x)) { @@ -214,6 +381,12 @@ void Walk(const IntrinsicTypeSpec::Complex &x, V &visitor) { visitor.Post(x); } } +template void Walk(IntrinsicTypeSpec::Complex &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const IntrinsicTypeSpec::Logical &x, V &visitor) { if (visitor.Pre(x)) { @@ -221,12 +394,24 @@ void Walk(const IntrinsicTypeSpec::Logical &x, V &visitor) { visitor.Post(x); } } +template void Walk(IntrinsicTypeSpec::Logical &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const IntrinsicTypeSpec::Real &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.kind, visitor); visitor.Post(x); } } +template void Walk(IntrinsicTypeSpec::Real &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const LoopBounds &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.name, visitor); @@ -236,6 +421,15 @@ template void Walk(const LoopBounds &x, V &visitor) { visitor.Post(x); } } +template void Walk(LoopBounds &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.name, mutator); + Walk(x.lower, mutator); + Walk(x.upper, mutator); + Walk(x.step, mutator); + mutator.Post(x); + } +} template void Walk(const PartRef &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.name, visitor); @@ -244,6 +438,14 @@ template void Walk(const PartRef &x, V &visitor) { visitor.Post(x); } } +template void Walk(PartRef &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.name, mutator); + Walk(x.subscripts, mutator); + Walk(x.imageSelector, mutator); + mutator.Post(x); + } +} template void Walk(const ReadStmt &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.iounit, visitor); @@ -253,6 +455,15 @@ template void Walk(const ReadStmt &x, V &visitor) { visitor.Post(x); } } +template void Walk(ReadStmt &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.iounit, mutator); + Walk(x.format, mutator); + Walk(x.controls, mutator); + Walk(x.items, mutator); + mutator.Post(x); + } +} template void Walk(const RealLiteralConstant &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.real, visitor); @@ -260,11 +471,23 @@ template void Walk(const RealLiteralConstant &x, V &visitor) { visitor.Post(x); } } +template void Walk(RealLiteralConstant &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.real, mutator); + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const RealLiteralConstant::Real &x, V &visitor) { if (visitor.Pre(x)) { visitor.Post(x); } } +template void Walk(RealLiteralConstant::Real &x, M &mutator) { + if (mutator.Pre(x)) { + mutator.Post(x); + } +} template void Walk(const StructureComponent &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.base, visitor); @@ -272,6 +495,13 @@ template void Walk(const StructureComponent &x, V &visitor) { visitor.Post(x); } } +template void Walk(StructureComponent &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.base, mutator); + Walk(x.component, mutator); + mutator.Post(x); + } +} template void Walk(const Suffix &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.binding, visitor); @@ -279,6 +509,13 @@ template void Walk(const Suffix &x, V &visitor) { visitor.Post(x); } } +template void Walk(Suffix &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.binding, mutator); + Walk(x.resultName, mutator); + mutator.Post(x); + } +} template void Walk(const TypeBoundProcedureStmt::WithInterface &x, V &visitor) { if (visitor.Pre(x)) { @@ -288,6 +525,15 @@ void Walk(const TypeBoundProcedureStmt::WithInterface &x, V &visitor) { visitor.Post(x); } } +template +void Walk(TypeBoundProcedureStmt::WithInterface &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.interfaceName, mutator); + Walk(x.attributes, mutator); + Walk(x.bindingNames, mutator); + mutator.Post(x); + } +} template void Walk(const TypeBoundProcedureStmt::WithoutInterface &x, V &visitor) { if (visitor.Pre(x)) { @@ -296,6 +542,14 @@ void Walk(const TypeBoundProcedureStmt::WithoutInterface &x, V &visitor) { visitor.Post(x); } } +template +void Walk(TypeBoundProcedureStmt::WithoutInterface &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.attributes, mutator); + Walk(x.declarations, mutator); + mutator.Post(x); + } +} template void Walk(const UseStmt &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.nature, visitor); @@ -304,6 +558,14 @@ template void Walk(const UseStmt &x, V &visitor) { visitor.Post(x); } } +template void Walk(UseStmt &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.nature, mutator); + Walk(x.moduleName, mutator); + Walk(x.u, mutator); + mutator.Post(x); + } +} template void Walk(const WriteStmt &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.iounit, visitor); @@ -313,12 +575,27 @@ template void Walk(const WriteStmt &x, V &visitor) { visitor.Post(x); } } +template void Walk(WriteStmt &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.iounit, mutator); + Walk(x.format, mutator); + Walk(x.controls, mutator); + Walk(x.items, mutator); + mutator.Post(x); + } +} template void Walk(const format::ControlEditDesc &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.kind, visitor); visitor.Post(x); } } +template void Walk(format::ControlEditDesc &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.kind, mutator); + mutator.Post(x); + } +} template void Walk(const format::DerivedTypeDataEditDesc &x, V &visitor) { if (visitor.Pre(x)) { @@ -327,6 +604,13 @@ void Walk(const format::DerivedTypeDataEditDesc &x, V &visitor) { visitor.Post(x); } } +template void Walk(format::DerivedTypeDataEditDesc &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.type, mutator); + Walk(x.parameters, mutator); + mutator.Post(x); + } +} template void Walk(const format::FormatItem &x, V &visitor) { if (visitor.Pre(x)) { Walk(x.repeatCount, visitor); @@ -334,6 +618,13 @@ template void Walk(const format::FormatItem &x, V &visitor) { visitor.Post(x); } } +template void Walk(format::FormatItem &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.repeatCount, mutator); + Walk(x.u, mutator); + mutator.Post(x); + } +} template void Walk(const format::FormatSpecification &x, V &visitor) { if (visitor.Pre(x)) { @@ -342,6 +633,13 @@ void Walk(const format::FormatSpecification &x, V &visitor) { visitor.Post(x); } } +template void Walk(format::FormatSpecification &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.items, mutator); + Walk(x.unlimitedItems, mutator); + mutator.Post(x); + } +} template void Walk(const format::IntrinsicTypeDataEditDesc &x, V &visitor) { if (visitor.Pre(x)) { @@ -352,6 +650,17 @@ void Walk(const format::IntrinsicTypeDataEditDesc &x, V &visitor) { visitor.Post(x); } } +template +void Walk(format::IntrinsicTypeDataEditDesc &x, M &mutator) { + if (mutator.Pre(x)) { + Walk(x.kind, mutator); + Walk(x.width, mutator); + Walk(x.digits, mutator); + Walk(x.exponentWidth, mutator); + mutator.Post(x); + } +} + } // namespace parser } // namespace Fortran #endif // FORTRAN_PARSER_PARSE_TREE_VISITOR_H_ diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 0cf5477..5bbc8be 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -1099,7 +1099,7 @@ void ResolveNames( parser::Program &program, const parser::CookedSource &cookedSource) { parser::Messages messages{cookedSource}; ResolveNamesVisitor visitor{messages}; - parser::Walk(program, visitor); + parser::Walk(static_cast(program), visitor); if (!messages.empty()) { messages.Emit(std::cerr); return; diff --git a/flang/lib/semantics/rewrite-parse-tree.cc b/flang/lib/semantics/rewrite-parse-tree.cc index 990a154..62d9ec7 100644 --- a/flang/lib/semantics/rewrite-parse-tree.cc +++ b/flang/lib/semantics/rewrite-parse-tree.cc @@ -2,7 +2,7 @@ #include "scope.h" #include "symbol.h" #include "../parser/indirection.h" -#include "../parser/parse-tree-mutator.h" +#include "../parser/parse-tree-visitor.h" #include "../parser/parse-tree.h" #include -- 2.7.4