Changes in src/AST/Convert.cpp [4ec9513:ff3b0249]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r4ec9513 rff3b0249 9 9 // Author : Thierry Delisle 10 10 // Created On : Thu May 09 15::37::05 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Mar 16 15:01:00202213 // Update Count : 4 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 2 13:19:22 2022 13 // Update Count : 41 14 14 // 15 15 … … 49 49 //================================================================================================ 50 50 namespace ast { 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; 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; 58 61 59 62 } … … 273 276 decl->parent = get<AggregateDecl>().accept1( node->parent ); 274 277 declPostamble( decl, node ); 275 return nullptr; // ??278 return nullptr; 276 279 } 277 280 … … 307 310 node->name, 308 311 get<Attribute>().acceptL( node->attributes ), 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 312 LinkageSpec::Spec( node->linkage.val ) 313 ); 314 return aggregatePostamble( decl, node ); 313 315 } 314 316 … … 352 354 this->node = stmt; 353 355 return nullptr; 354 }355 356 void clausePostamble( Statement * stmt, const ast::StmtClause * node ) {357 stmt->location = node->location;358 this->node = stmt;359 356 } 360 357 … … 407 404 auto stmt = new SwitchStmt( 408 405 get<Expression>().accept1( node->cond ), 409 get<Statement>().acceptL( node-> cases )406 get<Statement>().acceptL( node->stmts ) 410 407 ); 411 408 return stmtPostamble( stmt, node ); 412 409 } 413 410 414 const ast:: CaseClause * visit( const ast::CaseClause* node ) override final {411 const ast::Stmt * visit( const ast::CaseStmt * node ) override final { 415 412 if ( inCache( node ) ) return nullptr; 416 413 auto stmt = new CaseStmt( … … 419 416 node->isDefault() 420 417 ); 421 clausePostamble( stmt, node ); 422 return nullptr; 418 return stmtPostamble( stmt, node ); 423 419 } 424 420 … … 516 512 } 517 513 518 const ast:: CatchClause * visit( const ast::CatchClause* node ) override final {514 const ast::Stmt * visit( const ast::CatchStmt * node ) override final { 519 515 if ( inCache( node ) ) return nullptr; 520 516 CatchStmt::Kind kind; … … 527 523 break; 528 524 default: 529 assertf(false, "Invalid ast:: ExceptionKind: %d\n", node->kind);525 assertf(false, "Invalid ast::CatchStmt::Kind: %d\n", node->kind); 530 526 } 531 527 auto stmt = new CatchStmt( … … 535 531 get<Statement>().accept1( node->body ) 536 532 ); 537 return clausePostamble( stmt, node ), nullptr;538 } 539 540 const ast:: FinallyClause * visit( const ast::FinallyClause* node ) override final {533 return stmtPostamble( stmt, node ); 534 } 535 536 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 541 537 if ( inCache( node ) ) return nullptr; 542 538 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 543 return clausePostamble( stmt, node ), nullptr;539 return stmtPostamble( stmt, node ); 544 540 } 545 541 … … 951 947 } 952 948 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 959 949 const ast::Expr * visit( const ast::AsmExpr * node ) override final { 960 950 auto expr = visitBaseExpr( node, … … 1477 1467 return strict_dynamic_cast< ast::Decl * >( node ); 1478 1468 } 1479 1469 1480 1470 ConverterOldToNew() = default; 1481 1471 ConverterOldToNew(const ConverterOldToNew &) = delete; … … 1505 1495 getAccept1< ast::type, decltype( old->child ) >( old->child ) 1506 1496 1507 1508 1497 template<typename NewT, typename OldC> 1509 1498 std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) { … … 1520 1509 # define GET_ACCEPT_V(child, type) \ 1521 1510 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 )1525 1511 1526 1512 template<typename NewT, typename OldC> … … 1724 1710 } 1725 1711 1726 // Convert SynTree::EnumDecl to AST::EnumDecl1727 1712 virtual void visit( const EnumDecl * old ) override final { 1728 1713 if ( inCache( old ) ) return; … … 1731 1716 old->name, 1732 1717 GET_ACCEPT_V(attributes, Attribute), 1733 { old->linkage.val }, 1734 GET_ACCEPT_1(base, Type), 1735 old->enumValues 1718 { old->linkage.val } 1736 1719 ); 1737 1720 cache.emplace( old, decl ); … … 1743 1726 decl->uniqueId = old->uniqueId; 1744 1727 decl->storage = { old->storageClasses.val }; 1728 1745 1729 this->node = decl; 1746 1730 } … … 1903 1887 old->location, 1904 1888 GET_ACCEPT_1(condition, Expr), 1905 GET_ACCEPT_V(statements, CaseClause),1889 GET_ACCEPT_V(statements, Stmt), 1906 1890 GET_LABELS_V(old->labels) 1907 1891 ); … … 1911 1895 virtual void visit( const CaseStmt * old ) override final { 1912 1896 if ( inCache( old ) ) return; 1913 this->node = new ast::Case Clause(1897 this->node = new ast::CaseStmt( 1914 1898 old->location, 1915 1899 GET_ACCEPT_1(condition, Expr), 1916 GET_ACCEPT_V(stmts, Stmt) 1917 ); 1918 auto labels = GET_LABELS_V(old->labels); 1919 assertf(labels.empty(), "Labels found on CaseStmt."); 1900 GET_ACCEPT_V(stmts, Stmt), 1901 GET_LABELS_V(old->labels) 1902 ); 1920 1903 cache.emplace( old, this->node ); 1921 1904 } … … 2025 2008 old->location, 2026 2009 GET_ACCEPT_1(block, CompoundStmt), 2027 GET_ACCEPT_V(handlers, Catch Clause),2028 GET_ACCEPT_1(finallyBlock, Finally Clause),2010 GET_ACCEPT_V(handlers, CatchStmt), 2011 GET_ACCEPT_1(finallyBlock, FinallyStmt), 2029 2012 GET_LABELS_V(old->labels) 2030 2013 ); … … 2046 2029 } 2047 2030 2048 this->node = new ast::Catch Clause(2031 this->node = new ast::CatchStmt( 2049 2032 old->location, 2050 2033 kind, 2051 2034 GET_ACCEPT_1(decl, Decl), 2052 2035 GET_ACCEPT_1(cond, Expr), 2053 GET_ACCEPT_1(body, Stmt) 2054 ); 2055 auto labels = GET_LABELS_V(old->labels); 2056 assertf(labels.empty(), "Labels found on CatchStmt."); 2036 GET_ACCEPT_1(body, Stmt), 2037 GET_LABELS_V(old->labels) 2038 ); 2057 2039 cache.emplace( old, this->node ); 2058 2040 } … … 2060 2042 virtual void visit( const FinallyStmt * old ) override final { 2061 2043 if ( inCache( old ) ) return; 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."); 2044 this->node = new ast::FinallyStmt( 2045 old->location, 2046 GET_ACCEPT_1(block, CompoundStmt), 2047 GET_LABELS_V(old->labels) 2048 ); 2068 2049 cache.emplace( old, this->node ); 2069 2050 } … … 2469 2450 2470 2451 virtual void visit( const DimensionExpr * old ) override final { 2471 this->node = visitBaseExpr( old, 2472 new ast::DimensionExpr( old->location, old->name ) 2473 ); 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"); 2474 2460 } 2475 2461 … … 2725 2711 2726 2712 for (auto & param : foralls) { 2727 ty->forall.emplace_back(new ast::TypeInstType(param ));2713 ty->forall.emplace_back(new ast::TypeInstType(param->name, param)); 2728 2714 for (auto asst : param->assertions) { 2729 2715 ty->assertions.emplace_back(new ast::VariableExpr({}, asst)); … … 2775 2761 } 2776 2762 2777 virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.2778 ast::EnumInstType * ty; 2763 virtual void visit( const EnumInstType * old ) override final { 2764 ast::EnumInstType * ty; 2779 2765 if ( old->baseEnum ) { 2780 ty = new ast::EnumInstType{ // Probably here: missing the specification of the base2766 ty = new ast::EnumInstType{ 2781 2767 GET_ACCEPT_1( baseEnum, EnumDecl ), 2782 2768 cv( old ),
Note:
See TracChangeset
for help on using the changeset viewer.