glsl.y 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. %{
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <stddef.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. #include "glsl_parser.h" //For context struct
  11. #include "glsl.parser.h" //For GLSL_STYPE and GLSL_LTYPE
  12. #include "glsl.lexer.h" //For glsl_lex()
  13. static void glsl_error(GLSL_LTYPE *loc, struct glsl_parse_context *c, const char *s);
  14. #define GLSL_STACK_BUFFER_SIZE (1024*1024)
  15. #define GLSL_STACK_BUFFER_PAYLOAD_SIZE (GLSL_STACK_BUFFER_SIZE - sizeof(intptr_t))
  16. uint8_t *glsl_parse_alloc(struct glsl_parse_context *context, size_t size, int align)
  17. {
  18. uint8_t *ret;
  19. if (size + align > (context->cur_buffer_end - context->cur_buffer)) {
  20. uint8_t *next_buffer = (uint8_t *)malloc(GLSL_STACK_BUFFER_SIZE);
  21. if (context->cur_buffer) {
  22. uint8_t **pnext = (uint8_t **)context->cur_buffer_end;
  23. *pnext = next_buffer;
  24. }
  25. context->cur_buffer_start = next_buffer;
  26. context->cur_buffer = next_buffer;
  27. context->cur_buffer_end = next_buffer + GLSL_STACK_BUFFER_PAYLOAD_SIZE;
  28. if (!context->first_buffer) {
  29. context->first_buffer = context->cur_buffer;
  30. }
  31. *((uint8_t **)context->cur_buffer_end) = NULL;
  32. }
  33. ret = context->cur_buffer;
  34. uint8_t *trunc = (uint8_t *)((~((intptr_t)align - 1)) & ((intptr_t)ret));
  35. if (trunc != ret) {
  36. ret = trunc + align;
  37. }
  38. context->cur_buffer = ret + size;
  39. return ret;
  40. }
  41. void glsl_parse_dealloc(struct glsl_parse_context *context)
  42. {
  43. uint8_t *buffer = context->first_buffer;
  44. while (buffer) {
  45. uint8_t *next = *((uint8_t **)(buffer + GLSL_STACK_BUFFER_PAYLOAD_SIZE));
  46. free(buffer);
  47. buffer = next;
  48. }
  49. }
  50. static char *glsl_parse_strdup(struct glsl_parse_context *context, const char *c)
  51. {
  52. int len = strlen(c);
  53. char *ret = (char *)glsl_parse_alloc(context, len + 1, 1);
  54. strcpy(ret, c);
  55. return ret;
  56. }
  57. struct glsl_node *new_glsl_node(struct glsl_parse_context *context, int code, ...)
  58. {
  59. struct glsl_node *temp;
  60. int i;
  61. int n = 0;
  62. va_list vl;
  63. va_start(vl, code);
  64. while (1) {
  65. temp = va_arg(vl, struct glsl_node *);
  66. if (temp)
  67. n++;
  68. else
  69. break;
  70. }
  71. va_end(vl);
  72. struct glsl_node *g = (struct glsl_node *)glsl_parse_alloc(context, offsetof(struct glsl_node, children[n]), 8);
  73. g->code = code;
  74. g->child_count = n;
  75. va_start(vl, code);
  76. for (i = 0; i < n; i++) {
  77. temp = va_arg(vl, struct glsl_node *);
  78. g->children[i] = temp;
  79. }
  80. va_end(vl);
  81. return g;
  82. }
  83. static struct glsl_node *new_glsl_identifier(struct glsl_parse_context *context, const char *str)
  84. {
  85. struct glsl_node *n = new_glsl_node(context, IDENTIFIER, NULL);
  86. if (!str)
  87. n->data.str = NULL;
  88. else
  89. n->data.str = glsl_parse_strdup(context, str);
  90. return n;
  91. }
  92. #define scanner context->scanner //To allow the scanner to find it's context
  93. %}
  94. %defines
  95. %define api.prefix {glsl_}
  96. %define api.value.type union
  97. %pure-parser
  98. %parse-param { struct glsl_parse_context * context }
  99. %lex-param { void * scanner }
  100. %locations
  101. %type <struct glsl_node *> translation_unit
  102. %type <struct glsl_node *> external_declaration
  103. %type <struct glsl_node *> function_definition
  104. %type <struct glsl_node *> compound_statement_no_new_scope
  105. %type <struct glsl_node *> statement
  106. %type <struct glsl_node *> statement_list
  107. %type <struct glsl_node *> compound_statement
  108. %type <struct glsl_node *> simple_statement
  109. %type <struct glsl_node *> declaration
  110. %type <struct glsl_node *> identifier_list
  111. %type <struct glsl_node *> init_declarator_list
  112. %type <struct glsl_node *> single_declaration
  113. %type <struct glsl_node *> initializer
  114. %type <struct glsl_node *> initializer_list
  115. %type <struct glsl_node *> expression_statement
  116. %type <struct glsl_node *> selection_statement
  117. %type <struct glsl_node *> switch_statement
  118. %type <struct glsl_node *> switch_statement_list
  119. %type <struct glsl_node *> case_label
  120. %type <struct glsl_node *> iteration_statement
  121. %type <struct glsl_node *> statement_no_new_scope
  122. %type <struct glsl_node *> for_init_statement
  123. %type <struct glsl_node *> conditionopt
  124. %type <struct glsl_node *> condition
  125. %type <struct glsl_node *> for_rest_statement
  126. %type <struct glsl_node *> jump_statement
  127. %type <struct glsl_node *> function_prototype
  128. %type <struct glsl_node *> function_declarator
  129. %type <struct glsl_node *> parameter_declaration
  130. %type <struct glsl_node *> parameter_declarator
  131. %type <struct glsl_node *> function_header
  132. %type <struct glsl_node *> function_parameter_list
  133. %type <struct glsl_node *> fully_specified_type
  134. %type <struct glsl_node *> parameter_type_specifier
  135. %type <struct glsl_node *> primary_expression
  136. %type <struct glsl_node *> expression
  137. %type <struct glsl_node *> assignment_expression
  138. %type <struct glsl_node *> conditional_expression
  139. %type <struct glsl_node *> logical_or_expression
  140. %type <struct glsl_node *> logical_xor_expression
  141. %type <struct glsl_node *> logical_and_expression
  142. %type <struct glsl_node *> exclusive_or_expression
  143. %type <struct glsl_node *> constant_expression
  144. %type <struct glsl_node *> and_expression
  145. %type <struct glsl_node *> equality_expression
  146. %type <struct glsl_node *> relational_expression
  147. %type <struct glsl_node *> shift_expression
  148. %type <struct glsl_node *> additive_expression
  149. %type <struct glsl_node *> multiplicative_expression
  150. %type <struct glsl_node *> unary_expression
  151. %type <struct glsl_node *> postfix_expression
  152. %type <struct glsl_node *> integer_expression
  153. %type <struct glsl_node *> inclusive_or_expression
  154. %type <struct glsl_node *> function_call
  155. %type <struct glsl_node *> function_call_or_method
  156. %type <struct glsl_node *> function_call_generic
  157. %type <struct glsl_node *> function_call_parameter_list
  158. %type <struct glsl_node *> function_identifier
  159. %type <struct glsl_node *> type_specifier
  160. %type <struct glsl_node *> type_specifier_nonarray
  161. %type <struct glsl_node *> struct_specifier
  162. %type <struct glsl_node *> array_specifier
  163. %type <struct glsl_node *> array_specifier_list
  164. %type <struct glsl_node *> struct_declaration_list
  165. %type <struct glsl_node *> struct_declaration
  166. %type <struct glsl_node *> struct_declarator_list
  167. %type <struct glsl_node *> struct_declarator
  168. %type <struct glsl_node *> type_qualifier
  169. %type <struct glsl_node *> single_type_qualifier
  170. %type <struct glsl_node *> layout_qualifier
  171. %type <struct glsl_node *> layout_qualifier_id_list
  172. %type <struct glsl_node *> layout_qualifier_id
  173. %type <struct glsl_node *> precision_qualifier
  174. %type <struct glsl_node *> invariant_qualifier
  175. %type <struct glsl_node *> precise_qualifier
  176. %type <struct glsl_node *> storage_qualifier
  177. %type <struct glsl_node *> interpolation_qualifier
  178. %type <struct glsl_node *> type_name_list
  179. %type <struct glsl_node *> variable_identifier
  180. %type <struct glsl_node *> decl_identifier
  181. %type <struct glsl_node *> block_identifier
  182. %type <struct glsl_node *> section_identifier
  183. %type <struct glsl_node *> struct_name
  184. %type <struct glsl_node *> type_name
  185. %type <struct glsl_node *> param_name
  186. %type <struct glsl_node *> function_name
  187. %type <struct glsl_node *> field_selection
  188. %type <struct glsl_node *> type_specifier_identifier
  189. %type <struct glsl_node *> layout_identifier
  190. %type <struct glsl_node *> section_statement
  191. %type <struct glsl_node *> declaration_statement_list
  192. %type <int> assignment_operator
  193. %type <int> unary_operator
  194. %token CONST
  195. %token BOOL
  196. %token FLOAT
  197. %token DOUBLE
  198. %token INT
  199. %token UINT
  200. %token BREAK
  201. %token CONTINUE
  202. %token DO
  203. %token ELSE
  204. %token FOR
  205. %token IF
  206. %token DISCARD
  207. %token RETURN
  208. %token RETURN_VALUE
  209. %token SWITCH
  210. %token CASE
  211. %token DEFAULT
  212. %token SUBROUTINE
  213. %token BVEC2
  214. %token BVEC3
  215. %token BVEC4
  216. %token IVEC2
  217. %token IVEC3
  218. %token IVEC4
  219. %token UVEC2
  220. %token UVEC3
  221. %token UVEC4
  222. %token VEC2
  223. %token VEC3
  224. %token VEC4
  225. %token MAT2
  226. %token MAT3
  227. %token MAT4
  228. %token CENTROID
  229. %token IN
  230. %token OUT
  231. %token INOUT
  232. %token UNIFORM
  233. %token PATCH
  234. %token SAMPLE
  235. %token BUFFER
  236. %token SHARED
  237. %token COHERENT
  238. %token VOLATILE
  239. %token RESTRICT
  240. %token READONLY
  241. %token WRITEONLY
  242. %token DVEC2
  243. %token DVEC3
  244. %token DVEC4
  245. %token DMAT2
  246. %token DMAT3
  247. %token DMAT4
  248. %token NOPERSPECTIVE
  249. %token FLAT
  250. %token SMOOTH
  251. %token LAYOUT
  252. %token MAT2X2
  253. %token MAT2X3
  254. %token MAT2X4
  255. %token MAT3X2
  256. %token MAT3X3
  257. %token MAT3X4
  258. %token MAT4X2
  259. %token MAT4X3
  260. %token MAT4X4
  261. %token DMAT2X2
  262. %token DMAT2X3
  263. %token DMAT2X4
  264. %token DMAT3X2
  265. %token DMAT3X3
  266. %token DMAT3X4
  267. %token DMAT4X2
  268. %token DMAT4X3
  269. %token DMAT4X4
  270. %token ATOMIC_UINT
  271. %token SAMPLER1D
  272. %token SAMPLER2D
  273. %token SAMPLER3D
  274. %token SAMPLERCUBE
  275. %token SAMPLER1DSHADOW
  276. %token SAMPLER2DSHADOW
  277. %token SAMPLERCUBESHADOW
  278. %token SAMPLER1DARRAY
  279. %token SAMPLER2DARRAY
  280. %token SAMPLER1DARRAYSHADOW
  281. %token SAMPLER2DARRAYSHADOW
  282. %token ISAMPLER1D
  283. %token ISAMPLER2D
  284. %token ISAMPLER3D
  285. %token ISAMPLERCUBE
  286. %token ISAMPLER1DARRAY
  287. %token ISAMPLER2DARRAY
  288. %token USAMPLER1D
  289. %token USAMPLER2D
  290. %token USAMPLER3D
  291. %token USAMPLERCUBE
  292. %token USAMPLER1DARRAY
  293. %token USAMPLER2DARRAY
  294. %token SAMPLER2DRECT
  295. %token SAMPLER2DRECTSHADOW
  296. %token ISAMPLER2DRECT
  297. %token USAMPLER2DRECT
  298. %token SAMPLERBUFFER
  299. %token ISAMPLERBUFFER
  300. %token USAMPLERBUFFER
  301. %token SAMPLERCUBEARRAY
  302. %token SAMPLERCUBEARRAYSHADOW
  303. %token ISAMPLERCUBEARRAY
  304. %token USAMPLERCUBEARRAY
  305. %token SAMPLER2DMS
  306. %token ISAMPLER2DMS
  307. %token USAMPLER2DMS
  308. %token SAMPLER2DMSARRAY
  309. %token ISAMPLER2DMSARRAY
  310. %token USAMPLER2DMSARRAY
  311. %token IMAGE1D
  312. %token IIMAGE1D
  313. %token UIMAGE1D
  314. %token IMAGE2D
  315. %token IIMAGE2D
  316. %token UIMAGE2D
  317. %token IMAGE3D
  318. %token IIMAGE3D
  319. %token UIMAGE3D
  320. %token IMAGE2DRECT
  321. %token IIMAGE2DRECT
  322. %token UIMAGE2DRECT
  323. %token IMAGECUBE
  324. %token IIMAGECUBE
  325. %token UIMAGECUBE
  326. %token IMAGEBUFFER
  327. %token IIMAGEBUFFER
  328. %token UIMAGEBUFFER
  329. %token IMAGE1DARRAY
  330. %token IIMAGE1DARRAY
  331. %token UIMAGE1DARRAY
  332. %token IMAGE2DARRAY
  333. %token IIMAGE2DARRAY
  334. %token UIMAGE2DARRAY
  335. %token IMAGECUBEARRAY
  336. %token IIMAGECUBEARRAY
  337. %token UIMAGECUBEARRAY
  338. %token IMAGE2DMS
  339. %token IIMAGE2DMS
  340. %token UIMAGE2DMS
  341. %token IMAGE2DMSARRAY
  342. %token IIMAGE2DMSARRAY
  343. %token UIMAGE2DMSARRAY
  344. %token STRUCT
  345. %token VOID
  346. %token WHILE
  347. %token <char *> IDENTIFIER
  348. %token <float> FLOATCONSTANT
  349. %token <double> DOUBLECONSTANT
  350. %token <int> INTCONSTANT
  351. %token <unsigned int> UINTCONSTANT
  352. %token TRUE_VALUE
  353. %token FALSE_VALUE
  354. %token LEFT_OP
  355. %token RIGHT_OP
  356. %token INC_OP
  357. %token DEC_OP
  358. %token LE_OP
  359. %token GE_OP
  360. %token EQ_OP
  361. %token NE_OP
  362. %token AND_OP
  363. %token OR_OP
  364. %token XOR_OP
  365. %token MUL_ASSIGN
  366. %token DIV_ASSIGN
  367. %token ADD_ASSIGN
  368. %token MOD_ASSIGN
  369. %token LEFT_ASSIGN
  370. %token RIGHT_ASSIGN
  371. %token AND_ASSIGN
  372. %token XOR_ASSIGN
  373. %token OR_ASSIGN
  374. %token SUB_ASSIGN
  375. %token LEFT_PAREN
  376. %token RIGHT_PAREN
  377. %token LEFT_BRACKET
  378. %token RIGHT_BRACKET
  379. %token LEFT_BRACE
  380. %token RIGHT_BRACE
  381. %token DOT
  382. %token COMMA
  383. %token COLON
  384. %token EQUAL
  385. %token SEMICOLON
  386. %token BANG
  387. %token DASH
  388. %token TILDE
  389. %token PLUS
  390. %token STAR
  391. %token SLASH
  392. %token PERCENT
  393. %token LEFT_ANGLE
  394. %token RIGHT_ANGLE
  395. %token VERTICAL_BAR
  396. %token CARET
  397. %token AMPERSAND
  398. %token QUESTION
  399. %token INVARIANT
  400. %token PRECISE
  401. %token HIGHP
  402. %token MEDIUMP
  403. %token LOWP
  404. %token PRECISION
  405. %token UNARY_PLUS
  406. %token UNARY_DASH
  407. %token PRE_INC_OP
  408. %token PRE_DEC_OP
  409. %token POST_DEC_OP
  410. %token POST_INC_OP
  411. %token ARRAY_REF_OP
  412. %token FUNCTION_CALL
  413. %token TYPE_NAME_LIST
  414. %token TYPE_SPECIFIER
  415. %token POSTFIX_EXPRESSION
  416. %token TYPE_QUALIFIER_LIST
  417. %token STRUCT_DECLARATION
  418. %token STRUCT_DECLARATOR
  419. %token STRUCT_SPECIFIER
  420. %token FUNCTION_DEFINITION
  421. %token DECLARATION
  422. %token STATEMENT_LIST
  423. %token TRANSLATION_UNIT
  424. %token PRECISION_DECLARATION
  425. %token BLOCK_DECLARATION
  426. %token TYPE_QUALIFIER_DECLARATION
  427. %token IDENTIFIER_LIST
  428. %token INIT_DECLARATOR_LIST
  429. %token FULLY_SPECIFIED_TYPE
  430. %token SINGLE_DECLARATION
  431. %token SINGLE_INIT_DECLARATION
  432. %token INITIALIZER_LIST
  433. %token EXPRESSION_STATEMENT
  434. %token SELECTION_STATEMENT
  435. %token SELECTION_STATEMENT_ELSE
  436. %token SWITCH_STATEMENT
  437. %token FOR_REST_STATEMENT
  438. %token WHILE_STATEMENT
  439. %token DO_STATEMENT
  440. %token FOR_STATEMENT
  441. %token CASE_LABEL
  442. %token CONDITION_OPT
  443. %token ASSIGNMENT_CONDITION
  444. %token EXPRESSION_CONDITION
  445. %token FUNCTION_HEADER
  446. %token FUNCTION_DECLARATION
  447. %token FUNCTION_PARAMETER_LIST
  448. %token PARAMETER_DECLARATION
  449. %token PARAMETER_DECLARATOR
  450. %token UNINITIALIZED_DECLARATION
  451. %token ARRAY_SPECIFIER
  452. %token ARRAY_SPECIFIER_LIST
  453. %token STRUCT_DECLARATOR_LIST
  454. %token FUNCTION_CALL_PARAMETER_LIST
  455. %token STRUCT_DECLARATION_LIST
  456. %token LAYOUT_QUALIFIER_ID
  457. %token LAYOUT_QUALIFIER_ID_LIST
  458. %token SUBROUTINE_TYPE
  459. %token PAREN_EXPRESSION
  460. %token INIT_DECLARATOR
  461. %token INITIALIZER
  462. %token TERNARY_EXPRESSION
  463. %token SECTION
  464. %token DECLARATION_STATEMENT_LIST
  465. %token SECTION_STATEMENT
  466. %token INITIALIZER_OPT
  467. %token NUM_GLSL_TOKEN
  468. %%
  469. root : { context->root = new_glsl_node(context, TRANSLATION_UNIT, NULL); }
  470. | translation_unit { context->root = $1; }
  471. ;
  472. translation_unit : external_declaration
  473. { $$ = new_glsl_node(context, TRANSLATION_UNIT, $1, NULL); }
  474. | translation_unit external_declaration
  475. { $$ = new_glsl_node(context, TRANSLATION_UNIT, $1, $2, NULL); }
  476. ;
  477. section_statement : SECTION section_identifier LEFT_BRACE declaration_statement_list RIGHT_BRACE SEMICOLON
  478. { $$ = new_glsl_node(context,SECTION_STATEMENT, $2, $4, NULL); }
  479. ;
  480. declaration_statement_list : declaration
  481. { $$ = new_glsl_node(context, DECLARATION_STATEMENT_LIST, $1, NULL); }
  482. | declaration_statement_list declaration
  483. { $$ = new_glsl_node(context, DECLARATION_STATEMENT_LIST, $1, $2, NULL); }
  484. ;
  485. block_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  486. ;
  487. decl_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  488. ;
  489. struct_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  490. ;
  491. type_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  492. ;
  493. param_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  494. ;
  495. function_name : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  496. ;
  497. field_selection : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  498. ;
  499. variable_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  500. ;
  501. layout_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  502. ;
  503. type_specifier_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  504. ;
  505. section_identifier : IDENTIFIER { $$ = new_glsl_identifier(context, $1); }
  506. ;
  507. external_declaration : function_definition { $$ = $1; }
  508. | declaration { $$ = $1; }
  509. | section_statement { $$ = $1; }
  510. ;
  511. function_definition : function_prototype compound_statement_no_new_scope
  512. { $$ = new_glsl_node(context, FUNCTION_DEFINITION,
  513. $1,
  514. $2,
  515. NULL); }
  516. | function_prototype
  517. { $$ = new_glsl_node(context, FUNCTION_DEFINITION,
  518. $1,
  519. new_glsl_node(context, STATEMENT_LIST, NULL),
  520. NULL); }
  521. ;
  522. compound_statement_no_new_scope : LEFT_BRACE RIGHT_BRACE { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
  523. | LEFT_BRACE statement_list RIGHT_BRACE { $$ = $2; }
  524. ;
  525. statement : compound_statement { $$ = $1; }
  526. | simple_statement { $$ = $1; }
  527. ;
  528. statement_list : statement { $$ = new_glsl_node(context, STATEMENT_LIST, $1, NULL); }
  529. | statement_list statement { $$ = new_glsl_node(context, STATEMENT_LIST, $1, $2, NULL); }
  530. ;
  531. compound_statement : LEFT_BRACE RIGHT_BRACE { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
  532. | LEFT_BRACE statement_list RIGHT_BRACE { $$ = $2; }
  533. ;
  534. simple_statement : declaration { $$ = $1; }
  535. | expression_statement { $$ = $1; }
  536. | selection_statement { $$ = $1; }
  537. | switch_statement { $$ = $1; }
  538. | case_label { $$= $1; }
  539. | iteration_statement { $$ = $1; }
  540. | jump_statement { $$ = $1; }
  541. ;
  542. declaration : function_prototype SEMICOLON { $$ = new_glsl_node(context, DECLARATION, $1, NULL); }
  543. | init_declarator_list SEMICOLON { $$ = new_glsl_node(context, DECLARATION, $1, NULL); }
  544. | PRECISION precision_qualifier type_specifier SEMICOLON
  545. { $$ = new_glsl_node(context, DECLARATION,
  546. new_glsl_node(context, PRECISION_DECLARATION,
  547. $2,
  548. $3,
  549. NULL),
  550. NULL); }
  551. | type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON
  552. { $$ = new_glsl_node(context, DECLARATION,
  553. new_glsl_node(context, BLOCK_DECLARATION,
  554. $1,
  555. $2,
  556. $4,
  557. new_glsl_identifier(context, NULL),
  558. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  559. NULL),
  560. NULL); }
  561. | type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE decl_identifier SEMICOLON
  562. { $$ = new_glsl_node(context, DECLARATION,
  563. new_glsl_node(context, BLOCK_DECLARATION,
  564. $1,
  565. $2,
  566. $4,
  567. $6,
  568. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  569. NULL),
  570. NULL); }
  571. | type_qualifier block_identifier LEFT_BRACE struct_declaration_list RIGHT_BRACE decl_identifier array_specifier_list SEMICOLON
  572. { $$ = new_glsl_node(context, DECLARATION,
  573. new_glsl_node(context, BLOCK_DECLARATION,
  574. $1,
  575. $2,
  576. $4,
  577. $6,
  578. $7,
  579. NULL),
  580. NULL); }
  581. | type_qualifier SEMICOLON
  582. { $$ = new_glsl_node(context, DECLARATION,
  583. new_glsl_node(context, UNINITIALIZED_DECLARATION,
  584. $1,
  585. new_glsl_identifier(context, NULL),
  586. NULL),
  587. NULL); }
  588. | type_qualifier type_name SEMICOLON
  589. { $$ = new_glsl_node(context, DECLARATION,
  590. new_glsl_node(context, UNINITIALIZED_DECLARATION,
  591. $1,
  592. $2,
  593. new_glsl_node(context, IDENTIFIER_LIST, NULL),
  594. NULL),
  595. NULL); }
  596. | type_qualifier type_name identifier_list SEMICOLON
  597. { $$ = new_glsl_node(context, DECLARATION,
  598. new_glsl_node(context, UNINITIALIZED_DECLARATION,
  599. $1,
  600. $2,
  601. $3,
  602. NULL),
  603. NULL); }
  604. ;
  605. identifier_list : COMMA decl_identifier { $$ = new_glsl_node(context, IDENTIFIER_LIST, $2, NULL); }
  606. | identifier_list COMMA decl_identifier
  607. { $$ = new_glsl_node(context, IDENTIFIER_LIST, $1, $3, NULL); }
  608. ;
  609. init_declarator_list : single_declaration { $$ = $1; }
  610. | init_declarator_list COMMA decl_identifier
  611. { $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
  612. $1,
  613. new_glsl_node(context, INIT_DECLARATOR,
  614. $3,
  615. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  616. NULL),
  617. NULL); }
  618. | init_declarator_list COMMA decl_identifier array_specifier_list
  619. { $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
  620. $1,
  621. new_glsl_node(context, INIT_DECLARATOR,
  622. $3,
  623. $4,
  624. NULL),
  625. NULL); }
  626. | init_declarator_list COMMA decl_identifier array_specifier_list EQUAL initializer
  627. { $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
  628. $1,
  629. new_glsl_node(context, INIT_DECLARATOR,
  630. $3,
  631. $4,
  632. $6,
  633. NULL),
  634. NULL); }
  635. | init_declarator_list COMMA decl_identifier EQUAL initializer
  636. { $$ = new_glsl_node(context, INIT_DECLARATOR_LIST,
  637. $1,
  638. new_glsl_node(context, INIT_DECLARATOR,
  639. $3,
  640. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  641. $5,
  642. NULL),
  643. NULL); }
  644. ;
  645. single_declaration : fully_specified_type
  646. { $$ = new_glsl_node(context, SINGLE_DECLARATION,
  647. $1,
  648. new_glsl_identifier(context, NULL),
  649. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  650. NULL); }
  651. | fully_specified_type decl_identifier
  652. { $$ = new_glsl_node(context, SINGLE_DECLARATION,
  653. $1,
  654. $2,
  655. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  656. NULL); }
  657. | fully_specified_type decl_identifier array_specifier_list
  658. { $$ = new_glsl_node(context, SINGLE_DECLARATION, $1, $2, $3, NULL); }
  659. | fully_specified_type decl_identifier array_specifier_list EQUAL initializer
  660. { $$ = new_glsl_node(context, SINGLE_INIT_DECLARATION, $1, $2, $3, $5, NULL); }
  661. | fully_specified_type decl_identifier EQUAL initializer
  662. { $$ = new_glsl_node(context, SINGLE_INIT_DECLARATION,
  663. $1,
  664. $2,
  665. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  666. $4,
  667. NULL); }
  668. ;
  669. initializer : assignment_expression { $$ = new_glsl_node(context, INITIALIZER, $1, NULL); }
  670. | LEFT_BRACE initializer_list RIGHT_BRACE { $$ = new_glsl_node(context, INITIALIZER, $2, NULL); }
  671. | LEFT_BRACE initializer_list COMMA RIGHT_BRACE { $$ = new_glsl_node(context, INITIALIZER, $2, NULL); }
  672. ;
  673. initializer_list : initializer
  674. { $$ = new_glsl_node(context, INITIALIZER_LIST, $1, NULL); }
  675. | initializer_list COMMA initializer
  676. { $$ = new_glsl_node(context, INITIALIZER_LIST, $1, $3, NULL); }
  677. ;
  678. expression_statement : SEMICOLON { $$ = new_glsl_node(context, EXPRESSION_STATEMENT, NULL); }
  679. | expression SEMICOLON { $$ = new_glsl_node(context, EXPRESSION_STATEMENT, $1, NULL); }
  680. ;
  681. selection_statement : IF LEFT_PAREN expression RIGHT_PAREN statement
  682. { $$ = new_glsl_node(context, SELECTION_STATEMENT, $3, $5, NULL); }
  683. | IF LEFT_PAREN expression RIGHT_PAREN statement ELSE statement
  684. { $$ = new_glsl_node(context, SELECTION_STATEMENT_ELSE, $3, $5, $7, NULL); }
  685. ;
  686. switch_statement : SWITCH LEFT_PAREN expression RIGHT_PAREN LEFT_BRACE switch_statement_list RIGHT_BRACE
  687. { $$ = new_glsl_node(context, SWITCH_STATEMENT, $3, $6, NULL); }
  688. ;
  689. switch_statement_list : { $$ = new_glsl_node(context, STATEMENT_LIST, NULL); }
  690. | statement_list { $$ = $1; }
  691. ;
  692. case_label : CASE expression COLON { $$ = new_glsl_node(context, CASE_LABEL, $2, NULL); }
  693. | DEFAULT COLON { $$ = new_glsl_node(context, CASE_LABEL, NULL); }
  694. ;
  695. iteration_statement : WHILE LEFT_PAREN condition RIGHT_PAREN statement_no_new_scope
  696. { $$ = new_glsl_node(context, WHILE_STATEMENT, $3, $5, NULL); }
  697. | DO statement WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
  698. { $$ = new_glsl_node(context, DO_STATEMENT, $2, $5, NULL); }
  699. | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope
  700. { $$ = new_glsl_node(context, FOR_STATEMENT, $3, $4, $6, NULL); }
  701. ;
  702. statement_no_new_scope : compound_statement_no_new_scope { $$ = $1; }
  703. | simple_statement { $$ = $1; }
  704. ;
  705. for_init_statement : expression_statement { $$ = $1; }
  706. | declaration { $$ = $1; }
  707. ;
  708. conditionopt : condition { $$ = new_glsl_node(context, CONDITION_OPT, $1, NULL); }
  709. | { $$ = new_glsl_node(context, CONDITION_OPT, NULL); }
  710. ;
  711. condition : expression
  712. { $$ = new_glsl_node(context, EXPRESSION_CONDITION, $1, NULL); }
  713. | fully_specified_type variable_identifier EQUAL initializer
  714. { $$ = new_glsl_node(context, ASSIGNMENT_CONDITION, $1, $2, $4, NULL); }
  715. ;
  716. for_rest_statement : conditionopt SEMICOLON
  717. { $$ = new_glsl_node(context, FOR_REST_STATEMENT, $1, NULL); }
  718. | conditionopt SEMICOLON expression
  719. { $$ = new_glsl_node(context, FOR_REST_STATEMENT, $1, $3, NULL); }
  720. ;
  721. jump_statement : CONTINUE SEMICOLON
  722. { $$ = new_glsl_node(context, CONTINUE, NULL); }
  723. | BREAK SEMICOLON
  724. { $$ = new_glsl_node(context, BREAK, NULL); }
  725. | RETURN SEMICOLON
  726. { $$ = new_glsl_node(context, RETURN, NULL); }
  727. | RETURN expression SEMICOLON
  728. { $$ = new_glsl_node(context, RETURN_VALUE, $2, NULL); }
  729. | DISCARD SEMICOLON
  730. { $$ = new_glsl_node(context, DISCARD, NULL); }
  731. ;
  732. function_prototype : function_declarator RIGHT_PAREN { $$ = $1; }
  733. ;
  734. function_declarator : function_header
  735. { $$ = new_glsl_node(context, FUNCTION_DECLARATION,
  736. $1,
  737. new_glsl_node(context, FUNCTION_PARAMETER_LIST, NULL),
  738. NULL); }
  739. | function_header function_parameter_list
  740. { $$ = new_glsl_node(context, FUNCTION_DECLARATION,
  741. $1,
  742. $2,
  743. NULL); }
  744. ;
  745. function_parameter_list : parameter_declaration
  746. { $$ = new_glsl_node(context, FUNCTION_PARAMETER_LIST, $1, NULL); }
  747. | function_parameter_list COMMA parameter_declaration
  748. { $$ = new_glsl_node(context, FUNCTION_PARAMETER_LIST, $1, $3, NULL); }
  749. ;
  750. parameter_declaration : type_qualifier parameter_declarator
  751. { $$ = new_glsl_node(context, PARAMETER_DECLARATION, $1, $2, NULL); }
  752. | parameter_declarator
  753. { $$ = new_glsl_node(context, PARAMETER_DECLARATION,
  754. new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
  755. $1,
  756. NULL); }
  757. | type_qualifier parameter_type_specifier
  758. { $$ = new_glsl_node(context, PARAMETER_DECLARATION, $1, $2, NULL); }
  759. | parameter_type_specifier
  760. { $$ = new_glsl_node(context, PARAMETER_DECLARATION,
  761. new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
  762. $1,
  763. NULL); }
  764. ;
  765. parameter_declarator : type_specifier param_name
  766. { $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, $2, NULL); }
  767. | type_specifier param_name array_specifier_list
  768. { $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, $2, $3, NULL);}
  769. ;
  770. function_header : fully_specified_type function_name LEFT_PAREN
  771. { $$ = new_glsl_node(context, FUNCTION_HEADER, $1, $2, NULL); }
  772. ;
  773. fully_specified_type : type_specifier
  774. { $$ = new_glsl_node(context, FULLY_SPECIFIED_TYPE,
  775. new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
  776. $1,
  777. NULL); }
  778. | type_qualifier type_specifier
  779. { $$ = new_glsl_node(context, FULLY_SPECIFIED_TYPE, $1, $2, NULL); }
  780. ;
  781. parameter_type_specifier : type_specifier
  782. { $$ = new_glsl_node(context, PARAMETER_DECLARATOR, $1, NULL); }
  783. ;
  784. type_specifier : type_specifier_nonarray
  785. { $$ = new_glsl_node(context, TYPE_SPECIFIER,
  786. $1,
  787. new_glsl_node(context, ARRAY_SPECIFIER_LIST, NULL),
  788. NULL); }
  789. | type_specifier_nonarray array_specifier_list
  790. { $$ = new_glsl_node(context, TYPE_SPECIFIER, $1, $2, NULL); }
  791. ;
  792. array_specifier_list : array_specifier
  793. { $$ = new_glsl_node(context, ARRAY_SPECIFIER_LIST, $1, NULL); }
  794. | array_specifier_list array_specifier
  795. { $$ = new_glsl_node(context, ARRAY_SPECIFIER_LIST, $1, $2, NULL); }
  796. ;
  797. array_specifier : LEFT_BRACKET RIGHT_BRACKET
  798. { $$ = new_glsl_node(context, ARRAY_SPECIFIER, NULL); }
  799. | LEFT_BRACKET constant_expression RIGHT_BRACKET
  800. { $$ = new_glsl_node(context, ARRAY_SPECIFIER, $2, NULL); }
  801. ;
  802. type_specifier_nonarray : VOID { $$ = new_glsl_node(context, VOID, NULL); }
  803. | FLOAT { $$ = new_glsl_node(context, FLOAT, NULL); }
  804. | DOUBLE { $$ = new_glsl_node(context, DOUBLE, NULL); }
  805. | INT { $$ = new_glsl_node(context, INT, NULL); }
  806. | UINT { $$ = new_glsl_node(context, UINT, NULL); }
  807. | BOOL { $$ = new_glsl_node(context, BOOL, NULL); }
  808. | VEC2 { $$ = new_glsl_node(context, VEC2, NULL); }
  809. | VEC3 { $$ = new_glsl_node(context, VEC3, NULL); }
  810. | VEC4 { $$ = new_glsl_node(context, VEC4, NULL); }
  811. | DVEC2 { $$ = new_glsl_node(context, DVEC2, NULL); }
  812. | DVEC3 { $$ = new_glsl_node(context, DVEC3, NULL); }
  813. | DVEC4 { $$ = new_glsl_node(context, DVEC4, NULL); }
  814. | BVEC2 { $$ = new_glsl_node(context, BVEC2, NULL); }
  815. | BVEC3 { $$ = new_glsl_node(context, BVEC3, NULL); }
  816. | BVEC4 { $$ = new_glsl_node(context, BVEC4, NULL); }
  817. | IVEC2 { $$ = new_glsl_node(context, IVEC2, NULL); }
  818. | IVEC3 { $$ = new_glsl_node(context, IVEC3, NULL); }
  819. | IVEC4 { $$ = new_glsl_node(context, IVEC4, NULL); }
  820. | UVEC2 { $$ = new_glsl_node(context, UVEC2, NULL); }
  821. | UVEC3 { $$ = new_glsl_node(context, UVEC3, NULL); }
  822. | UVEC4 { $$ = new_glsl_node(context, UVEC4, NULL); }
  823. | MAT2 { $$ = new_glsl_node(context, MAT2, NULL); }
  824. | MAT3 { $$ = new_glsl_node(context, MAT3, NULL); }
  825. | MAT4 { $$ = new_glsl_node(context, MAT4, NULL); }
  826. | MAT2X2 { $$ = new_glsl_node(context, MAT2X2, NULL); }
  827. | MAT2X3 { $$ = new_glsl_node(context, MAT2X3, NULL); }
  828. | MAT2X4 { $$ = new_glsl_node(context, MAT2X4, NULL); }
  829. | MAT3X2 { $$ = new_glsl_node(context, MAT3X2, NULL); }
  830. | MAT3X3 { $$ = new_glsl_node(context, MAT3X3, NULL); }
  831. | MAT3X4 { $$ = new_glsl_node(context, MAT3X4, NULL); }
  832. | MAT4X2 { $$ = new_glsl_node(context, MAT4X2, NULL); }
  833. | MAT4X3 { $$ = new_glsl_node(context, MAT4X3, NULL); }
  834. | MAT4X4 { $$ = new_glsl_node(context, MAT4X4, NULL); }
  835. | DMAT2 { $$ = new_glsl_node(context, DMAT2, NULL); }
  836. | DMAT3 { $$ = new_glsl_node(context, DMAT3, NULL); }
  837. | DMAT4 { $$ = new_glsl_node(context, DMAT4, NULL); }
  838. | DMAT2X2 { $$ = new_glsl_node(context, DMAT2X2, NULL); }
  839. | DMAT2X3 { $$ = new_glsl_node(context, DMAT2X3, NULL); }
  840. | DMAT2X4 { $$ = new_glsl_node(context, DMAT2X4, NULL); }
  841. | DMAT3X2 { $$ = new_glsl_node(context, DMAT3X2, NULL); }
  842. | DMAT3X3 { $$ = new_glsl_node(context, DMAT3X3, NULL); }
  843. | DMAT3X4 { $$ = new_glsl_node(context, DMAT3X4, NULL); }
  844. | DMAT4X2 { $$ = new_glsl_node(context, DMAT4X2, NULL); }
  845. | DMAT4X3 { $$ = new_glsl_node(context, DMAT4X3, NULL); }
  846. | DMAT4X4 { $$ = new_glsl_node(context, DMAT4X4, NULL); }
  847. | ATOMIC_UINT { $$ = new_glsl_node(context, UINT, NULL); }
  848. | SAMPLER1D { $$ = new_glsl_node(context, SAMPLER1D, NULL); }
  849. | SAMPLER2D { $$ = new_glsl_node(context, SAMPLER2D, NULL); }
  850. | SAMPLER3D { $$ = new_glsl_node(context, SAMPLER3D, NULL); }
  851. | SAMPLERCUBE { $$ = new_glsl_node(context, SAMPLERCUBE, NULL); }
  852. | SAMPLER1DSHADOW { $$ = new_glsl_node(context, SAMPLER1DSHADOW, NULL); }
  853. | SAMPLER2DSHADOW { $$ = new_glsl_node(context, SAMPLER2DSHADOW, NULL); }
  854. | SAMPLERCUBESHADOW { $$ = new_glsl_node(context, SAMPLERCUBESHADOW, NULL); }
  855. | SAMPLER1DARRAY { $$ = new_glsl_node(context, SAMPLER1DARRAY, NULL); }
  856. | SAMPLER2DARRAY { $$ = new_glsl_node(context, SAMPLER2DARRAY, NULL); }
  857. | SAMPLER1DARRAYSHADOW { $$ = new_glsl_node(context, SAMPLER1DARRAYSHADOW, NULL); }
  858. | SAMPLER2DARRAYSHADOW { $$ = new_glsl_node(context, SAMPLER2DARRAYSHADOW, NULL); }
  859. | SAMPLERCUBEARRAY { $$ = new_glsl_node(context, SAMPLERCUBEARRAY, NULL); }
  860. | SAMPLERCUBEARRAYSHADOW { $$ = new_glsl_node(context, SAMPLERCUBEARRAYSHADOW, NULL); }
  861. | ISAMPLER1D { $$ = new_glsl_node(context, ISAMPLER1D, NULL); }
  862. | ISAMPLER2D { $$ = new_glsl_node(context, ISAMPLER2D, NULL); }
  863. | ISAMPLER3D { $$ = new_glsl_node(context, ISAMPLER3D, NULL); }
  864. | ISAMPLERCUBE { $$ = new_glsl_node(context, ISAMPLERCUBE, NULL); }
  865. | ISAMPLER1DARRAY { $$ = new_glsl_node(context, ISAMPLER1DARRAY, NULL); }
  866. | ISAMPLER2DARRAY { $$ = new_glsl_node(context, ISAMPLER2DARRAY, NULL); }
  867. | ISAMPLERCUBEARRAY { $$ = new_glsl_node(context, ISAMPLERCUBEARRAY, NULL); }
  868. | USAMPLER1D { $$ = new_glsl_node(context, USAMPLER1D, NULL); }
  869. | USAMPLER2D { $$ = new_glsl_node(context, USAMPLER2D, NULL); }
  870. | USAMPLER3D { $$ = new_glsl_node(context, USAMPLER3D, NULL); }
  871. | USAMPLERCUBE { $$ = new_glsl_node(context, USAMPLERCUBE, NULL); }
  872. | USAMPLER1DARRAY { $$ = new_glsl_node(context, USAMPLER1DARRAY, NULL); }
  873. | USAMPLER2DARRAY { $$ = new_glsl_node(context, USAMPLER2DARRAY, NULL); }
  874. | USAMPLERCUBEARRAY { $$ = new_glsl_node(context, USAMPLERCUBEARRAY, NULL); }
  875. | SAMPLER2DRECT { $$ = new_glsl_node(context, SAMPLER2DRECT, NULL); }
  876. | SAMPLER2DRECTSHADOW { $$ = new_glsl_node(context, SAMPLER2DRECTSHADOW, NULL); }
  877. | ISAMPLER2DRECT { $$ = new_glsl_node(context, ISAMPLER2DRECT, NULL); }
  878. | USAMPLER2DRECT { $$ = new_glsl_node(context, USAMPLER2DRECT, NULL); }
  879. | SAMPLERBUFFER { $$ = new_glsl_node(context, SAMPLERBUFFER, NULL); }
  880. | ISAMPLERBUFFER { $$ = new_glsl_node(context, ISAMPLERBUFFER, NULL); }
  881. | USAMPLERBUFFER { $$ = new_glsl_node(context, USAMPLERBUFFER, NULL); }
  882. | SAMPLER2DMS { $$ = new_glsl_node(context, SAMPLER2DMS, NULL); }
  883. | ISAMPLER2DMS { $$ = new_glsl_node(context, ISAMPLER2DMS, NULL); }
  884. | USAMPLER2DMS { $$ = new_glsl_node(context, USAMPLER2DMS, NULL); }
  885. | SAMPLER2DMSARRAY { $$ = new_glsl_node(context, SAMPLER2DMSARRAY, NULL); }
  886. | ISAMPLER2DMSARRAY { $$ = new_glsl_node(context, ISAMPLER2DMSARRAY, NULL); }
  887. | USAMPLER2DMSARRAY { $$ = new_glsl_node(context, USAMPLER2DMSARRAY, NULL); }
  888. | IMAGE1D { $$ = new_glsl_node(context, IMAGE1D, NULL); }
  889. | IIMAGE1D { $$ = new_glsl_node(context, IIMAGE1D, NULL); }
  890. | UIMAGE1D { $$ = new_glsl_node(context, UIMAGE1D, NULL); }
  891. | IMAGE2D { $$ = new_glsl_node(context, IMAGE2D, NULL); }
  892. | IIMAGE2D { $$ = new_glsl_node(context, IIMAGE2D, NULL); }
  893. | UIMAGE2D { $$ = new_glsl_node(context, UIMAGE2D, NULL); }
  894. | IMAGE3D { $$ = new_glsl_node(context, IMAGE3D, NULL); }
  895. | IIMAGE3D { $$ = new_glsl_node(context, IIMAGE3D, NULL); }
  896. | UIMAGE3D { $$ = new_glsl_node(context, UIMAGE3D, NULL); }
  897. | IMAGE2DRECT { $$ = new_glsl_node(context, IMAGE2DRECT, NULL); }
  898. | IIMAGE2DRECT { $$ = new_glsl_node(context, IIMAGE2DRECT, NULL); }
  899. | UIMAGE2DRECT { $$ = new_glsl_node(context, UIMAGE2DRECT, NULL); }
  900. | IMAGECUBE { $$ = new_glsl_node(context, IMAGECUBE, NULL); }
  901. | IIMAGECUBE { $$ = new_glsl_node(context, IIMAGECUBE, NULL); }
  902. | UIMAGECUBE { $$ = new_glsl_node(context, UIMAGECUBE, NULL); }
  903. | IMAGEBUFFER { $$ = new_glsl_node(context, IMAGEBUFFER, NULL); }
  904. | IIMAGEBUFFER { $$ = new_glsl_node(context, IIMAGEBUFFER, NULL); }
  905. | UIMAGEBUFFER { $$ = new_glsl_node(context, UIMAGEBUFFER, NULL); }
  906. | IMAGE1DARRAY { $$ = new_glsl_node(context, IMAGE1DARRAY, NULL); }
  907. | IIMAGE1DARRAY { $$ = new_glsl_node(context, IIMAGE1DARRAY, NULL); }
  908. | UIMAGE1DARRAY { $$ = new_glsl_node(context, UIMAGE1DARRAY, NULL); }
  909. | IMAGE2DARRAY { $$ = new_glsl_node(context, IMAGE2DARRAY, NULL); }
  910. | IIMAGE2DARRAY { $$ = new_glsl_node(context, IIMAGE2DARRAY, NULL); }
  911. | UIMAGE2DARRAY { $$ = new_glsl_node(context, UIMAGE2DARRAY, NULL); }
  912. | IMAGECUBEARRAY { $$ = new_glsl_node(context, IMAGECUBEARRAY, NULL); }
  913. | IIMAGECUBEARRAY { $$ = new_glsl_node(context, IIMAGECUBEARRAY, NULL); }
  914. | UIMAGECUBEARRAY { $$ = new_glsl_node(context, UIMAGECUBEARRAY, NULL); }
  915. | IMAGE2DMS { $$ = new_glsl_node(context, IMAGE2DMS, NULL); }
  916. | IIMAGE2DMS { $$ = new_glsl_node(context, IIMAGE2DMS, NULL); }
  917. | UIMAGE2DMS { $$ = new_glsl_node(context, UIMAGE2DMS, NULL); }
  918. | IMAGE2DMSARRAY { $$ = new_glsl_node(context, IMAGE2DMSARRAY, NULL); }
  919. | IIMAGE2DMSARRAY { $$ = new_glsl_node(context, IIMAGE2DMSARRAY, NULL); }
  920. | UIMAGE2DMSARRAY { $$ = new_glsl_node(context, UIMAGE2DMSARRAY, NULL); }
  921. | struct_specifier { $$ = $1; }
  922. | type_specifier_identifier { $$ = $1; }
  923. ;
  924. struct_specifier : STRUCT struct_name LEFT_BRACE struct_declaration_list RIGHT_BRACE
  925. { $$ = new_glsl_node(context, STRUCT_SPECIFIER, $2, $4, NULL);}
  926. | STRUCT LEFT_BRACE struct_declaration_list RIGHT_BRACE
  927. { $$ = new_glsl_node(context, STRUCT_SPECIFIER,
  928. new_glsl_identifier(context, NULL),
  929. $3,
  930. NULL); }
  931. ;
  932. struct_declaration_list : struct_declaration
  933. { $$ = new_glsl_node(context, STRUCT_DECLARATION_LIST, $1, NULL); }
  934. | struct_declaration_list struct_declaration
  935. { $$ = new_glsl_node(context, STRUCT_DECLARATION_LIST, $1, $2, NULL); }
  936. ;
  937. struct_declaration : type_specifier struct_declarator_list SEMICOLON
  938. { $$ = new_glsl_node(context, STRUCT_DECLARATION,
  939. new_glsl_node(context, TYPE_QUALIFIER_LIST, NULL),
  940. $1,
  941. $2,
  942. NULL); }
  943. | type_qualifier type_specifier struct_declarator_list SEMICOLON
  944. { $$ = new_glsl_node(context, STRUCT_DECLARATION, $1, $2, $3, NULL); }
  945. ;
  946. struct_declarator_list : struct_declarator
  947. { $$ = new_glsl_node(context, STRUCT_DECLARATOR_LIST, $1, NULL); }
  948. | struct_declarator_list COMMA struct_declarator
  949. { $$ = new_glsl_node(context, STRUCT_DECLARATOR_LIST, $1, $3, NULL); }
  950. ;
  951. struct_declarator : decl_identifier
  952. { $$ = new_glsl_node(context, STRUCT_DECLARATOR, $1, NULL); }
  953. | decl_identifier array_specifier_list
  954. { $$ = new_glsl_node(context, STRUCT_DECLARATOR, $1, $2, NULL); }
  955. ;
  956. type_qualifier : single_type_qualifier
  957. { $$ = new_glsl_node(context, TYPE_QUALIFIER_LIST, $1, NULL); }
  958. | type_qualifier single_type_qualifier
  959. { $$ = new_glsl_node(context, TYPE_QUALIFIER_LIST, $1, $2, NULL); }
  960. ;
  961. single_type_qualifier : storage_qualifier { $$ = $1; }
  962. | layout_qualifier { $$ = $1; }
  963. | precision_qualifier { $$ = $1; }
  964. | interpolation_qualifier { $$ = $1; }
  965. | invariant_qualifier { $$ = $1; }
  966. | precise_qualifier { $$ = $1; }
  967. ;
  968. layout_qualifier : LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN { $$ = $3; }
  969. ;
  970. layout_qualifier_id_list: layout_qualifier_id { $$ = $1; }
  971. | layout_qualifier_id_list COMMA layout_qualifier_id
  972. { $$ = new_glsl_node(context, LAYOUT_QUALIFIER_ID_LIST, $1, $3, NULL); }
  973. ;
  974. layout_qualifier_id : layout_identifier
  975. { $$ = new_glsl_node(context, LAYOUT_QUALIFIER_ID, $1, NULL); }
  976. | layout_identifier EQUAL constant_expression
  977. { $$ = new_glsl_node(context, LAYOUT_QUALIFIER_ID, $1, $3, NULL);}
  978. | SHARED
  979. { $$ = new_glsl_node(context, SHARED, NULL); }
  980. ;
  981. precision_qualifier : HIGHP { $$ = new_glsl_node(context, HIGHP, NULL); }
  982. | MEDIUMP { $$ = new_glsl_node(context, MEDIUMP, NULL); }
  983. | LOWP { $$ = new_glsl_node(context, LOWP, NULL); }
  984. ;
  985. interpolation_qualifier : SMOOTH { $$ = new_glsl_node(context, SMOOTH, NULL); }
  986. | FLAT { $$ = new_glsl_node(context, FLAT, NULL); }
  987. | NOPERSPECTIVE { $$ = new_glsl_node(context, NOPERSPECTIVE, NULL); }
  988. ;
  989. invariant_qualifier : INVARIANT { $$ = new_glsl_node(context, INVARIANT, NULL); }
  990. ;
  991. precise_qualifier : PRECISE { $$ = new_glsl_node(context, PRECISE, NULL); }
  992. ;
  993. storage_qualifier : CONST { $$ = new_glsl_node(context, CONST, NULL); }
  994. | INOUT { $$ = new_glsl_node(context, INOUT, NULL); }
  995. | IN { $$ = new_glsl_node(context, IN, NULL); }
  996. | OUT { $$ = new_glsl_node(context, OUT, NULL); }
  997. | CENTROID { $$ = new_glsl_node(context, CENTROID, NULL); }
  998. | PATCH { $$ = new_glsl_node(context, PATCH, NULL); }
  999. | SAMPLE { $$ = new_glsl_node(context, SAMPLE, NULL); }
  1000. | UNIFORM { $$ = new_glsl_node(context, UNIFORM, NULL); }
  1001. | BUFFER { $$ = new_glsl_node(context, BUFFER, NULL); }
  1002. | SHARED { $$ = new_glsl_node(context, SHARED, NULL); }
  1003. | COHERENT { $$ = new_glsl_node(context, COHERENT, NULL); }
  1004. | VOLATILE { $$ = new_glsl_node(context, VOLATILE, NULL); }
  1005. | RESTRICT { $$ = new_glsl_node(context, RESTRICT, NULL); }
  1006. | READONLY { $$ = new_glsl_node(context, READONLY, NULL); }
  1007. | WRITEONLY { $$ = new_glsl_node(context, WRITEONLY, NULL); }
  1008. | SUBROUTINE { $$ = new_glsl_node(context, SUBROUTINE, NULL); }
  1009. | SUBROUTINE LEFT_PAREN type_name_list RIGHT_PAREN
  1010. { $$ = new_glsl_node(context, SUBROUTINE_TYPE,
  1011. new_glsl_node(context, TYPE_NAME_LIST, $3, NULL),
  1012. NULL); }
  1013. ;
  1014. type_name_list : type_name { $$ = $1; }
  1015. | type_name_list COMMA type_name
  1016. { $$ = new_glsl_node(context, TYPE_NAME_LIST, $1, $3, NULL); }
  1017. ;
  1018. expression : assignment_expression { $$ = $1; }
  1019. | expression COMMA assignment_expression
  1020. { $$ = new_glsl_node(context, COMMA, $1, $3, NULL); }
  1021. ;
  1022. assignment_expression : conditional_expression { $$ = $1; }
  1023. | unary_expression assignment_operator assignment_expression
  1024. { $$ = new_glsl_node(context,$2, $1, $3, NULL); }
  1025. ;
  1026. assignment_operator : EQUAL { $$ = EQUAL; }
  1027. | MUL_ASSIGN { $$ = MUL_ASSIGN; }
  1028. | DIV_ASSIGN { $$ = DIV_ASSIGN; }
  1029. | MOD_ASSIGN { $$ = MOD_ASSIGN; }
  1030. | ADD_ASSIGN { $$ = ADD_ASSIGN; }
  1031. | SUB_ASSIGN { $$ = SUB_ASSIGN; }
  1032. | LEFT_ASSIGN { $$ = LEFT_ASSIGN; }
  1033. | RIGHT_ASSIGN { $$ = RIGHT_ASSIGN; }
  1034. | AND_ASSIGN { $$ = AND_ASSIGN; }
  1035. | XOR_ASSIGN { $$ = XOR_ASSIGN; }
  1036. | OR_ASSIGN { $$ = OR_ASSIGN; }
  1037. ;
  1038. constant_expression : conditional_expression { $$ = $1; }
  1039. ;
  1040. conditional_expression : logical_or_expression { $$ = $1; }
  1041. | logical_or_expression QUESTION expression COLON assignment_expression
  1042. { $$ = new_glsl_node(context, TERNARY_EXPRESSION, $1, $3, $5, NULL); }
  1043. ;
  1044. logical_or_expression : logical_xor_expression { $$ = $1; }
  1045. | logical_or_expression OR_OP logical_xor_expression
  1046. { $$ = new_glsl_node(context, OR_OP, $1, $3, NULL); }
  1047. ;
  1048. logical_xor_expression : logical_and_expression { $$ = $1; }
  1049. | logical_xor_expression XOR_OP logical_and_expression
  1050. { $$ = new_glsl_node(context, XOR_OP, $1, $3, NULL); }
  1051. ;
  1052. logical_and_expression : inclusive_or_expression { $$ = $1; }
  1053. | logical_and_expression AND_OP inclusive_or_expression
  1054. { $$ = new_glsl_node(context, AND_OP, $1, $3, NULL); }
  1055. ;
  1056. inclusive_or_expression : exclusive_or_expression { $$ = $1; }
  1057. | inclusive_or_expression VERTICAL_BAR exclusive_or_expression
  1058. { $$ = new_glsl_node(context, VERTICAL_BAR, $1, $3, NULL); }
  1059. ;
  1060. exclusive_or_expression : and_expression { $$ = $1; }
  1061. | exclusive_or_expression CARET and_expression
  1062. { $$ = new_glsl_node(context, CARET, $1, $3, NULL); }
  1063. ;
  1064. and_expression : equality_expression { $$ = $1; }
  1065. | and_expression AMPERSAND equality_expression
  1066. { $$ = new_glsl_node(context, AMPERSAND, $1, $3, NULL); }
  1067. ;
  1068. equality_expression : relational_expression { $$ = $1; }
  1069. | equality_expression EQ_OP relational_expression
  1070. { $$ = new_glsl_node(context, EQ_OP, $1, $3, NULL); }
  1071. | equality_expression NE_OP relational_expression
  1072. { $$ = new_glsl_node(context, NE_OP, $1, $3, NULL); }
  1073. ;
  1074. relational_expression : shift_expression { $$ = $1; }
  1075. | relational_expression LEFT_ANGLE shift_expression
  1076. { $$ = new_glsl_node(context, LEFT_ANGLE, $1, $3, NULL); }
  1077. | relational_expression RIGHT_ANGLE shift_expression
  1078. { $$ = new_glsl_node(context, RIGHT_ANGLE, $1, $3, NULL); }
  1079. | relational_expression LE_OP shift_expression
  1080. { $$ = new_glsl_node(context, LE_OP, $1, $3, NULL); }
  1081. | relational_expression GE_OP shift_expression
  1082. { $$ = new_glsl_node(context, GE_OP, $1, $3, NULL); }
  1083. ;
  1084. shift_expression : additive_expression { $$ = $1; }
  1085. | shift_expression LEFT_OP additive_expression
  1086. { $$ = new_glsl_node(context, LEFT_OP, $1, $3, NULL); }
  1087. | shift_expression RIGHT_OP additive_expression
  1088. { $$ = new_glsl_node(context, RIGHT_OP, $1, $3, NULL); }
  1089. ;
  1090. additive_expression : multiplicative_expression { $$ = $1; }
  1091. | additive_expression PLUS multiplicative_expression
  1092. { $$ = new_glsl_node(context, PLUS, $1, $3, NULL); }
  1093. | additive_expression DASH multiplicative_expression
  1094. { $$ = new_glsl_node(context, DASH, $1, $3, NULL); }
  1095. ;
  1096. multiplicative_expression : unary_expression { $$ = $1; }
  1097. | multiplicative_expression STAR unary_expression
  1098. { $$ = new_glsl_node(context, STAR, $1, $3, NULL); }
  1099. | multiplicative_expression SLASH unary_expression
  1100. { $$ = new_glsl_node(context, SLASH, $1, $3, NULL); }
  1101. | multiplicative_expression PERCENT unary_expression
  1102. { $$ = new_glsl_node(context, PERCENT, $1, $3, NULL); }
  1103. ;
  1104. unary_expression : postfix_expression { $$ = $1; }
  1105. | INC_OP unary_expression
  1106. { $$ = new_glsl_node(context, PRE_INC_OP, $2, NULL); }
  1107. | DEC_OP unary_expression
  1108. { $$ = new_glsl_node(context, PRE_DEC_OP, $2, NULL); }
  1109. | unary_operator unary_expression
  1110. { $$ = new_glsl_node(context,$1, $2, NULL); }
  1111. ;
  1112. unary_operator : PLUS { $$ = UNARY_PLUS; }
  1113. | DASH { $$ = UNARY_DASH; }
  1114. | BANG { $$ = BANG; }
  1115. | TILDE { $$ = TILDE; }
  1116. ;
  1117. postfix_expression : primary_expression { $$ = $1; }
  1118. | postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET
  1119. { $$ = new_glsl_node(context, ARRAY_REF_OP, $1, $3, NULL); }
  1120. | function_call { $$ = $1; }
  1121. | postfix_expression DOT field_selection
  1122. { $$ = new_glsl_node(context, DOT, $1, $3, NULL);}
  1123. | postfix_expression INC_OP
  1124. { $$ = new_glsl_node(context, POST_INC_OP, $1, NULL); }
  1125. | postfix_expression DEC_OP
  1126. { $$ = new_glsl_node(context, POST_DEC_OP, $1, NULL); }
  1127. ;
  1128. integer_expression : expression { $$ = $1; }
  1129. ;
  1130. function_call : function_call_or_method { $$ = $1; }
  1131. ;
  1132. function_call_or_method : function_call_generic { $$ = $1; }
  1133. ;
  1134. function_call_generic : function_identifier LEFT_PAREN function_call_parameter_list RIGHT_PAREN
  1135. { $$ = new_glsl_node(context, FUNCTION_CALL, $1, $3, NULL); }
  1136. | function_identifier LEFT_PAREN LEFT_PAREN
  1137. { $$ = new_glsl_node(context, FUNCTION_CALL,
  1138. $1,
  1139. new_glsl_node(context, FUNCTION_CALL_PARAMETER_LIST, NULL),
  1140. NULL); }
  1141. | function_identifier LEFT_PAREN VOID RIGHT_PAREN
  1142. { $$ = new_glsl_node(context, FUNCTION_CALL,
  1143. $1,
  1144. new_glsl_node(context, FUNCTION_CALL_PARAMETER_LIST, NULL),
  1145. NULL); }
  1146. ;
  1147. function_call_parameter_list : assignment_expression
  1148. { $$ = new_glsl_node(context, FUNCTION_CALL_PARAMETER_LIST, $1, NULL); }
  1149. | function_call_parameter_list COMMA assignment_expression
  1150. { $$ = new_glsl_node(context, FUNCTION_CALL_PARAMETER_LIST, $1, $3, NULL); }
  1151. ;
  1152. function_identifier : type_specifier { $$ = $1; }
  1153. | postfix_expression
  1154. { $$ = new_glsl_node(context, POSTFIX_EXPRESSION, $1, NULL); }
  1155. ;
  1156. primary_expression : variable_identifier { $$ = $1; }
  1157. | INTCONSTANT
  1158. { $$ = new_glsl_node(context, INTCONSTANT, NULL); $$->data.i = $1; }
  1159. | UINTCONSTANT
  1160. { $$ = new_glsl_node(context, UINTCONSTANT, NULL); $$->data.ui = $1; }
  1161. | FLOATCONSTANT
  1162. { $$ = new_glsl_node(context, FLOATCONSTANT, NULL); $$->data.f = $1; }
  1163. | TRUE_VALUE
  1164. { $$ = new_glsl_node(context, TRUE_VALUE, NULL); }
  1165. | FALSE_VALUE
  1166. { $$ = new_glsl_node(context, FALSE_VALUE, NULL); }
  1167. | DOUBLECONSTANT
  1168. { $$ = new_glsl_node(context, DOUBLECONSTANT, NULL); $$->data.d = $1; }
  1169. | LEFT_PAREN expression RIGHT_PAREN
  1170. { $$ = new_glsl_node(context, PAREN_EXPRESSION, $2, NULL); }
  1171. ;
  1172. %%
  1173. #include "glsl_ast.h"
  1174. //The scanner macro, needed for integration with flex, causes problems below
  1175. #undef scanner
  1176. static void glsl_error(GLSL_LTYPE *loc, struct glsl_parse_context *c, const char *s)
  1177. {
  1178. c->error = true;
  1179. if (c->error_cb)
  1180. c->error_cb(s, loc->first_line, loc->first_column, loc->last_column);
  1181. }
  1182. int list_length(struct glsl_node *n, int list_token)
  1183. {
  1184. if (n->code != list_token) {
  1185. return 1;
  1186. } else {
  1187. int i;
  1188. int count = 0;
  1189. for (i = 0; i < n->child_count; i++) {
  1190. count += list_length(n->children[i], list_token);
  1191. }
  1192. return count;
  1193. }
  1194. }
  1195. static void list_gather(struct glsl_node *n, struct glsl_node *new_list, int list_token)
  1196. {
  1197. int i;
  1198. for (i = 0; i < n->child_count; i++) {
  1199. struct glsl_node *child = n->children[i];
  1200. if (child->code != list_token)
  1201. new_list->children[new_list->child_count++] = child;
  1202. else
  1203. list_gather(child, new_list, list_token);
  1204. }
  1205. }
  1206. static void list_collapse(struct glsl_parse_context *context, struct glsl_node *n)
  1207. {
  1208. int i;
  1209. for (i = 0; i < n->child_count; i++) {
  1210. struct glsl_node *child = n->children[i];
  1211. if (glsl_ast_is_list_node(child)) {
  1212. int list_token = child->code;
  1213. int length = list_length(child, list_token);
  1214. struct glsl_node *g = (struct glsl_node *)glsl_parse_alloc(context, offsetof(struct glsl_node, children[length]), 8);
  1215. g->code = list_token;
  1216. g->child_count = 0;
  1217. list_gather(child, g, list_token);
  1218. assert(g->child_count == length);
  1219. n->children[i] = g;
  1220. child = g;
  1221. }
  1222. list_collapse(context, child);
  1223. }
  1224. }
  1225. static bool parse_internal(struct glsl_parse_context *context)
  1226. {
  1227. context->error = false;
  1228. glsl_parse(context);
  1229. if (context->root) {
  1230. if (glsl_ast_is_list_node(context->root)) {
  1231. //
  1232. // list_collapse() can't combine all the TRANSLATION_UNIT nodes
  1233. // since it would need to replace g_glsl_node_root so we combine
  1234. // the TRANSLATION_UNIT nodes here.
  1235. //
  1236. int list_code = context->root->code;
  1237. int length = list_length(context->root, list_code);
  1238. struct glsl_node *new_root = (struct glsl_node *)glsl_parse_alloc(context, offsetof(struct glsl_node, children[length]), 8);
  1239. new_root->code = list_code;
  1240. new_root->child_count = 0;
  1241. list_gather(context->root, new_root, list_code);
  1242. assert(new_root->child_count == length);
  1243. context->root = new_root;
  1244. }
  1245. //
  1246. // Collapse other list nodes
  1247. //
  1248. list_collapse(context, context->root);
  1249. }
  1250. return context->error;
  1251. }
  1252. bool glsl_parse_file(struct glsl_parse_context *context, FILE *file)
  1253. {
  1254. glsl_lex_init(&(context->scanner));
  1255. glsl_set_in(file, context->scanner);
  1256. bool error;
  1257. error = parse_internal(context);
  1258. glsl_lex_destroy(context->scanner);
  1259. context->scanner = NULL;
  1260. return error;
  1261. }
  1262. bool glsl_parse_string(struct glsl_parse_context *context, const char *str)
  1263. {
  1264. char *text;
  1265. size_t sz;
  1266. bool error;
  1267. glsl_lex_init(&(context->scanner));
  1268. sz = strlen(str);
  1269. text = malloc(sz + 2);
  1270. strcpy(text, str);
  1271. text[sz + 1] = 0;
  1272. glsl__scan_buffer(text, sz + 2, context->scanner);
  1273. error = parse_internal(context);
  1274. free(text);
  1275. glsl_lex_destroy(context->scanner);
  1276. context->scanner = NULL;
  1277. return error;
  1278. }
  1279. void glsl_parse_context_init(struct glsl_parse_context *context)
  1280. {
  1281. context->root = NULL;
  1282. context->scanner = NULL;
  1283. context->first_buffer = NULL;
  1284. context->cur_buffer_start = NULL;
  1285. context->cur_buffer = NULL;
  1286. context->cur_buffer_end = NULL;
  1287. context->error_cb = NULL;
  1288. context->error = false;
  1289. }
  1290. void glsl_parse_set_error_cb(struct glsl_parse_context *context, glsl_parse_error_cb_t error_cb)
  1291. {
  1292. context->error_cb = error_cb;
  1293. }
  1294. void glsl_parse_context_destroy(struct glsl_parse_context *context)
  1295. {
  1296. glsl_parse_dealloc(context);
  1297. }