Changeset 59c8dff for src/AST


Ignore:
Timestamp:
Jan 19, 2024, 2:42:58 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
f988834
Parents:
8b4faf6
Message:

Draft Implementation for enum position pesudo function (posE). EnumPosExpr is mostly irrelevant for now. It is used in development/code probing and will be removed later

Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Expr.cpp

    r8b4faf6 r59c8dff  
    307307}
    308308
     309//
     310
     311// --- EnumPosExpr
     312EnumPosExpr::EnumPosExpr( const CodeLocation & loc, const EnumInstType * ty)
     313: Expr( loc, new BasicType{ BasicType::UnsignedInt }), type( ty ) {
     314        assert( ty );
     315}
     316
     317EnumPosExpr::EnumPosExpr( const CodeLocation & loc, const Expr * expr )
     318: Expr( loc, new BasicType{ BasicType::UnsignedInt }), expr(expr) {
     319        assert( expr );
     320}
     321
     322
    309323// --- LogicalExpr
    310324
  • src/AST/Expr.hpp

    r8b4faf6 r59c8dff  
    548548};
    549549
     550class EnumPosExpr final : public Expr {
     551public:
     552        ptr<EnumInstType> type;
     553        ptr<Expr> expr;
     554       
     555        EnumPosExpr( const CodeLocation & loc, const EnumInstType * ty );
     556        EnumPosExpr( const CodeLocation & loc, const Expr * expr );
     557        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     558private:
     559        EnumPosExpr * clone() const override { return new EnumPosExpr{ *this }; }
     560        MUTATE_FRIEND
     561};
     562
    550563/// Variants of short-circuiting logical expression
    551564enum LogicalFlag { OrExpr, AndExpr };
  • src/AST/Fwd.hpp

    r8b4faf6 r59c8dff  
    8989class OffsetofExpr;
    9090class OffsetPackExpr;
     91class EnumPosExpr;
    9192class LogicalExpr;
    9293class ConditionalExpr;
  • src/AST/Node.cpp

    r8b4faf6 r59c8dff  
    232232template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::weak >;
    233233template class ast::ptr_base< ast::OffsetPackExpr, ast::Node::ref_type::strong >;
     234template class ast::ptr_base< ast::EnumPosExpr, ast::Node::ref_type::weak >;
     235template class ast::ptr_base< ast::EnumPosExpr, ast::Node::ref_type::strong >;
    234236template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::weak >;
    235237template class ast::ptr_base< ast::LogicalExpr, ast::Node::ref_type::strong >;
  • src/AST/Pass.hpp

    r8b4faf6 r59c8dff  
    191191        const ast::Expr *             visit( const ast::OffsetofExpr         * ) override final;
    192192        const ast::Expr *             visit( const ast::OffsetPackExpr       * ) override final;
     193        const ast::Expr *             visit( const ast::EnumPosExpr          * ) override final;
    193194        const ast::Expr *             visit( const ast::LogicalExpr          * ) override final;
    194195        const ast::Expr *             visit( const ast::ConditionalExpr      * ) override final;
  • src/AST/Pass.impl.hpp

    r8b4faf6 r59c8dff  
    14521452
    14531453//--------------------------------------------------------------------------
     1454// EnumPosExpr
     1455template< typename core_t>
     1456const ast::Expr * ast::Pass< core_t >::visit( const ast::EnumPosExpr * node ) {
     1457        VISIT_START( node );
     1458
     1459        if ( __visit_children() ) {
     1460                guard_symtab guard { *this };
     1461                maybe_accept( node, &EnumPosExpr::type );
     1462                maybe_accept( node, &EnumPosExpr::expr );
     1463        }
     1464
     1465        VISIT_END( Expr, node );
     1466}
     1467
     1468//--------------------------------------------------------------------------
    14541469// LogicalExpr
    14551470template< typename core_t >
  • src/AST/Print.cpp

    r8b4faf6 r59c8dff  
    11831183        }
    11841184
     1185        virtual const ast::Expr * visit( const ast::EnumPosExpr * node ) override final {
     1186                os << "Enum Position Expression on: ";
     1187                ++indent;
     1188                safe_print( node->type );
     1189                --indent;
     1190                postprint( node );
     1191                return node;
     1192        }
     1193
    11851194        virtual const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    11861195                os << "Short-circuited operation (" << (node->isAnd ? "and" : "or") << ") on: ";
  • src/AST/Visitor.hpp

    r8b4faf6 r59c8dff  
    7979    virtual const ast::Expr *             visit( const ast::OffsetofExpr         * ) = 0;
    8080    virtual const ast::Expr *             visit( const ast::OffsetPackExpr       * ) = 0;
     81    virtual const ast::Expr *             visit( const ast::EnumPosExpr          * ) = 0;
    8182    virtual const ast::Expr *             visit( const ast::LogicalExpr          * ) = 0;
    8283    virtual const ast::Expr *             visit( const ast::ConditionalExpr      * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.