glsl: Clear type_qualifier using memset
[mesa.git] / src / glsl / glsl_parser.ypp
index 4132495f403fbedfedf4af47848ade8e043f272d..be763ed9f03eb551139ec873b9a19f80cd9e517d 100644 (file)
 %}
 
 %pure-parser
-%locations
 %error-verbose
 
+%locations
+%initial-action {
+   @$.first_line = 1;
+   @$.first_column = 1;
+   @$.last_line = 1;
+   @$.last_column = 1;
+   @$.source = 0;
+}
+
 %lex-param   {void *scanner}
 %parse-param {struct _mesa_glsl_parse_state *state}
-%name-prefix "_mesa_glsl_"
 
 %union {
    int n;
       unsigned i;
    } type_qualifier;
 
-   struct ast_node *node;
-   struct ast_type_specifier *type_specifier;
-   struct ast_fully_specified_type *fully_specified_type;
-   struct ast_function *function;
-   struct ast_parameter_declarator *parameter_declarator;
-   struct ast_function_definition *function_definition;
-   struct ast_compound_statement *compound_statement;
-   struct ast_expression *expression;
-   struct ast_declarator_list *declarator_list;
-   struct ast_struct_specifier *struct_specifier;
-   struct ast_declaration *declaration;
+   ast_node *node;
+   ast_type_specifier *type_specifier;
+   ast_fully_specified_type *fully_specified_type;
+   ast_function *function;
+   ast_parameter_declarator *parameter_declarator;
+   ast_function_definition *function_definition;
+   ast_compound_statement *compound_statement;
+   ast_expression *expression;
+   ast_declarator_list *declarator_list;
+   ast_struct_specifier *struct_specifier;
+   ast_declaration *declaration;
 
    struct {
-      struct ast_node *cond;
-      struct ast_expression *rest;
+      ast_node *cond;
+      ast_expression *rest;
    } for_rest_statement;
+
+   struct {
+      ast_node *then_statement;
+      ast_node *else_statement;
+   } selection_rest_statement;
 }
 
-%token ATTRIBUTE CONST BOOL FLOAT INT UINT
+%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
 %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
 %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
-%token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
+%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
 %token NOPERSPECTIVE FLAT SMOOTH
 %token MAT2X2 MAT2X3 MAT2X4
 %token MAT3X2 MAT3X3 MAT3X4
@@ -83,7 +95,7 @@
 %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
 %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
 %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
-%token STRUCT VOID WHILE
+%token STRUCT VOID_TOK WHILE
 %token <identifier> IDENTIFIER
 %token <real> FLOATCONSTANT
 %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
 %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
 %token SUB_ASSIGN
 %token INVARIANT
-%token LOWP MEDIUMP HIGHP PRECISION
+%token LOWP MEDIUMP HIGHP SUPERP PRECISION
 
-%token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
+%token VERSION EXTENSION LINE COLON EOL INTERFACE OUTPUT
+%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
+%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
+%token LAYOUT_TOK
 
    /* Reserved words that are not actually used in the grammar.
     */
-%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
-%token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
-%token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
+%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
+%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 SIZEOF CAST NAMESPACE USING
 
+%token ERROR_TOK
+
+%token COMMON PARTITION ACTIVE SAMPLERBUFFER FILTER
+%token  IMAGE1D  IMAGE2D  IMAGE3D  IMAGECUBE  IMAGE1DARRAY  IMAGE2DARRAY
+%token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGECUBE IIMAGE1DARRAY IIMAGE2DARRAY
+%token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGECUBE UIMAGE1DARRAY UIMAGE2DARRAY
+%token IMAGE1DSHADOW IMAGE2DSHADOW IMAGEBUFFER IIMAGEBUFFER UIMAGEBUFFER
+%token ROW_MAJOR
+
 %type <identifier> variable_identifier
 %type <node> statement
 %type <node> statement_list
 %type <node> simple_statement
-%type <node> statement_matched
-%type <node> statement_unmatched
 %type <n> precision_qualifier
 %type <type_qualifier> type_qualifier
 %type <type_qualifier> storage_qualifier
 %type <type_qualifier> interpolation_qualifier
