| 301 | |
| 302 | |
| 303 | Symbol * |
| 304 | ASTNode::coerce (Symbol *sym, const TypeSpec &type, bool acceptfloat) |
| 305 | { |
| 306 | if (equivalent (sym->typespec(), type)) |
| 307 | return sym; // No coercion necessary |
| 308 | |
| 309 | if (type.is_closure()) |
| 310 | return sym; // No coercion necessary |
| 311 | |
| 312 | if (acceptfloat && sym->typespec().is_float()) |
| 313 | return sym; |
| 314 | |
| 315 | if (type.is_unsized_array() && sym->typespec().is_array() && |
| 316 | equivalent (sym->typespec().elementtype(), type.elementtype())) { |
| 317 | // coercion not necessary to pass known length array to |
| 318 | // array parameter of unspecified length. |
| 319 | return sym; |
| 320 | } |
| 321 | |
| 322 | if (sym->symtype() == SymTypeConst && sym->typespec().is_int() && |
| 323 | type.is_floatbased()) { |
| 324 | // It's not only the wrong type, it's a constant of the wrong |
| 325 | // type. We need a new constant of the right type. |
| 326 | ConstantSymbol *constsym = (ConstantSymbol *) sym; |
| 327 | sym = m_compiler->make_constant (constsym->floatval ()); |
| 328 | if (type.is_float() || acceptfloat) |
| 329 | return sym; |
| 330 | } |
| 331 | |
| 332 | Symbol *t = m_compiler->make_temporary (type); |
| 333 | emitcode ("assign", t, sym); |
| 334 | return t; |
| 335 | } |
| 336 | |
| 337 | |
| 338 |
nothing calls this directly
no test coverage detected