Changeset 3bc69f2 for src/ResolvExpr
- Timestamp:
- Mar 18, 2022, 10:53:38 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 22226e4
- Parents:
- f7496c5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
rf7496c5 r3bc69f2 10 10 // Created On : Sun May 17 12:17:01 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Mar 16 16:07:00 202213 // Update Count : 24 612 // Last Modified On : Fri Mar 18 10:41:00 2022 13 // Update Count : 247 14 14 // 15 15 … … 1245 1245 : public ast::WithSymbolTable, public ast::WithGuards, 1246 1246 public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting, 1247 public ast::WithStmtsToAdd<> , public ast::WithConstTranslationUnit{1247 public ast::WithStmtsToAdd<> { 1248 1248 1249 1249 ast::ptr< ast::Type > functionReturn = nullptr; … … 1251 1251 // for work previously in GenInit 1252 1252 static InitTweak::ManagedTypes_new managedTypes; 1253 ResolveContext context; 1253 1254 1254 1255 bool inEnumDecl = false; 1255 1256 ResolveContext getContext() const {1257 return ResolveContext{ symtab, transUnit().global };1258 }1259 1256 1260 1257 public: 1261 1258 static size_t traceId; 1262 Resolver_new() = default; 1263 Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; } 1259 Resolver_new( const ast::TranslationGlobal & global ) : 1260 context{ symtab, global } {} 1261 Resolver_new( const ResolveContext & context ) : 1262 ast::WithSymbolTable{ context.symtab }, 1263 context{ symtab, context.global } {} 1264 1264 1265 1265 const ast::FunctionDecl * previsit( const ast::FunctionDecl * ); … … 1278 1278 const ast::AsmStmt * previsit( const ast::AsmStmt * ); 1279 1279 const ast::IfStmt * previsit( const ast::IfStmt * ); 1280 const ast::WhileDoStmt * 1280 const ast::WhileDoStmt * previsit( const ast::WhileDoStmt * ); 1281 1281 const ast::ForStmt * previsit( const ast::ForStmt * ); 1282 1282 const ast::SwitchStmt * previsit( const ast::SwitchStmt * ); … … 1305 1305 1306 1306 void resolve( ast::TranslationUnit& translationUnit ) { 1307 ast::Pass< Resolver_new >::run( translationUnit );1307 ast::Pass< Resolver_new >::run( translationUnit, translationUnit.global ); 1308 1308 } 1309 1309 … … 1312 1312 ) { 1313 1313 assert( ctorInit ); 1314 ast::Pass< Resolver_new > resolver{ context.symtab }; 1315 ast::TranslationUnit transUnit; 1316 transUnit.global = context.global; 1317 resolver.core.translationUnit = &transUnit; 1314 ast::Pass< Resolver_new > resolver( context ); 1318 1315 return ctorInit->accept( resolver ); 1319 1316 } … … 1323 1320 ) { 1324 1321 assert( stmtExpr ); 1325 ast::Pass< Resolver_new > resolver{ context.symtab }; 1326 ast::TranslationUnit transUnit; 1327 transUnit.global = context.global; 1328 resolver.core.translationUnit = &transUnit; 1322 ast::Pass< Resolver_new > resolver( context ); 1329 1323 auto ret = mutate(stmtExpr->accept(resolver)); 1330 1324 strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult(); … … 1381 1375 1382 1376 for (auto & attr: mutDecl->attributes) { 1383 attr = handleAttribute(mutDecl->location, attr, getContext());1377 attr = handleAttribute(mutDecl->location, attr, context ); 1384 1378 } 1385 1379 … … 1394 1388 } 1395 1389 for (auto & asst : mutDecl->assertions) { 1396 asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), getContext());1390 asst = fixObjectType(asst.strict_as<ast::ObjectDecl>(), context); 1397 1391 symtab.addId(asst); 1398 1392 mutType->assertions.emplace_back(new ast::VariableExpr(functionDecl->location, asst)); … … 1406 1400 1407 1401 for (auto & param : mutDecl->params) { 1408 param = fixObjectType(param.strict_as<ast::ObjectDecl>(), getContext());1402 param = fixObjectType(param.strict_as<ast::ObjectDecl>(), context); 1409 1403 symtab.addId(param); 1410 1404 paramTypes.emplace_back(param->get_type()); 1411 1405 } 1412 1406 for (auto & ret : mutDecl->returns) { 1413 ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), getContext());1407 ret = fixObjectType(ret.strict_as<ast::ObjectDecl>(), context); 1414 1408 returnTypes.emplace_back(ret->get_type()); 1415 1409 } … … 1482 1476 // enumerator initializers should not use the enum type to initialize, since the 1483 1477 // enum type is still incomplete at this point. Use `int` instead. 1484 objectDecl = fixObjectType(objectDecl, getContext());1478 objectDecl = fixObjectType(objectDecl, context); 1485 1479 currentObject = ast::CurrentObject{ 1486 1480 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } }; … … 1488 1482 else { 1489 1483 if (!objectDecl->isTypeFixed) { 1490 auto newDecl = fixObjectType(objectDecl, getContext());1484 auto newDecl = fixObjectType(objectDecl, context); 1491 1485 auto mutDecl = mutate(newDecl); 1492 1486 … … 1519 1513 // nested type decls are hoisted already. no need to do anything 1520 1514 if (auto obj = member.as<ast::ObjectDecl>()) { 1521 member = fixObjectType(obj, getContext());1515 member = fixObjectType(obj, context); 1522 1516 } 1523 1517 } … … 1542 1536 return ast::mutate_field( 1543 1537 assertDecl, &ast::StaticAssertDecl::cond, 1544 findIntegralExpression( assertDecl->cond, getContext()) );1538 findIntegralExpression( assertDecl->cond, context ) ); 1545 1539 } 1546 1540 … … 1557 1551 1558 1552 const ast::ArrayType * Resolver_new::previsit( const ast::ArrayType * at ) { 1559 return handlePtrType( at, getContext());1553 return handlePtrType( at, context ); 1560 1554 } 1561 1555 1562 1556 const ast::PointerType * Resolver_new::previsit( const ast::PointerType * pt ) { 1563 return handlePtrType( pt, getContext());1557 return handlePtrType( pt, context ); 1564 1558 } 1565 1559 … … 1569 1563 1570 1564 return ast::mutate_field( 1571 exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, getContext()) );1565 exprStmt, &ast::ExprStmt::expr, findVoidExpression( exprStmt->expr, context ) ); 1572 1566 } 1573 1567 … … 1576 1570 1577 1571 asmExpr = ast::mutate_field( 1578 asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, getContext()) );1572 asmExpr, &ast::AsmExpr::operand, findVoidExpression( asmExpr->operand, context ) ); 1579 1573 1580 1574 return asmExpr; … … 1590 1584 const ast::IfStmt * Resolver_new::previsit( const ast::IfStmt * ifStmt ) { 1591 1585 return ast::mutate_field( 1592 ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, getContext()) );1586 ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) ); 1593 1587 } 1594 1588 1595 1589 const ast::WhileDoStmt * Resolver_new::previsit( const ast::WhileDoStmt * whileDoStmt ) { 1596 1590 return ast::mutate_field( 1597 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, getContext()) );1591 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) ); 1598 1592 } 1599 1593 … … 1601 1595 if ( forStmt->cond ) { 1602 1596 forStmt = ast::mutate_field( 1603 forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, getContext()) );1597 forStmt, &ast::ForStmt::cond, findIntegralExpression( forStmt->cond, context ) ); 1604 1598 } 1605 1599 1606 1600 if ( forStmt->inc ) { 1607 1601 forStmt = ast::mutate_field( 1608 forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, getContext()) );1602 forStmt, &ast::ForStmt::inc, findVoidExpression( forStmt->inc, context ) ); 1609 1603 } 1610 1604 … … 1616 1610 switchStmt = ast::mutate_field( 1617 1611 switchStmt, &ast::SwitchStmt::cond, 1618 findIntegralExpression( switchStmt->cond, getContext()) );1612 findIntegralExpression( switchStmt->cond, context ) ); 1619 1613 currentObject = ast::CurrentObject{ switchStmt->location, switchStmt->cond->result }; 1620 1614 return switchStmt; … … 1629 1623 ast::ptr< ast::Expr > untyped = 1630 1624 new ast::CastExpr{ caseStmt->location, caseStmt->cond, initAlts.front().type }; 1631 ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, getContext());1625 ast::ptr< ast::Expr > newExpr = findSingleExpression( untyped, context ); 1632 1626 1633 1627 // case condition cannot have a cast in C, so it must be removed here, regardless of … … 1650 1644 branchStmt = ast::mutate_field( 1651 1645 branchStmt, &ast::BranchStmt::computedTarget, 1652 findSingleExpression( branchStmt->computedTarget, target, getContext()) );1646 findSingleExpression( branchStmt->computedTarget, target, context ) ); 1653 1647 } 1654 1648 return branchStmt; … … 1660 1654 returnStmt = ast::mutate_field( 1661 1655 returnStmt, &ast::ReturnStmt::expr, 1662 findSingleExpression( returnStmt->expr, functionReturn, getContext()) );1656 findSingleExpression( returnStmt->expr, functionReturn, context ) ); 1663 1657 } 1664 1658 return returnStmt; … … 1675 1669 throwStmt = ast::mutate_field( 1676 1670 throwStmt, &ast::ThrowStmt::expr, 1677 findSingleExpression( throwStmt->expr, exceptType, getContext()) );1671 findSingleExpression( throwStmt->expr, exceptType, context ) ); 1678 1672 } 1679 1673 return throwStmt; … … 1719 1713 1720 1714 ast::TypeEnvironment env; 1721 CandidateFinder funcFinder( getContext(), env );1715 CandidateFinder funcFinder( context, env ); 1722 1716 1723 1717 // Find all candidates for a function in canonical form … … 1933 1927 ); 1934 1928 1935 clause2.target.args.emplace_back( findSingleExpression( init, getContext()) );1929 clause2.target.args.emplace_back( findSingleExpression( init, context ) ); 1936 1930 } 1937 1931 1938 1932 // Resolve the conditions as if it were an IfStmt, statements normally 1939 clause2.cond = findSingleExpression( clause.cond, getContext());1933 clause2.cond = findSingleExpression( clause.cond, context ); 1940 1934 clause2.stmt = clause.stmt->accept( *visitor ); 1941 1935 … … 1952 1946 ast::ptr< ast::Type > target = 1953 1947 new ast::BasicType{ ast::BasicType::LongLongUnsignedInt }; 1954 timeout2.time = findSingleExpression( stmt->timeout.time, target, getContext());1955 timeout2.cond = findSingleExpression( stmt->timeout.cond, getContext());1948 timeout2.time = findSingleExpression( stmt->timeout.time, target, context ); 1949 timeout2.cond = findSingleExpression( stmt->timeout.cond, context ); 1956 1950 timeout2.stmt = stmt->timeout.stmt->accept( *visitor ); 1957 1951 … … 1966 1960 ast::WaitForStmt::OrElse orElse2; 1967 1961 1968 orElse2.cond = findSingleExpression( stmt->orElse.cond, getContext());1962 orElse2.cond = findSingleExpression( stmt->orElse.cond, context ); 1969 1963 orElse2.stmt = stmt->orElse.stmt->accept( *visitor ); 1970 1964 … … 1987 1981 for (auto & expr : exprs) { 1988 1982 // only struct- and union-typed expressions are viable candidates 1989 expr = findKindExpression( expr, getContext(), structOrUnion, "with expression" );1983 expr = findKindExpression( expr, context, structOrUnion, "with expression" ); 1990 1984 1991 1985 // if with expression might be impure, create a temporary so that it is evaluated once … … 2013 2007 ast::ptr< ast::Expr > untyped = new ast::UntypedInitExpr{ 2014 2008 singleInit->location, singleInit->value, currentObject.getOptions() }; 2015 ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, getContext());2009 ast::ptr<ast::Expr> newExpr = findSingleExpression( untyped, context ); 2016 2010 const ast::InitExpr * initExpr = newExpr.strict_as< ast::InitExpr >(); 2017 2011
Note: See TracChangeset
for help on using the changeset viewer.