Ignore:
Timestamp:
Jul 17, 2017, 3:05:57 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
e6cee92
Parents:
89be1c68
git-author:
Rob Schluntz <rschlunt@…> (07/17/17 14:58:13)
git-committer:
Rob Schluntz <rschlunt@…> (07/17/17 15:05:57)
Message:

Add reference cost field to cost tuple

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    r89be1c68 r7ebaa56  
    2121
    2222namespace ResolvExpr {
    23         const Cost Cost::zero = Cost( 0, 0, 0 );
    24         const Cost Cost::infinity = Cost( -1, -1, -1 );
    25         const Cost Cost::unsafe = Cost( 1, 0, 0 );
    26         const Cost Cost::poly = Cost( 0, 1, 0 );
    27         const Cost Cost::safe = Cost( 0, 0, 1 );
     23        const Cost Cost::zero = Cost( 0, 0, 0, 0 );
     24        const Cost Cost::infinity = Cost( -1, -1, -1, -1 );
     25        const Cost Cost::unsafe = Cost( 1, 0, 0, 0 );
     26        const Cost Cost::poly = Cost( 0, 1, 0, 0 );
     27        const Cost Cost::safe = Cost( 0, 0, 1, 0 );
     28        const Cost Cost::reference = Cost( 0, 0, 0, 1 );
    2829
    2930
     
    8081                        // TODO: document this
    8182                        Cost cost = convertToReferenceCost( safe_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env );
    82                         // TODO: increment reference cost
    83                         cost.incSafe();
     83                        cost.incReference();
    8484                        return cost;
    8585                } else if ( diff < -1 ) {
    8686                        // TODO: document this
    8787                        Cost cost = convertToReferenceCost( src, safe_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env );
    88                         // TODO: increment reference cost
    89                         cost.incSafe();
     88                        cost.incReference();
    9089                        return cost;
    9190                } else if ( diff == 0 ) {
     
    119118                                        // lvalue-to-reference conversion:  cv lvalue T => cv T &
    120119                                        if ( src->get_qualifiers() == destAsRef->get_base()->get_qualifiers() ) {
    121                                                 return Cost::safe; // cost needs to be non-zero to add cast
     120                                                return Cost::reference; // cost needs to be non-zero to add cast
    122121                                        } if ( src->get_qualifiers() < destAsRef->get_base()->get_qualifiers() ) {
    123                                                 return Cost::safe + Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same
     122                                                return Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same
    124123                                        } else {
    125124                                                return Cost::unsafe;
     
    273272                // cv can be safely dropped because of 'implicit dereference' behavior.
    274273                refType->get_base()->accept( *this );
    275                 // TODO: increment reference cost
    276                 cost.incSafe();
     274                cost.incReference();
    277275        }
    278276
Note: See TracChangeset for help on using the changeset viewer.