glsl: initialise killed_all field.
[mesa.git] / src / glsl / glsl_parser.yy
index 5ab4b630bc6fbd7e94415a613c9b08f546233495..407dbbeebccce72d5102b38cc7c32a1a9d9352df 100644 (file)
@@ -29,6 +29,7 @@
 #include "ast.h"
 #include "glsl_parser_extras.h"
 #include "glsl_types.h"
+#include "main/context.h"
 
 #define YYLEX_PARAM state->scanner
 
@@ -100,9 +101,13 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %token MAT4X2 MAT4X3 MAT4X4
 %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
 %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
-%token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
-%token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
-%token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
+%token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
+%token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
+%token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
+%token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
+%token USAMPLER2DARRAY USAMPLERCUBEARRAY
+%token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
+%token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
 %token SAMPLEREXTERNALOES
 %token STRUCT VOID_TOK WHILE
 %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
@@ -130,12 +135,12 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
 %token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
 %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
-%token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
+%token SAMPLER3DRECT
 %token SIZEOF CAST NAMESPACE USING
 
 %token ERROR_TOK
 
-%token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
+%token COMMON PARTITION ACTIVE FILTER
 %token  IMAGE1D  IMAGE2D  IMAGE3D  IMAGECUBE  IMAGE1DARRAY  IMAGE2DARRAY
 %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
 %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
@@ -153,10 +158,11 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %type <type_qualifier> interpolation_qualifier
 %type <type_qualifier> layout_qualifier
 %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
+%type <type_qualifier> uniform_block_layout_qualifier
 %type <type_specifier> type_specifier
 %type <type_specifier> type_specifier_no_prec
 %type <type_specifier> type_specifier_nonarray
-%type <n> basic_type_specifier_nonarray
+%type <identifier> basic_type_specifier_nonarray
 %type <fully_specified_type> fully_specified_type
 %type <function> function_prototype
 %type <function> function_header
@@ -211,11 +217,14 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %type <node> declaration
 %type <node> declaration_statement
 %type <node> jump_statement
+%type <node> uniform_block
 %type <struct_specifier> struct_specifier
-%type <node> struct_declaration_list
+%type <declarator_list> struct_declaration_list
 %type <declarator_list> struct_declaration
 %type <declaration> struct_declarator
 %type <declaration> struct_declarator_list
+%type <declarator_list> member_list
+%type <declarator_list> member_declaration
 %type <node> selection_statement
 %type <selection_rest_statement> selection_rest_statement
 %type <node> switch_statement
@@ -229,6 +238,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
 %type <node> conditionopt
 %type <node> for_init_statement
 %type <for_rest_statement> for_rest_statement
+%type <n> integer_constant
 %%
 
 translation_unit: 
@@ -253,19 +263,25 @@ version_statement:
           switch ($2) {
           case 100:
              state->es_shader = true;
-             supported = state->Const.GLSL_100ES;
+             supported = state->ctx->API == API_OPENGLES2 ||
+                         state->ctx->Extensions.ARB_ES2_compatibility;
              break;
           case 110:
-             supported = state->Const.GLSL_110;
-             break;
           case 120:
-             supported = state->Const.GLSL_120;
-             break;
+             /* FINISHME: Once the OpenGL 3.0 'forward compatible' context or
+              * the OpenGL 3.2 Core context is supported, this logic will need
+              * change.  Older versions of GLSL are no longer supported
+              * outside the compatibility contexts of 3.x.
+              */
           case 130:
-             supported = state->Const.GLSL_130;
-             break;
           case 140:
-             supported = state->Const.GLSL_140;
+          case 150:
+          case 330:
+          case 400:
+          case 410:
+          case 420:
+             supported = _mesa_is_desktop_gl(state->ctx) &&
+                         ((unsigned) $2) <= state->ctx->Const.GLSLVersion;
              break;
           default:
              supported = false;
@@ -285,6 +301,10 @@ version_statement:
                               state->version_string,
                               state->supported_version_string);
           }
