2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials provided
18 // with the distribution.
20 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
21 // contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 // POSSIBILITY OF SUCH DAMAGE.
39 // GLSL scanning, leveraging the scanning done by the preprocessor.
43 #include <unordered_map>
44 #include <unordered_set>
46 #include "../Include/Types.h"
47 #include "SymbolTable.h"
48 #include "ParseHelper.h"
49 #include "attribute.h"
50 #include "glslang_tab.cpp.h"
51 #include "ScanContext.h"
54 // preprocessor includes
55 #include "preprocessor/PpContext.h"
56 #include "preprocessor/PpTokens.h"
58 // Required to avoid missing prototype warnings for some compilers
59 int yylex(YYSTYPE*, glslang::TParseContext&);
63 // read past any white space
64 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
66 int c = peek(); // don't accidentally consume anything other than whitespace
67 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
68 if (c == '\r' || c == '\n')
69 foundNonSpaceTab = true;
75 // return true if a comment was actually consumed
76 bool TInputScanner::consumeComment()
81 get(); // consume the '/'
85 // a '//' style comment
86 get(); // consume the second '/'
89 while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
92 if (c == EndOfInput || c == '\r' || c == '\n') {
93 while (c == '\r' || c == '\n')
96 // we reached the end of the comment
99 // it's a '\', so we need to keep going, after skipping what's escaped
101 // read the skipped character
104 // if it's a two-character newline, skip both characters
105 if (c == '\r' && peek() == '\n')
111 // put back the last non-comment character
116 } else if (c == '*') {
118 // a '/*' style comment
119 get(); // consume the '*'
122 while (c != EndOfInput && c != '*')
127 break; // end of comment
128 // not end of comment
129 } else // end of input
135 // it's not a comment, put the '/' back
142 // skip whitespace, then skip a comment, rinse, repeat
143 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
146 consumeWhiteSpace(foundNonSpaceTab);
148 // if not starting a comment now, then done
150 if (c != '/' || c == EndOfInput)
153 // skip potential comment
154 foundNonSpaceTab = true;
155 if (! consumeComment())
161 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
162 // or no #version was found; otherwise, returns false. There is no error case, it always
163 // succeeds, but will leave version == 0 if no #version was found.
165 // Sets notFirstToken based on whether tokens (beyond white space and comments)
166 // appeared before the #version.
168 // N.B. does not attempt to leave input in any particular known state. The assumption
169 // is that scanning will start anew, following the rules for the chosen version/profile,
170 // and with a corresponding parsing context.
172 bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
174 // This function doesn't have to get all the semantics correct,
175 // just find the #version if there is a correct one present.
176 // The preprocessor will have the responsibility of getting all the semantics right.
178 bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
179 notFirstToken = false; // means not first WRT to real tokens
180 version = 0; // means not found
181 profile = ENoProfile;
183 bool foundNonSpaceTab = false;
184 bool lookingInMiddle = false;
187 if (lookingInMiddle) {
188 notFirstToken = true;
189 // make forward progress by finishing off the current line plus extra new lines
190 if (peek() == '\n' || peek() == '\r') {
191 while (peek() == '\n' || peek() == '\r')
196 } while (c != EndOfInput && c != '\n' && c != '\r');
197 while (peek() == '\n' || peek() == '\r')
199 if (peek() == EndOfInput)
202 lookingInMiddle = true;
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;
212 versionNotFirst = true;
219 } while (c == ' ' || c == '\t');
229 versionNotFirst = true;
236 } while (c == ' ' || c == '\t');
239 while (c >= '0' && c <= '9') {
240 version = 10 * version + (c - '0');
244 versionNotFirst = true;
249 while (c == ' ' || c == '\t')
253 const int maxProfileLength = 13; // not including any 0
254 char profileString[maxProfileLength];
256 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
257 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
259 profileString[profileLength] = (char)c;
262 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
263 versionNotFirst = true;
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;
274 return versionNotFirst;
278 // Fill this in when doing glslang-level scanning, to hand back to the parser.
281 explicit TParserToken(YYSTYPE& b) : sType(b) { }
285 TParserToken(TParserToken&);
286 TParserToken& operator=(TParserToken&);
289 } // end namespace glslang
291 // This is the function the glslang parser (i.e., bison) calls to get its next token
292 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
294 glslang::TParserToken token(*glslangTokenDesc);
296 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
303 bool operator()(const char* lhs, const char* rhs) const
305 return strcmp(lhs, rhs) == 0;
311 size_t operator()(const char* str) const
314 unsigned long hash = 5381;
317 while ((c = *str++) != 0)
318 hash = ((hash << 5) + hash) + c;
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 std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
333 void TScanContext::fillInKeywordMap()
335 if (KeywordMap != nullptr) {
336 // this is really an error, as this should called only once per process
337 // but, the only risk is if two threads called simultaneously
340 KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
342 (*KeywordMap)["const"] = CONST;
343 (*KeywordMap)["uniform"] = UNIFORM;
344 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
345 (*KeywordMap)["in"] = IN;
346 (*KeywordMap)["out"] = OUT;
347 (*KeywordMap)["inout"] = INOUT;
348 (*KeywordMap)["struct"] = STRUCT;
349 (*KeywordMap)["break"] = BREAK;
350 (*KeywordMap)["continue"] = CONTINUE;
351 (*KeywordMap)["do"] = DO;
352 (*KeywordMap)["for"] = FOR;
353 (*KeywordMap)["while"] = WHILE;
354 (*KeywordMap)["switch"] = SWITCH;
355 (*KeywordMap)["case"] = CASE;
356 (*KeywordMap)["default"] = DEFAULT;
357 (*KeywordMap)["if"] = IF;
358 (*KeywordMap)["else"] = ELSE;
359 (*KeywordMap)["discard"] = DISCARD;
360 (*KeywordMap)["return"] = RETURN;
361 (*KeywordMap)["void"] = VOID;
362 (*KeywordMap)["bool"] = BOOL;
363 (*KeywordMap)["float"] = FLOAT;
364 (*KeywordMap)["int"] = INT;
365 (*KeywordMap)["bvec2"] = BVEC2;
366 (*KeywordMap)["bvec3"] = BVEC3;
367 (*KeywordMap)["bvec4"] = BVEC4;
368 (*KeywordMap)["vec2"] = VEC2;
369 (*KeywordMap)["vec3"] = VEC3;
370 (*KeywordMap)["vec4"] = VEC4;
371 (*KeywordMap)["ivec2"] = IVEC2;
372 (*KeywordMap)["ivec3"] = IVEC3;
373 (*KeywordMap)["ivec4"] = IVEC4;
374 (*KeywordMap)["mat2"] = MAT2;
375 (*KeywordMap)["mat3"] = MAT3;
376 (*KeywordMap)["mat4"] = MAT4;
377 (*KeywordMap)["true"] = BOOLCONSTANT;
378 (*KeywordMap)["false"] = BOOLCONSTANT;
379 (*KeywordMap)["attribute"] = ATTRIBUTE;
380 (*KeywordMap)["varying"] = VARYING;
381 (*KeywordMap)["buffer"] = BUFFER;
382 (*KeywordMap)["coherent"] = COHERENT;
383 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
384 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
385 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
386 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
387 (*KeywordMap)["nonprivate"] = NONPRIVATE;
388 (*KeywordMap)["restrict"] = RESTRICT;
389 (*KeywordMap)["readonly"] = READONLY;
390 (*KeywordMap)["writeonly"] = WRITEONLY;
391 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
392 (*KeywordMap)["volatile"] = VOLATILE;
393 (*KeywordMap)["layout"] = LAYOUT;
394 (*KeywordMap)["shared"] = SHARED;
395 (*KeywordMap)["patch"] = PATCH;
396 (*KeywordMap)["sample"] = SAMPLE;
397 (*KeywordMap)["subroutine"] = SUBROUTINE;
398 (*KeywordMap)["highp"] = HIGH_PRECISION;
399 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
400 (*KeywordMap)["lowp"] = LOW_PRECISION;
401 (*KeywordMap)["precision"] = PRECISION;
402 (*KeywordMap)["mat2x2"] = MAT2X2;
403 (*KeywordMap)["mat2x3"] = MAT2X3;
404 (*KeywordMap)["mat2x4"] = MAT2X4;
405 (*KeywordMap)["mat3x2"] = MAT3X2;
406 (*KeywordMap)["mat3x3"] = MAT3X3;
407 (*KeywordMap)["mat3x4"] = MAT3X4;
408 (*KeywordMap)["mat4x2"] = MAT4X2;
409 (*KeywordMap)["mat4x3"] = MAT4X3;
410 (*KeywordMap)["mat4x4"] = MAT4X4;
411 (*KeywordMap)["dmat2"] = DMAT2;
412 (*KeywordMap)["dmat3"] = DMAT3;
413 (*KeywordMap)["dmat4"] = DMAT4;
414 (*KeywordMap)["dmat2x2"] = DMAT2X2;
415 (*KeywordMap)["dmat2x3"] = DMAT2X3;
416 (*KeywordMap)["dmat2x4"] = DMAT2X4;
417 (*KeywordMap)["dmat3x2"] = DMAT3X2;
418 (*KeywordMap)["dmat3x3"] = DMAT3X3;
419 (*KeywordMap)["dmat3x4"] = DMAT3X4;
420 (*KeywordMap)["dmat4x2"] = DMAT4X2;
421 (*KeywordMap)["dmat4x3"] = DMAT4X3;
422 (*KeywordMap)["dmat4x4"] = DMAT4X4;
423 (*KeywordMap)["image1D"] = IMAGE1D;
424 (*KeywordMap)["iimage1D"] = IIMAGE1D;
425 (*KeywordMap)["uimage1D"] = UIMAGE1D;
426 (*KeywordMap)["image2D"] = IMAGE2D;
427 (*KeywordMap)["iimage2D"] = IIMAGE2D;
428 (*KeywordMap)["uimage2D"] = UIMAGE2D;
429 (*KeywordMap)["image3D"] = IMAGE3D;
430 (*KeywordMap)["iimage3D"] = IIMAGE3D;
431 (*KeywordMap)["uimage3D"] = UIMAGE3D;
432 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
433 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
434 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
435 (*KeywordMap)["imageCube"] = IMAGECUBE;
436 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
437 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
438 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
439 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
440 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
441 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
442 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
443 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
444 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
445 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
446 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
447 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
448 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
449 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
450 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
451 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
452 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
453 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
454 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
455 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
456 (*KeywordMap)["double"] = DOUBLE;
457 (*KeywordMap)["dvec2"] = DVEC2;
458 (*KeywordMap)["dvec3"] = DVEC3;
459 (*KeywordMap)["dvec4"] = DVEC4;
460 (*KeywordMap)["uint"] = UINT;
461 (*KeywordMap)["uvec2"] = UVEC2;
462 (*KeywordMap)["uvec3"] = UVEC3;
463 (*KeywordMap)["uvec4"] = UVEC4;
465 (*KeywordMap)["int64_t"] = INT64_T;
466 (*KeywordMap)["uint64_t"] = UINT64_T;
467 (*KeywordMap)["i64vec2"] = I64VEC2;
468 (*KeywordMap)["i64vec3"] = I64VEC3;
469 (*KeywordMap)["i64vec4"] = I64VEC4;
470 (*KeywordMap)["u64vec2"] = U64VEC2;
471 (*KeywordMap)["u64vec3"] = U64VEC3;
472 (*KeywordMap)["u64vec4"] = U64VEC4;
474 // GL_EXT_shader_explicit_arithmetic_types
475 (*KeywordMap)["int8_t"] = INT8_T;
476 (*KeywordMap)["i8vec2"] = I8VEC2;
477 (*KeywordMap)["i8vec3"] = I8VEC3;
478 (*KeywordMap)["i8vec4"] = I8VEC4;
479 (*KeywordMap)["uint8_t"] = UINT8_T;
480 (*KeywordMap)["u8vec2"] = U8VEC2;
481 (*KeywordMap)["u8vec3"] = U8VEC3;
482 (*KeywordMap)["u8vec4"] = U8VEC4;
484 (*KeywordMap)["int16_t"] = INT16_T;
485 (*KeywordMap)["i16vec2"] = I16VEC2;
486 (*KeywordMap)["i16vec3"] = I16VEC3;
487 (*KeywordMap)["i16vec4"] = I16VEC4;
488 (*KeywordMap)["uint16_t"] = UINT16_T;
489 (*KeywordMap)["u16vec2"] = U16VEC2;
490 (*KeywordMap)["u16vec3"] = U16VEC3;
491 (*KeywordMap)["u16vec4"] = U16VEC4;
493 (*KeywordMap)["int32_t"] = INT32_T;
494 (*KeywordMap)["i32vec2"] = I32VEC2;
495 (*KeywordMap)["i32vec3"] = I32VEC3;
496 (*KeywordMap)["i32vec4"] = I32VEC4;
497 (*KeywordMap)["uint32_t"] = UINT32_T;
498 (*KeywordMap)["u32vec2"] = U32VEC2;
499 (*KeywordMap)["u32vec3"] = U32VEC3;
500 (*KeywordMap)["u32vec4"] = U32VEC4;
502 (*KeywordMap)["float16_t"] = FLOAT16_T;
503 (*KeywordMap)["f16vec2"] = F16VEC2;
504 (*KeywordMap)["f16vec3"] = F16VEC3;
505 (*KeywordMap)["f16vec4"] = F16VEC4;
506 (*KeywordMap)["f16mat2"] = F16MAT2;
507 (*KeywordMap)["f16mat3"] = F16MAT3;
508 (*KeywordMap)["f16mat4"] = F16MAT4;
509 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
510 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
511 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
512 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
513 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
514 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
515 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
516 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
517 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
519 (*KeywordMap)["float32_t"] = FLOAT32_T;
520 (*KeywordMap)["f32vec2"] = F32VEC2;
521 (*KeywordMap)["f32vec3"] = F32VEC3;
522 (*KeywordMap)["f32vec4"] = F32VEC4;
523 (*KeywordMap)["f32mat2"] = F32MAT2;
524 (*KeywordMap)["f32mat3"] = F32MAT3;
525 (*KeywordMap)["f32mat4"] = F32MAT4;
526 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
527 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
528 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
529 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
530 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
531 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
532 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
533 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
534 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
535 (*KeywordMap)["float64_t"] = FLOAT64_T;
536 (*KeywordMap)["f64vec2"] = F64VEC2;
537 (*KeywordMap)["f64vec3"] = F64VEC3;
538 (*KeywordMap)["f64vec4"] = F64VEC4;
539 (*KeywordMap)["f64mat2"] = F64MAT2;
540 (*KeywordMap)["f64mat3"] = F64MAT3;
541 (*KeywordMap)["f64mat4"] = F64MAT4;
542 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
543 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
544 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
545 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
546 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
547 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
548 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
549 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
550 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
552 (*KeywordMap)["sampler2D"] = SAMPLER2D;
553 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
554 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
555 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
556 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
557 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
558 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
559 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
560 (*KeywordMap)["usampler1D"] = USAMPLER1D;
561 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
562 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
563 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
564 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
565 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
566 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
567 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
568 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
569 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
570 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
571 (*KeywordMap)["usampler2D"] = USAMPLER2D;
572 (*KeywordMap)["usampler3D"] = USAMPLER3D;
573 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
574 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
575 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
576 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
577 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
578 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
579 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
580 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
581 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
582 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
583 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
584 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
585 (*KeywordMap)["sampler1D"] = SAMPLER1D;
586 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
587 (*KeywordMap)["sampler3D"] = SAMPLER3D;
588 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
589 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
590 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
591 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
593 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
595 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
597 (*KeywordMap)["sampler"] = SAMPLER;
598 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
600 (*KeywordMap)["texture2D"] = TEXTURE2D;
601 (*KeywordMap)["textureCube"] = TEXTURECUBE;
602 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
603 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
604 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
605 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
606 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
607 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
608 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
609 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
610 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
611 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
612 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
613 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
614 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
615 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
616 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
617 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
618 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
619 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
620 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
621 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
622 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
623 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
624 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
625 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
626 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
627 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
628 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
629 (*KeywordMap)["texture1D"] = TEXTURE1D;
630 (*KeywordMap)["texture3D"] = TEXTURE3D;
631 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
632 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
634 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
635 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
636 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
637 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
638 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
639 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
641 #ifdef AMD_EXTENSIONS
642 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
643 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
644 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
645 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
646 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
647 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
648 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
649 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
650 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
651 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
652 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
653 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
654 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
655 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
656 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
657 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
658 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
659 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
661 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
662 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
663 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
664 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
665 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
666 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
667 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
668 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
669 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
670 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
671 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
673 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
674 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
675 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
676 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
677 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
678 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
679 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
680 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
681 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
682 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
683 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
685 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
686 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
689 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
690 (*KeywordMap)["smooth"] = SMOOTH;
691 (*KeywordMap)["flat"] = FLAT;
692 #ifdef AMD_EXTENSIONS
693 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
695 (*KeywordMap)["centroid"] = CENTROID;
697 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
699 (*KeywordMap)["precise"] = PRECISE;
700 (*KeywordMap)["invariant"] = INVARIANT;
701 (*KeywordMap)["packed"] = PACKED;
702 (*KeywordMap)["resource"] = RESOURCE;
703 (*KeywordMap)["superp"] = SUPERP;
706 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
707 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
708 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
709 (*KeywordMap)["callableDataNV"] = CALLDATANV;
710 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
711 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
712 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
713 (*KeywordMap)["perviewNV"] = PERVIEWNV;
714 (*KeywordMap)["taskNV"] = PERTASKNV;
717 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
719 ReservedSet->insert("common");
720 ReservedSet->insert("partition");
721 ReservedSet->insert("active");
722 ReservedSet->insert("asm");
723 ReservedSet->insert("class");
724 ReservedSet->insert("union");
725 ReservedSet->insert("enum");
726 ReservedSet->insert("typedef");
727 ReservedSet->insert("template");
728 ReservedSet->insert("this");
729 ReservedSet->insert("goto");
730 ReservedSet->insert("inline");
731 ReservedSet->insert("noinline");
732 ReservedSet->insert("public");
733 ReservedSet->insert("static");
734 ReservedSet->insert("extern");
735 ReservedSet->insert("external");
736 ReservedSet->insert("interface");
737 ReservedSet->insert("long");
738 ReservedSet->insert("short");
739 ReservedSet->insert("half");
740 ReservedSet->insert("fixed");
741 ReservedSet->insert("unsigned");
742 ReservedSet->insert("input");
743 ReservedSet->insert("output");
744 ReservedSet->insert("hvec2");
745 ReservedSet->insert("hvec3");
746 ReservedSet->insert("hvec4");
747 ReservedSet->insert("fvec2");
748 ReservedSet->insert("fvec3");
749 ReservedSet->insert("fvec4");
750 ReservedSet->insert("sampler3DRect");
751 ReservedSet->insert("filter");
752 ReservedSet->insert("sizeof");
753 ReservedSet->insert("cast");
754 ReservedSet->insert("namespace");
755 ReservedSet->insert("using");
758 void TScanContext::deleteKeywordMap()
761 KeywordMap = nullptr;
763 ReservedSet = nullptr;
766 // Called by yylex to get the next token.
767 // Returning 0 implies end of input.
768 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
771 parserToken = &token;
773 int token = pp->tokenize(ppToken);
774 if (token == EndOfInput)
777 tokenText = ppToken.name;
779 parserToken->sType.lex.loc = loc;
781 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
782 case ',': afterType = false; return COMMA;
783 case ':': return COLON;
784 case '=': afterType = false; return EQUAL;
785 case '(': afterType = false; return LEFT_PAREN;
786 case ')': afterType = false; return RIGHT_PAREN;
787 case '.': field = true; return DOT;
788 case '!': return BANG;
789 case '-': return DASH;
790 case '~': return TILDE;
791 case '+': return PLUS;
792 case '*': return STAR;
793 case '/': return SLASH;
794 case '%': return PERCENT;
795 case '<': return LEFT_ANGLE;
796 case '>': return RIGHT_ANGLE;
797 case '|': return VERTICAL_BAR;
798 case '^': return CARET;
799 case '&': return AMPERSAND;
800 case '?': return QUESTION;
801 case '[': return LEFT_BRACKET;
802 case ']': return RIGHT_BRACKET;
803 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
804 case '}': return RIGHT_BRACE;
806 parseContext.error(loc, "illegal use of escape character", "\\", "");
809 case PPAtomAddAssign: return ADD_ASSIGN;
810 case PPAtomSubAssign: return SUB_ASSIGN;
811 case PPAtomMulAssign: return MUL_ASSIGN;
812 case PPAtomDivAssign: return DIV_ASSIGN;
813 case PPAtomModAssign: return MOD_ASSIGN;
815 case PpAtomRight: return RIGHT_OP;
816 case PpAtomLeft: return LEFT_OP;
818 case PpAtomRightAssign: return RIGHT_ASSIGN;
819 case PpAtomLeftAssign: return LEFT_ASSIGN;
820 case PpAtomAndAssign: return AND_ASSIGN;
821 case PpAtomOrAssign: return OR_ASSIGN;
822 case PpAtomXorAssign: return XOR_ASSIGN;
824 case PpAtomAnd: return AND_OP;
825 case PpAtomOr: return OR_OP;
826 case PpAtomXor: return XOR_OP;
828 case PpAtomEQ: return EQ_OP;
829 case PpAtomGE: return GE_OP;
830 case PpAtomNE: return NE_OP;
831 case PpAtomLE: return LE_OP;
833 case PpAtomDecrement: return DEC_OP;
834 case PpAtomIncrement: return INC_OP;
836 case PpAtomColonColon:
837 parseContext.error(loc, "not supported", "::", "");
840 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
841 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
842 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
843 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
844 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
845 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
846 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
847 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
848 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
849 case PpAtomIdentifier:
851 int token = tokenizeIdentifier();
856 case EndOfInput: return 0;
860 buf[0] = (char)token;
862 parseContext.error(loc, "unexpected token", buf, "");
868 int TScanContext::tokenizeIdentifier()
870 if (ReservedSet->find(tokenText) != ReservedSet->end())
871 return reservedWord();
873 auto it = KeywordMap->find(tokenText);
874 if (it == KeywordMap->end()) {
875 // Should have an identifier of some sort
876 return identifierOrType();
878 keyword = it->second;
903 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
906 return identifierOrType();
910 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
911 (parseContext.profile != EEsProfile && parseContext.version < 130))
937 if (strcmp("true", tokenText) == 0)
938 parserToken->sType.lex.b = true;
940 parserToken->sType.lex.b = false;
945 if (parseContext.profile == EEsProfile && parseContext.version >= 300)
951 if ((parseContext.profile == EEsProfile && parseContext.version < 310) ||
952 (parseContext.profile != EEsProfile && parseContext.version < 430))
953 return identifierOrType();
963 if (parseContext.symbolTable.atBuiltInLevel() ||
964 (parseContext.profile != EEsProfile && parseContext.version >= 460
965 && parseContext.extensionTurnedOn(E_GL_NV_ray_tracing)))
967 return identifierOrType();
971 if ((parseContext.profile == EEsProfile && parseContext.version >= 310) ||
972 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
974 return es30ReservedFromGLSL(420);
978 case QUEUEFAMILYCOHERENT:
979 case WORKGROUPCOHERENT:
980 case SUBGROUPCOHERENT:
985 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
987 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
990 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
992 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.profile == EEsProfile ||
993 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
999 const int numLayoutExts = 2;
1000 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1001 E_GL_ARB_explicit_attrib_location };
1002 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1003 (parseContext.profile != EEsProfile && parseContext.version < 140 &&
1004 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1005 return identifierOrType();
1009 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1010 (parseContext.profile != EEsProfile && parseContext.version < 140))
1011 return identifierOrType();
1015 if (parseContext.symbolTable.atBuiltInLevel() ||
1016 (parseContext.profile == EEsProfile &&
1017 (parseContext.version >= 320 ||
1018 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1019 (parseContext.profile != EEsProfile && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1022 return es30ReservedFromGLSL(400);
1025 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1026 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1028 return es30ReservedFromGLSL(400);
1031 return es30ReservedFromGLSL(400);
1033 case HIGH_PRECISION:
1034 case MEDIUM_PRECISION:
1037 return precisionKeyword();
1074 return firstGenerationImage(false);
1080 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1081 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1083 return firstGenerationImage(false);
1098 return firstGenerationImage(true);
1100 case IMAGECUBEARRAY:
1101 case IIMAGECUBEARRAY:
1102 case UIMAGECUBEARRAY:
1104 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1105 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1107 return secondGenerationImage();
1112 case IMAGE2DMSARRAY:
1113 case IIMAGE2DMSARRAY:
1114 case UIMAGE2DMSARRAY:
1116 return secondGenerationImage();
1123 if (parseContext.profile == EEsProfile || parseContext.version < 400)
1136 if (parseContext.symbolTable.atBuiltInLevel() ||
1137 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1138 (parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1139 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1140 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))))
1142 return identifierOrType();
1153 if (parseContext.symbolTable.atBuiltInLevel() ||
1154 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1155 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1156 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8)) &&
1157 parseContext.profile != EEsProfile && parseContext.version >= 450))
1159 return identifierOrType();
1170 if (parseContext.symbolTable.atBuiltInLevel() ||
1171 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1173 #ifdef AMD_EXTENSIONS
1174 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1176 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1177 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1178 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))))
1180 return identifierOrType();
1190 if (parseContext.symbolTable.atBuiltInLevel() ||
1191 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1192 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32)) &&
1193 parseContext.profile != EEsProfile && parseContext.version >= 450))
1195 return identifierOrType();
1213 if (parseContext.symbolTable.atBuiltInLevel() ||
1214 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1215 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32)) &&
1216 parseContext.profile != EEsProfile && parseContext.version >= 450))
1218 return identifierOrType();
1237 if (parseContext.symbolTable.atBuiltInLevel() ||
1238 ((parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1239 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64)) &&
1240 parseContext.profile != EEsProfile && parseContext.version >= 450))
1242 return identifierOrType();
1249 if (parseContext.symbolTable.atBuiltInLevel() ||
1250 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1252 #ifdef AMD_EXTENSIONS
1253 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1255 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1256 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1257 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))))
1260 return identifierOrType();
1275 if (parseContext.symbolTable.atBuiltInLevel() ||
1276 (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1278 #ifdef AMD_EXTENSIONS
1279 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1281 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1282 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))))
1285 return identifierOrType();
1287 case SAMPLERCUBEARRAY:
1288 case SAMPLERCUBEARRAYSHADOW:
1289 case ISAMPLERCUBEARRAY:
1290 case USAMPLERCUBEARRAY:
1292 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1293 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1295 if (parseContext.profile == EEsProfile || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1300 case ISAMPLER1DARRAY:
1301 case SAMPLER1DARRAYSHADOW:
1303 case USAMPLER1DARRAY:
1305 return es30ReservedFromGLSL(130);
1311 case SAMPLERCUBESHADOW:
1312 case SAMPLER2DARRAY:
1313 case SAMPLER2DARRAYSHADOW:
1317 case ISAMPLER2DARRAY:
1321 case USAMPLER2DARRAY:
1323 return nonreservedKeyword(300, 130);
1325 case ISAMPLER2DRECT:
1326 case USAMPLER2DRECT:
1328 return es30ReservedFromGLSL(140);
1332 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1333 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1335 return es30ReservedFromGLSL(130);
1337 case ISAMPLERBUFFER:
1338 case USAMPLERBUFFER:
1340 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1341 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1343 return es30ReservedFromGLSL(140);
1349 if (parseContext.profile == EEsProfile && parseContext.version >= 310)
1351 return es30ReservedFromGLSL(150);
1353 case SAMPLER2DMSARRAY:
1354 case ISAMPLER2DMSARRAY:
1355 case USAMPLER2DMSARRAY:
1357 if ((parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1358 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1360 return es30ReservedFromGLSL(150);
1363 case SAMPLER1DSHADOW:
1365 if (parseContext.profile == EEsProfile)
1371 if (parseContext.profile == EEsProfile && parseContext.version < 300) {
1372 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1377 case SAMPLER2DSHADOW:
1379 if (parseContext.profile == EEsProfile && parseContext.version < 300) {
1380 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1386 case SAMPLER2DRECTSHADOW:
1388 if (parseContext.profile == EEsProfile)
1390 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1391 if (parseContext.relaxedErrors())
1392 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1398 case SAMPLER1DARRAY:
1400 if (parseContext.profile == EEsProfile && parseContext.version == 300)
1402 else if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1403 (parseContext.profile != EEsProfile && parseContext.version < 130))
1404 return identifierOrType();
1407 case SAMPLEREXTERNALOES:
1409 if (parseContext.symbolTable.atBuiltInLevel() ||
1410 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1411 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1413 return identifierOrType();
1415 case SAMPLEREXTERNAL2DY2YEXT:
1417 if (parseContext.symbolTable.atBuiltInLevel() ||
1418 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1420 return identifierOrType();
1424 case TEXTURECUBEARRAY:
1425 case ITEXTURECUBEARRAY:
1426 case UTEXTURECUBEARRAY:
1427 case ITEXTURE1DARRAY:
1430 case UTEXTURE1DARRAY:
1432 case TEXTURE2DARRAY:
1436 case ITEXTURE2DARRAY:
1440 case UTEXTURE2DARRAY:
1441 case ITEXTURE2DRECT:
1442 case UTEXTURE2DRECT:
1443 case ITEXTUREBUFFER:
1444 case UTEXTUREBUFFER:
1448 case TEXTURE2DMSARRAY:
1449 case ITEXTURE2DMSARRAY:
1450 case UTEXTURE2DMSARRAY:
1454 case TEXTURE1DARRAY:
1457 if (parseContext.spvVersion.vulkan > 0)
1460 return identifierOrType();
1463 case SUBPASSINPUTMS:
1465 case ISUBPASSINPUTMS:
1467 case USUBPASSINPUTMS:
1468 if (parseContext.spvVersion.vulkan > 0)
1471 return identifierOrType();
1473 #ifdef AMD_EXTENSIONS
1477 case F16SAMPLER2DRECT:
1478 case F16SAMPLERCUBE:
1479 case F16SAMPLER1DARRAY:
1480 case F16SAMPLER2DARRAY:
1481 case F16SAMPLERCUBEARRAY:
1482 case F16SAMPLERBUFFER:
1483 case F16SAMPLER2DMS:
1484 case F16SAMPLER2DMSARRAY:
1485 case F16SAMPLER1DSHADOW:
1486 case F16SAMPLER2DSHADOW:
1487 case F16SAMPLER1DARRAYSHADOW:
1488 case F16SAMPLER2DARRAYSHADOW:
1489 case F16SAMPLER2DRECTSHADOW:
1490 case F16SAMPLERCUBESHADOW:
1491 case F16SAMPLERCUBEARRAYSHADOW:
1496 case F16IMAGE2DRECT:
1498 case F16IMAGE1DARRAY:
1499 case F16IMAGE2DARRAY:
1500 case F16IMAGECUBEARRAY:
1501 case F16IMAGEBUFFER:
1503 case F16IMAGE2DMSARRAY:
1508 case F16TEXTURE2DRECT:
1509 case F16TEXTURECUBE:
1510 case F16TEXTURE1DARRAY:
1511 case F16TEXTURE2DARRAY:
1512 case F16TEXTURECUBEARRAY:
1513 case F16TEXTUREBUFFER:
1514 case F16TEXTURE2DMS:
1515 case F16TEXTURE2DMSARRAY:
1517 case F16SUBPASSINPUT:
1518 case F16SUBPASSINPUTMS:
1520 if (parseContext.symbolTable.atBuiltInLevel() ||
1521 (parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch) &&
1522 parseContext.profile != EEsProfile && parseContext.version >= 450))
1524 return identifierOrType();
1528 #ifdef NV_EXTENSIONS
1529 if (parseContext.profile == EEsProfile && parseContext.version >= 300 &&
1530 parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1533 return es30ReservedFromGLSL(130);
1536 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1537 (parseContext.profile != EEsProfile && parseContext.version < 130))
1538 return identifierOrType();
1541 #ifdef AMD_EXTENSIONS
1542 case EXPLICITINTERPAMD:
1543 if (parseContext.profile != EEsProfile && parseContext.version >= 450 &&
1544 parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1546 return identifierOrType();
1549 #ifdef NV_EXTENSIONS
1551 if (((parseContext.profile != EEsProfile && parseContext.version >= 450) ||
1552 (parseContext.profile == EEsProfile && parseContext.version >= 320)) &&
1553 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1555 return identifierOrType();
1559 if (parseContext.profile == EEsProfile && parseContext.version < 300)
1561 else if (parseContext.profile != EEsProfile && parseContext.version < 130)
1562 return identifierOrType();
1566 if (parseContext.version < 120)
1567 return identifierOrType();
1571 if ((parseContext.profile == EEsProfile &&
1572 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1573 (parseContext.profile != EEsProfile && parseContext.version >= 400))
1575 if (parseContext.profile == EEsProfile && parseContext.version == 310) {
1579 return identifierOrType();
1582 if (parseContext.profile != EEsProfile && parseContext.version < 120)
1583 return identifierOrType();
1587 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1588 (parseContext.profile != EEsProfile && parseContext.version < 330))
1589 return reservedWord();
1590 return identifierOrType();
1594 bool reserved = (parseContext.profile == EEsProfile && parseContext.version >= 300) ||
1595 (parseContext.profile != EEsProfile && parseContext.version >= 420);
1596 return identifierOrReserved(reserved);
1600 bool reserved = parseContext.profile == EEsProfile || parseContext.version >= 130;
1601 return identifierOrReserved(reserved);
1604 #ifdef NV_EXTENSIONS
1605 case PERPRIMITIVENV:
1608 if ((parseContext.profile != EEsProfile && parseContext.version >= 450) ||
1609 (parseContext.profile == EEsProfile && parseContext.version >= 320) ||
1610 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1612 return identifierOrType();
1616 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1621 int TScanContext::identifierOrType()
1623 parserToken->sType.lex.string = NewPoolTString(tokenText);
1627 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1628 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1629 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1630 if (variable->isUserType() &&
1631 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1632 !(variable->getType().getBasicType() == EbtReference && afterBuffer)) {
1643 // Give an error for use of a reserved symbol.
1644 // However, allow built-in declarations to use reserved words, to allow
1645 // extension support before the extension is enabled.
1646 int TScanContext::reservedWord()
1648 if (! parseContext.symbolTable.atBuiltInLevel())
1649 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1654 int TScanContext::identifierOrReserved(bool reserved)
1662 if (parseContext.forwardCompatible)
1663 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1665 return identifierOrType();
1668 // For keywords that suddenly showed up on non-ES (not previously reserved)
1669 // but then got reserved by ES 3.0.
1670 int TScanContext::es30ReservedFromGLSL(int version)
1672 if (parseContext.symbolTable.atBuiltInLevel())
1675 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
1676 (parseContext.profile != EEsProfile && parseContext.version < version)) {
1677 if (parseContext.forwardCompatible)
1678 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1680 return identifierOrType();
1681 } else if (parseContext.profile == EEsProfile && parseContext.version >= 300)
1687 // For a keyword that was never reserved, until it suddenly
1688 // showed up, both in an es version and a non-ES version.
1689 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1691 if ((parseContext.profile == EEsProfile && parseContext.version < esVersion) ||
1692 (parseContext.profile != EEsProfile && parseContext.version < nonEsVersion)) {
1693 if (parseContext.forwardCompatible)
1694 parseContext.warn(loc, "using future keyword", tokenText, "");
1696 return identifierOrType();
1702 int TScanContext::precisionKeyword()
1704 if (parseContext.profile == EEsProfile || parseContext.version >= 130)
1707 if (parseContext.forwardCompatible)
1708 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1710 return identifierOrType();
1713 int TScanContext::matNxM()
1717 if (parseContext.version > 110)
1720 if (parseContext.forwardCompatible)
1721 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1723 return identifierOrType();
1726 int TScanContext::dMat()
1730 if (parseContext.profile == EEsProfile && parseContext.version >= 300) {
1736 if (parseContext.profile != EEsProfile && parseContext.version >= 400)
1739 if (parseContext.forwardCompatible)
1740 parseContext.warn(loc, "using future type keyword", tokenText, "");
1742 return identifierOrType();
1745 int TScanContext::firstGenerationImage(bool inEs310)
1747 if (parseContext.symbolTable.atBuiltInLevel() ||
1748 (parseContext.profile != EEsProfile && (parseContext.version >= 420 ||
1749 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1750 (inEs310 && parseContext.profile == EEsProfile && parseContext.version >= 310))
1753 if ((parseContext.profile == EEsProfile && parseContext.version >= 300) ||
1754 (parseContext.profile != EEsProfile && parseContext.version >= 130)) {
1760 if (parseContext.forwardCompatible)
1761 parseContext.warn(loc, "using future type keyword", tokenText, "");
1763 return identifierOrType();
1766 int TScanContext::secondGenerationImage()
1768 if (parseContext.profile == EEsProfile && parseContext.version >= 310) {
1773 if (parseContext.symbolTable.atBuiltInLevel() ||
1774 (parseContext.profile != EEsProfile &&
1775 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1778 if (parseContext.forwardCompatible)
1779 parseContext.warn(loc, "using future type keyword", tokenText, "");
1781 return identifierOrType();
1784 } // end namespace glslang