source: src/AST/Print.cpp@ 8e2cb4a

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 8e2cb4a was ef9988b, checked in by Fangren Yu <f37yu@…>, 5 years ago

fix lost typeinst in resolved assertions

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