Changes in src/AST/Convert.cpp [3e5dd913:23954b6]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r3e5dd913 r23954b6 55 55 56 56 // these need to be accessed in new FixInit now 57 ast:: ptr<ast::Type>sizeType = nullptr;58 constast::FunctionDecl * dereferenceOperator = nullptr;59 constast::StructDecl * dtorStruct = nullptr;60 constast::FunctionDecl * dtorStructDestroy = nullptr;57 ast::Type * sizeType = nullptr; 58 ast::FunctionDecl * dereferenceOperator = nullptr; 59 ast::StructDecl * dtorStruct = nullptr; 60 ast::FunctionDecl * dtorStructDestroy = nullptr; 61 61 62 62 } … … 205 205 ftype->parameters = get<DeclarationWithType>().acceptL(node->params); 206 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 } 207 ftype->forall = get<TypeDecl>().acceptL( node->type->forall ); 213 208 214 209 visitType(node->type, ftype); … … 238 233 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 239 234 // base comes from constructor 235 decl->parameters = get<TypeDecl>().acceptL( node->params ); 240 236 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 241 237 declPostamble( decl, node ); … … 607 603 608 604 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 609 rslt->add( src_i->first .typeString(),605 rslt->add( src_i->first, 610 606 get<Type>().accept1(src_i->second) ); 607 } 608 609 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) { 610 rslt->addVar( src_i->first, 611 get<Expression>().accept1(src_i->second) ); 611 612 } 612 613 … … 1212 1213 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1213 1214 // 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 1215 ty->forall = get<TypeDecl>().acceptL( node->forall ); 1235 1216 return visitType( node, ty ); 1236 1217 } 1237 1218 1238 1219 const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) { 1220 ty->forall = get<TypeDecl>().acceptL( old->forall ); 1239 1221 ty->parameters = get<Expression>().acceptL( old->params ); 1240 1222 ty->hoistType = old->hoistType; … … 1319 1301 ty = new TypeInstType{ 1320 1302 cv( node ), 1321 node-> typeString(),1303 node->name, 1322 1304 get<TypeDecl>().accept1( node->base ), 1323 1305 get<Attribute>().acceptL( node->attributes ) … … 1326 1308 ty = new TypeInstType{ 1327 1309 cv( node ), 1328 node-> typeString(),1310 node->name, 1329 1311 node->kind == ast::TypeDecl::Ftype, 1330 1312 get<Attribute>().acceptL( node->attributes ) … … 1451 1433 /// at conversion stage, all created nodes are guaranteed to be unique, therefore 1452 1434 /// const_casting out of smart pointers is permitted. 1453 std::unordered_map< const BaseSyntaxNode *, ast:: readonly<ast::Node> > cache = {};1435 std::unordered_map< const BaseSyntaxNode *, ast::ptr<ast::Node> > cache = {}; 1454 1436 1455 1437 // Local Utilities: … … 1585 1567 // can function type have attributes? seems not to be the case. 1586 1568 // visitType(old->type, ftype); 1587 1588 // collect assertions and put directly in FunctionDecl1589 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 1569 1600 1570 auto decl = new ast::FunctionDecl{ … … 1616 1586 cache.emplace( old, decl ); 1617 1587 1618 decl->assertions = std::move(assertions);1619 1588 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1620 1589 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); … … 1735 1704 cache.emplace( old, decl ); 1736 1705 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1706 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1737 1707 decl->extension = old->extension; 1738 1708 decl->uniqueId = old->uniqueId; … … 1750 1720 ); 1751 1721 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1722 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1752 1723 decl->extension = old->extension; 1753 1724 decl->uniqueId = old->uniqueId; … … 2099 2070 } 2100 2071 2101 // TypeSubstitution shouldn't exist yet in old.2102 2072 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { 2103 2073 2104 2074 if (!old) return nullptr; 2105 if (old->empty()) return nullptr; 2106 assert(false); 2107 2108 /* 2075 2109 2076 ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); 2110 2077 … … 2114 2081 } 2115 2082 2083 for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) { 2084 rslt->addVar( old_i->first, 2085 getAccept1<ast::Expr>(old_i->second) ); 2086 } 2087 2116 2088 return rslt; 2117 */2118 2089 } 2119 2090 … … 2643 2614 ty->params.emplace_back(v->get_type()); 2644 2615 } 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 } 2616 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2655 2617 visitType( old, ty ); 2656 2618 } 2657 2619 2658 2620 void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) { 2621 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 2659 2622 ty->params = GET_ACCEPT_V( parameters, Expr ); 2660 2623 ty->hoistType = old->hoistType; … … 2844 2807 ConverterOldToNew c; 2845 2808 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 2852 2809 for(auto d : translationUnit) { 2853 2810 d->accept( c );
Note:
See TracChangeset
for help on using the changeset viewer.