[Mesa-dev] [PATCH 3/7] glsl/parser: Move anonymous struct name handling to the parser

Ian Romanick idr at freedesktop.org
Tue Oct 17 18:14:06 UTC 2017


From: Ian Romanick <ian.d.romanick at intel.com>

There are two callers of the constructor, and they are right next to
each other.  Move the "#anon_struct" name handling to the parser so that
the conditional can be removed.

I've also deleted part of the comment (about the memory leak) because I
don't think it's quite accurate or relevant.

   text	   data	    bss	    dec	    hex	filename
8310399	 269336	 294072	8873807	 87674f	32-bit i965_dri.so before
8310339	 269336	 294072	8873747	 876713	32-bit i965_dri.so after
7845611	 346552	 420592	8612755	 836b93	64-bit i965_dri.so before
7845579	 346552	 420592	8612723	 836b73	64-bit i965_dri.so after

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/glsl_parser.yy         | 10 +++++++++-
 src/compiler/glsl/glsl_parser_extras.cpp | 15 ++-------------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index 3e555cf..58bbf6f 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -2384,7 +2384,15 @@ struct_specifier:
    | STRUCT '{' struct_declaration_list '}'
    {
       void *ctx = state->linalloc;
-      $$ = new(ctx) ast_struct_specifier(NULL, $3);
+
+      /* All anonymous structs have the same name. This simplifies matching of
+       * globals whose type is an unnamed struct.
+       *
+       * It also avoids a memory leak when the same shader is compiled over and
+       * over again.
+       */
+      $$ = new(ctx) ast_struct_specifier("#anon_struct", $3);
+
       $$->set_location_range(@2, @4);
    }
    ;
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index d6d6f3d..65f12f7 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1674,21 +1674,10 @@ ast_struct_specifier::print(void) const
 
 ast_struct_specifier::ast_struct_specifier(const char *identifier,
 					   ast_declarator_list *declarator_list)
+   : name(identifier), layout(NULL), declarations(), is_declaration(true),
+     type(NULL)
 {
-   if (identifier == NULL) {
-      /* All anonymous structs have the same name. This simplifies matching of
-       * globals whose type is an unnamed struct.
-       *
-       * It also avoids a memory leak when the same shader is compiled over and
-       * over again.
-       */
-      identifier = "#anon_struct";
-   }
-   name = identifier;
    this->declarations.push_degenerate_list_at_head(&declarator_list->link);
-   is_declaration = true;
-   layout = NULL;
-   type = NULL;
 }
 
 void ast_subroutine_list::print(void) const
-- 
2.9.5



More information about the mesa-dev mailing list