Changeset 7a780ad for src/ResolvExpr


Ignore:
Timestamp:
Apr 18, 2024, 5:19:17 PM (3 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
38093ae
Parents:
60c5b6d
Message:

Moved ast::BasicType::Kind to ast::BasicKind? in its own hearder. This is more consistent with other utility enums (although we still use this as a enum class) and reduces what some files need to include. Also did a upgrade in a comment with MAX_INTEGER_TYPE, it is now part of the enum.

Location:
src/ResolvExpr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r60c5b6d r7a780ad  
    21762176                        }
    21772177                ),
    2178                 new ast::BasicType( ast::BasicType::SignedInt )
     2178                new ast::BasicType( ast::BasicKind::SignedInt )
    21792179        );
    21802180}
  • src/ResolvExpr/CommonType.cc

    r60c5b6d r7a780ad  
    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

    r60c5b6d r7a780ad  
    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 ) ) {
     
    383383                }
    384384                return;
    385         } 
    386         static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     385        }
     386        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    387387        cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    388388        if ( cost < Cost::unsafe ) {
     
    396396        if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Label ) {
    397397            cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env );
    398         } 
     398        }
    399399        // Add Conversion To String
    400400    } else if ( src->attr == ast::EnumAttribute::Value ) {
     
    413413                    if ( cost < Cost::unsafe ) cost.incSafe();
    414414            } else {
    415                     static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
     415                    static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    416416                    cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    417417                    if ( cost < Cost::unsafe ) {
     
    478478        } else if ( const ast::BasicType * dstAsBasic =
    479479                        dynamic_cast< const ast::BasicType * >( dst ) ) {
    480                 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ];
     480                int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ];
    481481                if ( -1 == tableResult ) {
    482482                        cost = Cost::unsafe;
     
    484484                        cost = Cost::zero;
    485485                        cost.incSafe( tableResult + 1 );
    486                         cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
     486                        cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] );
    487487                }
    488488                // this has the effect of letting any expr such as x+0, x+1 to be typed
     
    510510        } else if ( const ast::BasicType * dstAsBasic =
    511511                        dynamic_cast< const ast::BasicType * >( dst ) ) {
    512                 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ];
     512                int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ];
    513513                if ( -1 == tableResult ) {
    514514                        cost = Cost::unsafe;
     
    516516                        cost = Cost::zero;
    517517                        cost.incSafe( tableResult + 1 );
    518                         cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] );
     518                        cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] );
    519519                }
    520520        } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) {
  • src/ResolvExpr/PtrsCastable.cc

    r60c5b6d r7a780ad  
    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

    r60c5b6d r7a780ad  
    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

    r60c5b6d r7a780ad  
    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.