scandir.inc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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,_DIR_ASMMODE,_DIR_ASSERTIONS,
  25. _DIR_BOOLEVAL,
  26. _DIR_D,_DIR_DEBUGINFO,_DIR_DEFINE,_DIR_DESCRIPTION,
  27. _DIR_ELSE,_DIR_ENDIF,_DIR_ERROR,_DIR_EXTENDEDSYNTAX,
  28. _DIR_FATAL,
  29. _DIR_HINT,_DIR_HINTS,
  30. _DIR_I,_DIR_I386_ATT,_DIR_I386_DIRECT,_DIR_I386_INTEL,_DIR_IOCHECKS,
  31. _DIR_IF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_INCLUDE,_DIR_INFO,
  32. _DIR_L,_DIR_LINK,_DIR_LINKLIB,_DIR_LOCALSYMBOLS,_DIR_LONGSTRINGS,
  33. _DIR_M,_DIR_MEMORY,_DIR_MESSAGE,_DIR_MINENUMSIZE,_DIR_MMX,
  34. _DIR_NOTE,_DIR_NOTES,
  35. _DIR_OPENSTRINGS,_DIR_OUTPUT_FORMAT,_DIR_OVERFLOWCHECKS,
  36. _DIR_PACKENUM,_DIR_PACKRECORDS,
  37. _DIR_RANGECHECKS,_DIR_REFERENCEINFO,
  38. _DIR_SATURATION,_DIR_SMARTLINK,_DIR_STACKFRAMES,_DIR_STOP,
  39. _DIR_TYPEDADDRESS,_DIR_TYPEINFO,
  40. _DIR_UNDEF,
  41. _DIR_VARSTRINGCHECKS,
  42. _DIR_WAIT,_DIR_WARNING,_DIR_WARNINGS,
  43. _DIR_Z1,_DIR_Z2,_DIR_Z4
  44. );
  45. const
  46. firstdirective=_DIR_NONE;
  47. lastdirective=_DIR_Z4;
  48. directive:array[tdirectivetoken] of directivestr=(
  49. '',
  50. 'ALIGN','ASMMODE','ASSERTIONS',
  51. 'BOOLEVAL',
  52. 'D','DEBUGINFO','DEFINE','DESCRIPTION',
  53. 'ELSE','ENDIF','ERROR','EXTENDEDSYNTAX',
  54. 'FATAL',
  55. 'HINT','HINTS',
  56. 'I','I386_ATT','I386_DIRECT','I386_INTEL','IOCHECKS',
  57. 'IF','IFDEF','IFNDEF','IFOPT','INCLUDE','INFO',
  58. 'L','LINK','LINKLIB','LOCALSYMBOLS','LONGSTRINGS',
  59. 'M','MEMORY','MESSAGE','MINENUMSIZE','MMX',
  60. 'NOTE','NOTES',
  61. 'OPENSTRINGS','OUTPUT_FORMAT','OVERFLOWCHECKS',
  62. 'PACKENUM','PACKRECORDS',
  63. 'RANGECHECKS','REFERENCEINFO',
  64. 'SATURATION','SMARTLINK','STACKFRAMES','STOP',
  65. 'TYPEDADDRESS','TYPEINFO',
  66. 'UNDEF',
  67. 'VARSTRINGCHECKS',
  68. 'WAIT','WARNING','WARNINGS',
  69. 'Z1','Z2','Z4'
  70. );
  71. function Get_Directive(const hs:string):tdirectivetoken;
  72. var
  73. i : tdirectivetoken;
  74. begin
  75. for i:=firstdirective to lastdirective do
  76. if directive[i]=hs then
  77. begin
  78. Get_Directive:=i;
  79. exit;
  80. end;
  81. Get_Directive:=_DIR_NONE;
  82. end;
  83. {-------------------------------------------
  84. IF Conditional Handling
  85. -------------------------------------------}
  86. var
  87. preprocpat : string;
  88. preproc_token : ttoken;
  89. procedure preproc_consume(t : ttoken);
  90. begin
  91. if t<>preproc_token then
  92. Message(scan_e_preproc_syntax_error);
  93. preproc_token:=current_scanner^.readpreproc;
  94. end;
  95. function read_expr : string;forward;
  96. function read_factor : string;
  97. var
  98. hs : string;
  99. mac : pmacrosym;
  100. len : byte;
  101. begin
  102. if preproc_token=ID then
  103. begin
  104. if preprocpat='NOT' then
  105. begin
  106. preproc_consume(ID);
  107. hs:=read_expr;
  108. if hs='0' then
  109. read_factor:='1'
  110. else
  111. read_factor:='0';
  112. end
  113. else
  114. begin
  115. mac:=pmacrosym(macros^.search(hs));
  116. hs:=preprocpat;
  117. preproc_consume(ID);
  118. if assigned(mac) then
  119. begin
  120. if mac^.defined and assigned(mac^.buftext) then
  121. begin
  122. if mac^.buflen>255 then
  123. begin
  124. len:=255;
  125. Message(scan_w_marco_cut_after_255_chars);
  126. end
  127. else
  128. len:=mac^.buflen;
  129. hs[0]:=char(len);
  130. move(mac^.buftext^,hs[1],len);
  131. end
  132. else
  133. read_factor:='';
  134. end
  135. else
  136. read_factor:=hs;
  137. end
  138. end
  139. else if preproc_token=LKLAMMER then
  140. begin
  141. preproc_consume(LKLAMMER);
  142. read_factor:=read_expr;
  143. preproc_consume(RKLAMMER);
  144. end
  145. else
  146. Message(scan_e_error_in_preproc_expr);
  147. end;
  148. function read_term : string;
  149. var
  150. hs1,hs2 : string;
  151. begin
  152. hs1:=read_factor;
  153. while true do
  154. begin
  155. if (preproc_token=ID) then
  156. begin
  157. if preprocpat='AND' then
  158. begin
  159. preproc_consume(ID);
  160. hs2:=read_factor;
  161. if (hs1<>'0') and (hs2<>'0') then
  162. hs1:='1';
  163. end
  164. else
  165. break;
  166. end
  167. else
  168. break;
  169. end;
  170. read_term:=hs1;
  171. end;
  172. function read_simple_expr : string;
  173. var
  174. hs1,hs2 : string;
  175. begin
  176. hs1:=read_term;
  177. while true do
  178. begin
  179. if (preproc_token=ID) then
  180. begin
  181. if preprocpat='OR' then
  182. begin
  183. preproc_consume(ID);
  184. hs2:=read_term;
  185. if (hs1<>'0') or (hs2<>'0') then
  186. hs1:='1';
  187. end
  188. else
  189. break;
  190. end
  191. else
  192. break;
  193. end;
  194. read_simple_expr:=hs1;
  195. end;
  196. function read_expr : string;
  197. var
  198. hs1,hs2 : string;
  199. b : boolean;
  200. t : ttoken;
  201. w : word;
  202. l1,l2 : longint;
  203. begin
  204. hs1:=read_simple_expr;
  205. t:=preproc_token;
  206. if not(t in [EQUAL,UNEQUAL,LT,GT,LTE,GTE]) then
  207. begin
  208. read_expr:=hs1;
  209. exit;
  210. end;
  211. preproc_consume(t);
  212. hs2:=read_simple_expr;
  213. if is_number(hs1) and is_number(hs2) then
  214. begin
  215. valint(hs1,l1,w);
  216. valint(hs2,l2,w);
  217. case t of
  218. EQUAL:
  219. b:=l1=l2;
  220. UNEQUAL:
  221. b:=l1<>l2;
  222. LT:
  223. b:=l1<l2;
  224. GT:
  225. b:=l1>l2;
  226. GTE:
  227. b:=l1>=l2;
  228. LTE:
  229. b:=l1<=l2;
  230. end;
  231. end
  232. else
  233. begin
  234. case t of
  235. EQUAL:
  236. b:=hs1=hs2;
  237. UNEQUAL:
  238. b:=hs1<>hs2;
  239. LT:
  240. b:=hs1<hs2;
  241. GT:
  242. b:=hs1>hs2;
  243. GTE:
  244. b:=hs1>=hs2;
  245. LTE:
  246. b:=hs1<=hs2;
  247. end;
  248. end;
  249. if b then
  250. read_expr:='1'
  251. else
  252. read_expr:='0';
  253. end;
  254. {-------------------------------------------
  255. Directives
  256. -------------------------------------------}
  257. function is_conditional(t:tdirectivetoken):boolean;
  258. begin
  259. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  260. end;
  261. procedure dir_conditional(t:tdirectivetoken);
  262. var
  263. hs : string;
  264. mac : pmacrosym;
  265. found : boolean;
  266. begin
  267. while true do
  268. begin
  269. case t of
  270. _DIR_ENDIF : begin
  271. current_scanner^.poppreprocstack;
  272. end;
  273. _DIR_ELSE : begin
  274. current_scanner^.elsepreprocstack;
  275. end;
  276. _DIR_IFDEF : begin
  277. current_scanner^.skipspace;
  278. hs:=current_scanner^.readid;
  279. mac:=pmacrosym(macros^.search(hs));
  280. current_scanner^.addpreprocstack(assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  281. end;
  282. _DIR_IFOPT : begin
  283. current_scanner^.skipspace;
  284. hs:=current_scanner^.readid;
  285. if (length(hs)=1) and (c in ['-','+']) then
  286. begin
  287. found:=CheckSwitch(hs[1],c);
  288. current_scanner^.readchar; {read + or -}
  289. end
  290. else
  291. Message(scan_w_illegal_switch);
  292. current_scanner^.addpreprocstack(found,hs,scan_c_ifopt_found);
  293. end;
  294. _DIR_IF : begin
  295. current_scanner^.skipspace;
  296. { start preproc expression scanner }
  297. preproc_token:=current_scanner^.readpreproc;
  298. hs:=read_expr;
  299. current_scanner^.addpreprocstack(hs<>'0',hs,scan_c_if_found);
  300. end;
  301. _DIR_IFNDEF : begin
  302. current_scanner^.skipspace;
  303. hs:=current_scanner^.readid;
  304. mac:=pmacrosym(macros^.search(hs));
  305. current_scanner^.addpreprocstack(not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  306. end;
  307. end;
  308. { accept the text ? }
  309. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  310. break
  311. else
  312. begin
  313. Message(scan_c_skipping_until);
  314. repeat
  315. current_scanner^.skipuntildirective;
  316. t:=Get_Directive(current_scanner^.readid);
  317. until is_conditional(t);
  318. Message1(scan_d_handling_switch,'$'+directive[t]);
  319. end;
  320. end;
  321. end;
  322. procedure dir_define(t:tdirectivetoken);
  323. var
  324. ht : ttoken;
  325. hs2,
  326. hs : string;
  327. mac : pmacrosym;
  328. macropos : longint;
  329. macrobuffer : pmacrobuffer;
  330. begin
  331. current_scanner^.skipspace;
  332. hs:=current_scanner^.readid;
  333. mac:=pmacrosym(macros^.search(hs));
  334. if not assigned(mac) then
  335. begin
  336. mac:=new(pmacrosym,init(hs));
  337. mac^.defined:=true;
  338. Message1(parser_m_macro_defined,mac^.name);
  339. macros^.insert(mac);
  340. end
  341. else
  342. begin
  343. Message1(parser_m_macro_defined,mac^.name);
  344. mac^.defined:=true;
  345. { delete old definition }
  346. if assigned(mac^.buftext) then
  347. begin
  348. freemem(mac^.buftext,mac^.buflen);
  349. mac^.buftext:=nil;
  350. end;
  351. end;
  352. if (cs_support_macro in aktmoduleswitches) then
  353. begin
  354. { key words are never substituted }
  355. hs2:=pattern;
  356. pattern:=hs;
  357. if is_keyword(ht) then
  358. Message(scan_e_keyword_cant_be_a_macro);
  359. pattern:=hs2;
  360. { !!!!!! handle macro params, need we this? }
  361. current_scanner^.skipspace;
  362. { may be a macro? }
  363. if c=':' then
  364. begin
  365. current_scanner^.readchar;
  366. if c='=' then
  367. begin
  368. new(macrobuffer);
  369. macropos:=0;
  370. { first char }
  371. current_scanner^.readchar;
  372. while (c<>'}') do
  373. begin
  374. macrobuffer^[macropos]:=c;
  375. current_scanner^.readchar;
  376. if c=#26 then Message(scan_f_end_of_file);
  377. inc(macropos);
  378. if macropos>maxmacrolen then
  379. Message(scan_f_macro_buffer_overflow);
  380. end;
  381. { free buffer of macro ?}
  382. if assigned(mac^.buftext) then
  383. freemem(mac^.buftext,mac^.buflen);
  384. { get new mem }
  385. getmem(mac^.buftext,macropos);
  386. mac^.buflen:=macropos;
  387. { copy the text }
  388. move(macrobuffer^,mac^.buftext^,macropos);
  389. dispose(macrobuffer);
  390. end;
  391. end;
  392. end;
  393. end;
  394. procedure dir_undef(t:tdirectivetoken);
  395. var
  396. hs : string;
  397. mac : pmacrosym;
  398. begin
  399. current_scanner^.skipspace;
  400. hs:=current_scanner^.readid;
  401. mac:=pmacrosym(macros^.search(hs));
  402. if not assigned(mac) then
  403. begin
  404. mac:=new(pmacrosym,init(hs));
  405. Message1(parser_m_macro_undefined,mac^.name);
  406. mac^.defined:=false;
  407. macros^.insert(mac);
  408. end
  409. else
  410. begin
  411. Message1(parser_m_macro_undefined,mac^.name);
  412. mac^.defined:=false;
  413. { delete old definition }
  414. if assigned(mac^.buftext) then
  415. begin
  416. freemem(mac^.buftext,mac^.buflen);
  417. mac^.buftext:=nil;
  418. end;
  419. end;
  420. end;
  421. procedure dir_message(t:tdirectivetoken);
  422. var
  423. w : tmsgconst;
  424. begin
  425. case t of
  426. _DIR_STOP,
  427. _DIR_FATAL : w:=scan_f_user_defined;
  428. _DIR_ERROR : w:=scan_e_user_defined;
  429. _DIR_WARNING : w:=scan_w_user_defined;
  430. _DIR_HINT : w:=scan_h_user_defined;
  431. _DIR_NOTE : w:=scan_n_user_defined;
  432. _DIR_MESSAGE,
  433. _DIR_INFO : w:=scan_i_user_defined;
  434. end;
  435. current_scanner^.skipspace;
  436. Message1(w,current_scanner^.readcomment);
  437. end;
  438. procedure dir_moduleswitch(t:tdirectivetoken);
  439. var
  440. sw : tmoduleswitch;
  441. begin
  442. case t of
  443. _DIR_SMARTLINK : sw:=cs_smartlink;
  444. end;
  445. current_scanner^.skipspace;
  446. if c='-' then
  447. aktmoduleswitches:=aktmoduleswitches-[sw]
  448. else
  449. aktmoduleswitches:=aktmoduleswitches+[sw];
  450. end;
  451. procedure dir_localswitch(t:tdirectivetoken);
  452. var
  453. sw : tlocalswitch;
  454. begin
  455. {$ifdef SUPPORT_MMX}
  456. case t of
  457. _DIR_MMX : sw:=cs_mmx;
  458. _DIR_SATURATION : sw:=cs_mmx_saturation;
  459. end;
  460. {$endif}
  461. current_scanner^.skipspace;
  462. if c='-' then
  463. aktlocalswitches:=aktlocalswitches-[sw]
  464. else
  465. aktlocalswitches:=aktlocalswitches+[sw];
  466. end;
  467. procedure dir_include(t:tdirectivetoken);
  468. var
  469. hs : string;
  470. path : dirstr;
  471. name : namestr;
  472. ext : extstr;
  473. hp : pinputfile;
  474. found : boolean;
  475. begin
  476. current_scanner^.skipspace;
  477. hs:=current_scanner^.readcomment;
  478. while (hs<>'') and (hs[length(hs)]=' ') do
  479. dec(byte(hs[0]));
  480. if hs='' then
  481. exit;
  482. if (hs[1]='%') then
  483. begin
  484. { save old }
  485. path:=hs;
  486. { remove %'s }
  487. Delete(hs,1,1);
  488. if hs[length(hs)]='%' then
  489. Delete(hs,length(hs),1);
  490. { first check for internal macros }
  491. if hs='TIME' then
  492. hs:=gettimestr
  493. else
  494. if hs='DATE' then
  495. hs:=getdatestr
  496. else
  497. if hs='FPCVERSION' then
  498. hs:=version_string
  499. else
  500. if hs='FPCTARGET' then
  501. hs:=target_string
  502. else
  503. hs:=getenv(hs);
  504. if hs='' then
  505. Comment(V_Warning,'Include environment '+path+' not found in environment')
  506. else
  507. begin
  508. { make it a stringconst }
  509. hs:=''''+hs+'''';
  510. current_scanner^.insertmacro(@hs[1],length(hs));
  511. end;
  512. end
  513. else
  514. begin
  515. hs:=FixFileName(hs);
  516. fsplit(hs,path,name,ext);
  517. { first look in the path of _d then currentmodule }
  518. path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found);
  519. { shutdown current file }
  520. current_scanner^.tempclose;
  521. { load new file }
  522. hp:=new(pinputfile,init(path+name+ext));
  523. current_scanner^.addfile(hp);
  524. if not current_scanner^.open then
  525. Message1(scan_f_cannot_open_includefile,hs);
  526. Message1(scan_u_start_include_file,current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^);
  527. current_scanner^.reload;
  528. { register for refs }
  529. current_module^.sourcefiles.register_file(hp);
  530. current_module^.current_index:=hp^.ref_index;
  531. end;
  532. end;
  533. procedure dir_description(t:tdirectivetoken);
  534. begin
  535. end;
  536. procedure dir_linkobject(t:tdirectivetoken);
  537. begin
  538. current_scanner^.skipspace;
  539. current_scanner^.readstring;
  540. current_module^.linkofiles.insert(FixFileName(orgpattern));
  541. end;
  542. procedure dir_linklib(t:tdirectivetoken);
  543. begin
  544. current_scanner^.skipspace;
  545. current_scanner^.readstring;
  546. current_module^.linkSharedLibs.insert(orgpattern);
  547. end;
  548. procedure dir_outputformat(t:tdirectivetoken);
  549. begin
  550. if not current_module^.in_global then
  551. Message(scan_w_switch_is_global)
  552. else
  553. begin
  554. current_scanner^.skipspace;
  555. if set_string_asm(current_scanner^.readid) then
  556. aktoutputformat:=target_asm.id
  557. else
  558. Message(scan_w_illegal_switch);
  559. end;
  560. end;
  561. procedure dir_packrecords(t:tdirectivetoken);
  562. var
  563. hs : string;
  564. begin
  565. current_scanner^.skipspace;
  566. if not(c in ['0'..'9']) then
  567. begin
  568. hs:=current_scanner^.readid;
  569. if (hs='NORMAL') or (hs='DEFAULT') then
  570. aktpackrecords:=2
  571. else
  572. Message(scan_w_only_pack_records);
  573. end
  574. else
  575. begin
  576. case current_scanner^.readval of
  577. 1 : aktpackrecords:=1;
  578. 2 : aktpackrecords:=2;
  579. 4 : aktpackrecords:=4;
  580. 16 : aktpackrecords:=16;
  581. else
  582. Message(scan_w_only_pack_records);
  583. end;
  584. end;
  585. end;
  586. procedure dir_packenum(t:tdirectivetoken);
  587. var
  588. hs : string;
  589. begin
  590. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  591. begin
  592. aktpackenum:=ord(pattern[2])-ord('0');
  593. exit;
  594. end;
  595. current_scanner^.skipspace;
  596. if not(c in ['0'..'9']) then
  597. begin
  598. hs:=current_scanner^.readid;
  599. if (hs='NORMAL') or (hs='DEFAULT') then
  600. aktpackenum:=4
  601. else
  602. Message(scan_w_only_pack_enum);
  603. end
  604. else
  605. begin
  606. case current_scanner^.readval of
  607. 1 : aktpackenum:=1;
  608. 2 : aktpackenum:=2;
  609. 4 : aktpackenum:=4;
  610. else
  611. Message(scan_w_only_pack_enum);
  612. end;
  613. end;
  614. end;
  615. procedure dir_wait(t:tdirectivetoken);
  616. begin
  617. Message(scan_i_press_enter);
  618. readln;
  619. end;
  620. procedure dir_asmmode(t:tdirectivetoken);
  621. var
  622. s : string;
  623. begin
  624. current_scanner^.skipspace;
  625. s:=current_scanner^.readid;
  626. if s='DEFAULT' then
  627. aktasmmode:=initasmmode
  628. else
  629. if not set_string_asmmode(s,aktasmmode) then
  630. Message1(scan_w_unsupported_asmmode_specifier,s);
  631. end;
  632. procedure dir_oldasmmode(t:tdirectivetoken);
  633. begin
  634. {$ifdef i386}
  635. case t of
  636. _DIR_I386_ATT : aktasmmode:=I386_ATT;
  637. _DIR_I386_DIRECT : aktasmmode:=I386_DIRECT;
  638. _DIR_I386_INTEL : aktasmmode:=I386_INTEL;
  639. end;
  640. {$endif}
  641. end;
  642. procedure dir_delphiswitch(t:tdirectivetoken);
  643. var
  644. sw,state : char;
  645. begin
  646. case t of
  647. _DIR_ALIGN : sw:='A';
  648. _DIR_ASSERTIONS : sw:='C';
  649. _DIR_BOOLEVAL : sw:='B';
  650. _DIR_DEBUGINFO : sw:='D';
  651. _DIR_IOCHECKS : sw:='I';
  652. _DIR_LOCALSYMBOLS : sw:='L';
  653. _DIR_LONGSTRINGS : sw:='H';
  654. _DIR_OPENSTRINGS : sw:='P';
  655. _DIR_OVERFLOWCHECKS : sw:='Q';
  656. _DIR_RANGECHECKS : sw:='R';
  657. _DIR_REFERENCEINFO : sw:='Y';
  658. _DIR_STACKFRAMES : sw:='W';
  659. _DIR_TYPEDADDRESS : sw:='T';
  660. _DIR_TYPEINFO : sw:='M';
  661. _DIR_VARSTRINGCHECKS : sw:='V';
  662. else
  663. exit;
  664. end;
  665. { support ON/OFF }
  666. if c=' ' then
  667. begin
  668. current_scanner^.skipspace;
  669. current_scanner^.readid;
  670. if pattern='ON' then
  671. state:='+'
  672. else
  673. if pattern='OFF' then
  674. state:='-';
  675. end
  676. else
  677. state:=c;
  678. { c contains the next char, a + or - would be fine }
  679. HandleSwitch(sw,state);
  680. end;
  681. procedure dir_memory(t:tdirectivetoken);
  682. var
  683. l : longint;
  684. begin
  685. current_scanner^.skipspace;
  686. l:=current_scanner^.readval;
  687. if l>1024 then
  688. stacksize:=l;
  689. current_scanner^.skipspace;
  690. if c=',' then
  691. begin
  692. current_scanner^.readchar;
  693. current_scanner^.skipspace;
  694. l:=current_scanner^.readval;
  695. if l>1024 then
  696. heapsize:=l;
  697. end;
  698. end;
  699. procedure dir_setverbose(t:tdirectivetoken);
  700. var
  701. flag,
  702. state : char;
  703. begin
  704. case t of
  705. _DIR_HINTS : flag:='H';
  706. _DIR_WARNINGS : flag:='W';
  707. _DIR_NOTES : flag:='N';
  708. else
  709. exit;
  710. end;
  711. { support ON/OFF }
  712. if c=' ' then
  713. begin
  714. current_scanner^.skipspace;
  715. current_scanner^.readid;
  716. if pattern='ON' then
  717. state:='+'
  718. else
  719. if pattern='OFF' then
  720. state:='-';
  721. end
  722. else
  723. state:=c;
  724. SetVerbosity(flag+state);
  725. end;
  726. type
  727. tdirectiveproc=procedure(t:tdirectivetoken);
  728. const
  729. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  730. {_DIR_NONE} nil,
  731. {_DIR_ALIGN} dir_delphiswitch,
  732. {_DIR_ASMMODE} dir_asmmode,
  733. {_DIR_ASSERTION} dir_delphiswitch,
  734. {_DIR_BOOLEVAL} dir_delphiswitch,
  735. {_DIR_D} dir_description,
  736. {_DIR_DEBUGINFO} dir_delphiswitch,
  737. {_DIR_DEFINE} dir_define,
  738. {_DIR_DESCRIPTION} dir_description,
  739. {_DIR_ELSE} dir_conditional,
  740. {_DIR_ENDIF} dir_conditional,
  741. {_DIR_ERROR} dir_message,
  742. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  743. {_DIR_FATAL} dir_message,
  744. {_DIR_HINT} dir_message,
  745. {_DIR_HINTS} dir_setverbose,
  746. {_DIR_I} dir_include,
  747. {_DIR_I386_ATT} dir_oldasmmode,
  748. {_DIR_I386_DIRECT} dir_oldasmmode,
  749. {_DIR_I386_INTEL} dir_oldasmmode,
  750. {_DIR_IOCHECKS} dir_delphiswitch,
  751. {_DIR_IF} dir_conditional,
  752. {_DIR_IFDEF} dir_conditional,
  753. {_DIR_IFNDEF} dir_conditional,
  754. {_DIR_IFOPT} dir_conditional,
  755. {_DIR_INCLUDE} dir_include,
  756. {_DIR_INFO} dir_message,
  757. {_DIR_L} dir_linkobject,
  758. {_DIR_LINK} dir_linkobject,
  759. {_DIR_LINKLIB} dir_linklib,
  760. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  761. {_DIR_LONGSTRINGS} dir_delphiswitch,
  762. {_DIR_M} dir_memory,
  763. {_DIR_MEMORY} dir_memory,
  764. {_DIR_MESSAGE} dir_message,
  765. {_DIR_MINENUMSIZE} dir_packenum,
  766. {_DIR_MMX} dir_localswitch,
  767. {_DIR_NOTE} dir_message,
  768. {_DIR_NOTES} dir_setverbose,
  769. {_DIR_OPENSTRINGS} dir_delphiswitch,
  770. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  771. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  772. {_DIR_PACKENUM} dir_packenum,
  773. {_DIR_PACKRECORDS} dir_packrecords,
  774. {_DIR_RANGECHECKS} dir_delphiswitch,
  775. {_DIR_REFERENCEINFO} dir_delphiswitch,
  776. {_DIR_SATURATION} dir_localswitch,
  777. {_DIR_SMARTLINK} dir_moduleswitch,
  778. {_DIR_STACKFRAMES} dir_delphiswitch,
  779. {_DIR_STOP} dir_message,
  780. {_DIR_UNDEF} dir_undef,
  781. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  782. {_DIR_TYPEINFO} dir_delphiswitch,
  783. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  784. {_DIR_WAIT} dir_wait,
  785. {_DIR_WARNING} dir_message,
  786. {_DIR_WARNINGS} dir_setverbose,
  787. {_DIR_Z1} dir_packenum,
  788. {_DIR_Z2} dir_packenum,
  789. {_DIR_Z4} dir_packenum
  790. );
  791. {-------------------------------------------
  792. Main switches handling
  793. -------------------------------------------}
  794. procedure handledirectives;
  795. var
  796. t : tdirectivetoken;
  797. p : tdirectiveproc;
  798. hs : string;
  799. begin
  800. current_scanner^.gettokenpos;
  801. current_scanner^.readchar; {Remove the $}
  802. hs:=current_scanner^.readid;
  803. Message1(scan_d_handling_switch,'$'+hs);
  804. if hs='' then
  805. Message1(scan_w_illegal_switch,'$'+hs);
  806. { Check for compiler switches }
  807. while (length(hs)=1) and (c in ['-','+']) do
  808. begin
  809. HandleSwitch(hs[1],c);
  810. current_scanner^.readchar; {Remove + or -}
  811. if c=',' then
  812. begin
  813. current_scanner^.readchar; {Remove , }
  814. { read next switch, support $v+,$+}
  815. hs:=current_scanner^.readid;
  816. if (hs='') then
  817. begin
  818. if (c='$') and not(cs_tp_compatible in aktmoduleswitches) then
  819. begin
  820. current_scanner^.readchar; { skip $ }
  821. hs:=current_scanner^.readid;
  822. end;
  823. if (hs='') then
  824. Message1(scan_w_illegal_directive,'$'+c);
  825. end
  826. else
  827. Message1(scan_d_handling_switch,'$'+hs);
  828. end
  829. else
  830. hs:='';
  831. end;
  832. { directives may follow switches after a , }
  833. if hs<>'' then
  834. begin
  835. t:=Get_Directive(hs);
  836. if t<>_DIR_NONE then
  837. begin
  838. p:=directiveproc[t];
  839. {$ifdef FPC}
  840. if assigned(p) then
  841. {$else}
  842. if @p<>nil then
  843. {$endif}
  844. p(t);
  845. end
  846. else
  847. Message1(scan_w_illegal_directive,'$'+hs);
  848. { conditionals already read the comment }
  849. if (current_scanner^.comment_level>0) then
  850. current_scanner^.readcomment;
  851. end;
  852. end;
  853. {
  854. $Log$
  855. Revision 1.24 1998-09-01 12:52:06 peter
  856. + a lot of delphi switches
  857. Revision 1.23 1998/08/26 15:35:34 peter
  858. * fixed scannerfiles for macros
  859. + $I %<environment>%
  860. Revision 1.22 1998/08/19 14:57:50 peter
  861. * small fix for aktfilepos
  862. Revision 1.20 1998/08/18 15:11:52 peter
  863. * recompiles again
  864. Revision 1.19 1998/08/18 09:24:44 pierre
  865. * small warning position bug fixed
  866. * support_mmx switches splitting was missing
  867. * rhide error and warning output corrected
  868. Revision 1.18 1998/08/10 14:50:25 peter
  869. + localswitches, moduleswitches, globalswitches splitting
  870. Revision 1.17 1998/08/10 09:56:04 peter
  871. * path to the include file is also written to the debug output
  872. Revision 1.16 1998/08/04 22:03:44 michael
  873. + fixed dir_include search() call
  874. Revision 1.15 1998/07/14 21:46:55 peter
  875. * updated messages file
  876. Revision 1.14 1998/07/14 14:47:03 peter
  877. * released NEWINPUT
  878. Revision 1.13 1998/07/07 12:32:54 peter
  879. * status.currentsource is now calculated in verbose (more accurated)
  880. Revision 1.12 1998/07/07 11:20:10 peter
  881. + NEWINPUT for a better inputfile and scanner object
  882. Revision 1.11 1998/06/04 23:51:59 peter
  883. * m68k compiles
  884. + .def file creation moved to gendef.pas so it could also be used
  885. for win32
  886. Revision 1.10 1998/05/30 14:31:10 peter
  887. + $ASMMODE
  888. Revision 1.9 1998/05/23 01:21:28 peter
  889. + aktasmmode, aktoptprocessor, aktoutputformat
  890. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  891. + $LIBNAME to set the library name where the unit will be put in
  892. * splitted cgi386 a bit (codeseg to large for bp7)
  893. * nasm, tasm works again. nasm moved to ag386nsm.pas
  894. Revision 1.8 1998/05/11 13:07:57 peter
  895. + $ifdef NEWPPU for the new ppuformat
  896. + $define GDB not longer required
  897. * removed all warnings and stripped some log comments
  898. * no findfirst/findnext anymore to remove smartlink *.o files
  899. Revision 1.7 1998/05/08 09:21:20 michael
  900. * Added missing -Fl message to messages file.
  901. * Corrected mangling of file names when doing Linklib
  902. * -Fl now actually WORKS.
  903. * Librarysearchpath is now a field in linker object.
  904. Revision 1.6 1998/05/04 17:54:28 peter
  905. + smartlinking works (only case jumptable left todo)
  906. * redesign of systems.pas to support assemblers and linkers
  907. + Unitname is now also in the PPU-file, increased version to 14
  908. Revision 1.5 1998/04/30 15:59:42 pierre
  909. * GDB works again better :
  910. correct type info in one pass
  911. + UseTokenInfo for better source position
  912. * fixed one remaining bug in scanner for line counts
  913. * several little fixes
  914. Revision 1.4 1998/04/29 13:42:27 peter
  915. + $IOCHECKS and $ALIGN to test already, other will follow soon
  916. * fixed the wrong linecounting with comments
  917. Revision 1.3 1998/04/28 11:45:53 florian
  918. * make it compilable with TP
  919. + small COM problems solved to compile classes.pp
  920. Revision 1.2 1998/04/28 10:09:54 pierre
  921. * typo error in asm style reading corrected
  922. Revision 1.1 1998/04/27 23:13:53 peter
  923. + the new files for the scanner
  924. }