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