scandir.inc 34 KB

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