From 1a38f0091ba2c93f8028bed177cc50a157c44ead Mon Sep 17 00:00:00 2001 From: peter klausler Date: Wed, 6 Mar 2019 14:08:10 -0800 Subject: [PATCH] [flang] More rearrangement Original-commit: flang-compiler/f18@7a675d9df6ac161d68314459b3a54575eda1d354 Reviewed-on: https://github.com/flang-compiler/f18/pull/316 Tree-same-pre-rewrite: false --- flang/lib/evaluate/fold.cc | 8 +- flang/lib/evaluate/traversal-descend.h | 152 --------------------------------- flang/lib/evaluate/traversal.h | 113 +++++++++++++++++++++--- 3 files changed, 106 insertions(+), 167 deletions(-) delete mode 100644 flang/lib/evaluate/traversal-descend.h diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index ee778e8..7f40d96 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -811,23 +811,21 @@ public: void Handle(const semantics::Symbol &symbol) { Check(symbol.attrs().test(semantics::Attr::PARAMETER)); } - void Handle(const CoarrayRef &) { NotConstant(); } + void Handle(const CoarrayRef &) { Return(false); } void Pre(const semantics::ParamValue ¶m) { Check(param.isExplicit()); } template void Pre(const FunctionRef &call) { if (const auto *intrinsic{std::get_if(&call.proc().u)}) { Check(intrinsic->name == "kind"); // TODO: Obviously many other intrinsics can be allowed } else { - NotConstant(); + Return(false); } } private: - void NotConstant() { Return(false); } - void Check(bool ok) { if (!ok) { - NotConstant(); + Return(false); } } }; diff --git a/flang/lib/evaluate/traversal-descend.h b/flang/lib/evaluate/traversal-descend.h deleted file mode 100644 index 23e4888..0000000 --- a/flang/lib/evaluate/traversal-descend.h +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FORTRAN_EVALUATE_TRAVERSAL_DESCEND_H_ -#define FORTRAN_EVALUATE_TRAVERSAL_DESCEND_H_ - -// descend::Descend() is a helper friend function template for -// Traversal::Visit(). Do not use it directly. -namespace Fortran::evaluate::descend { - -template void Descend(V &visitor, const A *p) { - if (p != nullptr) { - visitor.Visit(*p); - } -} -template -void Descend(V &visitor, const std::optional &o) { - if (o.has_value()) { - visitor.Visit(*o); - } -} -template -void Descend(V &visitor, const CopyableIndirection &p) { - visitor.Visit(p.value()); -} -template -void Descend(V &visitor, const std::variant &u) { - std::visit([&](const auto &x) { visitor.Visit(x); }, u); -} -template -void Descend(V &visitor, const std::vector &xs) { - for (const auto &x : xs) { - visitor.Visit(x); - } -} -template void Descend(V &visitor, const Expr &expr) { - visitor.Visit(expr.u); -} -template -void Descend(V &visitor, const Operation &op) { - visitor.Visit(op.left()); - if constexpr (op.operands > 1) { - visitor.Visit(op.right()); - } -} -template -void Descend(V &visitor, const ImpliedDo &ido) { - visitor.Visit(ido.lower()); - visitor.Visit(ido.upper()); - visitor.Visit(ido.stride()); - visitor.Visit(ido.values()); -} -template -void Descend(V &visitor, const ArrayConstructorValue &av) { - visitor.Visit(av.u); -} -template -void Descend(V &visitor, const ArrayConstructorValues &avs) { - visitor.Visit(avs.values()); -} -template -void Descend(V &visitor, - const ArrayConstructor> &ac) { - visitor.Visit( - static_cast>>( - ac)); - visitor.Visit(ac.LEN()); -} -template -void Descend(V &visitor, const semantics::ParamValue ¶m) { - visitor.Visit(param.GetExplicit()); -} -template -void Descend(V &visitor, const semantics::DerivedTypeSpec &derived) { - for (const auto &pair : derived.parameters()) { - visitor.Visit(pair.second); - } -} -template void Descend(V &visitor, const StructureConstructor &sc) { - visitor.Visit(sc.derivedTypeSpec()); - for (const auto &pair : sc.values()) { - visitor.Visit(pair.second); - } -} -template void Descend(V &visitor, const BaseObject &object) { - visitor.Visit(object.u); -} -template void Descend(V &visitor, const Component &component) { - visitor.Visit(component.base()); - visitor.Visit(component.GetLastSymbol()); -} -template -void Descend(V &visitor, const TypeParamInquiry &inq) { - visitor.Visit(inq.base()); - visitor.Visit(inq.parameter()); -} -template void Descend(V &visitor, const Triplet &triplet) { - visitor.Visit(triplet.lower()); - visitor.Visit(triplet.upper()); - visitor.Visit(triplet.stride()); -} -template void Descend(V &visitor, const Subscript &sscript) { - visitor.Visit(sscript.u); -} -template void Descend(V &visitor, const ArrayRef &aref) { - visitor.Visit(aref.base()); - visitor.Visit(aref.subscript()); -} -template void Descend(V &visitor, const CoarrayRef &caref) { - visitor.Visit(caref.base()); - visitor.Visit(caref.subscript()); - visitor.Visit(caref.cosubscript()); - visitor.Visit(caref.stat()); - visitor.Visit(caref.team()); -} -template void Descend(V &visitor, const DataRef &data) { - visitor.Visit(data.u); -} -template void Descend(V &visitor, const ComplexPart &z) { - visitor.Visit(z.complex()); -} -template -void Descend(V &visitor, const Designator &designator) { - visitor.Visit(designator.u); -} -template -void Descend(V &visitor, const Variable &var) { - visitor.Visit(var.u); -} -template void Descend(V &visitor, const ActualArgument &arg) { - visitor.Visit(arg.value()); -} -template void Descend(V &visitor, const ProcedureDesignator &p) { - visitor.Visit(p.u); -} -template void Descend(V &visitor, const ProcedureRef &call) { - visitor.Visit(call.proc()); - visitor.Visit(call.arguments()); -} -} -#endif // FORTRAN_EVALUATE_TRAVERSAL_DESCEND_H_ diff --git a/flang/lib/evaluate/traversal.h b/flang/lib/evaluate/traversal.h index 34a8834..9ce7c01 100644 --- a/flang/lib/evaluate/traversal.h +++ b/flang/lib/evaluate/traversal.h @@ -69,11 +69,6 @@ protected: Result result_; }; -namespace descend { -template -void Descend(VISITOR &, const EXPR &) {} -} - template class Traversal : public virtual TraversalBase, public A... { public: @@ -100,7 +95,7 @@ private: // No visitation class defines Handle(B), so try Pre()/Post(). Pre(x); if (!done_) { - descend::Descend(*this, x); + Descend(x); if (!done_) { Post(x); } @@ -115,10 +110,108 @@ private: } } - template friend void descend::Descend(Traversal &, const B &); + template void Descend(const X &) {} // default case + + template void Descend(const X *p) { + if (p != nullptr) { + Visit(*p); + } + } + template void Descend(const std::optional &o) { + if (o.has_value()) { + Visit(*o); + } + } + template void Descend(const CopyableIndirection &p) { + Visit(p.value()); + } + template void Descend(const std::variant &u) { + std::visit([&](const auto &x) { Visit(x); }, u); + } + template void Descend(const std::vector &xs) { + for (const auto &x : xs) { + Visit(x); + } + } + template void Descend(const Expr &expr) { Visit(expr.u); } + template + void Descend(const Operation &op) { + Visit(op.left()); + if constexpr (op.operands > 1) { + Visit(op.right()); + } + } + template void Descend(const ImpliedDo &ido) { + Visit(ido.lower()); + Visit(ido.upper()); + Visit(ido.stride()); + Visit(ido.values()); + } + template void Descend(const ArrayConstructorValue &av) { + Visit(av.u); + } + template void Descend(const ArrayConstructorValues &avs) { + Visit(avs.values()); + } + template + void Descend( + const ArrayConstructor> &ac) { + Visit(static_cast< + ArrayConstructorValues>>(ac)); + Visit(ac.LEN()); + } + void Descend(const semantics::ParamValue ¶m) { + Visit(param.GetExplicit()); + } + void Descend(const semantics::DerivedTypeSpec &derived) { + for (const auto &pair : derived.parameters()) { + Visit(pair.second); + } + } + void Descend(const StructureConstructor &sc) { + Visit(sc.derivedTypeSpec()); + for (const auto &pair : sc.values()) { + Visit(pair.second); + } + } + void Descend(const BaseObject &object) { Visit(object.u); } + void Descend(const Component &component) { + Visit(component.base()); + Visit(component.GetLastSymbol()); + } + template void Descend(const TypeParamInquiry &inq) { + Visit(inq.base()); + Visit(inq.parameter()); + } + void Descend(const Triplet &triplet) { + Visit(triplet.lower()); + Visit(triplet.upper()); + Visit(triplet.stride()); + } + void Descend(const Subscript &sscript) { Visit(sscript.u); } + void Descend(const ArrayRef &aref) { + Visit(aref.base()); + Visit(aref.subscript()); + } + void Descend(const CoarrayRef &caref) { + Visit(caref.base()); + Visit(caref.subscript()); + Visit(caref.cosubscript()); + Visit(caref.stat()); + Visit(caref.team()); + } + void Descend(const DataRef &data) { Visit(data.u); } + void Descend(const ComplexPart &z) { Visit(z.complex()); } + template void Descend(const Designator &designator) { + Visit(designator.u); + } + template void Descend(const Variable &var) { Visit(var.u); } + void Descend(const ActualArgument &arg) { Visit(arg.value()); } + void Descend(const ProcedureDesignator &p) { Visit(p.u); } + void Descend(const ProcedureRef &call) { + Visit(call.proc()); + Visit(call.arguments()); + } }; } - -// Helper friend function template definitions -#include "traversal-descend.h" #endif // FORTRAN_EVALUATE_TRAVERSAL_H_ -- 2.7.4