[461046f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[0351e9f] | 7 | // Print.cpp -- Print an AST (or sub-tree) to a stream. |
---|
[461046f] | 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Tue May 21 16:20:15 2019 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #include "Print.hpp" |
---|
| 17 | |
---|
| 18 | #include "Decl.hpp" |
---|
| 19 | #include "Expr.hpp" |
---|
| 20 | #include "Stmt.hpp" |
---|
| 21 | #include "Type.hpp" |
---|
| 22 | #include "TypeSubstitution.hpp" |
---|
[b26144d] | 23 | #include "CompilationState.h" |
---|
[461046f] | 24 | |
---|
[a2e758e] | 25 | #include "Common/utility.h" // for group_iterate |
---|
| 26 | |
---|
[5902625] | 27 | using namespace std; |
---|
[461046f] | 28 | |
---|
| 29 | namespace ast { |
---|
| 30 | |
---|
| 31 | template <typename C, typename... T> |
---|
[a8ed717] | 32 | constexpr array<C,sizeof...(T)> make_array(T&&... values) |
---|
[461046f] | 33 | { |
---|
[5902625] | 34 | return array<C,sizeof...(T)>{ |
---|
| 35 | forward<T>(values)... |
---|
[461046f] | 36 | }; |
---|
| 37 | } |
---|
| 38 | |
---|
[e67991f] | 39 | class Printer final : public Visitor { |
---|
[461046f] | 40 | public: |
---|
[5902625] | 41 | ostream & os; |
---|
[461046f] | 42 | Indenter indent; |
---|
[5902625] | 43 | bool short_mode; |
---|
[461046f] | 44 | |
---|
[5902625] | 45 | Printer(ostream & os, Indenter indent, bool short_mode) : os( os ), indent( indent ), short_mode(short_mode) {} |
---|
[461046f] | 46 | |
---|
| 47 | private: |
---|
| 48 | template< typename C > |
---|
| 49 | void printAll( const C & c ) { |
---|
| 50 | for ( const auto & i : c ) { |
---|
| 51 | if ( i ) { |
---|
| 52 | os << indent; |
---|
| 53 | i->accept( *this ); |
---|
| 54 | // need an endl after each element because it's not |
---|
| 55 | // easy to know when each individual item should end |
---|
[5902625] | 56 | os << endl; |
---|
[461046f] | 57 | } // if |
---|
| 58 | } // for |
---|
| 59 | } |
---|
| 60 | |
---|
[20a5977] | 61 | /// call if mandatory field is missing |
---|
| 62 | void undefined() { |
---|
| 63 | os << "UNDEFINED"; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /// call for fields that should be mandatory |
---|
| 67 | void safe_print( const ast::Node * n ) { |
---|
| 68 | if ( n ) n->accept( *this ); |
---|
| 69 | else undefined(); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /// call to print short form. Incorporates features of safe_print() |
---|
[6f4b7f2] | 73 | void short_print( const ast::Decl * n ) { |
---|
[20a5977] | 74 | if ( ! n ) { undefined(); return; } |
---|
| 75 | bool old_short = short_mode; short_mode = true; |
---|
| 76 | n->accept( *this ); |
---|
| 77 | short_mode = old_short; |
---|
| 78 | } |
---|
| 79 | |
---|
[461046f] | 80 | static const char* Names[]; |
---|
| 81 | |
---|
| 82 | struct Names { |
---|
| 83 | static constexpr auto FuncSpecifiers = make_array<const char*>( |
---|
| 84 | "inline", "_Noreturn", "fortran" |
---|
| 85 | ); |
---|
| 86 | |
---|
| 87 | static constexpr auto StorageClasses = make_array<const char*>( |
---|
| 88 | "extern", "static", "auto", "register", "_Thread_local" |
---|
| 89 | ); |
---|
| 90 | |
---|
| 91 | static constexpr auto Qualifiers = make_array<const char*>( |
---|
| 92 | "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" |
---|
| 93 | ); |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | template<typename storage_t, size_t N> |
---|
[5902625] | 97 | void print(const storage_t & storage, const array<const char *, N> & Names ) { |
---|
[461046f] | 98 | if ( storage.any() ) { |
---|
| 99 | for ( size_t i = 0; i < Names.size(); i += 1 ) { |
---|
| 100 | if ( storage[i] ) { |
---|
| 101 | os << Names[i] << ' '; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void print( const ast::Function::Specs & specs ) { |
---|
| 108 | print(specs, Names::FuncSpecifiers); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void print( const ast::Storage::Classes & storage ) { |
---|
| 112 | print(storage, Names::StorageClasses); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void print( const ast::CV::Qualifiers & qualifiers ) { |
---|
| 116 | print(qualifiers, Names::Qualifiers); |
---|
| 117 | } |
---|
| 118 | |
---|
[94b1f718] | 119 | void print( const std::vector<ast::Label> & labels ) { |
---|
| 120 | if ( labels.empty() ) return; |
---|
| 121 | os << indent << "... Labels: {"; |
---|
| 122 | bool isFirst = true; |
---|
| 123 | for ( const Label & l : labels ) { |
---|
| 124 | if ( isFirst ) { isFirst = false; } else { os << ","; } |
---|
| 125 | os << l; |
---|
| 126 | } |
---|
| 127 | os << "}" << endl; |
---|
| 128 | } |
---|
| 129 | |
---|
[20a5977] | 130 | void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) { |
---|
[79c907b] | 131 | if (inferred.data.resnSlots && !inferred.data.resnSlots->empty()) { |
---|
| 132 | os << indent << "with " << inferred.data.resnSlots->size() |
---|
[94b1f718] | 133 | << " pending inference slots" << endl; |
---|
[20a5977] | 134 | } |
---|
[79c907b] | 135 | if (inferred.data.inferParams && !inferred.data.inferParams->empty()) { |
---|
[94b1f718] | 136 | os << indent << "with inferred parameters " << level << ":" << endl; |
---|
[20a5977] | 137 | ++indent; |
---|
[79c907b] | 138 | for ( const auto & i : *inferred.data.inferParams ) { |
---|
[20a5977] | 139 | os << indent; |
---|
[79c907b] | 140 | short_print( i.second.declptr ); |
---|
[94b1f718] | 141 | os << endl; |
---|
[20a5977] | 142 | print( i.second.expr->inferred, level+1 ); |
---|
| 143 | } |
---|
| 144 | --indent; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
[361bf01] | 148 | void print( const ast::FunctionType::ForallList & forall ) { |
---|
[d908563] | 149 | if ( forall.empty() ) return; |
---|
[94b1f718] | 150 | os << "forall" << endl; |
---|
[b0ec971] | 151 | ++indent; |
---|
| 152 | printAll( forall ); |
---|
| 153 | os << indent; |
---|
| 154 | --indent; |
---|
| 155 | } |
---|
| 156 | |
---|
[3e5dd913] | 157 | void print( const ast::FunctionType::AssertionList & assts ) { |
---|
| 158 | if (assts.empty()) return; |
---|
| 159 | os << "with assertions" << endl; |
---|
| 160 | ++indent; |
---|
| 161 | printAll(assts); |
---|
| 162 | os << indent; |
---|
| 163 | --indent; |
---|
| 164 | } |
---|
| 165 | |
---|
[b0ec971] | 166 | void print( const std::vector<ptr<Attribute>> & attrs ) { |
---|
| 167 | if ( attrs.empty() ) return; |
---|
[94b1f718] | 168 | os << "with attributes" << endl; |
---|
[b0ec971] | 169 | ++indent; |
---|
| 170 | printAll( attrs ); |
---|
| 171 | --indent; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | void print( const std::vector<ptr<Expr>> & params ) { |
---|
| 175 | if ( params.empty() ) return; |
---|
[94b1f718] | 176 | os << endl << indent << "... with parameters" << endl; |
---|
[b0ec971] | 177 | ++indent; |
---|
| 178 | printAll( params ); |
---|
| 179 | --indent; |
---|
| 180 | } |
---|
| 181 | |
---|
[5902625] | 182 | void print( const ast::AggregateDecl * node ) { |
---|
[6f4b7f2] | 183 | os << node->typeString() << " " << node->name; |
---|
[a7d50b6] | 184 | |
---|
[6f4b7f2] | 185 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
[5902625] | 186 | os << " " << Linkage::name( node->linkage ); |
---|
[6f4b7f2] | 187 | } |
---|
[a7d50b6] | 188 | |
---|
[6f4b7f2] | 189 | os << " " << (node->body ? "with" : "without") << " body"; |
---|
[5902625] | 190 | |
---|
| 191 | if ( ! node->params.empty() ) { |
---|
| 192 | os << endl << indent << "... with parameters" << endl; |
---|
| 193 | ++indent; |
---|
| 194 | printAll( node->params ); |
---|
| 195 | --indent; |
---|
[6f4b7f2] | 196 | } |
---|
| 197 | |
---|
| 198 | if ( ! short_mode && ! node->members.empty() ) { |
---|
[5902625] | 199 | os << endl << indent << "... with members" << endl; |
---|
| 200 | ++indent; |
---|
| 201 | printAll( node->members ); |
---|
| 202 | --indent; |
---|
[6f4b7f2] | 203 | } |
---|
| 204 | |
---|
| 205 | if ( ! short_mode && ! node->attributes.empty() ) { |
---|
[5902625] | 206 | os << endl << indent << "... with attributes" << endl; |
---|
| 207 | ++indent; |
---|
| 208 | printAll( node->attributes ); |
---|
| 209 | --indent; |
---|
[6f4b7f2] | 210 | } |
---|
| 211 | |
---|
[4559b34] | 212 | auto ptrToEnum = dynamic_cast<const ast::EnumDecl *>(node); |
---|
| 213 | if ( ! short_mode && ptrToEnum && ptrToEnum->base ) { |
---|
| 214 | os << endl << indent << ".. with (enum) base" << endl; |
---|
| 215 | ++indent; |
---|
| 216 | ptrToEnum->base->accept( *this ); |
---|
| 217 | --indent; |
---|
| 218 | } |
---|
| 219 | |
---|
[5902625] | 220 | os << endl; |
---|
| 221 | } |
---|
| 222 | |
---|
[6f4b7f2] | 223 | void preprint( const ast::NamedTypeDecl * node ) { |
---|
[cd6a6ff] | 224 | if ( ! node->name.empty() ) { |
---|
[3e5dd913] | 225 | os << node->name << ": "; |
---|
[cd6a6ff] | 226 | } |
---|
[5902625] | 227 | |
---|
[6f4b7f2] | 228 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
[5902625] | 229 | os << Linkage::name( node->linkage ) << " "; |
---|
[6f4b7f2] | 230 | } |
---|
| 231 | |
---|
[5902625] | 232 | print( node->storage ); |
---|
| 233 | os << node->typeString(); |
---|
[a7d50b6] | 234 | |
---|
[5902625] | 235 | if ( node->base ) { |
---|
| 236 | os << " for "; |
---|
| 237 | ++indent; |
---|
| 238 | node->base->accept( *this ); |
---|
| 239 | --indent; |
---|
[6f4b7f2] | 240 | } |
---|
| 241 | |
---|
[79c907b] | 242 | if ( ! node->assertions.empty() ) { |
---|
[5902625] | 243 | os << endl << indent << "... with assertions" << endl; |
---|
| 244 | ++indent; |
---|
| 245 | printAll( node->assertions ); |
---|
| 246 | --indent; |
---|
[6f4b7f2] | 247 | } |
---|
[5902625] | 248 | } |
---|
[b0ec971] | 249 | |
---|
[20a5977] | 250 | void postprint( const ast::Expr * node ) { |
---|
| 251 | print( node->inferred ); |
---|
| 252 | |
---|
[ef9988b] | 253 | if ( node->result ) { |
---|
[cd6a6ff] | 254 | os << endl << indent << "... with resolved type:" << endl; |
---|
| 255 | ++indent; |
---|
| 256 | os << indent; |
---|
| 257 | node->result->accept( *this ); |
---|
| 258 | --indent; |
---|
[ef9988b] | 259 | } |
---|
| 260 | |
---|
[20a5977] | 261 | if ( node->env ) { |
---|
[94b1f718] | 262 | os << endl << indent << "... with environment:" << endl; |
---|
[20a5977] | 263 | ++indent; |
---|
| 264 | node->env->accept( *this ); |
---|
| 265 | --indent; |
---|
| 266 | } |
---|
[a16e246] | 267 | |
---|
[20a5977] | 268 | if ( node->extension ) { |
---|
[94b1f718] | 269 | os << endl << indent << "... with extension"; |
---|
[20a5977] | 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | void preprint( const ast::Type * node ) { |
---|
| 274 | print( node->qualifiers ); |
---|
| 275 | } |
---|
| 276 | |
---|
[361bf01] | 277 | void preprint( const ast::FunctionType * node ) { |
---|
[20a5977] | 278 | print( node->forall ); |
---|
[3e5dd913] | 279 | print( node->assertions ); |
---|
[20a5977] | 280 | print( node->qualifiers ); |
---|
| 281 | } |
---|
| 282 | |
---|
[98e8b3b] | 283 | void preprint( const ast::BaseInstType * node ) { |
---|
[20a5977] | 284 | print( node->attributes ); |
---|
| 285 | print( node->qualifiers ); |
---|
| 286 | } |
---|
| 287 | |
---|
[461046f] | 288 | public: |
---|
[e67991f] | 289 | virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { |
---|
[6f4b7f2] | 290 | if ( ! node->name.empty() ) os << node->name << ": "; |
---|
[461046f] | 291 | |
---|
[6f4b7f2] | 292 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
[461046f] | 293 | os << Linkage::name( node->linkage ) << " "; |
---|
[6f4b7f2] | 294 | } |
---|
[461046f] | 295 | |
---|
| 296 | print( node->storage ); |
---|
| 297 | |
---|
| 298 | if ( node->type ) { |
---|
| 299 | node->type->accept( *this ); |
---|
| 300 | } else { |
---|
[20a5977] | 301 | os << "untyped entity"; |
---|
[6f4b7f2] | 302 | } |
---|
[461046f] | 303 | |
---|
[6f4b7f2] | 304 | if ( ! short_mode && node->init ) { |
---|
| 305 | ++indent; |
---|
[461046f] | 306 | os << " with initializer (" << ( |
---|
| 307 | node->init->maybeConstructed |
---|
| 308 | ? "maybe constructed" |
---|
| 309 | : "not constructed" |
---|
[6f4b7f2] | 310 | ) << ")" << endl << indent; |
---|
[461046f] | 311 | node->init->accept( *this ); |
---|
| 312 | --indent; |
---|
[5902625] | 313 | os << endl; |
---|
[6f4b7f2] | 314 | } |
---|
[461046f] | 315 | |
---|
[6f4b7f2] | 316 | if ( ! short_mode && ! node->attributes.empty() ) { |
---|
[5902625] | 317 | os << endl << indent << "... with attributes:" << endl; |
---|
[461046f] | 318 | ++indent; |
---|
| 319 | printAll( node->attributes ); |
---|
| 320 | --indent; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | if ( node->bitfieldWidth ) { |
---|
| 324 | os << indent << " with bitfield width "; |
---|
| 325 | node->bitfieldWidth->accept( *this ); |
---|
[6f4b7f2] | 326 | } |
---|
| 327 | |
---|
[461046f] | 328 | return node; |
---|
| 329 | } |
---|
| 330 | |
---|
[e67991f] | 331 | virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { |
---|
[6f4b7f2] | 332 | if ( !node->name.empty() ) os << node->name << ": "; |
---|
| 333 | |
---|
| 334 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
[5902625] | 335 | os << Linkage::name( node->linkage ) << " "; |
---|
[6f4b7f2] | 336 | } |
---|
[5902625] | 337 | |
---|
[6f4b7f2] | 338 | if ( ! short_mode ) printAll( node->attributes ); |
---|
[5902625] | 339 | |
---|
| 340 | print( node->storage ); |
---|
| 341 | print( node->funcSpec ); |
---|
| 342 | |
---|
[451d958] | 343 | |
---|
| 344 | |
---|
| 345 | if ( node->type && node->isTypeFixed ) { |
---|
[5902625] | 346 | node->type->accept( *this ); |
---|
| 347 | } else { |
---|
[451d958] | 348 | if (!node->type_params.empty()) { |
---|
| 349 | os << "forall" << endl; |
---|
| 350 | ++indent; |
---|
| 351 | printAll(node->type_params); |
---|
| 352 | os << indent; |
---|
| 353 | --indent; |
---|
| 354 | |
---|
| 355 | if (!node->assertions.empty()) { |
---|
| 356 | os << "with assertions" << endl; |
---|
| 357 | ++indent; |
---|
| 358 | printAll(node->assertions); |
---|
| 359 | os << indent; |
---|
| 360 | --indent; |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | os << "function" << endl; |
---|
| 365 | if ( ! node->params.empty() ) { |
---|
| 366 | os << indent << "... with parameters" << endl; |
---|
| 367 | ++indent; |
---|
| 368 | printAll( node->params ); |
---|
| 369 | if ( node->type->isVarArgs ) { |
---|
| 370 | os << indent << "and a variable number of other arguments" << endl; |
---|
| 371 | } |
---|
| 372 | --indent; |
---|
| 373 | } else if ( node->type->isVarArgs ) { |
---|
| 374 | os << indent+1 << "accepting unspecified arguments" << endl; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | os << indent << "... returning"; |
---|
| 378 | if ( node->returns.empty() ) { |
---|
| 379 | os << " nothing" << endl; |
---|
| 380 | } else { |
---|
| 381 | os << endl; |
---|
| 382 | ++indent; |
---|
| 383 | printAll( node->returns ); |
---|
| 384 | --indent; |
---|
| 385 | } |
---|
[6f4b7f2] | 386 | } |
---|
[5902625] | 387 | |
---|
[6f4b7f2] | 388 | if ( ! short_mode && node->stmts ) { |
---|
[5902625] | 389 | ++indent; |
---|
[6f4b7f2] | 390 | os << " with body" << endl << indent; |
---|
[5902625] | 391 | node->stmts->accept( *this ); |
---|
| 392 | --indent; |
---|
[6f4b7f2] | 393 | } |
---|
| 394 | |
---|
[461046f] | 395 | return node; |
---|
| 396 | } |
---|
| 397 | |
---|
[e67991f] | 398 | virtual const ast::Decl * visit( const ast::StructDecl * node ) override final { |
---|
[5902625] | 399 | print(node); |
---|
[461046f] | 400 | return node; |
---|
| 401 | } |
---|
| 402 | |
---|
[e67991f] | 403 | virtual const ast::Decl * visit( const ast::UnionDecl * node ) override final { |
---|
[5902625] | 404 | print(node); |
---|
[461046f] | 405 | return node; |
---|
| 406 | } |
---|
| 407 | |
---|
[e67991f] | 408 | virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final { |
---|
[5902625] | 409 | print(node); |
---|
[461046f] | 410 | return node; |
---|
| 411 | } |
---|
| 412 | |
---|
[e67991f] | 413 | virtual const ast::Decl * visit( const ast::TraitDecl * node ) override final { |
---|
[5902625] | 414 | print(node); |
---|
[461046f] | 415 | return node; |
---|
| 416 | } |
---|
| 417 | |
---|
[e67991f] | 418 | virtual const ast::Decl * visit( const ast::TypeDecl * node ) override final { |
---|
[6f4b7f2] | 419 | preprint( node ); |
---|
| 420 | if ( ! short_mode && node->init ) { |
---|
[5902625] | 421 | os << endl << indent << "with type initializer: "; |
---|
| 422 | ++indent; |
---|
| 423 | node->init->accept( *this ); |
---|
| 424 | --indent; |
---|
| 425 | } |
---|
[6f4b7f2] | 426 | |
---|
[461046f] | 427 | return node; |
---|
| 428 | } |
---|
| 429 | |
---|
[e67991f] | 430 | virtual const ast::Decl * visit( const ast::TypedefDecl * node ) override final { |
---|
[6f4b7f2] | 431 | preprint( node ); |
---|
[461046f] | 432 | return node; |
---|
| 433 | } |
---|
| 434 | |
---|
[e67991f] | 435 | virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { |
---|
[6f4b7f2] | 436 | safe_print( node->stmt ); |
---|
[461046f] | 437 | return node; |
---|
| 438 | } |
---|
| 439 | |
---|
[2d019af] | 440 | virtual const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final { |
---|
| 441 | safe_print( node->stmt ); |
---|
| 442 | return node; |
---|
| 443 | } |
---|
| 444 | |
---|
[e67991f] | 445 | virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { |
---|
[5902625] | 446 | os << "Static Assert with condition: "; |
---|
| 447 | ++indent; |
---|
[6f4b7f2] | 448 | safe_print( node->cond ); |
---|
| 449 | os << endl << indent-1 << "and message: "; |
---|
| 450 | safe_print( node->msg ); |
---|
[5902625] | 451 | --indent; |
---|
| 452 | os << endl; |
---|
[6f4b7f2] | 453 | |
---|
[461046f] | 454 | return node; |
---|
| 455 | } |
---|
| 456 | |
---|
[e67991f] | 457 | virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { |
---|
[94b1f718] | 458 | os << "Compound Statement:" << endl; |
---|
[5902625] | 459 | ++indent; |
---|
| 460 | printAll( node->kids ); |
---|
| 461 | --indent; |
---|
[461046f] | 462 | return node; |
---|
| 463 | } |
---|
| 464 | |
---|
[e67991f] | 465 | virtual const ast::Stmt * visit( const ast::ExprStmt * node ) override final { |
---|
[5902625] | 466 | ++indent; |
---|
| 467 | os << "Expression Statement:" << endl << indent; |
---|
[20a5977] | 468 | safe_print( node->expr ); |
---|
[5902625] | 469 | --indent; |
---|
[461046f] | 470 | return node; |
---|
| 471 | } |
---|
| 472 | |
---|
[e67991f] | 473 | virtual const ast::Stmt * visit( const ast::AsmStmt * node ) override final { |
---|
[5902625] | 474 | os << "Assembler Statement:" << endl; |
---|
| 475 | ++indent; |
---|
[94b1f718] | 476 | os << indent-1 << "instruction:" << endl << indent; |
---|
| 477 | safe_print( node->instruction ); |
---|
[5902625] | 478 | if ( ! node->output.empty() ) { |
---|
[94b1f718] | 479 | os << endl << indent << "output:" << endl; |
---|
[5902625] | 480 | printAll( node->output ); |
---|
| 481 | } // if |
---|
| 482 | if ( ! node->input.empty() ) { |
---|
[94b1f718] | 483 | os << indent << "input:" << endl; |
---|
[5902625] | 484 | printAll( node->input ); |
---|
| 485 | } // if |
---|
| 486 | if ( ! node->clobber.empty() ) { |
---|
[94b1f718] | 487 | os << indent << "clobber:" << endl; |
---|
[5902625] | 488 | printAll( node->clobber ); |
---|
| 489 | } // if |
---|
| 490 | --indent; |
---|
[461046f] | 491 | return node; |
---|
| 492 | } |
---|
| 493 | |
---|
[e67991f] | 494 | virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { |
---|
[94b1f718] | 495 | os << "GCC Directive: " << node->directive << endl; |
---|
[461046f] | 496 | return node; |
---|
| 497 | } |
---|
| 498 | |
---|
[e67991f] | 499 | virtual const ast::Stmt * visit( const ast::IfStmt * node ) override final { |
---|
[94b1f718] | 500 | os << "If on condition:" << endl; |
---|
[5902625] | 501 | ++indent; |
---|
[94b1f718] | 502 | os << indent; |
---|
[20a5977] | 503 | safe_print( node->cond ); |
---|
[5902625] | 504 | --indent; |
---|
| 505 | |
---|
[94b1f718] | 506 | if ( ! node->inits.empty() ) { |
---|
| 507 | os << indent << "... with initialization:" << endl; |
---|
[5902625] | 508 | ++indent; |
---|
[94b1f718] | 509 | for ( const ast::Stmt * stmt : node->inits ) { |
---|
[5902625] | 510 | os << indent; |
---|
[94b1f718] | 511 | safe_print( stmt ); |
---|
[5902625] | 512 | } |
---|
| 513 | --indent; |
---|
| 514 | os << endl; |
---|
| 515 | } |
---|
| 516 | |
---|
[94b1f718] | 517 | os << indent << "... then:" << endl; |
---|
[5902625] | 518 | |
---|
| 519 | ++indent; |
---|
| 520 | os << indent; |
---|
[3b0bc16] | 521 | safe_print( node->then ); |
---|
[5902625] | 522 | --indent; |
---|
| 523 | |
---|
[3b0bc16] | 524 | if ( node->else_ != 0 ) { |
---|
[94b1f718] | 525 | os << indent << "... else:" << endl; |
---|
[5902625] | 526 | ++indent; |
---|
| 527 | os << indent; |
---|
[3b0bc16] | 528 | node->else_->accept( *this ); |
---|
[5902625] | 529 | --indent; |
---|
| 530 | } // if |
---|
[461046f] | 531 | return node; |
---|
| 532 | } |
---|
| 533 | |
---|
[3b0bc16] | 534 | virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { |
---|
[94b1f718] | 535 | if ( node->isDoWhile ) { os << "Do-"; } |
---|
| 536 | os << "While on condition:" << endl; |
---|
| 537 | ++indent; |
---|
| 538 | safe_print( node->cond ); |
---|
| 539 | os << indent-1 << "... with body:" << endl; |
---|
| 540 | safe_print( node->body ); |
---|
| 541 | |
---|
| 542 | if ( ! node->inits.empty() ) { |
---|
| 543 | os << indent-1 << "... with inits:" << endl; |
---|
| 544 | printAll( node->inits ); |
---|
| 545 | } |
---|
| 546 | --indent; |
---|
| 547 | |
---|
[461046f] | 548 | return node; |
---|
| 549 | } |
---|
| 550 | |
---|
[e67991f] | 551 | virtual const ast::Stmt * visit( const ast::ForStmt * node ) override final { |
---|
[94b1f718] | 552 | os << "For Statement" << endl; |
---|
| 553 | |
---|
| 554 | if ( ! node->inits.empty() ) { |
---|
| 555 | os << indent << "... initialization:" << endl; |
---|
| 556 | ++indent; |
---|
| 557 | for ( const ast::Stmt * stmt : node->inits ) { |
---|
| 558 | os << indent+1; |
---|
| 559 | safe_print( stmt ); |
---|
| 560 | } |
---|
| 561 | --indent; |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | if ( node->cond ) { |
---|
| 565 | os << indent << "... condition:" << endl; |
---|
| 566 | ++indent; |
---|
| 567 | os << indent; |
---|
| 568 | node->cond->accept( *this ); |
---|
| 569 | --indent; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | if ( node->inc ) { |
---|
| 573 | os << indent << "... increment:" << endl; |
---|
| 574 | ++indent; |
---|
| 575 | os << indent; |
---|
| 576 | node->inc->accept( *this ); |
---|
| 577 | --indent; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | if ( node->body ) { |
---|
| 581 | os << indent << "... with body:" << endl; |
---|
| 582 | ++indent; |
---|
| 583 | os << indent; |
---|
| 584 | node->body->accept( *this ); |
---|
| 585 | --indent; |
---|
| 586 | } |
---|
| 587 | os << endl; |
---|
| 588 | print( node->labels ); |
---|
| 589 | |
---|
[461046f] | 590 | return node; |
---|
| 591 | } |
---|
| 592 | |
---|
[e67991f] | 593 | virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { |
---|
[94b1f718] | 594 | os << "Switch on condition: "; |
---|
| 595 | safe_print( node->cond ); |
---|
| 596 | os << endl; |
---|
| 597 | |
---|
| 598 | ++indent; |
---|
[400b8be] | 599 | for ( const ast::CaseClause * stmt : node->cases ) { |
---|
[94b1f718] | 600 | stmt->accept( *this ); |
---|
| 601 | } |
---|
| 602 | --indent; |
---|
| 603 | |
---|
[461046f] | 604 | return node; |
---|
| 605 | } |
---|
| 606 | |
---|
[400b8be] | 607 | virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final { |
---|
[94b1f718] | 608 | if ( node->isDefault() ) { |
---|
| 609 | os << indent << "Default "; |
---|
| 610 | } else { |
---|
| 611 | os << indent << "Case "; |
---|
| 612 | safe_print( node->cond ); |
---|
| 613 | } // if |
---|
| 614 | os << endl; |
---|
| 615 | |
---|
| 616 | ++indent; |
---|
| 617 | for ( const ast::Stmt * stmt : node->stmts ) { |
---|
| 618 | os << indent; |
---|
| 619 | stmt->accept( *this ); |
---|
| 620 | } |
---|
| 621 | --indent; |
---|
| 622 | |
---|
[461046f] | 623 | return node; |
---|
| 624 | } |
---|
| 625 | |
---|
[e67991f] | 626 | virtual const ast::Stmt * visit( const ast::BranchStmt * node ) override final { |
---|
[94b1f718] | 627 | os << "Branch (" << node->kindName() << ")" << endl; |
---|
| 628 | ++indent; |
---|
| 629 | if ( ! node->target.empty() ) { |
---|
| 630 | os << indent << "with target: " << node->target << endl; |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | if ( ! node->originalTarget.empty() ) { |
---|
| 634 | os << indent << "with original target: " << node->originalTarget << endl; |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | if ( node->computedTarget ) { |
---|
| 638 | os << indent << "with computed target: "; |
---|
| 639 | node->computedTarget->accept( *this ); |
---|
| 640 | os << endl; |
---|
| 641 | } |
---|
| 642 | --indent; |
---|
| 643 | |
---|
[461046f] | 644 | return node; |
---|
| 645 | } |
---|
| 646 | |
---|
[e67991f] | 647 | virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { |
---|
[94b1f718] | 648 | os << "Return Statement, returning"; |
---|
| 649 | if ( node->expr ) { |
---|
| 650 | ++indent; |
---|
| 651 | os << ":" << endl << indent; |
---|
| 652 | node->expr->accept( *this ); |
---|
| 653 | --indent; |
---|
| 654 | } else { |
---|
| 655 | os << " void"; |
---|
| 656 | } |
---|
| 657 | os << endl; |
---|
| 658 | |
---|
[461046f] | 659 | return node; |
---|
| 660 | } |
---|
| 661 | |
---|
[e67991f] | 662 | virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { |
---|
[6f4b7f2] | 663 | if ( node->target ) os << "Non-Local "; |
---|
| 664 | |
---|
| 665 | switch( node->kind ) { |
---|
| 666 | case ast::ExceptionKind::Terminate: os << "Terminate "; break; |
---|
| 667 | case ast::ExceptionKind::Resume: os << "Resume "; break; |
---|
| 668 | } |
---|
| 669 | |
---|
| 670 | ++indent; |
---|
| 671 | os << "Throw Statement, raising: "; |
---|
| 672 | safe_print( node->expr ); |
---|
| 673 | if ( node->target ) { |
---|
| 674 | os << "... at: "; |
---|
| 675 | node->target->accept( *this ); |
---|
| 676 | } |
---|
| 677 | --indent; |
---|
| 678 | |
---|
[461046f] | 679 | return node; |
---|
| 680 | } |
---|
| 681 | |
---|
[e67991f] | 682 | virtual const ast::Stmt * visit( const ast::TryStmt * node ) override final { |
---|
[6f4b7f2] | 683 | ++indent; |
---|
[a7d50b6] | 684 | os << "Try Statement" << endl << indent-1 |
---|
[6f4b7f2] | 685 | << "... with block:" << endl << indent; |
---|
| 686 | safe_print( node->body ); |
---|
| 687 | |
---|
| 688 | os << indent-1 << "... and handlers:" << endl; |
---|
[400b8be] | 689 | for ( const ast::CatchClause * stmt : node->handlers ) { |
---|
[6f4b7f2] | 690 | os << indent; |
---|
| 691 | stmt->accept( *this ); |
---|
| 692 | } |
---|
| 693 | |
---|
| 694 | if ( node->finally ) { |
---|
| 695 | os << indent-1 << "... and finally:" << endl << indent; |
---|
| 696 | node->finally->accept( *this ); |
---|
| 697 | } |
---|
| 698 | --indent; |
---|
| 699 | |
---|
[461046f] | 700 | return node; |
---|
| 701 | } |
---|
| 702 | |
---|
[400b8be] | 703 | virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final { |
---|
[6f4b7f2] | 704 | os << "Catch "; |
---|
| 705 | switch ( node->kind ) { |
---|
| 706 | case ast::ExceptionKind::Terminate: os << "Terminate "; break; |
---|
| 707 | case ast::ExceptionKind::Resume: os << "Resume "; break; |
---|
| 708 | } |
---|
| 709 | os << "Statement" << endl << indent; |
---|
| 710 | |
---|
| 711 | ++indent; |
---|
| 712 | os << "... catching: "; |
---|
| 713 | short_print( node->decl ); |
---|
| 714 | os << endl; |
---|
| 715 | |
---|
| 716 | if ( node->cond ) { |
---|
| 717 | os << indent-1 << "... with conditional:" << endl << indent; |
---|
| 718 | node->cond->accept( *this ); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | os << indent-1 << "... with block:" << endl << indent; |
---|
| 722 | safe_print( node->body ); |
---|
| 723 | --indent; |
---|
[a7d50b6] | 724 | |
---|
[461046f] | 725 | return node; |
---|
| 726 | } |
---|
| 727 | |
---|
[400b8be] | 728 | virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { |
---|
[6f4b7f2] | 729 | os << "Finally Statement" << endl; |
---|
| 730 | os << indent << "... with block:" << endl; |
---|
| 731 | ++indent; |
---|
| 732 | os << indent; |
---|
| 733 | safe_print( node->body ); |
---|
| 734 | --indent; |
---|
| 735 | |
---|
[461046f] | 736 | return node; |
---|
| 737 | } |
---|
| 738 | |
---|
[37cdd97] | 739 | virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final { |
---|
| 740 | os << "Suspend Statement"; |
---|
| 741 | switch (node->type) { |
---|
| 742 | case ast::SuspendStmt::None : os << " with implicit target"; break; |
---|
| 743 | case ast::SuspendStmt::Generator: os << " for generator"; break; |
---|
| 744 | case ast::SuspendStmt::Coroutine: os << " for coroutine"; break; |
---|
| 745 | } |
---|
| 746 | os << endl; |
---|
| 747 | |
---|
| 748 | ++indent; |
---|
| 749 | if(node->then) { |
---|
| 750 | os << indent << " with post statement :" << endl; |
---|
| 751 | safe_print( node->then ); |
---|
| 752 | } |
---|
| 753 | ++indent; |
---|
| 754 | |
---|
| 755 | return node; |
---|
| 756 | } |
---|
| 757 | |
---|
[e67991f] | 758 | virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { |
---|
[6f4b7f2] | 759 | os << "Waitfor Statement" << endl; |
---|
| 760 | indent += 2; |
---|
| 761 | for( const auto & clause : node->clauses ) { |
---|
[f6e6a55] | 762 | clause->accept( *this ); |
---|
| 763 | } |
---|
[a7d50b6] | 764 | |
---|
[f6e6a55] | 765 | if ( node->timeout_time ) { |
---|
| 766 | os << indent-1 << "timeout of:" << endl; |
---|
| 767 | node->timeout_time->accept( *this ); |
---|
[6f4b7f2] | 768 | |
---|
[f6e6a55] | 769 | if ( node->timeout_stmt ) { |
---|
[6f4b7f2] | 770 | os << indent-1 << "... with statment:" << endl; |
---|
[f6e6a55] | 771 | node->timeout_stmt->accept( *this ); |
---|
[6f4b7f2] | 772 | } |
---|
| 773 | |
---|
[f6e6a55] | 774 | if ( node->timeout_cond ) { |
---|
[6f4b7f2] | 775 | os << indent-1 << "... with condition:" << endl; |
---|
[f6e6a55] | 776 | node->timeout_cond->accept( *this ); |
---|
[6f4b7f2] | 777 | } |
---|
| 778 | } |
---|
| 779 | |
---|
[f6e6a55] | 780 | if ( node->else_stmt ) { |
---|
| 781 | os << indent-1 << "else:" << endl; |
---|
| 782 | node->else_stmt->accept( *this ); |
---|
[6f4b7f2] | 783 | |
---|
[f6e6a55] | 784 | if ( node->else_cond ) { |
---|
[6f4b7f2] | 785 | os << indent-1 << "... with condition:" << endl; |
---|
[f6e6a55] | 786 | node->else_cond->accept( *this ); |
---|
[6f4b7f2] | 787 | } |
---|
| 788 | } |
---|
| 789 | |
---|
[f6e6a55] | 790 | return node; |
---|
| 791 | } |
---|
[6f4b7f2] | 792 | |
---|
[f6e6a55] | 793 | virtual const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { |
---|
| 794 | os << indent-1 << "target function: "; |
---|
| 795 | safe_print( node->target_func ); |
---|
| 796 | |
---|
| 797 | if ( !node->target_args.empty() ) { |
---|
| 798 | os << endl << indent-1 << "... with arguments:" << endl; |
---|
| 799 | for( const ast::Expr * arg : node->target_args ) { |
---|
| 800 | arg->accept( *this ); |
---|
[6f4b7f2] | 801 | } |
---|
| 802 | } |
---|
[f6e6a55] | 803 | |
---|
| 804 | if ( node->stmt ) { |
---|
| 805 | os << indent-1 << "... with statment:" << endl; |
---|
| 806 | node->stmt->accept( *this ); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | if ( node->cond ) { |
---|
| 810 | os << indent-1 << "... with condition:" << endl; |
---|
| 811 | node->cond->accept( *this ); |
---|
| 812 | } |
---|
[6f4b7f2] | 813 | |
---|
[461046f] | 814 | return node; |
---|
| 815 | } |
---|
| 816 | |
---|
[e67991f] | 817 | virtual const ast::Decl * visit( const ast::WithStmt * node ) override final { |
---|
[6f4b7f2] | 818 | os << "With statement" << endl; |
---|
| 819 | os << indent << "... with expressions:" << endl; |
---|
| 820 | ++indent; |
---|
| 821 | printAll( node->exprs ); |
---|
| 822 | os << indent-1 << "... with statement:" << endl << indent; |
---|
| 823 | safe_print( node->stmt ); |
---|
| 824 | --indent; |
---|
| 825 | |
---|
[461046f] | 826 | return node; |
---|
| 827 | } |
---|
| 828 | |
---|
[e67991f] | 829 | virtual const ast::NullStmt * visit( const ast::NullStmt * node ) override final { |
---|
[94b1f718] | 830 | os << "Null Statement" << endl; |
---|
| 831 | print( node->labels ); |
---|
| 832 | |
---|
[461046f] | 833 | return node; |
---|
| 834 | } |
---|
| 835 | |
---|
[e67991f] | 836 | virtual const ast::Stmt * visit( const ast::DeclStmt * node ) override final { |
---|
[6f4b7f2] | 837 | os << "Declaration of "; |
---|
| 838 | safe_print( node->decl ); |
---|
| 839 | |
---|
[461046f] | 840 | return node; |
---|
| 841 | } |
---|
| 842 | |
---|
[e67991f] | 843 | virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { |
---|
[6f4b7f2] | 844 | os << "Implicit Ctor Dtor Statement" << endl; |
---|
| 845 | os << indent << "... with Ctor/Dtor: "; |
---|
| 846 | ++indent; |
---|
| 847 | safe_print( node->callStmt ); |
---|
| 848 | --indent; |
---|
| 849 | os << endl; |
---|
| 850 | |
---|
[461046f] | 851 | return node; |
---|
| 852 | } |
---|
| 853 | |
---|
[6cebfef] | 854 | virtual const ast::Stmt * visit( const ast::MutexStmt * node ) override final { |
---|
| 855 | os << "Mutex Statement" << endl; |
---|
| 856 | os << indent << "... with Mutex Parameters: "; |
---|
| 857 | ++indent; |
---|
| 858 | printAll( node->mutexObjs ); |
---|
| 859 | --indent; |
---|
| 860 | os << indent << "... with Statement: "; |
---|
| 861 | ++indent; |
---|
| 862 | safe_print( node->stmt ); |
---|
| 863 | --indent; |
---|
| 864 | os << endl; |
---|
| 865 | |
---|
| 866 | return node; |
---|
| 867 | } |
---|
| 868 | |
---|
[e67991f] | 869 | virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { |
---|
[20a5977] | 870 | ++indent; |
---|
[94b1f718] | 871 | os << "Application of" << endl << indent; |
---|
[20a5977] | 872 | safe_print( node->func ); |
---|
[94b1f718] | 873 | os << endl; |
---|
[20a5977] | 874 | if ( ! node->args.empty() ) { |
---|
[94b1f718] | 875 | os << indent << "... to arguments" << endl; |
---|
[20a5977] | 876 | printAll( node->args ); |
---|
| 877 | } |
---|
| 878 | --indent; |
---|
| 879 | postprint( node ); |
---|
| 880 | |
---|
[461046f] | 881 | return node; |
---|
| 882 | } |
---|
| 883 | |
---|
[e67991f] | 884 | virtual const ast::Expr * visit( const ast::UntypedExpr * node ) override final { |
---|
[20a5977] | 885 | ++indent; |
---|
[94b1f718] | 886 | os << "Applying untyped:" << endl; |
---|
[20a5977] | 887 | os << indent; |
---|
| 888 | safe_print( node->func ); |
---|
[94b1f718] | 889 | os << endl << indent-1 << "...to:" << endl; |
---|
[20a5977] | 890 | printAll( node->args ); |
---|
| 891 | --indent; |
---|
| 892 | postprint( node ); |
---|
| 893 | |
---|
[461046f] | 894 | return node; |
---|
| 895 | } |
---|
| 896 | |
---|
[e67991f] | 897 | virtual const ast::Expr * visit( const ast::NameExpr * node ) override final { |
---|
[20a5977] | 898 | os << "Name: " << node->name; |
---|
| 899 | postprint( node ); |
---|
[d908563] | 900 | |
---|
[461046f] | 901 | return node; |
---|
| 902 | } |
---|
| 903 | |
---|
[e67991f] | 904 | virtual const ast::Expr * visit( const ast::AddressExpr * node ) override final { |
---|
[94b1f718] | 905 | os << "Address of:" << endl; |
---|
[20a5977] | 906 | ++indent; |
---|
| 907 | os << indent; |
---|
| 908 | safe_print( node->arg ); |
---|
| 909 | |
---|
| 910 | --indent; |
---|
| 911 | |
---|
[461046f] | 912 | return node; |
---|
| 913 | } |
---|
| 914 | |
---|
[e67991f] | 915 | virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { |
---|
[20a5977] | 916 | os << "Address of label:" << node->arg; |
---|
| 917 | |
---|
[461046f] | 918 | return node; |
---|
| 919 | } |
---|
| 920 | |
---|
[e67991f] | 921 | virtual const ast::Expr * visit( const ast::CastExpr * node ) override final { |
---|
[20a5977] | 922 | ++indent; |
---|
[a8ed717] | 923 | os << (node->isGenerated ? "Generated" : "Explicit") << " Cast of:" << endl << indent; |
---|
[20a5977] | 924 | safe_print( node->arg ); |
---|
[94b1f718] | 925 | os << endl << indent-1 << "... to:"; |
---|
[20a5977] | 926 | if ( ! node->result ) { |
---|
| 927 | os << " "; |
---|
| 928 | undefined(); |
---|
| 929 | } else if ( node->result->isVoid() ) { |
---|
| 930 | os << " nothing"; |
---|
| 931 | } else { |
---|
[94b1f718] | 932 | os << endl << indent; |
---|
[20a5977] | 933 | node->result->accept( *this ); |
---|
| 934 | } // if |
---|
| 935 | --indent; |
---|
| 936 | postprint( node ); |
---|
| 937 | |
---|
[461046f] | 938 | return node; |
---|
| 939 | } |
---|
| 940 | |
---|
[e67991f] | 941 | virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { |
---|
[20a5977] | 942 | ++indent; |
---|
[94b1f718] | 943 | os << "Keyword Cast of:" << endl << indent; |
---|
[20a5977] | 944 | safe_print( node->arg ); |
---|
| 945 | --indent; |
---|
[94b1f718] | 946 | os << endl << indent << "... to: " << node->targetString(); |
---|
[20a5977] | 947 | postprint( node ); |
---|
| 948 | |
---|
[461046f] | 949 | return node; |
---|
| 950 | } |
---|
| 951 | |
---|
[e67991f] | 952 | virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { |
---|
[20a5977] | 953 | ++indent; |
---|
[94b1f718] | 954 | os << "Virtual Cast of:" << endl << indent; |
---|
[20a5977] | 955 | safe_print( node->arg ); |
---|
[94b1f718] | 956 | os << endl << indent-1 << "... to:"; |
---|
[20a5977] | 957 | if ( ! node->result ) { |
---|
| 958 | os << " unknown"; |
---|
| 959 | } else { |
---|
[94b1f718] | 960 | os << endl << indent; |
---|
[20a5977] | 961 | node->result->accept( *this ); |
---|
| 962 | } |
---|
| 963 | --indent; |
---|
| 964 | postprint( node ); |
---|
| 965 | |
---|
[461046f] | 966 | return node; |
---|
| 967 | } |
---|
| 968 | |
---|
[e67991f] | 969 | virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { |
---|
[20a5977] | 970 | ++indent; |
---|
[94b1f718] | 971 | os << "Untyped Member Expression, with field: " << endl << indent; |
---|
[20a5977] | 972 | safe_print( node->member ); |
---|
[94b1f718] | 973 | os << indent-1 << "... from aggregate:" << endl << indent; |
---|
[20a5977] | 974 | safe_print( node->aggregate ); |
---|
| 975 | --indent; |
---|
| 976 | postprint( node ); |
---|
| 977 | |
---|
[461046f] | 978 | return node; |
---|
| 979 | } |
---|
| 980 | |
---|
[e67991f] | 981 | virtual const ast::Expr * visit( const ast::MemberExpr * node ) override final { |
---|
[20a5977] | 982 | ++indent; |
---|
[94b1f718] | 983 | os << "Member Expression, with field:" << endl << indent; |
---|
[20a5977] | 984 | safe_print( node->member ); |
---|
[94b1f718] | 985 | os << endl << indent-1 << "... from aggregate:" << endl << indent; |
---|
[20a5977] | 986 | safe_print( node->aggregate ); |
---|
| 987 | --indent; |
---|
| 988 | postprint( node ); |
---|
| 989 | |
---|
[461046f] | 990 | return node; |
---|
| 991 | } |
---|
| 992 | |
---|
[e67991f] | 993 | virtual const ast::Expr * visit( const ast::VariableExpr * node ) override final { |
---|
[20a5977] | 994 | os << "Variable Expression: "; |
---|
| 995 | short_print( node->var ); |
---|
| 996 | postprint( node ); |
---|
| 997 | |
---|
[461046f] | 998 | return node; |
---|
| 999 | } |
---|
| 1000 | |
---|
[e67991f] | 1001 | virtual const ast::Expr * visit( const ast::ConstantExpr * node ) override final { |
---|
[20a5977] | 1002 | os << "Constant Expression (" << node->rep; |
---|
| 1003 | if ( node->result ) { |
---|
| 1004 | os << ": "; |
---|
| 1005 | node->result->accept( *this ); |
---|
| 1006 | } |
---|
| 1007 | os << ")"; |
---|
| 1008 | postprint( node ); |
---|
| 1009 | |
---|
[461046f] | 1010 | return node; |
---|
| 1011 | } |
---|
| 1012 | |
---|
[e67991f] | 1013 | virtual const ast::Expr * visit( const ast::SizeofExpr * node ) override final { |
---|
[a16e246] | 1014 | os << "Sizeof Expression on: "; |
---|
| 1015 | ++indent; |
---|
| 1016 | if ( node->type ) node->type->accept( *this ); |
---|
| 1017 | else safe_print( node->expr ); |
---|
| 1018 | --indent; |
---|
| 1019 | postprint( node ); |
---|
| 1020 | |
---|
[461046f] | 1021 | return node; |
---|
| 1022 | } |
---|
| 1023 | |
---|
[e67991f] | 1024 | virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final { |
---|
[a16e246] | 1025 | os << "Alignof Expression on: "; |
---|
| 1026 | ++indent; |
---|
| 1027 | if ( node->type ) node->type->accept( *this ); |
---|
| 1028 | else safe_print( node->expr ); |
---|
| 1029 | --indent; |
---|
| 1030 | postprint( node ); |
---|
[d908563] | 1031 | |
---|
[461046f] | 1032 | return node; |
---|
| 1033 | } |
---|
| 1034 | |
---|
[e67991f] | 1035 | virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { |
---|
[a16e246] | 1036 | os << "Untyped Offsetof Expression on member " << node->member << " of "; |
---|
| 1037 | ++indent; |
---|
| 1038 | safe_print( node->type ); |
---|
| 1039 | --indent; |
---|
| 1040 | postprint( node ); |
---|
| 1041 | |
---|
[461046f] | 1042 | return node; |
---|
| 1043 | } |
---|
| 1044 | |
---|
[e67991f] | 1045 | virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { |
---|
[a16e246] | 1046 | os << "Offsetof Expression on member " << node->member->name << " of "; |
---|
| 1047 | ++indent; |
---|
| 1048 | safe_print( node->type ); |
---|
| 1049 | --indent; |
---|
| 1050 | postprint( node ); |
---|
| 1051 | |
---|
[461046f] | 1052 | return node; |
---|
| 1053 | } |
---|
| 1054 | |
---|
[e67991f] | 1055 | virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { |
---|
[a16e246] | 1056 | os << "Offset Pack Expression on: "; |
---|
| 1057 | ++indent; |
---|
| 1058 | safe_print( node->type ); |
---|
| 1059 | --indent; |
---|
| 1060 | postprint( node ); |
---|
| 1061 | |
---|
[461046f] | 1062 | return node; |
---|
| 1063 | } |
---|
| 1064 | |
---|
[e67991f] | 1065 | virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final { |
---|
[a16e246] | 1066 | os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: "; |
---|
| 1067 | safe_print( node->arg1 ); |
---|
| 1068 | os << " and "; |
---|
| 1069 | safe_print( node->arg2 ); |
---|
| 1070 | postprint( node ); |
---|
| 1071 | |
---|
[461046f] | 1072 | return node; |
---|
| 1073 | } |
---|
| 1074 | |
---|
[e67991f] | 1075 | virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { |
---|
[a16e246] | 1076 | ++indent; |
---|
[94b1f718] | 1077 | os << "Conditional expression on:" << endl << indent; |
---|
[a16e246] | 1078 | safe_print( node->arg1 ); |
---|
[94b1f718] | 1079 | os << indent-1 << "First alternative:" << endl << indent; |
---|
[a16e246] | 1080 | safe_print( node->arg2 ); |
---|
[94b1f718] | 1081 | os << indent-1 << "Second alternative:" << endl << indent; |
---|
[a16e246] | 1082 | safe_print( node->arg3 ); |
---|
| 1083 | --indent; |
---|
| 1084 | postprint( node ); |
---|
| 1085 | |
---|
[461046f] | 1086 | return node; |
---|
| 1087 | } |
---|
| 1088 | |
---|
[e67991f] | 1089 | virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final { |
---|
[a16e246] | 1090 | ++indent; |
---|
[94b1f718] | 1091 | os << "Comma Expression:" << endl << indent; |
---|
[a16e246] | 1092 | safe_print( node->arg1 ); |
---|
[94b1f718] | 1093 | os << endl << indent; |
---|
[a16e246] | 1094 | safe_print( node->arg2 ); |
---|
| 1095 | --indent; |
---|
| 1096 | postprint( node ); |
---|
| 1097 | |
---|
[461046f] | 1098 | return node; |
---|
| 1099 | } |
---|
| 1100 | |
---|
[e67991f] | 1101 | virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final { |
---|
[a16e246] | 1102 | safe_print( node->type ); |
---|
| 1103 | postprint( node ); |
---|
| 1104 | |
---|
[461046f] | 1105 | return node; |
---|
| 1106 | } |
---|
| 1107 | |
---|
[4ec9513] | 1108 | virtual const ast::Expr * visit( const ast::DimensionExpr * node ) override final { |
---|
| 1109 | os << "Type-Sys Value: " << node->name; |
---|
| 1110 | postprint( node ); |
---|
| 1111 | |
---|
| 1112 | return node; |
---|
| 1113 | } |
---|
| 1114 | |
---|
[e67991f] | 1115 | virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final { |
---|
[94b1f718] | 1116 | os << "Asm Expression:" << endl; |
---|
[a16e246] | 1117 | ++indent; |
---|
[665f432] | 1118 | if ( !node->inout.empty() ) os << "[" << node->inout << "] "; |
---|
[a16e246] | 1119 | if ( node->constraint ) node->constraint->accept( *this ); |
---|
| 1120 | if ( node->operand ) node->operand->accept( *this ); |
---|
| 1121 | --indent; |
---|
[d908563] | 1122 | |
---|
[461046f] | 1123 | return node; |
---|
| 1124 | } |
---|
| 1125 | |
---|
[e67991f] | 1126 | virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { |
---|
[a16e246] | 1127 | ++indent; |
---|
[94b1f718] | 1128 | os << "Implicit Copy Constructor Expression:" << endl << indent; |
---|
[a16e246] | 1129 | safe_print( node->callExpr ); |
---|
| 1130 | --indent; |
---|
| 1131 | postprint( node ); |
---|
| 1132 | |
---|
[461046f] | 1133 | return node; |
---|
| 1134 | } |
---|
| 1135 | |
---|
[e67991f] | 1136 | virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { |
---|
[94b1f718] | 1137 | os << "Constructor Expression:" << endl << indent+1; |
---|
[a16e246] | 1138 | indent += 2; |
---|
| 1139 | safe_print( node->callExpr ); |
---|
| 1140 | indent -= 2; |
---|
| 1141 | postprint( node ); |
---|
| 1142 | |
---|
[461046f] | 1143 | return node; |
---|
| 1144 | } |
---|
| 1145 | |
---|
[e67991f] | 1146 | virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { |
---|
[a16e246] | 1147 | ++indent; |
---|
[94b1f718] | 1148 | os << "Compound Literal Expression: " << endl << indent; |
---|
[a16e246] | 1149 | safe_print( node->result ); |
---|
| 1150 | os << indent; |
---|
| 1151 | safe_print( node->init ); |
---|
| 1152 | --indent; |
---|
| 1153 | postprint( node ); |
---|
| 1154 | |
---|
[461046f] | 1155 | return node; |
---|
| 1156 | } |
---|
| 1157 | |
---|
[e67991f] | 1158 | virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final { |
---|
[a16e246] | 1159 | os << "Range Expression: "; |
---|
| 1160 | safe_print( node->low ); |
---|
| 1161 | os << " ... "; |
---|
| 1162 | safe_print( node->high ); |
---|
| 1163 | postprint( node ); |
---|
| 1164 | |
---|
[461046f] | 1165 | return node; |
---|
| 1166 | } |
---|
| 1167 | |
---|
[e67991f] | 1168 | virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { |
---|
[94b1f718] | 1169 | os << "Untyped Tuple:" << endl; |
---|
[a16e246] | 1170 | ++indent; |
---|
| 1171 | printAll( node->exprs ); |
---|
| 1172 | --indent; |
---|
| 1173 | postprint( node ); |
---|
| 1174 | |
---|
[461046f] | 1175 | return node; |
---|
| 1176 | } |
---|
| 1177 | |
---|
[e67991f] | 1178 | virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final { |
---|
[94b1f718] | 1179 | os << "Tuple:" << endl; |
---|
[a16e246] | 1180 | ++indent; |
---|
| 1181 | printAll( node->exprs ); |
---|
| 1182 | --indent; |
---|
| 1183 | postprint( node ); |
---|
| 1184 | |
---|
[461046f] | 1185 | return node; |
---|
| 1186 | } |
---|
| 1187 | |
---|
[e67991f] | 1188 | virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { |
---|
[94b1f718] | 1189 | os << "Tuple Index Expression, with tuple:" << endl; |
---|
[a16e246] | 1190 | ++indent; |
---|
| 1191 | os << indent; |
---|
| 1192 | safe_print( node->tuple ); |
---|
[94b1f718] | 1193 | os << indent << "with index: " << node->index << endl; |
---|
[a16e246] | 1194 | --indent; |
---|
| 1195 | postprint( node ); |
---|
[d908563] | 1196 | |
---|
[461046f] | 1197 | return node; |
---|
| 1198 | } |
---|
| 1199 | |
---|
[e67991f] | 1200 | virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { |
---|
[94b1f718] | 1201 | os << "Tuple Assignment Expression, with stmt expr:" << endl; |
---|
[a16e246] | 1202 | ++indent; |
---|
| 1203 | os << indent; |
---|
| 1204 | safe_print( node->stmtExpr ); |
---|
| 1205 | --indent; |
---|
| 1206 | postprint( node ); |
---|
| 1207 | |
---|
[461046f] | 1208 | return node; |
---|
| 1209 | } |
---|
| 1210 | |
---|
[e67991f] | 1211 | virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final { |
---|
[a16e246] | 1212 | ++indent; |
---|
[94b1f718] | 1213 | os << "Statement Expression:" << endl << indent; |
---|
[a16e246] | 1214 | safe_print( node->stmts ); |
---|
| 1215 | if ( ! node->returnDecls.empty() ) { |
---|
| 1216 | os << indent << "... with returnDecls: "; |
---|
| 1217 | printAll( node->returnDecls ); |
---|
| 1218 | } |
---|
| 1219 | if ( ! node->dtors.empty() ) { |
---|
| 1220 | os << indent << "... with dtors: "; |
---|
| 1221 | printAll( node->dtors ); |
---|
| 1222 | } |
---|
| 1223 | --indent; |
---|
| 1224 | postprint( node ); |
---|
| 1225 | |
---|
[461046f] | 1226 | return node; |
---|
| 1227 | } |
---|
| 1228 | |
---|
[e67991f] | 1229 | virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final { |
---|
[a16e246] | 1230 | ++indent; |
---|
[94b1f718] | 1231 | os << "Unique Expression with id: " << node->id << endl << indent; |
---|
[a16e246] | 1232 | safe_print( node->expr ); |
---|
| 1233 | if ( node->object ) { |
---|
| 1234 | os << indent-1 << "... with decl: "; |
---|
| 1235 | short_print( node->object ); |
---|
| 1236 | } |
---|
| 1237 | --indent; |
---|
| 1238 | postprint( node ); |
---|
| 1239 | |
---|
[461046f] | 1240 | return node; |
---|
| 1241 | } |
---|
| 1242 | |
---|
[e67991f] | 1243 | virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { |
---|
[a16e246] | 1244 | ++indent; |
---|
[94b1f718] | 1245 | os << "Untyped Init Expression" << endl << indent; |
---|
[a16e246] | 1246 | safe_print( node->expr ); |
---|
| 1247 | if ( ! node->initAlts.empty() ) { |
---|
| 1248 | for ( const InitAlternative & alt : node->initAlts ) { |
---|
| 1249 | os << indent << "InitAlternative: "; |
---|
| 1250 | safe_print( alt.type ); |
---|
| 1251 | safe_print( alt.designation ); |
---|
| 1252 | } |
---|
| 1253 | } |
---|
| 1254 | --indent; |
---|
| 1255 | |
---|
[461046f] | 1256 | return node; |
---|
| 1257 | } |
---|
| 1258 | |
---|
[e67991f] | 1259 | virtual const ast::Expr * visit( const ast::InitExpr * node ) override final { |
---|
[a16e246] | 1260 | ++indent; |
---|
[94b1f718] | 1261 | os << "Init Expression" << endl << indent; |
---|
[a16e246] | 1262 | safe_print( node->expr ); |
---|
| 1263 | os << indent << "... with designation: "; |
---|
| 1264 | safe_print( node->designation ); |
---|
| 1265 | --indent; |
---|
| 1266 | |
---|
[461046f] | 1267 | return node; |
---|
| 1268 | } |
---|
| 1269 | |
---|
[e67991f] | 1270 | virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final { |
---|
[a16e246] | 1271 | ++indent; |
---|
[94b1f718] | 1272 | os << "Deleted Expression" << endl << indent; |
---|
[a16e246] | 1273 | safe_print( node->expr ); |
---|
[94b1f718] | 1274 | os << endl << indent << "... deleted by: "; |
---|
[a16e246] | 1275 | safe_print( node->deleteStmt ); |
---|
| 1276 | --indent; |
---|
| 1277 | |
---|
[461046f] | 1278 | return node; |
---|
| 1279 | } |
---|
| 1280 | |
---|
[e67991f] | 1281 | virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { |
---|
[a16e246] | 1282 | ++indent; |
---|
[94b1f718] | 1283 | os << "Default Argument Expression" << endl << indent; |
---|
[a16e246] | 1284 | safe_print( node->expr ); |
---|
| 1285 | --indent; |
---|
| 1286 | |
---|
[461046f] | 1287 | return node; |
---|
| 1288 | } |
---|
| 1289 | |
---|
[e67991f] | 1290 | virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final { |
---|
[a16e246] | 1291 | ++indent; |
---|
[94b1f718] | 1292 | os << "C11 _Generic Expression" << endl << indent; |
---|
[a16e246] | 1293 | safe_print( node->control ); |
---|
[94b1f718] | 1294 | os << endl << indent << "... with associations:" << endl; |
---|
[a16e246] | 1295 | for ( const auto & assoc : node->associations ) { |
---|
| 1296 | os << indent; |
---|
| 1297 | if ( assoc.type ) { |
---|
| 1298 | os << "... type: "; |
---|
| 1299 | assoc.type->accept( *this ); |
---|
[94b1f718] | 1300 | os << endl << indent << "... expression: "; |
---|
[a16e246] | 1301 | safe_print( assoc.expr ); |
---|
| 1302 | } else { |
---|
| 1303 | os << "... default: "; |
---|
| 1304 | safe_print( assoc.expr ); |
---|
| 1305 | } |
---|
[94b1f718] | 1306 | os << endl; |
---|
[a16e246] | 1307 | } |
---|
| 1308 | --indent; |
---|
| 1309 | |
---|
[461046f] | 1310 | return node; |
---|
| 1311 | } |
---|
| 1312 | |
---|
[e67991f] | 1313 | virtual const ast::Type * visit( const ast::VoidType * node ) override final { |
---|
[b0ec971] | 1314 | preprint( node ); |
---|
| 1315 | os << "void"; |
---|
[461046f] | 1316 | return node; |
---|
| 1317 | } |
---|
| 1318 | |
---|
[e67991f] | 1319 | virtual const ast::Type * visit( const ast::BasicType * node ) override final { |
---|
[b0ec971] | 1320 | preprint( node ); |
---|
| 1321 | os << ast::BasicType::typeNames[ node->kind ]; |
---|
[461046f] | 1322 | return node; |
---|
| 1323 | } |
---|
| 1324 | |
---|
[e67991f] | 1325 | virtual const ast::Type * visit( const ast::PointerType * node ) override final { |
---|
[b0ec971] | 1326 | preprint( node ); |
---|
| 1327 | if ( ! node->isArray() ) { |
---|
| 1328 | os << "pointer to "; |
---|
| 1329 | } else { |
---|
| 1330 | os << "decayed "; |
---|
| 1331 | if ( node->isStatic ) { |
---|
| 1332 | os << "static "; |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | if ( node->isVarLen ) { |
---|
| 1336 | os << "variable length array of "; |
---|
| 1337 | } else if ( node->dimension ) { |
---|
| 1338 | os << "array of "; |
---|
| 1339 | node->dimension->accept( *this ); |
---|
| 1340 | os << " "; |
---|
| 1341 | } |
---|
| 1342 | } |
---|
[20a5977] | 1343 | safe_print( node->base ); |
---|
[b0ec971] | 1344 | |
---|
[461046f] | 1345 | return node; |
---|
| 1346 | } |
---|
| 1347 | |
---|
[e67991f] | 1348 | virtual const ast::Type * visit( const ast::ArrayType * node ) override final { |
---|
[b0ec971] | 1349 | preprint( node ); |
---|
| 1350 | if ( node->isStatic ) { |
---|
| 1351 | os << "static "; |
---|
| 1352 | } |
---|
| 1353 | |
---|
| 1354 | if ( node->isVarLen ) { |
---|
| 1355 | os << "variable length array of "; |
---|
| 1356 | } else if ( node->dimension ) { |
---|
| 1357 | os << "array of "; |
---|
| 1358 | } else { |
---|
| 1359 | os << "open array of "; |
---|
| 1360 | } |
---|
| 1361 | |
---|
[20a5977] | 1362 | safe_print( node->base ); |
---|
[b0ec971] | 1363 | |
---|
| 1364 | if ( node->dimension ) { |
---|
| 1365 | os << " with dimension of "; |
---|
| 1366 | node->dimension->accept( *this ); |
---|
| 1367 | } |
---|
| 1368 | |
---|
[461046f] | 1369 | return node; |
---|
| 1370 | } |
---|
| 1371 | |
---|
[e67991f] | 1372 | virtual const ast::Type * visit( const ast::ReferenceType * node ) override final { |
---|
[b0ec971] | 1373 | preprint( node ); |
---|
| 1374 | os << "reference to "; |
---|
[20a5977] | 1375 | safe_print( node->base ); |
---|
[b0ec971] | 1376 | |
---|
[461046f] | 1377 | return node; |
---|
| 1378 | } |
---|
| 1379 | |
---|
[e67991f] | 1380 | virtual const ast::Type * visit( const ast::QualifiedType * node ) override final { |
---|
[b0ec971] | 1381 | preprint( node ); |
---|
| 1382 | ++indent; |
---|
[94b1f718] | 1383 | os << "Qualified Type:" << endl << indent; |
---|
[20a5977] | 1384 | safe_print( node->parent ); |
---|
[94b1f718] | 1385 | os << endl << indent; |
---|
[20a5977] | 1386 | safe_print( node->child ); |
---|
[94b1f718] | 1387 | os << endl; |
---|
[b0ec971] | 1388 | --indent; |
---|
| 1389 | |
---|
[461046f] | 1390 | return node; |
---|
| 1391 | } |
---|
| 1392 | |
---|
[e67991f] | 1393 | virtual const ast::Type * visit( const ast::FunctionType * node ) override final { |
---|
[b0ec971] | 1394 | preprint( node ); |
---|
[d908563] | 1395 | |
---|
[94b1f718] | 1396 | os << "function" << endl; |
---|
[b0ec971] | 1397 | if ( ! node->params.empty() ) { |
---|
[94b1f718] | 1398 | os << indent << "... with parameters" << endl; |
---|
[b0ec971] | 1399 | ++indent; |
---|
| 1400 | printAll( node->params ); |
---|
| 1401 | if ( node->isVarArgs ) { |
---|
[94b1f718] | 1402 | os << indent << "and a variable number of other arguments" << endl; |
---|
[b0ec971] | 1403 | } |
---|
| 1404 | --indent; |
---|
| 1405 | } else if ( node->isVarArgs ) { |
---|
[94b1f718] | 1406 | os << indent+1 << "accepting unspecified arguments" << endl; |
---|
[b0ec971] | 1407 | } |
---|
| 1408 | |
---|
| 1409 | os << indent << "... returning"; |
---|
| 1410 | if ( node->returns.empty() ) { |
---|
[94b1f718] | 1411 | os << " nothing" << endl; |
---|
[b0ec971] | 1412 | } else { |
---|
[94b1f718] | 1413 | os << endl; |
---|
[b0ec971] | 1414 | ++indent; |
---|
| 1415 | printAll( node->returns ); |
---|
| 1416 | --indent; |
---|
| 1417 | } |
---|
| 1418 | |
---|
[461046f] | 1419 | return node; |
---|
| 1420 | } |
---|
| 1421 | |
---|
[e67991f] | 1422 | virtual const ast::Type * visit( const ast::StructInstType * node ) override final { |
---|
[b0ec971] | 1423 | preprint( node ); |
---|
| 1424 | os << "instance of struct " << node->name; |
---|
| 1425 | if ( node->base ) { |
---|
| 1426 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
| 1427 | } |
---|
| 1428 | print( node->params ); |
---|
| 1429 | |
---|
[461046f] | 1430 | return node; |
---|
| 1431 | } |
---|
| 1432 | |
---|
[e67991f] | 1433 | virtual const ast::Type * visit( const ast::UnionInstType * node ) override final { |
---|
[b0ec971] | 1434 | preprint( node ); |
---|
| 1435 | os << "instance of union " << node->name; |
---|
| 1436 | if ( node->base ) { |
---|
| 1437 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
| 1438 | } |
---|
| 1439 | print( node->params ); |
---|
| 1440 | |
---|
[461046f] | 1441 | return node; |
---|
| 1442 | } |
---|
| 1443 | |
---|
[e67991f] | 1444 | virtual const ast::Type * visit( const ast::EnumInstType * node ) override final { |
---|
[b0ec971] | 1445 | preprint( node ); |
---|
| 1446 | os << "instance of enum " << node->name; |
---|
| 1447 | if ( node->base ) { |
---|
| 1448 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
| 1449 | } |
---|
| 1450 | print( node->params ); |
---|
| 1451 | |
---|
[461046f] | 1452 | return node; |
---|
| 1453 | } |
---|
| 1454 | |
---|
[e67991f] | 1455 | virtual const ast::Type * visit( const ast::TraitInstType * node ) override final { |
---|
[b0ec971] | 1456 | preprint( node ); |
---|
| 1457 | os << "instance of trait " << node->name; |
---|
| 1458 | print( node->params ); |
---|
| 1459 | |
---|
[461046f] | 1460 | return node; |
---|
| 1461 | } |
---|
| 1462 | |
---|
[e67991f] | 1463 | virtual const ast::Type * visit( const ast::TypeInstType * node ) override final { |
---|
[b0ec971] | 1464 | preprint( node ); |
---|
[3e5dd913] | 1465 | const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString(); |
---|
[cd6a6ff] | 1466 | os << "instance of type " << _name |
---|
[07de76b] | 1467 | << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)"; |
---|
[b0ec971] | 1468 | print( node->params ); |
---|
| 1469 | |
---|
[461046f] | 1470 | return node; |
---|
| 1471 | } |
---|
| 1472 | |
---|
[e67991f] | 1473 | virtual const ast::Type * visit( const ast::TupleType * node ) override final { |
---|
[b0ec971] | 1474 | preprint( node ); |
---|
[94b1f718] | 1475 | os << "tuple of types" << endl; |
---|
[b0ec971] | 1476 | ++indent; |
---|
| 1477 | printAll( node->types ); |
---|
| 1478 | --indent; |
---|
| 1479 | |
---|
[461046f] | 1480 | return node; |
---|
| 1481 | } |
---|
| 1482 | |
---|
[e67991f] | 1483 | virtual const ast::Type * visit( const ast::TypeofType * node ) override final { |
---|
[b0ec971] | 1484 | preprint( node ); |
---|
| 1485 | if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; } |
---|
| 1486 | os << "type-of expression "; |
---|
[20a5977] | 1487 | safe_print( node->expr ); |
---|
[b0ec971] | 1488 | |
---|
[461046f] | 1489 | return node; |
---|
| 1490 | } |
---|
| 1491 | |
---|
[3945abe] | 1492 | virtual const ast::Type * visit( const ast::VTableType * node ) override final { |
---|
| 1493 | preprint( node ); |
---|
| 1494 | os << "vtable for "; |
---|
| 1495 | safe_print( node->base ); |
---|
| 1496 | |
---|
| 1497 | return node; |
---|
| 1498 | } |
---|
| 1499 | |
---|
[e67991f] | 1500 | virtual const ast::Type * visit( const ast::VarArgsType * node ) override final { |
---|
[b0ec971] | 1501 | preprint( node ); |
---|
| 1502 | os << "builtin var args pack"; |
---|
[461046f] | 1503 | return node; |
---|
| 1504 | } |
---|
| 1505 | |
---|
[e67991f] | 1506 | virtual const ast::Type * visit( const ast::ZeroType * node ) override final { |
---|
[b0ec971] | 1507 | preprint( node ); |
---|
| 1508 | os << "zero_t"; |
---|
[461046f] | 1509 | return node; |
---|
| 1510 | } |
---|
| 1511 | |
---|
[e67991f] | 1512 | virtual const ast::Type * visit( const ast::OneType * node ) override final { |
---|
[b0ec971] | 1513 | preprint( node ); |
---|
| 1514 | os << "one_t"; |
---|
[461046f] | 1515 | return node; |
---|
| 1516 | } |
---|
| 1517 | |
---|
[e67991f] | 1518 | virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final { |
---|
[b0ec971] | 1519 | preprint( node ); |
---|
| 1520 | os << "Global Scope Type"; |
---|
[461046f] | 1521 | return node; |
---|
| 1522 | } |
---|
| 1523 | |
---|
[e67991f] | 1524 | virtual const ast::Designation * visit( const ast::Designation * node ) override final { |
---|
[c957e7f] | 1525 | if ( node->designators.empty() ) return node; |
---|
[94b1f718] | 1526 | os << "... designated by: " << endl; |
---|
[c957e7f] | 1527 | ++indent; |
---|
| 1528 | for ( const ast::Expr * d : node->designators ) { |
---|
| 1529 | os << indent; |
---|
| 1530 | d->accept( *this ); |
---|
[94b1f718] | 1531 | os << endl; |
---|
[c957e7f] | 1532 | } |
---|
| 1533 | --indent; |
---|
[461046f] | 1534 | return node; |
---|
| 1535 | } |
---|
| 1536 | |
---|
[e67991f] | 1537 | virtual const ast::Init * visit( const ast::SingleInit * node ) override final { |
---|
[c957e7f] | 1538 | os << "Simple Initializer: "; |
---|
[20a5977] | 1539 | safe_print( node->value ); |
---|
[461046f] | 1540 | return node; |
---|
| 1541 | } |
---|
| 1542 | |
---|
[e67991f] | 1543 | virtual const ast::Init * visit( const ast::ListInit * node ) override final { |
---|
[94b1f718] | 1544 | os << "Compound initializer: " << endl; |
---|
[c957e7f] | 1545 | ++indent; |
---|
| 1546 | for ( auto p : group_iterate( node->designations, node->initializers ) ) { |
---|
| 1547 | const ast::Designation * d = std::get<0>(p); |
---|
| 1548 | const ast::Init * init = std::get<1>(p); |
---|
| 1549 | os << indent; |
---|
| 1550 | init->accept( *this ); |
---|
[94b1f718] | 1551 | os << endl; |
---|
[c957e7f] | 1552 | if ( ! d->designators.empty() ) { |
---|
| 1553 | os << indent; |
---|
| 1554 | d->accept( *this ); |
---|
| 1555 | } |
---|
| 1556 | } |
---|
| 1557 | --indent; |
---|
[461046f] | 1558 | return node; |
---|
| 1559 | } |
---|
| 1560 | |
---|
[e67991f] | 1561 | virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final { |
---|
[94b1f718] | 1562 | os << "Constructor initializer: " << endl; |
---|
[c957e7f] | 1563 | if ( node->ctor ) { |
---|
| 1564 | os << indent << "... initially constructed with "; |
---|
| 1565 | ++indent; |
---|
| 1566 | node->ctor->accept( *this ); |
---|
| 1567 | --indent; |
---|
| 1568 | } |
---|
| 1569 | |
---|
| 1570 | if ( node->dtor ) { |
---|
| 1571 | os << indent << "... destructed with "; |
---|
| 1572 | ++indent; |
---|
| 1573 | node->dtor->accept( *this ); |
---|
| 1574 | --indent; |
---|
| 1575 | } |
---|
| 1576 | |
---|
| 1577 | if ( node->init ) { |
---|
| 1578 | os << indent << "... with fallback C-style initializer: "; |
---|
| 1579 | ++indent; |
---|
| 1580 | node->init->accept( *this ); |
---|
| 1581 | --indent; |
---|
| 1582 | } |
---|
[461046f] | 1583 | return node; |
---|
| 1584 | } |
---|
| 1585 | |
---|
[e67991f] | 1586 | virtual const ast::Attribute * visit( const ast::Attribute * node ) override final { |
---|
[489bacf] | 1587 | if ( node->empty() ) return node; |
---|
| 1588 | os << "Attribute with name: " << node->name; |
---|
| 1589 | if ( node->params.empty() ) return node; |
---|
[94b1f718] | 1590 | os << " with parameters: " << endl; |
---|
[489bacf] | 1591 | ++indent; |
---|
| 1592 | printAll( node->params ); |
---|
| 1593 | --indent; |
---|
[461046f] | 1594 | return node; |
---|
| 1595 | } |
---|
| 1596 | |
---|
[e67991f] | 1597 | virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { |
---|
[94b1f718] | 1598 | os << indent << "Types:" << endl; |
---|
[76ed81f] | 1599 | for ( const auto& i : *node ) { |
---|
[3e5dd913] | 1600 | os << indent+1 << i.first.typeString() << " -> "; |
---|
[76ed81f] | 1601 | indent += 2; |
---|
[20a5977] | 1602 | safe_print( i.second ); |
---|
[76ed81f] | 1603 | indent -= 2; |
---|
[94b1f718] | 1604 | os << endl; |
---|
[76ed81f] | 1605 | } |
---|
[461046f] | 1606 | return node; |
---|
| 1607 | } |
---|
| 1608 | |
---|
| 1609 | }; |
---|
| 1610 | |
---|
[5902625] | 1611 | void print( ostream & os, const ast::Node * node, Indenter indent ) { |
---|
| 1612 | Printer printer { os, indent, false }; |
---|
| 1613 | node->accept(printer); |
---|
| 1614 | } |
---|
| 1615 | |
---|
[6f4b7f2] | 1616 | void printShort( ostream & os, const ast::Decl * node, Indenter indent ) { |
---|
[5902625] | 1617 | Printer printer { os, indent, true }; |
---|
[461046f] | 1618 | node->accept(printer); |
---|
| 1619 | } |
---|
| 1620 | |
---|
| 1621 | // Annoyingly these needed to be defined out of line to avoid undefined references. |
---|
| 1622 | // The size here needs to be explicit but at least the compiler will produce an error |
---|
| 1623 | // if the wrong size is specified |
---|
[5902625] | 1624 | constexpr array<const char*, 3> Printer::Names::FuncSpecifiers; |
---|
| 1625 | constexpr array<const char*, 5> Printer::Names::StorageClasses; |
---|
| 1626 | constexpr array<const char*, 6> Printer::Names::Qualifiers; |
---|
[461046f] | 1627 | } |
---|