[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 | // |
---|
[c92bdcc] | 7 | // ConversionCost.cpp -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 07:06:19 2015 |
---|
[fb2bde4] | 11 | // Last Modified By : Andrew Beach |
---|
[1d17939] | 12 | // Last Modified On : Wed Jul 29 16:11:00 2020 |
---|
[cf32116] | 13 | // Update Count : 28 |
---|
[a32b204] | 14 | // |
---|
[51b7345] | 15 | |
---|
[c92bdcc] | 16 | #include "ConversionCost.hpp" |
---|
[ea6332d] | 17 | |
---|
| 18 | #include <cassert> // for assert |
---|
| 19 | #include <list> // for list, list<>::const_iterator |
---|
| 20 | #include <string> // for operator==, string |
---|
| 21 | |
---|
[c92bdcc] | 22 | #include "ResolvExpr/Cost.hpp" // for Cost |
---|
| 23 | #include "ResolvExpr/Unify.hpp" // for typesCompatibleIgnoreQualifiers |
---|
[5bf3976] | 24 | #include "ResolvExpr/PtrsAssignable.hpp" // for ptrsAssignable |
---|
[ef1da0e2] | 25 | |
---|
[51b7345] | 26 | namespace ResolvExpr { |
---|
[b46e3bd] | 27 | |
---|
[5ccb10d] | 28 | #if 0 |
---|
| 29 | #define PRINT(x) x |
---|
| 30 | #else |
---|
| 31 | #define PRINT(x) |
---|
| 32 | #endif |
---|
[ada4575] | 33 | |
---|
[13de4478] | 34 | namespace { |
---|
| 35 | |
---|
[e15853c] | 36 | // GENERATED START, DO NOT EDIT |
---|
[b2ea0cd] | 37 | // GENERATED BY BasicTypes-gen.cpp |
---|
[cdcddfe1] | 38 | /* EXTENDED INTEGRAL RANK HIERARCHY (root to leaves) |
---|
[e15853c] | 39 | _Bool |
---|
[7870799] | 40 | char signed char unsigned char |
---|
| 41 | signed short int unsigned short int |
---|
| 42 | signed int unsigned int |
---|
| 43 | signed long int unsigned long int |
---|
| 44 | signed long long int unsigned long long int |
---|
| 45 | __int128 unsigned __int128 |
---|
| 46 | _Float16 _Float16 _Complex |
---|
| 47 | _Float32 _Float32 _Complex |
---|
| 48 | float float _Complex |
---|
| 49 | _Float32x _Float32x _Complex |
---|
| 50 | _Float64 _Float64 _Complex |
---|
| 51 | double double _Complex |
---|
| 52 | _Float64x _Float64x _Complex |
---|
[e15853c] | 53 | __float80 |
---|
[7870799] | 54 | _Float128 _Float128 _Complex |
---|
[e15853c] | 55 | __float128 |
---|
[7870799] | 56 | long double long double _Complex |
---|
| 57 | _Float128x _Float128x _Complex |
---|
[cdcddfe1] | 58 | */ |
---|
[e15853c] | 59 | // GENERATED END |
---|
[cdcddfe1] | 60 | |
---|
[e15853c] | 61 | // GENERATED START, DO NOT EDIT |
---|
[b2ea0cd] | 62 | // GENERATED BY BasicTypes-gen.cpp |
---|
[7a780ad] | 63 | static const int costMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // path length from root to node |
---|
[3a55d9f] | 64 | /* B C SC UC SI SUI I UI LI LUI LLI LLUI IB UIB _FH _FH _F _FC F FC _FX _FXC FD _FDC D DC F80X_FDXC F80 _FB_FLDC FB LD LDC _FBX_FLDXC */ |
---|
| 65 | /* B */ { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 17, 16, 18, 17, }, |
---|
| 66 | /* C */ { -1, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 16, 15, 17, 16, }, |
---|
| 67 | /* SC */ { -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 16, 15, 17, 16, }, |
---|
| 68 | /* UC */ { -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 16, 15, 17, 16, }, |
---|
| 69 | /* SI */ { -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 14, 16, 15, }, |
---|
| 70 | /* SUI */ { -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 15, 14, 16, 15, }, |
---|
| 71 | /* I */ { -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 13, 15, 14, }, |
---|
| 72 | /* UI */ { -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 14, 13, 15, 14, }, |
---|
| 73 | /* LI */ { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 13, 12, 14, 13, }, |
---|
| 74 | /* LUI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 13, 12, 14, 13, }, |
---|
| 75 | /* LLI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 11, 13, 12, }, |
---|
| 76 | /* LLUI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 11, 13, 12, }, |
---|
| 77 | /* IB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 10, 12, 11, }, |
---|
| 78 | /* UIB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11, 10, 12, 11, }, |
---|
| 79 | /* _FH */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 9, 11, 10, }, |
---|
| 80 | /* _FH */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, -1, 7, -1, -1, 8, -1, 9, }, |
---|
| 81 | /* _F */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 8, 10, 9, }, |
---|
| 82 | /* _FC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, -1, 6, -1, -1, 7, -1, 8, }, |
---|
| 83 | /* F */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 7, 9, 8, }, |
---|
| 84 | /* FC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, -1, 5, -1, -1, 6, -1, 7, }, |
---|
| 85 | /* _FX */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 6, 8, 7, }, |
---|
| 86 | /* _FXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, -1, 4, -1, -1, 5, -1, 6, }, |
---|
| 87 | /* FD */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 5, 7, 6, }, |
---|
| 88 | /* _FDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, 2, -1, -1, 3, -1, -1, 4, -1, 5, }, |
---|
| 89 | /* D */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, 4, 5, 4, 6, 5, }, |
---|
| 90 | /* DC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, -1, -1, 2, -1, -1, 3, -1, 4, }, |
---|
| 91 | /* F80X */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 4, 3, 5, 4, }, |
---|
| 92 | /* _FDXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 1, -1, -1, 2, -1, 3, }, |
---|
| 93 | /* F80 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 1, 2, 2, 3, 3, 4, 4, }, |
---|
| 94 | /* _FB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 2, 3, 3, }, |
---|
| 95 | /* _FLDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 1, -1, 2, }, |
---|
| 96 | /* FB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 1, 2, 2, 3, }, |
---|
| 97 | /* LD */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, }, |
---|
| 98 | /* LDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, }, |
---|
| 99 | /* _FBX */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, }, |
---|
[ef5b828] | 100 | /* _FLDXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, }, |
---|
[e15853c] | 101 | }; // costMatrix |
---|
[1c9568f0] | 102 | static const int maxIntCost = 15; |
---|
[e15853c] | 103 | // GENERATED END |
---|
[cdcddfe1] | 104 | static_assert( |
---|
[7a780ad] | 105 | sizeof(costMatrix)/sizeof(costMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES, |
---|
[cdcddfe1] | 106 | "Missing row in the cost matrix" |
---|
| 107 | ); |
---|
| 108 | |
---|
[e15853c] | 109 | // GENERATED START, DO NOT EDIT |
---|
[b2ea0cd] | 110 | // GENERATED BY BasicTypes-gen.cpp |
---|
[7a780ad] | 111 | static const int signMatrix[ast::BasicKind::NUMBER_OF_BASIC_TYPES][ast::BasicKind::NUMBER_OF_BASIC_TYPES] = { // number of sign changes in safe conversion |
---|
[3a55d9f] | 112 | /* B C SC UC SI SUI I UI LI LUI LLI LLUI IB UIB _FH _FH _F _FC F FC _FX _FXC FD _FDC D DC F80X_FDXC F80 _FB_FLDC FB LD LDC _FBX_FLDXC */ |
---|
| 113 | /* B */ { 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 114 | /* C */ { -1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 115 | /* SC */ { -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 116 | /* UC */ { -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 117 | /* SI */ { -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 118 | /* SUI */ { -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 119 | /* I */ { -1, -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 120 | /* UI */ { -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 121 | /* LI */ { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 122 | /* LUI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 123 | /* LLI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 124 | /* LLUI */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 125 | /* IB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 126 | /* UIB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 127 | /* _FH */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 128 | /* _FH */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 129 | /* _F */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 130 | /* _FC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 131 | /* F */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 132 | /* FC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 133 | /* _FX */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 134 | /* _FXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 135 | /* FD */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 136 | /* _FDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 137 | /* D */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 138 | /* DC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 139 | /* F80X */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 140 | /* _FDXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 141 | /* F80 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 142 | /* _FB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, }, |
---|
| 143 | /* _FLDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 0, -1, 0, }, |
---|
| 144 | /* FB */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, }, |
---|
| 145 | /* LD */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, }, |
---|
| 146 | /* LDC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, }, |
---|
| 147 | /* _FBX */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, }, |
---|
[ef5b828] | 148 | /* _FLDXC */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, }, |
---|
[e15853c] | 149 | }; // signMatrix |
---|
| 150 | // GENERATED END |
---|
[cdcddfe1] | 151 | static_assert( |
---|
[7a780ad] | 152 | sizeof(signMatrix)/sizeof(signMatrix[0][0]) == ast::BasicKind::NUMBER_OF_BASIC_TYPES * ast::BasicKind::NUMBER_OF_BASIC_TYPES, |
---|
[cdcddfe1] | 153 | "Missing row in the sign matrix" |
---|
| 154 | ); |
---|
[a32b204] | 155 | |
---|
[cf32116] | 156 | int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, |
---|
| 157 | const ast::SymbolTable &, const ast::TypeEnvironment & env ) { |
---|
| 158 | return ptrsAssignable( t1, t2, env ); |
---|
| 159 | } |
---|
[fb2bde4] | 160 | } |
---|
| 161 | |
---|
| 162 | Cost conversionCost( |
---|
[cf32116] | 163 | const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, |
---|
| 164 | const ast::SymbolTable & symtab, const ast::TypeEnvironment & env |
---|
[fb2bde4] | 165 | ) { |
---|
| 166 | if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( dst ) ) { |
---|
[3e5dd913] | 167 | if ( const ast::EqvClass * eqv = env.lookup( *inst ) ) { |
---|
[fb2bde4] | 168 | if ( eqv->bound ) { |
---|
[cf32116] | 169 | return conversionCost(src, eqv->bound, srcIsLvalue, symtab, env ); |
---|
[fb2bde4] | 170 | } else { |
---|
| 171 | return Cost::infinity; |
---|
| 172 | } |
---|
| 173 | } else if ( const ast::NamedTypeDecl * named = symtab.lookupType( inst->name ) ) { |
---|
| 174 | const ast::TypeDecl * type = dynamic_cast< const ast::TypeDecl * >( named ); |
---|
| 175 | assertf( type, "Unexpected typedef." ); |
---|
| 176 | if ( type->base ) { |
---|
[cf32116] | 177 | return conversionCost( src, type->base, srcIsLvalue, symtab, env ) + Cost::safe; |
---|
[fb2bde4] | 178 | } |
---|
| 179 | } |
---|
| 180 | } |
---|
[251ce80] | 181 | if ( typesCompatibleIgnoreQualifiers( src, dst, env ) ) { |
---|
[9d5089e] | 182 | return Cost::zero; |
---|
[fb2bde4] | 183 | } else if ( dynamic_cast< const ast::VoidType * >( dst ) ) { |
---|
| 184 | return Cost::safe; |
---|
| 185 | } else if ( const ast::ReferenceType * refType = |
---|
| 186 | dynamic_cast< const ast::ReferenceType * >( dst ) ) { |
---|
[cf32116] | 187 | return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); |
---|
[fb2bde4] | 188 | } else { |
---|
[0bd3faf] | 189 | return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); |
---|
[fb2bde4] | 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
[cf32116] | 193 | static Cost convertToReferenceCost( const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, |
---|
[0f19f5e5] | 194 | int diff, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, |
---|
[cf32116] | 195 | PtrsCalculation func ) { |
---|
[fb2bde4] | 196 | if ( 0 < diff ) { |
---|
| 197 | Cost cost = convertToReferenceCost( |
---|
[cf32116] | 198 | strict_dynamic_cast< const ast::ReferenceType * >( src )->base, dst, |
---|
| 199 | srcIsLvalue, (diff - 1), symtab, env, func ); |
---|
[fb2bde4] | 200 | cost.incReference(); |
---|
| 201 | return cost; |
---|
| 202 | } else if ( diff < -1 ) { |
---|
| 203 | Cost cost = convertToReferenceCost( |
---|
| 204 | src, strict_dynamic_cast< const ast::ReferenceType * >( dst )->base, |
---|
[cf32116] | 205 | srcIsLvalue, (diff + 1), symtab, env, func ); |
---|
[fb2bde4] | 206 | cost.incReference(); |
---|
| 207 | return cost; |
---|
| 208 | } else if ( 0 == diff ) { |
---|
| 209 | const ast::ReferenceType * srcAsRef = dynamic_cast< const ast::ReferenceType * >( src ); |
---|
| 210 | const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst ); |
---|
| 211 | if ( srcAsRef && dstAsRef ) { |
---|
| 212 | ast::CV::Qualifiers tq1 = srcAsRef->base->qualifiers; |
---|
| 213 | ast::CV::Qualifiers tq2 = dstAsRef->base->qualifiers; |
---|
| 214 | if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( |
---|
[251ce80] | 215 | srcAsRef->base, dstAsRef->base, env ) ) { |
---|
[fb2bde4] | 216 | if ( tq1 == tq2 ) { |
---|
| 217 | return Cost::zero; |
---|
| 218 | } else { |
---|
| 219 | return Cost::safe; |
---|
| 220 | } |
---|
| 221 | } else { |
---|
| 222 | int assignResult = func( srcAsRef->base, dstAsRef->base, symtab, env ); |
---|
| 223 | if ( 0 < assignResult ) { |
---|
| 224 | return Cost::safe; |
---|
| 225 | } else if ( assignResult < 0 ) { |
---|
| 226 | return Cost::unsafe; |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | } else { |
---|
[0bd3faf] | 230 | return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); |
---|
[fb2bde4] | 231 | } |
---|
| 232 | } else { |
---|
| 233 | assert( -1 == diff ); |
---|
| 234 | const ast::ReferenceType * dstAsRef = dynamic_cast< const ast::ReferenceType * >( dst ); |
---|
| 235 | assert( dstAsRef ); |
---|
[251ce80] | 236 | if ( typesCompatibleIgnoreQualifiers( src, dstAsRef->base, env ) ) { |
---|
[cf32116] | 237 | if ( srcIsLvalue ) { |
---|
[fb2bde4] | 238 | if ( src->qualifiers == dstAsRef->base->qualifiers ) { |
---|
| 239 | return Cost::reference; |
---|
| 240 | } else if ( src->qualifiers < dstAsRef->base->qualifiers ) { |
---|
| 241 | return Cost::safe; |
---|
| 242 | } else { |
---|
| 243 | return Cost::unsafe; |
---|
| 244 | } |
---|
| 245 | } else if ( dstAsRef->base->is_const() ) { |
---|
| 246 | return Cost::safe; |
---|
| 247 | } else { |
---|
| 248 | return Cost::unsafe; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | return Cost::infinity; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dst, |
---|
[cf32116] | 256 | bool srcIsLvalue, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env, |
---|
| 257 | PtrsCalculation func ) { |
---|
[fb2bde4] | 258 | int sdepth = src->referenceDepth(), ddepth = dst->referenceDepth(); |
---|
[cf32116] | 259 | return convertToReferenceCost( src, dst, srcIsLvalue, sdepth - ddepth, symtab, env, func ); |
---|
[fb2bde4] | 260 | } |
---|
| 261 | |
---|
[0bd3faf] | 262 | void ConversionCost::postvisit( const ast::VoidType * voidType ) { |
---|
[fb2bde4] | 263 | (void)voidType; |
---|
| 264 | cost = Cost::infinity; |
---|
| 265 | } |
---|
| 266 | |
---|
[0bd3faf] | 267 | void ConversionCost::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) { |
---|
[fc134a48] | 268 | int tableResult = costMatrix[ src->kind ][ dest->kind ]; |
---|
| 269 | if ( tableResult == -1 ) { |
---|
| 270 | cost = Cost::unsafe; |
---|
| 271 | } else { |
---|
| 272 | cost = Cost::zero; |
---|
| 273 | cost.incSafe( tableResult ); |
---|
| 274 | cost.incSign( signMatrix[ src->kind ][ dest->kind ] ); |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
[0bd3faf] | 278 | void ConversionCost::postvisit( const ast::BasicType * basicType ) { |
---|
[fb2bde4] | 279 | if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { |
---|
[fc134a48] | 280 | conversionCostFromBasicToBasic( basicType, dstAsBasic ); |
---|
[af746cc] | 281 | } else if ( dynamic_cast< const ast::EnumAttrType *>(dst) ) { |
---|
[7a780ad] | 282 | static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; |
---|
[00eaeb8] | 283 | cost = costCalc( basicType, integer, srcIsLvalue, symtab, env ); |
---|
[af746cc] | 284 | } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { |
---|
[c333ed2] | 285 | if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { |
---|
[eb7586e] | 286 | cost = Cost::unsafe; |
---|
[af746cc] | 287 | } |
---|
[fb2bde4] | 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
[0bd3faf] | 291 | void ConversionCost::postvisit( const ast::PointerType * pointerType ) { |
---|
[fb2bde4] | 292 | if ( const ast::PointerType * dstAsPtr = dynamic_cast< const ast::PointerType * >( dst ) ) { |
---|
| 293 | ast::CV::Qualifiers tq1 = pointerType->base->qualifiers; |
---|
| 294 | ast::CV::Qualifiers tq2 = dstAsPtr->base->qualifiers; |
---|
| 295 | if ( tq1 <= tq2 && typesCompatibleIgnoreQualifiers( |
---|
[251ce80] | 296 | pointerType->base, dstAsPtr->base, env ) ) { |
---|
[fb2bde4] | 297 | if ( tq1 == tq2 ) { |
---|
| 298 | cost = Cost::zero; |
---|
| 299 | } else { |
---|
| 300 | cost = Cost::safe; |
---|
| 301 | } |
---|
[ef1da0e2] | 302 | } |
---|
| 303 | /* |
---|
| 304 | else if ( const ast::FunctionType * dstFunc = dstAsPtr->base.as<ast::FunctionType>()) { |
---|
| 305 | if (const ast::FunctionType * srcFunc = pointerType->base.as<ast::FunctionType>()) { |
---|
| 306 | if (dstFunc->params.empty() && dstFunc->isVarArgs ) { |
---|
| 307 | cost = Cost::unsafe; // assign any function to variadic fptr |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | else { |
---|
| 311 | ast::AssertionSet need, have; // unused |
---|
| 312 | ast::OpenVarSet open; |
---|
| 313 | env.extractOpenVars(open); |
---|
| 314 | ast::TypeEnvironment tenv = env; |
---|
| 315 | if ( unify(dstAsPtr->base, pointerType->base, tenv, need, have, open, symtab) ) { |
---|
| 316 | cost = Cost::safe; |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | // else infinity |
---|
| 320 | } |
---|
| 321 | */ |
---|
| 322 | else { |
---|
[fb2bde4] | 323 | int assignResult = ptrsAssignable( pointerType->base, dstAsPtr->base, env ); |
---|
| 324 | if ( 0 < assignResult && tq1 <= tq2 ) { |
---|
| 325 | if ( tq1 == tq2 ) { |
---|
| 326 | cost = Cost::safe; |
---|
| 327 | } else { |
---|
| 328 | cost = Cost::safe + Cost::safe; |
---|
| 329 | } |
---|
| 330 | } else if ( assignResult < 0 ) { |
---|
| 331 | cost = Cost::unsafe; |
---|
| 332 | } // else Cost::infinity |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
[0bd3faf] | 337 | void ConversionCost::postvisit( const ast::ArrayType * arrayType ) { |
---|
[fb2bde4] | 338 | (void)arrayType; |
---|
| 339 | } |
---|
| 340 | |
---|
[0bd3faf] | 341 | void ConversionCost::postvisit( const ast::ReferenceType * refType ) { |
---|
[fb2bde4] | 342 | assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); |
---|
| 343 | |
---|
[cf32116] | 344 | cost = costCalc( refType->base, dst, srcIsLvalue, symtab, env ); |
---|
[46da46b] | 345 | |
---|
| 346 | // xxx - should qualifiers be considered in pass-by-value? |
---|
| 347 | /* |
---|
[fb2bde4] | 348 | if ( refType->base->qualifiers == dst->qualifiers ) { |
---|
| 349 | cost.incReference(); |
---|
| 350 | } else if ( refType->base->qualifiers < dst->qualifiers ) { |
---|
| 351 | cost.incSafe(); |
---|
| 352 | } else { |
---|
| 353 | cost.incUnsafe(); |
---|
| 354 | } |
---|
[46da46b] | 355 | */ |
---|
| 356 | cost.incReference(); |
---|
[fb2bde4] | 357 | } |
---|
| 358 | |
---|
[0bd3faf] | 359 | void ConversionCost::postvisit( const ast::FunctionType * functionType ) { |
---|
[fb2bde4] | 360 | (void)functionType; |
---|
| 361 | } |
---|
| 362 | |
---|
[af746cc] | 363 | void ConversionCost::postvisit( const ast::EnumInstType * inst ) { |
---|
[cdb4eaa] | 364 | if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { |
---|
| 365 | if (inst->base && dstAsInst->base) { |
---|
| 366 | if (inst->base->name == dstAsInst->base->name) { |
---|
| 367 | cost = Cost::zero; |
---|
| 368 | return; |
---|
[af746cc] | 369 | } |
---|
| 370 | } |
---|
| 371 | return; |
---|
[7a780ad] | 372 | } |
---|
| 373 | static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; |
---|
[c75b30a] | 374 | cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); |
---|
[fb2bde4] | 375 | if ( cost < Cost::unsafe ) { |
---|
| 376 | cost.incSafe(); |
---|
| 377 | } |
---|
| 378 | } |
---|
| 379 | |
---|
[af746cc] | 380 | void ConversionCost::postvisit( const ast::EnumAttrType * src ) { |
---|
[fc1a3e2] | 381 | auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst); |
---|
[748c751] | 382 | assert( src->attr != ast::EnumAttribute::Label ); |
---|
[fc1a3e2] | 383 | if ( src->attr == ast::EnumAttribute::Value ) { |
---|
| 384 | if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) { |
---|
| 385 | cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); |
---|
| 386 | } else { |
---|
| 387 | auto baseType = src->instance->base->base; |
---|
| 388 | cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); |
---|
[af746cc] | 389 | if ( cost < Cost::infinity ) { |
---|
| 390 | cost.incUnsafe(); |
---|
| 391 | } |
---|
[fc1a3e2] | 392 | } |
---|
| 393 | } else { // ast::EnumAttribute::Posn |
---|
| 394 | if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { |
---|
| 395 | cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); |
---|
| 396 | if ( cost < Cost::unsafe ) cost.incSafe(); |
---|
| 397 | } else { |
---|
| 398 | static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; |
---|
| 399 | cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); |
---|
| 400 | if ( cost < Cost::unsafe ) { |
---|
| 401 | cost.incSafe(); |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
[0522ebe] | 405 | } |
---|
| 406 | |
---|
[0bd3faf] | 407 | void ConversionCost::postvisit( const ast::TraitInstType * traitInstType ) { |
---|
[fb2bde4] | 408 | (void)traitInstType; |
---|
| 409 | } |
---|
| 410 | |
---|
[0bd3faf] | 411 | void ConversionCost::postvisit( const ast::TypeInstType * typeInstType ) { |
---|
[3e5dd913] | 412 | if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) { |
---|
[cf32116] | 413 | cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); |
---|
[fb2bde4] | 414 | } else if ( const ast::TypeInstType * dstAsInst = |
---|
| 415 | dynamic_cast< const ast::TypeInstType * >( dst ) ) { |
---|
[3e5dd913] | 416 | if ( *typeInstType == *dstAsInst ) { |
---|
[fb2bde4] | 417 | cost = Cost::zero; |
---|
| 418 | } |
---|
| 419 | } else if ( const ast::NamedTypeDecl * namedType = symtab.lookupType( typeInstType->name ) ) { |
---|
| 420 | const ast::TypeDecl * type = dynamic_cast< const ast::TypeDecl * >( namedType ); |
---|
| 421 | assertf( type, "Unexpected typedef."); |
---|
| 422 | if ( type->base ) { |
---|
[cf32116] | 423 | cost = costCalc( type->base, dst, srcIsLvalue, symtab, env ) + Cost::safe; |
---|
[fb2bde4] | 424 | } |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | |
---|
[0bd3faf] | 428 | void ConversionCost::postvisit( const ast::TupleType * tupleType ) { |
---|
[fb2bde4] | 429 | Cost c = Cost::zero; |
---|
| 430 | if ( const ast::TupleType * dstAsTuple = dynamic_cast< const ast::TupleType * >( dst ) ) { |
---|
| 431 | auto srcIt = tupleType->types.begin(); |
---|
| 432 | auto dstIt = dstAsTuple->types.begin(); |
---|
| 433 | auto srcEnd = tupleType->types.end(); |
---|
| 434 | auto dstEnd = dstAsTuple->types.end(); |
---|
| 435 | while ( srcIt != srcEnd && dstIt != dstEnd ) { |
---|
[cf32116] | 436 | Cost newCost = costCalc( * srcIt++, * dstIt++, srcIsLvalue, symtab, env ); |
---|
[fb2bde4] | 437 | if ( newCost == Cost::infinity ) { |
---|
| 438 | return; |
---|
| 439 | } |
---|
| 440 | c += newCost; |
---|
| 441 | } |
---|
| 442 | if ( dstIt != dstEnd ) { |
---|
| 443 | cost = Cost::infinity; |
---|
| 444 | } else { |
---|
| 445 | cost = c; |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | |
---|
[0bd3faf] | 450 | void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) { |
---|
[fb2bde4] | 451 | (void)varArgsType; |
---|
| 452 | if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) { |
---|
| 453 | cost = Cost::zero; |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | |
---|
[0bd3faf] | 457 | void ConversionCost::postvisit( const ast::ZeroType * zeroType ) { |
---|
[fb2bde4] | 458 | (void)zeroType; |
---|
| 459 | if ( dynamic_cast< const ast::ZeroType * >( dst ) ) { |
---|
| 460 | cost = Cost::zero; |
---|
| 461 | } else if ( const ast::BasicType * dstAsBasic = |
---|
| 462 | dynamic_cast< const ast::BasicType * >( dst ) ) { |
---|
[7a780ad] | 463 | int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ]; |
---|
[fb2bde4] | 464 | if ( -1 == tableResult ) { |
---|
| 465 | cost = Cost::unsafe; |
---|
| 466 | } else { |
---|
| 467 | cost = Cost::zero; |
---|
| 468 | cost.incSafe( tableResult + 1 ); |
---|
[7a780ad] | 469 | cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] ); |
---|
[fb2bde4] | 470 | } |
---|
[46da46b] | 471 | // this has the effect of letting any expr such as x+0, x+1 to be typed |
---|
| 472 | // the same as x, instead of at least int. are we willing to sacrifice this little |
---|
| 473 | // bit of coherence with C? |
---|
| 474 | // TODO: currently this does not work when no zero/one overloads exist. Find a fix for it. |
---|
| 475 | // cost = Cost::zero; |
---|
[2f98fb2] | 476 | } else if ( dynamic_cast< const ast::PointerType * >( dst ) ) { |
---|
| 477 | cost = Cost::zero; |
---|
| 478 | // +1 for zero_t ->, +1 for disambiguation |
---|
| 479 | cost.incSafe( maxIntCost + 2 ); |
---|
[46da46b] | 480 | // assuming 0p is supposed to be used for pointers? |
---|
[af746cc] | 481 | } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { |
---|
[c333ed2] | 482 | if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { |
---|
[eb7586e] | 483 | cost = Cost::unsafe; |
---|
[af746cc] | 484 | } |
---|
[fb2bde4] | 485 | } |
---|
| 486 | } |
---|
| 487 | |
---|
[0bd3faf] | 488 | void ConversionCost::postvisit( const ast::OneType * oneType ) { |
---|
[fb2bde4] | 489 | (void)oneType; |
---|
| 490 | if ( dynamic_cast< const ast::OneType * >( dst ) ) { |
---|
| 491 | cost = Cost::zero; |
---|
| 492 | } else if ( const ast::BasicType * dstAsBasic = |
---|
[0bd3faf] | 493 | dynamic_cast< const ast::BasicType * >( dst ) ) { |
---|
[7a780ad] | 494 | int tableResult = costMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ]; |
---|
[fb2bde4] | 495 | if ( -1 == tableResult ) { |
---|
| 496 | cost = Cost::unsafe; |
---|
| 497 | } else { |
---|
| 498 | cost = Cost::zero; |
---|
| 499 | cost.incSafe( tableResult + 1 ); |
---|
[7a780ad] | 500 | cost.incSign( signMatrix[ ast::BasicKind::SignedInt ][ dstAsBasic->kind ] ); |
---|
[fb2bde4] | 501 | } |
---|
[af746cc] | 502 | } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { |
---|
[c333ed2] | 503 | if ( dstAsEnumInst->base && !dstAsEnumInst->base->isTyped ) { |
---|
[eb7586e] | 504 | cost = Cost::unsafe; |
---|
[af746cc] | 505 | } |
---|
[9d5089e] | 506 | } |
---|
[fb2bde4] | 507 | } |
---|
[0bd3faf] | 508 | |
---|
| 509 | // size_t ConversionCost::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); |
---|
[fb2bde4] | 510 | |
---|
[51b7345] | 511 | } // namespace ResolvExpr |
---|
[a32b204] | 512 | |
---|
| 513 | // Local Variables: // |
---|
| 514 | // tab-width: 4 // |
---|
| 515 | // mode: c++ // |
---|
| 516 | // compile-command: "make install" // |
---|
| 517 | // End: // |
---|