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