scandir.inc 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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 : b:=l1=l2;
  219. UNEQUAL : b:=l1<>l2;
  220. LT : b:=l1<l2;
  221. GT : b:=l1>l2;
  222. GTE : b:=l1>=l2;
  223. LTE : b:=l1<=l2;
  224. end;
  225. end
  226. else
  227. begin
  228. case t of
  229. EQUAL : b:=hs1=hs2;
  230. UNEQUAL : b:=hs1<>hs2;
  231. LT : b:=hs1<hs2;
  232. GT : b:=hs1>hs2;
  233. GTE : b:=hs1>=hs2;
  234. LTE : b:=hs1<=hs2;
  235. end;
  236. end;
  237. if b then
  238. read_expr:='1'
  239. else
  240. read_expr:='0';
  241. end;
  242. {-------------------------------------------
  243. Directives
  244. -------------------------------------------}
  245. function is_conditional(t:tdirectivetoken):boolean;
  246. begin
  247. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  248. end;
  249. procedure dir_conditional(t:tdirectivetoken);
  250. var
  251. hs : string;
  252. mac : pmacrosym;
  253. found : boolean;
  254. state : char;
  255. begin
  256. while true do
  257. begin
  258. case t of
  259. _DIR_ENDIF : begin
  260. current_scanner^.poppreprocstack;
  261. end;
  262. _DIR_ELSE : begin
  263. current_scanner^.elsepreprocstack;
  264. end;
  265. _DIR_IFDEF : begin
  266. current_scanner^.skipspace;
  267. hs:=current_scanner^.readid;
  268. mac:=pmacrosym(macros^.search(hs));
  269. current_scanner^.addpreprocstack(assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  270. end;
  271. _DIR_IFOPT : begin
  272. current_scanner^.skipspace;
  273. hs:=current_scanner^.readid;
  274. if (length(hs)>1) then
  275. Message(scan_w_illegal_switch)
  276. else
  277. begin
  278. state:=current_scanner^.ReadState;
  279. if state in ['-','+'] then
  280. found:=CheckSwitch(hs[1],state);
  281. end;
  282. current_scanner^.addpreprocstack(found,hs,scan_c_ifopt_found);
  283. end;
  284. _DIR_IF : begin
  285. current_scanner^.skipspace;
  286. { start preproc expression scanner }
  287. preproc_token:=current_scanner^.readpreproc;
  288. hs:=read_expr;
  289. current_scanner^.addpreprocstack(hs<>'0',hs,scan_c_if_found);
  290. end;
  291. _DIR_IFNDEF : begin
  292. current_scanner^.skipspace;
  293. hs:=current_scanner^.readid;
  294. mac:=pmacrosym(macros^.search(hs));
  295. current_scanner^.addpreprocstack(not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  296. end;
  297. end;
  298. { accept the text ? }
  299. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  300. break
  301. else
  302. begin
  303. Message(scan_c_skipping_until);
  304. repeat
  305. current_scanner^.skipuntildirective;
  306. t:=Get_Directive(current_scanner^.readid);
  307. until is_conditional(t);
  308. Message1(scan_d_handling_switch,'$'+directive[t]);
  309. end;
  310. end;
  311. end;
  312. procedure dir_define(t:tdirectivetoken);
  313. var
  314. ht : ttoken;
  315. hs2,
  316. hs : string;
  317. mac : pmacrosym;
  318. macropos : longint;
  319. macrobuffer : pmacrobuffer;
  320. begin
  321. current_scanner^.skipspace;
  322. hs:=current_scanner^.readid;
  323. mac:=pmacrosym(macros^.search(hs));
  324. if not assigned(mac) then
  325. begin
  326. mac:=new(pmacrosym,init(hs));
  327. mac^.defined:=true;
  328. Message1(parser_m_macro_defined,mac^.name);
  329. macros^.insert(mac);
  330. end
  331. else
  332. begin
  333. Message1(parser_m_macro_defined,mac^.name);
  334. mac^.defined:=true;
  335. { delete old definition }
  336. if assigned(mac^.buftext) then
  337. begin
  338. freemem(mac^.buftext,mac^.buflen);
  339. mac^.buftext:=nil;
  340. end;
  341. end;
  342. if (cs_support_macro in aktmoduleswitches) then
  343. begin
  344. { key words are never substituted }
  345. hs2:=pattern;
  346. pattern:=hs;
  347. if is_keyword(ht) then
  348. Message(scan_e_keyword_cant_be_a_macro);
  349. pattern:=hs2;
  350. { !!!!!! handle macro params, need we this? }
  351. current_scanner^.skipspace;
  352. { may be a macro? }
  353. if c=':' then
  354. begin
  355. current_scanner^.readchar;
  356. if c='=' then
  357. begin
  358. new(macrobuffer);
  359. macropos:=0;
  360. { first char }
  361. current_scanner^.readchar;
  362. while (c<>'}') do
  363. begin
  364. macrobuffer^[macropos]:=c;
  365. current_scanner^.readchar;
  366. if c=#26 then Message(scan_f_end_of_file);
  367. inc(macropos);
  368. if macropos>maxmacrolen then
  369. Message(scan_f_macro_buffer_overflow);
  370. end;
  371. { free buffer of macro ?}
  372. if assigned(mac^.buftext) then
  373. freemem(mac^.buftext,mac^.buflen);
  374. { get new mem }
  375. getmem(mac^.buftext,macropos);
  376. mac^.buflen:=macropos;
  377. { copy the text }
  378. move(macrobuffer^,mac^.buftext^,macropos);
  379. dispose(macrobuffer);
  380. end;
  381. end;
  382. end;
  383. end;
  384. procedure dir_undef(t:tdirectivetoken);
  385. var
  386. hs : string;
  387. mac : pmacrosym;
  388. begin
  389. current_scanner^.skipspace;
  390. hs:=current_scanner^.readid;
  391. mac:=pmacrosym(macros^.search(hs));
  392. if not assigned(mac) then
  393. begin
  394. mac:=new(pmacrosym,init(hs));
  395. Message1(parser_m_macro_undefined,mac^.name);
  396. mac^.defined:=false;
  397. macros^.insert(mac);
  398. end
  399. else
  400. begin
  401. Message1(parser_m_macro_undefined,mac^.name);
  402. mac^.defined:=false;
  403. { delete old definition }
  404. if assigned(mac^.buftext) then
  405. begin
  406. freemem(mac^.buftext,mac^.buflen);
  407. mac^.buftext:=nil;
  408. end;
  409. end;
  410. end;
  411. procedure dir_message(t:tdirectivetoken);
  412. var
  413. w : tmsgconst;
  414. begin
  415. case t of
  416. _DIR_STOP,
  417. _DIR_FATAL : w:=scan_f_user_defined;
  418. _DIR_ERROR : w:=scan_e_user_defined;
  419. _DIR_WARNING : w:=scan_w_user_defined;
  420. _DIR_HINT : w:=scan_h_user_defined;
  421. _DIR_NOTE : w:=scan_n_user_defined;
  422. _DIR_MESSAGE,
  423. _DIR_INFO : w:=scan_i_user_defined;
  424. end;
  425. current_scanner^.skipspace;
  426. Message1(w,current_scanner^.readcomment);
  427. end;
  428. procedure dir_moduleswitch(t:tdirectivetoken);
  429. var
  430. sw : tmoduleswitch;
  431. state : char;
  432. begin
  433. sw:=cs_modulenone;
  434. case t of
  435. _DIR_SMARTLINK : sw:=cs_smartlink;
  436. end;
  437. state:=current_scanner^.readstate;
  438. if (sw<>cs_modulenone) and (state in ['-','+']) then
  439. begin
  440. if state='-' then
  441. aktmoduleswitches:=aktmoduleswitches-[sw]
  442. else
  443. aktmoduleswitches:=aktmoduleswitches+[sw];
  444. end;
  445. end;
  446. procedure dir_localswitch(t:tdirectivetoken);
  447. var
  448. sw : tlocalswitch;
  449. state : char;
  450. begin
  451. sw:=cs_localnone;
  452. {$ifdef SUPPORT_MMX}
  453. case t of
  454. _DIR_MMX : sw:=cs_mmx;
  455. _DIR_SATURATION : sw:=cs_mmx_saturation;
  456. end;
  457. {$endif}
  458. state:=current_scanner^.readstate;
  459. if (sw<>cs_localnone) and (state in ['-','+']) then
  460. begin
  461. if state='-' then
  462. aktlocalswitches:=aktlocalswitches-[sw]
  463. else
  464. aktlocalswitches:=aktlocalswitches+[sw];
  465. end;
  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^.tempcloseinputfile;
  521. { load new file }
  522. hp:=new(pinputfile,init(path+name+ext));
  523. current_scanner^.addfile(hp);
  524. if not current_scanner^.openinputfile 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. end;
  531. end;
  532. procedure dir_description(t:tdirectivetoken);
  533. begin
  534. end;
  535. procedure dir_linkobject(t:tdirectivetoken);
  536. begin
  537. current_scanner^.skipspace;
  538. current_scanner^.readstring;
  539. current_module^.linkofiles.insert(FixFileName(orgpattern));
  540. end;
  541. procedure dir_linklib(t:tdirectivetoken);
  542. begin
  543. current_scanner^.skipspace;
  544. current_scanner^.readstring;
  545. current_module^.linkSharedLibs.insert(orgpattern);
  546. end;
  547. procedure dir_outputformat(t:tdirectivetoken);
  548. begin
  549. if not current_module^.in_global then
  550. Message(scan_w_switch_is_global)
  551. else
  552. begin
  553. current_scanner^.skipspace;
  554. if set_string_asm(current_scanner^.readid) then
  555. aktoutputformat:=target_asm.id
  556. else
  557. Message(scan_w_illegal_switch);
  558. end;
  559. end;
  560. procedure dir_packrecords(t:tdirectivetoken);
  561. var
  562. hs : string;
  563. begin
  564. current_scanner^.skipspace;
  565. if not(c in ['0'..'9']) then
  566. begin
  567. hs:=current_scanner^.readid;
  568. if (hs='NORMAL') or (hs='DEFAULT') then
  569. aktpackrecords:=2
  570. else
  571. Message(scan_w_only_pack_records);
  572. end
  573. else
  574. begin
  575. case current_scanner^.readval of
  576. 1 : aktpackrecords:=1;
  577. 2 : aktpackrecords:=2;
  578. 4 : aktpackrecords:=4;
  579. 16 : aktpackrecords:=16;
  580. else
  581. Message(scan_w_only_pack_records);
  582. end;
  583. end;
  584. end;
  585. procedure dir_packenum(t:tdirectivetoken);
  586. var
  587. hs : string;
  588. begin
  589. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  590. begin
  591. aktpackenum:=ord(pattern[2])-ord('0');
  592. exit;
  593. end;
  594. current_scanner^.skipspace;
  595. if not(c in ['0'..'9']) then
  596. begin
  597. hs:=current_scanner^.readid;
  598. if (hs='NORMAL') or (hs='DEFAULT') then
  599. aktpackenum:=4
  600. else
  601. Message(scan_w_only_pack_enum);
  602. end
  603. else
  604. begin
  605. case current_scanner^.readval of
  606. 1 : aktpackenum:=1;
  607. 2 : aktpackenum:=2;
  608. 4 : aktpackenum:=4;
  609. else
  610. Message(scan_w_only_pack_enum);
  611. end;
  612. end;
  613. end;
  614. procedure dir_wait(t:tdirectivetoken);
  615. begin
  616. Message(scan_i_press_enter);
  617. readln;
  618. end;
  619. procedure dir_asmmode(t:tdirectivetoken);
  620. var
  621. s : string;
  622. begin
  623. current_scanner^.skipspace;
  624. s:=current_scanner^.readid;
  625. if s='DEFAULT' then
  626. aktasmmode:=initasmmode
  627. else
  628. if not set_string_asmmode(s,aktasmmode) then
  629. Message1(scan_w_unsupported_asmmode_specifier,s);
  630. end;
  631. procedure dir_oldasmmode(t:tdirectivetoken);
  632. begin
  633. {$ifdef i386}
  634. case t of
  635. _DIR_I386_ATT : aktasmmode:=I386_ATT;
  636. _DIR_I386_DIRECT : aktasmmode:=I386_DIRECT;
  637. _DIR_I386_INTEL : aktasmmode:=I386_INTEL;
  638. end;
  639. {$endif}
  640. end;
  641. procedure dir_delphiswitch(t:tdirectivetoken);
  642. var
  643. sw,state : char;
  644. begin
  645. case t of
  646. _DIR_ALIGN : sw:='A';
  647. _DIR_ASSERTIONS : sw:='C';
  648. _DIR_BOOLEVAL : sw:='B';
  649. _DIR_DEBUGINFO : sw:='D';
  650. _DIR_IOCHECKS : sw:='I';
  651. _DIR_LOCALSYMBOLS : sw:='L';
  652. _DIR_LONGSTRINGS : sw:='H';
  653. _DIR_OPENSTRINGS : sw:='P';
  654. _DIR_OVERFLOWCHECKS : sw:='Q';
  655. _DIR_RANGECHECKS : sw:='R';
  656. _DIR_REFERENCEINFO : sw:='Y';
  657. _DIR_STACKFRAMES : sw:='W';
  658. _DIR_TYPEDADDRESS : sw:='T';
  659. _DIR_TYPEINFO : sw:='M';
  660. _DIR_VARSTRINGCHECKS : sw:='V';
  661. else
  662. exit;
  663. end;
  664. { c contains the next char, a + or - would be fine }
  665. state:=current_scanner^.readstate;
  666. if state in ['-','+'] then
  667. HandleSwitch(sw,state);
  668. end;
  669. procedure dir_memory(t:tdirectivetoken);
  670. var
  671. l : longint;
  672. begin
  673. current_scanner^.skipspace;
  674. l:=current_scanner^.readval;
  675. if l>1024 then
  676. stacksize:=l;
  677. current_scanner^.skipspace;
  678. if c=',' then
  679. begin
  680. current_scanner^.readchar;
  681. current_scanner^.skipspace;
  682. l:=current_scanner^.readval;
  683. if l>1024 then
  684. heapsize:=l;
  685. end;
  686. if c=',' then
  687. begin
  688. current_scanner^.readchar;
  689. current_scanner^.skipspace;
  690. l:=current_scanner^.readval;
  691. if l>1024 then
  692. maxheapsize:=l;
  693. end;
  694. if heapsize>maxheapsize then
  695. message(scan_w_illegal_switch);
  696. end;
  697. procedure dir_setverbose(t:tdirectivetoken);
  698. var
  699. flag,
  700. state : char;
  701. begin
  702. case t of
  703. _DIR_HINTS : flag:='H';
  704. _DIR_WARNINGS : flag:='W';
  705. _DIR_NOTES : flag:='N';
  706. else
  707. exit;
  708. end;
  709. { support ON/OFF }
  710. state:=current_scanner^.ReadState;
  711. SetVerbosity(flag+state);
  712. end;
  713. type
  714. tdirectiveproc=procedure(t:tdirectivetoken);
  715. const
  716. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  717. {_DIR_NONE} nil,
  718. {_DIR_ALIGN} dir_delphiswitch,
  719. {_DIR_ASMMODE} dir_asmmode,
  720. {_DIR_ASSERTION} dir_delphiswitch,
  721. {_DIR_BOOLEVAL} dir_delphiswitch,
  722. {_DIR_D} dir_description,
  723. {_DIR_DEBUGINFO} dir_delphiswitch,
  724. {_DIR_DEFINE} dir_define,
  725. {_DIR_DESCRIPTION} dir_description,
  726. {_DIR_ELSE} dir_conditional,
  727. {_DIR_ENDIF} dir_conditional,
  728. {_DIR_ERROR} dir_message,
  729. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  730. {_DIR_FATAL} dir_message,
  731. {_DIR_HINT} dir_message,
  732. {_DIR_HINTS} dir_setverbose,
  733. {_DIR_I} dir_include,
  734. {_DIR_I386_ATT} dir_oldasmmode,
  735. {_DIR_I386_DIRECT} dir_oldasmmode,
  736. {_DIR_I386_INTEL} dir_oldasmmode,
  737. {_DIR_IOCHECKS} dir_delphiswitch,
  738. {_DIR_IF} dir_conditional,
  739. {_DIR_IFDEF} dir_conditional,
  740. {_DIR_IFNDEF} dir_conditional,
  741. {_DIR_IFOPT} dir_conditional,
  742. {_DIR_INCLUDE} dir_include,
  743. {_DIR_INFO} dir_message,
  744. {_DIR_L} dir_linkobject,
  745. {_DIR_LINK} dir_linkobject,
  746. {_DIR_LINKLIB} dir_linklib,
  747. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  748. {_DIR_LONGSTRINGS} dir_delphiswitch,
  749. {_DIR_M} dir_memory,
  750. {_DIR_MEMORY} dir_memory,
  751. {_DIR_MESSAGE} dir_message,
  752. {_DIR_MINENUMSIZE} dir_packenum,
  753. {_DIR_MMX} dir_localswitch,
  754. {_DIR_NOTE} dir_message,
  755. {_DIR_NOTES} dir_setverbose,
  756. {_DIR_OPENSTRINGS} dir_delphiswitch,
  757. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  758. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  759. {_DIR_PACKENUM} dir_packenum,
  760. {_DIR_PACKRECORDS} dir_packrecords,
  761. {_DIR_RANGECHECKS} dir_delphiswitch,
  762. {_DIR_REFERENCEINFO} dir_delphiswitch,
  763. {_DIR_SATURATION} dir_localswitch,
  764. {_DIR_SMARTLINK} dir_moduleswitch,
  765. {_DIR_STACKFRAMES} dir_delphiswitch,
  766. {_DIR_STOP} dir_message,
  767. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  768. {_DIR_TYPEINFO} dir_delphiswitch,
  769. {_DIR_UNDEF} dir_undef,
  770. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  771. {_DIR_WAIT} dir_wait,
  772. {_DIR_WARNING} dir_message,
  773. {_DIR_WARNINGS} dir_setverbose,
  774. {_DIR_Z1} dir_packenum,
  775. {_DIR_Z2} dir_packenum,
  776. {_DIR_Z4} dir_packenum
  777. );
  778. {-------------------------------------------
  779. Main switches handling
  780. -------------------------------------------}
  781. procedure handledirectives;
  782. var
  783. t : tdirectivetoken;
  784. p : tdirectiveproc;
  785. hs : string;
  786. begin
  787. current_scanner^.gettokenpos;
  788. current_scanner^.readchar; {Remove the $}
  789. hs:=current_scanner^.readid;
  790. Message1(scan_d_handling_switch,'$'+hs);
  791. if hs='' then
  792. Message1(scan_w_illegal_switch,'$'+hs);
  793. { Check for compiler switches }
  794. while (length(hs)=1) and (c in ['-','+']) do
  795. begin
  796. HandleSwitch(hs[1],c);
  797. current_scanner^.readchar; {Remove + or -}
  798. if c=',' then
  799. begin
  800. current_scanner^.readchar; {Remove , }
  801. { read next switch, support $v+,$+}
  802. hs:=current_scanner^.readid;
  803. if (hs='') then
  804. begin
  805. if (c='$') and not(cs_tp_compatible in aktmoduleswitches) then
  806. begin
  807. current_scanner^.readchar; { skip $ }
  808. hs:=current_scanner^.readid;
  809. end;
  810. if (hs='') then
  811. Message1(scan_w_illegal_directive,'$'+c);
  812. end
  813. else
  814. Message1(scan_d_handling_switch,'$'+hs);
  815. end
  816. else
  817. hs:='';
  818. end;
  819. { directives may follow switches after a , }
  820. if hs<>'' then
  821. begin
  822. t:=Get_Directive(hs);
  823. if t<>_DIR_NONE then
  824. begin
  825. p:=directiveproc[t];
  826. {$ifdef FPC}
  827. if assigned(p) then
  828. {$else}
  829. if @p<>nil then
  830. {$endif}
  831. p(t);
  832. end
  833. else
  834. Message1(scan_w_illegal_directive,'$'+hs);
  835. { conditionals already read the comment }
  836. if (current_scanner^.comment_level>0) then
  837. current_scanner^.readcomment;
  838. end;
  839. end;
  840. {
  841. $Log$
  842. Revision 1.30 1998-09-16 16:41:47 peter
  843. * merged fixes
  844. Revision 1.28.2.1 1998/09/16 16:09:51 peter
  845. * on/off support also for the local/module switches
  846. Revision 1.29 1998/09/11 09:19:53 daniel
  847. * Removed tabs.
  848. Revision 1.28 1998/09/10 15:25:36 daniel
  849. + Added maxheapsize.
  850. * Corrected semi-bug in calling the assembler and the linker
  851. Revision 1.27 1998/09/09 15:33:59 peter
  852. * removed warnings
  853. Revision 1.26 1998/09/03 11:24:02 peter
  854. * moved more inputfile things from tscannerfile to tinputfile
  855. * changed ifdef Sourceline to cs_asm_source
  856. Revision 1.25 1998/09/02 15:13:31 peter
  857. * fixed typo in directive table
  858. Revision 1.24 1998/09/01 12:52:06 peter
  859. + a lot of delphi switches
  860. Revision 1.23 1998/08/26 15:35:34 peter
  861. * fixed scannerfiles for macros
  862. + $I %<environment>%
  863. Revision 1.22 1998/08/19 14:57:50 peter
  864. * small fix for aktfilepos
  865. Revision 1.20 1998/08/18 15:11:52 peter
  866. * recompiles again
  867. Revision 1.19 1998/08/18 09:24:44 pierre
  868. * small warning position bug fixed
  869. * support_mmx switches splitting was missing
  870. * rhide error and warning output corrected
  871. Revision 1.18 1998/08/10 14:50:25 peter
  872. + localswitches, moduleswitches, globalswitches splitting
  873. Revision 1.17 1998/08/10 09:56:04 peter
  874. * path to the include file is also written to the debug output
  875. Revision 1.16 1998/08/04 22:03:44 michael
  876. + fixed dir_include search() call
  877. Revision 1.15 1998/07/14 21:46:55 peter
  878. * updated messages file
  879. Revision 1.14 1998/07/14 14:47:03 peter
  880. * released NEWINPUT
  881. Revision 1.13 1998/07/07 12:32:54 peter
  882. * status.currentsource is now calculated in verbose (more accurated)
  883. Revision 1.12 1998/07/07 11:20:10 peter
  884. + NEWINPUT for a better inputfile and scanner object
  885. Revision 1.11 1998/06/04 23:51:59 peter
  886. * m68k compiles
  887. + .def file creation moved to gendef.pas so it could also be used
  888. for win32
  889. Revision 1.10 1998/05/30 14:31:10 peter
  890. + $ASMMODE
  891. Revision 1.9 1998/05/23 01:21:28 peter
  892. + aktasmmode, aktoptprocessor, aktoutputformat
  893. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  894. + $LIBNAME to set the library name where the unit will be put in
  895. * splitted cgi386 a bit (codeseg to large for bp7)
  896. * nasm, tasm works again. nasm moved to ag386nsm.pas
  897. Revision 1.8 1998/05/11 13:07:57 peter
  898. + $ifdef NEWPPU for the new ppuformat
  899. + $define GDB not longer required
  900. * removed all warnings and stripped some log comments
  901. * no findfirst/findnext anymore to remove smartlink *.o files
  902. Revision 1.7 1998/05/08 09:21:20 michael
  903. * Added missing -Fl message to messages file.
  904. * Corrected mangling of file names when doing Linklib
  905. * -Fl now actually WORKS.
  906. * Librarysearchpath is now a field in linker object.
  907. Revision 1.6 1998/05/04 17:54:28 peter
  908. + smartlinking works (only case jumptable left todo)
  909. * redesign of systems.pas to support assemblers and linkers
  910. + Unitname is now also in the PPU-file, increased version to 14
  911. Revision 1.5 1998/04/30 15:59:42 pierre
  912. * GDB works again better :
  913. correct type info in one pass
  914. + UseTokenInfo for better source position
  915. * fixed one remaining bug in scanner for line counts
  916. * several little fixes
  917. Revision 1.4 1998/04/29 13:42:27 peter
  918. + $IOCHECKS and $ALIGN to test already, other will follow soon
  919. * fixed the wrong linecounting with comments
  920. Revision 1.3 1998/04/28 11:45:53 florian
  921. * make it compilable with TP
  922. + small COM problems solved to compile classes.pp
  923. Revision 1.2 1998/04/28 10:09:54 pierre
  924. * typo error in asm style reading corrected
  925. Revision 1.1 1998/04/27 23:13:53 peter
  926. + the new files for the scanner
  927. }