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/menums.h"
32 #include "util/ralloc.h"
34 #include "util/hash_table.h"
36 #include "util/string_buffer.h"
40 #define yyscan_t void*
42 /* Some data types used for parser values. */
44 typedef struct expression_value
{
46 char *undefined_macro
;
50 typedef struct string_node
{
52 struct string_node
*next
;
55 typedef struct string_list
{
60 typedef struct token token_t
;
61 typedef struct token_list token_list_t
;
66 expression_value_t expression_value
;
68 string_list_t
*string_list
;
70 token_list_t
*token_list
;
73 # define YYSTYPE_IS_TRIVIAL 1
74 # define YYSTYPE_IS_DECLARED 1
76 typedef struct YYLTYPE
{
83 # define YYLTYPE_IS_DECLARED 1
84 # define YYLTYPE_IS_TRIVIAL 1
86 # define YYLLOC_DEFAULT(Current, Rhs, N) \
90 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
91 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
92 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
93 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
97 (Current).first_line = (Current).last_line = \
98 YYRHSLOC(Rhs, 0).last_line; \
99 (Current).first_column = (Current).last_column = \
100 YYRHSLOC(Rhs, 0).last_column; \
102 (Current).source = 0; \
111 typedef struct token_node
{
113 struct token_node
*next
;
119 token_node_t
*non_space_tail
;
122 typedef struct argument_node
{
123 token_list_t
*argument
;
124 struct argument_node
*next
;
127 typedef struct argument_list
{
128 argument_node_t
*head
;
129 argument_node_t
*tail
;
132 typedef struct glcpp_parser glcpp_parser_t
;
135 TOKEN_CLASS_IDENTIFIER
,
136 TOKEN_CLASS_IDENTIFIER_FINALIZED
,
137 TOKEN_CLASS_FUNC_MACRO
,
138 TOKEN_CLASS_OBJ_MACRO
142 glcpp_parser_classify_token (glcpp_parser_t
*parser
,
143 const char *identifier
,
144 int *parameter_index
);
148 string_list_t
*parameters
;
149 const char *identifier
;
150 token_list_t
*replacements
;
153 typedef struct expansion_node
{
155 token_node_t
*replacements
;
156 struct expansion_node
*next
;
159 typedef enum skip_type
{
165 typedef struct skip_node
{
168 YYLTYPE loc
; /* location of the initial #if/#elif/... */
169 struct skip_node
*next
;
172 typedef struct active_list
{
173 const char *identifier
;
174 token_node_t
*marker
;
175 struct active_list
*next
;
178 struct _mesa_glsl_parse_state
;
180 typedef void (*glcpp_extension_iterator
)(
181 struct _mesa_glsl_parse_state
*state
,
182 void (*add_builtin_define
)(glcpp_parser_t
*, const char *, int),
183 glcpp_parser_t
*data
,
187 struct glcpp_parser
{
190 struct hash_table
*defines
;
191 active_list_t
*active
;
192 int lexing_directive
;
193 int lexing_version_directive
;
195 int last_token_was_newline
;
196 int last_token_was_space
;
197 int first_non_space_token_this_line
;
198 int newline_as_space
;
202 int commented_newlines
;
203 skip_node_t
*skip_stack
;
205 token_list_t
*lex_from_list
;
206 token_node_t
*lex_from_node
;
207 struct _mesa_string_buffer
*output
;
208 struct _mesa_string_buffer
*info_log
;
210 glcpp_extension_iterator extensions
;
211 const struct gl_extensions
*extension_list
;
214 struct gl_context
*gl_ctx
;
218 * Has the #version been set?
220 * A separate flag is used because any possible sentinel value in
221 * \c ::version could also be set by a #version line.
225 bool has_new_line_number
;
227 bool has_new_source_number
;
228 int new_source_number
;
233 glcpp_parser_create(struct gl_context
*gl_ctx
,
234 glcpp_extension_iterator extensions
, void *state
);
237 glcpp_parser_parse (glcpp_parser_t
*parser
);
240 glcpp_parser_destroy (glcpp_parser_t
*parser
);
243 glcpp_parser_resolve_implicit_version(glcpp_parser_t
*parser
);
246 glcpp_preprocess(void *ralloc_ctx
, const char **shader
, char **info_log
,
247 glcpp_extension_iterator extensions
, void *state
,
248 struct gl_context
*g_ctx
);
250 /* Functions for writing to the info log */
253 glcpp_error (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
256 glcpp_warning (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
258 /* Generated by glcpp-lex.l to glcpp-lex.c */
261 glcpp_lex_init_extra (glcpp_parser_t
*parser
, yyscan_t
* scanner
);
264 glcpp_lex_set_source_string(glcpp_parser_t
*parser
, const char *shader
);
267 glcpp_lex (YYSTYPE
*lvalp
, YYLTYPE
*llocp
, yyscan_t scanner
);
270 glcpp_lex_destroy (yyscan_t scanner
);
272 /* Generated by glcpp-parse.y to glcpp-parse.c */
275 yyparse (glcpp_parser_t
*parser
);