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 "program/hash_table.h"
36 #define yyscan_t void*
38 /* Some data types used for parser values. */
40 typedef struct expression_value
{
42 char *undefined_macro
;
46 typedef struct string_node
{
48 struct string_node
*next
;
51 typedef struct string_list
{
56 typedef struct token token_t
;
57 typedef struct token_list token_list_t
;
62 expression_value_t expression_value
;
64 string_list_t
*string_list
;
66 token_list_t
*token_list
;
69 # define YYSTYPE_IS_TRIVIAL 1
70 # define YYSTYPE_IS_DECLARED 1
72 typedef struct YYLTYPE
{
79 # define YYLTYPE_IS_DECLARED 1
80 # define YYLTYPE_IS_TRIVIAL 1
82 # define YYLLOC_DEFAULT(Current, Rhs, N) \
86 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
87 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
88 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
89 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
93 (Current).first_line = (Current).last_line = \
94 YYRHSLOC(Rhs, 0).last_line; \
95 (Current).first_column = (Current).last_column = \
96 YYRHSLOC(Rhs, 0).last_column; \
98 (Current).source = 0; \
107 typedef struct token_node
{
109 struct token_node
*next
;
115 token_node_t
*non_space_tail
;
118 typedef struct argument_node
{
119 token_list_t
*argument
;
120 struct argument_node
*next
;
123 typedef struct argument_list
{
124 argument_node_t
*head
;
125 argument_node_t
*tail
;
128 typedef struct glcpp_parser glcpp_parser_t
;
131 TOKEN_CLASS_IDENTIFIER
,
132 TOKEN_CLASS_IDENTIFIER_FINALIZED
,
133 TOKEN_CLASS_FUNC_MACRO
,
134 TOKEN_CLASS_OBJ_MACRO
138 glcpp_parser_classify_token (glcpp_parser_t
*parser
,
139 const char *identifier
,
140 int *parameter_index
);
144 string_list_t
*parameters
;
145 const char *identifier
;
146 token_list_t
*replacements
;
149 typedef struct expansion_node
{
151 token_node_t
*replacements
;
152 struct expansion_node
*next
;
155 typedef enum skip_type
{
161 typedef struct skip_node
{
164 YYLTYPE loc
; /* location of the initial #if/#elif/... */
165 struct skip_node
*next
;
168 typedef struct active_list
{
169 const char *identifier
;
170 token_node_t
*marker
;
171 struct active_list
*next
;
174 struct glcpp_parser
{
176 struct hash_table
*defines
;
177 active_list_t
*active
;
178 int lexing_directive
;
180 int last_token_was_newline
;
181 int last_token_was_space
;
182 int first_non_space_token_this_line
;
183 int newline_as_space
;
186 int commented_newlines
;
187 skip_node_t
*skip_stack
;
189 token_list_t
*lex_from_list
;
190 token_node_t
*lex_from_node
;
193 size_t output_length
;
194 size_t info_log_length
;
196 const struct gl_extensions
*extensions
;
198 bool version_resolved
;
199 bool has_new_line_number
;
201 bool has_new_source_number
;
202 int new_source_number
;
206 struct gl_extensions
;
209 glcpp_parser_create (const struct gl_extensions
*extensions
, gl_api api
);
212 glcpp_parser_parse (glcpp_parser_t
*parser
);
215 glcpp_parser_destroy (glcpp_parser_t
*parser
);
218 glcpp_parser_resolve_implicit_version(glcpp_parser_t
*parser
);
221 glcpp_preprocess(void *ralloc_ctx
, const char **shader
, char **info_log
,
222 const struct gl_extensions
*extensions
, struct gl_context
*g_ctx
);
224 /* Functions for writing to the info log */
227 glcpp_error (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
230 glcpp_warning (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
232 /* Generated by glcpp-lex.l to glcpp-lex.c */
235 glcpp_lex_init_extra (glcpp_parser_t
*parser
, yyscan_t
* scanner
);
238 glcpp_lex_set_source_string(glcpp_parser_t
*parser
, const char *shader
);
241 glcpp_lex (YYSTYPE
*lvalp
, YYLTYPE
*llocp
, yyscan_t scanner
);
244 glcpp_lex_destroy (yyscan_t scanner
);
246 /* Generated by glcpp-parse.y to glcpp-parse.c */
249 yyparse (glcpp_parser_t
*parser
);