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