MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / coerce

Method coerce

src/liboslcomp/codegen.cpp:303–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301
302
303Symbol *
304ASTNode::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

Callers

nothing calls this directly

Calls 12

is_closureMethod · 0.80
is_floatMethod · 0.80
is_unsized_arrayMethod · 0.80
is_arrayMethod · 0.80
elementtypeMethod · 0.80
symtypeMethod · 0.80
is_intMethod · 0.80
is_floatbasedMethod · 0.80
make_constantMethod · 0.80
make_temporaryMethod · 0.80
equivalentFunction · 0.50
floatvalMethod · 0.45

Tested by

no test coverage detected