Ignore:
Timestamp:
Oct 16, 2023, 4:10:26 PM (12 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
d85141f
Parents:
e14d169
Message:

TypeVarMap? is now a subtype instead of an alias to remove the redundent constructor argument. Various bits of box pass clean-up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/BoxNew.cpp

    re14d169 r52a5262e  
    3939
    4040namespace {
    41 
    42 /// Common field of several sub-passes of box.
    43 struct BoxPass {
    44         TypeVarMap scopeTypeVars;
    45         BoxPass() : scopeTypeVars( ast::TypeData() ) {}
    46 };
    4741
    4842// TODO: Could this be a common helper somewhere?
     
    359353/// * Adds appropriate type variables to the function calls.
    360354struct CallAdapter final :
    361                 public BoxPass,
    362355                public ast::WithConstTypeSubstitution,
    363356                public ast::WithGuards,
     
    438431                CodeLocation const & location, ast::Type const * type );
    439432
    440         /// Set of adapter functions in the current scope.
     433        TypeVarMap scopeTypeVars;
    441434        ScopedMap< std::string, ast::DeclWithType const * > adapters;
    442435        std::map< ast::ApplicationExpr const *, ast::Expr const * > retVals;
     
    659652        ptrdiff_t initArgCount = mutExpr->args.size();
    660653
    661         TypeVarMap exprTypeVars = { ast::TypeData() };
     654        TypeVarMap exprTypeVars;
    662655        // TODO: Should this take into account the variables already bound in
    663656        // scopeTypeVars ([ex] remove them from exprTypeVars)?
     
    14101403
    14111404ast::FunctionDecl const * DeclAdapter::previsit( ast::FunctionDecl const * decl ) {
    1412         TypeVarMap localTypeVars = { ast::TypeData() };
     1405        TypeVarMap localTypeVars;
    14131406        makeTypeVarMap( decl, localTypeVars );
    14141407
     
    15581551        assertf( it != adapters.end(), "Could not correct floating node." );
    15591552        return ast::mutate_field( expr, &ast::VariableExpr::var, it->second );
    1560 
    15611553}
    15621554
     
    15701562/// * Inserts dynamic calculation of polymorphic type layouts where needed.
    15711563struct PolyGenericCalculator final :
    1572                 public BoxPass,
    15731564                public ast::WithConstTypeSubstitution,
    15741565                public ast::WithDeclsToAdd<>,
     
    16151606        /// C sizeof().
    16161607        ast::Expr const * genSizeof( CodeLocation const &, ast::Type const * );
    1617 
    16181608        /// Enters a new scope for type-variables,
    16191609        /// adding the type variables from the provided type.
    16201610        void beginTypeScope( ast::Type const * );
    16211611
     1612        /// The type variables and polymorphic parameters currently in scope.
     1613        TypeVarMap scopeTypeVars;
    16221614        /// Set of generic type layouts known in the current scope,
    16231615        /// indexed by sizeofName.
     
    16681660                ast::TypeDecl const * decl ) {
    16691661        ast::Type const * base = decl->base;
    1670         if ( nullptr == base) return decl;
     1662        if ( nullptr == base ) return decl;
    16711663
    16721664        // Add size/align variables for opaque type declarations.
     
    16931685        alignDecl->accept( *visitor );
    16941686
    1695         // Can't use [makeVar], because it inserts into stmtsToAdd and TypeDecls
    1696         // 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.
    16971689        declsToAddAfter.push_back( alignDecl );
    1698         // replace with sizeDecl.
    16991690        return sizeDecl;
    17001691}
     
    17211712
    17221713        // 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).
    17251715        ast::ObjectDecl * newBuf = new ast::ObjectDecl( decl->location,
    17261716                bufNamer.newName(),
     
    22102200/// * Strips fields from generic structure declarations.
    22112201struct Eraser final :
    2212                 public BoxPass,
    22132202                public ast::WithGuards {
    22142203        void guardTypeVarMap( ast::Type const * type ) {
     
    22252214        void previsit( ast::PointerType const * type );
    22262215        void previsit( ast::FunctionType const * type );
     2216public:
     2217        TypeVarMap scopeTypeVars;
    22272218};
    22282219
Note: See TracChangeset for help on using the changeset viewer.