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 "../ralloc.h"
32 #include "program/hash_table.h"
34 #define yyscan_t void*
36 /* Some data types used for parser values. */
38 typedef struct string_node
{
40 struct string_node
*next
;
43 typedef struct string_list
{
48 typedef struct token token_t
;
49 typedef struct token_list token_list_t
;
55 string_list_t
*string_list
;
57 token_list_t
*token_list
;
60 # define YYSTYPE_IS_TRIVIAL 1
61 # define YYSTYPE_IS_DECLARED 1
63 typedef struct YYLTYPE
{
70 # define YYLTYPE_IS_DECLARED 1
71 # define YYLTYPE_IS_TRIVIAL 1
73 # define YYLLOC_DEFAULT(Current, Rhs, N) \
77 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
78 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
79 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
80 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
84 (Current).first_line = (Current).last_line = \
85 YYRHSLOC(Rhs, 0).last_line; \
86 (Current).first_column = (Current).last_column = \
87 YYRHSLOC(Rhs, 0).last_column; \
89 (Current).source = 0; \
98 typedef struct token_node
{
100 struct token_node
*next
;
106 token_node_t
*non_space_tail
;
109 typedef struct argument_node
{
110 token_list_t
*argument
;
111 struct argument_node
*next
;
114 typedef struct argument_list
{
115 argument_node_t
*head
;
116 argument_node_t
*tail
;
119 typedef struct glcpp_parser glcpp_parser_t
;
122 TOKEN_CLASS_IDENTIFIER
,
123 TOKEN_CLASS_IDENTIFIER_FINALIZED
,
124 TOKEN_CLASS_FUNC_MACRO
,
125 TOKEN_CLASS_OBJ_MACRO
129 glcpp_parser_classify_token (glcpp_parser_t
*parser
,
130 const char *identifier
,
131 int *parameter_index
);
135 string_list_t
*parameters
;
136 const char *identifier
;
137 token_list_t
*replacements
;
140 typedef struct expansion_node
{
142 token_node_t
*replacements
;
143 struct expansion_node
*next
;
146 typedef enum skip_type
{
152 typedef struct skip_node
{
154 YYLTYPE loc
; /* location of the initial #if/#elif/... */
155 struct skip_node
*next
;
158 typedef struct active_list
{
159 const char *identifier
;
160 token_node_t
*marker
;
161 struct active_list
*next
;
164 struct glcpp_parser
{
166 struct hash_table
*defines
;
167 active_list_t
*active
;
170 int newline_as_space
;
173 skip_node_t
*skip_stack
;
174 token_list_t
*lex_from_list
;
175 token_node_t
*lex_from_node
;
178 size_t output_length
;
179 size_t info_log_length
;
181 bool has_new_line_number
;
183 bool has_new_source_number
;
184 int new_source_number
;
187 struct gl_extensions
;
190 glcpp_parser_create (const struct gl_extensions
*extensions
, int api
);
193 glcpp_parser_parse (glcpp_parser_t
*parser
);
196 glcpp_parser_destroy (glcpp_parser_t
*parser
);
199 glcpp_preprocess(void *ralloc_ctx
, const char **shader
, char **info_log
,
200 const struct gl_extensions
*extensions
, int api
);
202 /* Functions for writing to the info log */
205 glcpp_error (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
208 glcpp_warning (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
210 /* Generated by glcpp-lex.l to glcpp-lex.c */
213 glcpp_lex_init_extra (glcpp_parser_t
*parser
, yyscan_t
* scanner
);
216 glcpp_lex_set_source_string(glcpp_parser_t
*parser
, const char *shader
);
219 glcpp_lex (YYSTYPE
*lvalp
, YYLTYPE
*llocp
, yyscan_t scanner
);
222 glcpp_lex_destroy (yyscan_t scanner
);
224 /* Generated by glcpp-parse.y to glcpp-parse.c */
227 yyparse (glcpp_parser_t
*parser
);