2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
28 #include "main/simple_list.h"
30 #include "glsl_parser_extras.h"
32 struct ir_instruction
;
33 struct _mesa_glsl_parse_state
;
37 class ast_node
: public simple_node
{
40 virtual void print(void) const;
41 virtual ir_instruction
*hir(exec_list
*instructions
,
42 struct _mesa_glsl_parse_state
*state
);
45 * Retrieve the source location of an AST node
47 * This function is primarily used to get the source position of an AST node
48 * into a form that can be passed to \c _mesa_glsl_error.
50 * \sa _mesa_glsl_error, ast_node::set_location
52 struct YYLTYPE
get_location(void) const
56 locp
.source
= this->location
.source
;
57 locp
.first_line
= this->location
.line
;
58 locp
.first_column
= this->location
.column
;
59 locp
.last_line
= locp
.first_line
;
60 locp
.last_column
= locp
.first_column
;
66 * Set the source location of an AST node from a parser location
68 * \sa ast_node::get_location
70 void set_location(const struct YYLTYPE
*locp
)
72 this->location
.source
= locp
->source
;
73 this->location
.line
= locp
->first_line
;
74 this->location
.column
= locp
->first_column
;
93 ast_plus
, /**< Unary + operator. */
148 class ast_expression
: public ast_node
{
150 ast_expression(int oper
, ast_expression
*,
151 ast_expression
*, ast_expression
*);
153 static const char *operator_string(enum ast_operators op
);
155 virtual ir_instruction
*hir(exec_list
*instructions
,
156 struct _mesa_glsl_parse_state
*state
);
158 virtual void print(void) const;
160 enum ast_operators oper
;
162 ast_expression
*subexpressions
[3];
167 float float_constant
;
168 unsigned uint_constant
;
170 } primary_expression
;
174 * List of expressions for an \c ast_sequence.
176 struct simple_node expressions
;
179 class ast_expression_bin
: public ast_expression
{
181 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
183 virtual void print(void) const;
188 * Number of possible operators for an ast_expression
190 * This is done as a define instead of as an additional value in the enum so
191 * that the compiler won't generate spurious messages like "warning:
192 * enumeration value ‘ast_num_operators’ not handled in switch"
194 #define AST_NUM_OPERATORS (ast_sequence + 1)
197 class ast_compound_statement
: public ast_node
{
199 ast_compound_statement(int new_scope
, ast_node
*statements
);
200 virtual void print(void) const;
202 virtual ir_instruction
*hir(exec_list
*instructions
,
203 struct _mesa_glsl_parse_state
*state
);
206 struct simple_node statements
;
209 class ast_declaration
: public ast_node
{
211 ast_declaration(char *identifier
, int is_array
, ast_expression
*array_size
,
212 ast_expression
*initializer
);
213 virtual void print(void) const;
218 ast_expression
*array_size
;
220 ast_expression
*initializer
;
225 ast_precision_high
= 0, /**< Default precision. */
226 ast_precision_medium
,
230 struct ast_type_qualifier
{
231 unsigned invariant
:1;
233 unsigned attribute
:1;
241 unsigned noperspective
:1;
244 class ast_struct_specifier
: public ast_node
{
246 ast_struct_specifier(char *identifier
, ast_node
*declarator_list
);
247 virtual void print(void) const;
250 struct simple_node declarations
;
287 ast_samplercubeshadow
,
290 ast_sampler1darrayshadow
,
291 ast_sampler2darrayshadow
,
310 class ast_type_specifier
: public ast_node
{
312 ast_type_specifier(int specifier
);
314 virtual void print(void) const;
316 enum ast_types type_specifier
;
319 ast_struct_specifier
*structure
;
322 ast_expression
*array_size
;
324 unsigned precision
:2;
328 class ast_fully_specified_type
: public ast_node
{
330 virtual void print(void) const;
332 ast_type_qualifier qualifier
;
333 ast_type_specifier
*specifier
;
337 class ast_declarator_list
: public ast_node
{
339 ast_declarator_list(ast_fully_specified_type
*);
340 virtual void print(void) const;
342 virtual ir_instruction
*hir(exec_list
*instructions
,
343 struct _mesa_glsl_parse_state
*state
);
345 ast_fully_specified_type
*type
;
346 struct simple_node declarations
;
349 * Special flag for vertex shader "invariant" declarations.
351 * Vertex shaders can contain "invariant" variable redeclarations that do
352 * not include a type. For example, "invariant gl_Position;". This flag
353 * is used to note these cases when no type is specified.
359 class ast_parameter_declarator
: public ast_node
{
361 virtual void print(void) const;
363 virtual ir_instruction
*hir(exec_list
*instructions
,
364 struct _mesa_glsl_parse_state
*state
);
366 ast_fully_specified_type
*type
;
369 ast_expression
*array_size
;
373 class ast_function
: public ast_node
{
377 virtual void print(void) const;
379 ast_fully_specified_type
*return_type
;
382 struct simple_node parameters
;
386 class ast_declaration_statement
: public ast_node
{
388 ast_declaration_statement(void);
397 class ast_function
*function
;
398 ast_declarator_list
*declarator
;
399 ast_type_specifier
*type
;
405 class ast_expression_statement
: public ast_node
{
407 ast_expression_statement(ast_expression
*);
408 virtual void print(void) const;
410 virtual ir_instruction
*hir(exec_list
*instructions
,
411 struct _mesa_glsl_parse_state
*state
);
413 ast_expression
*expression
;
417 class ast_case_label
: public ast_node
{
421 * An expression of NULL means 'default'.
423 ast_expression
*expression
;
426 class ast_selection_statement
: public ast_node
{
428 ast_selection_statement(ast_expression
*condition
,
429 ast_node
*then_statement
,
430 ast_node
*else_statement
);
431 virtual void print(void) const;
433 ast_expression
*condition
;
434 ast_node
*then_statement
;
435 ast_node
*else_statement
;
439 class ast_switch_statement
: public ast_node
{
441 ast_expression
*expression
;
442 struct simple_node statements
;
445 class ast_iteration_statement
: public ast_node
{
447 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
448 ast_expression
*rest_expression
, ast_node
*body
);
450 virtual void print(void) const;
452 enum ast_iteration_modes
{
459 ast_node
*init_statement
;
461 ast_expression
*rest_expression
;
467 class ast_jump_statement
: public ast_node
{
469 ast_jump_statement(int mode
, ast_expression
*return_value
);
470 virtual void print(void) const;
472 enum ast_jump_modes
{
479 ast_expression
*opt_return_value
;
483 class ast_function_definition
: public ast_node
{
485 virtual void print(void) const;
487 virtual ir_instruction
*hir(exec_list
*instructions
,
488 struct _mesa_glsl_parse_state
*state
);
490 ast_function
*prototype
;
491 ast_compound_statement
*body
;
495 extern struct ir_instruction
*
496 _mesa_ast_field_selection_to_hir(const struct ast_expression
*expr
,
497 exec_list
*instructions
,
498 struct _mesa_glsl_parse_state
*state
);