Changeset 0b8bf27


Ignore:
Timestamp:
May 23, 2019, 10:39:17 AM (6 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
Files:
4 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 \
  • src/Makefile.in

    rf23de79d r0b8bf27  
    167167am__objects_1 = AST/Attribute.$(OBJEXT) AST/Convert.$(OBJEXT) \
    168168        AST/Decl.$(OBJEXT) AST/DeclReplacer.$(OBJEXT) \
    169         AST/Expr.$(OBJEXT) AST/Init.$(OBJEXT) \
    170         AST/LinkageSpec.$(OBJEXT) AST/Node.$(OBJEXT) \
    171         AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) AST/Stmt.$(OBJEXT) \
    172         AST/Type.$(OBJEXT) AST/TypeSubstitution.$(OBJEXT)
     169        AST/Expr.$(OBJEXT) AST/GenericSubstitution.$(OBJEXT) \
     170        AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \
     171        AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \
     172        AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \
     173        AST/TypeSubstitution.$(OBJEXT)
    173174am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \
    174175        CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \
     
    574575        AST/DeclReplacer.cpp \
    575576        AST/Expr.cpp \
     577        AST/GenericSubstitution.cpp \
    576578        AST/Init.cpp \
    577579        AST/LinkageSpec.cpp \
     
    739741        AST/$(DEPDIR)/$(am__dirstamp)
    740742AST/Expr.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
     743AST/GenericSubstitution.$(OBJEXT): AST/$(am__dirstamp) \
     744        AST/$(DEPDIR)/$(am__dirstamp)
    741745AST/Init.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    742746AST/LinkageSpec.$(OBJEXT): AST/$(am__dirstamp) \
     
    11731177@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/DeclReplacer.Po@am__quote@
    11741178@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Expr.Po@am__quote@
     1179@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/GenericSubstitution.Po@am__quote@
    11751180@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Init.Po@am__quote@
    11761181@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/LinkageSpec.Po@am__quote@
Note: See TracChangeset for help on using the changeset viewer.