3 * Copyright © 2008, 2009 Intel Corporation
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:
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
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.
26 #include "util/strtod.h"
28 #include "glsl_parser_extras.h"
29 #include "glsl_parser.h"
31 static int classify_identifier(struct _mesa_glsl_parse_state *, const char *);
34 #define YY_NO_UNISTD_H
37 #define YY_USER_ACTION \
39 yylloc->first_column = yycolumn + 1; \
40 yylloc->first_line = yylloc->last_line = yylineno + 1; \
42 yylloc->last_column = yycolumn + 1; \
45 #define YY_USER_INIT yylineno = 0; yycolumn = 0; yylloc->source = 0;
47 /* A macro for handling reserved words and keywords across language versions.
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.
53 * For example, consider the following lexer rule:
54 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER)
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
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)
67 * Like the KEYWORD macro, but the word is also treated as a keyword
68 * if the given boolean expression is true.
70 #define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \
71 allowed_glsl, allowed_glsl_es, \
74 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \
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); \
83 void *mem_ctx = yyextra; \
84 yylval->identifier = ralloc_strdup(mem_ctx, yytext); \
85 return classify_identifier(yyextra, yytext); \
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.
93 #define DEPRECATED_ES_KEYWORD(token) \
95 if (yyextra->is_version(0, 300)) { \
96 _mesa_glsl_error(yylloc, yyextra, \
97 "illegal use of reserved word `%s'", yytext); \
105 literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state,
106 YYSTYPE *lval, YYLTYPE *lloc, int base)
108 bool is_uint = (text[len - 1] == 'u' ||
109 text[len - 1] == 'U');
110 const char *digits = text;
117 unsigned __int64 value = _strtoui64(digits, NULL, base);
119 unsigned long long value = strtoull(digits, NULL, base);
122 lval->n = (int)value;
124 if (value > UINT_MAX) {
125 /* Note that signed 0xffffffff is valid, not out of range! */
126 if (state->is_version(130, 300)) {
127 _mesa_glsl_error(lloc, state,
128 "literal value `%s' out of range", text);
130 _mesa_glsl_warning(lloc, state,
131 "literal value `%s' out of range", text);
133 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) {
134 /* Tries to catch unintentionally providing a negative value.
135 * Note that -2147483648 is parsed as -(2147483648), so we don't
136 * want to warn for INT_MAX.
138 _mesa_glsl_warning(lloc, state,
139 "signed literal value `%s' is interpreted as %d",
142 return is_uint ? UINTCONSTANT : INTCONSTANT;
145 #define LITERAL_INTEGER(base) \
146 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base)
150 %option bison-bridge bison-locations reentrant noyywrap
151 %option nounput noyy_top_state
152 %option never-interactive
153 %option prefix="_mesa_glsl_lexer_"
154 %option extra-type="struct _mesa_glsl_parse_state *"
155 %option warn nodefault
157 /* Note: When adding any start conditions to this list, you must also
158 * update the "Internal compiler error" catch-all rule near the end of
163 HEX_INT 0[xX][0-9a-fA-F]+
165 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
173 /* Preprocessor tokens. */
175 ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; }
176 ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
177 {HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
178 /* Eat characters until the first digit is
182 while (!isdigit(*ptr))
185 /* Subtract one from the line number because
186 * yylineno is zero-based instead of
189 yylineno = strtol(ptr, &ptr, 0) - 1;
191 /* From GLSL 3.30 and GLSL ES on, after processing the
192 * line directive (including its new-line), the implementation
193 * will behave as if it is compiling at the line number passed
194 * as argument. It was line number + 1 in older specifications.
196 if (yyextra->is_version(330, 100))
199 yylloc->source = strtol(ptr, NULL, 0);
201 {HASH}line{SPCP}{INT}{SPC}$ {
202 /* Eat characters until the first digit is
206 while (!isdigit(*ptr))
209 /* Subtract one from the line number because
210 * yylineno is zero-based instead of
213 yylineno = strtol(ptr, &ptr, 0) - 1;
215 /* From GLSL 3.30 and GLSL ES on, after processing the
216 * line directive (including its new-line), the implementation
217 * will behave as if it is compiling at the line number passed
218 * as argument. It was line number + 1 in older specifications.
220 if (yyextra->is_version(330, 100))
223 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
225 return PRAGMA_DEBUG_ON;
227 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) {
229 return PRAGMA_DEBUG_OFF;
231 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) {
233 return PRAGMA_OPTIMIZE_ON;
235 ^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) {
237 return PRAGMA_OPTIMIZE_OFF;
239 ^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) {
241 return PRAGMA_INVARIANT_ALL;
243 ^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; }
245 <PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; }
251 <PP>[_a-zA-Z][_a-zA-Z0-9]* {
252 void *mem_ctx = yyextra;
253 yylval->identifier = ralloc_strdup(mem_ctx, yytext);
257 yylval->n = strtol(yytext, NULL, 10);
260 <PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; }
261 <PP>. { return yytext[0]; }
263 \n { yylineno++; yycolumn = 0; }
265 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
266 const return CONST_TOK;
267 bool return BOOL_TOK;
268 float return FLOAT_TOK;
270 uint KEYWORD(130, 300, 130, 300, UINT_TOK);
273 continue return CONTINUE;
279 discard return DISCARD;
280 return return RETURN;
288 uvec2 KEYWORD(130, 300, 130, 300, UVEC2);
289 uvec3 KEYWORD(130, 300, 130, 300, UVEC3);
290 uvec4 KEYWORD(130, 300, 130, 300, UVEC4);
297 mat2x2 KEYWORD(120, 300, 120, 300, MAT2X2);
298 mat2x3 KEYWORD(120, 300, 120, 300, MAT2X3);
299 mat2x4 KEYWORD(120, 300, 120, 300, MAT2X4);
300 mat3x2 KEYWORD(120, 300, 120, 300, MAT3X2);
301 mat3x3 KEYWORD(120, 300, 120, 300, MAT3X3);
302 mat3x4 KEYWORD(120, 300, 120, 300, MAT3X4);
303 mat4x2 KEYWORD(120, 300, 120, 300, MAT4X2);
304 mat4x3 KEYWORD(120, 300, 120, 300, MAT4X3);
305 mat4x4 KEYWORD(120, 300, 120, 300, MAT4X4);
309 inout return INOUT_TOK;
310 uniform return UNIFORM;
311 varying DEPRECATED_ES_KEYWORD(VARYING);
312 centroid KEYWORD(120, 300, 120, 300, CENTROID);
313 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
314 flat KEYWORD(130, 100, 130, 300, FLAT);
315 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
316 noperspective KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
318 sampler1D DEPRECATED_ES_KEYWORD(SAMPLER1D);
319 sampler2D return SAMPLER2D;
320 sampler3D return SAMPLER3D;
321 samplerCube return SAMPLERCUBE;
322 sampler1DArray KEYWORD(130, 300, 130, 0, SAMPLER1DARRAY);
323 sampler2DArray KEYWORD(130, 300, 130, 300, SAMPLER2DARRAY);
324 sampler1DShadow DEPRECATED_ES_KEYWORD(SAMPLER1DSHADOW);
325 sampler2DShadow return SAMPLER2DSHADOW;
326 samplerCubeShadow KEYWORD(130, 300, 130, 300, SAMPLERCUBESHADOW);
327 sampler1DArrayShadow KEYWORD(130, 300, 130, 0, SAMPLER1DARRAYSHADOW);
328 sampler2DArrayShadow KEYWORD(130, 300, 130, 300, SAMPLER2DARRAYSHADOW);
329 isampler1D KEYWORD(130, 300, 130, 0, ISAMPLER1D);
330 isampler2D KEYWORD(130, 300, 130, 300, ISAMPLER2D);
331 isampler3D KEYWORD(130, 300, 130, 300, ISAMPLER3D);
332 isamplerCube KEYWORD(130, 300, 130, 300, ISAMPLERCUBE);
333 isampler1DArray KEYWORD(130, 300, 130, 0, ISAMPLER1DARRAY);
334 isampler2DArray KEYWORD(130, 300, 130, 300, ISAMPLER2DARRAY);
335 usampler1D KEYWORD(130, 300, 130, 0, USAMPLER1D);
336 usampler2D KEYWORD(130, 300, 130, 300, USAMPLER2D);
337 usampler3D KEYWORD(130, 300, 130, 300, USAMPLER3D);
338 usamplerCube KEYWORD(130, 300, 130, 300, USAMPLERCUBE);
339 usampler1DArray KEYWORD(130, 300, 130, 0, USAMPLER1DARRAY);
340 usampler2DArray KEYWORD(130, 300, 130, 300, USAMPLER2DARRAY);
342 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */
343 /* these are reserved but not defined in GLSL 3.00 */
344 sampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMS);
345 isampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMS);
346 usampler2DMS KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMS);
347 sampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, SAMPLER2DMSARRAY);
348 isampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, ISAMPLER2DMSARRAY);
349 usampler2DMSArray KEYWORD_WITH_ALT(150, 300, 150, 0, yyextra->ARB_texture_multisample_enable, USAMPLER2DMSARRAY);
351 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */
352 samplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAY);
353 isamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, ISAMPLERCUBEARRAY);
354 usamplerCubeArray KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, USAMPLERCUBEARRAY);
355 samplerCubeArrayShadow KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_texture_cube_map_array_enable, SAMPLERCUBEARRAYSHADOW);
358 if (yyextra->OES_EGL_image_external_enable)
359 return SAMPLEREXTERNALOES;
364 /* keywords available with ARB_gpu_shader5 */
365 precise KEYWORD_WITH_ALT(400, 0, 400, 0, yyextra->ARB_gpu_shader5_enable, PRECISE);
367 /* keywords available with ARB_shader_image_load_store */
368 image1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1D);
369 image2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2D);
370 image3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE3D);
371 image2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DRECT);
372 imageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBE);
373 imageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGEBUFFER);
374 image1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE1DARRAY);
375 image2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DARRAY);
376 imageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGECUBEARRAY);
377 image2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMS);
378 image2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IMAGE2DMSARRAY);
379 iimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1D);
380 iimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2D);
381 iimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE3D);
382 iimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DRECT);
383 iimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBE);
384 iimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGEBUFFER);
385 iimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE1DARRAY);
386 iimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DARRAY);
387 iimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGECUBEARRAY);
388 iimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMS);
389 iimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, IIMAGE2DMSARRAY);
390 uimage1D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1D);
391 uimage2D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2D);
392 uimage3D KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE3D);
393 uimage2DRect KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DRECT);
394 uimageCube KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBE);
395 uimageBuffer KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGEBUFFER);
396 uimage1DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE1DARRAY);
397 uimage2DArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DARRAY);
398 uimageCubeArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGECUBEARRAY);
399 uimage2DMS KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMS);
400 uimage2DMSArray KEYWORD_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, UIMAGE2DMSARRAY);
401 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
402 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
403 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
404 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
406 coherent KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, COHERENT);
407 volatile KEYWORD_WITH_ALT(110, 100, 420, 0, yyextra->ARB_shader_image_load_store_enable, VOLATILE);
408 restrict KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, RESTRICT);
409 readonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, READONLY);
410 writeonly KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, WRITEONLY);
412 atomic_uint KEYWORD_WITH_ALT(420, 300, 420, 0, yyextra->ARB_shader_atomic_counters_enable, ATOMIC_UINT);
414 struct return STRUCT;
415 void return VOID_TOK;
418 if ((yyextra->is_version(140, 300))
419 || yyextra->AMD_conservative_depth_enable
420 || yyextra->ARB_conservative_depth_enable
421 || yyextra->ARB_explicit_attrib_location_enable
422 || yyextra->ARB_explicit_uniform_location_enable
423 || yyextra->has_separate_shader_objects()
424 || yyextra->ARB_uniform_buffer_object_enable
425 || yyextra->ARB_fragment_coord_conventions_enable
426 || yyextra->ARB_shading_language_420pack_enable
427 || yyextra->ARB_compute_shader_enable) {
430 void *mem_ctx = yyextra;
431 yylval->identifier = ralloc_strdup(mem_ctx, yytext);
432 return classify_identifier(yyextra, yytext);
446 ">>" return RIGHT_OP;
448 \*= return MUL_ASSIGN;
449 \/= return DIV_ASSIGN;
450 \+= return ADD_ASSIGN;
451 \%= return MOD_ASSIGN;
452 \<\<= return LEFT_ASSIGN;
453 >>= return RIGHT_ASSIGN;
454 &= return AND_ASSIGN;
455 "^=" return XOR_ASSIGN;
456 \|= return OR_ASSIGN;
457 -= return SUB_ASSIGN;
460 return LITERAL_INTEGER(10);
462 0[xX][0-9a-fA-F]+[uU]? {
463 return LITERAL_INTEGER(16);
466 return LITERAL_INTEGER(8);
469 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
470 \.[0-9]+([eE][+-]?[0-9]+)?[fF]? |
471 [0-9]+\.([eE][+-]?[0-9]+)?[fF]? |
472 [0-9]+[eE][+-]?[0-9]+[fF]? {
473 yylval->real = _mesa_strtof(yytext, NULL);
474 return FLOATCONSTANT;
477 [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
478 \.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) |
479 [0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) |
480 [0-9]+[eE][+-]?[0-9]+(lf|LF) {
481 if (!yyextra->is_version(400, 0) &&
482 !yyextra->ARB_gpu_shader_fp64_enable)
484 yylval->dreal = _mesa_strtod(yytext, NULL);
485 return DOUBLECONSTANT;
498 /* Reserved words in GLSL 1.10. */
499 asm KEYWORD(110, 100, 0, 0, ASM);
500 class KEYWORD(110, 100, 0, 0, CLASS);
501 union KEYWORD(110, 100, 0, 0, UNION);
502 enum KEYWORD(110, 100, 0, 0, ENUM);
503 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
504 template KEYWORD(110, 100, 0, 0, TEMPLATE);
505 this KEYWORD(110, 100, 0, 0, THIS);
506 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
507 goto KEYWORD(110, 100, 0, 0, GOTO);
508 switch KEYWORD(110, 100, 130, 300, SWITCH);
509 default KEYWORD(110, 100, 130, 300, DEFAULT);
510 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
511 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
512 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
513 static KEYWORD(110, 100, 0, 0, STATIC);
514 extern KEYWORD(110, 100, 0, 0, EXTERN);
515 external KEYWORD(110, 100, 0, 0, EXTERNAL);
516 interface KEYWORD(110, 100, 0, 0, INTERFACE);
517 long KEYWORD(110, 100, 0, 0, LONG_TOK);
518 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
519 double KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DOUBLE_TOK);
520 half KEYWORD(110, 100, 0, 0, HALF);
521 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
522 unsigned KEYWORD(110, 100, 0, 0, UNSIGNED);
523 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
524 output KEYWORD(110, 100, 0, 0, OUTPUT);
525 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
526 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
527 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
528 dvec2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC2);
529 dvec3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC3);
530 dvec4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DVEC4);
531 dmat2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
532 dmat3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
533 dmat4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
534 dmat2x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X2);
535 dmat2x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X3);
536 dmat2x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT2X4);
537 dmat3x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X2);
538 dmat3x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X3);
539 dmat3x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT3X4);
540 dmat4x2 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X2);
541 dmat4x3 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X3);
542 dmat4x4 KEYWORD_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, DMAT4X4);
543 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
544 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
545 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
546 sampler2DRect DEPRECATED_ES_KEYWORD(SAMPLER2DRECT);
547 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
548 sampler2DRectShadow DEPRECATED_ES_KEYWORD(SAMPLER2DRECTSHADOW);
549 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
550 cast KEYWORD(110, 100, 0, 0, CAST);
551 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
552 using KEYWORD(110, 100, 0, 0, USING);
554 /* Additional reserved words in GLSL 1.20. */
555 lowp KEYWORD(120, 100, 130, 100, LOWP);
556 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
557 highp KEYWORD(120, 100, 130, 100, HIGHP);
558 precision KEYWORD(120, 100, 130, 100, PRECISION);
560 /* Additional reserved words in GLSL 1.30. */
561 case KEYWORD(130, 300, 130, 300, CASE);
562 common KEYWORD(130, 300, 0, 0, COMMON);
563 partition KEYWORD(130, 300, 0, 0, PARTITION);
564 active KEYWORD(130, 300, 0, 0, ACTIVE);
565 superp KEYWORD(130, 100, 0, 0, SUPERP);
566 samplerBuffer KEYWORD(130, 300, 140, 0, SAMPLERBUFFER);
567 filter KEYWORD(130, 300, 0, 0, FILTER);
568 row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR);
570 /* Additional reserved words in GLSL 1.40 */
571 isampler2DRect KEYWORD(140, 300, 140, 0, ISAMPLER2DRECT);
572 usampler2DRect KEYWORD(140, 300, 140, 0, USAMPLER2DRECT);
573 isamplerBuffer KEYWORD(140, 300, 140, 0, ISAMPLERBUFFER);
574 usamplerBuffer KEYWORD(140, 300, 140, 0, USAMPLERBUFFER);
576 /* Additional reserved words in GLSL ES 3.00 */
577 resource KEYWORD(0, 300, 0, 0, RESOURCE);
578 patch KEYWORD(0, 300, 0, 0, PATCH);
579 sample KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_gpu_shader5_enable, SAMPLE);
580 subroutine KEYWORD(0, 300, 0, 0, SUBROUTINE);
583 [_a-zA-Z][_a-zA-Z0-9]* {
584 struct _mesa_glsl_parse_state *state = yyextra;
586 if (state->es_shader && strlen(yytext) > 1024) {
587 _mesa_glsl_error(yylloc, state,
588 "Identifier `%s' exceeds 1024 characters",
591 yylval->identifier = ralloc_strdup(ctx, yytext);
593 return classify_identifier(state, yytext);
596 . { return yytext[0]; }
601 classify_identifier(struct _mesa_glsl_parse_state *state, const char *name)
603 if (state->symbols->get_variable(name) || state->symbols->get_function(name))
605 else if (state->symbols->get_type(name))
606 return TYPE_IDENTIFIER;
608 return NEW_IDENTIFIER;
612 _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string)
614 yylex_init_extra(state, & state->scanner);
615 yy_scan_string(string, state->scanner);
619 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
621 yylex_destroy(state->scanner);