source: src/AST/Print.cpp@ 089b39e1

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