glsl: Add pragma to disable all warnings
[mesa.git] / src / compiler / glsl / glsl_lexer.ll
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 <ctype.h>
25 #include <limits.h>
26 #include "util/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 unsigned name_len, YYSTYPE *output);
33
34 #ifdef _MSC_VER
35 #define YY_NO_UNISTD_H
36 #endif
37
38 #define YY_NO_INPUT
39 #define YY_USER_ACTION \
40 do { \
41 yylloc->first_column = yycolumn + 1; \
42 yylloc->first_line = yylloc->last_line = yylineno + 1; \
43 yycolumn += yyleng; \
44 yylloc->last_column = yycolumn + 1; \
45 } while(0);
46
47 #define YY_USER_INIT yylineno = 0; yycolumn = 0; yylloc->source = 0;
48
49 /* A macro for handling reserved words and keywords across language versions.
50 *
51 * Certain words start out as identifiers, become reserved words in
52 * later language revisions, and finally become language keywords.
53 * This may happen at different times in desktop GLSL and GLSL ES.
54 *
55 * For example, consider the following lexer rule:
56 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER)
57 *
58 * This means that "samplerBuffer" will be treated as:
59 * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40
60 * - a reserved word - error ...in GLSL >= 1.30
61 * - an identifier ...in GLSL < 1.30 or GLSL ES
62 */
63 #define KEYWORD(reserved_glsl, reserved_glsl_es, \
64 allowed_glsl, allowed_glsl_es, token) \
65 KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
66 allowed_glsl, allowed_glsl_es, false, token)
67
68 /**
69 * Like the KEYWORD macro, but the word is also treated as a keyword
70 * if the given boolean expression is true.
71 */
72 #define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
73 allowed_glsl, allowed_glsl_es, \
74 alt_expr, token) \
75 do { \
76 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \
77 || (alt_expr)) { \
78 return token; \
79 } else if (yyextra->is_version(reserved_glsl, \
80 reserved_glsl_es)) { \
81 _mesa_glsl_error(yylloc, yyextra, \
82 "illegal use of reserved word `%s'", yytext); \
83 return ERROR_TOK; \
84 } else { \
85 return classify_identifier(yyextra, yytext, yyleng, yylval); \
86 } \
87 } while (0)
88
89 /**
90 * Like KEYWORD_WITH_ALT, but used for built-in GLSL types
91 */
92 #define TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \
93 allowed_glsl, allowed_glsl_es, \
94 alt_expr, gtype) \
95 do { \
96 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \
97 || (alt_expr)) { \
98 yylval->type = gtype; \
99 return BASIC_TYPE_TOK; \
100 } else if (yyextra->is_version(reserved_glsl, \
101 reserved_glsl_es)) { \
102 _mesa_glsl_error(yylloc, yyextra, \
103 "illegal use of reserved word `%s'", yytext); \
104 return ERROR_TOK; \
105 } else { \
106 return classify_identifier(yyextra, yytext, yyleng, yylval); \
107 } \
108 } while (0)
109
110 #define TYPE(reserved_glsl, reserved_glsl_es, \
111 allowed_glsl, allowed_glsl_es, \
112 gtype) \
113 TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \
114 allowed_glsl, allowed_glsl_es, \
115 false, gtype)
116
117 /**
118 * A macro for handling keywords that have been present in GLSL since
119 * its origin, but were changed into reserved words in GLSL 3.00 ES.
120 */
121 #define DEPRECATED_ES_KEYWORD(token) \
122 do { \
123 if (yyextra->is_version(0, 300)) { \
124 _mesa_glsl_error(yylloc, yyextra, \
125 "illegal use of reserved word `%s'", yytext); \
126 return ERROR_TOK; \
127 } else { \
128 return token; \
129 } \
130 } while (0)
131
132 /**
133 * Like DEPRECATED_ES_KEYWORD, but for types
134 */
135 #define DEPRECATED_ES_TYPE_WITH_ALT(alt_expr, gtype) \
136 do { \
137 if (yyextra->is_version(0, 300)) { \
138 _mesa_glsl_error(yylloc, yyextra, \
139 "illegal use of reserved word `%s'", yytext); \
140 return ERROR_TOK; \
141 } else if (alt_expr) { \
142 yylval->type = gtype; \
143 return BASIC_TYPE_TOK; \
144 } else { \
145 return classify_identifier(yyextra, yytext, yyleng, yylval); \
146 } \
147 } while (0)
148
149 #define DEPRECATED_ES_TYPE(gtype) \
150 DEPRECATED_ES_TYPE_WITH_ALT(true, gtype)
151
152 static int
153 literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
154 YYSTYPE *lval, YYLTYPE *lloc, int base)
155 {
156 bool is_uint = (text[len - 1] == 'u' ||
157 text[len - 1] == 'U');
158 bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L');
159 const char *digits = text;
160
161 if (is_long)
162 is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') ||
163 (text[len - 2] == 'U' && text[len - 1] == 'L');
164 /* Skip "0x" */
165 if (base == 16)
166 digits += 2;
167
168 unsigned long long value = strtoull(digits, NULL, base);
169
170 if (is_long)
171 lval->n64 = (int64_t)value;
172 else
173 lval->n = (int)value;
174
175 if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) {
176 /* Tries to catch unintentionally providing a negative value. */
177 _mesa_glsl_warning(lloc, state,
178 "signed literal value `%s' is interpreted as %lld",
179 text, lval->n64);
180 } else if (!is_long && value > UINT_MAX) {
181 /* Note that signed 0xffffffff is valid, not out of range! */
182 if (state->is_version(130, 300)) {
183 _mesa_glsl_error(lloc, state,
184 "literal value `%s' out of range", text);
185 } else {
186 _mesa_glsl_warning(lloc, state,
187 "literal value `%s' out of range", text);
188 }
189 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) {
190 /* Tries to catch unintentionally providing a negative value.
191 * Note that -2147483648 is parsed as -(2147483648), so we don't
192 * want to warn for INT_MAX.
193 */
194 _mesa_glsl_warning(lloc, state,
195 "signed literal value `%s' is interpreted as %d",
196 text, lval->n);
197 }
198 if (is_long)
199 return is_uint ? UINT64CONSTANT : INT64CONSTANT;
200 else
201 return is_uint ? UINTCONSTANT : INTCONSTANT;
202 }
203
204 #define LITERAL_INTEGER(base) \
205 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base)
206
207 %}
208
209 %option bison-bridge bison-locations reentrant noyywrap
210 %option nounput noyy_top_state
211 %option never-interactive
212 %option prefix="_mesa_glsl_lexer_"
213 %option extra-type="struct _mesa_glsl_parse_state *"
214 %option warn nodefault
215
216 /* Note: When adding any start conditions to this list, you must also
217 * update the "Internal compiler error" catch-all rule near the end of
218 * this file. */
219 %x PP PRAGMA
220
221 DEC_INT [1-9][0-9]*
222 HEX_INT 0[xX][0-9a-fA-F]+
223 OCT_INT 0[0-7]*
224 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
225 SPC [ \t]*
226 SPCP [ \t]+
227 HASH ^{SPC}#{SPC}
228 %%
229
230 [ \r\t]+ ;
231
232 /* Preprocessor tokens. */
233 ^[ \t]*#[ \t]*$ ;
234 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; }
235 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
236 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
237 /* Eat characters until the first digit is
238 * encountered
239 */
240 char *ptr = yytext;
241 while (!isdigit(*ptr))
242 ptr++;
243
244 /* Subtract one from the line number because
245 * yylineno is zero-based instead of
246 * one-based.
247 */
248 yylineno = strtol(ptr, &ptr, 0) - 1;
249
250 /* From GLSL 3.30 and GLSL ES on, after processing the
251 * line directive (including its new-line), the implementation
252 * will behave as if it is compiling at the line number passed
253 * as argument. It was line number + 1 in older specifications.
254 */
255 if (yyextra->is_version(330, 100))
256 yylineno--;
257
258 yylloc->source = strtol(ptr, NULL, 0);
259 }
260 {HASH}line{SPCP}{INT}{SPC}$ {
261 /* Eat characters until the first digit is
262 * encountered
263 */
264 char *ptr = yytext;
265 while (!isdigit(*ptr))
266 ptr++;
267
268 /* Subtract one from the line number because
269 * yylineno is zero-based instead of
270 * one-based.
271 */
272 yylineno = strtol(ptr, &ptr, 0) - 1;
273
274 /* From GLSL 3.30 and GLSL ES on, after processing the
275 * line directive (including its new-line), the implementation
276 * will behave as if it is compiling at the line number passed
277 * as argument. It was line number + 1 in older specifications.
278 */
279 if (yyextra->is_version(330, 100))
280 yylineno--;
281 }
282 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
283 BEGIN PP;
284 return PRAGMA_DEBUG_ON;
285 }
286 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
287 BEGIN PP;
288 return PRAGMA_DEBUG_OFF;
289 }
290 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
291 BEGIN PP;
292 return PRAGMA_OPTIMIZE_ON;
293 }
294 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
295 BEGIN PP;
296 return PRAGMA_OPTIMIZE_OFF;
297 }
298 ^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}on{SPC}\) {
299 BEGIN PP;
300 return PRAGMA_WARNING_ON;
301 }
302 ^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}off{SPC}\) {
303 BEGIN PP;
304 return PRAGMA_WARNING_OFF;
305 }
306 ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
307 BEGIN PP;
308 return PRAGMA_INVARIANT_ALL;
309 }
310 ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; }
311
312 <PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; }
313 <PRAGMA>. { }
314
315 <PP>\/\/[^\n]* { }
316 <PP>[ \t\r]* { }
317 <PP>: return COLON;
318 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
319 /* We're not doing linear_strdup here, to avoid an implicit call
320 * on strlen() for the length of the string, as this is already
321 * found by flex and stored in yyleng
322 */
323 void *mem_ctx = yyextra->linalloc;
324 char *id = (char *) linear_alloc_child(mem_ctx, yyleng + 1);
325 memcpy(id, yytext, yyleng + 1);
326 yylval->identifier = id;
327 return IDENTIFIER;
328 }
329 <PP>[1-9][0-9]* {
330 yylval->n = strtol(yytext, NULL, 10);
331 return INTCONSTANT;
332 }
333 <PP>0 {
334 yylval->n = 0;
335 return INTCONSTANT;
336 }
337 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
338 <PP>. { return yytext[0]; }
339
340 \n { yylineno++; yycolumn = 0; }
341
342 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
343 const return CONST_TOK;
344 bool { yylval->type = glsl_type::bool_type; return BASIC_TYPE_TOK; }
345 float { yylval->type = glsl_type::float_type; return BASIC_TYPE_TOK; }
346 int { yylval->type = glsl_type::int_type; return BASIC_TYPE_TOK; }
347 uint TYPE(130, 300, 130, 300, glsl_type::uint_type);
348
349 break return BREAK;
350 continue return CONTINUE;
351 do return DO;
352 while return WHILE;
353 else return ELSE;
354 for return FOR;
355 if return IF;
356 discard return DISCARD;
357 return return RETURN;
358
359 bvec2 { yylval->type = glsl_type::bvec2_type; return BASIC_TYPE_TOK; }
360 bvec3 { yylval->type = glsl_type::bvec3_type; return BASIC_TYPE_TOK; }
361 bvec4 { yylval->type = glsl_type::bvec4_type; return BASIC_TYPE_TOK; }
362 ivec2 { yylval->type = glsl_type::ivec2_type; return BASIC_TYPE_TOK; }
363 ivec3 { yylval->type = glsl_type::ivec3_type; return BASIC_TYPE_TOK; }
364 ivec4 { yylval->type = glsl_type::ivec4_type; return BASIC_TYPE_TOK; }
365 uvec2 TYPE(130, 300, 130, 300, glsl_type::uvec2_type);
366 uvec3 TYPE(130, 300, 130, 300, glsl_type::uvec3_type);
367 uvec4 TYPE(130, 300, 130, 300, glsl_type::uvec4_type);
368 vec2 { yylval->type = glsl_type::vec2_type; return BASIC_TYPE_TOK; }
369 vec3 { yylval->type = glsl_type::vec3_type; return BASIC_TYPE_TOK; }
370 vec4 { yylval->type = glsl_type::vec4_type; return BASIC_TYPE_TOK; }
371 mat2 { yylval->type = glsl_type::mat2_type; return BASIC_TYPE_TOK; }
372 mat3 { yylval->type = glsl_type::mat3_type; return BASIC_TYPE_TOK; }
373 mat4 { yylval->type = glsl_type::mat4_type; return BASIC_TYPE_TOK; }
374 mat2x2 TYPE(120, 300, 120, 300, glsl_type::mat2_type);
375 mat2x3 TYPE(120, 300, 120, 300, glsl_type::mat2x3_type);
376 mat2x4 TYPE(120, 300, 120, 300, glsl_type::mat2x4_type);
377 mat3x2 TYPE(120, 300, 120, 300, glsl_type::mat3x2_type);
378 mat3x3 TYPE(120, 300, 120, 300, glsl_type::mat3_type);
379 mat3x4 TYPE(120, 300, 120, 300, glsl_type::mat3x4_type);
380 mat4x2 TYPE(120, 300, 120, 300, glsl_type::mat4x2_type);
381 mat4x3 TYPE(120, 300, 120, 300, glsl_type::mat4x3_type);
382 mat4x4 TYPE(120, 300, 120, 300, glsl_type::mat4_type);
383
384 in return IN_TOK;
385 out return OUT_TOK;
386 inout return INOUT_TOK;
387 uniform return UNIFORM;
388 buffer KEYWORD_WITH_ALT(0, 0, 430, 310, yyextra->ARB_shader_storage_buffer_object_enable, BUFFER);
389 varying DEPRECATED_ES_KEYWORD(VARYING);
390 centroid KEYWORD(120, 300, 120, 300, CENTROID);
391 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
392 flat KEYWORD(130, 100, 130, 300, FLAT);
393 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
394 noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
395 patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH);
396
397 sampler1D DEPRECATED_ES_TYPE(glsl_type::sampler1D_type);
398 sampler2D { yylval->type = glsl_type::sampler2D_type; return BASIC_TYPE_TOK; }
399 sampler3D { yylval->type = glsl_type::sampler3D_type; return BASIC_TYPE_TOK; }
400 samplerCube { yylval->type = glsl_type::samplerCube_type; return BASIC_TYPE_TOK; }
401 sampler1DArray TYPE(130, 300, 130, 0, glsl_type::sampler1DArray_type);
402 sampler2DArray TYPE(130, 300, 130, 300, glsl_type::sampler2DArray_type);
403 sampler1DShadow DEPRECATED_ES_TYPE(glsl_type::sampler1DShadow_type);
404 sampler2DShadow { yylval->type = glsl_type::sampler2DShadow_type; return BASIC_TYPE_TOK; }
405 samplerCubeShadow TYPE(130, 300, 130, 300, glsl_type::samplerCubeShadow_type);
406 sampler1DArrayShadow TYPE(130, 300, 130, 0, glsl_type::sampler1DArrayShadow_type);
407 sampler2DArrayShadow TYPE(130, 300, 130, 300, glsl_type::sampler2DArrayShadow_type);
408 isampler1D TYPE(130, 300, 130, 0, glsl_type::isampler1D_type);
409 isampler2D TYPE(130, 300, 130, 300, glsl_type::isampler2D_type);
410 isampler3D TYPE(130, 300, 130, 300, glsl_type::isampler3D_type);
411 isamplerCube TYPE(130, 300, 130, 300, glsl_type::isamplerCube_type);
412 isampler1DArray TYPE(130, 300, 130, 0, glsl_type::isampler1DArray_type);
413 isampler2DArray TYPE(130, 300, 130, 300, glsl_type::isampler2DArray_type);
414 usampler1D TYPE(130, 300, 130, 0, glsl_type::usampler1D_type);
415 usampler2D TYPE(130, 300, 130, 300, glsl_type::usampler2D_type);
416 usampler3D TYPE(130, 300, 130, 300, glsl_type::usampler3D_type);
417 usamplerCube TYPE(130, 300, 130, 300, glsl_type::usamplerCube_type);
418 usampler1DArray TYPE(130, 300, 130, 0, glsl_type::usampler1DArray_type);
419 usampler2DArray TYPE(130, 300, 130, 300, glsl_type::usampler2DArray_type);
420
421 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
422 /* these are reserved but not defined in GLSL 3.00 */
423 /* [iu]sampler2DMS are defined in GLSL ES 3.10 */
424 sampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::sampler2DMS_type);
425 isampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::isampler2DMS_type);
426 usampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::usampler2DMS_type);
427 sampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::sampler2DMSArray_type);
428 isampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::isampler2DMSArray_type);
429 usampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::usampler2DMSArray_type);
430
431 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */
432 samplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::samplerCubeArray_type);
433 isamplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::isamplerCubeArray_type);
434 usamplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::usamplerCubeArray_type);
435 samplerCubeArrayShadow TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::samplerCubeArrayShadow_type);
436
437 samplerExternalOES {
438 if (yyextra->OES_EGL_image_external_enable || yyextra->OES_EGL_image_external_essl3_enable) {
439 yylval->type = glsl_type::samplerExternalOES_type;
440 return BASIC_TYPE_TOK;
441 } else
442 return IDENTIFIER;
443 }
444
445 /* keywords available with ARB_gpu_shader5 */
446 precise KEYWORD_WITH_ALT(400, 310, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->EXT_gpu_shader5_enable || yyextra->OES_gpu_shader5_enable, PRECISE);
447
448 /* keywords available with ARB_shader_image_load_store */
449 image1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1D_type);
450 image2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2D_type);
451 image3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image3D_type);
452 image2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DRect_type);
453 imageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::imageCube_type);
454 imageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::imageBuffer_type);
455 image1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1DArray_type);
456 image2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DArray_type);
457 imageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::imageCubeArray_type);
458 image2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMS_type);
459 image2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMSArray_type);
460 iimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1D_type);
461 iimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2D_type);
462 iimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage3D_type);
463 iimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DRect_type);
464 iimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimageCube_type);
465 iimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::iimageBuffer_type);
466 iimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1DArray_type);
467 iimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DArray_type);
468 iimageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::iimageCubeArray_type);
469 iimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMS_type);
470 iimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMSArray_type);
471 uimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1D_type);
472 uimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2D_type);
473 uimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage3D_type);
474 uimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DRect_type);
475 uimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimageCube_type);
476 uimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::uimageBuffer_type);
477 uimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1DArray_type);
478 uimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DArray_type);
479 uimageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, glsl_type::uimageCubeArray_type);
480 uimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMS_type);
481 uimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMSArray_type);
482 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
483 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
484 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
485 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
486
487 coherent KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, COHERENT);
488 volatile KEYWORD_WITH_ALT(110, 100, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, VOLATILE);
489 restrict KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, RESTRICT);
490 readonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, READONLY);
491 writeonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, WRITEONLY);
492
493 atomic_uint TYPE_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, glsl_type::atomic_uint_type);
494
495 shared KEYWORD_WITH_ALT(430, 310, 430, 310, yyextra->ARB_compute_shader_enable, SHARED);
496
497 struct return STRUCT;
498 void return VOID_TOK;
499
500 layout {
501 if ((yyextra->is_version(140, 300))
502 || yyextra->ARB_bindless_texture_enable
503 || yyextra->KHR_blend_equation_advanced_enable
504 || yyextra->AMD_conservative_depth_enable
505 || yyextra->ARB_conservative_depth_enable
506 || yyextra->ARB_explicit_attrib_location_enable
507 || yyextra->ARB_explicit_uniform_location_enable
508 || yyextra->ARB_post_depth_coverage_enable
509 || yyextra->has_separate_shader_objects()
510 || yyextra->ARB_uniform_buffer_object_enable
511 || yyextra->ARB_fragment_coord_conventions_enable
512 || yyextra->ARB_shading_language_420pack_enable
513 || yyextra->ARB_compute_shader_enable
514 || yyextra->ARB_tessellation_shader_enable
515 || yyextra->EXT_shader_framebuffer_fetch_non_coherent_enable) {
516 return LAYOUT_TOK;
517 } else {
518 return classify_identifier(yyextra, yytext, yyleng, yylval);
519 }
520 }
521
522 \+\+ return INC_OP;
523 -- return DEC_OP;
524 \<= return LE_OP;
525 >= return GE_OP;
526 == return EQ_OP;
527 != return NE_OP;
528 && return AND_OP;
529 \|\| return OR_OP;
530 "^^" return XOR_OP;
531 "<<" return LEFT_OP;
532 ">>" return RIGHT_OP;
533
534 \*= return MUL_ASSIGN;
535 \/= return DIV_ASSIGN;
536 \+= return ADD_ASSIGN;
537 \%= return MOD_ASSIGN;
538 \<\<= return LEFT_ASSIGN;
539 >>= return RIGHT_ASSIGN;
540 &= return AND_ASSIGN;
541 "^=" return XOR_ASSIGN;
542 \|= return OR_ASSIGN;
543 -= return SUB_ASSIGN;
544
545 [1-9][0-9]*([uU]|[lL]|ul|UL)? {
546 return LITERAL_INTEGER(10);
547 }
548 0[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? {
549 return LITERAL_INTEGER(16);
550 }
551 0[0-7]*([uU]|[lL]|ul|UL)? {
552 return LITERAL_INTEGER(8);
553 }
554
555 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
556 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
557 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? |
558 [0-9]+[eE][+-]?[0-9]+[fF]? {
559 struct _mesa_glsl_parse_state *state = yyextra;
560 char suffix = yytext[strlen(yytext) - 1];
561 if (!state->is_version(120, 300) &&
562 (suffix == 'f' || suffix == 'F')) {
563 _mesa_glsl_warning(yylloc, state,
564 "Float suffixes are invalid in GLSL 1.10");
565 }
566 yylval->real = _mesa_strtof(yytext, NULL);
567 return FLOATCONSTANT;
568 }
569
570 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
571 \.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
572 [0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) |
573 [0-9]+[eE][+-]?[0-9]+(lf|LF) {
574 if (!yyextra->is_version(400, 0) &&
575 !yyextra->ARB_gpu_shader_fp64_enable)
576 return ERROR_TOK;
577 yylval->dreal = _mesa_strtod(yytext, NULL);
578 return DOUBLECONSTANT;
579 }
580
581 true {
582 yylval->n = 1;
583 return BOOLCONSTANT;
584 }
585 false {
586 yylval->n = 0;
587 return BOOLCONSTANT;
588 }
589
590
591 /* Reserved words in GLSL 1.10. */
592 asm KEYWORD(110, 100, 0, 0, ASM);
593 class KEYWORD(110, 100, 0, 0, CLASS);
594 union KEYWORD(110, 100, 0, 0, UNION);
595 enum KEYWORD(110, 100, 0, 0, ENUM);
596 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
597 template KEYWORD(110, 100, 0, 0, TEMPLATE);
598 this KEYWORD(110, 100, 0, 0, THIS);
599 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
600 goto KEYWORD(110, 100, 0, 0, GOTO);
601 switch KEYWORD(110, 100, 130, 300, SWITCH);
602 default KEYWORD(110, 100, 130, 300, DEFAULT);
603 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
604 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
605 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
606 static KEYWORD(110, 100, 0, 0, STATIC);
607 extern KEYWORD(110, 100, 0, 0, EXTERN);
608 external KEYWORD(110, 100, 0, 0, EXTERNAL);
609 interface KEYWORD(110, 100, 0, 0, INTERFACE);
610 long KEYWORD(110, 100, 0, 0, LONG_TOK);
611 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
612 double TYPE_WITH_ALT(130, 100, 130, 300, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::double_type);
613 half KEYWORD(110, 100, 0, 0, HALF);
614 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
615 unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
616 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
617 output KEYWORD(110, 100, 0, 0, OUTPUT);
618 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
619 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
620 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
621 dvec2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec2_type);
622 dvec3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec3_type);
623 dvec4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec4_type);
624 dmat2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type);
625 dmat3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type);
626 dmat4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type);
627 dmat2x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type);
628 dmat2x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x3_type);
629 dmat2x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x4_type);
630 dmat3x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x2_type);
631 dmat3x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type);
632 dmat3x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x4_type);
633 dmat4x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x2_type);
634 dmat4x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x3_type);
635 dmat4x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type);
636 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
637 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
638 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
639 sampler2DRect TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRect_type);
640 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
641 sampler2DRectShadow TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRectShadow_type);
642 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
643 cast KEYWORD(110, 100, 0, 0, CAST);
644 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
645 using KEYWORD(110, 100, 0, 0, USING);
646
647 /* Additional reserved words in GLSL 1.20. */
648 lowp KEYWORD(120, 100, 130, 100, LOWP);
649 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
650 highp KEYWORD(120, 100, 130, 100, HIGHP);
651 precision KEYWORD(120, 100, 130, 100, PRECISION);
652
653 /* Additional reserved words in GLSL 1.30. */
654 case KEYWORD(130, 300, 130, 300, CASE);
655 common KEYWORD(130, 300, 0, 0, COMMON);
656 partition KEYWORD(130, 300, 0, 0, PARTITION);
657 active KEYWORD(130, 300, 0, 0, ACTIVE);
658 superp KEYWORD(130, 100, 0, 0, SUPERP);
659 samplerBuffer TYPE_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::samplerBuffer_type);
660 filter KEYWORD(130, 300, 0, 0, FILTER);
661 row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR);
662
663 /* Additional reserved words in GLSL 1.40 */
664 isampler2DRect TYPE(140, 300, 140, 0, glsl_type::isampler2DRect_type);
665 usampler2DRect TYPE(140, 300, 140, 0, glsl_type::usampler2DRect_type);
666 isamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::isamplerBuffer_type);
667 usamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::usamplerBuffer_type);
668
669 /* Additional reserved words in GLSL ES 3.00 */
670 resource KEYWORD(420, 300, 0, 0, RESOURCE);
671 sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE);
672 subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE);
673
674 /* Additional words for ARB_gpu_shader_int64 */
675 int64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::int64_t_type);
676 i64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec2_type);
677 i64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec3_type);
678 i64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec4_type);
679
680 uint64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::uint64_t_type);
681 u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec2_type);
682 u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec3_type);
683 u64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec4_type);
684
685 [_a-zA-Z][_a-zA-Z0-9]* {
686 struct _mesa_glsl_parse_state *state = yyextra;
687 if (state->es_shader && yyleng > 1024) {
688 _mesa_glsl_error(yylloc, state,
689 "Identifier `%s' exceeds 1024 characters",
690 yytext);
691 }
692 return classify_identifier(state, yytext, yyleng, yylval);
693 }
694
695 \. { struct _mesa_glsl_parse_state *state = yyextra;
696 state->is_field = true;
697 return DOT_TOK; }
698
699 . { return yytext[0]; }
700
701 %%
702
703 int
704 classify_identifier(struct _mesa_glsl_parse_state *state, const char *name,
705 unsigned name_len, YYSTYPE *output)
706 {
707 /* We're not doing linear_strdup here, to avoid an implicit call on
708 * strlen() for the length of the string, as this is already found by flex
709 * and stored in yyleng
710 */
711 char *id = (char *) linear_alloc_child(state->linalloc, name_len + 1);
712 memcpy(id, name, name_len + 1);
713 output->identifier = id;
714
715 if (state->is_field) {
716 state->is_field = false;
717 return FIELD_SELECTION;
718 }
719 if (state->symbols->get_variable(name) || state->symbols->get_function(name))
720 return IDENTIFIER;
721 else if (state->symbols->get_type(name))
722 return TYPE_IDENTIFIER;
723 else
724 return NEW_IDENTIFIER;
725 }
726
727 void
728 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
729 {
730 yylex_init_extra(state, & state->scanner);
731 yy_scan_string(string, state->scanner);
732 }
733
734 void
735 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
736 {
737 yylex_destroy(state->scanner);
738 }