3 * Copyright © 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "main/simple_list.h"
31 #include "glsl_parser_extras.h"
33 struct ir_instruction
;
34 struct _mesa_glsl_parse_state
;
38 class ast_node
: public simple_node
{
41 virtual void print(void) const;
42 virtual ir_rvalue
*hir(exec_list
*instructions
,
43 struct _mesa_glsl_parse_state
*state
);
46 * Retrieve the source location of an AST node
48 * This function is primarily used to get the source position of an AST node
49 * into a form that can be passed to \c _mesa_glsl_error.
51 * \sa _mesa_glsl_error, ast_node::set_location
53 struct YYLTYPE
get_location(void) const
57 locp
.source
= this->location
.source
;
58 locp
.first_line
= this->location
.line
;
59 locp
.first_column
= this->location
.column
;
60 locp
.last_line
= locp
.first_line
;
61 locp
.last_column
= locp
.first_column
;
67 * Set the source location of an AST node from a parser location
69 * \sa ast_node::get_location
71 void set_location(const struct YYLTYPE
*locp
)
73 this->location
.source
= locp
->source
;
74 this->location
.line
= locp
->first_line
;
75 this->location
.column
= locp
->first_column
;
94 ast_plus
, /**< Unary + operator. */
149 class ast_expression
: public ast_node
{
151 ast_expression(int oper
, ast_expression
*,
152 ast_expression
*, ast_expression
*);
154 ast_expression(const char *identifier
) :
157 subexpressions
[0] = NULL
;
158 subexpressions
[1] = NULL
;
159 subexpressions
[2] = NULL
;
160 primary_expression
.identifier
= (char *) identifier
;
163 static const char *operator_string(enum ast_operators op
);
165 virtual ir_rvalue
*hir(exec_list
*instructions
,
166 struct _mesa_glsl_parse_state
*state
);
168 virtual void print(void) const;
170 enum ast_operators oper
;
172 ast_expression
*subexpressions
[3];
177 float float_constant
;
178 unsigned uint_constant
;
180 } primary_expression
;
184 * List of expressions for an \c ast_sequence.
186 struct simple_node expressions
;
189 class ast_expression_bin
: public ast_expression
{
191 ast_expression_bin(int oper
, ast_expression
*, ast_expression
*);
193 virtual void print(void) const;
197 * Subclass of expressions for function calls
199 class ast_function_expression
: public ast_expression
{
201 ast_function_expression(ast_expression
*callee
)
202 : ast_expression(ast_function_call
, callee
,
209 ast_function_expression(class ast_type_specifier
*type
)
210 : ast_expression(ast_function_call
, (ast_expression
*) type
,
217 bool is_constructor() const
222 virtual ir_rvalue
*hir(exec_list
*instructions
,
223 struct _mesa_glsl_parse_state
*state
);
227 * Is this function call actually a constructor?
234 * Number of possible operators for an ast_expression
236 * This is done as a define instead of as an additional value in the enum so
237 * that the compiler won't generate spurious messages like "warning:
238 * enumeration value ‘ast_num_operators’ not handled in switch"
240 #define AST_NUM_OPERATORS (ast_sequence + 1)
243 class ast_compound_statement
: public ast_node
{
245 ast_compound_statement(int new_scope
, ast_node
*statements
);
246 virtual void print(void) const;
248 virtual ir_rvalue
*hir(exec_list
*instructions
,
249 struct _mesa_glsl_parse_state
*state
);
252 struct simple_node statements
;
255 class ast_declaration
: public ast_node
{
257 ast_declaration(char *identifier
, int is_array
, ast_expression
*array_size
,
258 ast_expression
*initializer
);
259 virtual void print(void) const;
264 ast_expression
*array_size
;
266 ast_expression
*initializer
;
271 ast_precision_high
= 0, /**< Default precision. */
272 ast_precision_medium
,
276 struct ast_type_qualifier
{
277 unsigned invariant
:1;
279 unsigned attribute
:1;
287 unsigned noperspective
:1;
290 class ast_struct_specifier
: public ast_node
{
292 ast_struct_specifier(char *identifier
, ast_node
*declarator_list
);
293 virtual void print(void) const;
296 struct simple_node declarations
;
333 ast_samplercubeshadow
,
336 ast_sampler1darrayshadow
,
337 ast_sampler2darrayshadow
,
356 class ast_type_specifier
: public ast_node
{
358 ast_type_specifier(int specifier
);
360 /** Construct a type specifier from a type name */
361 ast_type_specifier(const char *name
)
362 : type_specifier(ast_type_name
), type_name(name
), structure(NULL
),
363 is_array(false), array_size(NULL
), precision(ast_precision_high
)
368 /** Construct a type specifier from a structure definition */
369 ast_type_specifier(ast_struct_specifier
*s
)
370 : type_specifier(ast_struct
), type_name(s
->name
), structure(s
),
371 is_array(false), array_size(NULL
), precision(ast_precision_high
)
376 virtual void print(void) const;
378 enum ast_types type_specifier
;
380 const char *type_name
;
381 ast_struct_specifier
*structure
;
384 ast_expression
*array_size
;
386 unsigned precision
:2;
390 class ast_fully_specified_type
: public ast_node
{
392 virtual void print(void) const;
394 ast_type_qualifier qualifier
;
395 ast_type_specifier
*specifier
;
399 class ast_declarator_list
: public ast_node
{
401 ast_declarator_list(ast_fully_specified_type
*);
402 virtual void print(void) const;
404 virtual ir_rvalue
*hir(exec_list
*instructions
,
405 struct _mesa_glsl_parse_state
*state
);
407 ast_fully_specified_type
*type
;
408 struct simple_node declarations
;
411 * Special flag for vertex shader "invariant" declarations.
413 * Vertex shaders can contain "invariant" variable redeclarations that do
414 * not include a type. For example, "invariant gl_Position;". This flag
415 * is used to note these cases when no type is specified.
421 class ast_parameter_declarator
: public ast_node
{
423 virtual void print(void) const;
425 virtual ir_rvalue
*hir(exec_list
*instructions
,
426 struct _mesa_glsl_parse_state
*state
);
428 ast_fully_specified_type
*type
;
431 ast_expression
*array_size
;
435 class ast_function
: public ast_node
{
439 virtual void print(void) const;
441 ast_fully_specified_type
*return_type
;
444 struct simple_node parameters
;
448 class ast_declaration_statement
: public ast_node
{
450 ast_declaration_statement(void);
459 class ast_function
*function
;
460 ast_declarator_list
*declarator
;
461 ast_type_specifier
*type
;
467 class ast_expression_statement
: public ast_node
{
469 ast_expression_statement(ast_expression
*);
470 virtual void print(void) const;
472 virtual ir_rvalue
*hir(exec_list
*instructions
,
473 struct _mesa_glsl_parse_state
*state
);
475 ast_expression
*expression
;
479 class ast_case_label
: public ast_node
{
483 * An expression of NULL means 'default'.
485 ast_expression
*expression
;
488 class ast_selection_statement
: public ast_node
{
490 ast_selection_statement(ast_expression
*condition
,
491 ast_node
*then_statement
,
492 ast_node
*else_statement
);
493 virtual void print(void) const;
495 ast_expression
*condition
;
496 ast_node
*then_statement
;
497 ast_node
*else_statement
;
501 class ast_switch_statement
: public ast_node
{
503 ast_expression
*expression
;
504 struct simple_node statements
;
507 class ast_iteration_statement
: public ast_node
{
509 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
510 ast_expression
*rest_expression
, ast_node
*body
);
512 virtual void print(void) const;
514 enum ast_iteration_modes
{
521 ast_node
*init_statement
;
523 ast_expression
*rest_expression
;
529 class ast_jump_statement
: public ast_node
{
531 ast_jump_statement(int mode
, ast_expression
*return_value
);
532 virtual void print(void) const;
534 virtual ir_rvalue
*hir(exec_list
*instructions
,
535 struct _mesa_glsl_parse_state
*state
);
537 enum ast_jump_modes
{
544 ast_expression
*opt_return_value
;
548 class ast_function_definition
: public ast_node
{
550 virtual void print(void) const;
552 virtual ir_rvalue
*hir(exec_list
*instructions
,
553 struct _mesa_glsl_parse_state
*state
);
555 ast_function
*prototype
;
556 ast_compound_statement
*body
;
561 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
563 extern struct ir_rvalue
*
564 _mesa_ast_field_selection_to_hir(const struct ast_expression
*expr
,
565 exec_list
*instructions
,
566 struct _mesa_glsl_parse_state
*state
);