ebrowse.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828
  1. /* ebrowse.c --- parsing files for the ebrowse C++ browser
  2. Copyright (C) 1992-2012 Free Software Foundation, Inc.
  3. This file is part of GNU Emacs.
  4. GNU Emacs is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. GNU Emacs is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <config.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <ctype.h>
  19. #include <assert.h>
  20. #include <getopt.h>
  21. /* The SunOS compiler doesn't have SEEK_END. */
  22. #ifndef SEEK_END
  23. #define SEEK_END 2
  24. #endif
  25. /* Conditionalize function prototypes. */
  26. /* Value is non-zero if strings X and Y compare equal. */
  27. #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0)
  28. #include <min-max.h>
  29. /* Files are read in chunks of this number of bytes. */
  30. #define READ_CHUNK_SIZE (100 * 1024)
  31. /* The character used as a separator in path lists (like $PATH). */
  32. #if defined (__MSDOS__)
  33. #define PATH_LIST_SEPARATOR ';'
  34. #define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0)
  35. #else
  36. #if defined (WINDOWSNT)
  37. #define PATH_LIST_SEPARATOR ';'
  38. #define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0)
  39. #else
  40. #define PATH_LIST_SEPARATOR ':'
  41. #define FILENAME_EQ(X,Y) (streq (X,Y))
  42. #endif
  43. #endif
  44. /* The default output file name. */
  45. #define DEFAULT_OUTFILE "BROWSE"
  46. /* A version string written to the output file. Change this whenever
  47. the structure of the output file changes. */
  48. #define EBROWSE_FILE_VERSION "ebrowse 5.0"
  49. /* The output file consists of a tree of Lisp objects, with major
  50. nodes built out of Lisp structures. These are the heads of the
  51. Lisp structs with symbols identifying their type. */
  52. #define TREE_HEADER_STRUCT "[ebrowse-hs "
  53. #define TREE_STRUCT "[ebrowse-ts "
  54. #define MEMBER_STRUCT "[ebrowse-ms "
  55. #define CLASS_STRUCT "[ebrowse-cs "
  56. /* The name of the symbol table entry for global functions, variables,
  57. defines etc. This name also appears in the browser display. */
  58. #define GLOBALS_NAME "*Globals*"
  59. /* Token definitions. */
  60. enum token
  61. {
  62. YYEOF = 0, /* end of file */
  63. CSTRING = 256, /* string constant */
  64. CCHAR, /* character constant */
  65. CINT, /* integral constant */
  66. CFLOAT, /* real constant */
  67. ELLIPSIS, /* ... */
  68. LSHIFTASGN, /* <<= */
  69. RSHIFTASGN, /* >>= */
  70. ARROWSTAR, /* ->* */
  71. IDENT, /* identifier */
  72. DIVASGN, /* /= */
  73. INC, /* ++ */
  74. ADDASGN, /* += */
  75. DEC, /* -- */
  76. ARROW, /* -> */
  77. SUBASGN, /* -= */
  78. MULASGN, /* *= */
  79. MODASGN, /* %= */
  80. LOR, /* || */
  81. ORASGN, /* |= */
  82. LAND, /* && */
  83. ANDASGN, /* &= */
  84. XORASGN, /* ^= */
  85. POINTSTAR, /* .* */
  86. DCOLON, /* :: */
  87. EQ, /* == */
  88. NE, /* != */
  89. LE, /* <= */
  90. LSHIFT, /* << */
  91. GE, /* >= */
  92. RSHIFT, /* >> */
  93. /* Keywords. The undef's are there because these
  94. three symbols are very likely to be defined somewhere. */
  95. #undef BOOL
  96. #undef TRUE
  97. #undef FALSE
  98. ASM, /* asm */
  99. AUTO, /* auto */
  100. BREAK, /* break */
  101. CASE, /* case */
  102. CATCH, /* catch */
  103. CHAR, /* char */
  104. CLASS, /* class */
  105. CONST, /* const */
  106. CONTINUE, /* continue */
  107. DEFAULT, /* default */
  108. DELETE, /* delete */
  109. DO, /* do */
  110. DOUBLE, /* double */
  111. ELSE, /* else */
  112. ENUM, /* enum */
  113. EXTERN, /* extern */
  114. FLOAT, /* float */
  115. FOR, /* for */
  116. FRIEND, /* friend */
  117. GOTO, /* goto */
  118. IF, /* if */
  119. T_INLINE, /* inline */
  120. INT, /* int */
  121. LONG, /* long */
  122. NEW, /* new */
  123. OPERATOR, /* operator */
  124. PRIVATE, /* private */
  125. PROTECTED, /* protected */
  126. PUBLIC, /* public */
  127. REGISTER, /* register */
  128. RETURN, /* return */
  129. SHORT, /* short */
  130. SIGNED, /* signed */
  131. SIZEOF, /* sizeof */
  132. STATIC, /* static */
  133. STRUCT, /* struct */
  134. SWITCH, /* switch */
  135. TEMPLATE, /* template */
  136. THIS, /* this */
  137. THROW, /* throw */
  138. TRY, /* try */
  139. TYPEDEF, /* typedef */
  140. UNION, /* union */
  141. UNSIGNED, /* unsigned */
  142. VIRTUAL, /* virtual */
  143. VOID, /* void */
  144. VOLATILE, /* volatile */
  145. WHILE, /* while */
  146. MUTABLE, /* mutable */
  147. BOOL, /* bool */
  148. TRUE, /* true */
  149. FALSE, /* false */
  150. SIGNATURE, /* signature (GNU extension) */
  151. NAMESPACE, /* namespace */
  152. EXPLICIT, /* explicit */
  153. TYPENAME, /* typename */
  154. CONST_CAST, /* const_cast */
  155. DYNAMIC_CAST, /* dynamic_cast */
  156. REINTERPRET_CAST, /* reinterpret_cast */
  157. STATIC_CAST, /* static_cast */
  158. TYPEID, /* typeid */
  159. USING, /* using */
  160. WCHAR /* wchar_t */
  161. };
  162. /* Storage classes, in a wider sense. */
  163. enum sc
  164. {
  165. SC_UNKNOWN,
  166. SC_MEMBER, /* Is an instance member. */
  167. SC_STATIC, /* Is static member. */
  168. SC_FRIEND, /* Is friend function. */
  169. SC_TYPE /* Is a type definition. */
  170. };
  171. /* Member visibility. */
  172. enum visibility
  173. {
  174. V_PUBLIC,
  175. V_PROTECTED,
  176. V_PRIVATE
  177. };
  178. /* Member flags. */
  179. #define F_VIRTUAL 1 /* Is virtual function. */
  180. #define F_INLINE 2 /* Is inline function. */
  181. #define F_CONST 4 /* Is const. */
  182. #define F_PURE 8 /* Is pure virtual function. */
  183. #define F_MUTABLE 16 /* Is mutable. */
  184. #define F_TEMPLATE 32 /* Is a template. */
  185. #define F_EXPLICIT 64 /* Is explicit constructor. */
  186. #define F_THROW 128 /* Has a throw specification. */
  187. #define F_EXTERNC 256 /* Is declared extern "C". */
  188. #define F_DEFINE 512 /* Is a #define. */
  189. /* Two macros to set and test a bit in an int. */
  190. #define SET_FLAG(F, FLAG) ((F) |= (FLAG))
  191. #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0)
  192. /* Structure describing a class member. */
  193. struct member
  194. {
  195. struct member *next; /* Next in list of members. */
  196. struct member *anext; /* Collision chain in member_table. */
  197. struct member **list; /* Pointer to list in class. */
  198. unsigned param_hash; /* Hash value for parameter types. */
  199. int vis; /* Visibility (public, ...). */
  200. int flags; /* See F_* above. */
  201. char *regexp; /* Matching regular expression. */
  202. const char *filename; /* Don't free this shared string. */
  203. int pos; /* Buffer position of occurrence. */
  204. char *def_regexp; /* Regular expression matching definition. */
  205. const char *def_filename; /* File name of definition. */
  206. int def_pos; /* Buffer position of definition. */
  207. char name[1]; /* Member name. */
  208. };
  209. /* Structures of this type are used to connect class structures with
  210. their super and subclasses. */
  211. struct link
  212. {
  213. struct sym *sym; /* The super or subclass. */
  214. struct link *next; /* Next in list or NULL. */
  215. };
  216. /* Structure used to record namespace aliases. */
  217. struct alias
  218. {
  219. struct alias *next; /* Next in list. */
  220. struct sym *namesp; /* Namespace in which defined. */
  221. struct link *aliasee; /* List of aliased namespaces (A::B::C...). */
  222. char name[1]; /* Alias name. */
  223. };
  224. /* The structure used to describe a class in the symbol table,
  225. or a namespace in all_namespaces. */
  226. struct sym
  227. {
  228. int flags; /* Is class a template class?. */
  229. unsigned char visited; /* Used to find circles. */
  230. struct sym *next; /* Hash collision list. */
  231. struct link *subs; /* List of subclasses. */
  232. struct link *supers; /* List of superclasses. */
  233. struct member *vars; /* List of instance variables. */
  234. struct member *fns; /* List of instance functions. */
  235. struct member *static_vars; /* List of static variables. */
  236. struct member *static_fns; /* List of static functions. */
  237. struct member *friends; /* List of friend functions. */
  238. struct member *types; /* List of local types. */
  239. char *regexp; /* Matching regular expression. */
  240. int pos; /* Buffer position. */
  241. const char *filename; /* File in which it can be found. */
  242. const char *sfilename; /* File in which members can be found. */
  243. struct sym *namesp; /* Namespace in which defined. . */
  244. char name[1]; /* Name of the class. */
  245. };
  246. /* Experimental: Print info for `--position-info'. We print
  247. '(CLASS-NAME SCOPE MEMBER-NAME). */
  248. #define P_DEFN 1
  249. #define P_DECL 2
  250. int info_where;
  251. struct sym *info_cls = NULL;
  252. struct member *info_member = NULL;
  253. /* Experimental. For option `--position-info', the buffer position we
  254. are interested in. When this position is reached, print out
  255. information about what we know about that point. */
  256. int info_position = -1;
  257. /* Command line options structure for getopt_long. */
  258. struct option options[] =
  259. {
  260. {"append", no_argument, NULL, 'a'},
  261. {"files", required_argument, NULL, 'f'},
  262. {"help", no_argument, NULL, -2},
  263. {"min-regexp-length", required_argument, NULL, 'm'},
  264. {"max-regexp-length", required_argument, NULL, 'M'},
  265. {"no-nested-classes", no_argument, NULL, 'n'},
  266. {"no-regexps", no_argument, NULL, 'x'},
  267. {"no-structs-or-unions", no_argument, NULL, 's'},
  268. {"output-file", required_argument, NULL, 'o'},
  269. {"position-info", required_argument, NULL, 'p'},
  270. {"search-path", required_argument, NULL, 'I'},
  271. {"verbose", no_argument, NULL, 'v'},
  272. {"version", no_argument, NULL, -3},
  273. {"very-verbose", no_argument, NULL, 'V'},
  274. {NULL, 0, NULL, 0}
  275. };
  276. /* Semantic values of tokens. Set by yylex.. */
  277. unsigned yyival; /* Set for token CINT. */
  278. char *yytext; /* Set for token IDENT. */
  279. char *yytext_end;
  280. /* Output file. */
  281. FILE *yyout;
  282. /* Current line number. */
  283. int yyline;
  284. /* The name of the current input file. */
  285. const char *filename;
  286. /* Three character class vectors, and macros to test membership
  287. of characters. */
  288. char is_ident[255];
  289. char is_digit[255];
  290. char is_white[255];
  291. #define IDENTP(C) is_ident[(unsigned char) (C)]
  292. #define DIGITP(C) is_digit[(unsigned char) (C)]
  293. #define WHITEP(C) is_white[(unsigned char) (C)]
  294. /* Command line flags. */
  295. int f_append;
  296. int f_verbose;
  297. int f_very_verbose;
  298. int f_structs = 1;
  299. int f_regexps = 1;
  300. int f_nested_classes = 1;
  301. /* Maximum and minimum lengths of regular expressions matching a
  302. member, class etc., for writing them to the output file. These are
  303. overridable from the command line. */
  304. int min_regexp = 5;
  305. int max_regexp = 50;
  306. /* Input buffer. */
  307. char *inbuffer;
  308. char *in;
  309. size_t inbuffer_size;
  310. /* Return the current buffer position in the input file. */
  311. #define BUFFER_POS() (in - inbuffer)
  312. /* If current lookahead is CSTRING, the following points to the
  313. first character in the string constant. Used for recognizing
  314. extern "C". */
  315. char *string_start;
  316. /* The size of the hash tables for classes.and members. Should be
  317. prime. */
  318. #define TABLE_SIZE 1001
  319. /* The hash table for class symbols. */
  320. struct sym *class_table[TABLE_SIZE];
  321. /* Hash table containing all member structures. This is generally
  322. faster for member lookup than traversing the member lists of a
  323. `struct sym'. */
  324. struct member *member_table[TABLE_SIZE];
  325. /* Hash table for namespace aliases */
  326. struct alias *namespace_alias_table[TABLE_SIZE];
  327. /* The special class symbol used to hold global functions,
  328. variables etc. */
  329. struct sym *global_symbols;
  330. /* The current namespace. */
  331. struct sym *current_namespace;
  332. /* The list of all known namespaces. */
  333. struct sym *all_namespaces;
  334. /* Stack of namespaces we're currently nested in, during the parse. */
  335. struct sym **namespace_stack;
  336. int namespace_stack_size;
  337. int namespace_sp;
  338. /* The current lookahead token. */
  339. int tk = -1;
  340. /* Structure describing a keyword. */
  341. struct kw
  342. {
  343. const char *name; /* Spelling. */
  344. int tk; /* Token value. */
  345. struct kw *next; /* Next in collision chain. */
  346. };
  347. /* Keywords are lookup up in a hash table of their own. */
  348. #define KEYWORD_TABLE_SIZE 1001
  349. struct kw *keyword_table[KEYWORD_TABLE_SIZE];
  350. /* Search path. */
  351. struct search_path
  352. {
  353. char *path;
  354. struct search_path *next;
  355. };
  356. struct search_path *search_path;
  357. struct search_path *search_path_tail;
  358. /* Function prototypes. */
  359. static char *matching_regexp (void);
  360. static struct sym *add_sym (const char *, struct sym *);
  361. static void add_global_defn (char *, char *, int, unsigned, int, int, int);
  362. static void add_global_decl (char *, char *, int, unsigned, int, int, int);
  363. static struct member *add_member (struct sym *, char *, int, int, unsigned);
  364. static void class_definition (struct sym *, int, int, int);
  365. static char *operator_name (int *);
  366. static void parse_qualified_param_ident_or_type (char **);
  367. static void usage (int) NO_RETURN;
  368. static void version (void) NO_RETURN;
  369. /***********************************************************************
  370. Utilities
  371. ***********************************************************************/
  372. /* Print an error in a printf-like style with the current input file
  373. name and line number. */
  374. static void
  375. yyerror (const char *format, const char *s)
  376. {
  377. fprintf (stderr, "%s:%d: ", filename, yyline);
  378. fprintf (stderr, format, s);
  379. putc ('\n', stderr);
  380. }
  381. /* Like malloc but print an error and exit if not enough memory is
  382. available. */
  383. static void *
  384. xmalloc (size_t nbytes)
  385. {
  386. void *p = malloc (nbytes);
  387. if (p == NULL)
  388. {
  389. yyerror ("out of memory", NULL);
  390. exit (EXIT_FAILURE);
  391. }
  392. return p;
  393. }
  394. /* Like realloc but print an error and exit if out of memory. */
  395. static void *
  396. xrealloc (void *p, size_t sz)
  397. {
  398. p = realloc (p, sz);
  399. if (p == NULL)
  400. {
  401. yyerror ("out of memory", NULL);
  402. exit (EXIT_FAILURE);
  403. }
  404. return p;
  405. }
  406. /* Like strdup, but print an error and exit if not enough memory is
  407. available.. If S is null, return null. */
  408. static char *
  409. xstrdup (char *s)
  410. {
  411. if (s)
  412. s = strcpy (xmalloc (strlen (s) + 1), s);
  413. return s;
  414. }
  415. /***********************************************************************
  416. Symbols
  417. ***********************************************************************/
  418. /* Initialize the symbol table. This currently only sets up the
  419. special symbol for globals (`*Globals*'). */
  420. static void
  421. init_sym (void)
  422. {
  423. global_symbols = add_sym (GLOBALS_NAME, NULL);
  424. }
  425. /* Add a symbol for class NAME to the symbol table. NESTED_IN_CLASS
  426. is the class in which class NAME was found. If it is null,
  427. this means the scope of NAME is the current namespace.
  428. If a symbol for NAME already exists, return that. Otherwise
  429. create a new symbol and set it to default values. */
  430. static struct sym *
  431. add_sym (const char *name, struct sym *nested_in_class)
  432. {
  433. struct sym *sym;
  434. unsigned h;
  435. const char *s;
  436. struct sym *scope = nested_in_class ? nested_in_class : current_namespace;
  437. for (s = name, h = 0; *s; ++s)
  438. h = (h << 1) ^ *s;
  439. h %= TABLE_SIZE;
  440. for (sym = class_table[h]; sym; sym = sym->next)
  441. if (streq (name, sym->name)
  442. && ((!sym->namesp && !scope)
  443. || (sym->namesp && scope
  444. && streq (sym->namesp->name, scope->name))))
  445. break;
  446. if (sym == NULL)
  447. {
  448. if (f_very_verbose)
  449. {
  450. putchar ('\t');
  451. puts (name);
  452. }
  453. sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
  454. memset (sym, 0, sizeof *sym);
  455. strcpy (sym->name, name);
  456. sym->namesp = scope;
  457. sym->next = class_table[h];
  458. class_table[h] = sym;
  459. }
  460. return sym;
  461. }
  462. /* Add links between superclass SUPER and subclass SUB. */
  463. static void
  464. add_link (struct sym *super, struct sym *sub)
  465. {
  466. struct link *lnk, *lnk2, *p, *prev;
  467. /* See if a link already exists. */
  468. for (p = super->subs, prev = NULL;
  469. p && strcmp (sub->name, p->sym->name) > 0;
  470. prev = p, p = p->next)
  471. ;
  472. /* Avoid duplicates. */
  473. if (p == NULL || p->sym != sub)
  474. {
  475. lnk = (struct link *) xmalloc (sizeof *lnk);
  476. lnk2 = (struct link *) xmalloc (sizeof *lnk2);
  477. lnk->sym = sub;
  478. lnk->next = p;
  479. if (prev)
  480. prev->next = lnk;
  481. else
  482. super->subs = lnk;
  483. lnk2->sym = super;
  484. lnk2->next = sub->supers;
  485. sub->supers = lnk2;
  486. }
  487. }
  488. /* Find in class CLS member NAME.
  489. VAR non-zero means look for a member variable; otherwise a function
  490. is searched. SC specifies what kind of member is searched---a
  491. static, or per-instance member etc. HASH is a hash code for the
  492. parameter types of functions. Value is a pointer to the member
  493. found or null if not found. */
  494. static struct member *
  495. find_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
  496. {
  497. struct member **list;
  498. struct member *p;
  499. unsigned name_hash = 0;
  500. char *s;
  501. int i;
  502. switch (sc)
  503. {
  504. case SC_FRIEND:
  505. list = &cls->friends;
  506. break;
  507. case SC_TYPE:
  508. list = &cls->types;
  509. break;
  510. case SC_STATIC:
  511. list = var ? &cls->static_vars : &cls->static_fns;
  512. break;
  513. default:
  514. list = var ? &cls->vars : &cls->fns;
  515. break;
  516. }
  517. for (s = name; *s; ++s)
  518. name_hash = (name_hash << 1) ^ *s;
  519. i = name_hash % TABLE_SIZE;
  520. for (p = member_table[i]; p; p = p->anext)
  521. if (p->list == list && p->param_hash == hash && streq (name, p->name))
  522. break;
  523. return p;
  524. }
  525. /* Add to class CLS information for the declaration of member NAME.
  526. REGEXP is a regexp matching the declaration, if non-null. POS is
  527. the position in the source where the declaration is found. HASH is
  528. a hash code for the parameter list of the member, if it's a
  529. function. VAR non-zero means member is a variable or type. SC
  530. specifies the type of member (instance member, static, ...). VIS
  531. is the member's visibility (public, protected, private). FLAGS is
  532. a bit set giving additional information about the member (see the
  533. F_* defines). */
  534. static void
  535. add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int vis, int flags)
  536. {
  537. struct member *m;
  538. m = find_member (cls, name, var, sc, hash);
  539. if (m == NULL)
  540. m = add_member (cls, name, var, sc, hash);
  541. /* Have we seen a new filename? If so record that. */
  542. if (!cls->filename || !FILENAME_EQ (cls->filename, filename))
  543. m->filename = filename;
  544. m->regexp = regexp;
  545. m->pos = pos;
  546. m->flags = flags;
  547. switch (vis)
  548. {
  549. case PRIVATE:
  550. m->vis = V_PRIVATE;
  551. break;
  552. case PROTECTED:
  553. m->vis = V_PROTECTED;
  554. break;
  555. case PUBLIC:
  556. m->vis = V_PUBLIC;
  557. break;
  558. }
  559. info_where = P_DECL;
  560. info_cls = cls;
  561. info_member = m;
  562. }
  563. /* Add to class CLS information for the definition of member NAME.
  564. REGEXP is a regexp matching the declaration, if non-null. POS is
  565. the position in the source where the declaration is found. HASH is
  566. a hash code for the parameter list of the member, if it's a
  567. function. VAR non-zero means member is a variable or type. SC
  568. specifies the type of member (instance member, static, ...). VIS
  569. is the member's visibility (public, protected, private). FLAGS is
  570. a bit set giving additional information about the member (see the
  571. F_* defines). */
  572. static void
  573. add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
  574. {
  575. struct member *m;
  576. if (sc == SC_UNKNOWN)
  577. {
  578. m = find_member (cls, name, var, SC_MEMBER, hash);
  579. if (m == NULL)
  580. {
  581. m = find_member (cls, name, var, SC_STATIC, hash);
  582. if (m == NULL)
  583. m = add_member (cls, name, var, sc, hash);
  584. }
  585. }
  586. else
  587. {
  588. m = find_member (cls, name, var, sc, hash);
  589. if (m == NULL)
  590. m = add_member (cls, name, var, sc, hash);
  591. }
  592. if (!cls->sfilename)
  593. cls->sfilename = filename;
  594. if (!FILENAME_EQ (cls->sfilename, filename))
  595. m->def_filename = filename;
  596. m->def_regexp = regexp;
  597. m->def_pos = pos;
  598. m->flags |= flags;
  599. info_where = P_DEFN;
  600. info_cls = cls;
  601. info_member = m;
  602. }
  603. /* Add a symbol for a define named NAME to the symbol table.
  604. REGEXP is a regular expression matching the define in the source,
  605. if it is non-null. POS is the position in the file. */
  606. static void
  607. add_define (char *name, char *regexp, int pos)
  608. {
  609. add_global_defn (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
  610. add_global_decl (name, regexp, pos, 0, 1, SC_FRIEND, F_DEFINE);
  611. }
  612. /* Add information for the global definition of NAME.
  613. REGEXP is a regexp matching the declaration, if non-null. POS is
  614. the position in the source where the declaration is found. HASH is
  615. a hash code for the parameter list of the member, if it's a
  616. function. VAR non-zero means member is a variable or type. SC
  617. specifies the type of member (instance member, static, ...). VIS
  618. is the member's visibility (public, protected, private). FLAGS is
  619. a bit set giving additional information about the member (see the
  620. F_* defines). */
  621. static void
  622. add_global_defn (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
  623. {
  624. int i;
  625. struct sym *sym;
  626. /* Try to find out for which classes a function is a friend, and add
  627. what we know about it to them. */
  628. if (!var)
  629. for (i = 0; i < TABLE_SIZE; ++i)
  630. for (sym = class_table[i]; sym; sym = sym->next)
  631. if (sym != global_symbols && sym->friends)
  632. if (find_member (sym, name, 0, SC_FRIEND, hash))
  633. add_member_defn (sym, name, regexp, pos, hash, 0,
  634. SC_FRIEND, flags);
  635. /* Add to global symbols. */
  636. add_member_defn (global_symbols, name, regexp, pos, hash, var, sc, flags);
  637. }
  638. /* Add information for the global declaration of NAME.
  639. REGEXP is a regexp matching the declaration, if non-null. POS is
  640. the position in the source where the declaration is found. HASH is
  641. a hash code for the parameter list of the member, if it's a
  642. function. VAR non-zero means member is a variable or type. SC
  643. specifies the type of member (instance member, static, ...). VIS
  644. is the member's visibility (public, protected, private). FLAGS is
  645. a bit set giving additional information about the member (see the
  646. F_* defines). */
  647. static void
  648. add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, int sc, int flags)
  649. {
  650. /* Add declaration only if not already declared. Header files must
  651. be processed before source files for this to have the right effect.
  652. I do not want to handle implicit declarations at the moment. */
  653. struct member *m;
  654. struct member *found;
  655. m = found = find_member (global_symbols, name, var, sc, hash);
  656. if (m == NULL)
  657. m = add_member (global_symbols, name, var, sc, hash);
  658. /* Definition already seen => probably last declaration implicit.
  659. Override. This means that declarations must always be added to
  660. the symbol table before definitions. */
  661. if (!found)
  662. {
  663. if (!global_symbols->filename
  664. || !FILENAME_EQ (global_symbols->filename, filename))
  665. m->filename = filename;
  666. m->regexp = regexp;
  667. m->pos = pos;
  668. m->vis = V_PUBLIC;
  669. m->flags = flags;
  670. info_where = P_DECL;
  671. info_cls = global_symbols;
  672. info_member = m;
  673. }
  674. }
  675. /* Add a symbol for member NAME to class CLS.
  676. VAR non-zero means it's a variable. SC specifies the kind of
  677. member. HASH is a hash code for the parameter types of a function.
  678. Value is a pointer to the member's structure. */
  679. static struct member *
  680. add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
  681. {
  682. struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
  683. struct member **list;
  684. struct member *p;
  685. struct member *prev;
  686. unsigned name_hash = 0;
  687. int i;
  688. char *s;
  689. strcpy (m->name, name);
  690. m->param_hash = hash;
  691. m->vis = 0;
  692. m->flags = 0;
  693. m->regexp = NULL;
  694. m->filename = NULL;
  695. m->pos = 0;
  696. m->def_regexp = NULL;
  697. m->def_filename = NULL;
  698. m->def_pos = 0;
  699. assert (cls != NULL);
  700. switch (sc)
  701. {
  702. case SC_FRIEND:
  703. list = &cls->friends;
  704. break;
  705. case SC_TYPE:
  706. list = &cls->types;
  707. break;
  708. case SC_STATIC:
  709. list = var ? &cls->static_vars : &cls->static_fns;
  710. break;
  711. default:
  712. list = var ? &cls->vars : &cls->fns;
  713. break;
  714. }
  715. for (s = name; *s; ++s)
  716. name_hash = (name_hash << 1) ^ *s;
  717. i = name_hash % TABLE_SIZE;
  718. m->anext = member_table[i];
  719. member_table[i] = m;
  720. m->list = list;
  721. /* Keep the member list sorted. It's cheaper to do it here than to
  722. sort them in Lisp. */
  723. for (prev = NULL, p = *list;
  724. p && strcmp (name, p->name) > 0;
  725. prev = p, p = p->next)
  726. ;
  727. m->next = p;
  728. if (prev)
  729. prev->next = m;
  730. else
  731. *list = m;
  732. return m;
  733. }
  734. /* Given the root R of a class tree, step through all subclasses
  735. recursively, marking functions as virtual that are declared virtual
  736. in base classes. */
  737. static void
  738. mark_virtual (struct sym *r)
  739. {
  740. struct link *p;
  741. struct member *m, *m2;
  742. for (p = r->subs; p; p = p->next)
  743. {
  744. for (m = r->fns; m; m = m->next)
  745. if (HAS_FLAG (m->flags, F_VIRTUAL))
  746. {
  747. for (m2 = p->sym->fns; m2; m2 = m2->next)
  748. if (m->param_hash == m2->param_hash && streq (m->name, m2->name))
  749. SET_FLAG (m2->flags, F_VIRTUAL);
  750. }
  751. mark_virtual (p->sym);
  752. }
  753. }
  754. /* For all roots of the class tree, mark functions as virtual that
  755. are virtual because of a virtual declaration in a base class. */
  756. static void
  757. mark_inherited_virtual (void)
  758. {
  759. struct sym *r;
  760. int i;
  761. for (i = 0; i < TABLE_SIZE; ++i)
  762. for (r = class_table[i]; r; r = r->next)
  763. if (r->supers == NULL)
  764. mark_virtual (r);
  765. }
  766. /* Create and return a symbol for a namespace with name NAME. */
  767. static struct sym *
  768. make_namespace (char *name, struct sym *context)
  769. {
  770. struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
  771. memset (s, 0, sizeof *s);
  772. strcpy (s->name, name);
  773. s->next = all_namespaces;
  774. s->namesp = context;
  775. all_namespaces = s;
  776. return s;
  777. }
  778. /* Find the symbol for namespace NAME. If not found, return NULL */
  779. static struct sym *
  780. check_namespace (char *name, struct sym *context)
  781. {
  782. struct sym *p = NULL;
  783. for (p = all_namespaces; p; p = p->next)
  784. {
  785. if (streq (p->name, name) && (p->namesp == context))
  786. break;
  787. }
  788. return p;
  789. }
  790. /* Find the symbol for namespace NAME. If not found, add a new symbol
  791. for NAME to all_namespaces. */
  792. static struct sym *
  793. find_namespace (char *name, struct sym *context)
  794. {
  795. struct sym *p = check_namespace (name, context);
  796. if (p == NULL)
  797. p = make_namespace (name, context);
  798. return p;
  799. }
  800. /* Find namespace alias with name NAME. If not found return NULL. */
  801. static struct link *
  802. check_namespace_alias (char *name)
  803. {
  804. struct link *p = NULL;
  805. struct alias *al;
  806. unsigned h;
  807. char *s;
  808. for (s = name, h = 0; *s; ++s)
  809. h = (h << 1) ^ *s;
  810. h %= TABLE_SIZE;
  811. for (al = namespace_alias_table[h]; al; al = al->next)
  812. if (streq (name, al->name) && (al->namesp == current_namespace))
  813. {
  814. p = al->aliasee;
  815. break;
  816. }
  817. return p;
  818. }
  819. /* Register the name NEW_NAME as an alias for namespace list OLD_NAME. */
  820. static void
  821. register_namespace_alias (char *new_name, struct link *old_name)
  822. {
  823. unsigned h;
  824. char *s;
  825. struct alias *al;
  826. for (s = new_name, h = 0; *s; ++s)
  827. h = (h << 1) ^ *s;
  828. h %= TABLE_SIZE;
  829. /* Is it already in the table of aliases? */
  830. for (al = namespace_alias_table[h]; al; al = al->next)
  831. if (streq (new_name, al->name) && (al->namesp == current_namespace))
  832. return;
  833. al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
  834. strcpy (al->name, new_name);
  835. al->next = namespace_alias_table[h];
  836. al->namesp = current_namespace;
  837. al->aliasee = old_name;
  838. namespace_alias_table[h] = al;
  839. }
  840. /* Enter namespace with name NAME. */
  841. static void
  842. enter_namespace (char *name)
  843. {
  844. struct sym *p = find_namespace (name, current_namespace);
  845. if (namespace_sp == namespace_stack_size)
  846. {
  847. int size = max (10, 2 * namespace_stack_size);
  848. namespace_stack
  849. = (struct sym **) xrealloc ((void *)namespace_stack,
  850. size * sizeof *namespace_stack);
  851. namespace_stack_size = size;
  852. }
  853. namespace_stack[namespace_sp++] = current_namespace;
  854. current_namespace = p;
  855. }
  856. /* Leave the current namespace. */
  857. static void
  858. leave_namespace (void)
  859. {
  860. assert (namespace_sp > 0);
  861. current_namespace = namespace_stack[--namespace_sp];
  862. }
  863. /***********************************************************************
  864. Writing the Output File
  865. ***********************************************************************/
  866. /* Write string S to the output file FP in a Lisp-readable form.
  867. If S is null, write out `()'. */
  868. static inline void
  869. putstr (const char *s, FILE *fp)
  870. {
  871. if (!s)
  872. {
  873. putc ('(', fp);
  874. putc (')', fp);
  875. putc (' ', fp);
  876. }
  877. else
  878. {
  879. putc ('"', fp);
  880. fputs (s, fp);
  881. putc ('"', fp);
  882. putc (' ', fp);
  883. }
  884. }
  885. /* A dynamically allocated buffer for constructing a scope name. */
  886. char *scope_buffer;
  887. int scope_buffer_size;
  888. int scope_buffer_len;
  889. /* Make sure scope_buffer has enough room to add LEN chars to it. */
  890. static void
  891. ensure_scope_buffer_room (int len)
  892. {
  893. if (scope_buffer_len + len >= scope_buffer_size)
  894. {
  895. int new_size = max (2 * scope_buffer_size, scope_buffer_len + len);
  896. scope_buffer = (char *) xrealloc (scope_buffer, new_size);
  897. scope_buffer_size = new_size;
  898. }
  899. }
  900. /* Recursively add the scope names of symbol P and the scopes of its
  901. namespaces to scope_buffer. Value is a pointer to the complete
  902. scope name constructed. */
  903. static char *
  904. sym_scope_1 (struct sym *p)
  905. {
  906. int len;
  907. if (p->namesp)
  908. sym_scope_1 (p->namesp);
  909. if (*scope_buffer)
  910. {
  911. ensure_scope_buffer_room (3);
  912. strcat (scope_buffer, "::");
  913. scope_buffer_len += 2;
  914. }
  915. len = strlen (p->name);
  916. ensure_scope_buffer_room (len + 1);
  917. strcat (scope_buffer, p->name);
  918. scope_buffer_len += len;
  919. if (HAS_FLAG (p->flags, F_TEMPLATE))
  920. {
  921. ensure_scope_buffer_room (3);
  922. strcat (scope_buffer, "<>");
  923. scope_buffer_len += 2;
  924. }
  925. return scope_buffer;
  926. }
  927. /* Return the scope of symbol P in printed representation, i.e.
  928. as it would appear in a C*+ source file. */
  929. static char *
  930. sym_scope (struct sym *p)
  931. {
  932. if (!scope_buffer)
  933. {
  934. scope_buffer_size = 1024;
  935. scope_buffer = (char *) xmalloc (scope_buffer_size);
  936. }
  937. *scope_buffer = '\0';
  938. scope_buffer_len = 0;
  939. if (p->namesp)
  940. sym_scope_1 (p->namesp);
  941. return scope_buffer;
  942. }
  943. /* Dump the list of members M to file FP. Value is the length of the
  944. list. */
  945. static int
  946. dump_members (FILE *fp, struct member *m)
  947. {
  948. int n;
  949. putc ('(', fp);
  950. for (n = 0; m; m = m->next, ++n)
  951. {
  952. fputs (MEMBER_STRUCT, fp);
  953. putstr (m->name, fp);
  954. putstr (NULL, fp); /* FIXME? scope for globals */
  955. fprintf (fp, "%u ", (unsigned) m->flags);
  956. putstr (m->filename, fp);
  957. putstr (m->regexp, fp);
  958. fprintf (fp, "%u ", (unsigned) m->pos);
  959. fprintf (fp, "%u ", (unsigned) m->vis);
  960. putc (' ', fp);
  961. putstr (m->def_filename, fp);
  962. putstr (m->def_regexp, fp);
  963. fprintf (fp, "%u", (unsigned) m->def_pos);
  964. putc (']', fp);
  965. putc ('\n', fp);
  966. }
  967. putc (')', fp);
  968. putc ('\n', fp);
  969. return n;
  970. }
  971. /* Dump class ROOT to stream FP. */
  972. static void
  973. dump_sym (FILE *fp, struct sym *root)
  974. {
  975. fputs (CLASS_STRUCT, fp);
  976. putstr (root->name, fp);
  977. /* Print scope, if any. */
  978. if (root->namesp)
  979. putstr (sym_scope (root), fp);
  980. else
  981. putstr (NULL, fp);
  982. /* Print flags. */
  983. fprintf (fp, "%u", root->flags);
  984. putstr (root->filename, fp);
  985. putstr (root->regexp, fp);
  986. fprintf (fp, "%u", (unsigned) root->pos);
  987. putstr (root->sfilename, fp);
  988. putc (']', fp);
  989. putc ('\n', fp);
  990. }
  991. /* Dump class ROOT and its subclasses to file FP. Value is the
  992. number of classes written. */
  993. static int
  994. dump_tree (FILE *fp, struct sym *root)
  995. {
  996. struct link *lk;
  997. unsigned n = 0;
  998. dump_sym (fp, root);
  999. if (f_verbose)
  1000. {
  1001. putchar ('+');
  1002. fflush (stdout);
  1003. }
  1004. putc ('(', fp);
  1005. for (lk = root->subs; lk; lk = lk->next)
  1006. {
  1007. fputs (TREE_STRUCT, fp);
  1008. n += dump_tree (fp, lk->sym);
  1009. putc (']', fp);
  1010. }
  1011. putc (')', fp);
  1012. dump_members (fp, root->vars);
  1013. n += dump_members (fp, root->fns);
  1014. dump_members (fp, root->static_vars);
  1015. n += dump_members (fp, root->static_fns);
  1016. n += dump_members (fp, root->friends);
  1017. dump_members (fp, root->types);
  1018. /* Superclasses. */
  1019. putc ('(', fp);
  1020. putc (')', fp);
  1021. /* Mark slot. */
  1022. putc ('(', fp);
  1023. putc (')', fp);
  1024. putc ('\n', fp);
  1025. return n;
  1026. }
  1027. /* Dump the entire class tree to file FP. */
  1028. static void
  1029. dump_roots (FILE *fp)
  1030. {
  1031. int i, n = 0;
  1032. struct sym *r;
  1033. /* Output file header containing version string, command line
  1034. options etc. */
  1035. if (!f_append)
  1036. {
  1037. fputs (TREE_HEADER_STRUCT, fp);
  1038. putstr (EBROWSE_FILE_VERSION, fp);
  1039. putc ('\"', fp);
  1040. if (!f_structs)
  1041. fputs (" -s", fp);
  1042. if (f_regexps)
  1043. fputs (" -x", fp);
  1044. putc ('\"', fp);
  1045. fputs (" ()", fp);
  1046. fputs (" ()", fp);
  1047. putc (']', fp);
  1048. }
  1049. /* Mark functions as virtual that are so because of functions
  1050. declared virtual in base classes. */
  1051. mark_inherited_virtual ();
  1052. /* Dump the roots of the graph. */
  1053. for (i = 0; i < TABLE_SIZE; ++i)
  1054. for (r = class_table[i]; r; r = r->next)
  1055. if (!r->supers)
  1056. {
  1057. fputs (TREE_STRUCT, fp);
  1058. n += dump_tree (fp, r);
  1059. putc (']', fp);
  1060. }
  1061. if (f_verbose)
  1062. putchar ('\n');
  1063. }
  1064. /***********************************************************************
  1065. Scanner
  1066. ***********************************************************************/
  1067. #ifdef DEBUG
  1068. #define INCREMENT_LINENO \
  1069. do { \
  1070. if (f_very_verbose) \
  1071. { \
  1072. ++yyline; \
  1073. printf ("%d:\n", yyline); \
  1074. } \
  1075. else \
  1076. ++yyline; \
  1077. } while (0)
  1078. #else
  1079. #define INCREMENT_LINENO ++yyline
  1080. #endif
  1081. /* Define two macros for accessing the input buffer (current input
  1082. file). GET(C) sets C to the next input character and advances the
  1083. input pointer. UNGET retracts the input pointer. */
  1084. #define GET(C) ((C) = *in++)
  1085. #define UNGET() (--in)
  1086. /* Process a preprocessor line. Value is the next character from the
  1087. input buffer not consumed. */
  1088. static int
  1089. process_pp_line (void)
  1090. {
  1091. int in_comment = 0, in_string = 0;
  1092. int c;
  1093. char *p = yytext;
  1094. /* Skip over white space. The `#' has been consumed already. */
  1095. while (WHITEP (GET (c)))
  1096. ;
  1097. /* Read the preprocessor command (if any). */
  1098. while (IDENTP (c))
  1099. {
  1100. *p++ = c;
  1101. GET (c);
  1102. }
  1103. /* Is it a `define'? */
  1104. *p = '\0';
  1105. if (*yytext && streq (yytext, "define"))
  1106. {
  1107. p = yytext;
  1108. while (WHITEP (c))
  1109. GET (c);
  1110. while (IDENTP (c))
  1111. {
  1112. *p++ = c;
  1113. GET (c);
  1114. }
  1115. *p = '\0';
  1116. if (*yytext)
  1117. {
  1118. char *regexp = matching_regexp ();
  1119. int pos = BUFFER_POS ();
  1120. add_define (yytext, regexp, pos);
  1121. }
  1122. }
  1123. while (c && (c != '\n' || in_comment || in_string))
  1124. {
  1125. if (c == '\\')
  1126. GET (c);
  1127. else if (c == '/' && !in_comment)
  1128. {
  1129. if (GET (c) == '*')
  1130. in_comment = 1;
  1131. }
  1132. else if (c == '*' && in_comment)
  1133. {
  1134. if (GET (c) == '/')
  1135. in_comment = 0;
  1136. }
  1137. else if (c == '"')
  1138. in_string = !in_string;
  1139. if (c == '\n')
  1140. INCREMENT_LINENO;
  1141. GET (c);
  1142. }
  1143. return c;
  1144. }
  1145. /* Value is the next token from the input buffer. */
  1146. static int
  1147. yylex (void)
  1148. {
  1149. int c;
  1150. char end_char;
  1151. char *p;
  1152. for (;;)
  1153. {
  1154. while (WHITEP (GET (c)))
  1155. ;
  1156. switch (c)
  1157. {
  1158. case '\n':
  1159. INCREMENT_LINENO;
  1160. break;
  1161. case '\r':
  1162. break;
  1163. case 0:
  1164. /* End of file. */
  1165. return YYEOF;
  1166. case '\\':
  1167. GET (c);
  1168. break;
  1169. case '"':
  1170. case '\'':
  1171. /* String and character constants. */
  1172. end_char = c;
  1173. string_start = in;
  1174. while (GET (c) && c != end_char)
  1175. {
  1176. switch (c)
  1177. {
  1178. case '\\':
  1179. /* Escape sequences. */
  1180. if (!GET (c))
  1181. {
  1182. if (end_char == '\'')
  1183. yyerror ("EOF in character constant", NULL);
  1184. else
  1185. yyerror ("EOF in string constant", NULL);
  1186. goto end_string;
  1187. }
  1188. else switch (c)
  1189. {
  1190. case '\n':
  1191. INCREMENT_LINENO;
  1192. case 'a':
  1193. case 'b':
  1194. case 'f':
  1195. case 'n':
  1196. case 'r':
  1197. case 't':
  1198. case 'v':
  1199. break;
  1200. case 'x':
  1201. {
  1202. /* Hexadecimal escape sequence. */
  1203. int i;
  1204. for (i = 0; i < 2; ++i)
  1205. {
  1206. GET (c);
  1207. if (c >= '0' && c <= '7')
  1208. ;
  1209. else if (c >= 'a' && c <= 'f')
  1210. ;
  1211. else if (c >= 'A' && c <= 'F')
  1212. ;
  1213. else
  1214. {
  1215. UNGET ();
  1216. break;
  1217. }
  1218. }
  1219. }
  1220. break;
  1221. case '0':
  1222. {
  1223. /* Octal escape sequence. */
  1224. int i;
  1225. for (i = 0; i < 3; ++i)
  1226. {
  1227. GET (c);
  1228. if (c >= '0' && c <= '7')
  1229. ;
  1230. else
  1231. {
  1232. UNGET ();
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. break;
  1238. default:
  1239. break;
  1240. }
  1241. break;
  1242. case '\n':
  1243. if (end_char == '\'')
  1244. yyerror ("newline in character constant", NULL);
  1245. else
  1246. yyerror ("newline in string constant", NULL);
  1247. INCREMENT_LINENO;
  1248. break;
  1249. default:
  1250. break;
  1251. }
  1252. }
  1253. end_string:
  1254. return end_char == '\'' ? CCHAR : CSTRING;
  1255. case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
  1256. case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
  1257. case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
  1258. case 'v': case 'w': case 'x': case 'y': case 'z':
  1259. case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
  1260. case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
  1261. case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
  1262. case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_':
  1263. {
  1264. /* Identifier and keywords. */
  1265. unsigned hash;
  1266. struct kw *k;
  1267. p = yytext;
  1268. *p++ = hash = c;
  1269. while (IDENTP (GET (*p)))
  1270. {
  1271. hash = (hash << 1) ^ *p++;
  1272. if (p == yytext_end - 1)
  1273. {
  1274. int size = yytext_end - yytext;
  1275. yytext = (char *) xrealloc (yytext, 2 * size);
  1276. yytext_end = yytext + 2 * size;
  1277. p = yytext + size - 1;
  1278. }
  1279. }
  1280. UNGET ();
  1281. *p = 0;
  1282. for (k = keyword_table[hash % KEYWORD_TABLE_SIZE]; k; k = k->next)
  1283. if (streq (k->name, yytext))
  1284. return k->tk;
  1285. return IDENT;
  1286. }
  1287. case '/':
  1288. /* C and C++ comments, '/' and '/='. */
  1289. switch (GET (c))
  1290. {
  1291. case '*':
  1292. while (GET (c))
  1293. {
  1294. switch (c)
  1295. {
  1296. case '*':
  1297. if (GET (c) == '/')
  1298. goto comment_end;
  1299. UNGET ();
  1300. break;
  1301. case '\\':
  1302. GET (c);
  1303. break;
  1304. case '\n':
  1305. INCREMENT_LINENO;
  1306. break;
  1307. }
  1308. }
  1309. comment_end:;
  1310. break;
  1311. case '=':
  1312. return DIVASGN;
  1313. case '/':
  1314. while (GET (c) && c != '\n')
  1315. ;
  1316. /* Don't try to read past the end of the input buffer if
  1317. the file ends in a C++ comment without a newline. */
  1318. if (c == 0)
  1319. return YYEOF;
  1320. INCREMENT_LINENO;
  1321. break;
  1322. default:
  1323. UNGET ();
  1324. return '/';
  1325. }
  1326. break;
  1327. case '+':
  1328. if (GET (c) == '+')
  1329. return INC;
  1330. else if (c == '=')
  1331. return ADDASGN;
  1332. UNGET ();
  1333. return '+';
  1334. case '-':
  1335. switch (GET (c))
  1336. {
  1337. case '-':
  1338. return DEC;
  1339. case '>':
  1340. if (GET (c) == '*')
  1341. return ARROWSTAR;
  1342. UNGET ();
  1343. return ARROW;
  1344. case '=':
  1345. return SUBASGN;
  1346. }
  1347. UNGET ();
  1348. return '-';
  1349. case '*':
  1350. if (GET (c) == '=')
  1351. return MULASGN;
  1352. UNGET ();
  1353. return '*';
  1354. case '%':
  1355. if (GET (c) == '=')
  1356. return MODASGN;
  1357. UNGET ();
  1358. return '%';
  1359. case '|':
  1360. if (GET (c) == '|')
  1361. return LOR;
  1362. else if (c == '=')
  1363. return ORASGN;
  1364. UNGET ();
  1365. return '|';
  1366. case '&':
  1367. if (GET (c) == '&')
  1368. return LAND;
  1369. else if (c == '=')
  1370. return ANDASGN;
  1371. UNGET ();
  1372. return '&';
  1373. case '^':
  1374. if (GET (c) == '=')
  1375. return XORASGN;
  1376. UNGET ();
  1377. return '^';
  1378. case '.':
  1379. if (GET (c) == '*')
  1380. return POINTSTAR;
  1381. else if (c == '.')
  1382. {
  1383. if (GET (c) != '.')
  1384. yyerror ("invalid token '..' ('...' assumed)", NULL);
  1385. UNGET ();
  1386. return ELLIPSIS;
  1387. }
  1388. else if (!DIGITP (c))
  1389. {
  1390. UNGET ();
  1391. return '.';
  1392. }
  1393. goto mantissa;
  1394. case ':':
  1395. if (GET (c) == ':')
  1396. return DCOLON;
  1397. UNGET ();
  1398. return ':';
  1399. case '=':
  1400. if (GET (c) == '=')
  1401. return EQ;
  1402. UNGET ();
  1403. return '=';
  1404. case '!':
  1405. if (GET (c) == '=')
  1406. return NE;
  1407. UNGET ();
  1408. return '!';
  1409. case '<':
  1410. switch (GET (c))
  1411. {
  1412. case '=':
  1413. return LE;
  1414. case '<':
  1415. if (GET (c) == '=')
  1416. return LSHIFTASGN;
  1417. UNGET ();
  1418. return LSHIFT;
  1419. }
  1420. UNGET ();
  1421. return '<';
  1422. case '>':
  1423. switch (GET (c))
  1424. {
  1425. case '=':
  1426. return GE;
  1427. case '>':
  1428. if (GET (c) == '=')
  1429. return RSHIFTASGN;
  1430. UNGET ();
  1431. return RSHIFT;
  1432. }
  1433. UNGET ();
  1434. return '>';
  1435. case '#':
  1436. c = process_pp_line ();
  1437. if (c == 0)
  1438. return YYEOF;
  1439. break;
  1440. case '(': case ')': case '[': case ']': case '{': case '}':
  1441. case ';': case ',': case '?': case '~':
  1442. return c;
  1443. case '0':
  1444. yyival = 0;
  1445. if (GET (c) == 'x' || c == 'X')
  1446. {
  1447. while (GET (c))
  1448. {
  1449. if (DIGITP (c))
  1450. yyival = yyival * 16 + c - '0';
  1451. else if (c >= 'a' && c <= 'f')
  1452. yyival = yyival * 16 + c - 'a' + 10;
  1453. else if (c >= 'A' && c <= 'F')
  1454. yyival = yyival * 16 + c - 'A' + 10;
  1455. else
  1456. break;
  1457. }
  1458. goto int_suffixes;
  1459. }
  1460. else if (c == '.')
  1461. goto mantissa;
  1462. while (c >= '0' && c <= '7')
  1463. {
  1464. yyival = (yyival << 3) + c - '0';
  1465. GET (c);
  1466. }
  1467. int_suffixes:
  1468. /* Integer suffixes. */
  1469. while (isalpha (c))
  1470. GET (c);
  1471. UNGET ();
  1472. return CINT;
  1473. case '1': case '2': case '3': case '4': case '5': case '6':
  1474. case '7': case '8': case '9':
  1475. /* Integer or floating constant, part before '.'. */
  1476. yyival = c - '0';
  1477. while (GET (c) && DIGITP (c))
  1478. yyival = 10 * yyival + c - '0';
  1479. if (c != '.')
  1480. goto int_suffixes;
  1481. mantissa:
  1482. /* Digits following '.'. */
  1483. while (DIGITP (c))
  1484. GET (c);
  1485. /* Optional exponent. */
  1486. if (c == 'E' || c == 'e')
  1487. {
  1488. if (GET (c) == '-' || c == '+')
  1489. GET (c);
  1490. while (DIGITP (c))
  1491. GET (c);
  1492. }
  1493. /* Optional type suffixes. */
  1494. while (isalpha (c))
  1495. GET (c);
  1496. UNGET ();
  1497. return CFLOAT;
  1498. default:
  1499. break;
  1500. }
  1501. }
  1502. }
  1503. /* Actually local to matching_regexp. These variables must be in
  1504. global scope for the case that `static' get's defined away. */
  1505. static char *matching_regexp_buffer, *matching_regexp_end_buf;
  1506. /* Value is the string from the start of the line to the current
  1507. position in the input buffer, or maybe a bit more if that string is
  1508. shorter than min_regexp. */
  1509. static char *
  1510. matching_regexp (void)
  1511. {
  1512. char *p;
  1513. char *s;
  1514. char *t;
  1515. if (!f_regexps)
  1516. return NULL;
  1517. if (matching_regexp_buffer == NULL)
  1518. {
  1519. matching_regexp_buffer = (char *) xmalloc (max_regexp);
  1520. matching_regexp_end_buf = &matching_regexp_buffer[max_regexp] - 1;
  1521. }
  1522. /* Scan back to previous newline of buffer start. */
  1523. for (p = in - 1; p > inbuffer && *p != '\n'; --p)
  1524. ;
  1525. if (*p == '\n')
  1526. {
  1527. while (in - p < min_regexp && p > inbuffer)
  1528. {
  1529. /* Line probably not significant enough */
  1530. for (--p; p > inbuffer && *p != '\n'; --p)
  1531. ;
  1532. }
  1533. if (*p == '\n')
  1534. ++p;
  1535. }
  1536. /* Copy from end to make sure significant portions are included.
  1537. This implies that in the browser a regular expressing of the form
  1538. `^.*{regexp}' has to be used. */
  1539. for (s = matching_regexp_end_buf - 1, t = in;
  1540. s > matching_regexp_buffer && t > p;)
  1541. {
  1542. *--s = *--t;
  1543. if (*s == '"' || *s == '\\')
  1544. *--s = '\\';
  1545. }
  1546. *(matching_regexp_end_buf - 1) = '\0';
  1547. return xstrdup (s);
  1548. }
  1549. /* Return a printable representation of token T. */
  1550. static const char *
  1551. token_string (int t)
  1552. {
  1553. static char b[3];
  1554. switch (t)
  1555. {
  1556. case CSTRING: return "string constant";
  1557. case CCHAR: return "char constant";
  1558. case CINT: return "int constant";
  1559. case CFLOAT: return "floating constant";
  1560. case ELLIPSIS: return "...";
  1561. case LSHIFTASGN: return "<<=";
  1562. case RSHIFTASGN: return ">>=";
  1563. case ARROWSTAR: return "->*";
  1564. case IDENT: return "identifier";
  1565. case DIVASGN: return "/=";
  1566. case INC: return "++";
  1567. case ADDASGN: return "+=";
  1568. case DEC: return "--";
  1569. case ARROW: return "->";
  1570. case SUBASGN: return "-=";
  1571. case MULASGN: return "*=";
  1572. case MODASGN: return "%=";
  1573. case LOR: return "||";
  1574. case ORASGN: return "|=";
  1575. case LAND: return "&&";
  1576. case ANDASGN: return "&=";
  1577. case XORASGN: return "^=";
  1578. case POINTSTAR: return ".*";
  1579. case DCOLON: return "::";
  1580. case EQ: return "==";
  1581. case NE: return "!=";
  1582. case LE: return "<=";
  1583. case LSHIFT: return "<<";
  1584. case GE: return ">=";
  1585. case RSHIFT: return ">>";
  1586. case ASM: return "asm";
  1587. case AUTO: return "auto";
  1588. case BREAK: return "break";
  1589. case CASE: return "case";
  1590. case CATCH: return "catch";
  1591. case CHAR: return "char";
  1592. case CLASS: return "class";
  1593. case CONST: return "const";
  1594. case CONTINUE: return "continue";
  1595. case DEFAULT: return "default";
  1596. case DELETE: return "delete";
  1597. case DO: return "do";
  1598. case DOUBLE: return "double";
  1599. case ELSE: return "else";
  1600. case ENUM: return "enum";
  1601. case EXTERN: return "extern";
  1602. case FLOAT: return "float";
  1603. case FOR: return "for";
  1604. case FRIEND: return "friend";
  1605. case GOTO: return "goto";
  1606. case IF: return "if";
  1607. case T_INLINE: return "inline";
  1608. case INT: return "int";
  1609. case LONG: return "long";
  1610. case NEW: return "new";
  1611. case OPERATOR: return "operator";
  1612. case PRIVATE: return "private";
  1613. case PROTECTED: return "protected";
  1614. case PUBLIC: return "public";
  1615. case REGISTER: return "register";
  1616. case RETURN: return "return";
  1617. case SHORT: return "short";
  1618. case SIGNED: return "signed";
  1619. case SIZEOF: return "sizeof";
  1620. case STATIC: return "static";
  1621. case STRUCT: return "struct";
  1622. case SWITCH: return "switch";
  1623. case TEMPLATE: return "template";
  1624. case THIS: return "this";
  1625. case THROW: return "throw";
  1626. case TRY: return "try";
  1627. case TYPEDEF: return "typedef";
  1628. case UNION: return "union";
  1629. case UNSIGNED: return "unsigned";
  1630. case VIRTUAL: return "virtual";
  1631. case VOID: return "void";
  1632. case VOLATILE: return "volatile";
  1633. case WHILE: return "while";
  1634. case MUTABLE: return "mutable";
  1635. case BOOL: return "bool";
  1636. case TRUE: return "true";
  1637. case FALSE: return "false";
  1638. case SIGNATURE: return "signature";
  1639. case NAMESPACE: return "namespace";
  1640. case EXPLICIT: return "explicit";
  1641. case TYPENAME: return "typename";
  1642. case CONST_CAST: return "const_cast";
  1643. case DYNAMIC_CAST: return "dynamic_cast";
  1644. case REINTERPRET_CAST: return "reinterpret_cast";
  1645. case STATIC_CAST: return "static_cast";
  1646. case TYPEID: return "typeid";
  1647. case USING: return "using";
  1648. case WCHAR: return "wchar_t";
  1649. case YYEOF: return "EOF";
  1650. default:
  1651. if (t < 255)
  1652. {
  1653. b[0] = t;
  1654. b[1] = '\0';
  1655. return b;
  1656. }
  1657. else
  1658. return "???";
  1659. }
  1660. }
  1661. /* Reinitialize the scanner for a new input file. */
  1662. static void
  1663. re_init_scanner (void)
  1664. {
  1665. in = inbuffer;
  1666. yyline = 1;
  1667. if (yytext == NULL)
  1668. {
  1669. int size = 256;
  1670. yytext = (char *) xmalloc (size * sizeof *yytext);
  1671. yytext_end = yytext + size;
  1672. }
  1673. }
  1674. /* Insert a keyword NAME with token value TKV into the keyword hash
  1675. table. */
  1676. static void
  1677. insert_keyword (const char *name, int tkv)
  1678. {
  1679. const char *s;
  1680. unsigned h = 0;
  1681. struct kw *k = (struct kw *) xmalloc (sizeof *k);
  1682. for (s = name; *s; ++s)
  1683. h = (h << 1) ^ *s;
  1684. h %= KEYWORD_TABLE_SIZE;
  1685. k->name = name;
  1686. k->tk = tkv;
  1687. k->next = keyword_table[h];
  1688. keyword_table[h] = k;
  1689. }
  1690. /* Initialize the scanner for the first file. This sets up the
  1691. character class vectors and fills the keyword hash table. */
  1692. static void
  1693. init_scanner (void)
  1694. {
  1695. int i;
  1696. /* Allocate the input buffer */
  1697. inbuffer_size = READ_CHUNK_SIZE + 1;
  1698. inbuffer = in = (char *) xmalloc (inbuffer_size);
  1699. yyline = 1;
  1700. /* Set up character class vectors. */
  1701. for (i = 0; i < sizeof is_ident; ++i)
  1702. {
  1703. if (i == '_' || isalnum (i))
  1704. is_ident[i] = 1;
  1705. if (i >= '0' && i <= '9')
  1706. is_digit[i] = 1;
  1707. if (i == ' ' || i == '\t' || i == '\f' || i == '\v')
  1708. is_white[i] = 1;
  1709. }
  1710. /* Fill keyword hash table. */
  1711. insert_keyword ("and", LAND);
  1712. insert_keyword ("and_eq", ANDASGN);
  1713. insert_keyword ("asm", ASM);
  1714. insert_keyword ("auto", AUTO);
  1715. insert_keyword ("bitand", '&');
  1716. insert_keyword ("bitor", '|');
  1717. insert_keyword ("bool", BOOL);
  1718. insert_keyword ("break", BREAK);
  1719. insert_keyword ("case", CASE);
  1720. insert_keyword ("catch", CATCH);
  1721. insert_keyword ("char", CHAR);
  1722. insert_keyword ("class", CLASS);
  1723. insert_keyword ("compl", '~');
  1724. insert_keyword ("const", CONST);
  1725. insert_keyword ("const_cast", CONST_CAST);
  1726. insert_keyword ("continue", CONTINUE);
  1727. insert_keyword ("default", DEFAULT);
  1728. insert_keyword ("delete", DELETE);
  1729. insert_keyword ("do", DO);
  1730. insert_keyword ("double", DOUBLE);
  1731. insert_keyword ("dynamic_cast", DYNAMIC_CAST);
  1732. insert_keyword ("else", ELSE);
  1733. insert_keyword ("enum", ENUM);
  1734. insert_keyword ("explicit", EXPLICIT);
  1735. insert_keyword ("extern", EXTERN);
  1736. insert_keyword ("false", FALSE);
  1737. insert_keyword ("float", FLOAT);
  1738. insert_keyword ("for", FOR);
  1739. insert_keyword ("friend", FRIEND);
  1740. insert_keyword ("goto", GOTO);
  1741. insert_keyword ("if", IF);
  1742. insert_keyword ("inline", T_INLINE);
  1743. insert_keyword ("int", INT);
  1744. insert_keyword ("long", LONG);
  1745. insert_keyword ("mutable", MUTABLE);
  1746. insert_keyword ("namespace", NAMESPACE);
  1747. insert_keyword ("new", NEW);
  1748. insert_keyword ("not", '!');
  1749. insert_keyword ("not_eq", NE);
  1750. insert_keyword ("operator", OPERATOR);
  1751. insert_keyword ("or", LOR);
  1752. insert_keyword ("or_eq", ORASGN);
  1753. insert_keyword ("private", PRIVATE);
  1754. insert_keyword ("protected", PROTECTED);
  1755. insert_keyword ("public", PUBLIC);
  1756. insert_keyword ("register", REGISTER);
  1757. insert_keyword ("reinterpret_cast", REINTERPRET_CAST);
  1758. insert_keyword ("return", RETURN);
  1759. insert_keyword ("short", SHORT);
  1760. insert_keyword ("signed", SIGNED);
  1761. insert_keyword ("sizeof", SIZEOF);
  1762. insert_keyword ("static", STATIC);
  1763. insert_keyword ("static_cast", STATIC_CAST);
  1764. insert_keyword ("struct", STRUCT);
  1765. insert_keyword ("switch", SWITCH);
  1766. insert_keyword ("template", TEMPLATE);
  1767. insert_keyword ("this", THIS);
  1768. insert_keyword ("throw", THROW);
  1769. insert_keyword ("true", TRUE);
  1770. insert_keyword ("try", TRY);
  1771. insert_keyword ("typedef", TYPEDEF);
  1772. insert_keyword ("typeid", TYPEID);
  1773. insert_keyword ("typename", TYPENAME);
  1774. insert_keyword ("union", UNION);
  1775. insert_keyword ("unsigned", UNSIGNED);
  1776. insert_keyword ("using", USING);
  1777. insert_keyword ("virtual", VIRTUAL);
  1778. insert_keyword ("void", VOID);
  1779. insert_keyword ("volatile", VOLATILE);
  1780. insert_keyword ("wchar_t", WCHAR);
  1781. insert_keyword ("while", WHILE);
  1782. insert_keyword ("xor", '^');
  1783. insert_keyword ("xor_eq", XORASGN);
  1784. }
  1785. /***********************************************************************
  1786. Parser
  1787. ***********************************************************************/
  1788. /* Match the current lookahead token and set it to the next token. */
  1789. #define MATCH() (tk = yylex ())
  1790. /* Return the lookahead token. If current lookahead token is cleared,
  1791. read a new token. */
  1792. #define LA1 (tk == -1 ? (tk = yylex ()) : tk)
  1793. /* Is the current lookahead equal to the token T? */
  1794. #define LOOKING_AT(T) (tk == (T))
  1795. /* Is the current lookahead one of T1 or T2? */
  1796. #define LOOKING_AT2(T1, T2) (tk == (T1) || tk == (T2))
  1797. /* Is the current lookahead one of T1, T2 or T3? */
  1798. #define LOOKING_AT3(T1, T2, T3) (tk == (T1) || tk == (T2) || tk == (T3))
  1799. /* Is the current lookahead one of T1...T4? */
  1800. #define LOOKING_AT4(T1, T2, T3, T4) \
  1801. (tk == (T1) || tk == (T2) || tk == (T3) || tk == (T4))
  1802. /* Match token T if current lookahead is T. */
  1803. #define MATCH_IF(T) if (LOOKING_AT (T)) MATCH (); else ((void) 0)
  1804. /* Skip to matching token if current token is T. */
  1805. #define SKIP_MATCHING_IF(T) \
  1806. if (LOOKING_AT (T)) skip_matching (); else ((void) 0)
  1807. /* Skip forward until a given token TOKEN or YYEOF is seen and return
  1808. the current lookahead token after skipping. */
  1809. static int
  1810. skip_to (int token)
  1811. {
  1812. while (!LOOKING_AT2 (YYEOF, token))
  1813. MATCH ();
  1814. return tk;
  1815. }
  1816. /* Skip over pairs of tokens (parentheses, square brackets,
  1817. angle brackets, curly brackets) matching the current lookahead. */
  1818. static void
  1819. skip_matching (void)
  1820. {
  1821. int open, close, n;
  1822. switch (open = LA1)
  1823. {
  1824. case '{':
  1825. close = '}';
  1826. break;
  1827. case '(':
  1828. close = ')';
  1829. break;
  1830. case '<':
  1831. close = '>';
  1832. break;
  1833. case '[':
  1834. close = ']';
  1835. break;
  1836. default:
  1837. abort ();
  1838. }
  1839. for (n = 0;;)
  1840. {
  1841. if (LOOKING_AT (open))
  1842. ++n;
  1843. else if (LOOKING_AT (close))
  1844. --n;
  1845. else if (LOOKING_AT (YYEOF))
  1846. break;
  1847. MATCH ();
  1848. if (n == 0)
  1849. break;
  1850. }
  1851. }
  1852. static void
  1853. skip_initializer (void)
  1854. {
  1855. for (;;)
  1856. {
  1857. switch (LA1)
  1858. {
  1859. case ';':
  1860. case ',':
  1861. case YYEOF:
  1862. return;
  1863. case '{':
  1864. case '[':
  1865. case '(':
  1866. skip_matching ();
  1867. break;
  1868. default:
  1869. MATCH ();
  1870. break;
  1871. }
  1872. }
  1873. }
  1874. /* Build qualified namespace alias (A::B::c) and return it. */
  1875. static struct link *
  1876. match_qualified_namespace_alias (void)
  1877. {
  1878. struct link *head = NULL;
  1879. struct link *cur = NULL;
  1880. struct link *tmp = NULL;
  1881. for (;;)
  1882. {
  1883. MATCH ();
  1884. switch (LA1)
  1885. {
  1886. case IDENT:
  1887. tmp = (struct link *) xmalloc (sizeof *cur);
  1888. tmp->sym = find_namespace (yytext, cur ? cur->sym : NULL);
  1889. tmp->next = NULL;
  1890. if (head)
  1891. {
  1892. cur = cur->next = tmp;
  1893. }
  1894. else
  1895. {
  1896. head = cur = tmp;
  1897. }
  1898. break;
  1899. case DCOLON:
  1900. /* Just skip */
  1901. break;
  1902. default:
  1903. return head;
  1904. break;
  1905. }
  1906. }
  1907. }
  1908. /* Re-initialize the parser by resetting the lookahead token. */
  1909. static void
  1910. re_init_parser (void)
  1911. {
  1912. tk = -1;
  1913. }
  1914. /* Parse a parameter list, including the const-specifier,
  1915. pure-specifier, and throw-list that may follow a parameter list.
  1916. Return in FLAGS what was seen following the parameter list.
  1917. Returns a hash code for the parameter types. This value is used to
  1918. distinguish between overloaded functions. */
  1919. static unsigned
  1920. parm_list (int *flags)
  1921. {
  1922. unsigned hash = 0;
  1923. int type_seen = 0;
  1924. while (!LOOKING_AT2 (YYEOF, ')'))
  1925. {
  1926. switch (LA1)
  1927. {
  1928. /* Skip over grouping parens or parameter lists in parameter
  1929. declarations. */
  1930. case '(':
  1931. skip_matching ();
  1932. break;
  1933. /* Next parameter. */
  1934. case ',':
  1935. MATCH ();
  1936. type_seen = 0;
  1937. break;
  1938. /* Ignore the scope part of types, if any. This is because
  1939. some types need scopes when defined outside of a class body,
  1940. and don't need them inside the class body. This means that
  1941. we have to look for the last IDENT in a sequence of
  1942. IDENT::IDENT::... */
  1943. case IDENT:
  1944. if (!type_seen)
  1945. {
  1946. char *last_id;
  1947. unsigned ident_type_hash = 0;
  1948. parse_qualified_param_ident_or_type (&last_id);
  1949. if (last_id)
  1950. {
  1951. /* LAST_ID null means something like `X::*'. */
  1952. for (; *last_id; ++last_id)
  1953. ident_type_hash = (ident_type_hash << 1) ^ *last_id;
  1954. hash = (hash << 1) ^ ident_type_hash;
  1955. type_seen = 1;
  1956. }
  1957. }
  1958. else
  1959. MATCH ();
  1960. break;
  1961. case VOID:
  1962. /* This distinction is made to make `func (void)' equivalent
  1963. to `func ()'. */
  1964. type_seen = 1;
  1965. MATCH ();
  1966. if (!LOOKING_AT (')'))
  1967. hash = (hash << 1) ^ VOID;
  1968. break;
  1969. case BOOL: case CHAR: case CLASS: case CONST:
  1970. case DOUBLE: case ENUM: case FLOAT: case INT:
  1971. case LONG: case SHORT: case SIGNED: case STRUCT:
  1972. case UNION: case UNSIGNED: case VOLATILE: case WCHAR:
  1973. case ELLIPSIS:
  1974. type_seen = 1;
  1975. hash = (hash << 1) ^ LA1;
  1976. MATCH ();
  1977. break;
  1978. case '*': case '&': case '[': case ']':
  1979. hash = (hash << 1) ^ LA1;
  1980. MATCH ();
  1981. break;
  1982. default:
  1983. MATCH ();
  1984. break;
  1985. }
  1986. }
  1987. if (LOOKING_AT (')'))
  1988. {
  1989. MATCH ();
  1990. if (LOOKING_AT (CONST))
  1991. {
  1992. /* We can overload the same function on `const' */
  1993. hash = (hash << 1) ^ CONST;
  1994. SET_FLAG (*flags, F_CONST);
  1995. MATCH ();
  1996. }
  1997. if (LOOKING_AT (THROW))
  1998. {
  1999. MATCH ();
  2000. SKIP_MATCHING_IF ('(');
  2001. SET_FLAG (*flags, F_THROW);
  2002. }
  2003. if (LOOKING_AT ('='))
  2004. {
  2005. MATCH ();
  2006. if (LOOKING_AT (CINT) && yyival == 0)
  2007. {
  2008. MATCH ();
  2009. SET_FLAG (*flags, F_PURE);
  2010. }
  2011. }
  2012. }
  2013. return hash;
  2014. }
  2015. /* Print position info to stdout. */
  2016. static void
  2017. print_info (void)
  2018. {
  2019. if (info_position >= 0 && BUFFER_POS () <= info_position)
  2020. if (info_cls)
  2021. printf ("(\"%s\" \"%s\" \"%s\" %d)\n",
  2022. info_cls->name, sym_scope (info_cls),
  2023. info_member->name, info_where);
  2024. }
  2025. /* Parse a member declaration within the class body of CLS. VIS is
  2026. the access specifier for the member (private, protected,
  2027. public). */
  2028. static void
  2029. member (struct sym *cls, int vis)
  2030. {
  2031. char *id = NULL;
  2032. int sc = SC_MEMBER;
  2033. char *regexp = NULL;
  2034. int pos;
  2035. int is_constructor;
  2036. int anonymous = 0;
  2037. int flags = 0;
  2038. int class_tag;
  2039. int type_seen = 0;
  2040. int paren_seen = 0;
  2041. unsigned hash = 0;
  2042. int tilde = 0;
  2043. while (!LOOKING_AT4 (';', '{', '}', YYEOF))
  2044. {
  2045. switch (LA1)
  2046. {
  2047. default:
  2048. MATCH ();
  2049. break;
  2050. /* A function or class may follow. */
  2051. case TEMPLATE:
  2052. MATCH ();
  2053. SET_FLAG (flags, F_TEMPLATE);
  2054. /* Skip over template argument list */
  2055. SKIP_MATCHING_IF ('<');
  2056. break;
  2057. case EXPLICIT:
  2058. SET_FLAG (flags, F_EXPLICIT);
  2059. goto typeseen;
  2060. case MUTABLE:
  2061. SET_FLAG (flags, F_MUTABLE);
  2062. goto typeseen;
  2063. case T_INLINE:
  2064. SET_FLAG (flags, F_INLINE);
  2065. goto typeseen;
  2066. case VIRTUAL:
  2067. SET_FLAG (flags, F_VIRTUAL);
  2068. goto typeseen;
  2069. case '[':
  2070. skip_matching ();
  2071. break;
  2072. case ENUM:
  2073. sc = SC_TYPE;
  2074. goto typeseen;
  2075. case TYPEDEF:
  2076. sc = SC_TYPE;
  2077. goto typeseen;
  2078. case FRIEND:
  2079. sc = SC_FRIEND;
  2080. goto typeseen;
  2081. case STATIC:
  2082. sc = SC_STATIC;
  2083. goto typeseen;
  2084. case '~':
  2085. tilde = 1;
  2086. MATCH ();
  2087. break;
  2088. case IDENT:
  2089. /* Remember IDENTS seen so far. Among these will be the member
  2090. name. */
  2091. id = (char *) xrealloc (id, strlen (yytext) + 2);
  2092. if (tilde)
  2093. {
  2094. *id = '~';
  2095. strcpy (id + 1, yytext);
  2096. }
  2097. else
  2098. strcpy (id, yytext);
  2099. MATCH ();
  2100. break;
  2101. case OPERATOR:
  2102. {
  2103. char *s = operator_name (&sc);
  2104. id = (char *) xrealloc (id, strlen (s) + 1);
  2105. strcpy (id, s);
  2106. }
  2107. break;
  2108. case '(':
  2109. /* Most probably the beginning of a parameter list. */
  2110. MATCH ();
  2111. paren_seen = 1;
  2112. if (id && cls)
  2113. {
  2114. if (!(is_constructor = streq (id, cls->name)))
  2115. regexp = matching_regexp ();
  2116. }
  2117. else
  2118. is_constructor = 0;
  2119. pos = BUFFER_POS ();
  2120. hash = parm_list (&flags);
  2121. if (is_constructor)
  2122. regexp = matching_regexp ();
  2123. if (id && cls != NULL)
  2124. add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, flags);
  2125. while (!LOOKING_AT3 (';', '{', YYEOF))
  2126. MATCH ();
  2127. if (LOOKING_AT ('{') && id && cls)
  2128. add_member_defn (cls, id, regexp, pos, hash, 0, sc, flags);
  2129. free (id);
  2130. id = NULL;
  2131. sc = SC_MEMBER;
  2132. break;
  2133. case STRUCT: case UNION: case CLASS:
  2134. /* Nested class */
  2135. class_tag = LA1;
  2136. type_seen = 1;
  2137. MATCH ();
  2138. anonymous = 1;
  2139. /* More than one ident here to allow for MS-DOS specialties
  2140. like `_export class' etc. The last IDENT seen counts
  2141. as the class name. */
  2142. while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
  2143. {
  2144. if (LOOKING_AT (IDENT))
  2145. anonymous = 0;
  2146. MATCH ();
  2147. }
  2148. if (LOOKING_AT2 (':', '{'))
  2149. class_definition (anonymous ? NULL : cls, class_tag, flags, 1);
  2150. else
  2151. skip_to (';');
  2152. break;
  2153. case INT: case CHAR: case LONG: case UNSIGNED:
  2154. case SIGNED: case CONST: case DOUBLE: case VOID:
  2155. case SHORT: case VOLATILE: case BOOL: case WCHAR:
  2156. case TYPENAME:
  2157. typeseen:
  2158. type_seen = 1;
  2159. MATCH ();
  2160. break;
  2161. }
  2162. }
  2163. if (LOOKING_AT (';'))
  2164. {
  2165. /* The end of a member variable, a friend declaration or an access
  2166. declaration. We don't want to add friend classes as members. */
  2167. if (id && sc != SC_FRIEND && cls)
  2168. {
  2169. regexp = matching_regexp ();
  2170. pos = BUFFER_POS ();
  2171. if (cls != NULL)
  2172. {
  2173. if (type_seen || !paren_seen)
  2174. add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
  2175. else
  2176. add_member_decl (cls, id, regexp, pos, hash, 0, sc, vis, 0);
  2177. }
  2178. }
  2179. MATCH ();
  2180. print_info ();
  2181. }
  2182. else if (LOOKING_AT ('{'))
  2183. {
  2184. /* A named enum. */
  2185. if (sc == SC_TYPE && id && cls)
  2186. {
  2187. regexp = matching_regexp ();
  2188. pos = BUFFER_POS ();
  2189. if (cls != NULL)
  2190. {
  2191. add_member_decl (cls, id, regexp, pos, 0, 1, sc, vis, 0);
  2192. add_member_defn (cls, id, regexp, pos, 0, 1, sc, 0);
  2193. }
  2194. }
  2195. skip_matching ();
  2196. print_info ();
  2197. }
  2198. free (id);
  2199. }
  2200. /* Parse the body of class CLS. TAG is the tag of the class (struct,
  2201. union, class). */
  2202. static void
  2203. class_body (struct sym *cls, int tag)
  2204. {
  2205. int vis = tag == CLASS ? PRIVATE : PUBLIC;
  2206. int temp;
  2207. while (!LOOKING_AT2 (YYEOF, '}'))
  2208. {
  2209. switch (LA1)
  2210. {
  2211. case PRIVATE: case PROTECTED: case PUBLIC:
  2212. temp = LA1;
  2213. MATCH ();
  2214. if (LOOKING_AT (':'))
  2215. {
  2216. vis = temp;
  2217. MATCH ();
  2218. }
  2219. else
  2220. {
  2221. /* Probably conditional compilation for inheritance list.
  2222. We don't known whether there comes more of this.
  2223. This is only a crude fix that works most of the time. */
  2224. do
  2225. {
  2226. MATCH ();
  2227. }
  2228. while (LOOKING_AT2 (IDENT, ',')
  2229. || LOOKING_AT3 (PUBLIC, PROTECTED, PRIVATE));
  2230. }
  2231. break;
  2232. case TYPENAME:
  2233. case USING:
  2234. skip_to (';');
  2235. break;
  2236. /* Try to synchronize */
  2237. case CHAR: case CLASS: case CONST:
  2238. case DOUBLE: case ENUM: case FLOAT: case INT:
  2239. case LONG: case SHORT: case SIGNED: case STRUCT:
  2240. case UNION: case UNSIGNED: case VOID: case VOLATILE:
  2241. case TYPEDEF: case STATIC: case T_INLINE: case FRIEND:
  2242. case VIRTUAL: case TEMPLATE: case IDENT: case '~':
  2243. case BOOL: case WCHAR: case EXPLICIT: case MUTABLE:
  2244. member (cls, vis);
  2245. break;
  2246. default:
  2247. MATCH ();
  2248. break;
  2249. }
  2250. }
  2251. }
  2252. /* Parse a qualified identifier. Current lookahead is IDENT. A
  2253. qualified ident has the form `X<..>::Y<...>::T<...>. Returns a
  2254. symbol for that class. */
  2255. static struct sym *
  2256. parse_classname (void)
  2257. {
  2258. struct sym *last_class = NULL;
  2259. while (LOOKING_AT (IDENT))
  2260. {
  2261. last_class = add_sym (yytext, last_class);
  2262. MATCH ();
  2263. if (LOOKING_AT ('<'))
  2264. {
  2265. skip_matching ();
  2266. SET_FLAG (last_class->flags, F_TEMPLATE);
  2267. }
  2268. if (!LOOKING_AT (DCOLON))
  2269. break;
  2270. MATCH ();
  2271. }
  2272. return last_class;
  2273. }
  2274. /* Parse an operator name. Add the `static' flag to *SC if an
  2275. implicitly static operator has been parsed. Value is a pointer to
  2276. a static buffer holding the constructed operator name string. */
  2277. static char *
  2278. operator_name (int *sc)
  2279. {
  2280. static size_t id_size = 0;
  2281. static char *id = NULL;
  2282. const char *s;
  2283. size_t len;
  2284. MATCH ();
  2285. if (LOOKING_AT2 (NEW, DELETE))
  2286. {
  2287. /* `new' and `delete' are implicitly static. */
  2288. if (*sc != SC_FRIEND)
  2289. *sc = SC_STATIC;
  2290. s = token_string (LA1);
  2291. MATCH ();
  2292. len = strlen (s) + 10;
  2293. if (len > id_size)
  2294. {
  2295. size_t new_size = max (len, 2 * id_size);
  2296. id = (char *) xrealloc (id, new_size);
  2297. id_size = new_size;
  2298. }
  2299. strcpy (id, s);
  2300. /* Vector new or delete? */
  2301. if (LOOKING_AT ('['))
  2302. {
  2303. strcat (id, "[");
  2304. MATCH ();
  2305. if (LOOKING_AT (']'))
  2306. {
  2307. strcat (id, "]");
  2308. MATCH ();
  2309. }
  2310. }
  2311. }
  2312. else
  2313. {
  2314. size_t tokens_matched = 0;
  2315. len = 20;
  2316. if (len > id_size)
  2317. {
  2318. int new_size = max (len, 2 * id_size);
  2319. id = (char *) xrealloc (id, new_size);
  2320. id_size = new_size;
  2321. }
  2322. strcpy (id, "operator");
  2323. /* Beware access declarations of the form "X::f;" Beware of
  2324. `operator () ()'. Yet another difficulty is found in
  2325. GCC 2.95's STL: `operator == __STL_NULL_TMPL_ARGS (...'. */
  2326. while (!(LOOKING_AT ('(') && tokens_matched)
  2327. && !LOOKING_AT2 (';', YYEOF))
  2328. {
  2329. s = token_string (LA1);
  2330. len += strlen (s) + 2;
  2331. if (len > id_size)
  2332. {
  2333. size_t new_size = max (len, 2 * id_size);
  2334. id = (char *) xrealloc (id, new_size);
  2335. id_size = new_size;
  2336. }
  2337. if (*s != ')' && *s != ']')
  2338. strcat (id, " ");
  2339. strcat (id, s);
  2340. MATCH ();
  2341. /* If this is a simple operator like `+', stop now. */
  2342. if (!isalpha ((unsigned char) *s) && *s != '(' && *s != '[')
  2343. break;
  2344. ++tokens_matched;
  2345. }
  2346. }
  2347. return id;
  2348. }
  2349. /* This one consumes the last IDENT of a qualified member name like
  2350. `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
  2351. symbol structure for the ident. */
  2352. static struct sym *
  2353. parse_qualified_ident_or_type (char **last_id)
  2354. {
  2355. struct sym *cls = NULL;
  2356. char *id = NULL;
  2357. size_t id_size = 0;
  2358. int enter = 0;
  2359. while (LOOKING_AT (IDENT))
  2360. {
  2361. int len = strlen (yytext) + 1;
  2362. if (len > id_size)
  2363. {
  2364. id = (char *) xrealloc (id, len);
  2365. id_size = len;
  2366. }
  2367. strcpy (id, yytext);
  2368. *last_id = id;
  2369. MATCH ();
  2370. SKIP_MATCHING_IF ('<');
  2371. if (LOOKING_AT (DCOLON))
  2372. {
  2373. struct sym *pcn = NULL;
  2374. struct link *pna = check_namespace_alias (id);
  2375. if (pna)
  2376. {
  2377. do
  2378. {
  2379. enter_namespace (pna->sym->name);
  2380. enter++;
  2381. pna = pna->next;
  2382. }
  2383. while (pna);
  2384. }
  2385. else if ((pcn = check_namespace (id, current_namespace)))
  2386. {
  2387. enter_namespace (pcn->name);
  2388. enter++;
  2389. }
  2390. else
  2391. cls = add_sym (id, cls);
  2392. *last_id = NULL;
  2393. free (id);
  2394. id = NULL;
  2395. id_size = 0;
  2396. MATCH ();
  2397. }
  2398. else
  2399. break;
  2400. }
  2401. while (enter--)
  2402. leave_namespace ();
  2403. return cls;
  2404. }
  2405. /* This one consumes the last IDENT of a qualified member name like
  2406. `X::Y::z'. This IDENT is returned in LAST_ID. Value is the
  2407. symbol structure for the ident. */
  2408. static void
  2409. parse_qualified_param_ident_or_type (char **last_id)
  2410. {
  2411. struct sym *cls = NULL;
  2412. static char *id = NULL;
  2413. static int id_size = 0;
  2414. assert (LOOKING_AT (IDENT));
  2415. do
  2416. {
  2417. int len = strlen (yytext) + 1;
  2418. if (len > id_size)
  2419. {
  2420. id = (char *) xrealloc (id, len);
  2421. id_size = len;
  2422. }
  2423. strcpy (id, yytext);
  2424. *last_id = id;
  2425. MATCH ();
  2426. SKIP_MATCHING_IF ('<');
  2427. if (LOOKING_AT (DCOLON))
  2428. {
  2429. cls = add_sym (id, cls);
  2430. *last_id = NULL;
  2431. MATCH ();
  2432. }
  2433. else
  2434. break;
  2435. }
  2436. while (LOOKING_AT (IDENT));
  2437. }
  2438. /* Parse a class definition.
  2439. CONTAINING is the class containing the class being parsed or null.
  2440. This may also be null if NESTED != 0 if the containing class is
  2441. anonymous. TAG is the tag of the class (struct, union, class).
  2442. NESTED is non-zero if we are parsing a nested class.
  2443. Current lookahead is the class name. */
  2444. static void
  2445. class_definition (struct sym *containing, int tag, int flags, int nested)
  2446. {
  2447. struct sym *current;
  2448. struct sym *base_class;
  2449. /* Set CURRENT to null if no entry has to be made for the class
  2450. parsed. This is the case for certain command line flag
  2451. settings. */
  2452. if ((tag != CLASS && !f_structs) || (nested && !f_nested_classes))
  2453. current = NULL;
  2454. else
  2455. {
  2456. current = add_sym (yytext, containing);
  2457. current->pos = BUFFER_POS ();
  2458. current->regexp = matching_regexp ();
  2459. current->filename = filename;
  2460. current->flags = flags;
  2461. }
  2462. /* If at ':', base class list follows. */
  2463. if (LOOKING_AT (':'))
  2464. {
  2465. int done = 0;
  2466. MATCH ();
  2467. while (!done)
  2468. {
  2469. switch (LA1)
  2470. {
  2471. case VIRTUAL: case PUBLIC: case PROTECTED: case PRIVATE:
  2472. MATCH ();
  2473. break;
  2474. case IDENT:
  2475. base_class = parse_classname ();
  2476. if (base_class && current && base_class != current)
  2477. add_link (base_class, current);
  2478. break;
  2479. /* The `,' between base classes or the end of the base
  2480. class list. Add the previously found base class.
  2481. It's done this way to skip over sequences of
  2482. `A::B::C' until we reach the end.
  2483. FIXME: it is now possible to handle `class X : public B::X'
  2484. because we have enough information. */
  2485. case ',':
  2486. MATCH ();
  2487. break;
  2488. default:
  2489. /* A syntax error, possibly due to preprocessor constructs
  2490. like
  2491. #ifdef SOMETHING
  2492. class A : public B
  2493. #else
  2494. class A : private B.
  2495. MATCH until we see something like `;' or `{'. */
  2496. while (!LOOKING_AT3 (';', YYEOF, '{'))
  2497. MATCH ();
  2498. done = 1;
  2499. case '{':
  2500. done = 1;
  2501. break;
  2502. }
  2503. }
  2504. }
  2505. /* Parse the class body if there is one. */
  2506. if (LOOKING_AT ('{'))
  2507. {
  2508. if (tag != CLASS && !f_structs)
  2509. skip_matching ();
  2510. else
  2511. {
  2512. MATCH ();
  2513. class_body (current, tag);
  2514. if (LOOKING_AT ('}'))
  2515. {
  2516. MATCH ();
  2517. if (LOOKING_AT (';') && !nested)
  2518. MATCH ();
  2519. }
  2520. }
  2521. }
  2522. }
  2523. /* Add to class *CLS information for the declaration of variable or
  2524. type *ID. If *CLS is null, this means a global declaration. SC is
  2525. the storage class of *ID. FLAGS is a bit set giving additional
  2526. information about the member (see the F_* defines). */
  2527. static void
  2528. add_declarator (struct sym **cls, char **id, int flags, int sc)
  2529. {
  2530. if (LOOKING_AT2 (';', ','))
  2531. {
  2532. /* The end of a member variable or of an access declaration
  2533. `X::f'. To distinguish between them we have to know whether
  2534. type information has been seen. */
  2535. if (*id)
  2536. {
  2537. char *regexp = matching_regexp ();
  2538. int pos = BUFFER_POS ();
  2539. if (*cls)
  2540. add_member_defn (*cls, *id, regexp, pos, 0, 1, SC_UNKNOWN, flags);
  2541. else
  2542. add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
  2543. }
  2544. MATCH ();
  2545. print_info ();
  2546. }
  2547. else if (LOOKING_AT ('{'))
  2548. {
  2549. if (sc == SC_TYPE && *id)
  2550. {
  2551. /* A named enumeration. */
  2552. char *regexp = matching_regexp ();
  2553. int pos = BUFFER_POS ();
  2554. add_global_defn (*id, regexp, pos, 0, 1, sc, flags);
  2555. }
  2556. skip_matching ();
  2557. print_info ();
  2558. }
  2559. free (*id);
  2560. *id = NULL;
  2561. *cls = NULL;
  2562. }
  2563. /* Parse a declaration. */
  2564. static void
  2565. declaration (int flags)
  2566. {
  2567. char *id = NULL;
  2568. struct sym *cls = NULL;
  2569. char *regexp = NULL;
  2570. int pos = 0;
  2571. unsigned hash = 0;
  2572. int is_constructor;
  2573. int sc = 0;
  2574. while (!LOOKING_AT3 (';', '{', YYEOF))
  2575. {
  2576. switch (LA1)
  2577. {
  2578. default:
  2579. MATCH ();
  2580. break;
  2581. case '[':
  2582. skip_matching ();
  2583. break;
  2584. case ENUM:
  2585. case TYPEDEF:
  2586. sc = SC_TYPE;
  2587. MATCH ();
  2588. break;
  2589. case STATIC:
  2590. sc = SC_STATIC;
  2591. MATCH ();
  2592. break;
  2593. case INT: case CHAR: case LONG: case UNSIGNED:
  2594. case SIGNED: case CONST: case DOUBLE: case VOID:
  2595. case SHORT: case VOLATILE: case BOOL: case WCHAR:
  2596. MATCH ();
  2597. break;
  2598. case CLASS: case STRUCT: case UNION:
  2599. /* This is for the case `STARTWRAP class X : ...' or
  2600. `declare (X, Y)\n class A : ...'. */
  2601. if (id)
  2602. {
  2603. free (id);
  2604. return;
  2605. }
  2606. case '=':
  2607. /* Assumed to be the start of an initialization in this
  2608. context. */
  2609. skip_initializer ();
  2610. break;
  2611. case ',':
  2612. add_declarator (&cls, &id, flags, sc);
  2613. break;
  2614. case OPERATOR:
  2615. {
  2616. char *s = operator_name (&sc);
  2617. id = (char *) xrealloc (id, strlen (s) + 1);
  2618. strcpy (id, s);
  2619. }
  2620. break;
  2621. case T_INLINE:
  2622. SET_FLAG (flags, F_INLINE);
  2623. MATCH ();
  2624. break;
  2625. case '~':
  2626. MATCH ();
  2627. if (LOOKING_AT (IDENT))
  2628. {
  2629. id = (char *) xrealloc (id, strlen (yytext) + 2);
  2630. *id = '~';
  2631. strcpy (id + 1, yytext);
  2632. MATCH ();
  2633. }
  2634. break;
  2635. case IDENT:
  2636. cls = parse_qualified_ident_or_type (&id);
  2637. break;
  2638. case '(':
  2639. /* Most probably the beginning of a parameter list. */
  2640. if (cls)
  2641. {
  2642. MATCH ();
  2643. if (id && cls)
  2644. {
  2645. if (!(is_constructor = streq (id, cls->name)))
  2646. regexp = matching_regexp ();
  2647. }
  2648. else
  2649. is_constructor = 0;
  2650. pos = BUFFER_POS ();
  2651. hash = parm_list (&flags);
  2652. if (is_constructor)
  2653. regexp = matching_regexp ();
  2654. if (id && cls)
  2655. add_member_defn (cls, id, regexp, pos, hash, 0,
  2656. SC_UNKNOWN, flags);
  2657. }
  2658. else
  2659. {
  2660. /* This may be a C functions, but also a macro
  2661. call of the form `declare (A, B)' --- such macros
  2662. can be found in some class libraries. */
  2663. MATCH ();
  2664. if (id)
  2665. {
  2666. regexp = matching_regexp ();
  2667. pos = BUFFER_POS ();
  2668. hash = parm_list (&flags);
  2669. add_global_decl (id, regexp, pos, hash, 0, sc, flags);
  2670. }
  2671. /* This is for the case that the function really is
  2672. a macro with no `;' following it. If a CLASS directly
  2673. follows, we would miss it otherwise. */
  2674. if (LOOKING_AT3 (CLASS, STRUCT, UNION))
  2675. return;
  2676. }
  2677. while (!LOOKING_AT3 (';', '{', YYEOF))
  2678. MATCH ();
  2679. if (!cls && id && LOOKING_AT ('{'))
  2680. add_global_defn (id, regexp, pos, hash, 0, sc, flags);
  2681. free (id);
  2682. id = NULL;
  2683. break;
  2684. }
  2685. }
  2686. add_declarator (&cls, &id, flags, sc);
  2687. }
  2688. /* Parse a list of top-level declarations/definitions. START_FLAGS
  2689. says in which context we are parsing. If it is F_EXTERNC, we are
  2690. parsing in an `extern "C"' block. Value is 1 if EOF is reached, 0
  2691. otherwise. */
  2692. static int
  2693. globals (int start_flags)
  2694. {
  2695. int anonymous;
  2696. int class_tk;
  2697. int flags = start_flags;
  2698. for (;;)
  2699. {
  2700. char *prev_in = in;
  2701. switch (LA1)
  2702. {
  2703. case NAMESPACE:
  2704. {
  2705. MATCH ();
  2706. if (LOOKING_AT (IDENT))
  2707. {
  2708. char *namespace_name = xstrdup (yytext);
  2709. MATCH ();
  2710. if (LOOKING_AT ('='))
  2711. {
  2712. struct link *qna = match_qualified_namespace_alias ();
  2713. if (qna)
  2714. register_namespace_alias (namespace_name, qna);
  2715. if (skip_to (';') == ';')
  2716. MATCH ();
  2717. }
  2718. else if (LOOKING_AT ('{'))
  2719. {
  2720. MATCH ();
  2721. enter_namespace (namespace_name);
  2722. globals (0);
  2723. leave_namespace ();
  2724. MATCH_IF ('}');
  2725. }
  2726. free (namespace_name);
  2727. }
  2728. }
  2729. break;
  2730. case EXTERN:
  2731. MATCH ();
  2732. if (LOOKING_AT (CSTRING) && *string_start == 'C'
  2733. && *(string_start + 1) == '"')
  2734. {
  2735. /* This is `extern "C"'. */
  2736. MATCH ();
  2737. if (LOOKING_AT ('{'))
  2738. {
  2739. MATCH ();
  2740. globals (F_EXTERNC);
  2741. MATCH_IF ('}');
  2742. }
  2743. else
  2744. SET_FLAG (flags, F_EXTERNC);
  2745. }
  2746. break;
  2747. case TEMPLATE:
  2748. MATCH ();
  2749. SKIP_MATCHING_IF ('<');
  2750. SET_FLAG (flags, F_TEMPLATE);
  2751. break;
  2752. case CLASS: case STRUCT: case UNION:
  2753. class_tk = LA1;
  2754. MATCH ();
  2755. anonymous = 1;
  2756. /* More than one ident here to allow for MS-DOS and OS/2
  2757. specialties like `far', `_Export' etc. Some C++ libs
  2758. have constructs like `_OS_DLLIMPORT(_OS_CLIENT)' in front
  2759. of the class name. */
  2760. while (!LOOKING_AT4 (YYEOF, ';', ':', '{'))
  2761. {
  2762. if (LOOKING_AT (IDENT))
  2763. anonymous = 0;
  2764. MATCH ();
  2765. }
  2766. /* Don't add anonymous unions. */
  2767. if (LOOKING_AT2 (':', '{') && !anonymous)
  2768. class_definition (NULL, class_tk, flags, 0);
  2769. else
  2770. {
  2771. if (skip_to (';') == ';')
  2772. MATCH ();
  2773. }
  2774. flags = start_flags;
  2775. break;
  2776. case YYEOF:
  2777. return 1;
  2778. case '}':
  2779. return 0;
  2780. default:
  2781. declaration (flags);
  2782. flags = start_flags;
  2783. break;
  2784. }
  2785. if (prev_in == in)
  2786. yyerror ("parse error", NULL);
  2787. }
  2788. }
  2789. /* Parse the current input file. */
  2790. static void
  2791. yyparse (void)
  2792. {
  2793. while (globals (0) == 0)
  2794. MATCH_IF ('}');
  2795. }
  2796. /***********************************************************************
  2797. Main Program
  2798. ***********************************************************************/
  2799. /* Add the list of paths PATH_LIST to the current search path for
  2800. input files. */
  2801. static void
  2802. add_search_path (char *path_list)
  2803. {
  2804. while (*path_list)
  2805. {
  2806. char *start = path_list;
  2807. struct search_path *p;
  2808. while (*path_list && *path_list != PATH_LIST_SEPARATOR)
  2809. ++path_list;
  2810. p = (struct search_path *) xmalloc (sizeof *p);
  2811. p->path = (char *) xmalloc (path_list - start + 1);
  2812. memcpy (p->path, start, path_list - start);
  2813. p->path[path_list - start] = '\0';
  2814. p->next = NULL;
  2815. if (search_path_tail)
  2816. {
  2817. search_path_tail->next = p;
  2818. search_path_tail = p;
  2819. }
  2820. else
  2821. search_path = search_path_tail = p;
  2822. while (*path_list == PATH_LIST_SEPARATOR)
  2823. ++path_list;
  2824. }
  2825. }
  2826. /* Open FILE and return a file handle for it, or -1 if FILE cannot be
  2827. opened. Try to find FILE in search_path first, then try the
  2828. unchanged file name. */
  2829. static FILE *
  2830. open_file (char *file)
  2831. {
  2832. FILE *fp = NULL;
  2833. static char *buffer;
  2834. static int buffer_size;
  2835. struct search_path *path;
  2836. int flen = strlen (file) + 1; /* +1 for the slash */
  2837. filename = xstrdup (file);
  2838. for (path = search_path; path && fp == NULL; path = path->next)
  2839. {
  2840. int len = strlen (path->path) + flen;
  2841. if (len + 1 >= buffer_size)
  2842. {
  2843. buffer_size = max (len + 1, 2 * buffer_size);
  2844. buffer = (char *) xrealloc (buffer, buffer_size);
  2845. }
  2846. strcpy (buffer, path->path);
  2847. strcat (buffer, "/");
  2848. strcat (buffer, file);
  2849. fp = fopen (buffer, "r");
  2850. }
  2851. /* Try the original file name. */
  2852. if (fp == NULL)
  2853. fp = fopen (file, "r");
  2854. if (fp == NULL)
  2855. yyerror ("cannot open", NULL);
  2856. return fp;
  2857. }
  2858. /* Display usage information and exit program. */
  2859. #define USAGE "\
  2860. Usage: ebrowse [options] {files}\n\
  2861. \n\
  2862. -a, --append append output to existing file\n\
  2863. -f, --files=FILES read input file names from FILE\n\
  2864. -I, --search-path=LIST set search path for input files\n\
  2865. -m, --min-regexp-length=N set minimum regexp length to N\n\
  2866. -M, --max-regexp-length=N set maximum regexp length to N\n\
  2867. -n, --no-nested-classes exclude nested classes\n\
  2868. -o, --output-file=FILE set output file name to FILE\n\
  2869. -p, --position-info print info about position in file\n\
  2870. -s, --no-structs-or-unions don't record structs or unions\n\
  2871. -v, --verbose be verbose\n\
  2872. -V, --very-verbose be very verbose\n\
  2873. -x, --no-regexps don't record regular expressions\n\
  2874. --help display this help\n\
  2875. --version display version info\n\
  2876. "
  2877. static void
  2878. usage (int error)
  2879. {
  2880. puts (USAGE);
  2881. exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
  2882. }
  2883. /* Display version and copyright info. The VERSION macro is set
  2884. from config.h and contains the Emacs version. */
  2885. #ifndef VERSION
  2886. # define VERSION "21"
  2887. #endif
  2888. static void
  2889. version (void)
  2890. {
  2891. /* Makes it easier to update automatically. */
  2892. char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc.";
  2893. printf ("ebrowse %s\n", VERSION);
  2894. puts (emacs_copyright);
  2895. puts ("This program is distributed under the same terms as Emacs.");
  2896. exit (EXIT_SUCCESS);
  2897. }
  2898. /* Parse one input file FILE, adding classes and members to the symbol
  2899. table. */
  2900. static void
  2901. process_file (char *file)
  2902. {
  2903. FILE *fp;
  2904. fp = open_file (file);
  2905. if (fp)
  2906. {
  2907. size_t nread, nbytes;
  2908. /* Give a progress indication if needed. */
  2909. if (f_very_verbose)
  2910. {
  2911. puts (filename);
  2912. fflush (stdout);
  2913. }
  2914. else if (f_verbose)
  2915. {
  2916. putchar ('.');
  2917. fflush (stdout);
  2918. }
  2919. /* Read file to inbuffer. */
  2920. for (nread = 0;;)
  2921. {
  2922. if (nread + READ_CHUNK_SIZE >= inbuffer_size)
  2923. {
  2924. inbuffer_size = nread + READ_CHUNK_SIZE + 1;
  2925. inbuffer = (char *) xrealloc (inbuffer, inbuffer_size);
  2926. }
  2927. nbytes = fread (inbuffer + nread, 1, READ_CHUNK_SIZE, fp);
  2928. if (nbytes == 0)
  2929. break;
  2930. nread += nbytes;
  2931. }
  2932. inbuffer[nread] = '\0';
  2933. /* Reinitialize scanner and parser for the new input file. */
  2934. re_init_scanner ();
  2935. re_init_parser ();
  2936. /* Parse it and close the file. */
  2937. yyparse ();
  2938. fclose (fp);
  2939. }
  2940. }
  2941. /* Read a line from stream FP and return a pointer to a static buffer
  2942. containing its contents without the terminating newline. Value
  2943. is null when EOF is reached. */
  2944. static char *
  2945. read_line (FILE *fp)
  2946. {
  2947. static char *buffer;
  2948. static int buffer_size;
  2949. int i = 0, c;
  2950. while ((c = getc (fp)) != EOF && c != '\n')
  2951. {
  2952. if (i >= buffer_size)
  2953. {
  2954. buffer_size = max (100, buffer_size * 2);
  2955. buffer = (char *) xrealloc (buffer, buffer_size);
  2956. }
  2957. buffer[i++] = c;
  2958. }
  2959. if (c == EOF && i == 0)
  2960. return NULL;
  2961. if (i == buffer_size)
  2962. {
  2963. buffer_size = max (100, buffer_size * 2);
  2964. buffer = (char *) xrealloc (buffer, buffer_size);
  2965. }
  2966. buffer[i] = '\0';
  2967. if (i > 0 && buffer[i - 1] == '\r')
  2968. buffer[i - 1] = '\0';
  2969. return buffer;
  2970. }
  2971. /* Main entry point. */
  2972. int
  2973. main (int argc, char **argv)
  2974. {
  2975. int i;
  2976. int any_inputfiles = 0;
  2977. static const char *out_filename = DEFAULT_OUTFILE;
  2978. static char **input_filenames = NULL;
  2979. static int input_filenames_size = 0;
  2980. static int n_input_files;
  2981. filename = "command line";
  2982. yyout = stdout;
  2983. while ((i = getopt_long (argc, argv, "af:I:m:M:no:p:svVx",
  2984. options, NULL)) != EOF)
  2985. {
  2986. switch (i)
  2987. {
  2988. /* Experimental. */
  2989. case 'p':
  2990. info_position = atoi (optarg);
  2991. break;
  2992. case 'n':
  2993. f_nested_classes = 0;
  2994. break;
  2995. case 'x':
  2996. f_regexps = 0;
  2997. break;
  2998. /* Add the name of a file containing more input files. */
  2999. case 'f':
  3000. if (n_input_files == input_filenames_size)
  3001. {
  3002. input_filenames_size = max (10, 2 * input_filenames_size);
  3003. input_filenames = (char **) xrealloc ((void *)input_filenames,
  3004. input_filenames_size);
  3005. }
  3006. input_filenames[n_input_files++] = xstrdup (optarg);
  3007. break;
  3008. /* Append new output to output file instead of truncating it. */
  3009. case 'a':
  3010. f_append = 1;
  3011. break;
  3012. /* Include structs in the output */
  3013. case 's':
  3014. f_structs = 0;
  3015. break;
  3016. /* Be verbose (give a progress indication). */
  3017. case 'v':
  3018. f_verbose = 1;
  3019. break;
  3020. /* Be very verbose (print file names as they are processed). */
  3021. case 'V':
  3022. f_verbose = 1;
  3023. f_very_verbose = 1;
  3024. break;
  3025. /* Change the name of the output file. */
  3026. case 'o':
  3027. out_filename = optarg;
  3028. break;
  3029. /* Set minimum length for regular expression strings
  3030. when recorded in the output file. */
  3031. case 'm':
  3032. min_regexp = atoi (optarg);
  3033. break;
  3034. /* Set maximum length for regular expression strings
  3035. when recorded in the output file. */
  3036. case 'M':
  3037. max_regexp = atoi (optarg);
  3038. break;
  3039. /* Add to search path. */
  3040. case 'I':
  3041. add_search_path (optarg);
  3042. break;
  3043. /* Display help */
  3044. case -2:
  3045. usage (0);
  3046. break;
  3047. case -3:
  3048. version ();
  3049. break;
  3050. }
  3051. }
  3052. /* Call init_scanner after command line flags have been processed to be
  3053. able to add keywords depending on command line (not yet
  3054. implemented). */
  3055. init_scanner ();
  3056. init_sym ();
  3057. /* Open output file */
  3058. if (*out_filename)
  3059. {
  3060. if (f_append)
  3061. {
  3062. /* Check that the file to append to exists, and is not
  3063. empty. More specifically, it should be a valid file
  3064. produced by a previous run of ebrowse, but that's too
  3065. difficult to check. */
  3066. FILE *fp;
  3067. int rc;
  3068. fp = fopen (out_filename, "r");
  3069. if (fp == NULL)
  3070. {
  3071. yyerror ("file `%s' must exist for --append", out_filename);
  3072. exit (EXIT_FAILURE);
  3073. }
  3074. rc = fseek (fp, 0, SEEK_END);
  3075. if (rc == -1)
  3076. {
  3077. yyerror ("error seeking in file `%s'", out_filename);
  3078. exit (EXIT_FAILURE);
  3079. }
  3080. rc = ftell (fp);
  3081. if (rc == -1)
  3082. {
  3083. yyerror ("error getting size of file `%s'", out_filename);
  3084. exit (EXIT_FAILURE);
  3085. }
  3086. else if (rc == 0)
  3087. {
  3088. yyerror ("file `%s' is empty", out_filename);
  3089. /* It may be ok to use an empty file for appending.
  3090. exit (EXIT_FAILURE); */
  3091. }
  3092. fclose (fp);
  3093. }
  3094. yyout = fopen (out_filename, f_append ? "a" : "w");
  3095. if (yyout == NULL)
  3096. {
  3097. yyerror ("cannot open output file `%s'", out_filename);
  3098. exit (EXIT_FAILURE);
  3099. }
  3100. }
  3101. /* Process input files specified on the command line. */
  3102. while (optind < argc)
  3103. {
  3104. process_file (argv[optind++]);
  3105. any_inputfiles = 1;
  3106. }
  3107. /* Process files given on stdin if no files specified. */
  3108. if (!any_inputfiles && n_input_files == 0)
  3109. {
  3110. char *file;
  3111. while ((file = read_line (stdin)) != NULL)
  3112. process_file (file);
  3113. }
  3114. else
  3115. {
  3116. /* Process files from `--files=FILE'. Every line in FILE names
  3117. one input file to process. */
  3118. for (i = 0; i < n_input_files; ++i)
  3119. {
  3120. FILE *fp = fopen (input_filenames[i], "r");
  3121. if (fp == NULL)
  3122. yyerror ("cannot open input file `%s'", input_filenames[i]);
  3123. else
  3124. {
  3125. char *file;
  3126. while ((file = read_line (fp)) != NULL)
  3127. process_file (file);
  3128. fclose (fp);
  3129. }
  3130. }
  3131. }
  3132. /* Write output file. */
  3133. dump_roots (yyout);
  3134. /* Close output file. */
  3135. if (yyout != stdout)
  3136. fclose (yyout);
  3137. return EXIT_SUCCESS;
  3138. }
  3139. /* ebrowse.c ends here */