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