glsl: Apply implicit conversions to structure constructor parameters.
[mesa.git] / src / glsl / ir_reader.cpp
index 14bd2d62fd780937fa85276e8be8265a51273e86..e57e03c3078c0b50c3e1a4ae50cd1cce69fc89e0 100644 (file)
@@ -68,7 +68,7 @@ static ir_dereference *read_record_ref(_mesa_glsl_parse_state *, s_list *);
 
 void
 _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions,
-                  const char *src)
+                  const char *src, bool scan_for_protos)
 {
    s_expression *expr = s_expression::read_expression(state, src);
    if (expr == NULL) {
@@ -76,9 +76,11 @@ _mesa_glsl_read_ir(_mesa_glsl_parse_state *state, exec_list *instructions,
       return;
    }
    
-   scan_for_prototypes(state, instructions, expr);
-   if (state->error)
-      return;
+   if (scan_for_protos) {
+      scan_for_prototypes(state, instructions, expr);
+      if (state->error)
+        return;
+   }
 
    read_instructions(state, instructions, expr, NULL);
    talloc_free(expr);
@@ -207,6 +209,7 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body)
    ir_function *f = st->symbols->get_function(name->value());
    if (f == NULL) {
       f = new(ctx) ir_function(name->value());
+      f->is_builtin = true;
       added = st->symbols->add_function(f->name, f);
       assert(added);
    }
@@ -276,7 +279,11 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list,
    }
 
    ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);
-   if (sig != NULL) {
+   if (sig == NULL && skip_body) {
+      /* If scanning for prototypes, generate a new signature. */
+      sig = new(ctx) ir_function_signature(return_type);
+      f->add_signature(sig);
+   } else if (sig != NULL) {
       const char *badvar = sig->qualifiers_match(&hir_parameters);
       if (badvar != NULL) {
         ir_read_error(st, list, "function `%s' parameter `%s' qualifiers "
@@ -290,14 +297,15 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list,
         return;
       }
    } else {
-      sig = new(ctx) ir_function_signature(return_type);
-      sig->is_built_in = true;
-      f->add_signature(sig);
+      /* No prototype for this body exists - skip it. */
+      st->symbols->pop_scope();
+      return;
    }
+   assert(sig != NULL);
 
    sig->replace_parameters(&hir_parameters);
 
-   if (!skip_body) {
+   if (!skip_body && !body_list->subexpressions.is_empty()) {
       if (sig->is_defined) {
         ir_read_error(st, list, "function %s redefined", f->name);
         return;
@@ -795,7 +803,7 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list)
 
    const glsl_type *const base_type = type->get_base_type();
 
-   ir_constant_data data;
+   ir_constant_data data = { { 0 } };
 
    // Read in list of values (at most 16).
    int k = 0;