brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.8 KiB · 8d354cf Raw
243 lines · cpp
1//===-- Semantics/dump-expr.cpp -------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang/Semantics/dump-expr.h"10 11namespace Fortran::semantics {12 13static constexpr char whiteSpacePadding[]{14    ">>                                               "};15static constexpr auto whiteSize{sizeof(whiteSpacePadding) - 1};16 17inline const char *DumpEvaluateExpr::GetIndentString() const {18  auto count{(level_ * 2 >= whiteSize) ? whiteSize : level_ * 2};19  return whiteSpacePadding + whiteSize - count;20}21 22void DumpEvaluateExpr::Show(const evaluate::CoarrayRef &x) {23  Indent("coarray ref");24  Show(x.base());25  Show(x.cosubscript());26  Show(x.notify());27  Show(x.stat());28  Show(x.team());29  Outdent();30}31 32void DumpEvaluateExpr::Show(const evaluate::BOZLiteralConstant &) {33  Print("BOZ literal constant");34}35 36void DumpEvaluateExpr::Show(const evaluate::NullPointer &) {37  Print("null pointer");38}39 40void DumpEvaluateExpr::Show(const Symbol &symbol) {41  const auto &ultimate{symbol.GetUltimate()};42  Print("symbol: "s + symbol.name().ToString());43  if (const auto *assoc{ultimate.detailsIf<AssocEntityDetails>()}) {44    Indent("assoc details");45    Show(assoc->expr());46    Outdent();47  }48}49 50void DumpEvaluateExpr::Show(const evaluate::StaticDataObject &) {51  Print("static data object");52}53 54void DumpEvaluateExpr::Show(const evaluate::ImpliedDoIndex &) {55  Print("implied do index");56}57 58void DumpEvaluateExpr::Show(const evaluate::BaseObject &x) {59  Indent("base object");60  Show(x.u);61  Outdent();62}63void DumpEvaluateExpr::Show(const evaluate::Component &x) {64  Indent("component");65  Show(x.base());66  Show(x.GetLastSymbol());67  Outdent();68}69 70void DumpEvaluateExpr::Show(const evaluate::NamedEntity &x) {71  Indent("named entity");72  if (const auto *component{x.UnwrapComponent()}) {73    Show(*component);74  } else {75    Show(x.GetFirstSymbol());76  }77  Outdent();78}79 80void DumpEvaluateExpr::Show(const evaluate::TypeParamInquiry &x) {81  Indent("type inquiry");82  Show(x.base());83  Outdent();84}85 86void DumpEvaluateExpr::Show(const evaluate::Triplet &x) {87  Indent("triplet");88  Show(x.lower());89  Show(x.upper());90  Show(x.stride());91  Outdent();92}93 94void DumpEvaluateExpr::Show(const evaluate::Subscript &x) {95  Indent("subscript");96  Show(x.u);97  Outdent();98}99 100void DumpEvaluateExpr::Show(const evaluate::ArrayRef &x) {101  Indent("array ref");102  Show(x.base());103  Show(x.subscript());104  Outdent();105}106 107void DumpEvaluateExpr::Show(const evaluate::DataRef &x) {108  Indent("data ref");109  Show(x.u);110  Outdent();111}112 113void DumpEvaluateExpr::Show(const evaluate::Substring &x) {114  Indent("substring");115  Show(x.parent());116  Show(x.lower());117  Show(x.upper());118  Outdent();119}120 121void DumpEvaluateExpr::Show(const ParamValue &x) {122  Indent("param value");123  Show(x.GetExplicit());124  Outdent();125}126 127void DumpEvaluateExpr::Show(128    const DerivedTypeSpec::ParameterMapType::value_type &x) {129  Show(x.second);130}131 132void DumpEvaluateExpr::Show(const DerivedTypeSpec &x) {133  Indent("derived type spec");134  for (auto &v : x.parameters()) {135    Show(v);136  }137  Outdent();138}139 140void DumpEvaluateExpr::Show(141    const evaluate::StructureConstructorValues::value_type &x) {142  Show(x.second);143}144 145void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {146  Indent("structure constructor");147  Show(x.derivedTypeSpec());148  for (auto &v : x) {149    Show(v);150  }151  Outdent();152}153 154void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {155  Indent("relational some type");156  Show(x.u);157  Outdent();158}159 160void DumpEvaluateExpr::Show(const evaluate::ComplexPart &x) {161  Indent("complex part");162  Show(x.complex());163  Outdent();164}165 166void DumpEvaluateExpr::Show(const evaluate::ActualArgument &x) {167  Indent("actual argument");168  if (const auto *symbol{x.GetAssumedTypeDummy()}) {169    Show(*symbol);170  } else {171    Show(x.UnwrapExpr());172  }173  Outdent();174}175 176void DumpEvaluateExpr::Show(const evaluate::ProcedureDesignator &x) {177  Indent("procedure designator");178  if (const auto *component{x.GetComponent()}) {179    Show(*component);180  } else if (const auto *symbol{x.GetSymbol()}) {181    Show(*symbol);182  } else {183    Show(DEREF(x.GetSpecificIntrinsic()));184  }185  Outdent();186}187 188void DumpEvaluateExpr::Show(const evaluate::SpecificIntrinsic &) {189  Print("specific intrinsic");190}191 192void DumpEvaluateExpr::Show(const evaluate::DescriptorInquiry &x) {193  Indent("descriptor inquiry");194  Show(x.base());195  Outdent();196}197 198void DumpEvaluateExpr::Print(llvm::Twine twine) {199  outs_ << GetIndentString() << twine << '\n';200}201 202void DumpEvaluateExpr::Indent(llvm::StringRef s) {203  Print(s + " {");204  level_++;205}206 207void DumpEvaluateExpr::Outdent() {208  if (level_) {209    level_--;210  }211  Print("}");212}213 214//===----------------------------------------------------------------------===//215// Boilerplate entry points that the debugger can find.216//===----------------------------------------------------------------------===//217 218void DumpEvExpr(const SomeExpr &x) { DumpEvaluateExpr::Dump(x); }219 220void DumpEvExpr(221    const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 4>> &x) {222  DumpEvaluateExpr::Dump(x);223}224 225void DumpEvExpr(226    const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 8>> &x) {227  DumpEvaluateExpr::Dump(x);228}229 230void DumpEvExpr(const evaluate::ArrayRef &x) { DumpEvaluateExpr::Dump(x); }231 232void DumpEvExpr(const evaluate::DataRef &x) { DumpEvaluateExpr::Dump(x); }233 234void DumpEvExpr(const evaluate::Substring &x) { DumpEvaluateExpr::Dump(x); }235 236void DumpEvExpr(237    const evaluate::Designator<evaluate::Type<common::TypeCategory::Integer, 4>>238        &x) {239  DumpEvaluateExpr::Dump(x);240}241 242} // namespace Fortran::semantics243