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