Changes in src/AST/Convert.cpp [490fb92e:954c954]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r490fb92e r954c954 47 47 48 48 //================================================================================================ 49 namespace ast{49 namespace { 50 50 51 51 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 52 52 // allow us to use the same stratagy in the new ast. 53 // xxx - since convert back pass works, this concern seems to be unnecessary.54 55 // these need to be accessed in new FixInit now56 53 ast::Type * sizeType = nullptr; 57 54 ast::FunctionDecl * dereferenceOperator = nullptr; … … 66 63 using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >; 67 64 Cache cache; 68 69 // Statements can no longer be shared.70 // however, since StmtExprResult is now implemented, need to still maintain71 // readonly references.72 Cache readonlyCache;73 65 74 66 template<typename T> … … 162 154 } 163 155 164 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 ); 165 161 if ( inCache( node ) ) { 166 162 return nullptr; 167 163 } 168 auto bfwd = get<Expression>().accept1( node->bitfieldWidth );169 auto type = get<Type>().accept1( node->type );170 auto attr = get<Attribute>().acceptL( node->attributes );171 172 164 auto decl = new ObjectDecl( 173 165 node->name, … … 176 168 bfwd, 177 169 type->clone(), 178 nullptr, // prevent infinite loop170 init, 179 171 attr, 180 172 Type::FuncSpecifiers( node->funcSpec.val ) 181 173 ); 182 183 // handles the case where node->init references itself 184 // xxx - does it really happen? 185 declWithTypePostamble(decl, node); 186 auto init = get<Initializer>().accept1( node->init ); 187 decl->init = init; 188 189 this->node = decl; 190 return nullptr; 174 return declWithTypePostamble( decl, node ); 191 175 } 192 176 … … 221 205 decl->statements = get<CompoundStmt>().accept1( node->stmts ); 222 206 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 223 if ( ast::dereferenceOperator == node ) {207 if ( dereferenceOperator == node ) { 224 208 Validate::dereferenceOperator = decl; 225 209 } 226 if ( ast::dtorStructDestroy == node ) {210 if ( dtorStructDestroy == node ) { 227 211 Validate::dtorStructDestroy = decl; 228 212 } … … 283 267 ); 284 268 285 if ( ast::dtorStruct == node ) {269 if ( dtorStruct == node ) { 286 270 Validate::dtorStruct = decl; 287 271 } … … 336 320 337 321 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 338 // force statements in old tree to be unique. 339 // cache.emplace( node, stmt ); 340 readonlyCache.emplace( node, stmt ); 322 cache.emplace( node, stmt ); 341 323 stmt->location = node->location; 342 324 stmt->labels = makeLabelL( stmt, node->labels ); … … 355 337 if ( inCache( node ) ) return nullptr; 356 338 auto stmt = new ExprStmt( nullptr ); 339 cache.emplace( node, stmt ); 357 340 stmt->expr = get<Expression>().accept1( node->expr ); 358 341 return stmtPostamble( stmt, node ); … … 1028 1011 auto stmts = node->stmts; 1029 1012 // disable sharing between multiple StmtExprs explicitly. 1030 // this should no longer be true. 1031 1013 if (inCache(stmts)) { 1014 stmts = ast::deepCopy(stmts.get()); 1015 } 1032 1016 auto rslt = new StmtExpr( 1033 1017 get<CompoundStmt>().accept1(stmts) … … 1036 1020 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 1037 1021 rslt->dtors = get<Expression>().acceptL(node->dtors); 1038 if (node->resultExpr) {1039 // this MUST be found by children visit1040 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));1041 }1042 1022 1043 1023 auto expr = visitBaseExpr( node, rslt ); … … 1056 1036 1057 1037 auto expr = visitBaseExpr( node, rslt ); 1058 this->node = expr ->clone();1038 this->node = expr; 1059 1039 return nullptr; 1060 1040 } … … 1146 1126 auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1147 1127 // I believe this should always be a BasicType. 1148 if ( ast::sizeType == node ) {1128 if ( sizeType == node ) { 1149 1129 Validate::SizeType = type; 1150 1130 } … … 1549 1529 1550 1530 // function type is now derived from parameter decls instead of storing them 1551 1552 /*1553 1531 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type)); 1554 1532 ftype->params.reserve(paramVars.size()); … … 1562 1540 } 1563 1541 ftype->forall = std::move(forall); 1564 */ 1565 1566 // can function type have attributes? seems not to be the case. 1567 // visitType(old->type, ftype); 1542 visitType(old->type, ftype); 1568 1543 1569 1544 auto decl = new ast::FunctionDecl{ … … 1571 1546 old->name, 1572 1547 // GET_ACCEPT_1(type, FunctionType), 1573 std::move(forall),1574 1548 std::move(paramVars), 1575 1549 std::move(returnVars), … … 1578 1552 { old->linkage.val }, 1579 1553 GET_ACCEPT_V(attributes, Attribute), 1580 { old->get_funcSpec().val }, 1581 old->type->isVarArgs 1554 { old->get_funcSpec().val } 1582 1555 }; 1583 1556 1584 //decl->type = ftype;1557 decl->type = ftype; 1585 1558 cache.emplace( old, decl ); 1586 1559 … … 1597 1570 1598 1571 if ( Validate::dereferenceOperator == old ) { 1599 ast::dereferenceOperator = decl;1572 dereferenceOperator = decl; 1600 1573 } 1601 1574 1602 1575 if ( Validate::dtorStructDestroy == old ) { 1603 ast::dtorStructDestroy = decl;1576 dtorStructDestroy = decl; 1604 1577 } 1605 1578 } … … 1626 1599 1627 1600 if ( Validate::dtorStruct == old ) { 1628 ast::dtorStruct = decl;1601 dtorStruct = decl; 1629 1602 } 1630 1603 } … … 2558 2531 // I believe this should always be a BasicType. 2559 2532 if ( Validate::SizeType == old ) { 2560 ast::sizeType = type;2533 sizeType = type; 2561 2534 } 2562 2535 visitType( old, type );
Note:
See TracChangeset
for help on using the changeset viewer.