diff options
author | Timothy Arceri <[email protected]> | 2014-01-23 23:16:41 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2014-01-23 23:31:10 +1100 |
commit | bfb48750f08223fdf1c2d7bf4db1bba5a1088a7c (patch) | |
tree | 35708cca3bc36c503bce20aebe577b55b78846ed /src/glsl/glsl_parser.yy | |
parent | 72288e0c7b7ec769da71fbaf124ec4ee8be7577b (diff) |
glsl: Add ARB_arrays_of_arrays support to yacc definition and ast
Adds array specifier object to hold array information
Signed-off-by: Timothy Arceri <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Diffstat (limited to 'src/glsl/glsl_parser.yy')
-rw-r--r-- | src/glsl/glsl_parser.yy | 128 |
1 files changed, 56 insertions, 72 deletions
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 5451b764a77..2786e920922 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -97,6 +97,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2, ast_node *node; ast_type_specifier *type_specifier; + ast_array_specifier *array_specifier; ast_fully_specified_type *fully_specified_type; ast_function *function; ast_parameter_declarator *parameter_declarator; @@ -202,6 +203,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2, %type <type_qualifier> interface_qualifier %type <type_specifier> type_specifier %type <type_specifier> type_specifier_nonarray +%type <array_specifier> array_specifier %type <identifier> basic_type_specifier_nonarray %type <fully_specified_type> fully_specified_type %type <function> function_prototype @@ -880,7 +882,7 @@ parameter_declarator: $$->type->specifier = $1; $$->identifier = $2; } - | type_specifier any_identifier '[' constant_expression ']' + | type_specifier any_identifier array_specifier { void *ctx = state; $$ = new(ctx) ast_parameter_declarator(); @@ -889,8 +891,7 @@ parameter_declarator: $$->type->set_location(yylloc); $$->type->specifier = $1; $$->identifier = $2; - $$->is_array = true; - $$->array_size = $4; + $$->array_specifier = $3; } ; @@ -983,40 +984,20 @@ init_declarator_list: $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); } - | init_declarator_list ',' any_identifier '[' ']' + | init_declarator_list ',' any_identifier array_specifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL); + ast_declaration *decl = new(ctx) ast_declaration($3, true, $4, NULL); decl->set_location(yylloc); $$ = $1; $$->declarations.push_tail(&decl->link); state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); } - | init_declarator_list ',' any_identifier '[' constant_expression ']' + | init_declarator_list ',' any_identifier array_specifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL); - decl->set_location(yylloc); - - $$ = $1; - $$->declarations.push_tail(&decl->link); - state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - } - | init_declarator_list ',' any_identifier '[' ']' '=' initializer - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7); - decl->set_location(yylloc); - - $$ = $1; - $$->declarations.push_tail(&decl->link); - state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto)); - } - | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8); + ast_declaration *decl = new(ctx) ast_declaration($3, true, $4, $6); decl->set_location(yylloc); $$ = $1; @@ -1053,37 +1034,19 @@ single_declaration: $$->set_location(yylloc); $$->declarations.push_tail(&decl->link); } - | fully_specified_type any_identifier '[' ']' + | fully_specified_type any_identifier array_specifier { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL); + ast_declaration *decl = new(ctx) ast_declaration($2, true, $3, NULL); $$ = new(ctx) ast_declarator_list($1); $$->set_location(yylloc); $$->declarations.push_tail(&decl->link); } - | fully_specified_type any_identifier '[' constant_expression ']' + | fully_specified_type any_identifier array_specifier '=' initializer { void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL); - - $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); - $$->declarations.push_tail(&decl->link); - } - | fully_specified_type any_identifier '[' ']' '=' initializer - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6); - - $$ = new(ctx) ast_declarator_list($1); - $$->set_location(yylloc); - $$->declarations.push_tail(&decl->link); - } - | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer - { - void *ctx = state; - ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7); + ast_declaration *decl = new(ctx) ast_declaration($2, true, $3, $5); $$ = new(ctx) ast_declarator_list($1); $$->set_location(yylloc); @@ -1584,19 +1547,51 @@ storage_qualifier: } ; -type_specifier: - type_specifier_nonarray - | type_specifier_nonarray '[' ']' +array_specifier: + '[' ']' + { + void *ctx = state; + $$ = new(ctx) ast_array_specifier(yylloc); + } + | '[' constant_expression ']' + { + void *ctx = state; + $$ = new(ctx) ast_array_specifier(yylloc, $2); + } + | array_specifier '[' ']' + { + $$ = $1; + + if (!state->ARB_arrays_of_arrays_enable) { + _mesa_glsl_error(& @1, state, + "GL_ARB_arrays_of_arrays " + "required for defining arrays of arrays"); + } else { + _mesa_glsl_error(& @1, state, + "only the outermost array dimension can " + "be unsized"); + } + } + | array_specifier '[' constant_expression ']' { $$ = $1; - $$->is_array = true; - $$->array_size = NULL; + + if (!state->ARB_arrays_of_arrays_enable) { + _mesa_glsl_error(& @1, state, + "GL_ARB_arrays_of_arrays " + "required for defining arrays of arrays"); + } + + $$->add_dimension($3); } - | type_specifier_nonarray '[' constant_expression ']' + ; + +type_specifier: + type_specifier_nonarray + | type_specifier_nonarray array_specifier { $$ = $1; - $$->is_array = true; - $$->array_size = $3; + $$->array_specifier = $2; } ; @@ -1779,16 +1774,10 @@ struct_declarator: $$ = new(ctx) ast_declaration($1, false, NULL, NULL); $$->set_location(yylloc); } - | any_identifier '[' ']' + | any_identifier array_specifier { void *ctx = state; - $$ = new(ctx) ast_declaration($1, true, NULL, NULL); - $$->set_location(yylloc); - } - | any_identifier '[' constant_expression ']' - { - void *ctx = state; - $$ = new(ctx) ast_declaration($1, true, $3, NULL); + $$ = new(ctx) ast_declaration($1, true, $2, NULL); $$->set_location(yylloc); } ; @@ -2288,15 +2277,10 @@ instance_name_opt: $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, $1, false, NULL); } - | NEW_IDENTIFIER '[' constant_expression ']' - { - $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, - $1, true, $3); - } - | NEW_IDENTIFIER '[' ']' + | NEW_IDENTIFIER array_specifier { $$ = new(state) ast_interface_block(*state->default_uniform_qualifier, - $1, true, NULL); + $1, true, $2); } ; |