Changeset 19e567dd
- Timestamp:
- May 21, 2019, 12:48:18 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 51ff278, 5b35c21
- Parents:
- 292642a
- Location:
- src/AST
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r292642a r19e567dd 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 414 469 const ast::Expr * visit( const ast::ApplicationExpr * node ) override final { 415 (void)node; 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; 416 477 return nullptr; 417 478 } 418 479 419 480 const ast::Expr * visit( const ast::UntypedExpr * node ) override final { 420 (void)node; 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; 421 488 return nullptr; 422 489 } 423 490 424 491 const ast::Expr * visit( const ast::NameExpr * node ) override final { 425 (void)node; 492 auto expr = visitBaseExpr( node, 493 new NameExpr( 494 node->name 495 ) 496 ); 497 this->node = expr; 426 498 return nullptr; 427 499 } … … 1184 1256 getAccept1<ast::Expr>(old_i->second) ); 1185 1257 } 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 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 } 1195 1285 } 1196 1286 … … 1206 1296 } 1207 1297 1208 virtual void visit( ApplicationExpr * ) override final { 1209 // TODO 1210 } 1211 1212 virtual void visit( UntypedExpr * ) override final { 1213 // TODO 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 ); 1214 1316 } 1215 1317 … … 1223 1325 } 1224 1326 1225 virtual void visit( CastExpr * ) override final { 1226 // TODO ... (rest) 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 ); 1227 1335 } 1228 1336 -
src/AST/Expr.hpp
r292642a r19e567dd 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); 108 117 } 109 118 … … 114 123 case Params: return data.inferParams; 115 124 } 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); 116 134 } 117 135 };
Note: See TracChangeset
for help on using the changeset viewer.