Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glsl_parser.ypp 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. %{
  2. /*
  3. * Copyright © 2008, 2009 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <assert.h>
  28. #include "ast.h"
  29. #include "glsl_parser_extras.h"
  30. #include "glsl_types.h"
  31. #define YYLEX_PARAM state->scanner
  32. %}
  33. %pure-parser
  34. %locations
  35. %error-verbose
  36. %lex-param {void *scanner}
  37. %parse-param {struct _mesa_glsl_parse_state *state}
  38. %name-prefix "_mesa_glsl_"
  39. %union {
  40. int n;
  41. float real;
  42. char *identifier;
  43. union {
  44. struct ast_type_qualifier q;
  45. unsigned i;
  46. } type_qualifier;
  47. struct ast_node *node;
  48. struct ast_type_specifier *type_specifier;
  49. struct ast_fully_specified_type *fully_specified_type;
  50. struct ast_function *function;
  51. struct ast_parameter_declarator *parameter_declarator;
  52. struct ast_function_definition *function_definition;
  53. struct ast_compound_statement *compound_statement;
  54. struct ast_expression *expression;
  55. struct ast_declarator_list *declarator_list;
  56. struct ast_struct_specifier *struct_specifier;
  57. struct ast_declaration *declaration;
  58. struct {
  59. struct ast_node *cond;
  60. struct ast_expression *rest;
  61. } for_rest_statement;
  62. }
  63. %token ATTRIBUTE CONST BOOL FLOAT INT UINT
  64. %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
  65. %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4
  66. %token MAT2 MAT3 MAT4 CENTROID IN OUT INOUT UNIFORM VARYING
  67. %token NOPERSPECTIVE FLAT SMOOTH
  68. %token MAT2X2 MAT2X3 MAT2X4
  69. %token MAT3X2 MAT3X3 MAT3X4
  70. %token MAT4X2 MAT4X3 MAT4X4
  71. %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
  72. %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
  73. %token SAMPLER2DARRAYSHADOW ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
  74. %token ISAMPLER1DARRAY ISAMPLER2DARRAY USAMPLER1D USAMPLER2D USAMPLER3D
  75. %token USAMPLERCUBE USAMPLER1DARRAY USAMPLER2DARRAY
  76. %token STRUCT VOID WHILE
  77. %token <identifier> IDENTIFIER
  78. %token <real> FLOATCONSTANT
  79. %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
  80. %token <identifier> FIELD_SELECTION
  81. %token LEFT_OP RIGHT_OP
  82. %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
  83. %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
  84. %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
  85. %token SUB_ASSIGN
  86. %token INVARIANT
  87. %token LOWP MEDIUMP HIGHP PRECISION
  88. %token VERSION EXTENSION LINE PRAGMA COLON EOL INTERFACE OUTPUT
  89. /* Reserved words that are not actually used in the grammar.
  90. */
  91. %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED GOTO
  92. %token INLINE NOINLINE VOLATILE PUBLIC STATIC EXTERN EXTERNAL
  93. %token LONG SHORT DOUBLE HALF FIXED UNSIGNED INPUT OUPTUT
  94. %token HVEC2 HVEC3 HVEC4 DVEC2 DVEC3 DVEC4 FVEC2 FVEC3 FVEC4
  95. %token SAMPLER2DRECT SAMPLER3DRECT SAMPLER2DRECTSHADOW
  96. %token SIZEOF CAST NAMESPACE USING
  97. %type <identifier> variable_identifier
  98. %type <node> statement
  99. %type <node> statement_list
  100. %type <node> simple_statement
  101. %type <node> statement_matched
  102. %type <node> statement_unmatched
  103. %type <n> precision_qualifier
  104. %type <type_qualifier> type_qualifier
  105. %type <type_qualifier> storage_qualifier
  106. %type <type_qualifier> interpolation_qualifier
  107. %type <type_specifier> type_specifier
  108. %type <type_specifier> type_specifier_no_prec
  109. %type <type_specifier> type_specifier_nonarray
  110. %type <n> basic_type_specifier_nonarray
  111. %type <fully_specified_type> fully_specified_type
  112. %type <function> function_prototype
  113. %type <function> function_header
  114. %type <function> function_header_with_parameters
  115. %type <function> function_declarator
  116. %type <parameter_declarator> parameter_declarator
  117. %type <parameter_declarator> parameter_declaration
  118. %type <type_qualifier> parameter_qualifier
  119. %type <type_qualifier> parameter_type_qualifier
  120. %type <type_specifier> parameter_type_specifier
  121. %type <function_definition> function_definition
  122. %type <compound_statement> compound_statement_no_new_scope
  123. %type <compound_statement> compound_statement
  124. %type <node> statement_no_new_scope
  125. %type <node> expression_statement
  126. %type <expression> expression
  127. %type <expression> primary_expression
  128. %type <expression> assignment_expression
  129. %type <expression> conditional_expression
  130. %type <expression> logical_or_expression
  131. %type <expression> logical_xor_expression
  132. %type <expression> logical_and_expression
  133. %type <expression> inclusive_or_expression
  134. %type <expression> exclusive_or_expression
  135. %type <expression> and_expression
  136. %type <expression> equality_expression
  137. %type <expression> relational_expression
  138. %type <expression> shift_expression
  139. %type <expression> additive_expression
  140. %type <expression> multiplicative_expression
  141. %type <expression> unary_expression
  142. %type <expression> constant_expression
  143. %type <expression> integer_expression
  144. %type <expression> postfix_expression
  145. %type <expression> function_call_header_with_parameters
  146. %type <expression> function_call_header_no_parameters
  147. %type <expression> function_call_header
  148. %type <expression> function_call_generic
  149. %type <expression> function_call_or_method
  150. %type <expression> function_call
  151. %type <n> assignment_operator
  152. %type <n> unary_operator
  153. %type <expression> function_identifier
  154. %type <node> external_declaration
  155. %type <declarator_list> init_declarator_list
  156. %type <declarator_list> single_declaration
  157. %type <expression> initializer
  158. %type <node> declaration
  159. %type <node> declaration_statement
  160. %type <node> jump_statement
  161. %type <struct_specifier> struct_specifier
  162. %type <node> struct_declaration_list
  163. %type <declarator_list> struct_declaration
  164. %type <declaration> struct_declarator
  165. %type <declaration> struct_declarator_list
  166. %type <node> selection_statement_matched
  167. %type <node> selection_statement_unmatched
  168. %type <node> iteration_statement
  169. %type <node> condition
  170. %type <node> conditionopt
  171. %type <node> for_init_statement
  172. %type <for_rest_statement> for_rest_statement
  173. %%
  174. translation_unit:
  175. version_statement extension_statement_list
  176. {
  177. _mesa_glsl_initialize_types(state);
  178. }
  179. external_declaration_list
  180. ;
  181. version_statement:
  182. /* blank - no #version specified */
  183. {
  184. state->language_version = 110;
  185. }
  186. | VERSION INTCONSTANT EOL
  187. {
  188. switch ($2) {
  189. case 110:
  190. case 120:
  191. case 130:
  192. /* FINISHME: Check against implementation support versions. */
  193. state->language_version = $2;
  194. break;
  195. default:
  196. _mesa_glsl_error(& @2, state, "Shading language version"
  197. "%u is not supported\n", $2);
  198. break;
  199. }
  200. }
  201. ;
  202. extension_statement_list:
  203. | extension_statement_list extension_statement
  204. ;
  205. extension_statement:
  206. EXTENSION IDENTIFIER COLON IDENTIFIER EOL
  207. {
  208. if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
  209. YYERROR;
  210. }
  211. }
  212. ;
  213. external_declaration_list:
  214. external_declaration
  215. {
  216. /* FINISHME: The NULL test is only required because 'precision'
  217. * FINISHME: statements are not yet supported.
  218. */
  219. if ($1 != NULL)
  220. state->translation_unit.push_tail(& $1->link);
  221. }
  222. | external_declaration_list external_declaration
  223. {
  224. /* FINISHME: The NULL test is only required because 'precision'
  225. * FINISHME: statements are not yet supported.
  226. */
  227. if ($2 != NULL)
  228. state->translation_unit.push_tail(& $2->link);
  229. }
  230. ;
  231. variable_identifier:
  232. IDENTIFIER
  233. ;
  234. primary_expression:
  235. variable_identifier
  236. {
  237. $$ = new ast_expression(ast_identifier, NULL, NULL, NULL);
  238. $$->set_location(yylloc);
  239. $$->primary_expression.identifier = $1;
  240. }
  241. | INTCONSTANT
  242. {
  243. $$ = new ast_expression(ast_int_constant, NULL, NULL, NULL);
  244. $$->set_location(yylloc);
  245. $$->primary_expression.int_constant = $1;
  246. }
  247. | UINTCONSTANT
  248. {
  249. $$ = new ast_expression(ast_uint_constant, NULL, NULL, NULL);
  250. $$->set_location(yylloc);
  251. $$->primary_expression.uint_constant = $1;
  252. }
  253. | FLOATCONSTANT
  254. {
  255. $$ = new ast_expression(ast_float_constant, NULL, NULL, NULL);
  256. $$->set_location(yylloc);
  257. $$->primary_expression.float_constant = $1;
  258. }
  259. | BOOLCONSTANT
  260. {
  261. $$ = new ast_expression(ast_bool_constant, NULL, NULL, NULL);
  262. $$->set_location(yylloc);
  263. $$->primary_expression.bool_constant = $1;
  264. }
  265. | '(' expression ')'
  266. {
  267. $$ = $2;
  268. }
  269. ;
  270. postfix_expression:
  271. primary_expression
  272. | postfix_expression '[' integer_expression ']'
  273. {
  274. $$ = new ast_expression(ast_array_index, $1, $3, NULL);
  275. $$->set_location(yylloc);
  276. }
  277. | function_call
  278. {
  279. /* Function call parameters used to be stored as a circular list in
  280. * subexpressions[1]. They are now stored as a regular list in
  281. * expressions. This assertion validates that the old code was
  282. * correctly converted. It can eventually be removed.
  283. */
  284. assert($1->subexpressions[1] == NULL);
  285. $$ = $1;
  286. }
  287. | postfix_expression '.' IDENTIFIER
  288. {
  289. $$ = new ast_expression(ast_field_selection, $1, NULL, NULL);
  290. $$->set_location(yylloc);
  291. $$->primary_expression.identifier = $3;
  292. }
  293. | postfix_expression INC_OP
  294. {
  295. $$ = new ast_expression(ast_post_inc, $1, NULL, NULL);
  296. $$->set_location(yylloc);
  297. }
  298. | postfix_expression DEC_OP
  299. {
  300. $$ = new ast_expression(ast_post_dec, $1, NULL, NULL);
  301. $$->set_location(yylloc);
  302. }
  303. ;
  304. integer_expression:
  305. expression
  306. ;
  307. function_call:
  308. function_call_or_method
  309. ;
  310. function_call_or_method:
  311. function_call_generic
  312. | postfix_expression '.' function_call_generic
  313. {
  314. $$ = new ast_expression(ast_field_selection, $1, $3, NULL);
  315. $$->set_location(yylloc);
  316. }
  317. ;
  318. function_call_generic:
  319. function_call_header_with_parameters ')'
  320. | function_call_header_no_parameters ')'
  321. ;
  322. function_call_header_no_parameters:
  323. function_call_header VOID
  324. | function_call_header
  325. ;
  326. function_call_header_with_parameters:
  327. function_call_header assignment_expression
  328. {
  329. $$ = $1;
  330. $$->set_location(yylloc);
  331. $$->expressions.push_tail(& $2->link);
  332. }
  333. | function_call_header_with_parameters ',' assignment_expression
  334. {
  335. $$ = $1;
  336. $$->set_location(yylloc);
  337. $$->expressions.push_tail(& $3->link);
  338. }
  339. ;
  340. // Grammar Note: Constructors look like functions, but lexical
  341. // analysis recognized most of them as keywords. They are now
  342. // recognized through "type_specifier".
  343. function_call_header:
  344. function_identifier '('
  345. ;
  346. function_identifier:
  347. type_specifier
  348. {
  349. $$ = new ast_function_expression($1);
  350. $$->set_location(yylloc);
  351. }
  352. | IDENTIFIER
  353. {
  354. ast_expression *callee = new ast_expression($1);
  355. $$ = new ast_function_expression(callee);
  356. $$->set_location(yylloc);
  357. }
  358. | FIELD_SELECTION
  359. {
  360. ast_expression *callee = new ast_expression($1);
  361. $$ = new ast_function_expression(callee);
  362. $$->set_location(yylloc);
  363. }
  364. ;
  365. // Grammar Note: No traditional style type casts.
  366. unary_expression:
  367. postfix_expression
  368. | INC_OP unary_expression
  369. {
  370. $$ = new ast_expression(ast_pre_inc, $2, NULL, NULL);
  371. $$->set_location(yylloc);
  372. }
  373. | DEC_OP unary_expression
  374. {
  375. $$ = new ast_expression(ast_pre_dec, $2, NULL, NULL);
  376. $$->set_location(yylloc);
  377. }
  378. | unary_operator unary_expression
  379. {
  380. $$ = new ast_expression($1, $2, NULL, NULL);
  381. $$->set_location(yylloc);
  382. }
  383. ;
  384. // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
  385. unary_operator:
  386. '+' { $$ = ast_plus; }
  387. | '-' { $$ = ast_neg; }
  388. | '!' { $$ = ast_logic_not; }
  389. | '~' { $$ = ast_bit_not; }
  390. ;
  391. multiplicative_expression:
  392. unary_expression
  393. | multiplicative_expression '*' unary_expression
  394. {
  395. $$ = new ast_expression_bin(ast_mul, $1, $3);
  396. $$->set_location(yylloc);
  397. }
  398. | multiplicative_expression '/' unary_expression
  399. {
  400. $$ = new ast_expression_bin(ast_div, $1, $3);
  401. $$->set_location(yylloc);
  402. }
  403. | multiplicative_expression '%' unary_expression
  404. {
  405. $$ = new ast_expression_bin(ast_mod, $1, $3);
  406. $$->set_location(yylloc);
  407. }
  408. ;
  409. additive_expression:
  410. multiplicative_expression
  411. | additive_expression '+' multiplicative_expression
  412. {
  413. $$ = new ast_expression_bin(ast_add, $1, $3);
  414. $$->set_location(yylloc);
  415. }
  416. | additive_expression '-' multiplicative_expression
  417. {
  418. $$ = new ast_expression_bin(ast_sub, $1, $3);
  419. $$->set_location(yylloc);
  420. }
  421. ;
  422. shift_expression:
  423. additive_expression
  424. | shift_expression LEFT_OP additive_expression
  425. {
  426. $$ = new ast_expression_bin(ast_lshift, $1, $3);
  427. $$->set_location(yylloc);
  428. }
  429. | shift_expression RIGHT_OP additive_expression
  430. {
  431. $$ = new ast_expression_bin(ast_rshift, $1, $3);
  432. $$->set_location(yylloc);
  433. }
  434. ;
  435. relational_expression:
  436. shift_expression
  437. | relational_expression '<' shift_expression
  438. {
  439. $$ = new ast_expression_bin(ast_less, $1, $3);
  440. $$->set_location(yylloc);
  441. }
  442. | relational_expression '>' shift_expression
  443. {
  444. $$ = new ast_expression_bin(ast_greater, $1, $3);
  445. $$->set_location(yylloc);
  446. }
  447. | relational_expression LE_OP shift_expression
  448. {
  449. $$ = new ast_expression_bin(ast_lequal, $1, $3);
  450. $$->set_location(yylloc);
  451. }
  452. | relational_expression GE_OP shift_expression
  453. {
  454. $$ = new ast_expression_bin(ast_gequal, $1, $3);
  455. $$->set_location(yylloc);
  456. }
  457. ;
  458. equality_expression:
  459. relational_expression
  460. | equality_expression EQ_OP relational_expression
  461. {
  462. $$ = new ast_expression_bin(ast_equal, $1, $3);
  463. $$->set_location(yylloc);
  464. }
  465. | equality_expression NE_OP relational_expression
  466. {
  467. $$ = new ast_expression_bin(ast_nequal, $1, $3);
  468. $$->set_location(yylloc);
  469. }
  470. ;
  471. and_expression:
  472. equality_expression
  473. | and_expression '&' equality_expression
  474. {
  475. $$ = new ast_expression_bin(ast_bit_or, $1, $3);
  476. $$->set_location(yylloc);
  477. }
  478. ;
  479. exclusive_or_expression:
  480. and_expression
  481. | exclusive_or_expression '^' and_expression
  482. {
  483. $$ = new ast_expression_bin(ast_bit_xor, $1, $3);
  484. $$->set_location(yylloc);
  485. }
  486. ;
  487. inclusive_or_expression:
  488. exclusive_or_expression
  489. | inclusive_or_expression '|' exclusive_or_expression
  490. {
  491. $$ = new ast_expression_bin(ast_bit_or, $1, $3);
  492. $$->set_location(yylloc);
  493. }
  494. ;
  495. logical_and_expression:
  496. inclusive_or_expression
  497. | logical_and_expression AND_OP inclusive_or_expression
  498. {
  499. $$ = new ast_expression_bin(ast_logic_and, $1, $3);
  500. $$->set_location(yylloc);
  501. }
  502. ;
  503. logical_xor_expression:
  504. logical_and_expression
  505. | logical_xor_expression XOR_OP logical_and_expression
  506. {
  507. $$ = new ast_expression_bin(ast_logic_xor, $1, $3);
  508. $$->set_location(yylloc);
  509. }
  510. ;
  511. logical_or_expression:
  512. logical_xor_expression
  513. | logical_or_expression OR_OP logical_xor_expression
  514. {
  515. $$ = new ast_expression_bin(ast_logic_or, $1, $3);
  516. $$->set_location(yylloc);
  517. }
  518. ;
  519. conditional_expression:
  520. logical_or_expression
  521. | logical_or_expression '?' expression ':' assignment_expression
  522. {
  523. $$ = new ast_expression(ast_conditional, $1, $3, $5);
  524. $$->set_location(yylloc);
  525. }
  526. ;
  527. assignment_expression:
  528. conditional_expression
  529. | unary_expression assignment_operator assignment_expression
  530. {
  531. $$ = new ast_expression($2, $1, $3, NULL);
  532. $$->set_location(yylloc);
  533. }
  534. ;
  535. assignment_operator:
  536. '=' { $$ = ast_assign; }
  537. | MUL_ASSIGN { $$ = ast_mul_assign; }
  538. | DIV_ASSIGN { $$ = ast_div_assign; }
  539. | MOD_ASSIGN { $$ = ast_mod_assign; }
  540. | ADD_ASSIGN { $$ = ast_add_assign; }
  541. | SUB_ASSIGN { $$ = ast_sub_assign; }
  542. | LEFT_ASSIGN { $$ = ast_ls_assign; }
  543. | RIGHT_ASSIGN { $$ = ast_rs_assign; }
  544. | AND_ASSIGN { $$ = ast_and_assign; }
  545. | XOR_ASSIGN { $$ = ast_xor_assign; }
  546. | OR_ASSIGN { $$ = ast_or_assign; }
  547. ;
  548. expression:
  549. assignment_expression
  550. {
  551. $$ = $1;
  552. }
  553. | expression ',' assignment_expression
  554. {
  555. if ($1->oper != ast_sequence) {
  556. $$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
  557. $$->set_location(yylloc);
  558. $$->expressions.push_tail(& $1->link);
  559. } else {
  560. $$ = $1;
  561. }
  562. $$->expressions.push_tail(& $3->link);
  563. }
  564. ;
  565. constant_expression:
  566. conditional_expression
  567. ;
  568. declaration:
  569. function_prototype ';'
  570. {
  571. $$ = $1;
  572. }
  573. | init_declarator_list ';'
  574. {
  575. $$ = $1;
  576. }
  577. | PRECISION precision_qualifier type_specifier_no_prec ';'
  578. {
  579. if (($3->type_specifier != ast_float)
  580. && ($3->type_specifier != ast_int)) {
  581. _mesa_glsl_error(& @3, state, "global precision qualifier can "
  582. "only be applied to `int' or `float'\n");
  583. YYERROR;
  584. }
  585. $$ = NULL; /* FINISHME */
  586. }
  587. ;
  588. function_prototype:
  589. function_declarator ')'
  590. ;
  591. function_declarator:
  592. function_header
  593. | function_header_with_parameters
  594. ;
  595. function_header_with_parameters:
  596. function_header parameter_declaration
  597. {
  598. $$ = $1;
  599. $$->parameters.push_tail(& $2->link);
  600. }
  601. | function_header_with_parameters ',' parameter_declaration
  602. {
  603. $$ = $1;
  604. $$->parameters.push_tail(& $3->link);
  605. }
  606. ;
  607. function_header:
  608. fully_specified_type IDENTIFIER '('
  609. {
  610. $$ = new ast_function();
  611. $$->set_location(yylloc);
  612. $$->return_type = $1;
  613. $$->identifier = $2;
  614. }
  615. ;
  616. parameter_declarator:
  617. type_specifier IDENTIFIER
  618. {
  619. $$ = new ast_parameter_declarator();
  620. $$->set_location(yylloc);
  621. $$->type = new ast_fully_specified_type();
  622. $$->type->set_location(yylloc);
  623. $$->type->specifier = $1;
  624. $$->identifier = $2;
  625. }
  626. | type_specifier IDENTIFIER '[' constant_expression ']'
  627. {
  628. $$ = new ast_parameter_declarator();
  629. $$->set_location(yylloc);
  630. $$->type = new ast_fully_specified_type();
  631. $$->type->set_location(yylloc);
  632. $$->type->specifier = $1;
  633. $$->identifier = $2;
  634. $$->is_array = true;
  635. $$->array_size = $4;
  636. }
  637. ;
  638. parameter_declaration:
  639. parameter_type_qualifier parameter_qualifier parameter_declarator
  640. {
  641. $1.i |= $2.i;
  642. $$ = $3;
  643. $$->type->qualifier = $1.q;
  644. }
  645. | parameter_qualifier parameter_declarator
  646. {
  647. $$ = $2;
  648. $$->type->qualifier = $1.q;
  649. }
  650. | parameter_type_qualifier parameter_qualifier parameter_type_specifier
  651. {
  652. $1.i |= $2.i;
  653. $$ = new ast_parameter_declarator();
  654. $$->set_location(yylloc);
  655. $$->type = new ast_fully_specified_type();
  656. $$->type->qualifier = $1.q;
  657. $$->type->specifier = $3;
  658. }
  659. | parameter_qualifier parameter_type_specifier
  660. {
  661. $$ = new ast_parameter_declarator();
  662. $$->set_location(yylloc);
  663. $$->type = new ast_fully_specified_type();
  664. $$->type->qualifier = $1.q;
  665. $$->type->specifier = $2;
  666. }
  667. ;
  668. parameter_qualifier:
  669. /* empty */ { $$.i = 0; }
  670. | IN { $$.i = 0; $$.q.in = 1; }
  671. | OUT { $$.i = 0; $$.q.out = 1; }
  672. | INOUT { $$.i = 0; $$.q.in = 1; $$.q.out = 1; }
  673. ;
  674. parameter_type_specifier:
  675. type_specifier
  676. ;
  677. init_declarator_list:
  678. single_declaration
  679. | init_declarator_list ',' IDENTIFIER
  680. {
  681. ast_declaration *decl = new ast_declaration($3, false, NULL, NULL);
  682. decl->set_location(yylloc);
  683. $$ = $1;
  684. $$->declarations.push_tail(&decl->link);
  685. }
  686. | init_declarator_list ',' IDENTIFIER '[' ']'
  687. {
  688. ast_declaration *decl = new ast_declaration($3, true, NULL, NULL);
  689. decl->set_location(yylloc);
  690. $$ = $1;
  691. $$->declarations.push_tail(&decl->link);
  692. }
  693. | init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
  694. {
  695. ast_declaration *decl = new ast_declaration($3, true, $5, NULL);
  696. decl->set_location(yylloc);
  697. $$ = $1;
  698. $$->declarations.push_tail(&decl->link);
  699. }
  700. | init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
  701. {
  702. ast_declaration *decl = new ast_declaration($3, true, NULL, $7);
  703. decl->set_location(yylloc);
  704. $$ = $1;
  705. $$->declarations.push_tail(&decl->link);
  706. }
  707. | init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
  708. {
  709. ast_declaration *decl = new ast_declaration($3, true, $5, $8);
  710. decl->set_location(yylloc);
  711. $$ = $1;
  712. $$->declarations.push_tail(&decl->link);
  713. }
  714. | init_declarator_list ',' IDENTIFIER '=' initializer
  715. {
  716. ast_declaration *decl = new ast_declaration($3, false, NULL, $5);
  717. decl->set_location(yylloc);
  718. $$ = $1;
  719. $$->declarations.push_tail(&decl->link);
  720. }
  721. ;
  722. // Grammar Note: No 'enum', or 'typedef'.
  723. single_declaration:
  724. fully_specified_type
  725. {
  726. if ($1->specifier->type_specifier != ast_struct) {
  727. _mesa_glsl_error(& @1, state, "empty declaration list\n");
  728. YYERROR;
  729. } else {
  730. $$ = new ast_declarator_list($1);
  731. $$->set_location(yylloc);
  732. }
  733. }
  734. | fully_specified_type IDENTIFIER
  735. {
  736. ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
  737. $$ = new ast_declarator_list($1);
  738. $$->set_location(yylloc);
  739. $$->declarations.push_tail(&decl->link);
  740. }
  741. | fully_specified_type IDENTIFIER '[' ']'
  742. {
  743. ast_declaration *decl = new ast_declaration($2, true, NULL, NULL);
  744. $$ = new ast_declarator_list($1);
  745. $$->set_location(yylloc);
  746. $$->declarations.push_tail(&decl->link);
  747. }
  748. | fully_specified_type IDENTIFIER '[' constant_expression ']'
  749. {
  750. ast_declaration *decl = new ast_declaration($2, true, $4, NULL);
  751. $$ = new ast_declarator_list($1);
  752. $$->set_location(yylloc);
  753. $$->declarations.push_tail(&decl->link);
  754. }
  755. | fully_specified_type IDENTIFIER '[' ']' '=' initializer
  756. {
  757. ast_declaration *decl = new ast_declaration($2, true, NULL, $6);
  758. $$ = new ast_declarator_list($1);
  759. $$->set_location(yylloc);
  760. $$->declarations.push_tail(&decl->link);
  761. }
  762. | fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
  763. {
  764. ast_declaration *decl = new ast_declaration($2, true, $4, $7);
  765. $$ = new ast_declarator_list($1);
  766. $$->set_location(yylloc);
  767. $$->declarations.push_tail(&decl->link);
  768. }
  769. | fully_specified_type IDENTIFIER '=' initializer
  770. {
  771. ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
  772. $$ = new ast_declarator_list($1);
  773. $$->set_location(yylloc);
  774. $$->declarations.push_tail(&decl->link);
  775. }
  776. | INVARIANT IDENTIFIER // Vertex only.
  777. {
  778. ast_declaration *decl = new ast_declaration($2, false, NULL, NULL);
  779. $$ = new ast_declarator_list(NULL);
  780. $$->set_location(yylloc);
  781. $$->invariant = true;
  782. $$->declarations.push_tail(&decl->link);
  783. }
  784. ;
  785. fully_specified_type:
  786. type_specifier
  787. {
  788. $$ = new ast_fully_specified_type();
  789. $$->set_location(yylloc);
  790. $$->specifier = $1;
  791. }
  792. | type_qualifier type_specifier
  793. {
  794. $$ = new ast_fully_specified_type();
  795. $$->set_location(yylloc);
  796. $$->qualifier = $1.q;
  797. $$->specifier = $2;
  798. }
  799. ;
  800. interpolation_qualifier:
  801. SMOOTH { $$.i = 0; $$.q.smooth = 1; }
  802. | FLAT { $$.i = 0; $$.q.flat = 1; }
  803. | NOPERSPECTIVE { $$.i = 0; $$.q.noperspective = 1; }
  804. ;
  805. parameter_type_qualifier:
  806. CONST { $$.i = 0; $$.q.constant = 1; }
  807. ;
  808. type_qualifier:
  809. storage_qualifier
  810. | interpolation_qualifier type_qualifier
  811. {
  812. $$.i = $1.i | $2.i;
  813. }
  814. | INVARIANT type_qualifier
  815. {
  816. $$ = $2;
  817. $$.q.invariant = 1;
  818. }
  819. ;
  820. storage_qualifier:
  821. CONST { $$.i = 0; $$.q.constant = 1; }
  822. | ATTRIBUTE { $$.i = 0; $$.q.attribute = 1; }
  823. | VARYING { $$.i = 0; $$.q.varying = 1; }
  824. | CENTROID VARYING { $$.i = 0; $$.q.centroid = 1; $$.q.varying = 1; }
  825. | IN { $$.i = 0; $$.q.in = 1; }
  826. | OUT { $$.i = 0; $$.q.out = 1; }
  827. | CENTROID IN { $$.i = 0; $$.q.centroid = 1; $$.q.in = 1; }
  828. | CENTROID OUT { $$.i = 0; $$.q.centroid = 1; $$.q.out = 1; }
  829. | UNIFORM { $$.i = 0; $$.q.uniform = 1; }
  830. ;
  831. type_specifier:
  832. type_specifier_no_prec
  833. | precision_qualifier type_specifier_no_prec
  834. {
  835. $$ = $2;
  836. $$->precision = $1;
  837. }
  838. ;
  839. type_specifier_no_prec:
  840. type_specifier_nonarray
  841. | type_specifier_nonarray '[' ']'
  842. {
  843. $$ = $1;
  844. $$->is_array = true;
  845. $$->array_size = NULL;
  846. }
  847. | type_specifier_nonarray '[' constant_expression ']'
  848. {
  849. $$ = $1;
  850. $$->is_array = true;
  851. $$->array_size = $3;
  852. }
  853. ;
  854. type_specifier_nonarray:
  855. basic_type_specifier_nonarray
  856. {
  857. $$ = new ast_type_specifier($1);
  858. $$->set_location(yylloc);
  859. }
  860. | struct_specifier
  861. {
  862. $$ = new ast_type_specifier($1);
  863. $$->set_location(yylloc);
  864. }
  865. | IDENTIFIER
  866. {
  867. $$ = new ast_type_specifier($1);
  868. $$->set_location(yylloc);
  869. }
  870. ;
  871. basic_type_specifier_nonarray:
  872. VOID { $$ = ast_void; }
  873. | FLOAT { $$ = ast_float; }
  874. | INT { $$ = ast_int; }
  875. | UINT { $$ = ast_uint; }
  876. | BOOL { $$ = ast_bool; }
  877. | VEC2 { $$ = ast_vec2; }
  878. | VEC3 { $$ = ast_vec3; }
  879. | VEC4 { $$ = ast_vec4; }
  880. | BVEC2 { $$ = ast_bvec2; }
  881. | BVEC3 { $$ = ast_bvec3; }
  882. | BVEC4 { $$ = ast_bvec4; }
  883. | IVEC2 { $$ = ast_ivec2; }
  884. | IVEC3 { $$ = ast_ivec3; }
  885. | IVEC4 { $$ = ast_ivec4; }
  886. | UVEC2 { $$ = ast_uvec2; }
  887. | UVEC3 { $$ = ast_uvec3; }
  888. | UVEC4 { $$ = ast_uvec4; }
  889. | MAT2 { $$ = ast_mat2; }
  890. | MAT3 { $$ = ast_mat3; }
  891. | MAT4 { $$ = ast_mat4; }
  892. | MAT2X2 { $$ = ast_mat2; }
  893. | MAT2X3 { $$ = ast_mat2x3; }
  894. | MAT2X4 { $$ = ast_mat2x4; }
  895. | MAT3X2 { $$ = ast_mat3x2; }
  896. | MAT3X3 { $$ = ast_mat3; }
  897. | MAT3X4 { $$ = ast_mat3x4; }
  898. | MAT4X2 { $$ = ast_mat4x2; }
  899. | MAT4X3 { $$ = ast_mat4x3; }
  900. | MAT4X4 { $$ = ast_mat4; }
  901. | SAMPLER1D { $$ = ast_sampler1d; }
  902. | SAMPLER2D { $$ = ast_sampler2d; }
  903. | SAMPLER2DRECT { $$ = ast_sampler2drect; }
  904. | SAMPLER3D { $$ = ast_sampler3d; }
  905. | SAMPLERCUBE { $$ = ast_samplercube; }
  906. | SAMPLER1DSHADOW { $$ = ast_sampler1dshadow; }
  907. | SAMPLER2DSHADOW { $$ = ast_sampler2dshadow; }
  908. | SAMPLER2DRECTSHADOW { $$ = ast_sampler2drectshadow; }
  909. | SAMPLERCUBESHADOW { $$ = ast_samplercubeshadow; }
  910. | SAMPLER1DARRAY { $$ = ast_sampler1darray; }
  911. | SAMPLER2DARRAY { $$ = ast_sampler2darray; }
  912. | SAMPLER1DARRAYSHADOW { $$ = ast_sampler1darrayshadow; }
  913. | SAMPLER2DARRAYSHADOW { $$ = ast_sampler2darrayshadow; }
  914. | ISAMPLER1D { $$ = ast_isampler1d; }
  915. | ISAMPLER2D { $$ = ast_isampler2d; }
  916. | ISAMPLER3D { $$ = ast_isampler3d; }
  917. | ISAMPLERCUBE { $$ = ast_isamplercube; }
  918. | ISAMPLER1DARRAY { $$ = ast_isampler1darray; }
  919. | ISAMPLER2DARRAY { $$ = ast_isampler2darray; }
  920. | USAMPLER1D { $$ = ast_usampler1d; }
  921. | USAMPLER2D { $$ = ast_usampler2d; }
  922. | USAMPLER3D { $$ = ast_usampler3d; }
  923. | USAMPLERCUBE { $$ = ast_usamplercube; }
  924. | USAMPLER1DARRAY { $$ = ast_usampler1darray; }
  925. | USAMPLER2DARRAY { $$ = ast_usampler2darray; }
  926. ;
  927. precision_qualifier:
  928. HIGHP {
  929. if (state->language_version < 130)
  930. _mesa_glsl_error(& @1, state,
  931. "precission qualifier forbidden "
  932. "in GLSL %d.%d (1.30 or later "
  933. "required)\n",
  934. state->language_version / 100,
  935. state->language_version % 100);
  936. $$ = ast_precision_high;
  937. }
  938. | MEDIUMP {
  939. if (state->language_version < 130)
  940. _mesa_glsl_error(& @1, state,
  941. "precission qualifier forbidden "
  942. "in GLSL %d.%d (1.30 or later "
  943. "required)\n",
  944. state->language_version / 100,
  945. state->language_version % 100);
  946. $$ = ast_precision_medium;
  947. }
  948. | LOWP {
  949. if (state->language_version < 130)
  950. _mesa_glsl_error(& @1, state,
  951. "precission qualifier forbidden "
  952. "in GLSL %d.%d (1.30 or later "
  953. "required)\n",
  954. state->language_version / 100,
  955. state->language_version % 100);
  956. $$ = ast_precision_low;
  957. }
  958. ;
  959. struct_specifier:
  960. STRUCT IDENTIFIER '{' struct_declaration_list '}'
  961. {
  962. $$ = new ast_struct_specifier($2, $4);
  963. $$->set_location(yylloc);
  964. }
  965. | STRUCT '{' struct_declaration_list '}'
  966. {
  967. $$ = new ast_struct_specifier(NULL, $3);
  968. $$->set_location(yylloc);
  969. }
  970. ;
  971. struct_declaration_list:
  972. struct_declaration
  973. {
  974. $$ = (struct ast_node *) $1;
  975. $1->link.self_link();
  976. }
  977. | struct_declaration_list struct_declaration
  978. {
  979. $$ = (struct ast_node *) $1;
  980. $$->link.insert_before(& $2->link);
  981. }
  982. ;
  983. struct_declaration:
  984. type_specifier struct_declarator_list ';'
  985. {
  986. ast_fully_specified_type *type = new ast_fully_specified_type();
  987. type->set_location(yylloc);
  988. type->specifier = $1;
  989. $$ = new ast_declarator_list(type);
  990. $$->set_location(yylloc);
  991. $$->declarations.push_degenerate_list_at_head(& $2->link);
  992. }
  993. ;
  994. struct_declarator_list:
  995. struct_declarator
  996. {
  997. $$ = $1;
  998. $1->link.self_link();
  999. }
  1000. | struct_declarator_list ',' struct_declarator
  1001. {
  1002. $$ = $1;
  1003. $$->link.insert_before(& $3->link);
  1004. }
  1005. ;
  1006. struct_declarator:
  1007. IDENTIFIER
  1008. {
  1009. $$ = new ast_declaration($1, false, NULL, NULL);
  1010. $$->set_location(yylloc);
  1011. }
  1012. | IDENTIFIER '[' constant_expression ']'
  1013. {
  1014. $$ = new ast_declaration($1, true, $3, NULL);
  1015. $$->set_location(yylloc);
  1016. }
  1017. ;
  1018. initializer:
  1019. assignment_expression
  1020. ;
  1021. declaration_statement:
  1022. declaration
  1023. ;
  1024. // Grammar Note: labeled statements for SWITCH only; 'goto' is not
  1025. // supported.
  1026. statement:
  1027. statement_matched
  1028. | statement_unmatched
  1029. ;
  1030. statement_matched:
  1031. compound_statement { $$ = (struct ast_node *) $1; }
  1032. | simple_statement
  1033. ;
  1034. statement_unmatched:
  1035. selection_statement_unmatched
  1036. ;
  1037. simple_statement:
  1038. declaration_statement
  1039. | expression_statement
  1040. | selection_statement_matched
  1041. | switch_statement { $$ = NULL; }
  1042. | case_label { $$ = NULL; }
  1043. | iteration_statement
  1044. | jump_statement
  1045. ;
  1046. compound_statement:
  1047. '{' '}'
  1048. {
  1049. $$ = new ast_compound_statement(true, NULL);
  1050. $$->set_location(yylloc);
  1051. }
  1052. | '{' statement_list '}'
  1053. {
  1054. $$ = new ast_compound_statement(true, $2);
  1055. $$->set_location(yylloc);
  1056. }
  1057. ;
  1058. statement_no_new_scope:
  1059. compound_statement_no_new_scope { $$ = (struct ast_node *) $1; }
  1060. | simple_statement
  1061. ;
  1062. compound_statement_no_new_scope:
  1063. '{' '}'
  1064. {
  1065. $$ = new ast_compound_statement(false, NULL);
  1066. $$->set_location(yylloc);
  1067. }
  1068. | '{' statement_list '}'
  1069. {
  1070. $$ = new ast_compound_statement(false, $2);
  1071. $$->set_location(yylloc);
  1072. }
  1073. ;
  1074. statement_list:
  1075. statement
  1076. {
  1077. if ($1 == NULL) {
  1078. _mesa_glsl_error(& @1, state, "<nil> statement\n");
  1079. assert($1 != NULL);
  1080. }
  1081. $$ = $1;
  1082. $$->link.self_link();
  1083. }
  1084. | statement_list statement
  1085. {
  1086. if ($2 == NULL) {
  1087. _mesa_glsl_error(& @2, state, "<nil> statement\n");
  1088. assert($2 != NULL);
  1089. }
  1090. $$ = $1;
  1091. $$->link.insert_before(& $2->link);
  1092. }
  1093. ;
  1094. expression_statement:
  1095. ';'
  1096. {
  1097. $$ = new ast_expression_statement(NULL);
  1098. $$->set_location(yylloc);
  1099. }
  1100. | expression ';'
  1101. {
  1102. $$ = new ast_expression_statement($1);
  1103. $$->set_location(yylloc);
  1104. }
  1105. ;
  1106. selection_statement_matched:
  1107. IF '(' expression ')' statement_matched ELSE statement_matched
  1108. {
  1109. $$ = new ast_selection_statement($3, $5, $7);
  1110. $$->set_location(yylloc);
  1111. }
  1112. ;
  1113. selection_statement_unmatched:
  1114. IF '(' expression ')' statement_matched
  1115. {
  1116. $$ = new ast_selection_statement($3, $5, NULL);
  1117. $$->set_location(yylloc);
  1118. }
  1119. | IF '(' expression ')' statement_unmatched
  1120. {
  1121. $$ = new ast_selection_statement($3, $5, NULL);
  1122. $$->set_location(yylloc);
  1123. }
  1124. | IF '(' expression ')' statement_matched ELSE statement_unmatched
  1125. {
  1126. $$ = new ast_selection_statement($3, $5, $7);
  1127. $$->set_location(yylloc);
  1128. }
  1129. ;
  1130. condition:
  1131. expression
  1132. {
  1133. $$ = (struct ast_node *) $1;
  1134. }
  1135. | fully_specified_type IDENTIFIER '=' initializer
  1136. {
  1137. ast_declaration *decl = new ast_declaration($2, false, NULL, $4);
  1138. ast_declarator_list *declarator = new ast_declarator_list($1);
  1139. decl->set_location(yylloc);
  1140. declarator->set_location(yylloc);
  1141. declarator->declarations.push_tail(&decl->link);
  1142. $$ = declarator;
  1143. }
  1144. ;
  1145. switch_statement:
  1146. SWITCH '(' expression ')' compound_statement
  1147. ;
  1148. case_label:
  1149. CASE expression ':'
  1150. | DEFAULT ':'
  1151. ;
  1152. iteration_statement:
  1153. WHILE '(' condition ')' statement_no_new_scope
  1154. {
  1155. $$ = new ast_iteration_statement(ast_iteration_statement::ast_while,
  1156. NULL, $3, NULL, $5);
  1157. $$->set_location(yylloc);
  1158. }
  1159. | DO statement WHILE '(' expression ')' ';'
  1160. {
  1161. $$ = new ast_iteration_statement(ast_iteration_statement::ast_do_while,
  1162. NULL, $5, NULL, $2);
  1163. $$->set_location(yylloc);
  1164. }
  1165. | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
  1166. {
  1167. $$ = new ast_iteration_statement(ast_iteration_statement::ast_for,
  1168. $3, $4.cond, $4.rest, $6);
  1169. $$->set_location(yylloc);
  1170. }
  1171. ;
  1172. for_init_statement:
  1173. expression_statement
  1174. | declaration_statement
  1175. ;
  1176. conditionopt:
  1177. condition
  1178. | /* empty */
  1179. {
  1180. $$ = NULL;
  1181. }
  1182. ;
  1183. for_rest_statement:
  1184. conditionopt ';'
  1185. {
  1186. $$.cond = $1;
  1187. $$.rest = NULL;
  1188. }
  1189. | conditionopt ';' expression
  1190. {
  1191. $$.cond = $1;
  1192. $$.rest = $3;
  1193. }
  1194. ;
  1195. // Grammar Note: No 'goto'. Gotos are not supported.
  1196. jump_statement:
  1197. CONTINUE ';'
  1198. {
  1199. $$ = new ast_jump_statement(ast_jump_statement::ast_continue, NULL);
  1200. $$->set_location(yylloc);
  1201. }
  1202. | BREAK ';'
  1203. {
  1204. $$ = new ast_jump_statement(ast_jump_statement::ast_break, NULL);
  1205. $$->set_location(yylloc);
  1206. }
  1207. | RETURN ';'
  1208. {
  1209. $$ = new ast_jump_statement(ast_jump_statement::ast_return, NULL);
  1210. $$->set_location(yylloc);
  1211. }
  1212. | RETURN expression ';'
  1213. {
  1214. $$ = new ast_jump_statement(ast_jump_statement::ast_return, $2);
  1215. $$->set_location(yylloc);
  1216. }
  1217. | DISCARD ';' // Fragment shader only.
  1218. {
  1219. $$ = new ast_jump_statement(ast_jump_statement::ast_discard, NULL);
  1220. $$->set_location(yylloc);
  1221. }
  1222. ;
  1223. external_declaration:
  1224. function_definition { $$ = $1; }
  1225. | declaration { $$ = $1; }
  1226. ;
  1227. function_definition:
  1228. function_prototype compound_statement_no_new_scope
  1229. {
  1230. $$ = new ast_function_definition();
  1231. $$->set_location(yylloc);
  1232. $$->prototype = $1;
  1233. $$->body = $2;
  1234. }
  1235. ;