Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.proto.hpp

    r7ff3e522 r0d070ca  
    2020
    2121namespace ast {
    22 template<typename core_t>
     22template<typename pass_type>
    2323class Pass;
    2424
     
    113113        /// "Short hand" to check if this is a valid previsit function
    114114        /// Mostly used to make the static_assert look (and print) prettier
    115         template<typename core_t, typename node_t>
     115        template<typename pass_t, typename node_t>
    116116        struct is_valid_previsit {
    117                 using ret_t = decltype( ((core_t*)nullptr)->previsit( (const node_t *)nullptr ) );
     117                using ret_t = decltype( ((pass_t*)nullptr)->previsit( (const node_t *)nullptr ) );
    118118
    119119                static constexpr bool value = std::is_void< ret_t >::value ||
     
    129129        template<>
    130130        struct __assign<true> {
    131                 template<typename core_t, typename node_t>
    132                 static inline void result( core_t & core, const node_t * & node ) {
    133                         core.previsit( node );
     131                template<typename pass_t, typename node_t>
     132                static inline void result( pass_t & pass, const node_t * & node ) {
     133                        pass.previsit( node );
    134134                }
    135135        };
     
    137137        template<>
    138138        struct __assign<false> {
    139                 template<typename core_t, typename node_t>
    140                 static inline void result( core_t & core, const node_t * & node ) {
    141                         node = core.previsit( node );
     139                template<typename pass_t, typename node_t>
     140                static inline void result( pass_t & pass, const node_t * & node ) {
     141                        node = pass.previsit( node );
    142142                        assertf(node, "Previsit must not return NULL");
    143143                }
     
    152152        template<>
    153153        struct __return<true> {
    154                 template<typename core_t, typename node_t>
    155                 static inline const node_t * result( core_t & core, const node_t * & node ) {
    156                         core.postvisit( node );
     154                template<typename pass_t, typename node_t>
     155                static inline const node_t * result( pass_t & pass, const node_t * & node ) {
     156                        pass.postvisit( node );
    157157                        return node;
    158158                }
     
    161161        template<>
    162162        struct __return<false> {
    163                 template<typename core_t, typename node_t>
    164                 static inline auto result( core_t & core, const node_t * & node ) {
    165                         return core.postvisit( node );
     163                template<typename pass_t, typename node_t>
     164                static inline auto result( pass_t & pass, const node_t * & node ) {
     165                        return pass.postvisit( node );
    166166                }
    167167        };
     
    182182        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    183183        // PreVisit : may mutate the pointer passed in if the node is mutated in the previsit call
    184         template<typename core_t, typename node_t>
    185         static inline auto previsit( core_t & core, const node_t * & node, int ) -> decltype( core.previsit( node ), void() ) {
     184        template<typename pass_t, typename node_t>
     185        static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
    186186                static_assert(
    187                         is_valid_previsit<core_t, node_t>::value,
     187                        is_valid_previsit<pass_t, node_t>::value,
    188188                        "Previsit may not change the type of the node. It must return its paremeter or void."
    189189                );
     
    191191                __assign<
    192192                        std::is_void<
    193                                 decltype( core.previsit( node ) )
     193                                decltype( pass.previsit( node ) )
    194194                        >::value
    195                 >::result( core, node );
     195                >::result( pass, node );
    196196        }
    197197
    198         template<typename core_t, typename node_t>
    199         static inline auto previsit( core_t &, const node_t *, long ) {}
     198        template<typename pass_t, typename node_t>
     199        static inline auto previsit( pass_t &, const node_t *, long ) {}
    200200
    201201        // PostVisit : never mutates the passed pointer but may return a different node
    202         template<typename core_t, typename node_t>
    203         static inline auto postvisit( core_t & core, const node_t * node, int ) ->
    204                 decltype( core.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
     202        template<typename pass_t, typename node_t>
     203        static inline auto postvisit( pass_t & pass, const node_t * node, int ) ->
     204                decltype( pass.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
    205205        {
    206206                return __return<
    207207                        std::is_void<
    208                                 decltype( core.postvisit( node ) )
     208                                decltype( pass.postvisit( node ) )
    209209                        >::value
    210                 >::result( core, node );
     210                >::result( pass, node );
    211211        }
    212212
    213         template<typename core_t, typename node_t>
    214         static inline const node_t * postvisit( core_t &, const node_t * node, long ) { return node; }
     213        template<typename pass_t, typename node_t>
     214        static inline const node_t * postvisit( pass_t &, const node_t * node, long ) { return node; }
    215215
    216216        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    227227        // The type is not strictly enforced but does match the accessory
    228228        #define FIELD_PTR( name, default_type ) \
    229         template< typename core_t > \
    230         static inline auto name( core_t & core, int ) -> decltype( &core.name ) { return &core.name; } \
     229        template< typename pass_t > \
     230        static inline auto name( pass_t & pass, int ) -> decltype( &pass.name ) { return &pass.name; } \
    231231        \
    232         template< typename core_t > \
    233         static inline default_type * name( core_t &, long ) { return nullptr; }
     232        template< typename pass_t > \
     233        static inline default_type * name( pass_t &, long ) { return nullptr; }
    234234
    235235        // List of fields and their expected types
     
    241241        FIELD_PTR( visit_children, __pass::bool_ref )
    242242        FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
    243         FIELD_PTR( visitor, ast::Pass<core_t> * const )
     243        FIELD_PTR( visitor, ast::Pass<pass_t> * const )
    244244
    245245        // Remove the macro to make sure we don't clash
    246246        #undef FIELD_PTR
    247247
    248         template< typename core_t >
    249         static inline auto beginTrace(core_t &, int) -> decltype( core_t::traceId, void() ) {
    250                 // Stats::Heap::stacktrace_push(core_t::traceId);
     248        template< typename pass_t >
     249        static inline auto beginTrace(pass_t &, int) -> decltype( pass_t::traceId, void() ) {
     250                // Stats::Heap::stacktrace_push(pass_t::traceId);
    251251        }
    252252
    253         template< typename core_t >
    254         static inline auto endTrace(core_t &, int) -> decltype( core_t::traceId, void() ) {
     253        template< typename pass_t >
     254        static inline auto endTrace(pass_t &, int) -> decltype( pass_t::traceId, void() ) {
    255255                // Stats::Heap::stacktrace_pop();
    256256        }
    257257
    258         template< typename core_t >
    259         static void beginTrace(core_t &, long) {}
    260 
    261         template< typename core_t >
    262         static void endTrace(core_t &, long) {}
     258        template< typename pass_t >
     259        static void beginTrace(pass_t &, long) {}
     260
     261        template< typename pass_t >
     262        static void endTrace(pass_t &, long) {}
    263263
    264264        // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
     
    266266        // detect it using the same strategy
    267267        namespace scope {
    268                 template<typename core_t>
    269                 static inline auto enter( core_t & core, int ) -> decltype( core.beginScope(), void() ) {
    270                         core.beginScope();
    271                 }
    272 
    273                 template<typename core_t>
    274                 static inline void enter( core_t &, long ) {}
    275 
    276                 template<typename core_t>
    277                 static inline auto leave( core_t & core, int ) -> decltype( core.endScope(), void() ) {
    278                         core.endScope();
    279                 }
    280 
    281                 template<typename core_t>
    282                 static inline void leave( core_t &, long ) {}
     268                template<typename pass_t>
     269                static inline auto enter( pass_t & pass, int ) -> decltype( pass.beginScope(), void() ) {
     270                        pass.beginScope();
     271                }
     272
     273                template<typename pass_t>
     274                static inline void enter( pass_t &, long ) {}
     275
     276                template<typename pass_t>
     277                static inline auto leave( pass_t & pass, int ) -> decltype( pass.endScope(), void() ) {
     278                        pass.endScope();
     279                }
     280
     281                template<typename pass_t>
     282                static inline void leave( pass_t &, long ) {}
    283283        } // namespace scope
    284284
     
    287287        namespace symtab {
    288288                // Some simple scoping rules
    289                 template<typename core_t>
    290                 static inline auto enter( core_t & core, int ) -> decltype( core.symtab, void() ) {
    291                         core.symtab.enterScope();
    292                 }
    293 
    294                 template<typename core_t>
    295                 static inline auto enter( core_t &, long ) {}
    296 
    297                 template<typename core_t>
    298                 static inline auto leave( core_t & core, int ) -> decltype( core.symtab, void() ) {
    299                         core.symtab.leaveScope();
    300                 }
    301 
    302                 template<typename core_t>
    303                 static inline auto leave( core_t &, long ) {}
     289                template<typename pass_t>
     290                static inline auto enter( pass_t & pass, int ) -> decltype( pass.symtab, void() ) {
     291                        pass.symtab.enterScope();
     292                }
     293
     294                template<typename pass_t>
     295                static inline auto enter( pass_t &, long ) {}
     296
     297                template<typename pass_t>
     298                static inline auto leave( pass_t & pass, int ) -> decltype( pass.symtab, void() ) {
     299                        pass.symtab.leaveScope();
     300                }
     301
     302                template<typename pass_t>
     303                static inline auto leave( pass_t &, long ) {}
    304304
    305305                // The symbol table has 2 kind of functions mostly, 1 argument and 2 arguments
    306306                // Create macro to condense these common patterns
    307307                #define SYMTAB_FUNC1( func, type ) \
    308                 template<typename core_t> \
    309                 static inline auto func( core_t & core, int, type arg ) -> decltype( core.symtab.func( arg ), void() ) {\
    310                         core.symtab.func( arg ); \
     308                template<typename pass_t> \
     309                static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.symtab.func( arg ), void() ) {\
     310                        pass.symtab.func( arg ); \
    311311                } \
    312312                \
    313                 template<typename core_t> \
    314                 static inline void func( core_t &, long, type ) {}
     313                template<typename pass_t> \
     314                static inline void func( pass_t &, long, type ) {}
    315315
    316316                #define SYMTAB_FUNC2( func, type1, type2 ) \
    317                 template<typename core_t> \
    318                 static inline auto func( core_t & core, int, type1 arg1, type2 arg2 ) -> decltype( core.symtab.func( arg1, arg2 ), void () ) {\
    319                         core.symtab.func( arg1, arg2 ); \
     317                template<typename pass_t> \
     318                static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.symtab.func( arg1, arg2 ), void () ) {\
     319                        pass.symtab.func( arg1, arg2 ); \
    320320                } \
    321321                        \
    322                 template<typename core_t> \
    323                 static inline void func( core_t &, long, type1, type2 ) {}
     322                template<typename pass_t> \
     323                static inline void func( pass_t &, long, type1, type2 ) {}
    324324
    325325                SYMTAB_FUNC1( addId     , const DeclWithType *  );
     
    332332
    333333                // A few extra functions have more complicated behaviour, they are hand written
    334                 template<typename core_t>
    335                 static inline auto addStructFwd( core_t & core, int, const ast::StructDecl * decl ) -> decltype( core.symtab.addStruct( decl ), void() ) {
     334                template<typename pass_t>
     335                static inline auto addStructFwd( pass_t & pass, int, const ast::StructDecl * decl ) -> decltype( pass.symtab.addStruct( decl ), void() ) {
    336336                        ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
    337337                        fwd->params = decl->params;
    338                         core.symtab.addStruct( fwd );
    339                 }
    340 
    341                 template<typename core_t>
    342                 static inline void addStructFwd( core_t &, long, const ast::StructDecl * ) {}
    343 
    344                 template<typename core_t>
    345                 static inline auto addUnionFwd( core_t & core, int, const ast::UnionDecl * decl ) -> decltype( core.symtab.addUnion( decl ), void() ) {
     338                        pass.symtab.addStruct( fwd );
     339                }
     340
     341                template<typename pass_t>
     342                static inline void addStructFwd( pass_t &, long, const ast::StructDecl * ) {}
     343
     344                template<typename pass_t>
     345                static inline auto addUnionFwd( pass_t & pass, int, const ast::UnionDecl * decl ) -> decltype( pass.symtab.addUnion( decl ), void() ) {
    346346                        UnionDecl * fwd = new UnionDecl( decl->location, decl->name );
    347347                        fwd->params = decl->params;
    348                         core.symtab.addUnion( fwd );
    349                 }
    350 
    351                 template<typename core_t>
    352                 static inline void addUnionFwd( core_t &, long, const ast::UnionDecl * ) {}
    353 
    354                 template<typename core_t>
    355                 static inline auto addStruct( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addStruct( str ), void() ) {
    356                         if ( ! core.symtab.lookupStruct( str ) ) {
    357                                 core.symtab.addStruct( str );
     348                        pass.symtab.addUnion( fwd );
     349                }
     350
     351                template<typename pass_t>
     352                static inline void addUnionFwd( pass_t &, long, const ast::UnionDecl * ) {}
     353
     354                template<typename pass_t>
     355                static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.symtab.addStruct( str ), void() ) {
     356                        if ( ! pass.symtab.lookupStruct( str ) ) {
     357                                pass.symtab.addStruct( str );
    358358                        }
    359359                }
    360360
    361                 template<typename core_t>
    362                 static inline void addStruct( core_t &, long, const std::string & ) {}
    363 
    364                 template<typename core_t>
    365                 static inline auto addUnion( core_t & core, int, const std::string & str ) -> decltype( core.symtab.addUnion( str ), void() ) {
    366                         if ( ! core.symtab.lookupUnion( str ) ) {
    367                                 core.symtab.addUnion( str );
     361                template<typename pass_t>
     362                static inline void addStruct( pass_t &, long, const std::string & ) {}
     363
     364                template<typename pass_t>
     365                static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.symtab.addUnion( str ), void() ) {
     366                        if ( ! pass.symtab.lookupUnion( str ) ) {
     367                                pass.symtab.addUnion( str );
    368368                        }
    369369                }
    370370
    371                 template<typename core_t>
    372                 static inline void addUnion( core_t &, long, const std::string & ) {}
     371                template<typename pass_t>
     372                static inline void addUnion( pass_t &, long, const std::string & ) {}
    373373
    374374                #undef SYMTAB_FUNC1
     
    380380        namespace forall {
    381381                // Some simple scoping rules
    382                 template<typename core_t>
    383                 static inline auto enter( core_t & core, int, const ast::ParameterizedType * type )
    384                 -> decltype( core.subs, void() ) {
    385                         if ( ! type->forall.empty() ) core.subs.beginScope();
    386                 }
    387 
    388                 template<typename core_t>
    389                 static inline auto enter( core_t &, long, const ast::ParameterizedType * ) {}
    390 
    391                 template<typename core_t>
    392                 static inline auto leave( core_t & core, int, const ast::ParameterizedType * type )
    393                 -> decltype( core.subs, void() ) {
    394                         if ( ! type->forall.empty() ) { core.subs.endScope(); }
    395                 }
    396 
    397                 template<typename core_t>
    398                 static inline auto leave( core_t &, long, const ast::ParameterizedType * ) {}
     382                template<typename pass_t>
     383                static inline auto enter( pass_t & pass, int, const ast::ParameterizedType * type )
     384                -> decltype( pass.subs, void() ) {
     385                        if ( ! type->forall.empty() ) pass.subs.beginScope();
     386                }
     387
     388                template<typename pass_t>
     389                static inline auto enter( pass_t &, long, const ast::ParameterizedType * ) {}
     390
     391                template<typename pass_t>
     392                static inline auto leave( pass_t & pass, int, const ast::ParameterizedType * type )
     393                -> decltype( pass.subs, void() ) {
     394                        if ( ! type->forall.empty() ) { pass.subs.endScope(); }
     395                }
     396
     397                template<typename pass_t>
     398                static inline auto leave( pass_t &, long, const ast::ParameterizedType * ) {}
    399399
    400400                // Get the substitution table, if present
    401                 template<typename core_t>
    402                 static inline auto subs( core_t & core, int ) -> decltype( &core.subs ) {
    403                         return &core.subs;
    404                 }
    405 
    406                 template<typename core_t>
    407                 static inline ast::ForallSubstitutionTable * subs( core_t &, long ) { return nullptr; }
     401                template<typename pass_t>
     402                static inline auto subs( pass_t & pass, int ) -> decltype( &pass.subs ) {
     403                        return &pass.subs;
     404                }
     405
     406                template<typename pass_t>
     407                static inline ast::ForallSubstitutionTable * subs( pass_t &, long ) { return nullptr; }
    408408
    409409                // Replaces a TypeInstType's base TypeDecl according to the table
    410                 template<typename core_t>
    411                 static inline auto replace( core_t & core, int, const ast::TypeInstType *& inst )
    412                 -> decltype( core.subs, void() ) {
     410                template<typename pass_t>
     411                static inline auto replace( pass_t & pass, int, const ast::TypeInstType *& inst )
     412                -> decltype( pass.subs, void() ) {
    413413                        inst = ast::mutate_field(
    414                                 inst, &ast::TypeInstType::base, core.subs.replace( inst->base ) );
    415                 }
    416 
    417                 template<typename core_t>
    418                 static inline auto replace( core_t &, long, const ast::TypeInstType *& ) {}
     414                                inst, &ast::TypeInstType::base, pass.subs.replace( inst->base ) );
     415                }
     416
     417                template<typename pass_t>
     418                static inline auto replace( pass_t &, long, const ast::TypeInstType *& ) {}
    419419
    420420        } // namespace forall
Note: See TracChangeset for help on using the changeset viewer.