Scan.cpp 71 KB

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