2 //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 //Copyright (C) 2013 LunarG, Inc.
7 //Redistribution and use in source and binary forms, with or without
8 //modification, are permitted provided that the following conditions
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
14 // Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
19 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
20 // contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
23 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //POSSIBILITY OF SUCH DAMAGE.
38 // GLSL scanning, leveraging the scanning done by the preprocessor.
43 #include "../Include/Types.h"
44 #include "SymbolTable.h"
45 #include "glslang_tab.cpp.h"
46 #include "ParseHelper.h"
47 #include "ScanContext.h"
50 // preprocessor includes
51 #include "preprocessor/PpContext.h"
52 #include "preprocessor/PpTokens.h"
56 // read past any white space
57 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
59 char c = peek(); // don't accidentally consume anything other than whitespace
60 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
61 if (c == '\r' || c == '\n')
62 foundNonSpaceTab = true;
68 // return true if a comment was actually consumed
69 bool TInputScanner::consumeComment()
74 get(); // consume the '/'
78 // a '//' style comment
79 get(); // consume the second '/'
82 while (c > 0 && c != '\\' && c != '\r' && c != '\n')
85 if (c <= 0 || c == '\r' || c == '\n') {
86 while (c == '\r' || c == '\n')
89 // we reached the end of the comment
92 // it's a '\', so we need to keep going, after skipping what's escaped
94 // read the skipped character
97 // if it's a two-character newline, skip both characters
98 if (c == '\r' && peek() == '\n')
104 // put back the last non-comment character
109 } else if (c == '*') {
111 // a '/*' style comment
112 get(); // consume the '*'
115 while (c > 0 && c != '*')
120 break; // end of comment
121 // not end of comment
122 } else // end of input
128 // it's not a comment, put the '/' back
135 // skip whitespace, then skip a comment, rinse, repeat
136 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
139 consumeWhiteSpace(foundNonSpaceTab);
141 // if not starting a comment now, then done
143 if (c != '/' || c < 0)
146 // skip potential comment
147 foundNonSpaceTab = true;
148 if (! consumeComment())
154 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
155 // or no #version was found; otherwise, returns false. There is no error case, it always
156 // succeeds, but will leave version == 0 if no #version was found.
158 // N.B. does not attempt to leave input in any particular known state. The assumption
159 // is that scanning will start anew, following the rules for the chosen version/profile,
160 // and with a corresponding parsing context.
162 bool TInputScanner::scanVersion(int& version, EProfile& profile)
164 // This function doesn't have to get all the semantics correct,
165 // just find the #version if there is a correct one present.
166 // The preprocessor will have the responsibility of getting all the semantics right.
168 version = 0; // means not found
169 profile = ENoProfile;
171 bool foundNonSpaceTab = false;
172 consumeWhitespaceComment(foundNonSpaceTab);
182 } while (c == ' ' || c == '\t');
196 } while (c == ' ' || c == '\t');
199 while (c >= '0' && c <= '9') {
200 version = 10 * version + (c - '0');
207 while (c == ' ' || c == '\t')
211 const int maxProfileLength = 13; // not including any 0
212 char profileString[maxProfileLength];
214 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
215 if (c < 0 || c == ' ' || c == '\t' || c == '\n' || c == '\r')
217 profileString[profileLength] = c;
220 if (c > 0 && c != ' ' && c != '\t' && c != '\n' && c != '\r')
223 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
224 profile = EEsProfile;
225 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
226 profile = ECoreProfile;
227 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
228 profile = ECompatibilityProfile;
230 return foundNonSpaceTab;
233 // Fill this in when doing glslang-level scanning, to hand back to the parser.
236 explicit TParserToken(YYSTYPE& b) : sType(b) { }
241 } // end namespace glslang
243 // This is the function the glslang parser (i.e., bison) calls to get its next token
244 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
246 glslang::TParserToken token(*glslangTokenDesc);
248 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
253 // A single global usable by all threads, by all versions, by all languages.
254 // After a single process-level initialization, this is read only and thread safe
255 std::map<std::string, int>* KeywordMap = 0;
256 std::set<std::string>* ReservedSet = 0;
262 void TScanContext::fillInKeywordMap()
264 if (KeywordMap != 0) {
265 // this is really an error, as this should called only once per process
266 // but, the only risk is if two threads called simultaneously
269 KeywordMap = new std::map<std::string, int>;
271 (*KeywordMap)["const"] = CONST;
272 (*KeywordMap)["uniform"] = UNIFORM;
273 (*KeywordMap)["in"] = IN;
274 (*KeywordMap)["out"] = OUT;
275 (*KeywordMap)["inout"] = INOUT;
276 (*KeywordMap)["struct"] = STRUCT;
277 (*KeywordMap)["break"] = BREAK;
278 (*KeywordMap)["continue"] = CONTINUE;
279 (*KeywordMap)["do"] = DO;
280 (*KeywordMap)["for"] = FOR;
281 (*KeywordMap)["while"] = WHILE;
282 (*KeywordMap)["switch"] = SWITCH;
283 (*KeywordMap)["case"] = CASE;
284 (*KeywordMap)["default"] = DEFAULT;
285 (*KeywordMap)["if"] = IF;
286 (*KeywordMap)["else"] = ELSE;
287 (*KeywordMap)["discard"] = DISCARD;
288 (*KeywordMap)["return"] = RETURN;
289 (*KeywordMap)["void"] = VOID;
290 (*KeywordMap)["bool"] = BOOL;
291 (*KeywordMap)["float"] = FLOAT;
292 (*KeywordMap)["int"] = INT;
293 (*KeywordMap)["bvec2"] = BVEC2;
294 (*KeywordMap)["bvec3"] = BVEC3;
295 (*KeywordMap)["bvec4"] = BVEC4;
296 (*KeywordMap)["vec2"] = VEC2;
297 (*KeywordMap)["vec3"] = VEC3;
298 (*KeywordMap)["vec4"] = VEC4;
299 (*KeywordMap)["ivec2"] = IVEC2;
300 (*KeywordMap)["ivec3"] = IVEC3;
301 (*KeywordMap)["ivec4"] = IVEC4;
302 (*KeywordMap)["mat2"] = MAT2;
303 (*KeywordMap)["mat3"] = MAT3;
304 (*KeywordMap)["mat4"] = MAT4;
305 (*KeywordMap)["sampler2D"] = SAMPLER2D;
306 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
307 (*KeywordMap)["true"] = BOOLCONSTANT;
308 (*KeywordMap)["false"] = BOOLCONSTANT;
309 (*KeywordMap)["attribute"] = ATTRIBUTE;
310 (*KeywordMap)["varying"] = VARYING;
311 (*KeywordMap)["buffer"] = BUFFER;
312 (*KeywordMap)["coherent"] = COHERENT;
313 (*KeywordMap)["restrict"] = RESTRICT;
314 (*KeywordMap)["readonly"] = READONLY;
315 (*KeywordMap)["writeonly"] = WRITEONLY;
316 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
317 (*KeywordMap)["volatile"] = VOLATILE;
318 (*KeywordMap)["layout"] = LAYOUT;
319 (*KeywordMap)["shared"] = SHARED;
320 (*KeywordMap)["patch"] = PATCH;
321 (*KeywordMap)["sample"] = SAMPLE;
322 (*KeywordMap)["subroutine"] = SUBROUTINE;
323 (*KeywordMap)["highp"] = HIGH_PRECISION;
324 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
325 (*KeywordMap)["lowp"] = LOW_PRECISION;
326 (*KeywordMap)["precision"] = PRECISION;
327 (*KeywordMap)["mat2x2"] = MAT2X2;
328 (*KeywordMap)["mat2x3"] = MAT2X3;
329 (*KeywordMap)["mat2x4"] = MAT2X4;
330 (*KeywordMap)["mat3x2"] = MAT3X2;
331 (*KeywordMap)["mat3x3"] = MAT3X3;
332 (*KeywordMap)["mat3x4"] = MAT3X4;
333 (*KeywordMap)["mat4x2"] = MAT4X2;
334 (*KeywordMap)["mat4x3"] = MAT4X3;
335 (*KeywordMap)["mat4x4"] = MAT4X4;
336 (*KeywordMap)["dmat2"] = DMAT2;
337 (*KeywordMap)["dmat3"] = DMAT3;
338 (*KeywordMap)["dmat4"] = DMAT4;
339 (*KeywordMap)["dmat2x2"] = DMAT2X2;
340 (*KeywordMap)["dmat2x3"] = DMAT2X3;
341 (*KeywordMap)["dmat2x4"] = DMAT2X4;
342 (*KeywordMap)["dmat3x2"] = DMAT3X2;
343 (*KeywordMap)["dmat3x3"] = DMAT3X3;
344 (*KeywordMap)["dmat3x4"] = DMAT3X4;
345 (*KeywordMap)["dmat4x2"] = DMAT4X2;
346 (*KeywordMap)["dmat4x3"] = DMAT4X3;
347 (*KeywordMap)["dmat4x4"] = DMAT4X4;
348 (*KeywordMap)["image1D"] = IMAGE1D;
349 (*KeywordMap)["iimage1D"] = IIMAGE1D;
350 (*KeywordMap)["uimage1D"] = UIMAGE1D;
351 (*KeywordMap)["image2D"] = IMAGE2D;
352 (*KeywordMap)["iimage2D"] = IIMAGE2D;
353 (*KeywordMap)["uimage2D"] = UIMAGE2D;
354 (*KeywordMap)["image3D"] = IMAGE3D;
355 (*KeywordMap)["iimage3D"] = IIMAGE3D;
356 (*KeywordMap)["uimage3D"] = UIMAGE3D;
357 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
358 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
359 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
360 (*KeywordMap)["imageCube"] = IMAGECUBE;
361 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
362 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
363 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
364 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
365 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
366 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
367 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
368 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
369 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
370 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
371 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
372 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
373 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
374 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
375 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
376 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
377 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
378 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
379 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
380 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
381 (*KeywordMap)["double"] = DOUBLE;
382 (*KeywordMap)["dvec2"] = DVEC2;
383 (*KeywordMap)["dvec3"] = DVEC3;
384 (*KeywordMap)["dvec4"] = DVEC4;
385 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
386 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
387 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
388 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
389 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
390 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
391 (*KeywordMap)["usampler1D"] = USAMPLER1D;
392 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
393 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
394 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
395 (*KeywordMap)["uint"] = UINT;
396 (*KeywordMap)["uvec2"] = UVEC2;
397 (*KeywordMap)["uvec3"] = UVEC3;
398 (*KeywordMap)["uvec4"] = UVEC4;
399 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
400 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
401 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
402 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
403 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
404 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
405 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
406 (*KeywordMap)["usampler2D"] = USAMPLER2D;
407 (*KeywordMap)["usampler3D"] = USAMPLER3D;
408 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
409 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
410 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
411 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
412 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
413 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
414 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
415 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
416 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
417 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
418 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
419 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
420 (*KeywordMap)["sampler1D"] = SAMPLER1D;
421 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
422 (*KeywordMap)["sampler3D"] = SAMPLER3D;
423 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
424 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
425 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
426 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
427 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
428 (*KeywordMap)["smooth"] = SMOOTH;
429 (*KeywordMap)["flat"] = FLAT;
430 (*KeywordMap)["centroid"] = CENTROID;
431 (*KeywordMap)["precise"] = PRECISE;
432 (*KeywordMap)["invariant"] = INVARIANT;
433 (*KeywordMap)["packed"] = PACKED;
434 (*KeywordMap)["resource"] = RESOURCE;
435 (*KeywordMap)["superp"] = SUPERP;
437 ReservedSet = new std::set<std::string>;
439 ReservedSet->insert("common");
440 ReservedSet->insert("partition");
441 ReservedSet->insert("active");
442 ReservedSet->insert("asm");
443 ReservedSet->insert("class");
444 ReservedSet->insert("union");
445 ReservedSet->insert("enum");
446 ReservedSet->insert("typedef");
447 ReservedSet->insert("template");
448 ReservedSet->insert("this");
449 ReservedSet->insert("goto");
450 ReservedSet->insert("inline");
451 ReservedSet->insert("noinline");
452 ReservedSet->insert("public");
453 ReservedSet->insert("static");
454 ReservedSet->insert("extern");
455 ReservedSet->insert("external");
456 ReservedSet->insert("interface");
457 ReservedSet->insert("long");
458 ReservedSet->insert("short");
459 ReservedSet->insert("half");
460 ReservedSet->insert("fixed");
461 ReservedSet->insert("unsigned");
462 ReservedSet->insert("input");
463 ReservedSet->insert("output");
464 ReservedSet->insert("hvec2");
465 ReservedSet->insert("hvec3");
466 ReservedSet->insert("hvec4");
467 ReservedSet->insert("fvec2");
468 ReservedSet->insert("fvec3");
469 ReservedSet->insert("fvec4");
470 ReservedSet->insert("sampler3DRect");
471 ReservedSet->insert("filter");
472 ReservedSet->insert("sizeof");
473 ReservedSet->insert("cast");
474 ReservedSet->insert("namespace");
475 ReservedSet->insert("using");
478 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
480 parserToken = &token;
482 tokenText = pp->tokenize(&ppToken);
487 parserToken->sType.lex.loc = loc;
488 switch (ppToken.token) {
489 case ';': afterType = false; return SEMICOLON;
490 case ',': afterType = false; return COMMA;
491 case ':': return COLON;
492 case '=': afterType = false; return EQUAL;
493 case '(': afterType = false; return LEFT_PAREN;
494 case ')': afterType = false; return RIGHT_PAREN;
495 case '.': field = true; return DOT;
496 case '!': return BANG;
497 case '-': return DASH;
498 case '~': return TILDE;
499 case '+': return PLUS;
500 case '*': return STAR;
501 case '/': return SLASH;
502 case '%': return PERCENT;
503 case '<': return LEFT_ANGLE;
504 case '>': return RIGHT_ANGLE;
505 case '|': return VERTICAL_BAR;
506 case '^': return CARET;
507 case '&': return AMPERSAND;
508 case '?': return QUESTION;
509 case '[': return LEFT_BRACKET;
510 case ']': return RIGHT_BRACKET;
511 case '{': return LEFT_BRACE;
512 case '}': return RIGHT_BRACE;
514 case CPP_AND_OP: return AND_OP;
515 case CPP_SUB_ASSIGN: return SUB_ASSIGN;
516 case CPP_MOD_ASSIGN: return MOD_ASSIGN;
517 case CPP_ADD_ASSIGN: return ADD_ASSIGN;
518 case CPP_DIV_ASSIGN: return DIV_ASSIGN;
519 case CPP_MUL_ASSIGN: return MUL_ASSIGN;
520 case CPP_EQ_OP: return EQ_OP;
521 case CPP_XOR_OP: return XOR_OP;
522 case CPP_GE_OP: return GE_OP;
523 case CPP_RIGHT_OP: return RIGHT_OP;
524 case CPP_LE_OP: return LE_OP;
525 case CPP_LEFT_OP: return LEFT_OP;
526 case CPP_DEC_OP: return DEC_OP;
527 case CPP_NE_OP: return NE_OP;
528 case CPP_OR_OP: return OR_OP;
529 case CPP_INC_OP: return INC_OP;
530 case CPP_RIGHT_ASSIGN: return RIGHT_ASSIGN;
531 case CPP_LEFT_ASSIGN: return LEFT_ASSIGN;
532 case CPP_AND_ASSIGN: return AND_ASSIGN;
533 case CPP_OR_ASSIGN: return OR_ASSIGN;
534 case CPP_XOR_ASSIGN: return XOR_ASSIGN;
536 case CPP_INTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
537 case CPP_UINTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
538 case CPP_FLOATCONSTANT: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
539 case CPP_DOUBLECONSTANT: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
540 case CPP_IDENTIFIER: return tokenizeIdentifier();
545 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown PP token", loc);
550 int TScanContext::tokenizeIdentifier()
552 if (ReservedSet->find(tokenText) != ReservedSet->end())
553 return reservedWord();
555 std::map<std::string, int>::const_iterator it = KeywordMap->find(tokenText);
556 if (it == KeywordMap->end()) {
557 // Should have an identifier of some sort
558 return identifierOrType();
560 keyword = it->second;
584 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
585 (parseContext.profile != EEsProfile && parseContext.version < 130))
611 if (strcmp("true", tokenText) == 0)
612 parserToken->sType.lex.b = true;
614 parserToken->sType.lex.b = false;
619 if (parseContext.profile == EEsProfile && parseContext.version >= 300)
624 if (parseContext.version < 430)
625 return identifierOrType();
633 return es30ReservedFromGLSL(420);
636 if (parseContext.profile == EEsProfile || parseContext.version < 420)
642 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
643 (parseContext.profile != EEsProfile && parseContext.version < 140))
644 return identifierOrType();
650 return es30ReservedFromGLSL(400);
653 case MEDIUM_PRECISION:
656 return precisionKeyword();
707 return firstGenerationImage();
710 case IIMAGECUBEARRAY:
711 case UIMAGECUBEARRAY:
716 case IIMAGE2DMSARRAY:
717 case UIMAGE2DMSARRAY:
718 return secondGenerationImage();
724 case SAMPLERCUBEARRAY:
725 case SAMPLERCUBEARRAYSHADOW:
726 case ISAMPLERCUBEARRAY:
727 case USAMPLERCUBEARRAY:
729 if (parseContext.profile == EEsProfile || parseContext.version < 400)
734 case ISAMPLER1DARRAY:
735 case SAMPLER1DARRAYSHADOW:
737 case USAMPLER1DARRAY:
740 return es30ReservedFromGLSL(130);
746 case SAMPLERCUBESHADOW:
748 case SAMPLER2DARRAYSHADOW:
752 case ISAMPLER2DARRAY:
756 case USAMPLER2DARRAY:
758 return nonreservedKeyword(300, 130);
765 return es30ReservedFromGLSL(140);
770 case SAMPLER2DMSARRAY:
771 case ISAMPLER2DMSARRAY:
772 case USAMPLER2DMSARRAY:
774 return es30ReservedFromGLSL(150);
777 case SAMPLER1DSHADOW:
779 if (parseContext.profile == EEsProfile)
784 case SAMPLER2DSHADOW:
786 if (parseContext.profile == EEsProfile && parseContext.version < 300)
791 case SAMPLER2DRECTSHADOW:
793 if (parseContext.profile == EEsProfile ||
794 (parseContext.profile != EEsProfile && parseContext.version < 140))
800 if (parseContext.profile == EEsProfile && parseContext.version == 300)
802 else if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
803 (parseContext.profile != EEsProfile && parseContext.version < 130))
804 return identifierOrType();
808 return es30ReservedFromGLSL(130);
811 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
812 (parseContext.profile != EEsProfile && parseContext.version < 130))
813 return identifierOrType();
817 if (parseContext.profile == EEsProfile && parseContext.version < 300)
819 else if (parseContext.profile != EEsProfile && parseContext.version < 130)
820 return identifierOrType();
824 if (parseContext.version < 120)
825 return identifierOrType();
829 if (parseContext.profile == EEsProfile ||
830 (parseContext.profile != EEsProfile && parseContext.version < 400))
831 return identifierOrType();
835 if (parseContext.profile != EEsProfile && parseContext.version < 120)
836 return identifierOrType();
840 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
841 (parseContext.profile != EEsProfile && parseContext.version < 330))
842 return reservedWord();
843 return identifierOrType();
847 bool reserved = (parseContext.profile == EEsProfile && parseContext.version >= 300) ||
848 (parseContext.profile != EEsProfile && parseContext.version >= 420);
849 return identifierOrReserved(reserved);
853 bool reserved = parseContext.profile == EEsProfile || parseContext.version >= 130;
854 return identifierOrReserved(reserved);
858 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
863 int TScanContext::identifierOrType()
865 parserToken->sType.lex.string = NewPoolTString(tokenText);
869 return FIELD_SELECTION;
872 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
873 if (afterType == false && parserToken->sType.lex.symbol) {
874 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
875 if (variable->isUserType()) {
886 int TScanContext::reservedWord()
888 parseContext.error(loc, "Reserved word.", tokenText, "", "");
893 int TScanContext::identifierOrReserved(bool reserved)
901 if (parseContext.forwardCompatible)
902 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
904 return identifierOrType();
907 // For keywords that suddenly showed up on non-ES (not previously reserved)
908 // but then got reserved by ES 3.0.
909 int TScanContext::es30ReservedFromGLSL(int version)
911 if ((parseContext.profile == EEsProfile && parseContext.version < 300) ||
912 (parseContext.profile != EEsProfile && parseContext.version < version)) {
913 if (parseContext.forwardCompatible)
914 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
916 return identifierOrType();
917 } else if (parseContext.profile == EEsProfile && parseContext.version >= 300)
923 // For a keyword that was never reserved, until it suddenly
924 // showed up, both in an es version and a non-ES version.
925 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
927 if ((parseContext.profile == EEsProfile && parseContext.version < esVersion) ||
928 (parseContext.profile != EEsProfile && parseContext.version < nonEsVersion)) {
929 if (parseContext.forwardCompatible)
930 parseContext.warn(loc, "using future keyword", tokenText, "");
932 return identifierOrType();
938 int TScanContext::precisionKeyword()
940 if (parseContext.profile == EEsProfile || parseContext.version >= 130)
943 if (parseContext.forwardCompatible)
944 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
946 return identifierOrType();
949 int TScanContext::matNxM()
953 if (parseContext.version > 110)
956 if (parseContext.forwardCompatible)
957 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
959 return identifierOrType();
962 int TScanContext::dMat()
966 if (parseContext.profile == EEsProfile && parseContext.version >= 300) {
972 if (parseContext.profile != EEsProfile && parseContext.version >= 400)
975 if (parseContext.forwardCompatible)
976 parseContext.warn(loc, "using future type keyword", tokenText, "");
978 return identifierOrType();
981 int TScanContext::firstGenerationImage()
985 if (parseContext.profile != EEsProfile && parseContext.version >= 420)
988 if ((parseContext.profile == EEsProfile && parseContext.version >= 300) ||
989 (parseContext.profile != EEsProfile && parseContext.version >= 130)) {
995 if (parseContext.forwardCompatible)
996 parseContext.warn(loc, "using future type keyword", tokenText, "");
998 return identifierOrType();
1001 int TScanContext::secondGenerationImage()
1005 if (parseContext.profile != EEsProfile && parseContext.version >= 420)
1008 if (parseContext.forwardCompatible)
1009 parseContext.warn(loc, "using future type keyword", tokenText, "");
1011 return identifierOrType();
1014 } // end namespace glslang