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 -- Print an AST (or sub-tree) to a stream. |
---|
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 "Attribute.hpp" |
---|
19 | #include "Decl.hpp" |
---|
20 | #include "Expr.hpp" |
---|
21 | #include "Init.hpp" |
---|
22 | #include "Stmt.hpp" |
---|
23 | #include "Type.hpp" |
---|
24 | #include "TypeSubstitution.hpp" |
---|
25 | #include "CompilationState.hpp" |
---|
26 | #include "Common/Iterate.hpp" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | namespace ast { |
---|
31 | |
---|
32 | namespace { |
---|
33 | |
---|
34 | template<typename C, typename... T> |
---|
35 | constexpr array<C, sizeof...(T)> make_array( T&&... values ) { |
---|
36 | return array<C, sizeof...(T)>{ std::forward<T>( values )... }; |
---|
37 | } |
---|
38 | |
---|
39 | namespace 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 | |
---|
53 | template<typename bits_t, size_t N> |
---|
54 | void 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 | } |
---|
62 | } |
---|
63 | |
---|
64 | class Printer final : public Visitor { |
---|
65 | public: |
---|
66 | ostream & os; |
---|
67 | Indenter indent; |
---|
68 | bool short_mode; |
---|
69 | |
---|
70 | Printer(ostream & os, Indenter indent, bool short_mode) : os( os ), indent( indent ), short_mode(short_mode) {} |
---|
71 | |
---|
72 | private: |
---|
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 |
---|
81 | os << endl; |
---|
82 | } // if |
---|
83 | } // for |
---|
84 | } |
---|
85 | |
---|
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() |
---|
98 | void short_print( const ast::Decl * n ) { |
---|
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 | |
---|
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 | |
---|
116 | void print( const ast::Expr::InferUnion & inferred, unsigned level = 0 ) { |
---|
117 | if (inferred.data.resnSlots && !inferred.data.resnSlots->empty()) { |
---|
118 | os << indent << "with " << inferred.data.resnSlots->size() |
---|
119 | << " pending inference slots" << endl; |
---|
120 | } |
---|
121 | if (inferred.data.inferParams && !inferred.data.inferParams->empty()) { |
---|
122 | os << indent << "with inferred parameters " << level << ":" << endl; |
---|
123 | ++indent; |
---|
124 | for ( const auto & i : *inferred.data.inferParams ) { |
---|
125 | os << indent; |
---|
126 | short_print( i.second.declptr ); |
---|
127 | os << endl; |
---|
128 | print( i.second.expr->inferred, level+1 ); |
---|
129 | } |
---|
130 | --indent; |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | void print( const ast::FunctionType::ForallList & forall ) { |
---|
135 | if ( forall.empty() ) return; |
---|
136 | os << "forall" << endl; |
---|
137 | ++indent; |
---|
138 | printAll( forall ); |
---|
139 | os << indent; |
---|
140 | --indent; |
---|
141 | } |
---|
142 | |
---|
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 | |
---|
152 | void print( const std::vector<ptr<Attribute>> & attrs ) { |
---|
153 | if ( attrs.empty() ) return; |
---|
154 | os << "with attributes" << endl; |
---|
155 | ++indent; |
---|
156 | printAll( attrs ); |
---|
157 | --indent; |
---|
158 | } |
---|
159 | |
---|
160 | void print( const std::vector<ptr<Expr>> & params ) { |
---|
161 | if ( params.empty() ) return; |
---|
162 | os << endl << indent << "... with parameters" << endl; |
---|
163 | ++indent; |
---|
164 | printAll( params ); |
---|
165 | --indent; |
---|
166 | } |
---|
167 | |
---|
168 | void print( const ast::AggregateDecl * node ) { |
---|
169 | os << node->typeString() << " " << node->name; |
---|
170 | |
---|
171 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
172 | os << " " << Linkage::name( node->linkage ); |
---|
173 | } |
---|
174 | |
---|
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 | |
---|
184 | os << " " << (node->body ? "with" : "without") << " body"; |
---|
185 | |
---|
186 | if ( ! node->params.empty() ) { |
---|
187 | os << endl << indent << "... with parameters" << endl; |
---|
188 | ++indent; |
---|
189 | printAll( node->params ); |
---|
190 | --indent; |
---|
191 | } |
---|
192 | |
---|
193 | if ( ! short_mode && ! node->members.empty() ) { |
---|
194 | os << endl << indent << "... with members" << endl; |
---|
195 | ++indent; |
---|
196 | printAll( node->members ); |
---|
197 | --indent; |
---|
198 | } |
---|
199 | |
---|
200 | if ( ! short_mode && ! node->attributes.empty() ) { |
---|
201 | os << endl << indent << "... with attributes" << endl; |
---|
202 | ++indent; |
---|
203 | printAll( node->attributes ); |
---|
204 | --indent; |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | os << endl; |
---|
210 | } |
---|
211 | |
---|
212 | void print( const ast::WaitStmt * node ) { |
---|
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 | |
---|
239 | void preprint( const ast::NamedTypeDecl * node ) { |
---|
240 | if ( ! node->name.empty() ) { |
---|
241 | os << node->name << ": "; |
---|
242 | } |
---|
243 | |
---|
244 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
245 | os << Linkage::name( node->linkage ) << " "; |
---|
246 | } |
---|
247 | |
---|
248 | ast::print( os, node->storage ); |
---|
249 | os << node->typeString(); |
---|
250 | |
---|
251 | if ( node->base ) { |
---|
252 | os << " for "; |
---|
253 | ++indent; |
---|
254 | node->base->accept( *this ); |
---|
255 | --indent; |
---|
256 | } |
---|
257 | |
---|
258 | if ( ! node->assertions.empty() ) { |
---|
259 | os << endl << indent << "... with assertions" << endl; |
---|
260 | ++indent; |
---|
261 | printAll( node->assertions ); |
---|
262 | --indent; |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | void postprint( const ast::Expr * node ) { |
---|
267 | print( node->inferred ); |
---|
268 | |
---|
269 | if ( node->result ) { |
---|
270 | os << endl << indent << "... with resolved type:" << endl; |
---|
271 | ++indent; |
---|
272 | os << indent; |
---|
273 | node->result->accept( *this ); |
---|
274 | --indent; |
---|
275 | } |
---|
276 | |
---|
277 | if ( node->env ) { |
---|
278 | os << endl << indent << "... with environment:" << endl; |
---|
279 | ++indent; |
---|
280 | node->env->accept( *this ); |
---|
281 | --indent; |
---|
282 | } |
---|
283 | |
---|
284 | if ( node->extension ) { |
---|
285 | os << endl << indent << "... with extension"; |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | void preprint( const ast::Type * node ) { |
---|
290 | ast::print( os, node->qualifiers ); |
---|
291 | } |
---|
292 | |
---|
293 | void preprint( const ast::FunctionType * node ) { |
---|
294 | print( node->forall ); |
---|
295 | print( node->assertions ); |
---|
296 | ast::print( os, node->qualifiers ); |
---|
297 | } |
---|
298 | |
---|
299 | void preprint( const ast::BaseInstType * node ) { |
---|
300 | print( node->attributes ); |
---|
301 | ast::print( os, node->qualifiers ); |
---|
302 | } |
---|
303 | |
---|
304 | public: |
---|
305 | virtual const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { |
---|
306 | if ( ! node->name.empty() ) os << node->name << ": "; |
---|
307 | |
---|
308 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
309 | os << Linkage::name( node->linkage ) << " "; |
---|
310 | } |
---|
311 | |
---|
312 | ast::print( os, node->storage ); |
---|
313 | |
---|
314 | if ( node->type ) { |
---|
315 | node->type->accept( *this ); |
---|
316 | } else { |
---|
317 | os << "untyped entity"; |
---|
318 | } |
---|
319 | |
---|
320 | if ( ! short_mode && node->init ) { |
---|
321 | ++indent; |
---|
322 | os << " with initializer (" << ( |
---|
323 | node->init->maybeConstructed |
---|
324 | ? "maybe constructed" |
---|
325 | : "not constructed" |
---|
326 | ) << ")" << endl << indent; |
---|
327 | node->init->accept( *this ); |
---|
328 | --indent; |
---|
329 | os << endl; |
---|
330 | } |
---|
331 | |
---|
332 | if ( ! short_mode && ! node->attributes.empty() ) { |
---|
333 | os << endl << indent << "... with attributes:" << endl; |
---|
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 ); |
---|
342 | } |
---|
343 | |
---|
344 | return node; |
---|
345 | } |
---|
346 | |
---|
347 | virtual const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { |
---|
348 | if ( !node->name.empty() ) os << node->name << ": "; |
---|
349 | |
---|
350 | if ( ! short_mode && node->linkage != Linkage::Cforall ) { |
---|
351 | os << Linkage::name( node->linkage ) << " "; |
---|
352 | } |
---|
353 | |
---|
354 | if ( ! short_mode ) printAll( node->attributes ); |
---|
355 | |
---|
356 | ast::print( os, node->storage ); |
---|
357 | ast::print( os, node->funcSpec ); |
---|
358 | |
---|
359 | if ( node->type && node->isTypeFixed ) { |
---|
360 | node->type->accept( *this ); |
---|
361 | } else { |
---|
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 | } |
---|
400 | } |
---|
401 | |
---|
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 | |
---|
410 | if ( ! short_mode && node->stmts ) { |
---|
411 | ++indent; |
---|
412 | os << " with body" << endl << indent; |
---|
413 | node->stmts->accept( *this ); |
---|
414 | --indent; |
---|
415 | } |
---|
416 | |
---|
417 | return node; |
---|
418 | } |
---|
419 | |
---|
420 | virtual const ast::Decl * visit( const ast::StructDecl * node ) override final { |
---|
421 | print(node); |
---|
422 | return node; |
---|
423 | } |
---|
424 | |
---|
425 | virtual const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final { |
---|
426 | os << "inline "; |
---|
427 | if ( ! node->name.empty() ) os << node->name; |
---|
428 | |
---|
429 | return node; |
---|
430 | } |
---|
431 | |
---|
432 | virtual const ast::Decl * visit( const ast::UnionDecl * node ) override final { |
---|
433 | print(node); |
---|
434 | return node; |
---|
435 | } |
---|
436 | |
---|
437 | virtual const ast::Decl * visit( const ast::EnumDecl * node ) override final { |
---|
438 | print(node); |
---|
439 | return node; |
---|
440 | } |
---|
441 | |
---|
442 | virtual const ast::Decl * visit( const ast::TraitDecl * node ) override final { |
---|
443 | print(node); |
---|
444 | return node; |
---|
445 | } |
---|
446 | |
---|
447 | virtual const ast::Decl * visit( const ast::TypeDecl * node ) override final { |
---|
448 | preprint( node ); |
---|
449 | if ( ! short_mode && node->init ) { |
---|
450 | os << endl << indent << "with type initializer: "; |
---|
451 | ++indent; |
---|
452 | node->init->accept( *this ); |
---|
453 | --indent; |
---|
454 | } |
---|
455 | |
---|
456 | return node; |
---|
457 | } |
---|
458 | |
---|
459 | virtual const ast::Decl * visit( const ast::TypedefDecl * node ) override final { |
---|
460 | preprint( node ); |
---|
461 | return node; |
---|
462 | } |
---|
463 | |
---|
464 | virtual const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { |
---|
465 | safe_print( node->stmt ); |
---|
466 | return node; |
---|
467 | } |
---|
468 | |
---|
469 | virtual const ast::DirectiveDecl * visit( const ast::DirectiveDecl * node ) override final { |
---|
470 | safe_print( node->stmt ); |
---|
471 | return node; |
---|
472 | } |
---|
473 | |
---|
474 | virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { |
---|
475 | os << "Static Assert with condition: "; |
---|
476 | ++indent; |
---|
477 | safe_print( node->cond ); |
---|
478 | os << endl << indent-1 << "and message: "; |
---|
479 | safe_print( node->msg ); |
---|
480 | --indent; |
---|
481 | os << endl; |
---|
482 | |
---|
483 | return node; |
---|
484 | } |
---|
485 | |
---|
486 | virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { |
---|
487 | os << "Compound Statement:" << endl; |
---|
488 | ++indent; |
---|
489 | printAll( node->kids ); |
---|
490 | --indent; |
---|
491 | return node; |
---|
492 | } |
---|
493 | |
---|
494 | virtual const ast::Stmt * visit( const ast::ExprStmt * node ) override final { |
---|
495 | ++indent; |
---|
496 | os << "Expression Statement:" << endl << indent; |
---|
497 | safe_print( node->expr ); |
---|
498 | --indent; |
---|
499 | return node; |
---|
500 | } |
---|
501 | |
---|
502 | virtual const ast::Stmt * visit( const ast::AsmStmt * node ) override final { |
---|
503 | os << "Assembler Statement:" << endl; |
---|
504 | ++indent; |
---|
505 | os << indent-1 << "instruction:" << endl << indent; |
---|
506 | safe_print( node->instruction ); |
---|
507 | if ( ! node->output.empty() ) { |
---|
508 | os << endl << indent << "output:" << endl; |
---|
509 | printAll( node->output ); |
---|
510 | } // if |
---|
511 | if ( ! node->input.empty() ) { |
---|
512 | os << indent << "input:" << endl; |
---|
513 | printAll( node->input ); |
---|
514 | } // if |
---|
515 | if ( ! node->clobber.empty() ) { |
---|
516 | os << indent << "clobber:" << endl; |
---|
517 | printAll( node->clobber ); |
---|
518 | } // if |
---|
519 | --indent; |
---|
520 | return node; |
---|
521 | } |
---|
522 | |
---|
523 | virtual const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { |
---|
524 | os << "GCC Directive: " << node->directive << endl; |
---|
525 | return node; |
---|
526 | } |
---|
527 | |
---|
528 | virtual const ast::Stmt * visit( const ast::IfStmt * node ) override final { |
---|
529 | os << "If on condition:" << endl; |
---|
530 | ++indent; |
---|
531 | os << indent; |
---|
532 | safe_print( node->cond ); |
---|
533 | --indent; |
---|
534 | |
---|
535 | if ( ! node->inits.empty() ) { |
---|
536 | os << indent << "... with initialization:" << endl; |
---|
537 | ++indent; |
---|
538 | for ( const ast::Stmt * stmt : node->inits ) { |
---|
539 | os << indent; |
---|
540 | safe_print( stmt ); |
---|
541 | } |
---|
542 | --indent; |
---|
543 | os << endl; |
---|
544 | } |
---|
545 | |
---|
546 | os << indent << "... then:" << endl; |
---|
547 | |
---|
548 | ++indent; |
---|
549 | os << indent; |
---|
550 | safe_print( node->then ); |
---|
551 | --indent; |
---|
552 | |
---|
553 | if ( node->else_ != 0 ) { |
---|
554 | os << indent << "... else:" << endl; |
---|
555 | ++indent; |
---|
556 | os << indent; |
---|
557 | node->else_->accept( *this ); |
---|
558 | --indent; |
---|
559 | } // if |
---|
560 | return node; |
---|
561 | } |
---|
562 | |
---|
563 | virtual const ast::Stmt * visit( const ast::WhileDoStmt * node ) override final { |
---|
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 | |
---|
577 | return node; |
---|
578 | } |
---|
579 | |
---|
580 | virtual const ast::Stmt * visit( const ast::ForStmt * node ) override final { |
---|
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 | |
---|
619 | return node; |
---|
620 | } |
---|
621 | |
---|
622 | virtual const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { |
---|
623 | os << "Switch on condition: "; |
---|
624 | safe_print( node->cond ); |
---|
625 | os << endl; |
---|
626 | |
---|
627 | ++indent; |
---|
628 | for ( const ast::CaseClause * stmt : node->cases ) { |
---|
629 | stmt->accept( *this ); |
---|
630 | } |
---|
631 | --indent; |
---|
632 | |
---|
633 | return node; |
---|
634 | } |
---|
635 | |
---|
636 | virtual const ast::CaseClause * visit( const ast::CaseClause * node ) override final { |
---|
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 | |
---|
652 | return node; |
---|
653 | } |
---|
654 | |
---|
655 | virtual const ast::Stmt * visit( const ast::BranchStmt * node ) override final { |
---|
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 | |
---|
673 | return node; |
---|
674 | } |
---|
675 | |
---|
676 | virtual const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { |
---|
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 | |
---|
688 | return node; |
---|
689 | } |
---|
690 | |
---|
691 | virtual const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { |
---|
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 | |
---|
708 | return node; |
---|
709 | } |
---|
710 | |
---|
711 | virtual const ast::Stmt * visit( const ast::TryStmt * node ) override final { |
---|
712 | ++indent; |
---|
713 | os << "Try Statement" << endl << indent-1 |
---|
714 | << "... with block:" << endl << indent; |
---|
715 | safe_print( node->body ); |
---|
716 | |
---|
717 | os << indent-1 << "... and handlers:" << endl; |
---|
718 | for ( const ast::CatchClause * stmt : node->handlers ) { |
---|
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 | |
---|
729 | return node; |
---|
730 | } |
---|
731 | |
---|
732 | virtual const ast::CatchClause * visit( const ast::CatchClause * node ) override final { |
---|
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; |
---|
753 | |
---|
754 | return node; |
---|
755 | } |
---|
756 | |
---|
757 | virtual const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { |
---|
758 | os << "Finally Statement" << endl; |
---|
759 | os << indent << "... with block:" << endl; |
---|
760 | ++indent; |
---|
761 | os << indent; |
---|
762 | safe_print( node->body ); |
---|
763 | --indent; |
---|
764 | |
---|
765 | return node; |
---|
766 | } |
---|
767 | |
---|
768 | virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final { |
---|
769 | os << "Suspend Statement"; |
---|
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; |
---|
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 | |
---|
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 | |
---|
804 | virtual const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { |
---|
805 | os << "Waitfor Statement" << endl; |
---|
806 | indent += 2; |
---|
807 | for( const auto & clause : node->clauses ) { |
---|
808 | clause->accept( *this ); |
---|
809 | } |
---|
810 | |
---|
811 | if ( node->timeout_time ) { |
---|
812 | os << indent-1 << "timeout of:" << endl; |
---|
813 | node->timeout_time->accept( *this ); |
---|
814 | |
---|
815 | if ( node->timeout_stmt ) { |
---|
816 | os << indent-1 << "... with statment:" << endl; |
---|
817 | node->timeout_stmt->accept( *this ); |
---|
818 | } |
---|
819 | |
---|
820 | if ( node->timeout_cond ) { |
---|
821 | os << indent-1 << "... with condition:" << endl; |
---|
822 | node->timeout_cond->accept( *this ); |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | if ( node->else_stmt ) { |
---|
827 | os << indent-1 << "else:" << endl; |
---|
828 | node->else_stmt->accept( *this ); |
---|
829 | |
---|
830 | if ( node->else_cond ) { |
---|
831 | os << indent-1 << "... with condition:" << endl; |
---|
832 | node->else_cond->accept( *this ); |
---|
833 | } |
---|
834 | } |
---|
835 | |
---|
836 | return node; |
---|
837 | } |
---|
838 | |
---|
839 | virtual const ast::WaitForClause * visit( const ast::WaitForClause * node ) override final { |
---|
840 | os << indent-1 << "target function: "; |
---|
841 | safe_print( node->target ); |
---|
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 ); |
---|
847 | } |
---|
848 | } |
---|
849 | |
---|
850 | if ( node->stmt ) { |
---|
851 | os << indent-1 << "... with statment:" << endl; |
---|
852 | node->stmt->accept( *this ); |
---|
853 | } |
---|
854 | |
---|
855 | if ( node->when_cond ) { |
---|
856 | os << indent-1 << "... with condition:" << endl; |
---|
857 | node->when_cond->accept( *this ); |
---|
858 | } |
---|
859 | |
---|
860 | return node; |
---|
861 | } |
---|
862 | |
---|
863 | virtual const ast::Stmt * visit( const ast::WaitUntilStmt * node ) override final { |
---|
864 | os << "Waituntil Statement" << endl; |
---|
865 | indent += 2; |
---|
866 | for( const auto & clause : node->clauses ) { |
---|
867 | clause->accept( *this ); |
---|
868 | } |
---|
869 | // calls print( const ast::WaitStmt * node ) |
---|
870 | print(node); |
---|
871 | return node; |
---|
872 | } |
---|
873 | |
---|
874 | virtual const ast::Decl * visit( const ast::WithStmt * node ) override final { |
---|
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 | |
---|
883 | return node; |
---|
884 | } |
---|
885 | |
---|
886 | virtual const ast::NullStmt * visit( const ast::NullStmt * node ) override final { |
---|
887 | os << "Null Statement" << endl; |
---|
888 | print( node->labels ); |
---|
889 | |
---|
890 | return node; |
---|
891 | } |
---|
892 | |
---|
893 | virtual const ast::Stmt * visit( const ast::DeclStmt * node ) override final { |
---|
894 | os << "Declaration of "; |
---|
895 | safe_print( node->decl ); |
---|
896 | |
---|
897 | return node; |
---|
898 | } |
---|
899 | |
---|
900 | virtual const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { |
---|
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 | |
---|
908 | return node; |
---|
909 | } |
---|
910 | |
---|
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 | |
---|
926 | virtual const ast::Stmt * visit( const ast::CorunStmt * node ) override final { |
---|
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 | |
---|
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 | |
---|
979 | virtual const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { |
---|
980 | ++indent; |
---|
981 | os << "Application of" << endl << indent; |
---|
982 | safe_print( node->func ); |
---|
983 | os << endl; |
---|
984 | if ( ! node->args.empty() ) { |
---|
985 | os << indent << "... to arguments" << endl; |
---|
986 | printAll( node->args ); |
---|
987 | } |
---|
988 | --indent; |
---|
989 | postprint( node ); |
---|
990 | |
---|
991 | return node; |
---|
992 | } |
---|
993 | |
---|
994 | virtual const ast::Expr * visit( const ast::UntypedExpr * node ) override final { |
---|
995 | ++indent; |
---|
996 | os << "Applying untyped:" << endl; |
---|
997 | os << indent; |
---|
998 | safe_print( node->func ); |
---|
999 | os << endl << indent-1 << "...to:" << endl; |
---|
1000 | printAll( node->args ); |
---|
1001 | --indent; |
---|
1002 | postprint( node ); |
---|
1003 | |
---|
1004 | return node; |
---|
1005 | } |
---|
1006 | |
---|
1007 | virtual const ast::Expr * visit( const ast::NameExpr * node ) override final { |
---|
1008 | os << "Name: " << node->name; |
---|
1009 | postprint( node ); |
---|
1010 | |
---|
1011 | return node; |
---|
1012 | } |
---|
1013 | |
---|
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 | |
---|
1025 | virtual const ast::Expr * visit( const ast::AddressExpr * node ) override final { |
---|
1026 | os << "Address of:" << endl; |
---|
1027 | ++indent; |
---|
1028 | os << indent; |
---|
1029 | safe_print( node->arg ); |
---|
1030 | |
---|
1031 | --indent; |
---|
1032 | |
---|
1033 | return node; |
---|
1034 | } |
---|
1035 | |
---|
1036 | virtual const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { |
---|
1037 | os << "Address of label:" << node->arg; |
---|
1038 | |
---|
1039 | return node; |
---|
1040 | } |
---|
1041 | |
---|
1042 | virtual const ast::Expr * visit( const ast::CastExpr * node ) override final { |
---|
1043 | ++indent; |
---|
1044 | os << (node->isGenerated ? "Generated" : "Explicit") << " Cast of:" << endl << indent; |
---|
1045 | safe_print( node->arg ); |
---|
1046 | os << endl << indent-1 << "... to:"; |
---|
1047 | if ( ! node->result ) { |
---|
1048 | os << " "; |
---|
1049 | undefined(); |
---|
1050 | } else if ( node->result->isVoid() ) { |
---|
1051 | os << " nothing"; |
---|
1052 | } else { |
---|
1053 | os << endl << indent; |
---|
1054 | node->result->accept( *this ); |
---|
1055 | } // if |
---|
1056 | --indent; |
---|
1057 | postprint( node ); |
---|
1058 | |
---|
1059 | return node; |
---|
1060 | } |
---|
1061 | |
---|
1062 | virtual const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { |
---|
1063 | ++indent; |
---|
1064 | os << "Keyword Cast of:" << endl << indent; |
---|
1065 | safe_print( node->arg ); |
---|
1066 | --indent; |
---|
1067 | os << endl << indent << "... to: " << node->targetString(); |
---|
1068 | postprint( node ); |
---|
1069 | |
---|
1070 | return node; |
---|
1071 | } |
---|
1072 | |
---|
1073 | virtual const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { |
---|
1074 | ++indent; |
---|
1075 | os << "Virtual Cast of:" << endl << indent; |
---|
1076 | safe_print( node->arg ); |
---|
1077 | os << endl << indent-1 << "... to:"; |
---|
1078 | if ( ! node->result ) { |
---|
1079 | os << " unknown"; |
---|
1080 | } else { |
---|
1081 | os << endl << indent; |
---|
1082 | node->result->accept( *this ); |
---|
1083 | } |
---|
1084 | --indent; |
---|
1085 | postprint( node ); |
---|
1086 | |
---|
1087 | return node; |
---|
1088 | } |
---|
1089 | |
---|
1090 | virtual const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { |
---|
1091 | ++indent; |
---|
1092 | os << "Untyped Member Expression, with field: " << endl << indent; |
---|
1093 | safe_print( node->member ); |
---|
1094 | os << indent-1 << "... from aggregate:" << endl << indent; |
---|
1095 | safe_print( node->aggregate ); |
---|
1096 | --indent; |
---|
1097 | postprint( node ); |
---|
1098 | |
---|
1099 | return node; |
---|
1100 | } |
---|
1101 | |
---|
1102 | virtual const ast::Expr * visit( const ast::MemberExpr * node ) override final { |
---|
1103 | ++indent; |
---|
1104 | os << "Member Expression, with field:" << endl << indent; |
---|
1105 | safe_print( node->member ); |
---|
1106 | os << endl << indent-1 << "... from aggregate:" << endl << indent; |
---|
1107 | safe_print( node->aggregate ); |
---|
1108 | --indent; |
---|
1109 | postprint( node ); |
---|
1110 | |
---|
1111 | return node; |
---|
1112 | } |
---|
1113 | |
---|
1114 | virtual const ast::Expr * visit( const ast::VariableExpr * node ) override final { |
---|
1115 | os << "Variable Expression: "; |
---|
1116 | short_print( node->var ); |
---|
1117 | postprint( node ); |
---|
1118 | |
---|
1119 | return node; |
---|
1120 | } |
---|
1121 | |
---|
1122 | virtual const ast::Expr * visit( const ast::ConstantExpr * node ) override final { |
---|
1123 | os << "Constant Expression (" << node->rep; |
---|
1124 | if ( node->result ) { |
---|
1125 | os << ": "; |
---|
1126 | node->result->accept( *this ); |
---|
1127 | } |
---|
1128 | os << ")"; |
---|
1129 | postprint( node ); |
---|
1130 | |
---|
1131 | return node; |
---|
1132 | } |
---|
1133 | |
---|
1134 | virtual const ast::Expr * visit( const ast::SizeofExpr * node ) override final { |
---|
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 | |
---|
1142 | return node; |
---|
1143 | } |
---|
1144 | |
---|
1145 | virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final { |
---|
1146 | os << "Alignof Expression on: "; |
---|
1147 | ++indent; |
---|
1148 | if ( node->type ) node->type->accept( *this ); |
---|
1149 | else safe_print( node->expr ); |
---|
1150 | --indent; |
---|
1151 | postprint( node ); |
---|
1152 | |
---|
1153 | return node; |
---|
1154 | } |
---|
1155 | |
---|
1156 | virtual const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { |
---|
1157 | os << "Untyped Offsetof Expression on member " << node->member << " of "; |
---|
1158 | ++indent; |
---|
1159 | safe_print( node->type ); |
---|
1160 | --indent; |
---|
1161 | postprint( node ); |
---|
1162 | |
---|
1163 | return node; |
---|
1164 | } |
---|
1165 | |
---|
1166 | virtual const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { |
---|
1167 | os << "Offsetof Expression on member " << node->member->name << " of "; |
---|
1168 | ++indent; |
---|
1169 | safe_print( node->type ); |
---|
1170 | --indent; |
---|
1171 | postprint( node ); |
---|
1172 | |
---|
1173 | return node; |
---|
1174 | } |
---|
1175 | |
---|
1176 | virtual const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { |
---|
1177 | os << "Offset Pack Expression on: "; |
---|
1178 | ++indent; |
---|
1179 | safe_print( node->type ); |
---|
1180 | --indent; |
---|
1181 | postprint( node ); |
---|
1182 | |
---|
1183 | return node; |
---|
1184 | } |
---|
1185 | |
---|
1186 | virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final { |
---|
1187 | os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: "; |
---|
1188 | safe_print( node->arg1 ); |
---|
1189 | os << " and "; |
---|
1190 | safe_print( node->arg2 ); |
---|
1191 | postprint( node ); |
---|
1192 | |
---|
1193 | return node; |
---|
1194 | } |
---|
1195 | |
---|
1196 | virtual const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { |
---|
1197 | ++indent; |
---|
1198 | os << "Conditional expression on:" << endl << indent; |
---|
1199 | safe_print( node->arg1 ); |
---|
1200 | os << indent-1 << "First alternative:" << endl << indent; |
---|
1201 | safe_print( node->arg2 ); |
---|
1202 | os << indent-1 << "Second alternative:" << endl << indent; |
---|
1203 | safe_print( node->arg3 ); |
---|
1204 | --indent; |
---|
1205 | postprint( node ); |
---|
1206 | |
---|
1207 | return node; |
---|
1208 | } |
---|
1209 | |
---|
1210 | virtual const ast::Expr * visit( const ast::CommaExpr * node ) override final { |
---|
1211 | ++indent; |
---|
1212 | os << "Comma Expression:" << endl << indent; |
---|
1213 | safe_print( node->arg1 ); |
---|
1214 | os << endl << indent; |
---|
1215 | safe_print( node->arg2 ); |
---|
1216 | --indent; |
---|
1217 | postprint( node ); |
---|
1218 | |
---|
1219 | return node; |
---|
1220 | } |
---|
1221 | |
---|
1222 | virtual const ast::Expr * visit( const ast::TypeExpr * node ) override final { |
---|
1223 | safe_print( node->type ); |
---|
1224 | postprint( node ); |
---|
1225 | |
---|
1226 | return node; |
---|
1227 | } |
---|
1228 | |
---|
1229 | virtual const ast::Expr * visit( const ast::DimensionExpr * node ) override final { |
---|
1230 | os << "Type-Sys Value: " << node->name; |
---|
1231 | postprint( node ); |
---|
1232 | |
---|
1233 | return node; |
---|
1234 | } |
---|
1235 | |
---|
1236 | virtual const ast::Expr * visit( const ast::AsmExpr * node ) override final { |
---|
1237 | os << "Asm Expression:" << endl; |
---|
1238 | ++indent; |
---|
1239 | if ( !node->inout.empty() ) os << "[" << node->inout << "] "; |
---|
1240 | if ( node->constraint ) node->constraint->accept( *this ); |
---|
1241 | if ( node->operand ) node->operand->accept( *this ); |
---|
1242 | --indent; |
---|
1243 | |
---|
1244 | return node; |
---|
1245 | } |
---|
1246 | |
---|
1247 | virtual const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { |
---|
1248 | ++indent; |
---|
1249 | os << "Implicit Copy Constructor Expression:" << endl << indent; |
---|
1250 | safe_print( node->callExpr ); |
---|
1251 | --indent; |
---|
1252 | postprint( node ); |
---|
1253 | |
---|
1254 | return node; |
---|
1255 | } |
---|
1256 | |
---|
1257 | virtual const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { |
---|
1258 | os << "Constructor Expression:" << endl << indent+1; |
---|
1259 | indent += 2; |
---|
1260 | safe_print( node->callExpr ); |
---|
1261 | indent -= 2; |
---|
1262 | postprint( node ); |
---|
1263 | |
---|
1264 | return node; |
---|
1265 | } |
---|
1266 | |
---|
1267 | virtual const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { |
---|
1268 | ++indent; |
---|
1269 | os << "Compound Literal Expression: " << endl << indent; |
---|
1270 | safe_print( node->result ); |
---|
1271 | os << indent; |
---|
1272 | safe_print( node->init ); |
---|
1273 | --indent; |
---|
1274 | postprint( node ); |
---|
1275 | |
---|
1276 | return node; |
---|
1277 | } |
---|
1278 | |
---|
1279 | virtual const ast::Expr * visit( const ast::RangeExpr * node ) override final { |
---|
1280 | os << "Range Expression: "; |
---|
1281 | safe_print( node->low ); |
---|
1282 | os << " ... "; |
---|
1283 | safe_print( node->high ); |
---|
1284 | postprint( node ); |
---|
1285 | |
---|
1286 | return node; |
---|
1287 | } |
---|
1288 | |
---|
1289 | virtual const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { |
---|
1290 | os << "Untyped Tuple:" << endl; |
---|
1291 | ++indent; |
---|
1292 | printAll( node->exprs ); |
---|
1293 | --indent; |
---|
1294 | postprint( node ); |
---|
1295 | |
---|
1296 | return node; |
---|
1297 | } |
---|
1298 | |
---|
1299 | virtual const ast::Expr * visit( const ast::TupleExpr * node ) override final { |
---|
1300 | os << "Tuple:" << endl; |
---|
1301 | ++indent; |
---|
1302 | printAll( node->exprs ); |
---|
1303 | --indent; |
---|
1304 | postprint( node ); |
---|
1305 | |
---|
1306 | return node; |
---|
1307 | } |
---|
1308 | |
---|
1309 | virtual const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { |
---|
1310 | os << "Tuple Index Expression, with tuple:" << endl; |
---|
1311 | ++indent; |
---|
1312 | os << indent; |
---|
1313 | safe_print( node->tuple ); |
---|
1314 | os << indent << "with index: " << node->index << endl; |
---|
1315 | --indent; |
---|
1316 | postprint( node ); |
---|
1317 | |
---|
1318 | return node; |
---|
1319 | } |
---|
1320 | |
---|
1321 | virtual const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { |
---|
1322 | os << "Tuple Assignment Expression, with stmt expr:" << endl; |
---|
1323 | ++indent; |
---|
1324 | os << indent; |
---|
1325 | safe_print( node->stmtExpr ); |
---|
1326 | --indent; |
---|
1327 | postprint( node ); |
---|
1328 | |
---|
1329 | return node; |
---|
1330 | } |
---|
1331 | |
---|
1332 | virtual const ast::Expr * visit( const ast::StmtExpr * node ) override final { |
---|
1333 | ++indent; |
---|
1334 | os << "Statement Expression:" << endl << indent; |
---|
1335 | safe_print( node->stmts ); |
---|
1336 | if ( ! node->returnDecls.empty() ) { |
---|
1337 | os << indent << "... with returnDecls: "; |
---|
1338 | printAll( node->returnDecls ); |
---|
1339 | } |
---|
1340 | if ( ! node->dtors.empty() ) { |
---|
1341 | os << indent << "... with dtors: "; |
---|
1342 | printAll( node->dtors ); |
---|
1343 | } |
---|
1344 | --indent; |
---|
1345 | postprint( node ); |
---|
1346 | |
---|
1347 | return node; |
---|
1348 | } |
---|
1349 | |
---|
1350 | virtual const ast::Expr * visit( const ast::UniqueExpr * node ) override final { |
---|
1351 | ++indent; |
---|
1352 | os << "Unique Expression with id: " << node->id << endl << indent; |
---|
1353 | safe_print( node->expr ); |
---|
1354 | if ( node->object ) { |
---|
1355 | os << indent-1 << "... with decl: "; |
---|
1356 | short_print( node->object ); |
---|
1357 | } |
---|
1358 | --indent; |
---|
1359 | postprint( node ); |
---|
1360 | |
---|
1361 | return node; |
---|
1362 | } |
---|
1363 | |
---|
1364 | virtual const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { |
---|
1365 | ++indent; |
---|
1366 | os << "Untyped Init Expression" << endl << indent; |
---|
1367 | safe_print( node->expr ); |
---|
1368 | if ( ! node->initAlts.empty() ) { |
---|
1369 | for ( const InitAlternative & alt : node->initAlts ) { |
---|
1370 | os << indent << "InitAlternative: "; |
---|
1371 | safe_print( alt.type ); |
---|
1372 | safe_print( alt.designation ); |
---|
1373 | } |
---|
1374 | } |
---|
1375 | --indent; |
---|
1376 | |
---|
1377 | return node; |
---|
1378 | } |
---|
1379 | |
---|
1380 | virtual const ast::Expr * visit( const ast::InitExpr * node ) override final { |
---|
1381 | ++indent; |
---|
1382 | os << "Init Expression" << endl << indent; |
---|
1383 | safe_print( node->expr ); |
---|
1384 | os << indent << "... with designation: "; |
---|
1385 | safe_print( node->designation ); |
---|
1386 | --indent; |
---|
1387 | |
---|
1388 | return node; |
---|
1389 | } |
---|
1390 | |
---|
1391 | virtual const ast::Expr * visit( const ast::DeletedExpr * node ) override final { |
---|
1392 | ++indent; |
---|
1393 | os << "Deleted Expression" << endl << indent; |
---|
1394 | safe_print( node->expr ); |
---|
1395 | os << endl << indent << "... deleted by: "; |
---|
1396 | safe_print( node->deleteStmt ); |
---|
1397 | --indent; |
---|
1398 | |
---|
1399 | return node; |
---|
1400 | } |
---|
1401 | |
---|
1402 | virtual const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { |
---|
1403 | ++indent; |
---|
1404 | os << "Default Argument Expression" << endl << indent; |
---|
1405 | safe_print( node->expr ); |
---|
1406 | --indent; |
---|
1407 | |
---|
1408 | return node; |
---|
1409 | } |
---|
1410 | |
---|
1411 | virtual const ast::Expr * visit( const ast::GenericExpr * node ) override final { |
---|
1412 | ++indent; |
---|
1413 | os << "C11 _Generic Expression" << endl << indent; |
---|
1414 | safe_print( node->control ); |
---|
1415 | os << endl << indent << "... with associations:" << endl; |
---|
1416 | for ( const auto & assoc : node->associations ) { |
---|
1417 | os << indent; |
---|
1418 | if ( assoc.type ) { |
---|
1419 | os << "... type: "; |
---|
1420 | assoc.type->accept( *this ); |
---|
1421 | os << endl << indent << "... expression: "; |
---|
1422 | safe_print( assoc.expr ); |
---|
1423 | } else { |
---|
1424 | os << "... default: "; |
---|
1425 | safe_print( assoc.expr ); |
---|
1426 | } |
---|
1427 | os << endl; |
---|
1428 | } |
---|
1429 | --indent; |
---|
1430 | |
---|
1431 | return node; |
---|
1432 | } |
---|
1433 | |
---|
1434 | virtual const ast::Type * visit( const ast::VoidType * node ) override final { |
---|
1435 | preprint( node ); |
---|
1436 | os << "void"; |
---|
1437 | return node; |
---|
1438 | } |
---|
1439 | |
---|
1440 | virtual const ast::Type * visit( const ast::BasicType * node ) override final { |
---|
1441 | preprint( node ); |
---|
1442 | os << ast::BasicType::typeNames[ node->kind ]; |
---|
1443 | return node; |
---|
1444 | } |
---|
1445 | |
---|
1446 | virtual const ast::Type * visit( const ast::PointerType * node ) override final { |
---|
1447 | preprint( node ); |
---|
1448 | if ( ! node->isArray() ) { |
---|
1449 | os << "pointer to "; |
---|
1450 | } else { |
---|
1451 | os << "decayed "; |
---|
1452 | if ( node->isStatic ) { |
---|
1453 | os << "static "; |
---|
1454 | } |
---|
1455 | |
---|
1456 | if ( node->isVarLen ) { |
---|
1457 | os << "variable length array of "; |
---|
1458 | } else if ( node->dimension ) { |
---|
1459 | os << "array of "; |
---|
1460 | node->dimension->accept( *this ); |
---|
1461 | os << " "; |
---|
1462 | } |
---|
1463 | } |
---|
1464 | safe_print( node->base ); |
---|
1465 | |
---|
1466 | return node; |
---|
1467 | } |
---|
1468 | |
---|
1469 | virtual const ast::Type * visit( const ast::ArrayType * node ) override final { |
---|
1470 | preprint( node ); |
---|
1471 | if ( node->isStatic ) { |
---|
1472 | os << "static "; |
---|
1473 | } |
---|
1474 | |
---|
1475 | if ( node->isVarLen ) { |
---|
1476 | os << "variable length array of "; |
---|
1477 | } else if ( node->dimension ) { |
---|
1478 | os << "array of "; |
---|
1479 | } else { |
---|
1480 | os << "open array of "; |
---|
1481 | } |
---|
1482 | |
---|
1483 | safe_print( node->base ); |
---|
1484 | |
---|
1485 | if ( node->dimension ) { |
---|
1486 | os << " with dimension of "; |
---|
1487 | node->dimension->accept( *this ); |
---|
1488 | } |
---|
1489 | |
---|
1490 | return node; |
---|
1491 | } |
---|
1492 | |
---|
1493 | virtual const ast::Type * visit( const ast::ReferenceType * node ) override final { |
---|
1494 | preprint( node ); |
---|
1495 | os << "reference to "; |
---|
1496 | safe_print( node->base ); |
---|
1497 | |
---|
1498 | return node; |
---|
1499 | } |
---|
1500 | |
---|
1501 | virtual const ast::Type * visit( const ast::QualifiedType * node ) override final { |
---|
1502 | preprint( node ); |
---|
1503 | ++indent; |
---|
1504 | os << "Qualified Type:" << endl << indent; |
---|
1505 | safe_print( node->parent ); |
---|
1506 | os << endl << indent; |
---|
1507 | safe_print( node->child ); |
---|
1508 | os << endl; |
---|
1509 | --indent; |
---|
1510 | |
---|
1511 | return node; |
---|
1512 | } |
---|
1513 | |
---|
1514 | virtual const ast::Type * visit( const ast::FunctionType * node ) override final { |
---|
1515 | preprint( node ); |
---|
1516 | |
---|
1517 | os << "function" << endl; |
---|
1518 | if ( ! node->params.empty() ) { |
---|
1519 | os << indent << "... with parameters" << endl; |
---|
1520 | ++indent; |
---|
1521 | printAll( node->params ); |
---|
1522 | if ( node->isVarArgs ) { |
---|
1523 | os << indent << "and a variable number of other arguments" << endl; |
---|
1524 | } |
---|
1525 | --indent; |
---|
1526 | } else if ( node->isVarArgs ) { |
---|
1527 | os << indent+1 << "accepting unspecified arguments" << endl; |
---|
1528 | } |
---|
1529 | |
---|
1530 | os << indent << "... returning"; |
---|
1531 | if ( node->returns.empty() ) { |
---|
1532 | os << " nothing" << endl; |
---|
1533 | } else { |
---|
1534 | os << endl; |
---|
1535 | ++indent; |
---|
1536 | printAll( node->returns ); |
---|
1537 | --indent; |
---|
1538 | } |
---|
1539 | |
---|
1540 | return node; |
---|
1541 | } |
---|
1542 | |
---|
1543 | virtual const ast::Type * visit( const ast::StructInstType * node ) override final { |
---|
1544 | preprint( node ); |
---|
1545 | os << "instance of struct " << node->name; |
---|
1546 | if ( node->base ) { |
---|
1547 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
1548 | } |
---|
1549 | print( node->params ); |
---|
1550 | |
---|
1551 | return node; |
---|
1552 | } |
---|
1553 | |
---|
1554 | virtual const ast::Type * visit( const ast::UnionInstType * node ) override final { |
---|
1555 | preprint( node ); |
---|
1556 | os << "instance of union " << node->name; |
---|
1557 | if ( node->base ) { |
---|
1558 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
1559 | } |
---|
1560 | print( node->params ); |
---|
1561 | |
---|
1562 | return node; |
---|
1563 | } |
---|
1564 | |
---|
1565 | virtual const ast::Type * visit( const ast::EnumInstType * node ) override final { |
---|
1566 | preprint( node ); |
---|
1567 | os << "instance of enum " << node->name; |
---|
1568 | if ( node->base ) { |
---|
1569 | os << " " << ( node->base->body ? "with" : "without" ) << " body"; |
---|
1570 | } |
---|
1571 | print( node->params ); |
---|
1572 | |
---|
1573 | return node; |
---|
1574 | } |
---|
1575 | |
---|
1576 | virtual const ast::Type * visit( const ast::TraitInstType * node ) override final { |
---|
1577 | preprint( node ); |
---|
1578 | os << "instance of trait " << node->name; |
---|
1579 | print( node->params ); |
---|
1580 | |
---|
1581 | return node; |
---|
1582 | } |
---|
1583 | |
---|
1584 | virtual const ast::Type * visit( const ast::TypeInstType * node ) override final { |
---|
1585 | preprint( node ); |
---|
1586 | const auto & _name = deterministic_output && isUnboundType(node) ? "[unbound]" : node->typeString(); |
---|
1587 | os << "instance of type " << _name |
---|
1588 | << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)"; |
---|
1589 | print( node->params ); |
---|
1590 | |
---|
1591 | return node; |
---|
1592 | } |
---|
1593 | |
---|
1594 | virtual const ast::Type * visit( const ast::TupleType * node ) override final { |
---|
1595 | preprint( node ); |
---|
1596 | os << "tuple of types" << endl; |
---|
1597 | ++indent; |
---|
1598 | printAll( node->types ); |
---|
1599 | --indent; |
---|
1600 | |
---|
1601 | return node; |
---|
1602 | } |
---|
1603 | |
---|
1604 | virtual const ast::Type * visit( const ast::TypeofType * node ) override final { |
---|
1605 | preprint( node ); |
---|
1606 | if ( node->kind == ast::TypeofType::Basetypeof ) { os << "base-"; } |
---|
1607 | os << "type-of expression "; |
---|
1608 | safe_print( node->expr ); |
---|
1609 | |
---|
1610 | return node; |
---|
1611 | } |
---|
1612 | |
---|
1613 | virtual const ast::Type * visit( const ast::VTableType * node ) override final { |
---|
1614 | preprint( node ); |
---|
1615 | os << "vtable for "; |
---|
1616 | safe_print( node->base ); |
---|
1617 | |
---|
1618 | return node; |
---|
1619 | } |
---|
1620 | |
---|
1621 | virtual const ast::Type * visit( const ast::VarArgsType * node ) override final { |
---|
1622 | preprint( node ); |
---|
1623 | os << "builtin var args pack"; |
---|
1624 | return node; |
---|
1625 | } |
---|
1626 | |
---|
1627 | virtual const ast::Type * visit( const ast::ZeroType * node ) override final { |
---|
1628 | preprint( node ); |
---|
1629 | os << "zero_t"; |
---|
1630 | return node; |
---|
1631 | } |
---|
1632 | |
---|
1633 | virtual const ast::Type * visit( const ast::OneType * node ) override final { |
---|
1634 | preprint( node ); |
---|
1635 | os << "one_t"; |
---|
1636 | return node; |
---|
1637 | } |
---|
1638 | |
---|
1639 | virtual const ast::Type * visit( const ast::GlobalScopeType * node ) override final { |
---|
1640 | preprint( node ); |
---|
1641 | os << "Global Scope Type"; |
---|
1642 | return node; |
---|
1643 | } |
---|
1644 | |
---|
1645 | virtual const ast::Designation * visit( const ast::Designation * node ) override final { |
---|
1646 | if ( node->designators.empty() ) return node; |
---|
1647 | os << "... designated by: " << endl; |
---|
1648 | ++indent; |
---|
1649 | for ( const ast::Expr * d : node->designators ) { |
---|
1650 | os << indent; |
---|
1651 | d->accept( *this ); |
---|
1652 | os << endl; |
---|
1653 | } |
---|
1654 | --indent; |
---|
1655 | return node; |
---|
1656 | } |
---|
1657 | |
---|
1658 | virtual const ast::Init * visit( const ast::SingleInit * node ) override final { |
---|
1659 | os << "Simple Initializer: "; |
---|
1660 | safe_print( node->value ); |
---|
1661 | return node; |
---|
1662 | } |
---|
1663 | |
---|
1664 | virtual const ast::Init * visit( const ast::ListInit * node ) override final { |
---|
1665 | os << "Compound initializer: " << endl; |
---|
1666 | ++indent; |
---|
1667 | for ( auto p : group_iterate( node->designations, node->initializers ) ) { |
---|
1668 | const ast::Designation * d = std::get<0>(p); |
---|
1669 | const ast::Init * init = std::get<1>(p); |
---|
1670 | os << indent; |
---|
1671 | init->accept( *this ); |
---|
1672 | os << endl; |
---|
1673 | if ( ! d->designators.empty() ) { |
---|
1674 | os << indent; |
---|
1675 | d->accept( *this ); |
---|
1676 | } |
---|
1677 | } |
---|
1678 | --indent; |
---|
1679 | return node; |
---|
1680 | } |
---|
1681 | |
---|
1682 | virtual const ast::Init * visit( const ast::ConstructorInit * node ) override final { |
---|
1683 | os << "Constructor initializer: " << endl; |
---|
1684 | if ( node->ctor ) { |
---|
1685 | os << indent << "... initially constructed with "; |
---|
1686 | ++indent; |
---|
1687 | node->ctor->accept( *this ); |
---|
1688 | --indent; |
---|
1689 | } |
---|
1690 | |
---|
1691 | if ( node->dtor ) { |
---|
1692 | os << indent << "... destructed with "; |
---|
1693 | ++indent; |
---|
1694 | node->dtor->accept( *this ); |
---|
1695 | --indent; |
---|
1696 | } |
---|
1697 | |
---|
1698 | if ( node->init ) { |
---|
1699 | os << indent << "... with fallback C-style initializer: "; |
---|
1700 | ++indent; |
---|
1701 | node->init->accept( *this ); |
---|
1702 | --indent; |
---|
1703 | } |
---|
1704 | return node; |
---|
1705 | } |
---|
1706 | |
---|
1707 | virtual const ast::Attribute * visit( const ast::Attribute * node ) override final { |
---|
1708 | if ( node->empty() ) return node; |
---|
1709 | os << "Attribute with name: " << node->name; |
---|
1710 | if ( node->params.empty() ) return node; |
---|
1711 | os << " with parameters: " << endl; |
---|
1712 | ++indent; |
---|
1713 | printAll( node->params ); |
---|
1714 | --indent; |
---|
1715 | return node; |
---|
1716 | } |
---|
1717 | |
---|
1718 | virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { |
---|
1719 | os << indent << "Types:" << endl; |
---|
1720 | for ( const auto& i : *node ) { |
---|
1721 | os << indent+1 << i.first.typeString() << " -> "; |
---|
1722 | indent += 2; |
---|
1723 | safe_print( i.second ); |
---|
1724 | indent -= 2; |
---|
1725 | os << endl; |
---|
1726 | } |
---|
1727 | return node; |
---|
1728 | } |
---|
1729 | |
---|
1730 | }; |
---|
1731 | |
---|
1732 | } // namespace |
---|
1733 | |
---|
1734 | void print( ostream & os, const ast::Node * node, Indenter indent ) { |
---|
1735 | Printer printer { os, indent, false }; |
---|
1736 | node->accept(printer); |
---|
1737 | } |
---|
1738 | |
---|
1739 | void printShort( ostream & os, const ast::Decl * node, Indenter indent ) { |
---|
1740 | Printer printer { os, indent, true }; |
---|
1741 | node->accept(printer); |
---|
1742 | } |
---|
1743 | |
---|
1744 | void print( ostream & os, Function::Specs specs ) { |
---|
1745 | print( os, specs, Names::FuncSpecifiers ); |
---|
1746 | } |
---|
1747 | |
---|
1748 | void print( ostream & os, Storage::Classes storage ) { |
---|
1749 | print( os, storage, Names::StorageClasses ); |
---|
1750 | } |
---|
1751 | |
---|
1752 | void print( ostream & os, CV::Qualifiers qualifiers ) { |
---|
1753 | print( os, qualifiers, Names::Qualifiers ); |
---|
1754 | } |
---|
1755 | |
---|
1756 | } // namespace ast |
---|