Changeset eef8dfb for src/AST/Convert.cpp
- Timestamp:
- Jan 7, 2021, 2:55:57 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:
- 58fe85a
- Parents:
- bdfc032 (diff), 44e37ef (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
rbdfc032 reef8dfb 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 Dec 11 21:39:32 201913 // Update Count : 3 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Nov 12 10:07:00 2020 13 // Update Count : 34 14 14 // 15 15 … … 20 20 21 21 #include "AST/Attribute.hpp" 22 #include "AST/Copy.hpp" 22 23 #include "AST/Decl.hpp" 23 24 #include "AST/Expr.hpp" 24 25 #include "AST/Init.hpp" 25 26 #include "AST/Stmt.hpp" 27 #include "AST/TranslationUnit.hpp" 26 28 #include "AST/TypeSubstitution.hpp" 27 29 … … 46 48 47 49 //================================================================================================ 48 namespace {50 namespace ast { 49 51 50 52 // This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not) 51 53 // allow us to use the same stratagy in the new ast. 52 ast::Type * sizeType = nullptr; 53 ast::FunctionDecl * dereferenceOperator = nullptr; 54 ast::StructDecl * dtorStruct = nullptr; 55 ast::FunctionDecl * dtorStructDestroy = nullptr; 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; 56 61 57 62 } … … 62 67 using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >; 63 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; 64 74 65 75 template<typename T> … … 153 163 } 154 164 155 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 156 auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth ); 157 auto&& type = get<Type>().accept1( node->type ); 158 auto&& init = get<Initializer>().accept1( node->init ); 159 auto&& attr = get<Attribute>().acceptL( node->attributes ); 165 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 160 166 if ( inCache( node ) ) { 161 167 return nullptr; 162 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 163 173 auto decl = new ObjectDecl( 164 174 node->name, … … 166 176 LinkageSpec::Spec( node->linkage.val ), 167 177 bfwd, 168 type ,169 init,178 type->clone(), 179 nullptr, // prevent infinite loop 170 180 attr, 171 181 Type::FuncSpecifiers( node->funcSpec.val ) 172 182 ); 173 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; 174 192 } 175 193 176 194 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 177 195 if ( inCache( node ) ) return nullptr; 196 197 // function decl contains real variables that the type must use. 198 // the structural change means function type in and out of decl 199 // must be handled **differently** on convert back to old. 200 auto ftype = new FunctionType( 201 cv(node->type), 202 (bool)node->type->isVarArgs 203 ); 204 ftype->returnVals = get<DeclarationWithType>().acceptL(node->returns); 205 ftype->parameters = get<DeclarationWithType>().acceptL(node->params); 206 207 ftype->forall = get<TypeDecl>().acceptL( node->type_params ); 208 if (!node->assertions.empty()) { 209 assert(!ftype->forall.empty()); 210 // find somewhere to place assertions back, for convenience it is the last slot 211 ftype->forall.back()->assertions = get<DeclarationWithType>().acceptL(node->assertions); 212 } 213 214 visitType(node->type, ftype); 215 178 216 auto decl = new FunctionDecl( 179 217 node->name, 180 218 Type::StorageClasses( node->storage.val ), 181 219 LinkageSpec::Spec( node->linkage.val ), 182 get<FunctionType>().accept1( node->type ), 220 ftype, 221 //get<FunctionType>().accept1( node->type ), 183 222 {}, 184 223 get<Attribute>().acceptL( node->attributes ), … … 188 227 decl->statements = get<CompoundStmt>().accept1( node->stmts ); 189 228 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 190 if ( dereferenceOperator == node ) {229 if ( ast::dereferenceOperator == node ) { 191 230 Validate::dereferenceOperator = decl; 192 231 } 193 if ( dtorStructDestroy == node ) {232 if ( ast::dtorStructDestroy == node ) { 194 233 Validate::dtorStructDestroy = decl; 195 234 } … … 199 238 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 200 239 // base comes from constructor 201 decl->parameters = get<TypeDecl>().acceptL( node->params );202 240 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 203 241 declPostamble( decl, node ); … … 250 288 ); 251 289 252 if ( dtorStruct == node ) {290 if ( ast::dtorStruct == node ) { 253 291 Validate::dtorStruct = decl; 254 292 } … … 303 341 304 342 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 305 cache.emplace( node, stmt ); 343 // force statements in old tree to be unique. 344 // cache.emplace( node, stmt ); 345 readonlyCache.emplace( node, stmt ); 306 346 stmt->location = node->location; 307 347 stmt->labels = makeLabelL( stmt, node->labels ); … … 320 360 if ( inCache( node ) ) return nullptr; 321 361 auto stmt = new ExprStmt( nullptr ); 322 cache.emplace( node, stmt );323 362 stmt->expr = get<Expression>().accept1( node->expr ); 324 363 return stmtPostamble( stmt, node ); … … 493 532 } 494 533 534 const ast::Stmt * visit(const ast::SuspendStmt * node ) override final { 535 if ( inCache( node ) ) return nullptr; 536 auto stmt = new SuspendStmt(); 537 stmt->then = get<CompoundStmt>().accept1( node->then ); 538 switch(node->type) { 539 case ast::SuspendStmt::None : stmt->type = SuspendStmt::None ; break; 540 case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break; 541 case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break; 542 } 543 return stmtPostamble( stmt, node ); 544 } 545 495 546 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 496 547 if ( inCache( node ) ) return nullptr; … … 556 607 557 608 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 558 rslt->add( src_i->first ,609 rslt->add( src_i->first.typeString(), 559 610 get<Type>().accept1(src_i->second) ); 560 }561 562 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {563 rslt->addVar( src_i->first,564 get<Expression>().accept1(src_i->second) );565 611 } 566 612 … … 575 621 assert( tgtResnSlots.empty() ); 576 622 577 if ( srcInferred. mode == ast::Expr::InferUnion::Params ) {623 if ( srcInferred.data.inferParams ) { 578 624 const ast::InferredParams &srcParams = srcInferred.inferParams(); 579 625 for (auto & srcParam : srcParams) { … … 581 627 srcParam.second.decl, 582 628 get<Declaration>().accept1(srcParam.second.declptr), 583 get<Type>().accept1(srcParam.second.actualType) ,584 get<Type>().accept1(srcParam.second.formalType) ,585 get<Expression>().accept1(srcParam.second.expr) 629 get<Type>().accept1(srcParam.second.actualType)->clone(), 630 get<Type>().accept1(srcParam.second.formalType)->clone(), 631 get<Expression>().accept1(srcParam.second.expr)->clone() 586 632 )); 587 633 assert(res.second); 588 634 } 589 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) { 635 } 636 if ( srcInferred.data.resnSlots ) { 590 637 const ast::ResnSlots &srcSlots = srcInferred.resnSlots(); 591 638 for (auto srcSlot : srcSlots) { … … 608 655 609 656 tgt->result = get<Type>().accept1(src->result); 657 // Unconditionally use a clone of the result type. 658 // We know this will leak some objects: much of the immediate conversion result. 659 // In some cases, using the conversion result directly gives unintended object sharing. 660 // A parameter (ObjectDecl, a child of a FunctionType) is shared by the weak-ref cache. 661 // But tgt->result must be fully owned privately by tgt. 662 // Applying these conservative copies here means 663 // - weak references point at the declaration's copy, not these expr.result copies (good) 664 // - we copy more objects than really needed (bad, tolerated) 665 if (tgt->result) { 666 tgt->result = tgt->result->clone(); 667 } 610 668 return visitBaseExpr_skipResultType(src, tgt); 611 669 } … … 680 738 new KeywordCastExpr( 681 739 get<Expression>().accept1(node->arg), 682 castTarget 740 castTarget, 741 {node->concrete_target.field, node->concrete_target.getter} 683 742 ) 684 743 ); … … 967 1026 968 1027 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 1028 auto stmts = node->stmts; 1029 // disable sharing between multiple StmtExprs explicitly. 1030 // this should no longer be true. 1031 969 1032 auto rslt = new StmtExpr( 970 get<CompoundStmt>().accept1( node->stmts)1033 get<CompoundStmt>().accept1(stmts) 971 1034 ); 972 1035 973 1036 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 974 1037 rslt->dtors = get<Expression>().acceptL(node->dtors); 1038 if (node->resultExpr) { 1039 // this MUST be found by children visit 1040 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr)); 1041 } 975 1042 976 1043 auto expr = visitBaseExpr( node, rslt ); … … 989 1056 990 1057 auto expr = visitBaseExpr( node, rslt ); 991 this->node = expr ;1058 this->node = expr->clone(); 992 1059 return nullptr; 993 1060 } … … 1079 1146 auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind }; 1080 1147 // I believe this should always be a BasicType. 1081 if ( sizeType == node ) {1148 if ( ast::sizeType == node ) { 1082 1149 Validate::SizeType = type; 1083 1150 } … … 1121 1188 1122 1189 const ast::Type * visit( const ast::FunctionType * node ) override final { 1190 static std::string dummy_paramvar_prefix = "__param_"; 1191 static std::string dummy_returnvar_prefix = "__retval_"; 1192 1123 1193 auto ty = new FunctionType { 1124 1194 cv( node ), 1125 1195 (bool)node->isVarArgs 1126 1196 }; 1127 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1128 ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1129 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1197 auto returns = get<Type>().acceptL(node->returns); 1198 auto params = get<Type>().acceptL(node->params); 1199 1200 int ret_index = 0; 1201 for (auto t: returns) { 1202 // xxx - LinkageSpec shouldn't matter but needs to be something 1203 ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr); 1204 ty->returnVals.push_back(dummy); 1205 } 1206 int param_index = 0; 1207 for (auto t: params) { 1208 ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr); 1209 ty->parameters.push_back(dummy); 1210 } 1211 1212 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1213 // ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1214 1215 auto types = get<TypeInstType>().acceptL( node->forall ); 1216 for (auto t : types) { 1217 auto newT = new TypeDecl(*t->baseType); 1218 newT->name = t->name; // converted by typeString() 1219 for (auto asst : newT->assertions) delete asst; 1220 newT->assertions.clear(); 1221 ty->forall.push_back(newT); 1222 } 1223 auto assts = get<VariableExpr>().acceptL( node->assertions ); 1224 if (!assts.empty()) { 1225 assert(!types.empty()); 1226 for (auto asst : assts) { 1227 auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var)); 1228 delete newDecl->type; 1229 newDecl->type = asst->result->clone(); 1230 newDecl->storageClasses.is_extern = true; // hack 1231 ty->forall.back()->assertions.push_back(newDecl); 1232 } 1233 } 1234 1130 1235 return visitType( node, ty ); 1131 1236 } 1132 1237 1133 const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) { 1134 ty->forall = get<TypeDecl>().acceptL( old->forall ); 1238 const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) { 1135 1239 ty->parameters = get<Expression>().acceptL( old->params ); 1136 1240 ty->hoistType = old->hoistType; … … 1215 1319 ty = new TypeInstType{ 1216 1320 cv( node ), 1217 node-> name,1321 node->typeString(), 1218 1322 get<TypeDecl>().accept1( node->base ), 1219 1323 get<Attribute>().acceptL( node->attributes ) … … 1222 1326 ty = new TypeInstType{ 1223 1327 cv( node ), 1224 node-> name,1328 node->typeString(), 1225 1329 node->kind == ast::TypeDecl::Ftype, 1226 1330 get<Attribute>().acceptL( node->attributes ) … … 1319 1423 }; 1320 1424 1321 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > >&& translationUnit ) {1425 std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) { 1322 1426 ConverterNewToOld c; 1323 1427 std::list< Declaration * > decls; 1324 for(auto d : translationUnit ) {1428 for(auto d : translationUnit.decls) { 1325 1429 decls.emplace_back( c.decl( d ) ); 1326 1430 } … … 1343 1447 ast::Node * node = nullptr; 1344 1448 /// cache of nodes that might be referenced by readonly<> for de-duplication 1345 std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {}; 1449 /// in case that some nodes are dropped by conversion (due to possible structural change) 1450 /// use smart pointers in cache value to prevent accidental invalidation. 1451 /// at conversion stage, all created nodes are guaranteed to be unique, therefore 1452 /// const_casting out of smart pointers is permitted. 1453 std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {}; 1346 1454 1347 1455 // Local Utilities: … … 1416 1524 auto it = cache.find( old ); 1417 1525 if ( it == cache.end() ) return false; 1418 node = it->second;1526 node = const_cast<ast::Node *>(it->second.get()); 1419 1527 return true; 1420 1528 } … … 1455 1563 virtual void visit( const FunctionDecl * old ) override final { 1456 1564 if ( inCache( old ) ) return; 1565 auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType); 1566 auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType); 1567 auto forall = GET_ACCEPT_V(type->forall, TypeDecl); 1568 1569 // function type is now derived from parameter decls instead of storing them 1570 1571 /* 1572 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type)); 1573 ftype->params.reserve(paramVars.size()); 1574 ftype->returns.reserve(returnVars.size()); 1575 1576 for (auto & v: paramVars) { 1577 ftype->params.emplace_back(v->get_type()); 1578 } 1579 for (auto & v: returnVars) { 1580 ftype->returns.emplace_back(v->get_type()); 1581 } 1582 ftype->forall = std::move(forall); 1583 */ 1584 1585 // can function type have attributes? seems not to be the case. 1586 // visitType(old->type, ftype); 1587 1588 // collect assertions and put directly in FunctionDecl 1589 std::vector<ast::ptr<ast::DeclWithType>> assertions; 1590 for (auto & param: forall) { 1591 for (auto & asst: param->assertions) { 1592 assertf(asst->unique(), "newly converted decl must be unique"); 1593 assertions.emplace_back(asst); 1594 } 1595 auto mut = param.get_and_mutate(); 1596 assertf(mut == param, "newly converted decl must be unique"); 1597 mut->assertions.clear(); 1598 } 1599 1457 1600 auto decl = new ast::FunctionDecl{ 1458 1601 old->location, 1459 1602 old->name, 1460 GET_ACCEPT_1(type, FunctionType), 1603 // GET_ACCEPT_1(type, FunctionType), 1604 std::move(forall), 1605 std::move(paramVars), 1606 std::move(returnVars), 1461 1607 {}, 1462 1608 { old->storageClasses.val }, 1463 1609 { old->linkage.val }, 1464 1610 GET_ACCEPT_V(attributes, Attribute), 1465 { old->get_funcSpec().val } 1611 { old->get_funcSpec().val }, 1612 old->type->isVarArgs 1466 1613 }; 1614 1615 // decl->type = ftype; 1467 1616 cache.emplace( old, decl ); 1617 1618 decl->assertions = std::move(assertions); 1468 1619 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1469 1620 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); … … 1478 1629 1479 1630 if ( Validate::dereferenceOperator == old ) { 1480 dereferenceOperator = decl;1631 ast::dereferenceOperator = decl; 1481 1632 } 1482 1633 1483 1634 if ( Validate::dtorStructDestroy == old ) { 1484 dtorStructDestroy = decl;1635 ast::dtorStructDestroy = decl; 1485 1636 } 1486 1637 } … … 1507 1658 1508 1659 if ( Validate::dtorStruct == old ) { 1509 dtorStruct = decl;1660 ast::dtorStruct = decl; 1510 1661 } 1511 1662 } … … 1584 1735 cache.emplace( old, decl ); 1585 1736 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1586 decl->params = GET_ACCEPT_V(parameters, TypeDecl);1587 1737 decl->extension = old->extension; 1588 1738 decl->uniqueId = old->uniqueId; … … 1600 1750 ); 1601 1751 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1602 decl->params = GET_ACCEPT_V(parameters, TypeDecl);1603 1752 decl->extension = old->extension; 1604 1753 decl->uniqueId = old->uniqueId; … … 1859 2008 } 1860 2009 2010 virtual void visit( const SuspendStmt * old ) override final { 2011 if ( inCache( old ) ) return; 2012 ast::SuspendStmt::Type type; 2013 switch (old->type) { 2014 case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break; 2015 case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break; 2016 case SuspendStmt::None : type = ast::SuspendStmt::None ; break; 2017 default: abort(); 2018 } 2019 this->node = new ast::SuspendStmt( 2020 old->location, 2021 GET_ACCEPT_1(then , CompoundStmt), 2022 type, 2023 GET_LABELS_V(old->labels) 2024 ); 2025 cache.emplace( old, this->node ); 2026 } 2027 1861 2028 virtual void visit( const WaitForStmt * old ) override final { 1862 2029 if ( inCache( old ) ) return; … … 1932 2099 } 1933 2100 2101 // TypeSubstitution shouldn't exist yet in old. 1934 2102 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { 1935 2103 1936 2104 if (!old) return nullptr; 1937 2105 if (old->empty()) return nullptr; 2106 assert(false); 2107 2108 /* 1938 2109 ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); 1939 2110 … … 1943 2114 } 1944 2115 1945 for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {1946 rslt->addVar( old_i->first,1947 getAccept1<ast::Expr>(old_i->second) );1948 }1949 1950 2116 return rslt; 2117 */ 1951 2118 } 1952 2119 … … 1956 2123 1957 2124 assert( oldInferParams.empty() || oldResnSlots.empty() ); 1958 assert( newInferred.mode == ast::Expr::InferUnion::Empty );2125 // assert( newInferred.mode == ast::Expr::InferUnion::Empty ); 1959 2126 1960 2127 if ( !oldInferParams.empty() ) { … … 2039 2206 old->location, 2040 2207 GET_ACCEPT_1(arg, Expr), 2041 castTarget 2208 castTarget, 2209 {old->concrete_target.field, old->concrete_target.getter} 2042 2210 ) 2043 2211 ); … … 2087 2255 old->location, 2088 2256 GET_ACCEPT_1(member, DeclWithType), 2089 GET_ACCEPT_1(aggregate, Expr) 2257 GET_ACCEPT_1(aggregate, Expr), 2258 ast::MemberExpr::NoOpConstructionChosen 2090 2259 ) 2091 2260 ); … … 2419 2588 // I believe this should always be a BasicType. 2420 2589 if ( Validate::SizeType == old ) { 2421 sizeType = type;2590 ast::sizeType = type; 2422 2591 } 2423 2592 visitType( old, type ); … … 2464 2633 cv( old ) 2465 2634 }; 2466 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2467 ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2468 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2635 auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType); 2636 auto paramVars = GET_ACCEPT_V(parameters, DeclWithType); 2637 // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType ); 2638 // ty->params = GET_ACCEPT_V( parameters, DeclWithType ); 2639 for (auto & v: returnVars) { 2640 ty->returns.emplace_back(v->get_type()); 2641 } 2642 for (auto & v: paramVars) { 2643 ty->params.emplace_back(v->get_type()); 2644 } 2645 // xxx - when will this be non-null? 2646 // will have to create dangling (no-owner) decls to be pointed to 2647 auto foralls = GET_ACCEPT_V( forall, TypeDecl ); 2648 2649 for (auto & param : foralls) { 2650 ty->forall.emplace_back(new ast::TypeInstType(param->name, param)); 2651 for (auto asst : param->assertions) { 2652 ty->assertions.emplace_back(new ast::VariableExpr({}, asst)); 2653 } 2654 } 2469 2655 visitType( old, ty ); 2470 2656 } 2471 2657 2472 void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) { 2473 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2658 void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) { 2474 2659 ty->params = GET_ACCEPT_V( parameters, Expr ); 2475 2660 ty->hoistType = old->hoistType; … … 2616 2801 old->location, 2617 2802 GET_ACCEPT_1(value, Expr), 2618 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast:: DoConstruct2803 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct 2619 2804 ); 2620 2805 } … … 2625 2810 GET_ACCEPT_V(initializers, Init), 2626 2811 GET_ACCEPT_V(designations, Designation), 2627 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast:: DoConstruct2812 (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct 2628 2813 ); 2629 2814 } … … 2656 2841 #undef GET_ACCEPT_1 2657 2842 2658 std::list< ast::ptr< ast::Decl > >convert( const std::list< Declaration * > && translationUnit ) {2843 ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) { 2659 2844 ConverterOldToNew c; 2660 std::list< ast::ptr< ast::Decl > > decls; 2845 ast::TranslationUnit unit; 2846 if (Validate::SizeType) { 2847 // this should be a BasicType. 2848 auto old = strict_dynamic_cast<BasicType *>(Validate::SizeType); 2849 ast::sizeType = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind }; 2850 } 2851 2661 2852 for(auto d : translationUnit) { 2662 2853 d->accept( c ); 2663 decls.emplace_back( c.decl() );2854 unit.decls.emplace_back( c.decl() ); 2664 2855 } 2665 2856 deleteAll(translationUnit); 2666 return decls; 2857 2858 // Load the local static varables into the global store. 2859 unit.global.sizeType = ast::sizeType; 2860 unit.global.dereference = ast::dereferenceOperator; 2861 unit.global.dtorStruct = ast::dtorStruct; 2862 unit.global.dtorDestroy = ast::dtorStructDestroy; 2863 2864 return unit; 2667 2865 }
Note:
See TracChangeset
for help on using the changeset viewer.