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