<div dir="ltr">On 22 January 2013 00:51, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
This will soon also be used for processing interface block fields.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
---<br>
 src/glsl/ast_to_hir.cpp | 42 +++++++++++++++++++++++++++++-------------<br>
 1 file changed, 29 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp<br>
index c432369..bce3488 100644<br>
--- a/src/glsl/ast_to_hir.cpp<br>
+++ b/src/glsl/ast_to_hir.cpp<br>
@@ -4014,35 +4014,36 @@ ast_type_specifier::hir(exec_list *instructions,<br>
 }<br>
<br>
<br>
-ir_rvalue *<br>
-ast_struct_specifier::hir(exec_list *instructions,<br>
-                         struct _mesa_glsl_parse_state *state)<br>
+unsigned<br>
+ast_process_structure_or_interface_block(exec_list *instructions,<br>
+                                        struct _mesa_glsl_parse_state *state,<br>
+                                        exec_list *declarations,<br>
+                                        YYLTYPE &loc,<br>
+                                        glsl_struct_field **fields_ret)<br></blockquote><div><br></div><div>The contract with the caller isn't obvious to me from this function declaration.  Can we have a short comment above the function saying that the return value is the number of fields and that *fields_ret receives a pointer to a newly allocated array with that size?<br>
<br></div><div>With that change, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

 {<br>
    unsigned decl_count = 0;<br>
<br>
-   /* Make an initial pass over the list of structure fields to determine how<br>
+   /* Make an initial pass over the list of fields to determine how<br>
     * many there are.  Each element in this list is an ast_declarator_list.<br>
     * This means that we actually need to count the number of elements in the<br>
     * 'declarations' list in each of the elements.<br>
     */<br>
-   foreach_list_typed (ast_declarator_list, decl_list, link,<br>
-                      &this->declarations) {<br>
+   foreach_list_typed (ast_declarator_list, decl_list, link, declarations) {<br>
       foreach_list_const (decl_ptr, & decl_list->declarations) {<br>
         decl_count++;<br>
       }<br>
    }<br>
<br>
-   /* Allocate storage for the structure fields and process the field<br>
+   /* Allocate storage for the fields and process the field<br>
     * declarations.  As the declarations are processed, try to also convert<br>
     * the types to HIR.  This ensures that structure definitions embedded in<br>
-    * other structure definitions are processed.<br>
+    * other structure definitions or in interface blocks are processed.<br>
     */<br>
    glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field,<br>
                                                  decl_count);<br>
<br>
    unsigned i = 0;<br>
-   foreach_list_typed (ast_declarator_list, decl_list, link,<br>
-                      &this->declarations) {<br>
+   foreach_list_typed (ast_declarator_list, decl_list, link, declarations) {<br>
       const char *type_name;<br>
<br>
       decl_list->type->specifier->hir(instructions, state);<br>
@@ -4051,7 +4052,6 @@ ast_struct_specifier::hir(exec_list *instructions,<br>
        * embedded structure definitions have been removed from the language.<br>
        */<br>
       if (state->es_shader && decl_list->type->specifier->structure != NULL) {<br>
-        YYLTYPE loc = this->get_location();<br>
         _mesa_glsl_error(&loc, state, "Embedded structure definitions are "<br>
                          "not allowed in GLSL ES 1.00.");<br>
       }<br>
@@ -4063,7 +4063,6 @@ ast_struct_specifier::hir(exec_list *instructions,<br>
                          &decl_list->declarations) {<br>
         const struct glsl_type *field_type = decl_type;<br>
         if (decl->is_array) {<br>
-           YYLTYPE loc = decl->get_location();<br>
            field_type = process_array_type(&loc, decl_type, decl->array_size,<br>
                                            state);<br>
         }<br>
@@ -4076,10 +4075,27 @@ ast_struct_specifier::hir(exec_list *instructions,<br>
<br>
    assert(i == decl_count);<br>
<br>
+   *fields_ret = fields;<br>
+   return decl_count;<br>
+}<br>
+<br>
+<br>
+ir_rvalue *<br>
+ast_struct_specifier::hir(exec_list *instructions,<br>
+                         struct _mesa_glsl_parse_state *state)<br>
+{<br>
+   YYLTYPE loc = this->get_location();<br>
+   glsl_struct_field *fields;<br>
+   unsigned decl_count =<br>
+      ast_process_structure_or_interface_block(instructions,<br>
+                                              state,<br>
+                                              &this->declarations,<br>
+                                              loc,<br>
+                                              &fields);<br>
+<br>
    const glsl_type *t =<br>
       glsl_type::get_record_instance(fields, decl_count, this->name);<br>
<br>
-   YYLTYPE loc = this->get_location();<br>
    if (!state->symbols->add_type(name, t)) {<br>
       _mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);<br>
    } else {<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.11.7<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>