+%type <type_qualifier> layout_qualifier
+%type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
 %type <type_specifier> type_specifier
 %type <type_specifier> type_specifier_no_prec
 %type <type_specifier> type_specifier_nonarray
 %type <declarator_list> struct_declaration
 %type <declaration> struct_declarator
 %type <declaration> struct_declarator_list
-%type <node> selection_statement_matched
-%type <node> selection_statement_unmatched
+%type <node> selection_statement
+%type <selection_rest_statement> selection_rest_statement
 %type <node> iteration_statement
 %type <node> condition
 %type <node> conditionopt
@@ -194,13 +218,12 @@ translation_unit:
        ;
 
 version_statement:
-       /* blank - no #version specified */
-       {
-          state->language_version = 110;
-       }
+       /* blank - no #version specified: defaults are already set */
        | VERSION INTCONSTANT EOL
        {
           switch ($2) {
+          case 100:
+             state->es_shader = true;
           case 110:
           case 120:
           case 130:
@@ -215,6 +238,13 @@ version_statement:
        }
        ;
 
+pragma_statement:
+       PRAGMA_DEBUG_ON EOL
+       | PRAGMA_DEBUG_OFF EOL
+       | PRAGMA_OPTIMIZE_ON EOL
+       | PRAGMA_OPTIMIZE_OFF EOL
+       ;
+
 extension_statement_list:
 
        | extension_statement_list extension_statement
@@ -255,35 +285,35 @@ variable_identifier:
 primary_expression:
        variable_identifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.identifier = $1;
        }
        | INTCONSTANT
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.int_constant = $1;
        }
        | UINTCONSTANT
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.uint_constant = $1;
        }
        | FLOATCONSTANT
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.float_constant = $1;
        }
        | BOOLCONSTANT
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.bool_constant = $1;
@@ -298,36 +328,30 @@ postfix_expression:
        primary_expression
        | postfix_expression '[' integer_expression ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
           $$->set_location(yylloc);
        }
        | function_call
        {
-          /* Function call parameters used to be stored as a circular list in
-           * subexpressions[1].  They are now stored as a regular list in
-           * expressions.  This assertion validates that the old code was
-           * correctly converted.  It can eventually be removed.
-           */
-          assert($1->subexpressions[1] == NULL);
           $$ = $1;
        }
        | postfix_expression '.' IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
           $$->set_location(yylloc);
           $$->primary_expression.identifier = $3;
        }
        | postfix_expression INC_OP
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
           $$->set_location(yylloc);
        }
        | postfix_expression DEC_OP
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
           $$->set_location(yylloc);
        }
@@ -345,7 +369,7 @@ function_call_or_method:
        function_call_generic
        | postfix_expression '.' function_call_generic
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
           $$->set_location(yylloc);
        }
@@ -357,7 +381,7 @@ function_call_generic:
        ;
 
 function_call_header_no_parameters:
-       function_call_header VOID
+       function_call_header VOID_TOK
        | function_call_header
        ;
 
@@ -386,20 +410,20 @@ function_call_header:
 function_identifier:
        type_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_function_expression($1);
           $$->set_location(yylloc);
        }
        | IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_expression *callee = new(ctx) ast_expression($1);
           $$ = new(ctx) ast_function_expression(callee);
           $$->set_location(yylloc);
        }
        | FIELD_SELECTION
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_expression *callee = new(ctx) ast_expression($1);
           $$ = new(ctx) ast_function_expression(callee);
           $$->set_location(yylloc);
@@ -411,19 +435,19 @@ unary_expression:
        postfix_expression
        | INC_OP unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
           $$->set_location(yylloc);
        }
        | DEC_OP unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
           $$->set_location(yylloc);
        }
        | unary_operator unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
           $$->set_location(yylloc);
        }
@@ -441,19 +465,19 @@ multiplicative_expression:
        unary_expression
        | multiplicative_expression '*' unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
           $$->set_location(yylloc);
        }
        | multiplicative_expression '/' unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
           $$->set_location(yylloc);
        }
        | multiplicative_expression '%' unary_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
           $$->set_location(yylloc);
        }
