scandir.inc 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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_APPTYPE,_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','APPTYPE','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. {$ifndef TP}
  130. {$ifopt H+}
  131. setlength(hs,len);
  132. {$else}
  133. hs[0]:=char(len);
  134. {$endif}
  135. {$else}
  136. hs[0]:=char(len);
  137. {$endif}
  138. move(mac^.buftext^,hs[1],len);
  139. end
  140. else
  141. read_factor:='';
  142. end
  143. else
  144. read_factor:=hs;
  145. end
  146. end
  147. else if preproc_token=LKLAMMER then
  148. begin
  149. preproc_consume(LKLAMMER);
  150. read_factor:=read_expr;
  151. preproc_consume(RKLAMMER);
  152. end
  153. else
  154. Message(scan_e_error_in_preproc_expr);
  155. end;
  156. function read_term : string;
  157. var
  158. hs1,hs2 : string;
  159. begin
  160. hs1:=read_factor;
  161. while true do
  162. begin
  163. if (preproc_token=ID) then
  164. begin
  165. if preprocpat='AND' then
  166. begin
  167. preproc_consume(ID);
  168. hs2:=read_factor;
  169. if (hs1<>'0') and (hs2<>'0') then
  170. hs1:='1';
  171. end
  172. else
  173. break;
  174. end
  175. else
  176. break;
  177. end;
  178. read_term:=hs1;
  179. end;
  180. function read_simple_expr : string;
  181. var
  182. hs1,hs2 : string;
  183. begin
  184. hs1:=read_term;
  185. while true do
  186. begin
  187. if (preproc_token=ID) then
  188. begin
  189. if preprocpat='OR' then
  190. begin
  191. preproc_consume(ID);
  192. hs2:=read_term;
  193. if (hs1<>'0') or (hs2<>'0') then
  194. hs1:='1';
  195. end
  196. else
  197. break;
  198. end
  199. else
  200. break;
  201. end;
  202. read_simple_expr:=hs1;
  203. end;
  204. function read_expr : string;
  205. var
  206. hs1,hs2 : string;
  207. b : boolean;
  208. t : ttoken;
  209. w : integer;
  210. l1,l2 : longint;
  211. begin
  212. hs1:=read_simple_expr;
  213. t:=preproc_token;
  214. if not(t in [EQUAL,UNEQUAL,LT,GT,LTE,GTE]) then
  215. begin
  216. read_expr:=hs1;
  217. exit;
  218. end;
  219. preproc_consume(t);
  220. hs2:=read_simple_expr;
  221. if is_number(hs1) and is_number(hs2) then
  222. begin
  223. valint(hs1,l1,w);
  224. valint(hs2,l2,w);
  225. case t of
  226. EQUAL : b:=l1=l2;
  227. UNEQUAL : b:=l1<>l2;
  228. LT : b:=l1<l2;
  229. GT : b:=l1>l2;
  230. GTE : b:=l1>=l2;
  231. LTE : b:=l1<=l2;
  232. end;
  233. end
  234. else
  235. begin
  236. case t of
  237. EQUAL : b:=hs1=hs2;
  238. UNEQUAL : b:=hs1<>hs2;
  239. LT : b:=hs1<hs2;
  240. GT : b:=hs1>hs2;
  241. GTE : b:=hs1>=hs2;
  242. LTE : b:=hs1<=hs2;
  243. end;
  244. end;
  245. if b then
  246. read_expr:='1'
  247. else
  248. read_expr:='0';
  249. end;
  250. {-------------------------------------------
  251. Directives
  252. -------------------------------------------}
  253. function is_conditional(t:tdirectivetoken):boolean;
  254. begin
  255. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  256. end;
  257. procedure dir_conditional(t:tdirectivetoken);
  258. var
  259. hs : string;
  260. mac : pmacrosym;
  261. found : boolean;
  262. state : char;
  263. oldaktfilepos : tfileposinfo;
  264. begin
  265. oldaktfilepos:=aktfilepos;
  266. while true do
  267. begin
  268. current_scanner^.gettokenpos;
  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) then
  286. Message(scan_w_illegal_switch)
  287. else
  288. begin
  289. state:=current_scanner^.ReadState;
  290. if state in ['-','+'] then
  291. found:=CheckSwitch(hs[1],state);
  292. end;
  293. current_scanner^.addpreprocstack(found,hs,scan_c_ifopt_found);
  294. end;
  295. _DIR_IF : begin
  296. current_scanner^.skipspace;
  297. { start preproc expression scanner }
  298. preproc_token:=current_scanner^.readpreproc;
  299. hs:=read_expr;
  300. current_scanner^.addpreprocstack(hs<>'0',hs,scan_c_if_found);
  301. end;
  302. _DIR_IFNDEF : begin
  303. current_scanner^.skipspace;
  304. hs:=current_scanner^.readid;
  305. mac:=pmacrosym(macros^.search(hs));
  306. current_scanner^.addpreprocstack(not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  307. end;
  308. end;
  309. { accept the text ? }
  310. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  311. break
  312. else
  313. begin
  314. current_scanner^.gettokenpos;
  315. Message(scan_c_skipping_until);
  316. repeat
  317. current_scanner^.skipuntildirective;
  318. t:=Get_Directive(current_scanner^.readid);
  319. until is_conditional(t);
  320. current_scanner^.gettokenpos;
  321. Message1(scan_d_handling_switch,'$'+directive[t]);
  322. end;
  323. end;
  324. oldaktfilepos:=aktfilepos;
  325. end;
  326. procedure dir_define(t:tdirectivetoken);
  327. var
  328. hs : string;
  329. mac : pmacrosym;
  330. macropos : longint;
  331. macrobuffer : pmacrobuffer;
  332. begin
  333. current_scanner^.skipspace;
  334. hs:=current_scanner^.readid;
  335. mac:=pmacrosym(macros^.search(hs));
  336. if not assigned(mac) then
  337. begin
  338. mac:=new(pmacrosym,init(hs));
  339. mac^.defined:=true;
  340. Message1(parser_m_macro_defined,mac^.name);
  341. macros^.insert(mac);
  342. end
  343. else
  344. begin
  345. Message1(parser_m_macro_defined,mac^.name);
  346. mac^.defined:=true;
  347. { delete old definition }
  348. if assigned(mac^.buftext) then
  349. begin
  350. freemem(mac^.buftext,mac^.buflen);
  351. mac^.buftext:=nil;
  352. end;
  353. end;
  354. if (cs_support_macro in aktmoduleswitches) then
  355. begin
  356. { key words are never substituted }
  357. if is_keyword(hs) then
  358. Message(scan_e_keyword_cant_be_a_macro);
  359. { !!!!!! handle macro params, need we this? }
  360. current_scanner^.skipspace;
  361. { may be a macro? }
  362. if c=':' then
  363. begin
  364. current_scanner^.readchar;
  365. if c='=' then
  366. begin
  367. new(macrobuffer);
  368. macropos:=0;
  369. { first char }
  370. current_scanner^.readchar;
  371. while (c<>'}') do
  372. begin
  373. macrobuffer^[macropos]:=c;
  374. current_scanner^.readchar;
  375. if c=#26 then Message(scan_f_end_of_file);
  376. inc(macropos);
  377. if macropos>maxmacrolen then
  378. Message(scan_f_macro_buffer_overflow);
  379. end;
  380. { free buffer of macro ?}
  381. if assigned(mac^.buftext) then
  382. freemem(mac^.buftext,mac^.buflen);
  383. { get new mem }
  384. getmem(mac^.buftext,macropos);
  385. mac^.buflen:=macropos;
  386. { copy the text }
  387. move(macrobuffer^,mac^.buftext^,macropos);
  388. dispose(macrobuffer);
  389. end;
  390. end;
  391. end;
  392. end;
  393. procedure dir_undef(t:tdirectivetoken);
  394. var
  395. hs : string;
  396. mac : pmacrosym;
  397. begin
  398. current_scanner^.skipspace;
  399. hs:=current_scanner^.readid;
  400. mac:=pmacrosym(macros^.search(hs));
  401. if not assigned(mac) then
  402. begin
  403. mac:=new(pmacrosym,init(hs));
  404. Message1(parser_m_macro_undefined,mac^.name);
  405. mac^.defined:=false;
  406. macros^.insert(mac);
  407. end
  408. else
  409. begin
  410. Message1(parser_m_macro_undefined,mac^.name);
  411. mac^.defined:=false;
  412. { delete old definition }
  413. if assigned(mac^.buftext) then
  414. begin
  415. freemem(mac^.buftext,mac^.buflen);
  416. mac^.buftext:=nil;
  417. end;
  418. end;
  419. end;
  420. procedure dir_message(t:tdirectivetoken);
  421. var
  422. w : tmsgconst;
  423. begin
  424. case t of
  425. _DIR_STOP,
  426. _DIR_FATAL : w:=scan_f_user_defined;
  427. _DIR_ERROR : w:=scan_e_user_defined;
  428. _DIR_WARNING : w:=scan_w_user_defined;
  429. _DIR_HINT : w:=scan_h_user_defined;
  430. _DIR_NOTE : w:=scan_n_user_defined;
  431. _DIR_MESSAGE,
  432. _DIR_INFO : w:=scan_i_user_defined;
  433. end;
  434. current_scanner^.skipspace;
  435. Message1(w,current_scanner^.readcomment);
  436. end;
  437. procedure dir_moduleswitch(t:tdirectivetoken);
  438. var
  439. sw : tmoduleswitch;
  440. state : char;
  441. begin
  442. sw:=cs_modulenone;
  443. case t of
  444. _DIR_SMARTLINK : sw:=cs_smartlink;
  445. end;
  446. state:=current_scanner^.readstate;
  447. if (sw<>cs_modulenone) and (state in ['-','+']) then
  448. begin
  449. if state='-' then
  450. aktmoduleswitches:=aktmoduleswitches-[sw]
  451. else
  452. aktmoduleswitches:=aktmoduleswitches+[sw];
  453. end;
  454. end;
  455. procedure dir_localswitch(t:tdirectivetoken);
  456. var
  457. sw : tlocalswitch;
  458. state : char;
  459. begin
  460. sw:=cs_localnone;
  461. {$ifdef SUPPORT_MMX}
  462. case t of
  463. _DIR_MMX : sw:=cs_mmx;
  464. _DIR_SATURATION : sw:=cs_mmx_saturation;
  465. end;
  466. {$endif}
  467. state:=current_scanner^.readstate;
  468. if (sw<>cs_localnone) and (state in ['-','+']) then
  469. begin
  470. if state='-' then
  471. aktlocalswitches:=aktlocalswitches-[sw]
  472. else
  473. aktlocalswitches:=aktlocalswitches+[sw];
  474. end;
  475. end;
  476. procedure dir_include(t:tdirectivetoken);
  477. var
  478. hs : string;
  479. path : dirstr;
  480. name : namestr;
  481. ext : extstr;
  482. hp : pinputfile;
  483. i : longint;
  484. found : boolean;
  485. begin
  486. current_scanner^.skipspace;
  487. hs:=current_scanner^.readcomment;
  488. i:=length(hs);
  489. while (i>0) and (hs[i]=' ') do
  490. dec(i);
  491. Delete(hs,i+1,length(hs)-i);
  492. if hs='' then
  493. exit;
  494. if (hs[1]='%') then
  495. begin
  496. { case insensitive }
  497. hs:=upper(hs);
  498. { save old }
  499. path:=hs;
  500. { remove %'s }
  501. Delete(hs,1,1);
  502. if hs[length(hs)]='%' then
  503. Delete(hs,length(hs),1);
  504. { first check for internal macros }
  505. if hs='TIME' then
  506. hs:=gettimestr
  507. else
  508. if hs='DATE' then
  509. hs:=getdatestr
  510. else
  511. if hs='FILE' then
  512. hs:=current_module^.sourcefiles^.get_file_name(aktfilepos.fileindex)
  513. else
  514. if hs='LINE' then
  515. hs:=tostr(aktfilepos.line)
  516. else
  517. if hs='FPCVERSION' then
  518. hs:=version_string
  519. else
  520. if hs='FPCTARGET' then
  521. hs:=target_string
  522. else
  523. hs:=getenv(hs);
  524. if hs='' then
  525. Comment(V_Warning,'Include environment '+path+' not found in environment')
  526. else
  527. begin
  528. { make it a stringconst }
  529. hs:=''''+hs+'''';
  530. current_scanner^.insertmacro(@hs[1],length(hs));
  531. end;
  532. end
  533. else
  534. begin
  535. hs:=FixFileName(hs);
  536. fsplit(hs,path,name,ext);
  537. { first look in the path of _d then currentmodule }
  538. path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found);
  539. { shutdown current file }
  540. current_scanner^.tempcloseinputfile;
  541. { load new file }
  542. hp:=new(pinputfile,init(path+name+ext));
  543. current_scanner^.addfile(hp);
  544. if not current_scanner^.openinputfile then
  545. Message1(scan_f_cannot_open_includefile,hs);
  546. Message1(scan_t_start_include_file,current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^);
  547. current_scanner^.reload;
  548. { register for refs }
  549. current_module^.sourcefiles^.register_file(hp);
  550. end;
  551. end;
  552. procedure dir_description(t:tdirectivetoken);
  553. begin
  554. end;
  555. procedure dir_linkobject(t:tdirectivetoken);
  556. begin
  557. current_scanner^.skipspace;
  558. current_scanner^.readstring;
  559. current_module^.linkofiles.insert(FixFileName(orgpattern));
  560. end;
  561. procedure dir_linklib(t:tdirectivetoken);
  562. begin
  563. current_scanner^.skipspace;
  564. current_scanner^.readstring;
  565. current_module^.linkSharedLibs.insert(orgpattern);
  566. end;
  567. procedure dir_outputformat(t:tdirectivetoken);
  568. begin
  569. if not current_module^.in_global then
  570. Message(scan_w_switch_is_global)
  571. else
  572. begin
  573. current_scanner^.skipspace;
  574. if set_string_asm(current_scanner^.readid) then
  575. aktoutputformat:=target_asm.id
  576. else
  577. Message(scan_w_illegal_switch);
  578. end;
  579. end;
  580. procedure dir_mode(t:tdirectivetoken);
  581. begin
  582. if not current_module^.in_global then
  583. Message(scan_w_switch_is_global)
  584. else
  585. begin
  586. current_scanner^.skipspace;
  587. current_scanner^.readstring;
  588. if pattern='DEFAULT' then
  589. aktmodeswitches:=initmodeswitches
  590. else
  591. if pattern='DELPHI' then
  592. aktmodeswitches:=delphimodeswitches
  593. else
  594. if pattern='TP' then
  595. aktmodeswitches:=tpmodeswitches
  596. else
  597. if pattern='FPC' then
  598. aktmodeswitches:=fpcmodeswitches
  599. else
  600. if pattern='OBJFPC' then
  601. aktmodeswitches:=objfpcmodeswitches
  602. else
  603. if pattern='GPC' then
  604. aktmodeswitches:=gpcmodeswitches;
  605. end;
  606. end;
  607. procedure dir_packrecords(t:tdirectivetoken);
  608. var
  609. hs : string;
  610. begin
  611. current_scanner^.skipspace;
  612. if not(c in ['0'..'9']) then
  613. begin
  614. hs:=current_scanner^.readid;
  615. if (hs='NORMAL') or (hs='DEFAULT') then
  616. aktpackrecords:=2
  617. else
  618. Message(scan_w_only_pack_records);
  619. end
  620. else
  621. begin
  622. case current_scanner^.readval of
  623. 1 : aktpackrecords:=1;
  624. 2 : aktpackrecords:=2;
  625. 4 : aktpackrecords:=4;
  626. 8 : aktpackrecords:=8;
  627. 16 : aktpackrecords:=16;
  628. 32 : aktpackrecords:=32;
  629. else
  630. Message(scan_w_only_pack_records);
  631. end;
  632. end;
  633. end;
  634. procedure dir_packenum(t:tdirectivetoken);
  635. var
  636. hs : string;
  637. begin
  638. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  639. begin
  640. aktpackenum:=ord(pattern[2])-ord('0');
  641. exit;
  642. end;
  643. current_scanner^.skipspace;
  644. if not(c in ['0'..'9']) then
  645. begin
  646. hs:=current_scanner^.readid;
  647. if (hs='NORMAL') or (hs='DEFAULT') then
  648. aktpackenum:=4
  649. else
  650. Message(scan_w_only_pack_enum);
  651. end
  652. else
  653. begin
  654. case current_scanner^.readval of
  655. 1 : aktpackenum:=1;
  656. 2 : aktpackenum:=2;
  657. 4 : aktpackenum:=4;
  658. else
  659. Message(scan_w_only_pack_enum);
  660. end;
  661. end;
  662. end;
  663. procedure dir_apptype(t:tdirectivetoken);
  664. var
  665. hs : string;
  666. begin
  667. if target_info.target<>target_i386_win32 then
  668. Message(scan_w_app_type_not_support);
  669. if not current_module^.in_global then
  670. Message(scan_w_switch_is_global)
  671. else
  672. begin
  673. current_scanner^.skipspace;
  674. hs:=current_scanner^.readid;
  675. if hs='GUI' then
  676. apptype:=at_gui
  677. else if hs='CONSOLE' then
  678. apptype:=at_cui
  679. else
  680. Message1(scan_w_unsupported_app_type,hs);
  681. end;
  682. end;
  683. procedure dir_wait(t:tdirectivetoken);
  684. var had_info : boolean;
  685. begin
  686. had_info:=(status.verbosity and V_Info)<>0;
  687. { this message should allways appear !! }
  688. status.verbosity:=status.verbosity or V_Info;
  689. Message(scan_i_press_enter);
  690. readln;
  691. If not(had_info) then
  692. status.verbosity:=status.verbosity and (not V_Info);
  693. end;
  694. procedure dir_asmmode(t:tdirectivetoken);
  695. var
  696. s : string;
  697. begin
  698. current_scanner^.skipspace;
  699. s:=current_scanner^.readid;
  700. if s='DEFAULT' then
  701. aktasmmode:=initasmmode
  702. else
  703. if not set_string_asmmode(s,aktasmmode) then
  704. Message1(scan_w_unsupported_asmmode_specifier,s);
  705. end;
  706. procedure dir_oldasmmode(t:tdirectivetoken);
  707. begin
  708. {$ifdef i386}
  709. case t of
  710. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  711. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  712. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  713. end;
  714. {$endif i386}
  715. end;
  716. procedure dir_delphiswitch(t:tdirectivetoken);
  717. var
  718. sw,state : char;
  719. begin
  720. case t of
  721. _DIR_ALIGN : sw:='A';
  722. _DIR_ASSERTIONS : sw:='C';
  723. _DIR_BOOLEVAL : sw:='B';
  724. _DIR_DEBUGINFO : sw:='D';
  725. _DIR_IOCHECKS : sw:='I';
  726. _DIR_LOCALSYMBOLS : sw:='L';
  727. _DIR_LONGSTRINGS : sw:='H';
  728. _DIR_OPENSTRINGS : sw:='P';
  729. _DIR_OVERFLOWCHECKS : sw:='Q';
  730. _DIR_RANGECHECKS : sw:='R';
  731. _DIR_REFERENCEINFO : sw:='Y';
  732. _DIR_STACKFRAMES : sw:='W';
  733. _DIR_TYPEDADDRESS : sw:='T';
  734. _DIR_TYPEINFO : sw:='M';
  735. _DIR_VARSTRINGCHECKS : sw:='V';
  736. else
  737. exit;
  738. end;
  739. { c contains the next char, a + or - would be fine }
  740. state:=current_scanner^.readstate;
  741. if state in ['-','+'] then
  742. HandleSwitch(sw,state);
  743. end;
  744. procedure dir_memory(t:tdirectivetoken);
  745. var
  746. l : longint;
  747. begin
  748. current_scanner^.skipspace;
  749. l:=current_scanner^.readval;
  750. if l>1024 then
  751. stacksize:=l;
  752. current_scanner^.skipspace;
  753. if c=',' then
  754. begin
  755. current_scanner^.readchar;
  756. current_scanner^.skipspace;
  757. l:=current_scanner^.readval;
  758. if l>1024 then
  759. heapsize:=l;
  760. end;
  761. if c=',' then
  762. begin
  763. current_scanner^.readchar;
  764. current_scanner^.skipspace;
  765. l:=current_scanner^.readval;
  766. if l>1024 then
  767. maxheapsize:=l;
  768. end;
  769. if heapsize>maxheapsize then
  770. message(scan_w_illegal_switch);
  771. end;
  772. procedure dir_setverbose(t:tdirectivetoken);
  773. var
  774. flag,
  775. state : char;
  776. begin
  777. case t of
  778. _DIR_HINTS : flag:='H';
  779. _DIR_WARNINGS : flag:='W';
  780. _DIR_NOTES : flag:='N';
  781. else
  782. exit;
  783. end;
  784. { support ON/OFF }
  785. state:=current_scanner^.ReadState;
  786. SetVerbosity(flag+state);
  787. end;
  788. type
  789. tdirectiveproc=procedure(t:tdirectivetoken);
  790. const
  791. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  792. {_DIR_NONE} nil,
  793. {_DIR_ALIGN} dir_delphiswitch,
  794. {_DIR_APPTYPE} dir_apptype,
  795. {_DIR_ASMMODE} dir_asmmode,
  796. {_DIR_ASSERTION} dir_delphiswitch,
  797. {_DIR_BOOLEVAL} dir_delphiswitch,
  798. {_DIR_D} dir_description,
  799. {_DIR_DEBUGINFO} dir_delphiswitch,
  800. {_DIR_DEFINE} dir_define,
  801. {_DIR_DESCRIPTION} dir_description,
  802. {_DIR_ELSE} dir_conditional,
  803. {_DIR_ENDIF} dir_conditional,
  804. {_DIR_ERROR} dir_message,
  805. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  806. {_DIR_FATAL} dir_message,
  807. {_DIR_HINT} dir_message,
  808. {_DIR_HINTS} dir_setverbose,
  809. {_DIR_I} dir_include,
  810. {_DIR_I386_ATT} dir_oldasmmode,
  811. {_DIR_I386_DIRECT} dir_oldasmmode,
  812. {_DIR_I386_INTEL} dir_oldasmmode,
  813. {_DIR_IOCHECKS} dir_delphiswitch,
  814. {_DIR_IF} dir_conditional,
  815. {_DIR_IFDEF} dir_conditional,
  816. {_DIR_IFNDEF} dir_conditional,
  817. {_DIR_IFOPT} dir_conditional,
  818. {_DIR_INCLUDE} dir_include,
  819. {_DIR_INFO} dir_message,
  820. {_DIR_L} dir_linkobject,
  821. {_DIR_LINK} dir_linkobject,
  822. {_DIR_LINKLIB} dir_linklib,
  823. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  824. {_DIR_LONGSTRINGS} dir_delphiswitch,
  825. {_DIR_M} dir_memory,
  826. {_DIR_MEMORY} dir_memory,
  827. {_DIR_MESSAGE} dir_message,
  828. {_DIR_MINENUMSIZE} dir_packenum,
  829. {_DIR_MMX} dir_localswitch,
  830. {_DIR_MODE} dir_mode,
  831. {_DIR_NOTE} dir_message,
  832. {_DIR_NOTES} dir_setverbose,
  833. {_DIR_OPENSTRINGS} dir_delphiswitch,
  834. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  835. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  836. {_DIR_PACKENUM} dir_packenum,
  837. {_DIR_PACKRECORDS} dir_packrecords,
  838. {_DIR_RANGECHECKS} dir_delphiswitch,
  839. {_DIR_REFERENCEINFO} dir_delphiswitch,
  840. {_DIR_SATURATION} dir_localswitch,
  841. {_DIR_SMARTLINK} dir_moduleswitch,
  842. {_DIR_STACKFRAMES} dir_delphiswitch,
  843. {_DIR_STOP} dir_message,
  844. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  845. {_DIR_TYPEINFO} dir_delphiswitch,
  846. {_DIR_UNDEF} dir_undef,
  847. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  848. {_DIR_WAIT} dir_wait,
  849. {_DIR_WARNING} dir_message,
  850. {_DIR_WARNINGS} dir_setverbose,
  851. {_DIR_Z1} dir_packenum,
  852. {_DIR_Z2} dir_packenum,
  853. {_DIR_Z4} dir_packenum
  854. );
  855. {-------------------------------------------
  856. Main switches handling
  857. -------------------------------------------}
  858. procedure handledirectives;
  859. var
  860. t : tdirectivetoken;
  861. p : tdirectiveproc;
  862. hs : string;
  863. begin
  864. current_scanner^.gettokenpos;
  865. current_scanner^.readchar; {Remove the $}
  866. hs:=current_scanner^.readid;
  867. Message1(scan_d_handling_switch,'$'+hs);
  868. if hs='' then
  869. Message1(scan_w_illegal_switch,'$'+hs);
  870. { Check for compiler switches }
  871. while (length(hs)=1) and (c in ['-','+']) do
  872. begin
  873. HandleSwitch(hs[1],c);
  874. current_scanner^.readchar; {Remove + or -}
  875. if c=',' then
  876. begin
  877. current_scanner^.readchar; {Remove , }
  878. { read next switch, support $v+,$+}
  879. hs:=current_scanner^.readid;
  880. if (hs='') then
  881. begin
  882. if (c='$') and (m_fpc in aktmodeswitches) then
  883. begin
  884. current_scanner^.readchar; { skip $ }
  885. hs:=current_scanner^.readid;
  886. end;
  887. if (hs='') then
  888. Message1(scan_w_illegal_directive,'$'+c);
  889. end
  890. else
  891. Message1(scan_d_handling_switch,'$'+hs);
  892. end
  893. else
  894. hs:='';
  895. end;
  896. { directives may follow switches after a , }
  897. if hs<>'' then
  898. begin
  899. t:=Get_Directive(hs);
  900. if t<>_DIR_NONE then
  901. begin
  902. p:=directiveproc[t];
  903. {$ifdef FPC}
  904. if assigned(p) then
  905. {$else}
  906. if @p<>nil then
  907. {$endif}
  908. p(t);
  909. end
  910. else
  911. Message1(scan_w_illegal_directive,'$'+hs);
  912. { conditionals already read the comment }
  913. if (current_scanner^.comment_level>0) then
  914. current_scanner^.readcomment;
  915. end;
  916. end;
  917. {
  918. $Log$
  919. Revision 1.43 1998-11-16 15:41:43 peter
  920. * tp7 didn't like my ifopt H+ :(
  921. Revision 1.42 1998/11/16 12:18:04 peter
  922. * H+ fixes
  923. Revision 1.41 1998/10/22 17:54:08 florian
  924. + switch $APPTYPE for win32 added
  925. Revision 1.40 1998/10/21 20:16:04 peter
  926. * beter line info for conditionals
  927. Revision 1.39 1998/10/13 16:50:21 pierre
  928. * undid some changes of Peter that made the compiler wrong
  929. for m68k (I had to reinsert some ifdefs)
  930. * removed several memory leaks under m68k
  931. * removed the meory leaks for assembler readers
  932. * cross compiling shoud work again better
  933. ( crosscompiling sysamiga works
  934. but as68k still complain about some code !)
  935. Revision 1.38 1998/10/13 13:10:28 peter
  936. * new style for m68k/i386 infos and enums
  937. Revision 1.37 1998/10/08 23:29:04 peter
  938. * -vu shows unit info, -vt shows tried/used files
  939. Revision 1.36 1998/10/08 17:17:29 pierre
  940. * current_module old scanner tagged as invalid if unit is recompiled
  941. + added ppheap for better info on tracegetmem of heaptrc
  942. (adds line column and file index)
  943. * several memory leaks removed ith help of heaptrc !!
  944. Revision 1.35 1998/10/08 13:44:39 peter
  945. * fixed $I %date% not in uppercase
  946. Revision 1.34 1998/09/28 16:57:24 pierre
  947. * changed all length(p^.value_str^) into str_length(p)
  948. to get it work with and without ansistrings
  949. * changed sourcefiles field of tmodule to a pointer
  950. Revision 1.33 1998/09/26 17:45:40 peter
  951. + idtoken and only one token table
  952. Revision 1.32 1998/09/24 23:49:19 peter
  953. + aktmodeswitches
  954. Revision 1.31 1998/09/18 16:03:44 florian
  955. * some changes to compile with Delphi
  956. Revision 1.30 1998/09/16 16:41:47 peter
  957. * merged fixes
  958. Revision 1.28.2.1 1998/09/16 16:09:51 peter
  959. * on/off support also for the local/module switches
  960. Revision 1.29 1998/09/11 09:19:53 daniel
  961. * Removed tabs.
  962. Revision 1.28 1998/09/10 15:25:36 daniel
  963. + Added maxheapsize.
  964. * Corrected semi-bug in calling the assembler and the linker
  965. Revision 1.27 1998/09/09 15:33:59 peter
  966. * removed warnings
  967. Revision 1.26 1998/09/03 11:24:02 peter
  968. * moved more inputfile things from tscannerfile to tinputfile
  969. * changed ifdef Sourceline to cs_asm_source
  970. Revision 1.25 1998/09/02 15:13:31 peter
  971. * fixed typo in directive table
  972. Revision 1.24 1998/09/01 12:52:06 peter
  973. + a lot of delphi switches
  974. Revision 1.23 1998/08/26 15:35:34 peter
  975. * fixed scannerfiles for macros
  976. + $I %<environment>%
  977. Revision 1.22 1998/08/19 14:57:50 peter
  978. * small fix for aktfilepos
  979. Revision 1.20 1998/08/18 15:11:52 peter
  980. * recompiles again
  981. Revision 1.19 1998/08/18 09:24:44 pierre
  982. * small warning position bug fixed
  983. * support_mmx switches splitting was missing
  984. * rhide error and warning output corrected
  985. Revision 1.18 1998/08/10 14:50:25 peter
  986. + localswitches, moduleswitches, globalswitches splitting
  987. Revision 1.17 1998/08/10 09:56:04 peter
  988. * path to the include file is also written to the debug output
  989. Revision 1.16 1998/08/04 22:03:44 michael
  990. + fixed dir_include search() call
  991. Revision 1.15 1998/07/14 21:46:55 peter
  992. * updated messages file
  993. Revision 1.14 1998/07/14 14:47:03 peter
  994. * released NEWINPUT
  995. Revision 1.13 1998/07/07 12:32:54 peter
  996. * status.currentsource is now calculated in verbose (more accurated)
  997. Revision 1.12 1998/07/07 11:20:10 peter
  998. + NEWINPUT for a better inputfile and scanner object
  999. Revision 1.11 1998/06/04 23:51:59 peter
  1000. * m68k compiles
  1001. + .def file creation moved to gendef.pas so it could also be used
  1002. for win32
  1003. Revision 1.10 1998/05/30 14:31:10 peter
  1004. + $ASMMODE
  1005. Revision 1.9 1998/05/23 01:21:28 peter
  1006. + aktasmmode, aktoptprocessor, aktoutputformat
  1007. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  1008. + $LIBNAME to set the library name where the unit will be put in
  1009. * splitted cgi386 a bit (codeseg to large for bp7)
  1010. * nasm, tasm works again. nasm moved to ag386nsm.pas
  1011. Revision 1.8 1998/05/11 13:07:57 peter
  1012. + $ifdef NEWPPU for the new ppuformat
  1013. + $define GDB not longer required
  1014. * removed all warnings and stripped some log comments
  1015. * no findfirst/findnext anymore to remove smartlink *.o files
  1016. Revision 1.7 1998/05/08 09:21:20 michael
  1017. * Added missing -Fl message to messages file.
  1018. * Corrected mangling of file names when doing Linklib
  1019. * -Fl now actually WORKS.
  1020. * Librarysearchpath is now a field in linker object.
  1021. Revision 1.6 1998/05/04 17:54:28 peter
  1022. + smartlinking works (only case jumptable left todo)
  1023. * redesign of systems.pas to support assemblers and linkers
  1024. + Unitname is now also in the PPU-file, increased version to 14
  1025. Revision 1.5 1998/04/30 15:59:42 pierre
  1026. * GDB works again better :
  1027. correct type info in one pass
  1028. + UseTokenInfo for better source position
  1029. * fixed one remaining bug in scanner for line counts
  1030. * several little fixes
  1031. Revision 1.4 1998/04/29 13:42:27 peter
  1032. + $IOCHECKS and $ALIGN to test already, other will follow soon
  1033. * fixed the wrong linecounting with comments
  1034. Revision 1.3 1998/04/28 11:45:53 florian
  1035. * make it compilable with TP
  1036. + small COM problems solved to compile classes.pp
  1037. Revision 1.2 1998/04/28 10:09:54 pierre
  1038. * typo error in asm style reading corrected
  1039. Revision 1.1 1998/04/27 23:13:53 peter
  1040. + the new files for the scanner
  1041. }