Changeset 90e683b for src/AST


Ignore:
Timestamp:
Feb 3, 2025, 11:46:55 AM (8 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
54f70c6
Parents:
bbbff10
Message:

I set out to do a enum rework. It ended up being much the same and I unwound the core rework. But I hope the new names are a bit clearer and other minor fixes are helpful, so I am keeping those.

Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    rbbbff10 r90e683b  
    169169}
    170170
    171 bool EnumDecl::isTyped() const { return base; }
    172 
    173 bool EnumDecl::isOpaque() const { return isCfa && !isTyped(); }
    174 
    175171}
    176172
  • src/AST/Decl.hpp

    rbbbff10 r90e683b  
    306306enum class EnumAttribute{ Value, Posn, Label };
    307307
    308 /// enum declaration `enum Foo { ... };`
     308/// enum declaration `enum Foo { ... };` or `enum(...) Foo { ... };`
    309309class EnumDecl final : public AggregateDecl {
    310310public:
     
    317317        std::vector< ast::ptr<ast::EnumInstType>> inlinedDecl; // child enums
    318318
     319        bool is_c_enum     () const { return !isCfa; }
     320        bool is_opaque_enum() const { return isCfa && nullptr == base; }
     321        bool is_typed_enum () const { return isCfa && nullptr != base; }
     322
    319323        EnumDecl( const CodeLocation& loc, const std::string& name, bool isCfa = false,
    320324                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall,
     
    331335        const char * typeString() const override { return aggrString( Enum ); }
    332336
    333         bool isTyped() const;
    334         bool isOpaque() const;
    335337private:
    336338        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Util.cpp

    rbbbff10 r90e683b  
    8585        // Check that `type->returns` corresponds with `decl->returns`.
    8686        assert( type->returns.size() == decl->returns.size() );
     87}
     88
     89/// Check that an enumeration has not been made with an inconsistent spec.
     90void isEnumerationConsistent( const EnumDecl * node ) {
     91        if ( node->is_c_enum() ) {
     92                assert( nullptr == node->base );
     93        }
    8794}
    8895
     
    135142                previsit( (const ParseNode *)node );
    136143                functionDeclMatchesType( node );
     144        }
     145
     146        void previsit( const EnumDecl * node ) {
     147                previsit( (const ParseNode *)node );
     148                isEnumerationConsistent( node );
    137149        }
    138150
Note: See TracChangeset for help on using the changeset viewer.