scandir.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Peter Vreman
  4. This unit implements directive parsing for the scanner
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. const
  19. directivelen=16;
  20. type
  21. directivestr=string[directivelen];
  22. tdirectivetoken=(
  23. _DIR_NONE,
  24. _DIR_ALIGN,
  25. _DIR_D,_DIR_DEFINE,_DIR_DESCRIPTION,
  26. _DIR_ELSE,_DIR_ENDIF,_DIR_ERROR,
  27. _DIR_FATAL,
  28. _DIR_I,_DIR_I386_ATT,_DIR_I386_DIRECT,_DIR_I386_INTEL,_DIR_IOCHECKS,
  29. _DIR_IF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_INFO,
  30. _DIR_L,_DIR_LINKLIB,
  31. _DIR_MESSAGE,_DIR_MMX,
  32. _DIR_NOTE,
  33. _DIR_OUTPUT_FORMAT,
  34. _DIR_PACKRECORDS,
  35. _DIR_SATURATION,_DIR_STOP,
  36. _DIR_UNDEF,
  37. _DIR_WAIT,_DIR_WARNING
  38. );
  39. const
  40. firstdirective=_DIR_NONE;
  41. lastdirective=_DIR_WARNING;
  42. directive:array[tdirectivetoken] of directivestr=(
  43. '',
  44. 'ALIGN',
  45. 'D','DEFINE','DESCRIPTION',
  46. 'ELSE','ENDIF','ERROR',
  47. 'FATAL',
  48. 'I','I386_ATT','I386_DIRECT','I386_INTEL','IOCHECKS',
  49. 'IF','IFDEF','IFNDEF','IFOPT','INFO',
  50. 'L','LINKLIB',
  51. 'MESSAGE','MMX',
  52. 'NOTE',
  53. 'OUTPUT_FORMAT',
  54. 'PACKRECORDS',
  55. 'SATURATION','STOP',
  56. 'UNDEF',
  57. 'WAIT','WARNING'
  58. );
  59. function Get_Directive(const hs:string):tdirectivetoken;
  60. var
  61. i : tdirectivetoken;
  62. begin
  63. for i:=firstdirective to lastdirective do
  64. if directive[i]=hs then
  65. begin
  66. Get_Directive:=i;
  67. exit;
  68. end;
  69. Get_Directive:=_DIR_NONE;
  70. end;
  71. {-------------------------------------------
  72. IF Conditional Handling
  73. -------------------------------------------}
  74. var
  75. preprocpat : string;
  76. preproc_token : ttoken;
  77. function read_preproc : ttoken;
  78. begin
  79. skipspace;
  80. case c of
  81. 'A'..'Z',
  82. 'a'..'z',
  83. '_','0'..'9' : begin
  84. preprocpat:=readid;
  85. read_preproc:=ID;
  86. end;
  87. '(' : begin
  88. readchar;
  89. read_preproc:=LKLAMMER;
  90. end;
  91. ')' : begin
  92. readchar;
  93. read_preproc:=RKLAMMER;
  94. end;
  95. '+' : begin
  96. readchar;
  97. read_preproc:=PLUS;
  98. end;
  99. '-' : begin
  100. readchar;
  101. read_preproc:=MINUS;
  102. end;
  103. '*' : begin
  104. readchar;
  105. read_preproc:=STAR;
  106. end;
  107. '/' : begin
  108. readchar;
  109. read_preproc:=SLASH;
  110. end;
  111. '=' : begin
  112. readchar;
  113. read_preproc:=EQUAL;
  114. end;
  115. '>' : begin
  116. readchar;
  117. if c='=' then
  118. begin
  119. readchar;
  120. read_preproc:=GTE;
  121. end
  122. else
  123. read_preproc:=GT;
  124. end;
  125. '<' : begin
  126. readchar;
  127. case c of
  128. '>' : begin
  129. readchar;
  130. read_preproc:=UNEQUAL;
  131. end;
  132. '=' : begin
  133. readchar;
  134. read_preproc:=LTE;
  135. end;
  136. else read_preproc:=LT;
  137. end;
  138. end;
  139. #26 : Message(scan_f_end_of_file);
  140. else
  141. begin
  142. read_preproc:=_EOF;
  143. end;
  144. end;
  145. end;
  146. procedure preproc_consume(t : ttoken);
  147. begin
  148. if t<>preproc_token then
  149. Message(scan_e_preproc_syntax_error);
  150. preproc_token:=read_preproc;
  151. end;
  152. function read_expr : string;forward;
  153. function read_factor : string;
  154. var
  155. hs : string;
  156. mac : pmacrosym;
  157. len : byte;
  158. begin
  159. if preproc_token=ID then
  160. begin
  161. if preprocpat='NOT' then
  162. begin
  163. preproc_consume(ID);
  164. hs:=read_expr;
  165. if hs='0' then
  166. read_factor:='1'
  167. else
  168. read_factor:='0';
  169. end
  170. else
  171. begin
  172. mac:=pmacrosym(macros^.search(hs));
  173. hs:=preprocpat;
  174. preproc_consume(ID);
  175. if assigned(mac) then
  176. begin
  177. if mac^.defined and assigned(mac^.buftext) then
  178. begin
  179. if mac^.buflen>255 then
  180. begin
  181. len:=255;
  182. Message(scan_w_marco_cut_after_255_chars);
  183. end
  184. else
  185. len:=mac^.buflen;
  186. hs[0]:=char(len);
  187. move(mac^.buftext^,hs[1],len);
  188. end
  189. else
  190. read_factor:='';
  191. end
  192. else
  193. read_factor:=hs;
  194. end
  195. end
  196. else if preproc_token=LKLAMMER then
  197. begin
  198. preproc_consume(LKLAMMER);
  199. read_factor:=read_expr;
  200. preproc_consume(RKLAMMER);
  201. end
  202. else
  203. Message(scan_e_error_in_preproc_expr);
  204. end;
  205. function read_term : string;
  206. var
  207. hs1,hs2 : string;
  208. begin
  209. hs1:=read_factor;
  210. while true do
  211. begin
  212. if (preproc_token=ID) then
  213. begin
  214. if preprocpat='AND' then
  215. begin
  216. preproc_consume(ID);
  217. hs2:=read_factor;
  218. if (hs1<>'0') and (hs2<>'0') then
  219. hs1:='1';
  220. end
  221. else
  222. break;
  223. end
  224. else
  225. break;
  226. end;
  227. read_term:=hs1;
  228. end;
  229. function read_simple_expr : string;
  230. var
  231. hs1,hs2 : string;
  232. begin
  233. hs1:=read_term;
  234. while true do
  235. begin
  236. if (preproc_token=ID) then
  237. begin
  238. if preprocpat='OR' then
  239. begin
  240. preproc_consume(ID);
  241. hs2:=read_term;
  242. if (hs1<>'0') or (hs2<>'0') then
  243. hs1:='1';
  244. end
  245. else
  246. break;
  247. end
  248. else
  249. break;
  250. end;
  251. read_simple_expr:=hs1;
  252. end;
  253. function read_expr : string;
  254. var
  255. hs1,hs2 : string;
  256. b : boolean;
  257. t : ttoken;
  258. w : word;
  259. l1,l2 : longint;
  260. begin
  261. hs1:=read_simple_expr;
  262. t:=preproc_token;
  263. if not(t in [EQUAL,UNEQUAL,LT,GT,LTE,GTE]) then
  264. begin
  265. read_expr:=hs1;
  266. exit;
  267. end;
  268. preproc_consume(t);
  269. hs2:=read_simple_expr;
  270. if is_number(hs1) and is_number(hs2) then
  271. begin
  272. valint(hs1,l1,w);
  273. valint(hs2,l2,w);
  274. case t of
  275. EQUAL:
  276. b:=l1=l2;
  277. UNEQUAL:
  278. b:=l1<>l2;
  279. LT:
  280. b:=l1<l2;
  281. GT:
  282. b:=l1>l2;
  283. GTE:
  284. b:=l1>=l2;
  285. LTE:
  286. b:=l1<=l2;
  287. end;
  288. end
  289. else
  290. begin
  291. case t of
  292. EQUAL:
  293. b:=hs1=hs2;
  294. UNEQUAL:
  295. b:=hs1<>hs2;
  296. LT:
  297. b:=hs1<hs2;
  298. GT:
  299. b:=hs1>hs2;
  300. GTE:
  301. b:=hs1>=hs2;
  302. LTE:
  303. b:=hs1<=hs2;
  304. end;
  305. end;
  306. if b then
  307. read_expr:='1'
  308. else
  309. read_expr:='0';
  310. end;
  311. {-------------------------------------------
  312. Directives
  313. -------------------------------------------}
  314. function is_conditional(t:tdirectivetoken):boolean;
  315. begin
  316. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  317. end;
  318. procedure dir_conditional(t:tdirectivetoken);
  319. procedure newpreproc(isifdef,a:boolean;const s:string;w:tmsgconst);
  320. begin
  321. preprocstack:=new(ppreprocstack,init(isifdef,
  322. ((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  323. preprocstack^.name:=s;
  324. preprocstack^.line_nb:=current_module^.current_inputfile^.line_no;
  325. if preprocstack^.accept then
  326. Message2(w,preprocstack^.name,'accepted')
  327. else
  328. Message2(w,preprocstack^.name,'rejected');
  329. end;
  330. var
  331. hs : string;
  332. mac : pmacrosym;
  333. found : boolean;
  334. begin
  335. while true do
  336. begin
  337. case t of
  338. _DIR_ENDIF : begin
  339. { we can always accept an ELSE }
  340. if assigned(preprocstack) then
  341. begin
  342. Message1(scan_c_endif_found,preprocstack^.name);
  343. if not preprocstack^.isifdef then
  344. popstack;
  345. end
  346. else
  347. Message(scan_e_endif_without_if);
  348. { now pop the condition }
  349. if assigned(preprocstack) then
  350. begin
  351. { we only use $ifdef in the stack }
  352. if preprocstack^.isifdef then
  353. popstack
  354. else
  355. Message(scan_e_too_much_endifs);
  356. end
  357. else
  358. Message(scan_e_endif_without_if);
  359. end;
  360. _DIR_ELSE : begin
  361. if assigned(preprocstack) then
  362. begin
  363. preprocstack:=new(ppreprocstack,init(false,
  364. not(preprocstack^.accept) and
  365. ((preprocstack^.next=nil) or (preprocstack^.next^.accept)),preprocstack));
  366. preprocstack^.line_nb:=current_module^.current_inputfile^.line_no;
  367. preprocstack^.name:=preprocstack^.next^.name;
  368. if preprocstack^.accept then
  369. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  370. else
  371. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  372. end
  373. else
  374. Message(scan_e_endif_without_if);
  375. end;
  376. _DIR_IFDEF : begin
  377. skipspace;
  378. hs:=readid;
  379. mac:=pmacrosym(macros^.search(hs));
  380. newpreproc(true,assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  381. end;
  382. _DIR_IFOPT : begin
  383. skipspace;
  384. hs:=readid;
  385. if (length(hs)=1) and (c in ['-','+']) then
  386. begin
  387. found:=CheckSwitch(hs[1],c);
  388. readchar; {read + or -}
  389. end
  390. else
  391. Message(scan_w_illegal_switch);
  392. newpreproc(true,found,hs,scan_c_ifopt_found);
  393. end;
  394. _DIR_IF : begin
  395. skipspace;
  396. { start preproc expression scanner }
  397. preproc_token:=read_preproc;
  398. hs:=read_expr;
  399. newpreproc(true,hs<>'0',hs,scan_c_if_found);
  400. end;
  401. _DIR_IFNDEF : begin
  402. skipspace;
  403. hs:=readid;
  404. mac:=pmacrosym(macros^.search(hs));
  405. newpreproc(true,not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  406. end;
  407. end;
  408. { accept the text ? }
  409. if (preprocstack=nil) or preprocstack^.accept then
  410. break
  411. else
  412. begin
  413. Message(scan_c_skipping_until);
  414. repeat
  415. skipuntildirective;
  416. t:=Get_Directive(readid);
  417. until is_conditional(t);
  418. end;
  419. end;
  420. end;
  421. procedure dir_define(t:tdirectivetoken);
  422. var
  423. ht : ttoken;
  424. hs2,
  425. hs : string;
  426. mac : pmacrosym;
  427. begin
  428. skipspace;
  429. hs:=readid;
  430. mac:=pmacrosym(macros^.search(hs));
  431. if not assigned(mac) then
  432. begin
  433. mac:=new(pmacrosym,init(hs));
  434. mac^.defined:=true;
  435. Message1(parser_m_macro_defined,mac^.name);
  436. macros^.insert(mac);
  437. end
  438. else
  439. begin
  440. Message1(parser_m_macro_defined,mac^.name);
  441. mac^.defined:=true;
  442. { delete old definition }
  443. if assigned(mac^.buftext) then
  444. begin
  445. freemem(mac^.buftext,mac^.buflen);
  446. mac^.buftext:=nil;
  447. end;
  448. end;
  449. if support_macros then
  450. begin
  451. { key words are never substituted }
  452. hs2:=pattern;
  453. pattern:=hs;
  454. if is_keyword(ht) then
  455. Message(scan_e_keyword_cant_be_a_macro);
  456. pattern:=hs2;
  457. { !!!!!! handle macro params, need we this? }
  458. skipspace;
  459. { may be a macro? }
  460. if c=':' then
  461. begin
  462. readchar;
  463. if c='=' then
  464. begin
  465. { first char }
  466. readchar;
  467. macropos:=0;
  468. while (c<>'}') do
  469. begin
  470. macrobuffer^[macropos]:=c;
  471. readchar;
  472. if c=#26 then Message(scan_f_end_of_file);
  473. inc(macropos);
  474. if macropos>maxmacrolen then
  475. Message(scan_f_macro_buffer_overflow);
  476. end;
  477. { free buffer of macro ?}
  478. if assigned(mac^.buftext) then
  479. freemem(mac^.buftext,mac^.buflen);
  480. { get new mem }
  481. getmem(mac^.buftext,macropos);
  482. mac^.buflen:=macropos;
  483. { copy the text }
  484. move(macrobuffer^,mac^.buftext^,macropos);
  485. end;
  486. end;
  487. end;
  488. end;
  489. procedure dir_undef(t:tdirectivetoken);
  490. var
  491. hs : string;
  492. mac : pmacrosym;
  493. begin
  494. skipspace;
  495. hs:=readid;
  496. mac:=pmacrosym(macros^.search(hs));
  497. if not assigned(mac) then
  498. begin
  499. mac:=new(pmacrosym,init(hs));
  500. Message1(parser_m_macro_undefined,mac^.name);
  501. mac^.defined:=false;
  502. macros^.insert(mac);
  503. end
  504. else
  505. begin
  506. Message1(parser_m_macro_undefined,mac^.name);
  507. mac^.defined:=false;
  508. { delete old definition }
  509. if assigned(mac^.buftext) then
  510. begin
  511. freemem(mac^.buftext,mac^.buflen);
  512. mac^.buftext:=nil;
  513. end;
  514. end;
  515. end;
  516. procedure dir_message(t:tdirectivetoken);
  517. var
  518. w : tmsgconst;
  519. begin
  520. case t of
  521. _DIR_STOP,
  522. _DIR_FATAL : w:=scan_f_user_defined;
  523. _DIR_ERROR : w:=scan_e_user_defined;
  524. _DIR_WARNING : w:=scan_w_user_defined;
  525. _DIR_NOTE : w:=scan_n_user_defined;
  526. _DIR_MESSAGE,
  527. _DIR_INFO : w:=scan_i_user_defined;
  528. end;
  529. skipspace;
  530. Message1(w,readcomment);
  531. end;
  532. procedure dir_switch(t:tdirectivetoken);
  533. {$ifdef SUPPORT_MMX}
  534. var
  535. sw : tcswitch;
  536. {$endif}
  537. begin
  538. {$ifdef SUPPORT_MMX}
  539. case t of
  540. _DIR_MMX : sw:=cs_mmx;
  541. _DIR_SATURATION : sw:=cs_mmx_saturation;
  542. end;
  543. {$endif}
  544. end;
  545. procedure dir_include(t:tdirectivetoken);
  546. var
  547. hs : string;
  548. path : dirstr;
  549. name : namestr;
  550. ext : extstr;
  551. hp : pinputfile;
  552. found : boolean;
  553. begin
  554. skipspace;
  555. hs:=readcomment;
  556. while (hs<>'') and (hs[length(hs)]=' ') do
  557. dec(byte(hs[0]));
  558. hs:=FixFileName(hs);
  559. fsplit(hs,path,name,ext);
  560. { first look in the path of _d then currentmodule }
  561. path:=search(hs,path+';'+current_module^.current_inputfile^.path^+';'+includesearchpath,found);
  562. hp:=new(pinputfile,init(path,name,ext));
  563. hp^.reset;
  564. if ioresult=0 then
  565. begin
  566. current_module^.current_inputfile^.bufpos:=longint(inputpointer)-longint(inputbuffer);
  567. hp^.next:=current_module^.current_inputfile;
  568. current_module^.current_inputfile:=hp;
  569. status.currentsource:=current_module^.current_inputfile^.name^+current_module^.current_inputfile^.ext^;
  570. current_module^.sourcefiles.register_file(hp);
  571. current_module^.current_index:=hp^.ref_index;
  572. inputbuffer:=current_module^.current_inputfile^.buf;
  573. Message1(scan_u_start_include_file,current_module^.current_inputfile^.name^);
  574. reload;
  575. end
  576. else
  577. Message1(scan_f_cannot_open_includefile,hs);
  578. end;
  579. procedure dir_description(t:tdirectivetoken);
  580. begin
  581. end;
  582. procedure dir_linkobject(t:tdirectivetoken);
  583. var
  584. path,hs : string;
  585. found : boolean;
  586. begin
  587. skipspace;
  588. hs:=FixFileName(readstring);
  589. if (not path_absolute(hs)) and (not assigned(current_module^.current_inputfile^.path)) then
  590. path:=search(hs,current_module^.current_inputfile^.path^+';'+objectsearchpath,found);
  591. Linker.AddObjectFile(path+hs);
  592. current_module^.linkofiles.insert(hs);
  593. end;
  594. procedure dir_linklib(t:tdirectivetoken);
  595. var
  596. hs : string;
  597. begin
  598. skipspace;
  599. hs:=FixFileName(readstring);
  600. Linker.AddLibraryFile(hs);
  601. current_module^.linklibfiles.insert(hs);
  602. end;
  603. procedure dir_outputformat(t:tdirectivetoken);
  604. var
  605. hs : string;
  606. begin
  607. if not current_module^.in_main then
  608. Message(scan_w_switch_is_global)
  609. else
  610. begin
  611. skipspace;
  612. hs:=readid;
  613. {$ifdef i386}
  614. if hs='NASM' then
  615. current_module^.output_format:=of_nasm
  616. else
  617. if hs='MASM' then
  618. current_module^.output_format:=of_masm
  619. else
  620. if hs='O' then
  621. current_module^.output_format:=of_o
  622. else
  623. if hs='OBJ' then
  624. current_module^.output_format:=of_obj
  625. else
  626. {$endif}
  627. Message(scan_w_illegal_switch);
  628. end;
  629. { for use in globals }
  630. output_format:=current_module^.output_format;
  631. end;
  632. procedure dir_packrecords(t:tdirectivetoken);
  633. var
  634. hs : string;
  635. begin
  636. skipspace;
  637. if upcase(c)='N' then
  638. begin
  639. hs:=readid;
  640. if hs='NORMAL' then
  641. aktpackrecords:=2
  642. else
  643. Message(scan_w_only_pack_records);
  644. end
  645. else
  646. begin
  647. case readval of
  648. 1 : aktpackrecords:=1;
  649. 2 : aktpackrecords:=2;
  650. 4 : aktpackrecords:=4;
  651. else
  652. Message(scan_w_only_pack_records);
  653. end;
  654. end;
  655. end;
  656. procedure dir_wait(t:tdirectivetoken);
  657. begin
  658. Message(scan_i_press_enter);
  659. readln;
  660. end;
  661. procedure dir_asmmode(t:tdirectivetoken);
  662. begin
  663. {$ifdef i386}
  664. case t of
  665. _DIR_I386_ATT : aktasmmode:=I386_ATT;
  666. _DIR_I386_DIRECT : aktasmmode:=I386_DIRECT;
  667. _DIR_I386_INTEL : aktasmmode:=I386_INTEL;
  668. end;
  669. {$endif}
  670. end;
  671. procedure dir_delphiswitch(t:tdirectivetoken);
  672. var
  673. sw : char;
  674. begin
  675. case t of
  676. _DIR_ALIGN : sw:='A';
  677. _DIR_IOCHECKS : sw:='I';
  678. else
  679. exit;
  680. end;
  681. { c contains the next char, a + or - would be fine }
  682. HandleSwitch(sw,c);
  683. ReadComment;
  684. end;
  685. type
  686. tdirectiveproc=procedure(t:tdirectivetoken);
  687. const
  688. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  689. {_DIR_NONE} nil,
  690. {_DIR_ALIGN} dir_delphiswitch,
  691. {_DIR_D} dir_description,
  692. {_DIR_DEFINE} dir_define,
  693. {_DIR_DESCRIPTION} dir_description,
  694. {_DIR_ELSE} dir_conditional,
  695. {_DIR_ENDIF} dir_conditional,
  696. {_DIR_ERROR} dir_message,
  697. {_DIR_FATAL} dir_message,
  698. {_DIR_I} dir_include,
  699. {_DIR_I386_ATT} dir_asmmode,
  700. {_DIR_I386_DIRECT} dir_asmmode,
  701. {_DIR_I386_INTEL} dir_asmmode,
  702. {_DIR_IOCHECKS} dir_delphiswitch,
  703. {_DIR_IF} dir_conditional,
  704. {_DIR_IFDEF} dir_conditional,
  705. {_DIR_IFNDEF} dir_conditional,
  706. {_DIR_IFOPT} dir_conditional,
  707. {_DIR_INFO} dir_message,
  708. {_DIR_L} dir_linkobject,
  709. {_DIR_LINKLIB} dir_linklib,
  710. {_DIR_MESSAGE} dir_message,
  711. {_DIR_MMX} dir_switch,
  712. {_DIR_NOTE} dir_message,
  713. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  714. {_DIR_PACKRECORDS} dir_packrecords,
  715. {_DIR_SATURATION} dir_switch,
  716. {_DIR_STOP} dir_message,
  717. {_DIR_UNDEF} dir_undef,
  718. {_DIR_WAIT} dir_wait,
  719. {_DIR_WARNING} dir_message
  720. );
  721. {-------------------------------------------
  722. Main switches handling
  723. -------------------------------------------}
  724. procedure handledirectives;
  725. var
  726. t : tdirectivetoken;
  727. p : tdirectiveproc;
  728. hs : string;
  729. begin
  730. readchar; {Remove the $}
  731. hs:=readid;
  732. Message1(scan_d_handling_switch,'$'+hs);
  733. if hs='' then
  734. Message1(scan_w_illegal_switch,'$'+hs);
  735. { Check for compiler switches }
  736. while (length(hs)=1) and (c in ['-','+']) do
  737. begin
  738. HandleSwitch(hs[1],c);
  739. readchar; {Remove + or -}
  740. if c=',' then
  741. begin
  742. readchar; {Remove , }
  743. hs:=readid; {Check for multiple switches on one line}
  744. Message1(scan_d_handling_switch,'$'+hs);
  745. end
  746. else
  747. hs:='';
  748. end;
  749. { directives may follow switches after a , }
  750. if hs<>'' then
  751. begin
  752. t:=Get_Directive(hs);
  753. if t<>_DIR_NONE then
  754. begin
  755. p:=directiveproc[t];
  756. {$ifdef FPC}
  757. if assigned(p) then
  758. {$else}
  759. if @p<>nil then
  760. {$endif}
  761. p(t);
  762. end
  763. else
  764. Message1(scan_w_illegal_directive,'$'+hs);
  765. { conditionals already read the comment }
  766. if (comment_level>0) then
  767. readcomment;
  768. end;
  769. end;
  770. {
  771. $Log$
  772. Revision 1.5 1998-04-30 15:59:42 pierre
  773. * GDB works again better :
  774. correct type info in one pass
  775. + UseTokenInfo for better source position
  776. * fixed one remaining bug in scanner for line counts
  777. * several little fixes
  778. Revision 1.4 1998/04/29 13:42:27 peter
  779. + $IOCHECKS and $ALIGN to test already, other will follow soon
  780. * fixed the wrong linecounting with comments
  781. Revision 1.3 1998/04/28 11:45:53 florian
  782. * make it compilable with TP
  783. + small COM problems solved to compile classes.pp
  784. Revision 1.2 1998/04/28 10:09:54 pierre
  785. * typo error in asm style reading corrected
  786. Revision 1.1 1998/04/27 23:13:53 peter
  787. + the new files for the scanner
  788. }