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