glsl: Rename [u]int64_t tokens.
[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
33 #ifdef _MSC_VER
34 #define YY_NO_UNISTD_H
35 #endif
36
37 #define YY_USER_ACTION \
38 do { \
39 yylloc->first_column = yycolumn + 1; \
40 yylloc->first_line = yylloc->last_line = yylineno + 1; \
41 yycolumn += yyleng; \
42 yylloc->last_column = yycolumn + 1; \
43 } while(0);
44
45 #define YY_USER_INIT yylineno = 0; yycolumn = 0; yylloc->source = 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 void *mem_ctx = yyextra->linalloc; \
84 yylval->identifier = linear_strdup(mem_ctx, yytext); \
85 return classify_identifier(yyextra, yytext); \
86 } \
87 } while (0)
88
89 /**
90 * A macro for handling keywords that have been present in GLSL since
91 * its origin, but were changed into reserved words in GLSL 3.00 ES.
92 */
93 #define DEPRECATED_ES_KEYWORD(token) \
94 do { \
95 if (yyextra->is_version(0, 300)) { \
96 _mesa_glsl_error(yylloc, yyextra, \
97 "illegal use of reserved word `%s'", yytext); \
98 return ERROR_TOK; \
99 } else { \
100 return token; \
101 } \
102 } while (0)
103
104 static int
105 literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
106 YYSTYPE *lval, YYLTYPE *lloc, int base)
107 {
108 bool is_uint = (text[len - 1] == 'u' ||
109 text[len - 1] == 'U');
110 bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L');
111 const char *digits = text;
112
113 if (is_long)
114 is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') ||
115 (text[len - 2] == 'U' && text[len - 1] == 'L');
116 /* Skip "0x" */
117 if (base == 16)
118 digits += 2;
119
120 unsigned long long value = strtoull(digits, NULL, base);
121
122 if (is_long)
123 lval->n64 = (int64_t)value;
124 else
125 lval->n = (int)value;
126
127 if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) {
128 /* Tries to catch unintentionally providing a negative value. */
129 _mesa_glsl_warning(lloc, state,
130 "signed literal value `%s' is interpreted as %lld",
131 text, lval->n64);
132 } else if (!is_long && value > UINT_MAX) {
133 /* Note that signed 0xffffffff is valid, not out of range! */
134 if (state->is_version(130, 300)) {
135 _mesa_glsl_error(lloc, state,
136 "literal value `%s' out of range", text);
137 } else {
138 _mesa_glsl_warning(lloc, state,
139 "literal value `%s' out of range", text);
140 }
141 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) {
142 /* Tries to catch unintentionally providing a negative value.
143 * Note that -2147483648 is parsed as -(2147483648), so we don't
144 * want to warn for INT_MAX.
145 */
146 _mesa_glsl_warning(lloc, state,
147 "signed literal value `%s' is interpreted as %d",
148 text, lval->n);
149 }
150 if (is_long)
151 return is_uint ? UINT64CONSTANT : INT64CONSTANT;
152 else
153 return is_uint ? UINTCONSTANT : INTCONSTANT;
154 }
155
156 #define LITERAL_INTEGER(base) \
157 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base)
158
159 %}
160
161 %option bison-bridge bison-locations reentrant noyywrap
162 %option nounput noyy_top_state
163 %option never-interactive
164 %option prefix="_mesa_glsl_lexer_"
165 %option extra-type="struct _mesa_glsl_parse_state *"
166 %option warn nodefault
167
168 /* Note: When adding any start conditions to this list, you must also
169 * update the "Internal compiler error" catch-all rule near the end of
170 * this file. */
171 %x PP PRAGMA
172
173 DEC_INT [1-9][0-9]*
174 HEX_INT 0[xX][0-9a-fA-F]+
175 OCT_INT 0[0-7]*
176 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
177 SPC [ \t]*
178 SPCP [ \t]+
179 HASH ^{SPC}#{SPC}
180 %%
181
182 [ \r\t]+ ;
183
184 /* Preprocessor tokens. */
185 ^[ \t]*#[ \t]*$ ;
186 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; }
187 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
188 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
189 /* Eat characters until the first digit is
190 * encountered
191 */
192 char *ptr = yytext;
193 while (!isdigit(*ptr))
194 ptr++;
195
196 /* Subtract one from the line number because
197 * yylineno is zero-based instead of
198 * one-based.
199 */
200 yylineno = strtol(ptr, &ptr, 0) - 1;
201
202 /* From GLSL 3.30 and GLSL ES on, after processing the
203 * line directive (including its new-line), the implementation
204 * will behave as if it is compiling at the line number passed
205 * as argument. It was line number + 1 in older specifications.
206 */
207 if (yyextra->is_version(330, 100))
208 yylineno--;
209
210 yylloc->source = strtol(ptr, NULL, 0);
211 }
212 {HASH}line{SPCP}{INT}{SPC}$ {
213 /* Eat characters until the first digit is
214 * encountered
215 */
216 char *ptr = yytext;
217 while (!isdigit(*ptr))
218 ptr++;
219
220 /* Subtract one from the line number because
221 * yylineno is zero-based instead of
222 * one-based.
223 */
224 yylineno = strtol(ptr, &ptr, 0) - 1;
225
226 /* From GLSL 3.30 and GLSL ES on, after processing the
227 * line directive (including its new-line), the implementation
228 * will behave as if it is compiling at the line number passed
229 * as argument. It was line number + 1 in older specifications.
230 */
231 if (yyextra->is_version(330, 100))
232 yylineno--;
233 }
234 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
235 BEGIN PP;
236 return PRAGMA_DEBUG_ON;
237 }
238 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
239 BEGIN PP;
240 return PRAGMA_DEBUG_OFF;
241 }
242 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
243 BEGIN PP;
244 return PRAGMA_OPTIMIZE_ON;
245 }
246 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
247 BEGIN PP;
248 return PRAGMA_OPTIMIZE_OFF;
249 }
250 ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
251 BEGIN PP;
252 return PRAGMA_INVARIANT_ALL;
253 }
254 ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; }
255
256 <PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; }
257 <PRAGMA>. { }
258
259 <PP>\/\/[^\n]* { }
260 <PP>[ \t\r]* { }
261 <PP>: return COLON;
262 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
263 void *mem_ctx = yyextra->linalloc;
264 yylval->identifier = linear_strdup(mem_ctx, yytext);
265 return IDENTIFIER;
266 }
267 <PP>[1-9][0-9]* {
268 yylval->n = strtol(yytext, NULL, 10);
269 return INTCONSTANT;
270 }
271 <PP>0 {
272 yylval->n = 0;
273 return INTCONSTANT;
274 }
275 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
276 <PP>. { return yytext[0]; }
277
278 \n { yylineno++; yycolumn = 0; }
279
280 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
281 const return CONST_TOK;
282 bool return BOOL_TOK;
283 float return FLOAT_TOK;
284 int return INT_TOK;
285 uint KEYWORD(130, 300, 130, 300, UINT_TOK);
286
287 break return BREAK;
288 continue return CONTINUE;
289 do return DO;
290 while return WHILE;
291 else return ELSE;
292 for return FOR;
293 if return IF;
294 discard return DISCARD;
295 return return RETURN;
296
297 bvec2 return BVEC2;
298 bvec3 return BVEC3;
299 bvec4 return BVEC4;
300 ivec2 return IVEC2;
301 ivec3 return IVEC3;
302 ivec4 return IVEC4;
303 uvec2 KEYWORD(130, 300, 130, 300, UVEC2);
304 uvec3 KEYWORD(130, 300, 130, 300, UVEC3);
305 uvec4 KEYWORD(130, 300, 130, 300, UVEC4);
306 vec2 return VEC2;
307 vec3 return VEC3;
308 vec4 return VEC4;
309 mat2 return MAT2X2;
310 mat3 return MAT3X3;
311 mat4 return MAT4X4;
312 mat2x2 KEYWORD(120, 300, 120, 300, MAT2X2);
313 mat2x3 KEYWORD(120, 300, 120, 300, MAT2X3);
314 mat2x4 KEYWORD(120, 300, 120, 300, MAT2X4);
315 mat3x2 KEYWORD(120, 300, 120, 300, MAT3X2);
316 mat3x3 KEYWORD(120, 300, 120, 300, MAT3X3);
317 mat3x4 KEYWORD(120, 300, 120, 300, MAT3X4);
318 mat4x2 KEYWORD(120, 300, 120, 300, MAT4X2);
319 mat4x3 KEYWORD(120, 300, 120, 300, MAT4X3);
320 mat4x4 KEYWORD(120, 300, 120, 300, MAT4X4);
321
322 in return IN_TOK;
323 out return OUT_TOK;
324 inout return INOUT_TOK;
325 uniform return UNIFORM;
326 buffer KEYWORD_WITH_ALT(0, 0, 430, 310, yyextra->ARB_shader_storage_buffer_object_enable, BUFFER);
327 varying DEPRECATED_ES_KEYWORD(VARYING);
328 centroid KEYWORD(120, 300, 120, 300, CENTROID);
329 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
330 flat KEYWORD(130, 100, 130, 300, FLAT);
331 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
332 noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
333 patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH);
334
335 sampler1D DEPRECATED_ES_KEYWORD(SAMPLER1D);
336 sampler2D return SAMPLER2D;
337 sampler3D return SAMPLER3D;
338 samplerCube return SAMPLERCUBE;
339 sampler1DArray KEYWORD(130, 300, 130, 0, SAMPLER1DARRAY);
340 sampler2DArray KEYWORD(130, 300, 130, 300, SAMPLER2DARRAY);
341 sampler1DShadow DEPRECATED_ES_KEYWORD(SAMPLER1DSHADOW);
342 sampler2DShadow return SAMPLER2DSHADOW;
343 samplerCubeShadow KEYWORD(130, 300, 130, 300, SAMPLERCUBESHADOW);
344 sampler1DArrayShadow KEYWORD(130, 300, 130, 0, SAMPLER1DARRAYSHADOW);
345 sampler2DArrayShadow KEYWORD(130, 300, 130, 300, SAMPLER2DARRAYSHADOW);
346 isampler1D KEYWORD(130, 300, 130, 0, ISAMPLER1D);
347 isampler2D KEYWORD(130, 300, 130, 300, ISAMPLER2D);
348 isampler3D KEYWORD(130, 300, 130, 300, ISAMPLER3D);
349 isamplerCube KEYWORD(130, 300, 130, 300, ISAMPLERCUBE);
350 isampler1DArray KEYWORD(130, 300, 130, 0, ISAMPLER1DARRAY);
351 isampler2DArray KEYWORD(130, 300, 130, 300, ISAMPLER2DARRAY);
352 usampler1D KEYWORD(130, 300, 130, 0, USAMPLER1D);
353 usampler2D KEYWORD(130, 300, 130, 300, USAMPLER2D);
354 usampler3D KEYWORD(130, 300, 130, 300, USAMPLER3D);
355 usamplerCube KEYWORD(130, 300, 130, 300, USAMPLERCUBE);
356 usampler1DArray KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY);
357 usampler2DArray KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY);
358
359 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
360 /* these are reserved but not defined in GLSL 3.00 */
361 /* [iu]sampler2DMS are defined in GLSL ES 3.10 */
362 sampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS);
363 isampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS);
364 usampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS);
365 sampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, SAMPLER2DMSARRAY);
366 isampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, ISAMPLER2DMSARRAY);
367 usampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, USAMPLER2DMSARRAY);
368
369 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */
370 samplerCubeArray KEYWORD_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, SAMPLERCUBEARRAY);
371 isamplerCubeArray KEYWORD_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, ISAMPLERCUBEARRAY);
372 usamplerCubeArray KEYWORD_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, USAMPLERCUBEARRAY);
373 samplerCubeArrayShadow KEYWORD_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, SAMPLERCUBEARRAYSHADOW);
374
375 samplerExternalOES {
376 if (yyextra->OES_EGL_image_external_enable)
377 return SAMPLEREXTERNALOES;
378 else
379 return IDENTIFIER;
380 }
381
382 /* keywords available with ARB_gpu_shader5 */
383 precise KEYWORD_WITH_ALT(400, 310, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->EXT_gpu_shader5_enable || yyextra->OES_gpu_shader5_enable, PRECISE);
384
385 /* keywords available with ARB_shader_image_load_store */
386 image1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1D);
387 image2D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IMAGE2D);
388 image3D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IMAGE3D);
389 image2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DRECT);
390 imageCube KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IMAGECUBE);
391 imageBuffer KEYWORD_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, IMAGEBUFFER);
392 image1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1DARRAY);
393 image2DArray KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IMAGE2DARRAY);
394 imageCubeArray KEYWORD_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, IMAGECUBEARRAY);
395 image2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMS);
396 image2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMSARRAY);
397 iimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1D);
398 iimage2D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IIMAGE2D);
399 iimage3D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IIMAGE3D);
400 iimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DRECT);
401 iimageCube KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBE);
402 iimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, IIMAGEBUFFER);
403 iimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1DARRAY);
404 iimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DARRAY);
405 iimageCubeArray KEYWORD_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, IIMAGECUBEARRAY);
406 iimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMS);
407 iimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMSARRAY);
408 uimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1D);
409 uimage2D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, UIMAGE2D);
410 uimage3D KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, UIMAGE3D);
411 uimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DRECT);
412 uimageCube KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBE);
413 uimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, UIMAGEBUFFER);
414 uimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1DARRAY);
415 uimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DARRAY);
416 uimageCubeArray KEYWORD_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, UIMAGECUBEARRAY);
417 uimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMS);
418 uimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMSARRAY);
419 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
420 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
421 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
422 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
423
424 coherent KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, COHERENT);
425 volatile KEYWORD_WITH_ALT(110, 100, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, VOLATILE);
426 restrict KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, RESTRICT);
427 readonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, READONLY);
428 writeonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, WRITEONLY);
429
430 atomic_uint KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
431
432 shared KEYWORD_WITH_ALT(430, 310, 430, 310, yyextra->ARB_compute_shader_enable, SHARED);
433
434 struct return STRUCT;
435 void return VOID_TOK;
436
437 layout {
438 if ((yyextra->is_version(140, 300))
439 || yyextra->AMD_conservative_depth_enable
440 || yyextra->ARB_conservative_depth_enable
441 || yyextra->ARB_explicit_attrib_location_enable
442 || yyextra->ARB_explicit_uniform_location_enable
443 || yyextra->has_separate_shader_objects()
444 || yyextra->ARB_uniform_buffer_object_enable
445 || yyextra->ARB_fragment_coord_conventions_enable
446 || yyextra->ARB_shading_language_420pack_enable
447 || yyextra->ARB_compute_shader_enable
448 || yyextra->ARB_tessellation_shader_enable) {
449 return LAYOUT_TOK;
450 } else {
451 void *mem_ctx = yyextra->linalloc;
452 yylval->identifier = linear_strdup(mem_ctx, yytext);
453 return classify_identifier(yyextra, yytext);
454 }
455 }
456
457 \+\+ return INC_OP;
458 -- return DEC_OP;
459 \<= return LE_OP;
460 >= return GE_OP;
461 == return EQ_OP;
462 != return NE_OP;
463 && return AND_OP;
464 \|\| return OR_OP;
465 "^^" return XOR_OP;
466 "<<" return LEFT_OP;
467 ">>" return RIGHT_OP;
468
469 \*= return MUL_ASSIGN;
470 \/= return DIV_ASSIGN;
471 \+= return ADD_ASSIGN;
472 \%= return MOD_ASSIGN;
473 \<\<= return LEFT_ASSIGN;
474 >>= return RIGHT_ASSIGN;
475 &= return AND_ASSIGN;
476 "^=" return XOR_ASSIGN;
477 \|= return OR_ASSIGN;
478 -= return SUB_ASSIGN;
479
480 [1-9][0-9]*([uU]|[lL]|ul|UL)? {
481 return LITERAL_INTEGER(10);
482 }
483 0[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? {
484 return LITERAL_INTEGER(16);
485 }
486 0[0-7]*([uU]|[lL]|ul|UL)? {
487 return LITERAL_INTEGER(8);
488 }
489
490 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
491 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
492 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? |
493 [0-9]+[eE][+-]?[0-9]+[fF]? {
494 struct _mesa_glsl_parse_state *state = yyextra;
495 char suffix = yytext[strlen(yytext) - 1];
496 if (!state->is_version(120, 300) &&
497 (suffix == 'f' || suffix == 'F')) {
498 _mesa_glsl_warning(yylloc, state,
499 "Float suffixes are invalid in GLSL 1.10");
500 }
501 yylval->real = _mesa_strtof(yytext, NULL);
502 return FLOATCONSTANT;
503 }
504
505 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
506 \.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
507 [0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) |
508 [0-9]+[eE][+-]?[0-9]+(lf|LF) {
509 if (!yyextra->is_version(400, 0) &&
510 !yyextra->ARB_gpu_shader_fp64_enable)
511 return ERROR_TOK;
512 yylval->dreal = _mesa_strtod(yytext, NULL);
513 return DOUBLECONSTANT;
514 }
515
516 true {
517 yylval->n = 1;
518 return BOOLCONSTANT;
519 }
520 false {
521 yylval->n = 0;
522 return BOOLCONSTANT;
523 }
524
525
526 /* Reserved words in GLSL 1.10. */
527 asm KEYWORD(110, 100, 0, 0, ASM);
528 class KEYWORD(110, 100, 0, 0, CLASS);
529 union KEYWORD(110, 100, 0, 0, UNION);
530 enum KEYWORD(110, 100, 0, 0, ENUM);
531 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
532 template KEYWORD(110, 100, 0, 0, TEMPLATE);
533 this KEYWORD(110, 100, 0, 0, THIS);
534 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
535 goto KEYWORD(110, 100, 0, 0, GOTO);
536 switch KEYWORD(110, 100, 130, 300, SWITCH);
537 default KEYWORD(110, 100, 130, 300, DEFAULT);
538 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
539 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
540 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
541 static KEYWORD(110, 100, 0, 0, STATIC);
542 extern KEYWORD(110, 100, 0, 0, EXTERN);
543 external KEYWORD(110, 100, 0, 0, EXTERNAL);
544 interface KEYWORD(110, 100, 0, 0, INTERFACE);
545 long KEYWORD(110, 100, 0, 0, LONG_TOK);
546 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
547 double KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DOUBLE_TOK);
548 half KEYWORD(110, 100, 0, 0, HALF);
549 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
550 unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
551 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
552 output KEYWORD(110, 100, 0, 0, OUTPUT);
553 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
554 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
555 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
556 dvec2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC2);
557 dvec3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC3);
558 dvec4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC4);
559 dmat2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
560 dmat3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
561 dmat4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
562 dmat2x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
563 dmat2x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X3);
564 dmat2x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X4);
565 dmat3x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X2);
566 dmat3x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
567 dmat3x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X4);
568 dmat4x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X2);
569 dmat4x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X3);
570 dmat4x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
571 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
572 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
573 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
574 sampler2DRect DEPRECATED_ES_KEYWORD(SAMPLER2DRECT);
575 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
576 sampler2DRectShadow DEPRECATED_ES_KEYWORD(SAMPLER2DRECTSHADOW);
577 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
578 cast KEYWORD(110, 100, 0, 0, CAST);
579 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
580 using KEYWORD(110, 100, 0, 0, USING);
581
582 /* Additional reserved words in GLSL 1.20. */
583 lowp KEYWORD(120, 100, 130, 100, LOWP);
584 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
585 highp KEYWORD(120, 100, 130, 100, HIGHP);
586 precision KEYWORD(120, 100, 130, 100, PRECISION);
587
588 /* Additional reserved words in GLSL 1.30. */
589 case KEYWORD(130, 300, 130, 300, CASE);
590 common KEYWORD(130, 300, 0, 0, COMMON);
591 partition KEYWORD(130, 300, 0, 0, PARTITION);
592 active KEYWORD(130, 300, 0, 0, ACTIVE);
593 superp KEYWORD(130, 100, 0, 0, SUPERP);
594 samplerBuffer KEYWORD_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, SAMPLERBUFFER);
595 filter KEYWORD(130, 300, 0, 0, FILTER);
596 row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR);
597
598 /* Additional reserved words in GLSL 1.40 */
599 isampler2DRect KEYWORD(140, 300, 140, 0, ISAMPLER2DRECT);
600 usampler2DRect KEYWORD(140, 300, 140, 0, USAMPLER2DRECT);
601 isamplerBuffer KEYWORD_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, ISAMPLERBUFFER);
602 usamplerBuffer KEYWORD_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, USAMPLERBUFFER);
603
604 /* Additional reserved words in GLSL ES 3.00 */
605 resource KEYWORD(420, 300, 0, 0, RESOURCE);
606 sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE);
607 subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE);
608
609 /* Additional words for ARB_gpu_shader_int64 */
610 int64_t KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, INT64_TOK);
611 i64vec2 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC2);
612 i64vec3 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC3);
613 i64vec4 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, I64VEC4);
614
615 uint64_t KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, UINT64_TOK);
616 u64vec2 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC2);
617 u64vec3 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC3);
618 u64vec4 KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable, U64VEC4);
619
620 [_a-zA-Z][_a-zA-Z0-9]* {
621 struct _mesa_glsl_parse_state *state = yyextra;
622 void *ctx = state->linalloc;
623 if (state->es_shader && strlen(yytext) > 1024) {
624 _mesa_glsl_error(yylloc, state,
625 "Identifier `%s' exceeds 1024 characters",
626 yytext);
627 } else {
628 yylval->identifier = linear_strdup(ctx, yytext);
629 }
630 return classify_identifier(state, yytext);
631 }
632
633 \. { struct _mesa_glsl_parse_state *state = yyextra;
634 state->is_field = true;
635 return DOT_TOK; }
636
637 . { return yytext[0]; }
638
639 %%
640
641 int
642 classify_identifier(struct _mesa_glsl_parse_state *state, const char *name)
643 {
644 if (state->is_field) {
645 state->is_field = false;
646 return FIELD_SELECTION;
647 }
648 if (state->symbols->get_variable(name) || state->symbols->get_function(name))
649 return IDENTIFIER;
650 else if (state->symbols->get_type(name))
651 return TYPE_IDENTIFIER;
652 else
653 return NEW_IDENTIFIER;
654 }
655
656 void
657 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
658 {
659 yylex_init_extra(state, & state->scanner);
660 yy_scan_string(string, state->scanner);
661 }
662
663 void
664 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
665 {
666 yylex_destroy(state->scanner);
667 }