Ignore:
File:
1 edited

Legend:

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

    re0069bd r148f836e  
    5353#endif
    5454
    55 namespace ast::__pass {
    56         // Check if this is either a null pointer or a pointer to an empty container
    57         template<typename T>
    58         static inline bool empty( T * ptr ) {
    59                 return !ptr || ptr->empty();
    60         }
    61 
    62         template< typename core_t, typename node_t >
    63         static inline node_t* mutate(const node_t *node) {
    64                 return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node);
    65         }
    66 
    67         //------------------------------
    68         template<typename it_t, template <class...> class container_t>
    69         static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) {
    70                 if ( empty( decls ) ) return;
    71 
    72                 std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto {
    73                                 return new DeclStmt( decl->location, decl );
    74                         });
    75                 decls->clear();
    76                 if ( mutated ) *mutated = true;
    77         }
    78 
    79         template<typename it_t, template <class...> class container_t>
    80         static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {
    81                 if ( empty( stmts ) ) return;
    82 
    83                 std::move(stmts->begin(), stmts->end(), it);
    84                 stmts->clear();
    85                 if ( mutated ) *mutated = true;
    86         }
    87 
    88         //------------------------------
    89         /// Check if should be skipped, different for pointers and containers
     55namespace ast {
    9056        template<typename node_t>
    91         bool skip( const ast::ptr<node_t> & val ) {
    92                 return !val;
    93         }
    94 
    95         template< template <class...> class container_t, typename node_t >
    96         bool skip( const container_t<ast::ptr< node_t >> & val ) {
    97                 return val.empty();
    98         }
    99 
    100         //------------------------------
    101         /// Get the value to visit, different for pointers and containers
    102         template<typename node_t>
    103         auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) {
    104                 return val.get();
    105         }
    106 
    107         template<typename node_t>
    108         const node_t & get( const node_t & val, long ) {
    109                 return val;
    110         }
    111 
    112         //------------------------------
    113         /// Check if value was mutated, different for pointers and containers
    114         template<typename lhs_t, typename rhs_t>
    115         bool differs( const lhs_t * old_val, const rhs_t * new_val ) {
    116                 return old_val != new_val;
    117         }
    118 
    119         template< template <class...> class container_t, typename node_t >
    120         bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) {
    121                 return !new_val.empty();
     57        node_t * shallowCopy( const node_t * node );
     58
     59        namespace __pass {
     60                // Check if this is either a null pointer or a pointer to an empty container
     61                template<typename T>
     62                static inline bool empty( T * ptr ) {
     63                        return !ptr || ptr->empty();
     64                }
     65
     66                template< typename core_t, typename node_t >
     67                static inline node_t* mutate(const node_t *node) {
     68                        return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node);
     69                }
     70
     71                //------------------------------
     72                template<typename it_t, template <class...> class container_t>
     73                static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) {
     74                        if ( empty( decls ) ) return;
     75
     76                        std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto {
     77                                        return new DeclStmt( decl->location, decl );
     78                                });
     79                        decls->clear();
     80                        if ( mutated ) *mutated = true;
     81                }
     82
     83                template<typename it_t, template <class...> class container_t>
     84                static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * stmts, bool * mutated = nullptr ) {
     85                        if ( empty( stmts ) ) return;
     86
     87                        std::move(stmts->begin(), stmts->end(), it);
     88                        stmts->clear();
     89                        if ( mutated ) *mutated = true;
     90                }
     91
     92                //------------------------------
     93                /// Check if should be skipped, different for pointers and containers
     94                template<typename node_t>
     95                bool skip( const ast::ptr<node_t> & val ) {
     96                        return !val;
     97                }
     98
     99                template< template <class...> class container_t, typename node_t >
     100                bool skip( const container_t<ast::ptr< node_t >> & val ) {
     101                        return val.empty();
     102                }
     103
     104                //------------------------------
     105                /// Get the value to visit, different for pointers and containers
     106                template<typename node_t>
     107                auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) {
     108                        return val.get();
     109                }
     110
     111                template<typename node_t>
     112                const node_t & get( const node_t & val, long ) {
     113                        return val;
     114                }
     115
     116                //------------------------------
     117                /// Check if value was mutated, different for pointers and containers
     118                template<typename lhs_t, typename rhs_t>
     119                bool differs( const lhs_t * old_val, const rhs_t * new_val ) {
     120                        return old_val != new_val;
     121                }
     122
     123                template< template <class...> class container_t, typename node_t >
     124                bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) {
     125                        return !new_val.empty();
     126                }
    122127        }
    123128}
     
    19151920        VISIT_START( node );
    19161921
    1917         __pass::symtab::addStructId( core, 0, node->name );
     1922        __pass::symtab::addStruct( core, 0, node->name );
    19181923
    19191924        if ( __visit_children() ) {
     
    19311936        VISIT_START( node );
    19321937
    1933         __pass::symtab::addUnionId( core, 0, node->name );
     1938        __pass::symtab::addUnion( core, 0, node->name );
    19341939
    19351940        if ( __visit_children() ) {
Note: See TracChangeset for help on using the changeset viewer.