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