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