2 * Copyright © 2010 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.
30 #include "main/mtypes.h"
32 #include "util/ralloc.h"
34 #include "util/hash_table.h"
36 #include "util/string_buffer.h"
38 #define yyscan_t void*
40 /* Some data types used for parser values. */
42 typedef struct expression_value
{
44 char *undefined_macro
;
48 typedef struct string_node
{
50 struct string_node
*next
;
53 typedef struct string_list
{
58 typedef struct token token_t
;
59 typedef struct token_list token_list_t
;
64 expression_value_t expression_value
;
66 string_list_t
*string_list
;
68 token_list_t
*token_list
;
71 # define YYSTYPE_IS_TRIVIAL 1
72 # define YYSTYPE_IS_DECLARED 1
74 typedef struct YYLTYPE
{
81 # define YYLTYPE_IS_DECLARED 1
82 # define YYLTYPE_IS_TRIVIAL 1
84 # define YYLLOC_DEFAULT(Current, Rhs, N) \
88 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
89 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
90 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
91 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
95 (Current).first_line = (Current).last_line = \
96 YYRHSLOC(Rhs, 0).last_line; \
97 (Current).first_column = (Current).last_column = \
98 YYRHSLOC(Rhs, 0).last_column; \
100 (Current).source = 0; \
109 typedef struct token_node
{
111 struct token_node
*next
;
117 token_node_t
*non_space_tail
;
120 typedef struct argument_node
{
121 token_list_t
*argument
;
122 struct argument_node
*next
;
125 typedef struct argument_list
{
126 argument_node_t
*head
;
127 argument_node_t
*tail
;
130 typedef struct glcpp_parser glcpp_parser_t
;
133 TOKEN_CLASS_IDENTIFIER
,
134 TOKEN_CLASS_IDENTIFIER_FINALIZED
,
135 TOKEN_CLASS_FUNC_MACRO
,
136 TOKEN_CLASS_OBJ_MACRO
140 glcpp_parser_classify_token (glcpp_parser_t
*parser
,
141 const char *identifier
,
142 int *parameter_index
);
146 string_list_t
*parameters
;
147 const char *identifier
;
148 token_list_t
*replacements
;
151 typedef struct expansion_node
{
153 token_node_t
*replacements
;
154 struct expansion_node
*next
;
157 typedef enum skip_type
{
163 typedef struct skip_node
{
166 YYLTYPE loc
; /* location of the initial #if/#elif/... */
167 struct skip_node
*next
;
170 typedef struct active_list
{
171 const char *identifier
;
172 token_node_t
*marker
;
173 struct active_list
*next
;
176 struct _mesa_glsl_parse_state
;
178 typedef void (*glcpp_extension_iterator
)(
179 struct _mesa_glsl_parse_state
*state
,
180 void (*add_builtin_define
)(glcpp_parser_t
*, const char *, int),
181 glcpp_parser_t
*data
,
185 struct glcpp_parser
{
188 struct hash_table
*defines
;
189 active_list_t
*active
;
190 int lexing_directive
;
191 int lexing_version_directive
;
193 int last_token_was_newline
;
194 int last_token_was_space
;
195 int first_non_space_token_this_line
;
196 int newline_as_space
;
199 int commented_newlines
;
200 skip_node_t
*skip_stack
;
202 token_list_t
*lex_from_list
;
203 token_node_t
*lex_from_node
;
204 struct _mesa_string_buffer
*output
;
205 struct _mesa_string_buffer
*info_log
;
207 glcpp_extension_iterator extensions
;
208 const struct gl_extensions
*extension_list
;
214 * Has the #version been set?
216 * A separate flag is used because any possible sentinel value in
217 * \c ::version could also be set by a #version line.
221 bool has_new_line_number
;
223 bool has_new_source_number
;
224 int new_source_number
;
229 glcpp_parser_create(const struct gl_extensions
*extension_list
,
230 glcpp_extension_iterator extensions
, void *state
, gl_api api
);
233 glcpp_parser_parse (glcpp_parser_t
*parser
);
236 glcpp_parser_destroy (glcpp_parser_t
*parser
);
239 glcpp_parser_resolve_implicit_version(glcpp_parser_t
*parser
);
242 glcpp_preprocess(void *ralloc_ctx
, const char **shader
, char **info_log
,
243 glcpp_extension_iterator extensions
, void *state
,
244 struct gl_context
*g_ctx
);
246 /* Functions for writing to the info log */
249 glcpp_error (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
252 glcpp_warning (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
254 /* Generated by glcpp-lex.l to glcpp-lex.c */
257 glcpp_lex_init_extra (glcpp_parser_t
*parser
, yyscan_t
* scanner
);
260 glcpp_lex_set_source_string(glcpp_parser_t
*parser
, const char *shader
);
263 glcpp_lex (YYSTYPE
*lvalp
, YYLTYPE
*llocp
, yyscan_t scanner
);
266 glcpp_lex_destroy (yyscan_t scanner
);
268 /* Generated by glcpp-parse.y to glcpp-parse.c */
271 yyparse (glcpp_parser_t
*parser
);