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"
29 #include "glsl_parser_extras.h"
31 struct ir_instruction
;
32 struct _mesa_glsl_parse_state
;
36 #define _mesa_ast_print(n) \
37 ((ast_node *) n)->print()
39 #define _mesa_ast_to_hir(n, instr, s) \
40 ((struct ast_node *) n)->vtbl->to_hir((struct ast_node *) n, instr, s)
42 #define _mesa_ast_function_call_to_hir(n, p, s) \
43 ((struct ast_node *) n)->vtbl->function_call_to_hir( \
44 (struct ast_node *) n, \
45 (struct ast_node *) p, \
48 class ast_node
: public simple_node
{
51 virtual void print(void) const;
54 * Retrieve the source location of an AST node
56 * This function is primarily used to get the source position of an AST node
57 * into a form that can be passed to \c _mesa_glsl_error.
59 * \sa _mesa_glsl_error, ast_node::set_location
61 struct YYLTYPE
get_location(void) const
65 locp
.source
= this->location
.source
;
66 locp
.first_line
= this->location
.line
;
67 locp
.first_column
= this->location
.column
;
68 locp
.last_line
= locp
.first_line
;
69 locp
.last_column
= locp
.first_column
;
75 * Set the source location of an AST node from a parser location
77 * \sa ast_node::get_location
79 void set_location(const struct YYLTYPE
*locp
)
81 this->location
.source
= locp
->source
;
82 this->location
.line
= locp
->first_line
;
83 this->location
.column
= locp
->first_column
;
102 ast_plus
, /**< Unary + operator. */
157 class ast_expression
: public ast_node
{
159 ast_expression(int oper
, ast_expression
*,
160 ast_expression
*, ast_expression
*);
162 virtual void print(void) const;
164 enum ast_operators oper
;
166 ast_expression
*subexpressions
[3];
171 float float_constant
;
172 unsigned uint_constant
;
174 } primary_expression
;
178 * List of expressions for an \c ast_sequence.
180 struct simple_node expressions
;
184 * Number of possible operators for an ast_expression
186 * This is done as a define instead of as an additional value in the enum so
187 * that the compiler won't generate spurious messages like "warning:
188 * enumeration value ‘ast_num_operators’ not handled in switch"
190 #define AST_NUM_OPERATORS (ast_sequence + 1)
193 class ast_compound_statement
: public ast_node
{
195 ast_compound_statement(int new_scope
, ast_node
*statements
);
196 virtual void print(void) const;
199 struct simple_node statements
;
202 class ast_declaration
: public ast_node
{
204 ast_declaration(char *identifier
, int is_array
, ast_expression
*array_size
,
205 ast_expression
*initializer
);
206 virtual void print(void) const;
211 ast_expression
*array_size
;
213 ast_expression
*initializer
;
218 ast_precision_high
= 0, /**< Default precision. */
219 ast_precision_medium
,
223 struct ast_type_qualifier
{
224 unsigned invariant
:1;
226 unsigned attribute
:1;
234 unsigned noperspective
:1;
237 class ast_struct_specifier
: public ast_node
{
239 ast_struct_specifier(char *identifier
, ast_node
*declarator_list
);
240 virtual void print(void) const;
243 struct simple_node declarations
;
280 ast_samplercubeshadow
,
283 ast_sampler1darrayshadow
,
284 ast_sampler2darrayshadow
,
303 class ast_type_specifier
: public ast_node
{
305 ast_type_specifier(int specifier
);
307 virtual void print(void) const;
309 enum ast_types type_specifier
;
312 ast_struct_specifier
*structure
;
315 ast_expression
*array_size
;
317 unsigned precision
:2;
321 class ast_fully_specified_type
: public ast_node
{
323 virtual void print(void) const;
325 ast_type_qualifier qualifier
;
326 ast_type_specifier
*specifier
;
330 class ast_declarator_list
: public ast_node
{
332 ast_declarator_list(ast_fully_specified_type
*);
333 virtual void print(void) const;
335 ast_fully_specified_type
*type
;
336 struct simple_node declarations
;
339 * Special flag for vertex shader "invariant" declarations.
341 * Vertex shaders can contain "invariant" variable redeclarations that do
342 * not include a type. For example, "invariant gl_Position;". This flag
343 * is used to note these cases when no type is specified.
349 class ast_parameter_declarator
: public ast_node
{
351 virtual void print(void) const;
353 ast_fully_specified_type
*type
;
356 ast_expression
*array_size
;
360 class ast_function
: public ast_node
{
364 virtual void print(void) const;
366 ast_fully_specified_type
*return_type
;
369 struct simple_node parameters
;
373 class ast_declaration_statement
: public ast_node
{
375 ast_declaration_statement(void);
384 class ast_function
*function
;
385 ast_declarator_list
*declarator
;
386 ast_type_specifier
*type
;
392 class ast_expression_statement
: public ast_node
{
394 ast_expression_statement(ast_expression
*);
395 virtual void print(void) const;
397 ast_expression
*expression
;
401 class ast_case_label
: public ast_node
{
405 * An expression of NULL means 'default'.
407 ast_expression
*expression
;
410 class ast_selection_statement
: public ast_node
{
412 ast_selection_statement(ast_expression
*condition
,
413 ast_node
*then_statement
,
414 ast_node
*else_statement
);
415 virtual void print(void) const;
417 ast_expression
*condition
;
418 ast_node
*then_statement
;
419 ast_node
*else_statement
;
423 class ast_switch_statement
: public ast_node
{
425 ast_expression
*expression
;
426 struct simple_node statements
;
429 class ast_iteration_statement
: public ast_node
{
431 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
432 ast_expression
*rest_expression
, ast_node
*body
);
434 virtual void print(void) const;
436 enum ast_iteration_modes
{
443 ast_node
*init_statement
;
445 ast_expression
*rest_expression
;
451 class ast_jump_statement
: public ast_node
{
453 ast_jump_statement(int mode
, ast_expression
*return_value
);
454 virtual void print(void) const;
456 enum ast_jump_modes
{
463 ast_expression
*opt_return_value
;
467 class ast_function_definition
: public ast_node
{
469 virtual void print(void) const;
471 ast_function
*prototype
;
472 ast_compound_statement
*body
;
476 extern struct ir_instruction
*
477 ast_expression_to_hir(const ast_node
*ast
,
478 struct simple_node
*instructions
,
479 struct _mesa_glsl_parse_state
*state
);
481 extern struct ir_instruction
*
482 ast_expression_statement_to_hir(const struct ast_node
*ast
,
483 struct simple_node
*instructions
,
484 struct _mesa_glsl_parse_state
*state
);
486 extern struct ir_instruction
*
487 ast_compound_statement_to_hir(const struct ast_node
*ast
,
488 struct simple_node
*instructions
,
489 struct _mesa_glsl_parse_state
*state
);
491 extern struct ir_instruction
*
492 ast_function_definition_to_hir(const struct ast_node
*ast
,
493 struct simple_node
*instructions
,
494 struct _mesa_glsl_parse_state
*state
);
496 extern struct ir_instruction
*
497 ast_declarator_list_to_hir(const struct ast_node
*ast
,
498 struct simple_node
*instructions
,
499 struct _mesa_glsl_parse_state
*state
);
501 extern struct ir_instruction
*
502 ast_parameter_declarator_to_hir(const struct ast_node
*ast
,
503 struct simple_node
*instructions
,
504 struct _mesa_glsl_parse_state
*state
);
506 extern struct ir_instruction
*
507 _mesa_ast_field_selection_to_hir(const struct ast_expression
*expr
,
508 struct simple_node
*instructions
,
509 struct _mesa_glsl_parse_state
*state
);