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