glsl/linker: check for xfb_offset aliasing
[mesa.git] / src / compiler / glsl / glsl_lexer.ll
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
32 static 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
153 static int
154 literal_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
222 DEC_INT [1-9][0-9]*
223 HEX_INT 0[xX][0-9a-fA-F]+
224 OCT_INT 0[0-7]*
225 INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
226 SPC [ \t]*
227 SPCP [ \t]+
228 HASH ^{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
343 attribute DEPRECATED_ES_KEYWORD(ATTRIBUTE);
344 const return CONST_TOK;
345 bool { yylval->type = glsl_type::bool_type; return BASIC_TYPE_TOK; }
346 float { yylval->type = glsl_type::float_type; return BASIC_TYPE_TOK; }
347 int { yylval->type = glsl_type::int_type; return BASIC_TYPE_TOK; }
348 uint TYPE(130, 300, 130, 300, glsl_type::uint_type);
349
350 break return BREAK;
351 continue return CONTINUE;
352 do return DO;
353 while return WHILE;
354 else return ELSE;
355 for return FOR;
356 if return IF;
357 discard return DISCARD;
358 return return RETURN;
359
360 bvec2 { yylval->type = glsl_type::bvec2_type; return BASIC_TYPE_TOK; }
361 bvec3 { yylval->type = glsl_type::bvec3_type; return BASIC_TYPE_TOK; }
362 bvec4 { yylval->type = glsl_type::bvec4_type; return BASIC_TYPE_TOK; }
363 ivec2 { yylval->type = glsl_type::ivec2_type; return BASIC_TYPE_TOK; }
364 ivec3 { yylval->type = glsl_type::ivec3_type; return BASIC_TYPE_TOK; }
365 ivec4 { yylval->type = glsl_type::ivec4_type; return BASIC_TYPE_TOK; }
366 uvec2 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec2_type);
367 uvec3 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec3_type);
368 uvec4 TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::uvec4_type);
369 vec2 { yylval->type = glsl_type::vec2_type; return BASIC_TYPE_TOK; }
370 vec3 { yylval->type = glsl_type::vec3_type; return BASIC_TYPE_TOK; }
371 vec4 { yylval->type = glsl_type::vec4_type; return BASIC_TYPE_TOK; }
372 mat2 { yylval->type = glsl_type::mat2_type; return BASIC_TYPE_TOK; }
373 mat3 { yylval->type = glsl_type::mat3_type; return BASIC_TYPE_TOK; }
374 mat4 { yylval->type = glsl_type::mat4_type; return BASIC_TYPE_TOK; }
375 mat2x2 TYPE(120, 300, 120, 300, glsl_type::mat2_type);
376 mat2x3 TYPE(120, 300, 120, 300, glsl_type::mat2x3_type);
377 mat2x4 TYPE(120, 300, 120, 300, glsl_type::mat2x4_type);
378 mat3x2 TYPE(120, 300, 120, 300, glsl_type::mat3x2_type);
379 mat3x3 TYPE(120, 300, 120, 300, glsl_type::mat3_type);
380 mat3x4 TYPE(120, 300, 120, 300, glsl_type::mat3x4_type);
381 mat4x2 TYPE(120, 300, 120, 300, glsl_type::mat4x2_type);
382 mat4x3 TYPE(120, 300, 120, 300, glsl_type::mat4x3_type);
383 mat4x4 TYPE(120, 300, 120, 300, glsl_type::mat4_type);
384
385 in return IN_TOK;
386 out return OUT_TOK;
387 inout return INOUT_TOK;
388 uniform return UNIFORM;
389 buffer KEYWORD_WITH_ALT(0, 0, 430, 310, yyextra->ARB_shader_storage_buffer_object_enable, BUFFER);
390 varying DEPRECATED_ES_KEYWORD(VARYING);
391 centroid KEYWORD_WITH_ALT(120, 300, 120, 300, yyextra->EXT_gpu_shader4_enable, CENTROID);
392 invariant KEYWORD(120, 100, 120, 100, INVARIANT);
393 flat KEYWORD_WITH_ALT(130, 100, 130, 300, yyextra->EXT_gpu_shader4_enable, FLAT);
394 smooth KEYWORD(130, 300, 130, 300, SMOOTH);
395 noperspective KEYWORD_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable, NOPERSPECTIVE);
396 patch KEYWORD_WITH_ALT(0, 300, 400, 320, yyextra->has_tessellation_shader(), PATCH);
397
398 sampler1D DEPRECATED_ES_TYPE(glsl_type::sampler1D_type);
399 sampler2D { yylval->type = glsl_type::sampler2D_type; return BASIC_TYPE_TOK; }
400 sampler3D { yylval->type = glsl_type::sampler3D_type; return BASIC_TYPE_TOK; }
401 samplerCube { yylval->type = glsl_type::samplerCube_type; return BASIC_TYPE_TOK; }
402 sampler1DArray TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArray_type);
403 sampler2DArray TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArray_type);
404 sampler1DShadow DEPRECATED_ES_TYPE(glsl_type::sampler1DShadow_type);
405 sampler2DShadow { yylval->type = glsl_type::sampler2DShadow_type; return BASIC_TYPE_TOK; }
406 samplerCubeShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable, glsl_type::samplerCubeShadow_type);
407 sampler1DArrayShadow TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler1DArrayShadow_type);
408 sampler2DArrayShadow TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_array, glsl_type::sampler2DArrayShadow_type);
409 isampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler1D_type);
410 isampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler2D_type);
411 isampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isampler3D_type);
412 isamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::isamplerCube_type);
413 isampler1DArray 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);
414 isampler2DArray 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);
415 usampler1D TYPE_WITH_ALT(130, 300, 130, 0, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler1D_type);
416 usampler2D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler2D_type);
417 usampler3D TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usampler3D_type);
418 usamplerCube TYPE_WITH_ALT(130, 300, 130, 300, yyextra->EXT_gpu_shader4_enable && yyextra->ctx->Extensions.EXT_texture_integer, glsl_type::usamplerCube_type);
419 usampler1DArray 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);
420 usampler2DArray 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 */
425 sampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::sampler2DMS_type);
426 isampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::isampler2DMS_type);
427 usampler2DMS TYPE_WITH_ALT(150, 300, 150, 310, yyextra->ARB_texture_multisample_enable, glsl_type::usampler2DMS_type);
428 sampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::sampler2DMSArray_type);
429 isampler2DMSArray TYPE_WITH_ALT(150, 300, 150, 320, yyextra->ARB_texture_multisample_enable || yyextra->OES_texture_storage_multisample_2d_array_enable, glsl_type::isampler2DMSArray_type);
430 usampler2DMSArray 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 */
433 samplerCubeArray 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);
434 isamplerCubeArray 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);
435 usamplerCubeArray 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);
436 samplerCubeArrayShadow 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
438 samplerExternalOES {
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 */
447 precise 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 */
450 image1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1D_type);
451 image2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2D_type);
452 image3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image3D_type);
453 image2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DRect_type);
454 imageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::imageCube_type);
455 imageBuffer 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);
456 image1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image1DArray_type);
457 image2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DArray_type);
458 imageCubeArray 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);
459 image2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMS_type);
460 image2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::image2DMSArray_type);
461 iimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1D_type);
462 iimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2D_type);
463 iimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage3D_type);
464 iimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DRect_type);
465 iimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimageCube_type);
466 iimageBuffer 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);
467 iimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage1DArray_type);
468 iimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DArray_type);
469 iimageCubeArray 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);
470 iimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMS_type);
471 iimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::iimage2DMSArray_type);
472 uimage1D TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1D_type);
473 uimage2D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2D_type);
474 uimage3D TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage3D_type);
475 uimage2DRect TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DRect_type);
476 uimageCube TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimageCube_type);
477 uimageBuffer 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);
478 uimage1DArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage1DArray_type);
479 uimage2DArray TYPE_WITH_ALT(130, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DArray_type);
480 uimageCubeArray 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);
481 uimage2DMS TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMS_type);
482 uimage2DMSArray TYPE_WITH_ALT(130, 300, 420, 0, yyextra->ARB_shader_image_load_store_enable, glsl_type::uimage2DMSArray_type);
483 image1DShadow KEYWORD(130, 300, 0, 0, IMAGE1DSHADOW);
484 image2DShadow KEYWORD(130, 300, 0, 0, IMAGE2DSHADOW);
485 image1DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE1DARRAYSHADOW);
486 image2DArrayShadow KEYWORD(130, 300, 0, 0, IMAGE2DARRAYSHADOW);
487
488 coherent KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, COHERENT);
489 volatile KEYWORD_WITH_ALT(110, 100, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, VOLATILE);
490 restrict KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, RESTRICT);
491 readonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, READONLY);
492 writeonly KEYWORD_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_image_load_store_enable || yyextra->ARB_shader_storage_buffer_object_enable, WRITEONLY);
493
494 atomic_uint TYPE_WITH_ALT(420, 300, 420, 310, yyextra->ARB_shader_atomic_counters_enable, glsl_type::atomic_uint_type);
495
496 shared KEYWORD_WITH_ALT(430, 310, 430, 310, yyextra->ARB_compute_shader_enable, SHARED);
497
498 struct return STRUCT;
499 void return VOID_TOK;
500
501 layout {
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 }
549 0[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? {
550 return LITERAL_INTEGER(16);
551 }
552 0[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
582 true {
583 yylval->n = 1;
584 return BOOLCONSTANT;
585 }
586 false {
587 yylval->n = 0;
588 return BOOLCONSTANT;
589 }
590
591
592 /* Reserved words in GLSL 1.10. */
593 asm KEYWORD(110, 100, 0, 0, ASM);
594 class KEYWORD(110, 100, 0, 0, CLASS);
595 union KEYWORD(110, 100, 0, 0, UNION);
596 enum KEYWORD(110, 100, 0, 0, ENUM);
597 typedef KEYWORD(110, 100, 0, 0, TYPEDEF);
598 template KEYWORD(110, 100, 0, 0, TEMPLATE);
599 this KEYWORD(110, 100, 0, 0, THIS);
600 packed KEYWORD_WITH_ALT(110, 100, 140, 300, yyextra->ARB_uniform_buffer_object_enable, PACKED_TOK);
601 goto KEYWORD(110, 100, 0, 0, GOTO);
602 switch KEYWORD(110, 100, 130, 300, SWITCH);
603 default KEYWORD(110, 100, 130, 300, DEFAULT);
604 inline KEYWORD(110, 100, 0, 0, INLINE_TOK);
605 noinline KEYWORD(110, 100, 0, 0, NOINLINE);
606 public KEYWORD(110, 100, 0, 0, PUBLIC_TOK);
607 static KEYWORD(110, 100, 0, 0, STATIC);
608 extern KEYWORD(110, 100, 0, 0, EXTERN);
609 external KEYWORD(110, 100, 0, 0, EXTERNAL);
610 interface KEYWORD(110, 100, 0, 0, INTERFACE);
611 long KEYWORD(110, 100, 0, 0, LONG_TOK);
612 short KEYWORD(110, 100, 0, 0, SHORT_TOK);
613 double TYPE_WITH_ALT(130, 100, 130, 300, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::double_type);
614 half KEYWORD(110, 100, 0, 0, HALF);
615 fixed KEYWORD(110, 100, 0, 0, FIXED_TOK);
616 unsigned KEYWORD_WITH_ALT(110, 100, 0, 0, yyextra->EXT_gpu_shader4_enable, UNSIGNED);
617 input KEYWORD(110, 100, 0, 0, INPUT_TOK);
618 output KEYWORD(110, 100, 0, 0, OUTPUT);
619 hvec2 KEYWORD(110, 100, 0, 0, HVEC2);
620 hvec3 KEYWORD(110, 100, 0, 0, HVEC3);
621 hvec4 KEYWORD(110, 100, 0, 0, HVEC4);
622 dvec2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec2_type);
623 dvec3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec3_type);
624 dvec4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dvec4_type);
625 dmat2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type);
626 dmat3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type);
627 dmat4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type);
628 dmat2x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2_type);
629 dmat2x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x3_type);
630 dmat2x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat2x4_type);
631 dmat3x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x2_type);
632 dmat3x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3_type);
633 dmat3x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat3x4_type);
634 dmat4x2 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x2_type);
635 dmat4x3 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4x3_type);
636 dmat4x4 TYPE_WITH_ALT(110, 100, 400, 0, yyextra->ARB_gpu_shader_fp64_enable, glsl_type::dmat4_type);
637 fvec2 KEYWORD(110, 100, 0, 0, FVEC2);
638 fvec3 KEYWORD(110, 100, 0, 0, FVEC3);
639 fvec4 KEYWORD(110, 100, 0, 0, FVEC4);
640 sampler2DRect TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRect_type);
641 sampler3DRect KEYWORD(110, 100, 0, 0, SAMPLER3DRECT);
642 sampler2DRectShadow TYPE_WITH_ALT(110, 100, 0, 0, yyextra->ARB_texture_rectangle_enable, glsl_type::sampler2DRectShadow_type);
643 sizeof KEYWORD(110, 100, 0, 0, SIZEOF);
644 cast KEYWORD(110, 100, 0, 0, CAST);
645 namespace KEYWORD(110, 100, 0, 0, NAMESPACE);
646 using KEYWORD(110, 100, 0, 0, USING);
647
648 /* Additional reserved words in GLSL 1.20. */
649 lowp KEYWORD(120, 100, 130, 100, LOWP);
650 mediump KEYWORD(120, 100, 130, 100, MEDIUMP);
651 highp KEYWORD(120, 100, 130, 100, HIGHP);
652 precision KEYWORD(120, 100, 130, 100, PRECISION);
653
654 /* Additional reserved words in GLSL 1.30. */
655 case KEYWORD(130, 300, 130, 300, CASE);
656 common KEYWORD(130, 300, 0, 0, COMMON);
657 partition KEYWORD(130, 300, 0, 0, PARTITION);
658 active KEYWORD(130, 300, 0, 0, ACTIVE);
659 superp KEYWORD(130, 100, 0, 0, SUPERP);
660 samplerBuffer 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);
661 filter KEYWORD(130, 300, 0, 0, FILTER);
662 row_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 */
665 isampler2DRect 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);
666 usampler2DRect 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);
667 isamplerBuffer 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);
668 usamplerBuffer 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 */
671 resource KEYWORD(420, 300, 0, 0, RESOURCE);
672 sample KEYWORD_WITH_ALT(400, 300, 400, 320, yyextra->ARB_gpu_shader5_enable || yyextra->OES_shader_multisample_interpolation_enable, SAMPLE);
673 subroutine KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_shader_subroutine_enable, SUBROUTINE);
674
675 /* Additional words for ARB_gpu_shader_int64 */
676 int64_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);
677 i64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec2_type);
678 i64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec3_type);
679 i64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::i64vec4_type);
680
681 uint64_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);
682 u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec2_type);
683 u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, glsl_type::u64vec3_type);
684 u64vec4 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
704 int
705 classify_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
728 void
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
735 void
736 _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state)
737 {
738 yylex_destroy(state->scanner);
739 }