Changeset 15215f02 for src/ResolvExpr


Ignore:
Timestamp:
Apr 22, 2024, 11:37:36 PM (5 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
13de4478
Parents:
0fe07be (diff), d7c0ad5 (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:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r0fe07be r15215f02  
    14121412        }
    14131413
    1414     void Finder::postvisit(const ast::VariableExpr *variableExpr) {
    1415         // not sufficient to just pass `variableExpr` here, type might have changed
    1416 
    1417         auto cand = new Candidate(variableExpr, tenv);
    1418         candidates.emplace_back(cand);
    1419     }
     1414        void Finder::postvisit(const ast::VariableExpr *variableExpr) {
     1415                // not sufficient to just pass `variableExpr` here, type might have changed
     1416
     1417                auto cand = new Candidate(variableExpr, tenv);
     1418                candidates.emplace_back(cand);
     1419        }
    14201420
    14211421        void Finder::postvisit( const ast::ConstantExpr * constantExpr ) {
     
    21332133
    21342134// get the valueE(...) ApplicationExpr that returns the enum value
    2135 const ast::Expr * getValueEnumCall( 
    2136         const ast::Expr * expr, 
     2135const ast::Expr * getValueEnumCall(
     2136        const ast::Expr * expr,
    21372137        const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) {
    21382138                auto callExpr = new ast::UntypedExpr(
  • src/ResolvExpr/CommonType.cc

    r0fe07be r15215f02  
    397397                        }
    398398                } else if ( auto type2AsAttr = dynamic_cast< const ast::EnumAttrType * >( type2 ) ) {
    399             if ( type2AsAttr->attr == ast::EnumAttribute::Posn ) {
    400                             ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
    401                             if (
    402                                     ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
    403                                             || widen.first )
    404                                     && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers )
    405                                             || widen.second )
    406                             ) {
    407                                     result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers };
    408                             }
    409             }
     399                        if ( type2AsAttr->attr == ast::EnumAttribute::Posn ) {
     400                                ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
     401                                if (
     402                                        ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
     403                                                || widen.first )
     404                                        && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers )
     405                                                || widen.second )
     406                                ) {
     407                                        result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers };
     408                                }
     409                        }
    410410                }
    411411        }
     
    519519                                                                // xxx - assume LHS is always the target type
    520520
    521                                                                 if ( ! ((widen.second && ref2->qualifiers.is_mutex) 
     521                                                                if ( ! ((widen.second && ref2->qualifiers.is_mutex)
    522522                                                                || (ref1->qualifiers.is_mutex == ref2->qualifiers.is_mutex ))) return;
    523523
  • src/ResolvExpr/ConversionCost.cc

    r0fe07be r15215f02  
    379379
    380380void ConversionCost::postvisit( const ast::EnumAttrType * src ) {
    381     auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);
     381        auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);
    382382        assert( src->attr != ast::EnumAttribute::Label );
    383     if ( src->attr == ast::EnumAttribute::Value ) {
    384         if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
    385             cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    386         } else {
    387             auto baseType = src->instance->base->base;
    388             cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
     383        if ( src->attr == ast::EnumAttribute::Value ) {
     384                if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
     385                        cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
     386                } else {
     387                        auto baseType = src->instance->base->base;
     388                        cost = costCalc( baseType, dst, srcIsLvalue, symtab, env );
    389389                        if ( cost < Cost::infinity ) {
    390390                                cost.incUnsafe();
    391391                        }
    392         }
    393     } else { // ast::EnumAttribute::Posn
    394         if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    395                     cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );
    396                     if ( cost < Cost::unsafe ) cost.incSafe();
    397             } else {
    398                     static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    399                     cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    400                     if ( cost < Cost::unsafe ) {
    401                             cost.incSafe();
    402                     }
    403             }
    404     }
     392                }
     393        } else { // ast::EnumAttribute::Posn
     394                if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
     395                        cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env );
     396                        if ( cost < Cost::unsafe ) cost.incSafe();
     397                } else {
     398                        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
     399                        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
     400                        if ( cost < Cost::unsafe ) {
     401                                cost.incSafe();
     402                        }
     403                }
     404        }
    405405}
    406406
  • src/ResolvExpr/PolyCost.cc

    r0fe07be r15215f02  
    2929        const ast::TypeEnvironment &env_;
    3030
    31         PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 
     31        PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )
    3232        : symtab( symtab ), result( 0 ), env_( env ) {}
    3333
    3434        void previsit( const ast::TypeInstType * type ) {
    35                 if ( const ast::EqvClass * eqv = env_.lookup( *type ) ) /* && */ if ( eqv->bound ) {
     35                if ( const ast::EqvClass * eqv = env_.lookup( *type ) ; eqv && eqv->bound ) {
    3636                        if ( const ast::TypeInstType * otherType = eqv->bound.as< ast::TypeInstType >() ) {
    3737                                if ( symtab.lookupType( otherType->name ) ) {
    3838                                        // Bound to opaque type.
    39                                         result += 1;
     39                                        result = 1;
    4040                                }
    4141                        } else {
    4242                                // Bound to concrete type.
    43                                 result += 1;
     43                                result = 1;
    4444                        }
    4545                }
     
    5252        const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env
    5353) {
    54         ast::Pass<PolyCost> costing( symtab, env );
    55         type->accept( costing );
    56         return (costing.core.result > 0) ? 1 : 0;
     54        return ast::Pass<PolyCost>::read( type, symtab, env );
    5755}
    5856
  • src/ResolvExpr/Unify.cc

    r0fe07be r15215f02  
    307307                                // type unification calls expression unification (mutual recursion)
    308308                                if ( ! unify(array->dimension, array2->dimension,
    309                                     tenv, need, have, open, widen) ) return;
     309                                        tenv, need, have, open, widen) ) return;
    310310                        }
    311311
     
    455455                        // check that the other type is compatible and named the same
    456456                        auto otherInst = dynamic_cast< const XInstType * >( other );
    457                         if (otherInst && inst->name == otherInst->name) 
     457                        if (otherInst && inst->name == otherInst->name)
    458458                                this->result = otherInst;
    459459                        return otherInst;
     
    542542                        // Lazy approach for now
    543543                        if ( auto otherPos = dynamic_cast< const ast::EnumAttrType *>(type2) ) {
    544                             if ( enumAttr->match(otherPos) ) {
    545                                     result = otherPos;
    546                             }
    547             } 
     544                                if ( enumAttr->match(otherPos) ) {
     545                                        result = otherPos;
     546                                }
     547                        }
    548548                }
    549549
Note: See TracChangeset for help on using the changeset viewer.