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