- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/PtrsAssignable.cc
r5ccb10d rb0837e4 14 14 // 15 15 16 #include "typeops.h" 17 #include "SynTree/Type.h" 18 #include "SynTree/Declaration.h" 19 #include "SynTree/Visitor.h" 16 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass, TypeEnvironment 17 #include "SynTree/Type.h" // for TypeInstType, Type, BasicType 18 #include "SynTree/Visitor.h" // for Visitor 20 19 21 20 … … 48 47 49 48 int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env ) { 49 // std::cerr << "assignable: " << src << " | " << dest << std::endl; 50 50 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 51 51 EqvClass eqvClass; … … 55 55 } // if 56 56 if ( dynamic_cast< VoidType* >( dest ) ) { 57 return 1; 57 // void * = T * for any T is unsafe 58 // xxx - this should be safe, but that currently breaks the build 59 return -1; 58 60 } else { 59 61 PtrsAssignable ptrs( dest, env ); … … 66 68 67 69 void PtrsAssignable::visit( __attribute((unused)) VoidType *voidType ) { 68 if ( dynamic_cast< FunctionType* >( dest ) ) {69 result = 0;70 } else {71 result = -1;70 if ( ! dynamic_cast< FunctionType* >( dest ) ) { 71 // T * = void * is safe for any T that is not a function type. 72 // xxx - this should be unsafe... 73 result = 1; 72 74 } // if 73 75 } … … 76 78 void PtrsAssignable::visit( __attribute__((unused)) PointerType *pointerType ) {} 77 79 void PtrsAssignable::visit( __attribute__((unused)) ArrayType *arrayType ) {} 78 void PtrsAssignable::visit( __attribute__((unused)) FunctionType *functionType ) { 79 result = -1; 80 } 80 void PtrsAssignable::visit( __attribute__((unused)) FunctionType *functionType ) {} 81 81 82 82 void PtrsAssignable::visit( __attribute__((unused)) StructInstType *inst ) {} … … 84 84 85 85 void PtrsAssignable::visit( EnumInstType * ) { 86 if ( dynamic_cast< EnumInstType* >( dest ) ) { 86 if ( dynamic_cast< BasicType* >( dest ) ) { 87 // int * = E *, etc. is safe. This isn't technically correct, as each 88 // enum has one basic type that it is compatible with, an that type can 89 // differ from enum to enum. Without replicating GCC's internal logic, 90 // there is no way to know which type this particular enum is compatible 91 // with, so punt on this for now. 87 92 result = 1; 88 } else if ( BasicType *bt = dynamic_cast< BasicType* >( dest ) ) {89 result = bt->get_kind() == BasicType::SignedInt;90 93 } 91 94 } … … 95 98 EqvClass eqvClass; 96 99 if ( env.lookup( inst->get_name(), eqvClass ) && eqvClass.type ) { 100 // T * = S * for any S depends on the type bound to T 97 101 result = ptrsAssignable( eqvClass.type, dest, env ); 98 } else {99 result = 0;100 102 } // if 101 103 }
Note:
See TracChangeset
for help on using the changeset viewer.