- Timestamp:
- Feb 13, 2025, 5:52:15 PM (8 months ago)
- Branches:
- master
- Children:
- ef9f11c
- Parents:
- 502ff9e (diff), 53f4b55 (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. - Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r502ff9e rc341b57 301 301 // --- OffsetofExpr 302 302 303 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem )304 : OffsetofExpr( loc, ty, mem, nullptr ) {}305 306 303 OffsetofExpr::OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res ) 307 304 : Expr( loc, res ), type( ty ), member( mem ) { … … 324 321 325 322 // --- CommaExpr 323 326 324 bool CommaExpr::get_lvalue() const { 327 325 // This is wrong by C, but the current implementation uses it. -
src/AST/Expr.hpp
r502ff9e rc341b57 539 539 readonly<DeclWithType> member; 540 540 541 OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem );542 541 OffsetofExpr( const CodeLocation & loc, const Type * ty, const DeclWithType * mem, const Type * res ); 543 542 -
src/GenPoly/Box.cpp
r502ff9e rc341b57 2002 2002 new ast::OffsetofExpr( expr->location, 2003 2003 deepCopy( type ), 2004 memberDecl 2004 memberDecl, 2005 getLayoutType( transUnit() ) 2005 2006 ) 2006 2007 ) ); -
src/ResolvExpr/CandidateFinder.cpp
r502ff9e rc341b57 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 } -
src/ResolvExpr/ConversionCost.cpp
r502ff9e rc341b57 518 518 auto srcDecl = src->base; 519 519 auto dstDecl = dst->base; 520 if ( srcDecl->name == dstDecl->name) return Cost::safe;520 if ( srcDecl->name == dstDecl->name ) return Cost::safe; 521 521 Cost minCost = Cost::infinity; 522 for ( auto child: dstDecl->inlinedDecl) {523 Cost c = enumCastCost( src, child, symtab, env) + Cost::safe;524 if ( c<minCost) minCost = c;522 for ( auto child : dstDecl->inlinedDecl ) { 523 Cost c = enumCastCost( src, child, symtab, env ) + Cost::safe; 524 if ( c < minCost ) minCost = c; 525 525 } 526 526 return minCost; -
src/ResolvExpr/Cost.hpp
r502ff9e rc341b57 169 169 } 170 170 171 inline bool operator<=( const Cost lhs, const Cost rhs ) { 172 return !(rhs < lhs); 173 } 174 171 175 inline Cost operator+( const Cost lhs, const Cost rhs ) { 172 176 if ( lhs.all == Cost::infinity || rhs.all == Cost::infinity ) return Cost{ Cost::infinity }; -
src/Validate/EnumAndPointerDecay.cpp
r502ff9e rc341b57 48 48 } else if ( auto value = member.as<ast::InlineMemberDecl>() ) { 49 49 auto targetEnum = symtab.lookupEnum( value->name ); 50 // assert( targetEnum );51 50 if (!targetEnum) { 52 51 SemanticError(value, "Only another enum is allowed for enum inline syntax "); 53 52 } 54 53 const ast::EnumInstType * instType = new ast::EnumInstType(targetEnum); 55 mut->inlinedDecl. push_back( std::move(instType));54 mut->inlinedDecl.emplace_back( instType ); 56 55 for ( auto enumMember : targetEnum->members ) { 57 56 auto enumObject = enumMember.strict_as<ast::ObjectDecl>();
Note:
See TracChangeset
for help on using the changeset viewer.