Changes in / [5b35c21:e63326b]
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r5b35c21 re63326b 412 412 } 413 413 414 TypeSubstitution * convertTypeSubstitution(const ast::TypeSubstitution * src) {415 416 TypeSubstitution *rslt = new TypeSubstitution();417 418 for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {419 rslt->add( src_i->first,420 get<Type>().accept1(src_i->second) );421 }422 423 for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {424 rslt->addVar( src_i->first,425 get<Expression>().accept1(src_i->second) );426 }427 428 return rslt;429 }430 431 void convertInferUnion(std::map<UniqueId,ParamEntry> &tgtInferParams,432 std::vector<UniqueId> &tgtResnSlots,433 const ast::Expr::InferUnion &srcInferred ) {434 435 assert( tgtInferParams.empty() );436 assert( tgtResnSlots.empty() );437 438 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {439 const ast::InferredParams &srcParams = srcInferred.inferParamsConst();440 for (auto srcParam : srcParams) {441 tgtInferParams[srcParam.first] = ParamEntry(442 srcParam.second.decl,443 get<Type>().accept1(srcParam.second.actualType),444 get<Type>().accept1(srcParam.second.formalType),445 get<Expression>().accept1(srcParam.second.expr)446 );447 }448 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots ) {449 const ast::ResnSlots &srcSlots = srcInferred.resnSlotsConst();450 for (auto srcSlot : srcSlots) {451 tgtResnSlots.push_back(srcSlot);452 }453 }454 }455 456 Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {457 458 tgt->location = src->location;459 460 tgt->result = get<Type>().accept1(src->result);461 tgt->env = convertTypeSubstitution(src->env);462 463 tgt->extension = src->extension;464 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);465 466 return tgt;467 }468 469 414 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 470 auto expr = visitBaseExpr( node, 471 new ApplicationExpr( 472 get<Expression>().accept1(node->func), 473 get<Expression>().acceptL(node->args) 474 ) 475 ); 476 this->node = expr; 415 (void)node; 477 416 return nullptr; 478 417 } 479 418 480 419 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 481 auto expr = visitBaseExpr( node, 482 new UntypedExpr( 483 get<Expression>().accept1(node->func), 484 get<Expression>().acceptL(node->args) 485 ) 486 ); 487 this->node = expr; 420 (void)node; 488 421 return nullptr; 489 422 } 490 423 491 424 const ast::Expr * visit( const ast::NameExpr * node ) override final { 492 auto expr = visitBaseExpr( node, 493 new NameExpr( 494 node->name 495 ) 496 ); 497 this->node = expr; 425 (void)node; 498 426 return nullptr; 499 427 } … … 1256 1184 getAccept1<ast::Expr>(old_i->second) ); 1257 1185 } 1258 1259 return rslt; 1260 } 1261 1262 void convertInferUnion(ast::Expr::InferUnion &newInferred, 1263 const std::map<UniqueId,ParamEntry> &oldInferParams, 1264 const std::vector<UniqueId> &oldResnSlots) { 1265 1266 assert( oldInferParams.empty() || oldResnSlots.empty() ); 1267 assert( newInferred.mode == ast::Expr::InferUnion::Empty ); 1268 1269 if ( !oldInferParams.empty() ) { 1270 ast::InferredParams &tgt = newInferred.inferParams(); 1271 for (auto old : oldInferParams) { 1272 tgt[old.first] = ast::ParamEntry( 1273 old.second.decl, 1274 getAccept1<ast::Type>(old.second.actualType), 1275 getAccept1<ast::Type>(old.second.formalType), 1276 getAccept1<ast::Expr>(old.second.expr) 1277 ); 1278 } 1279 } else if ( !oldResnSlots.empty() ) { 1280 ast::ResnSlots &tgt = newInferred.resnSlots(); 1281 for (auto old : oldResnSlots) { 1282 tgt.push_back(old); 1283 } 1284 } 1186 } 1187 1188 void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) { 1189 1190 (void) nwInferred; 1191 (void) oldInferParams; 1192 (void) oldResnSlots; 1193 1194 // TODO 1285 1195 } 1286 1196 … … 1296 1206 } 1297 1207 1298 virtual void visit( ApplicationExpr * old ) override final { 1299 this->node = visitBaseExpr( old, 1300 new ast::ApplicationExpr( 1301 old->location, 1302 GET_ACCEPT_1(function, Expr), 1303 GET_ACCEPT_V(args, Expr) 1304 ) 1305 ); 1306 } 1307 1308 virtual void visit( UntypedExpr * old ) override final { 1309 this->node = visitBaseExpr( old, 1310 new ast::UntypedExpr( 1311 old->location, 1312 GET_ACCEPT_1(function, Expr), 1313 GET_ACCEPT_V(args, Expr) 1314 ) 1315 ); 1208 virtual void visit( ApplicationExpr * ) override final { 1209 // TODO 1210 } 1211 1212 virtual void visit( UntypedExpr * ) override final { 1213 // TODO 1316 1214 } 1317 1215 … … 1325 1223 } 1326 1224 1327 virtual void visit( CastExpr * old ) override final { 1328 this->node = visitBaseExpr( old, 1329 new ast::CastExpr( 1330 old->location, 1331 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr 1332 old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast 1333 ) 1334 ); 1225 virtual void visit( CastExpr * ) override final { 1226 // TODO ... (rest) 1335 1227 } 1336 1228 -
src/AST/Expr.hpp
r5b35c21 re63326b 106 106 case Params: assert(!"Cannot return to resnSlots from Params"); 107 107 } 108 return *((ResnSlots*)nullptr);109 }110 111 const ResnSlots& resnSlotsConst() const {112 if (mode == Slots) {113 return data.resnSlots;114 }115 assert(!"Mode was not already resnSlots");116 return *((ResnSlots*)nullptr);117 108 } 118 109 … … 123 114 case Params: return data.inferParams; 124 115 } 125 return *((InferredParams*)nullptr);126 }127 128 const InferredParams& inferParamsConst() const {129 if (mode == Params) {130 return data.inferParams;131 }132 assert(!"Mode was not already Params");133 return *((InferredParams*)nullptr);134 116 } 135 117 };
Note: See TracChangeset
for help on using the changeset viewer.