Changeset af746cc for src/AST


Ignore:
Timestamp:
Apr 15, 2024, 12:03:53 PM (3 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
dc58e5d
Parents:
d9bad51
Message:

Reimplement the resolution of Enum instance type

Location:
src/AST
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    rd9bad51 raf746cc  
    169169}
    170170
     171const std::string EnumDecl::getUnmangeldArrayName( const ast::EnumAttribute attr ) const {
     172                switch( attr ) {
     173                        case ast::EnumAttribute::Value: return "values_" + name ;
     174                        case ast::EnumAttribute::Label: return "labels_" + name;
     175                        default: /* Posn does not generate array */
     176                                return "";
     177                }
     178        }
     179
    171180}
    172181
  • src/AST/Decl.hpp

    rd9bad51 raf746cc  
    303303};
    304304
     305enum class EnumAttribute{ Value, Posn, Label };
    305306/// enum declaration `enum Foo { ... };`
    306307class EnumDecl final : public AggregateDecl {
     
    326327        const char * typeString() const override { return aggrString( Enum ); }
    327328
    328 
     329        const std::string getUnmangeldArrayName( const EnumAttribute attr ) const;
    329330private:
    330331        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Fwd.hpp

    rd9bad51 raf746cc  
    133133class OneType;
    134134class GlobalScopeType;
    135 class EnumPosType;
     135class EnumAttrType;
    136136
    137137class Designation;
  • src/AST/Pass.hpp

    rd9bad51 raf746cc  
    222222        const ast::Type *             visit( const ast::UnionInstType        * ) override final;
    223223        const ast::Type *             visit( const ast::EnumInstType         * ) override final;
    224         const ast::Type *             visit( const ast::EnumPosType          * ) override final;
     224        const ast::Type *             visit( const ast::EnumAttrType         * ) override final;
    225225        const ast::Type *             visit( const ast::TraitInstType        * ) override final;
    226226        const ast::Type *             visit( const ast::TypeInstType         * ) override final;
  • src/AST/Pass.impl.hpp

    rd9bad51 raf746cc  
    19861986
    19871987//--------------------------------------------------------------------------
    1988 // EnumPosType
    1989 template< typename core_t >
    1990 const ast::Type * ast::Pass< core_t >::visit( const ast::EnumPosType * node ) {
    1991         VISIT_START( node );
    1992 
     1988// EnumAttrType
     1989template< typename core_t >
     1990const ast::Type * ast::Pass< core_t >::visit( const ast::EnumAttrType * node ) {
     1991        VISIT_START( node );
    19931992        VISIT_END( Type, node );
    19941993}
  • src/AST/Print.cpp

    rd9bad51 raf746cc  
    15761576        }
    15771577
    1578         virtual const ast::Type * visit( const ast::EnumPosType * node ) override final {
    1579                 preprint( node );
    1580                 os << "enum pos with ";
     1578        virtual const ast::Type * visit( const ast::EnumAttrType * node ) override final {
     1579                preprint( node );
     1580                os << "enum attr ";
     1581        if ( node->attr == ast::EnumAttribute::Label ) {
     1582            os << "Label ";
     1583        } else if ( node->attr == ast::EnumAttribute::Value ) {
     1584            os << "Value ";
     1585        } else {
     1586            os << "Posn ";
     1587        }
    15811588                (*(node->instance)).accept( *this );
    15821589                return node;
  • src/AST/Type.hpp

    rd9bad51 raf746cc  
    362362using EnumInstType = SueInstType<EnumDecl>;
    363363
    364 class EnumPosType final : public Type {
     364class EnumAttrType final : public Type {
    365365public:
    366366        readonly<EnumInstType> instance;
    367         const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    368         EnumPosType( const EnumInstType * instance ): instance(instance) {}
     367    EnumAttribute attr;
     368        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
     369        EnumAttrType( const EnumInstType * instance, EnumAttribute attr = EnumAttribute::Posn )
     370                : instance(instance), attr(attr) {}
    369371       
    370 private:
    371         EnumPosType * clone() const override { return new EnumPosType{ *this }; }
     372    bool match( const ast::EnumAttrType * other) const {
     373        return instance->base->name == other->instance->base->name && attr == other->attr;
     374    }
     375private:
     376        EnumAttrType * clone() const override { return new EnumAttrType{ *this }; }
    372377        MUTATE_FRIEND
    373378};
  • src/AST/Visitor.hpp

    rd9bad51 raf746cc  
    119119    virtual const ast::Type *             visit( const ast::OneType              * ) = 0;
    120120    virtual const ast::Type *             visit( const ast::GlobalScopeType      * ) = 0;
    121     virtual const ast::Type *             visit( const ast::EnumPosType          * ) = 0;
     121    virtual const ast::Type *             visit( const ast::EnumAttrType         * ) = 0;
    122122    virtual const ast::Designation *      visit( const ast::Designation          * ) = 0;
    123123    virtual const ast::Init *             visit( const ast::SingleInit           * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.