summaryrefslogtreecommitdiffstats
path: root/src/glsl/glsl_parser.ypp
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl/glsl_parser.ypp')
-rw-r--r--src/glsl/glsl_parser.ypp206
1 files changed, 159 insertions, 47 deletions
diff --git a/src/glsl/glsl_parser.ypp b/src/glsl/glsl_parser.ypp
index 3982167c482..2c0498ece7a 100644
--- a/src/glsl/glsl_parser.ypp
+++ b/src/glsl/glsl_parser.ypp
@@ -93,7 +93,8 @@
%token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
%token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
%token STRUCT VOID_TOK WHILE
-%token <identifier> IDENTIFIER
+%token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
+%type <identifier> any_identifier
%token <real> FLOATCONSTANT
%token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
%token <identifier> FIELD_SELECTION
@@ -184,6 +185,10 @@
%type <expression> function_call_generic
%type <expression> function_call_or_method
%type <expression> function_call
+%type <expression> method_call_generic
+%type <expression> method_call_header_with_parameters
+%type <expression> method_call_header_no_parameters
+%type <expression> method_call_header
%type <n> assignment_operator
%type <n> unary_operator
%type <expression> function_identifier
@@ -214,31 +219,51 @@ 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:
/* blank - no #version specified: defaults are already set */
| VERSION INTCONSTANT EOL
{
+ bool supported = false;
+
switch ($2) {
case 100:
state->es_shader = true;
+ supported = state->Const.GLSL_100ES;
+ break;
case 110:
+ supported = state->Const.GLSL_110;
+ break;
case 120:
+ supported = state->Const.GLSL_120;
+ break;
case 130:
- /* FINISHME: Check against implementation support versions. */
- state->language_version = $2;
- state->version_string =
- talloc_asprintf(state, "GLSL%s %d.%02d",
- state->es_shader ? " ES" : "",
- state->language_version / 100,
- state->language_version % 100);
+ supported = state->Const.GLSL_130;
break;
default:
- _mesa_glsl_error(& @2, state, "Shading language version"
- "%u is not supported\n", $2);
+ supported = false;
break;
}
+
+ state->language_version = $2;
+ state->version_string =
+ ralloc_asprintf(state, "GLSL%s %d.%02d",
+ state->es_shader ? " ES" : "",
+ state->language_version / 100,
+ state->language_version % 100);
+
+ if (!supported) {
+ _mesa_glsl_error(& @2, state, "%s is not supported. "
+ "Supported versions are: %s\n",
+ state->version_string,
+ state->supported_version_string);
+ }
}
;
@@ -264,8 +289,14 @@ extension_statement_list:
| extension_statement_list extension_statement
;
+any_identifier:
+ IDENTIFIER
+ | TYPE_IDENTIFIER
+ | NEW_IDENTIFIER
+ ;
+
extension_statement:
- EXTENSION IDENTIFIER COLON IDENTIFIER EOL
+ EXTENSION any_identifier COLON any_identifier EOL
{
if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
YYERROR;
@@ -294,6 +325,7 @@ external_declaration_list:
variable_identifier:
IDENTIFIER
+ | NEW_IDENTIFIER
;
primary_expression:
@@ -350,7 +382,7 @@ postfix_expression:
{
$$ = $1;
}
- | postfix_expression '.' IDENTIFIER
+ | postfix_expression '.' any_identifier
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
@@ -381,7 +413,7 @@ function_call:
function_call_or_method:
function_call_generic
- | postfix_expression '.' function_call_generic
+ | postfix_expression '.' method_call_generic
{
void *ctx = state;
$$ = new(ctx) ast_expression(ast_field_selection, $1, $3, NULL);
@@ -428,7 +460,7 @@ function_identifier:
$$ = new(ctx) ast_function_expression($1);
$$->set_location(yylloc);
}
- | IDENTIFIER
+ | variable_identifier
{
void *ctx = state;
ast_expression *callee = new(ctx) ast_expression($1);
@@ -444,6 +476,44 @@ function_identifier:
}
;
+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);
+ }
+ ;
+
// Grammar Note: No traditional style type casts.
unary_expression:
postfix_expression
@@ -694,6 +764,7 @@ constant_expression:
declaration:
function_prototype ';'
{
+ state->symbols->pop_scope();
$$ = $1;
}
| init_declarator_list ';'
@@ -731,18 +802,21 @@ function_header_with_parameters:
;
function_header:
- fully_specified_type IDENTIFIER '('
+ fully_specified_type variable_identifier '('
{
void *ctx = state;
$$ = new(ctx) ast_function();
$$->set_location(yylloc);
$$->return_type = $1;
$$->identifier = $2;
+
+ state->symbols->add_function(new(state) ir_function($2));
+ state->symbols->push_scope();
}
;
parameter_declarator:
- type_specifier IDENTIFIER
+ type_specifier any_identifier
{
void *ctx = state;
$$ = new(ctx) ast_parameter_declarator();
@@ -752,7 +826,7 @@ parameter_declarator:
$$->type->specifier = $1;
$$->identifier = $2;
}
- | type_specifier IDENTIFIER '[' constant_expression ']'
+ | type_specifier any_identifier '[' constant_expression ']'
{
void *ctx = state;
$$ = new(ctx) ast_parameter_declarator();
@@ -830,7 +904,7 @@ parameter_type_specifier:
init_declarator_list:
single_declaration
- | init_declarator_list ',' IDENTIFIER
+ | init_declarator_list ',' any_identifier
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, NULL);
@@ -838,8 +912,9 @@ 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 ',' IDENTIFIER '[' ']'
+ | init_declarator_list ',' any_identifier '[' ']'
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, NULL);
@@ -847,8 +922,9 @@ 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 ',' IDENTIFIER '[' constant_expression ']'
+ | init_declarator_list ',' any_identifier '[' constant_expression ']'
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, NULL);
@@ -856,8 +932,9 @@ 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 ',' IDENTIFIER '[' ']' '=' initializer
+ | init_declarator_list ',' any_identifier '[' ']' '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, true, NULL, $7);
@@ -865,8 +942,9 @@ 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 ',' IDENTIFIER '[' constant_expression ']' '=' initializer
+ | init_declarator_list ',' any_identifier '[' constant_expression ']' '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, true, $5, $8);
@@ -874,8 +952,9 @@ 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 ',' IDENTIFIER '=' initializer
+ | init_declarator_list ',' any_identifier '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($3, false, NULL, $5);
@@ -883,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));
}
;
@@ -899,7 +979,7 @@ single_declaration:
$$->set_location(yylloc);
}
}
- | fully_specified_type IDENTIFIER
+ | fully_specified_type any_identifier
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, false, NULL, NULL);
@@ -908,7 +988,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | fully_specified_type IDENTIFIER '[' ']'
+ | fully_specified_type any_identifier '[' ']'
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, NULL);
@@ -917,7 +997,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | fully_specified_type IDENTIFIER '[' constant_expression ']'
+ | fully_specified_type any_identifier '[' constant_expression ']'
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, NULL);
@@ -926,7 +1006,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | fully_specified_type IDENTIFIER '[' ']' '=' initializer
+ | fully_specified_type any_identifier '[' ']' '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, true, NULL, $6);
@@ -935,7 +1015,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
+ | fully_specified_type any_identifier '[' constant_expression ']' '=' initializer
{
void *ctx = state;
ast_declaration *decl = new(ctx) ast_declaration($2, true, $4, $7);
@@ -944,7 +1024,7 @@ single_declaration:
$$->set_location(yylloc);
$$->declarations.push_tail(&decl->link);
}
- | 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);
@@ -953,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);
@@ -1012,13 +1092,14 @@ layout_qualifier_id_list:
;
layout_qualifier_id:
- IDENTIFIER
+ any_identifier
{
bool got_one = false;
memset(& $$, 0, sizeof($$));
- if (state->ARB_fragment_coord_conventions_enable) {
+ /* Layout qualifiers for ARB_fragment_coord_conventions. */
+ if (!got_one && state->ARB_fragment_coord_conventions_enable) {
if (strcmp($1, "origin_upper_left") == 0) {
got_one = true;
$$.flags.q.origin_upper_left = 1;
@@ -1026,22 +1107,44 @@ layout_qualifier_id:
got_one = true;
$$.flags.q.pixel_center_integer = 1;
}
+
+ if (got_one && state->ARB_fragment_coord_conventions_warn) {
+ _mesa_glsl_warning(& @1, state,
+ "GL_ARB_fragment_coord_conventions layout "
+ "identifier `%s' used\n", $1);
+ }
+ }
+
+ /* Layout qualifiers for AMD_conservative_depth. */
+ if (!got_one && state->AMD_conservative_depth_enable) {
+ if (strcmp($1, "depth_any") == 0) {
+ got_one = true;
+ $$.flags.q.depth_any = 1;
+ } else if (strcmp($1, "depth_greater") == 0) {
+ got_one = true;
+ $$.flags.q.depth_greater = 1;
+ } else if (strcmp($1, "depth_less") == 0) {
+ got_one = true;
+ $$.flags.q.depth_less = 1;
+ } else if (strcmp($1, "depth_unchanged") == 0) {
+ got_one = true;
+ $$.flags.q.depth_unchanged = 1;
+ }
+
+ if (got_one && state->AMD_conservative_depth_warn) {
+ _mesa_glsl_warning(& @1, state,
+ "GL_AMD_conservative_depth "
+ "layout qualifier `%s' is used\n", $1);
+ }
}
- /* If the identifier didn't match any known layout identifiers,
- * emit an error.
- */
if (!got_one) {
_mesa_glsl_error(& @1, state, "unrecognized layout identifier "
"`%s'\n", $1);
YYERROR;
- } else if (state->ARB_fragment_coord_conventions_warn) {
- _mesa_glsl_warning(& @1, state,
- "GL_ARB_fragment_coord_conventions layout "
- "identifier `%s' used\n", $1);
}
}
- | IDENTIFIER '=' INTCONSTANT
+ | any_identifier '=' INTCONSTANT
{
bool got_one = false;
@@ -1229,7 +1332,7 @@ type_specifier_nonarray:
$$ = new(ctx) ast_type_specifier($1);
$$->set_location(yylloc);
}
- | IDENTIFIER
+ | TYPE_IDENTIFIER
{
void *ctx = state;
$$ = new(ctx) ast_type_specifier($1);
@@ -1325,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 '}'
{
@@ -1381,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);
@@ -1427,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();
}
;
@@ -1519,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);
@@ -1639,5 +1749,7 @@ function_definition:
$$->set_location(yylloc);
$$->prototype = $1;
$$->body = $2;
+
+ state->symbols->pop_scope();
}
;