Changeset 23b6643f for src/ResolvExpr
- Timestamp:
- Sep 20, 2016, 4:47:34 PM (8 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:
- 1132b62
- Parents:
- aefcc3b (diff), db46512 (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. - Location:
- src/ResolvExpr
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
raefcc3b r23b6643f 37 37 virtual Type* mutate( TupleType *tupleType ); 38 38 virtual Type* mutate( VarArgsType *varArgsType ); 39 virtual Type* mutate( ZeroType *zeroType ); 40 virtual Type* mutate( OneType *oneType ); 39 41 40 42 const TypeEnvironment &env; … … 117 119 return varArgsType; 118 120 } 121 122 Type *AdjustExprType::mutate( ZeroType *zeroType ) { 123 return zeroType; 124 } 125 126 Type *AdjustExprType::mutate( OneType *oneType ) { 127 return oneType; 128 } 119 129 } // namespace ResolvExpr 120 130 -
src/ResolvExpr/CommonType.cc
raefcc3b r23b6643f 39 39 virtual void visit( TupleType *tupleType ); 40 40 virtual void visit( VarArgsType *varArgsType ); 41 virtual void visit( ZeroType *zeroType ); 42 virtual void visit( OneType *oneType ); 41 43 42 44 template< typename RefType > void handleRefType( RefType *inst, Type *other ); … … 134 136 result = new BasicType( basicType->get_qualifiers() + otherBasic->get_qualifiers(), newType ); 135 137 } // if 136 } else if ( EnumInstType *enumInstType = dynamic_cast< EnumInstType * >( type2 ) ) {137 // use signed int in lieu of the enum type138 } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { 139 // use signed int in lieu of the enum/zero/one type 138 140 BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ]; 139 if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= enumInstType->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= enumInstType->get_qualifiers() ) || widenSecond ) ) {140 result = new BasicType( basicType->get_qualifiers() + enumInstType->get_qualifiers(), newType );141 if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) { 142 result = new BasicType( basicType->get_qualifiers() + type2->get_qualifiers(), newType ); 141 143 } // if 142 144 } // if … … 171 173 otherPointer->get_base()->get_qualifiers() = tq2; 172 174 } // if 175 } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { 176 result = pointerType->clone(); 177 result->get_qualifiers() += type2->get_qualifiers(); 173 178 } // if 174 179 } … … 190 195 191 196 void CommonType::visit( EnumInstType *enumInstType ) { 192 if ( dynamic_cast< BasicType * >( type2 ) ) {197 if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { 193 198 // reuse BasicType, EnumInstType code by swapping type2 with enumInstType 194 199 Type * temp = type2; … … 230 235 void CommonType::visit( VarArgsType *varArgsType ) { 231 236 } 237 238 void CommonType::visit( ZeroType *zeroType ) { 239 if ( widenFirst ) { 240 if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { 241 if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) { 242 result = type2->clone(); 243 result->get_qualifiers() += zeroType->get_qualifiers(); 244 } 245 } 246 } 247 } 248 249 void CommonType::visit( OneType *oneType ) { 250 if ( widenFirst ) { 251 if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { 252 if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) { 253 result = type2->clone(); 254 result->get_qualifiers() += oneType->get_qualifiers(); 255 } 256 } 257 } 258 } 232 259 } // namespace ResolvExpr 233 260 -
src/ResolvExpr/ConversionCost.cc
raefcc3b r23b6643f 160 160 // xxx - not positive this is correct, but appears to allow casting int => enum 161 161 cost = Cost( 1, 0, 0 ); 162 } // if 162 } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) { 163 cost = Cost( 1, 0, 0 ); 164 } // if 163 165 } 164 166 … … 175 177 } // if 176 178 } // if 179 } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) { 180 cost = Cost( 1, 0, 0 ); 177 181 } // if 178 182 } … … 256 260 } 257 261 } 262 263 void ConversionCost::visit(ZeroType *zeroType) { 264 if ( dynamic_cast< ZeroType* >( dest ) ) { 265 cost = Cost::zero; 266 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) { 267 // copied from visit(BasicType*) for signed int, but +1 for safe conversions 268 int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ]; 269 if ( tableResult == -1 ) { 270 cost = Cost( 1, 0, 0 ); 271 } else { 272 cost = Cost( 0, 0, tableResult + 1 ); 273 } 274 } else if ( dynamic_cast< PointerType* >( dest ) ) { 275 cost = Cost( 0, 0, 1 ); 276 } 277 } 278 279 void ConversionCost::visit(OneType *oneType) { 280 if ( dynamic_cast< OneType* >( dest ) ) { 281 cost = Cost::zero; 282 } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) { 283 // copied from visit(BasicType*) for signed int, but +1 for safe conversions 284 int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ]; 285 if ( tableResult == -1 ) { 286 cost = Cost( 1, 0, 0 ); 287 } else { 288 cost = Cost( 0, 0, tableResult + 1 ); 289 } 290 } 291 } 258 292 } // namespace ResolvExpr 259 293 -
src/ResolvExpr/ConversionCost.h
raefcc3b r23b6643f 41 41 virtual void visit(TupleType *tupleType); 42 42 virtual void visit(VarArgsType *varArgsType); 43 virtual void visit(ZeroType *zeroType); 44 virtual void visit(OneType *oneType); 43 45 protected: 44 46 Type *dest; -
src/ResolvExpr/PtrsAssignable.cc
raefcc3b r23b6643f 39 39 virtual void visit( TupleType *tupleType ); 40 40 virtual void visit( VarArgsType *varArgsType ); 41 virtual void visit( ZeroType *zeroType ); 42 virtual void visit( OneType *oneType ); 41 43 private: 42 44 Type *dest; … … 141 143 void PtrsAssignable::visit( VarArgsType *varArgsType ) { 142 144 } 145 146 void PtrsAssignable::visit( ZeroType *zeroType ) { 147 } 148 149 void PtrsAssignable::visit( OneType *oneType ) { 150 } 151 143 152 } // namespace ResolvExpr 144 153 -
src/ResolvExpr/PtrsCastable.cc
raefcc3b r23b6643f 40 40 virtual void visit(TupleType *tupleType); 41 41 virtual void visit(VarArgsType *varArgsType); 42 virtual void visit(ZeroType *zeroType); 43 virtual void visit(OneType *oneType); 42 44 private: 43 45 Type *dest; … … 144 146 result = objectCast( dest, env, indexer ); 145 147 } 148 149 void PtrsCastable::visit(ZeroType *zeroType) { 150 result = objectCast( dest, env, indexer ); 151 } 152 153 void PtrsCastable::visit(OneType *oneType) { 154 result = objectCast( dest, env, indexer ); 155 } 146 156 } // namespace ResolvExpr 147 157 -
src/ResolvExpr/RenameVars.cc
raefcc3b r23b6643f 110 110 } 111 111 112 void RenameVars::visit( ZeroType *zeroType ) { 113 typeBefore( zeroType ); 114 typeAfter( zeroType ); 115 } 116 117 void RenameVars::visit( OneType *oneType ) { 118 typeBefore( oneType ); 119 typeAfter( oneType ); 120 } 121 112 122 void RenameVars::typeBefore( Type *type ) { 113 123 if ( ! type->get_forall().empty() ) { -
src/ResolvExpr/RenameVars.h
raefcc3b r23b6643f 44 44 virtual void visit( TupleType *tupleType ); 45 45 virtual void visit( VarArgsType *varArgsType ); 46 virtual void visit( ZeroType *zeroType ); 47 virtual void visit( OneType *oneType ); 46 48 47 49 void typeBefore( Type *type ); -
src/ResolvExpr/Resolver.cc
raefcc3b r23b6643f 134 134 } else if ( BasicType *bt = dynamic_cast< BasicType * >( type ) ) { 135 135 return bt->isInteger(); 136 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) { 137 return true; 136 138 } else { 137 139 return false; … … 455 457 } 456 458 } else { 457 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) ); 459 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext ) 460 || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) ); 458 461 // basic types are handled here 459 462 Visitor::visit( listInit ); -
src/ResolvExpr/Unify.cc
raefcc3b r23b6643f 60 60 virtual void visit(TupleType *tupleType); 61 61 virtual void visit(VarArgsType *varArgsType); 62 virtual void visit(ZeroType *zeroType); 63 virtual void visit(OneType *oneType); 62 64 63 65 template< typename RefType > void handleRefType( RefType *inst, Type *other ); … … 588 590 } 589 591 592 void Unify::visit(ZeroType *zeroType) { 593 result = dynamic_cast< ZeroType* >( type2 ); 594 } 595 596 void Unify::visit(OneType *oneType) { 597 result = dynamic_cast< OneType* >( type2 ); 598 } 599 590 600 // xxx - compute once and store in the FunctionType? 591 601 Type * extractResultType( FunctionType * function ) { … … 602 612 } 603 613 } 604 605 614 } // namespace ResolvExpr 606 615
Note: See TracChangeset
for help on using the changeset viewer.