Changes in src/ResolvExpr/PtrsCastable.cc [7870799:3c89751]
- File:
-
- 1 edited
-
src/ResolvExpr/PtrsCastable.cc (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/PtrsCastable.cc
r7870799 r3c89751 29 29 struct PtrsCastable_old : public WithShortCircuiting { 30 30 public: 31 PtrsCastable_old( const Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );31 PtrsCastable_old( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ); 32 32 33 33 int get_result() const { return result; } 34 34 35 void previsit( constType * ) { visit_children = false; }36 37 void postvisit( constVoidType * voidType );38 void postvisit( constBasicType * basicType );39 void postvisit( constPointerType * pointerType );40 void postvisit( constArrayType * arrayType );41 void postvisit( constFunctionType * functionType );42 void postvisit( constStructInstType * inst );43 void postvisit( constUnionInstType * inst );44 void postvisit( constEnumInstType * inst );45 void postvisit( constTraitInstType * inst );46 void postvisit( constTypeInstType * inst );47 void postvisit( constTupleType * tupleType );48 void postvisit( constVarArgsType * varArgsType );49 void postvisit( constZeroType * zeroType );50 void postvisit( constOneType * oneType );35 void previsit( Type * ) { visit_children = false; } 36 37 void postvisit( VoidType * voidType ); 38 void postvisit( BasicType * basicType ); 39 void postvisit( PointerType * pointerType ); 40 void postvisit( ArrayType * arrayType ); 41 void postvisit( FunctionType * functionType ); 42 void postvisit( StructInstType * inst ); 43 void postvisit( UnionInstType * inst ); 44 void postvisit( EnumInstType * inst ); 45 void postvisit( TraitInstType * inst ); 46 void postvisit( TypeInstType * inst ); 47 void postvisit( TupleType * tupleType ); 48 void postvisit( VarArgsType * varArgsType ); 49 void postvisit( ZeroType * zeroType ); 50 void postvisit( OneType * oneType ); 51 51 private: 52 const Type *dest;52 Type *dest; 53 53 int result; 54 54 const TypeEnvironment &env; … … 57 57 58 58 namespace { 59 int objectCast( const Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {60 if ( dynamic_cast< constFunctionType* >( src ) ) {59 int objectCast( Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 60 if ( dynamic_cast< FunctionType* >( src ) ) { 61 61 return -1; 62 } else if ( const TypeInstType * typeInst = dynamic_cast< constTypeInstType* >( src ) ) {63 if ( const NamedTypeDecl * ntDecl = indexer.lookupType( typeInst->name) ) {64 if ( const TypeDecl * tyDecl = dynamic_cast< constTypeDecl* >( ntDecl ) ) {65 if ( tyDecl-> kind== TypeDecl::Ftype ) {62 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( src ) ) { 63 if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 64 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { 65 if ( tyDecl->get_kind() == TypeDecl::Ftype ) { 66 66 return -1; 67 67 } // if 68 68 } //if 69 } else if ( const EqvClass * eqvClass = env.lookup( typeInst->get_name() ) ) {69 } else if ( const EqvClass *eqvClass = env.lookup( typeInst->get_name() ) ) { 70 70 if ( eqvClass->data.kind == TypeDecl::Ftype ) { 71 71 return -1; … … 75 75 return 1; 76 76 } 77 int functionCast( const Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {77 int functionCast( Type *src, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 78 78 return -1 * objectCast( src, env, indexer ); // reverse the sense of objectCast 79 79 } 80 80 } 81 81 82 int ptrsCastable( const Type * src, const Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {83 if ( const TypeInstType * destAsTypeInst = dynamic_cast< constTypeInstType* >( dest ) ) {84 if ( const EqvClass * eqvClass = env.lookup( destAsTypeInst->get_name() ) ) {82 int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 83 if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) { 84 if ( const EqvClass *eqvClass = env.lookup( destAsTypeInst->get_name() ) ) { 85 85 // xxx - should this be ptrsCastable? 86 86 return ptrsAssignable( src, eqvClass->type, env ); 87 87 } // if 88 88 } // if 89 if ( dynamic_cast< constVoidType* >( dest ) ) {89 if ( dynamic_cast< VoidType* >( dest ) ) { 90 90 return objectCast( src, env, indexer ); 91 91 } else { … … 96 96 } 97 97 98 PtrsCastable_old::PtrsCastable_old( const Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer )98 PtrsCastable_old::PtrsCastable_old( Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer ) 99 99 : dest( dest ), result( 0 ), env( env ), indexer( indexer ) { 100 100 } 101 101 102 void PtrsCastable_old::postvisit( constVoidType * ) {103 result = objectCast( dest, env, indexer ); 104 } 105 106 void PtrsCastable_old::postvisit( constBasicType * ) {107 result = objectCast( dest, env, indexer ); 108 } 109 110 void PtrsCastable_old::postvisit( constPointerType * ) {111 result = objectCast( dest, env, indexer ); 112 } 113 114 void PtrsCastable_old::postvisit( constArrayType * ) {115 result = objectCast( dest, env, indexer ); 116 } 117 118 void PtrsCastable_old::postvisit( constFunctionType * ) {102 void PtrsCastable_old::postvisit( VoidType * ) { 103 result = objectCast( dest, env, indexer ); 104 } 105 106 void PtrsCastable_old::postvisit( BasicType * ) { 107 result = objectCast( dest, env, indexer ); 108 } 109 110 void PtrsCastable_old::postvisit( PointerType * ) { 111 result = objectCast( dest, env, indexer ); 112 } 113 114 void PtrsCastable_old::postvisit( ArrayType * ) { 115 result = objectCast( dest, env, indexer ); 116 } 117 118 void PtrsCastable_old::postvisit( FunctionType * ) { 119 119 // result = -1; 120 120 result = functionCast( dest, env, indexer ); 121 121 } 122 122 123 void PtrsCastable_old::postvisit( constStructInstType * ) {124 result = objectCast( dest, env, indexer ); 125 } 126 127 void PtrsCastable_old::postvisit( constUnionInstType * ) {128 result = objectCast( dest, env, indexer ); 129 } 130 131 void PtrsCastable_old::postvisit( constEnumInstType * ) {132 if ( dynamic_cast< const EnumInstType* >( dest ) ) {123 void PtrsCastable_old::postvisit( StructInstType * ) { 124 result = objectCast( dest, env, indexer ); 125 } 126 127 void PtrsCastable_old::postvisit( UnionInstType * ) { 128 result = objectCast( dest, env, indexer ); 129 } 130 131 void PtrsCastable_old::postvisit( EnumInstType * ) { 132 if ( dynamic_cast< EnumInstType* >( dest ) ) { 133 133 result = 1; 134 } else if ( const BasicType * bt = dynamic_cast< const BasicType* >( dest ) ) {135 if ( bt-> kind== BasicType::SignedInt ) {134 } else if ( BasicType *bt = dynamic_cast< BasicType* >( dest ) ) { 135 if ( bt->get_kind() == BasicType::SignedInt ) { 136 136 result = 0; 137 137 } else { … … 143 143 } 144 144 145 void PtrsCastable_old::postvisit( constTraitInstType * ) {}146 147 void PtrsCastable_old::postvisit( constTypeInstType *inst ) {145 void PtrsCastable_old::postvisit( TraitInstType * ) {} 146 147 void PtrsCastable_old::postvisit(TypeInstType *inst ) { 148 148 //result = objectCast( inst, env, indexer ) > 0 && objectCast( dest, env, indexer ) > 0 ? 1 : -1; 149 149 result = objectCast( inst, env, indexer ) == objectCast( dest, env, indexer ) ? 1 : -1; 150 150 } 151 151 152 void PtrsCastable_old::postvisit( constTupleType * ) {153 result = objectCast( dest, env, indexer ); 154 } 155 156 void PtrsCastable_old::postvisit( constVarArgsType * ) {157 result = objectCast( dest, env, indexer ); 158 } 159 160 void PtrsCastable_old::postvisit( constZeroType * ) {161 result = objectCast( dest, env, indexer ); 162 } 163 164 void PtrsCastable_old::postvisit( constOneType * ) {152 void PtrsCastable_old::postvisit( TupleType * ) { 153 result = objectCast( dest, env, indexer ); 154 } 155 156 void PtrsCastable_old::postvisit( VarArgsType * ) { 157 result = objectCast( dest, env, indexer ); 158 } 159 160 void PtrsCastable_old::postvisit( ZeroType * ) { 161 result = objectCast( dest, env, indexer ); 162 } 163 164 void PtrsCastable_old::postvisit( OneType * ) { 165 165 result = objectCast( dest, env, indexer ); 166 166 } … … 168 168 namespace { 169 169 // can this type be cast to an object (1 for yes, -1 for no) 170 int objectCast( 171 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 170 int objectCast( 171 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 172 172 ) { 173 173 if ( dynamic_cast< const ast::FunctionType * >( src ) ) { … … 191 191 192 192 // can this type be cast to a function (inverse of objectCast) 193 int functionCast( 194 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 193 int functionCast( 194 const ast::Type * src, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 195 195 ) { 196 196 return -1 * objectCast( src, env, symtab ); … … 204 204 int result; 205 205 206 PtrsCastable_new( 206 PtrsCastable_new( 207 207 const ast::Type * d, const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 208 208 : dst( d ), env( e ), symtab( syms ), result( 0 ) {} … … 278 278 } // anonymous namespace 279 279 280 int ptrsCastable( 281 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 282 const ast::TypeEnvironment & env 280 int ptrsCastable( 281 const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab, 282 const ast::TypeEnvironment & env 283 283 ) { 284 284 if ( auto inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.