From 0da1a2cc369052643ccaea75a1722cc37652d82a Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 21 Jan 2014 15:41:26 -0800 Subject: glsl: Simplify aggregate type inference to prepare for ARB_arrays_of_arrays. Most of the time it is not necessary to perform type inference to compile GLSL; the type of every expression can be inferred from the contents of the expression itself (and previous type declarations). The exception is aggregate initializers: their type is determined by the LHS of the variable being assigned to. For example, in the statement: mat2 foo = { { 1, 2 }, { 3, 4 } }; the type of { 1, 2 } is only known to be vec2 (as opposed to, say, ivec2, uvec2, int[2], or a struct) because of the fact that the result is being assigned to a mat2. Previous to this patch, we handled this situation by doing some type inference during parsing: when parsing a declaration like the one above, we would call _mesa_set_aggregate_type(), which would infer the type of each aggregate initializer and store it in the corresponding ast_aggregate_initializer::constructor_type field. Since this happened at parse time, we couldn't do the type inference using glsl_type objects; we had to use ast_type_specifiers, which are much more awkward to work with. Things are about to get more complicated when we add support for ARB_arrays_of_arrays. This patch simplifies things by postponing the call to _mesa_set_aggregate_type() until ast-to-hir time, when we have access to glsl_type objects. As a side benefit, we only need to have one call to _mesa_set_aggregate_type() now, instead of six. Reviewed-by: Matt Turner --- src/glsl/glsl_parser.yy | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src/glsl/glsl_parser.yy') diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 1c56d6f145a..5451b764a77 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -1012,11 +1012,6 @@ 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 { @@ -1027,11 +1022,6 @@ 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 { @@ -1042,10 +1032,6 @@ 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); - } } ; @@ -1093,11 +1079,6 @@ 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 { @@ -1107,11 +1088,6 @@ 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 { @@ -1121,9 +1097,6 @@ 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. { -- cgit v1.2.3