Changeset 3e5dd913 for src/AST/Convert.cpp
- Timestamp:
- Dec 16, 2020, 2:43:12 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 53449a4
- Parents:
- 13fece5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r13fece5 r3e5dd913 205 205 ftype->parameters = get<DeclarationWithType>().acceptL(node->params); 206 206 207 ftype->forall = get<TypeDecl>().acceptL( node->type->forall ); 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 } 208 213 209 214 visitType(node->type, ftype); … … 602 607 603 608 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) { 604 rslt->add( src_i->first ,609 rslt->add( src_i->first.typeString(), 605 610 get<Type>().accept1(src_i->second) ); 606 }607 608 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {609 rslt->addVar( src_i->first,610 get<Expression>().accept1(src_i->second) );611 611 } 612 612 … … 1212 1212 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns ); 1213 1213 // ty->parameters = get<DeclarationWithType>().acceptL( node->params ); 1214 ty->forall = get<TypeDecl>().acceptL( node->forall ); 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 1235 return visitType( node, ty ); 1216 1236 } … … 1299 1319 ty = new TypeInstType{ 1300 1320 cv( node ), 1301 node-> name,1321 node->typeString(), 1302 1322 get<TypeDecl>().accept1( node->base ), 1303 1323 get<Attribute>().acceptL( node->attributes ) … … 1306 1326 ty = new TypeInstType{ 1307 1327 cv( node ), 1308 node-> name,1328 node->typeString(), 1309 1329 node->kind == ast::TypeDecl::Ftype, 1310 1330 get<Attribute>().acceptL( node->attributes ) … … 1431 1451 /// at conversion stage, all created nodes are guaranteed to be unique, therefore 1432 1452 /// const_casting out of smart pointers is permitted. 1433 std::unordered_map< const BaseSyntaxNode *, ast:: ptr<ast::Node> > cache = {};1453 std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {}; 1434 1454 1435 1455 // Local Utilities: … … 1565 1585 // can function type have attributes? seems not to be the case. 1566 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 } 1567 1599 1568 1600 auto decl = new ast::FunctionDecl{ … … 1584 1616 cache.emplace( old, decl ); 1585 1617 1618 decl->assertions = std::move(assertions); 1586 1619 decl->withExprs = GET_ACCEPT_V(withExprs, Expr); 1587 1620 decl->stmts = GET_ACCEPT_1(statements, CompoundStmt); … … 2066 2099 } 2067 2100 2101 // TypeSubstitution shouldn't exist yet in old. 2068 2102 ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) { 2069 2103 2070 2104 if (!old) return nullptr; 2071 2105 if (old->empty()) return nullptr; 2106 assert(false); 2107 2108 /* 2072 2109 ast::TypeSubstitution *rslt = new ast::TypeSubstitution(); 2073 2110 … … 2077 2114 } 2078 2115 2079 for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {2080 rslt->addVar( old_i->first,2081 getAccept1<ast::Expr>(old_i->second) );2082 }2083 2084 2116 return rslt; 2117 */ 2085 2118 } 2086 2119 … … 2610 2643 ty->params.emplace_back(v->get_type()); 2611 2644 } 2612 ty->forall = GET_ACCEPT_V( forall, TypeDecl ); 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 } 2613 2655 visitType( old, ty ); 2614 2656 }
Note: See TracChangeset
for help on using the changeset viewer.