Changeset 69867ad9 for src/ResolvExpr


Ignore:
Timestamp:
Apr 30, 2024, 12:08:46 PM (21 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
35897fb
Parents:
caaf424 (diff), 0153dbd (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

    rcaaf424 r69867ad9  
    906906                                }
    907907                                CandidateRef & choice = winners.front();
    908                                 choice->cost.incVar();
     908                                choice->cost.incSafe();
    909909                                candidates.emplace_back( std::move(choice) );
    910910                        }
     
    13761376                        ast::Expr * newExpr = data.combine( nameExpr->location, cost );
    13771377
    1378                         bool bentConversion = false;
    1379                         if ( auto inst = newExpr->result.as<ast::EnumInstType>() ) {
    1380                                 if ( inst->base && inst->base->base ) {
    1381                                         bentConversion = true;
    1382                                 }
    1383                         }
    1384 
     1378                        // bool bentConversion = false;
     1379                        // if ( auto inst = newExpr->result.as<ast::EnumInstType>() ) {
     1380                        //      if ( inst->base && inst->base->base ) {
     1381                        //              bentConversion = true;
     1382                        //      }
     1383                        // }
     1384
     1385                        // CandidateRef newCand = std::make_shared<Candidate>(
     1386                        //      newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, bentConversion? Cost::safe: Cost::zero,
     1387                        //      cost );
    13851388                        CandidateRef newCand = std::make_shared<Candidate>(
    1386                                 newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, bentConversion? Cost::safe: Cost::zero,
     1389                                newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, Cost::zero,
    13871390                                cost );
    1388 
    13891391                        if (newCand->expr->env) {
    13901392                                newCand->env.add(*newCand->expr->env);
     
    18291831                                        Cost cost = Cost::zero;
    18301832                                        ast::Expr * newExpr = data.combine( expr->location, cost );
     1833                                        // CandidateRef newCand =
     1834                                        //      std::make_shared<Candidate>(
     1835                                        //              newExpr, copy( tenv ), ast::OpenVarSet{},
     1836                                        //              ast::AssertionSet{}, Cost::safe, cost
     1837                                        //      );
    18311838                                        CandidateRef newCand =
    18321839                                                std::make_shared<Candidate>(
    18331840                                                        newExpr, copy( tenv ), ast::OpenVarSet{},
    1834                                                         ast::AssertionSet{}, Cost::safe, cost
     1841                                                        ast::AssertionSet{}, Cost::zero, cost
    18351842                                                );
    1836 
    18371843                                        if (newCand->expr->env) {
    18381844                                                newCand->env.add(*newCand->expr->env);
  • src/ResolvExpr/CastCost.cc

    rcaaf424 r69867ad9  
    5353                        } else {
    5454                                cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env );
     55                                if ( Cost::unsafe < cost ) {
     56                                        if (auto enumInst =  dynamic_cast<const ast::EnumInstType *>(dst)) {
     57                                                assert(enumInst->base->base);
     58                                                cost = Cost::unsafe;
     59                                        }
     60                                }
    5561                        }
     62                }
     63
     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                        cost = conversionCost( zero, dst, srcIsLvalue, symtab, env );
     71                        if ( Cost::unsafe < cost ) {
     72                                if (auto enumInst =  dynamic_cast<const ast::EnumInstType *>(dst)) {
     73                                        assert(enumInst->base->base);
     74                                        cost = Cost::unsafe;
     75                                }
     76                        }
     77                        // }
     78                }
     79
     80                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                        cost = conversionCost( one, dst, srcIsLvalue, symtab, env );
     87                        if ( Cost::unsafe < cost ) {
     88                                if (auto enumInst =  dynamic_cast<const ast::EnumInstType *>(dst)) {
     89                                        assert(enumInst->base->base);
     90                                        cost = Cost::unsafe;
     91                                }
     92                        }
     93                        // }
    5694                }
    5795
     
    80118                                        cost = Cost::unsafe;
    81119                                }
     120                        }
     121                }
     122
     123                void postvist( const ast::EnumInstType * ) {
     124                        if ( auto basic = dynamic_cast< const ast::BasicType * >(dst) ) {
     125                                if ( basic->isInteger() ) cost = Cost::unsafe;
    82126                        }
    83127                }
  • src/ResolvExpr/ConversionCost.cc

    rcaaf424 r69867ad9  
    284284        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    285285                if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    286                         cost = Cost::zero;
    287                         cost.incUnsafe();
     286                        cost = Cost::unsafe;
    288287                }
    289288        }
     
    482481        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    483482                if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    484                         cost = Cost::zero;
    485                         cost.incUnsafe();
     483                        cost = Cost::unsafe;
    486484                }
    487485        }
     
    504502        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
    505503                if ( dstAsEnumInst->base && !dstAsEnumInst->base->base ) {
    506                         cost = Cost::zero;
    507                         cost.incUnsafe();
     504                        cost = Cost::unsafe;
    508505                }
    509506        }
Note: See TracChangeset for help on using the changeset viewer.