1 //
2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 // Copyright (C) 2020 Google, Inc.
6 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
7 //
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
12 // are met:
13 //
14 // Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // Redistributions in binary form must reproduce the above
18 // copyright notice, this list of conditions and the following
19 // disclaimer in the documentation and/or other materials provided
20 // with the distribution.
21 //
22 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
23 // contributors may be used to endorse or promote products derived
24 // from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 // POSSIBILITY OF SUCH DAMAGE.
38 //
39
40 //
41 // GLSL scanning, leveraging the scanning done by the preprocessor.
42 //
43
44 #include <cstring>
45 #include <unordered_map>
46 #include <unordered_set>
47
48 #include "../Include/Types.h"
49 #include "SymbolTable.h"
50 #include "ParseHelper.h"
51 #include "attribute.h"
52 #include "glslang_tab.cpp.h"
53 #include "ScanContext.h"
54 #include "Scan.h"
55
56 // preprocessor includes
57 #include "preprocessor/PpContext.h"
58 #include "preprocessor/PpTokens.h"
59
60 // Required to avoid missing prototype warnings for some compilers
61 int yylex(YYSTYPE*, glslang::TParseContext&);
62
63 namespace glslang {
64
65 // read past any white space
consumeWhiteSpace(bool & foundNonSpaceTab)66 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
67 {
68 int c = peek(); // don't accidentally consume anything other than whitespace
69 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
70 if (c == '\r' || c == '\n')
71 foundNonSpaceTab = true;
72 get();
73 c = peek();
74 }
75 }
76
77 // return true if a comment was actually consumed
consumeComment()78 bool TInputScanner::consumeComment()
79 {
80 if (peek() != '/')
81 return false;
82
83 get(); // consume the '/'
84 int c = peek();
85 if (c == '/') {
86
87 // a '//' style comment
88 get(); // consume the second '/'
89 c = get();
90 do {
91 while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
92 c = get();
93
94 if (c == EndOfInput || c == '\r' || c == '\n') {
95 while (c == '\r' || c == '\n')
96 c = get();
97
98 // we reached the end of the comment
99 break;
100 } else {
101 // it's a '\', so we need to keep going, after skipping what's escaped
102
103 // read the skipped character
104 c = get();
105
106 // if it's a two-character newline, skip both characters
107 if (c == '\r' && peek() == '\n')
108 get();
109 c = get();
110 }
111 } while (true);
112
113 // put back the last non-comment character
114 if (c != EndOfInput)
115 unget();
116
117 return true;
118 } else if (c == '*') {
119
120 // a '/*' style comment
121 get(); // consume the '*'
122 c = get();
123 do {
124 while (c != EndOfInput && c != '*')
125 c = get();
126 if (c == '*') {
127 c = get();
128 if (c == '/')
129 break; // end of comment
130 // not end of comment
131 } else // end of input
132 break;
133 } while (true);
134
135 return true;
136 } else {
137 // it's not a comment, put the '/' back
138 unget();
139
140 return false;
141 }
142 }
143
144 // skip whitespace, then skip a comment, rinse, repeat
consumeWhitespaceComment(bool & foundNonSpaceTab)145 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
146 {
147 do {
148 consumeWhiteSpace(foundNonSpaceTab);
149
150 // if not starting a comment now, then done
151 int c = peek();
152 if (c != '/' || c == EndOfInput)
153 return;
154
155 // skip potential comment
156 foundNonSpaceTab = true;
157 if (! consumeComment())
158 return;
159
160 } while (true);
161 }
162
163 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
164 // or no #version was found; otherwise, returns false. There is no error case, it always
165 // succeeds, but will leave version == 0 if no #version was found.
166 //
167 // Sets notFirstToken based on whether tokens (beyond white space and comments)
168 // appeared before the #version.
169 //
170 // N.B. does not attempt to leave input in any particular known state. The assumption
171 // is that scanning will start anew, following the rules for the chosen version/profile,
172 // and with a corresponding parsing context.
173 //
scanVersion(int & version,EProfile & profile,bool & notFirstToken)174 bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
175 {
176 // This function doesn't have to get all the semantics correct,
177 // just find the #version if there is a correct one present.
178 // The preprocessor will have the responsibility of getting all the semantics right.
179
180 bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
181 notFirstToken = false; // means not first WRT to real tokens
182 version = 0; // means not found
183 profile = ENoProfile;
184
185 bool foundNonSpaceTab = false;
186 bool lookingInMiddle = false;
187 int c;
188 do {
189 if (lookingInMiddle) {
190 notFirstToken = true;
191 // make forward progress by finishing off the current line plus extra new lines
192 if (peek() != '\n' && peek() != '\r') {
193 do {
194 c = get();
195 } while (c != EndOfInput && c != '\n' && c != '\r');
196 }
197 while (peek() == '\n' || peek() == '\r')
198 get();
199 if (peek() == EndOfInput)
200 return true;
201 }
202 lookingInMiddle = true;
203
204 // Nominal start, skipping the desktop allowed comments and white space, but tracking if
205 // something else was found for ES:
206 consumeWhitespaceComment(foundNonSpaceTab);
207 if (foundNonSpaceTab)
208 versionNotFirst = true;
209
210 // "#"
211 if (get() != '#') {
212 versionNotFirst = true;
213 continue;
214 }
215
216 // whitespace
217 do {
218 c = get();
219 } while (c == ' ' || c == '\t');
220
221 // "version"
222 if ( c != 'v' ||
223 get() != 'e' ||
224 get() != 'r' ||
225 get() != 's' ||
226 get() != 'i' ||
227 get() != 'o' ||
228 get() != 'n') {
229 versionNotFirst = true;
230 continue;
231 }
232
233 // whitespace
234 do {
235 c = get();
236 } while (c == ' ' || c == '\t');
237
238 // version number
239 while (c >= '0' && c <= '9') {
240 version = 10 * version + (c - '0');
241 c = get();
242 }
243 if (version == 0) {
244 versionNotFirst = true;
245 continue;
246 }
247
248 // whitespace
249 while (c == ' ' || c == '\t')
250 c = get();
251
252 // profile
253 const int maxProfileLength = 13; // not including any 0
254 char profileString[maxProfileLength];
255 int profileLength;
256 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
257 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
258 break;
259 profileString[profileLength] = (char)c;
260 c = get();
261 }
262 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
263 versionNotFirst = true;
264 continue;
265 }
266
267 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
268 profile = EEsProfile;
269 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
270 profile = ECoreProfile;
271 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
272 profile = ECompatibilityProfile;
273
274 return versionNotFirst;
275 } while (true);
276 }
277
278 // Fill this in when doing glslang-level scanning, to hand back to the parser.
279 class TParserToken {
280 public:
TParserToken(YYSTYPE & b)281 explicit TParserToken(YYSTYPE& b) : sType(b) { }
282
283 YYSTYPE& sType;
284 protected:
285 TParserToken(TParserToken&);
286 TParserToken& operator=(TParserToken&);
287 };
288
289 } // end namespace glslang
290
291 // This is the function the glslang parser (i.e., bison) calls to get its next token
yylex(YYSTYPE * glslangTokenDesc,glslang::TParseContext & parseContext)292 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
293 {
294 glslang::TParserToken token(*glslangTokenDesc);
295
296 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
297 }
298
299 namespace {
300
301 struct str_eq
302 {
operator ()__anon37b7a2390111::str_eq303 bool operator()(const char* lhs, const char* rhs) const
304 {
305 return strcmp(lhs, rhs) == 0;
306 }
307 };
308
309 struct str_hash
310 {
operator ()__anon37b7a2390111::str_hash311 size_t operator()(const char* str) const
312 {
313 // djb2
314 unsigned long hash = 5381;
315 int c;
316
317 while ((c = *str++) != 0)
318 hash = ((hash << 5) + hash) + c;
319
320 return hash;
321 }
322 };
323
324 // A single global usable by all threads, by all versions, by all languages.
325 // After a single process-level initialization, this is read only and thread safe
326 std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
327 #ifndef GLSLANG_WEB
328 std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
329 #endif
330
331 };
332
333 namespace glslang {
334
fillInKeywordMap()335 void TScanContext::fillInKeywordMap()
336 {
337 if (KeywordMap != nullptr) {
338 // this is really an error, as this should called only once per process
339 // but, the only risk is if two threads called simultaneously
340 return;
341 }
342 KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
343
344 (*KeywordMap)["const"] = CONST;
345 (*KeywordMap)["uniform"] = UNIFORM;
346 (*KeywordMap)["buffer"] = BUFFER;
347 (*KeywordMap)["in"] = IN;
348 (*KeywordMap)["out"] = OUT;
349 (*KeywordMap)["smooth"] = SMOOTH;
350 (*KeywordMap)["flat"] = FLAT;
351 (*KeywordMap)["centroid"] = CENTROID;
352 (*KeywordMap)["invariant"] = INVARIANT;
353 (*KeywordMap)["packed"] = PACKED;
354 (*KeywordMap)["resource"] = RESOURCE;
355 (*KeywordMap)["inout"] = INOUT;
356 (*KeywordMap)["struct"] = STRUCT;
357 (*KeywordMap)["break"] = BREAK;
358 (*KeywordMap)["continue"] = CONTINUE;
359 (*KeywordMap)["do"] = DO;
360 (*KeywordMap)["for"] = FOR;
361 (*KeywordMap)["while"] = WHILE;
362 (*KeywordMap)["switch"] = SWITCH;
363 (*KeywordMap)["case"] = CASE;
364 (*KeywordMap)["default"] = DEFAULT;
365 (*KeywordMap)["if"] = IF;
366 (*KeywordMap)["else"] = ELSE;
367 (*KeywordMap)["discard"] = DISCARD;
368 (*KeywordMap)["return"] = RETURN;
369 (*KeywordMap)["void"] = VOID;
370 (*KeywordMap)["bool"] = BOOL;
371 (*KeywordMap)["float"] = FLOAT;
372 (*KeywordMap)["int"] = INT;
373 (*KeywordMap)["bvec2"] = BVEC2;
374 (*KeywordMap)["bvec3"] = BVEC3;
375 (*KeywordMap)["bvec4"] = BVEC4;
376 (*KeywordMap)["vec2"] = VEC2;
377 (*KeywordMap)["vec3"] = VEC3;
378 (*KeywordMap)["vec4"] = VEC4;
379 (*KeywordMap)["ivec2"] = IVEC2;
380 (*KeywordMap)["ivec3"] = IVEC3;
381 (*KeywordMap)["ivec4"] = IVEC4;
382 (*KeywordMap)["mat2"] = MAT2;
383 (*KeywordMap)["mat3"] = MAT3;
384 (*KeywordMap)["mat4"] = MAT4;
385 (*KeywordMap)["true"] = BOOLCONSTANT;
386 (*KeywordMap)["false"] = BOOLCONSTANT;
387 (*KeywordMap)["layout"] = LAYOUT;
388 (*KeywordMap)["shared"] = SHARED;
389 (*KeywordMap)["highp"] = HIGH_PRECISION;
390 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
391 (*KeywordMap)["lowp"] = LOW_PRECISION;
392 (*KeywordMap)["superp"] = SUPERP;
393 (*KeywordMap)["precision"] = PRECISION;
394 (*KeywordMap)["mat2x2"] = MAT2X2;
395 (*KeywordMap)["mat2x3"] = MAT2X3;
396 (*KeywordMap)["mat2x4"] = MAT2X4;
397 (*KeywordMap)["mat3x2"] = MAT3X2;
398 (*KeywordMap)["mat3x3"] = MAT3X3;
399 (*KeywordMap)["mat3x4"] = MAT3X4;
400 (*KeywordMap)["mat4x2"] = MAT4X2;
401 (*KeywordMap)["mat4x3"] = MAT4X3;
402 (*KeywordMap)["mat4x4"] = MAT4X4;
403 (*KeywordMap)["uint"] = UINT;
404 (*KeywordMap)["uvec2"] = UVEC2;
405 (*KeywordMap)["uvec3"] = UVEC3;
406 (*KeywordMap)["uvec4"] = UVEC4;
407
408 #ifndef GLSLANG_WEB
409 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
410 (*KeywordMap)["demote"] = DEMOTE;
411 (*KeywordMap)["attribute"] = ATTRIBUTE;
412 (*KeywordMap)["varying"] = VARYING;
413 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
414 (*KeywordMap)["coherent"] = COHERENT;
415 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
416 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
417 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
418 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
419 (*KeywordMap)["shadercallcoherent"] = SHADERCALLCOHERENT;
420 (*KeywordMap)["nonprivate"] = NONPRIVATE;
421 (*KeywordMap)["restrict"] = RESTRICT;
422 (*KeywordMap)["readonly"] = READONLY;
423 (*KeywordMap)["writeonly"] = WRITEONLY;
424 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
425 (*KeywordMap)["volatile"] = VOLATILE;
426 (*KeywordMap)["patch"] = PATCH;
427 (*KeywordMap)["sample"] = SAMPLE;
428 (*KeywordMap)["subroutine"] = SUBROUTINE;
429 (*KeywordMap)["dmat2"] = DMAT2;
430 (*KeywordMap)["dmat3"] = DMAT3;
431 (*KeywordMap)["dmat4"] = DMAT4;
432 (*KeywordMap)["dmat2x2"] = DMAT2X2;
433 (*KeywordMap)["dmat2x3"] = DMAT2X3;
434 (*KeywordMap)["dmat2x4"] = DMAT2X4;
435 (*KeywordMap)["dmat3x2"] = DMAT3X2;
436 (*KeywordMap)["dmat3x3"] = DMAT3X3;
437 (*KeywordMap)["dmat3x4"] = DMAT3X4;
438 (*KeywordMap)["dmat4x2"] = DMAT4X2;
439 (*KeywordMap)["dmat4x3"] = DMAT4X3;
440 (*KeywordMap)["dmat4x4"] = DMAT4X4;
441 (*KeywordMap)["image1D"] = IMAGE1D;
442 (*KeywordMap)["iimage1D"] = IIMAGE1D;
443 (*KeywordMap)["uimage1D"] = UIMAGE1D;
444 (*KeywordMap)["image2D"] = IMAGE2D;
445 (*KeywordMap)["iimage2D"] = IIMAGE2D;
446 (*KeywordMap)["uimage2D"] = UIMAGE2D;
447 (*KeywordMap)["image3D"] = IMAGE3D;
448 (*KeywordMap)["iimage3D"] = IIMAGE3D;
449 (*KeywordMap)["uimage3D"] = UIMAGE3D;
450 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
451 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
452 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
453 (*KeywordMap)["imageCube"] = IMAGECUBE;
454 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
455 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
456 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
457 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
458 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
459 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
460 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
461 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
462 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
463 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
464 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
465 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
466 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
467 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
468 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
469 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
470 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
471 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
472 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
473 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
474 (*KeywordMap)["double"] = DOUBLE;
475 (*KeywordMap)["dvec2"] = DVEC2;
476 (*KeywordMap)["dvec3"] = DVEC3;
477 (*KeywordMap)["dvec4"] = DVEC4;
478 (*KeywordMap)["int64_t"] = INT64_T;
479 (*KeywordMap)["uint64_t"] = UINT64_T;
480 (*KeywordMap)["i64vec2"] = I64VEC2;
481 (*KeywordMap)["i64vec3"] = I64VEC3;
482 (*KeywordMap)["i64vec4"] = I64VEC4;
483 (*KeywordMap)["u64vec2"] = U64VEC2;
484 (*KeywordMap)["u64vec3"] = U64VEC3;
485 (*KeywordMap)["u64vec4"] = U64VEC4;
486
487 // GL_EXT_shader_explicit_arithmetic_types
488 (*KeywordMap)["int8_t"] = INT8_T;
489 (*KeywordMap)["i8vec2"] = I8VEC2;
490 (*KeywordMap)["i8vec3"] = I8VEC3;
491 (*KeywordMap)["i8vec4"] = I8VEC4;
492 (*KeywordMap)["uint8_t"] = UINT8_T;
493 (*KeywordMap)["u8vec2"] = U8VEC2;
494 (*KeywordMap)["u8vec3"] = U8VEC3;
495 (*KeywordMap)["u8vec4"] = U8VEC4;
496
497 (*KeywordMap)["int16_t"] = INT16_T;
498 (*KeywordMap)["i16vec2"] = I16VEC2;
499 (*KeywordMap)["i16vec3"] = I16VEC3;
500 (*KeywordMap)["i16vec4"] = I16VEC4;
501 (*KeywordMap)["uint16_t"] = UINT16_T;
502 (*KeywordMap)["u16vec2"] = U16VEC2;
503 (*KeywordMap)["u16vec3"] = U16VEC3;
504 (*KeywordMap)["u16vec4"] = U16VEC4;
505
506 (*KeywordMap)["int32_t"] = INT32_T;
507 (*KeywordMap)["i32vec2"] = I32VEC2;
508 (*KeywordMap)["i32vec3"] = I32VEC3;
509 (*KeywordMap)["i32vec4"] = I32VEC4;
510 (*KeywordMap)["uint32_t"] = UINT32_T;
511 (*KeywordMap)["u32vec2"] = U32VEC2;
512 (*KeywordMap)["u32vec3"] = U32VEC3;
513 (*KeywordMap)["u32vec4"] = U32VEC4;
514
515 (*KeywordMap)["float16_t"] = FLOAT16_T;
516 (*KeywordMap)["f16vec2"] = F16VEC2;
517 (*KeywordMap)["f16vec3"] = F16VEC3;
518 (*KeywordMap)["f16vec4"] = F16VEC4;
519 (*KeywordMap)["f16mat2"] = F16MAT2;
520 (*KeywordMap)["f16mat3"] = F16MAT3;
521 (*KeywordMap)["f16mat4"] = F16MAT4;
522 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
523 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
524 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
525 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
526 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
527 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
528 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
529 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
530 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
531
532 (*KeywordMap)["float32_t"] = FLOAT32_T;
533 (*KeywordMap)["f32vec2"] = F32VEC2;
534 (*KeywordMap)["f32vec3"] = F32VEC3;
535 (*KeywordMap)["f32vec4"] = F32VEC4;
536 (*KeywordMap)["f32mat2"] = F32MAT2;
537 (*KeywordMap)["f32mat3"] = F32MAT3;
538 (*KeywordMap)["f32mat4"] = F32MAT4;
539 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
540 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
541 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
542 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
543 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
544 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
545 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
546 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
547 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
548 (*KeywordMap)["float64_t"] = FLOAT64_T;
549 (*KeywordMap)["f64vec2"] = F64VEC2;
550 (*KeywordMap)["f64vec3"] = F64VEC3;
551 (*KeywordMap)["f64vec4"] = F64VEC4;
552 (*KeywordMap)["f64mat2"] = F64MAT2;
553 (*KeywordMap)["f64mat3"] = F64MAT3;
554 (*KeywordMap)["f64mat4"] = F64MAT4;
555 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
556 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
557 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
558 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
559 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
560 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
561 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
562 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
563 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
564 #endif
565
566 (*KeywordMap)["sampler2D"] = SAMPLER2D;
567 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
568 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
569 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
570 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
571 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
572 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
573 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
574 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
575 (*KeywordMap)["usampler2D"] = USAMPLER2D;
576 (*KeywordMap)["usampler3D"] = USAMPLER3D;
577 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
578 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
579 (*KeywordMap)["sampler3D"] = SAMPLER3D;
580 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
581
582 (*KeywordMap)["texture2D"] = TEXTURE2D;
583 (*KeywordMap)["textureCube"] = TEXTURECUBE;
584 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
585 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
586 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
587 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
588 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
589 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
590 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
591 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
592 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
593 (*KeywordMap)["texture3D"] = TEXTURE3D;
594
595 (*KeywordMap)["sampler"] = SAMPLER;
596 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
597
598 #ifndef GLSLANG_WEB
599 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
600 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
601 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
602 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
603 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
604 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
605 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
606 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
607 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
608 (*KeywordMap)["usampler1D"] = USAMPLER1D;
609 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
610 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
611 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
612 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
613 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
614 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
615 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
616 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
617 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
618 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
619 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
620 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
621 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
622 (*KeywordMap)["sampler1D"] = SAMPLER1D;
623 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
624 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
625 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
626 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
627
628 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
629
630 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
631
632 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
633 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
634 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
635 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
636 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
637 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
638 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
639 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
640 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
641 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
642 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
643 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
644 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
645 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
646 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
647 (*KeywordMap)["texture1D"] = TEXTURE1D;
648 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
649 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
650
651 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
652 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
653 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
654 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
655 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
656 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
657
658 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
659 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
660 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
661 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
662 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
663 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
664 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
665 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
666 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
667 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
668 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
669 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
670 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
671 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
672 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
673 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
674 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
675 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
676
677 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
678 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
679 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
680 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
681 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
682 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
683 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
684 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
685 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
686 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
687 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
688
689 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
690 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
691 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
692 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
693 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
694 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
695 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
696 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
697 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
698 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
699 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
700
701 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
702 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
703 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
704 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
705 (*KeywordMap)["precise"] = PRECISE;
706
707 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
708 (*KeywordMap)["rayPayloadEXT"] = PAYLOADEXT;
709 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
710 (*KeywordMap)["rayPayloadInEXT"] = PAYLOADINEXT;
711 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
712 (*KeywordMap)["hitAttributeEXT"] = HITATTREXT;
713 (*KeywordMap)["callableDataNV"] = CALLDATANV;
714 (*KeywordMap)["callableDataEXT"] = CALLDATAEXT;
715 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
716 (*KeywordMap)["callableDataInEXT"] = CALLDATAINEXT;
717 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
718 (*KeywordMap)["accelerationStructureEXT"] = ACCSTRUCTEXT;
719 (*KeywordMap)["rayQueryEXT"] = RAYQUERYEXT;
720 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
721 (*KeywordMap)["perviewNV"] = PERVIEWNV;
722 (*KeywordMap)["taskNV"] = PERTASKNV;
723
724 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
725 (*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
726 (*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
727
728 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
729
730 ReservedSet->insert("common");
731 ReservedSet->insert("partition");
732 ReservedSet->insert("active");
733 ReservedSet->insert("asm");
734 ReservedSet->insert("class");
735 ReservedSet->insert("union");
736 ReservedSet->insert("enum");
737 ReservedSet->insert("typedef");
738 ReservedSet->insert("template");
739 ReservedSet->insert("this");
740 ReservedSet->insert("goto");
741 ReservedSet->insert("inline");
742 ReservedSet->insert("noinline");
743 ReservedSet->insert("public");
744 ReservedSet->insert("static");
745 ReservedSet->insert("extern");
746 ReservedSet->insert("external");
747 ReservedSet->insert("interface");
748 ReservedSet->insert("long");
749 ReservedSet->insert("short");
750 ReservedSet->insert("half");
751 ReservedSet->insert("fixed");
752 ReservedSet->insert("unsigned");
753 ReservedSet->insert("input");
754 ReservedSet->insert("output");
755 ReservedSet->insert("hvec2");
756 ReservedSet->insert("hvec3");
757 ReservedSet->insert("hvec4");
758 ReservedSet->insert("fvec2");
759 ReservedSet->insert("fvec3");
760 ReservedSet->insert("fvec4");
761 ReservedSet->insert("sampler3DRect");
762 ReservedSet->insert("filter");
763 ReservedSet->insert("sizeof");
764 ReservedSet->insert("cast");
765 ReservedSet->insert("namespace");
766 ReservedSet->insert("using");
767 #endif
768 }
769
deleteKeywordMap()770 void TScanContext::deleteKeywordMap()
771 {
772 delete KeywordMap;
773 KeywordMap = nullptr;
774 #ifndef GLSLANG_WEB
775 delete ReservedSet;
776 ReservedSet = nullptr;
777 #endif
778 }
779
780 // Called by yylex to get the next token.
781 // Returning 0 implies end of input.
tokenize(TPpContext * pp,TParserToken & token)782 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
783 {
784 do {
785 parserToken = &token;
786 TPpToken ppToken;
787 int token = pp->tokenize(ppToken);
788 if (token == EndOfInput)
789 return 0;
790
791 tokenText = ppToken.name;
792 loc = ppToken.loc;
793 parserToken->sType.lex.loc = loc;
794 switch (token) {
795 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
796 case ',': afterType = false; return COMMA;
797 case ':': return COLON;
798 case '=': afterType = false; return EQUAL;
799 case '(': afterType = false; return LEFT_PAREN;
800 case ')': afterType = false; return RIGHT_PAREN;
801 case '.': field = true; return DOT;
802 case '!': return BANG;
803 case '-': return DASH;
804 case '~': return TILDE;
805 case '+': return PLUS;
806 case '*': return STAR;
807 case '/': return SLASH;
808 case '%': return PERCENT;
809 case '<': return LEFT_ANGLE;
810 case '>': return RIGHT_ANGLE;
811 case '|': return VERTICAL_BAR;
812 case '^': return CARET;
813 case '&': return AMPERSAND;
814 case '?': return QUESTION;
815 case '[': return LEFT_BRACKET;
816 case ']': return RIGHT_BRACKET;
817 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
818 case '}': return RIGHT_BRACE;
819 case '\\':
820 parseContext.error(loc, "illegal use of escape character", "\\", "");
821 break;
822
823 case PPAtomAddAssign: return ADD_ASSIGN;
824 case PPAtomSubAssign: return SUB_ASSIGN;
825 case PPAtomMulAssign: return MUL_ASSIGN;
826 case PPAtomDivAssign: return DIV_ASSIGN;
827 case PPAtomModAssign: return MOD_ASSIGN;
828
829 case PpAtomRight: return RIGHT_OP;
830 case PpAtomLeft: return LEFT_OP;
831
832 case PpAtomRightAssign: return RIGHT_ASSIGN;
833 case PpAtomLeftAssign: return LEFT_ASSIGN;
834 case PpAtomAndAssign: return AND_ASSIGN;
835 case PpAtomOrAssign: return OR_ASSIGN;
836 case PpAtomXorAssign: return XOR_ASSIGN;
837
838 case PpAtomAnd: return AND_OP;
839 case PpAtomOr: return OR_OP;
840 case PpAtomXor: return XOR_OP;
841
842 case PpAtomEQ: return EQ_OP;
843 case PpAtomGE: return GE_OP;
844 case PpAtomNE: return NE_OP;
845 case PpAtomLE: return LE_OP;
846
847 case PpAtomDecrement: return DEC_OP;
848 case PpAtomIncrement: return INC_OP;
849
850 case PpAtomColonColon:
851 parseContext.error(loc, "not supported", "::", "");
852 break;
853
854 case PpAtomConstString: parserToken->sType.lex.string = NewPoolTString(tokenText); return STRING_LITERAL;
855 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
856 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
857 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
858 #ifndef GLSLANG_WEB
859 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
860 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
861 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
862 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
863 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
864 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
865 #endif
866 case PpAtomIdentifier:
867 {
868 int token = tokenizeIdentifier();
869 field = false;
870 return token;
871 }
872
873 case EndOfInput: return 0;
874
875 default:
876 char buf[2];
877 buf[0] = (char)token;
878 buf[1] = 0;
879 parseContext.error(loc, "unexpected token", buf, "");
880 break;
881 }
882 } while (true);
883 }
884
tokenizeIdentifier()885 int TScanContext::tokenizeIdentifier()
886 {
887 #ifndef GLSLANG_WEB
888 if (ReservedSet->find(tokenText) != ReservedSet->end())
889 return reservedWord();
890 #endif
891
892 auto it = KeywordMap->find(tokenText);
893 if (it == KeywordMap->end()) {
894 // Should have an identifier of some sort
895 return identifierOrType();
896 }
897 keyword = it->second;
898
899 switch (keyword) {
900 case CONST:
901 case UNIFORM:
902 case IN:
903 case OUT:
904 case INOUT:
905 case BREAK:
906 case CONTINUE:
907 case DO:
908 case FOR:
909 case WHILE:
910 case IF:
911 case ELSE:
912 case DISCARD:
913 case RETURN:
914 case CASE:
915 return keyword;
916
917 case BUFFER:
918 afterBuffer = true;
919 if ((parseContext.isEsProfile() && parseContext.version < 310) ||
920 (!parseContext.isEsProfile() && (parseContext.version < 430 &&
921 !parseContext.extensionTurnedOn(E_GL_ARB_shader_storage_buffer_object))))
922 return identifierOrType();
923 return keyword;
924
925 case STRUCT:
926 afterStruct = true;
927 return keyword;
928
929 case SWITCH:
930 case DEFAULT:
931 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
932 (!parseContext.isEsProfile() && parseContext.version < 130))
933 reservedWord();
934 return keyword;
935
936 case VOID:
937 case BOOL:
938 case FLOAT:
939 case INT:
940 case BVEC2:
941 case BVEC3:
942 case BVEC4:
943 case VEC2:
944 case VEC3:
945 case VEC4:
946 case IVEC2:
947 case IVEC3:
948 case IVEC4:
949 case MAT2:
950 case MAT3:
951 case MAT4:
952 case SAMPLER2D:
953 case SAMPLERCUBE:
954 afterType = true;
955 return keyword;
956
957 case BOOLCONSTANT:
958 if (strcmp("true", tokenText) == 0)
959 parserToken->sType.lex.b = true;
960 else
961 parserToken->sType.lex.b = false;
962 return keyword;
963
964 case SMOOTH:
965 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
966 (!parseContext.isEsProfile() && parseContext.version < 130))
967 return identifierOrType();
968 return keyword;
969 case FLAT:
970 if (parseContext.isEsProfile() && parseContext.version < 300)
971 reservedWord();
972 else if (!parseContext.isEsProfile() && parseContext.version < 130)
973 return identifierOrType();
974 return keyword;
975 case CENTROID:
976 if (parseContext.version < 120)
977 return identifierOrType();
978 return keyword;
979 case INVARIANT:
980 if (!parseContext.isEsProfile() && parseContext.version < 120)
981 return identifierOrType();
982 return keyword;
983 case PACKED:
984 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
985 (!parseContext.isEsProfile() && parseContext.version < 330))
986 return reservedWord();
987 return identifierOrType();
988
989 case RESOURCE:
990 {
991 bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
992 (!parseContext.isEsProfile() && parseContext.version >= 420);
993 return identifierOrReserved(reserved);
994 }
995 case SUPERP:
996 {
997 bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
998 return identifierOrReserved(reserved);
999 }
1000
1001 #ifndef GLSLANG_WEB
1002 case NOPERSPECTIVE:
1003 if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1004 return keyword;
1005 return es30ReservedFromGLSL(130);
1006
1007 case NONUNIFORM:
1008 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
1009 return keyword;
1010 else
1011 return identifierOrType();
1012 case ATTRIBUTE:
1013 case VARYING:
1014 if (parseContext.isEsProfile() && parseContext.version >= 300)
1015 reservedWord();
1016 return keyword;
1017 case PAYLOADNV:
1018 case PAYLOADINNV:
1019 case HITATTRNV:
1020 case CALLDATANV:
1021 case CALLDATAINNV:
1022 case ACCSTRUCTNV:
1023 if (parseContext.symbolTable.atBuiltInLevel() ||
1024 parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
1025 return keyword;
1026 return identifierOrType();
1027 case PAYLOADEXT:
1028 case PAYLOADINEXT:
1029 case HITATTREXT:
1030 case CALLDATAEXT:
1031 case CALLDATAINEXT:
1032 case ACCSTRUCTEXT:
1033 if (parseContext.symbolTable.atBuiltInLevel() ||
1034 parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing) ||
1035 parseContext.extensionTurnedOn(E_GL_EXT_ray_query))
1036 return keyword;
1037 return identifierOrType();
1038 case RAYQUERYEXT:
1039 if (parseContext.symbolTable.atBuiltInLevel() ||
1040 (!parseContext.isEsProfile() && parseContext.version >= 460
1041 && parseContext.extensionTurnedOn(E_GL_EXT_ray_query)))
1042 return keyword;
1043 return identifierOrType();
1044 case ATOMIC_UINT:
1045 if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
1046 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
1047 return keyword;
1048 return es30ReservedFromGLSL(420);
1049
1050 case COHERENT:
1051 case DEVICECOHERENT:
1052 case QUEUEFAMILYCOHERENT:
1053 case WORKGROUPCOHERENT:
1054 case SUBGROUPCOHERENT:
1055 case SHADERCALLCOHERENT:
1056 case NONPRIVATE:
1057 case RESTRICT:
1058 case READONLY:
1059 case WRITEONLY:
1060 if (parseContext.isEsProfile() && parseContext.version >= 310)
1061 return keyword;
1062 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
1063 case VOLATILE:
1064 if (parseContext.isEsProfile() && parseContext.version >= 310)
1065 return keyword;
1066 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
1067 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1068 reservedWord();
1069 return keyword;
1070 case PATCH:
1071 if (parseContext.symbolTable.atBuiltInLevel() ||
1072 (parseContext.isEsProfile() &&
1073 (parseContext.version >= 320 ||
1074 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1075 (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1076 return keyword;
1077
1078 return es30ReservedFromGLSL(400);
1079
1080 case SAMPLE:
1081 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1082 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1083 return keyword;
1084 return es30ReservedFromGLSL(400);
1085
1086 case SUBROUTINE:
1087 return es30ReservedFromGLSL(400);
1088 #endif
1089 case SHARED:
1090 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1091 (!parseContext.isEsProfile() && parseContext.version < 140))
1092 return identifierOrType();
1093 return keyword;
1094 case LAYOUT:
1095 {
1096 const int numLayoutExts = 2;
1097 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1098 E_GL_ARB_explicit_attrib_location };
1099 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1100 (!parseContext.isEsProfile() && parseContext.version < 140 &&
1101 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1102 return identifierOrType();
1103 return keyword;
1104 }
1105
1106 case HIGH_PRECISION:
1107 case MEDIUM_PRECISION:
1108 case LOW_PRECISION:
1109 case PRECISION:
1110 return precisionKeyword();
1111
1112 case MAT2X2:
1113 case MAT2X3:
1114 case MAT2X4:
1115 case MAT3X2:
1116 case MAT3X3:
1117 case MAT3X4:
1118 case MAT4X2:
1119 case MAT4X3:
1120 case MAT4X4:
1121 return matNxM();
1122
1123 #ifndef GLSLANG_WEB
1124 case DMAT2:
1125 case DMAT3:
1126 case DMAT4:
1127 case DMAT2X2:
1128 case DMAT2X3:
1129 case DMAT2X4:
1130 case DMAT3X2:
1131 case DMAT3X3:
1132 case DMAT3X4:
1133 case DMAT4X2:
1134 case DMAT4X3:
1135 case DMAT4X4:
1136 return dMat();
1137
1138 case IMAGE1D:
1139 case IIMAGE1D:
1140 case UIMAGE1D:
1141 case IMAGE1DARRAY:
1142 case IIMAGE1DARRAY:
1143 case UIMAGE1DARRAY:
1144 case IMAGE2DRECT:
1145 case IIMAGE2DRECT:
1146 case UIMAGE2DRECT:
1147 afterType = true;
1148 return firstGenerationImage(false);
1149
1150 case IMAGEBUFFER:
1151 case IIMAGEBUFFER:
1152 case UIMAGEBUFFER:
1153 afterType = true;
1154 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1155 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1156 return keyword;
1157 return firstGenerationImage(false);
1158
1159 case IMAGE2D:
1160 case IIMAGE2D:
1161 case UIMAGE2D:
1162 case IMAGE3D:
1163 case IIMAGE3D:
1164 case UIMAGE3D:
1165 case IMAGECUBE:
1166 case IIMAGECUBE:
1167 case UIMAGECUBE:
1168 case IMAGE2DARRAY:
1169 case IIMAGE2DARRAY:
1170 case UIMAGE2DARRAY:
1171 afterType = true;
1172 return firstGenerationImage(true);
1173
1174 case IMAGECUBEARRAY:
1175 case IIMAGECUBEARRAY:
1176 case UIMAGECUBEARRAY:
1177 afterType = true;
1178 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1179 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1180 return keyword;
1181 return secondGenerationImage();
1182
1183 case IMAGE2DMS:
1184 case IIMAGE2DMS:
1185 case UIMAGE2DMS:
1186 case IMAGE2DMSARRAY:
1187 case IIMAGE2DMSARRAY:
1188 case UIMAGE2DMSARRAY:
1189 afterType = true;
1190 return secondGenerationImage();
1191
1192 case DOUBLE:
1193 case DVEC2:
1194 case DVEC3:
1195 case DVEC4:
1196 afterType = true;
1197 if (parseContext.isEsProfile() || parseContext.version < 150 ||
1198 (!parseContext.symbolTable.atBuiltInLevel() &&
1199 (parseContext.version < 400 && !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) &&
1200 (parseContext.version < 410 && !parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)))))
1201 reservedWord();
1202 return keyword;
1203
1204 case INT64_T:
1205 case UINT64_T:
1206 case I64VEC2:
1207 case I64VEC3:
1208 case I64VEC4:
1209 case U64VEC2:
1210 case U64VEC3:
1211 case U64VEC4:
1212 afterType = true;
1213 if (parseContext.symbolTable.atBuiltInLevel() ||
1214 parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1215 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1216 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
1217 return keyword;
1218 return identifierOrType();
1219
1220 case INT8_T:
1221 case UINT8_T:
1222 case I8VEC2:
1223 case I8VEC3:
1224 case I8VEC4:
1225 case U8VEC2:
1226 case U8VEC3:
1227 case U8VEC4:
1228 afterType = true;
1229 if (parseContext.symbolTable.atBuiltInLevel() ||
1230 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1231 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1232 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
1233 return keyword;
1234 return identifierOrType();
1235
1236 case INT16_T:
1237 case UINT16_T:
1238 case I16VEC2:
1239 case I16VEC3:
1240 case I16VEC4:
1241 case U16VEC2:
1242 case U16VEC3:
1243 case U16VEC4:
1244 afterType = true;
1245 if (parseContext.symbolTable.atBuiltInLevel() ||
1246 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1247 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1248 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1249 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
1250 return keyword;
1251 return identifierOrType();
1252 case INT32_T:
1253 case UINT32_T:
1254 case I32VEC2:
1255 case I32VEC3:
1256 case I32VEC4:
1257 case U32VEC2:
1258 case U32VEC3:
1259 case U32VEC4:
1260 afterType = true;
1261 if (parseContext.symbolTable.atBuiltInLevel() ||
1262 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1263 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
1264 return keyword;
1265 return identifierOrType();
1266 case FLOAT32_T:
1267 case F32VEC2:
1268 case F32VEC3:
1269 case F32VEC4:
1270 case F32MAT2:
1271 case F32MAT3:
1272 case F32MAT4:
1273 case F32MAT2X2:
1274 case F32MAT2X3:
1275 case F32MAT2X4:
1276 case F32MAT3X2:
1277 case F32MAT3X3:
1278 case F32MAT3X4:
1279 case F32MAT4X2:
1280 case F32MAT4X3:
1281 case F32MAT4X4:
1282 afterType = true;
1283 if (parseContext.symbolTable.atBuiltInLevel() ||
1284 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1285 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
1286 return keyword;
1287 return identifierOrType();
1288
1289 case FLOAT64_T:
1290 case F64VEC2:
1291 case F64VEC3:
1292 case F64VEC4:
1293 case F64MAT2:
1294 case F64MAT3:
1295 case F64MAT4:
1296 case F64MAT2X2:
1297 case F64MAT2X3:
1298 case F64MAT2X4:
1299 case F64MAT3X2:
1300 case F64MAT3X3:
1301 case F64MAT3X4:
1302 case F64MAT4X2:
1303 case F64MAT4X3:
1304 case F64MAT4X4:
1305 afterType = true;
1306 if (parseContext.symbolTable.atBuiltInLevel() ||
1307 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1308 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
1309 return keyword;
1310 return identifierOrType();
1311
1312 case FLOAT16_T:
1313 case F16VEC2:
1314 case F16VEC3:
1315 case F16VEC4:
1316 afterType = true;
1317 if (parseContext.symbolTable.atBuiltInLevel() ||
1318 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1319 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1320 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1321 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1322 return keyword;
1323
1324 return identifierOrType();
1325
1326 case F16MAT2:
1327 case F16MAT3:
1328 case F16MAT4:
1329 case F16MAT2X2:
1330 case F16MAT2X3:
1331 case F16MAT2X4:
1332 case F16MAT3X2:
1333 case F16MAT3X3:
1334 case F16MAT3X4:
1335 case F16MAT4X2:
1336 case F16MAT4X3:
1337 case F16MAT4X4:
1338 afterType = true;
1339 if (parseContext.symbolTable.atBuiltInLevel() ||
1340 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1341 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1342 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1343 return keyword;
1344
1345 return identifierOrType();
1346
1347 case SAMPLERCUBEARRAY:
1348 case SAMPLERCUBEARRAYSHADOW:
1349 case ISAMPLERCUBEARRAY:
1350 case USAMPLERCUBEARRAY:
1351 afterType = true;
1352 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1353 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1354 return keyword;
1355 if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1356 reservedWord();
1357 return keyword;
1358
1359 case TEXTURECUBEARRAY:
1360 case ITEXTURECUBEARRAY:
1361 case UTEXTURECUBEARRAY:
1362 if (parseContext.spvVersion.vulkan > 0)
1363 return keyword;
1364 else
1365 return identifierOrType();
1366 #endif
1367
1368 case UINT:
1369 case UVEC2:
1370 case UVEC3:
1371 case UVEC4:
1372 case SAMPLERCUBESHADOW:
1373 case SAMPLER2DARRAY:
1374 case SAMPLER2DARRAYSHADOW:
1375 case ISAMPLER2D:
1376 case ISAMPLER3D:
1377 case ISAMPLERCUBE:
1378 case ISAMPLER2DARRAY:
1379 case USAMPLER2D:
1380 case USAMPLER3D:
1381 case USAMPLERCUBE:
1382 case USAMPLER2DARRAY:
1383 afterType = true;
1384 return nonreservedKeyword(300, 130);
1385
1386 case SAMPLER3D:
1387 afterType = true;
1388 if (parseContext.isEsProfile() && parseContext.version < 300) {
1389 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1390 reservedWord();
1391 }
1392 return keyword;
1393
1394 case SAMPLER2DSHADOW:
1395 afterType = true;
1396 if (parseContext.isEsProfile() && parseContext.version < 300) {
1397 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1398 reservedWord();
1399 }
1400 return keyword;
1401
1402 case TEXTURE2D:
1403 case TEXTURECUBE:
1404 case TEXTURE2DARRAY:
1405 case ITEXTURE2D:
1406 case ITEXTURE3D:
1407 case ITEXTURECUBE:
1408 case ITEXTURE2DARRAY:
1409 case UTEXTURE2D:
1410 case UTEXTURE3D:
1411 case UTEXTURECUBE:
1412 case UTEXTURE2DARRAY:
1413 case TEXTURE3D:
1414 case SAMPLER:
1415 case SAMPLERSHADOW:
1416 if (parseContext.spvVersion.vulkan > 0)
1417 return keyword;
1418 else
1419 return identifierOrType();
1420
1421 #ifndef GLSLANG_WEB
1422 case ISAMPLER1D:
1423 case ISAMPLER1DARRAY:
1424 case SAMPLER1DARRAYSHADOW:
1425 case USAMPLER1D:
1426 case USAMPLER1DARRAY:
1427 afterType = true;
1428 return es30ReservedFromGLSL(130);
1429 case ISAMPLER2DRECT:
1430 case USAMPLER2DRECT:
1431 afterType = true;
1432 return es30ReservedFromGLSL(140);
1433
1434 case SAMPLERBUFFER:
1435 afterType = true;
1436 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1437 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1438 return keyword;
1439 return es30ReservedFromGLSL(130);
1440
1441 case ISAMPLERBUFFER:
1442 case USAMPLERBUFFER:
1443 afterType = true;
1444 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1445 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1446 return keyword;
1447 return es30ReservedFromGLSL(140);
1448
1449 case SAMPLER2DMS:
1450 case ISAMPLER2DMS:
1451 case USAMPLER2DMS:
1452 afterType = true;
1453 if (parseContext.isEsProfile() && parseContext.version >= 310)
1454 return keyword;
1455 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1456 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1457 return keyword;
1458 return es30ReservedFromGLSL(150);
1459
1460 case SAMPLER2DMSARRAY:
1461 case ISAMPLER2DMSARRAY:
1462 case USAMPLER2DMSARRAY:
1463 afterType = true;
1464 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1465 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1466 return keyword;
1467 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1468 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1469 return keyword;
1470 return es30ReservedFromGLSL(150);
1471
1472 case SAMPLER1D:
1473 case SAMPLER1DSHADOW:
1474 afterType = true;
1475 if (parseContext.isEsProfile())
1476 reservedWord();
1477 return keyword;
1478
1479 case SAMPLER2DRECT:
1480 case SAMPLER2DRECTSHADOW:
1481 afterType = true;
1482 if (parseContext.isEsProfile())
1483 reservedWord();
1484 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1485 if (parseContext.relaxedErrors())
1486 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1487 else
1488 reservedWord();
1489 }
1490 return keyword;
1491
1492 case SAMPLER1DARRAY:
1493 afterType = true;
1494 if (parseContext.isEsProfile() && parseContext.version == 300)
1495 reservedWord();
1496 else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1497 (!parseContext.isEsProfile() && parseContext.version < 130))
1498 return identifierOrType();
1499 return keyword;
1500
1501 case SAMPLEREXTERNALOES:
1502 afterType = true;
1503 if (parseContext.symbolTable.atBuiltInLevel() ||
1504 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1505 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1506 return keyword;
1507 return identifierOrType();
1508
1509 case SAMPLEREXTERNAL2DY2YEXT:
1510 afterType = true;
1511 if (parseContext.symbolTable.atBuiltInLevel() ||
1512 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1513 return keyword;
1514 return identifierOrType();
1515
1516 case ITEXTURE1DARRAY:
1517 case UTEXTURE1D:
1518 case ITEXTURE1D:
1519 case UTEXTURE1DARRAY:
1520 case TEXTUREBUFFER:
1521 case ITEXTURE2DRECT:
1522 case UTEXTURE2DRECT:
1523 case ITEXTUREBUFFER:
1524 case UTEXTUREBUFFER:
1525 case TEXTURE2DMS:
1526 case ITEXTURE2DMS:
1527 case UTEXTURE2DMS:
1528 case TEXTURE2DMSARRAY:
1529 case ITEXTURE2DMSARRAY:
1530 case UTEXTURE2DMSARRAY:
1531 case TEXTURE1D:
1532 case TEXTURE2DRECT:
1533 case TEXTURE1DARRAY:
1534 if (parseContext.spvVersion.vulkan > 0)
1535 return keyword;
1536 else
1537 return identifierOrType();
1538
1539 case SUBPASSINPUT:
1540 case SUBPASSINPUTMS:
1541 case ISUBPASSINPUT:
1542 case ISUBPASSINPUTMS:
1543 case USUBPASSINPUT:
1544 case USUBPASSINPUTMS:
1545 if (parseContext.spvVersion.vulkan > 0)
1546 return keyword;
1547 else
1548 return identifierOrType();
1549
1550 case F16SAMPLER1D:
1551 case F16SAMPLER2D:
1552 case F16SAMPLER3D:
1553 case F16SAMPLER2DRECT:
1554 case F16SAMPLERCUBE:
1555 case F16SAMPLER1DARRAY:
1556 case F16SAMPLER2DARRAY:
1557 case F16SAMPLERCUBEARRAY:
1558 case F16SAMPLERBUFFER:
1559 case F16SAMPLER2DMS:
1560 case F16SAMPLER2DMSARRAY:
1561 case F16SAMPLER1DSHADOW:
1562 case F16SAMPLER2DSHADOW:
1563 case F16SAMPLER1DARRAYSHADOW:
1564 case F16SAMPLER2DARRAYSHADOW:
1565 case F16SAMPLER2DRECTSHADOW:
1566 case F16SAMPLERCUBESHADOW:
1567 case F16SAMPLERCUBEARRAYSHADOW:
1568
1569 case F16IMAGE1D:
1570 case F16IMAGE2D:
1571 case F16IMAGE3D:
1572 case F16IMAGE2DRECT:
1573 case F16IMAGECUBE:
1574 case F16IMAGE1DARRAY:
1575 case F16IMAGE2DARRAY:
1576 case F16IMAGECUBEARRAY:
1577 case F16IMAGEBUFFER:
1578 case F16IMAGE2DMS:
1579 case F16IMAGE2DMSARRAY:
1580
1581 case F16TEXTURE1D:
1582 case F16TEXTURE2D:
1583 case F16TEXTURE3D:
1584 case F16TEXTURE2DRECT:
1585 case F16TEXTURECUBE:
1586 case F16TEXTURE1DARRAY:
1587 case F16TEXTURE2DARRAY:
1588 case F16TEXTURECUBEARRAY:
1589 case F16TEXTUREBUFFER:
1590 case F16TEXTURE2DMS:
1591 case F16TEXTURE2DMSARRAY:
1592
1593 case F16SUBPASSINPUT:
1594 case F16SUBPASSINPUTMS:
1595 afterType = true;
1596 if (parseContext.symbolTable.atBuiltInLevel() ||
1597 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
1598 return keyword;
1599 return identifierOrType();
1600
1601 case EXPLICITINTERPAMD:
1602 if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1603 return keyword;
1604 return identifierOrType();
1605
1606 case PERVERTEXNV:
1607 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1608 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1609 return keyword;
1610 return identifierOrType();
1611
1612 case PRECISE:
1613 if ((parseContext.isEsProfile() &&
1614 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1615 (!parseContext.isEsProfile() && parseContext.version >= 400))
1616 return keyword;
1617 if (parseContext.isEsProfile() && parseContext.version == 310) {
1618 reservedWord();
1619 return keyword;
1620 }
1621 return identifierOrType();
1622
1623 case PERPRIMITIVENV:
1624 case PERVIEWNV:
1625 case PERTASKNV:
1626 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1627 (parseContext.isEsProfile() && parseContext.version >= 320) ||
1628 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1629 return keyword;
1630 return identifierOrType();
1631
1632 case FCOOPMATNV:
1633 afterType = true;
1634 if (parseContext.symbolTable.atBuiltInLevel() ||
1635 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1636 return keyword;
1637 return identifierOrType();
1638
1639 case UCOOPMATNV:
1640 case ICOOPMATNV:
1641 afterType = true;
1642 if (parseContext.symbolTable.atBuiltInLevel() ||
1643 parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
1644 return keyword;
1645 return identifierOrType();
1646
1647 case DEMOTE:
1648 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1649 return keyword;
1650 else
1651 return identifierOrType();
1652 #endif
1653
1654 default:
1655 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1656 return 0;
1657 }
1658 }
1659
identifierOrType()1660 int TScanContext::identifierOrType()
1661 {
1662 parserToken->sType.lex.string = NewPoolTString(tokenText);
1663 if (field)
1664 return IDENTIFIER;
1665
1666 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1667 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1668 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1669 if (variable->isUserType() &&
1670 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1671 !(variable->getType().isReference() && afterBuffer)) {
1672 afterType = true;
1673
1674 return TYPE_NAME;
1675 }
1676 }
1677 }
1678
1679 return IDENTIFIER;
1680 }
1681
1682 // Give an error for use of a reserved symbol.
1683 // However, allow built-in declarations to use reserved words, to allow
1684 // extension support before the extension is enabled.
reservedWord()1685 int TScanContext::reservedWord()
1686 {
1687 if (! parseContext.symbolTable.atBuiltInLevel())
1688 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1689
1690 return 0;
1691 }
1692
identifierOrReserved(bool reserved)1693 int TScanContext::identifierOrReserved(bool reserved)
1694 {
1695 if (reserved) {
1696 reservedWord();
1697
1698 return 0;
1699 }
1700
1701 if (parseContext.isForwardCompatible())
1702 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1703
1704 return identifierOrType();
1705 }
1706
1707 // For keywords that suddenly showed up on non-ES (not previously reserved)
1708 // but then got reserved by ES 3.0.
es30ReservedFromGLSL(int version)1709 int TScanContext::es30ReservedFromGLSL(int version)
1710 {
1711 if (parseContext.symbolTable.atBuiltInLevel())
1712 return keyword;
1713
1714 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1715 (!parseContext.isEsProfile() && parseContext.version < version)) {
1716 if (parseContext.isForwardCompatible())
1717 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1718
1719 return identifierOrType();
1720 } else if (parseContext.isEsProfile() && parseContext.version >= 300)
1721 reservedWord();
1722
1723 return keyword;
1724 }
1725
1726 // For a keyword that was never reserved, until it suddenly
1727 // showed up, both in an es version and a non-ES version.
nonreservedKeyword(int esVersion,int nonEsVersion)1728 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1729 {
1730 if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
1731 (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
1732 if (parseContext.isForwardCompatible())
1733 parseContext.warn(loc, "using future keyword", tokenText, "");
1734
1735 return identifierOrType();
1736 }
1737
1738 return keyword;
1739 }
1740
precisionKeyword()1741 int TScanContext::precisionKeyword()
1742 {
1743 if (parseContext.isEsProfile() || parseContext.version >= 130)
1744 return keyword;
1745
1746 if (parseContext.isForwardCompatible())
1747 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1748
1749 return identifierOrType();
1750 }
1751
matNxM()1752 int TScanContext::matNxM()
1753 {
1754 afterType = true;
1755
1756 if (parseContext.version > 110)
1757 return keyword;
1758
1759 if (parseContext.isForwardCompatible())
1760 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1761
1762 return identifierOrType();
1763 }
1764
dMat()1765 int TScanContext::dMat()
1766 {
1767 afterType = true;
1768
1769 if (parseContext.isEsProfile() && parseContext.version >= 300) {
1770 reservedWord();
1771
1772 return keyword;
1773 }
1774
1775 if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
1776 parseContext.symbolTable.atBuiltInLevel() ||
1777 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)) ||
1778 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)
1779 && parseContext.language == EShLangVertex)))
1780 return keyword;
1781
1782 if (parseContext.isForwardCompatible())
1783 parseContext.warn(loc, "using future type keyword", tokenText, "");
1784
1785 return identifierOrType();
1786 }
1787
firstGenerationImage(bool inEs310)1788 int TScanContext::firstGenerationImage(bool inEs310)
1789 {
1790 if (parseContext.symbolTable.atBuiltInLevel() ||
1791 (!parseContext.isEsProfile() && (parseContext.version >= 420 ||
1792 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1793 (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
1794 return keyword;
1795
1796 if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
1797 (!parseContext.isEsProfile() && parseContext.version >= 130)) {
1798 reservedWord();
1799
1800 return keyword;
1801 }
1802
1803 if (parseContext.isForwardCompatible())
1804 parseContext.warn(loc, "using future type keyword", tokenText, "");
1805
1806 return identifierOrType();
1807 }
1808
secondGenerationImage()1809 int TScanContext::secondGenerationImage()
1810 {
1811 if (parseContext.isEsProfile() && parseContext.version >= 310) {
1812 reservedWord();
1813 return keyword;
1814 }
1815
1816 if (parseContext.symbolTable.atBuiltInLevel() ||
1817 (!parseContext.isEsProfile() &&
1818 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1819 return keyword;
1820
1821 if (parseContext.isForwardCompatible())
1822 parseContext.warn(loc, "using future type keyword", tokenText, "");
1823
1824 return identifierOrType();
1825 }
1826
1827 } // end namespace glslang
1828