[glsl-in] Handle simple casts

This commit is contained in:
Pelle Johnsen
2020-11-16 08:08:35 +00:00
committed by Timo de Kort
parent 022b42c44b
commit 9041cd4b10

View File

@@ -244,10 +244,25 @@ pomelo! {
function_call ::= function_call_or_method(fc) {
match fc.kind {
FunctionCallKind::TypeConstructor(ty) => {
let h = extra.context.expressions.append(Expression::Compose {
ty,
components: fc.args.iter().map(|a| a.expression).collect(),
});
let h = if fc.args.len() == 1 {
let kind = match extra.module.types[ty].inner {
TypeInner::Scalar{kind, ..} => kind,
TypeInner::Vector{kind, ..} => kind,
_ => {
return Err(ErrorKind::SemanticError("Can only cast to scalar or vector"));
}
};
extra.context.expressions.append(Expression::As {
kind,
expr: fc.args[0].expression,
convert: true,
})
} else {
extra.context.expressions.append(Expression::Compose {
ty,
components: fc.args.iter().map(|a| a.expression).collect(),
})
};
ExpressionRule {
expression: h,
statements: fc.args.into_iter().map(|a| a.statements).flatten().collect(),