@@ -463,13 +487,13 @@ additive_expression:
        multiplicative_expression
        | additive_expression '+' multiplicative_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
           $$->set_location(yylloc);
        }
        | additive_expression '-' multiplicative_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
           $$->set_location(yylloc);
        }
@@ -479,13 +503,13 @@ shift_expression:
        additive_expression
        | shift_expression LEFT_OP additive_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
           $$->set_location(yylloc);
        }
        | shift_expression RIGHT_OP additive_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
           $$->set_location(yylloc);
        }
@@ -495,25 +519,25 @@ relational_expression:
        shift_expression
        | relational_expression '<' shift_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
           $$->set_location(yylloc);
        }
        | relational_expression '>' shift_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
           $$->set_location(yylloc);
        }
        | relational_expression LE_OP shift_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
           $$->set_location(yylloc);
        }
        | relational_expression GE_OP shift_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
           $$->set_location(yylloc);
        }
@@ -523,13 +547,13 @@ equality_expression:
        relational_expression
        | equality_expression EQ_OP relational_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
           $$->set_location(yylloc);
        }
        | equality_expression NE_OP relational_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
           $$->set_location(yylloc);
        }
@@ -539,7 +563,7 @@ and_expression:
        equality_expression
        | and_expression '&' equality_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
           $$->set_location(yylloc);
        }
@@ -549,7 +573,7 @@ exclusive_or_expression:
        and_expression
        | exclusive_or_expression '^' and_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
           $$->set_location(yylloc);
        }
@@ -559,7 +583,7 @@ inclusive_or_expression:
        exclusive_or_expression
        | inclusive_or_expression '|' exclusive_or_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
           $$->set_location(yylloc);
        }
@@ -569,7 +593,7 @@ logical_and_expression:
        inclusive_or_expression
        | logical_and_expression AND_OP inclusive_or_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
           $$->set_location(yylloc);
        }
@@ -579,7 +603,7 @@ logical_xor_expression:
        logical_and_expression
        | logical_xor_expression XOR_OP logical_and_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
           $$->set_location(yylloc);
        }
@@ -589,7 +613,7 @@ logical_or_expression:
        logical_xor_expression
        | logical_or_expression OR_OP logical_xor_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
           $$->set_location(yylloc);
        }
@@ -599,7 +623,7 @@ conditional_expression:
        logical_or_expression
        | logical_or_expression '?' expression ':' assignment_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
           $$->set_location(yylloc);
        }
@@ -609,7 +633,7 @@ assignment_expression:
        conditional_expression
        | unary_expression assignment_operator assignment_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression($2, $1, $3, NULL);
           $$->set_location(yylloc);
        }
@@ -636,7 +660,7 @@ expression:
        }
        | expression ',' assignment_expression
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           if ($1->oper != ast_sequence) {
              $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
              $$->set_location(yylloc);
@@ -700,7 +724,7 @@ function_header_with_parameters:
 function_header:
        fully_specified_type IDENTIFIER '('
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_function();
           $$->set_location(yylloc);
           $$->return_type = $1;
@@ -711,7 +735,7 @@ function_header:
 parameter_declarator:
        type_specifier IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_parameter_declarator();
           $$->set_location(yylloc);
           $$->type = new(ctx) ast_fully_specified_type();
@@ -721,7 +745,7 @@ parameter_declarator:
        }
        | type_specifier IDENTIFIER '[' constant_expression ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_parameter_declarator();
           $$->set_location(yylloc);
           $$->type = new(ctx) ast_fully_specified_type();
@@ -748,7 +772,7 @@ parameter_declaration:
        }
        | parameter_type_qualifier parameter_qualifier parameter_type_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $1.i |= $2.i;
 
           $$ = new(ctx) ast_parameter_declarator();
@@ -759,7 +783,7 @@ parameter_declaration:
        }
        | parameter_qualifier parameter_type_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_parameter_declarator();
           $$->set_location(yylloc);
           $$->type = new(ctx) ast_fully_specified_type();
@@ -769,10 +793,25 @@ parameter_declaration:
        ;
 
 parameter_qualifier:
