aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/glsl_parser.yy
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2013-06-29 19:29:16 -0700
committerMatt Turner <[email protected]>2013-07-11 20:58:59 -0700
commit1b0d6aef03161eff4c9933548e964fec1258ea44 (patch)
tree07945e9514fac1588c57cde6b1bbcf386d380568 /src/glsl/glsl_parser.yy
parentae79e86d4c0d82b4102e2ec65c93c8240fd22e9d (diff)
glsl: Add support for C-style initializers.
Required by GL_ARB_shading_language_420pack. Parts based on work done by Todd Previte and Ken Graunke, implementing basic support for C-style initializers of arrays. Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/glsl_parser.yy')
-rw-r--r--src/glsl/glsl_parser.yy51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index afbafce4cba..78f5bf6f4f2 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -221,6 +221,7 @@ static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
%type <declarator_list> init_declarator_list
%type <declarator_list> single_declaration
%type <expression> initializer
+%type <expression> initializer_list
%type <node> declaration
%type <node> declaration_statement
%type <node> jump_statement
@@ -961,6 +962,11 @@ init_declarator_list:
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
+ 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);
+ }
}
| init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
{
@@ -971,6 +977,11 @@ init_declarator_list:
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
+ 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);
+ }
}
| init_declarator_list ',' any_identifier '=' initializer
{
@@ -981,6 +992,10 @@ init_declarator_list:
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
+ if ($5->oper == ast_aggregate) {
+ ast_aggregate_initializer *ai = (ast_aggregate_initializer *)$5;
+ _mesa_ast_set_aggregate_type($1->type->specifier, ai, state);
+ }
}
;
@@ -1028,6 +1043,11 @@ single_declaration:
$$ = new(ctx) ast_declarator_list($1);
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
+ 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);
+ }
}
| fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
{
@@ -1037,6 +1057,11 @@ single_declaration:
$$ = new(ctx) ast_declarator_list($1);
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
+ 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);
+ }
}
| fully_specified_type any_identifier '=' initializer
{
@@ -1046,6 +1071,9 @@ single_declaration:
$$ = new(ctx) ast_declarator_list($1);
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
+ if ($4->oper == ast_aggregate) {
+ _mesa_ast_set_aggregate_type($1->specifier, $4, state);
+ }
}
| INVARIANT variable_identifier // Vertex only.
{
@@ -1506,6 +1534,7 @@ struct_specifier:
$$ = new(ctx) ast_struct_specifier($2, $4);
$$->set_location(yylloc);
state->symbols->add_type($2, glsl_type::void_type);
+ state->symbols->add_type_ast($2, new(ctx) ast_type_specifier($$));
}
| STRUCT '{' struct_declaration_list '}'
{
@@ -1573,6 +1602,28 @@ struct_declarator:
initializer:
assignment_expression
+ | '{' 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);
+ }
;
declaration_statement: