Changeset 0b8bf27 for src/AST


Ignore:
Timestamp:
May 23, 2019, 10:39:17 AM (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:
a2e758e
Parents:
f23de79d
Message:

Fixed pass visitor so previsit can return void to signify it will never mutate

Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/GenericSubstitution.cpp

    rf23de79d r0b8bf27  
    2323#include "Pass.hpp"
    2424#include "Type.hpp"
    25 #include "TypeSubstitution.cpp"
     25#include "TypeSubstitution.hpp"
    2626
    2727namespace ast {
     
    3232
    3333                void previsit( const Type * ty ) {
    34                         assertf( false, "Attempted generic substitution for non-aggregate type: %s", 
     34                        assertf( false, "Attempted generic substitution for non-aggregate type: %s",
    3535                                toString( ty ).c_str() );
    3636                }
  • src/AST/Pass.proto.hpp

    rf23de79d r0b8bf27  
    115115                static constexpr bool value = std::is_void< ret_t >::value ||
    116116                        std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
     117        };
     118
     119        template<bool is_void>
     120        struct __assign;
     121
     122        template<>
     123        struct __assign<true> {
     124                template<typename pass_t, typename node_t>
     125                static inline void result( pass_t & pass, const node_t * & node ) {
     126                        pass.previsit( node );
     127                }
     128        };
     129
     130        template<>
     131        struct __assign<false> {
     132                template<typename pass_t, typename node_t>
     133                static inline void result( pass_t & pass, const node_t * & node ) {
     134                        node = pass.previsit( node );
     135                        assertf(node, "Previsit must not return NULL");
     136                }
    117137        };
    118138
     
    138158                        "Previsit may not change the type of the node. It must return its paremeter or void."
    139159                );
    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                 }
     160
     161                __assign<
     162                        std::is_void<
     163                                decltype( pass.previsit( node ) )
     164                        >::value
     165                >::result( pass, node );
    146166        }
    147167
  • src/AST/module.mk

    rf23de79d r0b8bf27  
    2121        AST/DeclReplacer.cpp \
    2222        AST/Expr.cpp \
     23        AST/GenericSubstitution.cpp \
    2324        AST/Init.cpp \
    2425        AST/LinkageSpec.cpp \
Note: See TracChangeset for help on using the changeset viewer.