Changeset bd0b6b62
- Timestamp:
- Jan 11, 2018, 11:15:15 AM (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:
- 0690350
- Parents:
- 721cd19f
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CastCost.cc
r721cd19f rbd0b6b62 31 31 32 32 namespace ResolvExpr { 33 classCastCost : public ConversionCost {33 struct CastCost : public ConversionCost { 34 34 public: 35 35 CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc ); 36 36 37 virtual void visit( BasicType *basicType ); 38 virtual void visit( PointerType *pointerType ); 37 using ConversionCost::previsit; 38 using ConversionCost::postvisit; 39 void postvisit( BasicType * basicType ); 40 void postvisit( PointerType * pointerType ); 39 41 }; 40 42 … … 78 80 }); 79 81 } else { 80 CastCostconverter( dest, indexer, env, castCost );82 PassVisitor<CastCost> converter( dest, indexer, env, castCost ); 81 83 src->accept( converter ); 82 if ( converter. get_cost() == Cost::infinity ) {84 if ( converter.pass.get_cost() == Cost::infinity ) { 83 85 return Cost::infinity; 84 86 } else { 85 87 // xxx - why are we adding cost 0 here? 86 return converter. get_cost() + Cost::zero;88 return converter.pass.get_cost() + Cost::zero; 87 89 } // if 88 90 } // if … … 93 95 } 94 96 95 void CastCost:: visit( BasicType *basicType ) {97 void CastCost::postvisit( BasicType *basicType ) { 96 98 PointerType *destAsPointer = dynamic_cast< PointerType* >( dest ); 97 99 if ( destAsPointer && basicType->isInteger() ) { … … 103 105 } 104 106 105 void CastCost:: visit( PointerType *pointerType ) {107 void CastCost::postvisit( PointerType *pointerType ) { 106 108 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) { 107 109 if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) { -
src/ResolvExpr/ConversionCost.cc
r721cd19f rbd0b6b62 81 81 }); 82 82 } else { 83 ConversionCostconverter( dest, indexer, env, conversionCost );83 PassVisitor<ConversionCost> converter( dest, indexer, env, conversionCost ); 84 84 src->accept( converter ); 85 if ( converter. get_cost() == Cost::infinity ) {85 if ( converter.pass.get_cost() == Cost::infinity ) { 86 86 return Cost::infinity; 87 87 } else { 88 return converter. get_cost() + Cost::zero;88 return converter.pass.get_cost() + Cost::zero; 89 89 } // if 90 90 } // if … … 130 130 } else { 131 131 PRINT( std::cerr << "reference to rvalue conversion" << std::endl; ) 132 ConversionCostconverter( dest, indexer, env, conversionCost );132 PassVisitor<ConversionCost> converter( dest, indexer, env, conversionCost ); 133 133 src->accept( converter ); 134 return converter. get_cost();134 return converter.pass.get_cost(); 135 135 } // if 136 136 } else { … … 257 257 }; 258 258 259 void ConversionCost:: visit( VoidType * ) {259 void ConversionCost::postvisit( VoidType * ) { 260 260 cost = Cost::infinity; 261 261 } 262 262 263 void ConversionCost:: visit(BasicType *basicType) {263 void ConversionCost::postvisit(BasicType *basicType) { 264 264 if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) { 265 265 int tableResult = costMatrix[ basicType->get_kind() ][ destAsBasic->get_kind() ]; … … 278 278 } 279 279 280 void ConversionCost:: visit( PointerType * pointerType ) {280 void ConversionCost::postvisit( PointerType * pointerType ) { 281 281 if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) { 282 282 PRINT( std::cerr << pointerType << " ===> " << destAsPtr << std::endl; ) … … 312 312 } 313 313 314 void ConversionCost:: visit( ArrayType * ) {}315 316 void ConversionCost:: visit( ReferenceType * refType ) {314 void ConversionCost::postvisit( ArrayType * ) {} 315 316 void ConversionCost::postvisit( ReferenceType * refType ) { 317 317 // Note: dest can never be a reference, since it would have been caught in an earlier check 318 318 assert( ! dynamic_cast< ReferenceType * >( dest ) ); … … 331 331 } 332 332 333 void ConversionCost:: visit( FunctionType * ) {}334 335 void ConversionCost:: visit( StructInstType * inst ) {333 void ConversionCost::postvisit( FunctionType * ) {} 334 335 void ConversionCost::postvisit( StructInstType * inst ) { 336 336 if ( StructInstType *destAsInst = dynamic_cast< StructInstType* >( dest ) ) { 337 337 if ( inst->name == destAsInst->name ) { … … 341 341 } 342 342 343 void ConversionCost:: visit( UnionInstType * inst ) {343 void ConversionCost::postvisit( UnionInstType * inst ) { 344 344 if ( UnionInstType *destAsInst = dynamic_cast< UnionInstType* >( dest ) ) { 345 345 if ( inst->name == destAsInst->name ) { … … 349 349 } 350 350 351 void ConversionCost:: visit( EnumInstType * ) {351 void ConversionCost::postvisit( EnumInstType * ) { 352 352 static Type::Qualifiers q; 353 353 static BasicType integer( q, BasicType::SignedInt ); … … 358 358 } 359 359 360 void ConversionCost:: visit( TraitInstType * ) {}361 362 void ConversionCost:: visit( TypeInstType *inst ) {360 void ConversionCost::postvisit( TraitInstType * ) {} 361 362 void ConversionCost::postvisit( TypeInstType *inst ) { 363 363 EqvClass eqvClass; 364 364 NamedTypeDecl *namedType; … … 379 379 } 380 380 381 void ConversionCost:: visit( TupleType * tupleType ) {381 void ConversionCost::postvisit( TupleType * tupleType ) { 382 382 Cost c = Cost::zero; 383 383 if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) { … … 399 399 } 400 400 401 void ConversionCost:: visit( VarArgsType * ) {401 void ConversionCost::postvisit( VarArgsType * ) { 402 402 if ( dynamic_cast< VarArgsType* >( dest ) ) { 403 403 cost = Cost::zero; … … 405 405 } 406 406 407 void ConversionCost:: visit( ZeroType * ) {407 void ConversionCost::postvisit( ZeroType * ) { 408 408 if ( dynamic_cast< ZeroType * >( dest ) ) { 409 409 cost = Cost::zero; … … 422 422 } 423 423 424 void ConversionCost:: visit( OneType * ) {424 void ConversionCost::postvisit( OneType * ) { 425 425 if ( dynamic_cast< OneType * >( dest ) ) { 426 426 cost = Cost::zero; -
src/ResolvExpr/ConversionCost.h
r721cd19f rbd0b6b62 19 19 20 20 #include "Cost.h" // for Cost 21 22 #include "Common/PassVisitor.h" 21 23 #include "SynTree/Visitor.h" // for Visitor 22 24 #include "SynTree/SynTree.h" // for Visitor Nodes … … 30 32 31 33 typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction; 32 class ConversionCost : public Visitor{34 struct ConversionCost : public WithShortCircuiting { 33 35 public: 34 36 ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction ); … … 36 38 Cost get_cost() const { return cost; } 37 39 38 virtual void visit(VoidType *voidType); 39 virtual void visit(BasicType *basicType); 40 virtual void visit(PointerType *pointerType); 41 virtual void visit(ArrayType *arrayType); 42 virtual void visit(ReferenceType *refType); 43 virtual void visit(FunctionType *functionType); 44 virtual void visit(StructInstType *aggregateUseType); 45 virtual void visit(UnionInstType *aggregateUseType); 46 virtual void visit(EnumInstType *aggregateUseType); 47 virtual void visit(TraitInstType *aggregateUseType); 48 virtual void visit(TypeInstType *aggregateUseType); 49 virtual void visit(TupleType *tupleType); 50 virtual void visit(VarArgsType *varArgsType); 51 virtual void visit(ZeroType *zeroType); 52 virtual void visit(OneType *oneType); 40 void previsit( BaseSyntaxNode * ) { visit_children = false; } 41 42 void postvisit( VoidType * voidType ); 43 void postvisit( BasicType * basicType ); 44 void postvisit( PointerType * pointerType ); 45 void postvisit( ArrayType * arrayType ); 46 void postvisit( ReferenceType * refType ); 47 void postvisit( FunctionType * functionType ); 48 void postvisit( StructInstType * aggregateUseType ); 49 void postvisit( UnionInstType * aggregateUseType ); 50 void postvisit( EnumInstType * aggregateUseType ); 51 void postvisit( TraitInstType * aggregateUseType ); 52 void postvisit( TypeInstType * aggregateUseType ); 53 void postvisit( TupleType * tupleType ); 54 void postvisit( VarArgsType * varArgsType ); 55 void postvisit( ZeroType * zeroType ); 56 void postvisit( OneType * oneType ); 53 57 protected: 54 58 Type *dest;
Note: See TracChangeset
for help on using the changeset viewer.