Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/BoxNew.cpp

    r0bf0b978 rd3652df  
    9494
    9595/// Adds parameters for otype size and alignment to a function type.
    96 void addSTypeParams(
    97                 ast::vector<ast::DeclWithType> & params,
     96void addOTypeParams(
     97                ast::FunctionDecl * decl,
    9898                ast::vector<ast::TypeDecl> const & sizedParams ) {
     99        // TODO: Can we fold this into buildLayoutFunction to avoid rebuilding?
     100        ast::FunctionType * type = ast::mutate( decl->type.get() );
    99101        for ( ast::ptr<ast::TypeDecl> const & sizedParam : sizedParams ) {
    100102                ast::TypeInstType inst( sizedParam );
    101103                std::string paramName = Mangle::mangleType( &inst );
    102                 params.emplace_back( new ast::ObjectDecl(
     104                decl->params.emplace_back( new ast::ObjectDecl(
    103105                        sizedParam->location,
    104106                        sizeofName( paramName ),
    105107                        makeSizeAlignType()
    106108                ) );
    107                 params.emplace_back( new ast::ObjectDecl(
     109                type->params.emplace_back( makeSizeAlignType() );
     110                decl->params.emplace_back( new ast::ObjectDecl(
    108111                        sizedParam->location,
    109112                        alignofName( paramName ),
    110113                        makeSizeAlignType()
    111114                ) );
    112         }
     115                type->params.emplace_back( makeSizeAlignType() );
     116        }
     117        decl->type = type;
    113118}
    114119
     
    124129};
    125130
     131// TODO: Is there a better way to handle the different besides a flag?
    126132LayoutData buildLayoutFunction(
    127133                CodeLocation const & location, ast::AggregateDecl const * aggr,
    128                 ast::vector<ast::TypeDecl> const & sizedParams,
    129134                bool isInFunction, bool isStruct ) {
    130135        ast::ObjectDecl * sizeParam = new ast::ObjectDecl(
     
    148153                params.push_back( offsetParam );
    149154        }
    150         addSTypeParams( params, sizedParams );
    151155
    152156        // Routines at global scope marked "static" to prevent multiple
     
    234238
    235239        // Build layout function signature.
    236         LayoutData layout = buildLayoutFunction(
    237                 location, decl, sizedParams, isInFunction(), true );
     240        LayoutData layout =
     241                buildLayoutFunction( location, decl, isInFunction(), true );
    238242        ast::FunctionDecl * layoutDecl = layout.function;
    239243        // Also return these or extract them from the parameter list?
     
    242246        ast::ObjectDecl const * offsetofParam = layout.offsetofParam;
    243247        assert( nullptr != layout.offsetofParam );
     248        addOTypeParams( layoutDecl, sizedParams );
    244249
    245250        // Calculate structure layout in function body.
     
    308313
    309314        // Build layout function signature.
    310         LayoutData layout = buildLayoutFunction(
    311                 location, decl, sizedParams, isInFunction(), false );
     315        LayoutData layout =
     316                buildLayoutFunction( location, decl, isInFunction(), false );
    312317        ast::FunctionDecl * layoutDecl = layout.function;
    313318        // Also return these or extract them from the parameter list?
     
    315320        ast::ObjectDecl const * alignofParam = layout.alignofParam;
    316321        assert( nullptr == layout.offsetofParam );
     322        addOTypeParams( layoutDecl, sizedParams );
    317323
    318324        // Calculate union layout in function body.
     
    635641        // the variable can be reused as a parameter to the call rather than
    636642        // creating a new temporary variable. Previously this step was an
    637         // optimization, but with the introduction of tuples and UniqueExprs,
    638         // it is necessary to ensure that they use the same variable.
     643        // optimization, but
     644        // ...
     645        // with the introduction of tuples and UniqueExprs, it is necessary to
     646        // ensure that they use the same variable.
    639647        // Essentially, looking for pattern:
    640648        // (x=f(...), x)
     
    681689        // the distinction between _conc_T30 and T3(int)) concRetType may not be
    682690        // a good name in one or both of these places.
     691        // TODO A more appropriate name change is welcome.
    683692        if ( dynRetType ) {
    684693                ast::Type const * result = mutExpr->result;
     
    689698        } else if ( needsAdapter( function, scopeTypeVars )
    690699                        && !needsAdapter( function, exprTypeVars ) ) {
     700                // TODO:
     701                // The !needsAdapter check may be incorrect. It seems there is some
     702                // situation where an adapter is applied where it shouldn't be,
     703                // and this fixes it for some case. More investigation is needed.
     704
    691705                // Change the application so it calls the adapter rather than the
    692706                // passed function.
     
    17601774        /// Adds type parameters to the layout call; will generate the
    17611775        /// appropriate parameters if needed.
    1762         void addSTypeParamsToLayoutCall(
     1776        void addOTypeParamsToLayoutCall(
    17631777                ast::UntypedExpr * layoutCall,
    17641778                const ast::vector<ast::Type> & otypeParams );
     
    20002014                ast::MemberExpr const * expr ) {
    20012015        // Only mutate member expressions for polymorphic types.
     2016        int typeDepth;
    20022017        ast::Type const * objectType = hasPolyBase(
    2003                 expr->aggregate->result, scopeTypeVars
     2018                expr->aggregate->result, scopeTypeVars, &typeDepth
    20042019        );
    20052020        if ( !objectType ) return expr;
     
    20792094        }
    20802095        // MemberExpr was converted to pointer + offset; and it is not valid C to
    2081         // take the address of an addition, so strip away the address-of.
     2096        // take the address of an addition, so stript the address-of.
    20822097        // It also preserves the env value.
    20832098        return ast::mutate_field( expr->arg.get(), &ast::Expr::env, expr->env );
     
    22802295                                } );
    22812296
    2282                         addSTypeParamsToLayoutCall( layoutCall, sizedParams );
     2297                        addOTypeParamsToLayoutCall( layoutCall, sizedParams );
    22832298
    22842299                        stmtsToAddBefore.emplace_back(
     
    23212336                        } );
    23222337
    2323                 addSTypeParamsToLayoutCall( layoutCall, sizedParams );
     2338                addOTypeParamsToLayoutCall( layoutCall, sizedParams );
    23242339
    23252340                stmtsToAddBefore.emplace_back(
     
    23312346}
    23322347
    2333 void PolyGenericCalculator::addSTypeParamsToLayoutCall(
     2348void PolyGenericCalculator::addOTypeParamsToLayoutCall(
    23342349                ast::UntypedExpr * layoutCall,
    23352350                const ast::vector<ast::Type> & otypeParams ) {
Note: See TracChangeset for help on using the changeset viewer.