Changeset fa2c005 for src/Common


Ignore:
Timestamp:
Jun 8, 2023, 3:19:43 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT
Parents:
044ae62
Message:

Finish Adt POC

Location:
src/Common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Common/CodeLocationTools.cpp

    r044ae62 rfa2c005  
    185185    macro(FunctionType, Type) \
    186186    macro(StructInstType, Type) \
     187    macro(AdtInstType, Type) \
    187188    macro(UnionInstType, Type) \
    188189    macro(EnumInstType, Type) \
  • src/Common/PassVisitor.h

    r044ae62 rfa2c005  
    226226        virtual void visit( StructInstType * aggregateUseType ) override final;
    227227        virtual void visit( const StructInstType * aggregateUseType ) override final;
     228        virtual void visit( AdtInstType * aggregateUseType ) override final;
     229        virtual void visit( const AdtInstType * aggregateUseType ) override final;
    228230        virtual void visit( UnionInstType * aggregateUseType ) override final;
    229231        virtual void visit( const UnionInstType * aggregateUseType ) override final;
     
    351353        virtual Type * mutate( FunctionType * functionType ) override final;
    352354        virtual Type * mutate( StructInstType * aggregateUseType ) override final;
     355        virtual Type * mutate( AdtInstType * aggregateUseType ) override final;
    353356        virtual Type * mutate( UnionInstType * aggregateUseType ) override final;
    354357        virtual Type * mutate( EnumInstType * aggregateUseType ) override final;
     
    442445        void indexerAddStructFwd( const StructDecl          * node  ) { indexer_impl_addStructFwd( pass, 0, node ); }
    443446        void indexerAddEnum     ( const EnumDecl            * node  ) { indexer_impl_addEnum     ( pass, 0, node ); }
     447        void indexerAddAdt              ( const std::string                     & id    ) { indexer_impl_addAdt      ( pass, 0, id   ); }
    444448        void indexerAddAdt              ( const AdtDecl                         * node  ) { indexer_impl_addAdt          ( pass, 0, node ); }
    445449        void indexerAddAdtFwd   ( const AdtDecl                         * node  ) { indexer_impl_addAdtFwd   ( pass, 0, node  ); }
  • src/Common/PassVisitor.impl.h

    r044ae62 rfa2c005  
    688688
    689689//--------------------------------------------------------------------------
     690// AdtDecl
     691template< typename pass_type >
     692void PassVisitor< pass_type >::visit( AdtDecl * node ) {
     693        VISIT_START( node );
     694
     695        indexerAddAdtFwd( node );
     696
     697        maybeAccept_impl( node->data_union, *this );
     698        maybeAccept_impl( node->tag, *this );
     699
     700        maybeAccept_impl( node->parameters, *this );
     701        maybeAccept_impl( node->members   , *this );
     702        maybeAccept_impl( node->attributes, *this );
     703
     704        indexerAddAdt( node );
     705
     706        VISIT_END( node );
     707}
     708
     709template< typename pass_type >
     710void PassVisitor< pass_type >::visit( const AdtDecl * node ) {
     711        VISIT_START( node );
     712
     713        indexerAddAdtFwd( node );
     714
     715        maybeAccept_impl( node->data_union, *this );
     716        maybeAccept_impl( node->tag, *this );
     717
     718        maybeAccept_impl( node->parameters, *this );
     719        maybeAccept_impl( node->members   , *this );
     720        maybeAccept_impl( node->attributes, *this );
     721
     722        indexerAddAdt( node );
     723
     724        VISIT_END( node );
     725
     726
     727template< typename pass_type >
     728Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) {
     729        MUTATE_START( node );
     730       
     731        indexerAddAdtFwd( node );
     732
     733        maybeMutate_impl( node->data_union, *this );
     734        maybeMutate_impl( node->tag, *this );
     735
     736        maybeMutate_impl( node->parameters, *this );
     737        maybeMutate_impl( node->members   , *this );
     738        maybeMutate_impl( node->attributes, *this );
     739
     740        indexerAddAdt( node );
     741
     742        MUTATE_END( Declaration, node );
     743}
     744
     745
     746//--------------------------------------------------------------------------
    690747// UnionDecl
    691748template< typename pass_type >
     
    789846}
    790847
    791 template< typename pass_type >
    792 void PassVisitor< pass_type >::visit( AdtDecl * node ) {
    793         VISIT_START( node );
    794 
    795         indexerAddAdtFwd( node );
    796 
    797         // unlike structs, traits, and unions, enums inject their members into the global scope
    798         maybeAccept_impl( node->data_constructors, *this );
    799         maybeAccept_impl( node->data_union, *this );
    800         maybeAccept_impl( node->tag, *this );
    801 
    802         maybeAccept_impl( node->parameters, *this );
    803         maybeAccept_impl( node->members   , *this );
    804         maybeAccept_impl( node->attributes, *this );
    805 
    806         VISIT_END( node );
    807 }
    808 
    809 template< typename pass_type >
    810 void PassVisitor< pass_type >::visit( const AdtDecl * node ) {
    811         VISIT_START( node );
    812 
    813         indexerAddAdtFwd( node );
    814 
    815         maybeAccept_impl( node->data_constructors, *this );
    816         maybeAccept_impl( node->data_union, *this );
    817         maybeAccept_impl( node->tag, *this );
    818 
    819         maybeAccept_impl( node->parameters, *this );
    820         maybeAccept_impl( node->members   , *this );
    821         maybeAccept_impl( node->attributes, *this );
    822 
    823 
    824         VISIT_END( node );
    825 
    826 
    827 template< typename pass_type >
    828 Declaration * PassVisitor< pass_type >::mutate( AdtDecl * node ) {
    829         MUTATE_START( node );
    830        
    831         indexerAddAdtFwd( node );
    832 
    833         maybeMutate_impl( node->data_constructors, *this );
    834         maybeMutate_impl( node->data_union, *this );
    835         maybeMutate_impl( node->tag, *this );
    836 
    837         maybeMutate_impl( node->parameters, *this );
    838         maybeMutate_impl( node->members   , *this );
    839         maybeMutate_impl( node->attributes, *this );
    840 
    841         MUTATE_END( Declaration, node );
    842 }
    843848
    844849//--------------------------------------------------------------------------
     
    35403545
    35413546        indexerAddStruct( node->name );
     3547
     3548        {
     3549                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     3550                maybeMutate_impl( node->forall    , *this );
     3551                maybeMutate_impl( node->parameters, *this );
     3552        }
     3553
     3554        MUTATE_END( Type, node );
     3555}
     3556
     3557//--------------------------------------------------------------------------
     3558// AdtInstType
     3559template< typename pass_type >
     3560void PassVisitor< pass_type >::visit( AdtInstType * node ) {
     3561        VISIT_START( node );
     3562
     3563        indexerAddAdt( node->name );
     3564
     3565        {
     3566                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     3567                maybeAccept_impl( node->forall    , *this );
     3568                maybeAccept_impl( node->parameters, *this );
     3569        }
     3570
     3571        VISIT_END( node );
     3572}
     3573
     3574template< typename pass_type >
     3575void PassVisitor< pass_type >::visit( const AdtInstType * node ) {
     3576        VISIT_START( node );
     3577
     3578        indexerAddAdt( node->name );
     3579
     3580        {
     3581                auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
     3582                maybeAccept_impl( node->forall    , *this );
     3583                maybeAccept_impl( node->parameters, *this );
     3584        }
     3585
     3586        VISIT_END( node );
     3587}
     3588
     3589template< typename pass_type >
     3590Type * PassVisitor< pass_type >::mutate( AdtInstType * node ) {
     3591        MUTATE_START( node );
     3592
     3593        indexerAddAdt( node->name );
    35423594
    35433595        {
  • src/Common/PassVisitor.proto.h

    r044ae62 rfa2c005  
    256256        cloneAll( decl->parameters, fwd->parameters );
    257257
    258         // Experimental
    259         for ( const StructDecl * ctor : fwd->data_constructors ) {
    260                 indexer_impl_addStructFwd( pass, 0, ctor );
    261         }
    262 
    263258        pass.indexer.addAdt( fwd );
    264259}
     
    288283
    289284template<typename pass_type>
     285static inline auto indexer_impl_addAdt( pass_type & pass, int, const std::string & str ) -> decltype( pass.indexer.addAdt( str ), void() ) {
     286        assert( false );
     287        if ( ! pass.indexer.lookupAdt( str )) {
     288                pass.indexer.addAdt( str );
     289        }
     290}
     291
     292template<typename pass_type>
     293static inline auto indexer_impl_addAdt( pass_type &, long, const std::string & ) {
     294        assert( false );
     295}
     296
     297template<typename pass_type>
    290298static inline auto indexer_impl_addUnion( pass_type & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
    291299        if ( ! pass.indexer.lookupUnion( str ) ) {
Note: See TracChangeset for help on using the changeset viewer.