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