+
+          if (state->language_version >= 140) {
+             state->ARB_uniform_buffer_object_enable = true;
+          }
        }
        ;
 
@@ -295,7 +315,7 @@ pragma_statement:
        | PRAGMA_OPTIMIZE_OFF EOL
        | PRAGMA_INVARIANT_ALL EOL
        {
-          if (state->language_version < 120) {
+          if (state->language_version == 110) {
              _mesa_glsl_warning(& @1, state,
                                 "pragma `invariant(all)' not supported in %s",
                                 state->version_string);
@@ -798,6 +818,10 @@ declaration:
           $3->is_precision_statement = true;
           $$ = $3;
        }
+       | uniform_block
+       {
+          $$ = $1;
+       }
        ;
 
 function_prototype:
@@ -1092,40 +1116,31 @@ layout_qualifier_id_list:
        layout_qualifier_id
        | layout_qualifier_id_list ',' layout_qualifier_id
        {
-          if (($1.flags.i & $3.flags.i) != 0) {
-             _mesa_glsl_error(& @3, state,
-                              "duplicate layout qualifiers used\n");
+          $$ = $1;
+          if (!$$.merge_qualifier(& @3, state, $3)) {
              YYERROR;
           }
-
-          $$.flags.i = $1.flags.i | $3.flags.i;
-
-          if ($1.flags.q.explicit_location)
-             $$.location = $1.location;
-
-          if ($3.flags.q.explicit_location)
-             $$.location = $3.location;
        }
        ;
 
+integer_constant:
+       INTCONSTANT { $$ = $1; }
+       | UINTCONSTANT { $$ = $1; }
+
 layout_qualifier_id:
        any_identifier
        {
-          bool got_one = false;
-
           memset(& $$, 0, sizeof($$));
 
           /* Layout qualifiers for ARB_fragment_coord_conventions. */
-          if (!got_one && state->ARB_fragment_coord_conventions_enable) {
+          if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
              if (strcmp($1, "origin_upper_left") == 0) {
-                got_one = true;
                 $$.flags.q.origin_upper_left = 1;
              } else if (strcmp($1, "pixel_center_integer") == 0) {
-                got_one = true;
                 $$.flags.q.pixel_center_integer = 1;
              }
 
-             if (got_one && state->ARB_fragment_coord_conventions_warn) {
+             if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
                 _mesa_glsl_warning(& @1, state,
                                    "GL_ARB_fragment_coord_conventions layout "
                                    "identifier `%s' used\n", $1);
@@ -1133,45 +1148,56 @@ layout_qualifier_id:
           }
 
           /* Layout qualifiers for AMD/ARB_conservative_depth. */
-          if (!got_one &&
+          if (!$$.flags.i &&
               (state->AMD_conservative_depth_enable ||
                state->ARB_conservative_depth_enable)) {
              if (strcmp($1, "depth_any") == 0) {
-                got_one = true;
                 $$.flags.q.depth_any = 1;
              } else if (strcmp($1, "depth_greater") == 0) {
-                got_one = true;
                 $$.flags.q.depth_greater = 1;
              } else if (strcmp($1, "depth_less") == 0) {
-                got_one = true;
                 $$.flags.q.depth_less = 1;
              } else if (strcmp($1, "depth_unchanged") == 0) {
-                got_one = true;
                 $$.flags.q.depth_unchanged = 1;
              }
        
-             if (got_one && state->AMD_conservative_depth_warn) {
+             if ($$.flags.i && state->AMD_conservative_depth_warn) {
                 _mesa_glsl_warning(& @1, state,
                                    "GL_AMD_conservative_depth "
                                    "layout qualifier `%s' is used\n", $1);
              }
-             if (got_one && state->ARB_conservative_depth_warn) {
+             if ($$.flags.i && state->ARB_conservative_depth_warn) {
                 _mesa_glsl_warning(& @1, state,
                                    "GL_ARB_conservative_depth "
                                    "layout qualifier `%s' is used\n", $1);
              }
           }
 
-          if (!got_one) {
+          /* See also uniform_block_layout_qualifier. */
+          if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
+             if (strcmp($1, "std140") == 0) {
+                $$.flags.q.std140 = 1;
+             } else if (strcmp($1, "shared") == 0) {
+                $$.flags.q.shared = 1;
+             } else if (strcmp($1, "column_major") == 0) {
+                $$.flags.q.column_major = 1;
+             }
+
+             if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
+                _mesa_glsl_warning(& @1, state,
+                                   "#version 140 / GL_ARB_uniform_buffer_object "
+                                   "layout qualifier `%s' is used\n", $1);
+             }
+          }
+
+          if (!$$.flags.i) {
              _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
                               "`%s'\n", $1);
              YYERROR;
           }
        }
-       | any_identifier '=' INTCONSTANT
+       | any_identifier '=' integer_constant
        {
-          bool got_one = false;
-
           memset(& $$, 0, sizeof($$));
 
           if (state->ARB_explicit_attrib_location_enable) {
@@ -1179,8 +1205,6 @@ layout_qualifier_id:
               * FINISHME: GLSL 1.30 (or later) are supported.
               */
              if (strcmp("location", $1) == 0) {
-                got_one = true;
-
                 $$.flags.q.explicit_location = 1;
 
                 if ($3 >= 0) {
@@ -1191,12 +1215,24 @@ layout_qualifier_id:
                    YYERROR;
                 }
              }
+
+             if (strcmp("index", $1) == 0) {
+                $$.flags.q.explicit_index = 1;
+
+                if ($3 >= 0) {
+                   $$.index = $3;
+                } else {
+                   _mesa_glsl_error(& @3, state,
+                                    "invalid index %d specified\n", $3);
+                    YYERROR;
+                 }
+              }
           }
 
           /* If the identifier didn't match any known layout identifiers,
            * emit an error.
            */
-          if (!got_one) {
+          if (!$$.flags.i) {
              _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
                               "`%s'\n", $1);
              YYERROR;
@@ -1206,6 +1242,38 @@ layout_qualifier_id:
                                 "identifier `%s' used\n", $1);
           }
        }
+       | uniform_block_layout_qualifier
+       {
+          $$ = $1;
+          /* Layout qualifiers for ARB_uniform_buffer_object. */
+          if (!state->ARB_uniform_buffer_object_enable) {
+             _mesa_glsl_error(& @1, state,
+                              "#version 140 / GL_ARB_uniform_buffer_object "
+                              "layout qualifier `%s' is used\n", $1);
+          } else if (state->ARB_uniform_buffer_object_warn) {
+             _mesa_glsl_warning(& @1, state,
+                                "#version 140 / GL_ARB_uniform_buffer_object "
+                                "layout qualifier `%s' is used\n", $1);
+          }
+       }
+       ;
+
+/* This is a separate language rule because we parse these as tokens
+ * (due to them being reserved keywords) instead of identifiers like
+ * most qualifiers.  See the any_identifier path of
+ * layout_qualifier_id for the others.
+ */
+uniform_block_layout_qualifier:
+       ROW_MAJOR
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.flags.q.row_major = 1;
+       }
+       | PACKED_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.flags.q.packed = 1;
+       }
        ;
 
 interpolation_qualifier:
@@ -1365,58 +1433,67 @@ type_specifier_nonarray:
        ;
 
 basic_type_specifier_nonarray:
-       VOID_TOK                { $$ = ast_void; }
-       | FLOAT_TOK             { $$ = ast_float; }
-       | INT_TOK               { $$ = ast_int; }
-       | UINT_TOK              { $$ = ast_uint; }
-       | BOOL_TOK              { $$ = ast_bool; }
-       | VEC2                  { $$ = ast_vec2; }
-       | VEC3                  { $$ = ast_vec3; }
-       | VEC4                  { $$ = ast_vec4; }
-       | BVEC2                 { $$ = ast_bvec2; }
-       | BVEC3                 { $$ = ast_bvec3; }
-       | BVEC4                 { $$ = ast_bvec4; }
-       | IVEC2                 { $$ = ast_ivec2; }
-       | IVEC3                 { $$ = ast_ivec3; }
-       | IVEC4                 { $$ = ast_ivec4; }
-       | UVEC2                 { $$ = ast_uvec2; }
-       | UVEC3                 { $$ = ast_uvec3; }
-       | UVEC4                 { $$ = ast_uvec4; }
-       | MAT2X2                { $$ = ast_mat2; }
-       | MAT2X3                { $$ = ast_mat2x3; }
-       | MAT2X4                { $$ = ast_mat2x4; }
-       | MAT3X2                { $$ = ast_mat3x2; }
-       | MAT3X3                { $$ = ast_mat3; }
-       | MAT3X4                { $$ = ast_mat3x4; }
-       | MAT4X2                { $$ = ast_mat4x2; }
-       | MAT4X3                { $$ = ast_mat4x3; }
-       | MAT4X4                { $$ = ast_mat4; }
-       | SAMPLER1D             { $$ = ast_sampler1d; }
-       | SAMPLER2D             { $$ = ast_sampler2d; }
-       | SAMPLER2DRECT         { $$ = ast_sampler2drect; }
-       | SAMPLER3D             { $$ = ast_sampler3d; }
-       | SAMPLERCUBE           { $$ = ast_samplercube; }
-       | SAMPLEREXTERNALOES    { $$ = ast_samplerexternaloes; }
-       | SAMPLER1DSHADOW       { $$ = ast_sampler1dshadow; }
-       | SAMPLER2DSHADOW       { $$ = ast_sampler2dshadow; }
-       | SAMPLER2DRECTSHADOW   { $$ = ast_sampler2drectshadow; }
-       | SAMPLERCUBESHADOW     { $$ = ast_samplercubeshadow; }
-       | SAMPLER1DARRAY        { $$ = ast_sampler1darray; }
-       | SAMPLER2DARRAY        { $$ = ast_sampler2darray; }
-       | SAMPLER1DARRAYSHADOW  { $$ = ast_sampler1darrayshadow; }
-       | SAMPLER2DARRAYSHADOW  { $$ = ast_sampler2darrayshadow; }
-       | ISAMPLER1D            { $$ = ast_isampler1d; }
-       | ISAMPLER2D            { $$ = ast_isampler2d; }
-       | ISAMPLER3D            { $$ = ast_isampler3d; }
-       | ISAMPLERCUBE          { $$ = ast_isamplercube; }
-       | ISAMPLER1DARRAY       { $$ = ast_isampler1darray; }
-       | ISAMPLER2DARRAY       { $$ = ast_isampler2darray; }
-       | USAMPLER1D            { $$ = ast_usampler1d; }
-       | USAMPLER2D            { $$ = ast_usampler2d; }
-       | USAMPLER3D            { $$ = ast_usampler3d; }
-       | USAMPLERCUBE          { $$ = ast_usamplercube; }
-       | USAMPLER1DARRAY       { $$ = ast_usampler1darray; }
-       | USAMPLER2DARRAY       { $$ = ast_usampler2darray; }
+       VOID_TOK                { $$ = "void"; }
+       | FLOAT_TOK             { $$ = "float"; }
+       | INT_TOK               { $$ = "int"; }
+       | UINT_TOK              { $$ = "uint"; }
+       | BOOL_TOK              { $$ = "bool"; }
+       | VEC2                  { $$ = "vec2"; }
+       | VEC3                  { $$ = "vec3"; }
+       | VEC4                  { $$ = "vec4"; }
+       | BVEC2                 { $$ = "bvec2"; }
+       | BVEC3                 { $$ = "bvec3"; }
+       | BVEC4                 { $$ = "bvec4"; }
+       | IVEC2                 { $$ = "ivec2"; }
+       | IVEC3                 { $$ = "ivec3"; }
+       | IVEC4                 { $$ = "ivec4"; }
+       | UVEC2                 { $$ = "uvec2"; }
+       | UVEC3                 { $$ = "uvec3"; }
+       | UVEC4                 { $$ = "uvec4"; }
+       | MAT2X2                { $$ = "mat2"; }
+       | MAT2X3                { $$ = "mat2x3"; }
+       | MAT2X4                { $$ = "mat2x4"; }
+       | MAT3X2                { $$ = "mat3x2"; }
+       | MAT3X3                { $$ = "mat3"; }
+       | MAT3X4                { $$ = "mat3x4"; }
+       | MAT4X2                { $$ = "mat4x2"; }
+       | MAT4X3                { $$ = "mat4x3"; }
+       | MAT4X4                { $$ = "mat4"; }
+       | SAMPLER1D             { $$ = "sampler1D"; }
+       | SAMPLER2D             { $$ = "sampler2D"; }
+       | SAMPLER2DRECT         { $$ = "sampler2DRect"; }
+       | SAMPLER3D             { $$ = "sampler3D"; }
+       | SAMPLERCUBE           { $$ = "samplerCube"; }
+       | SAMPLEREXTERNALOES    { $$ = "samplerExternalOES"; }
+       | SAMPLER1DSHADOW       { $$ = "sampler1DShadow"; }
+       | SAMPLER2DSHADOW       { $$ = "sampler2DShadow"; }
+       | SAMPLER2DRECTSHADOW   { $$ = "sampler2DRectShadow"; }
+       | SAMPLERCUBESHADOW     { $$ = "samplerCubeShadow"; }
+       | SAMPLER1DARRAY        { $$ = "sampler1DArray"; }
+       | SAMPLER2DARRAY        { $$ = "sampler2DArray"; }
+       | SAMPLER1DARRAYSHADOW  { $$ = "sampler1DArrayShadow"; }
+       | SAMPLER2DARRAYSHADOW  { $$ = "sampler2DArrayShadow"; }
+       | SAMPLERBUFFER         { $$ = "samplerBuffer"; }
+       | SAMPLERCUBEARRAY      { $$ = "samplerCubeArray"; }
+       | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
+       | ISAMPLER1D            { $$ = "isampler1D"; }
+       | ISAMPLER2D            { $$ = "isampler2D"; }
+       | ISAMPLER2DRECT        { $$ = "isampler2DRect"; }
+       | ISAMPLER3D            { $$ = "isampler3D"; }
+       | ISAMPLERCUBE          { $$ = "isamplerCube"; }
+       | ISAMPLER1DARRAY       { $$ = "isampler1DArray"; }
+       | ISAMPLER2DARRAY       { $$ = "isampler2DArray"; }
+       | ISAMPLERBUFFER        { $$ = "isamplerBuffer"; }
+       | ISAMPLERCUBEARRAY     { $$ = "isamplerCubeArray"; }
+       | USAMPLER1D            { $$ = "usampler1D"; }
+       | USAMPLER2D            { $$ = "usampler2D"; }
+       | USAMPLER2DRECT        { $$ = "usampler2DRect"; }
+       | USAMPLER3D            { $$ = "usampler3D"; }
+       | USAMPLERCUBE          { $$ = "usamplerCube"; }
+       | USAMPLER1DARRAY       { $$ = "usampler1DArray"; }
+       | USAMPLER2DARRAY       { $$ = "usampler2DArray"; }
+       | USAMPLERBUFFER        { $$ = "usamplerBuffer"; }
+       | USAMPLERCUBEARRAY     { $$ = "usamplerCubeArray"; }
        ;
 
 precision_qualifier:
@@ -1471,12 +1548,12 @@ struct_specifier:
 struct_declaration_list:
        struct_declaration
        {
-          $$ = (ast_node *) $1;
+          $$ = $1;
           $1->link.self_link();
        }
        | struct_declaration_list struct_declaration
        {
-          $$ = (ast_node *) $1;
+          $$ = $1;
           $$->link.insert_before(& $2->link);
        }
        ;
@@ -1840,6 +1917,7 @@ external_declaration:
        function_definition     { $$ = $1; }
        | declaration           { $$ = $1; }
        | pragma_statement      { $$ = NULL; }
+       | layout_defaults       { $$ = NULL; }
        ;
 
 function_definition:
@@ -1854,3 +1932,103 @@ function_definition:
           state->symbols->pop_scope();
        }
        ;
+
+/* layout_qualifieropt is packed into this rule */
+uniform_block:
+       UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
+       {
+          void *ctx = state;
+          $$ = new(ctx) ast_uniform_block(*state->default_uniform_qualifier,
+                                          $2, $4);
+
+          if (!state->ARB_uniform_buffer_object_enable) {
+             _mesa_glsl_error(& @1, state,
+                              "#version 140 / GL_ARB_uniform_buffer_object "
+                              "required for defining uniform blocks\n");
+          } else if (state->ARB_uniform_buffer_object_warn) {
+             _mesa_glsl_warning(& @1, state,
+                                "#version 140 / GL_ARB_uniform_buffer_object "
+                                "required for defining uniform blocks\n");
+          }
+       }
+       | layout_qualifier UNIFORM NEW_IDENTIFIER '{' member_list '}' ';'
+       {
+          void *ctx = state;
+
+          ast_type_qualifier qual = *state->default_uniform_qualifier;
+          if (!qual.merge_qualifier(& @1, state, $1)) {
+             YYERROR;
+          }
+          $$ = new(ctx) ast_uniform_block(qual, $3, $5);
+
+          if (!state->ARB_uniform_buffer_object_enable) {
+             _mesa_glsl_error(& @1, state,
+                              "#version 140 / GL_ARB_uniform_buffer_object "
+                              "required for defining uniform blocks\n");
+          } else if (state->ARB_uniform_buffer_object_warn) {
+             _mesa_glsl_warning(& @1, state,
+                                "#version 140 / GL_ARB_uniform_buffer_object "
+                                "required for defining uniform blocks\n");
+          }
+       }
+       ;
+
+member_list:
+       member_declaration
+       {
+          $$ = $1;
+          $1->link.self_link();
+       }
+       | member_declaration member_list
+       {
+          $$ = $1;
+          $2->link.insert_before(& $$->link);
+       }
+       ;
+
+/* Specifying "uniform" inside of a uniform block is redundant. */
+uniformopt:
+       /* nothing */
+       | UNIFORM
+       ;
+
+member_declaration:
+       layout_qualifier uniformopt type_specifier struct_declarator_list ';'
+       {
+          void *ctx = state;
+          ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
+          type->set_location(yylloc);
+
+          type->qualifier = $1;
+          type->qualifier.flags.q.uniform = true;
+          type->specifier = $3;
+          $$ = new(ctx) ast_declarator_list(type);
+          $$->set_location(yylloc);
+          $$->ubo_qualifiers_valid = true;
+
+          $$->declarations.push_degenerate_list_at_head(& $4->link);
+       }
+       | uniformopt type_specifier struct_declarator_list ';'
+       {
+          void *ctx = state;
+          ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
+          type->set_location(yylloc);
+
+          type->qualifier.flags.q.uniform = true;
+          type->specifier = $2;
+          $$ = new(ctx) ast_declarator_list(type);
+          $$->set_location(yylloc);
+          $$->ubo_qualifiers_valid = true;
+
+          $$->declarations.push_degenerate_list_at_head(& $3->link);
+       }
+       ;
+
+layout_defaults:
+       layout_qualifier UNIFORM ';'
+       {
+          if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,
+                                                                 $1)) {
+             YYERROR;
+          }
+       }