Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/PtrsCastable.cc

    r00ac42e 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;
     
    5755                                return -1;
    5856                        } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) {
     57                                EqvClass eqvClass;
    5958                                if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    6059                                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
     
    6362                                                } // if
    6463                                        } //if
    65                                 } else if ( const EqvClass *eqvClass = env.lookup( typeInst->get_name() ) ) {
    66                                         if ( eqvClass->data.kind == TypeDecl::Ftype ) {
     64                                } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
     65                                        if ( eqvClass.data.kind == TypeDecl::Ftype ) {
    6766                                                return -1;
    6867                                        } // if
     
    7877        int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    7978                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    80                         if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
    81                                 // xxx - should this be ptrsCastable?
    82                                 return ptrsAssignable( src, eqvClass->type, env );
     79                        EqvClass eqvClass;
     80                        if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
     81                                return ptrsAssignable( src, eqvClass.type, env );
    8382                        } // if
    8483                } // if
     
    8685                        return objectCast( src, env, indexer );
    8786                } else {
    88                         PassVisitor<PtrsCastable> ptrs( dest, env, indexer );
     87                        PtrsCastable ptrs( dest, env, indexer );
    8988                        src->accept( ptrs );
    90                         return ptrs.pass.get_result();
     89                        return ptrs.get_result();
    9190                } // if
    9291        }
     
    9695        }
    9796
    98         void PtrsCastable::postvisit( VoidType * ) {
     97        void PtrsCastable::visit( VoidType * ) {
    9998                result = objectCast( dest, env, indexer );
    10099        }
    101100
    102         void PtrsCastable::postvisit( BasicType * ) {
     101        void PtrsCastable::visit( BasicType * ) {
    103102                result = objectCast( dest, env, indexer );
    104103        }
    105104
    106         void PtrsCastable::postvisit( PointerType * ) {
     105        void PtrsCastable::visit( PointerType * ) {
    107106                result = objectCast( dest, env, indexer );
    108107        }
    109108
    110         void PtrsCastable::postvisit( ArrayType * ) {
     109        void PtrsCastable::visit( ArrayType * ) {
    111110                result = objectCast( dest, env, indexer );
    112111        }
    113112
    114         void PtrsCastable::postvisit( FunctionType * ) {
     113        void PtrsCastable::visit( FunctionType * ) {
    115114                // result = -1;
    116115                result = functionCast( dest, env, indexer );
    117116        }
    118117
    119         void PtrsCastable::postvisit( StructInstType * ) {
     118        void PtrsCastable::visit( StructInstType * ) {
    120119                result = objectCast( dest, env, indexer );
    121120        }
    122121
    123         void PtrsCastable::postvisit( UnionInstType * ) {
     122        void PtrsCastable::visit( UnionInstType * ) {
    124123                result = objectCast( dest, env, indexer );
    125124        }
    126125
    127         void PtrsCastable::postvisit( EnumInstType * ) {
     126        void PtrsCastable::visit( EnumInstType * ) {
    128127                if ( dynamic_cast< EnumInstType* >( dest ) ) {
    129128                        result = 1;
     
    139138        }
    140139
    141         void PtrsCastable::postvisit( TraitInstType * ) {}
     140        void PtrsCastable::visit( TraitInstType * ) {}
    142141
    143         void PtrsCastable::postvisit(TypeInstType *inst) {
     142        void PtrsCastable::visit(TypeInstType *inst) {
    144143                //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
    145144                result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1;
    146145        }
    147146
    148         void PtrsCastable::postvisit( TupleType * ) {
     147        void PtrsCastable::visit( TupleType * ) {
    149148                result = objectCast( dest, env, indexer );
    150149        }
    151150
    152         void PtrsCastable::postvisit( VarArgsType * ) {
     151        void PtrsCastable::visit( VarArgsType * ) {
    153152                result = objectCast( dest, env, indexer );
    154153        }
    155154
    156         void PtrsCastable::postvisit( ZeroType * ) {
     155        void PtrsCastable::visit( ZeroType * ) {
    157156                result = objectCast( dest, env, indexer );
    158157        }
    159158
    160         void PtrsCastable::postvisit( OneType * ) {
     159        void PtrsCastable::visit( OneType * ) {
    161160                result = objectCast( dest, env, indexer );
    162161        }
Note: See TracChangeset for help on using the changeset viewer.