scanbase.pp 20 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. {
  2. Copyright (c) 1998-2000 by Florian Klaempfl
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ****************************************************************************}
  15. unit scanbase;
  16. {$H+}
  17. interface
  18. uses strings, h2plexlib,h2pyacclib;
  19. const
  20. version = '1.0.0';
  21. type
  22. Char=system.char;
  23. ttyp = (
  24. t_id,
  25. { p contains the string }
  26. t_arraydef,
  27. { }
  28. t_pointerdef,
  29. { p1 contains the definition
  30. if in type overrider
  31. or nothing for args
  32. }
  33. t_addrdef,
  34. t_void,
  35. { no field }
  36. t_dec,
  37. { }
  38. t_declist,
  39. { p1 is t_dec
  40. next if exists }
  41. t_memberdec,
  42. { p1 is type specifier
  43. p2 is declarator_list }
  44. t_structdef,
  45. { }
  46. t_memberdeclist,
  47. { p1 is memberdec
  48. next is next if it exist }
  49. t_procdef,
  50. { }
  51. t_uniondef,
  52. { }
  53. t_enumdef,
  54. { }
  55. t_enumlist,
  56. { }
  57. t_preop,
  58. { p contains the operator string
  59. p1 contains the right expr }
  60. t_bop,
  61. { p contains the operator string
  62. p1 contains the left expr
  63. p2 contains the right expr }
  64. t_arrayop,
  65. {
  66. p1 contains the array expr
  67. p2 contains the index expressions }
  68. t_callop,
  69. {
  70. p1 contains the proc expr
  71. p2 contains the index expressions }
  72. t_arg,
  73. {
  74. p1 contain the typedef
  75. p2 the declarator (t_dec)
  76. }
  77. t_arglist,
  78. { }
  79. t_funexprlist,
  80. { }
  81. t_exprlist,
  82. { p1 contains the expr
  83. next contains the next if it exists }
  84. t_ifexpr,
  85. { p1 contains the condition expr
  86. p2 contains the if branch
  87. p3 contains the else branch }
  88. t_funcname,
  89. { p1 contains the function dname
  90. p2 contains the funexprlist
  91. p3 possibly contains the return type }
  92. t_typespec,
  93. { p1 is the type itself
  94. p2 the typecast expr }
  95. t_size_specifier,
  96. { p1 expr for size }
  97. t_default_value,
  98. { p1 expr for value }
  99. t_statement_list,
  100. { p1 is the statement
  101. next is next if it exist }
  102. t_whilenode,
  103. t_fornode,
  104. t_dowhilenode,
  105. t_switchnode,
  106. t_gotonode,
  107. t_continuenode,
  108. t_breaknode
  109. );
  110. const
  111. ttypstr: array[ttyp] of string =
  112. (
  113. 't_id',
  114. 't_arraydef',
  115. 't_pointerdef',
  116. 't_addrdef',
  117. 't_void',
  118. 't_dec',
  119. 't_declist',
  120. 't_memberdec',
  121. 't_structdef',
  122. 't_memberdeclist',
  123. 't_procdef',
  124. 't_uniondef',
  125. 't_enumdef',
  126. 't_enumlist',
  127. 't_preop',
  128. 't_bop',
  129. 't_arrayop',
  130. 't_callop',
  131. 't_arg',
  132. 't_arglist',
  133. 't_funexprlist',
  134. 't_exprlist',
  135. 't_ifexpr',
  136. 't_funcname',
  137. 't_typespec',
  138. 't_size_specifier',
  139. 't_default_value',
  140. 't_statement_list',
  141. 't_whilenode',
  142. 't_fornode',
  143. 't_dowhilenode',
  144. 't_switchnode',
  145. 't_gotonode',
  146. 't_continuenode',
  147. 't_breaknode'
  148. );
  149. type
  150. presobject = ^tresobject;
  151. tresobject = object
  152. typ : ttyp;
  153. p : pchar;
  154. next : presobject;
  155. p1,p2,p3 : presobject;
  156. { name of int/real, then no T prefix is required }
  157. intname : boolean;
  158. constructor init_no(t : ttyp);
  159. constructor init_one(t : ttyp;_p1 : presobject);
  160. constructor init_two(t : ttyp;_p1,_p2 : presobject);
  161. constructor init_three(t : ttyp;_p1,_p2,_p3 : presobject);
  162. constructor init_id(const s : string);
  163. constructor init_intid(const s : string);
  164. constructor init_bop(const s : string;_p1,_p2 : presobject);
  165. constructor init_preop(const s : string;_p1 : presobject);
  166. procedure setstr(const s:string);
  167. function str : string;
  168. function strlength : byte;
  169. function get_copy : presobject;
  170. { can this ve considered as a constant ? }
  171. function is_const : boolean;
  172. destructor done;
  173. end;
  174. tblocktype = (bt_type,bt_const,bt_var,bt_func,bt_no);
  175. var
  176. infile : string;
  177. outfile : text;
  178. c : char;
  179. aktspace : string;
  180. block_type : tblocktype;
  181. commentstr: string;
  182. const
  183. in_define : boolean = false;
  184. { True if define spans to the next line }
  185. cont_line : boolean = false;
  186. { 1 after define; 2 after the ID to print the first separating space }
  187. in_space_define : byte = 0;
  188. arglevel : longint = 0;
  189. {> 1 = ifdef level in a ifdef C++ block
  190. 1 = first level in an ifdef block
  191. 0 = not in an ifdef block
  192. -1 = in else part of ifdef block, process like we weren't in the block
  193. but skip the incoming end.
  194. > -1 = ifdef sublevel in an else block.
  195. }
  196. cplusblocklevel : LongInt = 0;
  197. procedure internalerror(i : integer);
  198. function strpnew(const s : string) : pchar;
  199. procedure writetree(p: presobject);
  200. function NotInCPlusBlock : Boolean; inline;
  201. procedure skip_until_eol;
  202. procedure commenteof;
  203. procedure copy_until_eol;
  204. procedure HandleMultiLineComment;
  205. procedure HandleSingleLineComment;
  206. Procedure CheckLongString;
  207. Procedure HandleContinuation;
  208. Procedure HandleEOL;
  209. Procedure HandleWhiteSpace;
  210. Procedure HandleIdentifier;
  211. Procedure HandleLongInteger;
  212. Procedure HandleHexLongInteger;
  213. Procedure HandleNumber;
  214. Procedure HandleDeref;
  215. Procedure HandleCallingConvention(aCC : Integer);
  216. Procedure HandlePalmPilotCallingConvention;
  217. Procedure HandleIllegalCharacter;
  218. // Preprocessor routines...
  219. Procedure HandlePreProcIfDef;
  220. Procedure HandlePreProcIf;
  221. Procedure HandlePreProcElse;
  222. Procedure HandlePreProcElIf;
  223. Procedure HandlePreProcEndif;
  224. Procedure HandlePreProcUndef;
  225. Procedure HandlePreProcInclude;
  226. Procedure HandlePreProcLineInfo;
  227. Procedure HandlePreProcPragma;
  228. Procedure HandlePreProcDefine;
  229. Procedure HandlePreProcError;
  230. Procedure HandlePreProcStripConditional(isEnd : Boolean);
  231. Procedure EnterCplusPlus;
  232. const
  233. newline = #10;
  234. implementation
  235. uses
  236. h2poptions,converu;
  237. procedure writeentry(p: presobject; var currentlevel: integer);
  238. begin
  239. if assigned(p^.p1) then
  240. begin
  241. WriteLn(' Entry p1[',ttypstr[p^.p1^.typ],']',p^.p1^.str);
  242. end;
  243. if assigned(p^.p2) then
  244. begin
  245. WriteLn(' Entry p2[',ttypstr[p^.p2^.typ],']',p^.p2^.str);
  246. end;
  247. if assigned(p^.p3) then
  248. begin
  249. WriteLn(' Entry p3[',ttypstr[p^.p3^.typ],']',p^.p3^.str);
  250. end;
  251. end;
  252. procedure writetree(p: presobject);
  253. var
  254. i : integer;
  255. localp: presobject;
  256. localp1: presobject;
  257. currentlevel : integer;
  258. begin
  259. localp:=p;
  260. currentlevel:=0;
  261. while assigned(localp) do
  262. begin
  263. WriteLn('Entry[',ttypstr[localp^.typ],']',localp^.str);
  264. case localp^.typ of
  265. { Some arguments sharing the same type }
  266. t_arglist:
  267. begin
  268. localp1:=localp;
  269. while assigned(localp1) do
  270. begin
  271. writeentry(localp1,currentlevel);
  272. localp1:=localp1^.p1;
  273. end;
  274. end;
  275. end;
  276. localp:=localp^.next;
  277. end;
  278. end;
  279. procedure internalerror(i : integer);
  280. begin
  281. writeln('Internal error ',i,' in line ',yylineno);
  282. halt(1);
  283. end;
  284. procedure commenteof;
  285. begin
  286. writeln('unexpected EOF inside comment at line ',yylineno);
  287. end;
  288. procedure copy_until_eol;
  289. begin
  290. c:=get_char;
  291. while c<>newline do
  292. begin
  293. write(outfile,c);
  294. c:=get_char;
  295. end;
  296. end;
  297. procedure skip_until_eol;
  298. begin
  299. c:=get_char;
  300. while c<>newline do
  301. c:=get_char;
  302. end;
  303. function strpnew(const s : string) : pchar;
  304. var
  305. p : pchar;
  306. begin
  307. getmem(p,length(s)+1);
  308. strpcopy(p,s);
  309. strpnew:=p;
  310. end;
  311. function NotInCPlusBlock : Boolean; inline;
  312. begin
  313. NotInCPlusBlock := cplusblocklevel < 1;
  314. end;
  315. constructor tresobject.init_preop(const s : string;_p1 : presobject);
  316. begin
  317. typ:=t_preop;
  318. p:=strpnew(s);
  319. p1:=_p1;
  320. p2:=nil;
  321. p3:=nil;
  322. next:=nil;
  323. intname:=false;
  324. end;
  325. constructor tresobject.init_bop(const s : string;_p1,_p2 : presobject);
  326. begin
  327. typ:=t_bop;
  328. p:=strpnew(s);
  329. p1:=_p1;
  330. p2:=_p2;
  331. p3:=nil;
  332. next:=nil;
  333. intname:=false;
  334. end;
  335. constructor tresobject.init_id(const s : string);
  336. begin
  337. typ:=t_id;
  338. p:=strpnew(s);
  339. p1:=nil;
  340. p2:=nil;
  341. p3:=nil;
  342. next:=nil;
  343. intname:=false;
  344. end;
  345. constructor tresobject.init_intid(const s : string);
  346. begin
  347. typ:=t_id;
  348. p:=strpnew(s);
  349. p1:=nil;
  350. p2:=nil;
  351. p3:=nil;
  352. next:=nil;
  353. intname:=true;
  354. end;
  355. constructor tresobject.init_two(t : ttyp;_p1,_p2 : presobject);
  356. begin
  357. typ:=t;
  358. p1:=_p1;
  359. p2:=_p2;
  360. p3:=nil;
  361. p:=nil;
  362. next:=nil;
  363. intname:=false;
  364. end;
  365. constructor tresobject.init_three(t : ttyp;_p1,_p2,_p3 : presobject);
  366. begin
  367. typ:=t;
  368. p1:=_p1;
  369. p2:=_p2;
  370. p3:=_p3;
  371. p:=nil;
  372. next:=nil;
  373. intname:=false;
  374. end;
  375. constructor tresobject.init_one(t : ttyp;_p1 : presobject);
  376. begin
  377. typ:=t;
  378. p1:=_p1;
  379. p2:=nil;
  380. p3:=nil;
  381. next:=nil;
  382. p:=nil;
  383. intname:=false;
  384. end;
  385. constructor tresobject.init_no(t : ttyp);
  386. begin
  387. typ:=t;
  388. p:=nil;
  389. p1:=nil;
  390. p2:=nil;
  391. p3:=nil;
  392. next:=nil;
  393. intname:=false;
  394. end;
  395. procedure tresobject.setstr(const s : string);
  396. begin
  397. if assigned(p) then
  398. strdispose(p);
  399. p:=strpnew(s);
  400. end;
  401. function tresobject.str : string;
  402. begin
  403. str:=strpas(p);
  404. end;
  405. function tresobject.strlength : byte;
  406. begin
  407. if assigned(p) then
  408. strlength:=strlen(p)
  409. else
  410. strlength:=0;
  411. end;
  412. { can this ve considered as a constant ? }
  413. function tresobject.is_const : boolean;
  414. begin
  415. case typ of
  416. t_id,t_void :
  417. is_const:=true;
  418. t_preop :
  419. is_const:= ((str='-') or (str=' not ')) and p1^.is_const;
  420. t_bop :
  421. is_const:= p2^.is_const and p1^.is_const;
  422. else
  423. is_const:=false;
  424. end;
  425. end;
  426. function tresobject.get_copy : presobject;
  427. var
  428. newres : presobject;
  429. begin
  430. newres:=new(presobject,init_no(typ));
  431. newres^.intname:=intname;
  432. if assigned(p) then
  433. newres^.p:=strnew(p);
  434. if assigned(p1) then
  435. newres^.p1:=p1^.get_copy;
  436. if assigned(p2) then
  437. newres^.p2:=p2^.get_copy;
  438. if assigned(p3) then
  439. newres^.p3:=p3^.get_copy;
  440. if assigned(next) then
  441. newres^.next:=next^.get_copy;
  442. get_copy:=newres;
  443. end;
  444. destructor tresobject.done;
  445. begin
  446. (* writeln('disposing ',byte(typ)); *)
  447. if assigned(p)then strdispose(p);
  448. if assigned(p1) then
  449. dispose(p1,done);
  450. if assigned(p2) then
  451. dispose(p2,done);
  452. if assigned(p3) then
  453. dispose(p3,done);
  454. if assigned(next) then
  455. dispose(next,done);
  456. end;
  457. procedure HandleMultiLineComment;
  458. begin
  459. if not NotInCPlusBlock then
  460. begin
  461. Skip_until_eol;
  462. exit;
  463. end;
  464. if not stripcomment then
  465. write(outfile,aktspace,'{');
  466. repeat
  467. c:=get_char;
  468. case c of
  469. '*' :
  470. begin
  471. c:=get_char;
  472. if c='/' then
  473. begin
  474. if not stripcomment then
  475. write(outfile,' }');
  476. c:=get_char;
  477. if c=newline then
  478. writeln(outfile);
  479. unget_char(c);
  480. flush(outfile);
  481. exit;
  482. end
  483. else
  484. begin
  485. if not stripcomment then
  486. write(outfile,'*');
  487. unget_char(c)
  488. end;
  489. end;
  490. newline :
  491. begin
  492. if not stripcomment then
  493. begin
  494. writeln(outfile);
  495. write(outfile,aktspace);
  496. end;
  497. end;
  498. { Don't write this thing out, to
  499. avoid nested comments.
  500. }
  501. '{','}' :
  502. begin
  503. end;
  504. #0 :
  505. commenteof;
  506. else
  507. if not stripcomment then
  508. write(outfile,c);
  509. end;
  510. until false;
  511. flush(outfile);
  512. end;
  513. procedure HandleSingleLineComment;
  514. begin
  515. if not NotInCPlusBlock then
  516. begin
  517. skip_until_eol;
  518. exit;
  519. end;
  520. commentstr:='';
  521. if (in_define) and not (stripcomment) then
  522. begin
  523. commentstr:='{';
  524. end
  525. else
  526. If not stripcomment then
  527. write(outfile,aktspace,'{');
  528. repeat
  529. c:=get_char;
  530. case c of
  531. newline :
  532. begin
  533. unget_char(c);
  534. if not stripcomment then
  535. begin
  536. if in_define then
  537. begin
  538. commentstr:=commentstr+' }';
  539. end
  540. else
  541. begin
  542. write(outfile,' }');
  543. writeln(outfile);
  544. end;
  545. end;
  546. flush(outfile);
  547. exit;
  548. end;
  549. { Don't write this comment out,
  550. to avoid nested comment problems
  551. }
  552. '{','}' :
  553. begin
  554. end;
  555. #0 :
  556. commenteof;
  557. else
  558. if not stripcomment then
  559. begin
  560. if in_define then
  561. begin
  562. commentstr:=commentstr+c;
  563. end
  564. else
  565. write(outfile,c);
  566. end;
  567. end;
  568. until false;
  569. flush(outfile);
  570. end;
  571. Procedure CheckLongString;
  572. begin
  573. if NotInCPlusBlock then
  574. begin
  575. if win32headers then
  576. return(CSTRING)
  577. else
  578. return(256);
  579. end
  580. else skip_until_eol;
  581. end;
  582. Procedure HandleLongInteger;
  583. begin
  584. if NotInCPlusBlock then
  585. begin
  586. if yytext[1]='0' then
  587. begin
  588. delete(yytext,1,1);
  589. yytext:='&'+yytext;
  590. end;
  591. while yytext[length(yytext)] in ['L','U','l','u'] do
  592. Delete(yytext,length(yytext),1);
  593. return(NUMBER);
  594. end
  595. else skip_until_eol;
  596. end;
  597. Procedure HandleHexLongInteger;
  598. begin
  599. if NotInCPlusBlock then
  600. begin
  601. (* handle pre- and postfixes *)
  602. if copy(yytext,1,2)='0x' then
  603. begin
  604. delete(yytext,1,2);
  605. yytext:='$'+yytext;
  606. end;
  607. while yytext[length(yytext)] in ['L','U','l','u'] do
  608. Delete(yytext,length(yytext),1);
  609. return(NUMBER);
  610. end
  611. else
  612. skip_until_eol;
  613. end;
  614. procedure HandleNumber;
  615. begin
  616. if NotInCPlusBlock then
  617. begin
  618. return(NUMBER);
  619. end
  620. else
  621. skip_until_eol;
  622. end;
  623. Procedure HandleDeref;
  624. begin
  625. if NotInCPlusBlock then
  626. begin
  627. if in_define then
  628. return(DEREF)
  629. else
  630. return(256);
  631. end
  632. else
  633. skip_until_eol;
  634. end;
  635. Procedure HandlePreProcIfDef;
  636. begin
  637. if cplusblocklevel > 0 then
  638. Inc(cplusblocklevel)
  639. else
  640. begin
  641. if cplusblocklevel < 0 then
  642. Dec(cplusblocklevel);
  643. write(outfile,'{$ifdef ');
  644. copy_until_eol;
  645. writeln(outfile,'}');
  646. flush(outfile);
  647. end;
  648. end;
  649. Procedure HandlePreProcElse;
  650. begin
  651. if cplusblocklevel < -1 then
  652. begin
  653. writeln(outfile,'{$else}');
  654. block_type:=bt_no;
  655. flush(outfile);
  656. end
  657. else
  658. case cplusblocklevel of
  659. 0 :
  660. begin
  661. writeln(outfile,'{$else}');
  662. block_type:=bt_no;
  663. flush(outfile);
  664. end;
  665. 1 : cplusblocklevel := -1;
  666. -1 : cplusblocklevel := 1;
  667. end;
  668. end;
  669. Procedure HandlePreProcEndif;
  670. begin
  671. if cplusblocklevel > 0 then
  672. begin
  673. Dec(cplusblocklevel);
  674. end
  675. else
  676. begin
  677. case cplusblocklevel of
  678. 0 : begin
  679. writeln(outfile,'{$endif}');
  680. block_type:=bt_no;
  681. flush(outfile);
  682. end;
  683. -1 : begin
  684. cplusblocklevel :=0;
  685. end
  686. else
  687. inc(cplusblocklevel);
  688. end;
  689. end;
  690. end;
  691. Procedure HandlePreProcElif;
  692. begin
  693. if cplusblocklevel < -1 then
  694. begin
  695. if not stripinfo then
  696. write(outfile,'(*** was #elif ****)');
  697. write(outfile,'{$else');
  698. copy_until_eol;
  699. writeln(outfile,'}');
  700. block_type:=bt_no;
  701. flush(outfile);
  702. end
  703. else
  704. case cplusblocklevel of
  705. 0 :
  706. begin
  707. if not stripinfo then
  708. write(outfile,'(*** was #elif ****)');
  709. write(outfile,'{$else');
  710. copy_until_eol;
  711. writeln(outfile,'}');
  712. block_type:=bt_no;
  713. flush(outfile);
  714. end;
  715. 1 : cplusblocklevel := -1;
  716. -1 : cplusblocklevel := 1;
  717. end;
  718. end;
  719. Procedure HandlePreProcUndef;
  720. begin
  721. write(outfile,'{$undef');
  722. copy_until_eol;
  723. writeln(outfile,'}');
  724. flush(outfile);
  725. end;
  726. Procedure HandlePreProcInclude;
  727. begin
  728. if NotInCPlusBlock then
  729. begin
  730. write(outfile,'{$include');
  731. copy_until_eol;
  732. writeln(outfile,'}');
  733. flush(outfile);
  734. block_type:=bt_no;
  735. end
  736. else
  737. skip_until_eol;
  738. end;
  739. Procedure HandlePreProcIf;
  740. begin
  741. if cplusblocklevel > 0 then
  742. Inc(cplusblocklevel)
  743. else
  744. begin
  745. if cplusblocklevel < 0 then
  746. Dec(cplusblocklevel);
  747. write(outfile,'{$if');
  748. copy_until_eol;
  749. writeln(outfile,'}');
  750. flush(outfile);
  751. block_type:=bt_no;
  752. end;
  753. end;
  754. Procedure HandlePreProcLineInfo;
  755. begin
  756. if NotInCPlusBlock then
  757. (* preprocessor line info *)
  758. repeat
  759. c:=get_char;
  760. case c of
  761. newline :
  762. begin
  763. unget_char(c);
  764. exit;
  765. end;
  766. #0 :
  767. commenteof;
  768. end;
  769. until false
  770. else
  771. skip_until_eol;
  772. end;
  773. procedure HandlePreProcPragma;
  774. begin
  775. if not stripinfo then
  776. begin
  777. write(outfile,'(** unsupported pragma');
  778. write(outfile,'#pragma');
  779. copy_until_eol;
  780. writeln(outfile,'*)');
  781. flush(outfile);
  782. end
  783. else
  784. skip_until_eol;
  785. block_type:=bt_no;
  786. end;
  787. Procedure HandleContinuation;
  788. begin
  789. if in_define then
  790. begin
  791. cont_line:=true;
  792. end
  793. else
  794. begin
  795. writeln('Unexpected wrap of line ',yylineno);
  796. writeln('"',yyline,'"');
  797. return(256);
  798. end;
  799. end;
  800. Procedure HandleEOL;
  801. begin
  802. if not in_define then
  803. exit;
  804. in_space_define:=0;
  805. if cont_line then
  806. begin
  807. cont_line:=false;
  808. end
  809. else
  810. begin
  811. in_define:=false;
  812. if NotInCPlusBlock then
  813. return(NEW_LINE)
  814. else
  815. skip_until_eol
  816. end;
  817. end;
  818. Procedure HandlePreProcDefine;
  819. begin
  820. if NotInCPlusBlock then
  821. begin
  822. commentstr:='';
  823. in_define:=true;
  824. in_space_define:=1;
  825. return(DEFINE);
  826. end
  827. else
  828. skip_until_eol;
  829. end;
  830. Procedure HandlePreProcError;
  831. begin
  832. write(outfile,'{$error');
  833. copy_until_eol;
  834. writeln(outfile,'}');
  835. flush(outfile);
  836. end;
  837. Procedure EnterCplusPlus;
  838. begin
  839. Inc(cplusblocklevel);
  840. end;
  841. Procedure HandlePreProcStripConditional(isEnd : Boolean);
  842. begin
  843. if not stripinfo then
  844. if isEnd then
  845. writeln(outfile,'{ C++ end of extern C conditionnal removed }')
  846. else
  847. writeln(outfile,'{ C++ extern C conditionnal removed }');
  848. end;
  849. Procedure HandleIdentifier;
  850. begin
  851. if NotInCPlusBlock then
  852. begin
  853. if in_space_define=1 then
  854. in_space_define:=2;
  855. return(ID);
  856. end
  857. else
  858. skip_until_eol;
  859. end;
  860. Procedure HandleWhiteSpace;
  861. begin
  862. if NotInCPlusBlock then
  863. begin
  864. if (arglevel=0) and (in_space_define=2) then
  865. begin
  866. in_space_define:=0;
  867. return(SPACE_DEFINE);
  868. end;
  869. end
  870. else
  871. skip_until_eol;
  872. end;
  873. Procedure HandleCallingConvention(aCC :integer);
  874. begin
  875. if NotInCPlusBlock then
  876. begin
  877. if Win32headers then
  878. return(aCC)
  879. else
  880. return(ID);
  881. end
  882. else
  883. begin
  884. skip_until_eol;
  885. end;
  886. end;
  887. Procedure HandlePalmPilotCallingConvention;
  888. begin
  889. if NotInCPlusBlock then
  890. begin
  891. if not palmpilot then
  892. return(ID)
  893. else
  894. return(SYS_TRAP);
  895. end
  896. else
  897. begin
  898. skip_until_eol;
  899. end;
  900. end;
  901. Procedure HandleIllegalCharacter;
  902. begin
  903. writeln('Illegal character in line ',yylineno);
  904. writeln('"',yyline,'"');
  905. return(256);
  906. end;
  907. end.