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.
44 #include "Include/Types.h"
45 #include "SymbolTable.h"
46 #include "glslang_tab.cpp.h"
47 #include "ParseHelper.h"
48 #include "ScanContext.h"
50 // preprocessor includes
51 #include "preprocessor/PpContext.h"
52 #include "preprocessor/PpTokens.h"
56 // read past any white space
57 void ConsumeWhiteSpace(TInputScanner& input, bool& foundNonSpaceTab)
59 char c = input.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 ConsumeComment(TInputScanner& input)
71 if (input.peek() != '/')
74 input.get(); // consume the '/'
75 char c = input.peek();
78 // a '//' style comment
79 input.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' && input.peek() == '\n')
104 // put back the last non-comment character
109 } else if (c == '*') {
111 // a '/*' style comment
112 input.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 ConsumeWhitespaceComment(TInputScanner& input, bool& foundNonSpaceTab)
139 ConsumeWhiteSpace(input, foundNonSpaceTab);
141 // if not starting a comment now, then done
142 char c = input.peek();
143 if (c != '/' || c < 0)
146 // skip potential comment
147 foundNonSpaceTab = true;
148 if (! ConsumeComment(input))
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 ScanVersion(TInputScanner& input, 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(input, foundNonSpaceTab);
175 if (input.get() != '#')
182 } while (c == ' ' || c == '\t');
185 input.get() != 'e' ||
186 input.get() != 'r' ||
187 input.get() != 's' ||
188 input.get() != 'i' ||
189 input.get() != 'o' ||
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 }; // end glslang namespace
237 // Fill this in when doing glslang-level scanning, to hand back to the parser.
240 explicit TParserToken(YYSTYPE& b) : sType(b) { }
245 }; // end namespace glslang
247 // This is the function the glslang parser (i.e., bison) calls to get its next token
248 int yylex(YYSTYPE* glslangTokenDesc, TParseContext& parseContext)
250 glslang::TParserToken token(*glslangTokenDesc);
252 return parseContext.scanContext->tokenize(parseContext.ppContext, token);
257 // A single global usable by all threads, by all versions, by all languages.
258 // After a single process-level initialization, this is read only and thread safe
259 std::map<std::string, int>* KeywordMap = 0;
260 std::set<std::string>* ReservedSet = 0;
266 void TScanContext::fillInKeywordMap()
268 if (KeywordMap != 0) {
269 // this is really an error, as this should called only once per process
270 // but, the only risk is if two threads called simultaneously
273 KeywordMap = new std::map<std::string, int>;
275 (*KeywordMap)["const"] = CONST;
276 (*KeywordMap)["uniform"] = UNIFORM;
277 (*KeywordMap)["in"] = IN;
278 (*KeywordMap)["out"] = OUT;
279 (*KeywordMap)["inout"] = INOUT;
280 (*KeywordMap)["struct"] = STRUCT;
281 (*KeywordMap)["break"] = BREAK;
282 (*KeywordMap)["continue"] = CONTINUE;
283 (*KeywordMap)["do"] = DO;
284 (*KeywordMap)["for"] = FOR;
285 (*KeywordMap)["while"] = WHILE;
286 (*KeywordMap)["switch"] = SWITCH;
287 (*KeywordMap)["case"] = CASE;
288 (*KeywordMap)["default"] = DEFAULT;
289 (*KeywordMap)["if"] = IF;
290 (*KeywordMap)["else"] = ELSE;
291 (*KeywordMap)["discard"] = DISCARD;
292 (*KeywordMap)["return"] = RETURN;
293 (*KeywordMap)["void"] = VOID;
294 (*KeywordMap)["bool"] = BOOL;
295 (*KeywordMap)["float"] = FLOAT;
296 (*KeywordMap)["int"] = INT;
297 (*KeywordMap)["bvec2"] = BVEC2;
298 (*KeywordMap)["bvec3"] = BVEC3;
299 (*KeywordMap)["bvec4"] = BVEC4;
300 (*KeywordMap)["vec2"] = VEC2;
301 (*KeywordMap)["vec3"] = VEC3;
302 (*KeywordMap)["vec4"] = VEC4;
303 (*KeywordMap)["ivec2"] = IVEC2;
304 (*KeywordMap)["ivec3"] = IVEC3;
305 (*KeywordMap)["ivec4"] = IVEC4;
306 (*KeywordMap)["mat2"] = MAT2;
307 (*KeywordMap)["mat3"] = MAT3;
308 (*KeywordMap)["mat4"] = MAT4;
309 (*KeywordMap)["sampler2D"] = SAMPLER2D;
310 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
311 (*KeywordMap)["true"] = BOOLCONSTANT;
312 (*KeywordMap)["false"] = BOOLCONSTANT;
313 (*KeywordMap)["attribute"] = ATTRIBUTE;
314 (*KeywordMap)["varying"] = VARYING;
315 (*KeywordMap)["buffer"] = BUFFER;
316 (*KeywordMap)["coherent"] = COHERENT;
317 (*KeywordMap)["restrict"] = RESTRICT;
318 (*KeywordMap)["readonly"] = READONLY;
319 (*KeywordMap)["writeonly"] = WRITEONLY;
320 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
321 (*KeywordMap)["volatile"] = VOLATILE;
322 (*KeywordMap)["layout"] = LAYOUT;
323 (*KeywordMap)["shared"] = SHARED;
324 (*KeywordMap)["patch"] = PATCH;
325 (*KeywordMap)["sample"] = SAMPLE;
326 (*KeywordMap)["subroutine"] = SUBROUTINE;
327 (*KeywordMap)["highp"] = HIGH_PRECISION;
328 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
329 (*KeywordMap)["lowp"] = LOW_PRECISION;
330 (*KeywordMap)["precision"] = PRECISION;
331 (*KeywordMap)["mat2x2"] = MAT2X2;
332 (*KeywordMap)["mat2x3"] = MAT2X3;
333 (*KeywordMap)["mat2x4"] = MAT2X4;
334 (*KeywordMap)["mat3x2"] = MAT3X2;
335 (*KeywordMap)["mat3x3"] = MAT3X3;
336 (*KeywordMap)["mat3x4"] = MAT3X4;
337 (*KeywordMap)["mat4x2"] = MAT4X2;
338 (*KeywordMap)["mat4x3"] = MAT4X3;
339 (*KeywordMap)["mat4x4"] = MAT4X4;
340 (*KeywordMap)["dmat2"] = DMAT2;
341 (*KeywordMap)["dmat3"] = DMAT3;
342 (*KeywordMap)["dmat4"] = DMAT4;
343 (*KeywordMap)["dmat2x2"] = DMAT2X2;
344 (*KeywordMap)["dmat2x3"] = DMAT2X3;
345 (*KeywordMap)["dmat2x4"] = DMAT2X4;
346 (*KeywordMap)["dmat3x2"] = DMAT3X2;
347 (*KeywordMap)["dmat3x3"] = DMAT3X3;
348 (*KeywordMap)["dmat3x4"] = DMAT3X4;
349 (*KeywordMap)["dmat4x2"] = DMAT4X2;
350 (*KeywordMap)["dmat4x3"] = DMAT4X3;
351 (*KeywordMap)["dmat4x4"] = DMAT4X4;
352 (*KeywordMap)["image1D"] = IMAGE1D;
353 (*KeywordMap)["iimage1D"] = IIMAGE1D;
354 (*KeywordMap)["uimage1D"] = UIMAGE1D;
355 (*KeywordMap)["image2D"] = IMAGE2D;
356 (*KeywordMap)["iimage2D"] = IIMAGE2D;
357 (*KeywordMap)["uimage2D"] = UIMAGE2D;
358 (*KeywordMap)["image3D"] = IMAGE3D;
359 (*KeywordMap)["iimage3D"] = IIMAGE3D;
360 (*KeywordMap)["uimage3D"] = UIMAGE3D;
361 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
362 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
363 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
364 (*KeywordMap)["imageCube"] = IMAGECUBE;
365 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
366 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
367 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
368 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
369 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
370 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
371 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
372 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
373 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
374 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
375 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
376 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
377 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
378 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
379 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
380 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
381 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
382 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
383 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
384 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
385 (*KeywordMap)["double"] = DOUBLE;
386 (*KeywordMap)["dvec2"] = DVEC2;
387 (*KeywordMap)["dvec3"] = DVEC3;
388 (*KeywordMap)["dvec4"] = DVEC4;
389 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
390 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
391 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
392 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
393 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
394 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
395 (*KeywordMap)["usampler1D"] = USAMPLER1D;
396 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
397 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
398 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
399 (*KeywordMap)["uint"] = UINT;
400 (*KeywordMap)["uvec2"] = UVEC2;
401 (*KeywordMap)["uvec3"] = UVEC3;
402 (*KeywordMap)["uvec4"] = UVEC4;
403 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
404 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
405 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
406 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
407 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
408 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
409 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
410 (*KeywordMap)["usampler2D"] = USAMPLER2D;
411 (*KeywordMap)["usampler3D"] = USAMPLER3D;
412 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
413 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
414 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
415 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
416 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
417 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
418 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
419 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
420 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
421 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
422 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
423 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
424 (*KeywordMap)["sampler1D"] = SAMPLER1D;
425 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
426 (*KeywordMap)["sampler3D"] = SAMPLER3D;
427 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
428 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
429 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
430 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
431 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
432 (*KeywordMap)["smooth"] = SMOOTH;
433 (*KeywordMap)["flat"] = FLAT;
434 (*KeywordMap)["centroid"] = CENTROID;
435 (*KeywordMap)["precise"] = PRECISE;
436 (*KeywordMap)["invariant"] = INVARIANT;
437 (*KeywordMap)["packed"] = PACKED;
438 (*KeywordMap)["resource"] = RESOURCE;
439 (*KeywordMap)["superp"] = SUPERP;
441 ReservedSet = new std::set<std::string>;
443 ReservedSet->insert("common");
444 ReservedSet->insert("partition");
445 ReservedSet->insert("active");
446 ReservedSet->insert("asm");
447 ReservedSet->insert("class");
448 ReservedSet->insert("union");
449 ReservedSet->insert("enum");
450 ReservedSet->insert("typedef");
451 ReservedSet->insert("template");
452 ReservedSet->insert("this");
453 ReservedSet->insert("goto");
454 ReservedSet->insert("inline");
455 ReservedSet->insert("noinline");
456 ReservedSet->insert("public");
457 ReservedSet->insert("static");
458 ReservedSet->insert("extern");
459 ReservedSet->insert("external");
460 ReservedSet->insert("interface");
461 ReservedSet->insert("long");
462 ReservedSet->insert("short");
463 ReservedSet->insert("half");
464 ReservedSet->insert("fixed");
465 ReservedSet->insert("unsigned");
466 ReservedSet->insert("input");
467 ReservedSet->insert("output");
468 ReservedSet->insert("hvec2");
469 ReservedSet->insert("hvec3");
470 ReservedSet->insert("hvec4");
471 ReservedSet->insert("fvec2");
472 ReservedSet->insert("fvec3");
473 ReservedSet->insert("fvec4");
474 ReservedSet->insert("sampler3DRect");
475 ReservedSet->insert("filter");
476 ReservedSet->insert("sizeof");
477 ReservedSet->insert("cast");
478 ReservedSet->insert("namespace");
479 ReservedSet->insert("using");
482 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
484 parserToken = &token;
486 tokenText = pp->tokenize(&ppToken);
489 parserToken->sType.lex.loc = loc;
490 switch (ppToken.ppToken) {
491 case ';': afterType = false; return SEMICOLON;
492 case ',': afterType = false; return COMMA;
493 case ':': return COLON;
494 case '=': afterType = false; return EQUAL;
495 case '(': afterType = false; return LEFT_PAREN;
496 case ')': afterType = false; return RIGHT_PAREN;
497 case '.': field = true; return DOT;
498 case '!': return BANG;
499 case '-': return DASH;
500 case '~': return TILDE;
501 case '+': return PLUS;
502 case '*': return STAR;
503 case '/': return SLASH;
504 case '%': return PERCENT;
505 case '<': return LEFT_ANGLE;
506 case '>': return RIGHT_ANGLE;
507 case '|': return VERTICAL_BAR;
508 case '^': return CARET;
509 case '&': return AMPERSAND;
510 case '?': return QUESTION;
511 case '[': return LEFT_BRACKET;
512 case ']': return RIGHT_BRACKET;
513 case '{': return LEFT_BRACE;
514 case '}': return RIGHT_BRACE;
516 case CPP_AND_OP: return AND_OP;
517 case CPP_SUB_ASSIGN: return SUB_ASSIGN;
518 case CPP_MOD_ASSIGN: return MOD_ASSIGN;
519 case CPP_ADD_ASSIGN: return ADD_ASSIGN;
520 case CPP_DIV_ASSIGN: return DIV_ASSIGN;
521 case CPP_MUL_ASSIGN: return MUL_ASSIGN;
522 case CPP_EQ_OP: return EQ_OP;
523 case CPP_XOR_OP: return XOR_OP;
524 case CPP_GE_OP: return GE_OP;
525 case CPP_RIGHT_OP: return RIGHT_OP;
526 case CPP_LE_OP: return LE_OP;
527 case CPP_LEFT_OP: return LEFT_OP;
528 case CPP_DEC_OP: return DEC_OP;
529 case CPP_NE_OP: return NE_OP;
530 case CPP_OR_OP: return OR_OP;
531 case CPP_INC_OP: return INC_OP;
532 case CPP_RIGHT_ASSIGN: return RIGHT_ASSIGN;
533 case CPP_LEFT_ASSIGN: return LEFT_ASSIGN;
534 case CPP_AND_ASSIGN: return AND_ASSIGN;
535 case CPP_OR_ASSIGN: return OR_ASSIGN;
536 case CPP_XOR_ASSIGN: return XOR_ASSIGN;
538 case CPP_INTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
539 case CPP_UINTCONSTANT: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
540 case CPP_FLOATCONSTANT: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
541 case CPP_DOUBLECONSTANT: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
542 case CPP_IDENTIFIER: return tokenizeIdentifier();
547 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown PP token", loc);
552 int TScanContext::tokenizeIdentifier()
554 if (ReservedSet->find(tokenText) != ReservedSet->end())
555 return reservedWord();
557 keyword = (*KeywordMap)[tokenText];
559 // Should have an identifier of some sort
560 return identifierOrType();
585 if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
586 parseContext.profile != EEsProfile && parseContext.version < 130)
612 if (strcmp("true", tokenText) == 0)
613 parserToken->sType.lex.b = true;
615 parserToken->sType.lex.b = false;
620 if (parseContext.profile == EEsProfile && parseContext.version >= 300)
625 if (parseContext.version < 430)
626 return identifierOrType();
634 return es30ReservedFromGLSL(420);
637 if (parseContext.profile == EEsProfile || parseContext.version < 420)
643 if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
644 parseContext.profile != EEsProfile && parseContext.version < 140)
645 return identifierOrType();
651 return es30ReservedFromGLSL(400);
654 case MEDIUM_PRECISION:
657 return precisionKeyword();
708 return firstGenerationImage();
711 case IIMAGECUBEARRAY:
712 case UIMAGECUBEARRAY:
717 case IIMAGE2DMSARRAY:
718 case UIMAGE2DMSARRAY:
719 return secondGenerationImage();
725 case SAMPLERCUBEARRAY:
726 case SAMPLERCUBEARRAYSHADOW:
727 case ISAMPLERCUBEARRAY:
728 case USAMPLERCUBEARRAY:
730 if (parseContext.profile == EEsProfile || parseContext.version < 400)
735 case ISAMPLER1DARRAY:
736 case SAMPLER1DARRAYSHADOW:
738 case USAMPLER1DARRAY:
741 return es30ReservedFromGLSL(130);
747 case SAMPLERCUBESHADOW:
749 case SAMPLER2DARRAYSHADOW:
753 case ISAMPLER2DARRAY:
757 case USAMPLER2DARRAY:
759 return nonreservedKeyword(300, 130);
766 return es30ReservedFromGLSL(140);
771 case SAMPLER2DMSARRAY:
772 case ISAMPLER2DMSARRAY:
773 case USAMPLER2DMSARRAY:
775 return es30ReservedFromGLSL(150);
778 case SAMPLER1DSHADOW:
780 if (parseContext.profile == EEsProfile)
785 case SAMPLER2DSHADOW:
787 if (parseContext.profile == EEsProfile && parseContext.version < 300)
792 case SAMPLER2DRECTSHADOW:
794 if (parseContext.profile == EEsProfile ||
795 parseContext.profile != EEsProfile && parseContext.version < 140)
801 if (parseContext.profile == EEsProfile && parseContext.version == 300)
803 else if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
804 parseContext.profile != EEsProfile && parseContext.version < 130)
805 return identifierOrType();
809 return es30ReservedFromGLSL(130);
812 if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
813 parseContext.profile != EEsProfile && parseContext.version < 130)
814 return identifierOrType();
818 if (parseContext.profile == EEsProfile && parseContext.version < 300)
820 else if (parseContext.profile != EEsProfile && parseContext.version < 130)
821 return identifierOrType();
825 if (parseContext.version < 120)
826 return identifierOrType();
830 if (parseContext.profile == EEsProfile ||
831 parseContext.profile != EEsProfile && parseContext.version < 400)
832 return identifierOrType();
836 if (parseContext.profile != EEsProfile && parseContext.version < 120)
837 return identifierOrType();
841 if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
842 parseContext.profile != EEsProfile && parseContext.version < 330)
843 return reservedWord();
844 return identifierOrType();
848 bool reserved = parseContext.profile == EEsProfile && parseContext.version >= 300 ||
849 parseContext.profile != EEsProfile && parseContext.version >= 420;
850 return identifierOrReserved(reserved);
854 bool reserved = parseContext.profile == EEsProfile || parseContext.version >= 130;
855 return identifierOrReserved(reserved);
859 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
864 int TScanContext::identifierOrType()
866 parserToken->sType.lex.string = NewPoolTString(tokenText);
870 return FIELD_SELECTION;
873 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
874 if (afterType == false && parserToken->sType.lex.symbol) {
875 if (TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
876 if (variable->isUserType()) {
887 int TScanContext::reservedWord()
889 parseContext.error(loc, "Reserved word.", tokenText, "", "");
894 int TScanContext::identifierOrReserved(bool reserved)
902 if (parseContext.forwardCompatible)
903 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
905 return identifierOrType();
908 // For keywords that suddenly showed up on non-ES (not previously reserved)
909 // but then got reserved by ES 3.0.
910 int TScanContext::es30ReservedFromGLSL(int version)
912 if (parseContext.profile == EEsProfile && parseContext.version < 300 ||
913 parseContext.profile != EEsProfile && parseContext.version < version) {
914 if (parseContext.forwardCompatible)
915 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
917 return identifierOrType();
918 } else if (parseContext.profile == EEsProfile && parseContext.version >= 300)
924 // For a keyword that was never reserved, until it suddenly
925 // showed up, both in an es version and a non-ES version.
926 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
928 if (parseContext.profile == EEsProfile && parseContext.version < esVersion ||
929 parseContext.profile != EEsProfile && parseContext.version < nonEsVersion) {
930 if (parseContext.forwardCompatible)
931 parseContext.warn(loc, "using future keyword", tokenText, "");
933 return identifierOrType();
939 int TScanContext::precisionKeyword()
941 if (parseContext.profile == EEsProfile || parseContext.version >= 130)
944 if (parseContext.forwardCompatible)
945 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
947 return identifierOrType();
950 int TScanContext::matNxM()
954 if (parseContext.version > 110)
957 if (parseContext.forwardCompatible)
958 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
960 return identifierOrType();
963 int TScanContext::dMat()
967 if (parseContext.profile == EEsProfile && parseContext.version >= 300) {
973 if (parseContext.profile != EEsProfile && parseContext.version >= 400)
976 if (parseContext.forwardCompatible)
977 parseContext.warn(loc, "using future type keyword", tokenText, "");
979 return identifierOrType();
982 int TScanContext::firstGenerationImage()
986 if (parseContext.profile != EEsProfile && parseContext.version >= 420)
989 if (parseContext.profile == EEsProfile && parseContext.version >= 300 ||
990 parseContext.profile != EEsProfile && parseContext.version >= 130) {
996 if (parseContext.forwardCompatible)
997 parseContext.warn(loc, "using future type keyword", tokenText, "");
999 return identifierOrType();
1002 int TScanContext::secondGenerationImage()
1006 if (parseContext.profile != EEsProfile && parseContext.version >= 420)
1009 if (parseContext.forwardCompatible)
1010 parseContext.warn(loc, "using future type keyword", tokenText, "");
1012 return identifierOrType();