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#include "main/consts_exts.h" 31 32static int classify_identifier(struct _mesa_glsl_parse_state *, const char *, 33 unsigned name_len, YYSTYPE *output); 34 35#ifdef _MSC_VER 36#define YY_NO_UNISTD_H 37#endif 38 39#define YY_NO_INPUT 40#define YY_USER_ACTION \ 41 do { \ 42 yylloc->first_column = yycolumn + 1; \ 43 yylloc->first_line = yylloc->last_line = yylineno + 1; \ 44 yycolumn += yyleng; \ 45 yylloc->last_column = yycolumn + 1; \ 46 } while(0); 47 48#define YY_USER_INIT yylineno = 0; yycolumn = 0; yylloc->source = 0; \ 49 yylloc->path = NULL; 50 51/* A macro for handling reserved words and keywords across language versions. 52 * 53 * Certain words start out as identifiers, become reserved words in 54 * later language revisions, and finally become language keywords. 55 * This may happen at different times in desktop GLSL and GLSL ES. 56 * 57 * For example, consider the following lexer rule: 58 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER) 59 * 60 * This means that "samplerBuffer" will be treated as: 61 * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40 62 * - a reserved word - error ...in GLSL >= 1.30 63 * - an identifier ...in GLSL < 1.30 or GLSL ES 64 */ 65#define KEYWORD(reserved_glsl, reserved_glsl_es, \ 66 allowed_glsl, allowed_glsl_es, token) \ 67 KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 68 allowed_glsl, allowed_glsl_es, false, token) 69 70/** 71 * Like the KEYWORD macro, but the word is also treated as a keyword 72 * if the given boolean expression is true. 73 */ 74#define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 75 allowed_glsl, allowed_glsl_es, \ 76 alt_expr, token) \ 77 do { \ 78 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \ 79 || (alt_expr)) { \ 80 return token; \ 81 } else if (yyextra->is_version(reserved_glsl, \ 82 reserved_glsl_es)) { \ 83 _mesa_glsl_error(yylloc, yyextra, \ 84 "illegal use of reserved word `%s'", yytext); \ 85 return ERROR_TOK; \ 86 } else { \ 87 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 88 } \ 89 } while (0) 90 91/** 92 * Like KEYWORD_WITH_ALT, but used for built-in GLSL types 93 */ 94#define TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 95 allowed_glsl, allowed_glsl_es, \ 96 alt_expr, gtype) \ 97 do { \ 98 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \ 99 || (alt_expr)) { \ 100 yylval->type = gtype; \ 101 return BASIC_TYPE_TOK; \ 102 } else if (yyextra->is_version(reserved_glsl, \ 103 reserved_glsl_es)) { \ 104 _mesa_glsl_error(yylloc, yyextra, \ 105 "illegal use of reserved word `%s'", yytext); \ 106 return ERROR_TOK; \ 107 } else { \ 108 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 109 } \ 110 } while (0) 111 112#define TYPE(reserved_glsl, reserved_glsl_es, \ 113 allowed_glsl, allowed_glsl_es, \ 114 gtype) \ 115 TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 116 allowed_glsl, allowed_glsl_es, \ 117 false, gtype) 118 119/** 120 * A macro for handling keywords that have been present in GLSL since 121 * its origin, but were changed into reserved words in later versions. 122 */ 123#define DEPRECATED_KEYWORD(token, state, reserved_glsl, \ 124 reserved_glsl_es) \ 125 do { \ 126 if (yyextra->is_version(reserved_glsl, reserved_glsl_es) && \ 127 !state->compat_shader) { \ 128 _mesa_glsl_error(yylloc, yyextra, \ 129 "illegal use of reserved word `%s'", yytext); \ 130 return ERROR_TOK; \ 131 } else { \ 132 return token; \ 133 } \ 134 } while (0) 135 136/** 137 * Like DEPRECATED_KEYWORD, but for types 138 */ 139#define DEPRECATED_ES_TYPE_WITH_ALT(alt_expr, gtype) \ 140 do { \ 141 if (yyextra->is_version(0, 300)) { \ 142 _mesa_glsl_error(yylloc, yyextra, \ 143 "illegal use of reserved word `%s'", yytext); \ 144 return ERROR_TOK; \ 145 } else if (alt_expr) { \ 146 yylval->type = gtype; \ 147 return BASIC_TYPE_TOK; \ 148 } else { \ 149 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 150 } \ 151 } while (0) 152 153#define DEPRECATED_ES_TYPE(gtype) \ 154 DEPRECATED_ES_TYPE_WITH_ALT(true, gtype) 155 156static int 157literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state, 158 YYSTYPE *lval, YYLTYPE *lloc, int base) 159{ 160 bool is_uint = (text[len - 1] == 'u' || 161 text[len - 1] == 'U'); 162 bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L'); 163 const char *digits = text; 164 165 if (is_long) 166 is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') || 167 (text[len - 2] == 'U' && text[len - 1] == 'L'); 168 /* Skip "0x" */ 169 if (base == 16) 170 digits += 2; 171 172 unsigned long long value = strtoull(digits, NULL, base); 173 174 if (is_long) 175 lval->n64 = (int64_t)value; 176 else 177 lval->n = (int)value; 178 179 if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) { 180 /* Tries to catch unintentionally providing a negative value. */ 181 _mesa_glsl_warning(lloc, state, 182 "signed literal value `%s' is interpreted as %lld", 183 text, lval->n64); 184 } else if (!is_long && value > UINT_MAX) { 185 /* Note that signed 0xffffffff is valid, not out of range! */ 186 if (state->is_version(130, 300)) { 187 _mesa_glsl_error(lloc, state, 188 "literal value `%s' out of range", text); 189 } else { 190 _mesa_glsl_warning(lloc, state, 191 "literal value `%s' out of range", text); 192 } 193 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) { 194 /* Tries to catch unintentionally providing a negative value. 195 * Note that -2147483648 is parsed as -(2147483648), so we don't 196 * want to warn for INT_MAX. 197 */ 198 _mesa_glsl_warning(lloc, state, 199 "signed literal value `%s' is interpreted as %d", 200 text, lval->n); 201 } 202 if (is_long) 203 return is_uint ? UINT64CONSTANT : INT64CONSTANT; 204 else 205 return is_uint ? UINTCONSTANT : INTCONSTANT; 206} 207 208#define LITERAL_INTEGER(base) \ 209 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base) 210 211%} 212 213%option bison-bridge bison-locations reentrant noyywrap 214%option nounput noyy_top_state 215%option never-interactive 216%option prefix="_mesa_glsl_lexer_" 217%option extra-type="struct _mesa_glsl_parse_state *" 218%option warn nodefault 219 220 /* Note: When adding any start conditions to this list, you must also 221 * update the "Internal compiler error" catch-all rule near the end of 222 * this file. */ 223%x PP PRAGMA 224 225DEC_INT [1-9][0-9]* 226HEX_INT 0[xX][0-9a-fA-F]+ 227OCT_INT 0[0-7]* 228INT ({DEC_INT}|{HEX_INT}|{OCT_INT}) 229SPC [ \t]* 230SPCP [ \t]+ 231HASH ^{SPC}#{SPC} 232PATH ["][./ _A-Za-z0-9]*["] 233%% 234 235[ \r\t]+ ; 236 237 /* Preprocessor tokens. */ 238^[ \t]*#[ \t]*$ ; 239^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; } 240^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; } 241{HASH}include { 242 if (!yyextra->ARB_shading_language_include_enable) { 243 struct _mesa_glsl_parse_state *state = yyextra; 244 _mesa_glsl_error(yylloc, state, 245 "ARB_shading_language_include required " 246 "to use #include"); 247 } 248} 249{HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ { 250 /* Eat characters until the first digit is 251 * encountered 252 */ 253 char *ptr = yytext; 254 while (!isdigit(*ptr)) 255 ptr++; 256 257 /* Subtract one from the line number because 258 * yylineno is zero-based instead of 259 * one-based. 260 */ 261 yylineno = strtol(ptr, &ptr, 0) - 1; 262 263 /* From GLSL 3.30 and GLSL ES on, after processing the 264 * line directive (including its new-line), the implementation 265 * will behave as if it is compiling at the line number passed 266 * as argument. It was line number + 1 in older specifications. 267 */ 268 if (yyextra->is_version(330, 100)) 269 yylineno--; 270 271 yylloc->source = strtol(ptr, NULL, 0); 272 yylloc->path = NULL; 273 } 274{HASH}line{SPCP}{INT}{SPCP}{PATH}{SPC}$ { 275 if (!yyextra->ARB_shading_language_include_enable) { 276 struct _mesa_glsl_parse_state *state = yyextra; 277 _mesa_glsl_error(yylloc, state, 278 "ARB_shading_language_include required " 279 "to use #line <line> \"<path>\""); 280 } 281 282 /* Eat characters until the first digit is 283 * encountered 284 */ 285 char *ptr = yytext; 286 while (!isdigit(*ptr)) 287 ptr++; 288 289 /* Subtract one from the line number because 290 * yylineno is zero-based instead of 291 * one-based. 292 */ 293 yylineno = strtol(ptr, &ptr, 0) - 1; 294 295 /* From GLSL 3.30 and GLSL ES on, after processing the 296 * line directive (including its new-line), the implementation 297 * will behave as if it is compiling at the line number passed 298 * as argument. It was line number + 1 in older specifications. 299 */ 300 if (yyextra->is_version(330, 100)) 301 yylineno--; 302 303 while (isspace(*ptr)) 304 ptr++; 305 306 /* Skip over leading " */ 307 ptr++; 308 309 char *end = strrchr(ptr, '"'); 310 int path_len = (end - ptr) + 1; 311 linear_ctx *mem_ctx = yyextra->linalloc; 312 yylloc->path = (char *) linear_alloc_child(mem_ctx, path_len); 313 memcpy(yylloc->path, ptr, path_len); 314 yylloc->path[path_len - 1] = '\0'; 315 } 316{HASH}line{SPCP}{INT}{SPC}$ { 317 /* Eat characters until the first digit is 318 * encountered 319 */ 320 char *ptr = yytext; 321 while (!isdigit(*ptr)) 322 ptr++; 323 324 /* Subtract one from the line number because 325 * yylineno is zero-based instead of 326 * one-based. 327 */ 328 yylineno = strtol(ptr, &ptr, 0) - 1; 329 330 /* From GLSL 3.30 and GLSL ES on, after processing the 331 * line directive (including its new-line), the implementation 332 * will behave as if it is compiling at the line number passed 333 * as argument. It was line number + 1 in older specifications. 334 */ 335 if (yyextra->is_version(330, 100)) 336 yylineno--; 337 } 338^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) { 339 BEGIN PP; 340 return PRAGMA_DEBUG_ON; 341 } 342^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) { 343 BEGIN PP; 344 return PRAGMA_DEBUG_OFF; 345 } 346^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) { 347 BEGIN PP; 348 return PRAGMA_OPTIMIZE_ON; 349 } 350^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) { 351 BEGIN PP; 352 return PRAGMA_OPTIMIZE_OFF; 353 } 354^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}on{SPC}\) { 355 BEGIN PP; 356 return PRAGMA_WARNING_ON; 357 } 358^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}off{SPC}\) { 359 BEGIN PP; 360 return PRAGMA_WARNING_OFF; 361 } 362^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) { 363 BEGIN PP; 364 return PRAGMA_INVARIANT_ALL; 365 } 366^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; } 367 368<PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; } 369<PRAGMA>. { } 370 371<PP>\/\/[^\n]* { } 372<PP>[ \t\r]* { } 373<PP>: return COLON; 374<PP>[_a-zA-Z][_a-zA-Z0-9]* { 375 /* We're not doing linear_strdup here, to avoid an implicit call 376 * on strlen() for the length of the string, as this is already 377 * found by flex and stored in yyleng 378 */ 379 linear_ctx *mem_ctx = yyextra->linalloc; 380 char *id = (char *) linear_alloc_child(mem_ctx, yyleng + 1); 381 memcpy(id, yytext, yyleng + 1); 382 yylval->identifier = id; 383 return IDENTIFIER; 384 } 385<PP>[1-9][0-9]* { 386 yylval->n = strtol(yytext, NULL, 10); 387 return INTCONSTANT; 388 } 389<PP>0 { 390 yylval->n = 0; 391 return INTCONSTANT; 392 } 393<PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; } 394<PP>. { return yytext[0]; } 395 396\n { yylineno++; yycolumn = 0; } 397 398attribute DEPRECATED_KEYWORD(ATTRIBUTE, yyextra, 420, 300); 399const return CONST_TOK; 400bool { yylval->type = &glsl_type_builtin_bool; return BASIC_TYPE_TOK; } 401float { yylval->type = &glsl_type_builtin_float; return BASIC_TYPE_TOK; } 402int { yylval->type = &glsl_type_builtin_int; return BASIC_TYPE_TOK; } 403uint TYPE(130, 300, 130, 300, &glsl_type_builtin_uint); 404 405break return BREAK; 406continue return CONTINUE; 407do return DO; 408while return WHILE; 409else return ELSE; 410for return FOR; 411if return IF; 412discard return DISCARD; 413return return RETURN; 414demote KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->EXT_demote_to_helper_invocation_enable, DEMOTE); 415 416bvec2 { yylval->type = &glsl_type_builtin_bvec2; return BASIC_TYPE_TOK; } 417bvec3 { yylval->type = &glsl_type_builtin_bvec3; return BASIC_TYPE_TOK; } 418bvec4 { yylval->type = &glsl_type_builtin_bvec4; return BASIC_TYPE_TOK; } 419ivec2 { yylval->type = &glsl_type_builtin_ivec2; return BASIC_TYPE_TOK; } 420ivec3 { yylval->type = &glsl_type_builtin_ivec3; return BASIC_TYPE_TOK; } 421ivec4 { yylval->type = &glsl_type_builtin_ivec4; return BASIC_TYPE_TOK; } 422uvec2 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, &glsl_type_builtin_uvec2); 423uvec3 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, &glsl_type_builtin_uvec3); 424uvec4 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, &glsl_type_builtin_uvec4); 425vec2 { yylval->type = &glsl_type_builtin_vec2; return BASIC_TYPE_TOK; } 426vec3 { yylval->type = &glsl_type_builtin_vec3; return BASIC_TYPE_TOK; } 427vec4 { yylval->type = &glsl_type_builtin_vec4; return BASIC_TYPE_TOK; } 428mat2 { yylval->type = &glsl_type_builtin_mat2; return BASIC_TYPE_TOK; } 429mat3 { yylval->type = &glsl_type_builtin_mat3; return BASIC_TYPE_TOK; } 430mat4 { yylval->type = &glsl_type_builtin_mat4; return BASIC_TYPE_TOK; } 431mat2x2 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat2); 432mat2x3 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat2x3); 433mat2x4 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat2x4); 434mat3x2 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat3x2); 435mat3x3 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat3); 436mat3x4 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat3x4); 437mat4x2 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat4x2); 438mat4x3 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat4x3); 439mat4x4 TYPE(120, 300, 120, 300, &glsl_type_builtin_mat4); 440 441in return IN_TOK; 442out return OUT_TOK; 443inout return INOUT_TOK; 444uniform return UNIFORM; 445buffer KEYWORD_WITH_ALT(0, 0, 430, 310, yyextra->ARB_shader_storage_buffer_object_enable, BUFFER); 446varying DEPRECATED_KEYWORD(VARYING, yyextra, 420, 300); 447centroid KEYWORD_WITH_ALT(120, 300, 120, 300, yyextra->EXT_gpu_shader4_enable, CENTROID); 448invariant KEYWORD(120, 100, 120, 100, INVARIANT); 449flat KEYWORD_WITH_ALT(130, 100, 130, 300, yyextra->EXT_gpu_shader4_enable, FLAT); 450smooth KEYWORD(130, 300, 130, 300, SMOOTH); 451noperspective KEYWORD_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable || yyextra->NV_shader_noperspective_interpolation_enable, NOPERSPECTIVE); 452patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH); 453 454sampler1D DEPRECATED_ES_TYPE(&glsl_type_builtin_sampler1D); 455sampler2D { yylval->type = &glsl_type_builtin_sampler2D; return BASIC_TYPE_TOK; } 456sampler3D { yylval->type = &glsl_type_builtin_sampler3D; return BASIC_TYPE_TOK; } 457samplerCube { yylval->type = &glsl_type_builtin_samplerCube; return BASIC_TYPE_TOK; } 458sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, &glsl_type_builtin_sampler1DArray); 459sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, &glsl_type_builtin_sampler2DArray); 460sampler1DShadow DEPRECATED_ES_TYPE(&glsl_type_builtin_sampler1DShadow); 461sampler2DShadow { yylval->type = &glsl_type_builtin_sampler2DShadow; return BASIC_TYPE_TOK; } 462samplerCubeShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, &glsl_type_builtin_samplerCubeShadow); 463sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, &glsl_type_builtin_sampler1DArrayShadow); 464sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, &glsl_type_builtin_sampler2DArrayShadow); 465isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_isampler1D); 466isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_isampler2D); 467isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_isampler3D); 468isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_isamplerCube); 469isampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, &glsl_type_builtin_isampler1DArray); 470isampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, &glsl_type_builtin_isampler2DArray); 471usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_usampler1D); 472usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_usampler2D); 473usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_usampler3D); 474usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_usamplerCube); 475usampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, &glsl_type_builtin_usampler1DArray); 476usampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer && yyextra->exts->EXT_texture_array, &glsl_type_builtin_usampler2DArray); 477 478 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */ 479 /* these are reserved but not defined in GLSL 3.00 */ 480 /* [iu]sampler2DMS are defined in GLSL ES 3.10 */ 481sampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, &glsl_type_builtin_sampler2DMS); 482isampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, &glsl_type_builtin_isampler2DMS); 483usampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, &glsl_type_builtin_usampler2DMS); 484sampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, &glsl_type_builtin_sampler2DMSArray); 485isampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, &glsl_type_builtin_isampler2DMSArray); 486usampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, &glsl_type_builtin_usampler2DMSArray); 487 488 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */ 489samplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_samplerCubeArray); 490isamplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_isamplerCubeArray); 491usamplerCubeArray TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_usamplerCubeArray); 492samplerCubeArrayShadow TYPE_WITH_ALT(400, 310, 400, 320, yyextra->ARB_texture_cube_map_array_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_samplerCubeArrayShadow); 493 494samplerExternalOES { 495 if (yyextra->OES_EGL_image_external_enable || yyextra->OES_EGL_image_external_essl3_enable) { 496 yylval->type = &glsl_type_builtin_samplerExternalOES; 497 return BASIC_TYPE_TOK; 498 } else 499 return IDENTIFIER; 500 } 501 502 /* keywords available with ARB_gpu_shader5 */ 503precise KEYWORD_WITH_ALT(400, 310, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->EXT_gpu_shader5_enable || yyextra->OES_gpu_shader5_enable, PRECISE); 504 505 /* keywords available with ARB_shader_image_load_store */ 506image1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image1D); 507image2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image2D); 508image3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image3D); 509image2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image2DRect); 510imageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_imageCube); 511imageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, &glsl_type_builtin_imageBuffer); 512image1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image1DArray); 513image2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image2DArray); 514imageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_imageCubeArray); 515image2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image2DMS); 516image2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_image2DMSArray); 517iimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage1D); 518iimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage2D); 519iimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage3D); 520iimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage2DRect); 521iimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimageCube); 522iimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, &glsl_type_builtin_iimageBuffer); 523iimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage1DArray); 524iimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage2DArray); 525iimageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_iimageCubeArray); 526iimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage2DMS); 527iimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_iimage2DMSArray); 528uimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage1D); 529uimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage2D); 530uimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage3D); 531uimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage2DRect); 532uimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimageCube); 533uimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, &glsl_type_builtin_uimageBuffer); 534uimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage1DArray); 535uimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage2DArray); 536uimageCubeArray TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->OES_texture_cube_map_array_enable || yyextra->EXT_texture_cube_map_array_enable, &glsl_type_builtin_uimageCubeArray); 537uimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage2DMS); 538uimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, &glsl_type_builtin_uimage2DMSArray); 539image1DShadow KEYWORD(130, 0, 420, 0, IMAGE1DSHADOW); 540image2DShadow KEYWORD(130, 0, 420, 0, IMAGE2DSHADOW); 541image1DArrayShadow KEYWORD(130, 0, 420, 0, IMAGE1DARRAYSHADOW); 542image2DArrayShadow KEYWORD(130, 0, 420, 0, IMAGE2DARRAYSHADOW); 543 544coherent KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, COHERENT); 545volatile KEYWORD_WITH_ALT(110, 100, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, VOLATILE); 546restrict KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, RESTRICT); 547readonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, READONLY); 548writeonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, WRITEONLY); 549 550atomic_uint TYPE_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, &glsl_type_builtin_atomic_uint); 551 552shared KEYWORD_WITH_ALT(430, 310, 430, 310, yyextra->ARB_compute_shader_enable, SHARED); 553 554struct return STRUCT; 555void return VOID_TOK; 556 557layout { 558 if ((yyextra->is_version(140, 300)) 559 || yyextra->ARB_bindless_texture_enable 560 || yyextra->KHR_blend_equation_advanced_enable 561 || yyextra->AMD_conservative_depth_enable 562 || yyextra->ARB_conservative_depth_enable 563 || yyextra->ARB_explicit_attrib_location_enable 564 || yyextra->ARB_explicit_uniform_location_enable 565 || yyextra->ARB_post_depth_coverage_enable 566 || yyextra->has_separate_shader_objects() 567 || yyextra->ARB_uniform_buffer_object_enable 568 || yyextra->ARB_fragment_coord_conventions_enable 569 || yyextra->ARB_shading_language_420pack_enable 570 || yyextra->ARB_compute_shader_enable 571 || yyextra->ARB_tessellation_shader_enable 572 || yyextra->EXT_shader_framebuffer_fetch_non_coherent_enable) { 573 return LAYOUT_TOK; 574 } else { 575 return classify_identifier(yyextra, yytext, yyleng, yylval); 576 } 577 } 578 579\+\+ return INC_OP; 580-- return DEC_OP; 581\<= return LE_OP; 582>= return GE_OP; 583== return EQ_OP; 584!= return NE_OP; 585&& return AND_OP; 586\|\| return OR_OP; 587"^^" return XOR_OP; 588"<<" return LEFT_OP; 589">>" return RIGHT_OP; 590 591\*= return MUL_ASSIGN; 592\/= return DIV_ASSIGN; 593\+= return ADD_ASSIGN; 594\%= return MOD_ASSIGN; 595\<\<= return LEFT_ASSIGN; 596>>= return RIGHT_ASSIGN; 597&= return AND_ASSIGN; 598"^=" return XOR_ASSIGN; 599\|= return OR_ASSIGN; 600-= return SUB_ASSIGN; 601 602[1-9][0-9]*([uU]|[lL]|ul|UL)? { 603 return LITERAL_INTEGER(10); 604 } 6050[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? { 606 return LITERAL_INTEGER(16); 607 } 6080[0-7]*([uU]|[lL]|ul|UL)? { 609 return LITERAL_INTEGER(8); 610 } 611 612[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(hf|HF) | 613\.[0-9]+([eE][+-]?[0-9]+)?(hf|HF) | 614[0-9]+\.([eE][+-]?[0-9]+)?(hf|HF) | 615[0-9]+[eE][+-]?[0-9]+(hf|HF) { 616 if (!yyextra->AMD_gpu_shader_half_float_enable) 617 return ERROR_TOK; 618 yylval->dreal = _mesa_strtod(yytext, NULL); 619 return FLOAT16CONSTANT; 620 } 621 622[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | 623\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | 624[0-9]+\.([eE][+-]?[0-9]+)?[fF]? | 625[0-9]+[eE][+-]?[0-9]+[fF]? { 626 struct _mesa_glsl_parse_state *state = yyextra; 627 char suffix = yytext[strlen(yytext) - 1]; 628 if (!state->is_version(120, 300) && 629 (suffix == 'f' || suffix == 'F')) { 630 _mesa_glsl_warning(yylloc, state, 631 "Float suffixes are invalid in GLSL 1.10"); 632 } 633 yylval->real = _mesa_strtof(yytext, NULL); 634 return FLOATCONSTANT; 635 } 636 637[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 638\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 639[0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) | 640[0-9]+[eE][+-]?[0-9]+(lf|LF) { 641 if (!yyextra->is_version(400, 0) && 642 !yyextra->ARB_gpu_shader_fp64_enable) 643 return ERROR_TOK; 644 yylval->dreal = _mesa_strtod(yytext, NULL); 645 return DOUBLECONSTANT; 646 } 647 648true { 649 yylval->n = 1; 650 return BOOLCONSTANT; 651 } 652false { 653 yylval->n = 0; 654 return BOOLCONSTANT; 655 } 656 657 658 /* Reserved words in GLSL 1.10. */ 659asm KEYWORD(110, 100, 0, 0, ASM); 660class KEYWORD(110, 100, 0, 0, CLASS); 661union KEYWORD(110, 100, 0, 0, UNION); 662enum KEYWORD(110, 100, 0, 0, ENUM); 663typedef KEYWORD(110, 100, 0, 0, TYPEDEF); 664template KEYWORD(110, 100, 0, 0, TEMPLATE); 665this KEYWORD(110, 100, 0, 0, THIS); 666packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK); 667goto KEYWORD(110, 100, 0, 0, GOTO); 668switch KEYWORD(110, 100, 130, 300, SWITCH); 669default KEYWORD(110, 100, 130, 300, DEFAULT); 670inline KEYWORD(110, 100, 0, 0, INLINE_TOK); 671noinline KEYWORD(110, 100, 0, 0, NOINLINE); 672public KEYWORD(110, 100, 0, 0, PUBLIC_TOK); 673static KEYWORD(110, 100, 0, 0, STATIC); 674extern KEYWORD(110, 100, 0, 0, EXTERN); 675external KEYWORD(110, 100, 0, 0, EXTERNAL); 676interface KEYWORD(110, 100, 0, 0, INTERFACE_TOK); 677long KEYWORD(110, 100, 0, 0, LONG_TOK); 678short KEYWORD(110, 100, 0, 0, SHORT_TOK); 679double TYPE_WITH_ALT(130, 100, 130, 300, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_double); 680half KEYWORD(110, 100, 0, 0, HALF); 681fixed KEYWORD(110, 100, 0, 0, FIXED_TOK); 682unsigned KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->EXT_gpu_shader4_enable, UNSIGNED); 683input KEYWORD(110, 100, 0, 0, INPUT_TOK); 684output KEYWORD(110, 100, 0, 0, OUTPUT); 685hvec2 KEYWORD(110, 100, 0, 0, HVEC2); 686hvec3 KEYWORD(110, 100, 0, 0, HVEC3); 687hvec4 KEYWORD(110, 100, 0, 0, HVEC4); 688dvec2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dvec2); 689dvec3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dvec3); 690dvec4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dvec4); 691dmat2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat2); 692dmat3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat3); 693dmat4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat4); 694dmat2x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat2); 695dmat2x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat2x3); 696dmat2x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat2x4); 697dmat3x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat3x2); 698dmat3x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat3); 699dmat3x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat3x4); 700dmat4x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat4x2); 701dmat4x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat4x3); 702dmat4x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, &glsl_type_builtin_dmat4); 703fvec2 KEYWORD(110, 100, 0, 0, FVEC2); 704fvec3 KEYWORD(110, 100, 0, 0, FVEC3); 705fvec4 KEYWORD(110, 100, 0, 0, FVEC4); 706sampler2DRect TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, &glsl_type_builtin_sampler2DRect); 707sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT); 708sampler2DRectShadow TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, &glsl_type_builtin_sampler2DRectShadow); 709sizeof KEYWORD(110, 100, 0, 0, SIZEOF); 710cast KEYWORD(110, 100, 0, 0, CAST); 711namespace KEYWORD(110, 100, 0, 0, NAMESPACE); 712using KEYWORD(110, 100, 0, 0, USING); 713 714 /* Additional reserved words in GLSL 1.20. */ 715lowp KEYWORD(120, 100, 130, 100, LOWP); 716mediump KEYWORD(120, 100, 130, 100, MEDIUMP); 717highp KEYWORD(120, 100, 130, 100, HIGHP); 718precision KEYWORD(120, 100, 130, 100, PRECISION); 719 720 /* Additional reserved words in GLSL 1.30. */ 721case KEYWORD(130, 300, 130, 300, CASE); 722common KEYWORD(130, 300, 0, 0, COMMON); 723partition KEYWORD(130, 300, 0, 0, PARTITION); 724active KEYWORD(130, 300, 0, 0, ACTIVE); 725superp KEYWORD(130, 100, 0, 0, SUPERP); 726samplerBuffer TYPE_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object), &glsl_type_builtin_samplerBuffer); 727filter KEYWORD(130, 300, 0, 0, FILTER); 728row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR); 729 730 /* Additional reserved words in GLSL 1.40 */ 731isampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_isampler2DRect); 732usampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, &glsl_type_builtin_usampler2DRect); 733isamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object && yyextra->exts->EXT_texture_integer), &glsl_type_builtin_isamplerBuffer); 734usamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_buffer_object && yyextra->exts->EXT_texture_integer), &glsl_type_builtin_usamplerBuffer); 735 736 /* Additional reserved words in GLSL ES 3.00 */ 737resource KEYWORD(420, 300, 0, 0, RESOURCE); 738sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE); 739subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE); 740 741 /* Additional words for ARB_gpu_shader_int64 */ 742int64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_int64_t); 743i64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_i64vec2); 744i64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_i64vec3); 745i64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_i64vec4); 746 747uint64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_uint64_t); 748u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_u64vec2); 749u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_u64vec3); 750u64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_u64vec4); 751 752 /* Additional words for AMD_gpu_shader_half_float */ 753float16_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_float16_t); 754f16vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec2); 755f16vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec3); 756f16vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec4); 757f16mat2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2); 758f16mat3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3); 759f16mat4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4); 760f16mat2x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2); 761f16mat2x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2x3); 762f16mat2x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2x4); 763f16mat3x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3x2); 764f16mat3x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3); 765f16mat3x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3x4); 766f16mat4x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4x2); 767f16mat4x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4x3); 768f16mat4x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4); 769 770[_a-zA-Z][_a-zA-Z0-9]* { 771 struct _mesa_glsl_parse_state *state = yyextra; 772 if (state->es_shader && yyleng > 1024) { 773 _mesa_glsl_error(yylloc, state, 774 "Identifier `%s' exceeds 1024 characters", 775 yytext); 776 } 777 return classify_identifier(state, yytext, yyleng, yylval); 778 } 779 780\. { struct _mesa_glsl_parse_state *state = yyextra; 781 state->is_field = true; 782 return DOT_TOK; } 783 784. { return yytext[0]; } 785 786%% 787 788int 789classify_identifier(struct _mesa_glsl_parse_state *state, const char *name, 790 unsigned name_len, YYSTYPE *output) 791{ 792 /* We're not doing linear_strdup here, to avoid an implicit call on 793 * strlen() for the length of the string, as this is already found by flex 794 * and stored in yyleng 795 */ 796 char *id = (char *) linear_alloc_child(state->linalloc, name_len + 1); 797 memcpy(id, name, name_len + 1); 798 output->identifier = id; 799 800 if (state->is_field) { 801 state->is_field = false; 802 return FIELD_SELECTION; 803 } 804 if (state->symbols->get_variable(name) || state->symbols->get_function(name)) 805 return IDENTIFIER; 806 else if (state->symbols->get_type(name)) 807 return TYPE_IDENTIFIER; 808 else 809 return NEW_IDENTIFIER; 810} 811 812void 813_mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) 814{ 815 yylex_init_extra(state, & state->scanner); 816 yy_scan_string(string, state->scanner); 817} 818 819void 820_mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) 821{ 822 yylex_destroy(state->scanner); 823} 824