-       /* empty */     { $$.i = 0; }
-       | IN            { $$.i = 0; $$.q.in = 1; }
-       | OUT           { $$.i = 0; $$.q.out = 1; }
-       | INOUT         { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
+       /* empty */
+       {
+          memset(& $$, 0, sizeof($$));
+       }
+       | IN_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.in = 1;
+       }
+       | OUT_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.out = 1;
+       }
+       | INOUT_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.in = 1; $$.q.out = 1;
+       }
        ;
 
 parameter_type_specifier:
@@ -783,7 +822,7 @@ init_declarator_list:
        single_declaration
        | init_declarator_list ',' IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
           decl->set_location(yylloc);
 
@@ -792,7 +831,7 @@ init_declarator_list:
        }
        | init_declarator_list ',' IDENTIFIER '[' ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
           decl->set_location(yylloc);
 
@@ -801,7 +840,7 @@ init_declarator_list:
        }
        | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
           decl->set_location(yylloc);
 
@@ -810,7 +849,7 @@ init_declarator_list:
        }
        | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
           decl->set_location(yylloc);
 
@@ -819,7 +858,7 @@ init_declarator_list:
        }
        | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
           decl->set_location(yylloc);
 
@@ -828,7 +867,7 @@ init_declarator_list:
        }
        | init_declarator_list ',' IDENTIFIER '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
           decl->set_location(yylloc);
 
@@ -841,7 +880,7 @@ init_declarator_list:
 single_declaration:
        fully_specified_type
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           if ($1->specifier->type_specifier != ast_struct) {
              _mesa_glsl_error(& @1, state, "empty declaration list\n");
              YYERROR;
@@ -852,7 +891,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -861,7 +900,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER '[' ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -870,7 +909,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER '[' constant_expression ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -879,7 +918,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER '[' ']' '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -888,7 +927,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -897,7 +936,7 @@ single_declaration:
        }
        | fully_specified_type IDENTIFIER '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
 
           $$ = new(ctx) ast_declarator_list($1);
@@ -906,7 +945,7 @@ single_declaration:
        }
        | INVARIANT IDENTIFIER // Vertex only.
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
 
           $$ = new(ctx) ast_declarator_list(NULL);
@@ -920,14 +959,14 @@ single_declaration:
 fully_specified_type:
        type_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_fully_specified_type();
           $$->set_location(yylloc);
           $$->specifier = $1;
        }
        | type_qualifier type_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_fully_specified_type();
           $$->set_location(yylloc);
           $$->qualifier = $1.q;
@@ -935,39 +974,154 @@ fully_specified_type:
        }
        ;
 
+layout_qualifier:
+       LAYOUT_TOK '(' layout_qualifier_id_list ')'
+       {
+         $$ = $3;
+       }
+       ;
+
+layout_qualifier_id_list:
+       layout_qualifier_id
+       | layout_qualifier_id_list ',' layout_qualifier_id
+       {
+          $$.i = $1.i | $3.i;
+       }
+       ;
+
+layout_qualifier_id:
+       IDENTIFIER
+       {
+          bool got_one = false;
+
+          memset(& $$, 0, sizeof($$));
+
+          if (state->ARB_fragment_coord_conventions_enable) {
+             if (strcmp($1, "origin_upper_left") == 0) {
+                got_one = true;
+                $$.q.origin_upper_left = 1;
+             } else if (strcmp($1, "pixel_center_integer") == 0) {
+                got_one = true;
+                $$.q.pixel_center_integer = 1;
+             }
+          }
+
+          /* If the identifier didn't match any known layout identifiers,
+           * emit an error.
+           */
+          if (!got_one) {
+             _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
+                              "`%s'\n", $1);
+             YYERROR;
+          } else if (state->ARB_fragment_coord_conventions_warn) {
+             _mesa_glsl_warning(& @1, state,
+                                "GL_ARB_fragment_coord_conventions layout "
+                                "identifier `%s' used\n", $1);
+          }
+       }
+       ;
+
 interpolation_qualifier:
