Changeset 2e9b59b for src/AST/Convert.cpp
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 5b84a321
- Parents:
- ba897d21 (diff), bb7c77d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rba897d21 r2e9b59b 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 2 13:19:22202213 // Update Count : 4 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Mar 16 15:01:00 2022 13 // Update Count : 42 14 14 // 15 15 … … 49 49 //================================================================================================ 50 50 namespace ast { 51 52 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 53 // allow us to use the same stratagy in the new ast. 54 // xxx - since convert back pass works, this concern seems to be unnecessary. 55 56 // these need to be accessed in new FixInit now 57 ast::ptr<ast::Type> sizeType = nullptr; 58 const ast::FunctionDecl * dereferenceOperator = nullptr; 59 const ast::StructDecl * dtorStruct = nullptr; 60 const ast::FunctionDecl * dtorStructDestroy = nullptr; 51 // These are the shared local information used by ConverterNewToOld and 52 // ConverterOldToNew to update the global information in the two versions. 53 54 static ast::ptr<ast::Type> sizeType = nullptr; 55 static const ast::FunctionDecl * dereferenceOperator = nullptr; 56 static const ast::StructDecl * dtorStruct = nullptr; 57 static const ast::FunctionDecl * dtorStructDestroy = nullptr; 61 58 62 59 } … … 276 273 decl->parent = get<AggregateDecl>().accept1( node->parent ); 277 274 declPostamble( decl, node ); 278 return nullptr; 275 return nullptr; // ?? 279 276 } 280 277 … … 310 307 node->name, 311 308 get<Attribute>().acceptL( node->attributes ), 312 LinkageSpec::Spec( node->linkage.val ) 313 ); 314 return aggregatePostamble( decl, node ); 309 LinkageSpec::Spec( node->linkage.val ), 310 get<Type>().accept1(node->base) 311 ); 312 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble 315 313 } 316 314 … … 354 352 this->node = stmt; 355 353 return nullptr; 354 } 355 356 void clausePostamble( Statement * stmt, const ast::StmtClause * node ) { 357 stmt->location = node->location; 358 this->node = stmt; 356 359 } 357 360 … … 404 407 auto stmt = new SwitchStmt( 405 408 get<Expression>().accept1( node->cond ), 406 get<Statement>().acceptL( node-> stmts )409 get<Statement>().acceptL( node->cases ) 407 410 ); 408 411 return stmtPostamble( stmt, node ); 409 412 } 410 413 411 const ast:: Stmt * visit( const ast::CaseStmt* node ) override final {414 const ast::CaseClause * visit( const ast::CaseClause * node ) override final { 412 415 if ( inCache( node ) ) return nullptr; 413 416 auto stmt = new CaseStmt( … … 416 419 node->isDefault() 417 420 ); 418 return stmtPostamble( stmt, node ); 421 clausePostamble( stmt, node ); 422 return nullptr; 419 423 } 420 424 … … 512 516 } 513 517 514 const ast:: Stmt * visit( const ast::CatchStmt* node ) override final {518 const ast::CatchClause * visit( const ast::CatchClause * node ) override final { 515 519 if ( inCache( node ) ) return nullptr; 516 520 CatchStmt::Kind kind; … … 523 527 break; 524 528 default: 525 assertf(false, "Invalid ast:: CatchStmt::Kind: %d\n", node->kind);529 assertf(false, "Invalid ast::ExceptionKind: %d\n", node->kind); 526 530 } 527 531 auto stmt = new CatchStmt( … … 531 535 get<Statement>().accept1( node->body ) 532 536 ); 533 return stmtPostamble( stmt, node );534 } 535 536 const ast:: Stmt * visit( const ast::FinallyStmt* node ) override final {537 return clausePostamble( stmt, node ), nullptr; 538 } 539 540 const ast::FinallyClause * visit( const ast::FinallyClause * node ) override final { 537 541 if ( inCache( node ) ) return nullptr; 538 542 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 539 return stmtPostamble( stmt, node );543 return clausePostamble( stmt, node ), nullptr; 540 544 } 541 545 … … 947 951 } 948 952 953 const ast::Expr * visit( const ast::DimensionExpr * node ) override final { 954 auto expr = visitBaseExpr( node, new DimensionExpr( node->name ) ); 955 this->node = expr; 956 return nullptr; 957 } 958 949 959 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 950 960 auto expr = visitBaseExpr( node, … … 1467 1477 return strict_dynamic_cast< ast::Decl * >( node ); 1468 1478 } 1469 1479 1470 1480 ConverterOldToNew() = default; 1471 1481 ConverterOldToNew(const ConverterOldToNew &) = delete; … … 1495 1505 getAccept1< ast::type, decltype( old->child ) >( old->child ) 1496 1506 1507 1497 1508 template<typename NewT, typename OldC> 1498 1509 std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) { … … 1509 1520 # define GET_ACCEPT_V(child, type) \ 1510 1521 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 1522 1523 # define GET_ACCEPT_E(child, type) \ 1524 getAccept1< ast::type, decltype( old->base ) >( old->base ) 1511 1525 1512 1526 template<typename NewT, typename OldC> … … 1710 1724 } 1711 1725 1726 // Convert SynTree::EnumDecl to AST::EnumDecl 1712 1727 virtual void visit( const EnumDecl * old ) override final { 1713 1728 if ( inCache( old ) ) return; … … 1716 1731 old->name, 1717 1732 GET_ACCEPT_V(attributes, Attribute), 1718 { old->linkage.val } 1733 { old->linkage.val }, 1734 GET_ACCEPT_1(base, Type), 1735 old->enumValues 1719 1736 ); 1720 1737 cache.emplace( old, decl ); … … 1726 1743 decl->uniqueId = old->uniqueId; 1727 1744 decl->storage = { old->storageClasses.val }; 1728 1729 1745 this->node = decl; 1730 1746 } … … 1887 1903 old->location, 1888 1904 GET_ACCEPT_1(condition, Expr), 1889 GET_ACCEPT_V(statements, Stmt),1905 GET_ACCEPT_V(statements, CaseClause), 1890 1906 GET_LABELS_V(old->labels) 1891 1907 ); … … 1895 1911 virtual void visit( const CaseStmt * old ) override final { 1896 1912 if ( inCache( old ) ) return; 1897 this->node = new ast::Case Stmt(1913 this->node = new ast::CaseClause( 1898 1914 old->location, 1899 1915 GET_ACCEPT_1(condition, Expr), 1900 GET_ACCEPT_V(stmts, Stmt), 1901 GET_LABELS_V(old->labels) 1902 ); 1916 GET_ACCEPT_V(stmts, Stmt) 1917 ); 1918 auto labels = GET_LABELS_V(old->labels); 1919 assertf(labels.empty(), "Labels found on CaseStmt."); 1903 1920 cache.emplace( old, this->node ); 1904 1921 } … … 2008 2025 old->location, 2009 2026 GET_ACCEPT_1(block, CompoundStmt), 2010 GET_ACCEPT_V(handlers, Catch Stmt),2011 GET_ACCEPT_1(finallyBlock, Finally Stmt),2027 GET_ACCEPT_V(handlers, CatchClause), 2028 GET_ACCEPT_1(finallyBlock, FinallyClause), 2012 2029 GET_LABELS_V(old->labels) 2013 2030 ); … … 2029 2046 } 2030 2047 2031 this->node = new ast::Catch Stmt(2048 this->node = new ast::CatchClause( 2032 2049 old->location, 2033 2050 kind, 2034 2051 GET_ACCEPT_1(decl, Decl), 2035 2052 GET_ACCEPT_1(cond, Expr), 2036 GET_ACCEPT_1(body, Stmt), 2037 GET_LABELS_V(old->labels) 2038 ); 2053 GET_ACCEPT_1(body, Stmt) 2054 ); 2055 auto labels = GET_LABELS_V(old->labels); 2056 assertf(labels.empty(), "Labels found on CatchStmt."); 2039 2057 cache.emplace( old, this->node ); 2040 2058 } … … 2042 2060 virtual void visit( const FinallyStmt * old ) override final { 2043 2061 if ( inCache( old ) ) return; 2044 this->node = new ast::FinallyStmt( 2045 old->location, 2046 GET_ACCEPT_1(block, CompoundStmt), 2047 GET_LABELS_V(old->labels) 2048 ); 2062 this->node = new ast::FinallyClause( 2063 old->location, 2064 GET_ACCEPT_1(block, CompoundStmt) 2065 ); 2066 auto labels = GET_LABELS_V(old->labels); 2067 assertf(labels.empty(), "Labels found on FinallyStmt."); 2049 2068 cache.emplace( old, this->node ); 2050 2069 } … … 2450 2469 2451 2470 virtual void visit( const DimensionExpr * old ) override final { 2452 // DimensionExpr gets desugared away in Validate. 2453 // As long as new-AST passes don't use it, this cheap-cheerful error 2454 // detection helps ensure that these occurrences have been compiled 2455 // away, as expected. To move the DimensionExpr boundary downstream 2456 // or move the new-AST translation boundary upstream, implement 2457 // DimensionExpr in the new AST and implement a conversion. 2458 (void) old; 2459 assert(false && "DimensionExpr should not be present at new-AST boundary"); 2471 this->node = visitBaseExpr( old, 2472 new ast::DimensionExpr( old->location, old->name ) 2473 ); 2460 2474 } 2461 2475 … … 2711 2725 2712 2726 for (auto & param : foralls) { 2713 ty->forall.emplace_back(new ast::TypeInstType(param ->name, param));2727 ty->forall.emplace_back(new ast::TypeInstType(param)); 2714 2728 for (auto asst : param->assertions) { 2715 2729 ty->assertions.emplace_back(new ast::VariableExpr({}, asst)); … … 2761 2775 } 2762 2776 2763 virtual void visit( const EnumInstType * old ) override final { 2764 ast::EnumInstType * ty; 2777 virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage. 2778 ast::EnumInstType * ty; 2765 2779 if ( old->baseEnum ) { 2766 ty = new ast::EnumInstType{ 2780 ty = new ast::EnumInstType{ // Probably here: missing the specification of the base 2767 2781 GET_ACCEPT_1( baseEnum, EnumDecl ), 2768 2782 cv( old ),
Note:
See TracChangeset
for help on using the changeset viewer.