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 void *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 void *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::bool_type; return BASIC_TYPE_TOK; } 401float { yylval->type = glsl_type::float_type; return BASIC_TYPE_TOK; } 402int { yylval->type = glsl_type::int_type; return BASIC_TYPE_TOK; } 403uint TYPE(130, 300, 130, 300, glsl_type::uint_type); 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::bvec2_type; return BASIC_TYPE_TOK; } 417bvec3 { yylval->type = glsl_type::bvec3_type; return BASIC_TYPE_TOK; } 418bvec4 { yylval->type = glsl_type::bvec4_type; return BASIC_TYPE_TOK; } 419ivec2 { yylval->type = glsl_type::ivec2_type; return BASIC_TYPE_TOK; } 420ivec3 { yylval->type = glsl_type::ivec3_type; return BASIC_TYPE_TOK; } 421ivec4 { yylval->type = glsl_type::ivec4_type; return BASIC_TYPE_TOK; } 422uvec2 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec2_type); 423uvec3 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec3_type); 424uvec4 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec4_type); 425vec2 { yylval->type = glsl_type::vec2_type; return BASIC_TYPE_TOK; } 426vec3 { yylval->type = glsl_type::vec3_type; return BASIC_TYPE_TOK; } 427vec4 { yylval->type = glsl_type::vec4_type; return BASIC_TYPE_TOK; } 428mat2 { yylval->type = glsl_type::mat2_type; return BASIC_TYPE_TOK; } 429mat3 { yylval->type = glsl_type::mat3_type; return BASIC_TYPE_TOK; } 430mat4 { yylval->type = glsl_type::mat4_type; return BASIC_TYPE_TOK; } 431mat2x2 TYPE(120, 300, 120, 300, glsl_type::mat2_type); 432mat2x3 TYPE(120, 300, 120, 300, glsl_type::mat2x3_type); 433mat2x4 TYPE(120, 300, 120, 300, glsl_type::mat2x4_type); 434mat3x2 TYPE(120, 300, 120, 300, glsl_type::mat3x2_type); 435mat3x3 TYPE(120, 300, 120, 300, glsl_type::mat3_type); 436mat3x4 TYPE(120, 300, 120, 300, glsl_type::mat3x4_type); 437mat4x2 TYPE(120, 300, 120, 300, glsl_type::mat4x2_type); 438mat4x3 TYPE(120, 300, 120, 300, glsl_type::mat4x3_type); 439mat4x4 TYPE(120, 300, 120, 300, glsl_type::mat4_type); 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, NOPERSPECTIVE); 452patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH); 453 454sampler1D DEPRECATED_ES_TYPE(glsl_type::sampler1D_type); 455sampler2D { yylval->type = glsl_type::sampler2D_type; return BASIC_TYPE_TOK; } 456sampler3D { yylval->type = glsl_type::sampler3D_type; return BASIC_TYPE_TOK; } 457samplerCube { yylval->type = glsl_type::samplerCube_type; return BASIC_TYPE_TOK; } 458sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler1DArray_type); 459sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler2DArray_type); 460sampler1DShadow DEPRECATED_ES_TYPE(glsl_type::sampler1DShadow_type); 461sampler2DShadow { yylval->type = glsl_type::sampler2DShadow_type; return BASIC_TYPE_TOK; } 462samplerCubeShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::samplerCubeShadow_type); 463sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler1DArrayShadow_type); 464sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_array, glsl_type::sampler2DArrayShadow_type); 465isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler1D_type); 466isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler2D_type); 467isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isampler3D_type); 468isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::isamplerCube_type); 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::isampler1DArray_type); 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::isampler2DArray_type); 471usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler1D_type); 472usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler2D_type); 473usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usampler3D_type); 474usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->exts->EXT_texture_integer, glsl_type::usamplerCube_type); 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::usampler1DArray_type); 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::usampler2DArray_type); 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::sampler2DMS_type); 482isampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::isampler2DMS_type); 483usampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::usampler2DMS_type); 484sampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::sampler2DMSArray_type); 485isampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::isampler2DMSArray_type); 486usampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::usampler2DMSArray_type); 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::samplerCubeArray_type); 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::isamplerCubeArray_type); 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::usamplerCubeArray_type); 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::samplerCubeArrayShadow_type); 493 494samplerExternalOES { 495 if (yyextra->OES_EGL_image_external_enable || yyextra->OES_EGL_image_external_essl3_enable) { 496 yylval->type = glsl_type::samplerExternalOES_type; 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::image1D_type); 507image2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image2D_type); 508image3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image3D_type); 509image2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image2DRect_type); 510imageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::imageCube_type); 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::imageBuffer_type); 512image1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image1DArray_type); 513image2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image2DArray_type); 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::imageCubeArray_type); 515image2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image2DMS_type); 516image2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::image2DMSArray_type); 517iimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage1D_type); 518iimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage2D_type); 519iimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage3D_type); 520iimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage2DRect_type); 521iimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimageCube_type); 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::iimageBuffer_type); 523iimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage1DArray_type); 524iimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage2DArray_type); 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::iimageCubeArray_type); 526iimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage2DMS_type); 527iimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::iimage2DMSArray_type); 528uimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage1D_type); 529uimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage2D_type); 530uimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage3D_type); 531uimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage2DRect_type); 532uimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimageCube_type); 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::uimageBuffer_type); 534uimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage1DArray_type); 535uimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage2DArray_type); 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::uimageCubeArray_type); 537uimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage2DMS_type); 538uimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_shader_image_load_store_enable, glsl_type::uimage2DMSArray_type); 539image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW); 540image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW); 541image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW); 542image2DArrayShadow KEYWORD(130, 300, 0, 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::atomic_uint_type); 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]+)?[fF]? | 613\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | 614[0-9]+\.([eE][+-]?[0-9]+)?[fF]? | 615[0-9]+[eE][+-]?[0-9]+[fF]? { 616 struct _mesa_glsl_parse_state *state = yyextra; 617 char suffix = yytext[strlen(yytext) - 1]; 618 if (!state->is_version(120, 300) && 619 (suffix == 'f' || suffix == 'F')) { 620 _mesa_glsl_warning(yylloc, state, 621 "Float suffixes are invalid in GLSL 1.10"); 622 } 623 yylval->real = _mesa_strtof(yytext, NULL); 624 return FLOATCONSTANT; 625 } 626 627[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 628\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 629[0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) | 630[0-9]+[eE][+-]?[0-9]+(lf|LF) { 631 if (!yyextra->is_version(400, 0) && 632 !yyextra->ARB_gpu_shader_fp64_enable) 633 return ERROR_TOK; 634 yylval->dreal = _mesa_strtod(yytext, NULL); 635 return DOUBLECONSTANT; 636 } 637 638true { 639 yylval->n = 1; 640 return BOOLCONSTANT; 641 } 642false { 643 yylval->n = 0; 644 return BOOLCONSTANT; 645 } 646 647 648 /* Reserved words in GLSL 1.10. */ 649asm KEYWORD(110, 100, 0, 0, ASM); 650class KEYWORD(110, 100, 0, 0, CLASS); 651union KEYWORD(110, 100, 0, 0, UNION); 652enum KEYWORD(110, 100, 0, 0, ENUM); 653typedef KEYWORD(110, 100, 0, 0, TYPEDEF); 654template KEYWORD(110, 100, 0, 0, TEMPLATE); 655this KEYWORD(110, 100, 0, 0, THIS); 656packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK); 657goto KEYWORD(110, 100, 0, 0, GOTO); 658switch KEYWORD(110, 100, 130, 300, SWITCH); 659default KEYWORD(110, 100, 130, 300, DEFAULT); 660inline KEYWORD(110, 100, 0, 0, INLINE_TOK); 661noinline KEYWORD(110, 100, 0, 0, NOINLINE); 662public KEYWORD(110, 100, 0, 0, PUBLIC_TOK); 663static KEYWORD(110, 100, 0, 0, STATIC); 664extern KEYWORD(110, 100, 0, 0, EXTERN); 665external KEYWORD(110, 100, 0, 0, EXTERNAL); 666interface KEYWORD(110, 100, 0, 0, INTERFACE_TOK); 667long KEYWORD(110, 100, 0, 0, LONG_TOK); 668short KEYWORD(110, 100, 0, 0, SHORT_TOK); 669double TYPE_WITH_ALT(130, 100, 130, 300, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::double_type); 670half KEYWORD(110, 100, 0, 0, HALF); 671fixed KEYWORD(110, 100, 0, 0, FIXED_TOK); 672unsigned KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->EXT_gpu_shader4_enable, UNSIGNED); 673input KEYWORD(110, 100, 0, 0, INPUT_TOK); 674output KEYWORD(110, 100, 0, 0, OUTPUT); 675hvec2 KEYWORD(110, 100, 0, 0, HVEC2); 676hvec3 KEYWORD(110, 100, 0, 0, HVEC3); 677hvec4 KEYWORD(110, 100, 0, 0, HVEC4); 678dvec2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec2_type); 679dvec3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec3_type); 680dvec4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec4_type); 681dmat2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type); 682dmat3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type); 683dmat4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type); 684dmat2x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type); 685dmat2x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x3_type); 686dmat2x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x4_type); 687dmat3x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x2_type); 688dmat3x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type); 689dmat3x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x4_type); 690dmat4x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x2_type); 691dmat4x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x3_type); 692dmat4x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type); 693fvec2 KEYWORD(110, 100, 0, 0, FVEC2); 694fvec3 KEYWORD(110, 100, 0, 0, FVEC3); 695fvec4 KEYWORD(110, 100, 0, 0, FVEC4); 696sampler2DRect TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRect_type); 697sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT); 698sampler2DRectShadow TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRectShadow_type); 699sizeof KEYWORD(110, 100, 0, 0, SIZEOF); 700cast KEYWORD(110, 100, 0, 0, CAST); 701namespace KEYWORD(110, 100, 0, 0, NAMESPACE); 702using KEYWORD(110, 100, 0, 0, USING); 703 704 /* Additional reserved words in GLSL 1.20. */ 705lowp KEYWORD(120, 100, 130, 100, LOWP); 706mediump KEYWORD(120, 100, 130, 100, MEDIUMP); 707highp KEYWORD(120, 100, 130, 100, HIGHP); 708precision KEYWORD(120, 100, 130, 100, PRECISION); 709 710 /* Additional reserved words in GLSL 1.30. */ 711case KEYWORD(130, 300, 130, 300, CASE); 712common KEYWORD(130, 300, 0, 0, COMMON); 713partition KEYWORD(130, 300, 0, 0, PARTITION); 714active KEYWORD(130, 300, 0, 0, ACTIVE); 715superp KEYWORD(130, 100, 0, 0, SUPERP); 716samplerBuffer 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::samplerBuffer_type); 717filter KEYWORD(130, 300, 0, 0, FILTER); 718row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR); 719 720 /* Additional reserved words in GLSL 1.40 */ 721isampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, glsl_type::isampler2DRect_type); 722usampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->exts->NV_texture_rectangle && yyextra->exts->EXT_texture_integer, glsl_type::usampler2DRect_type); 723isamplerBuffer 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::isamplerBuffer_type); 724usamplerBuffer 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::usamplerBuffer_type); 725 726 /* Additional reserved words in GLSL ES 3.00 */ 727resource KEYWORD(420, 300, 0, 0, RESOURCE); 728sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE); 729subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE); 730 731 /* Additional words for ARB_gpu_shader_int64 */ 732int64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::int64_t_type); 733i64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec2_type); 734i64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec3_type); 735i64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec4_type); 736 737uint64_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::uint64_t_type); 738u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec2_type); 739u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec3_type); 740u64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec4_type); 741 742[_a-zA-Z][_a-zA-Z0-9]* { 743 struct _mesa_glsl_parse_state *state = yyextra; 744 if (state->es_shader && yyleng > 1024) { 745 _mesa_glsl_error(yylloc, state, 746 "Identifier `%s' exceeds 1024 characters", 747 yytext); 748 } 749 return classify_identifier(state, yytext, yyleng, yylval); 750 } 751 752\. { struct _mesa_glsl_parse_state *state = yyextra; 753 state->is_field = true; 754 return DOT_TOK; } 755 756. { return yytext[0]; } 757 758%% 759 760int 761classify_identifier(struct _mesa_glsl_parse_state *state, const char *name, 762 unsigned name_len, YYSTYPE *output) 763{ 764 /* We're not doing linear_strdup here, to avoid an implicit call on 765 * strlen() for the length of the string, as this is already found by flex 766 * and stored in yyleng 767 */ 768 char *id = (char *) linear_alloc_child(state->linalloc, name_len + 1); 769 memcpy(id, name, name_len + 1); 770 output->identifier = id; 771 772 if (state->is_field) { 773 state->is_field = false; 774 return FIELD_SELECTION; 775 } 776 if (state->symbols->get_variable(name) || state->symbols->get_function(name)) 777 return IDENTIFIER; 778 else if (state->symbols->get_type(name)) 779 return TYPE_IDENTIFIER; 780 else 781 return NEW_IDENTIFIER; 782} 783 784void 785_mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) 786{ 787 yylex_init_extra(state, & state->scanner); 788 yy_scan_string(string, state->scanner); 789} 790 791void 792_mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) 793{ 794 yylex_destroy(state->scanner); 795} 796