source: src/ResolvExpr/ConversionCost.cc @ d6655bd

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d6655bd was 201aeb9, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

first attempt at new basic-type int128, and length suffix with explicit size

  • Property mode set to 100644
File size: 18.0 KB
RevLine 
[a32b204]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[a436947]7// ConversionCost.cc --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 07:06:19 2015
11// Last Modified By : Peter A. Buhr
[201aeb9]12// Last Modified On : Mon Sep 25 15:43:34 2017
13// Update Count     : 10
[a32b204]14//
[51b7345]15
16#include "ConversionCost.h"
[ea6332d]17
18#include <cassert>                       // for assert
19#include <list>                          // for list, list<>::const_iterator
20#include <string>                        // for operator==, string
21
22#include "ResolvExpr/Cost.h"             // for Cost
23#include "ResolvExpr/TypeEnvironment.h"  // for EqvClass, TypeEnvironment
24#include "SymTab/Indexer.h"              // for Indexer
25#include "SynTree/Declaration.h"         // for TypeDecl, NamedTypeDecl
26#include "SynTree/Type.h"                // for Type, BasicType, TypeInstType
27#include "typeops.h"                     // for typesCompatibleIgnoreQualifiers
[51b7345]28
29namespace ResolvExpr {
[7ebaa56]30        const Cost Cost::zero = Cost( 0, 0, 0, 0 );
31        const Cost Cost::infinity = Cost( -1, -1, -1, -1 );
32        const Cost Cost::unsafe = Cost( 1, 0, 0, 0 );
33        const Cost Cost::poly = Cost( 0, 1, 0, 0 );
34        const Cost Cost::safe = Cost( 0, 0, 1, 0 );
35        const Cost Cost::reference = Cost( 0, 0, 0, 1 );
[b46e3bd]36
[5ccb10d]37#if 0
38#define PRINT(x) x
39#else
40#define PRINT(x)
41#endif
[a32b204]42        Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
43                if ( TypeInstType *destAsTypeInst = dynamic_cast< TypeInstType* >( dest ) ) {
44                        EqvClass eqvClass;
45                        NamedTypeDecl *namedType;
[5ccb10d]46                        PRINT( std::cerr << "type inst " << destAsTypeInst->get_name(); )
[a32b204]47                        if ( env.lookup( destAsTypeInst->get_name(), eqvClass ) ) {
[0b150ec]48                                if ( eqvClass.type ) {
49                                        return conversionCost( src, eqvClass.type, indexer, env );
50                                } else {
51                                        return Cost::infinity;
52                                }
[a32b204]53                        } else if ( ( namedType = indexer.lookupType( destAsTypeInst->get_name() ) ) ) {
[5ccb10d]54                                PRINT( std::cerr << " found" << std::endl; )
[a32b204]55                                TypeDecl *type = dynamic_cast< TypeDecl* >( namedType );
56                                // all typedefs should be gone by this point
57                                assert( type );
58                                if ( type->get_base() ) {
[89be1c68]59                                        return conversionCost( src, type->get_base(), indexer, env ) + Cost::safe;
[a32b204]60                                } // if
61                        } // if
[5ccb10d]62                        PRINT( std::cerr << " not found" << std::endl; )
[a32b204]63                } // if
[5ccb10d]64                PRINT(
65                        std::cerr << "src is ";
66                        src->print( std::cerr );
67                        std::cerr << std::endl << "dest is ";
68                        dest->print( std::cerr );
69                        std::cerr << std::endl << "env is" << std::endl;
70                        env.print( std::cerr, 8 );
71                )
[a32b204]72                if ( typesCompatibleIgnoreQualifiers( src, dest, indexer, env ) ) {
[5ccb10d]73                        PRINT( std::cerr << "compatible!" << std::endl; )
[89be1c68]74                        return Cost::zero;
[a32b204]75                } else if ( dynamic_cast< VoidType* >( dest ) ) {
[89be1c68]76                        return Cost::safe;
[2463d0e]77                } else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
[5ccb10d]78                        PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
[0c6596f]79                        return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer &){
80                                return ptrsAssignable( t1, t2, env );
81                        });
[a32b204]82                } else {
83                        ConversionCost converter( dest, indexer, env );
84                        src->accept( converter );
85                        if ( converter.get_cost() == Cost::infinity ) {
86                                return Cost::infinity;
87                        } else {
[89be1c68]88                                return converter.get_cost() + Cost::zero;
[a32b204]89                        } // if
90                } // if
91        }
92
[0c6596f]93        Cost convertToReferenceCost( Type * src, Type * dest, int diff, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
[108f3cdb]94                PRINT( std::cerr << "convert to reference cost... diff " << diff << std::endl; )
[89be1c68]95                if ( diff > 0 ) {
96                        // TODO: document this
[e3e16bc]97                        Cost cost = convertToReferenceCost( strict_dynamic_cast< ReferenceType * >( src )->get_base(), dest, diff-1, indexer, env, func );
[7ebaa56]98                        cost.incReference();
[89be1c68]99                        return cost;
100                } else if ( diff < -1 ) {
101                        // TODO: document this
[e3e16bc]102                        Cost cost = convertToReferenceCost( src, strict_dynamic_cast< ReferenceType * >( dest )->get_base(), diff+1, indexer, env, func );
[7ebaa56]103                        cost.incReference();
[89be1c68]104                        return cost;
105                } else if ( diff == 0 ) {
106                        ReferenceType * srcAsRef = dynamic_cast< ReferenceType * >( src );
107                        ReferenceType * destAsRef = dynamic_cast< ReferenceType * >( dest );
108                        if ( srcAsRef && destAsRef ) { // pointer-like conversions between references
[5ccb10d]109                                PRINT( std::cerr << "converting between references" << std::endl; )
[89be1c68]110                                if ( srcAsRef->get_base()->get_qualifiers() <= destAsRef->get_base()->get_qualifiers() && typesCompatibleIgnoreQualifiers( srcAsRef->get_base(), destAsRef->get_base(), indexer, env ) ) {
111                                        return Cost::safe;
112                                } else {  // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right?
[0c6596f]113                                        int assignResult = func( srcAsRef->get_base(), destAsRef->get_base(), env, indexer );
[5ccb10d]114                                        PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; )
[89be1c68]115                                        if ( assignResult < 0 ) {
116                                                return Cost::safe;
117                                        } else if ( assignResult > 0 ) {
118                                                return Cost::unsafe;
119                                        } // if
[2463d0e]120                                } // if
121                        } else {
[5ccb10d]122                                PRINT( std::cerr << "reference to rvalue conversion" << std::endl; )
[89be1c68]123                                ConversionCost converter( dest, indexer, env );
124                                src->accept( converter );
125                                return converter.get_cost();
126                        } // if
[2463d0e]127                } else {
[89be1c68]128                        ReferenceType * destAsRef = dynamic_cast< ReferenceType * >( dest );
129                        assert( diff == -1 && destAsRef );
[108f3cdb]130                        PRINT( std::cerr << "dest is: " << dest << " / src is: " << src << std::endl; )
[89be1c68]131                        if ( typesCompatibleIgnoreQualifiers( src, destAsRef->get_base(), indexer, env ) ) {
[5ccb10d]132                                PRINT( std::cerr << "converting compatible base type" << std::endl; )
[89be1c68]133                                if ( src->get_lvalue() ) {
[5ccb10d]134                                        PRINT(
135                                                std::cerr << "lvalue to reference conversion" << std::endl;
136                                                std::cerr << src << " => " << destAsRef << std::endl;
137                                        )
[89be1c68]138                                        // lvalue-to-reference conversion:  cv lvalue T => cv T &
139                                        if ( src->get_qualifiers() == destAsRef->get_base()->get_qualifiers() ) {
[7ebaa56]140                                                return Cost::reference; // cost needs to be non-zero to add cast
[89be1c68]141                                        } if ( src->get_qualifiers() < destAsRef->get_base()->get_qualifiers() ) {
[7ebaa56]142                                                return Cost::safe; // cost needs to be higher than previous cast to differentiate adding qualifiers vs. keeping same
[89be1c68]143                                        } else {
144                                                return Cost::unsafe;
145                                        } // if
146                                } else if ( destAsRef->get_base()->get_const() ) {
[5ccb10d]147                                        PRINT( std::cerr << "rvalue to const ref conversion" << std::endl; )
[89be1c68]148                                        // rvalue-to-const-reference conversion: T => const T &
149                                        return Cost::safe;
150                                } else {
[5ccb10d]151                                        PRINT( std::cerr << "rvalue to non-const reference conversion" << std::endl; )
[89be1c68]152                                        // rvalue-to-reference conversion: T => T &
153                                        return Cost::unsafe;
154                                } // if
155                        } // if
[5ccb10d]156                        PRINT( std::cerr << "attempting to convert from incompatible base type -- fail" << std::endl; )
[2463d0e]157                }
158                return Cost::infinity;
159        }
160
[0c6596f]161        Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) {
[89be1c68]162                int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth();
[0c6596f]163                return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func );
[89be1c68]164        }
165
[a32b204]166        ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )
167                : dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ) {
168        }
[51b7345]169
170/*
[a32b204]171            Old
172            ===
173           Double
174             |
175           Float
176             |
177           ULong
178           /   \
179        UInt    Long
180           \   /
181            Int
182             |
183           Ushort
184             |
185           Short
186             |
187           Uchar
188           /   \
189        Schar   Char
190
191                                New
192                                ===
193                       +-----LongDoubleComplex--+
194           LongDouble--+          |             +-LongDoubleImag
195             |         +---DoubleComplex---+         |
196           Double------+        |          +----DoubleImag
197             |           +-FloatComplex-+            |
198           Float---------+              +-------FloatImag
199             |
200          ULongLong
201             |
202          LongLong
203             |
204           ULong
205           /   \
206        UInt    Long
207           \   /
208            Int
209             |
210           Ushort
211             |
212           Short
213             |
214           Uchar
215           /   \
216        Schar   Char
217           \   /
218            Bool
[51b7345]219*/
220
[201aeb9]221        static const int costMatrix[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] = {
222        /* Src \ Dest:  Bool    Char    SChar   UChar   Short   UShort  Int     UInt    Long    ULong   LLong   ULLong  Float   Double  LDbl    FCplex  DCplex  LDCplex FImag   DImag   LDImag  I128,   U128 */
223                /* Bool */      { 0,    1,              1,              2,              3,              4,              5,              6,              6,              7,              8,              9,              12,             13,             14,             12,             13,             14,             -1,             -1,             -1,             10,             11,     },
224                /* Char */      { -1,   0,              -1,             1,              2,              3,              4,              5,              5,              6,              7,              8,              11,             12,             13,             11,             12,             13,             -1,             -1,             -1,             9,              10,     },
225                /* SChar */ { -1,       -1,             0,              1,              2,              3,              4,              5,              5,              6,              7,              8,              11,             12,             13,             11,             12,             13,             -1,             -1,             -1,             9,              10,     },
226                /* UChar */ { -1,       -1,             -1,             0,              1,              2,              3,              4,              4,              5,              6,              7,              10,             11,             12,             10,             11,             12,             -1,             -1,             -1,             8,              9,      },
227                /* Short */ { -1,       -1,             -1,             -1,             0,              1,              2,              3,              3,              4,              5,              6,              9,              10,             11,             9,              10,             11,             -1,             -1,             -1,             7,              8,      },
228                /* UShort */{ -1,       -1,             -1,             -1,             -1,             0,              1,              2,              2,              3,              4,              5,              8,              9,              10,             8,              9,              10,             -1,             -1,             -1,             6,              7,      },
229                /* Int */       { -1,   -1,             -1,             -1,             -1,             -1,             0,              1,              1,              2,              3,              4,              7,              8,              9,              7,              8,              9,              -1,             -1,             -1,             5,              6,      },
230                /* UInt */      { -1,   -1,             -1,             -1,             -1,             -1,             -1,             0,              -1,             1,              2,              3,              6,              7,              8,              6,              7,              8,              -1,             -1,             -1,             4,              5,      },
231                /* Long */      { -1,   -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              2,              3,              6,              7,              8,              6,              7,              8,              -1,             -1,             -1,             4,              5,      },
232                /* ULong */ { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              2,              5,              6,              7,              5,              6,              7,              -1,             -1,             -1,             3,              4,      },
233                /* LLong */ { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              4,              5,              6,              4,              5,              6,              -1,             -1,             -1,             2,              3,      },
234                /* ULLong */{ -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              3,              4,              5,              3,              4,              5,              -1,             -1,             -1,             1,              2,      },
235
236                /* Float */ { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              2,              1,              2,              3,              -1,             -1,             -1,             -1,             -1,     },
237                /* Double */{ -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              -1,             1,              2,              -1,             -1,             -1,             -1,             -1,     },
238                /* LDbl */      { -1,   -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              -1,             -1,             1,              -1,             -1,             -1,             -1,             -1,     },
239                /* FCplex */{ -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              2,              -1,             -1,             -1,             -1,             -1,     },
240                /* DCplex */{ -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              1,              -1,             -1,             -1,             -1,             -1,     },
241                /* LDCplex */{ -1,      -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             0,              -1,             -1,             -1,             -1,             -1,     },
242                /* FImag */ { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             1,              2,              3,              0,              1,              2,              -1,             -1,     },
243                /* DImag */ { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             1,              2,              -1,             0,              1,              -1,             -1,     },
244                /* LDImag */{ -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             1,              -1,             -1,             0,              -1,             -1,     },
245
246                /* I128 */  { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             2,              3,              4,              3,              4,              5,              -1,             -1,             -1,             0,              1,      },
247                /* U128 */  { -1,       -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             -1,             1,              2,              3,              2,              3,              4,              -1,             -1,             -1,             -1,             0,      },
[a32b204]248        };
249
[7e003011]250        void ConversionCost::visit( __attribute((unused)) VoidType *voidType ) {
[a32b204]251                cost = Cost::infinity;
252        }
253
254        void ConversionCost::visit(BasicType *basicType) {
255                if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
256                        int tableResult = costMatrix[ basicType->get_kind() ][ destAsBasic->get_kind() ];
257                        if ( tableResult == -1 ) {
[89be1c68]258                                cost = Cost::unsafe;
[a32b204]259                        } else {
[89be1c68]260                                cost = Cost::zero;
261                                cost.incSafe( tableResult );
[a32b204]262                        } // if
[a436947]263                } else if ( dynamic_cast< EnumInstType *>( dest ) ) {
264                        // xxx - not positive this is correct, but appears to allow casting int => enum
[89be1c68]265                        cost = Cost::unsafe;
[89e6ffc]266                } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
[89be1c68]267                        cost = Cost::unsafe;
[89e6ffc]268                } // if
[a32b204]269        }
270
271        void ConversionCost::visit(PointerType *pointerType) {
272                if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
[5ccb10d]273                        PRINT( std::cerr << pointerType << " ===> " << destAsPtr; )
[cb43451]274                        Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers();
275                        Type::Qualifiers tq2 = destAsPtr->get_base()->get_qualifiers();
276                        if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( pointerType->get_base(), destAsPtr->get_base(), indexer, env ) ) {
277                                if ( tq1 == tq2 ) {
278                                        // types are the same
279                                        cost = Cost::zero;
280                                } else {
281                                        // types are the same, except otherPointer has more qualifiers
[5ccb10d]282                                        PRINT( std::cerr << " :: compatible and good qualifiers" << std::endl; )
[cb43451]283                                        cost = Cost::safe;
284                                }
285                        } else {  // xxx - this discards qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right?
[a32b204]286                                int assignResult = ptrsAssignable( pointerType->get_base(), destAsPtr->get_base(), env );
[5ccb10d]287                                PRINT( std::cerr << " :: " << assignResult << std::endl; )
[cb43451]288                                if ( assignResult < 0 && pointerType->get_base()->get_qualifiers() <= destAsPtr->get_qualifiers() ) {
[89be1c68]289                                        cost = Cost::safe;
[a32b204]290                                } else if ( assignResult > 0 ) {
[89be1c68]291                                        cost = Cost::unsafe;
[a32b204]292                                } // if
[cb43451]293                                // assignResult == 0 means Cost::Infinity
[a32b204]294                        } // if
[89e6ffc]295                } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
[89be1c68]296                        cost = Cost::unsafe;
[a32b204]297                } // if
298        }
299
[7e003011]300        void ConversionCost::visit(__attribute((unused)) ArrayType *arrayType) {}
[2463d0e]301
302        void ConversionCost::visit(ReferenceType *refType) {
303                // Note: dest can never be a reference, since it would have been caught in an earlier check
304                assert( ! dynamic_cast< ReferenceType * >( dest ) );
305                // convert reference to rvalue: cv T1 & => T2
306                // recursively compute conversion cost from T1 to T2.
307                // cv can be safely dropped because of 'implicit dereference' behavior.
308                refType->get_base()->accept( *this );
[cb43451]309                if ( refType->get_base()->get_qualifiers() == dest->get_qualifiers() ) {
310                        cost.incReference();  // prefer exact qualifiers
311                } else if ( refType->get_base()->get_qualifiers() < dest->get_qualifiers() ) {
312                        cost.incSafe(); // then gaining qualifiers
313                } else {
314                        cost.incUnsafe(); // lose qualifiers as last resort
315                }
[5ccb10d]316                PRINT( std::cerr << refType << " ==> " << dest << " " << cost << std::endl; )
[2463d0e]317        }
318
[7e003011]319        void ConversionCost::visit(__attribute((unused)) FunctionType *functionType) {}
[a32b204]320
321        void ConversionCost::visit(StructInstType *inst) {
322                if ( StructInstType *destAsInst = dynamic_cast< StructInstType* >( dest ) ) {
323                        if ( inst->get_name() == destAsInst->get_name() ) {
324                                cost = Cost::zero;
325                        } // if
326                } // if
327        }
328
329        void ConversionCost::visit(UnionInstType *inst) {
330                if ( StructInstType *destAsInst = dynamic_cast< StructInstType* >( dest ) ) {
331                        if ( inst->get_name() == destAsInst->get_name() ) {
332                                cost = Cost::zero;
333                        } // if
334                } // if
335        }
336
[7e003011]337        void ConversionCost::visit( __attribute((unused)) EnumInstType *inst ) {
[a32b204]338                static Type::Qualifiers q;
339                static BasicType integer( q, BasicType::SignedInt );
[2463d0e]340                integer.accept( *this );  // safe if dest >= int
[89be1c68]341                if ( cost < Cost::unsafe ) {
[a32b204]342                        cost.incSafe();
343                } // if
344        }
345
[7e003011]346        void ConversionCost::visit( __attribute((unused)) TraitInstType *inst) {
[a32b204]347        }
348
349        void ConversionCost::visit(TypeInstType *inst) {
350                EqvClass eqvClass;
351                NamedTypeDecl *namedType;
352                if ( env.lookup( inst->get_name(), eqvClass ) ) {
353                        cost = conversionCost( eqvClass.type, dest, indexer, env );
354                } else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) {
355                        if ( inst->get_name() == destAsInst->get_name() ) {
356                                cost = Cost::zero;
357                        }
358                } else if ( ( namedType = indexer.lookupType( inst->get_name() ) ) ) {
359                        TypeDecl *type = dynamic_cast< TypeDecl* >( namedType );
360                        // all typedefs should be gone by this point
361                        assert( type );
362                        if ( type->get_base() ) {
[89be1c68]363                                cost = conversionCost( type->get_base(), dest, indexer, env ) + Cost::safe;
[a32b204]364                        } // if
365                } // if
366        }
367
[7e003011]368        void ConversionCost::visit( __attribute((unused)) TupleType *tupleType) {
[89be1c68]369                Cost c = Cost::zero;
[a32b204]370                if ( TupleType *destAsTuple = dynamic_cast< TupleType* >( dest ) ) {
371                        std::list< Type* >::const_iterator srcIt = tupleType->get_types().begin();
372                        std::list< Type* >::const_iterator destIt = destAsTuple->get_types().begin();
[4ab9536]373                        while ( srcIt != tupleType->get_types().end() && destIt != destAsTuple->get_types().end() ) {
[a32b204]374                                Cost newCost = conversionCost( *srcIt++, *destIt++, indexer, env );
375                                if ( newCost == Cost::infinity ) {
376                                        return;
377                                } // if
378                                c += newCost;
379                        } // while
380                        if ( destIt != destAsTuple->get_types().end() ) {
381                                cost = Cost::infinity;
382                        } else {
383                                cost = c;
384                        } // if
385                } // if
386        }
[44b7088]387
[7e003011]388        void ConversionCost::visit( __attribute((unused)) VarArgsType *varArgsType) {
[90c3b1c]389                if ( dynamic_cast< VarArgsType* >( dest ) ) {
[44b7088]390                        cost = Cost::zero;
391                }
392        }
[89e6ffc]393
[7e003011]394        void ConversionCost::visit( __attribute((unused)) ZeroType *zeroType) {
[89e6ffc]395                if ( dynamic_cast< ZeroType* >( dest ) ) {
396                        cost = Cost::zero;
397                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
398                        // copied from visit(BasicType*) for signed int, but +1 for safe conversions
399                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
400                        if ( tableResult == -1 ) {
[89be1c68]401                                cost = Cost::unsafe;
[89e6ffc]402                        } else {
[89be1c68]403                                cost = Cost::zero;
404                                cost.incSafe( tableResult + 1 );
[89e6ffc]405                        }
406                } else if ( dynamic_cast< PointerType* >( dest ) ) {
[89be1c68]407                        cost = Cost::safe;
[89e6ffc]408                }
409        }
410
[7e003011]411        void ConversionCost::visit( __attribute((unused)) OneType *oneType) {
[89e6ffc]412                if ( dynamic_cast< OneType* >( dest ) ) {
413                        cost = Cost::zero;
414                } else if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
415                        // copied from visit(BasicType*) for signed int, but +1 for safe conversions
416                        int tableResult = costMatrix[ BasicType::SignedInt ][ destAsBasic->get_kind() ];
417                        if ( tableResult == -1 ) {
[89be1c68]418                                cost = Cost::unsafe;
[89e6ffc]419                        } else {
[89be1c68]420                                cost = Cost::zero;
421                                cost.incSafe( tableResult + 1 );
[89e6ffc]422                        }
423                }
424        }
[51b7345]425} // namespace ResolvExpr
[a32b204]426
427// Local Variables: //
428// tab-width: 4 //
429// mode: c++ //
430// compile-command: "make install" //
431// End: //
Note: See TracBrowser for help on using the repository browser.