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