glsl_lexer.ll revision 7e102996
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/mtypes.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 50/* A macro for handling reserved words and keywords across language versions. 51 * 52 * Certain words start out as identifiers, become reserved words in 53 * later language revisions, and finally become language keywords. 54 * This may happen at different times in desktop GLSL and GLSL ES. 55 * 56 * For example, consider the following lexer rule: 57 * samplerBuffer KEYWORD(130, 0, 140, 0, SAMPLERBUFFER) 58 * 59 * This means that "samplerBuffer" will be treated as: 60 * - a keyword (SAMPLERBUFFER token) ...in GLSL >= 1.40 61 * - a reserved word - error ...in GLSL >= 1.30 62 * - an identifier ...in GLSL < 1.30 or GLSL ES 63 */ 64#define KEYWORD(reserved_glsl, reserved_glsl_es, \ 65 allowed_glsl, allowed_glsl_es, token) \ 66 KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 67 allowed_glsl, allowed_glsl_es, false, token) 68 69/** 70 * Like the KEYWORD macro, but the word is also treated as a keyword 71 * if the given boolean expression is true. 72 */ 73#define KEYWORD_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 74 allowed_glsl, allowed_glsl_es, \ 75 alt_expr, token) \ 76 do { \ 77 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \ 78 || (alt_expr)) { \ 79 return token; \ 80 } else if (yyextra->is_version(reserved_glsl, \ 81 reserved_glsl_es)) { \ 82 _mesa_glsl_error(yylloc, yyextra, \ 83 "illegal use of reserved word `%s'", yytext); \ 84 return ERROR_TOK; \ 85 } else { \ 86 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 87 } \ 88 } while (0) 89 90/** 91 * Like KEYWORD_WITH_ALT, but used for built-in GLSL types 92 */ 93#define TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 94 allowed_glsl, allowed_glsl_es, \ 95 alt_expr, gtype) \ 96 do { \ 97 if (yyextra->is_version(allowed_glsl, allowed_glsl_es) \ 98 || (alt_expr)) { \ 99 yylval->type = gtype; \ 100 return BASIC_TYPE_TOK; \ 101 } else if (yyextra->is_version(reserved_glsl, \ 102 reserved_glsl_es)) { \ 103 _mesa_glsl_error(yylloc, yyextra, \ 104 "illegal use of reserved word `%s'", yytext); \ 105 return ERROR_TOK; \ 106 } else { \ 107 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 108 } \ 109 } while (0) 110 111#define TYPE(reserved_glsl, reserved_glsl_es, \ 112 allowed_glsl, allowed_glsl_es, \ 113 gtype) \ 114 TYPE_WITH_ALT(reserved_glsl, reserved_glsl_es, \ 115 allowed_glsl, allowed_glsl_es, \ 116 false, gtype) 117 118/** 119 * A macro for handling keywords that have been present in GLSL since 120 * its origin, but were changed into reserved words in GLSL 3.00 ES. 121 */ 122#define DEPRECATED_ES_KEYWORD(token) \ 123 do { \ 124 if (yyextra->is_version(0, 300)) { \ 125 _mesa_glsl_error(yylloc, yyextra, \ 126 "illegal use of reserved word `%s'", yytext); \ 127 return ERROR_TOK; \ 128 } else { \ 129 return token; \ 130 } \ 131 } while (0) 132 133/** 134 * Like DEPRECATED_ES_KEYWORD, but for types 135 */ 136#define DEPRECATED_ES_TYPE_WITH_ALT(alt_expr, gtype) \ 137 do { \ 138 if (yyextra->is_version(0, 300)) { \ 139 _mesa_glsl_error(yylloc, yyextra, \ 140 "illegal use of reserved word `%s'", yytext); \ 141 return ERROR_TOK; \ 142 } else if (alt_expr) { \ 143 yylval->type = gtype; \ 144 return BASIC_TYPE_TOK; \ 145 } else { \ 146 return classify_identifier(yyextra, yytext, yyleng, yylval); \ 147 } \ 148 } while (0) 149 150#define DEPRECATED_ES_TYPE(gtype) \ 151 DEPRECATED_ES_TYPE_WITH_ALT(true, gtype) 152 153static int 154literal_integer(char *text, int len, struct _mesa_glsl_parse_state *state, 155 YYSTYPE *lval, YYLTYPE *lloc, int base) 156{ 157 bool is_uint = (text[len - 1] == 'u' || 158 text[len - 1] == 'U'); 159 bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L'); 160 const char *digits = text; 161 162 if (is_long) 163 is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') || 164 (text[len - 2] == 'U' && text[len - 1] == 'L'); 165 /* Skip "0x" */ 166 if (base == 16) 167 digits += 2; 168 169 unsigned long long value = strtoull(digits, NULL, base); 170 171 if (is_long) 172 lval->n64 = (int64_t)value; 173 else 174 lval->n = (int)value; 175 176 if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) { 177 /* Tries to catch unintentionally providing a negative value. */ 178 _mesa_glsl_warning(lloc, state, 179 "signed literal value `%s' is interpreted as %lld", 180 text, lval->n64); 181 } else if (!is_long && value > UINT_MAX) { 182 /* Note that signed 0xffffffff is valid, not out of range! */ 183 if (state->is_version(130, 300)) { 184 _mesa_glsl_error(lloc, state, 185 "literal value `%s' out of range", text); 186 } else { 187 _mesa_glsl_warning(lloc, state, 188 "literal value `%s' out of range", text); 189 } 190 } else if (base == 10 && !is_uint && (unsigned)value > (unsigned)INT_MAX + 1) { 191 /* Tries to catch unintentionally providing a negative value. 192 * Note that -2147483648 is parsed as -(2147483648), so we don't 193 * want to warn for INT_MAX. 194 */ 195 _mesa_glsl_warning(lloc, state, 196 "signed literal value `%s' is interpreted as %d", 197 text, lval->n); 198 } 199 if (is_long) 200 return is_uint ? UINT64CONSTANT : INT64CONSTANT; 201 else 202 return is_uint ? UINTCONSTANT : INTCONSTANT; 203} 204 205#define LITERAL_INTEGER(base) \ 206 literal_integer(yytext, yyleng, yyextra, yylval, yylloc, base) 207 208%} 209 210%option bison-bridge bison-locations reentrant noyywrap 211%option nounput noyy_top_state 212%option never-interactive 213%option prefix="_mesa_glsl_lexer_" 214%option extra-type="struct _mesa_glsl_parse_state *" 215%option warn nodefault 216 217 /* Note: When adding any start conditions to this list, you must also 218 * update the "Internal compiler error" catch-all rule near the end of 219 * this file. */ 220%x PP PRAGMA 221 222DEC_INT [1-9][0-9]* 223HEX_INT 0[xX][0-9a-fA-F]+ 224OCT_INT 0[0-7]* 225INT ({DEC_INT}|{HEX_INT}|{OCT_INT}) 226SPC [ \t]* 227SPCP [ \t]+ 228HASH ^{SPC}#{SPC} 229%% 230 231[ \r\t]+ ; 232 233 /* Preprocessor tokens. */ 234^[ \t]*#[ \t]*$ ; 235^[ \t]*#[ \t]*version { BEGIN PP; return VERSION_TOK; } 236^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; } 237{HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ { 238 /* Eat characters until the first digit is 239 * encountered 240 */ 241 char *ptr = yytext; 242 while (!isdigit(*ptr)) 243 ptr++; 244 245 /* Subtract one from the line number because 246 * yylineno is zero-based instead of 247 * one-based. 248 */ 249 yylineno = strtol(ptr, &ptr, 0) - 1; 250 251 /* From GLSL 3.30 and GLSL ES on, after processing the 252 * line directive (including its new-line), the implementation 253 * will behave as if it is compiling at the line number passed 254 * as argument. It was line number + 1 in older specifications. 255 */ 256 if (yyextra->is_version(330, 100)) 257 yylineno--; 258 259 yylloc->source = strtol(ptr, NULL, 0); 260 } 261{HASH}line{SPCP}{INT}{SPC}$ { 262 /* Eat characters until the first digit is 263 * encountered 264 */ 265 char *ptr = yytext; 266 while (!isdigit(*ptr)) 267 ptr++; 268 269 /* Subtract one from the line number because 270 * yylineno is zero-based instead of 271 * one-based. 272 */ 273 yylineno = strtol(ptr, &ptr, 0) - 1; 274 275 /* From GLSL 3.30 and GLSL ES on, after processing the 276 * line directive (including its new-line), the implementation 277 * will behave as if it is compiling at the line number passed 278 * as argument. It was line number + 1 in older specifications. 279 */ 280 if (yyextra->is_version(330, 100)) 281 yylineno--; 282 } 283^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) { 284 BEGIN PP; 285 return PRAGMA_DEBUG_ON; 286 } 287^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}off{SPC}\) { 288 BEGIN PP; 289 return PRAGMA_DEBUG_OFF; 290 } 291^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}on{SPC}\) { 292 BEGIN PP; 293 return PRAGMA_OPTIMIZE_ON; 294 } 295^{SPC}#{SPC}pragma{SPCP}optimize{SPC}\({SPC}off{SPC}\) { 296 BEGIN PP; 297 return PRAGMA_OPTIMIZE_OFF; 298 } 299^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}on{SPC}\) { 300 BEGIN PP; 301 return PRAGMA_WARNING_ON; 302 } 303^{SPC}#{SPC}pragma{SPCP}warning{SPC}\({SPC}off{SPC}\) { 304 BEGIN PP; 305 return PRAGMA_WARNING_OFF; 306 } 307^{SPC}#{SPC}pragma{SPCP}STDGL{SPCP}invariant{SPC}\({SPC}all{SPC}\) { 308 BEGIN PP; 309 return PRAGMA_INVARIANT_ALL; 310 } 311^{SPC}#{SPC}pragma{SPCP} { BEGIN PRAGMA; } 312 313<PRAGMA>\n { BEGIN 0; yylineno++; yycolumn = 0; } 314<PRAGMA>. { } 315 316<PP>\/\/[^\n]* { } 317<PP>[ \t\r]* { } 318<PP>: return COLON; 319<PP>[_a-zA-Z][_a-zA-Z0-9]* { 320 /* We're not doing linear_strdup here, to avoid an implicit call 321 * on strlen() for the length of the string, as this is already 322 * found by flex and stored in yyleng 323 */ 324 void *mem_ctx = yyextra->linalloc; 325 char *id = (char *) linear_alloc_child(mem_ctx, yyleng + 1); 326 memcpy(id, yytext, yyleng + 1); 327 yylval->identifier = id; 328 return IDENTIFIER; 329 } 330<PP>[1-9][0-9]* { 331 yylval->n = strtol(yytext, NULL, 10); 332 return INTCONSTANT; 333 } 334<PP>0 { 335 yylval->n = 0; 336 return INTCONSTANT; 337 } 338<PP>\n { BEGIN 0; yylineno++; yycolumn = 0; return EOL; } 339<PP>. { return yytext[0]; } 340 341\n { yylineno++; yycolumn = 0; } 342 343attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE); 344const return CONST_TOK; 345bool { yylval->type = glsl_type::bool_type; return BASIC_TYPE_TOK; } 346float { yylval->type = glsl_type::float_type; return BASIC_TYPE_TOK; } 347int { yylval->type = glsl_type::int_type; return BASIC_TYPE_TOK; } 348uint TYPE(130, 300, 130, 300, glsl_type::uint_type); 349 350break return BREAK; 351continue return CONTINUE; 352do return DO; 353while return WHILE; 354else return ELSE; 355for return FOR; 356if return IF; 357discard return DISCARD; 358return return RETURN; 359 360bvec2 { yylval->type = glsl_type::bvec2_type; return BASIC_TYPE_TOK; } 361bvec3 { yylval->type = glsl_type::bvec3_type; return BASIC_TYPE_TOK; } 362bvec4 { yylval->type = glsl_type::bvec4_type; return BASIC_TYPE_TOK; } 363ivec2 { yylval->type = glsl_type::ivec2_type; return BASIC_TYPE_TOK; } 364ivec3 { yylval->type = glsl_type::ivec3_type; return BASIC_TYPE_TOK; } 365ivec4 { yylval->type = glsl_type::ivec4_type; return BASIC_TYPE_TOK; } 366uvec2 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec2_type); 367uvec3 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec3_type); 368uvec4 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec4_type); 369vec2 { yylval->type = glsl_type::vec2_type; return BASIC_TYPE_TOK; } 370vec3 { yylval->type = glsl_type::vec3_type; return BASIC_TYPE_TOK; } 371vec4 { yylval->type = glsl_type::vec4_type; return BASIC_TYPE_TOK; } 372mat2 { yylval->type = glsl_type::mat2_type; return BASIC_TYPE_TOK; } 373mat3 { yylval->type = glsl_type::mat3_type; return BASIC_TYPE_TOK; } 374mat4 { yylval->type = glsl_type::mat4_type; return BASIC_TYPE_TOK; } 375mat2x2 TYPE(120, 300, 120, 300, glsl_type::mat2_type); 376mat2x3 TYPE(120, 300, 120, 300, glsl_type::mat2x3_type); 377mat2x4 TYPE(120, 300, 120, 300, glsl_type::mat2x4_type); 378mat3x2 TYPE(120, 300, 120, 300, glsl_type::mat3x2_type); 379mat3x3 TYPE(120, 300, 120, 300, glsl_type::mat3_type); 380mat3x4 TYPE(120, 300, 120, 300, glsl_type::mat3x4_type); 381mat4x2 TYPE(120, 300, 120, 300, glsl_type::mat4x2_type); 382mat4x3 TYPE(120, 300, 120, 300, glsl_type::mat4x3_type); 383mat4x4 TYPE(120, 300, 120, 300, glsl_type::mat4_type); 384 385in return IN_TOK; 386out return OUT_TOK; 387inout return INOUT_TOK; 388uniform return UNIFORM; 389buffer KEYWORD_WITH_ALT(0, 0, 430, 310, yyextra->ARB_shader_storage_buffer_object_enable, BUFFER); 390varying DEPRECATED_ES_KEYWORD(VARYING); 391centroid KEYWORD_WITH_ALT(120, 300, 120, 300, yyextra->EXT_gpu_shader4_enable, CENTROID); 392invariant KEYWORD(120, 100, 120, 100, INVARIANT); 393flat KEYWORD_WITH_ALT(130, 100, 130, 300, yyextra->EXT_gpu_shader4_enable, FLAT); 394smooth KEYWORD(130, 300, 130, 300, SMOOTH); 395noperspective KEYWORD_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable, NOPERSPECTIVE); 396patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH); 397 398sampler1D DEPRECATED_ES_TYPE(glsl_type::sampler1D_type); 399sampler2D { yylval->type = glsl_type::sampler2D_type; return BASIC_TYPE_TOK; } 400sampler3D { yylval->type = glsl_type::sampler3D_type; return BASIC_TYPE_TOK; } 401samplerCube { yylval->type = glsl_type::samplerCube_type; return BASIC_TYPE_TOK; } 402sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArray_type); 403sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArray_type); 404sampler1DShadow DEPRECATED_ES_TYPE(glsl_type::sampler1DShadow_type); 405sampler2DShadow { yylval->type = glsl_type::sampler2DShadow_type; return BASIC_TYPE_TOK; } 406samplerCubeShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::samplerCubeShadow_type); 407sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArrayShadow_type); 408sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArrayShadow_type); 409isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler1D_type); 410isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler2D_type); 411isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler3D_type); 412isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isamplerCube_type); 413isampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::isampler1DArray_type); 414isampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::isampler2DArray_type); 415usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler1D_type); 416usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler2D_type); 417usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler3D_type); 418usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usamplerCube_type); 419usampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::usampler1DArray_type); 420usampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::usampler2DArray_type); 421 422 /* additional keywords in ARB_texture_multisample, included in GLSL 1.50 */ 423 /* these are reserved but not defined in GLSL 3.00 */ 424 /* [iu]sampler2DMS are defined in GLSL ES 3.10 */ 425sampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::sampler2DMS_type); 426isampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::isampler2DMS_type); 427usampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::usampler2DMS_type); 428sampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::sampler2DMSArray_type); 429isampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::isampler2DMSArray_type); 430usampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::usampler2DMSArray_type); 431 432 /* keywords available with ARB_texture_cube_map_array_enable extension on desktop GLSL */ 433samplerCubeArray 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); 434isamplerCubeArray 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); 435usamplerCubeArray 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); 436samplerCubeArrayShadow 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); 437 438samplerExternalOES { 439 if (yyextra->OES_EGL_image_external_enable || yyextra->OES_EGL_image_external_essl3_enable) { 440 yylval->type = glsl_type::samplerExternalOES_type; 441 return BASIC_TYPE_TOK; 442 } else 443 return IDENTIFIER; 444 } 445 446 /* keywords available with ARB_gpu_shader5 */ 447precise KEYWORD_WITH_ALT(400, 310, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->EXT_gpu_shader5_enable || yyextra->OES_gpu_shader5_enable, PRECISE); 448 449 /* keywords available with ARB_shader_image_load_store */ 450image1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1D_type); 451image2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2D_type); 452image3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image3D_type); 453image2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DRect_type); 454imageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::imageCube_type); 455imageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::imageBuffer_type); 456image1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1DArray_type); 457image2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DArray_type); 458imageCubeArray TYPE_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, glsl_type::imageCubeArray_type); 459image2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMS_type); 460image2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMSArray_type); 461iimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1D_type); 462iimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2D_type); 463iimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage3D_type); 464iimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DRect_type); 465iimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimageCube_type); 466iimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::iimageBuffer_type); 467iimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1DArray_type); 468iimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DArray_type); 469iimageCubeArray TYPE_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, glsl_type::iimageCubeArray_type); 470iimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMS_type); 471iimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMSArray_type); 472uimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1D_type); 473uimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2D_type); 474uimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage3D_type); 475uimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DRect_type); 476uimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimageCube_type); 477uimageBuffer TYPE_WITH_ALT(130, 300, 420, 320, yyextra->ARB_shader_image_load_store_enable || yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable, glsl_type::uimageBuffer_type); 478uimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1DArray_type); 479uimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DArray_type); 480uimageCubeArray TYPE_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, glsl_type::uimageCubeArray_type); 481uimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMS_type); 482uimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMSArray_type); 483image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW); 484image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW); 485image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW); 486image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW); 487 488coherent KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, COHERENT); 489volatile KEYWORD_WITH_ALT(110, 100, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, VOLATILE); 490restrict KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, RESTRICT); 491readonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, READONLY); 492writeonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, WRITEONLY); 493 494atomic_uint TYPE_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, glsl_type::atomic_uint_type); 495 496shared KEYWORD_WITH_ALT(430, 310, 430, 310, yyextra->ARB_compute_shader_enable, SHARED); 497 498struct return STRUCT; 499void return VOID_TOK; 500 501layout { 502 if ((yyextra->is_version(140, 300)) 503 || yyextra->ARB_bindless_texture_enable 504 || yyextra->KHR_blend_equation_advanced_enable 505 || yyextra->AMD_conservative_depth_enable 506 || yyextra->ARB_conservative_depth_enable 507 || yyextra->ARB_explicit_attrib_location_enable 508 || yyextra->ARB_explicit_uniform_location_enable 509 || yyextra->ARB_post_depth_coverage_enable 510 || yyextra->has_separate_shader_objects() 511 || yyextra->ARB_uniform_buffer_object_enable 512 || yyextra->ARB_fragment_coord_conventions_enable 513 || yyextra->ARB_shading_language_420pack_enable 514 || yyextra->ARB_compute_shader_enable 515 || yyextra->ARB_tessellation_shader_enable 516 || yyextra->EXT_shader_framebuffer_fetch_non_coherent_enable) { 517 return LAYOUT_TOK; 518 } else { 519 return classify_identifier(yyextra, yytext, yyleng, yylval); 520 } 521 } 522 523\+\+ return INC_OP; 524-- return DEC_OP; 525\<= return LE_OP; 526>= return GE_OP; 527== return EQ_OP; 528!= return NE_OP; 529&& return AND_OP; 530\|\| return OR_OP; 531"^^" return XOR_OP; 532"<<" return LEFT_OP; 533">>" return RIGHT_OP; 534 535\*= return MUL_ASSIGN; 536\/= return DIV_ASSIGN; 537\+= return ADD_ASSIGN; 538\%= return MOD_ASSIGN; 539\<\<= return LEFT_ASSIGN; 540>>= return RIGHT_ASSIGN; 541&= return AND_ASSIGN; 542"^=" return XOR_ASSIGN; 543\|= return OR_ASSIGN; 544-= return SUB_ASSIGN; 545 546[1-9][0-9]*([uU]|[lL]|ul|UL)? { 547 return LITERAL_INTEGER(10); 548 } 5490[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? { 550 return LITERAL_INTEGER(16); 551 } 5520[0-7]*([uU]|[lL]|ul|UL)? { 553 return LITERAL_INTEGER(8); 554 } 555 556[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | 557\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | 558[0-9]+\.([eE][+-]?[0-9]+)?[fF]? | 559[0-9]+[eE][+-]?[0-9]+[fF]? { 560 struct _mesa_glsl_parse_state *state = yyextra; 561 char suffix = yytext[strlen(yytext) - 1]; 562 if (!state->is_version(120, 300) && 563 (suffix == 'f' || suffix == 'F')) { 564 _mesa_glsl_warning(yylloc, state, 565 "Float suffixes are invalid in GLSL 1.10"); 566 } 567 yylval->real = _mesa_strtof(yytext, NULL); 568 return FLOATCONSTANT; 569 } 570 571[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 572\.[0-9]+([eE][+-]?[0-9]+)?(lf|LF) | 573[0-9]+\.([eE][+-]?[0-9]+)?(lf|LF) | 574[0-9]+[eE][+-]?[0-9]+(lf|LF) { 575 if (!yyextra->is_version(400, 0) && 576 !yyextra->ARB_gpu_shader_fp64_enable) 577 return ERROR_TOK; 578 yylval->dreal = _mesa_strtod(yytext, NULL); 579 return DOUBLECONSTANT; 580 } 581 582true { 583 yylval->n = 1; 584 return BOOLCONSTANT; 585 } 586false { 587 yylval->n = 0; 588 return BOOLCONSTANT; 589 } 590 591 592 /* Reserved words in GLSL 1.10. */ 593asm KEYWORD(110, 100, 0, 0, ASM); 594class KEYWORD(110, 100, 0, 0, CLASS); 595union KEYWORD(110, 100, 0, 0, UNION); 596enum KEYWORD(110, 100, 0, 0, ENUM); 597typedef KEYWORD(110, 100, 0, 0, TYPEDEF); 598template KEYWORD(110, 100, 0, 0, TEMPLATE); 599this KEYWORD(110, 100, 0, 0, THIS); 600packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK); 601goto KEYWORD(110, 100, 0, 0, GOTO); 602switch KEYWORD(110, 100, 130, 300, SWITCH); 603default KEYWORD(110, 100, 130, 300, DEFAULT); 604inline KEYWORD(110, 100, 0, 0, INLINE_TOK); 605noinline KEYWORD(110, 100, 0, 0, NOINLINE); 606public KEYWORD(110, 100, 0, 0, PUBLIC_TOK); 607static KEYWORD(110, 100, 0, 0, STATIC); 608extern KEYWORD(110, 100, 0, 0, EXTERN); 609external KEYWORD(110, 100, 0, 0, EXTERNAL); 610interface KEYWORD(110, 100, 0, 0, INTERFACE); 611long KEYWORD(110, 100, 0, 0, LONG_TOK); 612short KEYWORD(110, 100, 0, 0, SHORT_TOK); 613double TYPE_WITH_ALT(130, 100, 130, 300, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::double_type); 614half KEYWORD(110, 100, 0, 0, HALF); 615fixed KEYWORD(110, 100, 0, 0, FIXED_TOK); 616unsigned KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->EXT_gpu_shader4_enable, UNSIGNED); 617input KEYWORD(110, 100, 0, 0, INPUT_TOK); 618output KEYWORD(110, 100, 0, 0, OUTPUT); 619hvec2 KEYWORD(110, 100, 0, 0, HVEC2); 620hvec3 KEYWORD(110, 100, 0, 0, HVEC3); 621hvec4 KEYWORD(110, 100, 0, 0, HVEC4); 622dvec2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec2_type); 623dvec3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec3_type); 624dvec4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec4_type); 625dmat2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type); 626dmat3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type); 627dmat4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type); 628dmat2x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type); 629dmat2x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x3_type); 630dmat2x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x4_type); 631dmat3x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x2_type); 632dmat3x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type); 633dmat3x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x4_type); 634dmat4x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x2_type); 635dmat4x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x3_type); 636dmat4x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type); 637fvec2 KEYWORD(110, 100, 0, 0, FVEC2); 638fvec3 KEYWORD(110, 100, 0, 0, FVEC3); 639fvec4 KEYWORD(110, 100, 0, 0, FVEC4); 640sampler2DRect TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRect_type); 641sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT); 642sampler2DRectShadow TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRectShadow_type); 643sizeof KEYWORD(110, 100, 0, 0, SIZEOF); 644cast KEYWORD(110, 100, 0, 0, CAST); 645namespace KEYWORD(110, 100, 0, 0, NAMESPACE); 646using KEYWORD(110, 100, 0, 0, USING); 647 648 /* Additional reserved words in GLSL 1.20. */ 649lowp KEYWORD(120, 100, 130, 100, LOWP); 650mediump KEYWORD(120, 100, 130, 100, MEDIUMP); 651highp KEYWORD(120, 100, 130, 100, HIGHP); 652precision KEYWORD(120, 100, 130, 100, PRECISION); 653 654 /* Additional reserved words in GLSL 1.30. */ 655case KEYWORD(130, 300, 130, 300, CASE); 656common KEYWORD(130, 300, 0, 0, COMMON); 657partition KEYWORD(130, 300, 0, 0, PARTITION); 658active KEYWORD(130, 300, 0, 0, ACTIVE); 659superp KEYWORD(130, 100, 0, 0, SUPERP); 660samplerBuffer TYPE_WITH_ALT(130, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object), glsl_type::samplerBuffer_type); 661filter KEYWORD(130, 300, 0, 0, FILTER); 662row_major KEYWORD_WITH_ALT(130, 0, 140, 0, yyextra->ARB_uniform_buffer_object_enable && !yyextra->es_shader, ROW_MAJOR); 663 664 /* Additional reserved words in GLSL 1.40 */ 665isampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.NV_texture_rectangle && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler2DRect_type); 666usampler2DRect TYPE_WITH_ALT(140, 300, 140, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.NV_texture_rectangle && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler2DRect_type); 667isamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object && yyextra->ctx->Extensions.EXT_texture_integer), glsl_type::isamplerBuffer_type); 668usamplerBuffer TYPE_WITH_ALT(140, 300, 140, 320, yyextra->EXT_texture_buffer_enable || yyextra->OES_texture_buffer_enable || (yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_buffer_object && yyextra->ctx->Extensions.EXT_texture_integer), glsl_type::usamplerBuffer_type); 669 670 /* Additional reserved words in GLSL ES 3.00 */ 671resource KEYWORD(420, 300, 0, 0, RESOURCE); 672sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE); 673subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE); 674 675 /* Additional words for ARB_gpu_shader_int64 */ 676int64_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); 677i64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec2_type); 678i64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec3_type); 679i64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec4_type); 680 681uint64_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); 682u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec2_type); 683u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec3_type); 684u64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec4_type); 685 686[_a-zA-Z][_a-zA-Z0-9]* { 687 struct _mesa_glsl_parse_state *state = yyextra; 688 if (state->es_shader && yyleng > 1024) { 689 _mesa_glsl_error(yylloc, state, 690 "Identifier `%s' exceeds 1024 characters", 691 yytext); 692 } 693 return classify_identifier(state, yytext, yyleng, yylval); 694 } 695 696\. { struct _mesa_glsl_parse_state *state = yyextra; 697 state->is_field = true; 698 return DOT_TOK; } 699 700. { return yytext[0]; } 701 702%% 703 704int 705classify_identifier(struct _mesa_glsl_parse_state *state, const char *name, 706 unsigned name_len, YYSTYPE *output) 707{ 708 /* We're not doing linear_strdup here, to avoid an implicit call on 709 * strlen() for the length of the string, as this is already found by flex 710 * and stored in yyleng 711 */ 712 char *id = (char *) linear_alloc_child(state->linalloc, name_len + 1); 713 memcpy(id, name, name_len + 1); 714 output->identifier = id; 715 716 if (state->is_field) { 717 state->is_field = false; 718 return FIELD_SELECTION; 719 } 720 if (state->symbols->get_variable(name) || state->symbols->get_function(name)) 721 return IDENTIFIER; 722 else if (state->symbols->get_type(name)) 723 return TYPE_IDENTIFIER; 724 else 725 return NEW_IDENTIFIER; 726} 727 728void 729_mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state, const char *string) 730{ 731 yylex_init_extra(state, & state->scanner); 732 yy_scan_string(string, state->scanner); 733} 734 735void 736_mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state) 737{ 738 yylex_destroy(state->scanner); 739} 740