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
;
334 ast_sampler2drectshadow
,
335 ast_samplercubeshadow
,
338 ast_sampler1darrayshadow
,
339 ast_sampler2darrayshadow
,
358 class ast_type_specifier
: public ast_node
{
360 ast_type_specifier(int specifier
);
362 /** Construct a type specifier from a type name */
363 ast_type_specifier(const char *name
)
364 : type_specifier(ast_type_name
), type_name(name
), structure(NULL
),
365 is_array(false), array_size(NULL
), precision(ast_precision_high
)
370 /** Construct a type specifier from a structure definition */
371 ast_type_specifier(ast_struct_specifier
*s
)
372 : type_specifier(ast_struct
), type_name(s
->name
), structure(s
),
373 is_array(false), array_size(NULL
), precision(ast_precision_high
)
378 const struct glsl_type
*glsl_type(const char **name
,
379 struct _mesa_glsl_parse_state
*state
)
382 virtual void print(void) const;
384 enum ast_types type_specifier
;
386 const char *type_name
;
387 ast_struct_specifier
*structure
;
390 ast_expression
*array_size
;
392 unsigned precision
:2;
396 class ast_fully_specified_type
: public ast_node
{
398 virtual void print(void) const;
400 ast_type_qualifier qualifier
;
401 ast_type_specifier
*specifier
;
405 class ast_declarator_list
: public ast_node
{
407 ast_declarator_list(ast_fully_specified_type
*);
408 virtual void print(void) const;
410 virtual ir_rvalue
*hir(exec_list
*instructions
,
411 struct _mesa_glsl_parse_state
*state
);
413 ast_fully_specified_type
*type
;
414 struct simple_node declarations
;
417 * Special flag for vertex shader "invariant" declarations.
419 * Vertex shaders can contain "invariant" variable redeclarations that do
420 * not include a type. For example, "invariant gl_Position;". This flag
421 * is used to note these cases when no type is specified.
427 class ast_parameter_declarator
: public ast_node
{
429 virtual void print(void) const;
431 virtual ir_rvalue
*hir(exec_list
*instructions
,
432 struct _mesa_glsl_parse_state
*state
);
434 ast_fully_specified_type
*type
;
437 ast_expression
*array_size
;
441 class ast_function
: public ast_node
{
445 virtual void print(void) const;
447 virtual ir_rvalue
*hir(exec_list
*instructions
,
448 struct _mesa_glsl_parse_state
*state
);
450 ast_fully_specified_type
*return_type
;
453 struct simple_node parameters
;
457 * Is this prototype part of the function definition?
459 * Used by ast_function_definition::hir to process the parameters, etc.
467 * Function signature corresponding to this function prototype instance
469 * Used by ast_function_definition::hir to process the parameters, etc.
474 class ir_function_signature
*signature
;
476 friend class ast_function_definition
;
480 class ast_declaration_statement
: public ast_node
{
482 ast_declaration_statement(void);
491 class ast_function
*function
;
492 ast_declarator_list
*declarator
;
493 ast_type_specifier
*type
;
499 class ast_expression_statement
: public ast_node
{
501 ast_expression_statement(ast_expression
*);
502 virtual void print(void) const;
504 virtual ir_rvalue
*hir(exec_list
*instructions
,
505 struct _mesa_glsl_parse_state
*state
);
507 ast_expression
*expression
;
511 class ast_case_label
: public ast_node
{
515 * An expression of NULL means 'default'.
517 ast_expression
*expression
;
520 class ast_selection_statement
: public ast_node
{
522 ast_selection_statement(ast_expression
*condition
,
523 ast_node
*then_statement
,
524 ast_node
*else_statement
);
525 virtual void print(void) const;
527 virtual ir_rvalue
*hir(exec_list
*instructions
,
528 struct _mesa_glsl_parse_state
*state
);
530 ast_expression
*condition
;
531 ast_node
*then_statement
;
532 ast_node
*else_statement
;
536 class ast_switch_statement
: public ast_node
{
538 ast_expression
*expression
;
539 struct simple_node statements
;
542 class ast_iteration_statement
: public ast_node
{
544 ast_iteration_statement(int mode
, ast_node
*init
, ast_node
*condition
,
545 ast_expression
*rest_expression
, ast_node
*body
);
547 virtual void print(void) const;
549 enum ast_iteration_modes
{
556 ast_node
*init_statement
;
558 ast_expression
*rest_expression
;
564 class ast_jump_statement
: public ast_node
{
566 ast_jump_statement(int mode
, ast_expression
*return_value
);
567 virtual void print(void) const;
569 virtual ir_rvalue
*hir(exec_list
*instructions
,
570 struct _mesa_glsl_parse_state
*state
);
572 enum ast_jump_modes
{
579 ast_expression
*opt_return_value
;
583 class ast_function_definition
: public ast_node
{
585 virtual void print(void) const;
587 virtual ir_rvalue
*hir(exec_list
*instructions
,
588 struct _mesa_glsl_parse_state
*state
);
590 ast_function
*prototype
;
591 ast_compound_statement
*body
;
596 _mesa_ast_to_hir(exec_list
*instructions
, struct _mesa_glsl_parse_state
*state
);
598 extern struct ir_rvalue
*
599 _mesa_ast_field_selection_to_hir(const struct ast_expression
*expr
,
600 exec_list
*instructions
,
601 struct _mesa_glsl_parse_state
*state
);