Changeset 12145b9


Ignore:
Timestamp:
Jan 15, 2018, 3:10:55 PM (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:
f07c1e6
Parents:
c0b9f5d
Message:

Convert PtrsCastable? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/PtrsCastable.cc

    rc0b9f5d r12145b9  
    1414//
    1515
     16#include "Common/PassVisitor.h"
    1617#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
    1718#include "SymTab/Indexer.h"              // for Indexer
     
    2122#include "typeops.h"                     // for ptrsAssignable
    2223
    23 
    2424namespace ResolvExpr {
    25         class PtrsCastable : public Visitor {
     25        struct PtrsCastable : public WithShortCircuiting {
    2626          public:
    2727                PtrsCastable( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     
    2929                int get_result() const { return result; }
    3030
    31                 virtual void visit(VoidType *voidType);
    32                 virtual void visit(BasicType *basicType);
    33                 virtual void visit(PointerType *pointerType);
    34                 virtual void visit(ArrayType *arrayType);
    35                 virtual void visit(FunctionType *functionType);
    36                 virtual void visit(StructInstType *inst);
    37                 virtual void visit(UnionInstType *inst);
    38                 virtual void visit(EnumInstType *inst);
    39                 virtual void visit(TraitInstType *inst);
    40                 virtual void visit(TypeInstType *inst);
    41                 virtual void visit(TupleType *tupleType);
    42                 virtual void visit(VarArgsType *varArgsType);
    43                 virtual void visit(ZeroType *zeroType);
    44                 virtual void visit(OneType *oneType);
     31                void previsit( Type * ) { visit_children = false; }
     32
     33                void postvisit( VoidType * voidType );
     34                void postvisit( BasicType * basicType );
     35                void postvisit( PointerType * pointerType );
     36                void postvisit( ArrayType * arrayType );
     37                void postvisit( FunctionType * functionType );
     38                void postvisit( StructInstType * inst );
     39                void postvisit( UnionInstType * inst );
     40                void postvisit( EnumInstType * inst );
     41                void postvisit( TraitInstType * inst );
     42                void postvisit( TypeInstType * inst );
     43                void postvisit( TupleType * tupleType );
     44                void postvisit( VarArgsType * varArgsType );
     45                void postvisit( ZeroType * zeroType );
     46                void postvisit( OneType * oneType );
    4547          private:
    4648                Type *dest;
     
    7981                        EqvClass eqvClass;
    8082                        if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
     83                                // xxx - should this be ptrsCastable?
    8184                                return ptrsAssignable( src, eqvClass.type, env );
    8285                        } // if
     
    8588                        return objectCast( src, env, indexer );
    8689                } else {
    87                         PtrsCastable ptrs( dest, env, indexer );
     90                        PassVisitor<PtrsCastable> ptrs( dest, env, indexer );
    8891                        src->accept( ptrs );
    89                         return ptrs.get_result();
     92                        return ptrs.pass.get_result();
    9093                } // if
    9194        }
     
    9598        }
    9699
    97         void PtrsCastable::visit( VoidType * ) {
     100        void PtrsCastable::postvisit( VoidType * ) {
    98101                result = objectCast( dest, env, indexer );
    99102        }
    100103
    101         void PtrsCastable::visit( BasicType * ) {
     104        void PtrsCastable::postvisit( BasicType * ) {
    102105                result = objectCast( dest, env, indexer );
    103106        }
    104107
    105         void PtrsCastable::visit( PointerType * ) {
     108        void PtrsCastable::postvisit( PointerType * ) {
    106109                result = objectCast( dest, env, indexer );
    107110        }
    108111
    109         void PtrsCastable::visit( ArrayType * ) {
     112        void PtrsCastable::postvisit( ArrayType * ) {
    110113                result = objectCast( dest, env, indexer );
    111114        }
    112115
    113         void PtrsCastable::visit( FunctionType * ) {
     116        void PtrsCastable::postvisit( FunctionType * ) {
    114117                // result = -1;
    115118                result = functionCast( dest, env, indexer );
    116119        }
    117120
    118         void PtrsCastable::visit( StructInstType * ) {
     121        void PtrsCastable::postvisit( StructInstType * ) {
    119122                result = objectCast( dest, env, indexer );
    120123        }
    121124
    122         void PtrsCastable::visit( UnionInstType * ) {
     125        void PtrsCastable::postvisit( UnionInstType * ) {
    123126                result = objectCast( dest, env, indexer );
    124127        }
    125128
    126         void PtrsCastable::visit( EnumInstType * ) {
     129        void PtrsCastable::postvisit( EnumInstType * ) {
    127130                if ( dynamic_cast< EnumInstType* >( dest ) ) {
    128131                        result = 1;
     
    138141        }
    139142
    140         void PtrsCastable::visit( TraitInstType * ) {}
     143        void PtrsCastable::postvisit( TraitInstType * ) {}
    141144
    142         void PtrsCastable::visit(TypeInstType *inst) {
     145        void PtrsCastable::postvisit(TypeInstType *inst) {
    143146                //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
    144147                result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1;
    145148        }
    146149
    147         void PtrsCastable::visit( TupleType * ) {
     150        void PtrsCastable::postvisit( TupleType * ) {
    148151                result = objectCast( dest, env, indexer );
    149152        }
    150153
    151         void PtrsCastable::visit( VarArgsType * ) {
     154        void PtrsCastable::postvisit( VarArgsType * ) {
    152155                result = objectCast( dest, env, indexer );
    153156        }
    154157
    155         void PtrsCastable::visit( ZeroType * ) {
     158        void PtrsCastable::postvisit( ZeroType * ) {
    156159                result = objectCast( dest, env, indexer );
    157160        }
    158161
    159         void PtrsCastable::visit( OneType * ) {
     162        void PtrsCastable::postvisit( OneType * ) {
    160163                result = objectCast( dest, env, indexer );
    161164        }
Note: See TracChangeset for help on using the changeset viewer.