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