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