Changeset 10a9479d for src/ResolvExpr


Ignore:
Timestamp:
Nov 23, 2024, 8:28:37 PM (14 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
956b389
Parents:
b006c51e (diff), de7b7a5 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    rb006c51e r10a9479d  
    12201220                        finder.allowVoid = true;
    12211221                }
    1222                 if ( castExpr->kind == ast::CastExpr::Return ) {
     1222                if ( ast::ReturnCast == castExpr->kind ) {
    12231223                        finder.strictMode = true;
    12241224                        finder.find( castExpr->arg, ResolveMode::withAdjustment() );
  • src/ResolvExpr/ConversionCost.cpp

    rb006c51e r10a9479d  
    250250                        newSrc = new ast::BasicType( ast::BasicKind::UnsignedInt );
    251251                }
     252                if (dstAsRef->base->is_const() ) {
     253                        auto cvtCost = conversionCost(newSrc, dstAsRef->base, srcIsLvalue, symtab, env) ;
     254                        if (cvtCost == Cost::zero) { // exact match, may use a lvalue src
     255                                if ( srcIsLvalue ) {
     256                                        if ( src->qualifiers == dstAsRef->base->qualifiers ) {
     257                                                return Cost::reference;
     258                                        } else if ( src->qualifiers < dstAsRef->base->qualifiers ) {
     259                                                return Cost::safe;
     260                                        } else {
     261                                                return Cost::unsafe;
     262                                        }
     263                                }
     264                                else {
     265                                        return Cost::reference;
     266                                }
     267                        }
     268                        else { // not exact match, conversion is needed so lvalueness of src does not matter
     269                                return cvtCost + Cost::reference;
     270                        }
     271                }
    252272                if ( typesCompatibleIgnoreQualifiers( newSrc, dstAsRef->base, env ) ) {
    253273                        if ( srcIsLvalue ) {
     
    259279                                        return Cost::unsafe;
    260280                                }
    261                         } else if ( dstAsRef->base->is_const() ) {
    262                                 return Cost::safe;
    263                         } else {
     281                        } else { // rvalue-to-NC-ref conversion
    264282                                return Cost::unsafe;
    265283                        }
  • src/ResolvExpr/Resolver.cpp

    rb006c51e r10a9479d  
    201201                                && typesCompatible( castExpr->arg->result, castExpr->result )
    202202                        ) {
    203                                 auto argAsEnum = castExpr->arg.as<ast::EnumInstType>();
    204                                 auto resultAsEnum = castExpr->result.as<ast::EnumInstType>();
    205                                 if (argAsEnum && resultAsEnum) {
    206                                         if (argAsEnum->base->name != resultAsEnum->base->name) {
    207                                                 std::cerr << "Enum Cast: " << argAsEnum->base->name << " to " << resultAsEnum->base->name << std::endl;
    208                                                 return castExpr;
    209                                         }
     203                                ast::EnumInstType const * arg, * result;
     204                                if ( ( result = castExpr->result.as<ast::EnumInstType>() ) &&
     205                                                ( arg = castExpr->arg.as<ast::EnumInstType>() ) &&
     206                                                arg->base->name != result->base->name) {
     207                                        return castExpr;
    210208                                }
    211209                                // generated cast is the same type as its argument, remove it after keeping env
     
    377375: public ast::WithSymbolTable, public ast::WithGuards,
    378376  public ast::WithVisitorRef<Resolver>, public ast::WithShortCircuiting,
    379   public ast::WithStmtsToAdd<> {
     377  public ast::WithStmtsToAdd {
    380378
    381379        ast::ptr< ast::Type > functionReturn = nullptr;
Note: See TracChangeset for help on using the changeset viewer.