Changeset 12145b9
- Timestamp:
- Jan 15, 2018, 3:10:55 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- f07c1e6
- Parents:
- c0b9f5d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/PtrsCastable.cc
rc0b9f5d r12145b9 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; … … 79 81 EqvClass eqvClass; 80 82 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 83 // xxx - should this be ptrsCastable? 81 84 return ptrsAssignable( src, eqvClass.type, env ); 82 85 } // if … … 85 88 return objectCast( src, env, indexer ); 86 89 } else { 87 P trsCastableptrs( dest, env, indexer );90 PassVisitor<PtrsCastable> ptrs( dest, env, indexer ); 88 91 src->accept( ptrs ); 89 return ptrs. get_result();92 return ptrs.pass.get_result(); 90 93 } // if 91 94 } … … 95 98 } 96 99 97 void PtrsCastable:: visit( VoidType * ) {100 void PtrsCastable::postvisit( VoidType * ) { 98 101 result = objectCast( dest, env, indexer ); 99 102 } 100 103 101 void PtrsCastable:: visit( BasicType * ) {104 void PtrsCastable::postvisit( BasicType * ) { 102 105 result = objectCast( dest, env, indexer ); 103 106 } 104 107 105 void PtrsCastable:: visit( PointerType * ) {108 void PtrsCastable::postvisit( PointerType * ) { 106 109 result = objectCast( dest, env, indexer ); 107 110 } 108 111 109 void PtrsCastable:: visit( ArrayType * ) {112 void PtrsCastable::postvisit( ArrayType * ) { 110 113 result = objectCast( dest, env, indexer ); 111 114 } 112 115 113 void PtrsCastable:: visit( FunctionType * ) {116 void PtrsCastable::postvisit( FunctionType * ) { 114 117 // result = -1; 115 118 result = functionCast( dest, env, indexer ); 116 119 } 117 120 118 void PtrsCastable:: visit( StructInstType * ) {121 void PtrsCastable::postvisit( StructInstType * ) { 119 122 result = objectCast( dest, env, indexer ); 120 123 } 121 124 122 void PtrsCastable:: visit( UnionInstType * ) {125 void PtrsCastable::postvisit( UnionInstType * ) { 123 126 result = objectCast( dest, env, indexer ); 124 127 } 125 128 126 void PtrsCastable:: visit( EnumInstType * ) {129 void PtrsCastable::postvisit( EnumInstType * ) { 127 130 if ( dynamic_cast< EnumInstType* >( dest ) ) { 128 131 result = 1; … … 138 141 } 139 142 140 void PtrsCastable:: visit( TraitInstType * ) {}143 void PtrsCastable::postvisit( TraitInstType * ) {} 141 144 142 void PtrsCastable:: visit(TypeInstType *inst) {145 void PtrsCastable::postvisit(TypeInstType *inst) { 143 146 //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1; 144 147 result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1; 145 148 } 146 149 147 void PtrsCastable:: visit( TupleType * ) {150 void PtrsCastable::postvisit( TupleType * ) { 148 151 result = objectCast( dest, env, indexer ); 149 152 } 150 153 151 void PtrsCastable:: visit( VarArgsType * ) {154 void PtrsCastable::postvisit( VarArgsType * ) { 152 155 result = objectCast( dest, env, indexer ); 153 156 } 154 157 155 void PtrsCastable:: visit( ZeroType * ) {158 void PtrsCastable::postvisit( ZeroType * ) { 156 159 result = objectCast( dest, env, indexer ); 157 160 } 158 161 159 void PtrsCastable:: visit( OneType * ) {162 void PtrsCastable::postvisit( OneType * ) { 160 163 result = objectCast( dest, env, indexer ); 161 164 }
Note: See TracChangeset
for help on using the changeset viewer.