Ignore:
Timestamp:
Sep 19, 2016, 5:23:41 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
a6fe3de
Parents:
fc4a0fa
Message:

Added support for ZeroType? and OneType? to all relevant visitors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    rfc4a0fa r89e6ffc  
    160160                        // xxx - not positive this is correct, but appears to allow casting int => enum
    161161                        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
    163165        }
    164166
     
    175177                                } // if
    176178                        } // if
     179                } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
     180                        cost = Cost( 1, 0, 0 );
    177181                } // if
    178182        }
     
    256260                }
    257261        }
     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        }
    258292} // namespace ResolvExpr
    259293
Note: See TracChangeset for help on using the changeset viewer.