Changes in / [9e72bae3:a750c71b]


Ignore:
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r9e72bae3 ra750c71b  
    283283: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {}
    284284
     285// --- CountExpr
     286
     287CountExpr::CountExpr( const CodeLocation & loc, const Expr * e )
     288: Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), expr(e), type( nullptr ) {}
     289
     290CountExpr::CountExpr( const CodeLocation & loc, const Type * t )
     291: Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), expr(nullptr), type( t ) {}
     292
    285293// --- AlignofExpr
    286294
    287295AlignofExpr::AlignofExpr( const CodeLocation & loc, const Type * t )
    288296: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), type( t ) {}
    289 
    290 // --- CountofExpr
    291 
    292 CountofExpr::CountofExpr( const CodeLocation & loc, const Type * t )
    293 : Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}
    294297
    295298// --- OffsetofExpr
  • src/AST/Expr.hpp

    r9e72bae3 ra750c71b  
    490490};
    491491
     492class CountExpr final : public Expr {
     493public:
     494        ptr<Expr> expr;
     495        ptr<Type> type;
     496
     497        CountExpr( const CodeLocation & loc, const Expr * t );
     498        CountExpr( const CodeLocation & loc, const Type * t );
     499
     500        const Expr * accept( Visitor & v )const override { return v.visit( this ); }
     501private:
     502        CountExpr * clone() const override { return new CountExpr( *this ); }
     503        MUTATE_FRIEND
     504};
     505
    492506/// alignof expression, e.g. `alignof(int)`, `alignof 3+4`
    493507class AlignofExpr final : public Expr {
     
    500514private:
    501515        AlignofExpr * clone() const override { return new AlignofExpr{ *this }; }
    502         MUTATE_FRIEND
    503 };
    504 
    505 /// countof expression, e.g. `countof(AnEnum)`, `countof pred(Head)`
    506 class CountofExpr final : public Expr {
    507 public:
    508         ptr<Type> type;
    509 
    510         CountofExpr( const CodeLocation & loc, const Type * t );
    511 
    512         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    513 private:
    514         CountofExpr * clone() const override { return new CountofExpr( *this ); }
    515516        MUTATE_FRIEND
    516517};
  • src/AST/Fwd.hpp

    r9e72bae3 ra750c71b  
    8686class ConstantExpr;
    8787class SizeofExpr;
     88class CountExpr;
    8889class AlignofExpr;
    89 class CountofExpr;
    9090class UntypedOffsetofExpr;
    9191class OffsetofExpr;
  • src/AST/Pass.hpp

    r9e72bae3 ra750c71b  
    173173        const ast::Expr *             visit( const ast::ConstantExpr         * ) override final;
    174174        const ast::Expr *             visit( const ast::SizeofExpr           * ) override final;
     175        const ast::Expr *             visit( const ast::CountExpr            * ) override final;
    175176        const ast::Expr *             visit( const ast::AlignofExpr          * ) override final;
    176         const ast::Expr *             visit( const ast::CountofExpr          * ) override final;
    177177        const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) override final;
    178178        const ast::Expr *             visit( const ast::OffsetofExpr         * ) override final;
  • src/AST/Pass.impl.hpp

    r9e72bae3 ra750c71b  
    13501350
    13511351//--------------------------------------------------------------------------
     1352// CountExpr
     1353template< typename core_t >
     1354const ast::Expr * ast::Pass< core_t >::visit( const ast::CountExpr * node ) {
     1355        VISIT_START( node );
     1356        if ( __visit_children() ) {
     1357                {
     1358                        guard_symtab guard { *this };
     1359                        maybe_accept( node, &CountExpr::result );
     1360                }
     1361                if ( node->type ) {
     1362                        maybe_accept( node, &CountExpr::type );
     1363                } else {
     1364                        maybe_accept( node, &CountExpr::expr );
     1365                }
     1366        }
     1367        VISIT_END( Expr, node );
     1368}
     1369
     1370//--------------------------------------------------------------------------
    13521371// AlignofExpr
    13531372template< typename core_t >
     
    13611380                }
    13621381                maybe_accept( node, &AlignofExpr::type );
    1363         }
    1364 
    1365         VISIT_END( Expr, node );
    1366 }
    1367 
    1368 //--------------------------------------------------------------------------
    1369 // CountofExpr
    1370 template< typename core_t >
    1371 const ast::Expr * ast::Pass< core_t >::visit( const ast::CountofExpr * node ) {
    1372         VISIT_START( node );
    1373 
    1374         if ( __visit_children() ) {
    1375                 {
    1376                         guard_symtab guard { *this };
    1377                         maybe_accept( node, &CountofExpr::result );
    1378                 }
    1379                 maybe_accept( node, &CountofExpr::type );
    13801382        }
    13811383
  • src/AST/Print.cpp

    r9e72bae3 ra750c71b  
    12071207        }
    12081208
    1209         virtual const ast::Expr * visit( const ast::CountofExpr * node ) override final {
     1209        virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
    12101210                os << "Count Expression on: ";
    12111211                ++indent;
    1212                 safe_print( node->type );
     1212                if ( node->type ) node->type->accept( *this );
     1213                else safe_print( node->expr );
    12131214                --indent;
    12141215                postprint( node );
  • src/AST/Visitor.hpp

    r9e72bae3 ra750c71b  
    7676    virtual const ast::Expr *             visit( const ast::ConstantExpr         * ) = 0;
    7777    virtual const ast::Expr *             visit( const ast::SizeofExpr           * ) = 0;
     78    virtual const ast::Expr *             visit( const ast::CountExpr            * ) = 0;
    7879    virtual const ast::Expr *             visit( const ast::AlignofExpr          * ) = 0;
    79     virtual const ast::Expr *             visit( const ast::CountofExpr          * ) = 0;
    8080    virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) = 0;
    8181    virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) = 0;
  • src/Common/CodeLocationTools.cpp

    r9e72bae3 ra750c71b  
    154154    macro(ConstantExpr, Expr) \
    155155    macro(SizeofExpr, Expr) \
     156    macro(CountExpr, Expr ) \
    156157    macro(AlignofExpr, Expr) \
    157     macro(CountofExpr, Expr ) \
    158158    macro(UntypedOffsetofExpr, Expr) \
    159159    macro(OffsetofExpr, Expr) \
  • src/Parser/parser.yy

    r9e72bae3 ra750c71b  
    946946                }
    947947        | COUNTOF unary_expression
    948                 { $$ = new ExpressionNode( new ast::CountofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 ) ) ) ); }
     948                { $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuild( $2 ) ) ); }
    949949        | COUNTOF '(' type_no_function ')'
    950                 { $$ = new ExpressionNode( new ast::CountofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
     950                { $$ = new ExpressionNode( new ast::CountExpr( yylloc, maybeMoveBuildType( $3 ) ) ); }
    951951        ;
    952952
  • src/ResolvExpr/CandidateFinder.cpp

    r9e72bae3 ra750c71b  
    672672                void postvisit( const ast::SizeofExpr * sizeofExpr );
    673673                void postvisit( const ast::AlignofExpr * alignofExpr );
    674                 void postvisit( const ast::CountofExpr * countExpr );
    675674                void postvisit( const ast::AddressExpr * addressExpr );
    676675                void postvisit( const ast::LabelAddressExpr * labelExpr );
     
    698697                void postvisit( const ast::UntypedInitExpr * initExpr );
    699698                void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
     699                void postvisit( const ast::CountExpr * countExpr );
    700700
    701701                void postvisit( const ast::InitExpr * ) {
     
    941941                }
    942942        }
     943       
    943944
    944945        /// Adds aggregate member interpretations
     
    12681269                                        ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env )
    12691270                                        : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env );
    1270 
     1271                       
    12711272                        // Redefine enum cast
    12721273                        auto argAsEnum = fromType.as<ast::EnumInstType>();
     
    14921493        }
    14931494
    1494         void Finder::postvisit( const ast::CountofExpr * countExpr ) {
    1495                 if ( auto enumInst = countExpr->type.as<ast::EnumInstType>() ) {
    1496                         addCandidate( ast::ConstantExpr::from_ulong( countExpr->location, enumInst->base->members.size()), tenv );
    1497                         return;
    1498                 }
    1499                 auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
    1500                 auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
    1501                 const ast::UntypedExpr * untyped = ast::UntypedExpr::createCall(
    1502                         countExpr->location, "Countof", { castFirst }
     1495        void Finder::postvisit( const ast::CountExpr * countExpr ) {
     1496                const ast::UntypedExpr * untyped = nullptr;
     1497                if ( countExpr->type ) {
     1498                        auto enumInst = countExpr->type.as<ast::EnumInstType>();
     1499                        if ( enumInst ) {
     1500                                addCandidate( ast::ConstantExpr::from_ulong(countExpr->location, enumInst->base->members.size()), tenv );
     1501                                return;
     1502                        }
     1503                        auto untypedFirst = ast::UntypedExpr::createCall( countExpr->location, "lowerBound", {} );
     1504                        auto castFirst = new ast::CastExpr( countExpr->location, untypedFirst , countExpr->type );
     1505                        untyped = ast::UntypedExpr::createCall(
     1506                                countExpr->location, "Countof", { castFirst }
     1507                        );
     1508                }
     1509                if (!untyped) untyped = ast::UntypedExpr::createCall(
     1510                                countExpr->location, "Countof", { countExpr->expr }
    15031511                );
    15041512                CandidateFinder finder( context, tenv );
     
    15061514                CandidateList winners = findMinCost( finder.candidates );
    15071515                if ( winners.size() == 0 ) {
    1508                         SemanticError( countExpr, "Countof is not implemented: " );
    1509                 }
    1510                 if ( winners.size() != 1 ) {
    1511                         SemanticError( countExpr, "Ambiguous expression in countof: " );
     1516                        SemanticError( countExpr->expr, "Countof is not implemented for operand: " );
     1517                }
     1518                if ( winners.size() !=  1 ) {
     1519                        SemanticError( countExpr->expr, "Ambiguous expression in countof operand: " );
    15121520                }
    15131521                CandidateRef & choice = winners.front();
  • tests/array-collections/boxed.bookend.cfa

    r9e72bae3 ra750c71b  
    2727static char * bookend_hi = 0p;
    2828
    29 // bookend pointers are set to stack addresses and compared (but not dereferenced)
    30 // after their functions exit; they are "dangling"
    31 #pragma GCC diagnostic push
    32 #pragma GCC diagnostic ignored "-Wpragmas" // -Wdangling-pointer unrecognized until GCC 12
    33 #pragma GCC diagnostic ignored "-Wdangling-pointer"
    34 
    3529void bookendInner( void ) {
    3630    char var = 'x';
     
    4135#define TC(...)
    4236#define TR( TRID, SZS, SZV, ETG, ACCS, SPS, OVLD ) \
    43     F_SIG( bookendOuter, TRID, SZS, SZV, ACCS, SPS, OVLD ) {                         \
     37    F_SIG( bookendOuter, TRID, SZS, SZV, ACCS, SPS, OVLD ) {                                  \
    4438        char var = 'x';                                                              \
    4539        (void) var;                                                                  \
    4640        bookend_hi = & var;                                                          \
    47         return CALL( allocAndAccess, TRID, SZS, n, expectedElmSz, tcid, vart );      \
     41        return CALL( allocAndAccess, TRID, SZS, n, expectedElmSz, tcid, vart );     \
    4842    }
    4943#include "boxed.cases.hfa"
    5044#undef TC
    5145#undef TR
    52 
    53 #pragma GCC diagnostic pop
    5446
    5547void resetBookends( void ) {
  • tests/malloc.cfa

    r9e72bae3 ra750c71b  
    6464        free( ip );
    6565
    66   #pragma GCC diagnostic push
    67   #pragma GCC diagnostic ignored "-Wpragmas" // -Walloc-size unrecognized until GCC 14
    68   #pragma GCC diagnostic ignored "-Walloc-size"
    6966        ip = (int *)malloc( 0 );
    70   #pragma GCC diagnostic pop
    7167        test_base( ip, 0, libAlign );
    7268        test_use( ip );
Note: See TracChangeset for help on using the changeset viewer.