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.yy 90KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972
  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. #ifndef _MSC_VER
  28. #include <strings.h>
  29. #endif
  30. #include <assert.h>
  31. #include "ast.h"
  32. #include "glsl_parser_extras.h"
  33. #include "compiler/glsl_types.h"
  34. #include "main/context.h"
  35. #ifdef _MSC_VER
  36. #pragma warning( disable : 4065 ) // switch statement contains 'default' but no 'case' labels
  37. #endif
  38. #undef yyerror
  39. static void yyerror(YYLTYPE *loc, _mesa_glsl_parse_state *st, const char *msg)
  40. {
  41. _mesa_glsl_error(loc, st, "%s", msg);
  42. }
  43. static int
  44. _mesa_glsl_lex(YYSTYPE *val, YYLTYPE *loc, _mesa_glsl_parse_state *state)
  45. {
  46. return _mesa_glsl_lexer_lex(val, loc, state->scanner);
  47. }
  48. static bool match_layout_qualifier(const char *s1, const char *s2,
  49. _mesa_glsl_parse_state *state)
  50. {
  51. /* From the GLSL 1.50 spec, section 4.3.8 (Layout Qualifiers):
  52. *
  53. * "The tokens in any layout-qualifier-id-list ... are not case
  54. * sensitive, unless explicitly noted otherwise."
  55. *
  56. * The text "unless explicitly noted otherwise" appears to be
  57. * vacuous--no desktop GLSL spec (up through GLSL 4.40) notes
  58. * otherwise.
  59. *
  60. * However, the GLSL ES 3.00 spec says, in section 4.3.8 (Layout
  61. * Qualifiers):
  62. *
  63. * "As for other identifiers, they are case sensitive."
  64. *
  65. * So we need to do a case-sensitive or a case-insensitive match,
  66. * depending on whether we are compiling for GLSL ES.
  67. */
  68. if (state->es_shader)
  69. return strcmp(s1, s2);
  70. else
  71. return strcasecmp(s1, s2);
  72. }
  73. %}
  74. %expect 0
  75. %pure-parser
  76. %error-verbose
  77. %locations
  78. %initial-action {
  79. @$.first_line = 1;
  80. @$.first_column = 1;
  81. @$.last_line = 1;
  82. @$.last_column = 1;
  83. @$.source = 0;
  84. }
  85. %lex-param {struct _mesa_glsl_parse_state *state}
  86. %parse-param {struct _mesa_glsl_parse_state *state}
  87. %union {
  88. int n;
  89. float real;
  90. double dreal;
  91. const char *identifier;
  92. struct ast_type_qualifier type_qualifier;
  93. ast_node *node;
  94. ast_type_specifier *type_specifier;
  95. ast_array_specifier *array_specifier;
  96. ast_fully_specified_type *fully_specified_type;
  97. ast_function *function;
  98. ast_parameter_declarator *parameter_declarator;
  99. ast_function_definition *function_definition;
  100. ast_compound_statement *compound_statement;
  101. ast_expression *expression;
  102. ast_declarator_list *declarator_list;
  103. ast_struct_specifier *struct_specifier;
  104. ast_declaration *declaration;
  105. ast_switch_body *switch_body;
  106. ast_case_label *case_label;
  107. ast_case_label_list *case_label_list;
  108. ast_case_statement *case_statement;
  109. ast_case_statement_list *case_statement_list;
  110. ast_interface_block *interface_block;
  111. ast_subroutine_list *subroutine_list;
  112. struct {
  113. ast_node *cond;
  114. ast_expression *rest;
  115. } for_rest_statement;
  116. struct {
  117. ast_node *then_statement;
  118. ast_node *else_statement;
  119. } selection_rest_statement;
  120. }
  121. %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
  122. %token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
  123. %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
  124. %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
  125. %token NOPERSPECTIVE FLAT SMOOTH
  126. %token MAT2X2 MAT2X3 MAT2X4
  127. %token MAT3X2 MAT3X3 MAT3X4
  128. %token MAT4X2 MAT4X3 MAT4X4
  129. %token DMAT2X2 DMAT2X3 DMAT2X4
  130. %token DMAT3X2 DMAT3X3 DMAT3X4
  131. %token DMAT4X2 DMAT4X3 DMAT4X4
  132. %token SAMPLER1D SAMPLER2D SAMPLER3D SAMPLERCUBE SAMPLER1DSHADOW SAMPLER2DSHADOW
  133. %token SAMPLERCUBESHADOW SAMPLER1DARRAY SAMPLER2DARRAY SAMPLER1DARRAYSHADOW
  134. %token SAMPLER2DARRAYSHADOW SAMPLERCUBEARRAY SAMPLERCUBEARRAYSHADOW
  135. %token ISAMPLER1D ISAMPLER2D ISAMPLER3D ISAMPLERCUBE
  136. %token ISAMPLER1DARRAY ISAMPLER2DARRAY ISAMPLERCUBEARRAY
  137. %token USAMPLER1D USAMPLER2D USAMPLER3D USAMPLERCUBE USAMPLER1DARRAY
  138. %token USAMPLER2DARRAY USAMPLERCUBEARRAY
  139. %token SAMPLER2DRECT ISAMPLER2DRECT USAMPLER2DRECT SAMPLER2DRECTSHADOW
  140. %token SAMPLERBUFFER ISAMPLERBUFFER USAMPLERBUFFER
  141. %token SAMPLER2DMS ISAMPLER2DMS USAMPLER2DMS
  142. %token SAMPLER2DMSARRAY ISAMPLER2DMSARRAY USAMPLER2DMSARRAY
  143. %token SAMPLEREXTERNALOES
  144. %token IMAGE1D IMAGE2D IMAGE3D IMAGE2DRECT IMAGECUBE IMAGEBUFFER
  145. %token IMAGE1DARRAY IMAGE2DARRAY IMAGECUBEARRAY IMAGE2DMS IMAGE2DMSARRAY
  146. %token IIMAGE1D IIMAGE2D IIMAGE3D IIMAGE2DRECT IIMAGECUBE IIMAGEBUFFER
  147. %token IIMAGE1DARRAY IIMAGE2DARRAY IIMAGECUBEARRAY IIMAGE2DMS IIMAGE2DMSARRAY
  148. %token UIMAGE1D UIMAGE2D UIMAGE3D UIMAGE2DRECT UIMAGECUBE UIMAGEBUFFER
  149. %token UIMAGE1DARRAY UIMAGE2DARRAY UIMAGECUBEARRAY UIMAGE2DMS UIMAGE2DMSARRAY
  150. %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW
  151. %token COHERENT VOLATILE RESTRICT READONLY WRITEONLY
  152. %token ATOMIC_UINT
  153. %token SHARED
  154. %token STRUCT VOID_TOK WHILE
  155. %token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
  156. %type <identifier> any_identifier
  157. %type <interface_block> instance_name_opt
  158. %token <real> FLOATCONSTANT
  159. %token <dreal> DOUBLECONSTANT
  160. %token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
  161. %token <identifier> FIELD_SELECTION
  162. %token LEFT_OP RIGHT_OP
  163. %token INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
  164. %token AND_OP OR_OP XOR_OP MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN
  165. %token MOD_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
  166. %token SUB_ASSIGN
  167. %token INVARIANT PRECISE
  168. %token LOWP MEDIUMP HIGHP SUPERP PRECISION
  169. %token VERSION_TOK EXTENSION LINE COLON EOL INTERFACE OUTPUT
  170. %token PRAGMA_DEBUG_ON PRAGMA_DEBUG_OFF
  171. %token PRAGMA_OPTIMIZE_ON PRAGMA_OPTIMIZE_OFF
  172. %token PRAGMA_INVARIANT_ALL
  173. %token LAYOUT_TOK
  174. %token DOT_TOK
  175. /* Reserved words that are not actually used in the grammar.
  176. */
  177. %token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
  178. %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
  179. %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
  180. %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
  181. %token SAMPLER3DRECT
  182. %token SIZEOF CAST NAMESPACE USING
  183. %token RESOURCE PATCH
  184. %token SUBROUTINE
  185. %token ERROR_TOK
  186. %token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
  187. %type <identifier> variable_identifier
  188. %type <node> statement
  189. %type <node> statement_list
  190. %type <node> simple_statement
  191. %type <n> precision_qualifier
  192. %type <type_qualifier> type_qualifier
  193. %type <type_qualifier> auxiliary_storage_qualifier
  194. %type <type_qualifier> storage_qualifier
  195. %type <type_qualifier> interpolation_qualifier
  196. %type <type_qualifier> layout_qualifier
  197. %type <type_qualifier> layout_qualifier_id_list layout_qualifier_id
  198. %type <type_qualifier> interface_block_layout_qualifier
  199. %type <type_qualifier> memory_qualifier
  200. %type <type_qualifier> subroutine_qualifier
  201. %type <subroutine_list> subroutine_type_list
  202. %type <type_qualifier> interface_qualifier
  203. %type <type_specifier> type_specifier
  204. %type <type_specifier> type_specifier_nonarray
  205. %type <array_specifier> array_specifier
  206. %type <identifier> basic_type_specifier_nonarray
  207. %type <fully_specified_type> fully_specified_type
  208. %type <function> function_prototype
  209. %type <function> function_header
  210. %type <function> function_header_with_parameters
  211. %type <function> function_declarator
  212. %type <parameter_declarator> parameter_declarator
  213. %type <parameter_declarator> parameter_declaration
  214. %type <type_qualifier> parameter_qualifier
  215. %type <type_qualifier> parameter_direction_qualifier
  216. %type <type_specifier> parameter_type_specifier
  217. %type <function_definition> function_definition
  218. %type <compound_statement> compound_statement_no_new_scope
  219. %type <compound_statement> compound_statement
  220. %type <node> statement_no_new_scope
  221. %type <node> expression_statement
  222. %type <expression> expression
  223. %type <expression> primary_expression
  224. %type <expression> assignment_expression
  225. %type <expression> conditional_expression
  226. %type <expression> logical_or_expression
  227. %type <expression> logical_xor_expression
  228. %type <expression> logical_and_expression
  229. %type <expression> inclusive_or_expression
  230. %type <expression> exclusive_or_expression
  231. %type <expression> and_expression
  232. %type <expression> equality_expression
  233. %type <expression> relational_expression
  234. %type <expression> shift_expression
  235. %type <expression> additive_expression
  236. %type <expression> multiplicative_expression
  237. %type <expression> unary_expression
  238. %type <expression> constant_expression
  239. %type <expression> integer_expression
  240. %type <expression> postfix_expression
  241. %type <expression> function_call_header_with_parameters
  242. %type <expression> function_call_header_no_parameters
  243. %type <expression> function_call_header
  244. %type <expression> function_call_generic
  245. %type <expression> function_call_or_method
  246. %type <expression> function_call
  247. %type <n> assignment_operator
  248. %type <n> unary_operator
  249. %type <expression> function_identifier
  250. %type <node> external_declaration
  251. %type <declarator_list> init_declarator_list
  252. %type <declarator_list> single_declaration
  253. %type <expression> initializer
  254. %type <expression> initializer_list
  255. %type <node> declaration
  256. %type <node> declaration_statement
  257. %type <node> jump_statement
  258. %type <node> interface_block
  259. %type <interface_block> basic_interface_block
  260. %type <struct_specifier> struct_specifier
  261. %type <declarator_list> struct_declaration_list
  262. %type <declarator_list> struct_declaration
  263. %type <declaration> struct_declarator
  264. %type <declaration> struct_declarator_list
  265. %type <declarator_list> member_list
  266. %type <declarator_list> member_declaration
  267. %type <node> selection_statement
  268. %type <selection_rest_statement> selection_rest_statement
  269. %type <node> switch_statement
  270. %type <switch_body> switch_body
  271. %type <case_label_list> case_label_list
  272. %type <case_label> case_label
  273. %type <case_statement> case_statement
  274. %type <case_statement_list> case_statement_list
  275. %type <node> iteration_statement
  276. %type <node> condition
  277. %type <node> conditionopt
  278. %type <node> for_init_statement
  279. %type <for_rest_statement> for_rest_statement
  280. %type <node> layout_defaults
  281. %type <type_qualifier> layout_uniform_defaults
  282. %type <type_qualifier> layout_buffer_defaults
  283. %type <type_qualifier> layout_in_defaults
  284. %type <type_qualifier> layout_out_defaults
  285. %right THEN ELSE
  286. %%
  287. translation_unit:
  288. version_statement extension_statement_list
  289. {
  290. _mesa_glsl_initialize_types(state);
  291. }
  292. external_declaration_list
  293. {
  294. delete state->symbols;
  295. state->symbols = new(ralloc_parent(state)) glsl_symbol_table;
  296. if (state->es_shader) {
  297. if (state->stage == MESA_SHADER_FRAGMENT) {
  298. state->symbols->add_default_precision_qualifier("int", ast_precision_medium);
  299. } else {
  300. state->symbols->add_default_precision_qualifier("float", ast_precision_high);
  301. state->symbols->add_default_precision_qualifier("int", ast_precision_high);
  302. }
  303. state->symbols->add_default_precision_qualifier("sampler2D", ast_precision_low);
  304. state->symbols->add_default_precision_qualifier("samplerExternalOES", ast_precision_low);
  305. state->symbols->add_default_precision_qualifier("samplerCube", ast_precision_low);
  306. state->symbols->add_default_precision_qualifier("atomic_uint", ast_precision_high);
  307. }
  308. _mesa_glsl_initialize_types(state);
  309. }
  310. ;
  311. version_statement:
  312. /* blank - no #version specified: defaults are already set */
  313. | VERSION_TOK INTCONSTANT EOL
  314. {
  315. state->process_version_directive(&@2, $2, NULL);
  316. if (state->error) {
  317. YYERROR;
  318. }
  319. }
  320. | VERSION_TOK INTCONSTANT any_identifier EOL
  321. {
  322. state->process_version_directive(&@2, $2, $3);
  323. if (state->error) {
  324. YYERROR;
  325. }
  326. }
  327. ;
  328. pragma_statement:
  329. PRAGMA_DEBUG_ON EOL
  330. | PRAGMA_DEBUG_OFF EOL
  331. | PRAGMA_OPTIMIZE_ON EOL
  332. | PRAGMA_OPTIMIZE_OFF EOL
  333. | PRAGMA_INVARIANT_ALL EOL
  334. {
  335. /* Pragma invariant(all) cannot be used in a fragment shader.
  336. *
  337. * Page 27 of the GLSL 1.20 spec, Page 53 of the GLSL ES 3.00 spec:
  338. *
  339. * "It is an error to use this pragma in a fragment shader."
  340. */
  341. if (state->is_version(120, 300) &&
  342. state->stage == MESA_SHADER_FRAGMENT) {
  343. _mesa_glsl_error(& @1, state,
  344. "pragma `invariant(all)' cannot be used "
  345. "in a fragment shader.");
  346. } else if (!state->is_version(120, 100)) {
  347. _mesa_glsl_warning(& @1, state,
  348. "pragma `invariant(all)' not supported in %s "
  349. "(GLSL ES 1.00 or GLSL 1.20 required)",
  350. state->get_version_string());
  351. } else {
  352. state->all_invariant = true;
  353. }
  354. }
  355. ;
  356. extension_statement_list:
  357. | extension_statement_list extension_statement
  358. ;
  359. any_identifier:
  360. IDENTIFIER
  361. | TYPE_IDENTIFIER
  362. | NEW_IDENTIFIER
  363. ;
  364. extension_statement:
  365. EXTENSION any_identifier COLON any_identifier EOL
  366. {
  367. if (!_mesa_glsl_process_extension($2, & @2, $4, & @4, state)) {
  368. YYERROR;
  369. }
  370. }
  371. ;
  372. external_declaration_list:
  373. external_declaration
  374. {
  375. /* FINISHME: The NULL test is required because pragmas are set to
  376. * FINISHME: NULL. (See production rule for external_declaration.)
  377. */
  378. if ($1 != NULL)
  379. state->translation_unit.push_tail(& $1->link);
  380. }
  381. | external_declaration_list external_declaration
  382. {
  383. /* FINISHME: The NULL test is required because pragmas are set to
  384. * FINISHME: NULL. (See production rule for external_declaration.)
  385. */
  386. if ($2 != NULL)
  387. state->translation_unit.push_tail(& $2->link);
  388. }
  389. | external_declaration_list extension_statement {
  390. if (!state->allow_extension_directive_midshader) {
  391. _mesa_glsl_error(& @2, state,
  392. "#extension directive is not allowed "
  393. "in the middle of a shader");
  394. YYERROR;
  395. }
  396. }
  397. ;
  398. variable_identifier:
  399. IDENTIFIER
  400. | NEW_IDENTIFIER
  401. ;
  402. primary_expression:
  403. variable_identifier
  404. {
  405. void *ctx = state->linalloc;
  406. $$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
  407. $$->set_location(@1);
  408. $$->primary_expression.identifier = $1;
  409. }
  410. | INTCONSTANT
  411. {
  412. void *ctx = state->linalloc;
  413. $$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
  414. $$->set_location(@1);
  415. $$->primary_expression.int_constant = $1;
  416. }
  417. | UINTCONSTANT
  418. {
  419. void *ctx = state->linalloc;
  420. $$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
  421. $$->set_location(@1);
  422. $$->primary_expression.uint_constant = $1;
  423. }
  424. | FLOATCONSTANT
  425. {
  426. void *ctx = state->linalloc;
  427. $$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
  428. $$->set_location(@1);
  429. $$->primary_expression.float_constant = $1;
  430. }
  431. | DOUBLECONSTANT
  432. {
  433. void *ctx = state->linalloc;
  434. $$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
  435. $$->set_location(@1);
  436. $$->primary_expression.double_constant = $1;
  437. }
  438. | BOOLCONSTANT
  439. {
  440. void *ctx = state->linalloc;
  441. $$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
  442. $$->set_location(@1);
  443. $$->primary_expression.bool_constant = $1;
  444. }
  445. | '(' expression ')'
  446. {
  447. $$ = $2;
  448. }
  449. ;
  450. postfix_expression:
  451. primary_expression
  452. | postfix_expression '[' integer_expression ']'
  453. {
  454. void *ctx = state->linalloc;
  455. $$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
  456. $$->set_location_range(@1, @4);
  457. }
  458. | function_call
  459. {
  460. $$ = $1;
  461. }
  462. | postfix_expression DOT_TOK FIELD_SELECTION
  463. {
  464. void *ctx = state->linalloc;
  465. $$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
  466. $$->set_location_range(@1, @3);
  467. $$->primary_expression.identifier = $3;
  468. }
  469. | postfix_expression INC_OP
  470. {
  471. void *ctx = state->linalloc;
  472. $$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
  473. $$->set_location_range(@1, @2);
  474. }
  475. | postfix_expression DEC_OP
  476. {
  477. void *ctx = state->linalloc;
  478. $$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
  479. $$->set_location_range(@1, @2);
  480. }
  481. ;
  482. integer_expression:
  483. expression
  484. ;
  485. function_call:
  486. function_call_or_method
  487. ;
  488. function_call_or_method:
  489. function_call_generic
  490. ;
  491. function_call_generic:
  492. function_call_header_with_parameters ')'
  493. | function_call_header_no_parameters ')'
  494. ;
  495. function_call_header_no_parameters:
  496. function_call_header VOID_TOK
  497. | function_call_header
  498. ;
  499. function_call_header_with_parameters:
  500. function_call_header assignment_expression
  501. {
  502. $$ = $1;
  503. $$->set_location(@1);
  504. $$->expressions.push_tail(& $2->link);
  505. }
  506. | function_call_header_with_parameters ',' assignment_expression
  507. {
  508. $$ = $1;
  509. $$->set_location(@1);
  510. $$->expressions.push_tail(& $3->link);
  511. }
  512. ;
  513. // Grammar Note: Constructors look like functions, but lexical
  514. // analysis recognized most of them as keywords. They are now
  515. // recognized through "type_specifier".
  516. function_call_header:
  517. function_identifier '('
  518. ;
  519. function_identifier:
  520. type_specifier
  521. {
  522. void *ctx = state->linalloc;
  523. $$ = new(ctx) ast_function_expression($1);
  524. $$->set_location(@1);
  525. }
  526. | postfix_expression
  527. {
  528. void *ctx = state->linalloc;
  529. $$ = new(ctx) ast_function_expression($1);
  530. $$->set_location(@1);
  531. }
  532. ;
  533. // Grammar Note: Constructors look like methods, but lexical
  534. // analysis recognized most of them as keywords. They are now
  535. // recognized through "type_specifier".
  536. // Grammar Note: No traditional style type casts.
  537. unary_expression:
  538. postfix_expression
  539. | INC_OP unary_expression
  540. {
  541. void *ctx = state->linalloc;
  542. $$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
  543. $$->set_location(@1);
  544. }
  545. | DEC_OP unary_expression
  546. {
  547. void *ctx = state->linalloc;
  548. $$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
  549. $$->set_location(@1);
  550. }
  551. | unary_operator unary_expression
  552. {
  553. void *ctx = state->linalloc;
  554. $$ = new(ctx) ast_expression($1, $2, NULL, NULL);
  555. $$->set_location_range(@1, @2);
  556. }
  557. ;
  558. // Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
  559. unary_operator:
  560. '+' { $$ = ast_plus; }
  561. | '-' { $$ = ast_neg; }
  562. | '!' { $$ = ast_logic_not; }
  563. | '~' { $$ = ast_bit_not; }
  564. ;
  565. multiplicative_expression:
  566. unary_expression
  567. | multiplicative_expression '*' unary_expression
  568. {
  569. void *ctx = state->linalloc;
  570. $$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
  571. $$->set_location_range(@1, @3);
  572. }
  573. | multiplicative_expression '/' unary_expression
  574. {
  575. void *ctx = state->linalloc;
  576. $$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
  577. $$->set_location_range(@1, @3);
  578. }
  579. | multiplicative_expression '%' unary_expression
  580. {
  581. void *ctx = state->linalloc;
  582. $$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
  583. $$->set_location_range(@1, @3);
  584. }
  585. ;
  586. additive_expression:
  587. multiplicative_expression
  588. | additive_expression '+' multiplicative_expression
  589. {
  590. void *ctx = state->linalloc;
  591. $$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
  592. $$->set_location_range(@1, @3);
  593. }
  594. | additive_expression '-' multiplicative_expression
  595. {
  596. void *ctx = state->linalloc;
  597. $$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
  598. $$->set_location_range(@1, @3);
  599. }
  600. ;
  601. shift_expression:
  602. additive_expression
  603. | shift_expression LEFT_OP additive_expression
  604. {
  605. void *ctx = state->linalloc;
  606. $$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
  607. $$->set_location_range(@1, @3);
  608. }
  609. | shift_expression RIGHT_OP additive_expression
  610. {
  611. void *ctx = state->linalloc;
  612. $$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
  613. $$->set_location_range(@1, @3);
  614. }
  615. ;
  616. relational_expression:
  617. shift_expression
  618. | relational_expression '<' shift_expression
  619. {
  620. void *ctx = state->linalloc;
  621. $$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
  622. $$->set_location_range(@1, @3);
  623. }
  624. | relational_expression '>' shift_expression
  625. {
  626. void *ctx = state->linalloc;
  627. $$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
  628. $$->set_location_range(@1, @3);
  629. }
  630. | relational_expression LE_OP shift_expression
  631. {
  632. void *ctx = state->linalloc;
  633. $$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
  634. $$->set_location_range(@1, @3);
  635. }
  636. | relational_expression GE_OP shift_expression
  637. {
  638. void *ctx = state->linalloc;
  639. $$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
  640. $$->set_location_range(@1, @3);
  641. }
  642. ;
  643. equality_expression:
  644. relational_expression
  645. | equality_expression EQ_OP relational_expression
  646. {
  647. void *ctx = state->linalloc;
  648. $$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
  649. $$->set_location_range(@1, @3);
  650. }
  651. | equality_expression NE_OP relational_expression
  652. {
  653. void *ctx = state->linalloc;
  654. $$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
  655. $$->set_location_range(@1, @3);
  656. }
  657. ;
  658. and_expression:
  659. equality_expression
  660. | and_expression '&' equality_expression
  661. {
  662. void *ctx = state->linalloc;
  663. $$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
  664. $$->set_location_range(@1, @3);
  665. }
  666. ;
  667. exclusive_or_expression:
  668. and_expression
  669. | exclusive_or_expression '^' and_expression
  670. {
  671. void *ctx = state->linalloc;
  672. $$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
  673. $$->set_location_range(@1, @3);
  674. }
  675. ;
  676. inclusive_or_expression:
  677. exclusive_or_expression
  678. | inclusive_or_expression '|' exclusive_or_expression
  679. {
  680. void *ctx = state->linalloc;
  681. $$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
  682. $$->set_location_range(@1, @3);
  683. }
  684. ;
  685. logical_and_expression:
  686. inclusive_or_expression
  687. | logical_and_expression AND_OP inclusive_or_expression
  688. {
  689. void *ctx = state->linalloc;
  690. $$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
  691. $$->set_location_range(@1, @3);
  692. }
  693. ;
  694. logical_xor_expression:
  695. logical_and_expression
  696. | logical_xor_expression XOR_OP logical_and_expression
  697. {
  698. void *ctx = state->linalloc;
  699. $$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
  700. $$->set_location_range(@1, @3);
  701. }
  702. ;
  703. logical_or_expression:
  704. logical_xor_expression
  705. | logical_or_expression OR_OP logical_xor_expression
  706. {
  707. void *ctx = state->linalloc;
  708. $$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
  709. $$->set_location_range(@1, @3);
  710. }
  711. ;
  712. conditional_expression:
  713. logical_or_expression
  714. | logical_or_expression '?' expression ':' assignment_expression
  715. {
  716. void *ctx = state->linalloc;
  717. $$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
  718. $$->set_location_range(@1, @5);
  719. }
  720. ;
  721. assignment_expression:
  722. conditional_expression
  723. | unary_expression assignment_operator assignment_expression
  724. {
  725. void *ctx = state->linalloc;
  726. $$ = new(ctx) ast_expression($2, $1, $3, NULL);
  727. $$->set_location_range(@1, @3);
  728. }
  729. ;
  730. assignment_operator:
  731. '=' { $$ = ast_assign; }
  732. | MUL_ASSIGN { $$ = ast_mul_assign; }
  733. | DIV_ASSIGN { $$ = ast_div_assign; }
  734. | MOD_ASSIGN { $$ = ast_mod_assign; }
  735. | ADD_ASSIGN { $$ = ast_add_assign; }
  736. | SUB_ASSIGN { $$ = ast_sub_assign; }
  737. | LEFT_ASSIGN { $$ = ast_ls_assign; }
  738. | RIGHT_ASSIGN { $$ = ast_rs_assign; }
  739. | AND_ASSIGN { $$ = ast_and_assign; }
  740. | XOR_ASSIGN { $$ = ast_xor_assign; }
  741. | OR_ASSIGN { $$ = ast_or_assign; }
  742. ;
  743. expression:
  744. assignment_expression
  745. {
  746. $$ = $1;
  747. }
  748. | expression ',' assignment_expression
  749. {
  750. void *ctx = state->linalloc;
  751. if ($1->oper != ast_sequence) {
  752. $$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
  753. $$->set_location_range(@1, @3);
  754. $$->expressions.push_tail(& $1->link);
  755. } else {
  756. $$ = $1;
  757. }
  758. $$->expressions.push_tail(& $3->link);
  759. }
  760. ;
  761. constant_expression:
  762. conditional_expression
  763. ;
  764. declaration:
  765. function_prototype ';'
  766. {
  767. state->symbols->pop_scope();
  768. $$ = $1;
  769. }
  770. | init_declarator_list ';'
  771. {
  772. $$ = $1;
  773. }
  774. | PRECISION precision_qualifier type_specifier ';'
  775. {
  776. $3->default_precision = $2;
  777. $$ = $3;
  778. }
  779. | interface_block
  780. {
  781. ast_interface_block *block = (ast_interface_block *) $1;
  782. if (block->layout.has_layout() || block->layout.has_memory()) {
  783. if (!block->default_layout.merge_qualifier(& @1, state, block->layout, false)) {
  784. YYERROR;
  785. }
  786. }
  787. block->layout = block->default_layout;
  788. if (!block->layout.push_to_global(& @1, state)) {
  789. YYERROR;
  790. }
  791. $$ = $1;
  792. }
  793. ;
  794. function_prototype:
  795. function_declarator ')'
  796. ;
  797. function_declarator:
  798. function_header
  799. | function_header_with_parameters
  800. ;
  801. function_header_with_parameters:
  802. function_header parameter_declaration
  803. {
  804. $$ = $1;
  805. $$->parameters.push_tail(& $2->link);
  806. }
  807. | function_header_with_parameters ',' parameter_declaration
  808. {
  809. $$ = $1;
  810. $$->parameters.push_tail(& $3->link);
  811. }
  812. ;
  813. function_header:
  814. fully_specified_type variable_identifier '('
  815. {
  816. void *ctx = state->linalloc;
  817. $$ = new(ctx) ast_function();
  818. $$->set_location(@2);
  819. $$->return_type = $1;
  820. $$->identifier = $2;
  821. if ($1->qualifier.flags.q.subroutine) {
  822. /* add type for IDENTIFIER search */
  823. state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
  824. } else
  825. state->symbols->add_function(new(state) ir_function($2));
  826. state->symbols->push_scope();
  827. }
  828. ;
  829. parameter_declarator:
  830. type_specifier any_identifier
  831. {
  832. void *ctx = state->linalloc;
  833. $$ = new(ctx) ast_parameter_declarator();
  834. $$->set_location_range(@1, @2);
  835. $$->type = new(ctx) ast_fully_specified_type();
  836. $$->type->set_location(@1);
  837. $$->type->specifier = $1;
  838. $$->identifier = $2;
  839. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  840. }
  841. | type_specifier any_identifier array_specifier
  842. {
  843. void *ctx = state->linalloc;
  844. $$ = new(ctx) ast_parameter_declarator();
  845. $$->set_location_range(@1, @3);
  846. $$->type = new(ctx) ast_fully_specified_type();
  847. $$->type->set_location(@1);
  848. $$->type->specifier = $1;
  849. $$->identifier = $2;
  850. $$->array_specifier = $3;
  851. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  852. }
  853. ;
  854. parameter_declaration:
  855. parameter_qualifier parameter_declarator
  856. {
  857. $$ = $2;
  858. $$->type->qualifier = $1;
  859. if (!$$->type->qualifier.push_to_global(& @1, state)) {
  860. YYERROR;
  861. }
  862. }
  863. | parameter_qualifier parameter_type_specifier
  864. {
  865. void *ctx = state->linalloc;
  866. $$ = new(ctx) ast_parameter_declarator();
  867. $$->set_location(@2);
  868. $$->type = new(ctx) ast_fully_specified_type();
  869. $$->type->set_location_range(@1, @2);
  870. $$->type->qualifier = $1;
  871. if (!$$->type->qualifier.push_to_global(& @1, state)) {
  872. YYERROR;
  873. }
  874. $$->type->specifier = $2;
  875. }
  876. ;
  877. parameter_qualifier:
  878. /* empty */
  879. {
  880. memset(& $$, 0, sizeof($$));
  881. }
  882. | CONST_TOK parameter_qualifier
  883. {
  884. if ($2.flags.q.constant)
  885. _mesa_glsl_error(&@1, state, "duplicate const qualifier");
  886. $$ = $2;
  887. $$.flags.q.constant = 1;
  888. }
  889. | PRECISE parameter_qualifier
  890. {
  891. if ($2.flags.q.precise)
  892. _mesa_glsl_error(&@1, state, "duplicate precise qualifier");
  893. $$ = $2;
  894. $$.flags.q.precise = 1;
  895. }
  896. | parameter_direction_qualifier parameter_qualifier
  897. {
  898. if (($1.flags.q.in || $1.flags.q.out) && ($2.flags.q.in || $2.flags.q.out))
  899. _mesa_glsl_error(&@1, state, "duplicate in/out/inout qualifier");
  900. if (!state->has_420pack_or_es31() && $2.flags.q.constant)
  901. _mesa_glsl_error(&@1, state, "in/out/inout must come after const "
  902. "or precise");
  903. $$ = $1;
  904. $$.merge_qualifier(&@1, state, $2, false);
  905. }
  906. | precision_qualifier parameter_qualifier
  907. {
  908. if ($2.precision != ast_precision_none)
  909. _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
  910. if (!state->has_420pack_or_es31() &&
  911. $2.flags.i != 0)
  912. _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
  913. $$ = $2;
  914. $$.precision = $1;
  915. }
  916. | memory_qualifier parameter_qualifier
  917. {
  918. $$ = $1;
  919. $$.merge_qualifier(&@1, state, $2, false);
  920. }
  921. parameter_direction_qualifier:
  922. IN_TOK
  923. {
  924. memset(& $$, 0, sizeof($$));
  925. $$.flags.q.in = 1;
  926. }
  927. | OUT_TOK
  928. {
  929. memset(& $$, 0, sizeof($$));
  930. $$.flags.q.out = 1;
  931. }
  932. | INOUT_TOK
  933. {
  934. memset(& $$, 0, sizeof($$));
  935. $$.flags.q.in = 1;
  936. $$.flags.q.out = 1;
  937. }
  938. ;
  939. parameter_type_specifier:
  940. type_specifier
  941. ;
  942. init_declarator_list:
  943. single_declaration
  944. | init_declarator_list ',' any_identifier
  945. {
  946. void *ctx = state->linalloc;
  947. ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
  948. decl->set_location(@3);
  949. $$ = $1;
  950. $$->declarations.push_tail(&decl->link);
  951. state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  952. }
  953. | init_declarator_list ',' any_identifier array_specifier
  954. {
  955. void *ctx = state->linalloc;
  956. ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
  957. decl->set_location_range(@3, @4);
  958. $$ = $1;
  959. $$->declarations.push_tail(&decl->link);
  960. state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  961. }
  962. | init_declarator_list ',' any_identifier array_specifier '=' initializer
  963. {
  964. void *ctx = state->linalloc;
  965. ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
  966. decl->set_location_range(@3, @4);
  967. $$ = $1;
  968. $$->declarations.push_tail(&decl->link);
  969. state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  970. }
  971. | init_declarator_list ',' any_identifier '=' initializer
  972. {
  973. void *ctx = state->linalloc;
  974. ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
  975. decl->set_location(@3);
  976. $$ = $1;
  977. $$->declarations.push_tail(&decl->link);
  978. state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
  979. }
  980. ;
  981. // Grammar Note: No 'enum', or 'typedef'.
  982. single_declaration:
  983. fully_specified_type
  984. {
  985. void *ctx = state->linalloc;
  986. /* Empty declaration list is valid. */
  987. $$ = new(ctx) ast_declarator_list($1);
  988. $$->set_location(@1);
  989. }
  990. | fully_specified_type any_identifier
  991. {
  992. void *ctx = state->linalloc;
  993. ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
  994. decl->set_location(@2);
  995. $$ = new(ctx) ast_declarator_list($1);
  996. $$->set_location_range(@1, @2);
  997. $$->declarations.push_tail(&decl->link);
  998. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  999. }
  1000. | fully_specified_type any_identifier array_specifier
  1001. {
  1002. void *ctx = state->linalloc;
  1003. ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
  1004. decl->set_location_range(@2, @3);
  1005. $$ = new(ctx) ast_declarator_list($1);
  1006. $$->set_location_range(@1, @3);
  1007. $$->declarations.push_tail(&decl->link);
  1008. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  1009. }
  1010. | fully_specified_type any_identifier array_specifier '=' initializer
  1011. {
  1012. void *ctx = state->linalloc;
  1013. ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
  1014. decl->set_location_range(@2, @3);
  1015. $$ = new(ctx) ast_declarator_list($1);
  1016. $$->set_location_range(@1, @3);
  1017. $$->declarations.push_tail(&decl->link);
  1018. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  1019. }
  1020. | fully_specified_type any_identifier '=' initializer
  1021. {
  1022. void *ctx = state->linalloc;
  1023. ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
  1024. decl->set_location(@2);
  1025. $$ = new(ctx) ast_declarator_list($1);
  1026. $$->set_location_range(@1, @2);
  1027. $$->declarations.push_tail(&decl->link);
  1028. state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
  1029. }
  1030. | INVARIANT variable_identifier
  1031. {
  1032. void *ctx = state->linalloc;
  1033. ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
  1034. decl->set_location(@2);
  1035. $$ = new(ctx) ast_declarator_list(NULL);
  1036. $$->set_location_range(@1, @2);
  1037. $$->invariant = true;
  1038. $$->declarations.push_tail(&decl->link);
  1039. }
  1040. | PRECISE variable_identifier
  1041. {
  1042. void *ctx = state->linalloc;
  1043. ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
  1044. decl->set_location(@2);
  1045. $$ = new(ctx) ast_declarator_list(NULL);
  1046. $$->set_location_range(@1, @2);
  1047. $$->precise = true;
  1048. $$->declarations.push_tail(&decl->link);
  1049. }
  1050. ;
  1051. fully_specified_type:
  1052. type_specifier
  1053. {
  1054. void *ctx = state->linalloc;
  1055. $$ = new(ctx) ast_fully_specified_type();
  1056. $$->set_location(@1);
  1057. $$->specifier = $1;
  1058. }
  1059. | type_qualifier type_specifier
  1060. {
  1061. void *ctx = state->linalloc;
  1062. $$ = new(ctx) ast_fully_specified_type();
  1063. $$->set_location_range(@1, @2);
  1064. $$->qualifier = $1;
  1065. if (!$$->qualifier.push_to_global(& @1, state)) {
  1066. YYERROR;
  1067. }
  1068. $$->specifier = $2;
  1069. if ($$->specifier->structure != NULL &&
  1070. $$->specifier->structure->is_declaration) {
  1071. $$->specifier->structure->layout = &$$->qualifier;
  1072. }
  1073. }
  1074. ;
  1075. layout_qualifier:
  1076. LAYOUT_TOK '(' layout_qualifier_id_list ')'
  1077. {
  1078. $$ = $3;
  1079. }
  1080. ;
  1081. layout_qualifier_id_list:
  1082. layout_qualifier_id
  1083. | layout_qualifier_id_list ',' layout_qualifier_id
  1084. {
  1085. $$ = $1;
  1086. if (!$$.merge_qualifier(& @3, state, $3, true)) {
  1087. YYERROR;
  1088. }
  1089. }
  1090. ;
  1091. layout_qualifier_id:
  1092. any_identifier
  1093. {
  1094. memset(& $$, 0, sizeof($$));
  1095. /* Layout qualifiers for ARB_fragment_coord_conventions. */
  1096. if (!$$.flags.i && (state->ARB_fragment_coord_conventions_enable ||
  1097. state->is_version(150, 0))) {
  1098. if (match_layout_qualifier($1, "origin_upper_left", state) == 0) {
  1099. $$.flags.q.origin_upper_left = 1;
  1100. } else if (match_layout_qualifier($1, "pixel_center_integer",
  1101. state) == 0) {
  1102. $$.flags.q.pixel_center_integer = 1;
  1103. }
  1104. if ($$.flags.i && state->ARB_fragment_coord_conventions_warn) {
  1105. _mesa_glsl_warning(& @1, state,
  1106. "GL_ARB_fragment_coord_conventions layout "
  1107. "identifier `%s' used", $1);
  1108. }
  1109. }
  1110. /* Layout qualifiers for AMD/ARB_conservative_depth. */
  1111. if (!$$.flags.i &&
  1112. (state->AMD_conservative_depth_enable ||
  1113. state->ARB_conservative_depth_enable ||
  1114. state->is_version(420, 0))) {
  1115. if (match_layout_qualifier($1, "depth_any", state) == 0) {
  1116. $$.flags.q.depth_any = 1;
  1117. } else if (match_layout_qualifier($1, "depth_greater", state) == 0) {
  1118. $$.flags.q.depth_greater = 1;
  1119. } else if (match_layout_qualifier($1, "depth_less", state) == 0) {
  1120. $$.flags.q.depth_less = 1;
  1121. } else if (match_layout_qualifier($1, "depth_unchanged",
  1122. state) == 0) {
  1123. $$.flags.q.depth_unchanged = 1;
  1124. }
  1125. if ($$.flags.i && state->AMD_conservative_depth_warn) {
  1126. _mesa_glsl_warning(& @1, state,
  1127. "GL_AMD_conservative_depth "
  1128. "layout qualifier `%s' is used", $1);
  1129. }
  1130. if ($$.flags.i && state->ARB_conservative_depth_warn) {
  1131. _mesa_glsl_warning(& @1, state,
  1132. "GL_ARB_conservative_depth "
  1133. "layout qualifier `%s' is used", $1);
  1134. }
  1135. }
  1136. /* See also interface_block_layout_qualifier. */
  1137. if (!$$.flags.i && state->has_uniform_buffer_objects()) {
  1138. if (match_layout_qualifier($1, "std140", state) == 0) {
  1139. $$.flags.q.std140 = 1;
  1140. } else if (match_layout_qualifier($1, "shared", state) == 0) {
  1141. $$.flags.q.shared = 1;
  1142. } else if (match_layout_qualifier($1, "std430", state) == 0) {
  1143. $$.flags.q.std430 = 1;
  1144. } else if (match_layout_qualifier($1, "column_major", state) == 0) {
  1145. $$.flags.q.column_major = 1;
  1146. /* "row_major" is a reserved word in GLSL 1.30+. Its token is parsed
  1147. * below in the interface_block_layout_qualifier rule.
  1148. *
  1149. * It is not a reserved word in GLSL ES 3.00, so it's handled here as
  1150. * an identifier.
  1151. *
  1152. * Also, this takes care of alternate capitalizations of
  1153. * "row_major" (which is necessary because layout qualifiers
  1154. * are case-insensitive in desktop GLSL).
  1155. */
  1156. } else if (match_layout_qualifier($1, "row_major", state) == 0) {
  1157. $$.flags.q.row_major = 1;
  1158. /* "packed" is a reserved word in GLSL, and its token is
  1159. * parsed below in the interface_block_layout_qualifier rule.
  1160. * However, we must take care of alternate capitalizations of
  1161. * "packed", because layout qualifiers are case-insensitive
  1162. * in desktop GLSL.
  1163. */
  1164. } else if (match_layout_qualifier($1, "packed", state) == 0) {
  1165. $$.flags.q.packed = 1;
  1166. }
  1167. if ($$.flags.i && state->ARB_uniform_buffer_object_warn) {
  1168. _mesa_glsl_warning(& @1, state,
  1169. "#version 140 / GL_ARB_uniform_buffer_object "
  1170. "layout qualifier `%s' is used", $1);
  1171. }
  1172. }
  1173. /* Layout qualifiers for GLSL 1.50 geometry shaders. */
  1174. if (!$$.flags.i) {
  1175. static const struct {
  1176. const char *s;
  1177. GLenum e;
  1178. } map[] = {
  1179. { "points", GL_POINTS },
  1180. { "lines", GL_LINES },
  1181. { "lines_adjacency", GL_LINES_ADJACENCY },
  1182. { "line_strip", GL_LINE_STRIP },
  1183. { "triangles", GL_TRIANGLES },
  1184. { "triangles_adjacency", GL_TRIANGLES_ADJACENCY },
  1185. { "triangle_strip", GL_TRIANGLE_STRIP },
  1186. };
  1187. for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
  1188. if (match_layout_qualifier($1, map[i].s, state) == 0) {
  1189. $$.flags.q.prim_type = 1;
  1190. $$.prim_type = map[i].e;
  1191. break;
  1192. }
  1193. }
  1194. if ($$.flags.i && !state->has_geometry_shader() &&
  1195. !state->has_tessellation_shader()) {
  1196. _mesa_glsl_error(& @1, state, "#version 150 layout "
  1197. "qualifier `%s' used", $1);
  1198. }
  1199. }
  1200. /* Layout qualifiers for ARB_shader_image_load_store. */
  1201. if (state->ARB_shader_image_load_store_enable ||
  1202. state->is_version(420, 310)) {
  1203. if (!$$.flags.i) {
  1204. static const struct {
  1205. const char *name;
  1206. GLenum format;
  1207. glsl_base_type base_type;
  1208. /** Minimum desktop GLSL version required for the image
  1209. * format. Use 130 if already present in the original
  1210. * ARB extension.
  1211. */
  1212. unsigned required_glsl;
  1213. /** Minimum GLSL ES version required for the image format. */
  1214. unsigned required_essl;
  1215. /* NV_image_formats */
  1216. bool nv_image_formats;
  1217. } map[] = {
  1218. { "rgba32f", GL_RGBA32F, GLSL_TYPE_FLOAT, 130, 310, false },
  1219. { "rgba16f", GL_RGBA16F, GLSL_TYPE_FLOAT, 130, 310, false },
  1220. { "rg32f", GL_RG32F, GLSL_TYPE_FLOAT, 130, 0, true },
  1221. { "rg16f", GL_RG16F, GLSL_TYPE_FLOAT, 130, 0, true },
  1222. { "r11f_g11f_b10f", GL_R11F_G11F_B10F, GLSL_TYPE_FLOAT, 130, 0, true },
  1223. { "r32f", GL_R32F, GLSL_TYPE_FLOAT, 130, 310, false },
  1224. { "r16f", GL_R16F, GLSL_TYPE_FLOAT, 130, 0, true },
  1225. { "rgba32ui", GL_RGBA32UI, GLSL_TYPE_UINT, 130, 310, false },
  1226. { "rgba16ui", GL_RGBA16UI, GLSL_TYPE_UINT, 130, 310, false },
  1227. { "rgb10_a2ui", GL_RGB10_A2UI, GLSL_TYPE_UINT, 130, 0, true },
  1228. { "rgba8ui", GL_RGBA8UI, GLSL_TYPE_UINT, 130, 310, false },
  1229. { "rg32ui", GL_RG32UI, GLSL_TYPE_UINT, 130, 0, true },
  1230. { "rg16ui", GL_RG16UI, GLSL_TYPE_UINT, 130, 0, true },
  1231. { "rg8ui", GL_RG8UI, GLSL_TYPE_UINT, 130, 0, true },
  1232. { "r32ui", GL_R32UI, GLSL_TYPE_UINT, 130, 310, false },
  1233. { "r16ui", GL_R16UI, GLSL_TYPE_UINT, 130, 0, true },
  1234. { "r8ui", GL_R8UI, GLSL_TYPE_UINT, 130, 0, true },
  1235. { "rgba32i", GL_RGBA32I, GLSL_TYPE_INT, 130, 310, false },
  1236. { "rgba16i", GL_RGBA16I, GLSL_TYPE_INT, 130, 310, false },
  1237. { "rgba8i", GL_RGBA8I, GLSL_TYPE_INT, 130, 310, false },
  1238. { "rg32i", GL_RG32I, GLSL_TYPE_INT, 130, 0, true },
  1239. { "rg16i", GL_RG16I, GLSL_TYPE_INT, 130, 0, true },
  1240. { "rg8i", GL_RG8I, GLSL_TYPE_INT, 130, 0, true },
  1241. { "r32i", GL_R32I, GLSL_TYPE_INT, 130, 310, false },
  1242. { "r16i", GL_R16I, GLSL_TYPE_INT, 130, 0, true },
  1243. { "r8i", GL_R8I, GLSL_TYPE_INT, 130, 0, true },
  1244. { "rgba16", GL_RGBA16, GLSL_TYPE_FLOAT, 130, 0, false },
  1245. { "rgb10_a2", GL_RGB10_A2, GLSL_TYPE_FLOAT, 130, 0, true },
  1246. { "rgba8", GL_RGBA8, GLSL_TYPE_FLOAT, 130, 310, false },
  1247. { "rg16", GL_RG16, GLSL_TYPE_FLOAT, 130, 0, false },
  1248. { "rg8", GL_RG8, GLSL_TYPE_FLOAT, 130, 0, true },
  1249. { "r16", GL_R16, GLSL_TYPE_FLOAT, 130, 0, false },
  1250. { "r8", GL_R8, GLSL_TYPE_FLOAT, 130, 0, true },
  1251. { "rgba16_snorm", GL_RGBA16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
  1252. { "rgba8_snorm", GL_RGBA8_SNORM, GLSL_TYPE_FLOAT, 130, 310, false },
  1253. { "rg16_snorm", GL_RG16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
  1254. { "rg8_snorm", GL_RG8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true },
  1255. { "r16_snorm", GL_R16_SNORM, GLSL_TYPE_FLOAT, 130, 0, false },
  1256. { "r8_snorm", GL_R8_SNORM, GLSL_TYPE_FLOAT, 130, 0, true }
  1257. };
  1258. for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
  1259. if ((state->is_version(map[i].required_glsl,
  1260. map[i].required_essl) ||
  1261. (state->NV_image_formats_enable &&
  1262. map[i].nv_image_formats)) &&
  1263. match_layout_qualifier($1, map[i].name, state) == 0) {
  1264. $$.flags.q.explicit_image_format = 1;
  1265. $$.image_format = map[i].format;
  1266. $$.image_base_type = map[i].base_type;
  1267. break;
  1268. }
  1269. }
  1270. }
  1271. if (!$$.flags.i &&
  1272. match_layout_qualifier($1, "early_fragment_tests", state) == 0) {
  1273. /* From section 4.4.1.3 of the GLSL 4.50 specification
  1274. * (Fragment Shader Inputs):
  1275. *
  1276. * "Fragment shaders also allow the following layout
  1277. * qualifier on in only (not with variable declarations)
  1278. * layout-qualifier-id
  1279. * early_fragment_tests
  1280. * [...]"
  1281. */
  1282. if (state->stage != MESA_SHADER_FRAGMENT) {
  1283. _mesa_glsl_error(& @1, state,
  1284. "early_fragment_tests layout qualifier only "
  1285. "valid in fragment shaders");
  1286. }
  1287. $$.flags.q.early_fragment_tests = 1;
  1288. }
  1289. }
  1290. /* Layout qualifiers for tessellation evaluation shaders. */
  1291. if (!$$.flags.i) {
  1292. static const struct {
  1293. const char *s;
  1294. GLenum e;
  1295. } map[] = {
  1296. /* triangles already parsed by gs-specific code */
  1297. { "quads", GL_QUADS },
  1298. { "isolines", GL_ISOLINES },
  1299. };
  1300. for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
  1301. if (match_layout_qualifier($1, map[i].s, state) == 0) {
  1302. $$.flags.q.prim_type = 1;
  1303. $$.prim_type = map[i].e;
  1304. break;
  1305. }
  1306. }
  1307. if ($$.flags.i && !state->has_tessellation_shader()) {
  1308. _mesa_glsl_error(& @1, state,
  1309. "primitive mode qualifier `%s' requires "
  1310. "GLSL 4.00 or ARB_tessellation_shader", $1);
  1311. }
  1312. }
  1313. if (!$$.flags.i) {
  1314. static const struct {
  1315. const char *s;
  1316. GLenum e;
  1317. } map[] = {
  1318. { "equal_spacing", GL_EQUAL },
  1319. { "fractional_odd_spacing", GL_FRACTIONAL_ODD },
  1320. { "fractional_even_spacing", GL_FRACTIONAL_EVEN },
  1321. };
  1322. for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
  1323. if (match_layout_qualifier($1, map[i].s, state) == 0) {
  1324. $$.flags.q.vertex_spacing = 1;
  1325. $$.vertex_spacing = map[i].e;
  1326. break;
  1327. }
  1328. }
  1329. if ($$.flags.i && !state->has_tessellation_shader()) {
  1330. _mesa_glsl_error(& @1, state,
  1331. "vertex spacing qualifier `%s' requires "
  1332. "GLSL 4.00 or ARB_tessellation_shader", $1);
  1333. }
  1334. }
  1335. if (!$$.flags.i) {
  1336. if (match_layout_qualifier($1, "cw", state) == 0) {
  1337. $$.flags.q.ordering = 1;
  1338. $$.ordering = GL_CW;
  1339. } else if (match_layout_qualifier($1, "ccw", state) == 0) {
  1340. $$.flags.q.ordering = 1;
  1341. $$.ordering = GL_CCW;
  1342. }
  1343. if ($$.flags.i && !state->has_tessellation_shader()) {
  1344. _mesa_glsl_error(& @1, state,
  1345. "ordering qualifier `%s' requires "
  1346. "GLSL 4.00 or ARB_tessellation_shader", $1);
  1347. }
  1348. }
  1349. if (!$$.flags.i) {
  1350. if (match_layout_qualifier($1, "point_mode", state) == 0) {
  1351. $$.flags.q.point_mode = 1;
  1352. $$.point_mode = true;
  1353. }
  1354. if ($$.flags.i && !state->has_tessellation_shader()) {
  1355. _mesa_glsl_error(& @1, state,
  1356. "qualifier `point_mode' requires "
  1357. "GLSL 4.00 or ARB_tessellation_shader");
  1358. }
  1359. }
  1360. if (!$$.flags.i) {
  1361. static const struct {
  1362. const char *s;
  1363. uint32_t mask;
  1364. } map[] = {
  1365. { "blend_support_multiply", BLEND_MULTIPLY },
  1366. { "blend_support_screen", BLEND_SCREEN },
  1367. { "blend_support_overlay", BLEND_OVERLAY },
  1368. { "blend_support_darken", BLEND_DARKEN },
  1369. { "blend_support_lighten", BLEND_LIGHTEN },
  1370. { "blend_support_colordodge", BLEND_COLORDODGE },
  1371. { "blend_support_colorburn", BLEND_COLORBURN },
  1372. { "blend_support_hardlight", BLEND_HARDLIGHT },
  1373. { "blend_support_softlight", BLEND_SOFTLIGHT },
  1374. { "blend_support_difference", BLEND_DIFFERENCE },
  1375. { "blend_support_exclusion", BLEND_EXCLUSION },
  1376. { "blend_support_hsl_hue", BLEND_HSL_HUE },
  1377. { "blend_support_hsl_saturation", BLEND_HSL_SATURATION },
  1378. { "blend_support_hsl_color", BLEND_HSL_COLOR },
  1379. { "blend_support_hsl_luminosity", BLEND_HSL_LUMINOSITY },
  1380. { "blend_support_all_equations", BLEND_ALL },
  1381. };
  1382. for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
  1383. if (match_layout_qualifier($1, map[i].s, state) == 0) {
  1384. $$.flags.q.blend_support = 1;
  1385. state->fs_blend_support |= map[i].mask;
  1386. break;
  1387. }
  1388. }
  1389. if ($$.flags.i &&
  1390. !state->KHR_blend_equation_advanced_enable &&
  1391. !state->is_version(0, 320)) {
  1392. _mesa_glsl_error(& @1, state,
  1393. "advanced blending layout qualifiers require "
  1394. "ESSL 3.20 or KHR_blend_equation_advanced");
  1395. }
  1396. if ($$.flags.i && state->stage != MESA_SHADER_FRAGMENT) {
  1397. _mesa_glsl_error(& @1, state,
  1398. "advanced blending layout qualifiers only "
  1399. "valid in fragment shaders");
  1400. }
  1401. }
  1402. /* Layout qualifiers for ARB_compute_variable_group_size. */
  1403. if (!$$.flags.i) {
  1404. if (match_layout_qualifier($1, "local_size_variable", state) == 0) {
  1405. $$.flags.q.local_size_variable = 1;
  1406. }
  1407. if ($$.flags.i && !state->ARB_compute_variable_group_size_enable) {
  1408. _mesa_glsl_error(& @1, state,
  1409. "qualifier `local_size_variable` requires "
  1410. "ARB_compute_variable_group_size");
  1411. }
  1412. }
  1413. if (!$$.flags.i) {
  1414. _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
  1415. "`%s'", $1);
  1416. YYERROR;
  1417. }
  1418. }
  1419. | any_identifier '=' constant_expression
  1420. {
  1421. memset(& $$, 0, sizeof($$));
  1422. void *ctx = state->linalloc;
  1423. if ($3->oper != ast_int_constant &&
  1424. $3->oper != ast_uint_constant &&
  1425. !state->has_enhanced_layouts()) {
  1426. _mesa_glsl_error(& @1, state,
  1427. "compile-time constant expressions require "
  1428. "GLSL 4.40 or ARB_enhanced_layouts");
  1429. }
  1430. if (match_layout_qualifier("align", $1, state) == 0) {
  1431. if (!state->has_enhanced_layouts()) {
  1432. _mesa_glsl_error(& @1, state,
  1433. "align qualifier requires "
  1434. "GLSL 4.40 or ARB_enhanced_layouts");
  1435. } else {
  1436. $$.flags.q.explicit_align = 1;
  1437. $$.align = $3;
  1438. }
  1439. }
  1440. if (match_layout_qualifier("location", $1, state) == 0) {
  1441. $$.flags.q.explicit_location = 1;
  1442. if ($$.flags.q.attribute == 1 &&
  1443. state->ARB_explicit_attrib_location_warn) {
  1444. _mesa_glsl_warning(& @1, state,
  1445. "GL_ARB_explicit_attrib_location layout "
  1446. "identifier `%s' used", $1);
  1447. }
  1448. $$.location = $3;
  1449. }
  1450. if (match_layout_qualifier("component", $1, state) == 0) {
  1451. if (!state->has_enhanced_layouts()) {
  1452. _mesa_glsl_error(& @1, state,
  1453. "component qualifier requires "
  1454. "GLSL 4.40 or ARB_enhanced_layouts");
  1455. } else {
  1456. $$.flags.q.explicit_component = 1;
  1457. $$.component = $3;
  1458. }
  1459. }
  1460. if (match_layout_qualifier("index", $1, state) == 0) {
  1461. if (state->es_shader && !state->EXT_blend_func_extended_enable) {
  1462. _mesa_glsl_error(& @3, state, "index layout qualifier requires EXT_blend_func_extended");
  1463. YYERROR;
  1464. }
  1465. $$.flags.q.explicit_index = 1;
  1466. $$.index = $3;
  1467. }
  1468. if ((state->has_420pack_or_es31() ||
  1469. state->has_atomic_counters() ||
  1470. state->has_shader_storage_buffer_objects()) &&
  1471. match_layout_qualifier("binding", $1, state) == 0) {
  1472. $$.flags.q.explicit_binding = 1;
  1473. $$.binding = $3;
  1474. }
  1475. if ((state->has_atomic_counters() ||
  1476. state->has_enhanced_layouts()) &&
  1477. match_layout_qualifier("offset", $1, state) == 0) {
  1478. $$.flags.q.explicit_offset = 1;
  1479. $$.offset = $3;
  1480. }
  1481. if (match_layout_qualifier("max_vertices", $1, state) == 0) {
  1482. $$.flags.q.max_vertices = 1;
  1483. $$.max_vertices = new(ctx) ast_layout_expression(@1, $3);
  1484. if (!state->has_geometry_shader()) {
  1485. _mesa_glsl_error(& @3, state,
  1486. "#version 150 max_vertices qualifier "
  1487. "specified", $3);
  1488. }
  1489. }
  1490. if (state->stage == MESA_SHADER_GEOMETRY) {
  1491. if (match_layout_qualifier("stream", $1, state) == 0 &&
  1492. state->check_explicit_attrib_stream_allowed(& @3)) {
  1493. $$.flags.q.stream = 1;
  1494. $$.flags.q.explicit_stream = 1;
  1495. $$.stream = $3;
  1496. }
  1497. }
  1498. if (state->has_enhanced_layouts()) {
  1499. if (match_layout_qualifier("xfb_buffer", $1, state) == 0) {
  1500. $$.flags.q.xfb_buffer = 1;
  1501. $$.flags.q.explicit_xfb_buffer = 1;
  1502. $$.xfb_buffer = $3;
  1503. }
  1504. if (match_layout_qualifier("xfb_offset", $1, state) == 0) {
  1505. $$.flags.q.explicit_xfb_offset = 1;
  1506. $$.offset = $3;
  1507. }
  1508. if (match_layout_qualifier("xfb_stride", $1, state) == 0) {
  1509. $$.flags.q.xfb_stride = 1;
  1510. $$.flags.q.explicit_xfb_stride = 1;
  1511. $$.xfb_stride = $3;
  1512. }
  1513. }
  1514. static const char * const local_size_qualifiers[3] = {
  1515. "local_size_x",
  1516. "local_size_y",
  1517. "local_size_z",
  1518. };
  1519. for (int i = 0; i < 3; i++) {
  1520. if (match_layout_qualifier(local_size_qualifiers[i], $1,
  1521. state) == 0) {
  1522. if (!state->has_compute_shader()) {
  1523. _mesa_glsl_error(& @3, state,
  1524. "%s qualifier requires GLSL 4.30 or "
  1525. "GLSL ES 3.10 or ARB_compute_shader",
  1526. local_size_qualifiers[i]);
  1527. YYERROR;
  1528. } else {
  1529. $$.flags.q.local_size |= (1 << i);
  1530. $$.local_size[i] = new(ctx) ast_layout_expression(@1, $3);
  1531. }
  1532. break;
  1533. }
  1534. }
  1535. if (match_layout_qualifier("invocations", $1, state) == 0) {
  1536. $$.flags.q.invocations = 1;
  1537. $$.invocations = new(ctx) ast_layout_expression(@1, $3);
  1538. if (!state->is_version(400, 320) &&
  1539. !state->ARB_gpu_shader5_enable &&
  1540. !state->OES_geometry_shader_enable &&
  1541. !state->EXT_geometry_shader_enable) {
  1542. _mesa_glsl_error(& @3, state,
  1543. "GL_ARB_gpu_shader5 invocations "
  1544. "qualifier specified", $3);
  1545. }
  1546. }
  1547. /* Layout qualifiers for tessellation control shaders. */
  1548. if (match_layout_qualifier("vertices", $1, state) == 0) {
  1549. $$.flags.q.vertices = 1;
  1550. $$.vertices = new(ctx) ast_layout_expression(@1, $3);
  1551. if (!state->has_tessellation_shader()) {
  1552. _mesa_glsl_error(& @1, state,
  1553. "vertices qualifier requires GLSL 4.00 or "
  1554. "ARB_tessellation_shader");
  1555. }
  1556. }
  1557. /* If the identifier didn't match any known layout identifiers,
  1558. * emit an error.
  1559. */
  1560. if (!$$.flags.i) {
  1561. _mesa_glsl_error(& @1, state, "unrecognized layout identifier "
  1562. "`%s'", $1);
  1563. YYERROR;
  1564. }
  1565. }
  1566. | interface_block_layout_qualifier
  1567. {
  1568. $$ = $1;
  1569. /* Layout qualifiers for ARB_uniform_buffer_object. */
  1570. if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
  1571. _mesa_glsl_error(& @1, state,
  1572. "#version 140 / GL_ARB_uniform_buffer_object "
  1573. "layout qualifier `%s' is used", $1);
  1574. } else if ($$.flags.q.uniform && state->ARB_uniform_buffer_object_warn) {
  1575. _mesa_glsl_warning(& @1, state,
  1576. "#version 140 / GL_ARB_uniform_buffer_object "
  1577. "layout qualifier `%s' is used", $1);
  1578. }
  1579. }
  1580. ;
  1581. /* This is a separate language rule because we parse these as tokens
  1582. * (due to them being reserved keywords) instead of identifiers like
  1583. * most qualifiers. See the any_identifier path of
  1584. * layout_qualifier_id for the others.
  1585. *
  1586. * Note that since layout qualifiers are case-insensitive in desktop
  1587. * GLSL, all of these qualifiers need to be handled as identifiers as
  1588. * well (by the any_identifier path of layout_qualifier_id).
  1589. */
  1590. interface_block_layout_qualifier:
  1591. ROW_MAJOR
  1592. {
  1593. memset(& $$, 0, sizeof($$));
  1594. $$.flags.q.row_major = 1;
  1595. }
  1596. | PACKED_TOK
  1597. {
  1598. memset(& $$, 0, sizeof($$));
  1599. $$.flags.q.packed = 1;
  1600. }
  1601. | SHARED
  1602. {
  1603. memset(& $$, 0, sizeof($$));
  1604. $$.flags.q.shared = 1;
  1605. }
  1606. ;
  1607. subroutine_qualifier:
  1608. SUBROUTINE
  1609. {
  1610. memset(& $$, 0, sizeof($$));
  1611. $$.flags.q.subroutine = 1;
  1612. }
  1613. | SUBROUTINE '(' subroutine_type_list ')'
  1614. {
  1615. memset(& $$, 0, sizeof($$));
  1616. $$.flags.q.subroutine_def = 1;
  1617. $$.subroutine_list = $3;
  1618. }
  1619. ;
  1620. subroutine_type_list:
  1621. any_identifier
  1622. {
  1623. void *ctx = state->linalloc;
  1624. ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
  1625. decl->set_location(@1);
  1626. $$ = new(ctx) ast_subroutine_list();
  1627. $$->declarations.push_tail(&decl->link);
  1628. }
  1629. | subroutine_type_list ',' any_identifier
  1630. {
  1631. void *ctx = state->linalloc;
  1632. ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
  1633. decl->set_location(@3);
  1634. $$ = $1;
  1635. $$->declarations.push_tail(&decl->link);
  1636. }
  1637. ;
  1638. interpolation_qualifier:
  1639. SMOOTH
  1640. {
  1641. memset(& $$, 0, sizeof($$));
  1642. $$.flags.q.smooth = 1;
  1643. }
  1644. | FLAT
  1645. {
  1646. memset(& $$, 0, sizeof($$));
  1647. $$.flags.q.flat = 1;
  1648. }
  1649. | NOPERSPECTIVE
  1650. {
  1651. memset(& $$, 0, sizeof($$));
  1652. $$.flags.q.noperspective = 1;
  1653. }
  1654. ;
  1655. type_qualifier:
  1656. /* Single qualifiers */
  1657. INVARIANT
  1658. {
  1659. memset(& $$, 0, sizeof($$));
  1660. $$.flags.q.invariant = 1;
  1661. }
  1662. | PRECISE
  1663. {
  1664. memset(& $$, 0, sizeof($$));
  1665. $$.flags.q.precise = 1;
  1666. }
  1667. | auxiliary_storage_qualifier
  1668. | storage_qualifier
  1669. | interpolation_qualifier
  1670. | layout_qualifier
  1671. | memory_qualifier
  1672. | subroutine_qualifier
  1673. | precision_qualifier
  1674. {
  1675. memset(&$$, 0, sizeof($$));
  1676. $$.precision = $1;
  1677. }
  1678. /* Multiple qualifiers:
  1679. * In GLSL 4.20, these can be specified in any order. In earlier versions,
  1680. * they appear in this order (see GLSL 1.50 section 4.7 & comments below):
  1681. *
  1682. * invariant interpolation auxiliary storage precision ...or...
  1683. * layout storage precision
  1684. *
  1685. * Each qualifier's rule ensures that the accumulated qualifiers on the right
  1686. * side don't contain any that must appear on the left hand side.
  1687. * For example, when processing a storage qualifier, we check that there are
  1688. * no auxiliary, interpolation, layout, invariant, or precise qualifiers to the right.
  1689. */
  1690. | PRECISE type_qualifier
  1691. {
  1692. if ($2.flags.q.precise)
  1693. _mesa_glsl_error(&@1, state, "duplicate \"precise\" qualifier");
  1694. $$ = $2;
  1695. $$.flags.q.precise = 1;
  1696. }
  1697. | INVARIANT type_qualifier
  1698. {
  1699. if ($2.flags.q.invariant)
  1700. _mesa_glsl_error(&@1, state, "duplicate \"invariant\" qualifier");
  1701. if (!state->has_420pack_or_es31() && $2.flags.q.precise)
  1702. _mesa_glsl_error(&@1, state,
  1703. "\"invariant\" must come after \"precise\"");
  1704. $$ = $2;
  1705. $$.flags.q.invariant = 1;
  1706. /* GLSL ES 3.00 spec, section 4.6.1 "The Invariant Qualifier":
  1707. *
  1708. * "Only variables output from a shader can be candidates for invariance.
  1709. * This includes user-defined output variables and the built-in output
  1710. * variables. As only outputs can be declared as invariant, an invariant
  1711. * output from one shader stage will still match an input of a subsequent
  1712. * stage without the input being declared as invariant."
  1713. *
  1714. * On the desktop side, this text first appears in GLSL 4.30.
  1715. */
  1716. if (state->is_version(430, 300) && $$.flags.q.in)
  1717. _mesa_glsl_error(&@1, state, "invariant qualifiers cannot be used with shader inputs");
  1718. }
  1719. | interpolation_qualifier type_qualifier
  1720. {
  1721. /* Section 4.3 of the GLSL 1.40 specification states:
  1722. * "...qualified with one of these interpolation qualifiers"
  1723. *
  1724. * GLSL 1.30 claims to allow "one or more", but insists that:
  1725. * "These interpolation qualifiers may only precede the qualifiers in,
  1726. * centroid in, out, or centroid out in a declaration."
  1727. *
  1728. * ...which means that e.g. smooth can't precede smooth, so there can be
  1729. * only one after all, and the 1.40 text is a clarification, not a change.
  1730. */
  1731. if ($2.has_interpolation())
  1732. _mesa_glsl_error(&@1, state, "duplicate interpolation qualifier");
  1733. if (!state->has_420pack_or_es31() &&
  1734. ($2.flags.q.precise || $2.flags.q.invariant)) {
  1735. _mesa_glsl_error(&@1, state, "interpolation qualifiers must come "
  1736. "after \"precise\" or \"invariant\"");
  1737. }
  1738. $$ = $1;
  1739. $$.merge_qualifier(&@1, state, $2, false);
  1740. }
  1741. | layout_qualifier type_qualifier
  1742. {
  1743. /* In the absence of ARB_shading_language_420pack, layout qualifiers may
  1744. * appear no later than auxiliary storage qualifiers. There is no
  1745. * particularly clear spec language mandating this, but in all examples
  1746. * the layout qualifier precedes the storage qualifier.
  1747. *
  1748. * We allow combinations of layout with interpolation, invariant or
  1749. * precise qualifiers since these are useful in ARB_separate_shader_objects.
  1750. * There is no clear spec guidance on this either.
  1751. */
  1752. $$ = $1;
  1753. $$.merge_qualifier(& @1, state, $2, false, $2.has_layout());
  1754. }
  1755. | subroutine_qualifier type_qualifier
  1756. {
  1757. $$ = $1;
  1758. $$.merge_qualifier(&@1, state, $2, false);
  1759. }
  1760. | auxiliary_storage_qualifier type_qualifier
  1761. {
  1762. if ($2.has_auxiliary_storage()) {
  1763. _mesa_glsl_error(&@1, state,
  1764. "duplicate auxiliary storage qualifier (centroid or sample)");
  1765. }
  1766. if (!state->has_420pack_or_es31() &&
  1767. ($2.flags.q.precise || $2.flags.q.invariant ||
  1768. $2.has_interpolation() || $2.has_layout())) {
  1769. _mesa_glsl_error(&@1, state, "auxiliary storage qualifiers must come "
  1770. "just before storage qualifiers");
  1771. }
  1772. $$ = $1;
  1773. $$.merge_qualifier(&@1, state, $2, false);
  1774. }
  1775. | storage_qualifier type_qualifier
  1776. {
  1777. /* Section 4.3 of the GLSL 1.20 specification states:
  1778. * "Variable declarations may have a storage qualifier specified..."
  1779. * 1.30 clarifies this to "may have one storage qualifier".
  1780. */
  1781. if ($2.has_storage())
  1782. _mesa_glsl_error(&@1, state, "duplicate storage qualifier");
  1783. if (!state->has_420pack_or_es31() &&
  1784. ($2.flags.q.precise || $2.flags.q.invariant || $2.has_interpolation() ||
  1785. $2.has_layout() || $2.has_auxiliary_storage())) {
  1786. _mesa_glsl_error(&@1, state, "storage qualifiers must come after "
  1787. "precise, invariant, interpolation, layout and auxiliary "
  1788. "storage qualifiers");
  1789. }
  1790. $$ = $1;
  1791. $$.merge_qualifier(&@1, state, $2, false);
  1792. }
  1793. | precision_qualifier type_qualifier
  1794. {
  1795. if ($2.precision != ast_precision_none)
  1796. _mesa_glsl_error(&@1, state, "duplicate precision qualifier");
  1797. if (!(state->has_420pack_or_es31()) &&
  1798. $2.flags.i != 0)
  1799. _mesa_glsl_error(&@1, state, "precision qualifiers must come last");
  1800. $$ = $2;
  1801. $$.precision = $1;
  1802. }
  1803. | memory_qualifier type_qualifier
  1804. {
  1805. $$ = $1;
  1806. $$.merge_qualifier(&@1, state, $2, false);
  1807. }
  1808. ;
  1809. auxiliary_storage_qualifier:
  1810. CENTROID
  1811. {
  1812. memset(& $$, 0, sizeof($$));
  1813. $$.flags.q.centroid = 1;
  1814. }
  1815. | SAMPLE
  1816. {
  1817. memset(& $$, 0, sizeof($$));
  1818. $$.flags.q.sample = 1;
  1819. }
  1820. | PATCH
  1821. {
  1822. memset(& $$, 0, sizeof($$));
  1823. $$.flags.q.patch = 1;
  1824. }
  1825. storage_qualifier:
  1826. CONST_TOK
  1827. {
  1828. memset(& $$, 0, sizeof($$));
  1829. $$.flags.q.constant = 1;
  1830. }
  1831. | ATTRIBUTE
  1832. {
  1833. memset(& $$, 0, sizeof($$));
  1834. $$.flags.q.attribute = 1;
  1835. }
  1836. | VARYING
  1837. {
  1838. memset(& $$, 0, sizeof($$));
  1839. $$.flags.q.varying = 1;
  1840. }
  1841. | IN_TOK
  1842. {
  1843. memset(& $$, 0, sizeof($$));
  1844. $$.flags.q.in = 1;
  1845. }
  1846. | OUT_TOK
  1847. {
  1848. memset(& $$, 0, sizeof($$));
  1849. $$.flags.q.out = 1;
  1850. if (state->stage == MESA_SHADER_GEOMETRY &&
  1851. state->has_explicit_attrib_stream()) {
  1852. /* Section 4.3.8.2 (Output Layout Qualifiers) of the GLSL 4.00
  1853. * spec says:
  1854. *
  1855. * "If the block or variable is declared with the stream
  1856. * identifier, it is associated with the specified stream;
  1857. * otherwise, it is associated with the current default stream."
  1858. */
  1859. $$.flags.q.stream = 1;
  1860. $$.flags.q.explicit_stream = 0;
  1861. $$.stream = state->out_qualifier->stream;
  1862. }
  1863. if (state->has_enhanced_layouts()) {
  1864. $$.flags.q.xfb_buffer = 1;
  1865. $$.flags.q.explicit_xfb_buffer = 0;
  1866. $$.xfb_buffer = state->out_qualifier->xfb_buffer;
  1867. }
  1868. }
  1869. | INOUT_TOK
  1870. {
  1871. memset(& $$, 0, sizeof($$));
  1872. $$.flags.q.in = 1;
  1873. $$.flags.q.out = 1;
  1874. if (!state->has_framebuffer_fetch() ||
  1875. !state->is_version(130, 300) ||
  1876. state->stage != MESA_SHADER_FRAGMENT)
  1877. _mesa_glsl_error(&@1, state, "A single interface variable cannot be "
  1878. "declared as both input and output");
  1879. }
  1880. | UNIFORM
  1881. {
  1882. memset(& $$, 0, sizeof($$));
  1883. $$.flags.q.uniform = 1;
  1884. }
  1885. | BUFFER
  1886. {
  1887. memset(& $$, 0, sizeof($$));
  1888. $$.flags.q.buffer = 1;
  1889. }
  1890. | SHARED
  1891. {
  1892. memset(& $$, 0, sizeof($$));
  1893. $$.flags.q.shared_storage = 1;
  1894. }
  1895. ;
  1896. memory_qualifier:
  1897. COHERENT
  1898. {
  1899. memset(& $$, 0, sizeof($$));
  1900. $$.flags.q.coherent = 1;
  1901. }
  1902. | VOLATILE
  1903. {
  1904. memset(& $$, 0, sizeof($$));
  1905. $$.flags.q._volatile = 1;
  1906. }
  1907. | RESTRICT
  1908. {
  1909. STATIC_ASSERT(sizeof($$.flags.q) <= sizeof($$.flags.i));
  1910. memset(& $$, 0, sizeof($$));
  1911. $$.flags.q.restrict_flag = 1;
  1912. }
  1913. | READONLY
  1914. {
  1915. memset(& $$, 0, sizeof($$));
  1916. $$.flags.q.read_only = 1;
  1917. }
  1918. | WRITEONLY
  1919. {
  1920. memset(& $$, 0, sizeof($$));
  1921. $$.flags.q.write_only = 1;
  1922. }
  1923. ;
  1924. array_specifier:
  1925. '[' ']'
  1926. {
  1927. void *ctx = state->linalloc;
  1928. $$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
  1929. ast_unsized_array_dim, NULL,
  1930. NULL, NULL));
  1931. $$->set_location_range(@1, @2);
  1932. }
  1933. | '[' constant_expression ']'
  1934. {
  1935. void *ctx = state->linalloc;
  1936. $$ = new(ctx) ast_array_specifier(@1, $2);
  1937. $$->set_location_range(@1, @3);
  1938. }
  1939. | array_specifier '[' ']'
  1940. {
  1941. void *ctx = state->linalloc;
  1942. $$ = $1;
  1943. if (state->check_arrays_of_arrays_allowed(& @1)) {
  1944. $$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
  1945. NULL, NULL));
  1946. }
  1947. }
  1948. | array_specifier '[' constant_expression ']'
  1949. {
  1950. $$ = $1;
  1951. if (state->check_arrays_of_arrays_allowed(& @1)) {
  1952. $$->add_dimension($3);
  1953. }
  1954. }
  1955. ;
  1956. type_specifier:
  1957. type_specifier_nonarray
  1958. | type_specifier_nonarray array_specifier
  1959. {
  1960. $$ = $1;
  1961. $$->array_specifier = $2;
  1962. }
  1963. ;
  1964. type_specifier_nonarray:
  1965. basic_type_specifier_nonarray
  1966. {
  1967. void *ctx = state->linalloc;
  1968. $$ = new(ctx) ast_type_specifier($1);
  1969. $$->set_location(@1);
  1970. }
  1971. | struct_specifier
  1972. {
  1973. void *ctx = state->linalloc;
  1974. $$ = new(ctx) ast_type_specifier($1);
  1975. $$->set_location(@1);
  1976. }
  1977. | TYPE_IDENTIFIER
  1978. {
  1979. void *ctx = state->linalloc;
  1980. $$ = new(ctx) ast_type_specifier($1);
  1981. $$->set_location(@1);
  1982. }
  1983. ;
  1984. basic_type_specifier_nonarray:
  1985. VOID_TOK { $$ = "void"; }
  1986. | FLOAT_TOK { $$ = "float"; }
  1987. | DOUBLE_TOK { $$ = "double"; }
  1988. | INT_TOK { $$ = "int"; }
  1989. | UINT_TOK { $$ = "uint"; }
  1990. | BOOL_TOK { $$ = "bool"; }
  1991. | VEC2 { $$ = "vec2"; }
  1992. | VEC3 { $$ = "vec3"; }
  1993. | VEC4 { $$ = "vec4"; }
  1994. | BVEC2 { $$ = "bvec2"; }
  1995. | BVEC3 { $$ = "bvec3"; }
  1996. | BVEC4 { $$ = "bvec4"; }
  1997. | IVEC2 { $$ = "ivec2"; }
  1998. | IVEC3 { $$ = "ivec3"; }
  1999. | IVEC4 { $$ = "ivec4"; }
  2000. | UVEC2 { $$ = "uvec2"; }
  2001. | UVEC3 { $$ = "uvec3"; }
  2002. | UVEC4 { $$ = "uvec4"; }
  2003. | DVEC2 { $$ = "dvec2"; }
  2004. | DVEC3 { $$ = "dvec3"; }
  2005. | DVEC4 { $$ = "dvec4"; }
  2006. | MAT2X2 { $$ = "mat2"; }
  2007. | MAT2X3 { $$ = "mat2x3"; }
  2008. | MAT2X4 { $$ = "mat2x4"; }
  2009. | MAT3X2 { $$ = "mat3x2"; }
  2010. | MAT3X3 { $$ = "mat3"; }
  2011. | MAT3X4 { $$ = "mat3x4"; }
  2012. | MAT4X2 { $$ = "mat4x2"; }
  2013. | MAT4X3 { $$ = "mat4x3"; }
  2014. | MAT4X4 { $$ = "mat4"; }
  2015. | DMAT2X2 { $$ = "dmat2"; }
  2016. | DMAT2X3 { $$ = "dmat2x3"; }
  2017. | DMAT2X4 { $$ = "dmat2x4"; }
  2018. | DMAT3X2 { $$ = "dmat3x2"; }
  2019. | DMAT3X3 { $$ = "dmat3"; }
  2020. | DMAT3X4 { $$ = "dmat3x4"; }
  2021. | DMAT4X2 { $$ = "dmat4x2"; }
  2022. | DMAT4X3 { $$ = "dmat4x3"; }
  2023. | DMAT4X4 { $$ = "dmat4"; }
  2024. | SAMPLER1D { $$ = "sampler1D"; }
  2025. | SAMPLER2D { $$ = "sampler2D"; }
  2026. | SAMPLER2DRECT { $$ = "sampler2DRect"; }
  2027. | SAMPLER3D { $$ = "sampler3D"; }
  2028. | SAMPLERCUBE { $$ = "samplerCube"; }
  2029. | SAMPLEREXTERNALOES { $$ = "samplerExternalOES"; }
  2030. | SAMPLER1DSHADOW { $$ = "sampler1DShadow"; }
  2031. | SAMPLER2DSHADOW { $$ = "sampler2DShadow"; }
  2032. | SAMPLER2DRECTSHADOW { $$ = "sampler2DRectShadow"; }
  2033. | SAMPLERCUBESHADOW { $$ = "samplerCubeShadow"; }
  2034. | SAMPLER1DARRAY { $$ = "sampler1DArray"; }
  2035. | SAMPLER2DARRAY { $$ = "sampler2DArray"; }
  2036. | SAMPLER1DARRAYSHADOW { $$ = "sampler1DArrayShadow"; }
  2037. | SAMPLER2DARRAYSHADOW { $$ = "sampler2DArrayShadow"; }
  2038. | SAMPLERBUFFER { $$ = "samplerBuffer"; }
  2039. | SAMPLERCUBEARRAY { $$ = "samplerCubeArray"; }
  2040. | SAMPLERCUBEARRAYSHADOW { $$ = "samplerCubeArrayShadow"; }
  2041. | ISAMPLER1D { $$ = "isampler1D"; }
  2042. | ISAMPLER2D { $$ = "isampler2D"; }
  2043. | ISAMPLER2DRECT { $$ = "isampler2DRect"; }
  2044. | ISAMPLER3D { $$ = "isampler3D"; }
  2045. | ISAMPLERCUBE { $$ = "isamplerCube"; }
  2046. | ISAMPLER1DARRAY { $$ = "isampler1DArray"; }
  2047. | ISAMPLER2DARRAY { $$ = "isampler2DArray"; }
  2048. | ISAMPLERBUFFER { $$ = "isamplerBuffer"; }
  2049. | ISAMPLERCUBEARRAY { $$ = "isamplerCubeArray"; }
  2050. | USAMPLER1D { $$ = "usampler1D"; }
  2051. | USAMPLER2D { $$ = "usampler2D"; }
  2052. | USAMPLER2DRECT { $$ = "usampler2DRect"; }
  2053. | USAMPLER3D { $$ = "usampler3D"; }
  2054. | USAMPLERCUBE { $$ = "usamplerCube"; }
  2055. | USAMPLER1DARRAY { $$ = "usampler1DArray"; }
  2056. | USAMPLER2DARRAY { $$ = "usampler2DArray"; }
  2057. | USAMPLERBUFFER { $$ = "usamplerBuffer"; }
  2058. | USAMPLERCUBEARRAY { $$ = "usamplerCubeArray"; }
  2059. | SAMPLER2DMS { $$ = "sampler2DMS"; }
  2060. | ISAMPLER2DMS { $$ = "isampler2DMS"; }
  2061. | USAMPLER2DMS { $$ = "usampler2DMS"; }
  2062. | SAMPLER2DMSARRAY { $$ = "sampler2DMSArray"; }
  2063. | ISAMPLER2DMSARRAY { $$ = "isampler2DMSArray"; }
  2064. | USAMPLER2DMSARRAY { $$ = "usampler2DMSArray"; }
  2065. | IMAGE1D { $$ = "image1D"; }
  2066. | IMAGE2D { $$ = "image2D"; }
  2067. | IMAGE3D { $$ = "image3D"; }
  2068. | IMAGE2DRECT { $$ = "image2DRect"; }
  2069. | IMAGECUBE { $$ = "imageCube"; }
  2070. | IMAGEBUFFER { $$ = "imageBuffer"; }
  2071. | IMAGE1DARRAY { $$ = "image1DArray"; }
  2072. | IMAGE2DARRAY { $$ = "image2DArray"; }
  2073. | IMAGECUBEARRAY { $$ = "imageCubeArray"; }
  2074. | IMAGE2DMS { $$ = "image2DMS"; }
  2075. | IMAGE2DMSARRAY { $$ = "image2DMSArray"; }
  2076. | IIMAGE1D { $$ = "iimage1D"; }
  2077. | IIMAGE2D { $$ = "iimage2D"; }
  2078. | IIMAGE3D { $$ = "iimage3D"; }
  2079. | IIMAGE2DRECT { $$ = "iimage2DRect"; }
  2080. | IIMAGECUBE { $$ = "iimageCube"; }
  2081. | IIMAGEBUFFER { $$ = "iimageBuffer"; }
  2082. | IIMAGE1DARRAY { $$ = "iimage1DArray"; }
  2083. | IIMAGE2DARRAY { $$ = "iimage2DArray"; }
  2084. | IIMAGECUBEARRAY { $$ = "iimageCubeArray"; }
  2085. | IIMAGE2DMS { $$ = "iimage2DMS"; }
  2086. | IIMAGE2DMSARRAY { $$ = "iimage2DMSArray"; }
  2087. | UIMAGE1D { $$ = "uimage1D"; }
  2088. | UIMAGE2D { $$ = "uimage2D"; }
  2089. | UIMAGE3D { $$ = "uimage3D"; }
  2090. | UIMAGE2DRECT { $$ = "uimage2DRect"; }
  2091. | UIMAGECUBE { $$ = "uimageCube"; }
  2092. | UIMAGEBUFFER { $$ = "uimageBuffer"; }
  2093. | UIMAGE1DARRAY { $$ = "uimage1DArray"; }
  2094. | UIMAGE2DARRAY { $$ = "uimage2DArray"; }
  2095. | UIMAGECUBEARRAY { $$ = "uimageCubeArray"; }
  2096. | UIMAGE2DMS { $$ = "uimage2DMS"; }
  2097. | UIMAGE2DMSARRAY { $$ = "uimage2DMSArray"; }
  2098. | ATOMIC_UINT { $$ = "atomic_uint"; }
  2099. ;
  2100. precision_qualifier:
  2101. HIGHP
  2102. {
  2103. state->check_precision_qualifiers_allowed(&@1);
  2104. $$ = ast_precision_high;
  2105. }
  2106. | MEDIUMP
  2107. {
  2108. state->check_precision_qualifiers_allowed(&@1);
  2109. $$ = ast_precision_medium;
  2110. }
  2111. | LOWP
  2112. {
  2113. state->check_precision_qualifiers_allowed(&@1);
  2114. $$ = ast_precision_low;
  2115. }
  2116. ;
  2117. struct_specifier:
  2118. STRUCT any_identifier '{' struct_declaration_list '}'
  2119. {
  2120. void *ctx = state->linalloc;
  2121. $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
  2122. $$->set_location_range(@2, @5);
  2123. state->symbols->add_type($2, glsl_type::void_type);
  2124. }
  2125. | STRUCT '{' struct_declaration_list '}'
  2126. {
  2127. void *ctx = state->linalloc;
  2128. $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
  2129. $$->set_location_range(@2, @4);
  2130. }
  2131. ;
  2132. struct_declaration_list:
  2133. struct_declaration
  2134. {
  2135. $$ = $1;
  2136. $1->link.self_link();
  2137. }
  2138. | struct_declaration_list struct_declaration
  2139. {
  2140. $$ = $1;
  2141. $$->link.insert_before(& $2->link);
  2142. }
  2143. ;
  2144. struct_declaration:
  2145. fully_specified_type struct_declarator_list ';'
  2146. {
  2147. void *ctx = state->linalloc;
  2148. ast_fully_specified_type *const type = $1;
  2149. type->set_location(@1);
  2150. if (type->qualifier.flags.i != 0)
  2151. _mesa_glsl_error(&@1, state,
  2152. "only precision qualifiers may be applied to "
  2153. "structure members");
  2154. $$ = new(ctx) ast_declarator_list(type);
  2155. $$->set_location(@2);
  2156. $$->declarations.push_degenerate_list_at_head(& $2->link);
  2157. }
  2158. ;
  2159. struct_declarator_list:
  2160. struct_declarator
  2161. {
  2162. $$ = $1;
  2163. $1->link.self_link();
  2164. }
  2165. | struct_declarator_list ',' struct_declarator
  2166. {
  2167. $$ = $1;
  2168. $$->link.insert_before(& $3->link);
  2169. }
  2170. ;
  2171. struct_declarator:
  2172. any_identifier
  2173. {
  2174. void *ctx = state->linalloc;
  2175. $$ = new(ctx) ast_declaration($1, NULL, NULL);
  2176. $$->set_location(@1);
  2177. }
  2178. | any_identifier array_specifier
  2179. {
  2180. void *ctx = state->linalloc;
  2181. $$ = new(ctx) ast_declaration($1, $2, NULL);
  2182. $$->set_location_range(@1, @2);
  2183. }
  2184. ;
  2185. initializer:
  2186. assignment_expression
  2187. | '{' initializer_list '}'
  2188. {
  2189. $$ = $2;
  2190. }
  2191. | '{' initializer_list ',' '}'
  2192. {
  2193. $$ = $2;
  2194. }
  2195. ;
  2196. initializer_list:
  2197. initializer
  2198. {
  2199. void *ctx = state->linalloc;
  2200. $$ = new(ctx) ast_aggregate_initializer();
  2201. $$->set_location(@1);
  2202. $$->expressions.push_tail(& $1->link);
  2203. }
  2204. | initializer_list ',' initializer
  2205. {
  2206. $1->expressions.push_tail(& $3->link);
  2207. }
  2208. ;
  2209. declaration_statement:
  2210. declaration
  2211. ;
  2212. // Grammar Note: labeled statements for SWITCH only; 'goto' is not
  2213. // supported.
  2214. statement:
  2215. compound_statement { $$ = (ast_node *) $1; }
  2216. | simple_statement
  2217. ;
  2218. simple_statement:
  2219. declaration_statement
  2220. | expression_statement
  2221. | selection_statement
  2222. | switch_statement
  2223. | iteration_statement
  2224. | jump_statement
  2225. ;
  2226. compound_statement:
  2227. '{' '}'
  2228. {
  2229. void *ctx = state->linalloc;
  2230. $$ = new(ctx) ast_compound_statement(true, NULL);
  2231. $$->set_location_range(@1, @2);
  2232. }
  2233. | '{'
  2234. {
  2235. state->symbols->push_scope();
  2236. }
  2237. statement_list '}'
  2238. {
  2239. void *ctx = state->linalloc;
  2240. $$ = new(ctx) ast_compound_statement(true, $3);
  2241. $$->set_location_range(@1, @4);
  2242. state->symbols->pop_scope();
  2243. }
  2244. ;
  2245. statement_no_new_scope:
  2246. compound_statement_no_new_scope { $$ = (ast_node *) $1; }
  2247. | simple_statement
  2248. ;
  2249. compound_statement_no_new_scope:
  2250. '{' '}'
  2251. {
  2252. void *ctx = state->linalloc;
  2253. $$ = new(ctx) ast_compound_statement(false, NULL);
  2254. $$->set_location_range(@1, @2);
  2255. }
  2256. | '{' statement_list '}'
  2257. {
  2258. void *ctx = state->linalloc;
  2259. $$ = new(ctx) ast_compound_statement(false, $2);
  2260. $$->set_location_range(@1, @3);
  2261. }
  2262. ;
  2263. statement_list:
  2264. statement
  2265. {
  2266. if ($1 == NULL) {
  2267. _mesa_glsl_error(& @1, state, "<nil> statement");
  2268. assert($1 != NULL);
  2269. }
  2270. $$ = $1;
  2271. $$->link.self_link();
  2272. }
  2273. | statement_list statement
  2274. {
  2275. if ($2 == NULL) {
  2276. _mesa_glsl_error(& @2, state, "<nil> statement");
  2277. assert($2 != NULL);
  2278. }
  2279. $$ = $1;
  2280. $$->link.insert_before(& $2->link);
  2281. }
  2282. ;
  2283. expression_statement:
  2284. ';'
  2285. {
  2286. void *ctx = state->linalloc;
  2287. $$ = new(ctx) ast_expression_statement(NULL);
  2288. $$->set_location(@1);
  2289. }
  2290. | expression ';'
  2291. {
  2292. void *ctx = state->linalloc;
  2293. $$ = new(ctx) ast_expression_statement($1);
  2294. $$->set_location(@1);
  2295. }
  2296. ;
  2297. selection_statement:
  2298. IF '(' expression ')' selection_rest_statement
  2299. {
  2300. $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
  2301. $5.else_statement);
  2302. $$->set_location_range(@1, @5);
  2303. }
  2304. ;
  2305. selection_rest_statement:
  2306. statement ELSE statement
  2307. {
  2308. $$.then_statement = $1;
  2309. $$.else_statement = $3;
  2310. }
  2311. | statement %prec THEN
  2312. {
  2313. $$.then_statement = $1;
  2314. $$.else_statement = NULL;
  2315. }
  2316. ;
  2317. condition:
  2318. expression
  2319. {
  2320. $$ = (ast_node *) $1;
  2321. }
  2322. | fully_specified_type any_identifier '=' initializer
  2323. {
  2324. void *ctx = state->linalloc;
  2325. ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
  2326. ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
  2327. decl->set_location_range(@2, @4);
  2328. declarator->set_location(@1);
  2329. declarator->declarations.push_tail(&decl->link);
  2330. $$ = declarator;
  2331. }
  2332. ;
  2333. /*
  2334. * switch_statement grammar is based on the syntax described in the body
  2335. * of the GLSL spec, not in it's appendix!!!
  2336. */
  2337. switch_statement:
  2338. SWITCH '(' expression ')' switch_body
  2339. {
  2340. $$ = new(state->linalloc) ast_switch_statement($3, $5);
  2341. $$->set_location_range(@1, @5);
  2342. }
  2343. ;
  2344. switch_body:
  2345. '{' '}'
  2346. {
  2347. $$ = new(state->linalloc) ast_switch_body(NULL);
  2348. $$->set_location_range(@1, @2);
  2349. }
  2350. | '{' case_statement_list '}'
  2351. {
  2352. $$ = new(state->linalloc) ast_switch_body($2);
  2353. $$->set_location_range(@1, @3);
  2354. }
  2355. ;
  2356. case_label:
  2357. CASE expression ':'
  2358. {
  2359. $$ = new(state->linalloc) ast_case_label($2);
  2360. $$->set_location(@2);
  2361. }
  2362. | DEFAULT ':'
  2363. {
  2364. $$ = new(state->linalloc) ast_case_label(NULL);
  2365. $$->set_location(@2);
  2366. }
  2367. ;
  2368. case_label_list:
  2369. case_label
  2370. {
  2371. ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
  2372. labels->labels.push_tail(& $1->link);
  2373. $$ = labels;
  2374. $$->set_location(@1);
  2375. }
  2376. | case_label_list case_label
  2377. {
  2378. $$ = $1;
  2379. $$->labels.push_tail(& $2->link);
  2380. }
  2381. ;
  2382. case_statement:
  2383. case_label_list statement
  2384. {
  2385. ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
  2386. stmts->set_location(@2);
  2387. stmts->stmts.push_tail(& $2->link);
  2388. $$ = stmts;
  2389. }
  2390. | case_statement statement
  2391. {
  2392. $$ = $1;
  2393. $$->stmts.push_tail(& $2->link);
  2394. }
  2395. ;
  2396. case_statement_list:
  2397. case_statement
  2398. {
  2399. ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
  2400. cases->set_location(@1);
  2401. cases->cases.push_tail(& $1->link);
  2402. $$ = cases;
  2403. }
  2404. | case_statement_list case_statement
  2405. {
  2406. $$ = $1;
  2407. $$->cases.push_tail(& $2->link);
  2408. }
  2409. ;
  2410. iteration_statement:
  2411. WHILE '(' condition ')' statement_no_new_scope
  2412. {
  2413. void *ctx = state->linalloc;
  2414. $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
  2415. NULL, $3, NULL, $5);
  2416. $$->set_location_range(@1, @4);
  2417. }
  2418. | DO statement WHILE '(' expression ')' ';'
  2419. {
  2420. void *ctx = state->linalloc;
  2421. $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
  2422. NULL, $5, NULL, $2);
  2423. $$->set_location_range(@1, @6);
  2424. }
  2425. | FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
  2426. {
  2427. void *ctx = state->linalloc;
  2428. $$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
  2429. $3, $4.cond, $4.rest, $6);
  2430. $$->set_location_range(@1, @6);
  2431. }
  2432. ;
  2433. for_init_statement:
  2434. expression_statement
  2435. | declaration_statement
  2436. ;
  2437. conditionopt:
  2438. condition
  2439. | /* empty */
  2440. {
  2441. $$ = NULL;
  2442. }
  2443. ;
  2444. for_rest_statement:
  2445. conditionopt ';'
  2446. {
  2447. $$.cond = $1;
  2448. $$.rest = NULL;
  2449. }
  2450. | conditionopt ';' expression
  2451. {
  2452. $$.cond = $1;
  2453. $$.rest = $3;
  2454. }
  2455. ;
  2456. // Grammar Note: No 'goto'. Gotos are not supported.
  2457. jump_statement:
  2458. CONTINUE ';'
  2459. {
  2460. void *ctx = state->linalloc;
  2461. $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
  2462. $$->set_location(@1);
  2463. }
  2464. | BREAK ';'
  2465. {
  2466. void *ctx = state->linalloc;
  2467. $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
  2468. $$->set_location(@1);
  2469. }
  2470. | RETURN ';'
  2471. {
  2472. void *ctx = state->linalloc;
  2473. $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
  2474. $$->set_location(@1);
  2475. }
  2476. | RETURN expression ';'
  2477. {
  2478. void *ctx = state->linalloc;
  2479. $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
  2480. $$->set_location_range(@1, @2);
  2481. }
  2482. | DISCARD ';' // Fragment shader only.
  2483. {
  2484. void *ctx = state->linalloc;
  2485. $$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
  2486. $$->set_location(@1);
  2487. }
  2488. ;
  2489. external_declaration:
  2490. function_definition { $$ = $1; }
  2491. | declaration { $$ = $1; }
  2492. | pragma_statement { $$ = NULL; }
  2493. | layout_defaults { $$ = $1; }
  2494. ;
  2495. function_definition:
  2496. function_prototype compound_statement_no_new_scope
  2497. {
  2498. void *ctx = state->linalloc;
  2499. $$ = new(ctx) ast_function_definition();
  2500. $$->set_location_range(@1, @2);
  2501. $$->prototype = $1;
  2502. $$->body = $2;
  2503. state->symbols->pop_scope();
  2504. }
  2505. ;
  2506. /* layout_qualifieropt is packed into this rule */
  2507. interface_block:
  2508. basic_interface_block
  2509. {
  2510. $$ = $1;
  2511. }
  2512. | layout_qualifier interface_block
  2513. {
  2514. ast_interface_block *block = (ast_interface_block *) $2;
  2515. if (!$1.merge_qualifier(& @1, state, block->layout, false,
  2516. block->layout.has_layout())) {
  2517. YYERROR;
  2518. }
  2519. block->layout = $1;
  2520. $$ = block;
  2521. }
  2522. | memory_qualifier interface_block
  2523. {
  2524. ast_interface_block *block = (ast_interface_block *)$2;
  2525. if (!block->default_layout.flags.q.buffer) {
  2526. _mesa_glsl_error(& @1, state,
  2527. "memory qualifiers can only be used in the "
  2528. "declaration of shader storage blocks");
  2529. }
  2530. if (!$1.merge_qualifier(& @1, state, block->layout, false)) {
  2531. YYERROR;
  2532. }
  2533. block->layout = $1;
  2534. $$ = block;
  2535. }
  2536. ;
  2537. basic_interface_block:
  2538. interface_qualifier NEW_IDENTIFIER '{' member_list '}' instance_name_opt ';'
  2539. {
  2540. ast_interface_block *const block = $6;
  2541. if ($1.flags.q.uniform) {
  2542. block->default_layout = *state->default_uniform_qualifier;
  2543. } else if ($1.flags.q.buffer) {
  2544. block->default_layout = *state->default_shader_storage_qualifier;
  2545. }
  2546. block->block_name = $2;
  2547. block->declarations.push_degenerate_list_at_head(& $4->link);
  2548. _mesa_ast_process_interface_block(& @1, state, block, $1);
  2549. $$ = block;
  2550. }
  2551. ;
  2552. interface_qualifier:
  2553. IN_TOK
  2554. {
  2555. memset(& $$, 0, sizeof($$));
  2556. $$.flags.q.in = 1;
  2557. }
  2558. | OUT_TOK
  2559. {
  2560. memset(& $$, 0, sizeof($$));
  2561. $$.flags.q.out = 1;
  2562. }
  2563. | UNIFORM
  2564. {
  2565. memset(& $$, 0, sizeof($$));
  2566. $$.flags.q.uniform = 1;
  2567. }
  2568. | BUFFER
  2569. {
  2570. memset(& $$, 0, sizeof($$));
  2571. $$.flags.q.buffer = 1;
  2572. }
  2573. | auxiliary_storage_qualifier interface_qualifier
  2574. {
  2575. if (!$1.flags.q.patch) {
  2576. _mesa_glsl_error(&@1, state, "invalid interface qualifier");
  2577. }
  2578. if ($2.has_auxiliary_storage()) {
  2579. _mesa_glsl_error(&@1, state, "duplicate patch qualifier");
  2580. }
  2581. $$ = $2;
  2582. $$.flags.q.patch = 1;
  2583. }
  2584. ;
  2585. instance_name_opt:
  2586. /* empty */
  2587. {
  2588. $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
  2589. }
  2590. | NEW_IDENTIFIER
  2591. {
  2592. $$ = new(state->linalloc) ast_interface_block($1, NULL);
  2593. $$->set_location(@1);
  2594. }
  2595. | NEW_IDENTIFIER array_specifier
  2596. {
  2597. $$ = new(state->linalloc) ast_interface_block($1, $2);
  2598. $$->set_location_range(@1, @2);
  2599. }
  2600. ;
  2601. member_list:
  2602. member_declaration
  2603. {
  2604. $$ = $1;
  2605. $1->link.self_link();
  2606. }
  2607. | member_declaration member_list
  2608. {
  2609. $$ = $1;
  2610. $2->link.insert_before(& $$->link);
  2611. }
  2612. ;
  2613. member_declaration:
  2614. fully_specified_type struct_declarator_list ';'
  2615. {
  2616. void *ctx = state->linalloc;
  2617. ast_fully_specified_type *type = $1;
  2618. type->set_location(@1);
  2619. if (type->qualifier.flags.q.attribute) {
  2620. _mesa_glsl_error(& @1, state,
  2621. "keyword 'attribute' cannot be used with "
  2622. "interface block member");
  2623. } else if (type->qualifier.flags.q.varying) {
  2624. _mesa_glsl_error(& @1, state,
  2625. "keyword 'varying' cannot be used with "
  2626. "interface block member");
  2627. }
  2628. $$ = new(ctx) ast_declarator_list(type);
  2629. $$->set_location(@2);
  2630. $$->declarations.push_degenerate_list_at_head(& $2->link);
  2631. }
  2632. ;
  2633. layout_uniform_defaults:
  2634. layout_qualifier layout_uniform_defaults
  2635. {
  2636. $$ = $1;
  2637. if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
  2638. YYERROR;
  2639. }
  2640. }
  2641. | layout_qualifier UNIFORM ';'
  2642. ;
  2643. layout_buffer_defaults:
  2644. layout_qualifier layout_buffer_defaults
  2645. {
  2646. $$ = $1;
  2647. if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
  2648. YYERROR;
  2649. }
  2650. }
  2651. | layout_qualifier BUFFER ';'
  2652. ;
  2653. layout_in_defaults:
  2654. layout_qualifier layout_in_defaults
  2655. {
  2656. $$ = $1;
  2657. if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
  2658. YYERROR;
  2659. }
  2660. if (!$$.validate_in_qualifier(& @1, state)) {
  2661. YYERROR;
  2662. }
  2663. }
  2664. | layout_qualifier IN_TOK ';'
  2665. {
  2666. if (!$1.validate_in_qualifier(& @1, state)) {
  2667. YYERROR;
  2668. }
  2669. }
  2670. ;
  2671. layout_out_defaults:
  2672. layout_qualifier layout_out_defaults
  2673. {
  2674. $$ = $1;
  2675. if (!$$.merge_qualifier(& @1, state, $2, false, true)) {
  2676. YYERROR;
  2677. }
  2678. if (!$$.validate_out_qualifier(& @1, state)) {
  2679. YYERROR;
  2680. }
  2681. }
  2682. | layout_qualifier OUT_TOK ';'
  2683. {
  2684. if (!$1.validate_out_qualifier(& @1, state)) {
  2685. YYERROR;
  2686. }
  2687. }
  2688. ;
  2689. layout_defaults:
  2690. layout_uniform_defaults
  2691. {
  2692. $$ = NULL;
  2693. if (!state->default_uniform_qualifier->
  2694. merge_qualifier(& @1, state, $1, false)) {
  2695. YYERROR;
  2696. }
  2697. if (!state->default_uniform_qualifier->
  2698. push_to_global(& @1, state)) {
  2699. YYERROR;
  2700. }
  2701. }
  2702. | layout_buffer_defaults
  2703. {
  2704. $$ = NULL;
  2705. if (!state->default_shader_storage_qualifier->
  2706. merge_qualifier(& @1, state, $1, false)) {
  2707. YYERROR;
  2708. }
  2709. if (!state->default_shader_storage_qualifier->
  2710. push_to_global(& @1, state)) {
  2711. YYERROR;
  2712. }
  2713. /* From the GLSL 4.50 spec, section 4.4.5:
  2714. *
  2715. * "It is a compile-time error to specify the binding identifier for
  2716. * the global scope or for block member declarations."
  2717. */
  2718. if (state->default_shader_storage_qualifier->flags.q.explicit_binding) {
  2719. _mesa_glsl_error(& @1, state,
  2720. "binding qualifier cannot be set for default layout");
  2721. }
  2722. }
  2723. | layout_in_defaults
  2724. {
  2725. $$ = NULL;
  2726. if (!$1.merge_into_in_qualifier(& @1, state, $$)) {
  2727. YYERROR;
  2728. }
  2729. if (!state->in_qualifier->push_to_global(& @1, state)) {
  2730. YYERROR;
  2731. }
  2732. }
  2733. | layout_out_defaults
  2734. {
  2735. $$ = NULL;
  2736. if (!$1.merge_into_out_qualifier(& @1, state, $$)) {
  2737. YYERROR;
  2738. }
  2739. if (!state->out_qualifier->push_to_global(& @1, state)) {
  2740. YYERROR;
  2741. }
  2742. }
  2743. ;