summaryrefslogtreecommitdiff
path: root/src/glsl/glsl_parser.ypp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2011-01-27 17:52:19 -0800
committerIan Romanick <ian.d.romanick@intel.com>2011-02-11 14:12:43 -0800
commit884215894493bdbc55abd567c121c9df06ae3bc7 (patch)
treeb1014ccae0f8a99d24021ac9ebd682f878898040 /src/glsl/glsl_parser.ypp
parentf4b812e1a661448cf4b624f283c949a54b52e9d5 (diff)
glsl: Finish out the reduce/reduce error fixes
Track variables, functions, and types during parsing. Use this information in the lexer to return the currect "type" for identifiers. Change the handling of structure constructors. They will now show up in the AST as constructors (instead of plain function calls). Fixes piglit tests constructor-18.vert, constructor-19.vert, and constructor-20.vert. Also fixes bugzilla #29926. NOTE: This is a candidate for the 7.9 and 7.10 branches.
Diffstat (limited to 'src/glsl/glsl_parser.ypp')
-rw-r--r--src/glsl/glsl_parser.ypp42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/glsl/glsl_parser.ypp b/src/glsl/glsl_parser.ypp
index dd23279aaa..2c0498ece7 100644
--- a/src/glsl/glsl_parser.ypp
+++ b/src/glsl/glsl_parser.ypp
@@ -219,6 +219,11 @@ translation_unit:
_mesa_glsl_initialize_types(state);
}
external_declaration_list
+ {
+ delete state->symbols;
+ state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
+ _mesa_glsl_initialize_types(state);
+ }
;
version_statement:
@@ -759,6 +764,7 @@ constant_expression:
declaration:
function_prototype ';'
{
+ state->symbols->pop_scope();
$$ = $1;
}
| init_declarator_list ';'
@@ -803,6 +809,9 @@ function_header:
$$->set_location(yylloc);
$$->return_type = $1;
$$->identifier = $2;
+
+ state->symbols->add_function(new(state) ir_function($2));
+ state->symbols->push_scope();
}
;
@@ -903,6 +912,7 @@ init_declarator_list:
$$ = $1;
$$->declarations.push_tail(&decl->link);
+ state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
| init_declarator_list ',' any_identifier '[' ']'
{
@@ -912,6 +922,7 @@ init_declarator_list:
$$ = $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 ']'
{
@@ -921,6 +932,7 @@ init_declarator_list:
$$ = $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
{
@@ -930,6 +942,7 @@ init_declarator_list:
$$ = $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
{
@@ -939,6 +952,7 @@ init_declarator_list:
$$ = $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
{
@@ -948,6 +962,7 @@ init_declarator_list:
$$ = $1;
$$->declarations.push_tail(&decl->link);
+ state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
;
@@ -1018,7 +1033,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | INVARIANT IDENTIFIER // Vertex only.
+ | INVARIANT variable_identifier // Vertex only.
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
@@ -1077,7 +1092,7 @@ layout_qualifier_id_list:
;
layout_qualifier_id:
- IDENTIFIER
+ any_identifier
{
bool got_one = false;
@@ -1129,7 +1144,7 @@ layout_qualifier_id:
YYERROR;
}
}
- | IDENTIFIER '=' INTCONSTANT
+ | any_identifier '=' INTCONSTANT
{
bool got_one = false;
@@ -1413,11 +1428,12 @@ precision_qualifier:
;
struct_specifier:
- STRUCT IDENTIFIER '{' struct_declaration_list '}'
+ STRUCT any_identifier '{' struct_declaration_list '}'
{
void *ctx = state;
$$ = new(ctx) ast_struct_specifier($2, $4);
$$->set_location(yylloc);
+ state->symbols->add_type($2, glsl_type::void_type);
}
| STRUCT '{' struct_declaration_list '}'
{
@@ -1469,13 +1485,14 @@ struct_declarator_list:
;
struct_declarator:
- IDENTIFIER
+ any_identifier
{
void *ctx = state;
$$ = new(ctx) ast_declaration($1, false, NULL, NULL);
$$->set_location(yylloc);
+ state->symbols->add_variable(new(state) ir_variable(NULL, $1, ir_var_auto));
}
- | IDENTIFIER '[' constant_expression ']'
+ | any_identifier '[' constant_expression ']'
{
void *ctx = state;
$$ = new(ctx) ast_declaration($1, true, $3, NULL);
@@ -1515,11 +1532,16 @@ compound_statement:
$$ = new(ctx) ast_compound_statement(true, NULL);
$$->set_location(yylloc);
}
- | '{' statement_list '}'
+ | '{'
+ {
+ state->symbols->push_scope();
+ }
+ statement_list '}'
{
void *ctx = state;
- $$ = new(ctx) ast_compound_statement(true, $2);
+ $$ = new(ctx) ast_compound_statement(true, $3);
$$->set_location(yylloc);
+ state->symbols->pop_scope();
}
;
@@ -1607,7 +1629,7 @@ condition:
{
$$ = (ast_node *) $1;
}
- | fully_specified_type IDENTIFIER '=' initializer
+ | fully_specified_type any_identifier '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, $4);
@@ -1727,5 +1749,7 @@ function_definition:
$$->set_location(yylloc);
$$->prototype = $1;
$$->body = $2;
+
+ state->symbols->pop_scope();
}
;