Changeset 90be0cf for src/ResolvExpr
- Timestamp:
- Oct 24, 2024, 12:50:14 PM (6 months ago)
- Branches:
- master
- Children:
- d031f7f
- Parents:
- 12c4a5f
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/ResolvExpr/CandidateFinder.cpp ¶
r12c4a5f r90be0cf 2136 2136 } 2137 2137 2138 /// If the target enum is a child, get the offset from the base to the target. 2139 static unsigned findChildOffset( 2140 const ast::EnumDecl * decl, const ast::EnumDecl * target ) { 2141 unsigned offset = 0; 2142 for ( auto inlined : decl->inlinedDecl ) { 2143 auto childDecl = inlined->base; 2144 if ( childDecl == target ) { 2145 return offset; 2146 } 2147 offset += childDecl->members.size(); 2148 } 2149 SemanticError( decl, "Cannot find the target enum." ); 2150 } 2151 2138 2152 const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src, 2139 2153 const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) { … … 2147 2161 ast::CastExpr * castToDst; 2148 2162 if (c<minCost) { 2149 unsigned offset = dstDecl->calChildOffset(dstChild.get());2163 unsigned offset = findChildOffset( dstDecl, dstChild.get()->base ); 2150 2164 if (offset > 0) { 2151 2165 auto untyped = ast::UntypedExpr::createCall( 2152 expr->location, 2153 "?+?", 2166 expr->location, 2167 "?+?", 2154 2168 { new ast::CastExpr( expr->location, 2155 2169 expr, -
TabularUnified src/ResolvExpr/CommonType.cpp ¶
r12c4a5f r90be0cf 636 636 void postvisit( const ast::UnionInstType * ) {} 637 637 638 /// Is the target enum a child of the base enum? 639 static bool isChildEnum( 640 const ast::EnumDecl * decl, const ast::EnumDecl * target ) { 641 if ( decl == target ) return true; 642 for ( auto inlined : decl->inlinedDecl ) { 643 if ( isChildEnum( inlined->base, target ) ) return true; 644 } 645 return false; 646 } 647 638 648 void postvisit( const ast::EnumInstType * param ) { 639 649 auto argAsEnumInst = dynamic_cast<const ast::EnumInstType *>(type2); … … 641 651 const ast::EnumDecl* paramDecl = param->base; 642 652 const ast::EnumDecl* argDecl = argAsEnumInst->base; 643 if (argDecl->isSubTypeOf(paramDecl)) result = param; 653 if ( isChildEnum( paramDecl, argDecl ) ) { 654 result = param; 655 } 644 656 } else if ( param->base && !param->base->isCfa ) { 645 657 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt );
Note: See TracChangeset
for help on using the changeset viewer.