Changeset f4c2f1a
- Timestamp:
- May 22, 2019, 3:23:25 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6380f78, 8abee136, dff6452
- Parents:
- e9b44489 (diff), dd6d7c6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/vtable.md
re9b44489 rf4c2f1a 220 220 trait iterator(otype T, otype Item) { 221 221 bool has_next(T const &); 222 Item get_next(T const *);222 Item get_next(T &); 223 223 } 224 224 -
src/AST/Convert.cpp
re9b44489 rf4c2f1a 265 265 stmt->location = node->location; 266 266 stmt->labels = makeLabelL( stmt, node->labels ); 267 cache.emplace( node, stmt ); 267 268 this->node = stmt; 268 269 return nullptr; … … 270 271 271 272 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 273 if ( inCache( node ) ) return nullptr; 272 274 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 273 275 stmtPostamble( stmt, node ); … … 276 278 277 279 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 280 if ( inCache( node ) ) return nullptr; 278 281 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 279 282 return stmtPostamble( stmt, node ); … … 281 284 282 285 const ast::Stmt * visit( const ast::AsmStmt * node ) override final { 286 if ( inCache( node ) ) return nullptr; 283 287 auto stmt = new AsmStmt( 284 288 node->isVolatile, … … 293 297 294 298 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 299 if ( inCache( node ) ) return nullptr; 295 300 auto stmt = new DirectiveStmt( node->directive ); 296 301 return stmtPostamble( stmt, node ); … … 298 303 299 304 const ast::Stmt * visit( const ast::IfStmt * node ) override final { 305 if ( inCache( node ) ) return nullptr; 300 306 auto stmt = new IfStmt( 301 307 get<Expression>().accept1( node->cond ), … … 308 314 309 315 const ast::Stmt * visit( const ast::SwitchStmt * node ) override final { 316 if ( inCache( node ) ) return nullptr; 310 317 auto stmt = new SwitchStmt( 311 318 get<Expression>().accept1( node->cond ), … … 316 323 317 324 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 325 if ( inCache( node ) ) return nullptr; 318 326 auto stmt = new CaseStmt( 319 327 get<Expression>().accept1( node->cond ), … … 325 333 326 334 const ast::Stmt * visit( const ast::WhileStmt * node ) override final { 335 if ( inCache( node ) ) return nullptr; 327 336 auto inits = get<Statement>().acceptL( node->inits ); 328 337 auto stmt = new WhileStmt( … … 336 345 337 346 const ast::Stmt * visit( const ast::ForStmt * node ) override final { 347 if ( inCache( node ) ) return nullptr; 338 348 auto stmt = new ForStmt( 339 349 get<Statement>().acceptL( node->inits ), … … 346 356 347 357 const ast::Stmt * visit( const ast::BranchStmt * node ) override final { 358 if ( inCache( node ) ) return nullptr; 348 359 BranchStmt * stmt; 349 360 if (node->computedTarget) { … … 375 386 376 387 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 388 if ( inCache( node ) ) return nullptr; 377 389 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 378 390 return stmtPostamble( stmt, node ); … … 380 392 381 393 const ast::Stmt * visit( const ast::ThrowStmt * node ) override final { 394 if ( inCache( node ) ) return nullptr; 382 395 ThrowStmt::Kind kind; 383 396 switch (node->kind) { … … 400 413 401 414 const ast::Stmt * visit( const ast::TryStmt * node ) override final { 415 if ( inCache( node ) ) return nullptr; 402 416 auto handlers = get<CatchStmt>().acceptL( node->handlers ); 403 417 auto stmt = new TryStmt( … … 410 424 411 425 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 426 if ( inCache( node ) ) return nullptr; 412 427 CatchStmt::Kind kind; 413 428 switch (node->kind) { … … 431 446 432 447 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 448 if ( inCache( node ) ) return nullptr; 433 449 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 434 450 return stmtPostamble( stmt, node ); … … 436 452 437 453 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 454 if ( inCache( node ) ) return nullptr; 438 455 auto stmt = new WaitForStmt; 439 456 stmt->clauses.reserve( node->clauses.size() ); … … 460 477 461 478 const ast::Stmt * visit( const ast::WithStmt * node ) override final { 479 if ( inCache( node ) ) return nullptr; 462 480 auto stmt = new WithStmt( 463 481 get<Expression>().acceptL( node->exprs ), … … 468 486 469 487 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 488 if ( inCache( node ) ) return nullptr; 470 489 auto stmt = new NullStmt(); 471 490 stmtPostamble( stmt, node ); … … 474 493 475 494 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 495 if ( inCache( node ) ) return nullptr; 476 496 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 477 497 return stmtPostamble( stmt, node ); … … 479 499 480 500 const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final { 481 (void)node; 482 return nullptr; 501 if ( inCache( node ) ) return nullptr; 502 auto stmt = new ImplicitCtorDtorStmt{ 503 get<Statement>().accept1( node->callStmt ) 504 }; 505 return stmtPostamble( stmt, node ); 483 506 } 484 507 … … 525 548 } 526 549 550 Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) { 551 552 tgt->location = src->location; 553 tgt->env = convertTypeSubstitution(src->env); 554 tgt->extension = src->extension; 555 556 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 557 return tgt; 558 } 559 527 560 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) { 528 561 529 tgt->location = src->location;530 531 562 tgt->result = get<Type>().accept1(src->result); 532 tgt->env = convertTypeSubstitution(src->env); 533 534 tgt->extension = src->extension; 535 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred); 536 537 return tgt; 563 return visitBaseExpr_skipResultType(src, tgt); 538 564 } 539 565 … … 628 654 629 655 const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final { 630 auto expr = visitBaseExpr ( node,656 auto expr = visitBaseExpr_skipResultType( node, 631 657 new VirtualCastExpr( 632 658 get<Expression>().accept1(node->arg), 633 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr659 get<Type>().accept1(node->result) 634 660 ) 635 661 ); … … 849 875 850 876 const ast::Expr * visit( const ast::TypeExpr * node ) override final { 851 (void)node; 877 auto expr = visitBaseExpr( node, 878 new TypeExpr( 879 get<Type>().accept1(node->type) 880 ) 881 ); 882 this->node = expr; 852 883 return nullptr; 853 884 } 854 885 855 886 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 856 (void)node; 887 auto expr = visitBaseExpr( node, 888 new AsmExpr( 889 get<Expression>().accept1(node->inout), 890 get<Expression>().accept1(node->constraint), 891 get<Expression>().accept1(node->operand) 892 ) 893 ); 894 this->node = expr; 857 895 return nullptr; 858 896 } 859 897 860 898 const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final { 861 (void)node; 899 auto rslt = new ImplicitCopyCtorExpr( 900 get<ApplicationExpr>().accept1(node->callExpr) 901 ); 902 903 rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls); 904 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 905 rslt->dtors = get<Expression>().acceptL(node->dtors); 906 907 auto expr = visitBaseExpr( node, rslt ); 908 this->node = expr; 862 909 return nullptr; 863 910 } 864 911 865 912 const ast::Expr * visit( const ast::ConstructorExpr * node ) override final { 866 (void)node; 913 auto expr = visitBaseExpr( node, 914 new ConstructorExpr( 915 get<Expression>().accept1(node->callExpr) 916 ) 917 ); 918 this->node = expr; 867 919 return nullptr; 868 920 } 869 921 870 922 const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final { 871 (void)node; 923 auto expr = visitBaseExpr_skipResultType( node, 924 new CompoundLiteralExpr( 925 get<Type>().accept1(node->result), 926 get<Initializer>().accept1(node->init) 927 ) 928 ); 929 this->node = expr; 872 930 return nullptr; 873 931 } 874 932 875 933 const ast::Expr * visit( const ast::RangeExpr * node ) override final { 876 (void)node; 934 auto expr = visitBaseExpr( node, 935 new RangeExpr( 936 get<Expression>().accept1(node->low), 937 get<Expression>().accept1(node->high) 938 ) 939 ); 940 this->node = expr; 877 941 return nullptr; 878 942 } 879 943 880 944 const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final { 881 (void)node; 945 auto expr = visitBaseExpr( node, 946 new UntypedTupleExpr( 947 get<Expression>().acceptL(node->exprs) 948 ) 949 ); 950 this->node = expr; 882 951 return nullptr; 883 952 } 884 953 885 954 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 886 (void)node; 955 auto expr = visitBaseExpr( node, 956 new UntypedTupleExpr( 957 get<Expression>().acceptL(node->exprs) 958 ) 959 ); 960 this->node = expr; 887 961 return nullptr; 888 962 } 889 963 890 964 const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final { 891 (void)node; 965 auto expr = visitBaseExpr( node, 966 new TupleIndexExpr( 967 get<Expression>().accept1(node->tuple), 968 node->index 969 ) 970 ); 971 this->node = expr; 892 972 return nullptr; 893 973 } 894 974 895 975 const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final { 896 (void)node; 976 auto expr = visitBaseExpr( node, 977 new TupleAssignExpr( 978 get<StmtExpr>().accept1(node->stmtExpr) 979 ) 980 ); 981 this->node = expr; 897 982 return nullptr; 898 983 } 899 984 900 985 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 901 (void)node; 986 auto rslt = new StmtExpr( 987 get<CompoundStmt>().accept1(node->stmts) 988 ); 989 990 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 991 rslt->dtors = get<Expression>().acceptL(node->dtors); 992 993 auto expr = visitBaseExpr( node, rslt ); 994 this->node = expr; 902 995 return nullptr; 903 996 } 904 997 905 998 const ast::Expr * visit( const ast::UniqueExpr * node ) override final { 906 (void)node; 999 auto rslt = new UniqueExpr( 1000 get<Expression>().accept1(node->expr) 1001 ); 1002 1003 rslt->object = get<ObjectDecl> ().accept1(node->object); 1004 rslt->var = get<VariableExpr>().accept1(node->var); 1005 1006 auto expr = visitBaseExpr( node, rslt ); 1007 this->node = expr; 907 1008 return nullptr; 908 1009 } 909 1010 910 1011 const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final { 911 (void)node; 1012 std::list<InitAlternative> initAlts; 1013 for (auto ia : node->initAlts) { 1014 initAlts.push_back(InitAlternative( 1015 get<Type> ().accept1(ia.type), 1016 get<Designation>().accept1(ia.designation) 1017 )); 1018 } 1019 auto expr = visitBaseExpr( node, 1020 new UntypedInitExpr( 1021 get<Expression>().accept1(node->expr), 1022 initAlts 1023 ) 1024 ); 1025 this->node = expr; 912 1026 return nullptr; 913 1027 } 914 1028 915 1029 const ast::Expr * visit( const ast::InitExpr * node ) override final { 916 (void)node; 1030 auto expr = visitBaseExpr( node, 1031 new InitExpr( 1032 get<Expression>().accept1(node->expr), 1033 get<Designation>().accept1(node->designation) 1034 ) 1035 ); 1036 this->node = expr; 917 1037 return nullptr; 918 1038 } 919 1039 920 1040 const ast::Expr * visit( const ast::DeletedExpr * node ) override final { 921 (void)node; 1041 auto expr = visitBaseExpr( node, 1042 new DeletedExpr( 1043 get<Expression>().accept1(node->expr), 1044 inCache(node->deleteStmt) ? 1045 this->node : 1046 get<BaseSyntaxNode>().accept1(node->deleteStmt) 1047 ) 1048 ); 1049 this->node = expr; 922 1050 return nullptr; 923 1051 } 924 1052 925 1053 const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final { 926 (void)node; 1054 auto expr = visitBaseExpr( node, 1055 new DefaultArgExpr( 1056 get<Expression>().accept1(node->expr) 1057 ) 1058 ); 1059 this->node = expr; 927 1060 return nullptr; 928 1061 } 929 1062 930 1063 const ast::Expr * visit( const ast::GenericExpr * node ) override final { 931 (void)node; 1064 std::list<GenericExpr::Association> associations; 1065 for (auto association : node->associations) { 1066 associations.push_back(GenericExpr::Association( 1067 get<Type> ().accept1(association.type), 1068 get<Expression>().accept1(association.expr) 1069 )); 1070 } 1071 auto expr = visitBaseExpr( node, 1072 new GenericExpr( 1073 get<Expression>().accept1(node->control), 1074 associations 1075 ) 1076 ); 1077 this->node = expr; 932 1078 return nullptr; 933 1079 } … … 1141 1287 1142 1288 const ast::Designation * visit( const ast::Designation * node ) override final { 1143 (void)node; 1289 auto designation = new Designation( get<Expression>().acceptL( node->designators ) ); 1290 designation->location = node->location; 1291 this->node = designation; 1144 1292 return nullptr; 1145 1293 } 1146 1294 1147 1295 const ast::Init * visit( const ast::SingleInit * node ) override final { 1148 (void)node; 1296 auto init = new SingleInit( 1297 get<Expression>().accept1( node->value ), 1298 ast::MaybeConstruct == node->maybeConstructed 1299 ); 1300 init->location = node->location; 1301 this->node = init; 1149 1302 return nullptr; 1150 1303 } 1151 1304 1152 1305 const ast::Init * visit( const ast::ListInit * node ) override final { 1153 (void)node; 1306 auto init = new ListInit( 1307 get<Initializer>().acceptL( node->initializers ), 1308 get<Designation>().acceptL( node->designations ), 1309 ast::MaybeConstruct == node->maybeConstructed 1310 ); 1311 init->location = node->location; 1312 this->node = init; 1154 1313 return nullptr; 1155 1314 } 1156 1315 1157 1316 const ast::Init * visit( const ast::ConstructorInit * node ) override final { 1158 (void)node; 1317 auto init = new ConstructorInit( 1318 get<Statement>().accept1( node->ctor ), 1319 get<Statement>().accept1( node->dtor ), 1320 get<Initializer>().accept1( node->init ) 1321 ); 1322 init->location = node->location; 1323 this->node = init; 1159 1324 return nullptr; 1160 1325 } 1161 1326 1162 1327 const ast::Attribute * visit( const ast::Attribute * node ) override final { 1163 (void)node; 1328 auto attr = new Attribute( 1329 node->name, 1330 get<Expression>().acceptL(node->parameters) 1331 ); 1332 this->node = attr; 1164 1333 return nullptr; 1165 1334 } 1166 1335 1167 1336 const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final { 1168 (void)node; 1337 // Handled by convertTypeSubstitution helper instead. 1338 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node. 1339 assert( 0 ); 1169 1340 return nullptr; 1170 1341 } … … 1277 1448 virtual void visit( FunctionDecl * old ) override final { 1278 1449 if ( inCache( old ) ) return; 1279 // TODO 1280 auto decl = (ast::FunctionDecl *)nullptr; 1450 auto decl = new ast::FunctionDecl{ 1451 old->location, 1452 old->name, 1453 GET_ACCEPT_1(type, FunctionType), 1454 GET_ACCEPT_1(statements, CompoundStmt), 1455 { old->storageClasses.val }, 1456 { old->linkage.val }, 1457 GET_ACCEPT_V(attributes, Attribute), 1458 { old->get_funcSpec().val } 1459 }; 1460 decl->scopeLevel = old->scopeLevel; 1461 decl->mangleName = old->mangleName; 1462 decl->isDeleted = old->isDeleted; 1463 decl->uniqueId = old->uniqueId; 1464 decl->extension = old->extension; 1281 1465 cache.emplace( old, decl ); 1466 1467 this->node = decl; 1282 1468 } 1283 1469 … … 1364 1550 1365 1551 virtual void visit( TypeDecl * old ) override final { 1366 if ( inCache( old ) ) return; 1367 // TODO 1368 auto decl = (ast::TypeDecl *)nullptr; 1552 if ( inCache( old ) ) return; 1553 auto decl = new ast::TypeDecl{ 1554 old->location, 1555 old->name, 1556 { old->storageClasses.val }, 1557 GET_ACCEPT_1(base, Type), 1558 (ast::TypeVar::Kind)(unsigned)old->kind, 1559 old->sized, 1560 GET_ACCEPT_1(init, Type) 1561 }; 1562 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1563 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1564 decl->extension = old->extension; 1565 decl->uniqueId = old->uniqueId; 1369 1566 cache.emplace( old, decl ); 1567 1568 this->node = decl; 1370 1569 } 1371 1570 … … 1387 1586 } 1388 1587 1389 virtual void visit( AsmDecl * ) override final { 1390 1391 } 1392 1393 virtual void visit( StaticAssertDecl * ) override final { 1394 1588 virtual void visit( AsmDecl * old ) override final { 1589 auto decl = new ast::AsmDecl{ 1590 old->location, 1591 GET_ACCEPT_1(stmt, AsmStmt) 1592 }; 1593 decl->extension = old->extension; 1594 decl->uniqueId = old->uniqueId; 1595 decl->storage = { old->storageClasses.val }; 1596 1597 this->node = decl; 1598 } 1599 1600 virtual void visit( StaticAssertDecl * old ) override final { 1601 auto decl = new ast::StaticAssertDecl{ 1602 old->location, 1603 GET_ACCEPT_1(condition, Expr), 1604 GET_ACCEPT_1(message, ConstantExpr) 1605 }; 1606 decl->extension = old->extension; 1607 decl->uniqueId = old->uniqueId; 1608 decl->storage = { old->storageClasses.val }; 1609 1610 this->node = decl; 1395 1611 } 1396 1612 1397 1613 virtual void visit( CompoundStmt * old ) override final { 1614 if ( inCache( old ) ) return; 1398 1615 auto stmt = new ast::CompoundStmt( 1399 1616 old->location, … … 1403 1620 1404 1621 this->node = stmt; 1622 cache.emplace( old, this->node ); 1405 1623 } 1406 1624 1407 1625 virtual void visit( ExprStmt * old ) override final { 1626 if ( inCache( old ) ) return; 1408 1627 this->node = new ast::ExprStmt( 1409 1628 old->location, … … 1411 1630 GET_LABELS_V(old->labels) 1412 1631 ); 1632 cache.emplace( old, this->node ); 1413 1633 } 1414 1634 1415 1635 virtual void visit( AsmStmt * old ) override final { 1636 if ( inCache( old ) ) return; 1416 1637 this->node = new ast::AsmStmt( 1417 1638 old->location, … … 1424 1645 GET_LABELS_V(old->labels) 1425 1646 ); 1647 cache.emplace( old, this->node ); 1426 1648 } 1427 1649 1428 1650 virtual void visit( DirectiveStmt * old ) override final { 1651 if ( inCache( old ) ) return; 1429 1652 this->node = new ast::DirectiveStmt( 1430 1653 old->location, … … 1432 1655 GET_LABELS_V(old->labels) 1433 1656 ); 1657 cache.emplace( old, this->node ); 1434 1658 } 1435 1659 1436 1660 virtual void visit( IfStmt * old ) override final { 1661 if ( inCache( old ) ) return; 1437 1662 this->node = new ast::IfStmt( 1438 1663 old->location, … … 1443 1668 GET_LABELS_V(old->labels) 1444 1669 ); 1670 cache.emplace( old, this->node ); 1445 1671 } 1446 1672 1447 1673 virtual void visit( SwitchStmt * old ) override final { 1674 if ( inCache( old ) ) return; 1448 1675 this->node = new ast::SwitchStmt( 1449 1676 old->location, … … 1452 1679 GET_LABELS_V(old->labels) 1453 1680 ); 1681 cache.emplace( old, this->node ); 1454 1682 } 1455 1683 1456 1684 virtual void visit( CaseStmt * old ) override final { 1685 if ( inCache( old ) ) return; 1457 1686 this->node = new ast::CaseStmt( 1458 1687 old->location, … … 1461 1690 GET_LABELS_V(old->labels) 1462 1691 ); 1692 cache.emplace( old, this->node ); 1463 1693 } 1464 1694 1465 1695 virtual void visit( WhileStmt * old ) override final { 1696 if ( inCache( old ) ) return; 1466 1697 this->node = new ast::WhileStmt( 1467 1698 old->location, … … 1472 1703 GET_LABELS_V(old->labels) 1473 1704 ); 1705 cache.emplace( old, this->node ); 1474 1706 } 1475 1707 1476 1708 virtual void visit( ForStmt * old ) override final { 1709 if ( inCache( old ) ) return; 1477 1710 this->node = new ast::ForStmt( 1478 1711 old->location, … … 1483 1716 GET_LABELS_V(old->labels) 1484 1717 ); 1718 cache.emplace( old, this->node ); 1485 1719 } 1486 1720 1487 1721 virtual void visit( BranchStmt * old ) override final { 1722 if ( inCache( old ) ) return; 1488 1723 if (old->computedTarget) { 1489 1724 this->node = new ast::BranchStmt( … … 1519 1754 this->node = stmt; 1520 1755 } 1756 cache.emplace( old, this->node ); 1521 1757 } 1522 1758 1523 1759 virtual void visit( ReturnStmt * old ) override final { 1760 if ( inCache( old ) ) return; 1524 1761 this->node = new ast::ReturnStmt( 1525 1762 old->location, … … 1527 1764 GET_LABELS_V(old->labels) 1528 1765 ); 1766 cache.emplace( old, this->node ); 1529 1767 } 1530 1768 1531 1769 virtual void visit( ThrowStmt * old ) override final { 1770 if ( inCache( old ) ) return; 1532 1771 ast::ThrowStmt::Kind kind; 1533 1772 switch (old->kind) { … … 1549 1788 GET_LABELS_V(old->labels) 1550 1789 ); 1790 cache.emplace( old, this->node ); 1551 1791 } 1552 1792 1553 1793 virtual void visit( TryStmt * old ) override final { 1794 if ( inCache( old ) ) return; 1554 1795 this->node = new ast::TryStmt( 1555 1796 old->location, … … 1559 1800 GET_LABELS_V(old->labels) 1560 1801 ); 1802 cache.emplace( old, this->node ); 1561 1803 } 1562 1804 1563 1805 virtual void visit( CatchStmt * old ) override final { 1806 if ( inCache( old ) ) return; 1564 1807 ast::CatchStmt::Kind kind; 1565 1808 switch (old->kind) { … … 1582 1825 GET_LABELS_V(old->labels) 1583 1826 ); 1827 cache.emplace( old, this->node ); 1584 1828 } 1585 1829 1586 1830 virtual void visit( FinallyStmt * old ) override final { 1831 if ( inCache( old ) ) return; 1587 1832 this->node = new ast::FinallyStmt( 1588 1833 old->location, … … 1590 1835 GET_LABELS_V(old->labels) 1591 1836 ); 1837 cache.emplace( old, this->node ); 1592 1838 } 1593 1839 1594 1840 virtual void visit( WaitForStmt * old ) override final { 1841 if ( inCache( old ) ) return; 1595 1842 ast::WaitForStmt * stmt = new ast::WaitForStmt( 1596 1843 old->location, … … 1620 1867 1621 1868 this->node = stmt; 1869 cache.emplace( old, this->node ); 1622 1870 } 1623 1871 1624 1872 virtual void visit( WithStmt * old ) override final { 1873 if ( inCache( old ) ) return; 1625 1874 this->node = new ast::WithStmt( 1626 1875 old->location, … … 1629 1878 GET_LABELS_V(old->labels) 1630 1879 ); 1880 cache.emplace( old, this->node ); 1631 1881 } 1632 1882 1633 1883 virtual void visit( NullStmt * old ) override final { 1884 if ( inCache( old ) ) return; 1634 1885 this->node = new ast::NullStmt( 1635 1886 old->location, 1636 1887 GET_LABELS_V(old->labels) 1637 1888 ); 1889 cache.emplace( old, this->node ); 1638 1890 } 1639 1891 1640 1892 virtual void visit( DeclStmt * old ) override final { 1893 if ( inCache( old ) ) return; 1641 1894 this->node = new ast::DeclStmt( 1642 1895 old->location, … … 1644 1897 GET_LABELS_V(old->labels) 1645 1898 ); 1899 cache.emplace( old, this->node ); 1646 1900 } 1647 1901 1648 1902 virtual void visit( ImplicitCtorDtorStmt * old ) override final { 1903 if ( inCache( old ) ) return; 1649 1904 this->node = new ast::ImplicitCtorDtorStmt( 1650 1905 old->location, … … 1652 1907 GET_LABELS_V(old->labels) 1653 1908 ); 1909 cache.emplace( old, this->node ); 1654 1910 } 1655 1911 … … 1696 1952 } 1697 1953 1698 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1699 1700 nw->result = GET_ACCEPT_1(result, Type); 1954 ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) { 1955 1701 1956 nw->env = convertTypeSubstitution(old->env); 1702 1957 … … 1705 1960 1706 1961 return nw; 1962 } 1963 1964 ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) { 1965 1966 nw->result = GET_ACCEPT_1(result, Type); 1967 return visitBaseExpr_SkipResultType(old, nw);; 1707 1968 } 1708 1969 … … 1772 2033 1773 2034 virtual void visit( VirtualCastExpr * old ) override final { 1774 this->node = visitBaseExpr ( old,2035 this->node = visitBaseExpr_SkipResultType( old, 1775 2036 new ast::VirtualCastExpr( 1776 2037 old->location, 1777 2038 GET_ACCEPT_1(arg, Expr), 1778 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr2039 GET_ACCEPT_1(result, Type) 1779 2040 ) 1780 2041 ); … … 2001 2262 } 2002 2263 2003 virtual void visit( TypeExpr * ) override final { 2004 2005 } 2006 2007 virtual void visit( AsmExpr * ) override final { 2008 2009 } 2010 2011 virtual void visit( ImplicitCopyCtorExpr * ) override final { 2012 2013 } 2014 2015 virtual void visit( ConstructorExpr * ) override final { 2016 2017 } 2018 2019 virtual void visit( CompoundLiteralExpr * ) override final { 2020 2021 } 2022 2023 virtual void visit( RangeExpr * ) override final { 2024 2025 } 2026 2027 virtual void visit( UntypedTupleExpr * ) override final { 2028 2029 } 2030 2031 virtual void visit( TupleExpr * ) override final { 2032 2033 } 2034 2035 virtual void visit( TupleIndexExpr * ) override final { 2036 2037 } 2038 2039 virtual void visit( TupleAssignExpr * ) override final { 2040 2041 } 2042 2043 virtual void visit( StmtExpr * ) override final { 2044 2045 } 2046 2047 virtual void visit( UniqueExpr * ) override final { 2048 2049 } 2050 2051 virtual void visit( UntypedInitExpr * ) override final { 2052 2053 } 2054 2055 virtual void visit( InitExpr * ) override final { 2056 2057 } 2058 2059 virtual void visit( DeletedExpr * ) override final { 2060 2061 } 2062 2063 virtual void visit( DefaultArgExpr * ) override final { 2064 2065 } 2066 2067 virtual void visit( GenericExpr * ) override final { 2068 2264 virtual void visit( TypeExpr * old ) override final { 2265 this->node = visitBaseExpr( old, 2266 new ast::TypeExpr( 2267 old->location, 2268 GET_ACCEPT_1(type, Type) 2269 ) 2270 ); 2271 } 2272 2273 virtual void visit( AsmExpr * old ) override final { 2274 this->node = visitBaseExpr( old, 2275 new ast::AsmExpr( 2276 old->location, 2277 GET_ACCEPT_1(inout, Expr), 2278 GET_ACCEPT_1(constraint, Expr), 2279 GET_ACCEPT_1(operand, Expr) 2280 ) 2281 ); 2282 } 2283 2284 virtual void visit( ImplicitCopyCtorExpr * old ) override final { 2285 auto rslt = new ast::ImplicitCopyCtorExpr( 2286 old->location, 2287 GET_ACCEPT_1(callExpr, ApplicationExpr) 2288 ); 2289 2290 rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl); 2291 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2292 rslt->dtors = GET_ACCEPT_V(dtors, Expr); 2293 2294 this->node = visitBaseExpr( old, rslt ); 2295 } 2296 2297 virtual void visit( ConstructorExpr * old ) override final { 2298 this->node = visitBaseExpr( old, 2299 new ast::ConstructorExpr( 2300 old->location, 2301 GET_ACCEPT_1(callExpr, Expr) 2302 ) 2303 ); 2304 } 2305 2306 virtual void visit( CompoundLiteralExpr * old ) override final { 2307 this->node = visitBaseExpr_SkipResultType( old, 2308 new ast::CompoundLiteralExpr( 2309 old->location, 2310 GET_ACCEPT_1(result, Type), 2311 GET_ACCEPT_1(initializer, Init) 2312 ) 2313 ); 2314 } 2315 2316 virtual void visit( RangeExpr * old ) override final { 2317 this->node = visitBaseExpr( old, 2318 new ast::RangeExpr( 2319 old->location, 2320 GET_ACCEPT_1(low, Expr), 2321 GET_ACCEPT_1(high, Expr) 2322 ) 2323 ); 2324 } 2325 2326 virtual void visit( UntypedTupleExpr * old ) override final { 2327 this->node = visitBaseExpr( old, 2328 new ast::UntypedTupleExpr( 2329 old->location, 2330 GET_ACCEPT_V(exprs, Expr) 2331 ) 2332 ); 2333 } 2334 2335 virtual void visit( TupleExpr * old ) override final { 2336 this->node = visitBaseExpr( old, 2337 new ast::TupleExpr( 2338 old->location, 2339 GET_ACCEPT_V(exprs, Expr) 2340 ) 2341 ); 2342 } 2343 2344 virtual void visit( TupleIndexExpr * old ) override final { 2345 this->node = visitBaseExpr( old, 2346 new ast::TupleIndexExpr( 2347 old->location, 2348 GET_ACCEPT_1(tuple, Expr), 2349 old->index 2350 ) 2351 ); 2352 } 2353 2354 virtual void visit( TupleAssignExpr * old ) override final { 2355 this->node = visitBaseExpr_SkipResultType( old, 2356 new ast::TupleAssignExpr( 2357 old->location, 2358 GET_ACCEPT_1(result, Type), 2359 GET_ACCEPT_1(stmtExpr, StmtExpr) 2360 ) 2361 ); 2362 } 2363 2364 virtual void visit( StmtExpr * old ) override final { 2365 auto rslt = new ast::StmtExpr( 2366 old->location, 2367 GET_ACCEPT_1(statements, CompoundStmt) 2368 ); 2369 rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl); 2370 rslt->dtors = GET_ACCEPT_V(dtors , Expr); 2371 2372 this->node = visitBaseExpr_SkipResultType( old, rslt ); 2373 } 2374 2375 virtual void visit( UniqueExpr * old ) override final { 2376 auto rslt = new ast::UniqueExpr( 2377 old->location, 2378 GET_ACCEPT_1(expr, Expr) 2379 ); 2380 rslt->object = GET_ACCEPT_1(object, ObjectDecl); 2381 rslt->var = GET_ACCEPT_1(var , VariableExpr); 2382 2383 this->node = visitBaseExpr( old, rslt ); 2384 } 2385 2386 virtual void visit( UntypedInitExpr * old ) override final { 2387 std::vector<ast::InitAlternative> initAlts; 2388 for (auto ia : old->initAlts) { 2389 initAlts.push_back(ast::InitAlternative( 2390 getAccept1< ast::Type, Type * >( ia.type ), 2391 getAccept1< ast::Designation, Designation * >( ia.designation ) 2392 )); 2393 } 2394 this->node = visitBaseExpr( old, 2395 new ast::UntypedInitExpr( 2396 old->location, 2397 GET_ACCEPT_1(expr, Expr), 2398 std::move(initAlts) 2399 ) 2400 ); 2401 } 2402 2403 virtual void visit( InitExpr * old ) override final { 2404 this->node = visitBaseExpr( old, 2405 new ast::InitExpr( 2406 old->location, 2407 GET_ACCEPT_1(expr, Expr), 2408 GET_ACCEPT_1(designation, Designation) 2409 ) 2410 ); 2411 } 2412 2413 virtual void visit( DeletedExpr * old ) override final { 2414 this->node = visitBaseExpr( old, 2415 new ast::DeletedExpr( 2416 old->location, 2417 GET_ACCEPT_1(expr, Expr), 2418 inCache(old->deleteStmt) ? 2419 this->node : 2420 GET_ACCEPT_1(deleteStmt, Node) 2421 ) 2422 ); 2423 } 2424 2425 virtual void visit( DefaultArgExpr * old ) override final { 2426 this->node = visitBaseExpr( old, 2427 new ast::DefaultArgExpr( 2428 old->location, 2429 GET_ACCEPT_1(expr, Expr) 2430 ) 2431 ); 2432 } 2433 2434 virtual void visit( GenericExpr * old ) override final { 2435 std::vector<ast::GenericExpr::Association> associations; 2436 for (auto association : old->associations) { 2437 associations.push_back(ast::GenericExpr::Association( 2438 getAccept1< ast::Type, Type * >( association.type ), 2439 getAccept1< ast::Expr, Expression * >( association.expr ) 2440 )); 2441 } 2442 this->node = visitBaseExpr( old, 2443 new ast::GenericExpr( 2444 old->location, 2445 GET_ACCEPT_1(control, Expr), 2446 std::move(associations) 2447 ) 2448 ); 2069 2449 } 2070 2450 … … 2262 2642 } 2263 2643 2264 virtual void visit( Designation * ) override final { 2265 2266 } 2267 2268 virtual void visit( SingleInit * ) override final { 2269 2270 } 2271 2272 virtual void visit( ListInit * ) override final { 2273 2274 } 2275 2276 virtual void visit( ConstructorInit * ) override final { 2277 2644 virtual void visit( Designation * old ) override final { 2645 this->node = new ast::Designation( 2646 old->location, 2647 GET_ACCEPT_V(designators, Expr) 2648 ); 2649 } 2650 2651 virtual void visit( SingleInit * old ) override final { 2652 this->node = new ast::SingleInit( 2653 old->location, 2654 GET_ACCEPT_1(value, Expr), 2655 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2656 ); 2657 } 2658 2659 virtual void visit( ListInit * old ) override final { 2660 this->node = new ast::ListInit( 2661 old->location, 2662 GET_ACCEPT_V(initializers, Init), 2663 GET_ACCEPT_V(designations, Designation), 2664 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct 2665 ); 2666 } 2667 2668 virtual void visit( ConstructorInit * old ) override final { 2669 this->node = new ast::ConstructorInit( 2670 old->location, 2671 GET_ACCEPT_1(ctor, Stmt), 2672 GET_ACCEPT_1(dtor, Stmt), 2673 GET_ACCEPT_1(init, Init) 2674 ); 2278 2675 } 2279 2676 2280 2677 virtual void visit( Constant * ) override final { 2281 2282 } 2283 2284 virtual void visit( Attribute * ) override final { 2285 2678 // Handled in visit( ConstantEpxr * ). 2679 // In the new tree, Constant fields are inlined into containing ConstantExpression. 2680 assert( 0 ); 2681 } 2682 2683 virtual void visit( Attribute * old ) override final { 2684 this->node = new ast::Attribute( 2685 old->name, 2686 GET_ACCEPT_V( parameters, Expr ) 2687 ); 2286 2688 } 2287 2689 2288 2690 virtual void visit( AttrExpr * ) override final { 2289 2290 assert( 0 ); 2691 assertf( false, "AttrExpr deprecated in new AST." ); 2291 2692 } 2292 2693 }; -
src/AST/Expr.cpp
re9b44489 rf4c2f1a 335 335 } 336 336 337 TupleAssignExpr::TupleAssignExpr( 338 const CodeLocation & loc, const Type * result, const StmtExpr * s ) 339 : Expr( loc, result ), stmtExpr() { 340 stmtExpr = s; 341 } 342 337 343 // --- StmtExpr 338 344 -
src/AST/Expr.hpp
re9b44489 rf4c2f1a 30 30 #define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node); 31 31 32 class ConverterOldToNew; 33 32 34 namespace ast { 33 35 … … 528 530 std::vector<ptr<ObjectDecl>> tempDecls; 529 531 std::vector<ptr<ObjectDecl>> returnDecls; 530 std::vector<ptr< ObjectDecl>> dtors;532 std::vector<ptr<Expr>> dtors; 531 533 532 534 ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call ) … … 635 637 636 638 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } 639 640 friend class ::ConverterOldToNew; 641 637 642 private: 638 643 TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; } 644 TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s ); 645 639 646 MUTATE_FRIEND 640 647 }; -
src/AST/Stmt.hpp
re9b44489 rf4c2f1a 96 96 }; 97 97 98 /// Assembly statement `asm ... ( "..." : ... )` 98 99 class AsmStmt final : public Stmt { 99 100 public: … … 118 119 }; 119 120 121 /// C-preprocessor directive `#...` 120 122 class DirectiveStmt final : public Stmt { 121 123 public: … … 132 134 }; 133 135 136 /// If conditional statement `if (...) ... else ...` 134 137 class IfStmt final : public Stmt { 135 138 public: … … 151 154 }; 152 155 156 /// Switch or choose conditional statement `switch (...) { ... }` 153 157 class SwitchStmt final : public Stmt { 154 158 public: … … 166 170 }; 167 171 172 /// Case label `case ...:` `default:` 168 173 class CaseStmt final : public Stmt { 169 174 public: … … 183 188 }; 184 189 190 /// While loop `while (...) ...` `do ... while (...); 185 191 class WhileStmt final : public Stmt { 186 192 public: … … 201 207 }; 202 208 209 /// For loop `for (... ; ... ; ...) ...` 203 210 class ForStmt final : public Stmt { 204 211 public: … … 219 226 }; 220 227 228 /// Branch control flow statement `goto ...` `break` `continue` `fallthru` 221 229 class BranchStmt final : public Stmt { 222 230 public: … … 246 254 }; 247 255 256 /// Return statement `return ...` 248 257 class ReturnStmt final : public Stmt { 249 258 public: … … 259 268 }; 260 269 270 /// Throw statement `throw ...` 261 271 class ThrowStmt final : public Stmt { 262 272 public: … … 277 287 }; 278 288 289 /// Try statement `try { ... } ...` 279 290 class TryStmt final : public Stmt { 280 291 public: … … 294 305 }; 295 306 307 /// Catch clause of try statement 296 308 class CatchStmt final : public Stmt { 297 309 public: … … 313 325 }; 314 326 327 /// Finally clause of try statement 315 328 class FinallyStmt final : public Stmt { 316 329 public: … … 327 340 }; 328 341 342 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...` 329 343 class WaitForStmt final : public Stmt { 330 344 public: … … 364 378 }; 365 379 380 /// With statement `with (...) ...` 366 381 class WithStmt final : public Stmt { 367 382 public: … … 379 394 }; 380 395 396 /// Any declaration in a (compound) statement. 381 397 class DeclStmt final : public Stmt { 382 398 public: … … 392 408 }; 393 409 410 /// Represents an implicit application of a constructor or destructor. 394 411 class ImplicitCtorDtorStmt final : public Stmt { 395 412 public: -
src/SynTree/Expression.h
re9b44489 rf4c2f1a 741 741 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 742 742 virtual void print( std::ostream & os, Indenter indent = {} ) const; 743 744 friend class ConverterNewToOld; 745 private: 746 TupleAssignExpr( StmtExpr * stmts ); 743 747 }; 744 748 -
src/SynTree/TupleExpr.cc
re9b44489 rf4c2f1a 105 105 } 106 106 107 TupleAssignExpr::TupleAssignExpr( 108 StmtExpr * s ) 109 : Expression(), stmtExpr(s) { 110 } 111 112 107 113 TupleAssignExpr::~TupleAssignExpr() { 108 114 delete stmtExpr;
Note: See TracChangeset
for help on using the changeset viewer.