Changeset c333ed2 for src/ResolvExpr
- Timestamp:
- May 7, 2024, 7:04:17 PM (8 months ago)
- Branches:
- master
- Children:
- 0b6c1c9
- Parents:
- 164a6b6
- Location:
- src/ResolvExpr
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r164a6b6 rc333ed2 2138 2138 } 2139 2139 2140 // get the valueE(...) ApplicationExpr that returns the enum value2141 const ast::Expr * getValueEnumCall(2142 const ast::Expr * expr,2143 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) {2144 auto callExpr = new ast::UntypedExpr(2145 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );2146 CandidateFinder finder( context, env );2147 finder.find( callExpr );2148 CandidateList winners = findMinCost( finder.candidates );2149 if (winners.size() != 1) {2150 SemanticError( callExpr, "Ambiguous expression in valueE..." );2151 }2152 CandidateRef & choice = winners.front();2153 return choice->expr;2154 }2155 2156 2140 const ast::Expr * createCondExpr( const ast::Expr * expr ) { 2157 2141 assert( expr ); -
src/ResolvExpr/CandidateFinder.hpp
r164a6b6 rc333ed2 70 70 const ast::Expr * expr, Cost & cost ); 71 71 72 /// Get the valueE application that returns the enum's value.73 const ast::Expr * getValueEnumCall( const ast::Expr * expr,74 const ResolveContext & context, const ast::TypeEnvironment & env );75 76 72 /// Wrap an expression to convert the result to a conditional result. 77 73 const ast::Expr * createCondExpr( const ast::Expr * expr ); -
src/ResolvExpr/CastCost.cc
r164a6b6 rc333ed2 54 54 cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env ); 55 55 if ( Cost::unsafe < cost ) { 56 if (auto enumInst = 57 assert(enumInst->base->base);58 cost = Cost::unsafe;56 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) { 57 // Always explict cast only for typed enum 58 if (enumInst->base->isTyped) cost = Cost::unsafe; 59 59 } 60 60 } … … 63 63 64 64 void postvisit( const ast::ZeroType * zero ) { 65 // auto ptr = dynamic_cast< const ast::PointerType * >( dst );66 // if ( ptr && basicType->isInteger() ) {67 // // needed for, e.g. unsigned long => void *68 // cost = Cost::unsafe;69 // } else {70 65 cost = conversionCost( zero, dst, srcIsLvalue, symtab, env ); 71 66 if ( Cost::unsafe < cost ) { 72 67 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) { 73 assert(enumInst->base->base); 74 cost = Cost::unsafe; 68 if (enumInst->base->isTyped) cost = Cost::unsafe; 75 69 } 76 70 } 77 // }78 71 } 79 72 80 73 void postvisit( const ast::OneType * one ) { 81 // auto ptr = dynamic_cast< const ast::PointerType * >( dst );82 // if ( ptr && basicType->isInteger() ) {83 // // needed for, e.g. unsigned long => void *84 // cost = Cost::unsafe;85 // } else {86 74 cost = conversionCost( one, dst, srcIsLvalue, symtab, env ); 87 75 if ( Cost::unsafe < cost ) { 88 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) { 89 assert(enumInst->base->base); 90 cost = Cost::unsafe; 76 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) { 77 if (enumInst->base->isTyped) cost = Cost::unsafe; 91 78 } 92 79 } 93 // }94 80 } 95 81 -
src/ResolvExpr/CommonType.cc
r164a6b6 rc333ed2 650 650 651 651 void postvisit( const ast::EnumInstType * enumInst ) { 652 if ( enumInst->base && !enumInst->base-> base) {652 if ( enumInst->base && !enumInst->base->isTyped ) { 653 653 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt ); 654 654 result = commonType( basicType, type2, tenv, need, have, open, widen); -
src/ResolvExpr/ConversionCost.cc
r164a6b6 rc333ed2 283 283 cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); 284 284 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 285 if ( dstAsEnumInst->base && !dstAsEnumInst->base-> base) {285 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 286 286 cost = Cost::unsafe; 287 287 } … … 480 480 // assuming 0p is supposed to be used for pointers? 481 481 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 482 if ( dstAsEnumInst->base && !dstAsEnumInst->base-> base) {482 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 483 483 cost = Cost::unsafe; 484 484 } … … 501 501 } 502 502 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 503 if ( dstAsEnumInst->base && !dstAsEnumInst->base-> base) {503 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { 504 504 cost = Cost::unsafe; 505 505 }
Note: See TracChangeset
for help on using the changeset viewer.