Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/PtrsCastable.cc

    rf9feab8 r90152a4  
    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;
     
    5557                                return -1;
    5658                        } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) {
    57                                 EqvClass eqvClass;
    5859                                if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
    5960                                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
     
    6263                                                } // if
    6364                                        } //if
    64                                 } else if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
    65                                         if ( eqvClass.data.kind == TypeDecl::Ftype ) {
     65                                } else if ( const EqvClass *eqvClass = env.lookup( typeInst->get_name() ) ) {
     66                                        if ( eqvClass->data.kind == TypeDecl::Ftype ) {
    6667                                                return -1;
    6768                                        } // if
     
    7778        int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    7879                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
    79                         EqvClass eqvClass;
    80                         if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
    81                                 return ptrsAssignable( src, eqvClass.type, env );
     80                        if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {
     81                                // xxx - should this be ptrsCastable?
     82                                return ptrsAssignable( src, eqvClass->type, env );
    8283                        } // if
    8384                } // if
     
    8586                        return objectCast( src, env, indexer );
    8687                } else {
    87                         PtrsCastable ptrs( dest, env, indexer );
     88                        PassVisitor<PtrsCastable> ptrs( dest, env, indexer );
    8889                        src->accept( ptrs );
    89                         return ptrs.get_result();
     90                        return ptrs.pass.get_result();
    9091                } // if
    9192        }
     
    9596        }
    9697
    97         void PtrsCastable::visit( VoidType * ) {
     98        void PtrsCastable::postvisit( VoidType * ) {
    9899                result = objectCast( dest, env, indexer );
    99100        }
    100101
    101         void PtrsCastable::visit( BasicType * ) {
     102        void PtrsCastable::postvisit( BasicType * ) {
    102103                result = objectCast( dest, env, indexer );
    103104        }
    104105
    105         void PtrsCastable::visit( PointerType * ) {
     106        void PtrsCastable::postvisit( PointerType * ) {
    106107                result = objectCast( dest, env, indexer );
    107108        }
    108109
    109         void PtrsCastable::visit( ArrayType * ) {
     110        void PtrsCastable::postvisit( ArrayType * ) {
    110111                result = objectCast( dest, env, indexer );
    111112        }
    112113
    113         void PtrsCastable::visit( FunctionType * ) {
     114        void PtrsCastable::postvisit( FunctionType * ) {
    114115                // result = -1;
    115116                result = functionCast( dest, env, indexer );
    116117        }
    117118
    118         void PtrsCastable::visit( StructInstType * ) {
     119        void PtrsCastable::postvisit( StructInstType * ) {
    119120                result = objectCast( dest, env, indexer );
    120121        }
    121122
    122         void PtrsCastable::visit( UnionInstType * ) {
     123        void PtrsCastable::postvisit( UnionInstType * ) {
    123124                result = objectCast( dest, env, indexer );
    124125        }
    125126
    126         void PtrsCastable::visit( EnumInstType * ) {
     127        void PtrsCastable::postvisit( EnumInstType * ) {
    127128                if ( dynamic_cast< EnumInstType* >( dest ) ) {
    128129                        result = 1;
     
    138139        }
    139140
    140         void PtrsCastable::visit( TraitInstType * ) {}
     141        void PtrsCastable::postvisit( TraitInstType * ) {}
    141142
    142         void PtrsCastable::visit(TypeInstType *inst) {
     143        void PtrsCastable::postvisit(TypeInstType *inst) {
    143144                //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1;
    144145                result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1;
    145146        }
    146147
    147         void PtrsCastable::visit( TupleType * ) {
     148        void PtrsCastable::postvisit( TupleType * ) {
    148149                result = objectCast( dest, env, indexer );
    149150        }
    150151
    151         void PtrsCastable::visit( VarArgsType * ) {
     152        void PtrsCastable::postvisit( VarArgsType * ) {
    152153                result = objectCast( dest, env, indexer );
    153154        }
    154155
    155         void PtrsCastable::visit( ZeroType * ) {
     156        void PtrsCastable::postvisit( ZeroType * ) {
    156157                result = objectCast( dest, env, indexer );
    157158        }
    158159
    159         void PtrsCastable::visit( OneType * ) {
     160        void PtrsCastable::postvisit( OneType * ) {
    160161                result = objectCast( dest, env, indexer );
    161162        }
Note: See TracChangeset for help on using the changeset viewer.