Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

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