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