diff --git a/flang/include/flang/Lower/DumpEvaluateExpr.h b/flang/include/flang/Lower/DumpEvaluateExpr.h deleted file mode 100644 index 88f53e96a81c2..0000000000000 --- a/flang/include/flang/Lower/DumpEvaluateExpr.h +++ /dev/null @@ -1,212 +0,0 @@ -//===-- Lower/DumpEvaluateExpr.h --------------------------------*- C++ -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef FORTRAN_LOWER_DUMPEVALUATEEXPR_H -#define FORTRAN_LOWER_DUMPEVALUATEEXPR_H - -#include "flang/Evaluate/tools.h" -#include "flang/Lower/Support/Utils.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Twine.h" - -namespace Fortran::lower { - -/// Class to dump Fortran::evaluate::Expr trees out in a user readable way. -/// -/// FIXME: This can be improved to dump more information in some cases. -class DumpEvaluateExpr { -public: - DumpEvaluateExpr() : outs(llvm::errs()) {} - DumpEvaluateExpr(llvm::raw_ostream &str) : outs(str) {} - - template - static void dump(const A &x) { - DumpEvaluateExpr{}.show(x); - } - template - static void dump(llvm::raw_ostream &stream, const A &x) { - DumpEvaluateExpr{stream}.show(x); - } - -private: - template - void show(const Fortran::common::Indirection &x) { - show(x.value()); - } - template - void show(const Fortran::semantics::SymbolRef x) { - show(*x); - } - template - void show(const std::unique_ptr &x) { - show(x.get()); - } - template - void show(const std::shared_ptr &x) { - show(x.get()); - } - template - void show(const A *x) { - if (x) { - show(*x); - return; - } - print("nullptr"); - } - template - void show(const std::optional &x) { - if (x) { - show(*x); - return; - } - print("None"); - } - template - void show(const std::variant &u) { - Fortran::common::visit([&](const auto &v) { show(v); }, u); - } - template - void show(const std::vector &x) { - indent("vector"); - for (const auto &v : x) - show(v); - outdent(); - } - void show(const Fortran::evaluate::BOZLiteralConstant &); - void show(const Fortran::evaluate::NullPointer &); - template - void show(const Fortran::evaluate::Constant &x) { - if constexpr (T::category == Fortran::common::TypeCategory::Derived) { - indent("derived constant"); - for (const auto &map : x.values()) - for (const auto &pair : map) - show(pair.second.value()); - outdent(); - } else { - print("constant"); - } - } - void show(const Fortran::semantics::Symbol &symbol); - void show(const Fortran::evaluate::StaticDataObject &); - void show(const Fortran::evaluate::ImpliedDoIndex &); - void show(const Fortran::evaluate::BaseObject &x); - void show(const Fortran::evaluate::Component &x); - void show(const Fortran::evaluate::NamedEntity &x); - void show(const Fortran::evaluate::TypeParamInquiry &x); - void show(const Fortran::evaluate::Triplet &x); - void show(const Fortran::evaluate::Subscript &x); - void show(const Fortran::evaluate::ArrayRef &x); - void show(const Fortran::evaluate::CoarrayRef &x); - void show(const Fortran::evaluate::DataRef &x); - void show(const Fortran::evaluate::Substring &x); - void show(const Fortran::evaluate::ComplexPart &x); - template - void show(const Fortran::evaluate::Designator &x) { - indent("designator"); - show(x.u); - outdent(); - } - template - void show(const Fortran::evaluate::Variable &x) { - indent("variable"); - show(x.u); - outdent(); - } - void show(const Fortran::evaluate::DescriptorInquiry &x); - void show(const Fortran::evaluate::SpecificIntrinsic &); - void show(const Fortran::evaluate::ProcedureDesignator &x); - void show(const Fortran::evaluate::ActualArgument &x); - void show(const Fortran::evaluate::ProcedureRef &x) { - indent("procedure ref"); - show(x.proc()); - show(x.arguments()); - outdent(); - } - template - void show(const Fortran::evaluate::FunctionRef &x) { - indent("function ref"); - show(x.proc()); - show(x.arguments()); - outdent(); - } - template - void show(const Fortran::evaluate::ArrayConstructorValue &x) { - show(x.u); - } - template - void show(const Fortran::evaluate::ArrayConstructorValues &x) { - indent("array constructor value"); - for (auto &v : x) - show(v); - outdent(); - } - template - void show(const Fortran::evaluate::ImpliedDo &x) { - indent("implied do"); - show(x.lower()); - show(x.upper()); - show(x.stride()); - show(x.values()); - outdent(); - } - void show(const Fortran::semantics::ParamValue &x); - void - show(const Fortran::semantics::DerivedTypeSpec::ParameterMapType::value_type - &x); - void show(const Fortran::semantics::DerivedTypeSpec &x); - void show(const Fortran::evaluate::StructureConstructorValues::value_type &x); - void show(const Fortran::evaluate::StructureConstructor &x); - template - void show(const Fortran::evaluate::Operation &op) { - indent("unary op"); - show(op.left()); - outdent(); - } - template - void show(const Fortran::evaluate::Operation &op) { - indent("binary op"); - show(op.left()); - show(op.right()); - outdent(); - } - void - show(const Fortran::evaluate::Relational &x); - template - void show(const Fortran::evaluate::Expr &x) { - indent("expr T"); - show(x.u); - outdent(); - } - - const char *getIndentString() const; - void print(llvm::Twine s); - void indent(llvm::StringRef s); - void outdent(); - - llvm::raw_ostream &outs; - unsigned level = 0; -}; - -LLVM_DUMP_METHOD void -dumpEvExpr(const Fortran::evaluate::Expr &x); -LLVM_DUMP_METHOD void dumpEvExpr( - const Fortran::evaluate::Expr< - Fortran::evaluate::Type> &x); -LLVM_DUMP_METHOD void dumpEvExpr( - const Fortran::evaluate::Expr< - Fortran::evaluate::Type> &x); -LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::ArrayRef &x); -LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::DataRef &x); -LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::Substring &x); -LLVM_DUMP_METHOD void dumpEvExpr( - const Fortran::evaluate::Designator< - Fortran::evaluate::Type> &x); - -} // namespace Fortran::lower - -#endif // FORTRAN_LOWER_DUMPEVALUATEEXPR_H diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h new file mode 100644 index 0000000000000..54c41300ecf36 --- /dev/null +++ b/flang/include/flang/Semantics/dump-expr.h @@ -0,0 +1,197 @@ +//===-- Semantics/dump-expr.h -----------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_SEMANTICS_DUMPEXPR_H +#define FORTRAN_SEMANTICS_DUMPEXPR_H + +#include "flang/Evaluate/tools.h" +#include "flang/Semantics/symbol.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" + +#include +#include +#include +#include + +namespace Fortran::semantics { + +/// Class to dump evaluate::Expr trees out in a user readable way. +/// +/// FIXME: This can be improved to dump more information in some cases. +class DumpEvaluateExpr { +public: + DumpEvaluateExpr() : outs_(llvm::errs()) {} + DumpEvaluateExpr(llvm::raw_ostream &str) : outs_(str) {} + + template static void Dump(const A &x) { + DumpEvaluateExpr{}.Show(x); + } + template + static void Dump(llvm::raw_ostream &stream, const A &x) { + DumpEvaluateExpr{stream}.Show(x); + } + +private: + template void Show(const common::Indirection &x) { + Show(x.value()); + } + template void Show(const SymbolRef x) { Show(*x); } + template void Show(const std::unique_ptr &x) { + Show(x.get()); + } + template void Show(const std::shared_ptr &x) { + Show(x.get()); + } + template void Show(const A *x) { + if (x) { + Show(*x); + return; + } + Print("nullptr"); + } + template void Show(const std::optional &x) { + if (x) { + Show(*x); + return; + } + Print("None"); + } + template void Show(const std::variant &u) { + common::visit([&](const auto &v) { Show(v); }, u); + } + template void Show(const std::vector &x) { + Indent("vector"); + for (const auto &v : x) { + Show(v); + } + Outdent(); + } + void Show(const evaluate::BOZLiteralConstant &); + void Show(const evaluate::NullPointer &); + template void Show(const evaluate::Constant &x) { + if constexpr (T::category == common::TypeCategory::Derived) { + Indent("derived constant"); + for (const auto &map : x.values()) { + for (const auto &pair : map) { + Show(pair.second.value()); + } + } + Outdent(); + } else { + Print("constant"); + } + } + void Show(const Symbol &symbol); + void Show(const evaluate::StaticDataObject &); + void Show(const evaluate::ImpliedDoIndex &); + void Show(const evaluate::BaseObject &x); + void Show(const evaluate::Component &x); + void Show(const evaluate::NamedEntity &x); + void Show(const evaluate::TypeParamInquiry &x); + void Show(const evaluate::Triplet &x); + void Show(const evaluate::Subscript &x); + void Show(const evaluate::ArrayRef &x); + void Show(const evaluate::CoarrayRef &x); + void Show(const evaluate::DataRef &x); + void Show(const evaluate::Substring &x); + void Show(const evaluate::ComplexPart &x); + template void Show(const evaluate::Designator &x) { + Indent("designator"); + Show(x.u); + Outdent(); + } + template void Show(const evaluate::Variable &x) { + Indent("variable"); + Show(x.u); + Outdent(); + } + void Show(const evaluate::DescriptorInquiry &x); + void Show(const evaluate::SpecificIntrinsic &); + void Show(const evaluate::ProcedureDesignator &x); + void Show(const evaluate::ActualArgument &x); + void Show(const evaluate::ProcedureRef &x) { + Indent("procedure ref"); + Show(x.proc()); + Show(x.arguments()); + Outdent(); + } + template void Show(const evaluate::FunctionRef &x) { + Indent("function ref"); + Show(x.proc()); + Show(x.arguments()); + Outdent(); + } + template void Show(const evaluate::ArrayConstructorValue &x) { + Show(x.u); + } + template + void Show(const evaluate::ArrayConstructorValues &x) { + Indent("array constructor value"); + for (auto &v : x) { + Show(v); + } + Outdent(); + } + template void Show(const evaluate::ImpliedDo &x) { + Indent("implied do"); + Show(x.lower()); + Show(x.upper()); + Show(x.stride()); + Show(x.values()); + Outdent(); + } + void Show(const ParamValue &x); + void Show(const DerivedTypeSpec::ParameterMapType::value_type &x); + void Show(const DerivedTypeSpec &x); + void Show(const evaluate::StructureConstructorValues::value_type &x); + void Show(const evaluate::StructureConstructor &x); + template + void Show(const evaluate::Operation &op) { + Indent("unary op"); + Show(op.left()); + Outdent(); + } + template + void Show(const evaluate::Operation &op) { + Indent("binary op"); + Show(op.left()); + Show(op.right()); + Outdent(); + } + void Show(const evaluate::Relational &x); + template void Show(const evaluate::Expr &x) { + Indent("expr T"); + Show(x.u); + Outdent(); + } + + const char *GetIndentString() const; + void Print(llvm::Twine s); + void Indent(llvm::StringRef s); + void Outdent(); + + llvm::raw_ostream &outs_; + unsigned level_{0}; +}; + +LLVM_DUMP_METHOD void DumpEvExpr(const evaluate::Expr &x); +LLVM_DUMP_METHOD void DumpEvExpr( + const evaluate::Expr> &x); +LLVM_DUMP_METHOD void DumpEvExpr( + const evaluate::Expr> &x); +LLVM_DUMP_METHOD void DumpEvExpr(const evaluate::ArrayRef &x); +LLVM_DUMP_METHOD void DumpEvExpr(const evaluate::DataRef &x); +LLVM_DUMP_METHOD void DumpEvExpr(const evaluate::Substring &x); +LLVM_DUMP_METHOD void DumpEvExpr( + const evaluate::Designator> + &x); + +} // namespace Fortran::semantics + +#endif // FORTRAN_SEMANTICS_DUMPEXPR_H diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt index 87dc2a052796a..0bd9a47cd040f 100644 --- a/flang/lib/Lower/CMakeLists.txt +++ b/flang/lib/Lower/CMakeLists.txt @@ -16,7 +16,6 @@ add_flang_library(FortranLower ConvertType.cpp ConvertVariable.cpp CustomIntrinsicCall.cpp - DumpEvaluateExpr.cpp HlfirIntrinsics.cpp HostAssociations.cpp IO.cpp diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index b33baf90582b8..b677a136a74aa 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -27,7 +27,6 @@ #include "flang/Lower/ConvertType.h" #include "flang/Lower/ConvertVariable.h" #include "flang/Lower/CustomIntrinsicCall.h" -#include "flang/Lower/DumpEvaluateExpr.h" #include "flang/Lower/Mangler.h" #include "flang/Lower/Runtime.h" #include "flang/Lower/Support/Utils.h" @@ -47,6 +46,7 @@ #include "flang/Optimizer/Dialect/FIROpsSupport.h" #include "flang/Optimizer/Support/FatalError.h" #include "flang/Runtime/support.h" +#include "flang/Semantics/dump-expr.h" #include "flang/Semantics/expression.h" #include "flang/Semantics/symbol.h" #include "flang/Semantics/tools.h" @@ -3925,7 +3925,7 @@ class ArrayExprLowering { /// determine the actual number of iterations when slicing triples are /// present. Lower these expressions here. bool determineShapeWithSlice(const Fortran::lower::SomeExpr &lhs) { - LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump( + LLVM_DEBUG(Fortran::semantics::DumpEvaluateExpr::Dump( llvm::dbgs() << "determine shape of:\n", lhs)); // FIXME: We may not want to use ExtractDataRef here since it doesn't deal // with substrings, etc. @@ -5073,7 +5073,7 @@ class ArrayExprLowering { template CC genarr(const Fortran::evaluate::Expr &x) { - LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump(llvm::dbgs(), x)); + LLVM_DEBUG(Fortran::semantics::DumpEvaluateExpr::Dump(llvm::dbgs(), x)); if (isArray(x) || (explicitSpaceIsActive() && isLeftHandSide()) || isElementalProcWithArrayArgs(x)) return Fortran::common::visit([&](const auto &e) { return genarr(e); }, diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index 91daa6f0ad6ea..dc00e0b13f583 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -21,7 +21,6 @@ #include "flang/Lower/ConvertProcedureDesignator.h" #include "flang/Lower/ConvertType.h" #include "flang/Lower/ConvertVariable.h" -#include "flang/Lower/DumpEvaluateExpr.h" #include "flang/Lower/StatementContext.h" #include "flang/Lower/SymbolMap.h" #include "flang/Optimizer/Builder/Complex.h" diff --git a/flang/lib/Lower/DumpEvaluateExpr.cpp b/flang/lib/Lower/DumpEvaluateExpr.cpp deleted file mode 100644 index 9273e94d702f8..0000000000000 --- a/flang/lib/Lower/DumpEvaluateExpr.cpp +++ /dev/null @@ -1,272 +0,0 @@ -//===-- Lower/DumpEvaluateExpr.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 "flang/Lower/DumpEvaluateExpr.h" -#include - -static constexpr char whiteSpacePadding[] = - ">> "; -static constexpr auto whiteSize = sizeof(whiteSpacePadding) - 1; - -inline const char *Fortran::lower::DumpEvaluateExpr::getIndentString() const { - auto count = (level * 2 >= whiteSize) ? whiteSize : level * 2; - return whiteSpacePadding + whiteSize - count; -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::CoarrayRef &x) { - indent("coarray ref"); - show(x.base()); - show(x.subscript()); - show(x.cosubscript()); - show(x.stat()); - show(x.team()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::BOZLiteralConstant &) { - print("BOZ literal constant"); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::NullPointer &) { - print("null pointer"); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::semantics::Symbol &symbol) { - const auto &ultimate{symbol.GetUltimate()}; - print("symbol: "s + std::string(toStringRef(symbol.name()))); - if (const auto *assoc = - ultimate.detailsIf()) { - indent("assoc details"); - show(assoc->expr()); - outdent(); - } -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::StaticDataObject &) { - print("static data object"); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::ImpliedDoIndex &) { - print("implied do index"); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::BaseObject &x) { - indent("base object"); - show(x.u); - outdent(); -} -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::Component &x) { - indent("component"); - show(x.base()); - show(x.GetLastSymbol()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::NamedEntity &x) { - indent("named entity"); - if (const auto *component = x.UnwrapComponent()) - show(*component); - else - show(x.GetFirstSymbol()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::TypeParamInquiry &x) { - indent("type inquiry"); - show(x.base()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::Triplet &x) { - indent("triplet"); - show(x.lower()); - show(x.upper()); - show(x.stride()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::Subscript &x) { - indent("subscript"); - show(x.u); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::ArrayRef &x) { - indent("array ref"); - show(x.base()); - show(x.subscript()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::DataRef &x) { - indent("data ref"); - show(x.u); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::Substring &x) { - indent("substring"); - show(x.parent()); - show(x.lower()); - show(x.upper()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::semantics::ParamValue &x) { - indent("param value"); - show(x.GetExplicit()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::semantics::DerivedTypeSpec::ParameterMapType::value_type - &x) { - show(x.second); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::semantics::DerivedTypeSpec &x) { - indent("derived type spec"); - for (auto &v : x.parameters()) - show(v); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::StructureConstructorValues::value_type &x) { - show(x.second); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::StructureConstructor &x) { - indent("structure constructor"); - show(x.derivedTypeSpec()); - for (auto &v : x) - show(v); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::Relational &x) { - indent("expr some type"); - show(x.u); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::ComplexPart &x) { - indent("complex part"); - show(x.complex()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::ActualArgument &x) { - indent("actual argument"); - if (const auto *symbol = x.GetAssumedTypeDummy()) - show(*symbol); - else - show(x.UnwrapExpr()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::ProcedureDesignator &x) { - indent("procedure designator"); - if (const auto *component = x.GetComponent()) - show(*component); - else if (const auto *symbol = x.GetSymbol()) - show(*symbol); - else - show(DEREF(x.GetSpecificIntrinsic())); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::SpecificIntrinsic &) { - print("specific intrinsic"); -} - -void Fortran::lower::DumpEvaluateExpr::show( - const Fortran::evaluate::DescriptorInquiry &x) { - indent("descriptor inquiry"); - show(x.base()); - outdent(); -} - -void Fortran::lower::DumpEvaluateExpr::print(llvm::Twine twine) { - outs << getIndentString() << twine << '\n'; -} - -void Fortran::lower::DumpEvaluateExpr::indent(llvm::StringRef s) { - print(s + " {"); - level++; -} - -void Fortran::lower::DumpEvaluateExpr::outdent() { - if (level) - level--; - print("}"); -} - -//===----------------------------------------------------------------------===// -// Boilerplate entry points that the debugger can find. -//===----------------------------------------------------------------------===// - -void Fortran::lower::dumpEvExpr(const Fortran::semantics::SomeExpr &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr( - const Fortran::evaluate::Expr< - Fortran::evaluate::Type> - &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr( - const Fortran::evaluate::Expr< - Fortran::evaluate::Type> - &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr(const Fortran::evaluate::ArrayRef &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr(const Fortran::evaluate::DataRef &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr(const Fortran::evaluate::Substring &x) { - DumpEvaluateExpr::dump(x); -} - -void Fortran::lower::dumpEvExpr( - const Fortran::evaluate::Designator< - Fortran::evaluate::Type> - &x) { - DumpEvaluateExpr::dump(x); -} diff --git a/flang/lib/Semantics/CMakeLists.txt b/flang/lib/Semantics/CMakeLists.txt index 00108dde49dbd..93bf0c7c5facd 100644 --- a/flang/lib/Semantics/CMakeLists.txt +++ b/flang/lib/Semantics/CMakeLists.txt @@ -29,6 +29,7 @@ add_flang_library(FortranSemantics compute-offsets.cpp data-to-inits.cpp definable.cpp + dump-expr.cpp expression.cpp mod-file.cpp openmp-modifiers.cpp diff --git a/flang/lib/Semantics/dump-expr.cpp b/flang/lib/Semantics/dump-expr.cpp new file mode 100644 index 0000000000000..850904bf897b9 --- /dev/null +++ b/flang/lib/Semantics/dump-expr.cpp @@ -0,0 +1,242 @@ +//===-- Semantics/dump-expr.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 "flang/Semantics/dump-expr.h" + +namespace Fortran::semantics { + +static constexpr char whiteSpacePadding[]{ + ">> "}; +static constexpr auto whiteSize{sizeof(whiteSpacePadding) - 1}; + +inline const char *DumpEvaluateExpr::GetIndentString() const { + auto count{(level_ * 2 >= whiteSize) ? whiteSize : level_ * 2}; + return whiteSpacePadding + whiteSize - count; +} + +void DumpEvaluateExpr::Show(const evaluate::CoarrayRef &x) { + Indent("coarray ref"); + Show(x.base()); + Show(x.subscript()); + Show(x.cosubscript()); + Show(x.stat()); + Show(x.team()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::BOZLiteralConstant &) { + Print("BOZ literal constant"); +} + +void DumpEvaluateExpr::Show(const evaluate::NullPointer &) { + Print("null pointer"); +} + +void DumpEvaluateExpr::Show(const Symbol &symbol) { + const auto &ultimate{symbol.GetUltimate()}; + Print("symbol: "s + symbol.name().ToString()); + if (const auto *assoc{ultimate.detailsIf()}) { + Indent("assoc details"); + Show(assoc->expr()); + Outdent(); + } +} + +void DumpEvaluateExpr::Show(const evaluate::StaticDataObject &) { + Print("static data object"); +} + +void DumpEvaluateExpr::Show(const evaluate::ImpliedDoIndex &) { + Print("implied do index"); +} + +void DumpEvaluateExpr::Show(const evaluate::BaseObject &x) { + Indent("base object"); + Show(x.u); + Outdent(); +} +void DumpEvaluateExpr::Show(const evaluate::Component &x) { + Indent("component"); + Show(x.base()); + Show(x.GetLastSymbol()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::NamedEntity &x) { + Indent("named entity"); + if (const auto *component{x.UnwrapComponent()}) { + Show(*component); + } else { + Show(x.GetFirstSymbol()); + } + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::TypeParamInquiry &x) { + Indent("type inquiry"); + Show(x.base()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::Triplet &x) { + Indent("triplet"); + Show(x.lower()); + Show(x.upper()); + Show(x.stride()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::Subscript &x) { + Indent("subscript"); + Show(x.u); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::ArrayRef &x) { + Indent("array ref"); + Show(x.base()); + Show(x.subscript()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::DataRef &x) { + Indent("data ref"); + Show(x.u); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::Substring &x) { + Indent("substring"); + Show(x.parent()); + Show(x.lower()); + Show(x.upper()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const ParamValue &x) { + Indent("param value"); + Show(x.GetExplicit()); + Outdent(); +} + +void DumpEvaluateExpr::Show( + const DerivedTypeSpec::ParameterMapType::value_type &x) { + Show(x.second); +} + +void DumpEvaluateExpr::Show(const DerivedTypeSpec &x) { + Indent("derived type spec"); + for (auto &v : x.parameters()) { + Show(v); + } + Outdent(); +} + +void DumpEvaluateExpr::Show( + const evaluate::StructureConstructorValues::value_type &x) { + Show(x.second); +} + +void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) { + Indent("structure constructor"); + Show(x.derivedTypeSpec()); + for (auto &v : x) { + Show(v); + } + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::Relational &x) { + Indent("expr some type"); + Show(x.u); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::ComplexPart &x) { + Indent("complex part"); + Show(x.complex()); + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::ActualArgument &x) { + Indent("actual argument"); + if (const auto *symbol{x.GetAssumedTypeDummy()}) { + Show(*symbol); + } else { + Show(x.UnwrapExpr()); + } + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::ProcedureDesignator &x) { + Indent("procedure designator"); + if (const auto *component{x.GetComponent()}) { + Show(*component); + } else if (const auto *symbol{x.GetSymbol()}) { + Show(*symbol); + } else { + Show(DEREF(x.GetSpecificIntrinsic())); + } + Outdent(); +} + +void DumpEvaluateExpr::Show(const evaluate::SpecificIntrinsic &) { + Print("specific intrinsic"); +} + +void DumpEvaluateExpr::Show(const evaluate::DescriptorInquiry &x) { + Indent("descriptor inquiry"); + Show(x.base()); + Outdent(); +} + +void DumpEvaluateExpr::Print(llvm::Twine twine) { + outs_ << GetIndentString() << twine << '\n'; +} + +void DumpEvaluateExpr::Indent(llvm::StringRef s) { + Print(s + " {"); + level_++; +} + +void DumpEvaluateExpr::Outdent() { + if (level_) { + level_--; + } + Print("}"); +} + +//===----------------------------------------------------------------------===// +// Boilerplate entry points that the debugger can find. +//===----------------------------------------------------------------------===// + +void DumpEvExpr(const SomeExpr &x) { DumpEvaluateExpr::Dump(x); } + +void DumpEvExpr( + const evaluate::Expr> &x) { + DumpEvaluateExpr::Dump(x); +} + +void DumpEvExpr( + const evaluate::Expr> &x) { + DumpEvaluateExpr::Dump(x); +} + +void DumpEvExpr(const evaluate::ArrayRef &x) { DumpEvaluateExpr::Dump(x); } + +void DumpEvExpr(const evaluate::DataRef &x) { DumpEvaluateExpr::Dump(x); } + +void DumpEvExpr(const evaluate::Substring &x) { DumpEvaluateExpr::Dump(x); } + +void DumpEvExpr( + const evaluate::Designator> + &x) { + DumpEvaluateExpr::Dump(x); +} + +} // namespace Fortran::semantics