Changeset 02c80cdc for src/ResolvExpr


Ignore:
Timestamp:
Apr 19, 2024, 11:30:55 AM (23 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master, stuck-waitfor-destruct
Children:
358e1152, 4e08a54
Parents:
d4264e8 (diff), 19313be5 (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:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    rd4264e8 r02c80cdc  
    513513                                        // add new result
    514514                                        assert( common );
    515                                         // auto attrType = common.as<ast::EnumAttrType>();
    516                                         // if ( attrType && ( attrType->attr == ast::EnumAttribute::Value ) ) {
    517                                         //      auto callExpr = new ast::UntypedExpr(
    518                                         //              expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
    519                                         //      CandidateFinder finder( context, env );
    520                                         //      finder.find( callExpr );
    521                                         //      CandidateList winners = findMinCost( finder.candidates );
    522                                         //      if (winners.size() != 1) {
    523                                         //              SemanticError( callExpr, "Ambiguous expression in valueE" );
    524                                         //      }
    525                                         //      CandidateRef & choice = winners.front();
    526                                         //      choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );
    527 
    528                                         //      results.emplace_back(
    529                                         //              i, choice->expr,
    530                                         //              std::move( env ), std::move( need ), std::move( have ), std::move( open ),
    531                                         //              nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    532                                         // } else {
    533515                                                results.emplace_back(
    534516                                                        i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),
     
    921903                                CandidateList winners = findMinCost( finder.candidates );
    922904                                if (winners.size() != 1) {
    923                                         SemanticError( callExpr, "Ambiguous expression in valueE" );
     905                                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
    924906                                }
    925907                                CandidateRef & choice = winners.front();
    926                                 // choice->cost.incSafe();
     908                                choice->cost.incVar();
    927909                                candidates.emplace_back( std::move(choice) );
    928910                        }
     
    18001782                                                        CandidateList winners = findMinCost( finder.candidates );
    18011783                                                        if (winners.size() != 1) {
    1802                                                                 SemanticError( callExpr, "Ambiguous expression in valueE" );
     1784                                                                SemanticError( callExpr, "Ambiguous expression in valueE..." );
    18031785                                                        }
    18041786                                                        CandidateRef & choice = winners.front();
     
    21502132}
    21512133
    2152 const ast::Expr * getValueEnumCall( const ast::Expr * expr,
    2153                 const ResolveContext & context, const ast::TypeEnvironment & env ) {
    2154         auto callExpr = new ast::UntypedExpr(
    2155                 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
    2156         CandidateFinder finder( context, env );
    2157         finder.find( callExpr );
    2158         CandidateList winners = findMinCost( finder.candidates );
    2159         if (winners.size() != 1) {
    2160                 SemanticError( callExpr, "Ambiguous expression in valueE" );
    2161         }
    2162         CandidateRef & choice = winners.front();
    2163         return choice->expr;
     2134// get the valueE(...) ApplicationExpr that returns the enum value
     2135const ast::Expr * getValueEnumCall(
     2136        const ast::Expr * expr,
     2137        const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) {
     2138                auto callExpr = new ast::UntypedExpr(
     2139                        expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
     2140                CandidateFinder finder( context, env );
     2141                finder.find( callExpr );
     2142                CandidateList winners = findMinCost( finder.candidates );
     2143                if (winners.size() != 1) {
     2144                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
     2145                }
     2146                CandidateRef & choice = winners.front();
     2147                return choice->expr;
    21642148}
    21652149
     
    21762160                        }
    21772161                ),
    2178                 new ast::BasicType( ast::BasicType::SignedInt )
     2162                new ast::BasicType( ast::BasicKind::SignedInt )
    21792163        );
    21802164}
  • src/ResolvExpr/CommonType.cc

    rd4264e8 r02c80cdc  
    3838        // GENERATED START, DO NOT EDIT
    3939        // GENERATED BY BasicTypes-gen.cc
    40         #define BT ast::BasicType::
    41         static const BT Kind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor
     40        #define BT ast::BasicKind::
     41        static const ast::BasicKind commonTypes[BT NUMBER_OF_BASIC_TYPES][BT NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor
    4242                /*                                      B                       C                      SC                      UC                      SI                     SUI
    4343                                                        I                      UI                      LI                     LUI                     LLI                    LLUI
     
    339339        // GENERATED END
    340340        static_assert(
    341                 sizeof(commonTypes)/sizeof(commonTypes[0][0]) == ast::BasicType::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,
     341                sizeof(commonTypes)/sizeof(commonTypes[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,
    342342                "Each basic type kind should have a corresponding row in the combined type matrix"
    343343        );
     
    366366        void postvisit( const ast::BasicType * basic ) {
    367367                if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) {
    368                         ast::BasicType::Kind kind;
     368                        ast::BasicKind kind;
    369369                        if (basic->kind != basic2->kind && !widen.first && !widen.second) return;
    370370                        else if (!widen.first) kind = basic->kind; // widen.second
     
    386386                        const ast::EnumDecl* enumDecl = enumInst->base;
    387387                        if ( !enumDecl->base ) {
    388                                 ast::BasicType::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ];
     388                                ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
    389389                                if (
    390390                                        ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
     
    398398                } else if ( auto type2AsAttr = dynamic_cast< const ast::EnumAttrType * >( type2 ) ) {
    399399            if ( type2AsAttr->attr == ast::EnumAttribute::Posn ) {
    400                             ast::BasicType::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ];
     400                            ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ];
    401401                            if (
    402402                                    ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers )
     
    649649        void postvisit( const ast::EnumInstType * enumInst ) {
    650650                if ( enumInst->base && !enumInst->base->base ) {
    651                         auto basicType = new ast::BasicType( ast::BasicType::UnsignedInt );
     651                        auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt );
    652652                        result = commonType( basicType, type2, tenv, need, have, open, widen);
    653653                }
     
    674674                } else if ( widen.second && dynamic_cast< const ast::OneType * >( type2 ) ) {
    675675                        result = new ast::BasicType{
    676                                 ast::BasicType::SignedInt, zero->qualifiers | type2->qualifiers };
     676                                ast::BasicKind::SignedInt, zero->qualifiers | type2->qualifiers };
    677677                } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
    678678                        const ast::EnumDecl * enumDecl = enumInst->base;
     
    695695                } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) {
    696696                        result = new ast::BasicType{
    697                                 ast::BasicType::SignedInt, one->qualifiers | type2->qualifiers };
     697                                ast::BasicKind::SignedInt, one->qualifiers | type2->qualifiers };
    698698                } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) {
    699699                        const ast::EnumDecl * enumDecl = enumInst->base;
  • src/ResolvExpr/ConversionCost.cc

    rd4264e8 r02c80cdc  
    5959        // GENERATED START, DO NOT EDIT
    6060        // GENERATED BY BasicTypes-gen.cc
    61         static const int costMatrix[ast::BasicType::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // path length from root to node
     61        static const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node
    6262                /*               B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
    6363                /*      B */ {   0,   1,   1,   2,   2,   3,   3,   4,   4,   5,   5,   6,   6,   7,   7,   8,   8,   9,   9,  10,  10,  11,  11,  12,  12,  13,  13,  14,  14,  15,  15,  16,  17,  16,  18,  17, },
     
    101101        // GENERATED END
    102102        static_assert(
    103                 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::BasicType::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,
     103                sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,
    104104                "Missing row in the cost matrix"
    105105        );
     
    107107        // GENERATED START, DO NOT EDIT
    108108        // GENERATED BY BasicTypes-gen.cc
    109         static const int signMatrix[ast::BasicType::NUMBER_OF_BASIC_TYPES][ast::BasicType::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion
     109        static const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion
    110110                /*               B    C   SC   UC   SI  SUI    I   UI   LI  LUI  LLI LLUI   IB  UIB  _FH  _FH   _F  _FC    F   FC  _FX _FXC   FD _FDC    D   DC F80X_FDXC  F80  _FB_FLDC   FB   LD  LDC _FBX_FLDXC */
    111111                /*      B */ {   0,   0,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   1,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, },
     
    148148        // GENERATED END
    149149        static_assert(
    150                 sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::BasicType::NUMBER_OF_BASIC_TYPES * ast::BasicType::NUMBER_OF_BASIC_TYPES,
     150                sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES,
    151151                "Missing row in the sign matrix"
    152152        );
     
    279279                conversionCostFromBasicToBasic( basicType, dstAsBasic );
    280280        } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) {
    281                 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     281                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    282282                cost = costCalc( basicType, integer, srcIsLvalue, symtab, env );
    283283        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
     
    362362
    363363void ConversionCost::postvisit( const ast::EnumInstType * inst ) {
    364         if ( inst->base && inst->base->base ) {
    365                 if ( auto dstAsAttr = dynamic_cast<const ast::EnumAttrType *>( dst ) ) {
    366                         auto instAsAttr = ast::EnumAttrType( inst, dstAsAttr->attr );
    367                         if ( instAsAttr.match(dstAsAttr) ) {
    368                                 cost.incUnsafe();
    369                         }
    370 
    371                 } else if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    372                         if (inst->base && dstAsInst->base) {
    373                                 if (inst->base == dstAsInst->base) {
    374                                         cost.incUnsafe();
    375                                 }
    376                         }
    377                 } else {
    378                         auto instAsVal = ast::EnumAttrType( inst, ast::EnumAttribute::Value );
    379                         cost = costCalc( &instAsVal, dst, srcIsLvalue, symtab, env );
    380                         if ( cost < Cost::infinity ) {
    381                                 cost.incUnsafe();
     364        if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
     365                if (inst->base && dstAsInst->base) {
     366                        if (inst->base->name == dstAsInst->base->name) {
     367                                cost = Cost::zero;
     368                                return;
    382369                        }
    383370                }
    384371                return;
    385         } 
    386         static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     372        }
     373        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    387374        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    388375        if ( cost < Cost::unsafe ) {
     
    393380void ConversionCost::postvisit( const ast::EnumAttrType * src ) {
    394381    auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst);
    395     if ( src->attr == ast::EnumAttribute::Label ) {
    396         if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Label ) {
    397             cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    398         }
    399         // Add Conversion To String
    400     } else if ( src->attr == ast::EnumAttribute::Value ) {
     382        assert( src->attr != ast::EnumAttribute::Label );
     383    if ( src->attr == ast::EnumAttribute::Value ) {
    401384        if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) {
    402385            cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
     
    413396                    if ( cost < Cost::unsafe ) cost.incSafe();
    414397            } else {
    415                     static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     398                    static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    416399                    cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    417400                    if ( cost < Cost::unsafe ) {
     
    478461        } else if ( const ast::BasicType * dstAsBasic =
    479462                        dynamic_cast< const ast::BasicType * >( dst ) ) {
    480                 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ];
     463                int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ];
    481464                if ( -1 == tableResult ) {
    482465                        cost = Cost::unsafe;
     
    484467                        cost = Cost::zero;
    485468                        cost.incSafe( tableResult + 1 );
    486                         cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
     469                        cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] );
    487470                }
    488471                // this has the effect of letting any expr such as x+0, x+1 to be typed
     
    510493        } else if ( const ast::BasicType * dstAsBasic =
    511494                        dynamic_cast< const ast::BasicType * >( dst ) ) {
    512                 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ];
     495                int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ];
    513496                if ( -1 == tableResult ) {
    514497                        cost = Cost::unsafe;
     
    516499                        cost = Cost::zero;
    517500                        cost.incSafe( tableResult + 1 );
    518                         cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
     501                        cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] );
    519502                }
    520503        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
  • src/ResolvExpr/PtrsCastable.cc

    rd4264e8 r02c80cdc  
    100100                                result = 1;
    101101                        } else if ( auto bt = dynamic_cast< const ast::BasicType * >( dst ) ) {
    102                                 if ( bt->kind == ast::BasicType::SignedInt ) {
     102                                if ( bt->kind == ast::BasicKind::SignedInt ) {
    103103                                        result = 0;
    104104                                } else {
  • src/ResolvExpr/ResolveTypeof.cc

    rd4264e8 r02c80cdc  
    6363                        if ( newType.as< ast::EnumInstType >() ) {
    6464                                newType = new ast::BasicType(
    65                                         ast::BasicType::SignedInt, newType->qualifiers, copy(newType->attributes) );
     65                                        ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) );
    6666                        }
    6767                        reset_qualifiers(
     
    9191                auto mutType = mutate(arrayType);
    9292                auto globalSizeType = context.global.sizeType;
    93                 ast::ptr<ast::Type> sizetype = globalSizeType ? globalSizeType : new ast::BasicType(ast::BasicType::LongUnsignedInt);
     93                ast::ptr<ast::Type> sizetype = globalSizeType ? globalSizeType : new ast::BasicType( ast::BasicKind::LongUnsignedInt );
    9494                mutType->dimension = findSingleExpression(arrayType->dimension, sizetype, context );
    9595
  • src/ResolvExpr/Resolver.cc

    rd4264e8 r02c80cdc  
    351351        bool isCharType( const ast::Type * t ) {
    352352                if ( auto bt = dynamic_cast< const ast::BasicType * >( t ) ) {
    353                         return bt->kind == ast::BasicType::Char
    354                                 || bt->kind == ast::BasicType::SignedChar
    355                                 || bt->kind == ast::BasicType::UnsignedChar;
     353                        return bt->kind == ast::BasicKind::Char
     354                                || bt->kind == ast::BasicKind::SignedChar
     355                                || bt->kind == ast::BasicKind::UnsignedChar;
    356356                }
    357357                return false;
     
    458458                        if (attr->params.size() == 1) {
    459459                                auto arg = attr->params.front();
    460                                 auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::BasicType::LongLongSignedInt ), context );
     460                                auto resolved = ResolvExpr::findSingleExpression( arg, new ast::BasicType( ast::BasicKind::LongLongSignedInt ), context );
    461461                                auto result = eval(arg);
    462462
     
    624624                        objectDecl = fixObjectType( objectDecl, context );
    625625                        currentObject = ast::CurrentObject{
    626                                 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     626                                objectDecl->location, new ast::BasicType{ ast::BasicKind::SignedInt } };
    627627                }
    628628        } else {
     
    10951095                // resolve the timeout as a size_t, the conditions like IfStmt, and stmts normally
    10961096                ast::ptr< ast::Type > target =
    1097                         new ast::BasicType{ ast::BasicType::LongLongUnsignedInt };
     1097                        new ast::BasicType{ ast::BasicKind::LongLongUnsignedInt };
    10981098                auto timeout_time = findSingleExpression( stmt->timeout_time, target, context );
    10991099                auto timeout_cond = findCondExpression( stmt->timeout_cond, context );
Note: See TracChangeset for help on using the changeset viewer.