Changeset dff6452


Ignore:
Timestamp:
May 22, 2019, 5:21:39 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
ef5ef56
Parents:
f4c2f1a
Message:

Minor fixes to which previsits are acceptable

File:
1 edited

Legend:

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

    rf4c2f1a rdff6452  
    107107                bool     * m_prev;
    108108                bool_ref * m_ref;
     109        };
     110
     111        template<typename pass_t, typename node_t>
     112        struct is_valid_previsit {
     113                using ret_t = decltype( ((pass_t*)nullptr)->previsit( (const node_t *)nullptr ) );
     114
     115                static constexpr bool value = std::is_void< ret_t >::value ||
     116                        std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
    109117        };
    110118
     
    127135        static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
    128136                static_assert(
    129                         std::is_base_of<const node_t, typename std::remove_pointer<decltype( pass.previsit( node ) )>::type >::value,
    130                         "Previsit may not change the type of the node. Use postvisit instead."
     137                        is_valid_previsit<pass_t, node_t>::value,
     138                        "Previsit may not change the type of the node. It must return its paremeter or void."
    131139                );
    132                 node = pass.previsit( node );
    133                 assert(node);
     140                if(std::is_void< decltype( pass.previsit(node) ) >::value) {
     141                        pass.previsit( node );
     142                } else {
     143                        node = pass.previsit( node );
     144                        assert(node);
     145                }
    134146        }
    135147
     
    139151        // PostVisit : never mutates the passed pointer but may return a different node
    140152        template<typename pass_t, typename node_t>
    141         static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
     153        static inline auto postvisit( pass_t & pass, const node_t * node, int ) ->
     154                decltype( pass.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
     155        {
    142156                return pass.postvisit( node );
    143157        }
Note: See TracChangeset for help on using the changeset viewer.