-       SMOOTH          { $$.i = 0; $$.q.smooth = 1; }
-       | FLAT          { $$.i = 0; $$.q.flat = 1; }
-       | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
+       SMOOTH
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.smooth = 1;
+       }
+       | FLAT
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.flat = 1;
+       }
+       | NOPERSPECTIVE
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.noperspective = 1;
+       }
        ;
 
 parameter_type_qualifier:
-       CONST           { $$.i = 0; $$.q.constant = 1; }
+       CONST_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.constant = 1;
+       }
        ;
 
 type_qualifier:
        storage_qualifier
-       | interpolation_qualifier type_qualifier
+       | layout_qualifier
+       | layout_qualifier storage_qualifier
        {
           $$.i = $1.i | $2.i;
        }
-       | INVARIANT type_qualifier
+       | interpolation_qualifier
+       | interpolation_qualifier storage_qualifier
+       {
+          $$.i = $1.i | $2.i;
+       }
+       | INVARIANT storage_qualifier
        {
           $$ = $2;
           $$.q.invariant = 1;
        }
+       | INVARIANT interpolation_qualifier storage_qualifier
+       {
+          $$.i = $2.i | $3.i;
+          $$.q.invariant = 1;
+       }
+       | INVARIANT
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.invariant = 1;
+       }
        ;
 
 storage_qualifier:
-       CONST                   { $$.i = 0; $$.q.constant = 1; }
-       | ATTRIBUTE             { $$.i = 0; $$.q.attribute = 1; }
-       | VARYING               { $$.i = 0; $$.q.varying = 1; }
-       | CENTROID VARYING      { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
-       | IN                    { $$.i = 0; $$.q.in = 1; }
-       | OUT                   { $$.i = 0; $$.q.out = 1; }
-       | CENTROID IN           { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
-       | CENTROID OUT          { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
-       | UNIFORM               { $$.i = 0; $$.q.uniform = 1; }
+       CONST_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.constant = 1;
+       }
+       | ATTRIBUTE
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.attribute = 1;
+       }
+       | VARYING
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.varying = 1;
+       }
+       | CENTROID VARYING
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.centroid = 1; $$.q.varying = 1;
+       }
+       | IN_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.in = 1;
+       }
+       | OUT_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.out = 1;
+       }
+       | CENTROID IN_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.centroid = 1; $$.q.in = 1;
+       }
+       | CENTROID OUT_TOK
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.centroid = 1; $$.q.out = 1;
+       }
+       | UNIFORM
+       {
+          memset(& $$, 0, sizeof($$));
+          $$.q.uniform = 1;
+       }
        ;
 
 type_specifier:
@@ -998,30 +1152,30 @@ type_specifier_no_prec:
 type_specifier_nonarray:
        basic_type_specifier_nonarray
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_type_specifier($1);
           $$->set_location(yylloc);
        }
        | struct_specifier
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_type_specifier($1);
           $$->set_location(yylloc);
        }
        | IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_type_specifier($1);
           $$->set_location(yylloc);
        }
        ;
 
 basic_type_specifier_nonarray:
-       VOID                    { $$ = ast_void; }
-       | FLOAT                 { $$ = ast_float; }
-       | INT                   { $$ = ast_int; }
-       | UINT                  { $$ = ast_uint; }
-       | BOOL                  { $$ = ast_bool; }
+       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; }
@@ -1034,9 +1188,6 @@ basic_type_specifier_nonarray:
        | UVEC2                 { $$ = ast_uvec2; }
        | UVEC3                 { $$ = ast_uvec3; }
        | UVEC4                 { $$ = ast_uvec4; }
-       | MAT2                  { $$ = ast_mat2; }
-       | MAT3                  { $$ = ast_mat3; }
-       | MAT4                  { $$ = ast_mat4; }
        | MAT2X2                { $$ = ast_mat2; }
        | MAT2X3                { $$ = ast_mat2x3; }
        | MAT2X4                { $$ = ast_mat2x4; }
@@ -1074,51 +1225,51 @@ basic_type_specifier_nonarray:
        ;
 
 precision_qualifier:
