dc816e90ee702ba8125d664d1eed563ade0dc04b
[reactos.git] / reactos / dll / opengl / mesa / src / glsl / glcpp / glcpp.h
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 #ifndef GLCPP_H
25 #define GLCPP_H
26
27 #include <stdint.h>
28
29 #include "../ralloc.h"
30
31 #include "program/hash_table.h"
32
33 #define yyscan_t void*
34
35 /* Some data types used for parser values. */
36
37 typedef struct string_node {
38 const char *str;
39 struct string_node *next;
40 } string_node_t;
41
42 typedef struct string_list {
43 string_node_t *head;
44 string_node_t *tail;
45 } string_list_t;
46
47 typedef struct token token_t;
48 typedef struct token_list token_list_t;
49
50 typedef union YYSTYPE
51 {
52 intmax_t ival;
53 char *str;
54 string_list_t *string_list;
55 token_t *token;
56 token_list_t *token_list;
57 } YYSTYPE;
58
59 # define YYSTYPE_IS_TRIVIAL 1
60 # define YYSTYPE_IS_DECLARED 1
61
62 typedef struct YYLTYPE {
63 int first_line;
64 int first_column;
65 int last_line;
66 int last_column;
67 unsigned source;
68 } YYLTYPE;
69 # define YYLTYPE_IS_DECLARED 1
70 # define YYLTYPE_IS_TRIVIAL 1
71
72 # define YYLLOC_DEFAULT(Current, Rhs, N) \
73 do { \
74 if (N) \
75 { \
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; \
80 } \
81 else \
82 { \
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; \
87 } \
88 (Current).source = 0; \
89 } while (0)
90
91 struct token {
92 int type;
93 YYSTYPE value;
94 YYLTYPE location;
95 };
96
97 typedef struct token_node {
98 token_t *token;
99 struct token_node *next;
100 } token_node_t;
101
102 struct token_list {
103 token_node_t *head;
104 token_node_t *tail;
105 token_node_t *non_space_tail;
106 };
107
108 typedef struct argument_node {
109 token_list_t *argument;
110 struct argument_node *next;
111 } argument_node_t;
112
113 typedef struct argument_list {
114 argument_node_t *head;
115 argument_node_t *tail;
116 } argument_list_t;
117
118 typedef struct glcpp_parser glcpp_parser_t;
119
120 typedef enum {
121 TOKEN_CLASS_IDENTIFIER,
122 TOKEN_CLASS_IDENTIFIER_FINALIZED,
123 TOKEN_CLASS_FUNC_MACRO,
124 TOKEN_CLASS_OBJ_MACRO
125 } token_class_t;
126
127 token_class_t
128 glcpp_parser_classify_token (glcpp_parser_t *parser,
129 const char *identifier,
130 int *parameter_index);
131
132 typedef struct {
133 int is_function;
134 string_list_t *parameters;
135 const char *identifier;
136 token_list_t *replacements;
137 } macro_t;
138
139 typedef struct expansion_node {
140 macro_t *macro;
141 token_node_t *replacements;
142 struct expansion_node *next;
143 } expansion_node_t;
144
145 typedef enum skip_type {
146 SKIP_NO_SKIP,
147 SKIP_TO_ELSE,
148 SKIP_TO_ENDIF
149 } skip_type_t;
150
151 typedef struct skip_node {
152 skip_type_t type;
153 YYLTYPE loc; /* location of the initial #if/#elif/... */
154 struct skip_node *next;
155 } skip_node_t;
156
157 typedef struct active_list {
158 const char *identifier;
159 token_node_t *marker;
160 struct active_list *next;
161 } active_list_t;
162
163 struct glcpp_parser {
164 yyscan_t scanner;
165 struct hash_table *defines;
166 active_list_t *active;
167 int lexing_if;
168 int space_tokens;
169 int newline_as_space;
170 int in_control_line;
171 int paren_count;
172 skip_node_t *skip_stack;
173 token_list_t *lex_from_list;
174 token_node_t *lex_from_node;
175 char *output;
176 char *info_log;
177 int error;
178 };
179
180 struct gl_extensions;
181
182 glcpp_parser_t *
183 glcpp_parser_create (const struct gl_extensions *extensions, int api);
184
185 int
186 glcpp_parser_parse (glcpp_parser_t *parser);
187
188 void
189 glcpp_parser_destroy (glcpp_parser_t *parser);
190
191 int
192 preprocess(void *ralloc_ctx, const char **shader, char **info_log,
193 const struct gl_extensions *extensions, int api);
194
195 /* Functions for writing to the info log */
196
197 void
198 glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
199
200 void
201 glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
202
203 /* Generated by glcpp-lex.l to glcpp-lex.c */
204
205 int
206 glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
207
208 void
209 glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);
210
211 int
212 glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner);
213
214 int
215 glcpp_lex_destroy (yyscan_t scanner);
216
217 /* Generated by glcpp-parse.y to glcpp-parse.c */
218
219 int
220 yyparse (glcpp_parser_t *parser);
221
222 #endif