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 ')'
| postfix_expression '[' integer_expression ']'
{
$$ = new ast_expression(ast_array_index, $1, $3, NULL);
+ $$->set_location(yylloc);
}
| function_call
{
| 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);
}
;
| postfix_expression '.' function_call_generic
{
$$ = new ast_expression(ast_field_selection, $1, $3, NULL);
+ $$->set_location(yylloc);
}
;
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);
}
type_specifier
{
$$ = new ast_function_expression($1);
+ $$->set_location(yylloc);
}
| IDENTIFIER
{
ast_expression *callee = new ast_expression($1);
$$ = new ast_function_expression(callee);
+ $$->set_location(yylloc);
}
| FIELD_SELECTION
{
ast_expression *callee = new ast_expression($1);
$$ = new ast_function_expression(callee);
+ $$->set_location(yylloc);
}
;
| 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);
}
;
| 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);
}
;
| 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);
}
;
| 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);
}
;
| 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);
}
;
| 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);
}
;
| and_expression '&' equality_expression
{
$$ = new ast_expression_bin(ast_bit_or, $1, $3);
+ $$->set_location(yylloc);
}
;
| exclusive_or_expression '^' and_expression
{
$$ = new ast_expression_bin(ast_bit_xor, $1, $3);
+ $$->set_location(yylloc);
}
;
| inclusive_or_expression '|' exclusive_or_expression
{
$$ = new ast_expression_bin(ast_bit_or, $1, $3);
+ $$->set_location(yylloc);
}
;
| logical_and_expression AND_OP inclusive_or_expression
{
$$ = new ast_expression_bin(ast_logic_and, $1, $3);
+ $$->set_location(yylloc);
}
;
| logical_xor_expression XOR_OP logical_and_expression
{
$$ = new ast_expression_bin(ast_logic_xor, $1, $3);
+ $$->set_location(yylloc);
}
;
| logical_or_expression OR_OP logical_xor_expression
{
$$ = new ast_expression_bin(ast_logic_or, $1, $3);
+ $$->set_location(yylloc);
}
;
| logical_or_expression '?' expression ':' assignment_expression
{
$$ = new ast_expression(ast_conditional, $1, $3, $5);
+ $$->set_location(yylloc);
}
;
| unary_expression assignment_operator assignment_expression
{
$$ = new ast_expression($2, $1, $3, NULL);
+ $$->set_location(yylloc);
}
;
{
if ($1->oper != ast_sequence) {
$$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
+ $$->set_location(yylloc);
insert_at_tail(& $$->expressions, $1);
} else {
$$ = $1;
fully_specified_type IDENTIFIER '('
{
$$ = new ast_function();
+ $$->set_location(yylloc);
$$->return_type = $1;
$$->identifier = $2;
}
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;
$1.i |= $2.i;
$$ = new ast_parameter_declarator();
+ $$->set_location(yylloc);
$$->type = new ast_fully_specified_type();
$$->type->qualifier = $1.q;
$$->type->specifier = $3;
| 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;
| init_declarator_list ',' IDENTIFIER
{
ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
+ decl->set_location(yylloc);
$$ = $1;
insert_at_tail(& $$->declarations,
| init_declarator_list ',' IDENTIFIER '[' ']'
{
ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
+ decl->set_location(yylloc);
$$ = $1;
insert_at_tail(& $$->declarations,
| 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,
| init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
{
ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
+ decl->set_location(yylloc);
$$ = $1;
insert_at_tail(& $$->declarations,
| 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,
| init_declarator_list ',' IDENTIFIER '=' initializer
{
ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
+ decl->set_location(yylloc);
$$ = $1;
insert_at_tail(& $$->declarations,
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
$$ = new ast_declarator_list(NULL);
+ $$->set_location(yylloc);
$$->invariant = true;
insert_at_tail(& $$->declarations,
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;
}
basic_type_specifier_nonarray
{
$$ = new ast_type_specifier($1);
+ $$->set_location(yylloc);
}
| struct_specifier
{
$$ = new ast_type_specifier($1);
+ $$->set_location(yylloc);
}
| TYPE_NAME
{
$$ = new ast_type_specifier($1);
+ $$->set_location(yylloc);
}
;
STRUCT IDENTIFIER '{' struct_declaration_list '}'
{
$$ = new ast_struct_specifier($2, $4);
+ $$->set_location(yylloc);
}
| STRUCT '{' struct_declaration_list '}'
{
$$ = new ast_struct_specifier(NULL, $3);
+ $$->set_location(yylloc);
}
;
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);
IDENTIFIER
{
$$ = new ast_declaration($1, false, NULL, NULL);
+ $$->set_location(yylloc);
}
| IDENTIFIER '[' constant_expression ']'
{
$$ = new ast_declaration($1, true, $3, NULL);
+ $$->set_location(yylloc);
}
;
'{' '}'
{
$$ = new ast_compound_statement(true, NULL);
+ $$->set_location(yylloc);
}
| '{' statement_list '}'
{
$$ = new ast_compound_statement(true, $2);
+ $$->set_location(yylloc);
}
;
'{' '}'
{
$$ = new ast_compound_statement(false, NULL);
+ $$->set_location(yylloc);
}
| '{' statement_list '}'
{
$$ = new ast_compound_statement(false, $2);
+ $$->set_location(yylloc);
}
;
';'
{
$$ = new ast_expression_statement(NULL);
+ $$->set_location(yylloc);
}
| expression ';'
{
$$ = new ast_expression_statement($1);
+ $$->set_location(yylloc);
}
;
IF '(' expression ')' statement_matched ELSE statement_matched
{
$$ = new ast_selection_statement($3, $5, $7);
+ $$->set_location(yylloc);
}
;
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);
}
;
{
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);
{
$$ = 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);
}
;
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);
}
;
function_prototype compound_statement_no_new_scope
{
$$ = new ast_function_definition();
+ $$->set_location(yylloc);
$$->prototype = $1;
$$->body = $2;
}