Changeset 525f7ad for src/AST


Ignore:
Timestamp:
Jun 19, 2024, 3:20:39 PM (16 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
57e43cd
Parents:
1725989
Message:
  1. Add count_e( enum_name ), a pseudo function that return the number of element in an enum; 2. Implementation of enum range loop.
Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r1725989 r525f7ad  
    282282: Expr( loc, new BasicType{ BasicKind::LongUnsignedInt } ), expr( nullptr ), type( t ) {}
    283283
     284// --- CountExpr
     285
     286CountExpr::CountExpr( const CodeLocation & loc, const Type * t )
     287: Expr( loc, new BasicType( BasicKind::LongUnsignedInt) ), type( t ) {}
     288
    284289// --- AlignofExpr
    285290
  • src/AST/Expr.hpp

    r1725989 r525f7ad  
    494494};
    495495
     496class CountExpr final : public Expr {
     497public:
     498        ptr<Type> type;
     499
     500        CountExpr( const CodeLocation & loc, const Type * t );
     501
     502        const Expr * accept( Visitor & v )const override { return v.visit( this ); }
     503private:
     504        CountExpr * clone() const override { return new CountExpr( *this ); }
     505        MUTATE_FRIEND
     506};
     507
    496508/// alignof expression, e.g. `alignof(int)`, `alignof 3+4`
    497509class AlignofExpr final : public Expr {
  • src/AST/Fwd.hpp

    r1725989 r525f7ad  
    8585class ConstantExpr;
    8686class SizeofExpr;
     87class CountExpr;
    8788class AlignofExpr;
    8889class UntypedOffsetofExpr;
  • src/AST/Pass.hpp

    r1725989 r525f7ad  
    172172        const ast::Expr *             visit( const ast::ConstantExpr         * ) override final;
    173173        const ast::Expr *             visit( const ast::SizeofExpr           * ) override final;
     174        const ast::Expr *             visit( const ast::CountExpr            * ) override final;
    174175        const ast::Expr *             visit( const ast::AlignofExpr          * ) override final;
    175176        const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) override final;
  • src/AST/Pass.impl.hpp

    r1725989 r525f7ad  
    802802                maybe_accept_top( node, &ForStmt::cond  );
    803803                maybe_accept_top( node, &ForStmt::inc   );
     804                maybe_accept_top( node, &ForStmt::range_over );
    804805                maybe_accept_as_compound( node, &ForStmt::body  );
    805806        }
     
    13231324        }
    13241325
     1326        VISIT_END( Expr, node );
     1327}
     1328
     1329//--------------------------------------------------------------------------
     1330// CountExpr
     1331template< typename core_t >
     1332const ast::Expr * ast::Pass< core_t >::visit( const ast::CountExpr * node ) {
     1333        VISIT_START( node );
     1334        if ( __visit_children() ) {
     1335                {
     1336                        guard_symtab guard { *this };
     1337                        maybe_accept( node, &CountExpr::result );
     1338                }
     1339                maybe_accept( node, &CountExpr::type );
     1340        }
    13251341        VISIT_END( Expr, node );
    13261342}
  • src/AST/Print.cpp

    r1725989 r525f7ad  
    11431143        }
    11441144
     1145        virtual const ast::Expr * visit( const ast::CountExpr * node ) override final {
     1146                os << "Count Expression on: ";
     1147                ++indent;
     1148                node->type->accept( *this );
     1149                --indent;
     1150                postprint( node );
     1151                return node;
     1152        }
     1153
    11451154        virtual const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    11461155                os << "Alignof Expression on: ";
  • src/AST/Stmt.hpp

    r1725989 r525f7ad  
    237237        ptr<Expr> cond;
    238238        ptr<Expr> inc;
     239        ptr<Expr> range_over;
    239240        ptr<Stmt> body;
    240241        ptr<Stmt> else_;
     
    242243        ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
    243244                         const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
    244                 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {}
     245                : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc),
     246                        range_over(nullptr), body(body), else_(nullptr) {}
    245247
    246248        ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
    247249                         const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} )
    248                 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {}
     250                : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc),
     251                        range_over(nullptr), body(body), else_(else_) {}
     252
     253        ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * range_over,
     254                         const Stmt * body, const Stmt * else_ )
     255                : Stmt(loc, std::move(labels)), inits(std::move(inits)), range_over(range_over), body(body), else_(else_) {}
    249256
    250257        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Visitor.hpp

    r1725989 r525f7ad  
    7575    virtual const ast::Expr *             visit( const ast::ConstantExpr         * ) = 0;
    7676    virtual const ast::Expr *             visit( const ast::SizeofExpr           * ) = 0;
     77    virtual const ast::Expr *             visit( const ast::CountExpr            * ) = 0;
    7778    virtual const ast::Expr *             visit( const ast::AlignofExpr          * ) = 0;
    7879    virtual const ast::Expr *             visit( const ast::UntypedOffsetofExpr  * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.