glcpp-parse.c 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046
  1. /* A Bison parser, made by GNU Bison 2.3. */
  2. /* Skeleton implementation for Bison's Yacc-like parsers in C
  3. Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  4. Free Software Foundation, Inc.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. /* As a special exception, you may create a larger work that contains
  18. part or all of the Bison parser skeleton and distribute that work
  19. under terms of your choice, so long as that work isn't itself a
  20. parser generator using the skeleton or a modified version thereof
  21. as a parser skeleton. Alternatively, if you modify or redistribute
  22. the parser skeleton itself, you may (at your option) remove this
  23. special exception, which will cause the skeleton and the resulting
  24. Bison output files to be licensed under the GNU General Public
  25. License without this special exception.
  26. This special exception was added by the Free Software Foundation in
  27. version 2.2 of Bison. */
  28. /* C LALR(1) parser skeleton written by Richard Stallman, by
  29. simplifying the original so-called "semantic" parser. */
  30. /* All symbols defined below should begin with yy or YY, to avoid
  31. infringing on user name space. This should be done even for local
  32. variables, as they might otherwise be expanded by user macros.
  33. There are some unavoidable exceptions within include files to
  34. define necessary library symbols; they are noted "INFRINGES ON
  35. USER NAME SPACE" below. */
  36. /* Identify Bison output. */
  37. #define YYBISON 1
  38. /* Bison version. */
  39. #define YYBISON_VERSION "2.3"
  40. /* Skeleton name. */
  41. #define YYSKELETON_NAME "yacc.c"
  42. /* Pure parsers. */
  43. #define YYPURE 1
  44. /* Using locations. */
  45. #define YYLSP_NEEDED 1
  46. /* Tokens. */
  47. #ifndef YYTOKENTYPE
  48. # define YYTOKENTYPE
  49. /* Put the tokens into the symbol table, so that GDB and other debuggers
  50. know about them. */
  51. enum yytokentype {
  52. COMMA_FINAL = 258,
  53. DEFINED = 259,
  54. ELIF_EXPANDED = 260,
  55. HASH = 261,
  56. HASH_DEFINE_FUNC = 262,
  57. HASH_DEFINE_OBJ = 263,
  58. HASH_ELIF = 264,
  59. HASH_ELSE = 265,
  60. HASH_ENDIF = 266,
  61. HASH_IF = 267,
  62. HASH_IFDEF = 268,
  63. HASH_IFNDEF = 269,
  64. HASH_UNDEF = 270,
  65. HASH_VERSION = 271,
  66. IDENTIFIER = 272,
  67. IF_EXPANDED = 273,
  68. INTEGER = 274,
  69. INTEGER_STRING = 275,
  70. NEWLINE = 276,
  71. OTHER = 277,
  72. PLACEHOLDER = 278,
  73. SPACE = 279,
  74. PASTE = 280,
  75. OR = 281,
  76. AND = 282,
  77. NOT_EQUAL = 283,
  78. EQUAL = 284,
  79. GREATER_OR_EQUAL = 285,
  80. LESS_OR_EQUAL = 286,
  81. RIGHT_SHIFT = 287,
  82. LEFT_SHIFT = 288,
  83. UNARY = 289
  84. };
  85. #endif
  86. /* Tokens. */
  87. #define COMMA_FINAL 258
  88. #define DEFINED 259
  89. #define ELIF_EXPANDED 260
  90. #define HASH 261
  91. #define HASH_DEFINE_FUNC 262
  92. #define HASH_DEFINE_OBJ 263
  93. #define HASH_ELIF 264
  94. #define HASH_ELSE 265
  95. #define HASH_ENDIF 266
  96. #define HASH_IF 267
  97. #define HASH_IFDEF 268
  98. #define HASH_IFNDEF 269
  99. #define HASH_UNDEF 270
  100. #define HASH_VERSION 271
  101. #define IDENTIFIER 272
  102. #define IF_EXPANDED 273
  103. #define INTEGER 274
  104. #define INTEGER_STRING 275
  105. #define NEWLINE 276
  106. #define OTHER 277
  107. #define PLACEHOLDER 278
  108. #define SPACE 279
  109. #define PASTE 280
  110. #define OR 281
  111. #define AND 282
  112. #define NOT_EQUAL 283
  113. #define EQUAL 284
  114. #define GREATER_OR_EQUAL 285
  115. #define LESS_OR_EQUAL 286
  116. #define RIGHT_SHIFT 287
  117. #define LEFT_SHIFT 288
  118. #define UNARY 289
  119. /* Copy the first part of user declarations. */
  120. #line 1 "src/glsl/glcpp/glcpp-parse.y"
  121. /*
  122. * Copyright © 2010 Intel Corporation
  123. *
  124. * Permission is hereby granted, free of charge, to any person obtaining a
  125. * copy of this software and associated documentation files (the "Software"),
  126. * to deal in the Software without restriction, including without limitation
  127. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  128. * and/or sell copies of the Software, and to permit persons to whom the
  129. * Software is furnished to do so, subject to the following conditions:
  130. *
  131. * The above copyright notice and this permission notice (including the next
  132. * paragraph) shall be included in all copies or substantial portions of the
  133. * Software.
  134. *
  135. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  136. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  137. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  138. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  139. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  140. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  141. * DEALINGS IN THE SOFTWARE.
  142. */
  143. #include <stdio.h>
  144. #include <stdlib.h>
  145. #include <string.h>
  146. #include <assert.h>
  147. #include <inttypes.h>
  148. #include "glcpp.h"
  149. #include "main/core.h" /* for struct gl_extensions */
  150. #include "main/mtypes.h" /* for gl_api enum */
  151. static void
  152. yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
  153. static void
  154. _define_object_macro (glcpp_parser_t *parser,
  155. YYLTYPE *loc,
  156. const char *macro,
  157. token_list_t *replacements);
  158. static void
  159. _define_function_macro (glcpp_parser_t *parser,
  160. YYLTYPE *loc,
  161. const char *macro,
  162. string_list_t *parameters,
  163. token_list_t *replacements);
  164. static string_list_t *
  165. _string_list_create (void *ctx);
  166. static void
  167. _string_list_append_item (string_list_t *list, const char *str);
  168. static int
  169. _string_list_contains (string_list_t *list, const char *member, int *index);
  170. static int
  171. _string_list_length (string_list_t *list);
  172. static int
  173. _string_list_equal (string_list_t *a, string_list_t *b);
  174. static argument_list_t *
  175. _argument_list_create (void *ctx);
  176. static void
  177. _argument_list_append (argument_list_t *list, token_list_t *argument);
  178. static int
  179. _argument_list_length (argument_list_t *list);
  180. static token_list_t *
  181. _argument_list_member_at (argument_list_t *list, int index);
  182. /* Note: This function ralloc_steal()s the str pointer. */
  183. static token_t *
  184. _token_create_str (void *ctx, int type, char *str);
  185. static token_t *
  186. _token_create_ival (void *ctx, int type, int ival);
  187. static token_list_t *
  188. _token_list_create (void *ctx);
  189. /* Note: This function calls ralloc_steal on token. */
  190. static void
  191. _token_list_append (token_list_t *list, token_t *token);
  192. static void
  193. _token_list_append_list (token_list_t *list, token_list_t *tail);
  194. static int
  195. _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b);
  196. static active_list_t *
  197. _active_list_push (active_list_t *list,
  198. const char *identifier,
  199. token_node_t *marker);
  200. static active_list_t *
  201. _active_list_pop (active_list_t *list);
  202. int
  203. _active_list_contains (active_list_t *list, const char *identifier);
  204. static void
  205. _glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list);
  206. static void
  207. _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
  208. token_list_t *list);
  209. static void
  210. _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
  211. token_list_t *list);
  212. static void
  213. _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
  214. int condition);
  215. static void
  216. _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
  217. const char *type, int condition);
  218. static void
  219. _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc);
  220. #define yylex glcpp_parser_lex
  221. static int
  222. glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser);
  223. static void
  224. glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list);
  225. static void
  226. add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
  227. /* Enabling traces. */
  228. #ifndef YYDEBUG
  229. # define YYDEBUG 0
  230. #endif
  231. /* Enabling verbose error messages. */
  232. #ifdef YYERROR_VERBOSE
  233. # undef YYERROR_VERBOSE
  234. # define YYERROR_VERBOSE 1
  235. #else
  236. # define YYERROR_VERBOSE 1
  237. #endif
  238. /* Enabling the token table. */
  239. #ifndef YYTOKEN_TABLE
  240. # define YYTOKEN_TABLE 0
  241. #endif
  242. #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
  243. typedef int YYSTYPE;
  244. # define yystype YYSTYPE /* obsolescent; will be withdrawn */
  245. # define YYSTYPE_IS_DECLARED 1
  246. # define YYSTYPE_IS_TRIVIAL 1
  247. #endif
  248. #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
  249. typedef struct YYLTYPE
  250. {
  251. int first_line;
  252. int first_column;
  253. int last_line;
  254. int last_column;
  255. } YYLTYPE;
  256. # define yyltype YYLTYPE /* obsolescent; will be withdrawn */
  257. # define YYLTYPE_IS_DECLARED 1
  258. # define YYLTYPE_IS_TRIVIAL 1
  259. #endif
  260. /* Copy the second part of user declarations. */
  261. /* Line 216 of yacc.c. */
  262. #line 329 "src/glsl/glcpp/glcpp-parse.c"
  263. #ifdef short
  264. # undef short
  265. #endif
  266. #ifdef YYTYPE_UINT8
  267. typedef YYTYPE_UINT8 yytype_uint8;
  268. #else
  269. typedef unsigned char yytype_uint8;
  270. #endif
  271. #ifdef YYTYPE_INT8
  272. typedef YYTYPE_INT8 yytype_int8;
  273. #elif (defined __STDC__ || defined __C99__FUNC__ \
  274. || defined __cplusplus || defined _MSC_VER)
  275. typedef signed char yytype_int8;
  276. #else
  277. typedef short int yytype_int8;
  278. #endif
  279. #ifdef YYTYPE_UINT16
  280. typedef YYTYPE_UINT16 yytype_uint16;
  281. #else
  282. typedef unsigned short int yytype_uint16;
  283. #endif
  284. #ifdef YYTYPE_INT16
  285. typedef YYTYPE_INT16 yytype_int16;
  286. #else
  287. typedef short int yytype_int16;
  288. #endif
  289. #ifndef YYSIZE_T
  290. # ifdef __SIZE_TYPE__
  291. # define YYSIZE_T __SIZE_TYPE__
  292. # elif defined size_t
  293. # define YYSIZE_T size_t
  294. # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
  295. || defined __cplusplus || defined _MSC_VER)
  296. # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
  297. # define YYSIZE_T size_t
  298. # else
  299. # define YYSIZE_T unsigned int
  300. # endif
  301. #endif
  302. #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
  303. #ifndef YY_
  304. # if defined YYENABLE_NLS && YYENABLE_NLS
  305. # if ENABLE_NLS
  306. # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
  307. # define YY_(msgid) dgettext ("bison-runtime", msgid)
  308. # endif
  309. # endif
  310. # ifndef YY_
  311. # define YY_(msgid) msgid
  312. # endif
  313. #endif
  314. /* Suppress unused-variable warnings by "using" E. */
  315. #if ! defined lint || defined __GNUC__
  316. # define YYUSE(e) ((void) (e))
  317. #else
  318. # define YYUSE(e) /* empty */
  319. #endif
  320. /* Identity function, used to suppress warnings about constant conditions. */
  321. #ifndef lint
  322. # define YYID(n) (n)
  323. #else
  324. #if (defined __STDC__ || defined __C99__FUNC__ \
  325. || defined __cplusplus || defined _MSC_VER)
  326. static int
  327. YYID (int i)
  328. #else
  329. static int
  330. YYID (i)
  331. int i;
  332. #endif
  333. {
  334. return i;
  335. }
  336. #endif
  337. #if ! defined yyoverflow || YYERROR_VERBOSE
  338. /* The parser invokes alloca or malloc; define the necessary symbols. */
  339. # ifdef YYSTACK_USE_ALLOCA
  340. # if YYSTACK_USE_ALLOCA
  341. # ifdef __GNUC__
  342. # define YYSTACK_ALLOC __builtin_alloca
  343. # elif defined __BUILTIN_VA_ARG_INCR
  344. # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
  345. # elif defined _AIX
  346. # define YYSTACK_ALLOC __alloca
  347. # elif defined _MSC_VER
  348. # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
  349. # define alloca _alloca
  350. # else
  351. # define YYSTACK_ALLOC alloca
  352. # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  353. || defined __cplusplus || defined _MSC_VER)
  354. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  355. # ifndef _STDLIB_H
  356. # define _STDLIB_H 1
  357. # endif
  358. # endif
  359. # endif
  360. # endif
  361. # endif
  362. # ifdef YYSTACK_ALLOC
  363. /* Pacify GCC's `empty if-body' warning. */
  364. # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
  365. # ifndef YYSTACK_ALLOC_MAXIMUM
  366. /* The OS might guarantee only one guard page at the bottom of the stack,
  367. and a page size can be as small as 4096 bytes. So we cannot safely
  368. invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
  369. to allow for a few compiler-allocated temporary stack slots. */
  370. # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
  371. # endif
  372. # else
  373. # define YYSTACK_ALLOC YYMALLOC
  374. # define YYSTACK_FREE YYFREE
  375. # ifndef YYSTACK_ALLOC_MAXIMUM
  376. # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
  377. # endif
  378. # if (defined __cplusplus && ! defined _STDLIB_H \
  379. && ! ((defined YYMALLOC || defined malloc) \
  380. && (defined YYFREE || defined free)))
  381. # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
  382. # ifndef _STDLIB_H
  383. # define _STDLIB_H 1
  384. # endif
  385. # endif
  386. # ifndef YYMALLOC
  387. # define YYMALLOC malloc
  388. # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  389. || defined __cplusplus || defined _MSC_VER)
  390. void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
  391. # endif
  392. # endif
  393. # ifndef YYFREE
  394. # define YYFREE free
  395. # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
  396. || defined __cplusplus || defined _MSC_VER)
  397. void free (void *); /* INFRINGES ON USER NAME SPACE */
  398. # endif
  399. # endif
  400. # endif
  401. #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
  402. #if (! defined yyoverflow \
  403. && (! defined __cplusplus \
  404. || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
  405. && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
  406. /* A type that is properly aligned for any stack member. */
  407. union yyalloc
  408. {
  409. yytype_int16 yyss;
  410. YYSTYPE yyvs;
  411. YYLTYPE yyls;
  412. };
  413. /* The size of the maximum gap between one aligned stack and the next. */
  414. # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
  415. /* The size of an array large to enough to hold all stacks, each with
  416. N elements. */
  417. # define YYSTACK_BYTES(N) \
  418. ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
  419. + 2 * YYSTACK_GAP_MAXIMUM)
  420. /* Copy COUNT objects from FROM to TO. The source and destination do
  421. not overlap. */
  422. # ifndef YYCOPY
  423. # if defined __GNUC__ && 1 < __GNUC__
  424. # define YYCOPY(To, From, Count) \
  425. __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
  426. # else
  427. # define YYCOPY(To, From, Count) \
  428. do \
  429. { \
  430. YYSIZE_T yyi; \
  431. for (yyi = 0; yyi < (Count); yyi++) \
  432. (To)[yyi] = (From)[yyi]; \
  433. } \
  434. while (YYID (0))
  435. # endif
  436. # endif
  437. /* Relocate STACK from its old location to the new one. The
  438. local variables YYSIZE and YYSTACKSIZE give the old and new number of
  439. elements in the stack, and YYPTR gives the new location of the
  440. stack. Advance YYPTR to a properly aligned location for the next
  441. stack. */
  442. # define YYSTACK_RELOCATE(Stack) \
  443. do \
  444. { \
  445. YYSIZE_T yynewbytes; \
  446. YYCOPY (&yyptr->Stack, Stack, yysize); \
  447. Stack = &yyptr->Stack; \
  448. yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
  449. yyptr += yynewbytes / sizeof (*yyptr); \
  450. } \
  451. while (YYID (0))
  452. #endif
  453. /* YYFINAL -- State number of the termination state. */
  454. #define YYFINAL 2
  455. /* YYLAST -- Last index in YYTABLE. */
  456. #define YYLAST 606
  457. /* YYNTOKENS -- Number of terminals. */
  458. #define YYNTOKENS 57
  459. /* YYNNTS -- Number of nonterminals. */
  460. #define YYNNTS 17
  461. /* YYNRULES -- Number of rules. */
  462. #define YYNRULES 101
  463. /* YYNRULES -- Number of states. */
  464. #define YYNSTATES 162
  465. /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
  466. #define YYUNDEFTOK 2
  467. #define YYMAXUTOK 289
  468. #define YYTRANSLATE(YYX) \
  469. ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
  470. /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
  471. static const yytype_uint8 yytranslate[] =
  472. {
  473. 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  474. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  475. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  476. 2, 2, 2, 47, 2, 2, 2, 43, 30, 2,
  477. 45, 46, 41, 39, 49, 40, 54, 42, 2, 2,
  478. 2, 2, 2, 2, 2, 2, 2, 2, 2, 55,
  479. 33, 56, 34, 2, 2, 2, 2, 2, 2, 2,
  480. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  481. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  482. 2, 50, 2, 51, 29, 2, 2, 2, 2, 2,
  483. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  484. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  485. 2, 2, 2, 52, 28, 53, 48, 2, 2, 2,
  486. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  487. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  488. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  489. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  490. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  491. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  492. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  493. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  494. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  495. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  496. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  497. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  498. 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
  499. 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  500. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  501. 25, 26, 27, 31, 32, 35, 36, 37, 38, 44
  502. };
  503. #if YYDEBUG
  504. /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
  505. YYRHS. */
  506. static const yytype_uint16 yyprhs[] =
  507. {
  508. 0, 0, 3, 4, 7, 9, 11, 13, 16, 20,
  509. 24, 29, 36, 44, 48, 52, 55, 60, 65, 69,
  510. 72, 75, 78, 82, 85, 87, 89, 91, 95, 99,
  511. 103, 107, 111, 115, 119, 123, 127, 131, 135, 139,
  512. 143, 147, 151, 155, 159, 163, 166, 169, 172, 175,
  513. 179, 181, 185, 187, 190, 193, 194, 196, 197, 199,
  514. 202, 207, 209, 211, 214, 216, 219, 221, 223, 225,
  515. 227, 229, 231, 233, 235, 237, 239, 241, 243, 245,
  516. 247, 249, 251, 253, 255, 257, 259, 261, 263, 265,
  517. 267, 269, 271, 273, 275, 277, 279, 281, 283, 285,
  518. 287, 289
  519. };
  520. /* YYRHS -- A `-1'-separated list of the rules' RHS. */
  521. static const yytype_int8 yyrhs[] =
  522. {
  523. 58, 0, -1, -1, 58, 59, -1, 61, -1, 65,
  524. -1, 60, -1, 6, 66, -1, 18, 63, 21, -1,
  525. 5, 63, 21, -1, 8, 17, 67, 21, -1, 7,
  526. 17, 45, 46, 67, 21, -1, 7, 17, 45, 64,
  527. 46, 67, 21, -1, 15, 17, 21, -1, 12, 70,
  528. 21, -1, 12, 21, -1, 13, 17, 68, 21, -1,
  529. 14, 17, 68, 21, -1, 9, 70, 21, -1, 9,
  530. 21, -1, 10, 21, -1, 11, 21, -1, 16, 62,
  531. 21, -1, 6, 21, -1, 20, -1, 19, -1, 62,
  532. -1, 63, 26, 63, -1, 63, 27, 63, -1, 63,
  533. 28, 63, -1, 63, 29, 63, -1, 63, 30, 63,
  534. -1, 63, 31, 63, -1, 63, 32, 63, -1, 63,
  535. 35, 63, -1, 63, 36, 63, -1, 63, 34, 63,
  536. -1, 63, 33, 63, -1, 63, 37, 63, -1, 63,
  537. 38, 63, -1, 63, 40, 63, -1, 63, 39, 63,
  538. -1, 63, 43, 63, -1, 63, 42, 63, -1, 63,
  539. 41, 63, -1, 47, 63, -1, 48, 63, -1, 40,
  540. 63, -1, 39, 63, -1, 45, 63, 46, -1, 17,
  541. -1, 64, 49, 17, -1, 21, -1, 71, 21, -1,
  542. 71, 21, -1, -1, 71, -1, -1, 71, -1, 4,
  543. 17, -1, 4, 45, 17, 46, -1, 72, -1, 69,
  544. -1, 70, 69, -1, 72, -1, 71, 72, -1, 17,
  545. -1, 20, -1, 73, -1, 22, -1, 24, -1, 50,
  546. -1, 51, -1, 45, -1, 46, -1, 52, -1, 53,
  547. -1, 54, -1, 30, -1, 41, -1, 39, -1, 40,
  548. -1, 48, -1, 47, -1, 42, -1, 43, -1, 38,
  549. -1, 37, -1, 33, -1, 34, -1, 36, -1, 35,
  550. -1, 32, -1, 31, -1, 29, -1, 28, -1, 27,
  551. -1, 26, -1, 55, -1, 49, -1, 56, -1, 25,
  552. -1
  553. };
  554. /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
  555. static const yytype_uint16 yyrline[] =
  556. {
  557. 0, 181, 181, 183, 187, 190, 195, 196, 200, 203,
  558. 209, 212, 215, 218, 226, 245, 255, 260, 265, 284,
  559. 299, 302, 305, 326, 330, 339, 344, 345, 348, 351,
  560. 354, 357, 360, 363, 366, 369, 372, 375, 378, 381,
  561. 384, 387, 390, 398, 406, 409, 412, 415, 418, 421,
  562. 427, 432, 440, 441, 445, 451, 452, 455, 457, 464,
  563. 468, 472, 477, 481, 488, 493, 500, 504, 508, 512,
  564. 516, 523, 524, 525, 526, 527, 528, 529, 530, 531,
  565. 532, 533, 534, 535, 536, 537, 538, 539, 540, 541,
  566. 542, 543, 544, 545, 546, 547, 548, 549, 550, 551,
  567. 552, 553
  568. };
  569. #endif
  570. #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
  571. /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
  572. First, the terminals, then, starting at YYNTOKENS, nonterminals. */
  573. static const char *const yytname[] =
  574. {
  575. "$end", "error", "$undefined", "COMMA_FINAL", "DEFINED",
  576. "ELIF_EXPANDED", "HASH", "HASH_DEFINE_FUNC", "HASH_DEFINE_OBJ",
  577. "HASH_ELIF", "HASH_ELSE", "HASH_ENDIF", "HASH_IF", "HASH_IFDEF",
  578. "HASH_IFNDEF", "HASH_UNDEF", "HASH_VERSION", "IDENTIFIER", "IF_EXPANDED",
  579. "INTEGER", "INTEGER_STRING", "NEWLINE", "OTHER", "PLACEHOLDER", "SPACE",
  580. "PASTE", "OR", "AND", "'|'", "'^'", "'&'", "NOT_EQUAL", "EQUAL", "'<'",
  581. "'>'", "GREATER_OR_EQUAL", "LESS_OR_EQUAL", "RIGHT_SHIFT", "LEFT_SHIFT",
  582. "'+'", "'-'", "'*'", "'/'", "'%'", "UNARY", "'('", "')'", "'!'", "'~'",
  583. "','", "'['", "']'", "'{'", "'}'", "'.'", "';'", "'='", "$accept",
  584. "input", "line", "expanded_line", "control_line", "integer_constant",
  585. "expression", "identifier_list", "text_line", "non_directive",
  586. "replacement_list", "junk", "conditional_token", "conditional_tokens",
  587. "pp_tokens", "preprocessing_token", "operator", 0
  588. };
  589. #endif
  590. # ifdef YYPRINT
  591. /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
  592. token YYLEX-NUM. */
  593. static const yytype_uint16 yytoknum[] =
  594. {
  595. 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
  596. 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
  597. 275, 276, 277, 278, 279, 280, 281, 282, 124, 94,
  598. 38, 283, 284, 60, 62, 285, 286, 287, 288, 43,
  599. 45, 42, 47, 37, 289, 40, 41, 33, 126, 44,
  600. 91, 93, 123, 125, 46, 59, 61
  601. };
  602. # endif
  603. /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
  604. static const yytype_uint8 yyr1[] =
  605. {
  606. 0, 57, 58, 58, 59, 59, 59, 59, 60, 60,
  607. 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
  608. 61, 61, 61, 61, 62, 62, 63, 63, 63, 63,
  609. 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
  610. 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
  611. 64, 64, 65, 65, 66, 67, 67, 68, 68, 69,
  612. 69, 69, 70, 70, 71, 71, 72, 72, 72, 72,
  613. 72, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  614. 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  615. 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  616. 73, 73
  617. };
  618. /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
  619. static const yytype_uint8 yyr2[] =
  620. {
  621. 0, 2, 0, 2, 1, 1, 1, 2, 3, 3,
  622. 4, 6, 7, 3, 3, 2, 4, 4, 3, 2,
  623. 2, 2, 3, 2, 1, 1, 1, 3, 3, 3,
  624. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  625. 3, 3, 3, 3, 3, 2, 2, 2, 2, 3,
  626. 1, 3, 1, 2, 2, 0, 1, 0, 1, 2,
  627. 4, 1, 1, 2, 1, 2, 1, 1, 1, 1,
  628. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  629. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  630. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  631. 1, 1
  632. };
  633. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
  634. STATE-NUM when YYTABLE doesn't specify something else to do. Zero
  635. means the default is an error. */
  636. static const yytype_uint8 yydefact[] =
  637. {
  638. 2, 0, 1, 0, 0, 0, 0, 0, 0, 0,
  639. 0, 0, 0, 0, 0, 66, 0, 67, 52, 69,
  640. 70, 101, 97, 96, 95, 94, 78, 93, 92, 88,
  641. 89, 91, 90, 87, 86, 80, 81, 79, 84, 85,
  642. 73, 74, 83, 82, 99, 71, 72, 75, 76, 77,
  643. 98, 100, 3, 6, 4, 5, 0, 64, 68, 25,
  644. 24, 0, 0, 0, 0, 0, 26, 0, 23, 7,
  645. 0, 0, 55, 0, 19, 62, 0, 61, 20, 21,
  646. 15, 0, 57, 57, 0, 0, 0, 53, 65, 48,
  647. 47, 0, 45, 46, 9, 0, 0, 0, 0, 0,
  648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  649. 0, 0, 0, 54, 0, 0, 56, 59, 0, 18,
  650. 63, 14, 0, 58, 0, 13, 22, 8, 49, 27,
  651. 28, 29, 30, 31, 32, 33, 37, 36, 34, 35,
  652. 38, 39, 41, 40, 44, 43, 42, 50, 55, 0,
  653. 10, 0, 16, 17, 0, 55, 0, 60, 11, 0,
  654. 51, 12
  655. };
  656. /* YYDEFGOTO[NTERM-NUM]. */
  657. static const yytype_int16 yydefgoto[] =
  658. {
  659. -1, 1, 52, 53, 54, 66, 67, 149, 55, 69,
  660. 115, 122, 75, 76, 116, 57, 58
  661. };
  662. /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
  663. STATE-NUM. */
  664. #define YYPACT_NINF -147
  665. static const yytype_int16 yypact[] =
  666. {
  667. -147, 112, -147, 28, -10, 55, 62, 152, -15, 59,
  668. 192, 85, 86, 87, 51, -147, 28, -147, -147, -147,
  669. -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
  670. -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
  671. -147, -147, -147, -147, -147, -147, -147, -147, -147, -147,
  672. -147, -147, -147, -147, -147, -147, 312, -147, -147, -147,
  673. -147, 28, 28, 28, 28, 28, -147, 428, -147, -147,
  674. 352, 63, 392, 17, -147, -147, 232, -147, -147, -147,
  675. -147, 272, 392, 392, 84, 89, 451, -147, -147, -147,
  676. -147, 469, -147, -147, -147, 28, 28, 28, 28, 28,
  677. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  678. 28, 28, 28, -147, 60, 90, 392, -147, 96, -147,
  679. -147, -147, 93, 392, 94, -147, -147, -147, -147, 489,
  680. 505, 520, 534, 547, 558, 558, 18, 18, 18, 18,
  681. 563, 563, 23, 23, -147, -147, -147, -147, 392, 32,
  682. -147, 61, -147, -147, 110, 392, 118, -147, -147, 149,
  683. -147, -147
  684. };
  685. /* YYPGOTO[NTERM-NUM]. */
  686. static const yytype_int16 yypgoto[] =
  687. {
  688. -147, -147, -147, -147, -147, 157, -11, -147, -147, -147,
  689. -146, 92, -68, 200, 0, -7, -147
  690. };
  691. /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
  692. positive, shift that token. If negative, reduce the rule which
  693. number is the opposite. If zero, do what YYDEFACT says.
  694. If YYTABLE_NINF, syntax error. */
  695. #define YYTABLE_NINF -1
  696. static const yytype_uint8 yytable[] =
  697. {
  698. 77, 56, 154, 77, 70, 86, 78, 15, 120, 159,
  699. 17, 68, 19, 120, 20, 21, 22, 23, 24, 25,
  700. 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  701. 36, 37, 38, 39, 117, 40, 41, 42, 43, 44,
  702. 45, 46, 47, 48, 49, 50, 51, 59, 60, 88,
  703. 89, 90, 91, 92, 93, 106, 107, 108, 109, 110,
  704. 111, 112, 118, 88, 110, 111, 112, 61, 62, 77,
  705. 59, 60, 71, 63, 77, 64, 65, 147, 155, 72,
  706. 79, 156, 123, 123, 129, 130, 131, 132, 133, 134,
  707. 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
  708. 145, 146, 82, 83, 84, 125, 148, 157, 114, 88,
  709. 126, 150, 2, 151, 152, 153, 88, 3, 4, 5,
  710. 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  711. 16, 158, 17, 18, 19, 160, 20, 21, 22, 23,
  712. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  713. 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
  714. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  715. 161, 85, 17, 74, 19, 124, 20, 21, 22, 23,
  716. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  717. 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
  718. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  719. 81, 0, 17, 80, 19, 0, 20, 21, 22, 23,
  720. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  721. 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
  722. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  723. 0, 0, 17, 119, 19, 0, 20, 21, 22, 23,
  724. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  725. 34, 35, 36, 37, 38, 39, 73, 40, 41, 42,
  726. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  727. 0, 0, 17, 121, 19, 0, 20, 21, 22, 23,
  728. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  729. 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
  730. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  731. 0, 0, 17, 87, 19, 0, 20, 21, 22, 23,
  732. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  733. 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
  734. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  735. 0, 0, 17, 113, 19, 0, 20, 21, 22, 23,
  736. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  737. 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
  738. 43, 44, 45, 46, 47, 48, 49, 50, 51, 15,
  739. 0, 0, 17, 0, 19, 0, 20, 21, 22, 23,
  740. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  741. 34, 35, 36, 37, 38, 39, 0, 40, 41, 42,
  742. 43, 44, 45, 46, 47, 48, 49, 50, 51, 94,
  743. 0, 0, 0, 0, 95, 96, 97, 98, 99, 100,
  744. 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
  745. 111, 112, 127, 0, 0, 0, 0, 95, 96, 97,
  746. 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
  747. 108, 109, 110, 111, 112, 95, 96, 97, 98, 99,
  748. 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
  749. 110, 111, 112, 0, 0, 128, 96, 97, 98, 99,
  750. 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
  751. 110, 111, 112, 97, 98, 99, 100, 101, 102, 103,
  752. 104, 105, 106, 107, 108, 109, 110, 111, 112, 98,
  753. 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
  754. 109, 110, 111, 112, 99, 100, 101, 102, 103, 104,
  755. 105, 106, 107, 108, 109, 110, 111, 112, 100, 101,
  756. 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
  757. 112, 102, 103, 104, 105, 106, 107, 108, 109, 110,
  758. 111, 112, 108, 109, 110, 111, 112
  759. };
  760. static const yytype_int16 yycheck[] =
  761. {
  762. 7, 1, 148, 10, 4, 16, 21, 17, 76, 155,
  763. 20, 21, 22, 81, 24, 25, 26, 27, 28, 29,
  764. 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  765. 40, 41, 42, 43, 17, 45, 46, 47, 48, 49,
  766. 50, 51, 52, 53, 54, 55, 56, 19, 20, 56,
  767. 61, 62, 63, 64, 65, 37, 38, 39, 40, 41,
  768. 42, 43, 45, 70, 41, 42, 43, 39, 40, 76,
  769. 19, 20, 17, 45, 81, 47, 48, 17, 46, 17,
  770. 21, 49, 82, 83, 95, 96, 97, 98, 99, 100,
  771. 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
  772. 111, 112, 17, 17, 17, 21, 46, 46, 45, 116,
  773. 21, 21, 0, 17, 21, 21, 123, 5, 6, 7,
  774. 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  775. 18, 21, 20, 21, 22, 17, 24, 25, 26, 27,
  776. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  777. 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
  778. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  779. 21, 14, 20, 21, 22, 83, 24, 25, 26, 27,
  780. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  781. 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
  782. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  783. 10, -1, 20, 21, 22, -1, 24, 25, 26, 27,
  784. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  785. 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
  786. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  787. -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
  788. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  789. 38, 39, 40, 41, 42, 43, 4, 45, 46, 47,
  790. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  791. -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
  792. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  793. 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
  794. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  795. -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
  796. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  797. 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
  798. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  799. -1, -1, 20, 21, 22, -1, 24, 25, 26, 27,
  800. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  801. 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
  802. 48, 49, 50, 51, 52, 53, 54, 55, 56, 17,
  803. -1, -1, 20, -1, 22, -1, 24, 25, 26, 27,
  804. 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
  805. 38, 39, 40, 41, 42, 43, -1, 45, 46, 47,
  806. 48, 49, 50, 51, 52, 53, 54, 55, 56, 21,
  807. -1, -1, -1, -1, 26, 27, 28, 29, 30, 31,
  808. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
  809. 42, 43, 21, -1, -1, -1, -1, 26, 27, 28,
  810. 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
  811. 39, 40, 41, 42, 43, 26, 27, 28, 29, 30,
  812. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  813. 41, 42, 43, -1, -1, 46, 27, 28, 29, 30,
  814. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  815. 41, 42, 43, 28, 29, 30, 31, 32, 33, 34,
  816. 35, 36, 37, 38, 39, 40, 41, 42, 43, 29,
  817. 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  818. 40, 41, 42, 43, 30, 31, 32, 33, 34, 35,
  819. 36, 37, 38, 39, 40, 41, 42, 43, 31, 32,
  820. 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
  821. 43, 33, 34, 35, 36, 37, 38, 39, 40, 41,
  822. 42, 43, 39, 40, 41, 42, 43
  823. };
  824. /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
  825. symbol of state STATE-NUM. */
  826. static const yytype_uint8 yystos[] =
  827. {
  828. 0, 58, 0, 5, 6, 7, 8, 9, 10, 11,
  829. 12, 13, 14, 15, 16, 17, 18, 20, 21, 22,
  830. 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  831. 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  832. 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
  833. 55, 56, 59, 60, 61, 65, 71, 72, 73, 19,
  834. 20, 39, 40, 45, 47, 48, 62, 63, 21, 66,
  835. 71, 17, 17, 4, 21, 69, 70, 72, 21, 21,
  836. 21, 70, 17, 17, 17, 62, 63, 21, 72, 63,
  837. 63, 63, 63, 63, 21, 26, 27, 28, 29, 30,
  838. 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  839. 41, 42, 43, 21, 45, 67, 71, 17, 45, 21,
  840. 69, 21, 68, 71, 68, 21, 21, 21, 46, 63,
  841. 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
  842. 63, 63, 63, 63, 63, 63, 63, 17, 46, 64,
  843. 21, 17, 21, 21, 67, 46, 49, 46, 21, 67,
  844. 17, 21
  845. };
  846. #define yyerrok (yyerrstatus = 0)
  847. #define yyclearin (yychar = YYEMPTY)
  848. #define YYEMPTY (-2)
  849. #define YYEOF 0
  850. #define YYACCEPT goto yyacceptlab
  851. #define YYABORT goto yyabortlab
  852. #define YYERROR goto yyerrorlab
  853. /* Like YYERROR except do call yyerror. This remains here temporarily
  854. to ease the transition to the new meaning of YYERROR, for GCC.
  855. Once GCC version 2 has supplanted version 1, this can go. */
  856. #define YYFAIL goto yyerrlab
  857. #define YYRECOVERING() (!!yyerrstatus)
  858. #define YYBACKUP(Token, Value) \
  859. do \
  860. if (yychar == YYEMPTY && yylen == 1) \
  861. { \
  862. yychar = (Token); \
  863. yylval = (Value); \
  864. yytoken = YYTRANSLATE (yychar); \
  865. YYPOPSTACK (1); \
  866. goto yybackup; \
  867. } \
  868. else \
  869. { \
  870. yyerror (&yylloc, parser, YY_("syntax error: cannot back up")); \
  871. YYERROR; \
  872. } \
  873. while (YYID (0))
  874. #define YYTERROR 1
  875. #define YYERRCODE 256
  876. /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  877. If N is 0, then set CURRENT to the empty location which ends
  878. the previous symbol: RHS[0] (always defined). */
  879. #define YYRHSLOC(Rhs, K) ((Rhs)[K])
  880. #ifndef YYLLOC_DEFAULT
  881. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  882. do \
  883. if (YYID (N)) \
  884. { \
  885. (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
  886. (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
  887. (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
  888. (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
  889. } \
  890. else \
  891. { \
  892. (Current).first_line = (Current).last_line = \
  893. YYRHSLOC (Rhs, 0).last_line; \
  894. (Current).first_column = (Current).last_column = \
  895. YYRHSLOC (Rhs, 0).last_column; \
  896. } \
  897. while (YYID (0))
  898. #endif
  899. /* YY_LOCATION_PRINT -- Print the location on the stream.
  900. This macro was not mandated originally: define only if we know
  901. we won't break user code: when these are the locations we know. */
  902. #ifndef YY_LOCATION_PRINT
  903. # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  904. # define YY_LOCATION_PRINT(File, Loc) \
  905. fprintf (File, "%d.%d-%d.%d", \
  906. (Loc).first_line, (Loc).first_column, \
  907. (Loc).last_line, (Loc).last_column)
  908. # else
  909. # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
  910. # endif
  911. #endif
  912. /* YYLEX -- calling `yylex' with the right arguments. */
  913. #ifdef YYLEX_PARAM
  914. # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
  915. #else
  916. # define YYLEX yylex (&yylval, &yylloc, parser)
  917. #endif
  918. /* Enable debugging if requested. */
  919. #if YYDEBUG
  920. # ifndef YYFPRINTF
  921. # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
  922. # define YYFPRINTF fprintf
  923. # endif
  924. # define YYDPRINTF(Args) \
  925. do { \
  926. if (yydebug) \
  927. YYFPRINTF Args; \
  928. } while (YYID (0))
  929. # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
  930. do { \
  931. if (yydebug) \
  932. { \
  933. YYFPRINTF (stderr, "%s ", Title); \
  934. yy_symbol_print (stderr, \
  935. Type, Value, Location, parser); \
  936. YYFPRINTF (stderr, "\n"); \
  937. } \
  938. } while (YYID (0))
  939. /*--------------------------------.
  940. | Print this symbol on YYOUTPUT. |
  941. `--------------------------------*/
  942. /*ARGSUSED*/
  943. #if (defined __STDC__ || defined __C99__FUNC__ \
  944. || defined __cplusplus || defined _MSC_VER)
  945. static void
  946. yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
  947. #else
  948. static void
  949. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
  950. FILE *yyoutput;
  951. int yytype;
  952. YYSTYPE const * const yyvaluep;
  953. YYLTYPE const * const yylocationp;
  954. glcpp_parser_t *parser;
  955. #endif
  956. {
  957. if (!yyvaluep)
  958. return;
  959. YYUSE (yylocationp);
  960. YYUSE (parser);
  961. # ifdef YYPRINT
  962. if (yytype < YYNTOKENS)
  963. YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
  964. # else
  965. YYUSE (yyoutput);
  966. # endif
  967. switch (yytype)
  968. {
  969. default:
  970. break;
  971. }
  972. }
  973. /*--------------------------------.
  974. | Print this symbol on YYOUTPUT. |
  975. `--------------------------------*/
  976. #if (defined __STDC__ || defined __C99__FUNC__ \
  977. || defined __cplusplus || defined _MSC_VER)
  978. static void
  979. yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, glcpp_parser_t *parser)
  980. #else
  981. static void
  982. yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, parser)
  983. FILE *yyoutput;
  984. int yytype;
  985. YYSTYPE const * const yyvaluep;
  986. YYLTYPE const * const yylocationp;
  987. glcpp_parser_t *parser;
  988. #endif
  989. {
  990. if (yytype < YYNTOKENS)
  991. YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
  992. else
  993. YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
  994. YY_LOCATION_PRINT (yyoutput, *yylocationp);
  995. YYFPRINTF (yyoutput, ": ");
  996. yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, parser);
  997. YYFPRINTF (yyoutput, ")");
  998. }
  999. /*------------------------------------------------------------------.
  1000. | yy_stack_print -- Print the state stack from its BOTTOM up to its |
  1001. | TOP (included). |
  1002. `------------------------------------------------------------------*/
  1003. #if (defined __STDC__ || defined __C99__FUNC__ \
  1004. || defined __cplusplus || defined _MSC_VER)
  1005. static void
  1006. yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
  1007. #else
  1008. static void
  1009. yy_stack_print (bottom, top)
  1010. yytype_int16 *bottom;
  1011. yytype_int16 *top;
  1012. #endif
  1013. {
  1014. YYFPRINTF (stderr, "Stack now");
  1015. for (; bottom <= top; ++bottom)
  1016. YYFPRINTF (stderr, " %d", *bottom);
  1017. YYFPRINTF (stderr, "\n");
  1018. }
  1019. # define YY_STACK_PRINT(Bottom, Top) \
  1020. do { \
  1021. if (yydebug) \
  1022. yy_stack_print ((Bottom), (Top)); \
  1023. } while (YYID (0))
  1024. /*------------------------------------------------.
  1025. | Report that the YYRULE is going to be reduced. |
  1026. `------------------------------------------------*/
  1027. #if (defined __STDC__ || defined __C99__FUNC__ \
  1028. || defined __cplusplus || defined _MSC_VER)
  1029. static void
  1030. yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, glcpp_parser_t *parser)
  1031. #else
  1032. static void
  1033. yy_reduce_print (yyvsp, yylsp, yyrule, parser)
  1034. YYSTYPE *yyvsp;
  1035. YYLTYPE *yylsp;
  1036. int yyrule;
  1037. glcpp_parser_t *parser;
  1038. #endif
  1039. {
  1040. int yynrhs = yyr2[yyrule];
  1041. int yyi;
  1042. unsigned long int yylno = yyrline[yyrule];
  1043. YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
  1044. yyrule - 1, yylno);
  1045. /* The symbols being reduced. */
  1046. for (yyi = 0; yyi < yynrhs; yyi++)
  1047. {
  1048. fprintf (stderr, " $%d = ", yyi + 1);
  1049. yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
  1050. &(yyvsp[(yyi + 1) - (yynrhs)])
  1051. , &(yylsp[(yyi + 1) - (yynrhs)]) , parser);
  1052. fprintf (stderr, "\n");
  1053. }
  1054. }
  1055. # define YY_REDUCE_PRINT(Rule) \
  1056. do { \
  1057. if (yydebug) \
  1058. yy_reduce_print (yyvsp, yylsp, Rule, parser); \
  1059. } while (YYID (0))
  1060. /* Nonzero means print parse trace. It is left uninitialized so that
  1061. multiple parsers can coexist. */
  1062. int yydebug;
  1063. #else /* !YYDEBUG */
  1064. # define YYDPRINTF(Args)
  1065. # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
  1066. # define YY_STACK_PRINT(Bottom, Top)
  1067. # define YY_REDUCE_PRINT(Rule)
  1068. #endif /* !YYDEBUG */
  1069. /* YYINITDEPTH -- initial size of the parser's stacks. */
  1070. #ifndef YYINITDEPTH
  1071. # define YYINITDEPTH 200
  1072. #endif
  1073. /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
  1074. if the built-in stack extension method is used).
  1075. Do not make this value too large; the results are undefined if
  1076. YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
  1077. evaluated with infinite-precision integer arithmetic. */
  1078. #ifndef YYMAXDEPTH
  1079. # define YYMAXDEPTH 10000
  1080. #endif
  1081. #if YYERROR_VERBOSE
  1082. # ifndef yystrlen
  1083. # if defined __GLIBC__ && defined _STRING_H
  1084. # define yystrlen strlen
  1085. # else
  1086. /* Return the length of YYSTR. */
  1087. #if (defined __STDC__ || defined __C99__FUNC__ \
  1088. || defined __cplusplus || defined _MSC_VER)
  1089. static YYSIZE_T
  1090. yystrlen (const char *yystr)
  1091. #else
  1092. static YYSIZE_T
  1093. yystrlen (yystr)
  1094. const char *yystr;
  1095. #endif
  1096. {
  1097. YYSIZE_T yylen;
  1098. for (yylen = 0; yystr[yylen]; yylen++)
  1099. continue;
  1100. return yylen;
  1101. }
  1102. # endif
  1103. # endif
  1104. # ifndef yystpcpy
  1105. # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
  1106. # define yystpcpy stpcpy
  1107. # else
  1108. /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
  1109. YYDEST. */
  1110. #if (defined __STDC__ || defined __C99__FUNC__ \
  1111. || defined __cplusplus || defined _MSC_VER)
  1112. static char *
  1113. yystpcpy (char *yydest, const char *yysrc)
  1114. #else
  1115. static char *
  1116. yystpcpy (yydest, yysrc)
  1117. char *yydest;
  1118. const char *yysrc;
  1119. #endif
  1120. {
  1121. char *yyd = yydest;
  1122. const char *yys = yysrc;
  1123. while ((*yyd++ = *yys++) != '\0')
  1124. continue;
  1125. return yyd - 1;
  1126. }
  1127. # endif
  1128. # endif
  1129. # ifndef yytnamerr
  1130. /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
  1131. quotes and backslashes, so that it's suitable for yyerror. The
  1132. heuristic is that double-quoting is unnecessary unless the string
  1133. contains an apostrophe, a comma, or backslash (other than
  1134. backslash-backslash). YYSTR is taken from yytname. If YYRES is
  1135. null, do not copy; instead, return the length of what the result
  1136. would have been. */
  1137. static YYSIZE_T
  1138. yytnamerr (char *yyres, const char *yystr)
  1139. {
  1140. if (*yystr == '"')
  1141. {
  1142. YYSIZE_T yyn = 0;
  1143. char const *yyp = yystr;
  1144. for (;;)
  1145. switch (*++yyp)
  1146. {
  1147. case '\'':
  1148. case ',':
  1149. goto do_not_strip_quotes;
  1150. case '\\':
  1151. if (*++yyp != '\\')
  1152. goto do_not_strip_quotes;
  1153. /* Fall through. */
  1154. default:
  1155. if (yyres)
  1156. yyres[yyn] = *yyp;
  1157. yyn++;
  1158. break;
  1159. case '"':
  1160. if (yyres)
  1161. yyres[yyn] = '\0';
  1162. return yyn;
  1163. }
  1164. do_not_strip_quotes: ;
  1165. }
  1166. if (! yyres)
  1167. return yystrlen (yystr);
  1168. return yystpcpy (yyres, yystr) - yyres;
  1169. }
  1170. # endif
  1171. /* Copy into YYRESULT an error message about the unexpected token
  1172. YYCHAR while in state YYSTATE. Return the number of bytes copied,
  1173. including the terminating null byte. If YYRESULT is null, do not
  1174. copy anything; just return the number of bytes that would be
  1175. copied. As a special case, return 0 if an ordinary "syntax error"
  1176. message will do. Return YYSIZE_MAXIMUM if overflow occurs during
  1177. size calculation. */
  1178. static YYSIZE_T
  1179. yysyntax_error (char *yyresult, int yystate, int yychar)
  1180. {
  1181. int yyn = yypact[yystate];
  1182. if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
  1183. return 0;
  1184. else
  1185. {
  1186. int yytype = YYTRANSLATE (yychar);
  1187. YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
  1188. YYSIZE_T yysize = yysize0;
  1189. YYSIZE_T yysize1;
  1190. int yysize_overflow = 0;
  1191. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  1192. char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  1193. int yyx;
  1194. # if 0
  1195. /* This is so xgettext sees the translatable formats that are
  1196. constructed on the fly. */
  1197. YY_("syntax error, unexpected %s");
  1198. YY_("syntax error, unexpected %s, expecting %s");
  1199. YY_("syntax error, unexpected %s, expecting %s or %s");
  1200. YY_("syntax error, unexpected %s, expecting %s or %s or %s");
  1201. YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
  1202. # endif
  1203. char *yyfmt;
  1204. char const *yyf;
  1205. static char const yyunexpected[] = "syntax error, unexpected %s";
  1206. static char const yyexpecting[] = ", expecting %s";
  1207. static char const yyor[] = " or %s";
  1208. char yyformat[sizeof yyunexpected
  1209. + sizeof yyexpecting - 1
  1210. + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
  1211. * (sizeof yyor - 1))];
  1212. char const *yyprefix = yyexpecting;
  1213. /* Start YYX at -YYN if negative to avoid negative indexes in
  1214. YYCHECK. */
  1215. int yyxbegin = yyn < 0 ? -yyn : 0;
  1216. /* Stay within bounds of both yycheck and yytname. */
  1217. int yychecklim = YYLAST - yyn + 1;
  1218. int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
  1219. int yycount = 1;
  1220. yyarg[0] = yytname[yytype];
  1221. yyfmt = yystpcpy (yyformat, yyunexpected);
  1222. for (yyx = yyxbegin; yyx < yyxend; ++yyx)
  1223. if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
  1224. {
  1225. if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
  1226. {
  1227. yycount = 1;
  1228. yysize = yysize0;
  1229. yyformat[sizeof yyunexpected - 1] = '\0';
  1230. break;
  1231. }
  1232. yyarg[yycount++] = yytname[yyx];
  1233. yysize1 = yysize + yytnamerr (0, yytname[yyx]);
  1234. yysize_overflow |= (yysize1 < yysize);
  1235. yysize = yysize1;
  1236. yyfmt = yystpcpy (yyfmt, yyprefix);
  1237. yyprefix = yyor;
  1238. }
  1239. yyf = YY_(yyformat);
  1240. yysize1 = yysize + yystrlen (yyf);
  1241. yysize_overflow |= (yysize1 < yysize);
  1242. yysize = yysize1;
  1243. if (yysize_overflow)
  1244. return YYSIZE_MAXIMUM;
  1245. if (yyresult)
  1246. {
  1247. /* Avoid sprintf, as that infringes on the user's name space.
  1248. Don't have undefined behavior even if the translation
  1249. produced a string with the wrong number of "%s"s. */
  1250. char *yyp = yyresult;
  1251. int yyi = 0;
  1252. while ((*yyp = *yyf) != '\0')
  1253. {
  1254. if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
  1255. {
  1256. yyp += yytnamerr (yyp, yyarg[yyi++]);
  1257. yyf += 2;
  1258. }
  1259. else
  1260. {
  1261. yyp++;
  1262. yyf++;
  1263. }
  1264. }
  1265. }
  1266. return yysize;
  1267. }
  1268. }
  1269. #endif /* YYERROR_VERBOSE */
  1270. /*-----------------------------------------------.
  1271. | Release the memory associated to this symbol. |
  1272. `-----------------------------------------------*/
  1273. /*ARGSUSED*/
  1274. #if (defined __STDC__ || defined __C99__FUNC__ \
  1275. || defined __cplusplus || defined _MSC_VER)
  1276. static void
  1277. yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, glcpp_parser_t *parser)
  1278. #else
  1279. static void
  1280. yydestruct (yymsg, yytype, yyvaluep, yylocationp, parser)
  1281. const char *yymsg;
  1282. int yytype;
  1283. YYSTYPE *yyvaluep;
  1284. YYLTYPE *yylocationp;
  1285. glcpp_parser_t *parser;
  1286. #endif
  1287. {
  1288. YYUSE (yyvaluep);
  1289. YYUSE (yylocationp);
  1290. YYUSE (parser);
  1291. if (!yymsg)
  1292. yymsg = "Deleting";
  1293. YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
  1294. switch (yytype)
  1295. {
  1296. default:
  1297. break;
  1298. }
  1299. }
  1300. /* Prevent warnings from -Wmissing-prototypes. */
  1301. #ifdef YYPARSE_PARAM
  1302. #if defined __STDC__ || defined __cplusplus
  1303. int yyparse (void *YYPARSE_PARAM);
  1304. #else
  1305. int yyparse ();
  1306. #endif
  1307. #else /* ! YYPARSE_PARAM */
  1308. #if defined __STDC__ || defined __cplusplus
  1309. int yyparse (glcpp_parser_t *parser);
  1310. #else
  1311. int yyparse ();
  1312. #endif
  1313. #endif /* ! YYPARSE_PARAM */
  1314. /*----------.
  1315. | yyparse. |
  1316. `----------*/
  1317. #ifdef YYPARSE_PARAM
  1318. #if (defined __STDC__ || defined __C99__FUNC__ \
  1319. || defined __cplusplus || defined _MSC_VER)
  1320. int
  1321. yyparse (void *YYPARSE_PARAM)
  1322. #else
  1323. int
  1324. yyparse (YYPARSE_PARAM)
  1325. void *YYPARSE_PARAM;
  1326. #endif
  1327. #else /* ! YYPARSE_PARAM */
  1328. #if (defined __STDC__ || defined __C99__FUNC__ \
  1329. || defined __cplusplus || defined _MSC_VER)
  1330. int
  1331. yyparse (glcpp_parser_t *parser)
  1332. #else
  1333. int
  1334. yyparse (parser)
  1335. glcpp_parser_t *parser;
  1336. #endif
  1337. #endif
  1338. {
  1339. /* The look-ahead symbol. */
  1340. int yychar;
  1341. /* The semantic value of the look-ahead symbol. */
  1342. YYSTYPE yylval;
  1343. /* Number of syntax errors so far. */
  1344. int yynerrs;
  1345. /* Location data for the look-ahead symbol. */
  1346. YYLTYPE yylloc;
  1347. int yystate;
  1348. int yyn;
  1349. int yyresult;
  1350. /* Number of tokens to shift before error messages enabled. */
  1351. int yyerrstatus;
  1352. /* Look-ahead token as an internal (translated) token number. */
  1353. int yytoken = 0;
  1354. #if YYERROR_VERBOSE
  1355. /* Buffer for error messages, and its allocated size. */
  1356. char yymsgbuf[128];
  1357. char *yymsg = yymsgbuf;
  1358. YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
  1359. #endif
  1360. /* Three stacks and their tools:
  1361. `yyss': related to states,
  1362. `yyvs': related to semantic values,
  1363. `yyls': related to locations.
  1364. Refer to the stacks thru separate pointers, to allow yyoverflow
  1365. to reallocate them elsewhere. */
  1366. /* The state stack. */
  1367. yytype_int16 yyssa[YYINITDEPTH];
  1368. yytype_int16 *yyss = yyssa;
  1369. yytype_int16 *yyssp;
  1370. /* The semantic value stack. */
  1371. YYSTYPE yyvsa[YYINITDEPTH];
  1372. YYSTYPE *yyvs = yyvsa;
  1373. YYSTYPE *yyvsp;
  1374. /* The location stack. */
  1375. YYLTYPE yylsa[YYINITDEPTH];
  1376. YYLTYPE *yyls = yylsa;
  1377. YYLTYPE *yylsp;
  1378. /* The locations where the error started and ended. */
  1379. YYLTYPE yyerror_range[2];
  1380. #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
  1381. YYSIZE_T yystacksize = YYINITDEPTH;
  1382. /* The variables used to return semantic value and location from the
  1383. action routines. */
  1384. YYSTYPE yyval;
  1385. YYLTYPE yyloc;
  1386. /* The number of symbols on the RHS of the reduced rule.
  1387. Keep to zero when no symbol should be popped. */
  1388. int yylen = 0;
  1389. YYDPRINTF ((stderr, "Starting parse\n"));
  1390. yystate = 0;
  1391. yyerrstatus = 0;
  1392. yynerrs = 0;
  1393. yychar = YYEMPTY; /* Cause a token to be read. */
  1394. /* Initialize stack pointers.
  1395. Waste one element of value and location stack
  1396. so that they stay on the same level as the state stack.
  1397. The wasted elements are never initialized. */
  1398. yyssp = yyss;
  1399. yyvsp = yyvs;
  1400. yylsp = yyls;
  1401. #if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
  1402. /* Initialize the default location before parsing starts. */
  1403. yylloc.first_line = yylloc.last_line = 1;
  1404. yylloc.first_column = yylloc.last_column = 0;
  1405. #endif
  1406. /* User initialization code. */
  1407. #line 148 "src/glsl/glcpp/glcpp-parse.y"
  1408. {
  1409. yylloc.first_line = 1;
  1410. yylloc.first_column = 1;
  1411. yylloc.last_line = 1;
  1412. yylloc.last_column = 1;
  1413. yylloc.source = 0;
  1414. }
  1415. /* Line 1078 of yacc.c. */
  1416. #line 1623 "src/glsl/glcpp/glcpp-parse.c"
  1417. yylsp[0] = yylloc;
  1418. goto yysetstate;
  1419. /*------------------------------------------------------------.
  1420. | yynewstate -- Push a new state, which is found in yystate. |
  1421. `------------------------------------------------------------*/
  1422. yynewstate:
  1423. /* In all cases, when you get here, the value and location stacks
  1424. have just been pushed. So pushing a state here evens the stacks. */
  1425. yyssp++;
  1426. yysetstate:
  1427. *yyssp = yystate;
  1428. if (yyss + yystacksize - 1 <= yyssp)
  1429. {
  1430. /* Get the current used size of the three stacks, in elements. */
  1431. YYSIZE_T yysize = yyssp - yyss + 1;
  1432. #ifdef yyoverflow
  1433. {
  1434. /* Give user a chance to reallocate the stack. Use copies of
  1435. these so that the &'s don't force the real ones into
  1436. memory. */
  1437. YYSTYPE *yyvs1 = yyvs;
  1438. yytype_int16 *yyss1 = yyss;
  1439. YYLTYPE *yyls1 = yyls;
  1440. /* Each stack pointer address is followed by the size of the
  1441. data in use in that stack, in bytes. This used to be a
  1442. conditional around just the two extra args, but that might
  1443. be undefined if yyoverflow is a macro. */
  1444. yyoverflow (YY_("memory exhausted"),
  1445. &yyss1, yysize * sizeof (*yyssp),
  1446. &yyvs1, yysize * sizeof (*yyvsp),
  1447. &yyls1, yysize * sizeof (*yylsp),
  1448. &yystacksize);
  1449. yyls = yyls1;
  1450. yyss = yyss1;
  1451. yyvs = yyvs1;
  1452. }
  1453. #else /* no yyoverflow */
  1454. # ifndef YYSTACK_RELOCATE
  1455. goto yyexhaustedlab;
  1456. # else
  1457. /* Extend the stack our own way. */
  1458. if (YYMAXDEPTH <= yystacksize)
  1459. goto yyexhaustedlab;
  1460. yystacksize *= 2;
  1461. if (YYMAXDEPTH < yystacksize)
  1462. yystacksize = YYMAXDEPTH;
  1463. {
  1464. yytype_int16 *yyss1 = yyss;
  1465. union yyalloc *yyptr =
  1466. (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
  1467. if (! yyptr)
  1468. goto yyexhaustedlab;
  1469. YYSTACK_RELOCATE (yyss);
  1470. YYSTACK_RELOCATE (yyvs);
  1471. YYSTACK_RELOCATE (yyls);
  1472. # undef YYSTACK_RELOCATE
  1473. if (yyss1 != yyssa)
  1474. YYSTACK_FREE (yyss1);
  1475. }
  1476. # endif
  1477. #endif /* no yyoverflow */
  1478. yyssp = yyss + yysize - 1;
  1479. yyvsp = yyvs + yysize - 1;
  1480. yylsp = yyls + yysize - 1;
  1481. YYDPRINTF ((stderr, "Stack size increased to %lu\n",
  1482. (unsigned long int) yystacksize));
  1483. if (yyss + yystacksize - 1 <= yyssp)
  1484. YYABORT;
  1485. }
  1486. YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  1487. goto yybackup;
  1488. /*-----------.
  1489. | yybackup. |
  1490. `-----------*/
  1491. yybackup:
  1492. /* Do appropriate processing given the current state. Read a
  1493. look-ahead token if we need one and don't already have one. */
  1494. /* First try to decide what to do without reference to look-ahead token. */
  1495. yyn = yypact[yystate];
  1496. if (yyn == YYPACT_NINF)
  1497. goto yydefault;
  1498. /* Not known => get a look-ahead token if don't already have one. */
  1499. /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
  1500. if (yychar == YYEMPTY)
  1501. {
  1502. YYDPRINTF ((stderr, "Reading a token: "));
  1503. yychar = YYLEX;
  1504. }
  1505. if (yychar <= YYEOF)
  1506. {
  1507. yychar = yytoken = YYEOF;
  1508. YYDPRINTF ((stderr, "Now at end of input.\n"));
  1509. }
  1510. else
  1511. {
  1512. yytoken = YYTRANSLATE (yychar);
  1513. YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
  1514. }
  1515. /* If the proper action on seeing token YYTOKEN is to reduce or to
  1516. detect an error, take that action. */
  1517. yyn += yytoken;
  1518. if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
  1519. goto yydefault;
  1520. yyn = yytable[yyn];
  1521. if (yyn <= 0)
  1522. {
  1523. if (yyn == 0 || yyn == YYTABLE_NINF)
  1524. goto yyerrlab;
  1525. yyn = -yyn;
  1526. goto yyreduce;
  1527. }
  1528. if (yyn == YYFINAL)
  1529. YYACCEPT;
  1530. /* Count tokens shifted since error; after three, turn off error
  1531. status. */
  1532. if (yyerrstatus)
  1533. yyerrstatus--;
  1534. /* Shift the look-ahead token. */
  1535. YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  1536. /* Discard the shifted token unless it is eof. */
  1537. if (yychar != YYEOF)
  1538. yychar = YYEMPTY;
  1539. yystate = yyn;
  1540. *++yyvsp = yylval;
  1541. *++yylsp = yylloc;
  1542. goto yynewstate;
  1543. /*-----------------------------------------------------------.
  1544. | yydefault -- do the default action for the current state. |
  1545. `-----------------------------------------------------------*/
  1546. yydefault:
  1547. yyn = yydefact[yystate];
  1548. if (yyn == 0)
  1549. goto yyerrlab;
  1550. goto yyreduce;
  1551. /*-----------------------------.
  1552. | yyreduce -- Do a reduction. |
  1553. `-----------------------------*/
  1554. yyreduce:
  1555. /* yyn is the number of a rule to reduce with. */
  1556. yylen = yyr2[yyn];
  1557. /* If YYLEN is nonzero, implement the default value of the action:
  1558. `$$ = $1'.
  1559. Otherwise, the following line sets YYVAL to garbage.
  1560. This behavior is undocumented and Bison
  1561. users should not rely upon it. Assigning to YYVAL
  1562. unconditionally makes the parser a bit smaller, and it avoids a
  1563. GCC warning that YYVAL may be used uninitialized. */
  1564. yyval = yyvsp[1-yylen];
  1565. /* Default location. */
  1566. YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
  1567. YY_REDUCE_PRINT (yyn);
  1568. switch (yyn)
  1569. {
  1570. case 4:
  1571. #line 187 "src/glsl/glcpp/glcpp-parse.y"
  1572. {
  1573. ralloc_strcat (&parser->output, "\n");
  1574. ;}
  1575. break;
  1576. case 5:
  1577. #line 190 "src/glsl/glcpp/glcpp-parse.y"
  1578. {
  1579. _glcpp_parser_print_expanded_token_list (parser, (yyvsp[(1) - (1)].token_list));
  1580. ralloc_strcat (&parser->output, "\n");
  1581. ralloc_free ((yyvsp[(1) - (1)].token_list));
  1582. ;}
  1583. break;
  1584. case 8:
  1585. #line 200 "src/glsl/glcpp/glcpp-parse.y"
  1586. {
  1587. _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), (yyvsp[(2) - (3)].ival));
  1588. ;}
  1589. break;
  1590. case 9:
  1591. #line 203 "src/glsl/glcpp/glcpp-parse.y"
  1592. {
  1593. _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]), "elif", (yyvsp[(2) - (3)].ival));
  1594. ;}
  1595. break;
  1596. case 10:
  1597. #line 209 "src/glsl/glcpp/glcpp-parse.y"
  1598. {
  1599. _define_object_macro (parser, & (yylsp[(2) - (4)]), (yyvsp[(2) - (4)].str), (yyvsp[(3) - (4)].token_list));
  1600. ;}
  1601. break;
  1602. case 11:
  1603. #line 212 "src/glsl/glcpp/glcpp-parse.y"
  1604. {
  1605. _define_function_macro (parser, & (yylsp[(2) - (6)]), (yyvsp[(2) - (6)].str), NULL, (yyvsp[(5) - (6)].token_list));
  1606. ;}
  1607. break;
  1608. case 12:
  1609. #line 215 "src/glsl/glcpp/glcpp-parse.y"
  1610. {
  1611. _define_function_macro (parser, & (yylsp[(2) - (7)]), (yyvsp[(2) - (7)].str), (yyvsp[(4) - (7)].string_list), (yyvsp[(6) - (7)].token_list));
  1612. ;}
  1613. break;
  1614. case 13:
  1615. #line 218 "src/glsl/glcpp/glcpp-parse.y"
  1616. {
  1617. macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (3)].str));
  1618. if (macro) {
  1619. hash_table_remove (parser->defines, (yyvsp[(2) - (3)].str));
  1620. ralloc_free (macro);
  1621. }
  1622. ralloc_free ((yyvsp[(2) - (3)].str));
  1623. ;}
  1624. break;
  1625. case 14:
  1626. #line 226 "src/glsl/glcpp/glcpp-parse.y"
  1627. {
  1628. /* Be careful to only evaluate the 'if' expression if
  1629. * we are not skipping. When we are skipping, we
  1630. * simply push a new 0-valued 'if' onto the skip
  1631. * stack.
  1632. *
  1633. * This avoids generating diagnostics for invalid
  1634. * expressions that are being skipped. */
  1635. if (parser->skip_stack == NULL ||
  1636. parser->skip_stack->type == SKIP_NO_SKIP)
  1637. {
  1638. _glcpp_parser_expand_if (parser, IF_EXPANDED, (yyvsp[(2) - (3)].token_list));
  1639. }
  1640. else
  1641. {
  1642. _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (3)]), 0);
  1643. parser->skip_stack->type = SKIP_TO_ENDIF;
  1644. }
  1645. ;}
  1646. break;
  1647. case 15:
  1648. #line 245 "src/glsl/glcpp/glcpp-parse.y"
  1649. {
  1650. /* #if without an expression is only an error if we
  1651. * are not skipping */
  1652. if (parser->skip_stack == NULL ||
  1653. parser->skip_stack->type == SKIP_NO_SKIP)
  1654. {
  1655. glcpp_error(& (yylsp[(1) - (2)]), parser, "#if with no expression");
  1656. }
  1657. _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (2)]), 0);
  1658. ;}
  1659. break;
  1660. case 16:
  1661. #line 255 "src/glsl/glcpp/glcpp-parse.y"
  1662. {
  1663. macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
  1664. ralloc_free ((yyvsp[(2) - (4)].str));
  1665. _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro != NULL);
  1666. ;}
  1667. break;
  1668. case 17:
  1669. #line 260 "src/glsl/glcpp/glcpp-parse.y"
  1670. {
  1671. macro_t *macro = hash_table_find (parser->defines, (yyvsp[(2) - (4)].str));
  1672. ralloc_free ((yyvsp[(2) - (4)].str));
  1673. _glcpp_parser_skip_stack_push_if (parser, & (yylsp[(1) - (4)]), macro == NULL);
  1674. ;}
  1675. break;
  1676. case 18:
  1677. #line 265 "src/glsl/glcpp/glcpp-parse.y"
  1678. {
  1679. /* Be careful to only evaluate the 'elif' expression
  1680. * if we are not skipping. When we are skipping, we
  1681. * simply change to a 0-valued 'elif' on the skip
  1682. * stack.
  1683. *
  1684. * This avoids generating diagnostics for invalid
  1685. * expressions that are being skipped. */
  1686. if (parser->skip_stack &&
  1687. parser->skip_stack->type == SKIP_TO_ELSE)
  1688. {
  1689. _glcpp_parser_expand_if (parser, ELIF_EXPANDED, (yyvsp[(2) - (3)].token_list));
  1690. }
  1691. else
  1692. {
  1693. _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (3)]),
  1694. "elif", 0);
  1695. }
  1696. ;}
  1697. break;
  1698. case 19:
  1699. #line 284 "src/glsl/glcpp/glcpp-parse.y"
  1700. {
  1701. /* #elif without an expression is an error unless we
  1702. * are skipping. */
  1703. if (parser->skip_stack &&
  1704. parser->skip_stack->type == SKIP_TO_ELSE)
  1705. {
  1706. glcpp_error(& (yylsp[(1) - (2)]), parser, "#elif with no expression");
  1707. }
  1708. else
  1709. {
  1710. _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]),
  1711. "elif", 0);
  1712. glcpp_warning(& (yylsp[(1) - (2)]), parser, "ignoring illegal #elif without expression");
  1713. }
  1714. ;}
  1715. break;
  1716. case 20:
  1717. #line 299 "src/glsl/glcpp/glcpp-parse.y"
  1718. {
  1719. _glcpp_parser_skip_stack_change_if (parser, & (yylsp[(1) - (2)]), "else", 1);
  1720. ;}
  1721. break;
  1722. case 21:
  1723. #line 302 "src/glsl/glcpp/glcpp-parse.y"
  1724. {
  1725. _glcpp_parser_skip_stack_pop (parser, & (yylsp[(1) - (2)]));
  1726. ;}
  1727. break;
  1728. case 22:
  1729. #line 305 "src/glsl/glcpp/glcpp-parse.y"
  1730. {
  1731. macro_t *macro = hash_table_find (parser->defines, "__VERSION__");
  1732. if (macro) {
  1733. hash_table_remove (parser->defines, "__VERSION__");
  1734. ralloc_free (macro);
  1735. }
  1736. add_builtin_define (parser, "__VERSION__", (yyvsp[(2) - (3)].ival));
  1737. if ((yyvsp[(2) - (3)].ival) == 100)
  1738. add_builtin_define (parser, "GL_ES", 1);
  1739. /* Currently, all ES2 implementations support highp in the
  1740. * fragment shader, so we always define this macro in ES2.
  1741. * If we ever get a driver that doesn't support highp, we'll
  1742. * need to add a flag to the gl_context and check that here.
  1743. */
  1744. if ((yyvsp[(2) - (3)].ival) >= 130 || (yyvsp[(2) - (3)].ival) == 100)
  1745. add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1);
  1746. ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, (yyvsp[(2) - (3)].ival));
  1747. ;}
  1748. break;
  1749. case 24:
  1750. #line 330 "src/glsl/glcpp/glcpp-parse.y"
  1751. {
  1752. if (strlen ((yyvsp[(1) - (1)].str)) >= 3 && strncmp ((yyvsp[(1) - (1)].str), "0x", 2) == 0) {
  1753. (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str) + 2, NULL, 16);
  1754. } else if ((yyvsp[(1) - (1)].str)[0] == '0') {
  1755. (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 8);
  1756. } else {
  1757. (yyval.ival) = strtoll ((yyvsp[(1) - (1)].str), NULL, 10);
  1758. }
  1759. ;}
  1760. break;
  1761. case 25:
  1762. #line 339 "src/glsl/glcpp/glcpp-parse.y"
  1763. {
  1764. (yyval.ival) = (yyvsp[(1) - (1)].ival);
  1765. ;}
  1766. break;
  1767. case 27:
  1768. #line 345 "src/glsl/glcpp/glcpp-parse.y"
  1769. {
  1770. (yyval.ival) = (yyvsp[(1) - (3)].ival) || (yyvsp[(3) - (3)].ival);
  1771. ;}
  1772. break;
  1773. case 28:
  1774. #line 348 "src/glsl/glcpp/glcpp-parse.y"
  1775. {
  1776. (yyval.ival) = (yyvsp[(1) - (3)].ival) && (yyvsp[(3) - (3)].ival);
  1777. ;}
  1778. break;
  1779. case 29:
  1780. #line 351 "src/glsl/glcpp/glcpp-parse.y"
  1781. {
  1782. (yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival);
  1783. ;}
  1784. break;
  1785. case 30:
  1786. #line 354 "src/glsl/glcpp/glcpp-parse.y"
  1787. {
  1788. (yyval.ival) = (yyvsp[(1) - (3)].ival) ^ (yyvsp[(3) - (3)].ival);
  1789. ;}
  1790. break;
  1791. case 31:
  1792. #line 357 "src/glsl/glcpp/glcpp-parse.y"
  1793. {
  1794. (yyval.ival) = (yyvsp[(1) - (3)].ival) & (yyvsp[(3) - (3)].ival);
  1795. ;}
  1796. break;
  1797. case 32:
  1798. #line 360 "src/glsl/glcpp/glcpp-parse.y"
  1799. {
  1800. (yyval.ival) = (yyvsp[(1) - (3)].ival) != (yyvsp[(3) - (3)].ival);
  1801. ;}
  1802. break;
  1803. case 33:
  1804. #line 363 "src/glsl/glcpp/glcpp-parse.y"
  1805. {
  1806. (yyval.ival) = (yyvsp[(1) - (3)].ival) == (yyvsp[(3) - (3)].ival);
  1807. ;}
  1808. break;
  1809. case 34:
  1810. #line 366 "src/glsl/glcpp/glcpp-parse.y"
  1811. {
  1812. (yyval.ival) = (yyvsp[(1) - (3)].ival) >= (yyvsp[(3) - (3)].ival);
  1813. ;}
  1814. break;
  1815. case 35:
  1816. #line 369 "src/glsl/glcpp/glcpp-parse.y"
  1817. {
  1818. (yyval.ival) = (yyvsp[(1) - (3)].ival) <= (yyvsp[(3) - (3)].ival);
  1819. ;}
  1820. break;
  1821. case 36:
  1822. #line 372 "src/glsl/glcpp/glcpp-parse.y"
  1823. {
  1824. (yyval.ival) = (yyvsp[(1) - (3)].ival) > (yyvsp[(3) - (3)].ival);
  1825. ;}
  1826. break;
  1827. case 37:
  1828. #line 375 "src/glsl/glcpp/glcpp-parse.y"
  1829. {
  1830. (yyval.ival) = (yyvsp[(1) - (3)].ival) < (yyvsp[(3) - (3)].ival);
  1831. ;}
  1832. break;
  1833. case 38:
  1834. #line 378 "src/glsl/glcpp/glcpp-parse.y"
  1835. {
  1836. (yyval.ival) = (yyvsp[(1) - (3)].ival) >> (yyvsp[(3) - (3)].ival);
  1837. ;}
  1838. break;
  1839. case 39:
  1840. #line 381 "src/glsl/glcpp/glcpp-parse.y"
  1841. {
  1842. (yyval.ival) = (yyvsp[(1) - (3)].ival) << (yyvsp[(3) - (3)].ival);
  1843. ;}
  1844. break;
  1845. case 40:
  1846. #line 384 "src/glsl/glcpp/glcpp-parse.y"
  1847. {
  1848. (yyval.ival) = (yyvsp[(1) - (3)].ival) - (yyvsp[(3) - (3)].ival);
  1849. ;}
  1850. break;
  1851. case 41:
  1852. #line 387 "src/glsl/glcpp/glcpp-parse.y"
  1853. {
  1854. (yyval.ival) = (yyvsp[(1) - (3)].ival) + (yyvsp[(3) - (3)].ival);
  1855. ;}
  1856. break;
  1857. case 42:
  1858. #line 390 "src/glsl/glcpp/glcpp-parse.y"
  1859. {
  1860. if ((yyvsp[(3) - (3)].ival) == 0) {
  1861. yyerror (& (yylsp[(1) - (3)]), parser,
  1862. "zero modulus in preprocessor directive");
  1863. } else {
  1864. (yyval.ival) = (yyvsp[(1) - (3)].ival) % (yyvsp[(3) - (3)].ival);
  1865. }
  1866. ;}
  1867. break;
  1868. case 43:
  1869. #line 398 "src/glsl/glcpp/glcpp-parse.y"
  1870. {
  1871. if ((yyvsp[(3) - (3)].ival) == 0) {
  1872. yyerror (& (yylsp[(1) - (3)]), parser,
  1873. "division by 0 in preprocessor directive");
  1874. } else {
  1875. (yyval.ival) = (yyvsp[(1) - (3)].ival) / (yyvsp[(3) - (3)].ival);
  1876. }
  1877. ;}
  1878. break;
  1879. case 44:
  1880. #line 406 "src/glsl/glcpp/glcpp-parse.y"
  1881. {
  1882. (yyval.ival) = (yyvsp[(1) - (3)].ival) * (yyvsp[(3) - (3)].ival);
  1883. ;}
  1884. break;
  1885. case 45:
  1886. #line 409 "src/glsl/glcpp/glcpp-parse.y"
  1887. {
  1888. (yyval.ival) = ! (yyvsp[(2) - (2)].ival);
  1889. ;}
  1890. break;
  1891. case 46:
  1892. #line 412 "src/glsl/glcpp/glcpp-parse.y"
  1893. {
  1894. (yyval.ival) = ~ (yyvsp[(2) - (2)].ival);
  1895. ;}
  1896. break;
  1897. case 47:
  1898. #line 415 "src/glsl/glcpp/glcpp-parse.y"
  1899. {
  1900. (yyval.ival) = - (yyvsp[(2) - (2)].ival);
  1901. ;}
  1902. break;
  1903. case 48:
  1904. #line 418 "src/glsl/glcpp/glcpp-parse.y"
  1905. {
  1906. (yyval.ival) = + (yyvsp[(2) - (2)].ival);
  1907. ;}
  1908. break;
  1909. case 49:
  1910. #line 421 "src/glsl/glcpp/glcpp-parse.y"
  1911. {
  1912. (yyval.ival) = (yyvsp[(2) - (3)].ival);
  1913. ;}
  1914. break;
  1915. case 50:
  1916. #line 427 "src/glsl/glcpp/glcpp-parse.y"
  1917. {
  1918. (yyval.string_list) = _string_list_create (parser);
  1919. _string_list_append_item ((yyval.string_list), (yyvsp[(1) - (1)].str));
  1920. ralloc_steal ((yyval.string_list), (yyvsp[(1) - (1)].str));
  1921. ;}
  1922. break;
  1923. case 51:
  1924. #line 432 "src/glsl/glcpp/glcpp-parse.y"
  1925. {
  1926. (yyval.string_list) = (yyvsp[(1) - (3)].string_list);
  1927. _string_list_append_item ((yyval.string_list), (yyvsp[(3) - (3)].str));
  1928. ralloc_steal ((yyval.string_list), (yyvsp[(3) - (3)].str));
  1929. ;}
  1930. break;
  1931. case 52:
  1932. #line 440 "src/glsl/glcpp/glcpp-parse.y"
  1933. { (yyval.token_list) = NULL; ;}
  1934. break;
  1935. case 54:
  1936. #line 445 "src/glsl/glcpp/glcpp-parse.y"
  1937. {
  1938. yyerror (& (yylsp[(1) - (2)]), parser, "Invalid tokens after #");
  1939. ;}
  1940. break;
  1941. case 55:
  1942. #line 451 "src/glsl/glcpp/glcpp-parse.y"
  1943. { (yyval.token_list) = NULL; ;}
  1944. break;
  1945. case 58:
  1946. #line 457 "src/glsl/glcpp/glcpp-parse.y"
  1947. {
  1948. glcpp_warning(&(yylsp[(1) - (1)]), parser, "extra tokens at end of directive");
  1949. ;}
  1950. break;
  1951. case 59:
  1952. #line 464 "src/glsl/glcpp/glcpp-parse.y"
  1953. {
  1954. int v = hash_table_find (parser->defines, (yyvsp[(2) - (2)].str)) ? 1 : 0;
  1955. (yyval.token) = _token_create_ival (parser, INTEGER, v);
  1956. ;}
  1957. break;
  1958. case 60:
  1959. #line 468 "src/glsl/glcpp/glcpp-parse.y"
  1960. {
  1961. int v = hash_table_find (parser->defines, (yyvsp[(3) - (4)].str)) ? 1 : 0;
  1962. (yyval.token) = _token_create_ival (parser, INTEGER, v);
  1963. ;}
  1964. break;
  1965. case 62:
  1966. #line 477 "src/glsl/glcpp/glcpp-parse.y"
  1967. {
  1968. (yyval.token_list) = _token_list_create (parser);
  1969. _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
  1970. ;}
  1971. break;
  1972. case 63:
  1973. #line 481 "src/glsl/glcpp/glcpp-parse.y"
  1974. {
  1975. (yyval.token_list) = (yyvsp[(1) - (2)].token_list);
  1976. _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
  1977. ;}
  1978. break;
  1979. case 64:
  1980. #line 488 "src/glsl/glcpp/glcpp-parse.y"
  1981. {
  1982. parser->space_tokens = 1;
  1983. (yyval.token_list) = _token_list_create (parser);
  1984. _token_list_append ((yyval.token_list), (yyvsp[(1) - (1)].token));
  1985. ;}
  1986. break;
  1987. case 65:
  1988. #line 493 "src/glsl/glcpp/glcpp-parse.y"
  1989. {
  1990. (yyval.token_list) = (yyvsp[(1) - (2)].token_list);
  1991. _token_list_append ((yyval.token_list), (yyvsp[(2) - (2)].token));
  1992. ;}
  1993. break;
  1994. case 66:
  1995. #line 500 "src/glsl/glcpp/glcpp-parse.y"
  1996. {
  1997. (yyval.token) = _token_create_str (parser, IDENTIFIER, (yyvsp[(1) - (1)].str));
  1998. (yyval.token)->location = yylloc;
  1999. ;}
  2000. break;
  2001. case 67:
  2002. #line 504 "src/glsl/glcpp/glcpp-parse.y"
  2003. {
  2004. (yyval.token) = _token_create_str (parser, INTEGER_STRING, (yyvsp[(1) - (1)].str));
  2005. (yyval.token)->location = yylloc;
  2006. ;}
  2007. break;
  2008. case 68:
  2009. #line 508 "src/glsl/glcpp/glcpp-parse.y"
  2010. {
  2011. (yyval.token) = _token_create_ival (parser, (yyvsp[(1) - (1)].ival), (yyvsp[(1) - (1)].ival));
  2012. (yyval.token)->location = yylloc;
  2013. ;}
  2014. break;
  2015. case 69:
  2016. #line 512 "src/glsl/glcpp/glcpp-parse.y"
  2017. {
  2018. (yyval.token) = _token_create_str (parser, OTHER, (yyvsp[(1) - (1)].str));
  2019. (yyval.token)->location = yylloc;
  2020. ;}
  2021. break;
  2022. case 70:
  2023. #line 516 "src/glsl/glcpp/glcpp-parse.y"
  2024. {
  2025. (yyval.token) = _token_create_ival (parser, SPACE, SPACE);
  2026. (yyval.token)->location = yylloc;
  2027. ;}
  2028. break;
  2029. case 71:
  2030. #line 523 "src/glsl/glcpp/glcpp-parse.y"
  2031. { (yyval.ival) = '['; ;}
  2032. break;
  2033. case 72:
  2034. #line 524 "src/glsl/glcpp/glcpp-parse.y"
  2035. { (yyval.ival) = ']'; ;}
  2036. break;
  2037. case 73:
  2038. #line 525 "src/glsl/glcpp/glcpp-parse.y"
  2039. { (yyval.ival) = '('; ;}
  2040. break;
  2041. case 74:
  2042. #line 526 "src/glsl/glcpp/glcpp-parse.y"
  2043. { (yyval.ival) = ')'; ;}
  2044. break;
  2045. case 75:
  2046. #line 527 "src/glsl/glcpp/glcpp-parse.y"
  2047. { (yyval.ival) = '{'; ;}
  2048. break;
  2049. case 76:
  2050. #line 528 "src/glsl/glcpp/glcpp-parse.y"
  2051. { (yyval.ival) = '}'; ;}
  2052. break;
  2053. case 77:
  2054. #line 529 "src/glsl/glcpp/glcpp-parse.y"
  2055. { (yyval.ival) = '.'; ;}
  2056. break;
  2057. case 78:
  2058. #line 530 "src/glsl/glcpp/glcpp-parse.y"
  2059. { (yyval.ival) = '&'; ;}
  2060. break;
  2061. case 79:
  2062. #line 531 "src/glsl/glcpp/glcpp-parse.y"
  2063. { (yyval.ival) = '*'; ;}
  2064. break;
  2065. case 80:
  2066. #line 532 "src/glsl/glcpp/glcpp-parse.y"
  2067. { (yyval.ival) = '+'; ;}
  2068. break;
  2069. case 81:
  2070. #line 533 "src/glsl/glcpp/glcpp-parse.y"
  2071. { (yyval.ival) = '-'; ;}
  2072. break;
  2073. case 82:
  2074. #line 534 "src/glsl/glcpp/glcpp-parse.y"
  2075. { (yyval.ival) = '~'; ;}
  2076. break;
  2077. case 83:
  2078. #line 535 "src/glsl/glcpp/glcpp-parse.y"
  2079. { (yyval.ival) = '!'; ;}
  2080. break;
  2081. case 84:
  2082. #line 536 "src/glsl/glcpp/glcpp-parse.y"
  2083. { (yyval.ival) = '/'; ;}
  2084. break;
  2085. case 85:
  2086. #line 537 "src/glsl/glcpp/glcpp-parse.y"
  2087. { (yyval.ival) = '%'; ;}
  2088. break;
  2089. case 86:
  2090. #line 538 "src/glsl/glcpp/glcpp-parse.y"
  2091. { (yyval.ival) = LEFT_SHIFT; ;}
  2092. break;
  2093. case 87:
  2094. #line 539 "src/glsl/glcpp/glcpp-parse.y"
  2095. { (yyval.ival) = RIGHT_SHIFT; ;}
  2096. break;
  2097. case 88:
  2098. #line 540 "src/glsl/glcpp/glcpp-parse.y"
  2099. { (yyval.ival) = '<'; ;}
  2100. break;
  2101. case 89:
  2102. #line 541 "src/glsl/glcpp/glcpp-parse.y"
  2103. { (yyval.ival) = '>'; ;}
  2104. break;
  2105. case 90:
  2106. #line 542 "src/glsl/glcpp/glcpp-parse.y"
  2107. { (yyval.ival) = LESS_OR_EQUAL; ;}
  2108. break;
  2109. case 91:
  2110. #line 543 "src/glsl/glcpp/glcpp-parse.y"
  2111. { (yyval.ival) = GREATER_OR_EQUAL; ;}
  2112. break;
  2113. case 92:
  2114. #line 544 "src/glsl/glcpp/glcpp-parse.y"
  2115. { (yyval.ival) = EQUAL; ;}
  2116. break;
  2117. case 93:
  2118. #line 545 "src/glsl/glcpp/glcpp-parse.y"
  2119. { (yyval.ival) = NOT_EQUAL; ;}
  2120. break;
  2121. case 94:
  2122. #line 546 "src/glsl/glcpp/glcpp-parse.y"
  2123. { (yyval.ival) = '^'; ;}
  2124. break;
  2125. case 95:
  2126. #line 547 "src/glsl/glcpp/glcpp-parse.y"
  2127. { (yyval.ival) = '|'; ;}
  2128. break;
  2129. case 96:
  2130. #line 548 "src/glsl/glcpp/glcpp-parse.y"
  2131. { (yyval.ival) = AND; ;}
  2132. break;
  2133. case 97:
  2134. #line 549 "src/glsl/glcpp/glcpp-parse.y"
  2135. { (yyval.ival) = OR; ;}
  2136. break;
  2137. case 98:
  2138. #line 550 "src/glsl/glcpp/glcpp-parse.y"
  2139. { (yyval.ival) = ';'; ;}
  2140. break;
  2141. case 99:
  2142. #line 551 "src/glsl/glcpp/glcpp-parse.y"
  2143. { (yyval.ival) = ','; ;}
  2144. break;
  2145. case 100:
  2146. #line 552 "src/glsl/glcpp/glcpp-parse.y"
  2147. { (yyval.ival) = '='; ;}
  2148. break;
  2149. case 101:
  2150. #line 553 "src/glsl/glcpp/glcpp-parse.y"
  2151. { (yyval.ival) = PASTE; ;}
  2152. break;
  2153. /* Line 1267 of yacc.c. */
  2154. #line 2485 "src/glsl/glcpp/glcpp-parse.c"
  2155. default: break;
  2156. }
  2157. YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
  2158. YYPOPSTACK (yylen);
  2159. yylen = 0;
  2160. YY_STACK_PRINT (yyss, yyssp);
  2161. *++yyvsp = yyval;
  2162. *++yylsp = yyloc;
  2163. /* Now `shift' the result of the reduction. Determine what state
  2164. that goes to, based on the state we popped back to and the rule
  2165. number reduced by. */
  2166. yyn = yyr1[yyn];
  2167. yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  2168. if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  2169. yystate = yytable[yystate];
  2170. else
  2171. yystate = yydefgoto[yyn - YYNTOKENS];
  2172. goto yynewstate;
  2173. /*------------------------------------.
  2174. | yyerrlab -- here on detecting error |
  2175. `------------------------------------*/
  2176. yyerrlab:
  2177. /* If not already recovering from an error, report this error. */
  2178. if (!yyerrstatus)
  2179. {
  2180. ++yynerrs;
  2181. #if ! YYERROR_VERBOSE
  2182. yyerror (&yylloc, parser, YY_("syntax error"));
  2183. #else
  2184. {
  2185. YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
  2186. if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
  2187. {
  2188. YYSIZE_T yyalloc = 2 * yysize;
  2189. if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
  2190. yyalloc = YYSTACK_ALLOC_MAXIMUM;
  2191. if (yymsg != yymsgbuf)
  2192. YYSTACK_FREE (yymsg);
  2193. yymsg = (char *) YYSTACK_ALLOC (yyalloc);
  2194. if (yymsg)
  2195. yymsg_alloc = yyalloc;
  2196. else
  2197. {
  2198. yymsg = yymsgbuf;
  2199. yymsg_alloc = sizeof yymsgbuf;
  2200. }
  2201. }
  2202. if (0 < yysize && yysize <= yymsg_alloc)
  2203. {
  2204. (void) yysyntax_error (yymsg, yystate, yychar);
  2205. yyerror (&yylloc, parser, yymsg);
  2206. }
  2207. else
  2208. {
  2209. yyerror (&yylloc, parser, YY_("syntax error"));
  2210. if (yysize != 0)
  2211. goto yyexhaustedlab;
  2212. }
  2213. }
  2214. #endif
  2215. }
  2216. yyerror_range[0] = yylloc;
  2217. if (yyerrstatus == 3)
  2218. {
  2219. /* If just tried and failed to reuse look-ahead token after an
  2220. error, discard it. */
  2221. if (yychar <= YYEOF)
  2222. {
  2223. /* Return failure if at end of input. */
  2224. if (yychar == YYEOF)
  2225. YYABORT;
  2226. }
  2227. else
  2228. {
  2229. yydestruct ("Error: discarding",
  2230. yytoken, &yylval, &yylloc, parser);
  2231. yychar = YYEMPTY;
  2232. }
  2233. }
  2234. /* Else will try to reuse look-ahead token after shifting the error
  2235. token. */
  2236. goto yyerrlab1;
  2237. /*---------------------------------------------------.
  2238. | yyerrorlab -- error raised explicitly by YYERROR. |
  2239. `---------------------------------------------------*/
  2240. yyerrorlab:
  2241. /* Pacify compilers like GCC when the user code never invokes
  2242. YYERROR and the label yyerrorlab therefore never appears in user
  2243. code. */
  2244. if (/*CONSTCOND*/ 0)
  2245. goto yyerrorlab;
  2246. yyerror_range[0] = yylsp[1-yylen];
  2247. /* Do not reclaim the symbols of the rule which action triggered
  2248. this YYERROR. */
  2249. YYPOPSTACK (yylen);
  2250. yylen = 0;
  2251. YY_STACK_PRINT (yyss, yyssp);
  2252. yystate = *yyssp;
  2253. goto yyerrlab1;
  2254. /*-------------------------------------------------------------.
  2255. | yyerrlab1 -- common code for both syntax error and YYERROR. |
  2256. `-------------------------------------------------------------*/
  2257. yyerrlab1:
  2258. yyerrstatus = 3; /* Each real token shifted decrements this. */
  2259. for (;;)
  2260. {
  2261. yyn = yypact[yystate];
  2262. if (yyn != YYPACT_NINF)
  2263. {
  2264. yyn += YYTERROR;
  2265. if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
  2266. {
  2267. yyn = yytable[yyn];
  2268. if (0 < yyn)
  2269. break;
  2270. }
  2271. }
  2272. /* Pop the current state because it cannot handle the error token. */
  2273. if (yyssp == yyss)
  2274. YYABORT;
  2275. yyerror_range[0] = *yylsp;
  2276. yydestruct ("Error: popping",
  2277. yystos[yystate], yyvsp, yylsp, parser);
  2278. YYPOPSTACK (1);
  2279. yystate = *yyssp;
  2280. YY_STACK_PRINT (yyss, yyssp);
  2281. }
  2282. if (yyn == YYFINAL)
  2283. YYACCEPT;
  2284. *++yyvsp = yylval;
  2285. yyerror_range[1] = yylloc;
  2286. /* Using YYLLOC is tempting, but would change the location of
  2287. the look-ahead. YYLOC is available though. */
  2288. YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
  2289. *++yylsp = yyloc;
  2290. /* Shift the error token. */
  2291. YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
  2292. yystate = yyn;
  2293. goto yynewstate;
  2294. /*-------------------------------------.
  2295. | yyacceptlab -- YYACCEPT comes here. |
  2296. `-------------------------------------*/
  2297. yyacceptlab:
  2298. yyresult = 0;
  2299. goto yyreturn;
  2300. /*-----------------------------------.
  2301. | yyabortlab -- YYABORT comes here. |
  2302. `-----------------------------------*/
  2303. yyabortlab:
  2304. yyresult = 1;
  2305. goto yyreturn;
  2306. #ifndef yyoverflow
  2307. /*-------------------------------------------------.
  2308. | yyexhaustedlab -- memory exhaustion comes here. |
  2309. `-------------------------------------------------*/
  2310. yyexhaustedlab:
  2311. yyerror (&yylloc, parser, YY_("memory exhausted"));
  2312. yyresult = 2;
  2313. /* Fall through. */
  2314. #endif
  2315. yyreturn:
  2316. if (yychar != YYEOF && yychar != YYEMPTY)
  2317. yydestruct ("Cleanup: discarding lookahead",
  2318. yytoken, &yylval, &yylloc, parser);
  2319. /* Do not reclaim the symbols of the rule which action triggered
  2320. this YYABORT or YYACCEPT. */
  2321. YYPOPSTACK (yylen);
  2322. YY_STACK_PRINT (yyss, yyssp);
  2323. while (yyssp != yyss)
  2324. {
  2325. yydestruct ("Cleanup: popping",
  2326. yystos[*yyssp], yyvsp, yylsp, parser);
  2327. YYPOPSTACK (1);
  2328. }
  2329. #ifndef yyoverflow
  2330. if (yyss != yyssa)
  2331. YYSTACK_FREE (yyss);
  2332. #endif
  2333. #if YYERROR_VERBOSE
  2334. if (yymsg != yymsgbuf)
  2335. YYSTACK_FREE (yymsg);
  2336. #endif
  2337. /* Make sure YYID is used. */
  2338. return YYID (yyresult);
  2339. }
  2340. #line 556 "src/glsl/glcpp/glcpp-parse.y"
  2341. string_list_t *
  2342. _string_list_create (void *ctx)
  2343. {
  2344. string_list_t *list;
  2345. list = ralloc (ctx, string_list_t);
  2346. list->head = NULL;
  2347. list->tail = NULL;
  2348. return list;
  2349. }
  2350. void
  2351. _string_list_append_item (string_list_t *list, const char *str)
  2352. {
  2353. string_node_t *node;
  2354. node = ralloc (list, string_node_t);
  2355. node->str = ralloc_strdup (node, str);
  2356. node->next = NULL;
  2357. if (list->head == NULL) {
  2358. list->head = node;
  2359. } else {
  2360. list->tail->next = node;
  2361. }
  2362. list->tail = node;
  2363. }
  2364. int
  2365. _string_list_contains (string_list_t *list, const char *member, int *index)
  2366. {
  2367. string_node_t *node;
  2368. int i;
  2369. if (list == NULL)
  2370. return 0;
  2371. for (i = 0, node = list->head; node; i++, node = node->next) {
  2372. if (strcmp (node->str, member) == 0) {
  2373. if (index)
  2374. *index = i;
  2375. return 1;
  2376. }
  2377. }
  2378. return 0;
  2379. }
  2380. int
  2381. _string_list_length (string_list_t *list)
  2382. {
  2383. int length = 0;
  2384. string_node_t *node;
  2385. if (list == NULL)
  2386. return 0;
  2387. for (node = list->head; node; node = node->next)
  2388. length++;
  2389. return length;
  2390. }
  2391. int
  2392. _string_list_equal (string_list_t *a, string_list_t *b)
  2393. {
  2394. string_node_t *node_a, *node_b;
  2395. if (a == NULL && b == NULL)
  2396. return 1;
  2397. if (a == NULL || b == NULL)
  2398. return 0;
  2399. for (node_a = a->head, node_b = b->head;
  2400. node_a && node_b;
  2401. node_a = node_a->next, node_b = node_b->next)
  2402. {
  2403. if (strcmp (node_a->str, node_b->str))
  2404. return 0;
  2405. }
  2406. /* Catch the case of lists being different lengths, (which
  2407. * would cause the loop above to terminate after the shorter
  2408. * list). */
  2409. return node_a == node_b;
  2410. }
  2411. argument_list_t *
  2412. _argument_list_create (void *ctx)
  2413. {
  2414. argument_list_t *list;
  2415. list = ralloc (ctx, argument_list_t);
  2416. list->head = NULL;
  2417. list->tail = NULL;
  2418. return list;
  2419. }
  2420. void
  2421. _argument_list_append (argument_list_t *list, token_list_t *argument)
  2422. {
  2423. argument_node_t *node;
  2424. node = ralloc (list, argument_node_t);
  2425. node->argument = argument;
  2426. node->next = NULL;
  2427. if (list->head == NULL) {
  2428. list->head = node;
  2429. } else {
  2430. list->tail->next = node;
  2431. }
  2432. list->tail = node;
  2433. }
  2434. int
  2435. _argument_list_length (argument_list_t *list)
  2436. {
  2437. int length = 0;
  2438. argument_node_t *node;
  2439. if (list == NULL)
  2440. return 0;
  2441. for (node = list->head; node; node = node->next)
  2442. length++;
  2443. return length;
  2444. }
  2445. token_list_t *
  2446. _argument_list_member_at (argument_list_t *list, int index)
  2447. {
  2448. argument_node_t *node;
  2449. int i;
  2450. if (list == NULL)
  2451. return NULL;
  2452. node = list->head;
  2453. for (i = 0; i < index; i++) {
  2454. node = node->next;
  2455. if (node == NULL)
  2456. break;
  2457. }
  2458. if (node)
  2459. return node->argument;
  2460. return NULL;
  2461. }
  2462. /* Note: This function ralloc_steal()s the str pointer. */
  2463. token_t *
  2464. _token_create_str (void *ctx, int type, char *str)
  2465. {
  2466. token_t *token;
  2467. token = ralloc (ctx, token_t);
  2468. token->type = type;
  2469. token->value.str = str;
  2470. ralloc_steal (token, str);
  2471. return token;
  2472. }
  2473. token_t *
  2474. _token_create_ival (void *ctx, int type, int ival)
  2475. {
  2476. token_t *token;
  2477. token = ralloc (ctx, token_t);
  2478. token->type = type;
  2479. token->value.ival = ival;
  2480. return token;
  2481. }
  2482. token_list_t *
  2483. _token_list_create (void *ctx)
  2484. {
  2485. token_list_t *list;
  2486. list = ralloc (ctx, token_list_t);
  2487. list->head = NULL;
  2488. list->tail = NULL;
  2489. list->non_space_tail = NULL;
  2490. return list;
  2491. }
  2492. void
  2493. _token_list_append (token_list_t *list, token_t *token)
  2494. {
  2495. token_node_t *node;
  2496. node = ralloc (list, token_node_t);
  2497. node->token = token;
  2498. node->next = NULL;
  2499. ralloc_steal (list, token);
  2500. if (list->head == NULL) {
  2501. list->head = node;
  2502. } else {
  2503. list->tail->next = node;
  2504. }
  2505. list->tail = node;
  2506. if (token->type != SPACE)
  2507. list->non_space_tail = node;
  2508. }
  2509. void
  2510. _token_list_append_list (token_list_t *list, token_list_t *tail)
  2511. {
  2512. if (tail == NULL || tail->head == NULL)
  2513. return;
  2514. if (list->head == NULL) {
  2515. list->head = tail->head;
  2516. } else {
  2517. list->tail->next = tail->head;
  2518. }
  2519. list->tail = tail->tail;
  2520. list->non_space_tail = tail->non_space_tail;
  2521. }
  2522. static token_list_t *
  2523. _token_list_copy (void *ctx, token_list_t *other)
  2524. {
  2525. token_list_t *copy;
  2526. token_node_t *node;
  2527. if (other == NULL)
  2528. return NULL;
  2529. copy = _token_list_create (ctx);
  2530. for (node = other->head; node; node = node->next) {
  2531. token_t *new_token = ralloc (copy, token_t);
  2532. *new_token = *node->token;
  2533. _token_list_append (copy, new_token);
  2534. }
  2535. return copy;
  2536. }
  2537. static void
  2538. _token_list_trim_trailing_space (token_list_t *list)
  2539. {
  2540. token_node_t *tail, *next;
  2541. if (list->non_space_tail) {
  2542. tail = list->non_space_tail->next;
  2543. list->non_space_tail->next = NULL;
  2544. list->tail = list->non_space_tail;
  2545. while (tail) {
  2546. next = tail->next;
  2547. ralloc_free (tail);
  2548. tail = next;
  2549. }
  2550. }
  2551. }
  2552. static int
  2553. _token_list_is_empty_ignoring_space (token_list_t *l)
  2554. {
  2555. token_node_t *n;
  2556. if (l == NULL)
  2557. return 1;
  2558. n = l->head;
  2559. while (n != NULL && n->token->type == SPACE)
  2560. n = n->next;
  2561. return n == NULL;
  2562. }
  2563. int
  2564. _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
  2565. {
  2566. token_node_t *node_a, *node_b;
  2567. if (a == NULL || b == NULL) {
  2568. int a_empty = _token_list_is_empty_ignoring_space(a);
  2569. int b_empty = _token_list_is_empty_ignoring_space(b);
  2570. return a_empty == b_empty;
  2571. }
  2572. node_a = a->head;
  2573. node_b = b->head;
  2574. while (1)
  2575. {
  2576. if (node_a == NULL && node_b == NULL)
  2577. break;
  2578. if (node_a == NULL || node_b == NULL)
  2579. return 0;
  2580. if (node_a->token->type == SPACE) {
  2581. node_a = node_a->next;
  2582. continue;
  2583. }
  2584. if (node_b->token->type == SPACE) {
  2585. node_b = node_b->next;
  2586. continue;
  2587. }
  2588. if (node_a->token->type != node_b->token->type)
  2589. return 0;
  2590. switch (node_a->token->type) {
  2591. case INTEGER:
  2592. if (node_a->token->value.ival !=
  2593. node_b->token->value.ival)
  2594. {
  2595. return 0;
  2596. }
  2597. break;
  2598. case IDENTIFIER:
  2599. case INTEGER_STRING:
  2600. case OTHER:
  2601. if (strcmp (node_a->token->value.str,
  2602. node_b->token->value.str))
  2603. {
  2604. return 0;
  2605. }
  2606. break;
  2607. }
  2608. node_a = node_a->next;
  2609. node_b = node_b->next;
  2610. }
  2611. return 1;
  2612. }
  2613. static void
  2614. _token_print (char **out, token_t *token)
  2615. {
  2616. if (token->type < 256) {
  2617. ralloc_asprintf_append (out, "%c", token->type);
  2618. return;
  2619. }
  2620. switch (token->type) {
  2621. case INTEGER:
  2622. ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival);
  2623. break;
  2624. case IDENTIFIER:
  2625. case INTEGER_STRING:
  2626. case OTHER:
  2627. ralloc_strcat (out, token->value.str);
  2628. break;
  2629. case SPACE:
  2630. ralloc_strcat (out, " ");
  2631. break;
  2632. case LEFT_SHIFT:
  2633. ralloc_strcat (out, "<<");
  2634. break;
  2635. case RIGHT_SHIFT:
  2636. ralloc_strcat (out, ">>");
  2637. break;
  2638. case LESS_OR_EQUAL:
  2639. ralloc_strcat (out, "<=");
  2640. break;
  2641. case GREATER_OR_EQUAL:
  2642. ralloc_strcat (out, ">=");
  2643. break;
  2644. case EQUAL:
  2645. ralloc_strcat (out, "==");
  2646. break;
  2647. case NOT_EQUAL:
  2648. ralloc_strcat (out, "!=");
  2649. break;
  2650. case AND:
  2651. ralloc_strcat (out, "&&");
  2652. break;
  2653. case OR:
  2654. ralloc_strcat (out, "||");
  2655. break;
  2656. case PASTE:
  2657. ralloc_strcat (out, "##");
  2658. break;
  2659. case COMMA_FINAL:
  2660. ralloc_strcat (out, ",");
  2661. break;
  2662. case PLACEHOLDER:
  2663. /* Nothing to print. */
  2664. break;
  2665. default:
  2666. assert(!"Error: Don't know how to print token.");
  2667. break;
  2668. }
  2669. }
  2670. /* Return a new token (ralloc()ed off of 'token') formed by pasting
  2671. * 'token' and 'other'. Note that this function may return 'token' or
  2672. * 'other' directly rather than allocating anything new.
  2673. *
  2674. * Caution: Only very cursory error-checking is performed to see if
  2675. * the final result is a valid single token. */
  2676. static token_t *
  2677. _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other)
  2678. {
  2679. token_t *combined = NULL;
  2680. /* Pasting a placeholder onto anything makes no change. */
  2681. if (other->type == PLACEHOLDER)
  2682. return token;
  2683. /* When 'token' is a placeholder, just return 'other'. */
  2684. if (token->type == PLACEHOLDER)
  2685. return other;
  2686. /* A very few single-character punctuators can be combined
  2687. * with another to form a multi-character punctuator. */
  2688. switch (token->type) {
  2689. case '<':
  2690. if (other->type == '<')
  2691. combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT);
  2692. else if (other->type == '=')
  2693. combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL);
  2694. break;
  2695. case '>':
  2696. if (other->type == '>')
  2697. combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT);
  2698. else if (other->type == '=')
  2699. combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL);
  2700. break;
  2701. case '=':
  2702. if (other->type == '=')
  2703. combined = _token_create_ival (token, EQUAL, EQUAL);
  2704. break;
  2705. case '!':
  2706. if (other->type == '=')
  2707. combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL);
  2708. break;
  2709. case '&':
  2710. if (other->type == '&')
  2711. combined = _token_create_ival (token, AND, AND);
  2712. break;
  2713. case '|':
  2714. if (other->type == '|')
  2715. combined = _token_create_ival (token, OR, OR);
  2716. break;
  2717. }
  2718. if (combined != NULL) {
  2719. /* Inherit the location from the first token */
  2720. combined->location = token->location;
  2721. return combined;
  2722. }
  2723. /* Two string-valued tokens can usually just be mashed
  2724. * together.
  2725. *
  2726. * XXX: This isn't actually legitimate. Several things here
  2727. * should result in a diagnostic since the result cannot be a
  2728. * valid, single pre-processing token. For example, pasting
  2729. * "123" and "abc" is not legal, but we don't catch that
  2730. * here. */
  2731. if ((token->type == IDENTIFIER || token->type == OTHER || token->type == INTEGER_STRING) &&
  2732. (other->type == IDENTIFIER || other->type == OTHER || other->type == INTEGER_STRING))
  2733. {
  2734. char *str;
  2735. str = ralloc_asprintf (token, "%s%s", token->value.str,
  2736. other->value.str);
  2737. combined = _token_create_str (token, token->type, str);
  2738. combined->location = token->location;
  2739. return combined;
  2740. }
  2741. glcpp_error (&token->location, parser, "");
  2742. ralloc_strcat (&parser->info_log, "Pasting \"");
  2743. _token_print (&parser->info_log, token);
  2744. ralloc_strcat (&parser->info_log, "\" and \"");
  2745. _token_print (&parser->info_log, other);
  2746. ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n");
  2747. return token;
  2748. }
  2749. static void
  2750. _token_list_print (glcpp_parser_t *parser, token_list_t *list)
  2751. {
  2752. token_node_t *node;
  2753. if (list == NULL)
  2754. return;
  2755. for (node = list->head; node; node = node->next)
  2756. _token_print (&parser->output, node->token);
  2757. }
  2758. void
  2759. yyerror (YYLTYPE *locp, glcpp_parser_t *parser, const char *error)
  2760. {
  2761. glcpp_error(locp, parser, "%s", error);
  2762. }
  2763. static void add_builtin_define(glcpp_parser_t *parser,
  2764. const char *name, int value)
  2765. {
  2766. token_t *tok;
  2767. token_list_t *list;
  2768. tok = _token_create_ival (parser, INTEGER, value);
  2769. list = _token_list_create(parser);
  2770. _token_list_append(list, tok);
  2771. _define_object_macro(parser, NULL, name, list);
  2772. }
  2773. glcpp_parser_t *
  2774. glcpp_parser_create (const struct gl_extensions *extensions, int api)
  2775. {
  2776. glcpp_parser_t *parser;
  2777. int language_version;
  2778. parser = ralloc (NULL, glcpp_parser_t);
  2779. glcpp_lex_init_extra (parser, &parser->scanner);
  2780. parser->defines = hash_table_ctor (32, hash_table_string_hash,
  2781. hash_table_string_compare);
  2782. parser->active = NULL;
  2783. parser->lexing_if = 0;
  2784. parser->space_tokens = 1;
  2785. parser->newline_as_space = 0;
  2786. parser->in_control_line = 0;
  2787. parser->paren_count = 0;
  2788. parser->skip_stack = NULL;
  2789. parser->lex_from_list = NULL;
  2790. parser->lex_from_node = NULL;
  2791. parser->output = ralloc_strdup(parser, "");
  2792. parser->info_log = ralloc_strdup(parser, "");
  2793. parser->error = 0;
  2794. /* Add pre-defined macros. */
  2795. add_builtin_define(parser, "GL_ARB_draw_buffers", 1);
  2796. add_builtin_define(parser, "GL_ARB_texture_rectangle", 1);
  2797. if (api == API_OPENGLES2)
  2798. add_builtin_define(parser, "GL_ES", 1);
  2799. if (extensions != NULL) {
  2800. if (extensions->EXT_texture_array) {
  2801. add_builtin_define(parser, "GL_EXT_texture_array", 1);
  2802. }
  2803. if (extensions->ARB_fragment_coord_conventions)
  2804. add_builtin_define(parser, "GL_ARB_fragment_coord_conventions",
  2805. 1);
  2806. if (extensions->ARB_explicit_attrib_location)
  2807. add_builtin_define(parser, "GL_ARB_explicit_attrib_location", 1);
  2808. if (extensions->AMD_conservative_depth)
  2809. add_builtin_define(parser, "GL_AMD_conservative_depth", 1);
  2810. }
  2811. language_version = 110;
  2812. add_builtin_define(parser, "__VERSION__", language_version);
  2813. return parser;
  2814. }
  2815. int
  2816. glcpp_parser_parse (glcpp_parser_t *parser)
  2817. {
  2818. return yyparse (parser);
  2819. }
  2820. void
  2821. glcpp_parser_destroy (glcpp_parser_t *parser)
  2822. {
  2823. glcpp_lex_destroy (parser->scanner);
  2824. hash_table_dtor (parser->defines);
  2825. ralloc_free (parser);
  2826. }
  2827. typedef enum function_status
  2828. {
  2829. FUNCTION_STATUS_SUCCESS,
  2830. FUNCTION_NOT_A_FUNCTION,
  2831. FUNCTION_UNBALANCED_PARENTHESES
  2832. } function_status_t;
  2833. /* Find a set of function-like macro arguments by looking for a
  2834. * balanced set of parentheses.
  2835. *
  2836. * When called, 'node' should be the opening-parenthesis token, (or
  2837. * perhaps preceeding SPACE tokens). Upon successful return *last will
  2838. * be the last consumed node, (corresponding to the closing right
  2839. * parenthesis).
  2840. *
  2841. * Return values:
  2842. *
  2843. * FUNCTION_STATUS_SUCCESS:
  2844. *
  2845. * Successfully parsed a set of function arguments.
  2846. *
  2847. * FUNCTION_NOT_A_FUNCTION:
  2848. *
  2849. * Macro name not followed by a '('. This is not an error, but
  2850. * simply that the macro name should be treated as a non-macro.
  2851. *
  2852. * FUNCTION_UNBALANCED_PARENTHESES
  2853. *
  2854. * Macro name is not followed by a balanced set of parentheses.
  2855. */
  2856. static function_status_t
  2857. _arguments_parse (argument_list_t *arguments,
  2858. token_node_t *node,
  2859. token_node_t **last)
  2860. {
  2861. token_list_t *argument;
  2862. int paren_count;
  2863. node = node->next;
  2864. /* Ignore whitespace before first parenthesis. */
  2865. while (node && node->token->type == SPACE)
  2866. node = node->next;
  2867. if (node == NULL || node->token->type != '(')
  2868. return FUNCTION_NOT_A_FUNCTION;
  2869. node = node->next;
  2870. argument = _token_list_create (arguments);
  2871. _argument_list_append (arguments, argument);
  2872. for (paren_count = 1; node; node = node->next) {
  2873. if (node->token->type == '(')
  2874. {
  2875. paren_count++;
  2876. }
  2877. else if (node->token->type == ')')
  2878. {
  2879. paren_count--;
  2880. if (paren_count == 0)
  2881. break;
  2882. }
  2883. if (node->token->type == ',' &&
  2884. paren_count == 1)
  2885. {
  2886. _token_list_trim_trailing_space (argument);
  2887. argument = _token_list_create (arguments);
  2888. _argument_list_append (arguments, argument);
  2889. }
  2890. else {
  2891. if (argument->head == NULL) {
  2892. /* Don't treat initial whitespace as
  2893. * part of the arguement. */
  2894. if (node->token->type == SPACE)
  2895. continue;
  2896. }
  2897. _token_list_append (argument, node->token);
  2898. }
  2899. }
  2900. if (paren_count)
  2901. return FUNCTION_UNBALANCED_PARENTHESES;
  2902. *last = node;
  2903. return FUNCTION_STATUS_SUCCESS;
  2904. }
  2905. static token_list_t *
  2906. _token_list_create_with_one_space (void *ctx)
  2907. {
  2908. token_list_t *list;
  2909. token_t *space;
  2910. list = _token_list_create (ctx);
  2911. space = _token_create_ival (list, SPACE, SPACE);
  2912. _token_list_append (list, space);
  2913. return list;
  2914. }
  2915. static void
  2916. _glcpp_parser_expand_if (glcpp_parser_t *parser, int type, token_list_t *list)
  2917. {
  2918. token_list_t *expanded;
  2919. token_t *token;
  2920. expanded = _token_list_create (parser);
  2921. token = _token_create_ival (parser, type, type);
  2922. _token_list_append (expanded, token);
  2923. _glcpp_parser_expand_token_list (parser, list);
  2924. _token_list_append_list (expanded, list);
  2925. glcpp_parser_lex_from (parser, expanded);
  2926. }
  2927. /* This is a helper function that's essentially part of the
  2928. * implementation of _glcpp_parser_expand_node. It shouldn't be called
  2929. * except for by that function.
  2930. *
  2931. * Returns NULL if node is a simple token with no expansion, (that is,
  2932. * although 'node' corresponds to an identifier defined as a
  2933. * function-like macro, it is not followed with a parenthesized
  2934. * argument list).
  2935. *
  2936. * Compute the complete expansion of node (which is a function-like
  2937. * macro) and subsequent nodes which are arguments.
  2938. *
  2939. * Returns the token list that results from the expansion and sets
  2940. * *last to the last node in the list that was consumed by the
  2941. * expansion. Specifically, *last will be set as follows: as the
  2942. * token of the closing right parenthesis.
  2943. */
  2944. static token_list_t *
  2945. _glcpp_parser_expand_function (glcpp_parser_t *parser,
  2946. token_node_t *node,
  2947. token_node_t **last)
  2948. {
  2949. macro_t *macro;
  2950. const char *identifier;
  2951. argument_list_t *arguments;
  2952. function_status_t status;
  2953. token_list_t *substituted;
  2954. int parameter_index;
  2955. identifier = node->token->value.str;
  2956. macro = hash_table_find (parser->defines, identifier);
  2957. assert (macro->is_function);
  2958. arguments = _argument_list_create (parser);
  2959. status = _arguments_parse (arguments, node, last);
  2960. switch (status) {
  2961. case FUNCTION_STATUS_SUCCESS:
  2962. break;
  2963. case FUNCTION_NOT_A_FUNCTION:
  2964. return NULL;
  2965. case FUNCTION_UNBALANCED_PARENTHESES:
  2966. glcpp_error (&node->token->location, parser, "Macro %s call has unbalanced parentheses\n", identifier);
  2967. return NULL;
  2968. }
  2969. /* Replace a macro defined as empty with a SPACE token. */
  2970. if (macro->replacements == NULL) {
  2971. ralloc_free (arguments);
  2972. return _token_list_create_with_one_space (parser);
  2973. }
  2974. if (! ((_argument_list_length (arguments) ==
  2975. _string_list_length (macro->parameters)) ||
  2976. (_string_list_length (macro->parameters) == 0 &&
  2977. _argument_list_length (arguments) == 1 &&
  2978. arguments->head->argument->head == NULL)))
  2979. {
  2980. glcpp_error (&node->token->location, parser,
  2981. "Error: macro %s invoked with %d arguments (expected %d)\n",
  2982. identifier,
  2983. _argument_list_length (arguments),
  2984. _string_list_length (macro->parameters));
  2985. return NULL;
  2986. }
  2987. /* Perform argument substitution on the replacement list. */
  2988. substituted = _token_list_create (arguments);
  2989. for (node = macro->replacements->head; node; node = node->next)
  2990. {
  2991. if (node->token->type == IDENTIFIER &&
  2992. _string_list_contains (macro->parameters,
  2993. node->token->value.str,
  2994. &parameter_index))
  2995. {
  2996. token_list_t *argument;
  2997. argument = _argument_list_member_at (arguments,
  2998. parameter_index);
  2999. /* Before substituting, we expand the argument
  3000. * tokens, or append a placeholder token for
  3001. * an empty argument. */
  3002. if (argument->head) {
  3003. token_list_t *expanded_argument;
  3004. expanded_argument = _token_list_copy (parser,
  3005. argument);
  3006. _glcpp_parser_expand_token_list (parser,
  3007. expanded_argument);
  3008. _token_list_append_list (substituted,
  3009. expanded_argument);
  3010. } else {
  3011. token_t *new_token;
  3012. new_token = _token_create_ival (substituted,
  3013. PLACEHOLDER,
  3014. PLACEHOLDER);
  3015. _token_list_append (substituted, new_token);
  3016. }
  3017. } else {
  3018. _token_list_append (substituted, node->token);
  3019. }
  3020. }
  3021. /* After argument substitution, and before further expansion
  3022. * below, implement token pasting. */
  3023. _token_list_trim_trailing_space (substituted);
  3024. node = substituted->head;
  3025. while (node)
  3026. {
  3027. token_node_t *next_non_space;
  3028. /* Look ahead for a PASTE token, skipping space. */
  3029. next_non_space = node->next;
  3030. while (next_non_space && next_non_space->token->type == SPACE)
  3031. next_non_space = next_non_space->next;
  3032. if (next_non_space == NULL)
  3033. break;
  3034. if (next_non_space->token->type != PASTE) {
  3035. node = next_non_space;
  3036. continue;
  3037. }
  3038. /* Now find the next non-space token after the PASTE. */
  3039. next_non_space = next_non_space->next;
  3040. while (next_non_space && next_non_space->token->type == SPACE)
  3041. next_non_space = next_non_space->next;
  3042. if (next_non_space == NULL) {
  3043. yyerror (&node->token->location, parser, "'##' cannot appear at either end of a macro expansion\n");
  3044. return NULL;
  3045. }
  3046. node->token = _token_paste (parser, node->token, next_non_space->token);
  3047. node->next = next_non_space->next;
  3048. if (next_non_space == substituted->tail)
  3049. substituted->tail = node;
  3050. node = node->next;
  3051. }
  3052. substituted->non_space_tail = substituted->tail;
  3053. return substituted;
  3054. }
  3055. /* Compute the complete expansion of node, (and subsequent nodes after
  3056. * 'node' in the case that 'node' is a function-like macro and
  3057. * subsequent nodes are arguments).
  3058. *
  3059. * Returns NULL if node is a simple token with no expansion.
  3060. *
  3061. * Otherwise, returns the token list that results from the expansion
  3062. * and sets *last to the last node in the list that was consumed by
  3063. * the expansion. Specifically, *last will be set as follows:
  3064. *
  3065. * As 'node' in the case of object-like macro expansion.
  3066. *
  3067. * As the token of the closing right parenthesis in the case of
  3068. * function-like macro expansion.
  3069. */
  3070. static token_list_t *
  3071. _glcpp_parser_expand_node (glcpp_parser_t *parser,
  3072. token_node_t *node,
  3073. token_node_t **last)
  3074. {
  3075. token_t *token = node->token;
  3076. const char *identifier;
  3077. macro_t *macro;
  3078. /* We only expand identifiers */
  3079. if (token->type != IDENTIFIER) {
  3080. /* We change any COMMA into a COMMA_FINAL to prevent
  3081. * it being mistaken for an argument separator
  3082. * later. */
  3083. if (token->type == ',') {
  3084. token->type = COMMA_FINAL;
  3085. token->value.ival = COMMA_FINAL;
  3086. }
  3087. return NULL;
  3088. }
  3089. /* Look up this identifier in the hash table. */
  3090. identifier = token->value.str;
  3091. macro = hash_table_find (parser->defines, identifier);
  3092. /* Not a macro, so no expansion needed. */
  3093. if (macro == NULL)
  3094. return NULL;
  3095. /* Finally, don't expand this macro if we're already actively
  3096. * expanding it, (to avoid infinite recursion). */
  3097. if (_active_list_contains (parser->active, identifier)) {
  3098. /* We change the token type here from IDENTIFIER to
  3099. * OTHER to prevent any future expansion of this
  3100. * unexpanded token. */
  3101. char *str;
  3102. token_list_t *expansion;
  3103. token_t *final;
  3104. str = ralloc_strdup (parser, token->value.str);
  3105. final = _token_create_str (parser, OTHER, str);
  3106. expansion = _token_list_create (parser);
  3107. _token_list_append (expansion, final);
  3108. *last = node;
  3109. return expansion;
  3110. }
  3111. if (! macro->is_function)
  3112. {
  3113. *last = node;
  3114. /* Replace a macro defined as empty with a SPACE token. */
  3115. if (macro->replacements == NULL)
  3116. return _token_list_create_with_one_space (parser);
  3117. return _token_list_copy (parser, macro->replacements);
  3118. }
  3119. return _glcpp_parser_expand_function (parser, node, last);
  3120. }
  3121. /* Push a new identifier onto the active list, returning the new list.
  3122. *
  3123. * Here, 'marker' is the token node that appears in the list after the
  3124. * expansion of 'identifier'. That is, when the list iterator begins
  3125. * examinging 'marker', then it is time to pop this node from the
  3126. * active stack.
  3127. */
  3128. active_list_t *
  3129. _active_list_push (active_list_t *list,
  3130. const char *identifier,
  3131. token_node_t *marker)
  3132. {
  3133. active_list_t *node;
  3134. node = ralloc (list, active_list_t);
  3135. node->identifier = ralloc_strdup (node, identifier);
  3136. node->marker = marker;
  3137. node->next = list;
  3138. return node;
  3139. }
  3140. active_list_t *
  3141. _active_list_pop (active_list_t *list)
  3142. {
  3143. active_list_t *node = list;
  3144. if (node == NULL)
  3145. return NULL;
  3146. node = list->next;
  3147. ralloc_free (list);
  3148. return node;
  3149. }
  3150. int
  3151. _active_list_contains (active_list_t *list, const char *identifier)
  3152. {
  3153. active_list_t *node;
  3154. if (list == NULL)
  3155. return 0;
  3156. for (node = list; node; node = node->next)
  3157. if (strcmp (node->identifier, identifier) == 0)
  3158. return 1;
  3159. return 0;
  3160. }
  3161. /* Walk over the token list replacing nodes with their expansion.
  3162. * Whenever nodes are expanded the walking will walk over the new
  3163. * nodes, continuing to expand as necessary. The results are placed in
  3164. * 'list' itself;
  3165. */
  3166. static void
  3167. _glcpp_parser_expand_token_list (glcpp_parser_t *parser,
  3168. token_list_t *list)
  3169. {
  3170. token_node_t *node_prev;
  3171. token_node_t *node, *last = NULL;
  3172. token_list_t *expansion;
  3173. if (list == NULL)
  3174. return;
  3175. _token_list_trim_trailing_space (list);
  3176. node_prev = NULL;
  3177. node = list->head;
  3178. while (node) {
  3179. while (parser->active && parser->active->marker == node)
  3180. parser->active = _active_list_pop (parser->active);
  3181. /* Find the expansion for node, which will replace all
  3182. * nodes from node to last, inclusive. */
  3183. expansion = _glcpp_parser_expand_node (parser, node, &last);
  3184. if (expansion) {
  3185. token_node_t *n;
  3186. for (n = node; n != last->next; n = n->next)
  3187. while (parser->active &&
  3188. parser->active->marker == n)
  3189. {
  3190. parser->active = _active_list_pop (parser->active);
  3191. }
  3192. parser->active = _active_list_push (parser->active,
  3193. node->token->value.str,
  3194. last->next);
  3195. /* Splice expansion into list, supporting a
  3196. * simple deletion if the expansion is
  3197. * empty. */
  3198. if (expansion->head) {
  3199. if (node_prev)
  3200. node_prev->next = expansion->head;
  3201. else
  3202. list->head = expansion->head;
  3203. expansion->tail->next = last->next;
  3204. if (last == list->tail)
  3205. list->tail = expansion->tail;
  3206. } else {
  3207. if (node_prev)
  3208. node_prev->next = last->next;
  3209. else
  3210. list->head = last->next;
  3211. if (last == list->tail)
  3212. list->tail = NULL;
  3213. }
  3214. } else {
  3215. node_prev = node;
  3216. }
  3217. node = node_prev ? node_prev->next : list->head;
  3218. }
  3219. while (parser->active)
  3220. parser->active = _active_list_pop (parser->active);
  3221. list->non_space_tail = list->tail;
  3222. }
  3223. void
  3224. _glcpp_parser_print_expanded_token_list (glcpp_parser_t *parser,
  3225. token_list_t *list)
  3226. {
  3227. if (list == NULL)
  3228. return;
  3229. _glcpp_parser_expand_token_list (parser, list);
  3230. _token_list_trim_trailing_space (list);
  3231. _token_list_print (parser, list);
  3232. }
  3233. static void
  3234. _check_for_reserved_macro_name (glcpp_parser_t *parser, YYLTYPE *loc,
  3235. const char *identifier)
  3236. {
  3237. /* According to the GLSL specification, macro names starting with "__"
  3238. * or "GL_" are reserved for future use. So, don't allow them.
  3239. */
  3240. if (strncmp(identifier, "__", 2) == 0) {
  3241. glcpp_error (loc, parser, "Macro names starting with \"__\" are reserved.\n");
  3242. }
  3243. if (strncmp(identifier, "GL_", 3) == 0) {
  3244. glcpp_error (loc, parser, "Macro names starting with \"GL_\" are reserved.\n");
  3245. }
  3246. }
  3247. static int
  3248. _macro_equal (macro_t *a, macro_t *b)
  3249. {
  3250. if (a->is_function != b->is_function)
  3251. return 0;
  3252. if (a->is_function) {
  3253. if (! _string_list_equal (a->parameters, b->parameters))
  3254. return 0;
  3255. }
  3256. return _token_list_equal_ignoring_space (a->replacements,
  3257. b->replacements);
  3258. }
  3259. void
  3260. _define_object_macro (glcpp_parser_t *parser,
  3261. YYLTYPE *loc,
  3262. const char *identifier,
  3263. token_list_t *replacements)
  3264. {
  3265. macro_t *macro, *previous;
  3266. if (loc != NULL)
  3267. _check_for_reserved_macro_name(parser, loc, identifier);
  3268. macro = ralloc (parser, macro_t);
  3269. macro->is_function = 0;
  3270. macro->parameters = NULL;
  3271. macro->identifier = ralloc_strdup (macro, identifier);
  3272. macro->replacements = replacements;
  3273. ralloc_steal (macro, replacements);
  3274. previous = hash_table_find (parser->defines, identifier);
  3275. if (previous) {
  3276. if (_macro_equal (macro, previous)) {
  3277. ralloc_free (macro);
  3278. return;
  3279. }
  3280. glcpp_error (loc, parser, "Redefinition of macro %s\n",
  3281. identifier);
  3282. }
  3283. hash_table_insert (parser->defines, macro, identifier);
  3284. }
  3285. void
  3286. _define_function_macro (glcpp_parser_t *parser,
  3287. YYLTYPE *loc,
  3288. const char *identifier,
  3289. string_list_t *parameters,
  3290. token_list_t *replacements)
  3291. {
  3292. macro_t *macro, *previous;
  3293. _check_for_reserved_macro_name(parser, loc, identifier);
  3294. macro = ralloc (parser, macro_t);
  3295. ralloc_steal (macro, parameters);
  3296. ralloc_steal (macro, replacements);
  3297. macro->is_function = 1;
  3298. macro->parameters = parameters;
  3299. macro->identifier = ralloc_strdup (macro, identifier);
  3300. macro->replacements = replacements;
  3301. previous = hash_table_find (parser->defines, identifier);
  3302. if (previous) {
  3303. if (_macro_equal (macro, previous)) {
  3304. ralloc_free (macro);
  3305. return;
  3306. }
  3307. glcpp_error (loc, parser, "Redefinition of macro %s\n",
  3308. identifier);
  3309. }
  3310. hash_table_insert (parser->defines, macro, identifier);
  3311. }
  3312. static int
  3313. glcpp_parser_lex (YYSTYPE *yylval, YYLTYPE *yylloc, glcpp_parser_t *parser)
  3314. {
  3315. token_node_t *node;
  3316. int ret;
  3317. if (parser->lex_from_list == NULL) {
  3318. ret = glcpp_lex (yylval, yylloc, parser->scanner);
  3319. /* XXX: This ugly block of code exists for the sole
  3320. * purpose of converting a NEWLINE token into a SPACE
  3321. * token, but only in the case where we have seen a
  3322. * function-like macro name, but have not yet seen its
  3323. * closing parenthesis.
  3324. *
  3325. * There's perhaps a more compact way to do this with
  3326. * mid-rule actions in the grammar.
  3327. *
  3328. * I'm definitely not pleased with the complexity of
  3329. * this code here.
  3330. */
  3331. if (parser->newline_as_space)
  3332. {
  3333. if (ret == '(') {
  3334. parser->paren_count++;
  3335. } else if (ret == ')') {
  3336. parser->paren_count--;
  3337. if (parser->paren_count == 0)
  3338. parser->newline_as_space = 0;
  3339. } else if (ret == NEWLINE) {
  3340. ret = SPACE;
  3341. } else if (ret != SPACE) {
  3342. if (parser->paren_count == 0)
  3343. parser->newline_as_space = 0;
  3344. }
  3345. }
  3346. else if (parser->in_control_line)
  3347. {
  3348. if (ret == NEWLINE)
  3349. parser->in_control_line = 0;
  3350. }
  3351. else if (ret == HASH_DEFINE_OBJ || ret == HASH_DEFINE_FUNC ||
  3352. ret == HASH_UNDEF || ret == HASH_IF ||
  3353. ret == HASH_IFDEF || ret == HASH_IFNDEF ||
  3354. ret == HASH_ELIF || ret == HASH_ELSE ||
  3355. ret == HASH_ENDIF || ret == HASH)
  3356. {
  3357. parser->in_control_line = 1;
  3358. }
  3359. else if (ret == IDENTIFIER)
  3360. {
  3361. macro_t *macro;
  3362. macro = hash_table_find (parser->defines,
  3363. yylval->str);
  3364. if (macro && macro->is_function) {
  3365. parser->newline_as_space = 1;
  3366. parser->paren_count = 0;
  3367. }
  3368. }
  3369. return ret;
  3370. }
  3371. node = parser->lex_from_node;
  3372. if (node == NULL) {
  3373. ralloc_free (parser->lex_from_list);
  3374. parser->lex_from_list = NULL;
  3375. return NEWLINE;
  3376. }
  3377. *yylval = node->token->value;
  3378. ret = node->token->type;
  3379. parser->lex_from_node = node->next;
  3380. return ret;
  3381. }
  3382. static void
  3383. glcpp_parser_lex_from (glcpp_parser_t *parser, token_list_t *list)
  3384. {
  3385. token_node_t *node;
  3386. assert (parser->lex_from_list == NULL);
  3387. /* Copy list, eliminating any space tokens. */
  3388. parser->lex_from_list = _token_list_create (parser);
  3389. for (node = list->head; node; node = node->next) {
  3390. if (node->token->type == SPACE)
  3391. continue;
  3392. _token_list_append (parser->lex_from_list, node->token);
  3393. }
  3394. ralloc_free (list);
  3395. parser->lex_from_node = parser->lex_from_list->head;
  3396. /* It's possible the list consisted of nothing but whitespace. */
  3397. if (parser->lex_from_node == NULL) {
  3398. ralloc_free (parser->lex_from_list);
  3399. parser->lex_from_list = NULL;
  3400. }
  3401. }
  3402. static void
  3403. _glcpp_parser_skip_stack_push_if (glcpp_parser_t *parser, YYLTYPE *loc,
  3404. int condition)
  3405. {
  3406. skip_type_t current = SKIP_NO_SKIP;
  3407. skip_node_t *node;
  3408. if (parser->skip_stack)
  3409. current = parser->skip_stack->type;
  3410. node = ralloc (parser, skip_node_t);
  3411. node->loc = *loc;
  3412. if (current == SKIP_NO_SKIP) {
  3413. if (condition)
  3414. node->type = SKIP_NO_SKIP;
  3415. else
  3416. node->type = SKIP_TO_ELSE;
  3417. } else {
  3418. node->type = SKIP_TO_ENDIF;
  3419. }
  3420. node->next = parser->skip_stack;
  3421. parser->skip_stack = node;
  3422. }
  3423. static void
  3424. _glcpp_parser_skip_stack_change_if (glcpp_parser_t *parser, YYLTYPE *loc,
  3425. const char *type, int condition)
  3426. {
  3427. if (parser->skip_stack == NULL) {
  3428. glcpp_error (loc, parser, "%s without #if\n", type);
  3429. return;
  3430. }
  3431. if (parser->skip_stack->type == SKIP_TO_ELSE) {
  3432. if (condition)
  3433. parser->skip_stack->type = SKIP_NO_SKIP;
  3434. } else {
  3435. parser->skip_stack->type = SKIP_TO_ENDIF;
  3436. }
  3437. }
  3438. static void
  3439. _glcpp_parser_skip_stack_pop (glcpp_parser_t *parser, YYLTYPE *loc)
  3440. {
  3441. skip_node_t *node;
  3442. if (parser->skip_stack == NULL) {
  3443. glcpp_error (loc, parser, "#endif without #if\n");
  3444. return;
  3445. }
  3446. node = parser->skip_stack;
  3447. parser->skip_stack = node->next;
  3448. ralloc_free (node);
  3449. }