-       HIGHP           {
-                          if (state->language_version < 130)
-                             _mesa_glsl_error(& @1, state,
-                                              "precission qualifier forbidden "
-                                              "in GLSL %d.%d (1.30 or later "
-                                              "required)\n",
-                                              state->language_version / 100,
-                                              state->language_version % 100);
-
-                          $$ = ast_precision_high;
-                       }
-       | MEDIUMP       {
-                          if (state->language_version < 130)
-                             _mesa_glsl_error(& @1, state,
-                                              "precission qualifier forbidden "
-                                              "in GLSL %d.%d (1.30 or later "
-                                              "required)\n",
-                                              state->language_version / 100,
-                                              state->language_version % 100);
-
-                          $$ = ast_precision_medium;
-                       }
-       | LOWP          {
-                          if (state->language_version < 130)
-                             _mesa_glsl_error(& @1, state,
-                                              "precission qualifier forbidden "
-                                              "in GLSL %d.%d (1.30 or later "
-                                              "required)\n",
-                                              state->language_version / 100,
-                                              state->language_version % 100);
-
-                          $$ = ast_precision_low;
-                       }
+       HIGHP     {
+                    if (!state->es_shader && state->language_version < 130)
+                       _mesa_glsl_error(& @1, state,
+                                        "precision qualifier forbidden "
+                                        "in GLSL %d.%d (1.30 or later "
+                                        "required)\n",
+                                        state->language_version / 100,
+                                        state->language_version % 100);
+
+                    $$ = ast_precision_high;
+                 }
+       | MEDIUMP {
+                    if (!state->es_shader && state->language_version < 130)
+                       _mesa_glsl_error(& @1, state,
+                                        "precision qualifier forbidden "
+                                        "in GLSL %d.%d (1.30 or later "
+                                        "required)\n",
+                                        state->language_version / 100,
+                                        state->language_version % 100);
+
+                    $$ = ast_precision_medium;
+                 }
+       | LOWP    {
+                    if (!state->es_shader && state->language_version < 130)
+                       _mesa_glsl_error(& @1, state,
+                                        "precision qualifier forbidden "
+                                        "in GLSL %d.%d (1.30 or later "
+                                        "required)\n",
+                                        state->language_version / 100,
+                                        state->language_version % 100);
+
+                    $$ = ast_precision_low;
+                 }
        ;
 
 struct_specifier:
        STRUCT IDENTIFIER '{' struct_declaration_list '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_struct_specifier($2, $4);
           $$->set_location(yylloc);
        }
        | STRUCT '{' struct_declaration_list '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_struct_specifier(NULL, $3);
           $$->set_location(yylloc);
        }
@@ -1127,12 +1278,12 @@ struct_specifier:
 struct_declaration_list:
        struct_declaration
        {
-          $$ = (struct ast_node *) $1;
+          $$ = (ast_node *) $1;
           $1->link.self_link();
        }
        | struct_declaration_list struct_declaration
        {
-          $$ = (struct ast_node *) $1;
+          $$ = (ast_node *) $1;
           $$->link.insert_before(& $2->link);
        }
        ;
@@ -1140,7 +1291,7 @@ struct_declaration_list:
 struct_declaration:
        type_specifier struct_declarator_list ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
           type->set_location(yylloc);
 
@@ -1168,13 +1319,13 @@ struct_declarator_list:
 struct_declarator:
        IDENTIFIER
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_declaration($1, false, NULL, NULL);
           $$->set_location(yylloc);
        }
        | IDENTIFIER '[' constant_expression ']'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_declaration($1, true, $3, NULL);
           $$->set_location(yylloc);
        }
@@ -1191,23 +1342,14 @@ declaration_statement:
        // Grammar Note: labeled statements for SWITCH only; 'goto' is not
        // supported.
 statement:
-       statement_matched
-       | statement_unmatched
-       ;
-
-statement_matched:
-       compound_statement      { $$ = (struct ast_node *) $1; }
+       compound_statement      { $$ = (ast_node *) $1; }
        | simple_statement
        ;
 
-statement_unmatched:
-       selection_statement_unmatched
-       ;
-
 simple_statement:
        declaration_statement
        | expression_statement
-       | selection_statement_matched
+       | selection_statement
        | switch_statement              { $$ = NULL; }
        | case_label                    { $$ = NULL; }
        | iteration_statement
