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.
29 #include "../ralloc.h"
31 #include "program/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
72 # define YYLLOC_DEFAULT(Current, Rhs, N) \
76 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
77 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
78 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
79 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
83 (Current).first_line = (Current).last_line = \
84 YYRHSLOC(Rhs, 0).last_line; \
85 (Current).first_column = (Current).last_column = \
86 YYRHSLOC(Rhs, 0).last_column; \
88 (Current).source = 0; \
97 typedef struct token_node {
99 struct token_node *next;
105 token_node_t *non_space_tail;
108 typedef struct argument_node {
109 token_list_t *argument;
110 struct argument_node *next;
113 typedef struct argument_list {
114 argument_node_t *head;
115 argument_node_t *tail;
118 typedef struct glcpp_parser glcpp_parser_t;
121 TOKEN_CLASS_IDENTIFIER,
122 TOKEN_CLASS_IDENTIFIER_FINALIZED,
123 TOKEN_CLASS_FUNC_MACRO,
124 TOKEN_CLASS_OBJ_MACRO
128 glcpp_parser_classify_token (glcpp_parser_t *parser,
129 const char *identifier,
130 int *parameter_index);
134 string_list_t *parameters;
135 const char *identifier;
136 token_list_t *replacements;
139 typedef struct expansion_node {
141 token_node_t *replacements;
142 struct expansion_node *next;
145 typedef enum skip_type {
151 typedef struct skip_node {
153 YYLTYPE loc; /* location of the initial #if/#elif/... */
154 struct skip_node *next;
157 typedef struct active_list {
158 const char *identifier;
159 token_node_t *marker;
160 struct active_list *next;
163 struct glcpp_parser {
165 struct hash_table *defines;
166 active_list_t *active;
169 int newline_as_space;
172 skip_node_t *skip_stack;
173 token_list_t *lex_from_list;
174 token_node_t *lex_from_node;
180 struct gl_extensions;
183 glcpp_parser_create (const struct gl_extensions *extensions, int api);
186 glcpp_parser_parse (glcpp_parser_t *parser);
189 glcpp_parser_destroy (glcpp_parser_t *parser);
192 preprocess(void *ralloc_ctx, const char **shader, char **info_log,
193 const struct gl_extensions *extensions, int api);
195 /* Functions for writing to the info log */
198 glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
201 glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
203 /* Generated by glcpp-lex.l to glcpp-lex.c */
206 glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
209 glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);
212 glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner);
215 glcpp_lex_destroy (yyscan_t scanner);
217 /* Generated by glcpp-parse.y to glcpp-parse.c */
220 yyparse (glcpp_parser_t *parser);