Replace builtin_types.h generation with the generated output.
[mesa.git] / glsl_parser.ypp
index 2f337b127c53e58c78acb1e69ef01a0c04a82fe4..250c51c7ee3feb4e6e204cc00c30e2f47ce6c60e 100644 (file)
@@ -28,7 +28,6 @@
     
 #include "ast.h"
 #include "glsl_parser_extras.h"
-#include "symbol_table.h"
 #include "glsl_types.h"
 
 #define YYLEX_PARAM state->scanner
 %type <expression> function_call
 %type <n> assignment_operator
 %type <n> unary_operator
-%type <node> function_identifier
+%type <expression> function_identifier
 %type <node> external_declaration
 %type <declarator_list> init_declarator_list
 %type <declarator_list> single_declaration
@@ -191,13 +190,13 @@ translation_unit:
        {
           _mesa_glsl_initialize_types(state);
        }
-       external_declaration_list
+       extension_statement_list external_declaration_list
        |
        {
           state->language_version = 110;
           _mesa_glsl_initialize_types(state);
        }
-       external_declaration_list
+       extension_statement_list external_declaration_list
        ;
 
 version_statement:
@@ -218,6 +217,20 @@ version_statement:
        }
        ;
 
+extension_statement_list:
+
+       | extension_statement_list extension_statement
+       ;
+
+extension_statement:
+       EXTENSION IDENTIFIER COLON IDENTIFIER EOL
+       {
+          if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
+             YYERROR;
+          }
+       }
+       ;
+
 external_declaration_list:
        external_declaration
        {
@@ -239,26 +252,31 @@ primary_expression:
        variable_identifier
        {
           $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.identifier = $1;
        }
        | INTCONSTANT
        {
           $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.int_constant = $1;
        }
        | UINTCONSTANT
        {
           $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.uint_constant = $1;
        }
        | FLOATCONSTANT
        {
           $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.float_constant = $1;
        }
        | BOOLCONSTANT
        {
           $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.bool_constant = $1;
        }
        | '(' expression ')'
@@ -272,6 +290,7 @@ postfix_expression:
        | postfix_expression '[' integer_expression ']'
        {
           $$ = new ast_expression(ast_array_index, $1, $3, NULL);
+          $$->set_location(yylloc);
        }
        | function_call
        {
@@ -280,15 +299,18 @@ postfix_expression:
        | postfix_expression '.' IDENTIFIER
        {
           $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
+          $$->set_location(yylloc);
           $$->primary_expression.identifier = $3;
        }
        | postfix_expression INC_OP
        {
           $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
+          $$->set_location(yylloc);
        }
        | postfix_expression DEC_OP
        {
           $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -305,6 +327,7 @@ function_call_or_method:
        | postfix_expression '.' function_call_generic
        {
           $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -322,11 +345,13 @@ function_call_header_with_parameters:
        function_call_header assignment_expression
        {
           $$ = $1;
+          $$->set_location(yylloc);
           $$->subexpressions[1] = $2;
        }
        | function_call_header_with_parameters ',' assignment_expression
        {
           $$ = $1;
+          $$->set_location(yylloc);
           insert_at_tail((struct simple_node *) $$->subexpressions[1],
                          (struct simple_node *) $3);
        }
@@ -337,23 +362,25 @@ function_call_header_with_parameters:
        // recognized through "type_specifier".
 function_call_header:
        function_identifier '('
-       {
-          $$ = new ast_function_expression($1);
-       }
        ;
 
 function_identifier:
        type_specifier
        {
-          $$ = (struct ast_node *) $1;
+          $$ = new ast_function_expression($1);
+          $$->set_location(yylloc);
        }
        | IDENTIFIER
        {
-          $$ = new ast_expression($1);
+          ast_expression *callee = new ast_expression($1);
+          $$ = new ast_function_expression(callee);
+          $$->set_location(yylloc);
        }
        | FIELD_SELECTION
        {
-          $$ = new ast_expression($1);
+          ast_expression *callee = new ast_expression($1);
+          $$ = new ast_function_expression(callee);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -363,14 +390,17 @@ unary_expression:
        | INC_OP unary_expression
        {
           $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
+          $$->set_location(yylloc);
        }
        | DEC_OP unary_expression
        {
           $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
+          $$->set_location(yylloc);
        }
        | unary_operator unary_expression
        {
           $$ = new ast_expression($1, $2, NULL, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -387,14 +417,17 @@ multiplicative_expression:
        | multiplicative_expression '*' unary_expression
        {
           $$ = new ast_expression_bin(ast_mul, $1, $3);
+          $$->set_location(yylloc);
        }
        | multiplicative_expression '/' unary_expression
        {
           $$ = new ast_expression_bin(ast_div, $1, $3);
+          $$->set_location(yylloc);
        }
        | multiplicative_expression '%' unary_expression
        {
           $$ = new ast_expression_bin(ast_mod, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -403,10 +436,12 @@ additive_expression:
        | additive_expression '+' multiplicative_expression
        {
           $$ = new ast_expression_bin(ast_add, $1, $3);
+          $$->set_location(yylloc);
        }
        | additive_expression '-' multiplicative_expression
        {
           $$ = new ast_expression_bin(ast_sub, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -415,10 +450,12 @@ shift_expression:
        | shift_expression LEFT_OP additive_expression
        {
           $$ = new ast_expression_bin(ast_lshift, $1, $3);
+          $$->set_location(yylloc);
        }
        | shift_expression RIGHT_OP additive_expression
        {
           $$ = new ast_expression_bin(ast_rshift, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -427,18 +464,22 @@ relational_expression:
        | relational_expression '<' shift_expression
        {
           $$ = new ast_expression_bin(ast_less, $1, $3);
+          $$->set_location(yylloc);
        }
        | relational_expression '>' shift_expression
        {
           $$ = new ast_expression_bin(ast_greater, $1, $3);
+          $$->set_location(yylloc);
        }
        | relational_expression LE_OP shift_expression
        {
           $$ = new ast_expression_bin(ast_lequal, $1, $3);
+          $$->set_location(yylloc);
        }
        | relational_expression GE_OP shift_expression
        {
           $$ = new ast_expression_bin(ast_gequal, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -447,10 +488,12 @@ equality_expression:
        | equality_expression EQ_OP relational_expression
        {
           $$ = new ast_expression_bin(ast_equal, $1, $3);
+          $$->set_location(yylloc);
        }
        | equality_expression NE_OP relational_expression
        {
           $$ = new ast_expression_bin(ast_nequal, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -459,6 +502,7 @@ and_expression:
        | and_expression '&' equality_expression
        {
           $$ = new ast_expression_bin(ast_bit_or, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -467,6 +511,7 @@ exclusive_or_expression:
        | exclusive_or_expression '^' and_expression
        {
           $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -475,6 +520,7 @@ inclusive_or_expression:
        | inclusive_or_expression '|' exclusive_or_expression
        {
           $$ = new ast_expression_bin(ast_bit_or, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -483,6 +529,7 @@ logical_and_expression:
        | logical_and_expression AND_OP inclusive_or_expression
        {
           $$ = new ast_expression_bin(ast_logic_and, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -491,6 +538,7 @@ logical_xor_expression:
        | logical_xor_expression XOR_OP logical_and_expression
        {
           $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -499,6 +547,7 @@ logical_or_expression:
        | logical_or_expression OR_OP logical_xor_expression
        {
           $$ = new ast_expression_bin(ast_logic_or, $1, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -507,6 +556,7 @@ conditional_expression:
        | logical_or_expression '?' expression ':' assignment_expression
        {
           $$ = new ast_expression(ast_conditional, $1, $3, $5);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -515,6 +565,7 @@ assignment_expression:
        | unary_expression assignment_operator assignment_expression
        {
           $$ = new ast_expression($2, $1, $3, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -541,6 +592,7 @@ expression:
        {
           if ($1->oper != ast_sequence) {
              $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
+             $$->set_location(yylloc);
              insert_at_tail(& $$->expressions, $1);
           } else {
              $$ = $1;
@@ -582,13 +634,13 @@ function_header_with_parameters:
        function_header parameter_declaration
        {
           $$ = $1;
-          insert_at_head(& $$->parameters,
+          insert_at_tail(& $$->parameters,
                          (struct simple_node *) $2);
        }
        | function_header_with_parameters ',' parameter_declaration
        {
           $$ = $1;
-          insert_at_head(& $$->parameters,
+          insert_at_tail(& $$->parameters,
                          (struct simple_node *) $3);
        }
        ;
@@ -597,6 +649,7 @@ function_header:
        fully_specified_type IDENTIFIER '('
        {
           $$ = new ast_function();
+          $$->set_location(yylloc);
           $$->return_type = $1;
           $$->identifier = $2;
        }
@@ -606,14 +659,18 @@ parameter_declarator:
        type_specifier IDENTIFIER
        {
           $$ = new ast_parameter_declarator();
+          $$->set_location(yylloc);
           $$->type = new ast_fully_specified_type();
+          $$->type->set_location(yylloc);
           $$->type->specifier = $1;
           $$->identifier = $2;
        }
        | type_specifier IDENTIFIER '[' constant_expression ']'
        {
           $$ = new ast_parameter_declarator();
+          $$->set_location(yylloc);
           $$->type = new ast_fully_specified_type();
+          $$->type->set_location(yylloc);
           $$->type->specifier = $1;
           $$->identifier = $2;
           $$->is_array = true;
@@ -639,6 +696,7 @@ parameter_declaration:
           $1.i |= $2.i;
 
           $$ = new ast_parameter_declarator();
+          $$->set_location(yylloc);
           $$->type = new ast_fully_specified_type();
           $$->type->qualifier = $1.q;
           $$->type->specifier = $3;
@@ -646,6 +704,7 @@ parameter_declaration:
        | parameter_qualifier parameter_type_specifier
        {
           $$ = new ast_parameter_declarator();
+          $$->set_location(yylloc);
           $$->type = new ast_fully_specified_type();
           $$->type->qualifier = $1.q;
           $$->type->specifier = $2;
@@ -668,6 +727,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER
        {
           ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -676,6 +736,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER '[' ']'
        {
           ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -684,6 +745,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
        {
           ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -692,6 +754,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
        {
           ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -700,6 +763,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
        {
           ast_declaration *decl = new ast_declaration($3, true, $5, $8);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -708,6 +772,7 @@ init_declarator_list:
        | init_declarator_list ',' IDENTIFIER '=' initializer
        {
           ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
+          decl->set_location(yylloc);
 
           $$ = $1;
           insert_at_tail(& $$->declarations,
@@ -720,12 +785,14 @@ single_declaration:
        fully_specified_type
        {
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
        }
        | fully_specified_type IDENTIFIER
        {
           ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -734,6 +801,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -742,6 +810,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -750,6 +819,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -758,6 +828,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, true, $4, $7);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -766,6 +837,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
 
           $$ = new ast_declarator_list($1);
+          $$->set_location(yylloc);
           insert_at_tail(& $$->declarations,
                          (struct simple_node *) decl);
        }
@@ -774,6 +846,7 @@ single_declaration:
           ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
 
           $$ = new ast_declarator_list(NULL);
+          $$->set_location(yylloc);
           $$->invariant = true;
 
           insert_at_tail(& $$->declarations,
@@ -785,11 +858,13 @@ fully_specified_type:
        type_specifier
        {
           $$ = new ast_fully_specified_type();
+          $$->set_location(yylloc);
           $$->specifier = $1;
        }
        | type_qualifier type_specifier
        {
           $$ = new ast_fully_specified_type();
+          $$->set_location(yylloc);
           $$->qualifier = $1.q;
           $$->specifier = $2;
        }
@@ -859,16 +934,17 @@ type_specifier_nonarray:
        basic_type_specifier_nonarray
        {
           $$ = new ast_type_specifier($1);
+          $$->set_location(yylloc);
        }
        | struct_specifier
        {
-          $$ = new ast_type_specifier(ast_struct);
-          $$->structure = $1;
+          $$ = new ast_type_specifier($1);
+          $$->set_location(yylloc);
        }
        | TYPE_NAME
        {
-          $$ = new ast_type_specifier(ast_type_name);
-          $$->type_name = $1;
+          $$ = new ast_type_specifier($1);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -904,10 +980,12 @@ basic_type_specifier_nonarray:
        | MAT4X4                { $$ = ast_mat4; }
        | SAMPLER1D             { $$ = ast_sampler1d; }
        | SAMPLER2D             { $$ = ast_sampler2d; }
+       | SAMPLER2DRECT         { $$ = ast_sampler2drect; }
        | SAMPLER3D             { $$ = ast_sampler3d; }
        | SAMPLERCUBE           { $$ = ast_samplercube; }
        | SAMPLER1DSHADOW       { $$ = ast_sampler1dshadow; }
        | SAMPLER2DSHADOW       { $$ = ast_sampler2dshadow; }
+       | SAMPLER2DRECTSHADOW   { $$ = ast_sampler2drectshadow; }
        | SAMPLERCUBESHADOW     { $$ = ast_samplercubeshadow; }
        | SAMPLER1DARRAY        { $$ = ast_sampler1darray; }
        | SAMPLER2DARRAY        { $$ = ast_sampler2darray; }
@@ -937,12 +1015,12 @@ struct_specifier:
        STRUCT IDENTIFIER '{' struct_declaration_list '}'
        {
           $$ = new ast_struct_specifier($2, $4);
-
-          _mesa_symbol_table_add_symbol(state->symbols, 0, $2, $$);
+          $$->set_location(yylloc);
        }
        | STRUCT '{' struct_declaration_list '}'
        {
           $$ = new ast_struct_specifier(NULL, $3);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -963,9 +1041,11 @@ struct_declaration:
        type_specifier struct_declarator_list ';'
        {
           ast_fully_specified_type *type = new ast_fully_specified_type();
+          type->set_location(yylloc);
 
           type->specifier = $1;
           $$ = new ast_declarator_list(type);
+          $$->set_location(yylloc);
 
           insert_at_tail((struct simple_node *) $2,
                          & $$->declarations);
@@ -986,10 +1066,12 @@ struct_declarator:
        IDENTIFIER
        {
           $$ = new ast_declaration($1, false, NULL, NULL);
+          $$->set_location(yylloc);
        }
        | IDENTIFIER '[' constant_expression ']'
        {
           $$ = new ast_declaration($1, true, $3, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1031,10 +1113,12 @@ compound_statement:
        '{' '}'
        {
           $$ = new ast_compound_statement(true, NULL);
+          $$->set_location(yylloc);
        }
        | '{' statement_list '}'
        {
           $$ = new ast_compound_statement(true, $2);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1047,10 +1131,12 @@ compound_statement_no_new_scope:
        '{' '}'
        {
           $$ = new ast_compound_statement(false, NULL);
+          $$->set_location(yylloc);
        }
        | '{' statement_list '}'
        {
           $$ = new ast_compound_statement(false, $2);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1081,10 +1167,12 @@ expression_statement:
        ';'
        {
           $$ = new ast_expression_statement(NULL);
+          $$->set_location(yylloc);
        }
        | expression ';'
        {
           $$ = new ast_expression_statement($1);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1092,6 +1180,7 @@ selection_statement_matched:
        IF '(' expression ')' statement_matched ELSE statement_matched
        {
           $$ = new ast_selection_statement($3, $5, $7);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1099,14 +1188,17 @@ selection_statement_unmatched:
        IF '(' expression ')' statement_matched
        {
           $$ = new ast_selection_statement($3, $5, NULL);
+          $$->set_location(yylloc);
        }
        | IF '(' expression ')' statement_unmatched
        {
           $$ = new ast_selection_statement($3, $5, NULL);
+          $$->set_location(yylloc);
        }
        | IF '(' expression ')' statement_matched ELSE statement_unmatched
        {
           $$ = new ast_selection_statement($3, $5, $7);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1119,6 +1211,8 @@ condition:
        {
           ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
           ast_declarator_list *declarator = new ast_declarator_list($1);
+          decl->set_location(yylloc);
+          declarator->set_location(yylloc);
 
           insert_at_tail(& declarator->declarations,
                          (struct simple_node *) decl);
@@ -1141,16 +1235,19 @@ iteration_statement:
        {
           $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
                                            NULL, $3, NULL, $5);
+          $$->set_location(yylloc);
        }
        | DO statement WHILE '(' expression ')' ';'
        {
           $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
                                            NULL, $5, NULL, $2);
+          $$->set_location(yylloc);
        }
        | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
        {
           $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
                                            $3, $4.cond, $4.rest, $6);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1185,22 +1282,27 @@ jump_statement:
        CONTINUE ';' 
        {
           $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
+          $$->set_location(yylloc);
        }
        | BREAK ';'
        {
           $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
+          $$->set_location(yylloc);
        }
        | RETURN ';'
        {
           $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
+          $$->set_location(yylloc);
        }
        | RETURN expression ';'
        {
           $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
+          $$->set_location(yylloc);
        }
        | DISCARD ';' // Fragment shader only.
        {
           $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
+          $$->set_location(yylloc);
        }
        ;
 
@@ -1213,6 +1315,7 @@ function_definition:
        function_prototype compound_statement_no_new_scope
        {
           $$ = new ast_function_definition();
+          $$->set_location(yylloc);
           $$->prototype = $1;
           $$->body = $2;
        }