Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/PtrsCastable.cc

    r12145b9 rb0837e4  
    1414//
    1515
    16 #include "Common/PassVisitor.h"
    1716#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
    1817#include "SymTab/Indexer.h"              // for Indexer
     
    2221#include "typeops.h"                     // for ptrsAssignable
    2322
     23
    2424namespace ResolvExpr {
    25         struct PtrsCastable : public WithShortCircuiting {
     25        class PtrsCastable : public Visitor {
    2626          public:
    2727                PtrsCastable( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     
    2929                int get_result() const { return result; }
    3030
    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 );
     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);
    4745          private:
    4846                Type *dest;
     
    8179                        EqvClass eqvClass;
    8280                        if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
    83                                 // xxx - should this be ptrsCastable?
    8481                                return ptrsAssignable( src, eqvClass.type, env );
    8582                        } // if
     
    8885                        return objectCast( src, env, indexer );
    8986                } else {
    90                         PassVisitor<PtrsCastable> ptrs( dest, env, indexer );
     87                        PtrsCastable ptrs( dest, env, indexer );
    9188                        src->accept( ptrs );
    92                         return ptrs.pass.get_result();
     89                        return ptrs.get_result();
    9390                } // if
    9491        }
     
    9895        }
    9996
    100         void PtrsCastable::postvisit( VoidType * ) {
     97        void PtrsCastable::visit( VoidType * ) {
    10198                result = objectCast( dest, env, indexer );
    10299        }
    103100
    104         void PtrsCastable::postvisit( BasicType * ) {
     101        void PtrsCastable::visit( BasicType * ) {
    105102                result = objectCast( dest, env, indexer );
    106103        }
    107104
    108         void PtrsCastable::postvisit( PointerType * ) {
     105        void PtrsCastable::visit( PointerType * ) {
    109106                result = objectCast( dest, env, indexer );
    110107        }
    111108
    112         void PtrsCastable::postvisit( ArrayType * ) {
     109        void PtrsCastable::visit( ArrayType * ) {
    113110                result = objectCast( dest, env, indexer );
    114111        }
    115112
    116         void PtrsCastable::postvisit( FunctionType * ) {
     113        void PtrsCastable::visit( FunctionType * ) {
    117114                // result = -1;
    118115                result = functionCast( dest, env, indexer );
    119116        }
    120117
    121         void PtrsCastable::postvisit( StructInstType * ) {
     118        void PtrsCastable::visit( StructInstType * ) {
    122119                result = objectCast( dest, env, indexer );
    123120        }
    124121
    125         void PtrsCastable::postvisit( UnionInstType * ) {
     122        void PtrsCastable::visit( UnionInstType * ) {
    126123                result = objectCast( dest, env, indexer );
    127124        }
    128125
    129         void PtrsCastable::postvisit( EnumInstType * ) {
     126        void PtrsCastable::visit( EnumInstType * ) {
    130127                if ( dynamic_cast< EnumInstType* >( dest ) ) {
    131128                        result = 1;
     
    141138        }
    142139
    143         void PtrsCastable::postvisit( TraitInstType * ) {}
     140        void PtrsCastable::visit( TraitInstType * ) {}
    144141
    145         void PtrsCastable::postvisit(TypeInstType *inst) {
     142        void PtrsCastable::visit(TypeInstType *inst) {
    146143                //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
    147144                result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1;
    148145        }
    149146
    150         void PtrsCastable::postvisit( TupleType * ) {
     147        void PtrsCastable::visit( TupleType * ) {
    151148                result = objectCast( dest, env, indexer );
    152149        }
    153150
    154         void PtrsCastable::postvisit( VarArgsType * ) {
     151        void PtrsCastable::visit( VarArgsType * ) {
    155152                result = objectCast( dest, env, indexer );
    156153        }
    157154
    158         void PtrsCastable::postvisit( ZeroType * ) {
     155        void PtrsCastable::visit( ZeroType * ) {
    159156                result = objectCast( dest, env, indexer );
    160157        }
    161158
    162         void PtrsCastable::postvisit( OneType * ) {
     159        void PtrsCastable::visit( OneType * ) {
    163160                result = objectCast( dest, env, indexer );
    164161        }
Note: See TracChangeset for help on using the changeset viewer.