Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | %{ |
2 | /* |
||
3 | * Copyright © 2008, 2009 Intel Corporation |
||
4 | * |
||
5 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
6 | * copy of this software and associated documentation files (the "Software"), |
||
7 | * to deal in the Software without restriction, including without limitation |
||
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
9 | * and/or sell copies of the Software, and to permit persons to whom the |
||
10 | * Software is furnished to do so, subject to the following conditions: |
||
11 | * |
||
12 | * The above copyright notice and this permission notice (including the next |
||
13 | * paragraph) shall be included in all copies or substantial portions of the |
||
14 | * Software. |
||
15 | * |
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
22 | * DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | #include |
||
25 | #include |
||
26 | #include "strtod.h" |
||
27 | #include "ast.h" |
||
28 | #include "glsl_parser_extras.h" |
||
29 | #include "glsl_parser.h" |
||
30 | |||
31 | static int classify_identifier(struct _mesa_glsl_parse_state *, const char *); |
||
32 | |||
33 | #ifdef _MSC_VER |
||
34 | #define YY_NO_UNISTD_H |
||
35 | #endif |
||
36 | |||
37 | #define YY_USER_ACTION \ |
||
38 | do { \ |
||
39 | yylloc->source = 0; \ |
||
40 | yylloc->first_column = yycolumn + 1; \ |
||
41 | yylloc->first_line = yylineno + 1; \ |
||
42 | yycolumn += yyleng; \ |
||
43 | } while(0); |
||
44 | |||
45 | #define YY_USER_INIT yylineno = 0; yycolumn = 0; |
||
46 | |||
47 | /* A macro for handling reserved words and keywords across language versions. |
||
48 | * |
||
49 | * Certain words start out as identifiers, become reserved words in |
||
50 | * later language revisions, and finally become language keywords. |
||
51 | * This may happen at different times in desktop GLSL and GLSL ES. |
||
52 | * |
||
53 | * For example, consider the following lexer rule: |
||
54 | * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER) |
||
55 | * |
||
56 | * This means that "samplerBuffer" will be treated as: |
||
57 | * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40 |
||
58 | * - a reserved word - error ...in GLSL >= 1.30 |
||
59 | * - an identifier ...in GLSL < 1.30 or GLSL ES |
||
60 | */ |
||
61 | #define KEYWORD(reserved_glsl, reserved_glsl_es, \ |
||
62 | allowed_glsl, allowed_glsl_es, token) \ |
||
63 | KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ |
||
64 | allowed_glsl, allowed_glsl_es, false, token) |
||
65 | |||
66 | /** |
||
67 | * Like the KEYWORD macro, but the word is also treated as a keyword |
||
68 | * if the given boolean expression is true. |
||
69 | */ |
||
70 | #define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ |
||
71 | allowed_glsl, allowed_glsl_es, \ |
||
72 | alt_expr, token) \ |
||
73 | do { \ |
||
74 | if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \ |
||
75 | || (alt_expr)) { \ |
||
76 | return token; \ |
||
77 | } else if (yyextra->is_version(reserved_glsl, \ |
||
78 | reserved_glsl_es)) { \ |
||
79 | _mesa_glsl_error(yylloc, yyextra, \ |
||
80 | "Illegal use of reserved word `%s'", yytext); \ |
||
81 | return ERROR_TOK; \ |
||
82 | } else { \ |
||
83 | yylval->identifier = strdup(yytext); \ |
||
84 | return classify_identifier(yyextra, yytext); \ |
||
85 | } \ |
||
86 | } while (0) |
||
87 | |||
88 | /** |
||
89 | * A macro for handling keywords that have been present in GLSL since |
||
90 | * its origin, but were changed into reserved words in GLSL 3.00 ES. |
||
91 | */ |
||
92 | #define DEPRECATED_ES_KEYWORD(token) \ |
||
93 | do { \ |
||
94 | if (yyextra->is_version(0, 300)) { \ |
||
95 | _mesa_glsl_error(yylloc, yyextra, \ |
||
96 | "Illegal use of reserved word `%s'", yytext); \ |
||
97 | return ERROR_TOK; \ |
||
98 | } else { \ |
||
99 | return token; \ |
||
100 | } \ |
||
101 | } while (0) |
||
102 | |||
103 | static int |
||
104 | literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state, |
||
105 | YYSTYPE *lval, YYLTYPE *lloc, int base) |
||
106 | { |
||
107 | bool is_uint = (text[len - 1] == 'u' || |
||
108 | text[len - 1] == 'U'); |
||
109 | const char *digits = text; |
||
110 | |||
111 | /* Skip "0x" */ |
||
112 | if (base == 16) |
||
113 | digits += 2; |
||
114 | |||
115 | #ifdef _MSC_VER |
||
116 | unsigned __int64 value = _strtoui64(digits, NULL, base); |
||
117 | #else |
||
118 | unsigned long long value = strtoull(digits, NULL, base); |
||
119 | #endif |
||
120 | |||
121 | lval->n = (int)value; |
||
122 | |||
123 | if (value > UINT_MAX) { |
||
124 | /* Note that signed 0xffffffff is valid, not out of range! */ |
||
125 | if (state->is_version(130, 300)) { |
||
126 | _mesa_glsl_error(lloc, state, |
||
127 | "Literal value `%s' out of range", text); |
||
128 | } else { |
||
129 | _mesa_glsl_warning(lloc, state, |
||
130 | "Literal value `%s' out of range", text); |
||
131 | } |
||
132 | } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) { |
||
133 | /* Tries to catch unintentionally providing a negative value. |
||
134 | * Note that -2147483648 is parsed as -(2147483648), so we don't |
||
135 | * want to warn for INT_MAX. |
||
136 | */ |
||
137 | _mesa_glsl_warning(lloc, state, |
||
138 | "Signed literal value `%s' is interpreted as %d", |
||
139 | text, lval->n); |
||
140 | } |
||
141 | return is_uint ? UINTCONSTANT : INTCONSTANT; |
||
142 | } |
||
143 | |||
144 | #define LITERAL_INTEGER(base) \ |
||
145 | literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base) |
||
146 | |||
147 | %} |
||
148 | |||
149 | %option bison-bridge bison-locations reentrant noyywrap |
||
150 | %option nounput noyy_top_state |
||
151 | %option never-interactive |
||
152 | %option prefix="_mesa_glsl_lexer_" |
||
153 | %option extra-type="struct _mesa_glsl_parse_state *" |
||
154 | |||
155 | %x PP PRAGMA |
||
156 | |||
157 | DEC_INT [1-9][0-9]* |
||
158 | HEX_INT 0[xX][0-9a-fA-F]+ |
||
159 | OCT_INT 0[0-7]* |
||
160 | INT ({DEC_INT}|{HEX_INT}|{OCT_INT}) |
||
161 | SPC [ \t]* |
||
162 | SPCP [ \t]+ |
||
163 | HASH ^{SPC}#{SPC} |
||
164 | %% |
||
165 | |||
166 | [ \r\t]+ ; |
||
167 | |||
168 | /* Preprocessor tokens. */ |
||
169 | ^[ \t]*#[ \t]*$ ; |
||
170 | ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; } |
||
171 | ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; } |
||
172 | {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ { |
||
173 | /* Eat characters until the first digit is |
||
174 | * encountered |
||
175 | */ |
||
176 | char *ptr = yytext; |
||
177 | while (!isdigit(*ptr)) |
||
178 | ptr++; |
||
179 | |||
180 | /* Subtract one from the line number because |
||
181 | * yylineno is zero-based instead of |
||
182 | * one-based. |
||
183 | */ |
||
184 | yylineno = strtol(ptr, &ptr, 0) - 1; |
||
185 | yylloc->source = strtol(ptr, NULL, 0); |
||
186 | } |
||
187 | {HASH}line{SPCP}{INT}{SPC}$ { |
||
188 | /* Eat characters until the first digit is |
||
189 | * encountered |
||
190 | */ |
||
191 | char *ptr = yytext; |
||
192 | while (!isdigit(*ptr)) |
||
193 | ptr++; |
||
194 | |||
195 | /* Subtract one from the line number because |
||
196 | * yylineno is zero-based instead of |
||
197 | * one-based. |
||
198 | */ |
||
199 | yylineno = strtol(ptr, &ptr, 0) - 1; |
||
200 | } |
||
201 | ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) { |
||
202 | BEGIN PP; |
||
203 | return PRAGMA_DEBUG_ON; |
||
204 | } |
||
205 | ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) { |
||
206 | BEGIN PP; |
||
207 | return PRAGMA_DEBUG_OFF; |
||
208 | } |
||
209 | ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) { |
||
210 | BEGIN PP; |
||
211 | return PRAGMA_OPTIMIZE_ON; |
||
212 | } |
||
213 | ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) { |
||
214 | BEGIN PP; |
||
215 | return PRAGMA_OPTIMIZE_OFF; |
||
216 | } |
||
217 | ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) { |
||
218 | BEGIN PP; |
||
219 | return PRAGMA_INVARIANT_ALL; |
||
220 | } |
||
221 | ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; } |
||
222 | |||
223 |
|
||
224 |
|
||
225 | |||
226 |
|
||
227 |
|
||
228 |
|
||
229 |
|
||
230 | yylval->identifier = strdup(yytext); |
||
231 | return IDENTIFIER; |
||
232 | } |
||
233 |
|
||
234 | yylval->n = strtol(yytext, NULL, 10); |
||
235 | return INTCONSTANT; |
||
236 | } |
||
237 |
|
||
238 | |||
239 | \n { yylineno++; yycolumn = 0; } |
||
240 | |||
241 | attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE); |
||
242 | const return CONST_TOK; |
||
243 | bool return BOOL_TOK; |
||
244 | float return FLOAT_TOK; |
||
245 | int return INT_TOK; |
||
246 | uint KEYWORD(130, 300, 130, 300, UINT_TOK); |
||
247 | |||
248 | break return BREAK; |
||
249 | continue return CONTINUE; |
||
250 | do return DO; |
||
251 | while return WHILE; |
||
252 | else return ELSE; |
||
253 | for return FOR; |
||
254 | if return IF; |
||
255 | discard return DISCARD; |
||
256 | return return RETURN; |
||
257 | |||
258 | bvec2 return BVEC2; |
||
259 | bvec3 return BVEC3; |
||
260 | bvec4 return BVEC4; |
||
261 | ivec2 return IVEC2; |
||
262 | ivec3 return IVEC3; |
||
263 | ivec4 return IVEC4; |
||
264 | uvec2 KEYWORD(130, 300, 130, 300, UVEC2); |
||
265 | uvec3 KEYWORD(130, 300, 130, 300, UVEC3); |
||
266 | uvec4 KEYWORD(130, 300, 130, 300, UVEC4); |
||
267 | vec2 return VEC2; |
||
268 | vec3 return VEC3; |
||
269 | vec4 return VEC4; |
||
270 | mat2 return MAT2X2; |
||
271 | mat3 return MAT3X3; |
||
272 | mat4 return MAT4X4; |
||
273 | mat2x2 KEYWORD(120, 300, 120, 300, MAT2X2); |
||
274 | mat2x3 KEYWORD(120, 300, 120, 300, MAT2X3); |
||
275 | mat2x4 KEYWORD(120, 300, 120, 300, MAT2X4); |
||
276 | mat3x2 KEYWORD(120, 300, 120, 300, MAT3X2); |
||
277 | mat3x3 KEYWORD(120, 300, 120, 300, MAT3X3); |
||
278 | mat3x4 KEYWORD(120, 300, 120, 300, MAT3X4); |
||
279 | mat4x2 KEYWORD(120, 300, 120, 300, MAT4X2); |
||
280 | mat4x3 KEYWORD(120, 300, 120, 300, MAT4X3); |
||
281 | mat4x4 KEYWORD(120, 300, 120, 300, MAT4X4); |
||
282 | |||
283 | in return IN_TOK; |
||
284 | out return OUT_TOK; |
||
285 | inout return INOUT_TOK; |
||
286 | uniform return UNIFORM; |
||
287 | varying DEPRECATED_ES_KEYWORD(VARYING); |
||
288 | centroid KEYWORD(120, 300, 120, 300, CENTROID); |
||
289 | invariant KEYWORD(120, 100, 120, 100, INVARIANT); |
||
290 | flat KEYWORD(130, 100, 130, 300, FLAT); |
||
291 | smooth KEYWORD(130, 300, 130, 300, SMOOTH); |
||
292 | noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE); |
||
293 | |||
294 | sampler1D DEPRECATED_ES_KEYWORD(SAMPLER1D); |
||
295 | sampler2D return SAMPLER2D; |
||
296 | sampler3D return SAMPLER3D; |
||
297 | samplerCube return SAMPLERCUBE; |
||
298 | sampler1DArray KEYWORD(130, 300, 130, 0, SAMPLER1DARRAY); |
||
299 | sampler2DArray KEYWORD(130, 300, 130, 300, SAMPLER2DARRAY); |
||
300 | sampler1DShadow DEPRECATED_ES_KEYWORD(SAMPLER1DSHADOW); |
||
301 | sampler2DShadow return SAMPLER2DSHADOW; |
||
302 | samplerCubeShadow KEYWORD(130, 300, 130, 300, SAMPLERCUBESHADOW); |
||
303 | sampler1DArrayShadow KEYWORD(130, 300, 130, 0, SAMPLER1DARRAYSHADOW); |
||
304 | sampler2DArrayShadow KEYWORD(130, 300, 130, 300, SAMPLER2DARRAYSHADOW); |
||
305 | isampler1D KEYWORD(130, 300, 130, 0, ISAMPLER1D); |
||
306 | isampler2D KEYWORD(130, 300, 130, 300, ISAMPLER2D); |
||
307 | isampler3D KEYWORD(130, 300, 130, 300, ISAMPLER3D); |
||
308 | isamplerCube KEYWORD(130, 300, 130, 300, ISAMPLERCUBE); |
||
309 | isampler1DArray KEYWORD(130, 300, 130, 0, ISAMPLER1DARRAY); |
||
310 | isampler2DArray KEYWORD(130, 300, 130, 300, ISAMPLER2DARRAY); |
||
311 | usampler1D KEYWORD(130, 300, 130, 0, USAMPLER1D); |
||
312 | usampler2D KEYWORD(130, 300, 130, 300, USAMPLER2D); |
||
313 | usampler3D KEYWORD(130, 300, 130, 300, USAMPLER3D); |
||
314 | usamplerCube KEYWORD(130, 300, 130, 300, USAMPLERCUBE); |
||
315 | usampler1DArray KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY); |
||
316 | usampler2DArray KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY); |
||
317 | |||
318 | /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */ |
||
319 | /* these are reserved but not defined in GLSL 3.00 */ |
||
320 | sampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS); |
||
321 | isampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS); |
||
322 | usampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS); |
||
323 | sampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMSARRAY); |
||
324 | isampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMSARRAY); |
||
325 | usampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMSARRAY); |
||
326 | |||
327 | /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */ |
||
328 | samplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAY); |
||
329 | isamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, ISAMPLERCUBEARRAY); |
||
330 | usamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, USAMPLERCUBEARRAY); |
||
331 | samplerCubeArrayShadow KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAYSHADOW); |
||
332 | |||
333 | samplerExternalOES { |
||
334 | if (yyextra->OES_EGL_image_external_enable) |
||
335 | return SAMPLEREXTERNALOES; |
||
336 | else |
||
337 | return IDENTIFIER; |
||
338 | } |
||
339 | |||
340 | |||
341 | struct return STRUCT; |
||
342 | void return VOID_TOK; |
||
343 | |||
344 | layout { |
||
345 | if ((yyextra->is_version(140, 300)) |
||
346 | || yyextra->AMD_conservative_depth_enable |
||
347 | || yyextra->ARB_conservative_depth_enable |
||
348 | || yyextra->ARB_explicit_attrib_location_enable |
||
349 | || yyextra->ARB_uniform_buffer_object_enable |
||
350 | || yyextra->ARB_fragment_coord_conventions_enable |
||
351 | || yyextra->ARB_shading_language_420pack_enable) { |
||
352 | return LAYOUT_TOK; |
||
353 | } else { |
||
354 | yylval->identifier = strdup(yytext); |
||
355 | return classify_identifier(yyextra, yytext); |
||
356 | } |
||
357 | } |
||
358 | |||
359 | \+\+ return INC_OP; |
||
360 | -- return DEC_OP; |
||
361 | \<= return LE_OP; |
||
362 | >= return GE_OP; |
||
363 | == return EQ_OP; |
||
364 | != return NE_OP; |
||
365 | && return AND_OP; |
||
366 | \|\| return OR_OP; |
||
367 | "^^" return XOR_OP; |
||
368 | "<<" return LEFT_OP; |
||
369 | ">>" return RIGHT_OP; |
||
370 | |||
371 | \*= return MUL_ASSIGN; |
||
372 | \/= return DIV_ASSIGN; |
||
373 | \+= return ADD_ASSIGN; |
||
374 | \%= return MOD_ASSIGN; |
||
375 | \<\<= return LEFT_ASSIGN; |
||
376 | >>= return RIGHT_ASSIGN; |
||
377 | &= return AND_ASSIGN; |
||
378 | "^=" return XOR_ASSIGN; |
||
379 | \|= return OR_ASSIGN; |
||
380 | -= return SUB_ASSIGN; |
||
381 | |||
382 | [1-9][0-9]*[uU]? { |
||
383 | return LITERAL_INTEGER(10); |
||
384 | } |
||
385 | 0[xX][0-9a-fA-F]+[uU]? { |
||
386 | return LITERAL_INTEGER(16); |
||
387 | } |
||
388 | 0[0-7]*[uU]? { |
||
389 | return LITERAL_INTEGER(8); |
||
390 | } |
||
391 | |||
392 | [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? { |
||
393 | yylval->real = glsl_strtof(yytext, NULL); |
||
394 | return FLOATCONSTANT; |
||
395 | } |
||
396 | \.[0-9]+([eE][+-]?[0-9]+)?[fF]? { |
||
397 | yylval->real = glsl_strtof(yytext, NULL); |
||
398 | return FLOATCONSTANT; |
||
399 | } |
||
400 | [0-9]+\.([eE][+-]?[0-9]+)?[fF]? { |
||
401 | yylval->real = glsl_strtof(yytext, NULL); |
||
402 | return FLOATCONSTANT; |
||
403 | } |
||
404 | [0-9]+[eE][+-]?[0-9]+[fF]? { |
||
405 | yylval->real = glsl_strtof(yytext, NULL); |
||
406 | return FLOATCONSTANT; |
||
407 | } |
||
408 | [0-9]+[fF] { |
||
409 | yylval->real = glsl_strtof(yytext, NULL); |
||
410 | return FLOATCONSTANT; |
||
411 | } |
||
412 | |||
413 | true { |
||
414 | yylval->n = 1; |
||
415 | return BOOLCONSTANT; |
||
416 | } |
||
417 | false { |
||
418 | yylval->n = 0; |
||
419 | return BOOLCONSTANT; |
||
420 | } |
||
421 | |||
422 | |||
423 | /* Reserved words in GLSL 1.10. */ |
||
424 | asm KEYWORD(110, 100, 0, 0, ASM); |
||
425 | class KEYWORD(110, 100, 0, 0, CLASS); |
||
426 | union KEYWORD(110, 100, 0, 0, UNION); |
||
427 | enum KEYWORD(110, 100, 0, 0, ENUM); |
||
428 | typedef KEYWORD(110, 100, 0, 0, TYPEDEF); |
||
429 | template KEYWORD(110, 100, 0, 0, TEMPLATE); |
||
430 | this KEYWORD(110, 100, 0, 0, THIS); |
||
431 | packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK); |
||
432 | goto KEYWORD(110, 100, 0, 0, GOTO); |
||
433 | switch KEYWORD(110, 100, 130, 300, SWITCH); |
||
434 | default KEYWORD(110, 100, 130, 300, DEFAULT); |
||
435 | inline KEYWORD(110, 100, 0, 0, INLINE_TOK); |
||
436 | noinline KEYWORD(110, 100, 0, 0, NOINLINE); |
||
437 | volatile KEYWORD(110, 100, 0, 0, VOLATILE); |
||
438 | public KEYWORD(110, 100, 0, 0, PUBLIC_TOK); |
||
439 | static KEYWORD(110, 100, 0, 0, STATIC); |
||
440 | extern KEYWORD(110, 100, 0, 0, EXTERN); |
||
441 | external KEYWORD(110, 100, 0, 0, EXTERNAL); |
||
442 | interface KEYWORD(110, 100, 0, 0, INTERFACE); |
||
443 | long KEYWORD(110, 100, 0, 0, LONG_TOK); |
||
444 | short KEYWORD(110, 100, 0, 0, SHORT_TOK); |
||
445 | double KEYWORD(110, 100, 400, 0, DOUBLE_TOK); |
||
446 | half KEYWORD(110, 100, 0, 0, HALF); |
||
447 | fixed KEYWORD(110, 100, 0, 0, FIXED_TOK); |
||
448 | unsigned KEYWORD(110, 100, 0, 0, UNSIGNED); |
||
449 | input KEYWORD(110, 100, 0, 0, INPUT_TOK); |
||
450 | output KEYWORD(110, 100, 0, 0, OUTPUT); |
||
451 | hvec2 KEYWORD(110, 100, 0, 0, HVEC2); |
||
452 | hvec3 KEYWORD(110, 100, 0, 0, HVEC3); |
||
453 | hvec4 KEYWORD(110, 100, 0, 0, HVEC4); |
||
454 | dvec2 KEYWORD(110, 100, 400, 0, DVEC2); |
||
455 | dvec3 KEYWORD(110, 100, 400, 0, DVEC3); |
||
456 | dvec4 KEYWORD(110, 100, 400, 0, DVEC4); |
||
457 | fvec2 KEYWORD(110, 100, 0, 0, FVEC2); |
||
458 | fvec3 KEYWORD(110, 100, 0, 0, FVEC3); |
||
459 | fvec4 KEYWORD(110, 100, 0, 0, FVEC4); |
||
460 | sampler2DRect DEPRECATED_ES_KEYWORD(SAMPLER2DRECT); |
||
461 | sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT); |
||
462 | sampler2DRectShadow DEPRECATED_ES_KEYWORD(SAMPLER2DRECTSHADOW); |
||
463 | sizeof KEYWORD(110, 100, 0, 0, SIZEOF); |
||
464 | cast KEYWORD(110, 100, 0, 0, CAST); |
||
465 | namespace KEYWORD(110, 100, 0, 0, NAMESPACE); |
||
466 | using KEYWORD(110, 100, 0, 0, USING); |
||
467 | |||
468 | /* Additional reserved words in GLSL 1.20. */ |
||
469 | lowp KEYWORD(120, 100, 130, 100, LOWP); |
||
470 | mediump KEYWORD(120, 100, 130, 100, MEDIUMP); |
||
471 | highp KEYWORD(120, 100, 130, 100, HIGHP); |
||
472 | precision KEYWORD(120, 100, 130, 100, PRECISION); |
||
473 | |||
474 | /* Additional reserved words in GLSL 1.30. */ |
||
475 | case KEYWORD(130, 300, 130, 300, CASE); |
||
476 | common KEYWORD(130, 300, 0, 0, COMMON); |
||
477 | partition KEYWORD(130, 300, 0, 0, PARTITION); |
||
478 | active KEYWORD(130, 300, 0, 0, ACTIVE); |
||
479 | superp KEYWORD(130, 100, 0, 0, SUPERP); |
||
480 | samplerBuffer KEYWORD(130, 300, 140, 0, SAMPLERBUFFER); |
||
481 | filter KEYWORD(130, 300, 0, 0, FILTER); |
||
482 | image1D KEYWORD(130, 300, 0, 0, IMAGE1D); |
||
483 | image2D KEYWORD(130, 300, 0, 0, IMAGE2D); |
||
484 | image3D KEYWORD(130, 300, 0, 0, IMAGE3D); |
||
485 | imageCube KEYWORD(130, 300, 0, 0, IMAGECUBE); |
||
486 | iimage1D KEYWORD(130, 300, 0, 0, IIMAGE1D); |
||
487 | iimage2D KEYWORD(130, 300, 0, 0, IIMAGE2D); |
||
488 | iimage3D KEYWORD(130, 300, 0, 0, IIMAGE3D); |
||
489 | iimageCube KEYWORD(130, 300, 0, 0, IIMAGECUBE); |
||
490 | uimage1D KEYWORD(130, 300, 0, 0, UIMAGE1D); |
||
491 | uimage2D KEYWORD(130, 300, 0, 0, UIMAGE2D); |
||
492 | uimage3D KEYWORD(130, 300, 0, 0, UIMAGE3D); |
||
493 | uimageCube KEYWORD(130, 300, 0, 0, UIMAGECUBE); |
||
494 | image1DArray KEYWORD(130, 300, 0, 0, IMAGE1DARRAY); |
||
495 | image2DArray KEYWORD(130, 300, 0, 0, IMAGE2DARRAY); |
||
496 | iimage1DArray KEYWORD(130, 300, 0, 0, IIMAGE1DARRAY); |
||
497 | iimage2DArray KEYWORD(130, 300, 0, 0, IIMAGE2DARRAY); |
||
498 | uimage1DArray KEYWORD(130, 300, 0, 0, UIMAGE1DARRAY); |
||
499 | uimage2DArray KEYWORD(130, 300, 0, 0, UIMAGE2DARRAY); |
||
500 | image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW); |
||
501 | image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW); |
||
502 | image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW); |
||
503 | image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW); |
||
504 | imageBuffer KEYWORD(130, 300, 0, 0, IMAGEBUFFER); |
||
505 | iimageBuffer KEYWORD(130, 300, 0, 0, IIMAGEBUFFER); |
||
506 | uimageBuffer KEYWORD(130, 300, 0, 0, UIMAGEBUFFER); |
||
507 | row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR); |
||
508 | |||
509 | /* Additional reserved words in GLSL 1.40 */ |
||
510 | isampler2DRect KEYWORD(140, 300, 140, 0, ISAMPLER2DRECT); |
||
511 | usampler2DRect KEYWORD(140, 300, 140, 0, USAMPLER2DRECT); |
||
512 | isamplerBuffer KEYWORD(140, 300, 140, 0, ISAMPLERBUFFER); |
||
513 | usamplerBuffer KEYWORD(140, 300, 140, 0, USAMPLERBUFFER); |
||
514 | |||
515 | /* Additional reserved words in GLSL ES 3.00 */ |
||
516 | coherent KEYWORD(0, 300, 0, 0, COHERENT); |
||
517 | restrict KEYWORD(0, 300, 0, 0, RESTRICT); |
||
518 | readonly KEYWORD(0, 300, 0, 0, READONLY); |
||
519 | writeonly KEYWORD(0, 300, 0, 0, WRITEONLY); |
||
520 | resource KEYWORD(0, 300, 0, 0, RESOURCE); |
||
521 | atomic_uint KEYWORD(0, 300, 0, 0, ATOMIC_UINT); |
||
522 | patch KEYWORD(0, 300, 0, 0, PATCH); |
||
523 | sample KEYWORD(0, 300, 0, 0, SAMPLE); |
||
524 | subroutine KEYWORD(0, 300, 0, 0, SUBROUTINE); |
||
525 | |||
526 | |||
527 | [_a-zA-Z][_a-zA-Z0-9]* { |
||
528 | struct _mesa_glsl_parse_state *state = yyextra; |
||
529 | void *ctx = state; |
||
530 | yylval->identifier = ralloc_strdup(ctx, yytext); |
||
531 | return classify_identifier(state, yytext); |
||
532 | } |
||
533 | |||
534 | . { return yytext[0]; } |
||
535 | |||
536 | %% |
||
537 | |||
538 | int |
||
539 | classify_identifier(struct _mesa_glsl_parse_state *state, const char *name) |
||
540 | { |
||
541 | if (state->symbols->get_variable(name) || state->symbols->get_function(name)) |
||
542 | return IDENTIFIER; |
||
543 | else if (state->symbols->get_type(name)) |
||
544 | return TYPE_IDENTIFIER; |
||
545 | else |
||
546 | return NEW_IDENTIFIER; |
||
547 | } |
||
548 | |||
549 | void |
||
550 | _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) |
||
551 | { |
||
552 | yylex_init_extra(state, & state->scanner); |
||
553 | yy_scan_string(string, state->scanner); |
||
554 | } |
||
555 | |||
556 | void |
||
557 | _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) |
||
558 | { |
||
559 | yylex_destroy(state->scanner); |
||
560 | }=>\<=>"><">=>> |