Changeset 52a5262e for src/GenPoly
- Timestamp:
- Oct 16, 2023, 4:10:26 PM (16 months ago)
- Branches:
- master
- Children:
- d85141f
- Parents:
- e14d169
- Location:
- src/GenPoly
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/BoxNew.cpp
re14d169 r52a5262e 39 39 40 40 namespace { 41 42 /// Common field of several sub-passes of box.43 struct BoxPass {44 TypeVarMap scopeTypeVars;45 BoxPass() : scopeTypeVars( ast::TypeData() ) {}46 };47 41 48 42 // TODO: Could this be a common helper somewhere? … … 359 353 /// * Adds appropriate type variables to the function calls. 360 354 struct CallAdapter final : 361 public BoxPass,362 355 public ast::WithConstTypeSubstitution, 363 356 public ast::WithGuards, … … 438 431 CodeLocation const & location, ast::Type const * type ); 439 432 440 /// Set of adapter functions in the current scope.433 TypeVarMap scopeTypeVars; 441 434 ScopedMap< std::string, ast::DeclWithType const * > adapters; 442 435 std::map< ast::ApplicationExpr const *, ast::Expr const * > retVals; … … 659 652 ptrdiff_t initArgCount = mutExpr->args.size(); 660 653 661 TypeVarMap exprTypeVars = { ast::TypeData() };654 TypeVarMap exprTypeVars; 662 655 // TODO: Should this take into account the variables already bound in 663 656 // scopeTypeVars ([ex] remove them from exprTypeVars)? … … 1410 1403 1411 1404 ast::FunctionDecl const * DeclAdapter::previsit( ast::FunctionDecl const * decl ) { 1412 TypeVarMap localTypeVars = { ast::TypeData() };1405 TypeVarMap localTypeVars; 1413 1406 makeTypeVarMap( decl, localTypeVars ); 1414 1407 … … 1558 1551 assertf( it != adapters.end(), "Could not correct floating node." ); 1559 1552 return ast::mutate_field( expr, &ast::VariableExpr::var, it->second ); 1560 1561 1553 } 1562 1554 … … 1570 1562 /// * Inserts dynamic calculation of polymorphic type layouts where needed. 1571 1563 struct PolyGenericCalculator final : 1572 public BoxPass,1573 1564 public ast::WithConstTypeSubstitution, 1574 1565 public ast::WithDeclsToAdd<>, … … 1615 1606 /// C sizeof(). 1616 1607 ast::Expr const * genSizeof( CodeLocation const &, ast::Type const * ); 1617 1618 1608 /// Enters a new scope for type-variables, 1619 1609 /// adding the type variables from the provided type. 1620 1610 void beginTypeScope( ast::Type const * ); 1621 1611 1612 /// The type variables and polymorphic parameters currently in scope. 1613 TypeVarMap scopeTypeVars; 1622 1614 /// Set of generic type layouts known in the current scope, 1623 1615 /// indexed by sizeofName. … … 1668 1660 ast::TypeDecl const * decl ) { 1669 1661 ast::Type const * base = decl->base; 1670 if ( nullptr == base ) return decl;1662 if ( nullptr == base ) return decl; 1671 1663 1672 1664 // Add size/align variables for opaque type declarations. … … 1693 1685 alignDecl->accept( *visitor ); 1694 1686 1695 // Can't use [makeVar], because it inserts into stmtsToAdd and TypeDecls1696 // can occur at global scope.1687 // A little trick to replace this with two declarations. 1688 // Adding after makes sure that there is no conflict with adding stmts. 1697 1689 declsToAddAfter.push_back( alignDecl ); 1698 // replace with sizeDecl.1699 1690 return sizeDecl; 1700 1691 } … … 1721 1712 1722 1713 // Change initialization of a polymorphic value object to allocate via a 1723 // variable-length-array (alloca was previouly used, but it cannot be 1724 // safely used in loops). 1714 // variable-length-array (alloca cannot be safely used in loops). 1725 1715 ast::ObjectDecl * newBuf = new ast::ObjectDecl( decl->location, 1726 1716 bufNamer.newName(), … … 2210 2200 /// * Strips fields from generic structure declarations. 2211 2201 struct Eraser final : 2212 public BoxPass,2213 2202 public ast::WithGuards { 2214 2203 void guardTypeVarMap( ast::Type const * type ) { … … 2225 2214 void previsit( ast::PointerType const * type ); 2226 2215 void previsit( ast::FunctionType const * type ); 2216 public: 2217 TypeVarMap scopeTypeVars; 2227 2218 }; 2228 2219 -
src/GenPoly/GenPoly.cc
re14d169 r52a5262e 273 273 if ( func->returns.empty() ) return nullptr; 274 274 275 TypeVarMap forallTypes = { ast::TypeData() };275 TypeVarMap forallTypes; 276 276 makeTypeVarMap( func, forallTypes ); 277 277 return isDynType( func->returns.front(), forallTypes ); … … 801 801 const ast::FunctionType * function = getFunctionType( expr->func->result ); 802 802 assertf( function, "ApplicationExpr has non-function type: %s", toString( expr->func->result ).c_str() ); 803 TypeVarMap exprTyVars = { ast::TypeData() };803 TypeVarMap exprTyVars; 804 804 makeTypeVarMap( function, exprTyVars ); 805 805 return needsBoxing( param, arg, exprTyVars, subst ); -
src/GenPoly/GenPoly.h
re14d169 r52a5262e 33 33 34 34 typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap; 35 using TypeVarMap = ErasableScopedMap< ast::TypeEnvKey, ast::TypeData >; 35 struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> { 36 TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {} 37 }; 36 38 37 39 /// Replaces a TypeInstType by its referrent in the environment, if applicable
Note: See TracChangeset
for help on using the changeset viewer.