@@ -1217,33 +1359,33 @@ simple_statement:
 compound_statement:
        '{' '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_compound_statement(true, NULL);
           $$->set_location(yylloc);
        }
        | '{' statement_list '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_compound_statement(true, $2);
           $$->set_location(yylloc);
        }
        ;
 
 statement_no_new_scope:
-       compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
+       compound_statement_no_new_scope { $$ = (ast_node *) $1; }
        | simple_statement
        ;
 
 compound_statement_no_new_scope:
        '{' '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_compound_statement(false, NULL);
           $$->set_location(yylloc);
        }
        | '{' statement_list '}'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_compound_statement(false, $2);
           $$->set_location(yylloc);
        }
@@ -1274,56 +1416,48 @@ statement_list:
 expression_statement:
        ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_statement(NULL);
           $$->set_location(yylloc);
        }
        | expression ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_expression_statement($1);
           $$->set_location(yylloc);
        }
        ;
 
-selection_statement_matched:
-       IF '(' expression ')' statement_matched ELSE statement_matched
+selection_statement:
+       IF '(' expression ')' selection_rest_statement
        {
-          void *ctx = talloc_parent(state);
-          $$ = new(ctx) ast_selection_statement($3, $5, $7);
+          $$ = new(state) ast_selection_statement($3, $5.then_statement,
+                                                  $5.else_statement);
           $$->set_location(yylloc);
        }
        ;
 
-selection_statement_unmatched:
-       IF '(' expression ')' statement_matched
+selection_rest_statement:
+       statement ELSE statement
        {
-          void *ctx = talloc_parent(state);
-          $$ = new(ctx) ast_selection_statement($3, $5, NULL);
-          $$->set_location(yylloc);
+          $$.then_statement = $1;
+          $$.else_statement = $3;
        }
-       | IF '(' expression ')' statement_unmatched
+       | statement
        {
-          void *ctx = talloc_parent(state);
-          $$ = new(ctx) ast_selection_statement($3, $5, NULL);
-          $$->set_location(yylloc);
-       }
-       | IF '(' expression ')' statement_matched ELSE statement_unmatched
-       {
-          void *ctx = talloc_parent(state);
-          $$ = new(ctx) ast_selection_statement($3, $5, $7);
-          $$->set_location(yylloc);
+          $$.then_statement = $1;
+          $$.else_statement = NULL;
        }
        ;
 
 condition:
        expression
        {
-          $$ = (struct ast_node *) $1;
+          $$ = (ast_node *) $1;
        }
        | fully_specified_type IDENTIFIER '=' initializer
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
           ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
           decl->set_location(yylloc);
@@ -1346,21 +1480,21 @@ case_label:
 iteration_statement:
        WHILE '(' condition ')' statement_no_new_scope
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
                                                    NULL, $3, NULL, $5);
           $$->set_location(yylloc);
        }
        | DO statement WHILE '(' expression ')' ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
                                                    NULL, $5, NULL, $2);
           $$->set_location(yylloc);
        }
        | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
                                                    $3, $4.cond, $4.rest, $6);
           $$->set_location(yylloc);
@@ -1397,31 +1531,31 @@ for_rest_statement:
 jump_statement:
        CONTINUE ';' 
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
           $$->set_location(yylloc);
        }
        | BREAK ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
           $$->set_location(yylloc);
        }
        | RETURN ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
           $$->set_location(yylloc);
        }
        | RETURN expression ';'
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
           $$->set_location(yylloc);
        }
        | DISCARD ';' // Fragment shader only.
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
           $$->set_location(yylloc);
        }
@@ -1430,12 +1564,13 @@ jump_statement:
 external_declaration:
        function_definition     { $$ = $1; }
        | declaration           { $$ = $1; }
+       | pragma_statement      { $$ = NULL; }
        ;
 
 function_definition:
        function_prototype compound_statement_no_new_scope
        {
-          void *ctx = talloc_parent(state);
+          void *ctx = state;
           $$ = new(ctx) ast_function_definition();
           $$->set_location(yylloc);
           $$->prototype = $1;