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