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.
31 #include "hash_table.h"
33 #define yyscan_t void*
35 /* Some data types used for parser values. */
37 typedef struct string_node
{
39 struct string_node
*next
;
42 typedef struct string_list
{
47 typedef struct token token_t
;
48 typedef struct token_list token_list_t
;
54 string_list_t
*string_list
;
56 token_list_t
*token_list
;
59 # define YYSTYPE_IS_TRIVIAL 1
60 # define YYSTYPE_IS_DECLARED 1
62 typedef struct YYLTYPE
{
69 # define YYLTYPE_IS_DECLARED 1
70 # define YYLTYPE_IS_TRIVIAL 1
78 typedef struct token_node
{
80 struct token_node
*next
;
86 token_node_t
*non_space_tail
;
89 typedef struct argument_node
{
90 token_list_t
*argument
;
91 struct argument_node
*next
;
94 typedef struct argument_list
{
95 argument_node_t
*head
;
96 argument_node_t
*tail
;
99 typedef struct glcpp_parser glcpp_parser_t
;
102 TOKEN_CLASS_IDENTIFIER
,
103 TOKEN_CLASS_IDENTIFIER_FINALIZED
,
104 TOKEN_CLASS_FUNC_MACRO
,
105 TOKEN_CLASS_OBJ_MACRO
109 glcpp_parser_classify_token (glcpp_parser_t
*parser
,
110 const char *identifier
,
111 int *parameter_index
);
115 string_list_t
*parameters
;
116 const char *identifier
;
117 token_list_t
*replacements
;
120 typedef struct expansion_node
{
122 token_node_t
*replacements
;
123 struct expansion_node
*next
;
126 typedef enum skip_type
{
132 typedef struct skip_node
{
134 YYLTYPE loc
; /* location of the initial #if/#elif/... */
135 struct skip_node
*next
;
138 typedef struct active_list
{
139 const char *identifier
;
140 token_node_t
*marker
;
141 struct active_list
*next
;
144 struct glcpp_parser
{
146 struct hash_table
*defines
;
147 active_list_t
*active
;
150 int newline_as_space
;
153 skip_node_t
*skip_stack
;
154 token_list_t
*lex_from_list
;
155 token_node_t
*lex_from_node
;
162 glcpp_parser_create (void);
165 glcpp_parser_parse (glcpp_parser_t
*parser
);
168 glcpp_parser_destroy (glcpp_parser_t
*parser
);
171 preprocess(void *talloc_ctx
, const char **shader
, char **info_log
);
173 /* Functions for writing to the info log */
176 glcpp_error (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
179 glcpp_warning (YYLTYPE
*locp
, glcpp_parser_t
*parser
, const char *fmt
, ...);
181 /* Generated by glcpp-lex.l to glcpp-lex.c */
184 glcpp_lex_init_extra (glcpp_parser_t
*parser
, yyscan_t
* scanner
);
187 glcpp_lex_set_source_string(glcpp_parser_t
*parser
, const char *shader
);
190 glcpp_lex (YYSTYPE
*lvalp
, YYLTYPE
*llocp
, yyscan_t scanner
);
193 glcpp_lex_destroy (yyscan_t scanner
);
195 /* Generated by glcpp-parse.y to glcpp-parse.c */
198 yyparse (glcpp_parser_t
*parser
);
200 /* xtalloc - wrappers around talloc to check for out-of-memory */
202 #define xtalloc(ctx, type) (type *)xtalloc_named_const(ctx, sizeof(type), #type)
204 #define xtalloc_size(ctx, size) xtalloc_named_const(ctx, size, __location__)
207 xtalloc_named_const (const void *context
, size_t size
, const char *name
);
210 xtalloc_strdup (const void *t
, const char *p
);
213 xtalloc_strndup (const void *t
, const char *p
, size_t n
);
216 xtalloc_asprintf (const void *t
, const char *fmt
, ...);
219 _xtalloc_reference_loc (const void *context
,
220 const void *ptr
, const char *location
);
222 #define xtalloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_xtalloc_reference_loc((ctx),(ptr), __location__)