glsl: Separate code into process_record_constructor().
authorMatt Turner <mattst88@gmail.com>
Thu, 13 Jun 2013 19:05:21 +0000 (12:05 -0700)
committerMatt Turner <mattst88@gmail.com>
Fri, 12 Jul 2013 03:58:59 +0000 (20:58 -0700)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/ast_function.cpp

index bbc607ac4e3cd6130a7c7dd453ad96a672b16150..53bf2b1fff1f498401632b6497472b03fff119bf 100644 (file)
@@ -1260,6 +1260,63 @@ emit_inline_record_constructor(const glsl_type *type,
 }
 
 
+static ir_rvalue *
+process_record_constructor(exec_list *instructions,
+                           const glsl_type *constructor_type,
+                           YYLTYPE *loc, exec_list *parameters,
+                           struct _mesa_glsl_parse_state *state)
+{
+   void *ctx = state;
+   exec_list actual_parameters;
+
+   process_parameters(instructions, &actual_parameters,
+                      parameters, state);
+
+   exec_node *node = actual_parameters.head;
+   for (unsigned i = 0; i < constructor_type->length; i++) {
+      ir_rvalue *ir = (ir_rvalue *) node;
+
+      if (node->is_tail_sentinel()) {
+         _mesa_glsl_error(loc, state,
+                          "insufficient parameters to constructor for `%s'",
+                          constructor_type->name);
+         return ir_rvalue::error_value(ctx);
+      }
+
+      if (apply_implicit_conversion(constructor_type->fields.structure[i].type,
+                                 ir, state)) {
+         node->replace_with(ir);
+      } else {
+         _mesa_glsl_error(loc, state,
+                          "parameter type mismatch in constructor for `%s.%s' "
+                          "(%s vs %s)",
+                          constructor_type->name,
+                          constructor_type->fields.structure[i].name,
+                          ir->type->name,
+                          constructor_type->fields.structure[i].type->name);
+         return ir_rvalue::error_value(ctx);;
+      }
+
+      node = node->next;
+   }
+
+   if (!node->is_tail_sentinel()) {
+      _mesa_glsl_error(loc, state, "too many parameters in constructor "
+                                    "for `%s'", constructor_type->name);
+      return ir_rvalue::error_value(ctx);
+   }
+
+   ir_rvalue *const constant =
+      constant_record_constructor(constructor_type, &actual_parameters,
+                                  state);
+
+   return (constant != NULL)
+            ? constant
+            : emit_inline_record_constructor(constructor_type, instructions,
+                                             &actual_parameters, state);
+}
+
+
 ir_rvalue *
 ast_function_expression::hir(exec_list *instructions,
                             struct _mesa_glsl_parse_state *state)
@@ -1326,54 +1383,9 @@ ast_function_expression::hir(exec_list *instructions,
        * correct order.
        */
       if (constructor_type->is_record()) {
-        exec_list actual_parameters;
-
-        process_parameters(instructions, &actual_parameters,
-                           &this->expressions, state);
-
-        exec_node *node = actual_parameters.head;
-        for (unsigned i = 0; i < constructor_type->length; i++) {
-           ir_rvalue *ir = (ir_rvalue *) node;
-
-           if (node->is_tail_sentinel()) {
-              _mesa_glsl_error(&loc, state,
-                               "insufficient parameters to constructor "
-                               "for `%s'",
-                               constructor_type->name);
-              return ir_rvalue::error_value(ctx);
-           }
-
-           if (apply_implicit_conversion(constructor_type->fields.structure[i].type,
-                                         ir, state)) {
-              node->replace_with(ir);
-           } else {
-              _mesa_glsl_error(&loc, state,
-                               "parameter type mismatch in constructor "
-                               "for `%s.%s' (%s vs %s)",
-                               constructor_type->name,
-                               constructor_type->fields.structure[i].name,
-                               ir->type->name,
-                               constructor_type->fields.structure[i].type->name);
-              return ir_rvalue::error_value(ctx);;
-           }
-
-           node = node->next;
-        }
-
-        if (!node->is_tail_sentinel()) {
-           _mesa_glsl_error(&loc, state, "too many parameters in constructor "
-                            "for `%s'", constructor_type->name);
-           return ir_rvalue::error_value(ctx);
-        }
-
-        ir_rvalue *const constant =
-           constant_record_constructor(constructor_type, &actual_parameters,
-                                       state);
-
-        return (constant != NULL)
-           ? constant
-           : emit_inline_record_constructor(constructor_type, instructions,
-                                            &actual_parameters, state);
+         return process_record_constructor(instructions, constructor_type,
+                                           &loc, &this->expressions,
+                                           state);
       }
 
       if (!constructor_type->is_numeric() && !constructor_type->is_boolean())