Changeset a97b9ed for src/GenPoly/BoxNew.cpp
- Timestamp:
- Oct 16, 2023, 8:09:51 AM (14 months ago)
- Branches:
- master
- Children:
- 2bf46a5, 54e59dd, 61e5d99
- Parents:
- 946a6e4 (diff), 8cbe732 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/BoxNew.cpp
r946a6e4 ra97b9ed 94 94 95 95 /// Adds parameters for otype size and alignment to a function type. 96 void add OTypeParams(97 ast:: FunctionDecl * decl,96 void addSTypeParams( 97 ast::vector<ast::DeclWithType> & params, 98 98 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() );101 99 for ( ast::ptr<ast::TypeDecl> const & sizedParam : sizedParams ) { 102 100 ast::TypeInstType inst( sizedParam ); 103 101 std::string paramName = Mangle::mangleType( &inst ); 104 decl->params.emplace_back( new ast::ObjectDecl(102 params.emplace_back( new ast::ObjectDecl( 105 103 sizedParam->location, 106 104 sizeofName( paramName ), 107 105 makeSizeAlignType() 108 106 ) ); 109 type->params.emplace_back( makeSizeAlignType() ); 110 decl->params.emplace_back( new ast::ObjectDecl( 107 params.emplace_back( new ast::ObjectDecl( 111 108 sizedParam->location, 112 109 alignofName( paramName ), 113 110 makeSizeAlignType() 114 111 ) ); 115 type->params.emplace_back( makeSizeAlignType() ); 116 } 117 decl->type = type; 112 } 118 113 } 119 114 … … 129 124 }; 130 125 131 // TODO: Is there a better way to handle the different besides a flag?132 126 LayoutData buildLayoutFunction( 133 127 CodeLocation const & location, ast::AggregateDecl const * aggr, 128 ast::vector<ast::TypeDecl> const & sizedParams, 134 129 bool isInFunction, bool isStruct ) { 135 130 ast::ObjectDecl * sizeParam = new ast::ObjectDecl( … … 153 148 params.push_back( offsetParam ); 154 149 } 150 addSTypeParams( params, sizedParams ); 155 151 156 152 // Routines at global scope marked "static" to prevent multiple … … 238 234 239 235 // Build layout function signature. 240 LayoutData layout = 241 buildLayoutFunction( location, decl, isInFunction(), true );236 LayoutData layout = buildLayoutFunction( 237 location, decl, sizedParams, isInFunction(), true ); 242 238 ast::FunctionDecl * layoutDecl = layout.function; 243 239 // Also return these or extract them from the parameter list? … … 246 242 ast::ObjectDecl const * offsetofParam = layout.offsetofParam; 247 243 assert( nullptr != layout.offsetofParam ); 248 addOTypeParams( layoutDecl, sizedParams );249 244 250 245 // Calculate structure layout in function body. … … 313 308 314 309 // Build layout function signature. 315 LayoutData layout = 316 buildLayoutFunction( location, decl, isInFunction(), false );310 LayoutData layout = buildLayoutFunction( 311 location, decl, sizedParams, isInFunction(), false ); 317 312 ast::FunctionDecl * layoutDecl = layout.function; 318 313 // Also return these or extract them from the parameter list? … … 320 315 ast::ObjectDecl const * alignofParam = layout.alignofParam; 321 316 assert( nullptr == layout.offsetofParam ); 322 addOTypeParams( layoutDecl, sizedParams );323 317 324 318 // Calculate union layout in function body. … … 641 635 // the variable can be reused as a parameter to the call rather than 642 636 // creating a new temporary variable. Previously this step was an 643 // optimization, but 644 // ... 645 // with the introduction of tuples and UniqueExprs, it is necessary to 646 // ensure that they use the same variable. 637 // optimization, but with the introduction of tuples and UniqueExprs, 638 // it is necessary to ensure that they use the same variable. 647 639 // Essentially, looking for pattern: 648 640 // (x=f(...), x) … … 689 681 // the distinction between _conc_T30 and T3(int)) concRetType may not be 690 682 // a good name in one or both of these places. 691 // TODO A more appropriate name change is welcome.692 683 if ( dynRetType ) { 693 684 ast::Type const * result = mutExpr->result; … … 698 689 } else if ( needsAdapter( function, scopeTypeVars ) 699 690 && !needsAdapter( function, exprTypeVars ) ) { 700 // TODO:701 // The !needsAdapter check may be incorrect. It seems there is some702 // situation where an adapter is applied where it shouldn't be,703 // and this fixes it for some case. More investigation is needed.704 705 691 // Change the application so it calls the adapter rather than the 706 692 // passed function. … … 1774 1760 /// Adds type parameters to the layout call; will generate the 1775 1761 /// appropriate parameters if needed. 1776 void add OTypeParamsToLayoutCall(1762 void addSTypeParamsToLayoutCall( 1777 1763 ast::UntypedExpr * layoutCall, 1778 1764 const ast::vector<ast::Type> & otypeParams ); … … 2014 2000 ast::MemberExpr const * expr ) { 2015 2001 // Only mutate member expressions for polymorphic types. 2016 int typeDepth;2017 2002 ast::Type const * objectType = hasPolyBase( 2018 expr->aggregate->result, scopeTypeVars , &typeDepth2003 expr->aggregate->result, scopeTypeVars 2019 2004 ); 2020 2005 if ( !objectType ) return expr; … … 2094 2079 } 2095 2080 // MemberExpr was converted to pointer + offset; and it is not valid C to 2096 // take the address of an addition, so strip tthe address-of.2081 // take the address of an addition, so strip away the address-of. 2097 2082 // It also preserves the env value. 2098 2083 return ast::mutate_field( expr->arg.get(), &ast::Expr::env, expr->env ); … … 2295 2280 } ); 2296 2281 2297 add OTypeParamsToLayoutCall( layoutCall, sizedParams );2282 addSTypeParamsToLayoutCall( layoutCall, sizedParams ); 2298 2283 2299 2284 stmtsToAddBefore.emplace_back( … … 2336 2321 } ); 2337 2322 2338 add OTypeParamsToLayoutCall( layoutCall, sizedParams );2323 addSTypeParamsToLayoutCall( layoutCall, sizedParams ); 2339 2324 2340 2325 stmtsToAddBefore.emplace_back( … … 2346 2331 } 2347 2332 2348 void PolyGenericCalculator::add OTypeParamsToLayoutCall(2333 void PolyGenericCalculator::addSTypeParamsToLayoutCall( 2349 2334 ast::UntypedExpr * layoutCall, 2350 2335 const ast::vector<ast::Type> & otypeParams ) {
Note: See TracChangeset
for help on using the changeset viewer.