h2pas.y 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723
  1. %{
  2. program h2pas;
  3. (*
  4. $Id$
  5. Copyright (c) 1998-2000 by Florian Klaempfl
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************)
  18. uses
  19. SysUtils,classes,
  20. options,scan,converu,lexlib,yacclib;
  21. type
  22. YYSTYPE = presobject;
  23. const
  24. SHORT_STR = 'smallint';
  25. USHORT_STR = 'word';
  26. INT_STR = 'longint';
  27. UINT_STR = 'dword';
  28. CHAR_STR = 'char';
  29. UCHAR_STR = 'byte'; { should we use byte or char for 'unsigned char' ?? }
  30. INT64_STR = 'int64';
  31. QWORD_STR = 'qword';
  32. REAL_STR = 'double';
  33. WCHAR_STR = 'widechar';
  34. var
  35. hp,ph : presobject;
  36. implemfile : text; (* file for implementation headers extern procs *)
  37. IsExtern : boolean;
  38. NeedEllipsisOverload : boolean;
  39. must_write_packed_field : boolean;
  40. tempfile : text;
  41. No_pop : boolean;
  42. s,TN,PN : String;
  43. pointerprefix: boolean;
  44. freedynlibproc,
  45. loaddynlibproc : tstringlist;
  46. (* $ define yydebug
  47. compile with -dYYDEBUG to get debugging info *)
  48. const
  49. (* number of a?b:c construction in one define *)
  50. if_nb : longint = 0;
  51. is_packed : boolean = false;
  52. is_procvar : boolean = false;
  53. var space_array : array [0..255] of byte;
  54. space_index : byte;
  55. { Used when PPointers is used - pointer type definitions }
  56. PTypeList : TStringList;
  57. procedure shift(space_number : byte);
  58. var
  59. i : byte;
  60. begin
  61. space_array[space_index]:=space_number;
  62. inc(space_index);
  63. for i:=1 to space_number do
  64. aktspace:=aktspace+' ';
  65. end;
  66. procedure popshift;
  67. begin
  68. dec(space_index);
  69. if space_index<0 then
  70. internalerror(20);
  71. delete(aktspace,1,space_array[space_index]);
  72. end;
  73. function str(i : longint) : string;
  74. var
  75. s : string;
  76. begin
  77. system.str(i,s);
  78. str:=s;
  79. end;
  80. function hexstr(i : cardinal) : string;
  81. const
  82. HexTbl : array[0..15] of char='0123456789ABCDEF';
  83. var
  84. str : string;
  85. begin
  86. str:='';
  87. while i<>0 do
  88. begin
  89. str:=hextbl[i and $F]+str;
  90. i:=i shr 4;
  91. end;
  92. if str='' then str:='0';
  93. hexstr:='$'+str;
  94. end;
  95. function uppercase(s : string) : string;
  96. var
  97. i : byte;
  98. begin
  99. for i:=1 to length(s) do
  100. s[i]:=UpCase(s[i]);
  101. uppercase:=s;
  102. end;
  103. procedure write_type_specifier(var outfile:text; p : presobject);forward;
  104. procedure write_p_a_def(var outfile:text; p,simple_type : presobject);forward;
  105. procedure write_ifexpr(var outfile:text; p : presobject);forward;
  106. procedure write_funexpr(var outfile:text; p : presobject);forward;
  107. procedure yymsg(const msg : string);
  108. begin
  109. writeln('line ',line_no,': ',msg);
  110. end;
  111. { This converts pascal reserved words to
  112. the correct syntax.
  113. }
  114. function FixId(const s:string):string;
  115. const
  116. maxtokens = 14;
  117. reservedid: array[1..maxtokens] of string[14] =
  118. (
  119. 'CLASS',
  120. 'DISPOSE',
  121. 'FUNCTION',
  122. 'FALSE',
  123. 'LABEL',
  124. 'NEW',
  125. 'PROPERTY',
  126. 'PROCEDURE',
  127. 'RECORD',
  128. 'REPEAT',
  129. 'STRING',
  130. 'TYPE',
  131. 'TRUE',
  132. 'UNTIL'
  133. );
  134. var
  135. b : boolean;
  136. up : string;
  137. i: integer;
  138. begin
  139. if s='' then
  140. begin
  141. FixId:='';
  142. exit;
  143. end;
  144. b:=false;
  145. up:=Uppercase(s);
  146. for i:=1 to maxtokens do
  147. begin
  148. if up=reservedid[i] then
  149. begin
  150. b:=true;
  151. break;
  152. end;
  153. end;
  154. if b then
  155. FixId:='_'+s
  156. else
  157. FixId:=s;
  158. end;
  159. function TypeName(const s:string):string;
  160. var
  161. i : longint;
  162. begin
  163. i:=1;
  164. if RemoveUnderScore and (length(s)>1) and (s[1]='_') then
  165. i:=2;
  166. if PrependTypes then
  167. TypeName:='T'+Copy(s,i,255)
  168. else
  169. TypeName:=Copy(s,i,255);
  170. end;
  171. function PointerName(const s:string):string;
  172. var
  173. i : longint;
  174. begin
  175. i:=1;
  176. if RemoveUnderScore and (length(s)>1) and (s[1]='_') then
  177. i:=2;
  178. if UsePPointers then
  179. begin
  180. PointerName:='P'+Copy(s,i,255);
  181. PTypeList.Add(PointerName);
  182. end
  183. else
  184. PointerName:=Copy(s,i,255);
  185. if PointerPrefix then
  186. PTypeList.Add('P'+s);
  187. end;
  188. procedure write_packed_fields_info(var outfile:text; p : presobject; ph : string);
  189. var
  190. hp1,hp2,hp3 : presobject;
  191. is_sized : boolean;
  192. line : string;
  193. flag_index : longint;
  194. name : pchar;
  195. ps : byte;
  196. begin
  197. { write out the tempfile created }
  198. close(tempfile);
  199. reset(tempfile);
  200. is_sized:=false;
  201. flag_index:=0;
  202. writeln(outfile);
  203. writeln(outfile,aktspace,'const');
  204. shift(3);
  205. while not eof(tempfile) do
  206. begin
  207. readln(tempfile,line);
  208. ps:=pos('&',line);
  209. if ps>0 then
  210. line:=copy(line,1,ps-1)+ph+'_'+copy(line,ps+1,255);
  211. writeln(outfile,aktspace,line);
  212. end;
  213. writeln(outfile);
  214. close(tempfile);
  215. rewrite(tempfile);
  216. popshift;
  217. (* walk through all members *)
  218. hp1 := p^.p1;
  219. while assigned(hp1) do
  220. begin
  221. (* hp2 is t_memberdec *)
  222. hp2:=hp1^.p1;
  223. (* hp3 is t_declist *)
  224. hp3:=hp2^.p2;
  225. while assigned(hp3) do
  226. begin
  227. if assigned(hp3^.p1^.p3) and
  228. (hp3^.p1^.p3^.typ = t_size_specifier) then
  229. begin
  230. is_sized:=true;
  231. name:=hp3^.p1^.p2^.p;
  232. { get function in interface }
  233. write(outfile,aktspace,'function ',name);
  234. write(outfile,'(var a : ',ph,') : ');
  235. shift(2);
  236. write_p_a_def(outfile,hp3^.p1^.p1,hp2^.p1);
  237. writeln(outfile,';');
  238. popshift;
  239. { get function in implementation }
  240. write(implemfile,aktspace,'function ',name);
  241. write(implemfile,'(var a : ',ph,') : ');
  242. if not compactmode then
  243. shift(2);
  244. write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
  245. writeln(implemfile,';');
  246. writeln(implemfile,aktspace,'begin');
  247. shift(3);
  248. write(implemfile,aktspace,name,':=(a.flag',flag_index);
  249. writeln(implemfile,' and bm_',ph,'_',name,') shr bp_',ph,'_',name,';');
  250. popshift;
  251. writeln(implemfile,aktspace,'end;');
  252. if not compactmode then
  253. popshift;
  254. writeln(implemfile,'');
  255. { set function in interface }
  256. write(outfile,aktspace,'procedure set_',name);
  257. write(outfile,'(var a : ',ph,'; __',name,' : ');
  258. shift(2);
  259. write_p_a_def(outfile,hp3^.p1^.p1,hp2^.p1);
  260. writeln(outfile,');');
  261. popshift;
  262. { set function in implementation }
  263. write(implemfile,aktspace,'procedure set_',name);
  264. write(implemfile,'(var a : ',ph,'; __',name,' : ');
  265. if not compactmode then
  266. shift(2);
  267. write_p_a_def(implemfile,hp3^.p1^.p1,hp2^.p1);
  268. writeln(implemfile,');');
  269. writeln(implemfile,aktspace,'begin');
  270. shift(3);
  271. write(implemfile,aktspace,'a.flag',flag_index,':=');
  272. write(implemfile,'a.flag',flag_index,' or ');
  273. writeln(implemfile,'((__',name,' shl bp_',ph,'_',name,') and bm_',ph,'_',name,');');
  274. popshift;
  275. writeln(implemfile,aktspace,'end;');
  276. if not compactmode then
  277. popshift;
  278. writeln(implemfile,'');
  279. end
  280. else if is_sized then
  281. begin
  282. is_sized:=false;
  283. inc(flag_index);
  284. end;
  285. hp3:=hp3^.next;
  286. end;
  287. hp1:=hp1^.next;
  288. end;
  289. must_write_packed_field:=false;
  290. block_type:=bt_no;
  291. end;
  292. procedure write_expr(var outfile:text; p : presobject);
  293. begin
  294. if assigned(p) then
  295. begin
  296. case p^.typ of
  297. t_id,
  298. t_ifexpr :
  299. write(outfile,FixId(p^.p));
  300. t_funexprlist :
  301. write_funexpr(outfile,p);
  302. t_exprlist :
  303. begin
  304. if assigned(p^.p1) then
  305. write_expr(outfile,p^.p1);
  306. if assigned(p^.next) then
  307. begin
  308. write(', ');
  309. write_expr(outfile,p^.next);
  310. end;
  311. end;
  312. t_preop : begin
  313. write(outfile,p^.p,'(');
  314. write_expr(outfile,p^.p1);
  315. write(outfile,')');
  316. flush(outfile);
  317. end;
  318. t_typespec : begin
  319. write_type_specifier(outfile,p^.p1);
  320. write(outfile,'(');
  321. write_expr(outfile,p^.p2);
  322. write(outfile,')');
  323. flush(outfile);
  324. end;
  325. t_bop : begin
  326. if p^.p1^.typ<>t_id then
  327. write(outfile,'(');
  328. write_expr(outfile,p^.p1);
  329. if p^.p1^.typ<>t_id then
  330. write(outfile,')');
  331. write(outfile,p^.p);
  332. if p^.p2^.typ<>t_id then
  333. write(outfile,'(');
  334. write_expr(outfile,p^.p2);
  335. if p^.p2^.typ<>t_id then
  336. write(outfile,')');
  337. flush(outfile);
  338. end;
  339. t_arrayop :
  340. begin
  341. write_expr(outfile,p^.p1);
  342. write(outfile,p^.p,'[');
  343. write_expr(outfile,p^.p2);
  344. write(outfile,']');
  345. flush(outfile);
  346. end;
  347. t_callop :
  348. begin
  349. write_expr(outfile,p^.p1);
  350. write(outfile,p^.p,'(');
  351. write_expr(outfile,p^.p2);
  352. write(outfile,')');
  353. flush(outfile);
  354. end;
  355. else internalerror(2);
  356. end;
  357. end;
  358. end;
  359. procedure write_ifexpr(var outfile:text; p : presobject);
  360. begin
  361. flush(outfile);
  362. write(outfile,'if ');
  363. write_expr(outfile,p^.p1);
  364. writeln(outfile,' then');
  365. write(outfile,aktspace,' ');
  366. write(outfile,p^.p);
  367. write(outfile,':=');
  368. write_expr(outfile,p^.p2);
  369. writeln(outfile);
  370. writeln(outfile,aktspace,'else');
  371. write(outfile,aktspace,' ');
  372. write(outfile,p^.p);
  373. write(outfile,':=');
  374. write_expr(outfile,p^.p3);
  375. writeln(outfile,';');
  376. write(outfile,aktspace);
  377. flush(outfile);
  378. end;
  379. procedure write_all_ifexpr(var outfile:text; p : presobject);
  380. begin
  381. if assigned(p) then
  382. begin
  383. case p^.typ of
  384. t_id :;
  385. t_preop :
  386. write_all_ifexpr(outfile,p^.p1);
  387. t_callop,
  388. t_arrayop,
  389. t_bop :
  390. begin
  391. write_all_ifexpr(outfile,p^.p1);
  392. write_all_ifexpr(outfile,p^.p2);
  393. end;
  394. t_ifexpr :
  395. begin
  396. write_all_ifexpr(outfile,p^.p1);
  397. write_all_ifexpr(outfile,p^.p2);
  398. write_all_ifexpr(outfile,p^.p3);
  399. write_ifexpr(outfile,p);
  400. end;
  401. t_typespec :
  402. write_all_ifexpr(outfile,p^.p2);
  403. t_funexprlist,
  404. t_exprlist :
  405. begin
  406. if assigned(p^.p1) then
  407. write_all_ifexpr(outfile,p^.p1);
  408. if assigned(p^.next) then
  409. write_all_ifexpr(outfile,p^.next);
  410. end
  411. else
  412. internalerror(6);
  413. end;
  414. end;
  415. end;
  416. procedure write_funexpr(var outfile:text; p : presobject);
  417. var
  418. i : longint;
  419. begin
  420. if assigned(p) then
  421. begin
  422. case p^.typ of
  423. t_ifexpr :
  424. write(outfile,p^.p);
  425. t_exprlist :
  426. begin
  427. write_expr(outfile,p^.p1);
  428. if assigned(p^.next) then
  429. begin
  430. write(outfile,',');
  431. write_funexpr(outfile,p^.next);
  432. end
  433. end;
  434. t_funcname :
  435. begin
  436. if not compactmode then
  437. shift(2);
  438. if if_nb>0 then
  439. begin
  440. writeln(outfile,aktspace,'var');
  441. write(outfile,aktspace,' ');
  442. for i:=1 to if_nb do
  443. begin
  444. write(outfile,'if_local',i);
  445. if i<if_nb then
  446. write(outfile,', ')
  447. else
  448. writeln(outfile,' : longint;');
  449. end;
  450. writeln(outfile,aktspace,'(* result types are not known *)');
  451. if_nb:=0;
  452. end;
  453. writeln(outfile,aktspace,'begin');
  454. shift(3);
  455. write(outfile,aktspace);
  456. write_all_ifexpr(outfile,p^.p2);
  457. write_expr(outfile,p^.p1);
  458. write(outfile,':=');
  459. write_funexpr(outfile,p^.p2);
  460. writeln(outfile,';');
  461. popshift;
  462. writeln(outfile,aktspace,'end;');
  463. if not compactmode then
  464. popshift;
  465. flush(outfile);
  466. end;
  467. t_funexprlist :
  468. begin
  469. if assigned(p^.p3) then
  470. begin
  471. write_type_specifier(outfile,p^.p3);
  472. write(outfile,'(');
  473. end;
  474. if assigned(p^.p1) then
  475. write_funexpr(outfile,p^.p1);
  476. if assigned(p^.p2) then
  477. begin
  478. write(outfile,'(');
  479. write_funexpr(outfile,p^.p2);
  480. write(outfile,')');
  481. end;
  482. if assigned(p^.p3) then
  483. write(outfile,')');
  484. end
  485. else internalerror(5);
  486. end;
  487. end;
  488. end;
  489. function ellipsisarg : presobject;
  490. begin
  491. ellipsisarg:=new(presobject,init_two(t_arg,nil,nil));
  492. end;
  493. const
  494. (* if in args *dname is replaced by pdname *)
  495. in_args : boolean = false;
  496. typedef_level : longint = 0;
  497. (* writes an argument list, where p is t_arglist *)
  498. procedure write_args(var outfile:text; p : presobject);
  499. var
  500. len,para : longint;
  501. old_in_args : boolean;
  502. varpara : boolean;
  503. lastp : presobject;
  504. hs : string;
  505. begin
  506. NeedEllipsisOverload:=false;
  507. para:=1;
  508. len:=0;
  509. lastp:=nil;
  510. old_in_args:=in_args;
  511. in_args:=true;
  512. write(outfile,'(');
  513. shift(2);
  514. (* walk through all arguments *)
  515. (* p must be of type t_arglist *)
  516. while assigned(p) do
  517. begin
  518. if p^.typ<>t_arglist then
  519. internalerror(10);
  520. (* is ellipsis ? *)
  521. if not assigned(p^.p1^.p1) and
  522. not assigned(p^.p1^.next) then
  523. begin
  524. write(outfile,'args:array of const');
  525. (* if variable number of args we must allways pop *)
  526. no_pop:=false;
  527. (* Needs 2 declarations, also one without args, becuase
  528. in C you can omit the second parameter. Default parameter
  529. doesn't help as that isn't possible with array of const *)
  530. NeedEllipsisOverload:=true;
  531. (* Remove this para *)
  532. if assigned(lastp) then
  533. lastp^.next:=nil;
  534. dispose(p,done);
  535. (* leave the loop as p isnot valid anymore *)
  536. break;
  537. end
  538. (* we need to correct this in the pp file after *)
  539. else
  540. begin
  541. (* generate a call by reference parameter ? *)
  542. // varpara:=usevarparas and
  543. // assigned(p^.p1^.p2^.p1) and
  544. // (p^.p1^.p2^.p1^.typ in [t_addrdef,t_pointerdef]) and
  545. // assigned(p^.p1^.p2^.p1^.p1) and
  546. // (p^.p1^.p2^.p1^.p1^.typ<>t_procdef);
  547. varpara:=usevarparas and
  548. assigned(p^.p1^.p1) and
  549. (p^.p1^.p1^.typ in [t_addrdef,t_pointerdef]) and
  550. assigned(p^.p1^.p1^.p1) and
  551. (p^.p1^.p1^.p1^.typ<>t_procdef);
  552. (* do not do it for char pointer !! *)
  553. (* para : pchar; and var para : char; are *)
  554. (* completely different in pascal *)
  555. (* here we exclude all typename containing char *)
  556. (* is this a good method ?? *)
  557. if varpara and
  558. (p^.p1^.p1^.typ=t_pointerdef) and
  559. (p^.p1^.p1^.p1^.typ=t_id) and
  560. (pos('CHAR',uppercase(p^.p1^.p1^.p1^.str))<>0) then
  561. varpara:=false;
  562. if varpara then
  563. begin
  564. write(outfile,'var ');
  565. inc(len,4);
  566. end;
  567. (* write new parameter name *)
  568. if assigned(p^.p1^.p2^.p2) then
  569. begin
  570. hs:=FixId(p^.p1^.p2^.p2^.p);
  571. write(outfile,hs);
  572. inc(len,length(hs));
  573. end
  574. else
  575. begin
  576. If removeUnderscore then
  577. begin
  578. Write (outfile,'para',para);
  579. inc(Len,5);
  580. end
  581. else
  582. begin
  583. write(outfile,'_para',para);
  584. inc(Len,6);
  585. end;
  586. end;
  587. write(outfile,':');
  588. if varpara then
  589. begin
  590. write_p_a_def(outfile,p^.p1^.p2^.p1,p^.p1^.p1^.p1);
  591. end
  592. else
  593. write_p_a_def(outfile,p^.p1^.p2^.p1,p^.p1^.p1);
  594. end;
  595. lastp:=p;
  596. p:=p^.next;
  597. if assigned(p) then
  598. begin
  599. write(outfile,'; ');
  600. { if len>40 then : too complicated to compute }
  601. if (para mod 5) = 0 then
  602. begin
  603. writeln(outfile);
  604. write(outfile,aktspace);
  605. end;
  606. end;
  607. inc(para);
  608. end;
  609. write(outfile,')');
  610. flush(outfile);
  611. in_args:=old_in_args;
  612. popshift;
  613. end;
  614. procedure write_p_a_def(var outfile:text; p,simple_type : presobject);
  615. var
  616. i : longint;
  617. error : integer;
  618. pointerwritten,
  619. constant : boolean;
  620. begin
  621. if not(assigned(p)) then
  622. begin
  623. write_type_specifier(outfile,simple_type);
  624. exit;
  625. end;
  626. case p^.typ of
  627. t_pointerdef : begin
  628. (* procedure variable ? *)
  629. if assigned(p^.p1) and (p^.p1^.typ=t_procdef) then
  630. begin
  631. is_procvar:=true;
  632. (* distinguish between procedure and function *)
  633. if (simple_type^.typ=t_void) and (p^.p1^.p1=nil) then
  634. begin
  635. write(outfile,'procedure ');
  636. shift(10);
  637. (* write arguments *)
  638. if assigned(p^.p1^.p2) then
  639. write_args(outfile,p^.p1^.p2);
  640. flush(outfile);
  641. popshift;
  642. end
  643. else
  644. begin
  645. write(outfile,'function ');
  646. shift(9);
  647. (* write arguments *)
  648. if assigned(p^.p1^.p2) then
  649. write_args(outfile,p^.p1^.p2);
  650. write(outfile,':');
  651. flush(outfile);
  652. write_p_a_def(outfile,p^.p1^.p1,simple_type);
  653. popshift;
  654. end
  655. end
  656. else
  657. begin
  658. (* generate "pointer" ? *)
  659. if (simple_type^.typ=t_void) and (p^.p1=nil) then
  660. begin
  661. write(outfile,'pointer');
  662. flush(outfile);
  663. end
  664. else
  665. begin
  666. pointerwritten:=false;
  667. if (p^.p1=nil) and UsePPointers then
  668. begin
  669. if (simple_type^.typ=t_id) then
  670. begin
  671. write(outfile,PointerName(simple_type^.p));
  672. pointerwritten:=true;
  673. end
  674. { structure }
  675. else if (simple_type^.typ in [t_uniondef,t_structdef]) and
  676. (simple_type^.p1=nil) and (simple_type^.p2^.typ=t_id) then
  677. begin
  678. write(outfile,PointerName(simple_type^.p2^.p));
  679. pointerwritten:=true;
  680. end;
  681. end;
  682. if not pointerwritten then
  683. begin
  684. if in_args then
  685. begin
  686. write(outfile,'P');
  687. pointerprefix:=true;
  688. end
  689. else
  690. write(outfile,'^');
  691. write_p_a_def(outfile,p^.p1,simple_type);
  692. pointerprefix:=false;
  693. end;
  694. end;
  695. end;
  696. end;
  697. t_arraydef : begin
  698. constant:=false;
  699. if assigned(p^.p2) then
  700. begin
  701. if p^.p2^.typ=t_id then
  702. begin
  703. val(p^.p2^.str,i,error);
  704. if error=0 then
  705. begin
  706. dec(i);
  707. constant:=true;
  708. end;
  709. end;
  710. if not constant then
  711. begin
  712. write(outfile,'array[0..(');
  713. write_expr(outfile,p^.p2);
  714. write(outfile,')-1] of ');
  715. end
  716. else
  717. begin
  718. write(outfile,'array[0..',i,'] of ');
  719. end;
  720. end
  721. else
  722. begin
  723. (* open array *)
  724. write(outfile,'array of ');
  725. end;
  726. flush(outfile);
  727. write_p_a_def(outfile,p^.p1,simple_type);
  728. end;
  729. else internalerror(1);
  730. end;
  731. end;
  732. procedure write_type_specifier(var outfile:text; p : presobject);
  733. var
  734. hp1,hp2,hp3,lastexpr : presobject;
  735. i,l,w : longint;
  736. error : integer;
  737. current_power,
  738. mask : cardinal;
  739. flag_index : longint;
  740. current_level : byte;
  741. pointerwritten,
  742. is_sized : boolean;
  743. begin
  744. case p^.typ of
  745. t_id :
  746. begin
  747. if pointerprefix then
  748. PTypeList.Add('P'+p^.str);
  749. if p^.intname then
  750. write(outfile,p^.p)
  751. else
  752. write(outfile,TypeName(p^.p));
  753. end;
  754. { what can we do with void defs ? }
  755. t_void :
  756. write(outfile,'void');
  757. t_pointerdef :
  758. begin
  759. pointerwritten:=false;
  760. if (p^.p1^.typ=t_void) then
  761. begin
  762. write(outfile,'pointer');
  763. pointerwritten:=true;
  764. end
  765. else
  766. if UsePPointers then
  767. begin
  768. if (p^.p1^.typ=t_id) then
  769. begin
  770. write(outfile,PointerName(p^.p1^.p));
  771. pointerwritten:=true;
  772. end
  773. { structure }
  774. else if (p^.p1^.typ in [t_uniondef,t_structdef]) and
  775. (p^.p1^.p1=nil) and (p^.p1^.p2^.typ=t_id) then
  776. begin
  777. write(outfile,PointerName(p^.p1^.p2^.p));
  778. pointerwritten:=true;
  779. end;
  780. end;
  781. if not pointerwritten then
  782. begin
  783. if in_args then
  784. begin
  785. write(outfile,'P');
  786. pointerprefix:=true;
  787. end
  788. else
  789. write(outfile,'^');
  790. write_type_specifier(outfile,p^.p1);
  791. pointerprefix:=false;
  792. end;
  793. end;
  794. t_enumdef :
  795. begin
  796. if (typedef_level>1) and (p^.p1=nil) and
  797. (p^.p2^.typ=t_id) then
  798. begin
  799. if pointerprefix then
  800. PTypeList.Add('P'+p^.p2^.str);
  801. write(outfile,p^.p2^.p);
  802. end
  803. else
  804. if not EnumToConst then
  805. begin
  806. write(outfile,'(');
  807. hp1:=p^.p1;
  808. w:=length(aktspace);
  809. while assigned(hp1) do
  810. begin
  811. write(outfile,hp1^.p1^.p);
  812. if assigned(hp1^.p2) then
  813. begin
  814. write(outfile,' := ');
  815. write_expr(outfile,hp1^.p2);
  816. w:=w+6;(* strlen(hp1^.p); *)
  817. end;
  818. w:=w+length(hp1^.p1^.str);
  819. hp1:=hp1^.next;
  820. if assigned(hp1) then
  821. write(outfile,',');
  822. if w>40 then
  823. begin
  824. writeln(outfile);
  825. write(outfile,aktspace);
  826. w:=length(aktspace);
  827. end;
  828. flush(outfile);
  829. end;
  830. write(outfile,')');
  831. flush(outfile);
  832. end
  833. else
  834. begin
  835. Writeln (outfile,' Longint;');
  836. hp1:=p^.p1;
  837. l:=0;
  838. lastexpr:=nil;
  839. Writeln (outfile,copy(aktspace,1,length(aktspace)-2),'Const');
  840. while assigned(hp1) do
  841. begin
  842. write (outfile,aktspace,hp1^.p1^.p,' = ');
  843. if assigned(hp1^.p2) then
  844. begin
  845. write_expr(outfile,hp1^.p2);
  846. writeln(outfile,';');
  847. lastexpr:=hp1^.p2;
  848. if lastexpr^.typ=t_id then
  849. begin
  850. val(lastexpr^.str,l,error);
  851. if error=0 then
  852. begin
  853. inc(l);
  854. lastexpr:=nil;
  855. end
  856. else
  857. l:=1;
  858. end
  859. else
  860. l:=1;
  861. end
  862. else
  863. begin
  864. if assigned(lastexpr) then
  865. begin
  866. write(outfile,'(');
  867. write_expr(outfile,lastexpr);
  868. writeln(outfile,')+',l,';');
  869. end
  870. else
  871. writeln (outfile,l,';');
  872. inc(l);
  873. end;
  874. hp1:=hp1^.next;
  875. flush(outfile);
  876. end;
  877. block_type:=bt_const;
  878. end;
  879. end;
  880. t_structdef :
  881. begin
  882. inc(typedef_level);
  883. flag_index:=-1;
  884. is_sized:=false;
  885. current_level:=0;
  886. if ((in_args) or (typedef_level>1)) and
  887. (p^.p1=nil) and (p^.p2^.typ=t_id) then
  888. begin
  889. if pointerprefix then
  890. PTypeList.Add('P'+p^.p2^.str);
  891. write(outfile,TypeName(p^.p2^.p));
  892. end
  893. else
  894. begin
  895. if packrecords then
  896. writeln(outfile,'packed record')
  897. else
  898. writeln(outfile,'record');
  899. shift(3);
  900. hp1:=p^.p1;
  901. (* walk through all members *)
  902. while assigned(hp1) do
  903. begin
  904. (* hp2 is t_memberdec *)
  905. hp2:=hp1^.p1;
  906. (* hp3 is t_declist *)
  907. hp3:=hp2^.p2;
  908. while assigned(hp3) do
  909. begin
  910. if not assigned(hp3^.p1^.p3) or
  911. (hp3^.p1^.p3^.typ <> t_size_specifier) then
  912. begin
  913. if is_sized then
  914. begin
  915. if current_level <= 16 then
  916. writeln(outfile,'word;')
  917. else if current_level <= 32 then
  918. writeln(outfile,'longint;')
  919. else
  920. internalerror(11);
  921. is_sized:=false;
  922. end;
  923. write(outfile,aktspace,FixId(hp3^.p1^.p2^.p));
  924. write(outfile,' : ');
  925. shift(2);
  926. write_p_a_def(outfile,hp3^.p1^.p1,hp2^.p1);
  927. popshift;
  928. end;
  929. { size specifier or default value ? }
  930. if assigned(hp3^.p1^.p3) then
  931. begin
  932. { we could use mask to implement this }
  933. { because we need to respect the positions }
  934. if hp3^.p1^.p3^.typ = t_size_specifier then
  935. begin
  936. if not is_sized then
  937. begin
  938. current_power:=1;
  939. current_level:=0;
  940. inc(flag_index);
  941. write(outfile,aktspace,'flag',flag_index,' : ');
  942. end;
  943. must_write_packed_field:=true;
  944. is_sized:=true;
  945. { can it be something else than a constant ? }
  946. { it can be a macro !! }
  947. if hp3^.p1^.p3^.p1^.typ=t_id then
  948. begin
  949. val(hp3^.p1^.p3^.p1^.str,l,error);
  950. if error=0 then
  951. begin
  952. mask:=0;
  953. for i:=1 to l do
  954. begin
  955. inc(mask,current_power);
  956. current_power:=current_power*2;
  957. end;
  958. write(tempfile,'bm_&',hp3^.p1^.p2^.p);
  959. writeln(tempfile,' = ',hexstr(mask),';');
  960. write(tempfile,'bp_&',hp3^.p1^.p2^.p);
  961. writeln(tempfile,' = ',current_level,';');
  962. current_level:=current_level + l;
  963. { go to next flag if 31 }
  964. if current_level = 32 then
  965. begin
  966. write(outfile,'longint');
  967. is_sized:=false;
  968. end;
  969. end;
  970. end;
  971. end
  972. else if hp3^.p1^.p3^.typ = t_default_value then
  973. begin
  974. write(outfile,'{=');
  975. write_expr(outfile,hp3^.p1^.p3^.p1);
  976. write(outfile,' ignored}');
  977. end;
  978. end;
  979. if not is_sized then
  980. begin
  981. if is_procvar then
  982. begin
  983. if not no_pop then
  984. begin
  985. write(outfile,';cdecl');
  986. no_pop:=true;
  987. end;
  988. is_procvar:=false;
  989. end;
  990. writeln(outfile,';');
  991. end;
  992. hp3:=hp3^.next;
  993. end;
  994. hp1:=hp1^.next;
  995. end;
  996. if is_sized then
  997. begin
  998. if current_level <= 16 then
  999. writeln(outfile,'word;')
  1000. else if current_level <= 32 then
  1001. writeln(outfile,'longint;')
  1002. else
  1003. internalerror(11);
  1004. is_sized:=false;
  1005. end;
  1006. popshift;
  1007. write(outfile,aktspace,'end');
  1008. flush(outfile);
  1009. end;
  1010. dec(typedef_level);
  1011. end;
  1012. t_uniondef :
  1013. begin
  1014. inc(typedef_level);
  1015. if (typedef_level>1) and (p^.p1=nil) and
  1016. (p^.p2^.typ=t_id) then
  1017. begin
  1018. write(outfile,p^.p2^.p);
  1019. end
  1020. else
  1021. begin
  1022. inc(typedef_level);
  1023. if packrecords then
  1024. writeln(outfile,'packed record')
  1025. else
  1026. writeln(outfile,'record');
  1027. shift(2);
  1028. writeln(outfile,aktspace,'case longint of');
  1029. shift(3);
  1030. l:=0;
  1031. hp1:=p^.p1;
  1032. (* walk through all members *)
  1033. while assigned(hp1) do
  1034. begin
  1035. (* hp2 is t_memberdec *)
  1036. hp2:=hp1^.p1;
  1037. (* hp3 is t_declist *)
  1038. hp3:=hp2^.p2;
  1039. while assigned(hp3) do
  1040. begin
  1041. write(outfile,aktspace,l,' : ( ');
  1042. write(outfile,FixId(hp3^.p1^.p2^.p),' : ');
  1043. shift(2);
  1044. write_p_a_def(outfile,hp3^.p1^.p1,hp2^.p1);
  1045. popshift;
  1046. writeln(outfile,' );');
  1047. hp3:=hp3^.next;
  1048. inc(l);
  1049. end;
  1050. hp1:=hp1^.next;
  1051. end;
  1052. popshift;
  1053. write(outfile,aktspace,'end');
  1054. popshift;
  1055. flush(outfile);
  1056. dec(typedef_level);
  1057. end;
  1058. dec(typedef_level);
  1059. end;
  1060. else
  1061. internalerror(3);
  1062. end;
  1063. end;
  1064. procedure write_def_params(var outfile:text; p : presobject);
  1065. var
  1066. hp1 : presobject;
  1067. begin
  1068. case p^.typ of
  1069. t_enumdef : begin
  1070. hp1:=p^.p1;
  1071. while assigned(hp1) do
  1072. begin
  1073. write(outfile,FixId(hp1^.p1^.p));
  1074. hp1:=hp1^.next;
  1075. if assigned(hp1) then
  1076. write(outfile,',')
  1077. else
  1078. write(outfile);
  1079. flush(outfile);
  1080. end;
  1081. flush(outfile);
  1082. end;
  1083. else internalerror(4);
  1084. end;
  1085. end;
  1086. %}
  1087. %token TYPEDEF DEFINE
  1088. %token COLON SEMICOLON COMMA
  1089. %token LKLAMMER RKLAMMER LECKKLAMMER RECKKLAMMER
  1090. %token LGKLAMMER RGKLAMMER
  1091. %token STRUCT UNION ENUM
  1092. %token ID NUMBER CSTRING
  1093. %token SHORT UNSIGNED LONG INT REAL _CHAR
  1094. %token VOID _CONST
  1095. %token _FAR _HUGE _NEAR
  1096. %token _ASSIGN NEW_LINE SPACE_DEFINE
  1097. %token EXTERN STDCALL CDECL CALLBACK PASCAL WINAPI APIENTRY WINGDIAPI SYS_TRAP
  1098. %token _PACKED
  1099. %token ELLIPSIS
  1100. %right R_AND
  1101. %left EQUAL UNEQUAL GT LT GTE LTE
  1102. %left QUESTIONMARK COLON
  1103. %left _OR
  1104. %left _AND
  1105. %left _PLUS MINUS
  1106. %left _SHR _SHL
  1107. %left STAR _SLASH
  1108. %right _NOT
  1109. %right LKLAMMER
  1110. %right PSTAR
  1111. %right P_AND
  1112. %right LECKKLAMMER
  1113. %left POINT DEREF
  1114. %left COMMA
  1115. %left STICK
  1116. %token SIGNED
  1117. %%
  1118. file : declaration_list
  1119. ;
  1120. maybe_space :
  1121. SPACE_DEFINE
  1122. {
  1123. $$:=nil;
  1124. } |
  1125. {
  1126. $$:=nil;
  1127. }
  1128. ;
  1129. error_info : {
  1130. writeln(outfile,'(* error ');
  1131. writeln(outfile,yyline);
  1132. };
  1133. declaration_list : declaration_list declaration
  1134. { if yydebug then writeln('declaration reduced at line ',line_no);
  1135. if yydebug then writeln(outfile,'(* declaration reduced *)');
  1136. }
  1137. | declaration_list define_dec
  1138. { if yydebug then writeln('define declaration reduced at line ',line_no);
  1139. if yydebug then writeln(outfile,'(* define declaration reduced *)');
  1140. }
  1141. | declaration
  1142. { if yydebug then writeln('declaration reduced at line ',line_no);
  1143. }
  1144. | define_dec
  1145. { if yydebug then writeln('define declaration reduced at line ',line_no);
  1146. }
  1147. ;
  1148. dec_specifier :
  1149. EXTERN { $$:=new(presobject,init_id('extern')); }
  1150. |{ $$:=new(presobject,init_id('intern')); }
  1151. ;
  1152. dec_modifier :
  1153. STDCALL { $$:=new(presobject,init_id('no_pop')); }
  1154. | CDECL { $$:=new(presobject,init_id('cdecl')); }
  1155. | CALLBACK { $$:=new(presobject,init_id('no_pop')); }
  1156. | PASCAL { $$:=new(presobject,init_id('no_pop')); }
  1157. | WINAPI { $$:=new(presobject,init_id('no_pop')); }
  1158. | APIENTRY { $$:=new(presobject,init_id('no_pop')); }
  1159. | WINGDIAPI { $$:=new(presobject,init_id('no_pop')); }
  1160. | { $$:=nil }
  1161. ;
  1162. systrap_specifier:
  1163. SYS_TRAP LKLAMMER dname RKLAMMER { $$:=$3; }
  1164. | { $$:=nil; }
  1165. ;
  1166. declaration :
  1167. dec_specifier type_specifier dec_modifier declarator_list systrap_specifier SEMICOLON
  1168. {
  1169. IsExtern:=false;
  1170. (* by default we must pop the args pushed on stack *)
  1171. no_pop:=false;
  1172. if (assigned($4)and assigned($4^.p1)and assigned($4^.p1^.p1))
  1173. and ($4^.p1^.p1^.typ=t_procdef) then
  1174. begin
  1175. repeat
  1176. If UseLib then
  1177. IsExtern:=true
  1178. else
  1179. IsExtern:=assigned($1)and($1^.str='extern');
  1180. no_pop:=assigned($3) and ($3^.str='no_pop');
  1181. if (block_type<>bt_func) and not(createdynlib) then
  1182. begin
  1183. writeln(outfile);
  1184. block_type:=bt_func;
  1185. end;
  1186. (* dyn. procedures must be put into a var block *)
  1187. if createdynlib then
  1188. begin
  1189. if (block_type<>bt_var) then
  1190. begin
  1191. if not(compactmode) then
  1192. writeln(outfile);
  1193. writeln(outfile,aktspace,'var');
  1194. block_type:=bt_var;
  1195. end;
  1196. shift(2);
  1197. end;
  1198. if not CompactMode then
  1199. begin
  1200. write(outfile,aktspace);
  1201. if not IsExtern then
  1202. write(implemfile,aktspace);
  1203. end;
  1204. (* distinguish between procedure and function *)
  1205. if assigned($2) then
  1206. if ($2^.typ=t_void) and ($4^.p1^.p1^.p1=nil) then
  1207. begin
  1208. if createdynlib then
  1209. begin
  1210. write(outfile,$4^.p1^.p2^.p,' : procedure');
  1211. end
  1212. else
  1213. begin
  1214. shift(10);
  1215. write(outfile,'procedure ',$4^.p1^.p2^.p);
  1216. end;
  1217. if assigned($4^.p1^.p1^.p2) then
  1218. write_args(outfile,$4^.p1^.p1^.p2);
  1219. if createdynlib then
  1220. begin
  1221. loaddynlibproc.add('pointer('+$4^.p1^.p2^.p+'):=GetProcAddress(hlib,'''+$4^.p1^.p2^.p+''');');
  1222. freedynlibproc.add($4^.p1^.p2^.p+':=nil;');
  1223. end
  1224. else if not IsExtern then
  1225. begin
  1226. write(implemfile,'procedure ',$4^.p1^.p2^.p);
  1227. if assigned($4^.p1^.p1^.p2) then
  1228. write_args(implemfile,$4^.p1^.p1^.p2);
  1229. end;
  1230. end
  1231. else
  1232. begin
  1233. if createdynlib then
  1234. begin
  1235. write(outfile,$4^.p1^.p2^.p,' : function');
  1236. end
  1237. else
  1238. begin
  1239. shift(9);
  1240. write(outfile,'function ',$4^.p1^.p2^.p);
  1241. end;
  1242. if assigned($4^.p1^.p1^.p2) then
  1243. write_args(outfile,$4^.p1^.p1^.p2);
  1244. write(outfile,':');
  1245. write_p_a_def(outfile,$4^.p1^.p1^.p1,$2);
  1246. if createdynlib then
  1247. begin
  1248. loaddynlibproc.add('pointer('+$4^.p1^.p2^.p+'):=GetProcAddress(hlib,'''+$4^.p1^.p2^.p+''');');
  1249. freedynlibproc.add($4^.p1^.p2^.p+':=nil;');
  1250. end
  1251. else if not IsExtern then
  1252. begin
  1253. write(implemfile,'function ',$4^.p1^.p2^.p);
  1254. if assigned($4^.p1^.p1^.p2) then
  1255. write_args(implemfile,$4^.p1^.p1^.p2);
  1256. write(implemfile,':');
  1257. write_p_a_def(implemfile,$4^.p1^.p1^.p1,$2);
  1258. end;
  1259. end;
  1260. if assigned($5) then
  1261. write(outfile,';systrap ',$5^.p);
  1262. (* No CDECL in interface for Uselib *)
  1263. if IsExtern and (not no_pop) then
  1264. write(outfile,';cdecl');
  1265. popshift;
  1266. if createdynlib then
  1267. begin
  1268. writeln(outfile,';');
  1269. end
  1270. else if UseLib then
  1271. begin
  1272. if IsExtern then
  1273. begin
  1274. write (outfile,';external');
  1275. If UseName then
  1276. Write(outfile,' External_library name ''',$4^.p1^.p2^.p,'''');
  1277. end;
  1278. writeln(outfile,';');
  1279. end
  1280. else
  1281. begin
  1282. writeln(outfile,';');
  1283. if not IsExtern then
  1284. begin
  1285. writeln(implemfile,';');
  1286. writeln(implemfile,aktspace,'begin');
  1287. writeln(implemfile,aktspace,' { You must implement this function }');
  1288. writeln(implemfile,aktspace,'end;');
  1289. end;
  1290. end;
  1291. IsExtern:=false;
  1292. if not(compactmode) and not(createdynlib) then
  1293. writeln(outfile);
  1294. until not NeedEllipsisOverload;
  1295. end
  1296. else (* $4^.p1^.p1^.typ=t_procdef *)
  1297. if assigned($4)and assigned($4^.p1) then
  1298. begin
  1299. shift(2);
  1300. if block_type<>bt_var then
  1301. begin
  1302. if not(compactmode) then
  1303. writeln(outfile);
  1304. writeln(outfile,aktspace,'var');
  1305. end;
  1306. block_type:=bt_var;
  1307. shift(3);
  1308. IsExtern:=assigned($1)and($1^.str='extern');
  1309. (* walk through all declarations *)
  1310. hp:=$4;
  1311. while assigned(hp) and assigned(hp^.p1) do
  1312. begin
  1313. (* write new var name *)
  1314. if assigned(hp^.p1^.p2) and assigned(hp^.p1^.p2^.p) then
  1315. write(outfile,aktspace,hp^.p1^.p2^.p);
  1316. write(outfile,' : ');
  1317. shift(2);
  1318. (* write its type *)
  1319. write_p_a_def(outfile,hp^.p1^.p1,$2);
  1320. if assigned(hp^.p1^.p2)and assigned(hp^.p1^.p2^.p)then
  1321. begin
  1322. if isExtern then
  1323. write(outfile,';cvar;external')
  1324. else
  1325. write(outfile,';cvar;public');
  1326. end;
  1327. writeln(outfile,';');
  1328. popshift;
  1329. hp:=hp^.p2;
  1330. end;
  1331. popshift;
  1332. popshift;
  1333. end;
  1334. if assigned($1)then dispose($1,done);
  1335. if assigned($2)then dispose($2,done);
  1336. if assigned($4)then dispose($4,done);
  1337. } |
  1338. special_type_specifier SEMICOLON
  1339. {
  1340. if block_type<>bt_type then
  1341. begin
  1342. if not(compactmode) then
  1343. writeln(outfile);
  1344. writeln(outfile,aktspace,'type');
  1345. block_type:=bt_type;
  1346. end;
  1347. shift(3);
  1348. if ( yyv[yysp-1]^.p2 <> nil ) then
  1349. begin
  1350. (* write new type name *)
  1351. TN:=TypeName($1^.p2^.p);
  1352. PN:=PointerName($1^.p2^.p);
  1353. (* define a Pointer type also for structs *)
  1354. if UsePPointers and (Uppercase(tn)<>Uppercase(pn)) and
  1355. assigned($1) and ($1^.typ in [t_uniondef,t_structdef]) then
  1356. writeln(outfile,aktspace,PN,' = ^',TN,';');
  1357. write(outfile,aktspace,TN,' = ');
  1358. shift(2);
  1359. hp:=$1;
  1360. write_type_specifier(outfile,hp);
  1361. popshift;
  1362. (* enum_to_const can make a switch to const *)
  1363. if block_type=bt_type then
  1364. writeln(outfile,';');
  1365. writeln(outfile);
  1366. flush(outfile);
  1367. popshift;
  1368. if must_write_packed_field then
  1369. write_packed_fields_info(outfile,hp,TN);
  1370. if assigned(hp) then
  1371. dispose(hp,done)
  1372. end
  1373. else
  1374. begin
  1375. TN:=TypeName(yyv[yysp-1]^.str);
  1376. PN:=PointerName(yyv[yysp-1]^.str);
  1377. if UsePPointers then writeln(outfile,aktspace,PN,' = ^',TN,';');
  1378. if PackRecords then
  1379. writeln(outfile, aktspace, TN, ' = packed record')
  1380. else
  1381. writeln(outfile, aktspace, TN, ' = record');
  1382. writeln(outfile, aktspace, ' {undefined structure}');
  1383. writeln(outfile, aktspace, ' end;');
  1384. writeln(outfile);
  1385. popshift;
  1386. end;
  1387. } |
  1388. TYPEDEF STRUCT dname dname SEMICOLON
  1389. {
  1390. (* TYPEDEF STRUCT dname dname SEMICOLON *)
  1391. if block_type<>bt_type then
  1392. begin
  1393. if not(compactmode) then
  1394. writeln(outfile);
  1395. writeln(outfile,aktspace,'type');
  1396. block_type:=bt_type;
  1397. end;
  1398. PN:=TypeName($3^.p);
  1399. TN:=TypeName($4^.p);
  1400. if Uppercase(tn)<>Uppercase(pn) then
  1401. begin
  1402. shift(3);
  1403. writeln(outfile,aktspace,PN,' = ',TN,';');
  1404. popshift;
  1405. end;
  1406. if assigned($3) then
  1407. dispose($3,done);
  1408. if assigned($4) then
  1409. dispose($4,done);
  1410. } |
  1411. TYPEDEF type_specifier LKLAMMER dec_modifier declarator RKLAMMER maybe_space LKLAMMER argument_declaration_list RKLAMMER SEMICOLON
  1412. {
  1413. (* TYPEDEF type_specifier LKLAMMER dec_modifier declarator RKLAMMER maybe_space LKLAMMER argument_declaration_list RKLAMMER SEMICOLON *)
  1414. if block_type<>bt_type then
  1415. begin
  1416. if not(compactmode) then
  1417. writeln(outfile);
  1418. writeln(outfile,aktspace,'type');
  1419. block_type:=bt_type;
  1420. end;
  1421. no_pop:=assigned($4) and ($4^.str='no_pop');
  1422. shift(3);
  1423. (* walk through all declarations *)
  1424. hp:=$5;
  1425. if assigned(hp) then
  1426. begin
  1427. hp:=$5;
  1428. while assigned(hp^.p1) do
  1429. hp:=hp^.p1;
  1430. hp^.p1:=new(presobject,init_two(t_procdef,nil,$9));
  1431. hp:=$5;
  1432. if assigned(hp^.p1) and assigned(hp^.p1^.p1) then
  1433. begin
  1434. writeln(outfile);
  1435. (* write new type name *)
  1436. write(outfile,aktspace,TypeName(hp^.p2^.p),' = ');
  1437. shift(2);
  1438. write_p_a_def(outfile,hp^.p1,$2);
  1439. popshift;
  1440. (* if no_pop it is normal fpc calling convention *)
  1441. if is_procvar and
  1442. (not no_pop) then
  1443. write(outfile,';cdecl');
  1444. writeln(outfile,';');
  1445. flush(outfile);
  1446. end;
  1447. end;
  1448. popshift;
  1449. if assigned($2)then
  1450. dispose($2,done);
  1451. if assigned($4)then
  1452. dispose($4,done);
  1453. if assigned($5)then (* disposes also $9 *)
  1454. dispose($5,done);
  1455. } |
  1456. TYPEDEF type_specifier dec_modifier declarator_list SEMICOLON
  1457. {
  1458. (* TYPEDEF type_specifier dec_modifier declarator_list SEMICOLON *)
  1459. if block_type<>bt_type then
  1460. begin
  1461. if not(compactmode) then
  1462. writeln(outfile);
  1463. writeln(outfile,aktspace,'type');
  1464. block_type:=bt_type;
  1465. end;
  1466. no_pop:=assigned($3) and ($3^.str='no_pop');
  1467. shift(3);
  1468. (* Get the name to write the type definition for, try
  1469. to use the tag name first *)
  1470. if assigned($2^.p2) then
  1471. begin
  1472. ph:=$2^.p2;
  1473. end
  1474. else
  1475. begin
  1476. if not assigned($4^.p1^.p2) then
  1477. internalerror(4444);
  1478. ph:=$4^.p1^.p2;
  1479. end;
  1480. (* write type definition *)
  1481. is_procvar:=false;
  1482. writeln(outfile);
  1483. TN:=TypeName(ph^.p);
  1484. PN:=PointerName(ph^.p);
  1485. if UsePPointers and (Uppercase(tn)<>Uppercase(pn)) and
  1486. assigned($2) and ($2^.typ<>t_procdef) then
  1487. writeln(outfile,aktspace,PN,' = ^',TN,';');
  1488. (* write new type name *)
  1489. write(outfile,aktspace,TN,' = ');
  1490. shift(2);
  1491. write_type_specifier(outfile,$2);
  1492. popshift;
  1493. (* if no_pop it is normal fpc calling convention *)
  1494. if is_procvar and
  1495. (not no_pop) then
  1496. write(outfile,';cdecl');
  1497. writeln(outfile,';');
  1498. flush(outfile);
  1499. (* write alias names, ph points to the name already used *)
  1500. hp:=$4;
  1501. while assigned(hp) do
  1502. begin
  1503. if (hp<>ph) and assigned(hp^.p1^.p2) then
  1504. begin
  1505. PN:=TypeName(ph^.p);
  1506. TN:=TypeName(hp^.p1^.p2^.p);
  1507. if Uppercase(TN)<>Uppercase(PN) then
  1508. begin
  1509. write(outfile,aktspace,TN,' = ');
  1510. write_p_a_def(outfile,hp^.p1^.p1,ph);
  1511. writeln(outfile,';');
  1512. PN:=PointerName(hp^.p1^.p2^.p);
  1513. if UsePPointers and (Uppercase(tn)<>Uppercase(pn)) and
  1514. assigned($2) and ($2^.typ<>t_procdef) then
  1515. writeln(outfile,aktspace,PN,' = ^',TN,';');
  1516. end;
  1517. end;
  1518. hp:=hp^.next;
  1519. end;
  1520. popshift;
  1521. if must_write_packed_field then
  1522. if assigned(ph) then
  1523. write_packed_fields_info(outfile,$2,ph^.str)
  1524. else if assigned($2^.p2) then
  1525. write_packed_fields_info(outfile,$2,$2^.p2^.str);
  1526. if assigned($2)then
  1527. dispose($2,done);
  1528. if assigned($3)then
  1529. dispose($3,done);
  1530. if assigned($4)then
  1531. dispose($4,done);
  1532. } |
  1533. TYPEDEF dname SEMICOLON
  1534. {
  1535. if block_type<>bt_type then
  1536. begin
  1537. if not(compactmode) then
  1538. writeln(outfile);
  1539. writeln(outfile,aktspace,'type');
  1540. block_type:=bt_type;
  1541. end;
  1542. shift(3);
  1543. (* write as pointer *)
  1544. writeln(outfile);
  1545. writeln(outfile,'(* generic typedef *)');
  1546. writeln(outfile,aktspace,$2^.p,' = pointer;');
  1547. flush(outfile);
  1548. popshift;
  1549. if assigned($2) then
  1550. dispose($2,done);
  1551. }
  1552. | error error_info SEMICOLON
  1553. { writeln(outfile,'in declaration at line ',line_no,' *)');
  1554. aktspace:='';
  1555. in_space_define:=0;
  1556. in_define:=false;
  1557. arglevel:=0;
  1558. if_nb:=0;
  1559. aktspace:=' ';
  1560. space_index:=1;
  1561. yyerrok;}
  1562. ;
  1563. define_dec :
  1564. DEFINE dname LKLAMMER enum_list RKLAMMER para_def_expr NEW_LINE
  1565. {
  1566. (* DEFINE dname LKLAMMER enum_list RKLAMMER para_def_expr NEW_LINE *)
  1567. if not stripinfo then
  1568. begin
  1569. writeln (outfile,aktspace,'{ was #define dname(params) para_def_expr }');
  1570. writeln (implemfile,aktspace,'{ was #define dname(params) para_def_expr }');
  1571. if assigned($4) then
  1572. begin
  1573. writeln (outfile,aktspace,'{ argument types are unknown }');
  1574. writeln (implemfile,aktspace,'{ argument types are unknown }');
  1575. end;
  1576. if not assigned($6^.p3) then
  1577. begin
  1578. writeln(outfile,aktspace,'{ return type might be wrong } ');
  1579. writeln(implemfile,aktspace,'{ return type might be wrong } ');
  1580. end;
  1581. end;
  1582. block_type:=bt_func;
  1583. write(outfile,aktspace,'function ',$2^.p);
  1584. write(implemfile,aktspace,'function ',$2^.p);
  1585. if assigned($4) then
  1586. begin
  1587. write(outfile,'(');
  1588. write(implemfile,'(');
  1589. ph:=new(presobject,init_one(t_enumdef,$4));
  1590. write_def_params(outfile,ph);
  1591. write_def_params(implemfile,ph);
  1592. if assigned(ph) then dispose(ph,done);
  1593. ph:=nil;
  1594. (* types are unknown *)
  1595. write(outfile,' : longint)');
  1596. write(implemfile,' : longint)');
  1597. end;
  1598. if not assigned($6^.p3) then
  1599. begin
  1600. writeln(outfile,' : longint;',aktspace,commentstr);
  1601. writeln(implemfile,' : longint;');
  1602. flush(outfile);
  1603. end
  1604. else
  1605. begin
  1606. write(outfile,' : ');
  1607. write_type_specifier(outfile,$6^.p3);
  1608. writeln(outfile,';',aktspace,commentstr);
  1609. flush(outfile);
  1610. write(implemfile,' : ');
  1611. write_type_specifier(implemfile,$6^.p3);
  1612. writeln(implemfile,';');
  1613. end;
  1614. writeln(outfile);
  1615. flush(outfile);
  1616. hp:=new(presobject,init_two(t_funcname,$2,$6));
  1617. write_funexpr(implemfile,hp);
  1618. writeln(implemfile);
  1619. flush(implemfile);
  1620. if assigned(hp)then dispose(hp,done);
  1621. }|
  1622. DEFINE dname SPACE_DEFINE NEW_LINE
  1623. {
  1624. (* DEFINE dname SPACE_DEFINE NEW_LINE *)
  1625. writeln(outfile,'{$define ',$2^.p,'}',aktspace,commentstr);
  1626. flush(outfile);
  1627. if assigned($2)then
  1628. dispose($2,done);
  1629. }|
  1630. DEFINE dname NEW_LINE
  1631. {
  1632. writeln(outfile,'{$define ',$2^.p,'}',aktspace,commentstr);
  1633. flush(outfile);
  1634. if assigned($2)then
  1635. dispose($2,done);
  1636. } |
  1637. DEFINE dname SPACE_DEFINE def_expr NEW_LINE
  1638. {
  1639. (* DEFINE dname SPACE_DEFINE def_expr NEW_LINE *)
  1640. if ($4^.typ=t_exprlist) and
  1641. $4^.p1^.is_const and
  1642. not assigned($4^.next) then
  1643. begin
  1644. if block_type<>bt_const then
  1645. begin
  1646. writeln(outfile);
  1647. writeln(outfile,aktspace,'const');
  1648. end;
  1649. block_type:=bt_const;
  1650. shift(3);
  1651. write(outfile,aktspace,$2^.p);
  1652. write(outfile,' = ');
  1653. flush(outfile);
  1654. write_expr(outfile,$4^.p1);
  1655. writeln(outfile,';',aktspace,commentstr);
  1656. popshift;
  1657. if assigned($2) then
  1658. dispose($2,done);
  1659. if assigned($4) then
  1660. dispose($4,done);
  1661. end
  1662. else
  1663. begin
  1664. if not stripinfo then
  1665. begin
  1666. writeln (outfile,aktspace,'{ was #define dname def_expr }');
  1667. writeln (implemfile,aktspace,'{ was #define dname def_expr }');
  1668. end;
  1669. block_type:=bt_func;
  1670. write(outfile,aktspace,'function ',$2^.p);
  1671. write(implemfile,aktspace,'function ',$2^.p);
  1672. shift(2);
  1673. if not assigned($4^.p3) then
  1674. begin
  1675. writeln(outfile,' : longint;');
  1676. writeln(outfile,aktspace,' { return type might be wrong }');
  1677. flush(outfile);
  1678. writeln(implemfile,' : longint;');
  1679. writeln(implemfile,aktspace,' { return type might be wrong }');
  1680. end
  1681. else
  1682. begin
  1683. write(outfile,' : ');
  1684. write_type_specifier(outfile,$4^.p3);
  1685. writeln(outfile,';',aktspace,commentstr);
  1686. flush(outfile);
  1687. write(implemfile,' : ');
  1688. write_type_specifier(implemfile,$4^.p3);
  1689. writeln(implemfile,';');
  1690. end;
  1691. writeln(outfile);
  1692. flush(outfile);
  1693. hp:=new(presobject,init_two(t_funcname,$2,$4));
  1694. write_funexpr(implemfile,hp);
  1695. popshift;
  1696. dispose(hp,done);
  1697. writeln(implemfile);
  1698. flush(implemfile);
  1699. end;
  1700. }
  1701. | error error_info NEW_LINE
  1702. { writeln(outfile,'in define line ',line_no,' *)');
  1703. aktspace:='';
  1704. in_space_define:=0;
  1705. in_define:=false;
  1706. arglevel:=0;
  1707. if_nb:=0;
  1708. aktspace:=' ';
  1709. space_index:=1;
  1710. yyerrok;}
  1711. ;
  1712. closed_list : LGKLAMMER member_list RGKLAMMER
  1713. {$$:=$2;} |
  1714. error error_info RGKLAMMER
  1715. { writeln(outfile,' in member_list *)');
  1716. yyerrok;
  1717. $$:=nil;
  1718. }
  1719. ;
  1720. closed_enum_list : LGKLAMMER enum_list RGKLAMMER
  1721. {$$:=$2;} |
  1722. error error_info RGKLAMMER
  1723. { writeln(outfile,' in enum_list *)');
  1724. yyerrok;
  1725. $$:=nil;
  1726. }
  1727. ;
  1728. special_type_specifier :
  1729. STRUCT dname closed_list _PACKED
  1730. {
  1731. if (not is_packed) and (not packrecords) then
  1732. writeln(outfile,'{$PACKRECORDS 1}');
  1733. is_packed:=true;
  1734. $$:=new(presobject,init_two(t_structdef,$3,$2));
  1735. } |
  1736. STRUCT dname closed_list
  1737. {
  1738. if (is_packed) and (not packrecords) then
  1739. writeln(outfile,'{$PACKRECORDS 4}');
  1740. is_packed:=false;
  1741. $$:=new(presobject,init_two(t_structdef,$3,$2));
  1742. } |
  1743. UNION dname closed_list _PACKED
  1744. {
  1745. if (not is_packed) and (not packrecords) then
  1746. writeln(outfile,'{$PACKRECORDS 1}');
  1747. is_packed:=true;
  1748. $$:=new(presobject,init_two(t_uniondef,$3,$2));
  1749. } |
  1750. UNION dname closed_list
  1751. {
  1752. $$:=new(presobject,init_two(t_uniondef,$3,$2));
  1753. } |
  1754. UNION dname
  1755. {
  1756. $$:=$2;
  1757. } |
  1758. STRUCT dname
  1759. {
  1760. $$:=$2;
  1761. } |
  1762. ENUM dname closed_enum_list
  1763. {
  1764. $$:=new(presobject,init_two(t_enumdef,$3,$2));
  1765. } |
  1766. ENUM dname
  1767. {
  1768. $$:=$2;
  1769. };
  1770. type_specifier :
  1771. _CONST type_specifier
  1772. {
  1773. if not stripinfo then
  1774. writeln(outfile,'(* Const before type ignored *)');
  1775. $$:=$2;
  1776. } |
  1777. UNION closed_list _PACKED
  1778. {
  1779. if (not is_packed) and (not packrecords)then
  1780. writeln(outfile,'{$PACKRECORDS 1}');
  1781. is_packed:=true;
  1782. $$:=new(presobject,init_one(t_uniondef,$2));
  1783. } |
  1784. UNION closed_list
  1785. {
  1786. $$:=new(presobject,init_one(t_uniondef,$2));
  1787. } |
  1788. STRUCT closed_list _PACKED
  1789. {
  1790. if (not is_packed) and (not packrecords) then
  1791. writeln(outfile,'{$PACKRECORDS 1}');
  1792. is_packed:=true;
  1793. $$:=new(presobject,init_one(t_structdef,$2));
  1794. } |
  1795. STRUCT closed_list
  1796. {
  1797. if (is_packed) and (not packrecords) then
  1798. writeln(outfile,'{$PACKRECORDS 4}');
  1799. is_packed:=false;
  1800. $$:=new(presobject,init_one(t_structdef,$2));
  1801. } |
  1802. ENUM closed_enum_list
  1803. {
  1804. $$:=new(presobject,init_one(t_enumdef,$2));
  1805. } |
  1806. special_type_specifier
  1807. {
  1808. $$:=$1;
  1809. } |
  1810. simple_type_name { $$:=$1; }
  1811. ;
  1812. member_list : member_declaration member_list
  1813. {
  1814. $$:=new(presobject,init_one(t_memberdeclist,$1));
  1815. $$^.next:=$2;
  1816. } |
  1817. member_declaration
  1818. {
  1819. $$:=new(presobject,init_one(t_memberdeclist,$1));
  1820. }
  1821. ;
  1822. member_declaration :
  1823. type_specifier declarator_list SEMICOLON
  1824. {
  1825. $$:=new(presobject,init_two(t_memberdec,$1,$2));
  1826. }
  1827. ;
  1828. dname : ID { (*dname*)
  1829. $$:=new(presobject,init_id(act_token));
  1830. }
  1831. ;
  1832. special_type_name :
  1833. SIGNED special_type_name
  1834. {
  1835. hp:=$2;
  1836. $$:=hp;
  1837. if assigned(hp) then
  1838. begin
  1839. s:=strpas(hp^.p);
  1840. if s=UINT_STR then
  1841. s:=INT_STR
  1842. else if s=USHORT_STR then
  1843. s:=SHORT_STR
  1844. else if s=UCHAR_STR then
  1845. s:=CHAR_STR
  1846. else if s=QWORD_STR then
  1847. s:=INT64_STR
  1848. else
  1849. s:='';
  1850. if s<>'' then
  1851. hp^.setstr(s);
  1852. end;
  1853. } |
  1854. UNSIGNED special_type_name
  1855. {
  1856. hp:=$2;
  1857. $$:=hp;
  1858. if assigned(hp) then
  1859. begin
  1860. s:=strpas(hp^.p);
  1861. if s=INT_STR then
  1862. s:=UINT_STR
  1863. else if s=SHORT_STR then
  1864. s:=USHORT_STR
  1865. else if s=CHAR_STR then
  1866. s:=UCHAR_STR
  1867. else if s=INT64_STR then
  1868. s:=QWORD_STR
  1869. else
  1870. s:='';
  1871. if s<>'' then
  1872. hp^.setstr(s);
  1873. end;
  1874. } |
  1875. INT
  1876. {
  1877. $$:=new(presobject,init_intid(INT_STR));
  1878. } |
  1879. LONG
  1880. {
  1881. $$:=new(presobject,init_intid(INT_STR));
  1882. } |
  1883. LONG INT
  1884. {
  1885. $$:=new(presobject,init_intid(INT_STR));
  1886. } |
  1887. LONG LONG
  1888. {
  1889. $$:=new(presobject,init_intid(INT64_STR));
  1890. } |
  1891. LONG LONG INT
  1892. {
  1893. $$:=new(presobject,init_intid(INT64_STR));
  1894. } |
  1895. SHORT
  1896. {
  1897. $$:=new(presobject,init_intid(SHORT_STR));
  1898. } |
  1899. SHORT INT
  1900. {
  1901. $$:=new(presobject,init_intid(SHORT_STR));
  1902. } |
  1903. REAL
  1904. {
  1905. $$:=new(presobject,init_intid(REAL_STR));
  1906. } |
  1907. VOID
  1908. {
  1909. $$:=new(presobject,init_no(t_void));
  1910. } |
  1911. _CHAR
  1912. {
  1913. $$:=new(presobject,init_intid(CHAR_STR));
  1914. } |
  1915. UNSIGNED
  1916. {
  1917. $$:=new(presobject,init_intid(UINT_STR));
  1918. }
  1919. ;
  1920. simple_type_name :
  1921. special_type_name
  1922. {
  1923. $$:=$1;
  1924. }
  1925. |
  1926. dname
  1927. {
  1928. $$:=$1;
  1929. tn:=$$^.str;
  1930. if removeunderscore and
  1931. (length(tn)>1) and (tn[1]='_') then
  1932. $$^.setstr(Copy(tn,2,length(tn)-1));
  1933. }
  1934. ;
  1935. declarator_list :
  1936. declarator_list COMMA declarator
  1937. {
  1938. $$:=$1;
  1939. hp:=$1;
  1940. while assigned(hp^.next) do
  1941. hp:=hp^.next;
  1942. hp^.next:=new(presobject,init_one(t_declist,$3));
  1943. }|
  1944. error error_info COMMA declarator_list
  1945. {
  1946. writeln(outfile,' in declarator_list *)');
  1947. $$:=$4;
  1948. yyerrok;
  1949. }|
  1950. error error_info
  1951. {
  1952. writeln(outfile,' in declarator_list *)');
  1953. yyerrok;
  1954. }|
  1955. declarator
  1956. {
  1957. $$:=new(presobject,init_one(t_declist,$1));
  1958. }
  1959. ;
  1960. argument_declaration : type_specifier declarator
  1961. {
  1962. $$:=new(presobject,init_two(t_arg,$1,$2));
  1963. } |
  1964. type_specifier STAR declarator
  1965. {
  1966. (* type_specifier STAR declarator *)
  1967. hp:=new(presobject,init_one(t_pointerdef,$1));
  1968. $$:=new(presobject,init_two(t_arg,hp,$3));
  1969. } |
  1970. type_specifier abstract_declarator
  1971. {
  1972. $$:=new(presobject,init_two(t_arg,$1,$2));
  1973. }
  1974. ;
  1975. argument_declaration_list : argument_declaration
  1976. {
  1977. $$:=new(presobject,init_two(t_arglist,$1,nil));
  1978. } |
  1979. argument_declaration COMMA argument_declaration_list
  1980. {
  1981. $$:=new(presobject,init_two(t_arglist,$1,nil));
  1982. $$^.next:=$3;
  1983. } |
  1984. ELLIPSIS
  1985. {
  1986. $$:=new(presobject,init_two(t_arglist,ellipsisarg,nil));
  1987. } |
  1988. {
  1989. $$:=nil;
  1990. }
  1991. ;
  1992. size_overrider :
  1993. _FAR
  1994. { $$:=new(presobject,init_id('far'));}
  1995. | _NEAR
  1996. { $$:=new(presobject,init_id('near'));}
  1997. | _HUGE
  1998. { $$:=new(presobject,init_id('huge'));}
  1999. ;
  2000. declarator :
  2001. _CONST declarator
  2002. {
  2003. if not stripinfo then
  2004. writeln(outfile,'(* Const before declarator ignored *)');
  2005. $$:=$2;
  2006. } |
  2007. size_overrider STAR declarator
  2008. {
  2009. if not stripinfo then
  2010. writeln(outfile,aktspace,'(* ',$1^.p,' ignored *)');
  2011. dispose($1,done);
  2012. hp:=$3;
  2013. $$:=hp;
  2014. while assigned(hp^.p1) do
  2015. hp:=hp^.p1;
  2016. hp^.p1:=new(presobject,init_one(t_pointerdef,nil));
  2017. } |
  2018. STAR declarator
  2019. {
  2020. (* %prec PSTAR this was wrong!! *)
  2021. hp:=$2;
  2022. $$:=hp;
  2023. while assigned(hp^.p1) do
  2024. hp:=hp^.p1;
  2025. hp^.p1:=new(presobject,init_one(t_pointerdef,nil));
  2026. } |
  2027. _AND declarator %prec P_AND
  2028. {
  2029. hp:=$2;
  2030. $$:=hp;
  2031. while assigned(hp^.p1) do
  2032. hp:=hp^.p1;
  2033. hp^.p1:=new(presobject,init_one(t_addrdef,nil));
  2034. } |
  2035. dname COLON expr
  2036. {
  2037. (* size specifier supported *)
  2038. hp:=new(presobject,init_one(t_size_specifier,$3));
  2039. $$:=new(presobject,init_three(t_dec,nil,$1,hp));
  2040. }|
  2041. dname ASSIGN expr
  2042. {
  2043. if not stripinfo then
  2044. writeln(outfile,'(* Warning : default value for ',$1^.p,' ignored *)');
  2045. hp:=new(presobject,init_one(t_default_value,$3));
  2046. $$:=new(presobject,init_three(t_dec,nil,$1,hp));
  2047. }|
  2048. dname
  2049. {
  2050. $$:=new(presobject,init_two(t_dec,nil,$1));
  2051. }|
  2052. declarator LKLAMMER argument_declaration_list RKLAMMER
  2053. {
  2054. hp:=$1;
  2055. $$:=hp;
  2056. while assigned(hp^.p1) do
  2057. hp:=hp^.p1;
  2058. hp^.p1:=new(presobject,init_two(t_procdef,nil,$3));
  2059. } |
  2060. declarator no_arg
  2061. {
  2062. hp:=$1;
  2063. $$:=hp;
  2064. while assigned(hp^.p1) do
  2065. hp:=hp^.p1;
  2066. hp^.p1:=new(presobject,init_two(t_procdef,nil,nil));
  2067. } |
  2068. declarator LECKKLAMMER expr RECKKLAMMER
  2069. {
  2070. hp:=$1;
  2071. $$:=hp;
  2072. while assigned(hp^.p1) do
  2073. hp:=hp^.p1;
  2074. hp^.p1:=new(presobject,init_two(t_arraydef,nil,$3));
  2075. } |
  2076. declarator LECKKLAMMER RECKKLAMMER
  2077. {
  2078. (* this is translated into a pointer *)
  2079. hp:=$1;
  2080. $$:=hp;
  2081. while assigned(hp^.p1) do
  2082. hp:=hp^.p1;
  2083. hp^.p1:=new(presobject,init_two(t_arraydef,nil,nil));
  2084. } |
  2085. LKLAMMER declarator RKLAMMER
  2086. {
  2087. $$:=$2;
  2088. }
  2089. ;
  2090. no_arg : LKLAMMER RKLAMMER |
  2091. LKLAMMER VOID RKLAMMER;
  2092. abstract_declarator :
  2093. _CONST abstract_declarator
  2094. {
  2095. if not stripinfo then
  2096. writeln(outfile,'(* Const before abstract_declarator ignored *)');
  2097. $$:=$2;
  2098. } |
  2099. size_overrider STAR abstract_declarator
  2100. {
  2101. if not stripinfo then
  2102. writeln(outfile,aktspace,'(* ',$1^.p,' ignored *)');
  2103. dispose($1,done);
  2104. hp:=$3;
  2105. $$:=hp;
  2106. while assigned(hp^.p1) do
  2107. hp:=hp^.p1;
  2108. hp^.p1:=new(presobject,init_one(t_pointerdef,nil));
  2109. } |
  2110. STAR abstract_declarator %prec PSTAR
  2111. {
  2112. hp:=$2;
  2113. $$:=hp;
  2114. while assigned(hp^.p1) do
  2115. hp:=hp^.p1;
  2116. hp^.p1:=new(presobject,init_one(t_pointerdef,nil));
  2117. } |
  2118. abstract_declarator LKLAMMER argument_declaration_list RKLAMMER
  2119. {
  2120. hp:=$1;
  2121. $$:=hp;
  2122. while assigned(hp^.p1) do
  2123. hp:=hp^.p1;
  2124. hp^.p1:=new(presobject,init_two(t_procdef,nil,$3));
  2125. } |
  2126. abstract_declarator no_arg
  2127. {
  2128. hp:=$1;
  2129. $$:=hp;
  2130. while assigned(hp^.p1) do
  2131. hp:=hp^.p1;
  2132. hp^.p1:=new(presobject,init_two(t_procdef,nil,nil));
  2133. } |
  2134. abstract_declarator LECKKLAMMER expr RECKKLAMMER
  2135. {
  2136. hp:=$1;
  2137. $$:=hp;
  2138. while assigned(hp^.p1) do
  2139. hp:=hp^.p1;
  2140. hp^.p1:=new(presobject,init_two(t_arraydef,nil,$3));
  2141. } |
  2142. declarator LECKKLAMMER RECKKLAMMER
  2143. {
  2144. (* this is translated into a pointer *)
  2145. hp:=$1;
  2146. $$:=hp;
  2147. while assigned(hp^.p1) do
  2148. hp:=hp^.p1;
  2149. hp^.p1:=new(presobject,init_two(t_arraydef,nil,nil));
  2150. } |
  2151. LKLAMMER abstract_declarator RKLAMMER
  2152. {
  2153. $$:=$2;
  2154. } |
  2155. {
  2156. $$:=new(presobject,init_two(t_dec,nil,nil));
  2157. }
  2158. ;
  2159. expr :
  2160. shift_expr
  2161. {$$:=$1;}
  2162. ;
  2163. shift_expr :
  2164. expr EQUAL expr
  2165. { $$:=new(presobject,init_bop(' = ',$1,$3));}
  2166. | expr UNEQUAL expr
  2167. { $$:=new(presobject,init_bop(' <> ',$1,$3));}
  2168. | expr GT expr
  2169. { $$:=new(presobject,init_bop(' > ',$1,$3));}
  2170. | expr GTE expr
  2171. { $$:=new(presobject,init_bop(' >= ',$1,$3));}
  2172. | expr LT expr
  2173. { $$:=new(presobject,init_bop(' < ',$1,$3));}
  2174. | expr LTE expr
  2175. { $$:=new(presobject,init_bop(' <= ',$1,$3));}
  2176. | expr _PLUS expr
  2177. { $$:=new(presobject,init_bop(' + ',$1,$3));}
  2178. | expr MINUS expr
  2179. { $$:=new(presobject,init_bop(' - ',$1,$3));}
  2180. | expr STAR expr
  2181. { $$:=new(presobject,init_bop(' * ',$1,$3));}
  2182. | expr _SLASH expr
  2183. { $$:=new(presobject,init_bop(' / ',$1,$3));}
  2184. | expr _OR expr
  2185. { $$:=new(presobject,init_bop(' or ',$1,$3));}
  2186. | expr _AND expr
  2187. { $$:=new(presobject,init_bop(' and ',$1,$3));}
  2188. | expr _NOT expr
  2189. { $$:=new(presobject,init_bop(' not ',$1,$3));}
  2190. | expr _SHL expr
  2191. { $$:=new(presobject,init_bop(' shl ',$1,$3));}
  2192. | expr _SHR expr
  2193. { $$:=new(presobject,init_bop(' shr ',$1,$3));}
  2194. | expr QUESTIONMARK colon_expr
  2195. { $3^.p1:=$1;
  2196. $$:=$3;
  2197. inc(if_nb);
  2198. $$^.p:=strpnew('if_local'+str(if_nb));
  2199. } |
  2200. unary_expr {$$:=$1;}
  2201. ;
  2202. colon_expr : expr COLON expr
  2203. { (* if A then B else C *)
  2204. $$:=new(presobject,init_three(t_ifexpr,nil,$1,$3));}
  2205. ;
  2206. maybe_empty_unary_expr :
  2207. unary_expr
  2208. { $$:=$1; }
  2209. |
  2210. { $$:=nil;}
  2211. ;
  2212. unary_expr:
  2213. dname
  2214. {
  2215. $$:=$1;
  2216. } |
  2217. special_type_name
  2218. {
  2219. $$:=$1;
  2220. } |
  2221. CSTRING
  2222. {
  2223. (* remove L prefix for widestrings *)
  2224. s:=act_token;
  2225. if Win32headers and (s[1]='L') then
  2226. delete(s,1,1);
  2227. $$:=new(presobject,init_id(''''+copy(s,2,length(s)-2)+''''));
  2228. } |
  2229. NUMBER
  2230. {
  2231. $$:=new(presobject,init_id(act_token));
  2232. } |
  2233. unary_expr POINT expr
  2234. {
  2235. $$:=new(presobject,init_bop('.',$1,$3));
  2236. } |
  2237. unary_expr DEREF expr
  2238. {
  2239. $$:=new(presobject,init_bop('^.',$1,$3));
  2240. } |
  2241. MINUS unary_expr
  2242. {
  2243. $$:=new(presobject,init_preop('-',$2));
  2244. }|
  2245. _AND unary_expr %prec R_AND
  2246. {
  2247. $$:=new(presobject,init_preop('@',$2));
  2248. }|
  2249. _NOT unary_expr
  2250. {
  2251. $$:=new(presobject,init_preop(' not ',$2));
  2252. } |
  2253. LKLAMMER dname RKLAMMER maybe_empty_unary_expr
  2254. {
  2255. if assigned($4) then
  2256. $$:=new(presobject,init_two(t_typespec,$2,$4))
  2257. else
  2258. $$:=$2;
  2259. } |
  2260. LKLAMMER type_specifier RKLAMMER unary_expr
  2261. {
  2262. $$:=new(presobject,init_two(t_typespec,$2,$4));
  2263. } |
  2264. LKLAMMER type_specifier STAR RKLAMMER unary_expr
  2265. {
  2266. hp:=new(presobject,init_one(t_pointerdef,$2));
  2267. $$:=new(presobject,init_two(t_typespec,hp,$5));
  2268. } |
  2269. LKLAMMER type_specifier size_overrider STAR RKLAMMER unary_expr
  2270. {
  2271. if not stripinfo then
  2272. writeln(outfile,aktspace,'(* ',$3^.p,' ignored *)');
  2273. dispose($3,done);
  2274. write_type_specifier(outfile,$2);
  2275. writeln(outfile,' ignored *)');
  2276. hp:=new(presobject,init_one(t_pointerdef,$2));
  2277. $$:=new(presobject,init_two(t_typespec,hp,$6));
  2278. } |
  2279. dname LKLAMMER exprlist RKLAMMER
  2280. {
  2281. hp:=new(presobject,init_one(t_exprlist,$1));
  2282. $$:=new(presobject,init_three(t_funexprlist,hp,$3,nil));
  2283. } |
  2284. LKLAMMER shift_expr RKLAMMER
  2285. {
  2286. $$:=$2;
  2287. } |
  2288. LKLAMMER STAR unary_expr RKLAMMER maybe_space LKLAMMER exprlist RKLAMMER
  2289. {
  2290. $$:=new(presobject,init_two(t_callop,$3,$7));
  2291. } |
  2292. dname LECKKLAMMER exprlist RECKKLAMMER
  2293. {
  2294. $$:=new(presobject,init_two(t_arrayop,$1,$3));
  2295. }
  2296. ;
  2297. enum_list :
  2298. enum_element COMMA enum_list
  2299. { (*enum_element COMMA enum_list *)
  2300. $$:=$1;
  2301. $$^.next:=$3;
  2302. } |
  2303. enum_element {
  2304. $$:=$1;
  2305. } |
  2306. {(* empty enum list *)
  2307. $$:=nil;};
  2308. enum_element :
  2309. dname _ASSIGN expr
  2310. { begin (*enum_element: dname _ASSIGN expr *)
  2311. $$:=new(presobject,init_two(t_enumlist,$1,$3));
  2312. end;
  2313. } |
  2314. dname
  2315. {
  2316. begin (*enum_element: dname*)
  2317. $$:=new(presobject,init_two(t_enumlist,$1,nil));
  2318. end;
  2319. };
  2320. def_expr :
  2321. unary_expr
  2322. {
  2323. if $1^.typ=t_funexprlist then
  2324. $$:=$1
  2325. else
  2326. $$:=new(presobject,init_two(t_exprlist,$1,nil));
  2327. (* if here is a type specifier
  2328. we know the return type *)
  2329. if ($1^.typ=t_typespec) then
  2330. $$^.p3:=$1^.p1^.get_copy;
  2331. }
  2332. ;
  2333. para_def_expr :
  2334. SPACE_DEFINE def_expr
  2335. {
  2336. $$:=$2;
  2337. } |
  2338. maybe_space LKLAMMER def_expr RKLAMMER
  2339. {
  2340. $$:=$3
  2341. }
  2342. ;
  2343. exprlist : exprelem COMMA exprlist
  2344. { (*exprlist COMMA expr*)
  2345. $$:=$1;
  2346. $1^.next:=$3;
  2347. } |
  2348. exprelem
  2349. {
  2350. $$:=$1;
  2351. } |
  2352. { (* empty expression list *)
  2353. $$:=nil; };
  2354. exprelem :
  2355. expr
  2356. {
  2357. $$:=new(presobject,init_one(t_exprlist,$1));
  2358. };
  2359. %%
  2360. function yylex : Integer;
  2361. begin
  2362. yylex:=scan.yylex;
  2363. line_no:=yylineno;
  2364. end;
  2365. procedure WriteFileHeader(var headerfile: Text);
  2366. var
  2367. i: integer;
  2368. originalstr: string;
  2369. begin
  2370. { write unit header }
  2371. if not includefile then
  2372. begin
  2373. if createdynlib then
  2374. writeln(headerfile,'{$mode objfpc}');
  2375. writeln(headerfile,'unit ',unitname,';');
  2376. writeln(headerfile,'interface');
  2377. writeln(headerfile);
  2378. writeln(headerfile,'{');
  2379. writeln(headerfile,' Automatically converted by H2Pas ',version,' from ',inputfilename);
  2380. writeln(headerfile,' The following command line parameters were used:');
  2381. for i:=1 to paramcount do
  2382. writeln(headerfile,' ',paramstr(i));
  2383. writeln(headerfile,'}');
  2384. writeln(headerfile);
  2385. end;
  2386. if UseName then
  2387. begin
  2388. writeln(headerfile,aktspace,'const');
  2389. writeln(headerfile,aktspace,' External_library=''',libfilename,'''; {Setup as you need}');
  2390. writeln(headerfile);
  2391. end;
  2392. if UsePPointers then
  2393. begin
  2394. Writeln(headerfile,aktspace,'{ Pointers to basic pascal types, inserted by h2pas conversion program.}');
  2395. Writeln(headerfile,aktspace,'Type');
  2396. Writeln(headerfile,aktspace,' PLongint = ^Longint;');
  2397. Writeln(headerfile,aktspace,' PSmallInt = ^SmallInt;');
  2398. Writeln(headerfile,aktspace,' PByte = ^Byte;');
  2399. Writeln(headerfile,aktspace,' PWord = ^Word;');
  2400. Writeln(headerfile,aktspace,' PDWord = ^DWord;');
  2401. Writeln(headerfile,aktspace,' PDouble = ^Double;');
  2402. Writeln(headerfile);
  2403. end;
  2404. if PTypeList.count <> 0 then
  2405. Writeln(headerfile,aktspace,'Type');
  2406. for i:=0 to (PTypeList.Count-1) do
  2407. begin
  2408. originalstr:=copy(PTypelist[i],2,length(PTypeList[i]));
  2409. Writeln(headerfile,aktspace,PTypeList[i],' = ^',originalstr,';');
  2410. end;
  2411. if not packrecords then
  2412. begin
  2413. writeln(headerfile,'{$IFDEF FPC}');
  2414. writeln(headerfile,'{$PACKRECORDS C}');
  2415. writeln(headerfile,'{$ENDIF}');
  2416. end;
  2417. writeln(headerfile);
  2418. end;
  2419. var
  2420. SS : string;
  2421. i : longint;
  2422. headerfile: Text;
  2423. finaloutfile: Text;
  2424. begin
  2425. pointerprefix:=false;
  2426. { Initialize }
  2427. PTypeList:=TStringList.Create;
  2428. PTypeList.Sorted := true;
  2429. PTypeList.Duplicates := dupIgnore;
  2430. freedynlibproc:=TStringList.Create;
  2431. loaddynlibproc:=TStringList.Create;
  2432. yydebug:=true;
  2433. aktspace:='';
  2434. block_type:=bt_no;
  2435. IsExtern:=false;
  2436. { Read commandline options }
  2437. ProcessOptions;
  2438. if not CompactMode then
  2439. aktspace:=' ';
  2440. { open input and output files }
  2441. assign(yyinput, inputfilename);
  2442. {$I-}
  2443. reset(yyinput);
  2444. {$I+}
  2445. if ioresult<>0 then
  2446. begin
  2447. writeln('file ',inputfilename,' not found!');
  2448. halt(1);
  2449. end;
  2450. { This is the intermediate output file }
  2451. assign(outfile, 'ext3.tmp');
  2452. {$I-}
  2453. rewrite(outfile);
  2454. {$I+}
  2455. if ioresult<>0 then
  2456. begin
  2457. writeln('file ext3.tmp could not be created!');
  2458. halt(1);
  2459. end;
  2460. writeln(outfile);
  2461. { Open tempfiles }
  2462. { This is where the implementation section of the unit shall be stored }
  2463. Assign(implemfile,'ext.tmp');
  2464. rewrite(implemfile);
  2465. Assign(tempfile,'ext2.tmp');
  2466. rewrite(tempfile);
  2467. { Parse! }
  2468. yyparse;
  2469. { Write implementation if needed }
  2470. if not(includefile) then
  2471. begin
  2472. writeln(outfile);
  2473. writeln(outfile,'implementation');
  2474. writeln(outfile);
  2475. end;
  2476. { here we have a problem if a line is longer than 255 chars !! }
  2477. reset(implemfile);
  2478. while not eof(implemfile) do
  2479. begin
  2480. readln(implemfile,SS);
  2481. writeln(outfile,SS);
  2482. end;
  2483. if createdynlib then
  2484. begin
  2485. writeln(outfile,' uses');
  2486. writeln(outfile,' SysUtils,');
  2487. writeln(outfile,'{$ifdef Win32}');
  2488. writeln(outfile,' Windows;');
  2489. writeln(outfile,'{$else}');
  2490. writeln(outfile,' DLLFuncs;');
  2491. writeln(outfile,'{$endif win32}');
  2492. writeln(outfile);
  2493. writeln(outfile,' var');
  2494. writeln(outfile,' hlib : thandle;');
  2495. writeln(outfile);
  2496. writeln(outfile);
  2497. writeln(outfile,' procedure Free',unitname,';');
  2498. writeln(outfile,' begin');
  2499. writeln(outfile,' FreeLibrary(hlib);');
  2500. for i:=0 to (freedynlibproc.Count-1) do
  2501. Writeln(outfile,' ',freedynlibproc[i]);
  2502. writeln(outfile,' end;');
  2503. writeln(outfile);
  2504. writeln(outfile);
  2505. writeln(outfile,' procedure Load',unitname,'(lib : pchar);');
  2506. writeln(outfile,' begin');
  2507. writeln(outfile,' Free',unitname,';');
  2508. writeln(outfile,' hlib:=LoadLibrary(lib);');
  2509. writeln(outfile,' if hlib=0 then');
  2510. writeln(outfile,' raise Exception.Create(format(''Could not load library: %s'',[lib]));');
  2511. writeln(outfile);
  2512. for i:=0 to (loaddynlibproc.Count-1) do
  2513. Writeln(outfile,' ',loaddynlibproc[i]);
  2514. writeln(outfile,' end;');
  2515. writeln(outfile);
  2516. writeln(outfile);
  2517. writeln(outfile,'initialization');
  2518. writeln(outfile,' Load',unitname,'(''',unitname,''');');
  2519. writeln(outfile,'finalization');
  2520. writeln(outfile,' Free',unitname,';');
  2521. end;
  2522. { write end of file }
  2523. writeln(outfile);
  2524. if not(includefile) then
  2525. writeln(outfile,'end.');
  2526. { close and erase tempfiles }
  2527. close(implemfile);
  2528. erase(implemfile);
  2529. close(tempfile);
  2530. erase(tempfile);
  2531. flush(outfile);
  2532. {**** generate full file ****}
  2533. assign(headerfile, 'ext4.tmp');
  2534. {$I-}
  2535. rewrite(headerfile);
  2536. {$I+}
  2537. if ioresult<>0 then
  2538. begin
  2539. writeln('file ext4.tmp could not be created!');
  2540. halt(1);
  2541. end;
  2542. WriteFileHeader(HeaderFile);
  2543. { Final output filename }
  2544. assign(finaloutfile, outputfilename);
  2545. {$I-}
  2546. rewrite(finaloutfile);
  2547. {$I+}
  2548. if ioresult<>0 then
  2549. begin
  2550. writeln('file ',outputfilename,' could not be created!');
  2551. halt(1);
  2552. end;
  2553. writeln(finaloutfile);
  2554. { Read unit header file }
  2555. reset(headerfile);
  2556. while not eof(headerfile) do
  2557. begin
  2558. readln(headerfile,SS);
  2559. writeln(finaloutfile,SS);
  2560. end;
  2561. { Read interface and implementation file }
  2562. reset(outfile);
  2563. while not eof(outfile) do
  2564. begin
  2565. readln(outfile,SS);
  2566. writeln(finaloutfile,SS);
  2567. end;
  2568. close(HeaderFile);
  2569. close(outfile);
  2570. close(finaloutfile);
  2571. erase(outfile);
  2572. erase(headerfile);
  2573. PTypeList.Free;
  2574. freedynlibproc.free;
  2575. loaddynlibproc.free;
  2576. end.
  2577. {
  2578. $Log$
  2579. Revision 1.10 2005-02-20 11:09:41 florian
  2580. + added -P:
  2581. allows to generate headers which load proc. dyn. from libs
  2582. Revision 1.9 2004/09/08 22:21:41 carl
  2583. + support for creating packed records
  2584. * var parameter bugfixes
  2585. Revision 1.8 2004/08/13 02:35:29 carl
  2586. + bugfixes with C++ comments, they are now placed above the definition
  2587. * some bugfixes with the _label reserved word.
  2588. Revision 1.7 2004/06/20 17:56:05 marco
  2589. Patch from Christian Iversen. ioresult check when opening for output
  2590. Revision 1.6 2003/02/13 22:20:24 michael
  2591. + Patch from Jeff Pohlmeyer to process empty structs
  2592. Revision 1.5 2002/09/07 15:40:33 peter
  2593. * old logs removed and tabs fixed
  2594. }