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