2010-02-22 21:19:34 +00:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* Copyright © 2008, 2009 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "ast.h"
|
|
|
|
#include "glsl_parser_extras.h"
|
|
|
|
#include "glsl_types.h"
|
2012-07-31 09:28:35 +01:00
|
|
|
#include "main/context.h"
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
#define YYLEX_PARAM state->scanner
|
|
|
|
|
2011-12-08 09:35:48 +00:00
|
|
|
#undef yyerror
|
|
|
|
|
|
|
|
static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
|
|
|
|
{
|
|
|
|
_mesa_glsl_error(loc, st, "%s", msg);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%pure-parser
|
|
|
|
%error-verbose
|
|
|
|
|
2010-08-11 00:52:54 +01:00
|
|
|
%locations
|
|
|
|
%initial-action {
|
|
|
|
@$.first_line = 1;
|
|
|
|
@$.first_column = 1;
|
|
|
|
@$.last_line = 1;
|
|
|
|
@$.last_column = 1;
|
|
|
|
@$.source = 0;
|
|
|
|
}
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
%lex-param {void *scanner}
|
|
|
|
%parse-param {struct _mesa_glsl_parse_state *state}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
int n;
|
|
|
|
float real;
|
2012-03-30 07:17:31 +01:00
|
|
|
const char *identifier;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-10-06 00:38:47 +01:00
|
|
|
struct ast_type_qualifier type_qualifier;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-08-14 00:46:43 +01:00
|
|
|
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;
|
2011-11-07 23:11:04 +00:00
|
|
|
ast_switch_body *switch_body;
|
|
|
|
ast_case_label *case_label;
|
|
|
|
ast_case_label_list *case_label_list;
|
|
|
|
ast_case_statement *case_statement;
|
|
|
|
ast_case_statement_list *case_statement_list;
|
2013-03-09 18:40:41 +00:00
|
|
|
ast_interface_block *interface_block;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
struct {
|
2010-08-14 00:46:43 +01:00
|
|
|
ast_node *cond;
|
|
|
|
ast_expression *rest;
|
2010-02-22 21:19:34 +00:00
|
|
|
} for_rest_statement;
|
2010-09-07 20:56:18 +01:00
|
|
|
|
|
|
|
struct {
|
|
|
|
ast_node *then_statement;
|
|
|
|
ast_node *else_statement;
|
|
|
|
} selection_rest_statement;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
|
2010-08-13 17:23:54 +01:00
|
|
|
%token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK
|
2010-02-22 21:19:34 +00:00
|
|
|
%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
|
2010-08-13 17:23:54 +01:00
|
|
|
%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING
|
2010-02-22 21:19:34 +00:00
|
|
|
%token NOPERSPECTIVE FLAT SMOOTH
|
|
|
|
%token MAT2X2 MAT2X3 MAT2X4
|
|
|
|
%token MAT3X2 MAT3X3 MAT3X4
|
|
|
|
%token MAT4X2 MAT4X3 MAT4X4
|
|
|
|
%token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
|
|
|
|
%token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
|
2012-11-03 10:43:17 +00:00
|
|
|
%token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
|
|
|
|
%token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
|
|
|
|
%token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
|
|
|
|
%token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
|
|
|
|
%token USAMPLER2DARRAY USAMPLERCUBEARRAY
|
2012-04-13 20:34:45 +01:00
|
|
|
%token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
|
|
|
|
%token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
|
2012-12-21 08:33:37 +00:00
|
|
|
%token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
|
|
|
|
%token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
|
2011-10-23 11:51:06 +01:00
|
|
|
%token SAMPLEREXTERNALOES
|
2010-08-13 17:23:54 +01:00
|
|
|
%token STRUCT VOID_TOK WHILE
|
2010-10-08 01:25:34 +01:00
|
|
|
%token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
|
|
|
|
%type <identifier> any_identifier
|
2013-03-09 19:00:59 +00:00
|
|
|
%type <interface_block> instance_name_opt
|
2010-02-22 21:19:34 +00:00
|
|
|
%token <real> FLOATCONSTANT
|
|
|
|
%token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
|
|
|
|
%token <identifier> FIELD_SELECTION
|
|
|
|
%token LEFT_OP RIGHT_OP
|
|
|
|
%token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
|
|
|
|
%token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
|
|
|
|
%token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
|
|
|
|
%token SUB_ASSIGN
|
|
|
|
%token INVARIANT
|
2010-08-07 08:50:08 +01:00
|
|
|
%token LOWP MEDIUMP HIGHP SUPERP PRECISION
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2011-12-24 00:21:05 +00:00
|
|
|
%token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
|
2010-08-30 19:58:04 +01:00
|
|
|
%token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
|
|
|
|
%token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
|
2011-01-06 18:49:56 +00:00
|
|
|
%token PRAGMA_INVARIANT_ALL
|
2010-07-01 01:30:03 +01:00
|
|
|
%token LAYOUT_TOK
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
/* Reserved words that are not actually used in the grammar.
|
|
|
|
*/
|
2010-08-13 17:23:54 +01:00
|
|
|
%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
|
2010-07-01 00:40:47 +01:00
|
|
|
%token INLINE_TOK NOINLINE VOLATILE PUBLIC_TOK STATIC EXTERN EXTERNAL
|
2010-08-13 17:23:54 +01:00
|
|
|
%token LONG_TOK SHORT_TOK DOUBLE_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK OUPTUT
|
2010-02-22 21:19:34 +00:00
|
|
|
%token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
|
2012-04-13 20:34:45 +01:00
|
|
|
%token SAMPLER3DRECT
|
2010-06-08 02:55:41 +01:00
|
|
|
%token SIZEOF CAST NAMESPACE USING
|
glsl: parse GLSL ES 3.00 keywords correctly.
GLSL ES 3.00 adds the following keywords over GLSL 1.00: uint,
uvec[2-4], matNxM, centroid, flat, smooth, various samplers, layout,
switch, default, and case.
Additionally, it reserves a large number of keywords, some of which
were already reserved in versions of desktop GL that Mesa supports,
some of which are new to Mesa.
A few of the reserved keywords in GLSL ES 3.00 are keywords that are
supported in all other versions of GLSL: attribute, varying,
sampler1D, sampler1DShador, sampler2DRect, and sampler2DRectShadow.
This patch updates the lexer to handle all of the new keywords
correctly when the language being parsed is GLSL 3.00 ES.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Carl Worth <cworth@cworth.org>
2012-08-02 16:17:55 +01:00
|
|
|
%token COHERENT RESTRICT READONLY WRITEONLY RESOURCE ATOMIC_UINT PATCH SAMPLE
|
2012-12-21 08:33:37 +00:00
|
|
|
%token SUBROUTINE
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-08-12 01:01:31 +01:00
|
|
|
%token ERROR_TOK
|
|
|
|
|
2012-04-13 20:34:45 +01:00
|
|
|
%token COMMON PARTITION ACTIVE FILTER
|
2010-08-07 08:50:08 +01:00
|
|
|
%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
|
2010-11-14 06:02:09 +00:00
|
|
|
%token IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
|
2010-08-07 08:50:08 +01:00
|
|
|
%token ROW_MAJOR
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <identifier> variable_identifier
|
|
|
|
%type <node> statement
|
|
|
|
%type <node> statement_list
|
|
|
|
%type <node> simple_statement
|
|
|
|
%type <n> precision_qualifier
|
|
|
|
%type <type_qualifier> type_qualifier
|
|
|
|
%type <type_qualifier> storage_qualifier
|
|
|
|
%type <type_qualifier> interpolation_qualifier
|
2010-10-06 00:14:18 +01:00
|
|
|
%type <type_qualifier> layout_qualifier
|
2010-07-01 01:30:03 +01:00
|
|
|
%type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
|
2013-03-09 19:00:59 +00:00
|
|
|
%type <type_qualifier> interface_block_layout_qualifier
|
2013-03-09 19:36:11 +00:00
|
|
|
%type <type_qualifier> interface_qualifier
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <type_specifier> type_specifier
|
|
|
|
%type <type_specifier> type_specifier_no_prec
|
|
|
|
%type <type_specifier> type_specifier_nonarray
|
2012-03-30 07:17:32 +01:00
|
|
|
%type <identifier> basic_type_specifier_nonarray
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <fully_specified_type> fully_specified_type
|
|
|
|
%type <function> function_prototype
|
|
|
|
%type <function> function_header
|
|
|
|
%type <function> function_header_with_parameters
|
|
|
|
%type <function> function_declarator
|
|
|
|
%type <parameter_declarator> parameter_declarator
|
|
|
|
%type <parameter_declarator> parameter_declaration
|
|
|
|
%type <type_qualifier> parameter_qualifier
|
|
|
|
%type <type_qualifier> parameter_type_qualifier
|
|
|
|
%type <type_specifier> parameter_type_specifier
|
|
|
|
%type <function_definition> function_definition
|
|
|
|
%type <compound_statement> compound_statement_no_new_scope
|
|
|
|
%type <compound_statement> compound_statement
|
|
|
|
%type <node> statement_no_new_scope
|
|
|
|
%type <node> expression_statement
|
|
|
|
%type <expression> expression
|
|
|
|
%type <expression> primary_expression
|
|
|
|
%type <expression> assignment_expression
|
|
|
|
%type <expression> conditional_expression
|
|
|
|
%type <expression> logical_or_expression
|
|
|
|
%type <expression> logical_xor_expression
|
|
|
|
%type <expression> logical_and_expression
|
|
|
|
%type <expression> inclusive_or_expression
|
|
|
|
%type <expression> exclusive_or_expression
|
|
|
|
%type <expression> and_expression
|
|
|
|
%type <expression> equality_expression
|
|
|
|
%type <expression> relational_expression
|
|
|
|
%type <expression> shift_expression
|
|
|
|
%type <expression> additive_expression
|
|
|
|
%type <expression> multiplicative_expression
|
|
|
|
%type <expression> unary_expression
|
|
|
|
%type <expression> constant_expression
|
|
|
|
%type <expression> integer_expression
|
|
|
|
%type <expression> postfix_expression
|
|
|
|
%type <expression> function_call_header_with_parameters
|
|
|
|
%type <expression> function_call_header_no_parameters
|
|
|
|
%type <expression> function_call_header
|
|
|
|
%type <expression> function_call_generic
|
|
|
|
%type <expression> function_call_or_method
|
|
|
|
%type <expression> function_call
|
2010-10-08 01:25:34 +01:00
|
|
|
%type <expression> method_call_generic
|
|
|
|
%type <expression> method_call_header_with_parameters
|
|
|
|
%type <expression> method_call_header_no_parameters
|
|
|
|
%type <expression> method_call_header
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <n> assignment_operator
|
|
|
|
%type <n> unary_operator
|
2010-03-12 00:12:25 +00:00
|
|
|
%type <expression> function_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <node> external_declaration
|
|
|
|
%type <declarator_list> init_declarator_list
|
|
|
|
%type <declarator_list> single_declaration
|
|
|
|
%type <expression> initializer
|
2013-06-30 03:29:16 +01:00
|
|
|
%type <expression> initializer_list
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <node> declaration
|
|
|
|
%type <node> declaration_statement
|
|
|
|
%type <node> jump_statement
|
2013-03-09 19:00:59 +00:00
|
|
|
%type <node> interface_block
|
|
|
|
%type <interface_block> basic_interface_block
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <struct_specifier> struct_specifier
|
2012-04-26 18:16:52 +01:00
|
|
|
%type <declarator_list> struct_declaration_list
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <declarator_list> struct_declaration
|
|
|
|
%type <declaration> struct_declarator
|
|
|
|
%type <declaration> struct_declarator_list
|
2012-04-18 21:35:56 +01:00
|
|
|
%type <declarator_list> member_list
|
|
|
|
%type <declarator_list> member_declaration
|
2010-09-07 20:56:18 +01:00
|
|
|
%type <node> selection_statement
|
|
|
|
%type <selection_rest_statement> selection_rest_statement
|
2011-11-07 23:07:43 +00:00
|
|
|
%type <node> switch_statement
|
2011-11-07 23:11:04 +00:00
|
|
|
%type <switch_body> switch_body
|
|
|
|
%type <case_label_list> case_label_list
|
|
|
|
%type <case_label> case_label
|
|
|
|
%type <case_statement> case_statement
|
|
|
|
%type <case_statement_list> case_statement_list
|
2010-02-22 21:19:34 +00:00
|
|
|
%type <node> iteration_statement
|
|
|
|
%type <node> condition
|
|
|
|
%type <node> conditionopt
|
|
|
|
%type <node> for_init_statement
|
|
|
|
%type <for_rest_statement> for_rest_statement
|
2012-11-20 06:36:28 +00:00
|
|
|
%type <n> integer_constant
|
2013-07-13 07:10:14 +01:00
|
|
|
|
|
|
|
%right THEN ELSE
|
2010-02-22 21:19:34 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
translation_unit:
|
2010-06-09 06:33:43 +01:00
|
|
|
version_statement extension_statement_list
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
|
|
|
_mesa_glsl_initialize_types(state);
|
|
|
|
}
|
2010-06-09 06:33:43 +01:00
|
|
|
external_declaration_list
|
2011-01-28 01:52:19 +00:00
|
|
|
{
|
|
|
|
delete state->symbols;
|
|
|
|
state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
|
|
|
|
_mesa_glsl_initialize_types(state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
version_statement:
|
2010-09-05 08:31:28 +01:00
|
|
|
/* blank - no #version specified: defaults are already set */
|
2011-12-24 00:21:05 +00:00
|
|
|
| VERSION_TOK INTCONSTANT EOL
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2012-08-02 19:17:30 +01:00
|
|
|
state->process_version_directive(&@2, $2, NULL);
|
2013-06-08 05:46:04 +01:00
|
|
|
if (state->error) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2012-08-02 19:17:30 +01:00
|
|
|
| VERSION_TOK INTCONSTANT any_identifier EOL
|
|
|
|
{
|
|
|
|
state->process_version_directive(&@2, $2, $3);
|
2013-06-08 05:46:04 +01:00
|
|
|
if (state->error) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
2012-08-02 19:17:30 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
2010-08-30 19:58:04 +01:00
|
|
|
pragma_statement:
|
|
|
|
PRAGMA_DEBUG_ON EOL
|
|
|
|
| PRAGMA_DEBUG_OFF EOL
|
|
|
|
| PRAGMA_OPTIMIZE_ON EOL
|
|
|
|
| PRAGMA_OPTIMIZE_OFF EOL
|
2011-01-06 18:49:56 +00:00
|
|
|
| PRAGMA_INVARIANT_ALL EOL
|
|
|
|
{
|
2012-08-01 22:50:05 +01:00
|
|
|
if (!state->is_version(120, 100)) {
|
2011-01-06 18:49:56 +00:00
|
|
|
_mesa_glsl_warning(& @1, state,
|
2012-08-01 22:50:05 +01:00
|
|
|
"pragma `invariant(all)' not supported in %s "
|
|
|
|
"(GLSL ES 1.00 or GLSL 1.20 required).",
|
2012-08-02 14:45:30 +01:00
|
|
|
state->get_version_string());
|
2011-01-06 18:49:56 +00:00
|
|
|
} else {
|
|
|
|
state->all_invariant = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 19:58:04 +01:00
|
|
|
;
|
|
|
|
|
2010-04-08 00:46:25 +01:00
|
|
|
extension_statement_list:
|
|
|
|
|
|
|
|
| extension_statement_list extension_statement
|
|
|
|
;
|
|
|
|
|
2010-10-08 01:25:34 +01:00
|
|
|
any_identifier:
|
|
|
|
IDENTIFIER
|
|
|
|
| TYPE_IDENTIFIER
|
|
|
|
| NEW_IDENTIFIER
|
|
|
|
;
|
|
|
|
|
2010-04-08 00:46:25 +01:00
|
|
|
extension_statement:
|
2010-10-08 01:25:34 +01:00
|
|
|
EXTENSION any_identifier COLON any_identifier EOL
|
2010-04-08 00:46:25 +01:00
|
|
|
{
|
|
|
|
if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
external_declaration_list:
|
|
|
|
external_declaration
|
|
|
|
{
|
2011-01-17 05:44:57 +00:00
|
|
|
/* FINISHME: The NULL test is required because pragmas are set to
|
|
|
|
* FINISHME: NULL. (See production rule for external_declaration.)
|
2010-06-08 02:55:41 +01:00
|
|
|
*/
|
|
|
|
if ($1 != NULL)
|
|
|
|
state->translation_unit.push_tail(& $1->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| external_declaration_list external_declaration
|
|
|
|
{
|
2011-01-17 05:44:57 +00:00
|
|
|
/* FINISHME: The NULL test is required because pragmas are set to
|
|
|
|
* FINISHME: NULL. (See production rule for external_declaration.)
|
2010-06-08 02:55:41 +01:00
|
|
|
*/
|
|
|
|
if ($2 != NULL)
|
|
|
|
state->translation_unit.push_tail(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
variable_identifier:
|
|
|
|
IDENTIFIER
|
2010-10-08 01:25:34 +01:00
|
|
|
| NEW_IDENTIFIER
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
primary_expression:
|
|
|
|
variable_identifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.identifier = $1;
|
|
|
|
}
|
|
|
|
| INTCONSTANT
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.int_constant = $1;
|
|
|
|
}
|
|
|
|
| UINTCONSTANT
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.uint_constant = $1;
|
|
|
|
}
|
|
|
|
| FLOATCONSTANT
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.float_constant = $1;
|
|
|
|
}
|
|
|
|
| BOOLCONSTANT
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.bool_constant = $1;
|
|
|
|
}
|
|
|
|
| '(' expression ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
postfix_expression:
|
|
|
|
primary_expression
|
|
|
|
| postfix_expression '[' integer_expression ']'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| function_call
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| postfix_expression '.' any_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->primary_expression.identifier = $3;
|
|
|
|
}
|
|
|
|
| postfix_expression INC_OP
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| postfix_expression DEC_OP
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
integer_expression:
|
|
|
|
expression
|
|
|
|
;
|
|
|
|
|
|
|
|
function_call:
|
|
|
|
function_call_or_method
|
|
|
|
;
|
|
|
|
|
|
|
|
function_call_or_method:
|
|
|
|
function_call_generic
|
2010-10-08 01:25:34 +01:00
|
|
|
| postfix_expression '.' method_call_generic
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
function_call_generic:
|
|
|
|
function_call_header_with_parameters ')'
|
|
|
|
| function_call_header_no_parameters ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
function_call_header_no_parameters:
|
2010-08-13 17:23:54 +01:00
|
|
|
function_call_header VOID_TOK
|
2010-02-22 21:19:34 +00:00
|
|
|
| function_call_header
|
|
|
|
;
|
|
|
|
|
|
|
|
function_call_header_with_parameters:
|
|
|
|
function_call_header assignment_expression
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->expressions.push_tail(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| function_call_header_with_parameters ',' assignment_expression
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->expressions.push_tail(& $3->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: Constructors look like functions, but lexical
|
|
|
|
// analysis recognized most of them as keywords. They are now
|
|
|
|
// recognized through "type_specifier".
|
|
|
|
function_call_header:
|
|
|
|
function_identifier '('
|
|
|
|
;
|
|
|
|
|
|
|
|
function_identifier:
|
|
|
|
type_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_function_expression($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| variable_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_expression *callee = new(ctx) ast_expression($1);
|
|
|
|
$$ = new(ctx) ast_function_expression(callee);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| FIELD_SELECTION
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_expression *callee = new(ctx) ast_expression($1);
|
|
|
|
$$ = new(ctx) ast_function_expression(callee);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-10-08 01:25:34 +01:00
|
|
|
method_call_generic:
|
|
|
|
method_call_header_with_parameters ')'
|
|
|
|
| method_call_header_no_parameters ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
method_call_header_no_parameters:
|
|
|
|
method_call_header VOID_TOK
|
|
|
|
| method_call_header
|
|
|
|
;
|
|
|
|
|
|
|
|
method_call_header_with_parameters:
|
|
|
|
method_call_header assignment_expression
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->set_location(yylloc);
|
|
|
|
$$->expressions.push_tail(& $2->link);
|
|
|
|
}
|
|
|
|
| method_call_header_with_parameters ',' assignment_expression
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->set_location(yylloc);
|
|
|
|
$$->expressions.push_tail(& $3->link);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: Constructors look like methods, but lexical
|
|
|
|
// analysis recognized most of them as keywords. They are now
|
|
|
|
// recognized through "type_specifier".
|
|
|
|
method_call_header:
|
|
|
|
variable_identifier '('
|
|
|
|
{
|
|
|
|
void *ctx = state;
|
|
|
|
ast_expression *callee = new(ctx) ast_expression($1);
|
|
|
|
$$ = new(ctx) ast_function_expression(callee);
|
|
|
|
$$->set_location(yylloc);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
// Grammar Note: No traditional style type casts.
|
|
|
|
unary_expression:
|
|
|
|
postfix_expression
|
|
|
|
| INC_OP unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| DEC_OP unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| unary_operator unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression($1, $2, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
|
|
|
|
unary_operator:
|
|
|
|
'+' { $$ = ast_plus; }
|
|
|
|
| '-' { $$ = ast_neg; }
|
|
|
|
| '!' { $$ = ast_logic_not; }
|
|
|
|
| '~' { $$ = ast_bit_not; }
|
|
|
|
;
|
|
|
|
|
|
|
|
multiplicative_expression:
|
|
|
|
unary_expression
|
|
|
|
| multiplicative_expression '*' unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| multiplicative_expression '/' unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| multiplicative_expression '%' unary_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
additive_expression:
|
|
|
|
multiplicative_expression
|
|
|
|
| additive_expression '+' multiplicative_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| additive_expression '-' multiplicative_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
shift_expression:
|
|
|
|
additive_expression
|
|
|
|
| shift_expression LEFT_OP additive_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| shift_expression RIGHT_OP additive_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
relational_expression:
|
|
|
|
shift_expression
|
|
|
|
| relational_expression '<' shift_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| relational_expression '>' shift_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| relational_expression LE_OP shift_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| relational_expression GE_OP shift_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
equality_expression:
|
|
|
|
relational_expression
|
|
|
|
| equality_expression EQ_OP relational_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| equality_expression NE_OP relational_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
and_expression:
|
|
|
|
equality_expression
|
|
|
|
| and_expression '&' equality_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-10-19 01:25:52 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
exclusive_or_expression:
|
|
|
|
and_expression
|
|
|
|
| exclusive_or_expression '^' and_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
inclusive_or_expression:
|
|
|
|
exclusive_or_expression
|
|
|
|
| inclusive_or_expression '|' exclusive_or_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
logical_and_expression:
|
|
|
|
inclusive_or_expression
|
|
|
|
| logical_and_expression AND_OP inclusive_or_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
logical_xor_expression:
|
|
|
|
logical_and_expression
|
|
|
|
| logical_xor_expression XOR_OP logical_and_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
logical_or_expression:
|
|
|
|
logical_xor_expression
|
|
|
|
| logical_or_expression OR_OP logical_xor_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
conditional_expression:
|
|
|
|
logical_or_expression
|
|
|
|
| logical_or_expression '?' expression ':' assignment_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
assignment_expression:
|
|
|
|
conditional_expression
|
|
|
|
| unary_expression assignment_operator assignment_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression($2, $1, $3, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
assignment_operator:
|
|
|
|
'=' { $$ = ast_assign; }
|
|
|
|
| MUL_ASSIGN { $$ = ast_mul_assign; }
|
|
|
|
| DIV_ASSIGN { $$ = ast_div_assign; }
|
|
|
|
| MOD_ASSIGN { $$ = ast_mod_assign; }
|
|
|
|
| ADD_ASSIGN { $$ = ast_add_assign; }
|
|
|
|
| SUB_ASSIGN { $$ = ast_sub_assign; }
|
|
|
|
| LEFT_ASSIGN { $$ = ast_ls_assign; }
|
|
|
|
| RIGHT_ASSIGN { $$ = ast_rs_assign; }
|
|
|
|
| AND_ASSIGN { $$ = ast_and_assign; }
|
|
|
|
| XOR_ASSIGN { $$ = ast_xor_assign; }
|
|
|
|
| OR_ASSIGN { $$ = ast_or_assign; }
|
|
|
|
;
|
|
|
|
|
|
|
|
expression:
|
|
|
|
assignment_expression
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| expression ',' assignment_expression
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-02-22 21:19:34 +00:00
|
|
|
if ($1->oper != ast_sequence) {
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->expressions.push_tail(& $1->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
} else {
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->expressions.push_tail(& $3->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
constant_expression:
|
|
|
|
conditional_expression
|
|
|
|
;
|
|
|
|
|
|
|
|
declaration:
|
|
|
|
function_prototype ';'
|
|
|
|
{
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->pop_scope();
|
2010-02-22 21:19:34 +00:00
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| init_declarator_list ';'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| PRECISION precision_qualifier type_specifier_no_prec ';'
|
|
|
|
{
|
2011-01-17 05:44:57 +00:00
|
|
|
$3->precision = $2;
|
|
|
|
$3->is_precision_statement = true;
|
|
|
|
$$ = $3;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2013-03-09 19:00:59 +00:00
|
|
|
| interface_block
|
2012-04-18 21:35:56 +01:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
function_prototype:
|
|
|
|
function_declarator ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
function_declarator:
|
|
|
|
function_header
|
|
|
|
| function_header_with_parameters
|
|
|
|
;
|
|
|
|
|
|
|
|
function_header_with_parameters:
|
|
|
|
function_header parameter_declaration
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->parameters.push_tail(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| function_header_with_parameters ',' parameter_declaration
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->parameters.push_tail(& $3->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
function_header:
|
2010-10-08 01:25:34 +01:00
|
|
|
fully_specified_type variable_identifier '('
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_function();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->return_type = $1;
|
|
|
|
$$->identifier = $2;
|
2011-01-28 01:52:19 +00:00
|
|
|
|
|
|
|
state->symbols->add_function(new(state) ir_function($2));
|
|
|
|
state->symbols->push_scope();
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
parameter_declarator:
|
2010-10-08 01:25:34 +01:00
|
|
|
type_specifier any_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_parameter_declarator();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-06-24 01:12:11 +01:00
|
|
|
$$->type = new(ctx) ast_fully_specified_type();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->type->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->type->specifier = $1;
|
|
|
|
$$->identifier = $2;
|
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| type_specifier any_identifier '[' constant_expression ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_parameter_declarator();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-06-24 01:12:11 +01:00
|
|
|
$$->type = new(ctx) ast_fully_specified_type();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->type->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->type->specifier = $1;
|
|
|
|
$$->identifier = $2;
|
|
|
|
$$->is_array = true;
|
|
|
|
$$->array_size = $4;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
parameter_declaration:
|
|
|
|
parameter_type_qualifier parameter_qualifier parameter_declarator
|
|
|
|
{
|
2010-10-06 00:38:47 +01:00
|
|
|
$1.flags.i |= $2.flags.i;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $3;
|
2010-10-06 00:38:47 +01:00
|
|
|
$$->type->qualifier = $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| parameter_qualifier parameter_declarator
|
|
|
|
{
|
|
|
|
$$ = $2;
|
2010-10-06 00:38:47 +01:00
|
|
|
$$->type->qualifier = $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| parameter_type_qualifier parameter_qualifier parameter_type_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-10-06 00:38:47 +01:00
|
|
|
$1.flags.i |= $2.flags.i;
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_parameter_declarator();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-06-24 01:12:11 +01:00
|
|
|
$$->type = new(ctx) ast_fully_specified_type();
|
2010-10-06 00:38:47 +01:00
|
|
|
$$->type->qualifier = $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->type->specifier = $3;
|
|
|
|
}
|
|
|
|
| parameter_qualifier parameter_type_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_parameter_declarator();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-06-24 01:12:11 +01:00
|
|
|
$$->type = new(ctx) ast_fully_specified_type();
|
2010-10-06 00:38:47 +01:00
|
|
|
$$->type->qualifier = $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->type->specifier = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
parameter_qualifier:
|
2010-10-06 00:23:32 +01:00
|
|
|
/* empty */
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
}
|
|
|
|
| IN_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.in = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| OUT_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.out = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| INOUT_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.in = 1;
|
|
|
|
$$.flags.q.out = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
parameter_type_specifier:
|
|
|
|
type_specifier
|
|
|
|
;
|
|
|
|
|
|
|
|
init_declarator_list:
|
|
|
|
single_declaration
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier '[' ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier '[' constant_expression ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier '[' ']' '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($7->oper == ast_aggregate) {
|
|
|
|
ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
|
|
|
|
ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, NULL);
|
|
|
|
_mesa_ast_set_aggregate_type(type, ai, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($8->oper == ast_aggregate) {
|
|
|
|
ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$8;
|
|
|
|
ast_type_specifier *type = new(ctx) ast_type_specifier($1->type->specifier, true, $5);
|
|
|
|
_mesa_ast_set_aggregate_type(type, ai, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| init_declarator_list ',' any_identifier '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($5->oper == ast_aggregate) {
|
|
|
|
ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
|
|
|
|
_mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: No 'enum', or 'typedef'.
|
|
|
|
single_declaration:
|
|
|
|
fully_specified_type
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2011-08-03 16:39:07 +01:00
|
|
|
/* Empty declaration list is valid. */
|
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier '[' ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier '[' constant_expression ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier '[' ']' '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($6->oper == ast_aggregate) {
|
|
|
|
ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$6;
|
|
|
|
ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, NULL);
|
|
|
|
_mesa_ast_set_aggregate_type(type, ai, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($7->oper == ast_aggregate) {
|
|
|
|
ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$7;
|
|
|
|
ast_type_specifier *type = new(ctx) ast_type_specifier($1->specifier, true, $4);
|
|
|
|
_mesa_ast_set_aggregate_type(type, ai, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| fully_specified_type any_identifier '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2013-06-30 03:29:16 +01:00
|
|
|
if ($4->oper == ast_aggregate) {
|
|
|
|
_mesa_ast_set_aggregate_type($1->specifier, $4, state);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2011-01-28 01:52:19 +00:00
|
|
|
| INVARIANT variable_identifier // Vertex only.
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list(NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->invariant = true;
|
|
|
|
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_tail(&decl->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
fully_specified_type:
|
|
|
|
type_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_fully_specified_type();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->specifier = $1;
|
|
|
|
}
|
|
|
|
| type_qualifier type_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_fully_specified_type();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-10-06 00:38:47 +01:00
|
|
|
$$->qualifier = $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->specifier = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-07-01 01:30:03 +01:00
|
|
|
layout_qualifier:
|
|
|
|
LAYOUT_TOK '(' layout_qualifier_id_list ')'
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
layout_qualifier_id_list:
|
|
|
|
layout_qualifier_id
|
|
|
|
| layout_qualifier_id_list ',' layout_qualifier_id
|
|
|
|
{
|
2012-06-22 21:36:35 +01:00
|
|
|
$$ = $1;
|
|
|
|
if (!$$.merge_qualifier(& @3, state, $3)) {
|
2010-10-06 01:00:31 +01:00
|
|
|
YYERROR;
|
|
|
|
}
|
2010-07-01 01:30:03 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-11-20 06:36:28 +00:00
|
|
|
integer_constant:
|
|
|
|
INTCONSTANT { $$ = $1; }
|
|
|
|
| UINTCONSTANT { $$ = $1; }
|
2012-11-20 06:36:28 +00:00
|
|
|
;
|
2012-11-20 06:36:28 +00:00
|
|
|
|
2010-07-01 01:30:03 +01:00
|
|
|
layout_qualifier_id:
|
2011-01-28 01:52:19 +00:00
|
|
|
any_identifier
|
2010-07-01 01:30:03 +01:00
|
|
|
{
|
2010-10-06 00:23:32 +01:00
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-07-01 01:30:03 +01:00
|
|
|
|
2011-01-27 09:40:14 +00:00
|
|
|
/* Layout qualifiers for ARB_fragment_coord_conventions. */
|
2012-04-24 20:14:39 +01:00
|
|
|
if (!$$.flags.i && state->ARB_fragment_coord_conventions_enable) {
|
2010-07-01 01:30:03 +01:00
|
|
|
if (strcmp($1, "origin_upper_left") == 0) {
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.origin_upper_left = 1;
|
2010-07-01 01:30:03 +01:00
|
|
|
} else if (strcmp($1, "pixel_center_integer") == 0) {
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.pixel_center_integer = 1;
|
2010-07-01 01:30:03 +01:00
|
|
|
}
|
2011-01-27 09:40:14 +00:00
|
|
|
|
2012-04-24 20:14:39 +01:00
|
|
|
if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
|
2011-01-27 09:40:14 +00:00
|
|
|
_mesa_glsl_warning(& @1, state,
|
|
|
|
"GL_ARB_fragment_coord_conventions layout "
|
|
|
|
"identifier `%s' used\n", $1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-09 18:53:29 +01:00
|
|
|
/* Layout qualifiers for AMD/ARB_conservative_depth. */
|
2012-04-24 20:14:39 +01:00
|
|
|
if (!$$.flags.i &&
|
2011-11-19 15:41:08 +00:00
|
|
|
(state->AMD_conservative_depth_enable ||
|
|
|
|
state->ARB_conservative_depth_enable)) {
|
2011-01-27 09:40:14 +00:00
|
|
|
if (strcmp($1, "depth_any") == 0) {
|
|
|
|
$$.flags.q.depth_any = 1;
|
|
|
|
} else if (strcmp($1, "depth_greater") == 0) {
|
|
|
|
$$.flags.q.depth_greater = 1;
|
|
|
|
} else if (strcmp($1, "depth_less") == 0) {
|
|
|
|
$$.flags.q.depth_less = 1;
|
|
|
|
} else if (strcmp($1, "depth_unchanged") == 0) {
|
|
|
|
$$.flags.q.depth_unchanged = 1;
|
|
|
|
}
|
|
|
|
|
2012-04-24 20:14:39 +01:00
|
|
|
if ($$.flags.i && state->AMD_conservative_depth_warn) {
|
2011-11-19 15:41:08 +00:00
|
|
|
_mesa_glsl_warning(& @1, state,
|
|
|
|
"GL_AMD_conservative_depth "
|
|
|
|
"layout qualifier `%s' is used\n", $1);
|
|
|
|
}
|
2012-04-24 20:14:39 +01:00
|
|
|
if ($$.flags.i && state->ARB_conservative_depth_warn) {
|
2011-01-27 09:40:14 +00:00
|
|
|
_mesa_glsl_warning(& @1, state,
|
2011-08-09 18:53:29 +01:00
|
|
|
"GL_ARB_conservative_depth "
|
2011-01-27 09:40:14 +00:00
|
|
|
"layout qualifier `%s' is used\n", $1);
|
|
|
|
}
|
2010-07-01 01:30:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-09 19:00:59 +00:00
|
|
|
/* See also interface_block_layout_qualifier. */
|
2012-04-18 21:35:56 +01:00
|
|
|
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;
|
2013-07-11 19:28:58 +01:00
|
|
|
/* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
|
|
|
|
* below in the interface_block_layout_qualifier rule.
|
|
|
|
*
|
|
|
|
* It is not a reserved word in GLSL ES 3.00, so it's handled here as
|
|
|
|
* an identifier.
|
|
|
|
*/
|
2012-11-09 20:26:42 +00:00
|
|
|
} else if (strcmp($1, "row_major") == 0) {
|
|
|
|
$$.flags.q.row_major = 1;
|
2012-04-18 21:35:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 20:14:39 +01:00
|
|
|
if (!$$.flags.i) {
|
2010-07-01 01:30:03 +01:00
|
|
|
_mesa_glsl_error(& @1, state, "unrecognized layout identifier "
|
|
|
|
"`%s'\n", $1);
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
}
|
2012-11-20 06:36:28 +00:00
|
|
|
| any_identifier '=' integer_constant
|
2010-10-06 01:00:31 +01:00
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
|
|
|
|
if (state->ARB_explicit_attrib_location_enable) {
|
|
|
|
if (strcmp("location", $1) == 0) {
|
|
|
|
$$.flags.q.explicit_location = 1;
|
|
|
|
|
|
|
|
if ($3 >= 0) {
|
|
|
|
$$.location = $3;
|
|
|
|
} else {
|
|
|
|
_mesa_glsl_error(& @3, state,
|
|
|
|
"invalid location %d specified\n", $3);
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
}
|
glsl: add support for ARB_blend_func_extended (v3)
This adds index support to the GLSL compiler.
I'm not 100% sure of my approach here, esp without how output ordering
happens wrt location, index pairs, in the "mark" function.
Since current hw doesn't ever have a location > 0 with an index > 0,
we don't have to work out if the output ordering the hw requires is
location, index, location, index or location, location, index, index.
But we have no hw to know, so punt on it for now.
v2: index requires layout - catch and error
setup explicit index properly.
v3: drop idx_offset stuff, assume index follow location
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-03-24 13:33:41 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-10-06 01:00:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the identifier didn't match any known layout identifiers,
|
|
|
|
* emit an error.
|
|
|
|
*/
|
2012-04-24 20:14:39 +01:00
|
|
|
if (!$$.flags.i) {
|
2010-10-06 01:00:31 +01:00
|
|
|
_mesa_glsl_error(& @1, state, "unrecognized layout identifier "
|
|
|
|
"`%s'\n", $1);
|
|
|
|
YYERROR;
|
|
|
|
} else if (state->ARB_explicit_attrib_location_warn) {
|
|
|
|
_mesa_glsl_warning(& @1, state,
|
|
|
|
"GL_ARB_explicit_attrib_location layout "
|
|
|
|
"identifier `%s' used\n", $1);
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 19:00:59 +00:00
|
|
|
| interface_block_layout_qualifier
|
2012-04-18 21:35:56 +01:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
/* Layout qualifiers for ARB_uniform_buffer_object. */
|
2013-03-09 19:36:11 +00:00
|
|
|
if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
|
2012-04-18 21:35:56 +01:00
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"#version 140 / GL_ARB_uniform_buffer_object "
|
|
|
|
"layout qualifier `%s' is used\n", $1);
|
2013-03-09 19:36:11 +00:00
|
|
|
} else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
|
2012-04-18 21:35:56 +01:00
|
|
|
_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.
|
|
|
|
*/
|
2013-03-09 19:00:59 +00:00
|
|
|
interface_block_layout_qualifier:
|
2012-04-18 21:35:56 +01:00
|
|
|
ROW_MAJOR
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
$$.flags.q.row_major = 1;
|
|
|
|
}
|
|
|
|
| PACKED_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
$$.flags.q.packed = 1;
|
|
|
|
}
|
2010-07-01 01:30:03 +01:00
|
|
|
;
|
|
|
|
|
2010-02-22 21:19:34 +00:00
|
|
|
interpolation_qualifier:
|
2010-10-06 00:23:32 +01:00
|
|
|
SMOOTH
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.smooth = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| FLAT
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.flat = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| NOPERSPECTIVE
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.noperspective = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
parameter_type_qualifier:
|
2010-10-06 00:23:32 +01:00
|
|
|
CONST_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.constant = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type_qualifier:
|
|
|
|
storage_qualifier
|
2010-10-06 00:14:18 +01:00
|
|
|
| layout_qualifier
|
|
|
|
| layout_qualifier storage_qualifier
|
|
|
|
{
|
2010-10-06 00:38:47 +01:00
|
|
|
$$ = $1;
|
|
|
|
$$.flags.i |= $2.flags.i;
|
2010-10-06 00:14:18 +01:00
|
|
|
}
|
|
|
|
| interpolation_qualifier
|
|
|
|
| interpolation_qualifier storage_qualifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-10-06 00:38:47 +01:00
|
|
|
$$ = $1;
|
|
|
|
$$.flags.i |= $2.flags.i;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-06 00:14:18 +01:00
|
|
|
| INVARIANT storage_qualifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
|
|
|
$$ = $2;
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.invariant = 1;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-06 00:14:18 +01:00
|
|
|
| INVARIANT interpolation_qualifier storage_qualifier
|
|
|
|
{
|
2010-10-06 00:38:47 +01:00
|
|
|
$$ = $2;
|
|
|
|
$$.flags.i |= $3.flags.i;
|
|
|
|
$$.flags.q.invariant = 1;
|
2010-10-06 00:14:18 +01:00
|
|
|
}
|
|
|
|
| INVARIANT
|
|
|
|
{
|
2010-10-06 00:23:32 +01:00
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.invariant = 1;
|
2010-10-06 00:14:18 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
storage_qualifier:
|
2010-10-06 00:23:32 +01:00
|
|
|
CONST_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.constant = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| ATTRIBUTE
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.attribute = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| VARYING
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.varying = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| CENTROID VARYING
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.centroid = 1;
|
|
|
|
$$.flags.q.varying = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| IN_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.in = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| OUT_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.out = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| CENTROID IN_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.centroid = 1; $$.flags.q.in = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| CENTROID OUT_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.centroid = 1; $$.flags.q.out = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
|
|
|
| UNIFORM
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
2010-10-06 00:38:47 +01:00
|
|
|
$$.flags.q.uniform = 1;
|
2010-10-06 00:23:32 +01:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type_specifier:
|
|
|
|
type_specifier_no_prec
|
2011-01-17 06:08:56 +00:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
| precision_qualifier type_specifier_no_prec
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
$$->precision = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
type_specifier_no_prec:
|
|
|
|
type_specifier_nonarray
|
|
|
|
| type_specifier_nonarray '[' ']'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->is_array = true;
|
|
|
|
$$->array_size = NULL;
|
|
|
|
}
|
|
|
|
| type_specifier_nonarray '[' constant_expression ']'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->is_array = true;
|
|
|
|
$$->array_size = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
type_specifier_nonarray:
|
|
|
|
basic_type_specifier_nonarray
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_type_specifier($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| struct_specifier
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_type_specifier($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2010-10-08 01:25:34 +01:00
|
|
|
| TYPE_IDENTIFIER
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_type_specifier($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
basic_type_specifier_nonarray:
|
2012-03-30 07:17:32 +01:00
|
|
|
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"; }
|
2012-03-26 22:13:17 +01:00
|
|
|
| SAMPLERBUFFER { $$ = "samplerBuffer"; }
|
2012-11-03 10:43:17 +00:00
|
|
|
| SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
|
|
|
|
| SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
|
2012-03-30 07:17:32 +01:00
|
|
|
| ISAMPLER1D { $$ = "isampler1D"; }
|
|
|
|
| ISAMPLER2D { $$ = "isampler2D"; }
|
2012-04-13 20:34:45 +01:00
|
|
|
| ISAMPLER2DRECT { $$ = "isampler2DRect"; }
|
2012-03-30 07:17:32 +01:00
|
|
|
| ISAMPLER3D { $$ = "isampler3D"; }
|
|
|
|
| ISAMPLERCUBE { $$ = "isamplerCube"; }
|
|
|
|
| ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
|
|
|
|
| ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
|
2012-04-13 20:34:45 +01:00
|
|
|
| ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
|
2012-11-03 10:43:17 +00:00
|
|
|
| ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
|
2012-03-30 07:17:32 +01:00
|
|
|
| USAMPLER1D { $$ = "usampler1D"; }
|
|
|
|
| USAMPLER2D { $$ = "usampler2D"; }
|
2012-04-13 20:34:45 +01:00
|
|
|
| USAMPLER2DRECT { $$ = "usampler2DRect"; }
|
2012-03-30 07:17:32 +01:00
|
|
|
| USAMPLER3D { $$ = "usampler3D"; }
|
|
|
|
| USAMPLERCUBE { $$ = "usamplerCube"; }
|
|
|
|
| USAMPLER1DARRAY { $$ = "usampler1DArray"; }
|
|
|
|
| USAMPLER2DARRAY { $$ = "usampler2DArray"; }
|
2012-04-13 20:34:45 +01:00
|
|
|
| USAMPLERBUFFER { $$ = "usamplerBuffer"; }
|
2012-11-03 10:43:17 +00:00
|
|
|
| USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
|
2012-12-21 08:33:37 +00:00
|
|
|
| SAMPLER2DMS { $$ = "sampler2DMS"; }
|
|
|
|
| ISAMPLER2DMS { $$ = "isampler2DMS"; }
|
|
|
|
| USAMPLER2DMS { $$ = "usampler2DMS"; }
|
|
|
|
| SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
|
|
|
|
| ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
|
|
|
|
| USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
precision_qualifier:
|
2010-09-05 09:32:32 +01:00
|
|
|
HIGHP {
|
2012-08-05 17:57:01 +01:00
|
|
|
state->check_precision_qualifiers_allowed(&@1);
|
2010-09-05 09:32:32 +01:00
|
|
|
|
|
|
|
$$ = ast_precision_high;
|
|
|
|
}
|
|
|
|
| MEDIUMP {
|
2012-08-05 17:57:01 +01:00
|
|
|
state->check_precision_qualifiers_allowed(&@1);
|
2010-09-05 09:32:32 +01:00
|
|
|
|
|
|
|
$$ = ast_precision_medium;
|
|
|
|
}
|
|
|
|
| LOWP {
|
2012-08-05 17:57:01 +01:00
|
|
|
state->check_precision_qualifiers_allowed(&@1);
|
2010-09-05 09:32:32 +01:00
|
|
|
|
|
|
|
$$ = ast_precision_low;
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
struct_specifier:
|
2011-01-28 01:52:19 +00:00
|
|
|
STRUCT any_identifier '{' struct_declaration_list '}'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_struct_specifier($2, $4);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->add_type($2, glsl_type::void_type);
|
2013-06-30 03:29:16 +01:00
|
|
|
state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| STRUCT '{' struct_declaration_list '}'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_struct_specifier(NULL, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_declaration_list:
|
|
|
|
struct_declaration
|
|
|
|
{
|
2012-04-26 18:16:52 +01:00
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$1->link.self_link();
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| struct_declaration_list struct_declaration
|
|
|
|
{
|
2012-04-26 18:16:52 +01:00
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->link.insert_before(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_declaration:
|
|
|
|
type_specifier struct_declarator_list ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_fully_specified_type *type = new(ctx) ast_fully_specified_type();
|
2010-04-01 01:12:34 +01:00
|
|
|
type->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
|
|
|
type->specifier = $1;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declarator_list(type);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->declarations.push_degenerate_list_at_head(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_declarator_list:
|
|
|
|
struct_declarator
|
2010-05-10 19:17:53 +01:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$1->link.self_link();
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
| struct_declarator_list ',' struct_declarator
|
|
|
|
{
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->link.insert_before(& $3->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_declarator:
|
2011-01-28 01:52:19 +00:00
|
|
|
any_identifier
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declaration($1, false, NULL, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2011-01-28 01:52:19 +00:00
|
|
|
| any_identifier '[' constant_expression ']'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_declaration($1, true, $3, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
initializer:
|
|
|
|
assignment_expression
|
2013-06-30 03:29:16 +01:00
|
|
|
| '{' initializer_list '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
| '{' initializer_list ',' '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
initializer_list:
|
|
|
|
initializer
|
|
|
|
{
|
|
|
|
void *ctx = state;
|
|
|
|
$$ = new(ctx) ast_aggregate_initializer();
|
|
|
|
$$->set_location(yylloc);
|
|
|
|
$$->expressions.push_tail(& $1->link);
|
|
|
|
}
|
|
|
|
| initializer_list ',' initializer
|
|
|
|
{
|
|
|
|
$1->expressions.push_tail(& $3->link);
|
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
declaration_statement:
|
|
|
|
declaration
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: labeled statements for SWITCH only; 'goto' is not
|
|
|
|
// supported.
|
|
|
|
statement:
|
2010-08-14 00:46:43 +01:00
|
|
|
compound_statement { $$ = (ast_node *) $1; }
|
2010-02-22 21:19:34 +00:00
|
|
|
| simple_statement
|
|
|
|
;
|
|
|
|
|
|
|
|
simple_statement:
|
|
|
|
declaration_statement
|
|
|
|
| expression_statement
|
2010-09-07 20:56:18 +01:00
|
|
|
| selection_statement
|
2011-11-07 23:07:43 +00:00
|
|
|
| switch_statement
|
2010-02-22 21:19:34 +00:00
|
|
|
| iteration_statement
|
|
|
|
| jump_statement
|
|
|
|
;
|
|
|
|
|
|
|
|
compound_statement:
|
|
|
|
'{' '}'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_compound_statement(true, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2011-01-28 01:52:19 +00:00
|
|
|
| '{'
|
|
|
|
{
|
|
|
|
state->symbols->push_scope();
|
|
|
|
}
|
|
|
|
statement_list '}'
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2011-01-28 01:52:19 +00:00
|
|
|
$$ = new(ctx) ast_compound_statement(true, $3);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2011-01-28 01:52:19 +00:00
|
|
|
state->symbols->pop_scope();
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
statement_no_new_scope:
|
2010-08-14 00:46:43 +01:00
|
|
|
compound_statement_no_new_scope { $$ = (ast_node *) $1; }
|
2010-02-22 21:19:34 +00:00
|
|
|
| simple_statement
|
|
|
|
;
|
|
|
|
|
|
|
|
compound_statement_no_new_scope:
|
|
|
|
'{' '}'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_compound_statement(false, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| '{' statement_list '}'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_compound_statement(false, $2);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
statement_list:
|
|
|
|
statement
|
|
|
|
{
|
|
|
|
if ($1 == NULL) {
|
|
|
|
_mesa_glsl_error(& @1, state, "<nil> statement\n");
|
|
|
|
assert($1 != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->link.self_link();
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| statement_list statement
|
|
|
|
{
|
|
|
|
if ($2 == NULL) {
|
|
|
|
_mesa_glsl_error(& @2, state, "<nil> statement\n");
|
|
|
|
assert($2 != NULL);
|
|
|
|
}
|
|
|
|
$$ = $1;
|
2010-05-10 19:17:53 +01:00
|
|
|
$$->link.insert_before(& $2->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
expression_statement:
|
|
|
|
';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_statement(NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| expression ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_expression_statement($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-09-07 20:56:18 +01:00
|
|
|
selection_statement:
|
|
|
|
IF '(' expression ')' selection_rest_statement
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-09-07 20:56:18 +01:00
|
|
|
$$ = new(state) ast_selection_statement($3, $5.then_statement,
|
|
|
|
$5.else_statement);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2010-09-07 20:56:18 +01:00
|
|
|
selection_rest_statement:
|
|
|
|
statement ELSE statement
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-09-07 20:56:18 +01:00
|
|
|
$$.then_statement = $1;
|
|
|
|
$$.else_statement = $3;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2013-07-13 07:10:14 +01:00
|
|
|
| statement %prec THEN
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-09-07 20:56:18 +01:00
|
|
|
$$.then_statement = $1;
|
|
|
|
$$.else_statement = NULL;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
condition:
|
|
|
|
expression
|
|
|
|
{
|
2010-08-14 00:46:43 +01:00
|
|
|
$$ = (ast_node *) $1;
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
2011-01-28 01:52:19 +00:00
|
|
|
| fully_specified_type any_identifier '=' initializer
|
2010-02-22 21:19:34 +00:00
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
|
|
|
|
ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
|
2010-04-01 01:12:34 +01:00
|
|
|
decl->set_location(yylloc);
|
|
|
|
declarator->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
|
2010-05-10 19:17:53 +01:00
|
|
|
declarator->declarations.push_tail(&decl->link);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$ = declarator;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2011-11-07 23:07:43 +00:00
|
|
|
/*
|
|
|
|
* siwtch_statement grammar is based on the syntax described in the body
|
|
|
|
* of the GLSL spec, not in it's appendix!!!
|
|
|
|
*/
|
2010-02-22 21:19:34 +00:00
|
|
|
switch_statement:
|
2011-11-07 23:07:43 +00:00
|
|
|
SWITCH '(' expression ')' switch_body
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = new(state) ast_switch_statement($3, $5);
|
2012-01-30 17:46:09 +00:00
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
switch_body:
|
|
|
|
'{' '}'
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = new(state) ast_switch_body(NULL);
|
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
| '{' case_statement_list '}'
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = new(state) ast_switch_body($2);
|
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
case_label:
|
|
|
|
CASE expression ':'
|
2011-11-07 23:07:43 +00:00
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = new(state) ast_case_label($2);
|
2012-01-30 17:41:55 +00:00
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
| DEFAULT ':'
|
2011-11-07 23:07:43 +00:00
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = new(state) ast_case_label(NULL);
|
2012-01-30 17:41:55 +00:00
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
case_label_list:
|
|
|
|
case_label
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
ast_case_label_list *labels = new(state) ast_case_label_list();
|
|
|
|
|
|
|
|
labels->labels.push_tail(& $1->link);
|
|
|
|
$$ = labels;
|
2012-01-30 17:46:09 +00:00
|
|
|
$$->set_location(yylloc);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
| case_label_list case_label
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = $1;
|
|
|
|
$$->labels.push_tail(& $2->link);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
case_statement:
|
2011-11-07 23:11:04 +00:00
|
|
|
case_label_list statement
|
|
|
|
{
|
|
|
|
ast_case_statement *stmts = new(state) ast_case_statement($1);
|
2012-01-30 17:46:09 +00:00
|
|
|
stmts->set_location(yylloc);
|
2011-11-07 23:11:04 +00:00
|
|
|
|
|
|
|
stmts->stmts.push_tail(& $2->link);
|
2011-11-14 14:14:45 +00:00
|
|
|
$$ = stmts;
|
2011-11-07 23:11:04 +00:00
|
|
|
}
|
|
|
|
| case_statement statement
|
2011-11-07 23:07:43 +00:00
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = $1;
|
|
|
|
$$->stmts.push_tail(& $2->link);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
case_statement_list:
|
|
|
|
case_statement
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
ast_case_statement_list *cases= new(state) ast_case_statement_list();
|
2012-01-30 17:46:09 +00:00
|
|
|
cases->set_location(yylloc);
|
2011-11-07 23:11:04 +00:00
|
|
|
|
|
|
|
cases->cases.push_tail(& $1->link);
|
|
|
|
$$ = cases;
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
|
|
|
| case_statement_list case_statement
|
|
|
|
{
|
2011-11-07 23:11:04 +00:00
|
|
|
$$ = $1;
|
|
|
|
$$->cases.push_tail(& $2->link);
|
2011-11-07 23:07:43 +00:00
|
|
|
}
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
iteration_statement:
|
|
|
|
WHILE '(' condition ')' statement_no_new_scope
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
|
|
|
|
NULL, $3, NULL, $5);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| DO statement WHILE '(' expression ')' ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
|
|
|
|
NULL, $5, NULL, $2);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
|
|
|
|
$3, $4.cond, $4.rest, $6);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
for_init_statement:
|
|
|
|
expression_statement
|
|
|
|
| declaration_statement
|
|
|
|
;
|
|
|
|
|
|
|
|
conditionopt:
|
|
|
|
condition
|
|
|
|
| /* empty */
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
for_rest_statement:
|
|
|
|
conditionopt ';'
|
|
|
|
{
|
|
|
|
$$.cond = $1;
|
|
|
|
$$.rest = NULL;
|
|
|
|
}
|
|
|
|
| conditionopt ';' expression
|
|
|
|
{
|
|
|
|
$$.cond = $1;
|
|
|
|
$$.rest = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
// Grammar Note: No 'goto'. Gotos are not supported.
|
|
|
|
jump_statement:
|
|
|
|
CONTINUE ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| BREAK ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| RETURN ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| RETURN expression ';'
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
| DISCARD ';' // Fragment shader only.
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
external_declaration:
|
|
|
|
function_definition { $$ = $1; }
|
|
|
|
| declaration { $$ = $1; }
|
2010-08-30 19:58:04 +01:00
|
|
|
| pragma_statement { $$ = NULL; }
|
2012-06-22 21:36:35 +01:00
|
|
|
| layout_defaults { $$ = NULL; }
|
2010-02-22 21:19:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
function_definition:
|
|
|
|
function_prototype compound_statement_no_new_scope
|
|
|
|
{
|
2010-06-25 21:14:37 +01:00
|
|
|
void *ctx = state;
|
2010-06-24 01:12:11 +01:00
|
|
|
$$ = new(ctx) ast_function_definition();
|
2010-04-01 01:12:34 +01:00
|
|
|
$$->set_location(yylloc);
|
2010-02-22 21:19:34 +00:00
|
|
|
$$->prototype = $1;
|
|
|
|
$$->body = $2;
|
2011-01-28 01:52:19 +00:00
|
|
|
|
|
|
|
state->symbols->pop_scope();
|
2010-02-22 21:19:34 +00:00
|
|
|
}
|
|
|
|
;
|
2012-04-18 21:35:56 +01:00
|
|
|
|
|
|
|
/* layout_qualifieropt is packed into this rule */
|
2013-03-09 19:00:59 +00:00
|
|
|
interface_block:
|
|
|
|
basic_interface_block
|
2012-04-18 21:35:56 +01:00
|
|
|
{
|
2012-11-28 07:21:56 +00:00
|
|
|
$$ = $1;
|
2012-04-18 21:35:56 +01:00
|
|
|
}
|
2013-03-09 19:00:59 +00:00
|
|
|
| layout_qualifier basic_interface_block
|
2012-04-18 21:35:56 +01:00
|
|
|
{
|
2013-03-09 18:40:41 +00:00
|
|
|
ast_interface_block *block = $2;
|
2012-11-28 07:21:56 +00:00
|
|
|
if (!block->layout.merge_qualifier(& @1, state, $1)) {
|
2012-06-22 21:36:35 +01:00
|
|
|
YYERROR;
|
|
|
|
}
|
2012-11-28 07:21:56 +00:00
|
|
|
$$ = block;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-03-09 19:00:59 +00:00
|
|
|
basic_interface_block:
|
2013-03-09 19:36:11 +00:00
|
|
|
interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
|
2012-11-28 07:21:56 +00:00
|
|
|
{
|
2013-03-09 18:40:41 +00:00
|
|
|
ast_interface_block *const block = $6;
|
2012-12-11 20:13:30 +00:00
|
|
|
|
|
|
|
block->block_name = $2;
|
|
|
|
block->declarations.push_degenerate_list_at_head(& $4->link);
|
2012-07-26 21:11:05 +01:00
|
|
|
|
2013-03-09 19:36:11 +00:00
|
|
|
if ($1.flags.q.uniform) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state->es_shader || state->language_version < 150) {
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"#version 150 required for using "
|
|
|
|
"interface blocks.\n");
|
|
|
|
}
|
2012-07-26 21:11:05 +01:00
|
|
|
}
|
2012-12-11 20:13:30 +00:00
|
|
|
|
2013-03-09 21:01:13 +00:00
|
|
|
/* From the GLSL 1.50.11 spec, section 4.3.7 ("Interface Blocks"):
|
|
|
|
* "It is illegal to have an input block in a vertex shader
|
|
|
|
* or an output block in a fragment shader"
|
|
|
|
*/
|
|
|
|
if ((state->target == vertex_shader) && $1.flags.q.in) {
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"`in' interface block is not allowed for "
|
|
|
|
"a vertex shader\n");
|
|
|
|
} else if ((state->target == fragment_shader) && $1.flags.q.out) {
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"`out' interface block is not allowed for "
|
|
|
|
"a fragment shader\n");
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:13:30 +00:00
|
|
|
/* Since block arrays require names, and both features are added in
|
|
|
|
* the same language versions, we don't have to explicitly
|
|
|
|
* version-check both things.
|
|
|
|
*/
|
2013-03-09 22:09:30 +00:00
|
|
|
if (block->instance_name != NULL) {
|
|
|
|
state->check_version(150, 300, & @1, "interface blocks with "
|
|
|
|
"an instance name are not allowed");
|
2012-12-11 20:13:30 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 17:52:19 +00:00
|
|
|
unsigned interface_type_mask;
|
|
|
|
struct ast_type_qualifier temp_type_qualifier;
|
|
|
|
|
|
|
|
/* Get a bitmask containing only the in/out/uniform flags, allowing us
|
|
|
|
* to ignore other irrelevant flags like interpolation qualifiers.
|
|
|
|
*/
|
|
|
|
temp_type_qualifier.flags.i = 0;
|
|
|
|
temp_type_qualifier.flags.q.uniform = true;
|
|
|
|
temp_type_qualifier.flags.q.in = true;
|
|
|
|
temp_type_qualifier.flags.q.out = true;
|
|
|
|
interface_type_mask = temp_type_qualifier.flags.i;
|
|
|
|
|
|
|
|
/* Get the block's interface qualifier. The interface_qualifier
|
|
|
|
* production rule guarantees that only one bit will be set (and
|
|
|
|
* it will be in/out/uniform).
|
|
|
|
*/
|
|
|
|
unsigned block_interface_qualifier = $1.flags.i;
|
|
|
|
|
|
|
|
block->layout.flags.i |= block_interface_qualifier;
|
|
|
|
|
|
|
|
foreach_list_typed (ast_declarator_list, member, link, &block->declarations) {
|
|
|
|
ast_type_qualifier& qualifier = member->type->qualifier;
|
|
|
|
if ((qualifier.flags.i & interface_type_mask) == 0) {
|
|
|
|
/* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
|
|
|
|
* "If no optional qualifier is used in a member declaration, the
|
|
|
|
* qualifier of the variable is just in, out, or uniform as declared
|
|
|
|
* by interface-qualifier."
|
|
|
|
*/
|
|
|
|
qualifier.flags.i |= block_interface_qualifier;
|
|
|
|
} else if ((qualifier.flags.i & interface_type_mask) !=
|
|
|
|
block_interface_qualifier) {
|
|
|
|
/* GLSLangSpec.1.50.11, 4.3.7 (Interface Blocks):
|
|
|
|
* "If optional qualifiers are used, they can include interpolation
|
|
|
|
* and storage qualifiers and they must declare an input, output,
|
|
|
|
* or uniform variable consistent with the interface qualifier of
|
|
|
|
* the block."
|
|
|
|
*/
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"uniform/in/out qualifier on "
|
|
|
|
"interface block member does not match "
|
|
|
|
"the interface block\n");
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 19:36:11 +00:00
|
|
|
|
2012-12-11 20:13:30 +00:00
|
|
|
$$ = block;
|
2012-04-18 21:35:56 +01:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-03-09 19:36:11 +00:00
|
|
|
interface_qualifier:
|
|
|
|
IN_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
$$.flags.q.in = 1;
|
|
|
|
}
|
|
|
|
| OUT_TOK
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
$$.flags.q.out = 1;
|
|
|
|
}
|
|
|
|
| UNIFORM
|
|
|
|
{
|
|
|
|
memset(& $$, 0, sizeof($$));
|
|
|
|
$$.flags.q.uniform = 1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-11-28 07:45:17 +00:00
|
|
|
instance_name_opt:
|
|
|
|
/* empty */
|
|
|
|
{
|
2013-03-09 18:40:41 +00:00
|
|
|
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
|
2012-12-11 20:13:30 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2012-11-28 07:45:17 +00:00
|
|
|
}
|
|
|
|
| NEW_IDENTIFIER
|
|
|
|
{
|
2013-03-09 18:40:41 +00:00
|
|
|
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
|
2012-12-11 20:13:30 +00:00
|
|
|
$1,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
| NEW_IDENTIFIER '[' constant_expression ']'
|
|
|
|
{
|
2013-03-09 18:40:41 +00:00
|
|
|
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
|
2012-12-11 20:13:30 +00:00
|
|
|
$1,
|
|
|
|
$3);
|
|
|
|
}
|
|
|
|
| NEW_IDENTIFIER '[' ']'
|
|
|
|
{
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"instance block arrays must be explicitly sized\n");
|
|
|
|
|
2013-03-09 18:40:41 +00:00
|
|
|
$$ = new(state) ast_interface_block(*state->default_uniform_qualifier,
|
2012-12-11 20:13:30 +00:00
|
|
|
$1,
|
|
|
|
NULL);
|
2012-11-28 07:45:17 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-04-18 21:35:56 +01:00
|
|
|
member_list:
|
|
|
|
member_declaration
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$1->link.self_link();
|
|
|
|
}
|
|
|
|
| member_declaration member_list
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$2->link.insert_before(& $$->link);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
member_declaration:
|
2013-03-09 22:52:14 +00:00
|
|
|
fully_specified_type struct_declarator_list ';'
|
2012-04-18 21:35:56 +01:00
|
|
|
{
|
|
|
|
void *ctx = state;
|
2013-03-09 22:52:14 +00:00
|
|
|
ast_fully_specified_type *type = $1;
|
2012-04-18 21:35:56 +01:00
|
|
|
type->set_location(yylloc);
|
|
|
|
|
2013-03-09 22:52:14 +00:00
|
|
|
if (type->qualifier.flags.q.attribute) {
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"keyword 'attribute' cannot be used with "
|
|
|
|
"interface block member\n");
|
|
|
|
} else if (type->qualifier.flags.q.varying) {
|
|
|
|
_mesa_glsl_error(& @1, state,
|
|
|
|
"keyword 'varying' cannot be used with "
|
|
|
|
"interface block member\n");
|
|
|
|
}
|
2012-04-18 21:35:56 +01:00
|
|
|
|
|
|
|
$$ = new(ctx) ast_declarator_list(type);
|
|
|
|
$$->set_location(yylloc);
|
2012-04-27 02:19:39 +01:00
|
|
|
$$->ubo_qualifiers_valid = true;
|
2012-04-18 21:35:56 +01:00
|
|
|
|
2013-03-09 22:52:14 +00:00
|
|
|
$$->declarations.push_degenerate_list_at_head(& $2->link);
|
2012-04-18 21:35:56 +01:00
|
|
|
}
|
|
|
|
;
|
2012-06-22 21:36:35 +01:00
|
|
|
|
|
|
|
layout_defaults:
|
|
|
|
layout_qualifier UNIFORM ';'
|
|
|
|
{
|
|
|
|
if (!state->default_uniform_qualifier->merge_qualifier(& @1, state,
|
|
|
|
$1)) {
|
|
|
|
YYERROR;
|
|
|
|
}
|
|
|
|
}
|