Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//===-- Lower/DumpEvaluateExpr.h --------------------------------*- C++ -*-===//
//===-- Semantics/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
#ifndef FORTRAN_SEMANTICS_DUMPEVALUATEEXPR_H
#define FORTRAN_SEMANTICS_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 {
namespace Fortran::semantics {

/// Class to dump Fortran::evaluate::Expr trees out in a user readable way.
///
Expand All @@ -24,8 +23,7 @@ class DumpEvaluateExpr {
DumpEvaluateExpr() : outs(llvm::errs()) {}
DumpEvaluateExpr(llvm::raw_ostream &str) : outs(str) {}

template <typename A>
static void dump(const A &x) {
template <typename A> static void dump(const A &x) {
DumpEvaluateExpr{}.show(x);
}
template <typename A>
Expand All @@ -38,49 +36,41 @@ class DumpEvaluateExpr {
void show(const Fortran::common::Indirection<A, C> &x) {
show(x.value());
}
template <typename A>
void show(const Fortran::semantics::SymbolRef x) {
template <typename A> void show(const Fortran::semantics::SymbolRef x) {
show(*x);
}
template <typename A>
void show(const std::unique_ptr<A> &x) {
template <typename A> void show(const std::unique_ptr<A> &x) {
show(x.get());
}
template <typename A>
void show(const std::shared_ptr<A> &x) {
template <typename A> void show(const std::shared_ptr<A> &x) {
show(x.get());
}
template <typename A>
void show(const A *x) {
template <typename A> void show(const A *x) {
if (x) {
show(*x);
return;
}
print("nullptr");
}
template <typename A>
void show(const std::optional<A> &x) {
template <typename A> void show(const std::optional<A> &x) {
if (x) {
show(*x);
return;
}
print("None");
}
template <typename... A>
void show(const std::variant<A...> &u) {
template <typename... A> void show(const std::variant<A...> &u) {
Fortran::common::visit([&](const auto &v) { show(v); }, u);
}
template <typename A>
void show(const std::vector<A> &x) {
template <typename A> void show(const std::vector<A> &x) {
indent("vector");
for (const auto &v : x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

braces please

show(v);
outdent();
}
void show(const Fortran::evaluate::BOZLiteralConstant &);
void show(const Fortran::evaluate::NullPointer &);
template <typename T>
void show(const Fortran::evaluate::Constant<T> &x) {
template <typename T> void show(const Fortran::evaluate::Constant<T> &x) {
if constexpr (T::category == Fortran::common::TypeCategory::Derived) {
indent("derived constant");
for (const auto &map : x.values())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

braces around loop bodies, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Expand All @@ -105,14 +95,12 @@ class DumpEvaluateExpr {
void show(const Fortran::evaluate::DataRef &x);
void show(const Fortran::evaluate::Substring &x);
void show(const Fortran::evaluate::ComplexPart &x);
template <typename T>
void show(const Fortran::evaluate::Designator<T> &x) {
template <typename T> void show(const Fortran::evaluate::Designator<T> &x) {
indent("designator");
show(x.u);
outdent();
}
template <typename T>
void show(const Fortran::evaluate::Variable<T> &x) {
template <typename T> void show(const Fortran::evaluate::Variable<T> &x) {
indent("variable");
show(x.u);
outdent();
Expand All @@ -127,8 +115,7 @@ class DumpEvaluateExpr {
show(x.arguments());
outdent();
}
template <typename T>
void show(const Fortran::evaluate::FunctionRef<T> &x) {
template <typename T> void show(const Fortran::evaluate::FunctionRef<T> &x) {
indent("function ref");
show(x.proc());
show(x.arguments());
Expand All @@ -145,8 +132,7 @@ class DumpEvaluateExpr {
show(v);
outdent();
}
template <typename T>
void show(const Fortran::evaluate::ImpliedDo<T> &x) {
template <typename T> void show(const Fortran::evaluate::ImpliedDo<T> &x) {
indent("implied do");
show(x.lower());
show(x.upper());
Expand All @@ -155,9 +141,9 @@ class DumpEvaluateExpr {
outdent();
}
void show(const Fortran::semantics::ParamValue &x);
void
show(const Fortran::semantics::DerivedTypeSpec::ParameterMapType::value_type
&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);
Expand All @@ -174,10 +160,9 @@ class DumpEvaluateExpr {
show(op.right());
outdent();
}
void
show(const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &x);
template <typename T>
void show(const Fortran::evaluate::Expr<T> &x) {
void show(
const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &x);
template <typename T> void show(const Fortran::evaluate::Expr<T> &x) {
indent("expr T");
show(x.u);
outdent();
Expand All @@ -192,21 +177,18 @@ class DumpEvaluateExpr {
unsigned level = 0;
};

LLVM_DUMP_METHOD void
dumpEvExpr(const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &x);
LLVM_DUMP_METHOD void dumpEvExpr(
const Fortran::evaluate::Expr<
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> &x);
LLVM_DUMP_METHOD void dumpEvExpr(
const Fortran::evaluate::Expr<
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 8>> &x);
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &x);
LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::Expr<
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> &x);
LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::Expr<
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 8>> &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<Fortran::common::TypeCategory::Integer, 4>> &x);
LLVM_DUMP_METHOD void dumpEvExpr(const Fortran::evaluate::Designator<
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> &x);

} // namespace Fortran::lower
} // namespace Fortran::semantics

#endif // FORTRAN_LOWER_DUMPEVALUATEEXPR_H
#endif // FORTRAN_SEMANTICS_DUMPEVALUATEEXPR_H
1 change: 0 additions & 1 deletion flang/lib/Lower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ add_flang_library(FortranLower
ConvertType.cpp
ConvertVariable.cpp
CustomIntrinsicCall.cpp
DumpEvaluateExpr.cpp
HlfirIntrinsics.cpp
HostAssociations.cpp
IO.cpp
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/Lower/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -5073,7 +5073,7 @@ class ArrayExprLowering {

template <typename A>
CC genarr(const Fortran::evaluate::Expr<A> &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); },
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Lower/ConvertExprToHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading