Changes in src/AST/Convert.cpp [675d816:f685679]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r675d816 rf685679 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 17 16:01:00 201913 // Update Count : 412 // Last Modified On : Thu May 23 16:59:00 2019 13 // Update Count : 6 14 14 // 15 15 16 16 #include "Convert.hpp" 17 17 18 #include "AST/Pass.hpp"18 #include <unordered_map> 19 19 20 20 #include "AST/Attribute.hpp" … … 23 23 #include "AST/Init.hpp" 24 24 #include "AST/Stmt.hpp" 25 25 #include "AST/TypeSubstitution.hpp" 26 26 27 27 #include "SynTree/Attribute.h" 28 28 #include "SynTree/Declaration.h" 29 #include "SynTree/TypeSubstitution.h" 29 30 30 31 //================================================================================================ … … 43 44 class ConverterNewToOld : public ast::Visitor { 44 45 BaseSyntaxNode * node = nullptr; 46 using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >; 47 Cache cache; 45 48 46 49 template<typename T> … … 48 51 ConverterNewToOld & visitor; 49 52 50 template<typename U> 51 T * accept1( const ast::ptr<U> & ptr ) { 53 template<typename U, enum ast::Node::ref_type R> 54 T * accept1( const ast::ptr_base<U, R> & ptr ) { 55 if ( ! ptr ) return nullptr; 52 56 ptr->accept( visitor ); 53 57 T * ret = strict_dynamic_cast< T * >( visitor.node ); … … 88 92 } 89 93 94 /// get new qualifiers from old type 95 Type::Qualifiers cv( const ast::Type * ty ) { return { ty->qualifiers.val }; } 96 97 /// returns true and sets `node` if in cache 98 bool inCache( const ast::Node * node ) { 99 auto it = cache.find( node ); 100 if ( it == cache.end() ) return false; 101 this->node = it->second; 102 return true; 103 } 104 90 105 public: 91 106 Declaration * decl( const ast::Decl * declNode ) { … … 94 109 95 110 private: 111 void declPostamble( Declaration * decl, const ast::Decl * node ) { 112 decl->location = node->location; 113 // name comes from constructor 114 // linkage comes from constructor 115 decl->extension = node->extension; 116 decl->uniqueId = node->uniqueId; 117 // storageClasses comes from constructor 118 this->node = decl; 119 } 120 121 const ast::DeclWithType * declWithTypePostamble ( 122 DeclarationWithType * decl, const ast::DeclWithType * node ) { 123 cache.emplace( node, decl ); 124 decl->mangleName = node->mangleName; 125 decl->scopeLevel = node->scopeLevel; 126 decl->asmName = get<Expression>().accept1( node->asmName ); 127 // attributes comes from constructor 128 decl->isDeleted = node->isDeleted; 129 // fs comes from constructor 130 declPostamble( decl, node ); 131 return nullptr; 132 } 133 96 134 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 97 (void)node; 98 return nullptr; 135 if ( inCache( node ) ) return nullptr; 136 auto decl = new ObjectDecl( 137 node->name, 138 Type::StorageClasses( node->storage.val ), 139 LinkageSpec::Spec( node->linkage.val ), 140 get<Expression>().accept1( node->bitfieldWidth ), 141 get<Type>().accept1( node->type ), 142 get<Initializer>().accept1( node->init ), 143 get<Attribute>().acceptL( node->attributes ), 144 Type::FuncSpecifiers( node->funcSpec.val ) 145 ); 146 return declWithTypePostamble( decl, node ); 99 147 } 100 148 101 149 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 102 (void)node; 150 if ( inCache( node ) ) return nullptr; 151 auto decl = new FunctionDecl( 152 node->name, 153 Type::StorageClasses( node->storage.val ), 154 LinkageSpec::Spec( node->linkage.val ), 155 get<FunctionType>().accept1( node->type ), 156 get<CompoundStmt>().accept1( node->stmts ), 157 get<Attribute>().acceptL( node->attributes ), 158 Type::FuncSpecifiers( node->funcSpec.val ) 159 ); 160 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 161 return declWithTypePostamble( decl, node ); 162 } 163 164 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 165 // base comes from constructor 166 decl->parameters = get<TypeDecl>().acceptL( node->params ); 167 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 168 declPostamble( decl, node ); 169 return nullptr; 170 } 171 172 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 173 if ( inCache( node ) ) return nullptr; 174 auto decl = new TypeDecl( 175 node->name, 176 Type::StorageClasses( node->storage.val ), 177 get<Type>().accept1( node->base ), 178 (TypeDecl::Kind)(unsigned)node->kind, 179 node->sized, 180 get<Type>().accept1( node->init ) 181 ); 182 cache.emplace( node, decl ); 183 return namedTypePostamble( decl, node ); 184 } 185 186 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 187 auto decl = new TypedefDecl( 188 node->name, 189 node->location, 190 Type::StorageClasses( node->storage.val ), 191 get<Type>().accept1( node->base ), 192 LinkageSpec::Spec( node->linkage.val ) 193 ); 194 return namedTypePostamble( decl, node ); 195 } 196 197 const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) { 198 cache.emplace( node, decl ); 199 decl->members = get<Declaration>().acceptL( node->members ); 200 decl->parameters = get<TypeDecl>().acceptL( node->params ); 201 decl->body = node->body; 202 // attributes come from constructor 203 decl->parent = get<AggregateDecl>().accept1( node->parent ); 204 declPostamble( decl, node ); 103 205 return nullptr; 104 206 } 105 207 106 208 const ast::Decl * visit( const ast::StructDecl * node ) override final { 107 (void)node; 108 return nullptr; 209 if ( inCache( node ) ) return nullptr; 210 auto decl = new StructDecl( 211 node->name, 212 node->kind, 213 get<Attribute>().acceptL( node->attributes ), 214 LinkageSpec::Spec( node->linkage.val ) 215 ); 216 return aggregatePostamble( decl, node ); 109 217 } 110 218 111 219 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 112 (void)node; 113 return nullptr; 220 if ( inCache( node ) ) return nullptr; 221 auto decl = new UnionDecl( 222 node->name, 223 get<Attribute>().acceptL( node->attributes ), 224 LinkageSpec::Spec( node->linkage.val ) 225 ); 226 return aggregatePostamble( decl, node ); 114 227 } 115 228 116 229 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 117 (void)node; 118 return nullptr; 230 if ( inCache( node ) ) return nullptr; 231 auto decl = new EnumDecl( 232 node->name, 233 get<Attribute>().acceptL( node->attributes ), 234 LinkageSpec::Spec( node->linkage.val ) 235 ); 236 return aggregatePostamble( decl, node ); 119 237 } 120 238 121 239 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 122 (void)node; 123 return nullptr; 124 } 125 126 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 127 (void)node; 128 return nullptr; 129 } 130 131 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 132 (void)node; 133 return nullptr; 240 if ( inCache( node ) ) return nullptr; 241 auto decl = new TraitDecl( 242 node->name, 243 {}, 244 LinkageSpec::Spec( node->linkage.val ) 245 ); 246 return aggregatePostamble( decl, node ); 134 247 } 135 248 136 249 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 137 (void)node; 250 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 251 declPostamble( decl, node ); 138 252 return nullptr; 139 253 } 140 254 141 255 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 142 (void)node; 143 return nullptr; 144 } 145 146 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 147 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 256 auto decl = new StaticAssertDecl( 257 get<Expression>().accept1( node->cond ), 258 get<ConstantExpr>().accept1( node->msg ) 259 ); 260 declPostamble( decl, node ); 261 return nullptr; 262 } 263 264 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 265 cache.emplace( node, stmt ); 148 266 stmt->location = node->location; 149 267 stmt->labels = makeLabelL( stmt, node->labels ); … … 152 270 } 153 271 272 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 273 if ( inCache( node ) ) return nullptr; 274 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 275 stmtPostamble( stmt, node ); 276 return nullptr; 277 } 278 154 279 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 155 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );156 stmt->location = node->location;157 stmt->labels = makeLabelL( stmt, node->labels);158 this->node = stmt;159 return nullptr;280 if ( inCache( node ) ) return nullptr; 281 auto stmt = new ExprStmt( nullptr ); 282 cache.emplace( node, stmt ); 283 stmt->expr = get<Expression>().accept1( node->expr ); 284 return stmtPostamble( stmt, node ); 160 285 } 161 286 162 287 const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 288 if ( inCache( node ) ) return nullptr; 163 289 auto stmt = new AsmStmt( 164 290 node->isVolatile, … … 169 295 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 170 296 ); 171 stmt->location = node->location; 172 stmt->labels = makeLabelL( stmt, node->labels ); 173 this->node = stmt; 174 return nullptr; 297 return stmtPostamble( stmt, node ); 175 298 } 176 299 177 300 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 301 if ( inCache( node ) ) return nullptr; 178 302 auto stmt = new DirectiveStmt( node->directive ); 179 stmt->location = node->location; 180 stmt->labels = makeLabelL( stmt, node->labels ); 181 this->node = stmt; 182 return nullptr; 303 return stmtPostamble( stmt, node ); 183 304 } 184 305 185 306 const ast::Stmt * visit( const ast::IfStmt * node ) override final { 307 if ( inCache( node ) ) return nullptr; 186 308 auto stmt = new IfStmt( 187 309 get<Expression>().accept1( node->cond ), … … 190 312 get<Statement>().acceptL( node->inits ) 191 313 ); 192 stmt->location = node->location; 193 stmt->labels = makeLabelL( stmt, node->labels ); 194 this->node = stmt; 195 return nullptr; 314 return stmtPostamble( stmt, node ); 196 315 } 197 316 198 317 const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 318 if ( inCache( node ) ) return nullptr; 199 319 auto stmt = new SwitchStmt( 200 320 get<Expression>().accept1( node->cond ), 201 321 get<Statement>().acceptL( node->stmts ) 202 322 ); 203 stmt->location = node->location; 204 stmt->labels = makeLabelL( stmt, node->labels ); 205 this->node = stmt; 206 return nullptr; 323 return stmtPostamble( stmt, node ); 207 324 } 208 325 209 326 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 327 if ( inCache( node ) ) return nullptr; 210 328 auto stmt = new CaseStmt( 211 329 get<Expression>().accept1( node->cond ), … … 213 331 node->isDefault() 214 332 ); 215 stmt->location = node->location; 216 stmt->labels = makeLabelL( stmt, node->labels ); 217 this->node = stmt; 218 return nullptr; 333 return stmtPostamble( stmt, node ); 219 334 } 220 335 221 336 const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 337 if ( inCache( node ) ) return nullptr; 222 338 auto inits = get<Statement>().acceptL( node->inits ); 223 339 auto stmt = new WhileStmt( … … 227 343 node->isDoWhile 228 344 ); 229 stmt->location = node->location; 230 stmt->labels = makeLabelL( stmt, node->labels ); 231 this->node = stmt; 232 return nullptr; 345 return stmtPostamble( stmt, node ); 233 346 } 234 347 235 348 const ast::Stmt * visit( const ast::ForStmt * node ) override final { 349 if ( inCache( node ) ) return nullptr; 236 350 auto stmt = new ForStmt( 237 351 get<Statement>().acceptL( node->inits ), … … 240 354 get<Statement>().accept1( node->body ) 241 355 ); 242 stmt->location = node->location; 243 stmt->labels = makeLabelL( stmt, node->labels ); 244 this->node = stmt; 245 return nullptr; 356 return stmtPostamble( stmt, node ); 246 357 } 247 358 248 359 const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 360 if ( inCache( node ) ) return nullptr; 249 361 BranchStmt * stmt; 250 362 if (node->computedTarget) { … … 272 384 stmt->target = makeLabel( stmt, node->target ); 273 385 } 274 stmt->location = node->location; 275 stmt->labels = makeLabelL( stmt, node->labels ); 276 this->node = stmt; 277 return nullptr; 386 return stmtPostamble( stmt, node ); 278 387 } 279 388 280 389 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 390 if ( inCache( node ) ) return nullptr; 281 391 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 282 stmt->location = node->location; 283 stmt->labels = makeLabelL( stmt, node->labels ); 284 this->node = stmt; 285 return nullptr; 392 return stmtPostamble( stmt, node ); 286 393 } 287 394 288 395 const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 396 if ( inCache( node ) ) return nullptr; 289 397 ThrowStmt::Kind kind; 290 398 switch (node->kind) { … … 303 411 get<Expression>().accept1( node->target ) 304 412 ); 305 stmt->location = node->location; 306 stmt->labels = makeLabelL( stmt, node->labels ); 307 this->node = stmt; 308 return nullptr; 413 return stmtPostamble( stmt, node ); 309 414 } 310 415 311 416 const ast::Stmt * visit( const ast::TryStmt * node ) override final { 417 if ( inCache( node ) ) return nullptr; 312 418 auto handlers = get<CatchStmt>().acceptL( node->handlers ); 313 419 auto stmt = new TryStmt( … … 316 422 get<FinallyStmt>().accept1( node->finally ) 317 423 ); 318 stmt->location = node->location; 319 stmt->labels = makeLabelL( stmt, node->labels ); 320 this->node = stmt; 321 return nullptr; 424 return stmtPostamble( stmt, node ); 322 425 } 323 426 324 427 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 428 if ( inCache( node ) ) return nullptr; 325 429 CatchStmt::Kind kind; 326 430 switch (node->kind) { … … 340 444 get<Statement>().accept1( node->body ) 341 445 ); 342 stmt->location = node->location; 343 stmt->labels = makeLabelL( stmt, node->labels ); 344 this->node = stmt; 345 return nullptr; 446 return stmtPostamble( stmt, node ); 346 447 } 347 448 348 449 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 450 if ( inCache( node ) ) return nullptr; 349 451 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 350 stmt->location = node->location; 351 stmt->labels = makeLabelL( stmt, node->labels ); 352 this->node = stmt; 353 return nullptr; 452 return stmtPostamble( stmt, node ); 354 453 } 355 454 356 455 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 456 if ( inCache( node ) ) return nullptr; 357 457 auto stmt = new WaitForStmt; 358 458 stmt->clauses.reserve( node->clauses.size() ); 359 459 for ( auto clause : node->clauses ) { 360 460 stmt->clauses.push_back({{ 361 get<Expression>().accept1( clause.target.func tion),362 get<Expression>().acceptL( clause.target.arg uments ),461 get<Expression>().accept1( clause.target.func ), 462 get<Expression>().acceptL( clause.target.args ), 363 463 }, 364 464 get<Statement>().accept1( clause.stmt ), … … 375 475 get<Expression>().accept1( node->orElse.cond ), 376 476 }; 377 stmt->location = node->location; 378 stmt->labels = makeLabelL( stmt, node->labels ); 379 this->node = stmt; 380 return nullptr; 477 return stmtPostamble( stmt, node ); 381 478 } 382 479 383 480 const ast::Stmt * visit( const ast::WithStmt * node ) override final { 481 if ( inCache( node ) ) return nullptr; 384 482 auto stmt = new WithStmt( 385 483 get<Expression>().acceptL( node->exprs ), 386 484 get<Statement>().accept1( node->stmt ) 387 485 ); 388 stmt->location = node->location; 389 stmt->labels = makeLabelL( stmt, node->labels ); 390 this->node = stmt; 391 return nullptr; 486 return stmtPostamble( stmt, node ); 392 487 } 393 488 394 489 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 490 if ( inCache( node ) ) return nullptr; 395 491 auto stmt = new NullStmt(); 396 stmt->location = node->location; 397 stmt->labels = makeLabelL( stmt, node->labels ); 398 this->node = stmt; 492 stmtPostamble( stmt, node ); 399 493 return nullptr; 400 494 } 401 495 402 496 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 497 if ( inCache( node ) ) return nullptr; 403 498 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 404 stmt->location = node->location; 405 stmt->labels = makeLabelL( stmt, node->labels ); 406 this->node = stmt; 407 return nullptr; 499 return stmtPostamble( stmt, node ); 408 500 } 409 501 410 502 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 503 if ( inCache( node ) ) return nullptr; 504 auto stmt = new ImplicitCtorDtorStmt{ 505 get<Statement>().accept1( node->callStmt ) 506 }; 507 return stmtPostamble( stmt, node ); 508 } 509 510 TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) { 511 512 if (!src) return nullptr; 513 514 TypeSubstitution *rslt = new TypeSubstitution(); 515 516 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 517 rslt->add( src_i->first, 518 get<Type>().accept1(src_i->second) ); 519 } 520 521 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) { 522 rslt->addVar( src_i->first, 523 get<Expression>().accept1(src_i->second) ); 524 } 525 526 return rslt; 527 } 528 529 void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams, 530 std::vector<UniqueId> &tgtResnSlots, 531 const ast::Expr::InferUnion &srcInferred ) { 532 533 assert( tgtInferParams.empty() ); 534 assert( tgtResnSlots.empty() ); 535 536 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) { 537 const ast::InferredParams &srcParams = srcInferred.inferParamsConst(); 538 for (auto srcParam : srcParams) { 539 tgtInferParams[srcParam.first] = ParamEntry( 540 srcParam.second.decl, 541 get<Type>().accept1(srcParam.second.actualType), 542 get<Type>().accept1(srcParam.second.formalType), 543 get<Expression>().accept1(srcParam.second.expr) 544 ); 545 } 546 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) { 547 const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst(); 548 for (auto srcSlot : srcSlots) { 549 tgtResnSlots.push_back(srcSlot); 550 } 551 } 552 } 553 554 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 555 556 tgt->location = src->location; 557 tgt->env = convertTypeSubstitution(src->env); 558 tgt->extension = src->extension; 559 560 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 561 return tgt; 562 } 563 564 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 565 566 tgt->result = get<Type>().accept1(src->result); 567 return visitBaseExpr_skipResultType(src, tgt); 568 } 569 570 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 571 auto expr = visitBaseExpr( node, 572 new ApplicationExpr( 573 get<Expression>().accept1(node->func), 574 get<Expression>().acceptL(node->args) 575 ) 576 ); 577 this->node = expr; 578 return nullptr; 579 } 580 581 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 582 auto expr = visitBaseExpr( node, 583 new UntypedExpr( 584 get<Expression>().accept1(node->func), 585 get<Expression>().acceptL(node->args) 586 ) 587 ); 588 this->node = expr; 589 return nullptr; 590 } 591 592 const ast::Expr * visit( const ast::NameExpr * node ) override final { 593 auto expr = visitBaseExpr( node, 594 new NameExpr( 595 node->name 596 ) 597 ); 598 this->node = expr; 599 return nullptr; 600 } 601 602 const ast::Expr * visit( const ast::AddressExpr * node ) override final { 603 auto expr = visitBaseExpr( node, 604 new AddressExpr( 605 get<Expression>().accept1(node->arg) 606 ) 607 ); 608 this->node = expr; 609 return nullptr; 610 } 611 612 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final { 613 auto expr = visitBaseExpr( node, 614 new LabelAddressExpr( 615 makeLabel(nullptr, node->arg) 616 ) 617 ); 618 this->node = expr; 619 return nullptr; 620 } 621 622 const ast::Expr * visit( const ast::CastExpr * node ) override final { 623 auto expr = visitBaseExpr( node, 624 new CastExpr( 625 get<Expression>().accept1(node->arg), 626 (node->isGenerated == ast::GeneratedCast) 627 ) 628 ); 629 this->node = expr; 630 return nullptr; 631 } 632 633 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 634 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 635 switch (node->target) { 636 case ast::KeywordCastExpr::Coroutine: 637 castTarget = KeywordCastExpr::Coroutine; 638 break; 639 case ast::KeywordCastExpr::Thread: 640 castTarget = KeywordCastExpr::Thread; 641 break; 642 case ast::KeywordCastExpr::Monitor: 643 castTarget = KeywordCastExpr::Monitor; 644 break; 645 default: 646 break; 647 } 648 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 649 auto expr = visitBaseExpr( node, 650 new KeywordCastExpr( 651 get<Expression>().accept1(node->arg), 652 castTarget 653 ) 654 ); 655 this->node = expr; 656 return nullptr; 657 } 658 659 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 660 auto expr = visitBaseExpr_skipResultType( node, 661 new VirtualCastExpr( 662 get<Expression>().accept1(node->arg), 663 get<Type>().accept1(node->result) 664 ) 665 ); 666 this->node = expr; 667 return nullptr; 668 } 669 670 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final { 671 auto expr = visitBaseExpr( node, 672 new UntypedMemberExpr( 673 get<Expression>().accept1(node->member), 674 get<Expression>().accept1(node->aggregate) 675 ) 676 ); 677 this->node = expr; 678 return nullptr; 679 } 680 681 const ast::Expr * visit( const ast::MemberExpr * node ) override final { 682 auto expr = visitBaseExpr( node, 683 new MemberExpr( 684 inCache(node->member) ? 685 dynamic_cast<DeclarationWithType *>(this->node) : 686 get<DeclarationWithType>().accept1(node->member), 687 get<Expression>().accept1(node->aggregate) 688 ) 689 ); 690 this->node = expr; 691 return nullptr; 692 } 693 694 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 695 auto expr = visitBaseExpr( node, 696 new VariableExpr( 697 inCache(node->var) ? 698 dynamic_cast<DeclarationWithType *>(this->node) : 699 get<DeclarationWithType>().accept1(node->var) 700 ) 701 ); 702 this->node = expr; 703 return nullptr; 704 } 705 706 bool isIntlikeConstantType(const ast::Type *t) { 707 if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) { 708 if ( basicType->isInteger() ) { 709 return true; 710 } 711 } else if ( dynamic_cast< const ast::OneType * >( t ) ) { 712 return true; 713 } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) { 714 return true; 715 } else if ( dynamic_cast< const ast::PointerType * >( t ) ) { 716 // null pointer constants, with zero int-values 717 return true; 718 } 719 return false; 720 } 721 722 bool isFloatlikeConstantType(const ast::Type *t) { 723 if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) { 724 if ( ! bty->isInteger() ) { 725 return true; 726 } 727 } 728 return false; 729 } 730 731 bool isStringlikeConstantType(const ast::Type *t) { 732 if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) { 733 if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) { 734 if ( bty->kind == ast::BasicType::Kind::Char ) { 735 return true; 736 } 737 } 738 } 739 return false; 740 } 741 742 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 743 ConstantExpr *rslt = nullptr; 744 if (isIntlikeConstantType(node->result)) { 745 rslt = new ConstantExpr(Constant( 746 get<Type>().accept1(node->result), 747 node->rep, 748 (unsigned long long) node->intValue() 749 )); 750 } else if (isFloatlikeConstantType(node->result)) { 751 rslt = new ConstantExpr(Constant( 752 get<Type>().accept1(node->result), 753 node->rep, 754 (double) node->floatValue() 755 )); 756 } else if (isStringlikeConstantType(node->result)) { 757 rslt = new ConstantExpr(Constant::from_string( 758 node->rep 759 )); 760 } 761 assert(rslt); 762 auto expr = visitBaseExpr( node, rslt ); 763 this->node = expr; 764 return nullptr; 765 } 766 767 const ast::Expr * visit( const ast::SizeofExpr * node ) override final { 768 assert (node->expr || node->type); 769 assert (! (node->expr && node->type)); 770 SizeofExpr *rslt; 771 if (node->expr) { 772 rslt = new SizeofExpr( 773 get<Expression>().accept1(node->expr) 774 ); 775 assert (!rslt->isType); 776 } 777 if (node->type) { 778 rslt = new SizeofExpr( 779 get<Type>().accept1(node->type) 780 ); 781 assert (rslt->isType); 782 } 783 auto expr = visitBaseExpr( node, rslt ); 784 this->node = expr; 785 return nullptr; 786 } 787 788 const ast::Expr * visit( const ast::AlignofExpr * node ) override final { 789 assert (node->expr || node->type); 790 assert (! (node->expr && node->type)); 791 AlignofExpr *rslt; 792 if (node->expr) { 793 rslt = new AlignofExpr( 794 get<Expression>().accept1(node->expr) 795 ); 796 assert (!rslt->isType); 797 } 798 if (node->type) { 799 rslt = new AlignofExpr( 800 get<Type>().accept1(node->type) 801 ); 802 assert (rslt->isType); 803 } 804 auto expr = visitBaseExpr( node, rslt ); 805 this->node = expr; 806 return nullptr; 807 } 808 809 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final { 810 auto expr = visitBaseExpr( node, 811 new UntypedOffsetofExpr( 812 get<Type>().accept1(node->type), 813 node->member 814 ) 815 ); 816 this->node = expr; 817 return nullptr; 818 } 819 820 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final { 821 auto expr = visitBaseExpr( node, 822 new OffsetofExpr( 823 get<Type>().accept1(node->type), 824 inCache(node->member) ? 825 dynamic_cast<DeclarationWithType *>(this->node) : 826 get<DeclarationWithType>().accept1(node->member) 827 ) 828 ); 829 this->node = expr; 830 return nullptr; 831 } 832 833 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final { 834 auto expr = visitBaseExpr( node, 835 new OffsetPackExpr( 836 get<StructInstType>().accept1(node->type) 837 ) 838 ); 839 this->node = expr; 840 return nullptr; 841 } 842 843 const ast::Expr * visit( const ast::LogicalExpr * node ) override final { 844 assert (node->isAnd == ast::LogicalFlag::AndExpr || 845 node->isAnd == ast::LogicalFlag::OrExpr ); 846 auto expr = visitBaseExpr( node, 847 new LogicalExpr( 848 get<Expression>().accept1(node->arg1), 849 get<Expression>().accept1(node->arg2), 850 (node->isAnd == ast::LogicalFlag::AndExpr) 851 ) 852 ); 853 this->node = expr; 854 return nullptr; 855 } 856 857 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final { 858 auto expr = visitBaseExpr( node, 859 new ConditionalExpr( 860 get<Expression>().accept1(node->arg1), 861 get<Expression>().accept1(node->arg2), 862 get<Expression>().accept1(node->arg3) 863 ) 864 ); 865 this->node = expr; 866 return nullptr; 867 } 868 869 const ast::Expr * visit( const ast::CommaExpr * node ) override final { 870 auto expr = visitBaseExpr( node, 871 new CommaExpr( 872 get<Expression>().accept1(node->arg1), 873 get<Expression>().accept1(node->arg2) 874 ) 875 ); 876 this->node = expr; 877 return nullptr; 878 } 879 880 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 881 auto expr = visitBaseExpr( node, 882 new TypeExpr( 883 get<Type>().accept1(node->type) 884 ) 885 ); 886 this->node = expr; 887 return nullptr; 888 } 889 890 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 891 auto expr = visitBaseExpr( node, 892 new AsmExpr( 893 get<Expression>().accept1(node->inout), 894 get<Expression>().accept1(node->constraint), 895 get<Expression>().accept1(node->operand) 896 ) 897 ); 898 this->node = expr; 899 return nullptr; 900 } 901 902 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 903 auto rslt = new ImplicitCopyCtorExpr( 904 get<ApplicationExpr>().accept1(node->callExpr) 905 ); 906 907 rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls); 908 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 909 rslt->dtors = get<Expression>().acceptL(node->dtors); 910 911 auto expr = visitBaseExpr( node, rslt ); 912 this->node = expr; 913 return nullptr; 914 } 915 916 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 917 auto expr = visitBaseExpr( node, 918 new ConstructorExpr( 919 get<Expression>().accept1(node->callExpr) 920 ) 921 ); 922 this->node = expr; 923 return nullptr; 924 } 925 926 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 927 auto expr = visitBaseExpr_skipResultType( node, 928 new CompoundLiteralExpr( 929 get<Type>().accept1(node->result), 930 get<Initializer>().accept1(node->init) 931 ) 932 ); 933 this->node = expr; 934 return nullptr; 935 } 936 937 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 938 auto expr = visitBaseExpr( node, 939 new RangeExpr( 940 get<Expression>().accept1(node->low), 941 get<Expression>().accept1(node->high) 942 ) 943 ); 944 this->node = expr; 945 return nullptr; 946 } 947 948 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 949 auto expr = visitBaseExpr( node, 950 new UntypedTupleExpr( 951 get<Expression>().acceptL(node->exprs) 952 ) 953 ); 954 this->node = expr; 955 return nullptr; 956 } 957 958 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 959 auto expr = visitBaseExpr( node, 960 new UntypedTupleExpr( 961 get<Expression>().acceptL(node->exprs) 962 ) 963 ); 964 this->node = expr; 965 return nullptr; 966 } 967 968 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 969 auto expr = visitBaseExpr( node, 970 new TupleIndexExpr( 971 get<Expression>().accept1(node->tuple), 972 node->index 973 ) 974 ); 975 this->node = expr; 976 return nullptr; 977 } 978 979 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 980 auto expr = visitBaseExpr( node, 981 new TupleAssignExpr( 982 get<StmtExpr>().accept1(node->stmtExpr) 983 ) 984 ); 985 this->node = expr; 986 return nullptr; 987 } 988 989 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 990 auto rslt = new StmtExpr( 991 get<CompoundStmt>().accept1(node->stmts) 992 ); 993 994 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 995 rslt->dtors = get<Expression>().acceptL(node->dtors); 996 997 auto expr = visitBaseExpr( node, rslt ); 998 this->node = expr; 999 return nullptr; 1000 } 1001 1002 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 1003 auto rslt = new UniqueExpr( 1004 get<Expression>().accept1(node->expr) 1005 ); 1006 1007 rslt->object = get<ObjectDecl> ().accept1(node->object); 1008 rslt->var = get<VariableExpr>().accept1(node->var); 1009 1010 auto expr = visitBaseExpr( node, rslt ); 1011 this->node = expr; 1012 return nullptr; 1013 } 1014 1015 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 1016 std::list<InitAlternative> initAlts; 1017 for (auto ia : node->initAlts) { 1018 initAlts.push_back(InitAlternative( 1019 get<Type> ().accept1(ia.type), 1020 get<Designation>().accept1(ia.designation) 1021 )); 1022 } 1023 auto expr = visitBaseExpr( node, 1024 new UntypedInitExpr( 1025 get<Expression>().accept1(node->expr), 1026 initAlts 1027 ) 1028 ); 1029 this->node = expr; 1030 return nullptr; 1031 } 1032 1033 const ast::Expr * visit( const ast::InitExpr * node ) override final { 1034 auto expr = visitBaseExpr( node, 1035 new InitExpr( 1036 get<Expression>().accept1(node->expr), 1037 get<Designation>().accept1(node->designation) 1038 ) 1039 ); 1040 this->node = expr; 1041 return nullptr; 1042 } 1043 1044 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 1045 auto expr = visitBaseExpr( node, 1046 new DeletedExpr( 1047 get<Expression>().accept1(node->expr), 1048 inCache(node->deleteStmt) ? 1049 this->node : 1050 get<BaseSyntaxNode>().accept1(node->deleteStmt) 1051 ) 1052 ); 1053 this->node = expr; 1054 return nullptr; 1055 } 1056 1057 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 1058 auto expr = visitBaseExpr( node, 1059 new DefaultArgExpr( 1060 get<Expression>().accept1(node->expr) 1061 ) 1062 ); 1063 this->node = expr; 1064 return nullptr; 1065 } 1066 1067 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 1068 std::list<GenericExpr::Association> associations; 1069 for (auto association : node->associations) { 1070 associations.push_back(GenericExpr::Association( 1071 get<Type> ().accept1(association.type), 1072 get<Expression>().accept1(association.expr) 1073 )); 1074 } 1075 auto expr = visitBaseExpr( node, 1076 new GenericExpr( 1077 get<Expression>().accept1(node->control), 1078 associations 1079 ) 1080 ); 1081 this->node = expr; 1082 return nullptr; 1083 } 1084 1085 const ast::Type * visit( const ast::VoidType * node ) override final { 1086 this->node = new VoidType{ cv( node ) }; 1087 return nullptr; 1088 } 1089 1090 const ast::Type * visit( const ast::BasicType * node ) override final { 1091 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1092 return nullptr; 1093 } 1094 1095 const ast::Type * visit( const ast::PointerType * node ) override final { 1096 this->node = new PointerType{ 1097 cv( node ), 1098 get<Type>().accept1( node->base ), 1099 get<Expression>().accept1( node->dimension ), 1100 (bool)node->isVarLen, 1101 (bool)node->isStatic 1102 }; 1103 return nullptr; 1104 } 1105 1106 const ast::Type * visit( const ast::ArrayType * node ) override final { 1107 this->node = new ArrayType{ 1108 cv( node ), 1109 get<Type>().accept1( node->base ), 1110 get<Expression>().accept1( node->dimension ), 1111 (bool)node->isVarLen, 1112 (bool)node->isStatic 1113 }; 1114 return nullptr; 1115 } 1116 1117 const ast::Type * visit( const ast::ReferenceType * node ) override final { 1118 this->node = new ReferenceType{ 1119 cv( node ), 1120 get<Type>().accept1( node->base ) 1121 }; 1122 return nullptr; 1123 } 1124 1125 const ast::Type * visit( const ast::QualifiedType * node ) override final { 1126 this->node = new QualifiedType{ 1127 cv( node ), 1128 get<Type>().accept1( node->parent ), 1129 get<Type>().accept1( node->child ) 1130 }; 1131 return nullptr; 1132 } 1133 1134 const ast::Type * visit( const ast::FunctionType * node ) override final { 1135 auto ty = new FunctionType { 1136 cv( node ), 1137 (bool)node->isVarArgs 1138 }; 1139 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1140 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1141 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1142 this->node = ty; 1143 return nullptr; 1144 } 1145 1146 void postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) { 1147 ty->forall = get<TypeDecl>().acceptL( old->forall ); 1148 ty->parameters = get<Expression>().acceptL( old->params ); 1149 ty->hoistType = old->hoistType; 1150 } 1151 1152 const ast::Type * visit( const ast::StructInstType * node ) override final { 1153 StructInstType * ty; 1154 if ( node->base ) { 1155 ty = new StructInstType{ 1156 cv( node ), 1157 get<StructDecl>().accept1( node->base ), 1158 get<Attribute>().acceptL( node->attributes ) 1159 }; 1160 } else { 1161 ty = new StructInstType{ 1162 cv( node ), 1163 node->name, 1164 get<Attribute>().acceptL( node->attributes ) 1165 }; 1166 } 1167 postvisit( node, ty ); 1168 this->node = ty; 1169 return nullptr; 1170 } 1171 1172 const ast::Type * visit( const ast::UnionInstType * node ) override final { 1173 UnionInstType * ty; 1174 if ( node->base ) { 1175 ty = new UnionInstType{ 1176 cv( node ), 1177 get<UnionDecl>().accept1( node->base ), 1178 get<Attribute>().acceptL( node->attributes ) 1179 }; 1180 } else { 1181 ty = new UnionInstType{ 1182 cv( node ), 1183 node->name, 1184 get<Attribute>().acceptL( node->attributes ) 1185 }; 1186 } 1187 postvisit( node, ty ); 1188 this->node = ty; 1189 return nullptr; 1190 } 1191 1192 const ast::Type * visit( const ast::EnumInstType * node ) override final { 1193 EnumInstType * ty; 1194 if ( node->base ) { 1195 ty = new EnumInstType{ 1196 cv( node ), 1197 get<EnumDecl>().accept1( node->base ), 1198 get<Attribute>().acceptL( node->attributes ) 1199 }; 1200 } else { 1201 ty = new EnumInstType{ 1202 cv( node ), 1203 node->name, 1204 get<Attribute>().acceptL( node->attributes ) 1205 }; 1206 } 1207 postvisit( node, ty ); 1208 this->node = ty; 1209 return nullptr; 1210 } 1211 1212 const ast::Type * visit( const ast::TraitInstType * node ) override final { 1213 TraitInstType * ty; 1214 if ( node->base ) { 1215 ty = new TraitInstType{ 1216 cv( node ), 1217 get<TraitDecl>().accept1( node->base ), 1218 get<Attribute>().acceptL( node->attributes ) 1219 }; 1220 } else { 1221 ty = new TraitInstType{ 1222 cv( node ), 1223 node->name, 1224 get<Attribute>().acceptL( node->attributes ) 1225 }; 1226 } 1227 postvisit( node, ty ); 1228 this->node = ty; 1229 return nullptr; 1230 } 1231 1232 const ast::Type * visit( const ast::TypeInstType * node ) override final { 1233 TypeInstType * ty; 1234 if ( node->base ) { 1235 ty = new TypeInstType{ 1236 cv( node ), 1237 node->name, 1238 get<TypeDecl>().accept1( node->base ), 1239 get<Attribute>().acceptL( node->attributes ) 1240 }; 1241 } else { 1242 ty = new TypeInstType{ 1243 cv( node ), 1244 node->name, 1245 node->kind == ast::TypeVar::Ftype, 1246 get<Attribute>().acceptL( node->attributes ) 1247 }; 1248 } 1249 postvisit( node, ty ); 1250 this->node = ty; 1251 return nullptr; 1252 } 1253 1254 const ast::Type * visit( const ast::TupleType * node ) override final { 1255 this->node = new TupleType{ 1256 cv( node ), 1257 get<Type>().acceptL( node->types ) 1258 // members generated by TupleType c'tor 1259 }; 1260 return nullptr; 1261 } 1262 1263 const ast::Type * visit( const ast::TypeofType * node ) override final { 1264 this->node = new TypeofType{ 1265 cv( node ), 1266 get<Expression>().accept1( node->expr ), 1267 (bool)node->kind 1268 }; 1269 return nullptr; 1270 } 1271 1272 const ast::Type * visit( const ast::VarArgsType * node ) override final { 1273 this->node = new VarArgsType{ cv( node ) }; 1274 return nullptr; 1275 } 1276 1277 const ast::Type * visit( const ast::ZeroType * node ) override final { 1278 this->node = new ZeroType{ cv( node ) }; 1279 return nullptr; 1280 } 1281 1282 const ast::Type * visit( const ast::OneType * node ) override final { 1283 this->node = new OneType{ cv( node ) }; 1284 return nullptr; 1285 } 1286 1287 const ast::Type * visit( const ast::GlobalScopeType * ) override final { 1288 this->node = new GlobalScopeType{}; 1289 return nullptr; 1290 } 1291 1292 const ast::Designation * visit( const ast::Designation * node ) override final { 1293 auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); 1294 designation->location = node->location; 1295 this->node = designation; 1296 return nullptr; 1297 } 1298 1299 const ast::Init * visit( const ast::SingleInit * node ) override final { 1300 auto init = new SingleInit( 1301 get<Expression>().accept1( node->value ), 1302 ast::MaybeConstruct == node->maybeConstructed 1303 ); 1304 init->location = node->location; 1305 this->node = init; 1306 return nullptr; 1307 } 1308 1309 const ast::Init * visit( const ast::ListInit * node ) override final { 1310 auto init = new ListInit( 1311 get<Initializer>().acceptL( node->initializers ), 1312 get<Designation>().acceptL( node->designations ), 1313 ast::MaybeConstruct == node->maybeConstructed 1314 ); 1315 init->location = node->location; 1316 this->node = init; 1317 return nullptr; 1318 } 1319 1320 const ast::Init * visit( const ast::ConstructorInit * node ) override final { 1321 auto init = new ConstructorInit( 1322 get<Statement>().accept1( node->ctor ), 1323 get<Statement>().accept1( node->dtor ), 1324 get<Initializer>().accept1( node->init ) 1325 ); 1326 init->location = node->location; 1327 this->node = init; 1328 return nullptr; 1329 } 1330 1331 const ast::Attribute * visit( const ast::Attribute * node ) override final { 1332 auto attr = new Attribute( 1333 node->name, 1334 get<Expression>().acceptL(node->params) 1335 ); 1336 this->node = attr; 1337 return nullptr; 1338 } 1339 1340 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 1341 // Handled by convertTypeSubstitution helper instead. 1342 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node. 1343 assert( 0 ); 411 1344 (void)node; 412 1345 return nullptr; 413 1346 } 414 415 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final {416 (void)node;417 return nullptr;418 }419 420 const ast::Expr * visit( const ast::UntypedExpr * node ) override final {421 (void)node;422 return nullptr;423 }424 425 const ast::Expr * visit( const ast::NameExpr * node ) override final {426 (void)node;427 return nullptr;428 }429 430 const ast::Expr * visit( const ast::AddressExpr * node ) override final {431 (void)node;432 return nullptr;433 }434 435 const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {436 (void)node;437 return nullptr;438 }439 440 const ast::Expr * visit( const ast::CastExpr * node ) override final {441 (void)node;442 return nullptr;443 }444 445 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {446 (void)node;447 return nullptr;448 }449 450 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {451 (void)node;452 return nullptr;453 }454 455 const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {456 (void)node;457 return nullptr;458 }459 460 const ast::Expr * visit( const ast::MemberExpr * node ) override final {461 (void)node;462 return nullptr;463 }464 465 const ast::Expr * visit( const ast::VariableExpr * node ) override final {466 (void)node;467 return nullptr;468 }469 470 const ast::Expr * visit( const ast::ConstantExpr * node ) override final {471 (void)node;472 return nullptr;473 }474 475 const ast::Expr * visit( const ast::SizeofExpr * node ) override final {476 (void)node;477 return nullptr;478 }479 480 const ast::Expr * visit( const ast::AlignofExpr * node ) override final {481 (void)node;482 return nullptr;483 }484 485 const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {486 (void)node;487 return nullptr;488 }489 490 const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {491 (void)node;492 return nullptr;493 }494 495 const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {496 (void)node;497 return nullptr;498 }499 500 const ast::Expr * visit( const ast::LogicalExpr * node ) override final {501 (void)node;502 return nullptr;503 }504 505 const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {506 (void)node;507 return nullptr;508 }509 510 const ast::Expr * visit( const ast::CommaExpr * node ) override final {511 (void)node;512 return nullptr;513 }514 515 const ast::Expr * visit( const ast::TypeExpr * node ) override final {516 (void)node;517 return nullptr;518 }519 520 const ast::Expr * visit( const ast::AsmExpr * node ) override final {521 (void)node;522 return nullptr;523 }524 525 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {526 (void)node;527 return nullptr;528 }529 530 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {531 (void)node;532 return nullptr;533 }534 535 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {536 (void)node;537 return nullptr;538 }539 540 const ast::Expr * visit( const ast::RangeExpr * node ) override final {541 (void)node;542 return nullptr;543 }544 545 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {546 (void)node;547 return nullptr;548 }549 550 const ast::Expr * visit( const ast::TupleExpr * node ) override final {551 (void)node;552 return nullptr;553 }554 555 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {556 (void)node;557 return nullptr;558 }559 560 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {561 (void)node;562 return nullptr;563 }564 565 const ast::Expr * visit( const ast::StmtExpr * node ) override final {566 (void)node;567 return nullptr;568 }569 570 const ast::Expr * visit( const ast::UniqueExpr * node ) override final {571 (void)node;572 return nullptr;573 }574 575 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {576 (void)node;577 return nullptr;578 }579 580 const ast::Expr * visit( const ast::InitExpr * node ) override final {581 (void)node;582 return nullptr;583 }584 585 const ast::Expr * visit( const ast::DeletedExpr * node ) override final {586 (void)node;587 return nullptr;588 }589 590 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {591 (void)node;592 return nullptr;593 }594 595 const ast::Expr * visit( const ast::GenericExpr * node ) override final {596 (void)node;597 return nullptr;598 }599 600 const ast::Type * visit( const ast::VoidType * node ) override final {601 (void)node;602 return nullptr;603 }604 605 const ast::Type * visit( const ast::BasicType * node ) override final {606 (void)node;607 return nullptr;608 }609 610 const ast::Type * visit( const ast::PointerType * node ) override final {611 (void)node;612 return nullptr;613 }614 615 const ast::Type * visit( const ast::ArrayType * node ) override final {616 (void)node;617 return nullptr;618 }619 620 const ast::Type * visit( const ast::ReferenceType * node ) override final {621 (void)node;622 return nullptr;623 }624 625 const ast::Type * visit( const ast::QualifiedType * node ) override final {626 (void)node;627 return nullptr;628 }629 630 const ast::Type * visit( const ast::FunctionType * node ) override final {631 (void)node;632 return nullptr;633 }634 635 const ast::Type * visit( const ast::StructInstType * node ) override final {636 (void)node;637 return nullptr;638 }639 640 const ast::Type * visit( const ast::UnionInstType * node ) override final {641 (void)node;642 return nullptr;643 }644 645 const ast::Type * visit( const ast::EnumInstType * node ) override final {646 (void)node;647 return nullptr;648 }649 650 const ast::Type * visit( const ast::TraitInstType * node ) override final {651 (void)node;652 return nullptr;653 }654 655 const ast::Type * visit( const ast::TypeInstType * node ) override final {656 (void)node;657 return nullptr;658 }659 660 const ast::Type * visit( const ast::TupleType * node ) override final {661 (void)node;662 return nullptr;663 }664 665 const ast::Type * visit( const ast::TypeofType * node ) override final {666 (void)node;667 return nullptr;668 }669 670 const ast::Type * visit( const ast::VarArgsType * node ) override final {671 (void)node;672 return nullptr;673 }674 675 const ast::Type * visit( const ast::ZeroType * node ) override final {676 (void)node;677 return nullptr;678 }679 680 const ast::Type * visit( const ast::OneType * node ) override final {681 (void)node;682 return nullptr;683 }684 685 const ast::Type * visit( const ast::GlobalScopeType * node ) override final {686 (void)node;687 return nullptr;688 }689 690 const ast::Designation * visit( const ast::Designation * node ) override final {691 (void)node;692 return nullptr;693 }694 695 const ast::Init * visit( const ast::SingleInit * node ) override final {696 (void)node;697 return nullptr;698 }699 700 const ast::Init * visit( const ast::ListInit * node ) override final {701 (void)node;702 return nullptr;703 }704 705 const ast::Init * visit( const ast::ConstructorInit * node ) override final {706 (void)node;707 return nullptr;708 }709 710 const ast::Attribute * visit( const ast::Attribute * node ) override final {711 (void)node;712 return nullptr;713 }714 715 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {716 (void)node;717 return nullptr;718 }719 1347 }; 720 1348 721 std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) {1349 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) { 722 1350 ConverterNewToOld c; 723 1351 std::list< Declaration * > decls; 724 1352 for(auto d : translationUnit) { 725 1353 decls.emplace_back( c.decl( d ) ); 726 delete d;727 1354 } 728 1355 return decls; … … 737 1364 } 738 1365 private: 1366 /// conversion output 739 1367 ast::Node * node; 1368 /// cache of nodes that might be referenced by readonly<> for de-duplication 1369 std::unordered_map< BaseSyntaxNode *, ast::Node * > cache; 740 1370 741 1371 // Local Utilities: … … 743 1373 template<typename NewT, typename OldT> 744 1374 NewT * getAccept1( OldT old ) { 1375 if ( ! old ) return nullptr; 745 1376 old->accept(*this); 746 1377 return strict_dynamic_cast< NewT * >( node ); … … 784 1415 to<std::vector>::from( make_labels( std::move( labels ) ) ) 785 1416 1417 static ast::CV::Qualifiers cv( Type * ty ) { return { ty->get_qualifiers().val }; } 1418 1419 /// returns true and sets `node` if in cache 1420 bool inCache( BaseSyntaxNode * old ) { 1421 auto it = cache.find( old ); 1422 if ( it == cache.end() ) return false; 1423 node = it->second; 1424 return true; 1425 } 1426 786 1427 // Now all the visit functions: 787 1428 788 1429 virtual void visit( ObjectDecl * old ) override final { 1430 if ( inCache( old ) ) return; 789 1431 auto decl = new ast::ObjectDecl( 790 1432 old->location, … … 798 1440 { old->get_funcSpec().val } 799 1441 ); 1442 cache.emplace( old, decl ); 800 1443 decl->scopeLevel = old->scopeLevel; 801 1444 decl->mangleName = old->mangleName; … … 807 1450 } 808 1451 809 virtual void visit( FunctionDecl * ) override final { 810 1452 virtual void visit( FunctionDecl * old ) override final { 1453 if ( inCache( old ) ) return; 1454 auto decl = new ast::FunctionDecl{ 1455 old->location, 1456 old->name, 1457 GET_ACCEPT_1(type, FunctionType), 1458 GET_ACCEPT_1(statements, CompoundStmt), 1459 { old->storageClasses.val }, 1460 { old->linkage.val }, 1461 GET_ACCEPT_V(attributes, Attribute), 1462 { old->get_funcSpec().val } 1463 }; 1464 cache.emplace( old, decl ); 1465 decl->scopeLevel = old->scopeLevel; 1466 decl->mangleName = old->mangleName; 1467 decl->isDeleted = old->isDeleted; 1468 decl->uniqueId = old->uniqueId; 1469 decl->extension = old->extension; 1470 1471 this->node = decl; 811 1472 } 812 1473 813 1474 virtual void visit( StructDecl * old ) override final { 1475 if ( inCache( old ) ) return; 814 1476 auto decl = new ast::StructDecl( 815 1477 old->location, … … 819 1481 { old->linkage.val } 820 1482 ); 1483 cache.emplace( old, decl ); 821 1484 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 822 1485 decl->body = old->body; … … 831 1494 832 1495 virtual void visit( UnionDecl * old ) override final { 1496 if ( inCache( old ) ) return; 833 1497 auto decl = new ast::UnionDecl( 834 1498 old->location, … … 837 1501 { old->linkage.val } 838 1502 ); 1503 cache.emplace( old, decl ); 839 1504 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 840 1505 decl->body = old->body; … … 849 1514 850 1515 virtual void visit( EnumDecl * old ) override final { 1516 if ( inCache( old ) ) return; 851 1517 auto decl = new ast::UnionDecl( 852 1518 old->location, … … 855 1521 { old->linkage.val } 856 1522 ); 1523 cache.emplace( old, decl ); 857 1524 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 858 1525 decl->body = old->body; … … 867 1534 868 1535 virtual void visit( TraitDecl * old ) override final { 1536 if ( inCache( old ) ) return; 869 1537 auto decl = new ast::UnionDecl( 870 1538 old->location, … … 873 1541 { old->linkage.val } 874 1542 ); 1543 cache.emplace( old, decl ); 875 1544 decl->parent = GET_ACCEPT_1(parent, AggregateDecl); 876 1545 decl->body = old->body; … … 884 1553 } 885 1554 886 virtual void visit( TypeDecl * ) override final { 887 1555 virtual void visit( TypeDecl * old ) override final { 1556 if ( inCache( old ) ) return; 1557 auto decl = new ast::TypeDecl{ 1558 old->location, 1559 old->name, 1560 { old->storageClasses.val }, 1561 GET_ACCEPT_1(base, Type), 1562 (ast::TypeVar::Kind)(unsigned)old->kind, 1563 old->sized, 1564 GET_ACCEPT_1(init, Type) 1565 }; 1566 cache.emplace( old, decl ); 1567 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1568 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1569 decl->extension = old->extension; 1570 decl->uniqueId = old->uniqueId; 1571 1572 this->node = decl; 888 1573 } 889 1574 … … 905 1590 } 906 1591 907 virtual void visit( AsmDecl * ) override final { 908 909 } 910 911 virtual void visit( StaticAssertDecl * ) override final { 912 1592 virtual void visit( AsmDecl * old ) override final { 1593 auto decl = new ast::AsmDecl{ 1594 old->location, 1595 GET_ACCEPT_1(stmt, AsmStmt) 1596 }; 1597 decl->extension = old->extension; 1598 decl->uniqueId = old->uniqueId; 1599 decl->storage = { old->storageClasses.val }; 1600 1601 this->node = decl; 1602 } 1603 1604 virtual void visit( StaticAssertDecl * old ) override final { 1605 auto decl = new ast::StaticAssertDecl{ 1606 old->location, 1607 GET_ACCEPT_1(condition, Expr), 1608 GET_ACCEPT_1(message, ConstantExpr) 1609 }; 1610 decl->extension = old->extension; 1611 decl->uniqueId = old->uniqueId; 1612 decl->storage = { old->storageClasses.val }; 1613 1614 this->node = decl; 913 1615 } 914 1616 915 1617 virtual void visit( CompoundStmt * old ) override final { 1618 if ( inCache( old ) ) return; 916 1619 auto stmt = new ast::CompoundStmt( 917 1620 old->location, … … 921 1624 922 1625 this->node = stmt; 1626 cache.emplace( old, this->node ); 923 1627 } 924 1628 925 1629 virtual void visit( ExprStmt * old ) override final { 1630 if ( inCache( old ) ) return; 926 1631 this->node = new ast::ExprStmt( 927 1632 old->location, … … 929 1634 GET_LABELS_V(old->labels) 930 1635 ); 1636 cache.emplace( old, this->node ); 931 1637 } 932 1638 933 1639 virtual void visit( AsmStmt * old ) override final { 1640 if ( inCache( old ) ) return; 934 1641 this->node = new ast::AsmStmt( 935 1642 old->location, … … 942 1649 GET_LABELS_V(old->labels) 943 1650 ); 1651 cache.emplace( old, this->node ); 944 1652 } 945 1653 946 1654 virtual void visit( DirectiveStmt * old ) override final { 1655 if ( inCache( old ) ) return; 947 1656 this->node = new ast::DirectiveStmt( 948 1657 old->location, … … 950 1659 GET_LABELS_V(old->labels) 951 1660 ); 1661 cache.emplace( old, this->node ); 952 1662 } 953 1663 954 1664 virtual void visit( IfStmt * old ) override final { 1665 if ( inCache( old ) ) return; 955 1666 this->node = new ast::IfStmt( 956 1667 old->location, … … 961 1672 GET_LABELS_V(old->labels) 962 1673 ); 1674 cache.emplace( old, this->node ); 963 1675 } 964 1676 965 1677 virtual void visit( SwitchStmt * old ) override final { 1678 if ( inCache( old ) ) return; 966 1679 this->node = new ast::SwitchStmt( 967 1680 old->location, … … 970 1683 GET_LABELS_V(old->labels) 971 1684 ); 1685 cache.emplace( old, this->node ); 972 1686 } 973 1687 974 1688 virtual void visit( CaseStmt * old ) override final { 1689 if ( inCache( old ) ) return; 975 1690 this->node = new ast::CaseStmt( 976 1691 old->location, … … 979 1694 GET_LABELS_V(old->labels) 980 1695 ); 1696 cache.emplace( old, this->node ); 981 1697 } 982 1698 983 1699 virtual void visit( WhileStmt * old ) override final { 1700 if ( inCache( old ) ) return; 984 1701 this->node = new ast::WhileStmt( 985 1702 old->location, … … 990 1707 GET_LABELS_V(old->labels) 991 1708 ); 1709 cache.emplace( old, this->node ); 992 1710 } 993 1711 994 1712 virtual void visit( ForStmt * old ) override final { 1713 if ( inCache( old ) ) return; 995 1714 this->node = new ast::ForStmt( 996 1715 old->location, … … 1001 1720 GET_LABELS_V(old->labels) 1002 1721 ); 1722 cache.emplace( old, this->node ); 1003 1723 } 1004 1724 1005 1725 virtual void visit( BranchStmt * old ) override final { 1726 if ( inCache( old ) ) return; 1006 1727 if (old->computedTarget) { 1007 1728 this->node = new ast::BranchStmt( … … 1037 1758 this->node = stmt; 1038 1759 } 1760 cache.emplace( old, this->node ); 1039 1761 } 1040 1762 1041 1763 virtual void visit( ReturnStmt * old ) override final { 1764 if ( inCache( old ) ) return; 1042 1765 this->node = new ast::ReturnStmt( 1043 1766 old->location, … … 1045 1768 GET_LABELS_V(old->labels) 1046 1769 ); 1770 cache.emplace( old, this->node ); 1047 1771 } 1048 1772 1049 1773 virtual void visit( ThrowStmt * old ) override final { 1774 if ( inCache( old ) ) return; 1050 1775 ast::ThrowStmt::Kind kind; 1051 1776 switch (old->kind) { … … 1067 1792 GET_LABELS_V(old->labels) 1068 1793 ); 1794 cache.emplace( old, this->node ); 1069 1795 } 1070 1796 1071 1797 virtual void visit( TryStmt * old ) override final { 1798 if ( inCache( old ) ) return; 1072 1799 this->node = new ast::TryStmt( 1073 1800 old->location, … … 1077 1804 GET_LABELS_V(old->labels) 1078 1805 ); 1806 cache.emplace( old, this->node ); 1079 1807 } 1080 1808 1081 1809 virtual void visit( CatchStmt * old ) override final { 1810 if ( inCache( old ) ) return; 1082 1811 ast::CatchStmt::Kind kind; 1083 1812 switch (old->kind) { … … 1100 1829 GET_LABELS_V(old->labels) 1101 1830 ); 1831 cache.emplace( old, this->node ); 1102 1832 } 1103 1833 1104 1834 virtual void visit( FinallyStmt * old ) override final { 1835 if ( inCache( old ) ) return; 1105 1836 this->node = new ast::FinallyStmt( 1106 1837 old->location, … … 1108 1839 GET_LABELS_V(old->labels) 1109 1840 ); 1841 cache.emplace( old, this->node ); 1110 1842 } 1111 1843 1112 1844 virtual void visit( WaitForStmt * old ) override final { 1845 if ( inCache( old ) ) return; 1113 1846 ast::WaitForStmt * stmt = new ast::WaitForStmt( 1114 1847 old->location, … … 1138 1871 1139 1872 this->node = stmt; 1873 cache.emplace( old, this->node ); 1140 1874 } 1141 1875 1142 1876 virtual void visit( WithStmt * old ) override final { 1877 if ( inCache( old ) ) return; 1143 1878 this->node = new ast::WithStmt( 1144 1879 old->location, … … 1147 1882 GET_LABELS_V(old->labels) 1148 1883 ); 1884 cache.emplace( old, this->node ); 1149 1885 } 1150 1886 1151 1887 virtual void visit( NullStmt * old ) override final { 1888 if ( inCache( old ) ) return; 1152 1889 this->node = new ast::NullStmt( 1153 1890 old->location, 1154 1891 GET_LABELS_V(old->labels) 1155 1892 ); 1893 cache.emplace( old, this->node ); 1156 1894 } 1157 1895 1158 1896 virtual void visit( DeclStmt * old ) override final { 1897 if ( inCache( old ) ) return; 1159 1898 this->node = new ast::DeclStmt( 1160 1899 old->location, … … 1162 1901 GET_LABELS_V(old->labels) 1163 1902 ); 1903 cache.emplace( old, this->node ); 1164 1904 } 1165 1905 1166 1906 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 1167 this->node = new ast::ImplicitCtorDtorStmt( 1168 old->location, 1169 GET_ACCEPT_1(callStmt, Stmt), 1907 if ( inCache( old ) ) return; 1908 auto stmt = new ast::ImplicitCtorDtorStmt( 1909 old->location, 1910 nullptr, 1170 1911 GET_LABELS_V(old->labels) 1171 1912 ); 1172 } 1173 1174 virtual void visit( ApplicationExpr * ) override final { 1175 1176 } 1177 1178 virtual void visit( UntypedExpr * ) override final { 1179 1180 } 1181 1182 virtual void visit( NameExpr * ) override final { 1183 1184 } 1185 1186 virtual void visit( CastExpr * ) override final { 1187 1188 } 1189 1190 virtual void visit( KeywordCastExpr * ) override final { 1191 1192 } 1193 1194 virtual void visit( VirtualCastExpr * ) override final { 1195 1196 } 1197 1198 virtual void visit( AddressExpr * ) override final { 1199 1200 } 1201 1202 virtual void visit( LabelAddressExpr * ) override final { 1203 1204 } 1205 1206 virtual void visit( UntypedMemberExpr * ) override final { 1207 1208 } 1209 1210 virtual void visit( MemberExpr * ) override final { 1211 1212 } 1213 1214 virtual void visit( VariableExpr * ) override final { 1215 1216 } 1217 1218 virtual void visit( ConstantExpr * ) override final { 1219 1220 } 1221 1222 virtual void visit( SizeofExpr * ) override final { 1223 1224 } 1225 1226 virtual void visit( AlignofExpr * ) override final { 1227 1228 } 1229 1230 virtual void visit( UntypedOffsetofExpr * ) override final { 1231 1232 } 1233 1234 virtual void visit( OffsetofExpr * ) override final { 1235 1236 } 1237 1238 virtual void visit( OffsetPackExpr * ) override final { 1239 1240 } 1241 1242 virtual void visit( LogicalExpr * ) override final { 1243 1244 } 1245 1246 virtual void visit( ConditionalExpr * ) override final { 1247 1248 } 1249 1250 virtual void visit( CommaExpr * ) override final { 1251 1252 } 1253 1254 virtual void visit( TypeExpr * ) override final { 1255 1256 } 1257 1258 virtual void visit( AsmExpr * ) override final { 1259 1260 } 1261 1262 virtual void visit( ImplicitCopyCtorExpr * ) override final { 1263 1264 } 1265 1266 virtual void visit( ConstructorExpr * ) override final { 1267 1268 } 1269 1270 virtual void visit( CompoundLiteralExpr * ) override final { 1271 1272 } 1273 1274 virtual void visit( RangeExpr * ) override final { 1275 1276 } 1277 1278 virtual void visit( UntypedTupleExpr * ) override final { 1279 1280 } 1281 1282 virtual void visit( TupleExpr * ) override final { 1283 1284 } 1285 1286 virtual void visit( TupleIndexExpr * ) override final { 1287 1288 } 1289 1290 virtual void visit( TupleAssignExpr * ) override final { 1291 1292 } 1293 1294 virtual void visit( StmtExpr * ) override final { 1295 1296 } 1297 1298 virtual void visit( UniqueExpr * ) override final { 1299 1300 } 1301 1302 virtual void visit( UntypedInitExpr * ) override final { 1303 1304 } 1305 1306 virtual void visit( InitExpr * ) override final { 1307 1308 } 1309 1310 virtual void visit( DeletedExpr * ) override final { 1311 1312 } 1313 1314 virtual void visit( DefaultArgExpr * ) override final { 1315 1316 } 1317 1318 virtual void visit( GenericExpr * ) override final { 1319 1320 } 1321 1322 virtual void visit( VoidType * ) override final { 1323 1324 } 1325 1326 virtual void visit( BasicType * ) override final { 1327 1328 } 1329 1330 virtual void visit( PointerType * ) override final { 1331 1332 } 1333 1334 virtual void visit( ArrayType * ) override final { 1335 1336 } 1337 1338 virtual void visit( ReferenceType * ) override final { 1339 1340 } 1341 1342 virtual void visit( QualifiedType * ) override final { 1343 1344 } 1345 1346 virtual void visit( FunctionType * ) override final { 1347 1348 } 1349 1350 virtual void visit( StructInstType * ) override final { 1351 1352 } 1353 1354 virtual void visit( UnionInstType * ) override final { 1355 1356 } 1357 1358 virtual void visit( EnumInstType * ) override final { 1359 1360 } 1361 1362 virtual void visit( TraitInstType * ) override final { 1363 1364 } 1365 1366 virtual void visit( TypeInstType * ) override final { 1367 1368 } 1369 1370 virtual void visit( TupleType * ) override final { 1371 1372 } 1373 1374 virtual void visit( TypeofType * ) override final { 1375 1913 this->node = stmt; 1914 cache.emplace( old, this->node ); 1915 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt); 1916 } 1917 1918 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { 1919 1920 if (!old) return nullptr; 1921 1922 ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); 1923 1924 for (decltype(old->begin()) old_i = old->begin(); old_i != old->end(); old_i++) { 1925 rslt->add( old_i->first, 1926 getAccept1<ast::Type>(old_i->second) ); 1927 } 1928 1929 for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) { 1930 rslt->addVar( old_i->first, 1931 getAccept1<ast::Expr>(old_i->second) ); 1932 } 1933 1934 return rslt; 1935 } 1936 1937 void convertInferUnion(ast::Expr::InferUnion &newInferred, 1938 const std::map<UniqueId,ParamEntry> &oldInferParams, 1939 const std::vector<UniqueId> &oldResnSlots) { 1940 1941 assert( oldInferParams.empty() || oldResnSlots.empty() ); 1942 assert( newInferred.mode == ast::Expr::InferUnion::Empty ); 1943 1944 if ( !oldInferParams.empty() ) { 1945 ast::InferredParams &tgt = newInferred.inferParams(); 1946 for (auto old : oldInferParams) { 1947 tgt[old.first] = ast::ParamEntry( 1948 old.second.decl, 1949 getAccept1<ast::Type>(old.second.actualType), 1950 getAccept1<ast::Type>(old.second.formalType), 1951 getAccept1<ast::Expr>(old.second.expr) 1952 ); 1953 } 1954 } else if ( !oldResnSlots.empty() ) { 1955 ast::ResnSlots &tgt = newInferred.resnSlots(); 1956 for (auto old : oldResnSlots) { 1957 tgt.push_back(old); 1958 } 1959 } 1960 } 1961 1962 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1963 1964 nw->env = convertTypeSubstitution(old->env); 1965 1966 nw->extension = old->extension; 1967 convertInferUnion(nw->inferred, old->inferParams, old->resnSlots); 1968 1969 return nw; 1970 } 1971 1972 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1973 1974 nw->result = GET_ACCEPT_1(result, Type); 1975 return visitBaseExpr_SkipResultType(old, nw);; 1976 } 1977 1978 virtual void visit( ApplicationExpr * old ) override final { 1979 this->node = visitBaseExpr( old, 1980 new ast::ApplicationExpr( 1981 old->location, 1982 GET_ACCEPT_1(function, Expr), 1983 GET_ACCEPT_V(args, Expr) 1984 ) 1985 ); 1986 } 1987 1988 virtual void visit( UntypedExpr * old ) override final { 1989 this->node = visitBaseExpr( old, 1990 new ast::UntypedExpr( 1991 old->location, 1992 GET_ACCEPT_1(function, Expr), 1993 GET_ACCEPT_V(args, Expr) 1994 ) 1995 ); 1996 } 1997 1998 virtual void visit( NameExpr * old ) override final { 1999 this->node = visitBaseExpr( old, 2000 new ast::NameExpr( 2001 old->location, 2002 old->get_name() 2003 ) 2004 ); 2005 } 2006 2007 virtual void visit( CastExpr * old ) override final { 2008 this->node = visitBaseExpr( old, 2009 new ast::CastExpr( 2010 old->location, 2011 GET_ACCEPT_1(arg, Expr), 2012 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 2013 ) 2014 ); 2015 } 2016 2017 virtual void visit( KeywordCastExpr * old) override final { 2018 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 2019 switch (old->target) { 2020 case KeywordCastExpr::Coroutine: 2021 castTarget = ast::KeywordCastExpr::Coroutine; 2022 break; 2023 case KeywordCastExpr::Thread: 2024 castTarget = ast::KeywordCastExpr::Thread; 2025 break; 2026 case KeywordCastExpr::Monitor: 2027 castTarget = ast::KeywordCastExpr::Monitor; 2028 break; 2029 default: 2030 break; 2031 } 2032 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 2033 this->node = visitBaseExpr( old, 2034 new ast::KeywordCastExpr( 2035 old->location, 2036 GET_ACCEPT_1(arg, Expr), 2037 castTarget 2038 ) 2039 ); 2040 } 2041 2042 virtual void visit( VirtualCastExpr * old ) override final { 2043 this->node = visitBaseExpr_SkipResultType( old, 2044 new ast::VirtualCastExpr( 2045 old->location, 2046 GET_ACCEPT_1(arg, Expr), 2047 GET_ACCEPT_1(result, Type) 2048 ) 2049 ); 2050 } 2051 2052 virtual void visit( AddressExpr * old ) override final { 2053 this->node = visitBaseExpr( old, 2054 new ast::AddressExpr( 2055 old->location, 2056 GET_ACCEPT_1(arg, Expr) 2057 ) 2058 ); 2059 } 2060 2061 virtual void visit( LabelAddressExpr * old ) override final { 2062 this->node = visitBaseExpr( old, 2063 new ast::LabelAddressExpr( 2064 old->location, 2065 make_label(&old->arg) 2066 ) 2067 ); 2068 } 2069 2070 virtual void visit( UntypedMemberExpr * old ) override final { 2071 this->node = visitBaseExpr( old, 2072 new ast::UntypedMemberExpr( 2073 old->location, 2074 GET_ACCEPT_1(member, Expr), 2075 GET_ACCEPT_1(aggregate, Expr) 2076 ) 2077 ); 2078 } 2079 2080 virtual void visit( MemberExpr * old ) override final { 2081 this->node = visitBaseExpr( old, 2082 new ast::MemberExpr( 2083 old->location, 2084 inCache(old->member) ? 2085 dynamic_cast<ast::DeclWithType *>(this->node) : 2086 GET_ACCEPT_1(member, DeclWithType), 2087 GET_ACCEPT_1(aggregate, Expr) 2088 ) 2089 ); 2090 } 2091 2092 virtual void visit( VariableExpr * old ) override final { 2093 this->node = visitBaseExpr( old, 2094 new ast::VariableExpr( 2095 old->location, 2096 inCache(old->var) ? 2097 dynamic_cast<ast::DeclWithType *>(this->node) : 2098 GET_ACCEPT_1(var, DeclWithType) 2099 ) 2100 ); 2101 } 2102 2103 bool isIntlikeConstantType(const Type *t) { 2104 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) { 2105 if ( basicType->isInteger() ) { 2106 return true; 2107 } 2108 } else if ( dynamic_cast< const OneType * >( t ) ) { 2109 return true; 2110 } else if ( dynamic_cast< const ZeroType * >( t ) ) { 2111 return true; 2112 } else if ( dynamic_cast< const PointerType * >( t ) ) { 2113 // null pointer constants, with zero int-values 2114 return true; 2115 } 2116 return false; 2117 } 2118 2119 int isFloatlikeConstantType(const Type *t) { 2120 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) { 2121 if ( ! bty->isInteger() ) { 2122 return true; 2123 } 2124 } 2125 return false; 2126 } 2127 2128 int isStringlikeConstantType(const Type *t) { 2129 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) { 2130 if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) { 2131 if ( bty->kind == BasicType::Kind::Char ) { 2132 return true; 2133 } 2134 } 2135 } 2136 return false; 2137 } 2138 2139 virtual void visit( ConstantExpr * old ) override final { 2140 ast::ConstantExpr *rslt = nullptr; 2141 if (isIntlikeConstantType(old->result)) { 2142 rslt = new ast::ConstantExpr( 2143 old->location, 2144 GET_ACCEPT_1(result, Type), 2145 old->constant.get_value(), 2146 (unsigned long long) old->intValue() 2147 ); 2148 } else if (isFloatlikeConstantType(old->result)) { 2149 rslt = new ast::ConstantExpr( 2150 old->location, 2151 GET_ACCEPT_1(result, Type), 2152 old->constant.get_value(), 2153 (double) old->constant.get_dval() 2154 ); 2155 } else if (isStringlikeConstantType(old->result)) { 2156 rslt = ast::ConstantExpr::from_string( 2157 old->location, 2158 old->constant.get_value() 2159 ); 2160 } 2161 assert(rslt); 2162 this->node = visitBaseExpr( old, rslt ); 2163 } 2164 2165 virtual void visit( SizeofExpr * old ) override final { 2166 assert (old->expr || old->type); 2167 assert (! (old->expr && old->type)); 2168 ast::SizeofExpr *rslt; 2169 if (old->expr) { 2170 assert(!old->isType); 2171 rslt = new ast::SizeofExpr( 2172 old->location, 2173 GET_ACCEPT_1(expr, Expr) 2174 ); 2175 } 2176 if (old->type) { 2177 assert(old->isType); 2178 rslt = new ast::SizeofExpr( 2179 old->location, 2180 GET_ACCEPT_1(type, Type) 2181 ); 2182 } 2183 this->node = visitBaseExpr( old, rslt ); 2184 } 2185 2186 virtual void visit( AlignofExpr * old ) override final { 2187 assert (old->expr || old->type); 2188 assert (! (old->expr && old->type)); 2189 ast::AlignofExpr *rslt; 2190 if (old->expr) { 2191 assert(!old->isType); 2192 rslt = new ast::AlignofExpr( 2193 old->location, 2194 GET_ACCEPT_1(expr, Expr) 2195 ); 2196 } 2197 if (old->type) { 2198 assert(old->isType); 2199 rslt = new ast::AlignofExpr( 2200 old->location, 2201 GET_ACCEPT_1(type, Type) 2202 ); 2203 } 2204 this->node = visitBaseExpr( old, rslt ); 2205 } 2206 2207 virtual void visit( UntypedOffsetofExpr * old ) override final { 2208 this->node = visitBaseExpr( old, 2209 new ast::UntypedOffsetofExpr( 2210 old->location, 2211 GET_ACCEPT_1(type, Type), 2212 old->member 2213 ) 2214 ); 2215 } 2216 2217 virtual void visit( OffsetofExpr * old ) override final { 2218 this->node = visitBaseExpr( old, 2219 new ast::OffsetofExpr( 2220 old->location, 2221 GET_ACCEPT_1(type, Type), 2222 inCache(old->member) ? 2223 dynamic_cast<ast::DeclWithType *>(this->node) : 2224 GET_ACCEPT_1(member, DeclWithType) 2225 ) 2226 ); 2227 } 2228 2229 virtual void visit( OffsetPackExpr * old ) override final { 2230 this->node = visitBaseExpr( old, 2231 new ast::OffsetPackExpr( 2232 old->location, 2233 GET_ACCEPT_1(type, StructInstType) 2234 ) 2235 ); 2236 } 2237 2238 virtual void visit( LogicalExpr * old ) override final { 2239 this->node = visitBaseExpr( old, 2240 new ast::LogicalExpr( 2241 old->location, 2242 GET_ACCEPT_1(arg1, Expr), 2243 GET_ACCEPT_1(arg2, Expr), 2244 old->get_isAnd() ? 2245 ast::LogicalFlag::AndExpr : 2246 ast::LogicalFlag::OrExpr 2247 ) 2248 ); 2249 } 2250 2251 virtual void visit( ConditionalExpr * old ) override final { 2252 this->node = visitBaseExpr( old, 2253 new ast::ConditionalExpr( 2254 old->location, 2255 GET_ACCEPT_1(arg1, Expr), 2256 GET_ACCEPT_1(arg2, Expr), 2257 GET_ACCEPT_1(arg3, Expr) 2258 ) 2259 ); 2260 } 2261 2262 virtual void visit( CommaExpr * old ) override final { 2263 this->node = visitBaseExpr( old, 2264 new ast::CommaExpr( 2265 old->location, 2266 GET_ACCEPT_1(arg1, Expr), 2267 GET_ACCEPT_1(arg2, Expr) 2268 ) 2269 ); 2270 } 2271 2272 virtual void visit( TypeExpr * old ) override final { 2273 this->node = visitBaseExpr( old, 2274 new ast::TypeExpr( 2275 old->location, 2276 GET_ACCEPT_1(type, Type) 2277 ) 2278 ); 2279 } 2280 2281 virtual void visit( AsmExpr * old ) override final { 2282 this->node = visitBaseExpr( old, 2283 new ast::AsmExpr( 2284 old->location, 2285 GET_ACCEPT_1(inout, Expr), 2286 GET_ACCEPT_1(constraint, Expr), 2287 GET_ACCEPT_1(operand, Expr) 2288 ) 2289 ); 2290 } 2291 2292 virtual void visit( ImplicitCopyCtorExpr * old ) override final { 2293 auto rslt = new ast::ImplicitCopyCtorExpr( 2294 old->location, 2295 GET_ACCEPT_1(callExpr, ApplicationExpr) 2296 ); 2297 2298 rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl); 2299 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2300 rslt->dtors = GET_ACCEPT_V(dtors, Expr); 2301 2302 this->node = visitBaseExpr( old, rslt ); 2303 } 2304 2305 virtual void visit( ConstructorExpr * old ) override final { 2306 this->node = visitBaseExpr( old, 2307 new ast::ConstructorExpr( 2308 old->location, 2309 GET_ACCEPT_1(callExpr, Expr) 2310 ) 2311 ); 2312 } 2313 2314 virtual void visit( CompoundLiteralExpr * old ) override final { 2315 this->node = visitBaseExpr_SkipResultType( old, 2316 new ast::CompoundLiteralExpr( 2317 old->location, 2318 GET_ACCEPT_1(result, Type), 2319 GET_ACCEPT_1(initializer, Init) 2320 ) 2321 ); 2322 } 2323 2324 virtual void visit( RangeExpr * old ) override final { 2325 this->node = visitBaseExpr( old, 2326 new ast::RangeExpr( 2327 old->location, 2328 GET_ACCEPT_1(low, Expr), 2329 GET_ACCEPT_1(high, Expr) 2330 ) 2331 ); 2332 } 2333 2334 virtual void visit( UntypedTupleExpr * old ) override final { 2335 this->node = visitBaseExpr( old, 2336 new ast::UntypedTupleExpr( 2337 old->location, 2338 GET_ACCEPT_V(exprs, Expr) 2339 ) 2340 ); 2341 } 2342 2343 virtual void visit( TupleExpr * old ) override final { 2344 this->node = visitBaseExpr( old, 2345 new ast::TupleExpr( 2346 old->location, 2347 GET_ACCEPT_V(exprs, Expr) 2348 ) 2349 ); 2350 } 2351 2352 virtual void visit( TupleIndexExpr * old ) override final { 2353 this->node = visitBaseExpr( old, 2354 new ast::TupleIndexExpr( 2355 old->location, 2356 GET_ACCEPT_1(tuple, Expr), 2357 old->index 2358 ) 2359 ); 2360 } 2361 2362 virtual void visit( TupleAssignExpr * old ) override final { 2363 this->node = visitBaseExpr_SkipResultType( old, 2364 new ast::TupleAssignExpr( 2365 old->location, 2366 GET_ACCEPT_1(result, Type), 2367 GET_ACCEPT_1(stmtExpr, StmtExpr) 2368 ) 2369 ); 2370 } 2371 2372 virtual void visit( StmtExpr * old ) override final { 2373 auto rslt = new ast::StmtExpr( 2374 old->location, 2375 GET_ACCEPT_1(statements, CompoundStmt) 2376 ); 2377 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2378 rslt->dtors = GET_ACCEPT_V(dtors , Expr); 2379 2380 this->node = visitBaseExpr_SkipResultType( old, rslt ); 2381 } 2382 2383 virtual void visit( UniqueExpr * old ) override final { 2384 auto rslt = new ast::UniqueExpr( 2385 old->location, 2386 GET_ACCEPT_1(expr, Expr) 2387 ); 2388 rslt->object = GET_ACCEPT_1(object, ObjectDecl); 2389 rslt->var = GET_ACCEPT_1(var , VariableExpr); 2390 2391 this->node = visitBaseExpr( old, rslt ); 2392 } 2393 2394 virtual void visit( UntypedInitExpr * old ) override final { 2395 std::vector<ast::InitAlternative> initAlts; 2396 for (auto ia : old->initAlts) { 2397 initAlts.push_back(ast::InitAlternative( 2398 getAccept1< ast::Type, Type * >( ia.type ), 2399 getAccept1< ast::Designation, Designation * >( ia.designation ) 2400 )); 2401 } 2402 this->node = visitBaseExpr( old, 2403 new ast::UntypedInitExpr( 2404 old->location, 2405 GET_ACCEPT_1(expr, Expr), 2406 std::move(initAlts) 2407 ) 2408 ); 2409 } 2410 2411 virtual void visit( InitExpr * old ) override final { 2412 this->node = visitBaseExpr( old, 2413 new ast::InitExpr( 2414 old->location, 2415 GET_ACCEPT_1(expr, Expr), 2416 GET_ACCEPT_1(designation, Designation) 2417 ) 2418 ); 2419 } 2420 2421 virtual void visit( DeletedExpr * old ) override final { 2422 this->node = visitBaseExpr( old, 2423 new ast::DeletedExpr( 2424 old->location, 2425 GET_ACCEPT_1(expr, Expr), 2426 inCache(old->deleteStmt) ? 2427 this->node : 2428 GET_ACCEPT_1(deleteStmt, Node) 2429 ) 2430 ); 2431 } 2432 2433 virtual void visit( DefaultArgExpr * old ) override final { 2434 this->node = visitBaseExpr( old, 2435 new ast::DefaultArgExpr( 2436 old->location, 2437 GET_ACCEPT_1(expr, Expr) 2438 ) 2439 ); 2440 } 2441 2442 virtual void visit( GenericExpr * old ) override final { 2443 std::vector<ast::GenericExpr::Association> associations; 2444 for (auto association : old->associations) { 2445 associations.push_back(ast::GenericExpr::Association( 2446 getAccept1< ast::Type, Type * >( association.type ), 2447 getAccept1< ast::Expr, Expression * >( association.expr ) 2448 )); 2449 } 2450 this->node = visitBaseExpr( old, 2451 new ast::GenericExpr( 2452 old->location, 2453 GET_ACCEPT_1(control, Expr), 2454 std::move(associations) 2455 ) 2456 ); 2457 } 2458 2459 virtual void visit( VoidType * old ) override final { 2460 this->node = new ast::VoidType{ cv( old ) }; 2461 } 2462 2463 virtual void visit( BasicType * old ) override final { 2464 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) }; 2465 } 2466 2467 virtual void visit( PointerType * old ) override final { 2468 this->node = new ast::PointerType{ 2469 GET_ACCEPT_1( base, Type ), 2470 GET_ACCEPT_1( dimension, Expr ), 2471 (ast::LengthFlag)old->isVarLen, 2472 (ast::DimensionFlag)old->isStatic, 2473 cv( old ) 2474 }; 2475 } 2476 2477 virtual void visit( ArrayType * old ) override final { 2478 this->node = new ast::ArrayType{ 2479 GET_ACCEPT_1( base, Type ), 2480 GET_ACCEPT_1( dimension, Expr ), 2481 (ast::LengthFlag)old->isVarLen, 2482 (ast::DimensionFlag)old->isStatic, 2483 cv( old ) 2484 }; 2485 } 2486 2487 virtual void visit( ReferenceType * old ) override final { 2488 this->node = new ast::ReferenceType{ 2489 GET_ACCEPT_1( base, Type ), 2490 cv( old ) 2491 }; 2492 } 2493 2494 virtual void visit( QualifiedType * old ) override final { 2495 this->node = new ast::QualifiedType{ 2496 GET_ACCEPT_1( parent, Type ), 2497 GET_ACCEPT_1( child, Type ), 2498 cv( old ) 2499 }; 2500 } 2501 2502 virtual void visit( FunctionType * old ) override final { 2503 auto ty = new ast::FunctionType { 2504 (ast::ArgumentFlag)old->isVarArgs, 2505 cv( old ) 2506 }; 2507 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2508 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2509 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2510 this->node = ty; 2511 } 2512 2513 void postvisit( ReferenceToType * old, ast::ReferenceToType * ty ) { 2514 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2515 ty->params = GET_ACCEPT_V( parameters, Expr ); 2516 ty->hoistType = old->hoistType; 2517 } 2518 2519 virtual void visit( StructInstType * old ) override final { 2520 ast::StructInstType * ty; 2521 if ( old->baseStruct ) { 2522 ty = new ast::StructInstType{ 2523 GET_ACCEPT_1( baseStruct, StructDecl ), 2524 cv( old ), 2525 GET_ACCEPT_V( attributes, Attribute ) 2526 }; 2527 } else { 2528 ty = new ast::StructInstType{ 2529 old->name, 2530 cv( old ), 2531 GET_ACCEPT_V( attributes, Attribute ) 2532 }; 2533 } 2534 postvisit( old, ty ); 2535 this->node = ty; 2536 } 2537 2538 virtual void visit( UnionInstType * old ) override final { 2539 ast::UnionInstType * ty; 2540 if ( old->baseUnion ) { 2541 ty = new ast::UnionInstType{ 2542 GET_ACCEPT_1( baseUnion, UnionDecl ), 2543 cv( old ), 2544 GET_ACCEPT_V( attributes, Attribute ) 2545 }; 2546 } else { 2547 ty = new ast::UnionInstType{ 2548 old->name, 2549 cv( old ), 2550 GET_ACCEPT_V( attributes, Attribute ) 2551 }; 2552 } 2553 postvisit( old, ty ); 2554 this->node = ty; 2555 } 2556 2557 virtual void visit( EnumInstType * old ) override final { 2558 ast::EnumInstType * ty; 2559 if ( old->baseEnum ) { 2560 ty = new ast::EnumInstType{ 2561 GET_ACCEPT_1( baseEnum, EnumDecl ), 2562 cv( old ), 2563 GET_ACCEPT_V( attributes, Attribute ) 2564 }; 2565 } else { 2566 ty = new ast::EnumInstType{ 2567 old->name, 2568 cv( old ), 2569 GET_ACCEPT_V( attributes, Attribute ) 2570 }; 2571 } 2572 postvisit( old, ty ); 2573 this->node = ty; 2574 } 2575 2576 virtual void visit( TraitInstType * old ) override final { 2577 ast::TraitInstType * ty; 2578 if ( old->baseTrait ) { 2579 ty = new ast::TraitInstType{ 2580 GET_ACCEPT_1( baseTrait, TraitDecl ), 2581 cv( old ), 2582 GET_ACCEPT_V( attributes, Attribute ) 2583 }; 2584 } else { 2585 ty = new ast::TraitInstType{ 2586 old->name, 2587 cv( old ), 2588 GET_ACCEPT_V( attributes, Attribute ) 2589 }; 2590 } 2591 postvisit( old, ty ); 2592 this->node = ty; 2593 } 2594 2595 virtual void visit( TypeInstType * old ) override final { 2596 ast::TypeInstType * ty; 2597 if ( old->baseType ) { 2598 ty = new ast::TypeInstType{ 2599 old->name, 2600 GET_ACCEPT_1( baseType, TypeDecl ), 2601 cv( old ), 2602 GET_ACCEPT_V( attributes, Attribute ) 2603 }; 2604 } else { 2605 ty = new ast::TypeInstType{ 2606 old->name, 2607 old->isFtype ? ast::TypeVar::Ftype : ast::TypeVar::Dtype, 2608 cv( old ), 2609 GET_ACCEPT_V( attributes, Attribute ) 2610 }; 2611 } 2612 postvisit( old, ty ); 2613 this->node = ty; 2614 } 2615 2616 virtual void visit( TupleType * old ) override final { 2617 this->node = new ast::TupleType{ 2618 GET_ACCEPT_V( types, Type ), 2619 // members generated by TupleType c'tor 2620 cv( old ) 2621 }; 2622 } 2623 2624 virtual void visit( TypeofType * old ) override final { 2625 this->node = new ast::TypeofType{ 2626 GET_ACCEPT_1( expr, Expr ), 2627 (ast::TypeofType::Kind)old->is_basetypeof, 2628 cv( old ) 2629 }; 1376 2630 } 1377 2631 1378 2632 virtual void visit( AttrType * ) override final { 1379 1380 } 1381 1382 virtual void visit( VarArgsType * ) override final {1383 1384 } 1385 1386 virtual void visit( ZeroType * ) override final {1387 1388 } 1389 1390 virtual void visit( OneType * ) override final {1391 2633 assertf( false, "AttrType deprecated in new AST." ); 2634 } 2635 2636 virtual void visit( VarArgsType * old ) override final { 2637 this->node = new ast::VarArgsType{ cv( old ) }; 2638 } 2639 2640 virtual void visit( ZeroType * old ) override final { 2641 this->node = new ast::ZeroType{ cv( old ) }; 2642 } 2643 2644 virtual void visit( OneType * old ) override final { 2645 this->node = new ast::OneType{ cv( old ) }; 1392 2646 } 1393 2647 1394 2648 virtual void visit( GlobalScopeType * ) override final { 1395 1396 } 1397 1398 virtual void visit( Designation * ) override final { 1399 1400 } 1401 1402 virtual void visit( SingleInit * ) override final { 1403 1404 } 1405 1406 virtual void visit( ListInit * ) override final { 1407 1408 } 1409 1410 virtual void visit( ConstructorInit * ) override final { 1411 2649 this->node = new ast::GlobalScopeType{}; 2650 } 2651 2652 virtual void visit( Designation * old ) override final { 2653 this->node = new ast::Designation( 2654 old->location, 2655 GET_ACCEPT_V(designators, Expr) 2656 ); 2657 } 2658 2659 virtual void visit( SingleInit * old ) override final { 2660 this->node = new ast::SingleInit( 2661 old->location, 2662 GET_ACCEPT_1(value, Expr), 2663 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2664 ); 2665 } 2666 2667 virtual void visit( ListInit * old ) override final { 2668 this->node = new ast::ListInit( 2669 old->location, 2670 GET_ACCEPT_V(initializers, Init), 2671 GET_ACCEPT_V(designations, Designation), 2672 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2673 ); 2674 } 2675 2676 virtual void visit( ConstructorInit * old ) override final { 2677 this->node = new ast::ConstructorInit( 2678 old->location, 2679 GET_ACCEPT_1(ctor, Stmt), 2680 GET_ACCEPT_1(dtor, Stmt), 2681 GET_ACCEPT_1(init, Init) 2682 ); 1412 2683 } 1413 2684 1414 2685 virtual void visit( Constant * ) override final { 1415 1416 } 1417 1418 virtual void visit( Attribute * ) override final { 1419 2686 // Handled in visit( ConstantEpxr * ). 2687 // In the new tree, Constant fields are inlined into containing ConstantExpression. 2688 assert( 0 ); 2689 } 2690 2691 virtual void visit( Attribute * old ) override final { 2692 this->node = new ast::Attribute( 2693 old->name, 2694 GET_ACCEPT_V( parameters, Expr ) 2695 ); 1420 2696 } 1421 2697 1422 2698 virtual void visit( AttrExpr * ) override final { 1423 1424 assert( 0 ); 2699 assertf( false, "AttrExpr deprecated in new AST." ); 1425 2700 } 1426 2701 }; … … 1436 2711 d->accept( c ); 1437 2712 decls.emplace_back( c.decl() ); 1438 delete d;1439 }2713 } 2714 deleteAll(translationUnit); 1440 2715 return decls; 1441 2716 }
Note:
See TracChangeset
for help on using the changeset viewer.