Changeset a8404d9 for src/ResolvExpr/CandidateFinder.cpp
- Timestamp:
- Feb 12, 2025, 11:33:33 AM (2 months ago)
- Branches:
- master
- Children:
- 5e8d75bb
- Parents:
- 54cd1a51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r54cd1a51 ra8404d9 2150 2150 } 2151 2151 2152 const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src, 2153 const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {2152 const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src, 2153 const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) { 2154 2154 auto srcDecl = src->base; 2155 2155 auto dstDecl = dst->base; 2156 2156 2157 if ( srcDecl->name == dstDecl->name) return expr;2158 2159 for ( auto& dstChild: dstDecl->inlinedDecl) {2157 if ( srcDecl->name == dstDecl->name ) return expr; 2158 2159 for ( auto& dstChild : dstDecl->inlinedDecl ) { 2160 2160 Cost c = castCost(src, dstChild, false, context.symtab, env); 2161 ast::CastExpr * castToDst; 2162 if (c<minCost) { 2163 unsigned offset = findChildOffset( dstDecl, dstChild.get()->base ); 2164 if (offset > 0) { 2165 auto untyped = ast::UntypedExpr::createCall( 2166 expr->location, 2167 "?+?", 2168 { new ast::CastExpr( expr->location, 2169 expr, 2170 new ast::BasicType(ast::BasicKind::SignedInt), 2171 ast::GeneratedFlag::ExplicitCast ), 2172 ast::ConstantExpr::from_int(expr->location, offset)} ); 2173 CandidateFinder finder(context, env); 2174 finder.find( untyped ); 2175 CandidateList winners = findMinCost( finder.candidates ); 2176 CandidateRef & choice = winners.front(); 2177 choice->expr = new ast::CastExpr(expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast); 2178 auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost ); 2179 if ( !destExpr ) continue; 2180 castToDst = new ast::CastExpr( destExpr, dst ); 2181 } else { 2182 castToDst = new ast::CastExpr( expr, dst ); 2183 } 2184 return castToDst; 2161 if ( minCost <= c ) continue; 2162 unsigned offset = findChildOffset( dstDecl, dstChild.get()->base ); 2163 if ( offset <= 0 ) return new ast::CastExpr( expr, dst ); 2164 2165 auto untyped = ast::UntypedExpr::createCall( 2166 expr->location, 2167 "?+?", 2168 { new ast::CastExpr( expr->location, 2169 expr, 2170 new ast::BasicType( ast::BasicKind::SignedInt ), 2171 ast::GeneratedFlag::ExplicitCast ), 2172 ast::ConstantExpr::from_int( expr->location, offset ) } ); 2173 CandidateFinder finder(context, env); 2174 finder.find( untyped ); 2175 CandidateList winners = findMinCost( finder.candidates ); 2176 CandidateRef & choice = winners.front(); 2177 choice->expr = new ast::CastExpr( expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast ); 2178 if ( auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost ) ) { 2179 return new ast::CastExpr( destExpr, dst ); 2185 2180 } 2186 2181 }
Note: See TracChangeset
for help on using the changeset viewer.