scandir.inc 30 KB

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