Changeset 90152a4 for src/ResolvExpr/PtrsAssignable.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
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/PtrsAssignable.cc
rf9feab8 r90152a4 14 14 // 15 15 16 #include "Common/PassVisitor.h" 16 17 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass, TypeEnvironment 17 18 #include "SynTree/Type.h" // for TypeInstType, Type, BasicType … … 20 21 21 22 namespace ResolvExpr { 22 class PtrsAssignable : public Visitor { 23 public: 23 struct PtrsAssignable : public WithShortCircuiting { 24 24 PtrsAssignable( Type *dest, const TypeEnvironment &env ); 25 25 26 26 int get_result() const { return result; } 27 27 28 virtual void visit( VoidType *voidType ); 29 virtual void visit( BasicType *basicType ); 30 virtual void visit( PointerType *pointerType ); 31 virtual void visit( ArrayType *arrayType ); 32 virtual void visit( FunctionType *functionType ); 33 virtual void visit( StructInstType *inst ); 34 virtual void visit( UnionInstType *inst ); 35 virtual void visit( EnumInstType *inst ); 36 virtual void visit( TraitInstType *inst ); 37 virtual void visit( TypeInstType *inst ); 38 virtual void visit( TupleType *tupleType ); 39 virtual void visit( VarArgsType *varArgsType ); 40 virtual void visit( ZeroType *zeroType ); 41 virtual void visit( OneType *oneType ); 28 void previsit( Type * ) { visit_children = false; } 29 30 void postvisit( VoidType * voidType ); 31 void postvisit( BasicType * basicType ); 32 void postvisit( PointerType * pointerType ); 33 void postvisit( ArrayType * arrayType ); 34 void postvisit( FunctionType * functionType ); 35 void postvisit( StructInstType * inst ); 36 void postvisit( UnionInstType * inst ); 37 void postvisit( EnumInstType * inst ); 38 void postvisit( TraitInstType * inst ); 39 void postvisit( TypeInstType * inst ); 40 void postvisit( TupleType * tupleType ); 41 void postvisit( VarArgsType * varArgsType ); 42 void postvisit( ZeroType * zeroType ); 43 void postvisit( OneType * oneType ); 42 44 private: 43 45 Type *dest; … … 49 51 // std::cerr << "assignable: " << src << " | " << dest << std::endl; 50 52 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 51 EqvClass eqvClass; 52 if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) { 53 return ptrsAssignable( src, eqvClass.type, env ); 53 if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 54 return ptrsAssignable( src, eqvClass->type, env ); 54 55 } // if 55 56 } // if … … 59 60 return -1; 60 61 } else { 61 P trsAssignableptrs( dest, env );62 PassVisitor<PtrsAssignable> ptrs( dest, env ); 62 63 src->accept( ptrs ); 63 return ptrs. get_result();64 return ptrs.pass.get_result(); 64 65 } // if 65 66 } … … 67 68 PtrsAssignable::PtrsAssignable( Type *dest, const TypeEnvironment &env ) : dest( dest ), result( 0 ), env( env ) {} 68 69 69 void PtrsAssignable:: visit( __attribute((unused)) VoidType *voidType) {70 void PtrsAssignable::postvisit( VoidType * ) { 70 71 // T * = void * is disallowed - this is a change from C, where any 71 72 // void * can be assigned or passed to a non-void pointer without a cast. 72 73 } 73 74 74 void PtrsAssignable:: visit( __attribute__((unused)) BasicType *basicType ) {}75 void PtrsAssignable:: visit( __attribute__((unused)) PointerType *pointerType ) {}76 void PtrsAssignable:: visit( __attribute__((unused)) ArrayType *arrayType ) {}77 void PtrsAssignable:: visit( __attribute__((unused)) FunctionType *functionType ) {}75 void PtrsAssignable::postvisit( __attribute__((unused)) BasicType *basicType ) {} 76 void PtrsAssignable::postvisit( __attribute__((unused)) PointerType *pointerType ) {} 77 void PtrsAssignable::postvisit( __attribute__((unused)) ArrayType *arrayType ) {} 78 void PtrsAssignable::postvisit( __attribute__((unused)) FunctionType *functionType ) {} 78 79 79 void PtrsAssignable:: visit( __attribute__((unused)) StructInstType *inst ) {}80 void PtrsAssignable:: visit( __attribute__((unused)) UnionInstType *inst ) {}80 void PtrsAssignable::postvisit( __attribute__((unused)) StructInstType *inst ) {} 81 void PtrsAssignable::postvisit( __attribute__((unused)) UnionInstType *inst ) {} 81 82 82 void PtrsAssignable:: visit( EnumInstType * ) {83 void PtrsAssignable::postvisit( EnumInstType * ) { 83 84 if ( dynamic_cast< BasicType* >( dest ) ) { 84 85 // int * = E *, etc. is safe. This isn't technically correct, as each … … 91 92 } 92 93 93 void PtrsAssignable::visit( __attribute__((unused)) TraitInstType *inst ) {} 94 void PtrsAssignable::visit( TypeInstType *inst ) { 95 EqvClass eqvClass; 96 if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) { 97 // T * = S * for any S depends on the type bound to T 98 result = ptrsAssignable( eqvClass.type, dest, env ); 94 void PtrsAssignable::postvisit( __attribute__((unused)) TraitInstType *inst ) {} 95 void PtrsAssignable::postvisit( TypeInstType *inst ) { 96 if ( const EqvClass *eqvClass = env.lookup( inst->get_name() ) ) { 97 if ( eqvClass->type ) { 98 // T * = S * for any S depends on the type bound to T 99 result = ptrsAssignable( eqvClass->type, dest, env ); 100 } 99 101 } // if 100 102 } 101 103 102 void PtrsAssignable:: visit( __attribute__((unused)) TupleType *tupleType ) {}103 void PtrsAssignable:: visit( __attribute__((unused)) VarArgsType *varArgsType ) {}104 void PtrsAssignable:: visit( __attribute__((unused)) ZeroType *zeroType ) {}105 void PtrsAssignable:: visit( __attribute__((unused)) OneType *oneType ) {}104 void PtrsAssignable::postvisit( __attribute__((unused)) TupleType *tupleType ) {} 105 void PtrsAssignable::postvisit( __attribute__((unused)) VarArgsType *varArgsType ) {} 106 void PtrsAssignable::postvisit( __attribute__((unused)) ZeroType *zeroType ) {} 107 void PtrsAssignable::postvisit( __attribute__((unused)) OneType *oneType ) {} 106 108 107 109 } // namespace ResolvExpr
Note:
See TracChangeset
for help on using the changeset viewer.