Changes in src/ResolvExpr/PtrsCastable.cc [00ac42e:b0837e4]
- File:
-
- 1 edited
-
src/ResolvExpr/PtrsCastable.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/PtrsCastable.cc
r00ac42e rb0837e4 14 14 // 15 15 16 #include "Common/PassVisitor.h"17 16 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass, TypeEnvironment 18 17 #include "SymTab/Indexer.h" // for Indexer … … 22 21 #include "typeops.h" // for ptrsAssignable 23 22 23 24 24 namespace ResolvExpr { 25 struct PtrsCastable : public WithShortCircuiting{25 class PtrsCastable : public Visitor { 26 26 public: 27 27 PtrsCastable( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ); … … 29 29 int get_result() const { return result; } 30 30 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); 47 45 private: 48 46 Type *dest; … … 57 55 return -1; 58 56 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) { 57 EqvClass eqvClass; 59 58 if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 60 59 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { … … 63 62 } // if 64 63 } //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 ) { 67 66 return -1; 68 67 } // if … … 78 77 int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 79 78 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 ); 83 82 } // if 84 83 } // if … … 86 85 return objectCast( src, env, indexer ); 87 86 } else { 88 P assVisitor<PtrsCastable>ptrs( dest, env, indexer );87 PtrsCastable ptrs( dest, env, indexer ); 89 88 src->accept( ptrs ); 90 return ptrs. pass.get_result();89 return ptrs.get_result(); 91 90 } // if 92 91 } … … 96 95 } 97 96 98 void PtrsCastable:: postvisit( VoidType * ) {97 void PtrsCastable::visit( VoidType * ) { 99 98 result = objectCast( dest, env, indexer ); 100 99 } 101 100 102 void PtrsCastable:: postvisit( BasicType * ) {101 void PtrsCastable::visit( BasicType * ) { 103 102 result = objectCast( dest, env, indexer ); 104 103 } 105 104 106 void PtrsCastable:: postvisit( PointerType * ) {105 void PtrsCastable::visit( PointerType * ) { 107 106 result = objectCast( dest, env, indexer ); 108 107 } 109 108 110 void PtrsCastable:: postvisit( ArrayType * ) {109 void PtrsCastable::visit( ArrayType * ) { 111 110 result = objectCast( dest, env, indexer ); 112 111 } 113 112 114 void PtrsCastable:: postvisit( FunctionType * ) {113 void PtrsCastable::visit( FunctionType * ) { 115 114 // result = -1; 116 115 result = functionCast( dest, env, indexer ); 117 116 } 118 117 119 void PtrsCastable:: postvisit( StructInstType * ) {118 void PtrsCastable::visit( StructInstType * ) { 120 119 result = objectCast( dest, env, indexer ); 121 120 } 122 121 123 void PtrsCastable:: postvisit( UnionInstType * ) {122 void PtrsCastable::visit( UnionInstType * ) { 124 123 result = objectCast( dest, env, indexer ); 125 124 } 126 125 127 void PtrsCastable:: postvisit( EnumInstType * ) {126 void PtrsCastable::visit( EnumInstType * ) { 128 127 if ( dynamic_cast< EnumInstType* >( dest ) ) { 129 128 result = 1; … … 139 138 } 140 139 141 void PtrsCastable:: postvisit( TraitInstType * ) {}140 void PtrsCastable::visit( TraitInstType * ) {} 142 141 143 void PtrsCastable:: postvisit(TypeInstType *inst) {142 void PtrsCastable::visit(TypeInstType *inst) { 144 143 //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1; 145 144 result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1; 146 145 } 147 146 148 void PtrsCastable:: postvisit( TupleType * ) {147 void PtrsCastable::visit( TupleType * ) { 149 148 result = objectCast( dest, env, indexer ); 150 149 } 151 150 152 void PtrsCastable:: postvisit( VarArgsType * ) {151 void PtrsCastable::visit( VarArgsType * ) { 153 152 result = objectCast( dest, env, indexer ); 154 153 } 155 154 156 void PtrsCastable:: postvisit( ZeroType * ) {155 void PtrsCastable::visit( ZeroType * ) { 157 156 result = objectCast( dest, env, indexer ); 158 157 } 159 158 160 void PtrsCastable:: postvisit( OneType * ) {159 void PtrsCastable::visit( OneType * ) { 161 160 result = objectCast( dest, env, indexer ); 162 161 }
Note:
See TracChangeset
for help on using the changeset viewer.