Changeset c28ea4e for src/AST/Convert.cpp
- Timestamp:
- Nov 4, 2020, 2:56:30 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- eeb5023
- Parents:
- 4b30e8cc (diff), a3f5208a (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
r4b30e8cc rc28ea4e 25 25 #include "AST/Init.hpp" 26 26 #include "AST/Stmt.hpp" 27 #include "AST/TranslationUnit.hpp" 27 28 #include "AST/TypeSubstitution.hpp" 28 29 … … 47 48 48 49 //================================================================================================ 49 namespace {50 namespace ast { 50 51 51 52 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 52 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 53 57 ast::Type * sizeType = nullptr; 54 58 ast::FunctionDecl * dereferenceOperator = nullptr; … … 63 67 using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >; 64 68 Cache cache; 69 70 // Statements can no longer be shared. 71 // however, since StmtExprResult is now implemented, need to still maintain 72 // readonly references. 73 Cache readonlyCache; 65 74 66 75 template<typename T> … … 154 163 } 155 164 156 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 157 auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth ); 158 auto&& type = get<Type>().accept1( node->type ); 159 auto&& init = get<Initializer>().accept1( node->init ); 160 auto&& attr = get<Attribute>().acceptL( node->attributes ); 165 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 161 166 if ( inCache( node ) ) { 162 167 return nullptr; 163 168 } 169 auto bfwd = get<Expression>().accept1( node->bitfieldWidth ); 170 auto type = get<Type>().accept1( node->type ); 171 auto attr = get<Attribute>().acceptL( node->attributes ); 172 164 173 auto decl = new ObjectDecl( 165 174 node->name, … … 168 177 bfwd, 169 178 type->clone(), 170 init,179 nullptr, // prevent infinite loop 171 180 attr, 172 181 Type::FuncSpecifiers( node->funcSpec.val ) 173 182 ); 174 return declWithTypePostamble( decl, node ); 183 184 // handles the case where node->init references itself 185 // xxx - does it really happen? 186 declWithTypePostamble(decl, node); 187 auto init = get<Initializer>().accept1( node->init ); 188 decl->init = init; 189 190 this->node = decl; 191 return nullptr; 175 192 } 176 193 … … 205 222 decl->statements = get<CompoundStmt>().accept1( node->stmts ); 206 223 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 207 if ( dereferenceOperator == node ) {224 if ( ast::dereferenceOperator == node ) { 208 225 Validate::dereferenceOperator = decl; 209 226 } 210 if ( dtorStructDestroy == node ) {227 if ( ast::dtorStructDestroy == node ) { 211 228 Validate::dtorStructDestroy = decl; 212 229 } … … 267 284 ); 268 285 269 if ( dtorStruct == node ) {286 if ( ast::dtorStruct == node ) { 270 287 Validate::dtorStruct = decl; 271 288 } … … 320 337 321 338 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 322 cache.emplace( node, stmt ); 339 // force statements in old tree to be unique. 340 // cache.emplace( node, stmt ); 341 readonlyCache.emplace( node, stmt ); 323 342 stmt->location = node->location; 324 343 stmt->labels = makeLabelL( stmt, node->labels ); … … 337 356 if ( inCache( node ) ) return nullptr; 338 357 auto stmt = new ExprStmt( nullptr ); 339 cache.emplace( node, stmt );340 358 stmt->expr = get<Expression>().accept1( node->expr ); 341 359 return stmtPostamble( stmt, node ); … … 1011 1029 auto stmts = node->stmts; 1012 1030 // disable sharing between multiple StmtExprs explicitly. 1013 if (inCache(stmts)) { 1014 stmts = ast::deepCopy(stmts.get()); 1015 } 1031 // this should no longer be true. 1032 1016 1033 auto rslt = new StmtExpr( 1017 1034 get<CompoundStmt>().accept1(stmts) … … 1020 1037 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 1021 1038 rslt->dtors = get<Expression>().acceptL(node->dtors); 1039 if (node->resultExpr) { 1040 // this MUST be found by children visit 1041 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr)); 1042 } 1022 1043 1023 1044 auto expr = visitBaseExpr( node, rslt ); … … 1036 1057 1037 1058 auto expr = visitBaseExpr( node, rslt ); 1038 this->node = expr ;1059 this->node = expr->clone(); 1039 1060 return nullptr; 1040 1061 } … … 1126 1147 auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1127 1148 // I believe this should always be a BasicType. 1128 if ( sizeType == node ) {1149 if ( ast::sizeType == node ) { 1129 1150 Validate::SizeType = type; 1130 1151 } … … 1384 1405 }; 1385 1406 1386 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > >&& translationUnit ) {1407 std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) { 1387 1408 ConverterNewToOld c; 1388 1409 std::list< Declaration * > decls; 1389 for(auto d : translationUnit ) {1410 for(auto d : translationUnit.decls) { 1390 1411 decls.emplace_back( c.decl( d ) ); 1391 1412 } … … 1529 1550 1530 1551 // function type is now derived from parameter decls instead of storing them 1552 1553 /* 1531 1554 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type)); 1532 1555 ftype->params.reserve(paramVars.size()); … … 1540 1563 } 1541 1564 ftype->forall = std::move(forall); 1542 visitType(old->type, ftype); 1565 */ 1566 1567 // can function type have attributes? seems not to be the case. 1568 // visitType(old->type, ftype); 1543 1569 1544 1570 auto decl = new ast::FunctionDecl{ … … 1546 1572 old->name, 1547 1573 // GET_ACCEPT_1(type, FunctionType), 1574 std::move(forall), 1548 1575 std::move(paramVars), 1549 1576 std::move(returnVars), … … 1552 1579 { old->linkage.val }, 1553 1580 GET_ACCEPT_V(attributes, Attribute), 1554 { old->get_funcSpec().val } 1581 { old->get_funcSpec().val }, 1582 old->type->isVarArgs 1555 1583 }; 1556 1584 1557 decl->type = ftype;1585 // decl->type = ftype; 1558 1586 cache.emplace( old, decl ); 1559 1587 … … 1570 1598 1571 1599 if ( Validate::dereferenceOperator == old ) { 1572 dereferenceOperator = decl;1600 ast::dereferenceOperator = decl; 1573 1601 } 1574 1602 1575 1603 if ( Validate::dtorStructDestroy == old ) { 1576 dtorStructDestroy = decl;1604 ast::dtorStructDestroy = decl; 1577 1605 } 1578 1606 } … … 1599 1627 1600 1628 if ( Validate::dtorStruct == old ) { 1601 dtorStruct = decl;1629 ast::dtorStruct = decl; 1602 1630 } 1603 1631 } … … 2531 2559 // I believe this should always be a BasicType. 2532 2560 if ( Validate::SizeType == old ) { 2533 sizeType = type;2561 ast::sizeType = type; 2534 2562 } 2535 2563 visitType( old, type ); … … 2776 2804 #undef GET_ACCEPT_1 2777 2805 2778 std::list< ast::ptr< ast::Decl > >convert( const std::list< Declaration * > && translationUnit ) {2806 ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) { 2779 2807 ConverterOldToNew c; 2780 std::list< ast::ptr< ast::Decl > > decls;2808 ast::TranslationUnit unit; 2781 2809 for(auto d : translationUnit) { 2782 2810 d->accept( c ); 2783 decls.emplace_back( c.decl() );2811 unit.decls.emplace_back( c.decl() ); 2784 2812 } 2785 2813 deleteAll(translationUnit); 2786 return decls;2814 return unit; 2787 2815 }
Note:
See TracChangeset
for help on using the changeset viewer.