scandir.inc 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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,_DIR_MODE,
  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','MODE',
  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 : integer;
  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. hs : string;
  315. mac : pmacrosym;
  316. macropos : longint;
  317. macrobuffer : pmacrobuffer;
  318. begin
  319. current_scanner^.skipspace;
  320. hs:=current_scanner^.readid;
  321. mac:=pmacrosym(macros^.search(hs));
  322. if not assigned(mac) then
  323. begin
  324. mac:=new(pmacrosym,init(hs));
  325. mac^.defined:=true;
  326. Message1(parser_m_macro_defined,mac^.name);
  327. macros^.insert(mac);
  328. end
  329. else
  330. begin
  331. Message1(parser_m_macro_defined,mac^.name);
  332. mac^.defined:=true;
  333. { delete old definition }
  334. if assigned(mac^.buftext) then
  335. begin
  336. freemem(mac^.buftext,mac^.buflen);
  337. mac^.buftext:=nil;
  338. end;
  339. end;
  340. if (cs_support_macro in aktmoduleswitches) then
  341. begin
  342. { key words are never substituted }
  343. if is_keyword(hs) then
  344. Message(scan_e_keyword_cant_be_a_macro);
  345. { !!!!!! handle macro params, need we this? }
  346. current_scanner^.skipspace;
  347. { may be a macro? }
  348. if c=':' then
  349. begin
  350. current_scanner^.readchar;
  351. if c='=' then
  352. begin
  353. new(macrobuffer);
  354. macropos:=0;
  355. { first char }
  356. current_scanner^.readchar;
  357. while (c<>'}') do
  358. begin
  359. macrobuffer^[macropos]:=c;
  360. current_scanner^.readchar;
  361. if c=#26 then Message(scan_f_end_of_file);
  362. inc(macropos);
  363. if macropos>maxmacrolen then
  364. Message(scan_f_macro_buffer_overflow);
  365. end;
  366. { free buffer of macro ?}
  367. if assigned(mac^.buftext) then
  368. freemem(mac^.buftext,mac^.buflen);
  369. { get new mem }
  370. getmem(mac^.buftext,macropos);
  371. mac^.buflen:=macropos;
  372. { copy the text }
  373. move(macrobuffer^,mac^.buftext^,macropos);
  374. dispose(macrobuffer);
  375. end;
  376. end;
  377. end;
  378. end;
  379. procedure dir_undef(t:tdirectivetoken);
  380. var
  381. hs : string;
  382. mac : pmacrosym;
  383. begin
  384. current_scanner^.skipspace;
  385. hs:=current_scanner^.readid;
  386. mac:=pmacrosym(macros^.search(hs));
  387. if not assigned(mac) then
  388. begin
  389. mac:=new(pmacrosym,init(hs));
  390. Message1(parser_m_macro_undefined,mac^.name);
  391. mac^.defined:=false;
  392. macros^.insert(mac);
  393. end
  394. else
  395. begin
  396. Message1(parser_m_macro_undefined,mac^.name);
  397. mac^.defined:=false;
  398. { delete old definition }
  399. if assigned(mac^.buftext) then
  400. begin
  401. freemem(mac^.buftext,mac^.buflen);
  402. mac^.buftext:=nil;
  403. end;
  404. end;
  405. end;
  406. procedure dir_message(t:tdirectivetoken);
  407. var
  408. w : tmsgconst;
  409. begin
  410. case t of
  411. _DIR_STOP,
  412. _DIR_FATAL : w:=scan_f_user_defined;
  413. _DIR_ERROR : w:=scan_e_user_defined;
  414. _DIR_WARNING : w:=scan_w_user_defined;
  415. _DIR_HINT : w:=scan_h_user_defined;
  416. _DIR_NOTE : w:=scan_n_user_defined;
  417. _DIR_MESSAGE,
  418. _DIR_INFO : w:=scan_i_user_defined;
  419. end;
  420. current_scanner^.skipspace;
  421. Message1(w,current_scanner^.readcomment);
  422. end;
  423. procedure dir_moduleswitch(t:tdirectivetoken);
  424. var
  425. sw : tmoduleswitch;
  426. state : char;
  427. begin
  428. sw:=cs_modulenone;
  429. case t of
  430. _DIR_SMARTLINK : sw:=cs_smartlink;
  431. end;
  432. state:=current_scanner^.readstate;
  433. if (sw<>cs_modulenone) and (state in ['-','+']) then
  434. begin
  435. if state='-' then
  436. aktmoduleswitches:=aktmoduleswitches-[sw]
  437. else
  438. aktmoduleswitches:=aktmoduleswitches+[sw];
  439. end;
  440. end;
  441. procedure dir_localswitch(t:tdirectivetoken);
  442. var
  443. sw : tlocalswitch;
  444. state : char;
  445. begin
  446. sw:=cs_localnone;
  447. {$ifdef SUPPORT_MMX}
  448. case t of
  449. _DIR_MMX : sw:=cs_mmx;
  450. _DIR_SATURATION : sw:=cs_mmx_saturation;
  451. end;
  452. {$endif}
  453. state:=current_scanner^.readstate;
  454. if (sw<>cs_localnone) and (state in ['-','+']) then
  455. begin
  456. if state='-' then
  457. aktlocalswitches:=aktlocalswitches-[sw]
  458. else
  459. aktlocalswitches:=aktlocalswitches+[sw];
  460. end;
  461. end;
  462. procedure dir_include(t:tdirectivetoken);
  463. var
  464. hs : string;
  465. path : dirstr;
  466. name : namestr;
  467. ext : extstr;
  468. hp : pinputfile;
  469. found : boolean;
  470. begin
  471. current_scanner^.skipspace;
  472. hs:=current_scanner^.readcomment;
  473. while (hs<>'') and (hs[length(hs)]=' ') do
  474. dec(byte(hs[0]));
  475. if hs='' then
  476. exit;
  477. if (hs[1]='%') then
  478. begin
  479. { save old }
  480. path:=hs;
  481. { remove %'s }
  482. Delete(hs,1,1);
  483. if hs[length(hs)]='%' then
  484. Delete(hs,length(hs),1);
  485. { first check for internal macros }
  486. if hs='TIME' then
  487. hs:=gettimestr
  488. else
  489. if hs='DATE' then
  490. hs:=getdatestr
  491. else
  492. if hs='FPCVERSION' then
  493. hs:=version_string
  494. else
  495. if hs='FPCTARGET' then
  496. hs:=target_string
  497. else
  498. hs:=getenv(hs);
  499. if hs='' then
  500. Comment(V_Warning,'Include environment '+path+' not found in environment')
  501. else
  502. begin
  503. { make it a stringconst }
  504. hs:=''''+hs+'''';
  505. current_scanner^.insertmacro(@hs[1],length(hs));
  506. end;
  507. end
  508. else
  509. begin
  510. hs:=FixFileName(hs);
  511. fsplit(hs,path,name,ext);
  512. { first look in the path of _d then currentmodule }
  513. path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found);
  514. { shutdown current file }
  515. current_scanner^.tempcloseinputfile;
  516. { load new file }
  517. hp:=new(pinputfile,init(path+name+ext));
  518. current_scanner^.addfile(hp);
  519. if not current_scanner^.openinputfile then
  520. Message1(scan_f_cannot_open_includefile,hs);
  521. Message1(scan_u_start_include_file,current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^);
  522. current_scanner^.reload;
  523. { register for refs }
  524. current_module^.sourcefiles^.register_file(hp);
  525. end;
  526. end;
  527. procedure dir_description(t:tdirectivetoken);
  528. begin
  529. end;
  530. procedure dir_linkobject(t:tdirectivetoken);
  531. begin
  532. current_scanner^.skipspace;
  533. current_scanner^.readstring;
  534. current_module^.linkofiles.insert(FixFileName(orgpattern));
  535. end;
  536. procedure dir_linklib(t:tdirectivetoken);
  537. begin
  538. current_scanner^.skipspace;
  539. current_scanner^.readstring;
  540. current_module^.linkSharedLibs.insert(orgpattern);
  541. end;
  542. procedure dir_outputformat(t:tdirectivetoken);
  543. begin
  544. if not current_module^.in_global then
  545. Message(scan_w_switch_is_global)
  546. else
  547. begin
  548. current_scanner^.skipspace;
  549. if set_string_asm(current_scanner^.readid) then
  550. aktoutputformat:=target_asm.id
  551. else
  552. Message(scan_w_illegal_switch);
  553. end;
  554. end;
  555. procedure dir_mode(t:tdirectivetoken);
  556. begin
  557. if not current_module^.in_global then
  558. Message(scan_w_switch_is_global)
  559. else
  560. begin
  561. current_scanner^.skipspace;
  562. current_scanner^.readstring;
  563. if pattern='DEFAULT' then
  564. aktmodeswitches:=initmodeswitches
  565. else
  566. if pattern='DELPHI' then
  567. aktmodeswitches:=delphimodeswitches
  568. else
  569. if pattern='TP' then
  570. aktmodeswitches:=tpmodeswitches
  571. else
  572. if pattern='FPC' then
  573. aktmodeswitches:=fpcmodeswitches
  574. else
  575. if pattern='OBJFPC' then
  576. aktmodeswitches:=objfpcmodeswitches
  577. else
  578. if pattern='GPC' then
  579. aktmodeswitches:=gpcmodeswitches;
  580. end;
  581. end;
  582. procedure dir_packrecords(t:tdirectivetoken);
  583. var
  584. hs : string;
  585. begin
  586. current_scanner^.skipspace;
  587. if not(c in ['0'..'9']) then
  588. begin
  589. hs:=current_scanner^.readid;
  590. if (hs='NORMAL') or (hs='DEFAULT') then
  591. aktpackrecords:=2
  592. else
  593. Message(scan_w_only_pack_records);
  594. end
  595. else
  596. begin
  597. case current_scanner^.readval of
  598. 1 : aktpackrecords:=1;
  599. 2 : aktpackrecords:=2;
  600. 4 : aktpackrecords:=4;
  601. 8 : aktpackrecords:=8;
  602. 16 : aktpackrecords:=16;
  603. 32 : aktpackrecords:=32;
  604. else
  605. Message(scan_w_only_pack_records);
  606. end;
  607. end;
  608. end;
  609. procedure dir_packenum(t:tdirectivetoken);
  610. var
  611. hs : string;
  612. begin
  613. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  614. begin
  615. aktpackenum:=ord(pattern[2])-ord('0');
  616. exit;
  617. end;
  618. current_scanner^.skipspace;
  619. if not(c in ['0'..'9']) then
  620. begin
  621. hs:=current_scanner^.readid;
  622. if (hs='NORMAL') or (hs='DEFAULT') then
  623. aktpackenum:=4
  624. else
  625. Message(scan_w_only_pack_enum);
  626. end
  627. else
  628. begin
  629. case current_scanner^.readval of
  630. 1 : aktpackenum:=1;
  631. 2 : aktpackenum:=2;
  632. 4 : aktpackenum:=4;
  633. else
  634. Message(scan_w_only_pack_enum);
  635. end;
  636. end;
  637. end;
  638. procedure dir_wait(t:tdirectivetoken);
  639. begin
  640. Message(scan_i_press_enter);
  641. readln;
  642. end;
  643. procedure dir_asmmode(t:tdirectivetoken);
  644. var
  645. s : string;
  646. begin
  647. current_scanner^.skipspace;
  648. s:=current_scanner^.readid;
  649. if s='DEFAULT' then
  650. aktasmmode:=initasmmode
  651. else
  652. if not set_string_asmmode(s,aktasmmode) then
  653. Message1(scan_w_unsupported_asmmode_specifier,s);
  654. end;
  655. procedure dir_oldasmmode(t:tdirectivetoken);
  656. begin
  657. {$ifdef i386}
  658. case t of
  659. _DIR_I386_ATT : aktasmmode:=I386_ATT;
  660. _DIR_I386_DIRECT : aktasmmode:=I386_DIRECT;
  661. _DIR_I386_INTEL : aktasmmode:=I386_INTEL;
  662. end;
  663. {$endif}
  664. end;
  665. procedure dir_delphiswitch(t:tdirectivetoken);
  666. var
  667. sw,state : char;
  668. begin
  669. case t of
  670. _DIR_ALIGN : sw:='A';
  671. _DIR_ASSERTIONS : sw:='C';
  672. _DIR_BOOLEVAL : sw:='B';
  673. _DIR_DEBUGINFO : sw:='D';
  674. _DIR_IOCHECKS : sw:='I';
  675. _DIR_LOCALSYMBOLS : sw:='L';
  676. _DIR_LONGSTRINGS : sw:='H';
  677. _DIR_OPENSTRINGS : sw:='P';
  678. _DIR_OVERFLOWCHECKS : sw:='Q';
  679. _DIR_RANGECHECKS : sw:='R';
  680. _DIR_REFERENCEINFO : sw:='Y';
  681. _DIR_STACKFRAMES : sw:='W';
  682. _DIR_TYPEDADDRESS : sw:='T';
  683. _DIR_TYPEINFO : sw:='M';
  684. _DIR_VARSTRINGCHECKS : sw:='V';
  685. else
  686. exit;
  687. end;
  688. { c contains the next char, a + or - would be fine }
  689. state:=current_scanner^.readstate;
  690. if state in ['-','+'] then
  691. HandleSwitch(sw,state);
  692. end;
  693. procedure dir_memory(t:tdirectivetoken);
  694. var
  695. l : longint;
  696. begin
  697. current_scanner^.skipspace;
  698. l:=current_scanner^.readval;
  699. if l>1024 then
  700. stacksize:=l;
  701. current_scanner^.skipspace;
  702. if c=',' then
  703. begin
  704. current_scanner^.readchar;
  705. current_scanner^.skipspace;
  706. l:=current_scanner^.readval;
  707. if l>1024 then
  708. heapsize:=l;
  709. end;
  710. if c=',' then
  711. begin
  712. current_scanner^.readchar;
  713. current_scanner^.skipspace;
  714. l:=current_scanner^.readval;
  715. if l>1024 then
  716. maxheapsize:=l;
  717. end;
  718. if heapsize>maxheapsize then
  719. message(scan_w_illegal_switch);
  720. end;
  721. procedure dir_setverbose(t:tdirectivetoken);
  722. var
  723. flag,
  724. state : char;
  725. begin
  726. case t of
  727. _DIR_HINTS : flag:='H';
  728. _DIR_WARNINGS : flag:='W';
  729. _DIR_NOTES : flag:='N';
  730. else
  731. exit;
  732. end;
  733. { support ON/OFF }
  734. state:=current_scanner^.ReadState;
  735. SetVerbosity(flag+state);
  736. end;
  737. type
  738. tdirectiveproc=procedure(t:tdirectivetoken);
  739. const
  740. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  741. {_DIR_NONE} nil,
  742. {_DIR_ALIGN} dir_delphiswitch,
  743. {_DIR_ASMMODE} dir_asmmode,
  744. {_DIR_ASSERTION} dir_delphiswitch,
  745. {_DIR_BOOLEVAL} dir_delphiswitch,
  746. {_DIR_D} dir_description,
  747. {_DIR_DEBUGINFO} dir_delphiswitch,
  748. {_DIR_DEFINE} dir_define,
  749. {_DIR_DESCRIPTION} dir_description,
  750. {_DIR_ELSE} dir_conditional,
  751. {_DIR_ENDIF} dir_conditional,
  752. {_DIR_ERROR} dir_message,
  753. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  754. {_DIR_FATAL} dir_message,
  755. {_DIR_HINT} dir_message,
  756. {_DIR_HINTS} dir_setverbose,
  757. {_DIR_I} dir_include,
  758. {_DIR_I386_ATT} dir_oldasmmode,
  759. {_DIR_I386_DIRECT} dir_oldasmmode,
  760. {_DIR_I386_INTEL} dir_oldasmmode,
  761. {_DIR_IOCHECKS} dir_delphiswitch,
  762. {_DIR_IF} dir_conditional,
  763. {_DIR_IFDEF} dir_conditional,
  764. {_DIR_IFNDEF} dir_conditional,
  765. {_DIR_IFOPT} dir_conditional,
  766. {_DIR_INCLUDE} dir_include,
  767. {_DIR_INFO} dir_message,
  768. {_DIR_L} dir_linkobject,
  769. {_DIR_LINK} dir_linkobject,
  770. {_DIR_LINKLIB} dir_linklib,
  771. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  772. {_DIR_LONGSTRINGS} dir_delphiswitch,
  773. {_DIR_M} dir_memory,
  774. {_DIR_MEMORY} dir_memory,
  775. {_DIR_MESSAGE} dir_message,
  776. {_DIR_MINENUMSIZE} dir_packenum,
  777. {_DIR_MMX} dir_localswitch,
  778. {_DIR_MODE} dir_mode,
  779. {_DIR_NOTE} dir_message,
  780. {_DIR_NOTES} dir_setverbose,
  781. {_DIR_OPENSTRINGS} dir_delphiswitch,
  782. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  783. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  784. {_DIR_PACKENUM} dir_packenum,
  785. {_DIR_PACKRECORDS} dir_packrecords,
  786. {_DIR_RANGECHECKS} dir_delphiswitch,
  787. {_DIR_REFERENCEINFO} dir_delphiswitch,
  788. {_DIR_SATURATION} dir_localswitch,
  789. {_DIR_SMARTLINK} dir_moduleswitch,
  790. {_DIR_STACKFRAMES} dir_delphiswitch,
  791. {_DIR_STOP} dir_message,
  792. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  793. {_DIR_TYPEINFO} dir_delphiswitch,
  794. {_DIR_UNDEF} dir_undef,
  795. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  796. {_DIR_WAIT} dir_wait,
  797. {_DIR_WARNING} dir_message,
  798. {_DIR_WARNINGS} dir_setverbose,
  799. {_DIR_Z1} dir_packenum,
  800. {_DIR_Z2} dir_packenum,
  801. {_DIR_Z4} dir_packenum
  802. );
  803. {-------------------------------------------
  804. Main switches handling
  805. -------------------------------------------}
  806. procedure handledirectives;
  807. var
  808. t : tdirectivetoken;
  809. p : tdirectiveproc;
  810. hs : string;
  811. begin
  812. current_scanner^.gettokenpos;
  813. current_scanner^.readchar; {Remove the $}
  814. hs:=current_scanner^.readid;
  815. Message1(scan_d_handling_switch,'$'+hs);
  816. if hs='' then
  817. Message1(scan_w_illegal_switch,'$'+hs);
  818. { Check for compiler switches }
  819. while (length(hs)=1) and (c in ['-','+']) do
  820. begin
  821. HandleSwitch(hs[1],c);
  822. current_scanner^.readchar; {Remove + or -}
  823. if c=',' then
  824. begin
  825. current_scanner^.readchar; {Remove , }
  826. { read next switch, support $v+,$+}
  827. hs:=current_scanner^.readid;
  828. if (hs='') then
  829. begin
  830. if (c='$') and (m_fpc in aktmodeswitches) then
  831. begin
  832. current_scanner^.readchar; { skip $ }
  833. hs:=current_scanner^.readid;
  834. end;
  835. if (hs='') then
  836. Message1(scan_w_illegal_directive,'$'+c);
  837. end
  838. else
  839. Message1(scan_d_handling_switch,'$'+hs);
  840. end
  841. else
  842. hs:='';
  843. end;
  844. { directives may follow switches after a , }
  845. if hs<>'' then
  846. begin
  847. t:=Get_Directive(hs);
  848. if t<>_DIR_NONE then
  849. begin
  850. p:=directiveproc[t];
  851. {$ifdef FPC}
  852. if assigned(p) then
  853. {$else}
  854. if @p<>nil then
  855. {$endif}
  856. p(t);
  857. end
  858. else
  859. Message1(scan_w_illegal_directive,'$'+hs);
  860. { conditionals already read the comment }
  861. if (current_scanner^.comment_level>0) then
  862. current_scanner^.readcomment;
  863. end;
  864. end;
  865. {
  866. $Log$
  867. Revision 1.34 1998-09-28 16:57:24 pierre
  868. * changed all length(p^.value_str^) into str_length(p)
  869. to get it work with and without ansistrings
  870. * changed sourcefiles field of tmodule to a pointer
  871. Revision 1.33 1998/09/26 17:45:40 peter
  872. + idtoken and only one token table
  873. Revision 1.32 1998/09/24 23:49:19 peter
  874. + aktmodeswitches
  875. Revision 1.31 1998/09/18 16:03:44 florian
  876. * some changes to compile with Delphi
  877. Revision 1.30 1998/09/16 16:41:47 peter
  878. * merged fixes
  879. Revision 1.28.2.1 1998/09/16 16:09:51 peter
  880. * on/off support also for the local/module switches
  881. Revision 1.29 1998/09/11 09:19:53 daniel
  882. * Removed tabs.
  883. Revision 1.28 1998/09/10 15:25:36 daniel
  884. + Added maxheapsize.
  885. * Corrected semi-bug in calling the assembler and the linker
  886. Revision 1.27 1998/09/09 15:33:59 peter
  887. * removed warnings
  888. Revision 1.26 1998/09/03 11:24:02 peter
  889. * moved more inputfile things from tscannerfile to tinputfile
  890. * changed ifdef Sourceline to cs_asm_source
  891. Revision 1.25 1998/09/02 15:13:31 peter
  892. * fixed typo in directive table
  893. Revision 1.24 1998/09/01 12:52:06 peter
  894. + a lot of delphi switches
  895. Revision 1.23 1998/08/26 15:35:34 peter
  896. * fixed scannerfiles for macros
  897. + $I %<environment>%
  898. Revision 1.22 1998/08/19 14:57:50 peter
  899. * small fix for aktfilepos
  900. Revision 1.20 1998/08/18 15:11:52 peter
  901. * recompiles again
  902. Revision 1.19 1998/08/18 09:24:44 pierre
  903. * small warning position bug fixed
  904. * support_mmx switches splitting was missing
  905. * rhide error and warning output corrected
  906. Revision 1.18 1998/08/10 14:50:25 peter
  907. + localswitches, moduleswitches, globalswitches splitting
  908. Revision 1.17 1998/08/10 09:56:04 peter
  909. * path to the include file is also written to the debug output
  910. Revision 1.16 1998/08/04 22:03:44 michael
  911. + fixed dir_include search() call
  912. Revision 1.15 1998/07/14 21:46:55 peter
  913. * updated messages file
  914. Revision 1.14 1998/07/14 14:47:03 peter
  915. * released NEWINPUT
  916. Revision 1.13 1998/07/07 12:32:54 peter
  917. * status.currentsource is now calculated in verbose (more accurated)
  918. Revision 1.12 1998/07/07 11:20:10 peter
  919. + NEWINPUT for a better inputfile and scanner object
  920. Revision 1.11 1998/06/04 23:51:59 peter
  921. * m68k compiles
  922. + .def file creation moved to gendef.pas so it could also be used
  923. for win32
  924. Revision 1.10 1998/05/30 14:31:10 peter
  925. + $ASMMODE
  926. Revision 1.9 1998/05/23 01:21:28 peter
  927. + aktasmmode, aktoptprocessor, aktoutputformat
  928. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  929. + $LIBNAME to set the library name where the unit will be put in
  930. * splitted cgi386 a bit (codeseg to large for bp7)
  931. * nasm, tasm works again. nasm moved to ag386nsm.pas
  932. Revision 1.8 1998/05/11 13:07:57 peter
  933. + $ifdef NEWPPU for the new ppuformat
  934. + $define GDB not longer required
  935. * removed all warnings and stripped some log comments
  936. * no findfirst/findnext anymore to remove smartlink *.o files
  937. Revision 1.7 1998/05/08 09:21:20 michael
  938. * Added missing -Fl message to messages file.
  939. * Corrected mangling of file names when doing Linklib
  940. * -Fl now actually WORKS.
  941. * Librarysearchpath is now a field in linker object.
  942. Revision 1.6 1998/05/04 17:54:28 peter
  943. + smartlinking works (only case jumptable left todo)
  944. * redesign of systems.pas to support assemblers and linkers
  945. + Unitname is now also in the PPU-file, increased version to 14
  946. Revision 1.5 1998/04/30 15:59:42 pierre
  947. * GDB works again better :
  948. correct type info in one pass
  949. + UseTokenInfo for better source position
  950. * fixed one remaining bug in scanner for line counts
  951. * several little fixes
  952. Revision 1.4 1998/04/29 13:42:27 peter
  953. + $IOCHECKS and $ALIGN to test already, other will follow soon
  954. * fixed the wrong linecounting with comments
  955. Revision 1.3 1998/04/28 11:45:53 florian
  956. * make it compilable with TP
  957. + small COM problems solved to compile classes.pp
  958. Revision 1.2 1998/04/28 10:09:54 pierre
  959. * typo error in asm style reading corrected
  960. Revision 1.1 1998/04/27 23:13:53 peter
  961. + the new files for the scanner
  962. }