Changeset 0bf0b97


Ignore:
Timestamp:
Oct 13, 2023, 10:10:45 AM (7 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
8cbe732
Parents:
e85a72b8
Message:

Layout function builds its entire parameter list before creating the declaration now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/BoxNew.cpp

    re85a72b8 r0bf0b97  
    9595/// Adds parameters for otype size and alignment to a function type.
    9696void addSTypeParams(
    97                 ast::FunctionDecl * decl,
     97                ast::vector<ast::DeclWithType> & params,
    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() );
    10199        for ( ast::ptr<ast::TypeDecl> const & sizedParam : sizedParams ) {
    102100                ast::TypeInstType inst( sizedParam );
    103101                std::string paramName = Mangle::mangleType( &inst );
    104                 decl->params.emplace_back( new ast::ObjectDecl(
     102                params.emplace_back( new ast::ObjectDecl(
    105103                        sizedParam->location,
    106104                        sizeofName( paramName ),
    107105                        makeSizeAlignType()
    108106                ) );
    109                 type->params.emplace_back( makeSizeAlignType() );
    110                 decl->params.emplace_back( new ast::ObjectDecl(
     107                params.emplace_back( new ast::ObjectDecl(
    111108                        sizedParam->location,
    112109                        alignofName( paramName ),
    113110                        makeSizeAlignType()
    114111                ) );
    115                 type->params.emplace_back( makeSizeAlignType() );
    116         }
    117         decl->type = type;
     112        }
    118113}
    119114
     
    129124};
    130125
    131 // TODO: Is there a better way to handle the different besides a flag?
    132126LayoutData buildLayoutFunction(
    133127                CodeLocation const & location, ast::AggregateDecl const * aggr,
     128                ast::vector<ast::TypeDecl> const & sizedParams,
    134129                bool isInFunction, bool isStruct ) {
    135130        ast::ObjectDecl * sizeParam = new ast::ObjectDecl(
     
    153148                params.push_back( offsetParam );
    154149        }
     150        addSTypeParams( params, sizedParams );
    155151
    156152        // Routines at global scope marked "static" to prevent multiple
     
    238234
    239235        // Build layout function signature.
    240         LayoutData layout =
    241                 buildLayoutFunction( location, decl, isInFunction(), true );
     236        LayoutData layout = buildLayoutFunction(
     237                location, decl, sizedParams, isInFunction(), true );
    242238        ast::FunctionDecl * layoutDecl = layout.function;
    243239        // Also return these or extract them from the parameter list?
     
    246242        ast::ObjectDecl const * offsetofParam = layout.offsetofParam;
    247243        assert( nullptr != layout.offsetofParam );
    248         addSTypeParams( layoutDecl, sizedParams );
    249244
    250245        // Calculate structure layout in function body.
     
    313308
    314309        // Build layout function signature.
    315         LayoutData layout =
    316                 buildLayoutFunction( location, decl, isInFunction(), false );
     310        LayoutData layout = buildLayoutFunction(
     311                location, decl, sizedParams, isInFunction(), false );
    317312        ast::FunctionDecl * layoutDecl = layout.function;
    318313        // Also return these or extract them from the parameter list?
     
    320315        ast::ObjectDecl const * alignofParam = layout.alignofParam;
    321316        assert( nullptr == layout.offsetofParam );
    322         addSTypeParams( layoutDecl, sizedParams );
    323317
    324318        // Calculate union layout in function body.
Note: See TracChangeset for help on using the changeset viewer.