Changes in src/GenPoly/BoxNew.cpp [0bf0b978:d3652df]
- File:
-
- 1 edited
-
src/GenPoly/BoxNew.cpp (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/BoxNew.cpp
r0bf0b978 rd3652df 94 94 95 95 /// Adds parameters for otype size and alignment to a function type. 96 void add STypeParams(97 ast:: vector<ast::DeclWithType> & params,96 void addOTypeParams( 97 ast::FunctionDecl * decl, 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() ); 99 101 for ( ast::ptr<ast::TypeDecl> const & sizedParam : sizedParams ) { 100 102 ast::TypeInstType inst( sizedParam ); 101 103 std::string paramName = Mangle::mangleType( &inst ); 102 params.emplace_back( new ast::ObjectDecl(104 decl->params.emplace_back( new ast::ObjectDecl( 103 105 sizedParam->location, 104 106 sizeofName( paramName ), 105 107 makeSizeAlignType() 106 108 ) ); 107 params.emplace_back( new ast::ObjectDecl( 109 type->params.emplace_back( makeSizeAlignType() ); 110 decl->params.emplace_back( new ast::ObjectDecl( 108 111 sizedParam->location, 109 112 alignofName( paramName ), 110 113 makeSizeAlignType() 111 114 ) ); 112 } 115 type->params.emplace_back( makeSizeAlignType() ); 116 } 117 decl->type = type; 113 118 } 114 119 … … 124 129 }; 125 130 131 // TODO: Is there a better way to handle the different besides a flag? 126 132 LayoutData buildLayoutFunction( 127 133 CodeLocation const & location, ast::AggregateDecl const * aggr, 128 ast::vector<ast::TypeDecl> const & sizedParams,129 134 bool isInFunction, bool isStruct ) { 130 135 ast::ObjectDecl * sizeParam = new ast::ObjectDecl( … … 148 153 params.push_back( offsetParam ); 149 154 } 150 addSTypeParams( params, sizedParams );151 155 152 156 // Routines at global scope marked "static" to prevent multiple … … 234 238 235 239 // Build layout function signature. 236 LayoutData layout = buildLayoutFunction(237 location, decl, sizedParams, isInFunction(), true );240 LayoutData layout = 241 buildLayoutFunction( location, decl, isInFunction(), true ); 238 242 ast::FunctionDecl * layoutDecl = layout.function; 239 243 // Also return these or extract them from the parameter list? … … 242 246 ast::ObjectDecl const * offsetofParam = layout.offsetofParam; 243 247 assert( nullptr != layout.offsetofParam ); 248 addOTypeParams( layoutDecl, sizedParams ); 244 249 245 250 // Calculate structure layout in function body. … … 308 313 309 314 // Build layout function signature. 310 LayoutData layout = buildLayoutFunction(311 location, decl, sizedParams, isInFunction(), false );315 LayoutData layout = 316 buildLayoutFunction( location, decl, isInFunction(), false ); 312 317 ast::FunctionDecl * layoutDecl = layout.function; 313 318 // Also return these or extract them from the parameter list? … … 315 320 ast::ObjectDecl const * alignofParam = layout.alignofParam; 316 321 assert( nullptr == layout.offsetofParam ); 322 addOTypeParams( layoutDecl, sizedParams ); 317 323 318 324 // Calculate union layout in function body. … … 635 641 // the variable can be reused as a parameter to the call rather than 636 642 // 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. 639 647 // Essentially, looking for pattern: 640 648 // (x=f(...), x) … … 681 689 // the distinction between _conc_T30 and T3(int)) concRetType may not be 682 690 // a good name in one or both of these places. 691 // TODO A more appropriate name change is welcome. 683 692 if ( dynRetType ) { 684 693 ast::Type const * result = mutExpr->result; … … 689 698 } else if ( needsAdapter( function, scopeTypeVars ) 690 699 && !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 691 705 // Change the application so it calls the adapter rather than the 692 706 // passed function. … … 1760 1774 /// Adds type parameters to the layout call; will generate the 1761 1775 /// appropriate parameters if needed. 1762 void add STypeParamsToLayoutCall(1776 void addOTypeParamsToLayoutCall( 1763 1777 ast::UntypedExpr * layoutCall, 1764 1778 const ast::vector<ast::Type> & otypeParams ); … … 2000 2014 ast::MemberExpr const * expr ) { 2001 2015 // Only mutate member expressions for polymorphic types. 2016 int typeDepth; 2002 2017 ast::Type const * objectType = hasPolyBase( 2003 expr->aggregate->result, scopeTypeVars 2018 expr->aggregate->result, scopeTypeVars, &typeDepth 2004 2019 ); 2005 2020 if ( !objectType ) return expr; … … 2079 2094 } 2080 2095 // MemberExpr was converted to pointer + offset; and it is not valid C to 2081 // take the address of an addition, so strip awaythe address-of.2096 // take the address of an addition, so stript the address-of. 2082 2097 // It also preserves the env value. 2083 2098 return ast::mutate_field( expr->arg.get(), &ast::Expr::env, expr->env ); … … 2280 2295 } ); 2281 2296 2282 add STypeParamsToLayoutCall( layoutCall, sizedParams );2297 addOTypeParamsToLayoutCall( layoutCall, sizedParams ); 2283 2298 2284 2299 stmtsToAddBefore.emplace_back( … … 2321 2336 } ); 2322 2337 2323 add STypeParamsToLayoutCall( layoutCall, sizedParams );2338 addOTypeParamsToLayoutCall( layoutCall, sizedParams ); 2324 2339 2325 2340 stmtsToAddBefore.emplace_back( … … 2331 2346 } 2332 2347 2333 void PolyGenericCalculator::add STypeParamsToLayoutCall(2348 void PolyGenericCalculator::addOTypeParamsToLayoutCall( 2334 2349 ast::UntypedExpr * layoutCall, 2335 2350 const ast::vector<ast::Type> & otypeParams ) {
Note:
See TracChangeset
for help on using the changeset viewer.