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