Changeset 36a2367


Ignore:
Timestamp:
Jan 17, 2018, 11:49:15 AM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
53452de
Parents:
d7d9a60
Message:

Convert Unify to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    rd7d9a60 r36a2367  
    4444namespace ResolvExpr {
    4545
    46         class Unify : public Visitor {
    47           public:
     46        struct Unify : public WithShortCircuiting {
    4847                Unify( Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );
    4948
    5049                bool get_result() const { return result; }
     50
     51                void previsit( BaseSyntaxNode * ) { visit_children = false; }
     52
     53                void postvisit( VoidType * voidType );
     54                void postvisit( BasicType * basicType );
     55                void postvisit( PointerType * pointerType );
     56                void postvisit( ArrayType * arrayType );
     57                void postvisit( ReferenceType * refType );
     58                void postvisit( FunctionType * functionType );
     59                void postvisit( StructInstType * aggregateUseType );
     60                void postvisit( UnionInstType * aggregateUseType );
     61                void postvisit( EnumInstType * aggregateUseType );
     62                void postvisit( TraitInstType * aggregateUseType );
     63                void postvisit( TypeInstType * aggregateUseType );
     64                void postvisit( TupleType * tupleType );
     65                void postvisit( VarArgsType * varArgsType );
     66                void postvisit( ZeroType * zeroType );
     67                void postvisit( OneType * oneType );
     68
    5169          private:
    52                 virtual void visit(VoidType *voidType);
    53                 virtual void visit(BasicType *basicType);
    54                 virtual void visit(PointerType *pointerType);
    55                 virtual void visit(ArrayType *arrayType);
    56                 virtual void visit(ReferenceType *refType);
    57                 virtual void visit(FunctionType *functionType);
    58                 virtual void visit(StructInstType *aggregateUseType);
    59                 virtual void visit(UnionInstType *aggregateUseType);
    60                 virtual void visit(EnumInstType *aggregateUseType);
    61                 virtual void visit(TraitInstType *aggregateUseType);
    62                 virtual void visit(TypeInstType *aggregateUseType);
    63                 virtual void visit(TupleType *tupleType);
    64                 virtual void visit(VarArgsType *varArgsType);
    65                 virtual void visit(ZeroType *zeroType);
    66                 virtual void visit(OneType *oneType);
    67 
    6870                template< typename RefType > void handleRefType( RefType *inst, Type *other );
    6971                template< typename RefType > void handleGenericRefType( RefType *inst, Type *other );
     
    325327                        result = bindVar( var2, type1, entry2->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer );
    326328                } else {
    327                         Unify comparator( type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer );
     329                        PassVisitor<Unify> comparator( type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer );
    328330                        type1->accept( comparator );
    329                         result = comparator.get_result();
     331                        result = comparator.pass.get_result();
    330332                } // if
    331333#ifdef DEBUG
     
    404406        }
    405407
    406         void Unify::visit( __attribute__((unused)) VoidType *voidType) {
     408        void Unify::postvisit( __attribute__((unused)) VoidType *voidType) {
    407409                result = dynamic_cast< VoidType* >( type2 );
    408410        }
    409411
    410         void Unify::visit(BasicType *basicType) {
     412        void Unify::postvisit(BasicType *basicType) {
    411413                if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) {
    412414                        result = basicType->get_kind() == otherBasic->get_kind();
     
    436438        }
    437439
    438         void Unify::visit(PointerType *pointerType) {
     440        void Unify::postvisit(PointerType *pointerType) {
    439441                if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
    440442                        result = unifyExact( pointerType->get_base(), otherPointer->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     
    444446        }
    445447
    446         void Unify::visit(ReferenceType *refType) {
     448        void Unify::postvisit(ReferenceType *refType) {
    447449                if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) {
    448450                        result = unifyExact( refType->get_base(), otherRef->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
     
    452454        }
    453455
    454         void Unify::visit(ArrayType *arrayType) {
     456        void Unify::postvisit(ArrayType *arrayType) {
    455457                ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 );
    456458                // to unify, array types must both be VLA or both not VLA
     
    567569        }
    568570
    569         void Unify::visit(FunctionType *functionType) {
     571        void Unify::postvisit(FunctionType *functionType) {
    570572                FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 );
    571573                if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) {
     
    669671        }
    670672
    671         void Unify::visit(StructInstType *structInst) {
     673        void Unify::postvisit(StructInstType *structInst) {
    672674                handleGenericRefType( structInst, type2 );
    673675        }
    674676
    675         void Unify::visit(UnionInstType *unionInst) {
     677        void Unify::postvisit(UnionInstType *unionInst) {
    676678                handleGenericRefType( unionInst, type2 );
    677679        }
    678680
    679         void Unify::visit(EnumInstType *enumInst) {
     681        void Unify::postvisit(EnumInstType *enumInst) {
    680682                handleRefType( enumInst, type2 );
    681683        }
    682684
    683         void Unify::visit(TraitInstType *contextInst) {
     685        void Unify::postvisit(TraitInstType *contextInst) {
    684686                handleRefType( contextInst, type2 );
    685687        }
    686688
    687         void Unify::visit(TypeInstType *typeInst) {
     689        void Unify::postvisit(TypeInstType *typeInst) {
    688690                assert( openVars.find( typeInst->get_name() ) == openVars.end() );
    689691                TypeInstType *otherInst = dynamic_cast< TypeInstType* >( type2 );
     
    740742        }
    741743
    742         void Unify::visit(TupleType *tupleType) {
     744        void Unify::postvisit(TupleType *tupleType) {
    743745                if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) {
    744746                        std::unique_ptr<TupleType> flat1( tupleType->clone() );
     
    757759        }
    758760
    759         void Unify::visit( __attribute__((unused)) VarArgsType *varArgsType ) {
     761        void Unify::postvisit( __attribute__((unused)) VarArgsType *varArgsType ) {
    760762                result = dynamic_cast< VarArgsType* >( type2 );
    761763        }
    762764
    763         void Unify::visit( __attribute__((unused)) ZeroType *zeroType ) {
     765        void Unify::postvisit( __attribute__((unused)) ZeroType *zeroType ) {
    764766                result = dynamic_cast< ZeroType* >( type2 );
    765767        }
    766768
    767         void Unify::visit( __attribute__((unused)) OneType *oneType ) {
     769        void Unify::postvisit( __attribute__((unused)) OneType *oneType ) {
    768770                result = dynamic_cast< OneType* >( type2 );
    769771        }
Note: See TracChangeset for help on using the changeset viewer.