+
+/**
+ * Perform automatic type and constant conversion of constructor parameters
+ *
+ * This implements the rules in the "Implicit Conversions" rules, not the
+ * "Conversion and Scalar Constructors".
+ *
+ * After attempting the implicit conversion, an attempt to convert into a
+ * constant valued expression is also done.
+ *
+ * The \c from \c ir_rvalue is converted "in place".
+ *
+ * \param from Operand that is being converted
+ * \param to Base type the operand will be converted to
+ * \param state GLSL compiler state
+ *
+ * \return
+ * If the attempt to convert into a constant expression succeeds, \c true is
+ * returned. Otherwise \c false is returned.
+ */
+static bool
+implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
+ struct _mesa_glsl_parse_state *state)
+{
+ ir_rvalue *result = from;
+
+ if (to != from->type->base_type) {
+ const glsl_type *desired_type =
+ glsl_type::get_instance(to,
+ from->type->vector_elements,
+ from->type->matrix_columns);
+
+ if (from->type->can_implicitly_convert_to(desired_type, state)) {
+ /* Even though convert_component() implements the constructor
+ * conversion rules (not the implicit conversion rules), its safe
+ * to use it here because we already checked that the implicit
+ * conversion is legal.
+ */
+ result = convert_component(from, desired_type);
+ }
+ }
+
+ ir_rvalue *const constant = result->constant_expression_value();
+
+ if (constant != NULL)
+ result = constant;
+
+ if (from != result) {
+ from->replace_with(result);
+ from = result;
+ }
+
+ return constant != NULL;
+}
+
+