[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 | // CommonType.cc -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 06:59:27 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[ada4575] | 12 | // Last Modified On : Thu Feb 14 17:10:10 2019 |
---|
| 13 | // Update Count : 24 |
---|
[a32b204] | 14 | // |
---|
[51b7345] | 15 | |
---|
[5bf3976] | 16 | #include "CommonType.hpp" |
---|
| 17 | |
---|
[e3e16bc] | 18 | #include <cassert> // for strict_dynamic_cast |
---|
[ea6332d] | 19 | #include <map> // for _Rb_tree_const_iterator |
---|
| 20 | #include <utility> // for pair |
---|
| 21 | |
---|
[ee574a2] | 22 | #include "AST/Decl.hpp" |
---|
| 23 | #include "AST/Type.hpp" |
---|
[53452de] | 24 | #include "Common/PassVisitor.h" |
---|
[ea6332d] | 25 | #include "ResolvExpr/TypeEnvironment.h" // for OpenVarSet, AssertionSet |
---|
| 26 | #include "SymTab/Indexer.h" // for Indexer |
---|
| 27 | #include "SynTree/Declaration.h" // for TypeDecl, NamedTypeDecl (ptr... |
---|
| 28 | #include "SynTree/Type.h" // for BasicType, BasicType::Kind::... |
---|
| 29 | #include "SynTree/Visitor.h" // for Visitor |
---|
[d286cf68] | 30 | #include "Unify.h" // for unifyExact, WidenMode |
---|
[ea6332d] | 31 | #include "typeops.h" // for isFtype |
---|
[ef1da0e2] | 32 | #include "Tuples/Tuples.h" |
---|
[51b7345] | 33 | |
---|
[ba89e9b7] | 34 | // #define DEBUG |
---|
[9d1e3f7] | 35 | #ifdef DEBUG |
---|
| 36 | #define PRINT(x) x |
---|
| 37 | #else |
---|
| 38 | #define PRINT(x) |
---|
| 39 | #endif |
---|
[51b7345] | 40 | |
---|
| 41 | namespace ResolvExpr { |
---|
[ee574a2] | 42 | struct CommonType_old : public WithShortCircuiting { |
---|
[ef5b828] | 43 | CommonType_old( Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
| 44 | Type * get_result() const { return result; } |
---|
[a32b204] | 45 | |
---|
[53452de] | 46 | void previsit( BaseSyntaxNode * ) { visit_children = false; } |
---|
| 47 | |
---|
| 48 | void postvisit( VoidType * voidType ); |
---|
| 49 | void postvisit( BasicType * basicType ); |
---|
| 50 | void postvisit( PointerType * pointerType ); |
---|
| 51 | void postvisit( ArrayType * arrayType ); |
---|
| 52 | void postvisit( ReferenceType * refType ); |
---|
| 53 | void postvisit( FunctionType * functionType ); |
---|
| 54 | void postvisit( StructInstType * aggregateUseType ); |
---|
| 55 | void postvisit( UnionInstType * aggregateUseType ); |
---|
| 56 | void postvisit( EnumInstType * aggregateUseType ); |
---|
| 57 | void postvisit( TraitInstType * aggregateUseType ); |
---|
| 58 | void postvisit( TypeInstType * aggregateUseType ); |
---|
| 59 | void postvisit( TupleType * tupleType ); |
---|
| 60 | void postvisit( VarArgsType * varArgsType ); |
---|
| 61 | void postvisit( ZeroType * zeroType ); |
---|
| 62 | void postvisit( OneType * oneType ); |
---|
| 63 | |
---|
| 64 | private: |
---|
[ef5b828] | 65 | template< typename Pointer > void getCommonWithVoidPointer( Pointer * voidPointer, Pointer * otherPointer ); |
---|
| 66 | template< typename RefType > void handleRefType( RefType * inst, Type * other ); |
---|
[a32b204] | 67 | |
---|
[ef5b828] | 68 | Type * result; |
---|
| 69 | Type * type2; // inherited |
---|
[a32b204] | 70 | bool widenFirst, widenSecond; |
---|
| 71 | const SymTab::Indexer &indexer; |
---|
| 72 | TypeEnvironment &env; |
---|
| 73 | const OpenVarSet &openVars; |
---|
| 74 | }; |
---|
| 75 | |
---|
[000178a] | 76 | Type * handleReference( Type * t1, Type * t2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment & env, const OpenVarSet &openVars ) { |
---|
| 77 | Type * common = nullptr; |
---|
[65cec25] | 78 | AssertionSet have, need; |
---|
| 79 | OpenVarSet newOpen( openVars ); |
---|
| 80 | // need unify to bind type variables |
---|
[000178a] | 81 | if ( unify( t1, t2, env, have, need, newOpen, indexer, common ) ) { |
---|
[9d1e3f7] | 82 | PRINT( |
---|
| 83 | std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl; |
---|
| 84 | ) |
---|
[ef5b828] | 85 | if ( (widenFirst || t2->tq <= t1->tq) && (widenSecond || t1->tq <= t2->tq) ) { |
---|
[9d1e3f7] | 86 | PRINT( |
---|
| 87 | std::cerr << "widen okay" << std::endl; |
---|
| 88 | ) |
---|
[ef5b828] | 89 | common->tq |= t1->tq; |
---|
| 90 | common->tq |= t2->tq; |
---|
[000178a] | 91 | return common; |
---|
[65cec25] | 92 | } |
---|
| 93 | } |
---|
[9d1e3f7] | 94 | PRINT( |
---|
| 95 | std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl; |
---|
| 96 | ) |
---|
[000178a] | 97 | return nullptr; |
---|
[65cec25] | 98 | } |
---|
| 99 | |
---|
[ef5b828] | 100 | Type * commonType( Type * type1, Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) { |
---|
[ee574a2] | 101 | PassVisitor<CommonType_old> visitor( type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
[65cec25] | 102 | |
---|
[e6cee92] | 103 | int depth1 = type1->referenceDepth(); |
---|
| 104 | int depth2 = type2->referenceDepth(); |
---|
| 105 | if ( depth1 > 0 || depth2 > 0 ) { |
---|
| 106 | int diff = depth1-depth2; |
---|
| 107 | // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed. |
---|
[ba89e9b7] | 108 | // if ( diff > 1 || diff < -1 ) return nullptr; |
---|
[e6cee92] | 109 | |
---|
| 110 | // special case where one type has a reference depth of 1 larger than the other |
---|
[000178a] | 111 | if ( diff > 0 || diff < 0 ) { |
---|
[9d1e3f7] | 112 | PRINT( |
---|
| 113 | std::cerr << "reference depth diff: " << diff << std::endl; |
---|
| 114 | ) |
---|
[000178a] | 115 | Type * result = nullptr; |
---|
[74cdfb1] | 116 | ReferenceType * ref1 = dynamic_cast< ReferenceType * >( type1 ); |
---|
| 117 | ReferenceType * ref2 = dynamic_cast< ReferenceType * >( type2 ); |
---|
| 118 | if ( diff > 0 ) { |
---|
| 119 | // deeper on the left |
---|
| 120 | assert( ref1 ); |
---|
[000178a] | 121 | result = handleReference( ref1->base, type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
| 122 | } else { |
---|
[74cdfb1] | 123 | // deeper on the right |
---|
| 124 | assert( ref2 ); |
---|
[000178a] | 125 | result = handleReference( type1, ref2->base, widenFirst, widenSecond, indexer, env, openVars ); |
---|
| 126 | } |
---|
[74cdfb1] | 127 | if ( result && ref1 ) { |
---|
| 128 | // formal is reference, so result should be reference |
---|
[9d1e3f7] | 129 | PRINT( |
---|
| 130 | std::cerr << "formal is reference; result should be reference" << std::endl; |
---|
| 131 | ) |
---|
[ef5b828] | 132 | result = new ReferenceType( ref1->tq, result ); |
---|
[74cdfb1] | 133 | } |
---|
[9d1e3f7] | 134 | PRINT( |
---|
| 135 | std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl; |
---|
| 136 | ) |
---|
[000178a] | 137 | return result; |
---|
[65cec25] | 138 | } |
---|
[e6cee92] | 139 | // otherwise, both are reference types of the same depth and this is handled by the CommonType visitor. |
---|
[65cec25] | 140 | } |
---|
| 141 | |
---|
[a32b204] | 142 | type1->accept( visitor ); |
---|
[ef5b828] | 143 | Type * result = visitor.pass.get_result(); |
---|
[a32b204] | 144 | if ( ! result ) { |
---|
[2c57025] | 145 | // this appears to be handling for opaque type declarations |
---|
[a32b204] | 146 | if ( widenSecond ) { |
---|
[ef5b828] | 147 | if ( const TypeInstType * inst = dynamic_cast< const TypeInstType * >( type2 ) ) { |
---|
| 148 | if ( const NamedTypeDecl * nt = indexer.lookupType( inst->get_name() ) ) { |
---|
| 149 | const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( nt ); |
---|
[a32b204] | 150 | if ( type->get_base() ) { |
---|
[ef5b828] | 151 | Type::Qualifiers tq1 = type1->tq, tq2 = type2->tq; |
---|
[a32b204] | 152 | AssertionSet have, need; |
---|
| 153 | OpenVarSet newOpen( openVars ); |
---|
[ef5b828] | 154 | type1->tq = Type::Qualifiers(); |
---|
| 155 | type->get_base()->tq = tq1; |
---|
[a32b204] | 156 | if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 157 | result = type1->clone(); |
---|
[ef5b828] | 158 | result->tq = tq1 | tq2; |
---|
[a32b204] | 159 | } // if |
---|
[ef5b828] | 160 | type1->tq = tq1; |
---|
| 161 | type->get_base()->tq = Type::Qualifiers(); |
---|
[a32b204] | 162 | } // if |
---|
| 163 | } // if |
---|
| 164 | } // if |
---|
| 165 | } // if |
---|
| 166 | } // if |
---|
[51b7345] | 167 | #ifdef DEBUG |
---|
[c93bc28] | 168 | std::cerr << "============= commonType" << std::endl << "type1 is "; |
---|
| 169 | type1->print( std::cerr ); |
---|
| 170 | std::cerr << " type2 is "; |
---|
| 171 | type2->print( std::cerr ); |
---|
[a32b204] | 172 | if ( result ) { |
---|
[c93bc28] | 173 | std::cerr << " common type is "; |
---|
| 174 | result->print( std::cerr ); |
---|
[a32b204] | 175 | } else { |
---|
[c93bc28] | 176 | std::cerr << " no common type"; |
---|
[a32b204] | 177 | } // if |
---|
[c93bc28] | 178 | std::cerr << std::endl; |
---|
[51b7345] | 179 | #endif |
---|
[a32b204] | 180 | return result; |
---|
| 181 | } |
---|
[cdcddfe1] | 182 | |
---|
[e15853c] | 183 | // GENERATED START, DO NOT EDIT |
---|
[6fd1955] | 184 | // GENERATED BY BasicTypes-gen.cc |
---|
[e15853c] | 185 | #define BT BasicType:: |
---|
| 186 | static const BasicType::Kind commonTypes[BasicType::NUMBER_OF_BASIC_TYPES][BasicType::NUMBER_OF_BASIC_TYPES] = { // nearest common ancestor |
---|
[96df1329] | 187 | /* B C SC UC SI SUI |
---|
| 188 | I UI LI LUI LLI LLUI |
---|
| 189 | IB UIB _FH _FH _F _FC |
---|
| 190 | F FC _FX _FXC FD _FDC |
---|
| 191 | D DC F80X _FDXC F80 _FB |
---|
| 192 | _FLDC FB LD LDC _FBX _FLDXC |
---|
| 193 | */ |
---|
| 194 | { |
---|
[3a55d9f] | 195 | /* B */ BT Bool, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 196 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 197 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 198 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 199 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 200 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 201 | }, |
---|
| 202 | { |
---|
[3a55d9f] | 203 | /* C */ BT Char, BT Char, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 204 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 205 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 206 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 207 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 208 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 209 | }, |
---|
| 210 | { |
---|
[3a55d9f] | 211 | /* SC */ BT SignedChar, BT SignedChar, BT SignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 212 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 213 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 214 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 215 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 216 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 217 | }, |
---|
| 218 | { |
---|
[3a55d9f] | 219 | /* UC */ BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT UnsignedChar, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 220 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 221 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 222 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 223 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 224 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 225 | }, |
---|
| 226 | { |
---|
[3a55d9f] | 227 | /* SI */ BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortSignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 228 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 229 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 230 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 231 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 232 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 233 | }, |
---|
| 234 | { |
---|
[3a55d9f] | 235 | /* SUI */ BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, BT ShortUnsignedInt, |
---|
[96df1329] | 236 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 237 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 238 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 239 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 240 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 241 | }, |
---|
| 242 | { |
---|
[3a55d9f] | 243 | /* I */ BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, BT SignedInt, |
---|
[96df1329] | 244 | BT SignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 245 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 246 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 247 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 248 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 249 | }, |
---|
| 250 | { |
---|
[3a55d9f] | 251 | /* UI */ BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, BT UnsignedInt, |
---|
[96df1329] | 252 | BT UnsignedInt, BT UnsignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 253 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 254 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 255 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 256 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 257 | }, |
---|
| 258 | { |
---|
[3a55d9f] | 259 | /* LI */ BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, |
---|
[96df1329] | 260 | BT LongSignedInt, BT LongSignedInt, BT LongSignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 261 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 262 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 263 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 264 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 265 | }, |
---|
| 266 | { |
---|
[3a55d9f] | 267 | /* LUI */ BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, |
---|
[96df1329] | 268 | BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongUnsignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 269 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 270 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 271 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 272 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 273 | }, |
---|
| 274 | { |
---|
[3a55d9f] | 275 | /* LLI */ BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, |
---|
[96df1329] | 276 | BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongSignedInt, BT LongLongUnsignedInt, |
---|
| 277 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 278 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 279 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 280 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 281 | }, |
---|
| 282 | { |
---|
[3a55d9f] | 283 | /* LLUI */ BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, |
---|
[96df1329] | 284 | BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, BT LongLongUnsignedInt, |
---|
| 285 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 286 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 287 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 288 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 289 | }, |
---|
| 290 | { |
---|
[3a55d9f] | 291 | /* IB */ BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, |
---|
[96df1329] | 292 | BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, BT SignedInt128, |
---|
| 293 | BT SignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 294 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 295 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 296 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 297 | }, |
---|
| 298 | { |
---|
[3a55d9f] | 299 | /* UIB */ BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, |
---|
[96df1329] | 300 | BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, BT UnsignedInt128, |
---|
| 301 | BT UnsignedInt128, BT UnsignedInt128, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 302 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 303 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 304 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 305 | }, |
---|
| 306 | { |
---|
[3a55d9f] | 307 | /* _FH */ BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, |
---|
[96df1329] | 308 | BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16, |
---|
| 309 | BT uFloat16, BT uFloat16, BT uFloat16, BT uFloat16Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 310 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 311 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 312 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 313 | }, |
---|
| 314 | { |
---|
[3a55d9f] | 315 | /* _FH */ BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, |
---|
[96df1329] | 316 | BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, |
---|
| 317 | BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat16Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
| 318 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 319 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 320 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 321 | }, |
---|
| 322 | { |
---|
[3a55d9f] | 323 | /* _F */ BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, |
---|
[96df1329] | 324 | BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32, |
---|
| 325 | BT uFloat32, BT uFloat32, BT uFloat32, BT uFloat32Complex, BT uFloat32, BT uFloat32Complex, |
---|
| 326 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 327 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 328 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 329 | }, |
---|
| 330 | { |
---|
[3a55d9f] | 331 | /* _FC */ BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
[96df1329] | 332 | BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
| 333 | BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, BT uFloat32Complex, |
---|
| 334 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 335 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 336 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 337 | }, |
---|
| 338 | { |
---|
[3a55d9f] | 339 | /* F */ BT Float, BT Float, BT Float, BT Float, BT Float, BT Float, |
---|
[96df1329] | 340 | BT Float, BT Float, BT Float, BT Float, BT Float, BT Float, |
---|
| 341 | BT Float, BT Float, BT Float, BT FloatComplex, BT Float, BT FloatComplex, |
---|
| 342 | BT Float, BT FloatComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 343 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 344 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 345 | }, |
---|
| 346 | { |
---|
[3a55d9f] | 347 | /* FC */ BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
[96df1329] | 348 | BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
| 349 | BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, BT FloatComplex, |
---|
| 350 | BT FloatComplex, BT FloatComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 351 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 352 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 353 | }, |
---|
| 354 | { |
---|
[3a55d9f] | 355 | /* _FX */ BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, |
---|
[96df1329] | 356 | BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32x, |
---|
| 357 | BT uFloat32x, BT uFloat32x, BT uFloat32x, BT uFloat32xComplex, BT uFloat32x, BT uFloat32xComplex, |
---|
| 358 | BT uFloat32x, BT uFloat32xComplex, BT uFloat32x, BT uFloat32xComplex, BT uFloat64, BT uFloat64Complex, |
---|
| 359 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 360 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 361 | }, |
---|
| 362 | { |
---|
[3a55d9f] | 363 | /* _FXC */ BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
[96df1329] | 364 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
| 365 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, |
---|
| 366 | BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat32xComplex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 367 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 368 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 369 | }, |
---|
| 370 | { |
---|
[3a55d9f] | 371 | /* FD */ BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, |
---|
[96df1329] | 372 | BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64, |
---|
| 373 | BT uFloat64, BT uFloat64, BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, |
---|
| 374 | BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, BT uFloat64, BT uFloat64Complex, |
---|
| 375 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 376 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 377 | }, |
---|
| 378 | { |
---|
[3a55d9f] | 379 | /* _FDC */ BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
[96df1329] | 380 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 381 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 382 | BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, BT uFloat64Complex, |
---|
| 383 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 384 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 385 | }, |
---|
| 386 | { |
---|
[3a55d9f] | 387 | /* D */ BT Double, BT Double, BT Double, BT Double, BT Double, BT Double, |
---|
[96df1329] | 388 | BT Double, BT Double, BT Double, BT Double, BT Double, BT Double, |
---|
| 389 | BT Double, BT Double, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, |
---|
| 390 | BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, BT Double, BT DoubleComplex, |
---|
| 391 | BT Double, BT DoubleComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 392 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 393 | }, |
---|
| 394 | { |
---|
[3a55d9f] | 395 | /* DC */ BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
[96df1329] | 396 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
| 397 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
| 398 | BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, BT DoubleComplex, |
---|
| 399 | BT DoubleComplex, BT DoubleComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 400 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 401 | }, |
---|
| 402 | { |
---|
[3a55d9f] | 403 | /* F80X */ BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, |
---|
[96df1329] | 404 | BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64x, |
---|
| 405 | BT uFloat64x, BT uFloat64x, BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, |
---|
| 406 | BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, |
---|
| 407 | BT uFloat64x, BT uFloat64xComplex, BT uFloat64x, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 408 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 409 | }, |
---|
| 410 | { |
---|
[3a55d9f] | 411 | /* _FDXC */ BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
[96df1329] | 412 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
| 413 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
| 414 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, |
---|
| 415 | BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat64xComplex, BT uFloat128Complex, |
---|
| 416 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 417 | }, |
---|
| 418 | { |
---|
[3a55d9f] | 419 | /* F80 */ BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, |
---|
[96df1329] | 420 | BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uuFloat80, |
---|
| 421 | BT uuFloat80, BT uuFloat80, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, |
---|
| 422 | BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, |
---|
| 423 | BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat64xComplex, BT uuFloat80, BT uFloat128, |
---|
| 424 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 425 | }, |
---|
| 426 | { |
---|
[3a55d9f] | 427 | /* _FB */ BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, |
---|
[96df1329] | 428 | BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128, |
---|
| 429 | BT uFloat128, BT uFloat128, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, |
---|
| 430 | BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, |
---|
| 431 | BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128Complex, BT uFloat128, BT uFloat128, |
---|
| 432 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 433 | }, |
---|
| 434 | { |
---|
[3a55d9f] | 435 | /* _FLDC */ BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
[96df1329] | 436 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
| 437 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
| 438 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
| 439 | BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, BT uFloat128Complex, |
---|
| 440 | BT uFloat128Complex, BT uFloat128Complex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 441 | }, |
---|
| 442 | { |
---|
[3a55d9f] | 443 | /* FB */ BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, |
---|
[96df1329] | 444 | BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uuFloat128, |
---|
| 445 | BT uuFloat128, BT uuFloat128, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, |
---|
| 446 | BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, |
---|
| 447 | BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uFloat128Complex, BT uuFloat128, BT uuFloat128, |
---|
| 448 | BT uFloat128Complex, BT uuFloat128, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 449 | }, |
---|
| 450 | { |
---|
[3a55d9f] | 451 | /* LD */ BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, |
---|
[96df1329] | 452 | BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, BT LongDouble, |
---|
| 453 | BT LongDouble, BT LongDouble, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, |
---|
| 454 | BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, |
---|
| 455 | BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDoubleComplex, BT LongDouble, BT LongDouble, |
---|
| 456 | BT LongDoubleComplex, BT LongDouble, BT LongDouble, BT LongDoubleComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 457 | }, |
---|
| 458 | { |
---|
[3a55d9f] | 459 | /* LDC */ BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
[96df1329] | 460 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
| 461 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
| 462 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
| 463 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, |
---|
| 464 | BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT LongDoubleComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 465 | }, |
---|
| 466 | { |
---|
[3a55d9f] | 467 | /* _FBX */ BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, |
---|
[96df1329] | 468 | BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128x, |
---|
| 469 | BT uFloat128x, BT uFloat128x, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 470 | BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 471 | BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128x, |
---|
| 472 | BT uFloat128xComplex, BT uFloat128x, BT uFloat128x, BT uFloat128xComplex, BT uFloat128x, BT uFloat128xComplex, |
---|
| 473 | }, |
---|
| 474 | { |
---|
[ef5b828] | 475 | /* _FLDXC */ BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
[96df1329] | 476 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 477 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 478 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 479 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 480 | BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, BT uFloat128xComplex, |
---|
| 481 | }, |
---|
[fd9ae1d] | 482 | }; // commonTypes |
---|
[e15853c] | 483 | #undef BT |
---|
| 484 | // GENERATED END |
---|
[4ee3b0c1] | 485 | static_assert( |
---|
[ef5b828] | 486 | sizeof(commonTypes)/sizeof(commonTypes[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES * BasicType::NUMBER_OF_BASIC_TYPES, |
---|
[4ee3b0c1] | 487 | "Each basic type kind should have a corresponding row in the combined type matrix" |
---|
| 488 | ); |
---|
[a32b204] | 489 | |
---|
[ef5b828] | 490 | CommonType_old::CommonType_old( Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) |
---|
[a32b204] | 491 | : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) { |
---|
| 492 | } |
---|
| 493 | |
---|
[ee574a2] | 494 | void CommonType_old::postvisit( VoidType * ) {} |
---|
[a32b204] | 495 | |
---|
[ef5b828] | 496 | void CommonType_old::postvisit( BasicType * basicType ) { |
---|
| 497 | if ( BasicType * otherBasic = dynamic_cast< BasicType * >( type2 ) ) { |
---|
[cdcddfe1] | 498 | BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ otherBasic->get_kind() ]; |
---|
[ef5b828] | 499 | if ( ( ( newType == basicType->get_kind() && basicType->tq >= otherBasic->tq ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->tq <= otherBasic->tq ) || widenSecond ) ) { |
---|
| 500 | result = new BasicType( basicType->tq | otherBasic->tq, newType ); |
---|
[a32b204] | 501 | } // if |
---|
[fc134a48] | 502 | } else if ( dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) { |
---|
[89e6ffc] | 503 | // use signed int in lieu of the enum/zero/one type |
---|
[cdcddfe1] | 504 | BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
[ef5b828] | 505 | if ( ( ( newType == basicType->get_kind() && basicType->tq >= type2->tq ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->tq <= type2->tq ) || widenSecond ) ) { |
---|
| 506 | result = new BasicType( basicType->tq | type2->tq, newType ); |
---|
[a436947] | 507 | } // if |
---|
[fc134a48] | 508 | } else if ( const EnumInstType * enumInst = dynamic_cast< const EnumInstType * > ( type2 ) ) { |
---|
| 509 | const EnumDecl* enumDecl = enumInst->baseEnum; |
---|
| 510 | if ( const Type* baseType = enumDecl->base ) { |
---|
| 511 | result = baseType->clone(); |
---|
| 512 | } else { |
---|
| 513 | BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
| 514 | if ( ( ( newType == basicType->get_kind() && basicType->tq >= type2->tq ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->tq <= type2->tq ) || widenSecond ) ) { |
---|
| 515 | result = new BasicType( basicType->tq | type2->tq, newType ); |
---|
| 516 | } // if |
---|
| 517 | } |
---|
| 518 | } |
---|
[a32b204] | 519 | } |
---|
| 520 | |
---|
[65cec25] | 521 | template< typename Pointer > |
---|
[ef5b828] | 522 | void CommonType_old::getCommonWithVoidPointer( Pointer * voidPointer, Pointer * otherPointer ) { |
---|
| 523 | if ( TypeInstType * var = dynamic_cast< TypeInstType * >( otherPointer->get_base() ) ) { |
---|
[a2a77af] | 524 | OpenVarSet::const_iterator entry = openVars.find( var->get_name() ); |
---|
| 525 | if ( entry != openVars.end() ) { |
---|
| 526 | AssertionSet need, have; |
---|
| 527 | WidenMode widen( widenFirst, widenSecond ); |
---|
[d286cf68] | 528 | if ( entry != openVars.end() && ! env.bindVar(var, voidPointer->get_base(), entry->second, need, have, openVars, widen, indexer ) ) return; |
---|
[a2a77af] | 529 | } |
---|
[2c57025] | 530 | } |
---|
[a2a77af] | 531 | result = voidPointer->clone(); |
---|
[ef5b828] | 532 | result->tq |= otherPointer->tq; |
---|
[2c57025] | 533 | } |
---|
| 534 | |
---|
[ef5b828] | 535 | void CommonType_old::postvisit( PointerType * pointerType ) { |
---|
| 536 | if ( PointerType * otherPointer = dynamic_cast< PointerType * >( type2 ) ) { |
---|
[c93bc28] | 537 | // std::cerr << "commonType: two pointers: " << pointerType << " / " << otherPointer << std::endl; |
---|
[ef5b828] | 538 | if ( widenFirst && dynamic_cast< VoidType * >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) { |
---|
[a2a77af] | 539 | getCommonWithVoidPointer( otherPointer, pointerType ); |
---|
[ef5b828] | 540 | } else if ( widenSecond && dynamic_cast< VoidType * >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) { |
---|
[a2a77af] | 541 | getCommonWithVoidPointer( pointerType, otherPointer ); |
---|
[ef5b828] | 542 | } else if ( ( pointerType->get_base()->tq >= otherPointer->get_base()->tq || widenFirst ) |
---|
| 543 | && ( pointerType->get_base()->tq <= otherPointer->get_base()->tq || widenSecond ) ) { |
---|
[c93bc28] | 544 | // std::cerr << "middle case" << std::endl; |
---|
[ef5b828] | 545 | Type::Qualifiers tq1 = pointerType->get_base()->tq, tq2 = otherPointer->get_base()->tq; |
---|
| 546 | pointerType->get_base()->tq = Type::Qualifiers(); |
---|
| 547 | otherPointer->get_base()->tq = Type::Qualifiers(); |
---|
[a32b204] | 548 | AssertionSet have, need; |
---|
| 549 | OpenVarSet newOpen( openVars ); |
---|
| 550 | if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
[c93bc28] | 551 | // std::cerr << "unifyExact success" << std::endl; |
---|
[a32b204] | 552 | if ( tq1 < tq2 ) { |
---|
| 553 | result = pointerType->clone(); |
---|
| 554 | } else { |
---|
| 555 | result = otherPointer->clone(); |
---|
| 556 | } // if |
---|
[ef5b828] | 557 | strict_dynamic_cast<PointerType *>(result)->base->tq = tq1 | tq2; |
---|
[a32b204] | 558 | } else { |
---|
[c93bc28] | 559 | /// std::cerr << "place for ptr-to-type" << std::endl; |
---|
[a32b204] | 560 | } // if |
---|
[ef5b828] | 561 | pointerType->get_base()->tq = tq1; |
---|
| 562 | otherPointer->get_base()->tq = tq2; |
---|
[a32b204] | 563 | } // if |
---|
[ef5b828] | 564 | } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) { |
---|
[89e6ffc] | 565 | result = pointerType->clone(); |
---|
[ef5b828] | 566 | result->tq |= type2->tq; |
---|
[a32b204] | 567 | } // if |
---|
| 568 | } |
---|
| 569 | |
---|
[ee574a2] | 570 | void CommonType_old::postvisit( ArrayType * ) {} |
---|
[65cec25] | 571 | |
---|
[ef5b828] | 572 | void CommonType_old::postvisit( ReferenceType * refType ) { |
---|
| 573 | if ( ReferenceType * otherRef = dynamic_cast< ReferenceType * >( type2 ) ) { |
---|
[c93bc28] | 574 | // std::cerr << "commonType: both references: " << refType << " / " << otherRef << std::endl; |
---|
[ef5b828] | 575 | // std::cerr << ( refType->get_base()->tq >= otherRef->get_base()->tq || widenFirst ) << (refType->get_base()->tq <= otherRef->get_base()->tq || widenSecond) << std::endl; |
---|
| 576 | if ( widenFirst && dynamic_cast< VoidType * >( otherRef->get_base() ) && ! isFtype(refType->get_base()) ) { |
---|
[65cec25] | 577 | getCommonWithVoidPointer( otherRef, refType ); |
---|
[ef5b828] | 578 | } else if ( widenSecond && dynamic_cast< VoidType * >( refType->get_base() ) && ! isFtype(otherRef->get_base()) ) { |
---|
[65cec25] | 579 | getCommonWithVoidPointer( refType, otherRef ); |
---|
[ef5b828] | 580 | } else if ( ( refType->get_base()->tq >= otherRef->get_base()->tq || widenFirst ) |
---|
| 581 | && ( refType->get_base()->tq <= otherRef->get_base()->tq || widenSecond ) ) { |
---|
[c93bc28] | 582 | // std::cerr << "middle case" << std::endl; |
---|
[ef5b828] | 583 | Type::Qualifiers tq1 = refType->get_base()->tq, tq2 = otherRef->get_base()->tq; |
---|
| 584 | refType->get_base()->tq = Type::Qualifiers(); |
---|
| 585 | otherRef->get_base()->tq = Type::Qualifiers(); |
---|
[65cec25] | 586 | AssertionSet have, need; |
---|
| 587 | OpenVarSet newOpen( openVars ); |
---|
| 588 | if ( unifyExact( refType->get_base(), otherRef->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 589 | if ( tq1 < tq2 ) { |
---|
| 590 | result = refType->clone(); |
---|
| 591 | } else { |
---|
| 592 | result = otherRef->clone(); |
---|
| 593 | } // if |
---|
[ef5b828] | 594 | strict_dynamic_cast<ReferenceType *>(result)->base->tq = tq1 | tq2; |
---|
[65cec25] | 595 | } else { |
---|
[c93bc28] | 596 | /// std::cerr << "place for ptr-to-type" << std::endl; |
---|
[65cec25] | 597 | } // if |
---|
[ef5b828] | 598 | refType->get_base()->tq = tq1; |
---|
| 599 | otherRef->get_base()->tq = tq2; |
---|
[65cec25] | 600 | } // if |
---|
[ef5b828] | 601 | } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) { |
---|
[65cec25] | 602 | result = refType->clone(); |
---|
[ef5b828] | 603 | result->tq |= type2->tq; |
---|
[65cec25] | 604 | } // if |
---|
| 605 | } |
---|
| 606 | |
---|
[ee574a2] | 607 | void CommonType_old::postvisit( FunctionType * ) {} |
---|
| 608 | void CommonType_old::postvisit( StructInstType * ) {} |
---|
| 609 | void CommonType_old::postvisit( UnionInstType * ) {} |
---|
[a32b204] | 610 | |
---|
[ef5b828] | 611 | void CommonType_old::postvisit( EnumInstType * enumInstType ) { |
---|
| 612 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) { |
---|
[a436947] | 613 | // reuse BasicType, EnumInstType code by swapping type2 with enumInstType |
---|
[53452de] | 614 | result = commonType( type2, enumInstType, widenSecond, widenFirst, indexer, env, openVars ); |
---|
[a436947] | 615 | } // if |
---|
[a32b204] | 616 | } |
---|
| 617 | |
---|
[ee574a2] | 618 | void CommonType_old::postvisit( TraitInstType * ) { |
---|
[a32b204] | 619 | } |
---|
| 620 | |
---|
[ef5b828] | 621 | void CommonType_old::postvisit( TypeInstType * inst ) { |
---|
[a32b204] | 622 | if ( widenFirst ) { |
---|
[ef5b828] | 623 | const NamedTypeDecl * nt = indexer.lookupType( inst->get_name() ); |
---|
[a32b204] | 624 | if ( nt ) { |
---|
[ef5b828] | 625 | const TypeDecl * type = strict_dynamic_cast< const TypeDecl * >( nt ); |
---|
[a32b204] | 626 | if ( type->get_base() ) { |
---|
[ef5b828] | 627 | Type::Qualifiers tq1 = inst->tq, tq2 = type2->tq; |
---|
[a32b204] | 628 | AssertionSet have, need; |
---|
| 629 | OpenVarSet newOpen( openVars ); |
---|
[ef5b828] | 630 | type2->tq = Type::Qualifiers(); |
---|
| 631 | type->get_base()->tq = tq1; |
---|
[a32b204] | 632 | if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) { |
---|
| 633 | result = type2->clone(); |
---|
[ef5b828] | 634 | result->tq = tq1 | tq2; |
---|
[a32b204] | 635 | } // if |
---|
[ef5b828] | 636 | type2->tq = tq2; |
---|
| 637 | type->get_base()->tq = Type::Qualifiers(); |
---|
[a32b204] | 638 | } // if |
---|
| 639 | } // if |
---|
| 640 | } // if |
---|
| 641 | } |
---|
| 642 | |
---|
[ee574a2] | 643 | void CommonType_old::postvisit( TupleType * ) {} |
---|
| 644 | void CommonType_old::postvisit( VarArgsType * ) {} |
---|
[89e6ffc] | 645 | |
---|
[ef5b828] | 646 | void CommonType_old::postvisit( ZeroType * zeroType ) { |
---|
[89e6ffc] | 647 | if ( widenFirst ) { |
---|
[ef5b828] | 648 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< PointerType * >( type2 ) || dynamic_cast< EnumInstType * >( type2 ) ) { |
---|
| 649 | if ( widenSecond || zeroType->tq <= type2->tq ) { |
---|
[89e6ffc] | 650 | result = type2->clone(); |
---|
[ef5b828] | 651 | result->tq |= zeroType->tq; |
---|
[89e6ffc] | 652 | } |
---|
[ef5b828] | 653 | } else if ( widenSecond && dynamic_cast< OneType * >( type2 ) ) { |
---|
| 654 | result = new BasicType( zeroType->tq, BasicType::SignedInt ); |
---|
| 655 | result->tq |= type2->tq; |
---|
[89e6ffc] | 656 | } |
---|
| 657 | } |
---|
| 658 | } |
---|
| 659 | |
---|
[ef5b828] | 660 | void CommonType_old::postvisit( OneType * oneType ) { |
---|
[89e6ffc] | 661 | if ( widenFirst ) { |
---|
[ef5b828] | 662 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< EnumInstType * >( type2 ) ) { |
---|
| 663 | if ( widenSecond || oneType->tq <= type2->tq ) { |
---|
[89e6ffc] | 664 | result = type2->clone(); |
---|
[ef5b828] | 665 | result->tq |= oneType->tq; |
---|
[89e6ffc] | 666 | } |
---|
[ef5b828] | 667 | } else if ( widenSecond && dynamic_cast< ZeroType * >( type2 ) ) { |
---|
| 668 | result = new BasicType( oneType->tq, BasicType::SignedInt ); |
---|
| 669 | result->tq |= type2->tq; |
---|
[89e6ffc] | 670 | } |
---|
| 671 | } |
---|
| 672 | } |
---|
[ee574a2] | 673 | |
---|
| 674 | class CommonType_new final : public ast::WithShortCircuiting { |
---|
| 675 | const ast::Type * type2; |
---|
| 676 | WidenMode widen; |
---|
| 677 | const ast::SymbolTable & symtab; |
---|
| 678 | ast::TypeEnvironment & tenv; |
---|
| 679 | const ast::OpenVarSet & open; |
---|
[ef1da0e2] | 680 | ast::AssertionSet & need; |
---|
| 681 | ast::AssertionSet & have; |
---|
[ee574a2] | 682 | public: |
---|
[c15085d] | 683 | static size_t traceId; |
---|
[ee574a2] | 684 | ast::ptr< ast::Type > result; |
---|
| 685 | |
---|
[ef5b828] | 686 | CommonType_new( |
---|
| 687 | const ast::Type * t2, WidenMode w, const ast::SymbolTable & st, |
---|
[ef1da0e2] | 688 | ast::TypeEnvironment & env, const ast::OpenVarSet & o, |
---|
| 689 | ast::AssertionSet & need, ast::AssertionSet & have ) |
---|
| 690 | : type2( t2 ), widen( w ), symtab( st ), tenv( env ), open( o ), need (need), have (have) ,result() {} |
---|
[ee574a2] | 691 | |
---|
| 692 | void previsit( const ast::Node * ) { visit_children = false; } |
---|
| 693 | |
---|
| 694 | void postvisit( const ast::VoidType * ) {} |
---|
| 695 | |
---|
| 696 | void postvisit( const ast::BasicType * basic ) { |
---|
| 697 | if ( auto basic2 = dynamic_cast< const ast::BasicType * >( type2 ) ) { |
---|
| 698 | #warning remove casts when `commonTypes` moved to new AST |
---|
| 699 | ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)basic2->kind ]; |
---|
[ef5b828] | 700 | if ( |
---|
| 701 | ( ( kind == basic->kind && basic->qualifiers >= basic2->qualifiers ) |
---|
| 702 | || widen.first ) |
---|
| 703 | && ( ( kind == basic2->kind && basic->qualifiers <= basic2->qualifiers ) |
---|
| 704 | || widen.second ) |
---|
[ee574a2] | 705 | ) { |
---|
| 706 | result = new ast::BasicType{ kind, basic->qualifiers | basic2->qualifiers }; |
---|
| 707 | } |
---|
[ef5b828] | 708 | } else if ( |
---|
[fc134a48] | 709 | dynamic_cast< const ast::ZeroType * >( type2 ) |
---|
[ee574a2] | 710 | || dynamic_cast< const ast::OneType * >( type2 ) |
---|
| 711 | ) { |
---|
| 712 | #warning remove casts when `commonTypes` moved to new AST |
---|
| 713 | ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)ast::BasicType::SignedInt ]; |
---|
[ef5b828] | 714 | if ( |
---|
| 715 | ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) |
---|
| 716 | || widen.first ) |
---|
| 717 | && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers ) |
---|
| 718 | || widen.second ) |
---|
[ee574a2] | 719 | ) { |
---|
| 720 | result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers }; |
---|
| 721 | } |
---|
[fc134a48] | 722 | } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { |
---|
| 723 | #warning remove casts when `commonTypes` moved to new AST |
---|
| 724 | const ast::EnumDecl* enumDecl = enumInst->base; |
---|
| 725 | if ( enumDecl->base ) { |
---|
| 726 | result = enumDecl->base.get(); |
---|
| 727 | } else { |
---|
| 728 | ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)ast::BasicType::SignedInt ]; |
---|
| 729 | if ( |
---|
| 730 | ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) |
---|
| 731 | || widen.first ) |
---|
| 732 | && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers ) |
---|
| 733 | || widen.second ) |
---|
| 734 | ) { |
---|
| 735 | result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers }; |
---|
| 736 | } |
---|
| 737 | } |
---|
[ee574a2] | 738 | } |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | private: |
---|
| 742 | template< typename Pointer > |
---|
| 743 | void getCommonWithVoidPointer( const Pointer * voidPtr, const Pointer * oPtr ) { |
---|
| 744 | const ast::Type * base = oPtr->base; |
---|
| 745 | if ( auto var = dynamic_cast< const ast::TypeInstType * >( base ) ) { |
---|
[3e5dd913] | 746 | auto entry = open.find( *var ); |
---|
[ee574a2] | 747 | if ( entry != open.end() ) { |
---|
| 748 | ast::AssertionSet need, have; |
---|
[ef5b828] | 749 | if ( ! tenv.bindVar( |
---|
| 750 | var, voidPtr->base, entry->second, need, have, open, widen, symtab ) |
---|
[ee574a2] | 751 | ) return; |
---|
| 752 | } |
---|
| 753 | } |
---|
| 754 | result = voidPtr; |
---|
| 755 | add_qualifiers( result, oPtr->qualifiers ); |
---|
| 756 | } |
---|
| 757 | |
---|
[fc134a48] | 758 | // For a typed enum, we want to unify type1 with the base type of the enum |
---|
| 759 | bool tryResolveWithTypedEnum( const ast::Type * type1 ) { |
---|
| 760 | if (auto enumInst = dynamic_cast<const ast::EnumInstType *> (type2) ) { |
---|
| 761 | ast::OpenVarSet newOpen{ open }; |
---|
| 762 | if (enumInst->base->base |
---|
| 763 | && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen, symtab)) { |
---|
| 764 | result = type1; |
---|
| 765 | return true; |
---|
| 766 | } |
---|
| 767 | } |
---|
| 768 | return false; |
---|
| 769 | } |
---|
| 770 | |
---|
[ee574a2] | 771 | public: |
---|
| 772 | void postvisit( const ast::PointerType * pointer ) { |
---|
| 773 | if ( auto pointer2 = dynamic_cast< const ast::PointerType * >( type2 ) ) { |
---|
[ef5b828] | 774 | if ( |
---|
| 775 | widen.first |
---|
| 776 | && pointer2->base.as< ast::VoidType >() |
---|
| 777 | && ! ast::isFtype( pointer->base ) |
---|
[ee574a2] | 778 | ) { |
---|
| 779 | getCommonWithVoidPointer( pointer2, pointer ); |
---|
[ef5b828] | 780 | } else if ( |
---|
| 781 | widen.second |
---|
| 782 | && pointer->base.as< ast::VoidType >() |
---|
| 783 | && ! ast::isFtype( pointer2->base ) |
---|
[ee574a2] | 784 | ) { |
---|
| 785 | getCommonWithVoidPointer( pointer, pointer2 ); |
---|
| 786 | } else if ( |
---|
| 787 | ( pointer->base->qualifiers >= pointer2->base->qualifiers || widen.first ) |
---|
| 788 | && ( pointer->base->qualifiers <= pointer2->base->qualifiers || widen.second ) |
---|
| 789 | ) { |
---|
| 790 | ast::CV::Qualifiers q1 = pointer->base->qualifiers; |
---|
| 791 | ast::CV::Qualifiers q2 = pointer2->base->qualifiers; |
---|
| 792 | |
---|
[ef5b828] | 793 | // force t{1,2} to be cloned if their qualifiers must be stripped, so that |
---|
[ee574a2] | 794 | // pointer{,2}->base are unchanged |
---|
| 795 | ast::ptr< ast::Type > t1{ pointer->base }, t2{ pointer2->base }; |
---|
| 796 | reset_qualifiers( t1 ); |
---|
| 797 | reset_qualifiers( t2 ); |
---|
[ef5b828] | 798 | |
---|
[ee574a2] | 799 | ast::OpenVarSet newOpen{ open }; |
---|
| 800 | if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) { |
---|
| 801 | result = pointer; |
---|
| 802 | if ( q1.val != q2.val ) { |
---|
| 803 | // reset result->base->qualifiers to be union of two base qualifiers |
---|
[ef5b828] | 804 | strict_dynamic_cast< ast::PointerType * >( |
---|
| 805 | result.get_and_mutate() |
---|
[ee574a2] | 806 | )->base.get_and_mutate()->qualifiers = q1 | q2; |
---|
| 807 | } |
---|
| 808 | } |
---|
[ef1da0e2] | 809 | else if ( isFtype (t1) && isFtype (t2) ) { |
---|
| 810 | auto f1 = t1.as<ast::FunctionType>(); |
---|
| 811 | if (!f1) return; |
---|
| 812 | auto f2 = t2.strict_as<ast::FunctionType>(); |
---|
| 813 | |
---|
| 814 | assertf(f1->returns.size() <= 1, "Function return should not be a list"); |
---|
| 815 | assertf(f2->returns.size() <= 1, "Function return should not be a list"); |
---|
| 816 | |
---|
| 817 | if ( |
---|
| 818 | ( f1->params.size() != f2->params.size() || f1->returns.size() != f2->returns.size() ) |
---|
| 819 | && ! f1->isTtype() |
---|
| 820 | && ! f2->isTtype() |
---|
| 821 | ) return; |
---|
| 822 | |
---|
| 823 | auto params1 = flattenList( f1->params, tenv ); |
---|
| 824 | auto params2 = flattenList( f2->params, tenv ); |
---|
| 825 | |
---|
| 826 | auto crnt1 = params1.begin(); |
---|
| 827 | auto crnt2 = params2.begin(); |
---|
| 828 | auto end1 = params1.end(); |
---|
| 829 | auto end2 = params2.end(); |
---|
| 830 | |
---|
| 831 | while (crnt1 != end1 && crnt2 != end2 ) { |
---|
| 832 | const ast::Type * arg1 = *crnt1; |
---|
| 833 | const ast::Type * arg2 = *crnt2; |
---|
| 834 | |
---|
| 835 | bool isTuple1 = Tuples::isTtype( t1 ); |
---|
| 836 | bool isTuple2 = Tuples::isTtype( t2 ); |
---|
| 837 | |
---|
| 838 | // assumes here that ttype *must* be last parameter |
---|
| 839 | if ( isTuple1 && ! isTuple2 ) { |
---|
| 840 | // combine remainder of list2, then unify |
---|
| 841 | if (unifyExact( |
---|
| 842 | arg1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, |
---|
| 843 | noWiden(), symtab )) { |
---|
| 844 | break; |
---|
| 845 | |
---|
| 846 | } |
---|
| 847 | else return; |
---|
| 848 | } else if ( ! isTuple1 && isTuple2 ) { |
---|
| 849 | // combine remainder of list1, then unify |
---|
| 850 | if (unifyExact( |
---|
| 851 | tupleFromTypes( crnt1, end1 ), arg2, tenv, need, have, open, |
---|
| 852 | noWiden(), symtab )) { |
---|
| 853 | break; |
---|
| 854 | |
---|
| 855 | } |
---|
| 856 | else return; |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | // allow qualifiers of pointer and reference base to become more specific |
---|
| 860 | if (auto ref1 = dynamic_cast<const ast::ReferenceType *> (arg1)) { |
---|
| 861 | if (auto ref2 = dynamic_cast<const ast::ReferenceType *> (arg2)) { |
---|
| 862 | ast::ptr<ast::Type> base1 = ref1->base; |
---|
| 863 | ast::ptr<ast::Type> base2 = ref2->base; |
---|
| 864 | |
---|
| 865 | // xxx - assume LHS is always the target type |
---|
| 866 | |
---|
| 867 | if ( ! ((widen.second && ref2->qualifiers.is_mutex) |
---|
| 868 | || (ref1->qualifiers.is_mutex == ref2->qualifiers.is_mutex ))) return; |
---|
| 869 | |
---|
| 870 | if ( (widen.second && base1->qualifiers <= base2->qualifiers ) || (base2->qualifiers == base1->qualifiers) ) { |
---|
| 871 | |
---|
| 872 | reset_qualifiers(base1); |
---|
| 873 | reset_qualifiers(base2); |
---|
| 874 | |
---|
| 875 | if ( ! unifyExact( |
---|
| 876 | base1, base2, tenv, need, have, open, noWiden(), symtab ) |
---|
| 877 | ) return; |
---|
| 878 | } |
---|
| 879 | } |
---|
| 880 | else return; |
---|
| 881 | } |
---|
| 882 | else if (auto ptr1 = dynamic_cast<const ast::PointerType *> (arg1)) { |
---|
| 883 | if (auto ptr2 = dynamic_cast<const ast::PointerType *> (arg2)) { |
---|
| 884 | ast::ptr<ast::Type> base1 = ptr1->base; |
---|
| 885 | ast::ptr<ast::Type> base2 = ptr2->base; |
---|
| 886 | |
---|
| 887 | // xxx - assume LHS is always the target type |
---|
| 888 | // a function accepting const can always be called by non-const arg |
---|
| 889 | |
---|
| 890 | if ( (widen.second && base1->qualifiers <= base2->qualifiers ) || (base2->qualifiers == base1->qualifiers) ) { |
---|
| 891 | |
---|
| 892 | reset_qualifiers(base1); |
---|
| 893 | reset_qualifiers(base2); |
---|
| 894 | |
---|
| 895 | if ( ! unifyExact( |
---|
| 896 | base1, base2, tenv, need, have, open, noWiden(), symtab ) |
---|
| 897 | ) return; |
---|
| 898 | } |
---|
| 899 | } |
---|
| 900 | else return; |
---|
| 901 | |
---|
| 902 | } |
---|
| 903 | else if (! unifyExact( |
---|
| 904 | arg1, arg2, tenv, need, have, open, noWiden(), symtab )) return; |
---|
| 905 | |
---|
| 906 | ++crnt1; ++crnt2; |
---|
| 907 | } |
---|
| 908 | if ( crnt1 != end1 ) { |
---|
| 909 | // try unifying empty tuple with ttype |
---|
| 910 | const ast::Type * t1 = *crnt1; |
---|
| 911 | if (! Tuples::isTtype( t1 ) ) return; |
---|
| 912 | if (! unifyExact( |
---|
| 913 | t1, tupleFromTypes( crnt2, end2 ), tenv, need, have, open, |
---|
| 914 | noWiden(), symtab )) return; |
---|
| 915 | } else if ( crnt2 != end2 ) { |
---|
| 916 | // try unifying empty tuple with ttype |
---|
| 917 | const ast::Type * t2 = *crnt2; |
---|
| 918 | if (! Tuples::isTtype( t2 ) ) return; |
---|
| 919 | if (! unifyExact( |
---|
| 920 | tupleFromTypes( crnt1, end1 ), t2, tenv, need, have, open, |
---|
| 921 | noWiden(), symtab )) return; |
---|
| 922 | } |
---|
| 923 | if ((f1->returns.size() == 0 && f2->returns.size() == 0) |
---|
| 924 | || (f1->returns.size() == 1 && f2->returns.size() == 1 && unifyExact(f1->returns[0], f2->returns[0], tenv, need, have, open, noWiden(), symtab))) { |
---|
| 925 | result = pointer; |
---|
| 926 | |
---|
| 927 | for (auto & assn : f1->assertions) { |
---|
| 928 | auto i = need.find(assn); |
---|
| 929 | if (i != need.end()) i->second.isUsed = true; |
---|
| 930 | auto j = have.find(assn); |
---|
| 931 | if (j != have.end()) j->second.isUsed = true; |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | for (auto & assn : f2->assertions) { |
---|
| 935 | auto i = need.find(assn); |
---|
| 936 | if (i != need.end()) i->second.isUsed = true; |
---|
| 937 | auto j = have.find(assn); |
---|
| 938 | if (j != have.end()) j->second.isUsed = true; |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | } |
---|
| 942 | } // if ftype |
---|
| 943 | |
---|
[ee574a2] | 944 | } |
---|
| 945 | } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) { |
---|
| 946 | result = pointer; |
---|
| 947 | add_qualifiers( result, type2->qualifiers ); |
---|
[fc134a48] | 948 | } else { |
---|
| 949 | tryResolveWithTypedEnum( pointer ); |
---|
[ee574a2] | 950 | } |
---|
| 951 | } |
---|
| 952 | |
---|
[fc134a48] | 953 | void postvisit( const ast::ArrayType * arr ) { |
---|
| 954 | // xxx - does it make sense? |
---|
| 955 | tryResolveWithTypedEnum( arr ); |
---|
| 956 | } |
---|
[ee574a2] | 957 | |
---|
| 958 | void postvisit( const ast::ReferenceType * ref ) { |
---|
| 959 | if ( auto ref2 = dynamic_cast< const ast::ReferenceType * >( type2 ) ) { |
---|
| 960 | if ( |
---|
[ef5b828] | 961 | widen.first && ref2->base.as< ast::VoidType >() && ! ast::isFtype( ref->base ) |
---|
[ee574a2] | 962 | ) { |
---|
| 963 | getCommonWithVoidPointer( ref2, ref ); |
---|
[ef5b828] | 964 | } else if ( |
---|
| 965 | widen.second && ref->base.as< ast::VoidType>() && ! ast::isFtype( ref2->base ) |
---|
[ee574a2] | 966 | ) { |
---|
| 967 | getCommonWithVoidPointer( ref, ref2 ); |
---|
| 968 | } else if ( |
---|
| 969 | ( ref->base->qualifiers >= ref2->base->qualifiers || widen.first ) |
---|
| 970 | && ( ref->base->qualifiers <= ref2->base->qualifiers || widen.second ) |
---|
| 971 | ) { |
---|
| 972 | ast::CV::Qualifiers q1 = ref->base->qualifiers, q2 = ref2->base->qualifiers; |
---|
| 973 | |
---|
[ef5b828] | 974 | // force t{1,2} to be cloned if their qualifiers must be stripped, so that |
---|
[ee574a2] | 975 | // ref{,2}->base are unchanged |
---|
| 976 | ast::ptr< ast::Type > t1{ ref->base }, t2{ ref2->base }; |
---|
| 977 | reset_qualifiers( t1 ); |
---|
| 978 | reset_qualifiers( t2 ); |
---|
| 979 | |
---|
| 980 | ast::OpenVarSet newOpen{ open }; |
---|
| 981 | if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) { |
---|
| 982 | result = ref; |
---|
| 983 | if ( q1.val != q2.val ) { |
---|
| 984 | // reset result->base->qualifiers to be union of two base qualifiers |
---|
[ef5b828] | 985 | strict_dynamic_cast< ast::ReferenceType * >( |
---|
| 986 | result.get_and_mutate() |
---|
[ee574a2] | 987 | )->base.get_and_mutate()->qualifiers = q1 | q2; |
---|
| 988 | } |
---|
| 989 | } |
---|
| 990 | } |
---|
| 991 | } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) { |
---|
| 992 | result = ref; |
---|
| 993 | add_qualifiers( result, type2->qualifiers ); |
---|
[fc134a48] | 994 | } else { |
---|
| 995 | if (!dynamic_cast<const ast::EnumInstType *>(type2)) |
---|
[ef1da0e2] | 996 | result = commonType( type2, ref, tenv, need, have, open, widen, symtab ); |
---|
[ee574a2] | 997 | } |
---|
| 998 | } |
---|
| 999 | |
---|
[fc134a48] | 1000 | void postvisit( const ast::FunctionType * func) { |
---|
| 1001 | tryResolveWithTypedEnum( func ); |
---|
| 1002 | } |
---|
[ee574a2] | 1003 | |
---|
[fc134a48] | 1004 | void postvisit( const ast::StructInstType * inst ) { |
---|
| 1005 | tryResolveWithTypedEnum( inst ); |
---|
| 1006 | } |
---|
[ee574a2] | 1007 | |
---|
[fc134a48] | 1008 | void postvisit( const ast::UnionInstType * inst ) { |
---|
| 1009 | tryResolveWithTypedEnum( inst ); |
---|
| 1010 | } |
---|
[ee574a2] | 1011 | |
---|
| 1012 | void postvisit( const ast::EnumInstType * enumInst ) { |
---|
[fc134a48] | 1013 | if (!dynamic_cast<const ast::EnumInstType *>(type2)) |
---|
[ef1da0e2] | 1014 | result = commonType( type2, enumInst, tenv, need, have, open, widen, symtab); |
---|
[ee574a2] | 1015 | } |
---|
| 1016 | |
---|
| 1017 | void postvisit( const ast::TraitInstType * ) {} |
---|
| 1018 | |
---|
| 1019 | void postvisit( const ast::TypeInstType * inst ) { |
---|
| 1020 | if ( ! widen.first ) return; |
---|
| 1021 | if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) { |
---|
[ef5b828] | 1022 | if ( const ast::Type * base = |
---|
| 1023 | strict_dynamic_cast< const ast::TypeDecl * >( nt )->base |
---|
[ee574a2] | 1024 | ) { |
---|
| 1025 | ast::CV::Qualifiers q1 = inst->qualifiers, q2 = type2->qualifiers; |
---|
| 1026 | |
---|
| 1027 | // force t{1,2} to be cloned if their qualifiers must be mutated |
---|
| 1028 | ast::ptr< ast::Type > t1{ base }, t2{ type2 }; |
---|
| 1029 | reset_qualifiers( t1, q1 ); |
---|
| 1030 | reset_qualifiers( t2 ); |
---|
| 1031 | |
---|
| 1032 | ast::OpenVarSet newOpen{ open }; |
---|
| 1033 | if ( unifyExact( t1, t2, tenv, have, need, newOpen, noWiden(), symtab ) ) { |
---|
| 1034 | result = type2; |
---|
| 1035 | reset_qualifiers( result, q1 | q2 ); |
---|
[fc134a48] | 1036 | } else { |
---|
| 1037 | tryResolveWithTypedEnum( t1 ); |
---|
[ee574a2] | 1038 | } |
---|
| 1039 | } |
---|
| 1040 | } |
---|
| 1041 | } |
---|
| 1042 | |
---|
[fc134a48] | 1043 | void postvisit( const ast::TupleType * tuple) { |
---|
| 1044 | tryResolveWithTypedEnum( tuple ); |
---|
| 1045 | } |
---|
[ee574a2] | 1046 | |
---|
| 1047 | void postvisit( const ast::VarArgsType * ) {} |
---|
| 1048 | |
---|
| 1049 | void postvisit( const ast::ZeroType * zero ) { |
---|
| 1050 | if ( ! widen.first ) return; |
---|
[fc134a48] | 1051 | if ( dynamic_cast< const ast::BasicType * >( type2 ) |
---|
| 1052 | || dynamic_cast< const ast::PointerType * >( type2 ) ) { |
---|
[ee574a2] | 1053 | if ( widen.second || zero->qualifiers <= type2->qualifiers ) { |
---|
| 1054 | result = type2; |
---|
| 1055 | add_qualifiers( result, zero->qualifiers ); |
---|
| 1056 | } |
---|
| 1057 | } else if ( widen.second && dynamic_cast< const ast::OneType * >( type2 ) ) { |
---|
[ef5b828] | 1058 | result = new ast::BasicType{ |
---|
[ee574a2] | 1059 | ast::BasicType::SignedInt, zero->qualifiers | type2->qualifiers }; |
---|
[fc134a48] | 1060 | } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { |
---|
| 1061 | const ast::EnumDecl * enumDecl = enumInst->base; |
---|
| 1062 | if ( enumDecl->base ) { |
---|
| 1063 | if ( tryResolveWithTypedEnum( zero ) ) |
---|
| 1064 | add_qualifiers( result, zero->qualifiers ); |
---|
| 1065 | } else { |
---|
| 1066 | if ( widen.second || zero->qualifiers <= type2->qualifiers ) { |
---|
| 1067 | result = type2; |
---|
| 1068 | add_qualifiers( result, zero->qualifiers ); |
---|
| 1069 | } |
---|
| 1070 | } |
---|
[ee574a2] | 1071 | } |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | void postvisit( const ast::OneType * one ) { |
---|
| 1075 | if ( ! widen.first ) return; |
---|
[fc134a48] | 1076 | if ( dynamic_cast< const ast::BasicType * >( type2 ) ) { |
---|
[ee574a2] | 1077 | if ( widen.second || one->qualifiers <= type2->qualifiers ) { |
---|
| 1078 | result = type2; |
---|
| 1079 | add_qualifiers( result, one->qualifiers ); |
---|
| 1080 | } |
---|
| 1081 | } else if ( widen.second && dynamic_cast< const ast::ZeroType * >( type2 ) ) { |
---|
[ef5b828] | 1082 | result = new ast::BasicType{ |
---|
[ee574a2] | 1083 | ast::BasicType::SignedInt, one->qualifiers | type2->qualifiers }; |
---|
[fc134a48] | 1084 | } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { |
---|
| 1085 | const ast::EnumDecl * enumBase = enumInst->base; |
---|
| 1086 | if ( enumBase->base ) { |
---|
| 1087 | if ( tryResolveWithTypedEnum( one )) |
---|
| 1088 | add_qualifiers( result, one->qualifiers ); |
---|
| 1089 | } else { |
---|
| 1090 | if ( widen.second || one->qualifiers <= type2->qualifiers ) { |
---|
| 1091 | result = type2; |
---|
| 1092 | add_qualifiers( result, one->qualifiers ); |
---|
| 1093 | } |
---|
| 1094 | } |
---|
[ee574a2] | 1095 | } |
---|
| 1096 | } |
---|
| 1097 | |
---|
| 1098 | }; |
---|
| 1099 | |
---|
[0d070ca] | 1100 | // size_t CommonType_new::traceId = Stats::Heap::new_stacktrace_id("CommonType_new"); |
---|
[ee574a2] | 1101 | namespace { |
---|
[ef5b828] | 1102 | ast::ptr< ast::Type > handleReference( |
---|
| 1103 | const ast::ptr< ast::Type > & t1, const ast::ptr< ast::Type > & t2, WidenMode widen, |
---|
| 1104 | const ast::SymbolTable & symtab, ast::TypeEnvironment & env, |
---|
| 1105 | const ast::OpenVarSet & open |
---|
[ee574a2] | 1106 | ) { |
---|
| 1107 | ast::ptr<ast::Type> common; |
---|
| 1108 | ast::AssertionSet have, need; |
---|
| 1109 | ast::OpenVarSet newOpen{ open }; |
---|
| 1110 | |
---|
| 1111 | // need unify to bind type variables |
---|
| 1112 | if ( unify( t1, t2, env, have, need, newOpen, symtab, common ) ) { |
---|
| 1113 | ast::CV::Qualifiers q1 = t1->qualifiers, q2 = t2->qualifiers; |
---|
| 1114 | PRINT( |
---|
| 1115 | std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl; |
---|
| 1116 | ) |
---|
| 1117 | if ( ( widen.first || q2 <= q1 ) && ( widen.second || q1 <= q2 ) ) { |
---|
| 1118 | PRINT( |
---|
| 1119 | std::cerr << "widen okay" << std::endl; |
---|
| 1120 | ) |
---|
| 1121 | add_qualifiers( common, q1 | q2 ); |
---|
| 1122 | return common; |
---|
| 1123 | } |
---|
| 1124 | } |
---|
| 1125 | |
---|
| 1126 | PRINT( |
---|
| 1127 | std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl; |
---|
| 1128 | ) |
---|
| 1129 | return { nullptr }; |
---|
| 1130 | } |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | ast::ptr< ast::Type > commonType( |
---|
[ef5b828] | 1134 | const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, |
---|
[ef1da0e2] | 1135 | ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, |
---|
| 1136 | const ast::OpenVarSet & open, WidenMode widen, const ast::SymbolTable & symtab |
---|
[ee574a2] | 1137 | ) { |
---|
| 1138 | unsigned depth1 = type1->referenceDepth(); |
---|
| 1139 | unsigned depth2 = type2->referenceDepth(); |
---|
| 1140 | |
---|
| 1141 | if ( depth1 != depth2 ) { // implies depth1 > 0 || depth2 > 0 |
---|
| 1142 | PRINT( |
---|
| 1143 | std::cerr << "reference depth diff: " << (depth1-depth2) << std::endl; |
---|
| 1144 | ) |
---|
| 1145 | ast::ptr< ast::Type > result; |
---|
| 1146 | const ast::ReferenceType * ref1 = type1.as< ast::ReferenceType >(); |
---|
[b604426] | 1147 | const ast::ReferenceType * ref2 = type2.as< ast::ReferenceType >(); |
---|
[ef5b828] | 1148 | |
---|
[ee574a2] | 1149 | if ( depth1 > depth2 ) { |
---|
| 1150 | assert( ref1 ); |
---|
| 1151 | result = handleReference( ref1->base, type2, widen, symtab, env, open ); |
---|
| 1152 | } else { // implies depth1 < depth2 |
---|
| 1153 | assert( ref2 ); |
---|
| 1154 | result = handleReference( type1, ref2->base, widen, symtab, env, open ); |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | if ( result && ref1 ) { |
---|
| 1158 | // formal is reference, so result should be reference |
---|
| 1159 | PRINT( |
---|
| 1160 | std::cerr << "formal is reference; result should be reference" << std::endl; |
---|
| 1161 | ) |
---|
| 1162 | result = new ast::ReferenceType{ result, ref1->qualifiers }; |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | PRINT( |
---|
| 1166 | std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is " |
---|
| 1167 | "[" << result << "]" << std::endl; |
---|
| 1168 | ) |
---|
| 1169 | return result; |
---|
| 1170 | } |
---|
| 1171 | // otherwise both are reference types of the same depth and this is handled by the visitor |
---|
[ef1da0e2] | 1172 | ast::Pass<CommonType_new> visitor{ type2, widen, symtab, env, open, need, have }; |
---|
[ee574a2] | 1173 | type1->accept( visitor ); |
---|
[7ff3e522] | 1174 | ast::ptr< ast::Type > result = visitor.core.result; |
---|
[ee574a2] | 1175 | |
---|
| 1176 | // handling for opaque type declarations (?) |
---|
| 1177 | if ( ! result && widen.second ) { |
---|
| 1178 | if ( const ast::TypeInstType * inst = type2.as< ast::TypeInstType >() ) { |
---|
| 1179 | if ( const ast::NamedTypeDecl * nt = symtab.lookupType( inst->name ) ) { |
---|
| 1180 | auto type = strict_dynamic_cast< const ast::TypeDecl * >( nt ); |
---|
| 1181 | if ( type->base ) { |
---|
| 1182 | ast::CV::Qualifiers q1 = type1->qualifiers, q2 = type2->qualifiers; |
---|
| 1183 | ast::OpenVarSet newOpen{ open }; |
---|
| 1184 | |
---|
[ef5b828] | 1185 | // force t{1,2} to be cloned if its qualifiers must be stripped, so that |
---|
| 1186 | // type1 and type->base are left unchanged; calling convention forces |
---|
[ee574a2] | 1187 | // {type1,type->base}->strong_ref >= 1 |
---|
| 1188 | ast::ptr<ast::Type> t1{ type1 }, t2{ type->base }; |
---|
| 1189 | reset_qualifiers( t1 ); |
---|
| 1190 | reset_qualifiers( t2, q1 ); |
---|
[ef5b828] | 1191 | |
---|
[ee574a2] | 1192 | if ( unifyExact( t1, t2, env, have, need, newOpen, noWiden(), symtab ) ) { |
---|
| 1193 | result = t1; |
---|
| 1194 | reset_qualifiers( result, q1 | q2 ); |
---|
| 1195 | } |
---|
| 1196 | } |
---|
| 1197 | } |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | |
---|
| 1201 | return result; |
---|
| 1202 | } |
---|
| 1203 | |
---|
[51b7345] | 1204 | } // namespace ResolvExpr |
---|
[a32b204] | 1205 | |
---|
| 1206 | // Local Variables: // |
---|
| 1207 | // tab-width: 4 // |
---|
| 1208 | // mode: c++ // |
---|
| 1209 | // compile-command: "make install" // |
---|
| 1210 | // End: // |
---|