scandir.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit implements directive parsing for the scanner
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit scandir;
  18. {$i fpcdefs.inc}
  19. interface
  20. procedure InitScannerDirectives;
  21. implementation
  22. uses
  23. cutils,
  24. globtype,globals,systems,widestr,
  25. verbose,comphook,ppu,
  26. scanner,switches,
  27. fmodule,
  28. symtable,
  29. rabase;
  30. const
  31. localswitchesstackmax = 20;
  32. var
  33. localswitchesstack: array[0..localswitchesstackmax] of tlocalswitches;
  34. localswitchesstackpos: Integer;
  35. {*****************************************************************************
  36. Helpers
  37. *****************************************************************************}
  38. procedure do_delphiswitch(sw:char);
  39. var
  40. state : char;
  41. begin
  42. { c contains the next char, a + or - would be fine }
  43. state:=current_scanner.readstate;
  44. if state in ['-','+'] then
  45. HandleSwitch(sw,state);
  46. end;
  47. procedure do_setverbose(flag:char);
  48. var
  49. state : char;
  50. begin
  51. { support ON/OFF }
  52. state:=current_scanner.ReadState;
  53. SetVerbosity(flag+state);
  54. end;
  55. procedure do_moduleswitch(sw:tmoduleswitch);
  56. var
  57. state : char;
  58. begin
  59. state:=current_scanner.readstate;
  60. if (sw<>cs_modulenone) and (state in ['-','+']) then
  61. begin
  62. if state='-' then
  63. exclude(aktmoduleswitches,sw)
  64. else
  65. include(aktmoduleswitches,sw);
  66. end;
  67. end;
  68. procedure do_localswitch(sw:tlocalswitch);
  69. var
  70. state : char;
  71. begin
  72. state:=current_scanner.readstate;
  73. if (sw<>cs_localnone) and (state in ['-','+']) then
  74. begin
  75. if not localswitcheschanged then
  76. nextaktlocalswitches:=aktlocalswitches;
  77. if state='-' then
  78. exclude(nextaktlocalswitches,sw)
  79. else
  80. include(nextaktlocalswitches,sw);
  81. localswitcheschanged:=true;
  82. end;
  83. end;
  84. procedure do_localswitchdefault(sw:tlocalswitch);
  85. var
  86. state : char;
  87. begin
  88. state:=current_scanner.readstatedefault;
  89. if (sw<>cs_localnone) and (state in ['-','+','*']) then
  90. begin
  91. if not localswitcheschanged then
  92. nextaktlocalswitches:=aktlocalswitches;
  93. if state='-' then
  94. exclude(nextaktlocalswitches,sw)
  95. else
  96. if state='+' then
  97. include(nextaktlocalswitches,sw)
  98. else
  99. begin
  100. if sw in initlocalswitches then
  101. include(nextaktlocalswitches,sw)
  102. else
  103. exclude(nextaktlocalswitches,sw);
  104. end;
  105. localswitcheschanged:=true;
  106. end;
  107. end;
  108. procedure do_message(w:integer);
  109. begin
  110. current_scanner.skipspace;
  111. Message1(w,current_scanner.readcomment);
  112. end;
  113. {*****************************************************************************
  114. Directive Callbacks
  115. *****************************************************************************}
  116. procedure dir_align;
  117. var
  118. hs : string;
  119. begin
  120. current_scanner.skipspace;
  121. if not(c in ['0'..'9']) then
  122. begin
  123. { Support also the ON and OFF as switch }
  124. hs:=current_scanner.readid;
  125. if (hs='ON') then
  126. aktpackrecords:=4
  127. else if (hs='OFF') then
  128. aktpackrecords:=1
  129. else if m_mac in aktmodeswitches then
  130. begin
  131. { Support switches used in Apples Universal Interfaces}
  132. if (hs='MAC68K') then
  133. aktpackrecords:=2
  134. else if (hs='POWER') then
  135. aktpackrecords:=4
  136. else if (hs='RESET') then
  137. aktpackrecords:=0
  138. else
  139. Message1(scan_e_illegal_pack_records,hs);
  140. end
  141. else
  142. Message1(scan_e_illegal_pack_records,hs);
  143. end
  144. else
  145. begin
  146. case current_scanner.readval of
  147. 1 : aktpackrecords:=1;
  148. 2 : aktpackrecords:=2;
  149. 4 : aktpackrecords:=4;
  150. 8 : aktpackrecords:=8;
  151. 16 : aktpackrecords:=16;
  152. 32 : aktpackrecords:=32;
  153. else
  154. Message1(scan_e_illegal_pack_records,hs);
  155. end;
  156. end;
  157. end;
  158. procedure dir_asmmode;
  159. var
  160. s : string;
  161. begin
  162. current_scanner.skipspace;
  163. s:=current_scanner.readid;
  164. If Inside_asm_statement then
  165. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  166. if s='DEFAULT' then
  167. aktasmmode:=initasmmode
  168. else
  169. if not SetAsmReadMode(s,aktasmmode) then
  170. Message1(scan_e_illegal_asmmode_specifier,s);
  171. end;
  172. {$ifdef m68k}
  173. procedure dir_appid;
  174. begin
  175. if target_info.system<>system_m68k_palmos then
  176. Message(scan_w_appid_not_support);
  177. { change description global var in all cases }
  178. { it not used but in win32 and os2 }
  179. current_scanner.skipspace;
  180. palmos_applicationid:=current_scanner.readcomment;
  181. end;
  182. procedure dir_appname;
  183. begin
  184. if target_info.system<>system_m68k_palmos then
  185. Message(scan_w_appname_not_support);
  186. { change description global var in all cases }
  187. { it not used but in win32 and os2 }
  188. current_scanner.skipspace;
  189. palmos_applicationname:=current_scanner.readcomment;
  190. end;
  191. {$endif m68k}
  192. procedure dir_apptype;
  193. var
  194. hs : string;
  195. begin
  196. if not (target_info.system in [system_i386_win32,system_i386_os2,
  197. system_i386_emx, system_powerpc_macos]) then
  198. Message(scan_w_app_type_not_support);
  199. if not current_module.in_global then
  200. Message(scan_w_switch_is_global)
  201. else
  202. begin
  203. current_scanner.skipspace;
  204. hs:=current_scanner.readid;
  205. if hs='GUI' then
  206. apptype:=app_gui
  207. else if hs='CONSOLE' then
  208. apptype:=app_cui
  209. else if (hs='NATIVE') and (target_info.system in system_windows) then
  210. apptype:=app_native
  211. else if (hs='FS') and (target_info.system in [system_i386_os2,
  212. system_i386_emx]) then
  213. apptype:=app_fs
  214. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  215. apptype:=app_tool
  216. else
  217. Message1(scan_w_unsupported_app_type,hs);
  218. end;
  219. end;
  220. procedure dir_calling;
  221. var
  222. hs : string;
  223. begin
  224. current_scanner.skipspace;
  225. hs:=current_scanner.readid;
  226. if not SetAktProcCall(hs,false) then
  227. Message1(parser_w_unknown_proc_directive_ignored,hs);
  228. end;
  229. procedure dir_checkpointer;
  230. begin
  231. do_localswitchdefault(cs_checkpointer);
  232. end;
  233. procedure dir_objectchecks;
  234. begin
  235. do_localswitch(cs_check_object);
  236. end;
  237. procedure dir_assertions;
  238. begin
  239. do_delphiswitch('C');
  240. end;
  241. procedure dir_booleval;
  242. begin
  243. do_delphiswitch('B');
  244. end;
  245. procedure dir_debuginfo;
  246. begin
  247. do_delphiswitch('D');
  248. end;
  249. procedure dir_description;
  250. begin
  251. if not (target_info.system in [system_i386_os2,system_i386_emx,
  252. system_i386_win32,system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  253. Message(scan_w_description_not_support);
  254. { change description global var in all cases }
  255. { it not used but in win32, os2 and netware }
  256. current_scanner.skipspace;
  257. description:=current_scanner.readcomment;
  258. DescriptionSetExplicity:=true;
  259. end;
  260. procedure dir_screenname; {ad}
  261. begin
  262. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  263. {Message(scan_w_decription_not_support);}
  264. comment (V_Warning,'Screenname only supported for target netware');
  265. current_scanner.skipspace;
  266. nwscreenname:=current_scanner.readcomment;
  267. end;
  268. procedure dir_threadname; {ad}
  269. begin
  270. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  271. {Message(scan_w_decription_not_support);}
  272. comment (V_Warning,'Threadname only supported for target netware');
  273. current_scanner.skipspace;
  274. nwthreadname:=current_scanner.readcomment;
  275. end;
  276. procedure dir_copyright; {ad}
  277. begin
  278. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  279. {Message(scan_w_decription_not_support);}
  280. comment (V_Warning,'Copyright only supported for target netware');
  281. current_scanner.skipspace;
  282. nwcopyright:=current_scanner.readcomment;
  283. end;
  284. procedure dir_error;
  285. begin
  286. do_message(scan_e_user_defined);
  287. end;
  288. procedure dir_extendedsyntax;
  289. begin
  290. do_delphiswitch('X');
  291. end;
  292. procedure dir_fatal;
  293. begin
  294. do_message(scan_f_user_defined);
  295. end;
  296. procedure dir_fputype;
  297. begin
  298. current_scanner.skipspace;
  299. { current_scanner.undef_macro('FPU'+fputypestr[aktfputype]); }
  300. if not(SetFPUType(upper(current_scanner.readcomment),false)) then
  301. comment(V_Error,'Illegal FPU type');
  302. { current_scanner.def_macro('FPU'+fputypestr[aktfputype]); }
  303. end;
  304. procedure dir_goto;
  305. begin
  306. do_moduleswitch(cs_support_goto);
  307. end;
  308. procedure dir_hint;
  309. begin
  310. do_message(scan_h_user_defined);
  311. end;
  312. procedure dir_hints;
  313. begin
  314. do_setverbose('H');
  315. end;
  316. procedure dir_implicitexceptions;
  317. begin
  318. do_moduleswitch(cs_implicit_exceptions);
  319. end;
  320. procedure dir_includepath;
  321. begin
  322. if not current_module.in_global then
  323. Message(scan_w_switch_is_global)
  324. else
  325. begin
  326. current_scanner.skipspace;
  327. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  328. end;
  329. end;
  330. procedure dir_info;
  331. begin
  332. do_message(scan_i_user_defined);
  333. end;
  334. procedure dir_inline;
  335. begin
  336. do_moduleswitch(cs_support_inline);
  337. end;
  338. procedure dir_interfaces;
  339. var
  340. hs : string;
  341. begin
  342. {corba/com/default}
  343. current_scanner.skipspace;
  344. hs:=current_scanner.readid;
  345. if (hs='CORBA') then
  346. aktinterfacetype:=it_interfacecorba
  347. else if (hs='COM') then
  348. aktinterfacetype:=it_interfacecom
  349. else if (hs='DEFAULT') then
  350. aktinterfacetype:=initinterfacetype
  351. else
  352. Message(scan_e_invalid_interface_type);
  353. end;
  354. procedure dir_iochecks;
  355. begin
  356. do_delphiswitch('I');
  357. end;
  358. procedure dir_libexport;
  359. begin
  360. {not implemented}
  361. end;
  362. procedure dir_librarypath;
  363. begin
  364. if not current_module.in_global then
  365. Message(scan_w_switch_is_global)
  366. else
  367. begin
  368. current_scanner.skipspace;
  369. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  370. end;
  371. end;
  372. procedure dir_link;
  373. var
  374. s : string;
  375. begin
  376. current_scanner.skipspace;
  377. if scanner.c = '''' then
  378. begin
  379. s:= current_scanner.readquotedstring;
  380. current_scanner.readcomment
  381. end
  382. else
  383. s:= trimspace(current_scanner.readcomment);
  384. s:=AddExtension(FixFileName(s),target_info.objext);
  385. current_module.linkotherofiles.add(s,link_allways);
  386. end;
  387. procedure dir_linklib;
  388. type
  389. tLinkMode=(lm_shared,lm_static);
  390. var
  391. s : string;
  392. quote : char;
  393. libext,
  394. libname,
  395. linkmodestr : string;
  396. p : longint;
  397. linkMode : tLinkMode;
  398. begin
  399. current_scanner.skipspace;
  400. if scanner.c = '''' then
  401. begin
  402. libname:= current_scanner.readquotedstring;
  403. s:= current_scanner.readcomment;
  404. p:=pos(',',s);
  405. end
  406. else
  407. begin
  408. s:= current_scanner.readcomment;
  409. p:=pos(',',s);
  410. if p=0 then
  411. libname:=TrimSpace(s)
  412. else
  413. libname:=TrimSpace(copy(s,1,p-1));
  414. end;
  415. if p=0 then
  416. linkmodeStr:=''
  417. else
  418. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  419. if (libname='') or (libname='''''') or (libname='""') then
  420. exit;
  421. { create library name }
  422. if libname[1] in ['''','"'] then
  423. begin
  424. quote:=libname[1];
  425. Delete(libname,1,1);
  426. p:=pos(quote,libname);
  427. if p>0 then
  428. Delete(libname,p,1);
  429. end;
  430. libname:=FixFileName(libname);
  431. { get linkmode, default is to check the extension for
  432. the static library, otherwise shared linking is assumed }
  433. linkmode:=lm_shared;
  434. if linkModeStr='' then
  435. begin
  436. libext:=SplitExtension(libname);
  437. if libext=target_info.staticClibext then
  438. linkMode:=lm_static;
  439. end
  440. else if linkModeStr='STATIC' then
  441. linkmode:=lm_static
  442. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  443. linkmode:=lm_shared
  444. else
  445. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  446. { add to the list of other libraries }
  447. if linkMode=lm_static then
  448. current_module.linkOtherStaticLibs.add(libname,link_allways)
  449. else
  450. current_module.linkOtherSharedLibs.add(libname,link_allways);
  451. end;
  452. procedure dir_localsymbols;
  453. begin
  454. do_delphiswitch('L');
  455. end;
  456. procedure dir_longstrings;
  457. begin
  458. do_delphiswitch('H');
  459. end;
  460. procedure dir_macro;
  461. begin
  462. do_moduleswitch(cs_support_macro);
  463. end;
  464. procedure dir_maxfpuregisters;
  465. var
  466. l : integer;
  467. hs : string;
  468. begin
  469. current_scanner.skipspace;
  470. if not(c in ['0'..'9']) then
  471. begin
  472. hs:=current_scanner.readid;
  473. if (hs='NORMAL') or (hs='DEFAULT') then
  474. aktmaxfpuregisters:=-1
  475. else
  476. Message(scan_e_invalid_maxfpureg_value);
  477. end
  478. else
  479. begin
  480. l:=current_scanner.readval;
  481. case l of
  482. 0..8:
  483. aktmaxfpuregisters:=l;
  484. else
  485. Message(scan_e_invalid_maxfpureg_value);
  486. end;
  487. end;
  488. end;
  489. procedure dir_memory;
  490. var
  491. l : longint;
  492. begin
  493. current_scanner.skipspace;
  494. l:=current_scanner.readval;
  495. if l>1024 then
  496. stacksize:=l;
  497. if c=',' then
  498. begin
  499. current_scanner.readchar;
  500. current_scanner.skipspace;
  501. l:=current_scanner.readval;
  502. if l>1024 then
  503. heapsize:=l;
  504. end;
  505. end;
  506. procedure dir_message;
  507. var
  508. hs : string;
  509. w : longint;
  510. begin
  511. w:=0;
  512. current_scanner.skipspace;
  513. { Message level specified? }
  514. if c='''' then
  515. w:=scan_n_user_defined
  516. else
  517. begin
  518. hs:=current_scanner.readid;
  519. if (hs='WARN') or (hs='WARNING') then
  520. w:=scan_w_user_defined
  521. else
  522. if (hs='ERROR') then
  523. w:=scan_e_user_defined
  524. else
  525. if (hs='FATAL') then
  526. w:=scan_f_user_defined
  527. else
  528. if (hs='HINT') then
  529. w:=scan_h_user_defined
  530. else
  531. if (hs='NOTE') then
  532. w:=scan_n_user_defined
  533. else
  534. Message1(scan_w_illegal_directive,hs);
  535. end;
  536. { Only print message when there was no error }
  537. if w<>0 then
  538. begin
  539. current_scanner.skipspace;
  540. if c='''' then
  541. hs:=current_scanner.readquotedstring
  542. else
  543. hs:=current_scanner.readcomment;
  544. Message1(w,hs);
  545. end
  546. else
  547. current_scanner.readcomment;
  548. end;
  549. procedure dir_mode;
  550. begin
  551. if not current_module.in_global then
  552. Message(scan_w_switch_is_global)
  553. else
  554. begin
  555. current_scanner.skipspace;
  556. current_scanner.readstring;
  557. if not current_module.mode_switch_allowed and
  558. not ((m_mac in aktmodeswitches) and (pattern='MACPAS')) then
  559. Message1(scan_e_mode_switch_not_allowed,pattern)
  560. else if SetCompileMode(pattern,false) then
  561. ConsolidateMode
  562. else
  563. Message1(scan_w_illegal_switch,pattern)
  564. end;
  565. current_module.mode_switch_allowed:= false;
  566. end;
  567. procedure dir_mmx;
  568. begin
  569. do_localswitch(cs_mmx);
  570. end;
  571. procedure dir_note;
  572. begin
  573. do_message(scan_n_user_defined);
  574. end;
  575. procedure dir_notes;
  576. begin
  577. do_setverbose('N');
  578. end;
  579. procedure dir_objectpath;
  580. begin
  581. if not current_module.in_global then
  582. Message(scan_w_switch_is_global)
  583. else
  584. begin
  585. current_scanner.skipspace;
  586. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  587. end;
  588. end;
  589. procedure dir_openstrings;
  590. begin
  591. do_delphiswitch('P');
  592. end;
  593. procedure dir_output_format;
  594. begin
  595. if not current_module.in_global then
  596. Message(scan_w_switch_is_global)
  597. else
  598. begin
  599. current_scanner.skipspace;
  600. if set_target_asm_by_string(current_scanner.readid) then
  601. aktoutputformat:=target_asm.id
  602. else
  603. Message1(scan_w_illegal_switch,pattern);
  604. end;
  605. end;
  606. procedure dir_overflowchecks;
  607. begin
  608. do_delphiswitch('Q');
  609. end;
  610. procedure dir_packenum;
  611. var
  612. hs : string;
  613. begin
  614. current_scanner.skipspace;
  615. if not(c in ['0'..'9']) then
  616. begin
  617. hs:=current_scanner.readid;
  618. if (hs='NORMAL') or (hs='DEFAULT') then
  619. aktpackenum:=4
  620. else
  621. Message1(scan_e_illegal_pack_enum, hs);
  622. end
  623. else
  624. begin
  625. case current_scanner.readval of
  626. 1 : aktpackenum:=1;
  627. 2 : aktpackenum:=2;
  628. 4 : aktpackenum:=4;
  629. else
  630. Message1(scan_e_illegal_pack_enum, pattern);
  631. end;
  632. end;
  633. end;
  634. procedure dir_packrecords;
  635. var
  636. hs : string;
  637. begin
  638. current_scanner.skipspace;
  639. if not(c in ['0'..'9']) then
  640. begin
  641. hs:=current_scanner.readid;
  642. { C has the special recordalignmax of -1 }
  643. if (hs='C') then
  644. aktpackrecords:=-1
  645. else
  646. if (hs='NORMAL') or (hs='DEFAULT') then
  647. aktpackrecords:=0
  648. else
  649. Message1(scan_e_illegal_pack_records,hs);
  650. end
  651. else
  652. begin
  653. case current_scanner.readval of
  654. 1 : aktpackrecords:=1;
  655. 2 : aktpackrecords:=2;
  656. 4 : aktpackrecords:=4;
  657. 8 : aktpackrecords:=8;
  658. 16 : aktpackrecords:=16;
  659. 32 : aktpackrecords:=32;
  660. else
  661. Message1(scan_e_illegal_pack_records,pattern);
  662. end;
  663. end;
  664. end;
  665. {$ifdef testvarsets}
  666. procedure dir_packset;
  667. var
  668. hs : string;
  669. begin
  670. current_scanner.skipspace;
  671. if not(c in ['1','2','4']) then
  672. begin
  673. hs:=current_scanner.readid;
  674. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  675. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  676. else
  677. Message(scan_w_only_packset);
  678. end
  679. else
  680. begin
  681. case current_scanner.readval of
  682. 1 : aktsetalloc:=1;
  683. 2 : aktsetalloc:=2;
  684. 4 : aktsetalloc:=4;
  685. else
  686. Message(scan_w_only_packset);
  687. end;
  688. end;
  689. end;
  690. {$ENDIF}
  691. procedure dir_pop;
  692. begin
  693. if localswitchesstackpos < 1 then
  694. Message(scan_e_too_many_pop);
  695. if not localswitcheschanged then
  696. nextaktlocalswitches:=aktlocalswitches;
  697. Dec(localswitchesstackpos);
  698. nextaktlocalswitches:= localswitchesstack[localswitchesstackpos];
  699. localswitcheschanged:=true;
  700. end;
  701. procedure dir_profile;
  702. begin
  703. do_moduleswitch(cs_profile);
  704. { defined/undefine FPC_PROFILE }
  705. if cs_profile in aktmoduleswitches then
  706. def_system_macro('FPC_PROFILE')
  707. else
  708. undef_system_macro('FPC_PROFILE');
  709. end;
  710. procedure dir_push;
  711. begin
  712. if localswitchesstackpos > localswitchesstackmax then
  713. Message(scan_e_too_many_push);
  714. if localswitcheschanged then
  715. begin
  716. aktlocalswitches:=nextaktlocalswitches;
  717. localswitcheschanged:=false;
  718. end;
  719. localswitchesstack[localswitchesstackpos]:= aktlocalswitches;
  720. Inc(localswitchesstackpos);
  721. end;
  722. procedure dir_rangechecks;
  723. begin
  724. do_delphiswitch('R');
  725. end;
  726. procedure dir_referenceinfo;
  727. begin
  728. do_delphiswitch('Y');
  729. end;
  730. procedure dir_resource;
  731. var
  732. s : string;
  733. begin
  734. current_scanner.skipspace;
  735. if scanner.c = '''' then
  736. begin
  737. s:= current_scanner.readquotedstring;
  738. current_scanner.readcomment
  739. end
  740. else
  741. s:= trimspace(current_scanner.readcomment);
  742. { replace * with current module name.
  743. This should always be defined. }
  744. if s[1]='*' then
  745. if Assigned(Current_Module) then
  746. begin
  747. delete(S,1,1);
  748. if m_delphi in aktmodeswitches then
  749. insert(current_module.realmodulename^,S,1)
  750. else
  751. insert(lower(current_module.modulename^),S,1);
  752. end;
  753. s:=AddExtension(FixFileName(s),target_info.resext);
  754. if target_info.res<>res_none then
  755. begin
  756. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  757. if (target_info.res = res_emxbind) and
  758. not (Current_module.ResourceFiles.Empty) then
  759. Message(scan_w_only_one_resourcefile_supported)
  760. else
  761. current_module.resourcefiles.insert(FixFileName(s));
  762. end
  763. else
  764. Message(scan_e_resourcefiles_not_supported);
  765. end;
  766. procedure dir_saturation;
  767. begin
  768. do_localswitch(cs_mmx_saturation);
  769. end;
  770. procedure dir_smartlink;
  771. begin
  772. do_moduleswitch(cs_create_smart);
  773. end;
  774. procedure dir_stackframes;
  775. begin
  776. do_delphiswitch('W');
  777. end;
  778. procedure dir_static;
  779. begin
  780. do_moduleswitch(cs_static_keyword);
  781. end;
  782. procedure dir_stop;
  783. begin
  784. do_message(scan_f_user_defined);
  785. end;
  786. {$ifdef powerpc}
  787. procedure dir_syscall;
  788. var
  789. sctype : string;
  790. begin
  791. if not (target_info.system in [system_powerpc_morphos]) then
  792. comment (V_Warning,'Syscall directive is useless on this target.');
  793. current_scanner.skipspace;
  794. sctype:=current_scanner.readid;
  795. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  796. (sctype='BASESYSV') or (sctype='R12BASE') then
  797. syscall_convention:=sctype
  798. else
  799. comment (V_Warning,'Invalid Syscall directive ignored.');
  800. end;
  801. {$endif}
  802. procedure dir_typedaddress;
  803. begin
  804. do_delphiswitch('T');
  805. end;
  806. procedure dir_typeinfo;
  807. begin
  808. do_delphiswitch('M');
  809. end;
  810. procedure dir_unitpath;
  811. begin
  812. if not current_module.in_global then
  813. Message(scan_w_switch_is_global)
  814. else
  815. with current_scanner,current_module,localunitsearchpath do
  816. begin
  817. skipspace;
  818. AddPath(path^,readcomment,false);
  819. end;
  820. end;
  821. procedure dir_varstringchecks;
  822. begin
  823. do_delphiswitch('V');
  824. end;
  825. procedure dir_version;
  826. var
  827. major, minor, revision : longint;
  828. error : integer;
  829. begin
  830. if not (target_info.system in [system_i386_os2,system_i386_emx,
  831. system_i386_win32,system_i386_netware,system_i386_wdosx,
  832. system_i386_netwlibc]) then
  833. begin
  834. Message(scan_n_version_not_support);
  835. exit;
  836. end;
  837. if (compile_level<>1) then
  838. Message(scan_n_only_exe_version)
  839. else
  840. begin
  841. { change description global var in all cases }
  842. { it not used but in win32, os2 and netware }
  843. current_scanner.skipspace;
  844. { we should only accept Major.Minor format for win32 and os2 }
  845. current_scanner.readnumber;
  846. major:=0;
  847. minor:=0;
  848. revision:=0;
  849. val(pattern,major,error);
  850. if (error<>0) or (major > high(word)) or (major < 0) then
  851. begin
  852. Message1(scan_w_wrong_version_ignored,pattern);
  853. exit;
  854. end;
  855. if c='.' then
  856. begin
  857. current_scanner.readchar;
  858. current_scanner.readnumber;
  859. val(pattern,minor,error);
  860. if (error<>0) or (minor > high(word)) or (minor < 0) then
  861. begin
  862. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  863. exit;
  864. end;
  865. if (c='.') and
  866. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  867. begin
  868. current_scanner.readchar;
  869. current_scanner.readnumber;
  870. val(pattern,revision,error);
  871. if (error<>0) or (revision > high(word)) or (revision < 0) then
  872. begin
  873. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  874. exit;
  875. end;
  876. dllmajor:=word(major);
  877. dllminor:=word(minor);
  878. dllrevision:=word(revision);
  879. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  880. end
  881. else
  882. begin
  883. dllmajor:=word(major);
  884. dllminor:=word(minor);
  885. dllversion:=tostr(major)+'.'+tostr(minor);
  886. end;
  887. end
  888. else
  889. dllversion:=tostr(major);
  890. end;
  891. end;
  892. procedure dir_wait;
  893. var
  894. had_info : boolean;
  895. begin
  896. had_info:=(status.verbosity and V_Info)<>0;
  897. { this message should allways appear !! }
  898. status.verbosity:=status.verbosity or V_Info;
  899. Message(scan_i_press_enter);
  900. readln;
  901. If not(had_info) then
  902. status.verbosity:=status.verbosity and (not V_Info);
  903. end;
  904. procedure dir_warning;
  905. begin
  906. do_message(scan_w_user_defined);
  907. end;
  908. procedure dir_warnings;
  909. begin
  910. do_setverbose('W');
  911. end;
  912. procedure dir_writeableconst;
  913. begin
  914. do_delphiswitch('J');
  915. end;
  916. procedure dir_z1;
  917. begin
  918. aktpackenum:=1;
  919. end;
  920. procedure dir_z2;
  921. begin
  922. aktpackenum:=2;
  923. end;
  924. procedure dir_z4;
  925. begin
  926. aktpackenum:=4;
  927. end;
  928. procedure dir_externalsym;
  929. begin
  930. end;
  931. procedure dir_nodefine;
  932. begin
  933. end;
  934. procedure dir_hppemit;
  935. begin
  936. end;
  937. procedure dir_weakpackageunit;
  938. begin
  939. end;
  940. procedure dir_codepage;
  941. var
  942. s : string;
  943. begin
  944. if not current_module.in_global then
  945. Message(scan_w_switch_is_global)
  946. else
  947. begin
  948. current_scanner.skipspace;
  949. s:=current_scanner.readcomment;
  950. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  951. aktsourcecodepage:='utf8'
  952. else if not(cpavailable(s)) then
  953. Message1(option_code_page_not_available,s)
  954. else
  955. aktsourcecodepage:=s;
  956. end;
  957. end;
  958. procedure dir_coperators;
  959. begin
  960. do_moduleswitch(cs_support_c_operators);
  961. end;
  962. {****************************************************************************
  963. Initialize Directives
  964. ****************************************************************************}
  965. procedure InitScannerDirectives;
  966. begin
  967. AddDirective('ALIGN',directive_all, @dir_align);
  968. {$ifdef m68k}
  969. AddDirective('APPID',directive_all, @dir_appid);
  970. AddDirective('APPNAME',directive_all, @dir_appname);
  971. {$endif m68k}
  972. AddDirective('APPTYPE',directive_all, @dir_apptype);
  973. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  974. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  975. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  976. AddDirective('CALLING',directive_all, @dir_calling);
  977. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  978. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  979. AddDirective('COPERATORS',directive_all, @dir_coperators);
  980. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  981. AddDirective('D',directive_all, @dir_description);
  982. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  983. AddDirective('DESCRIPTION',directive_all, @dir_description);
  984. AddDirective('ERROR',directive_all, @dir_error);
  985. AddDirective('ERRORC',directive_mac, @dir_error);
  986. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  987. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  988. AddDirective('FATAL',directive_all, @dir_fatal);
  989. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  990. AddDirective('GOTO',directive_all, @dir_goto);
  991. AddDirective('HINT',directive_all, @dir_hint);
  992. AddDirective('HINTS',directive_all, @dir_hints);
  993. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  994. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  995. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  996. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  997. AddDirective('INFO',directive_all, @dir_info);
  998. AddDirective('INLINE',directive_all, @dir_inline);
  999. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1000. AddDirective('L',directive_all, @dir_link);
  1001. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1002. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1003. AddDirective('LINK',directive_all, @dir_link);
  1004. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1005. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1006. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1007. AddDirective('M',directive_all, @dir_memory);
  1008. AddDirective('MACRO',directive_all, @dir_macro);
  1009. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1010. AddDirective('MEMORY',directive_all, @dir_memory);
  1011. AddDirective('MESSAGE',directive_all, @dir_message);
  1012. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1013. AddDirective('MMX',directive_all, @dir_mmx);
  1014. AddDirective('MODE',directive_all, @dir_mode);
  1015. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1016. AddDirective('NOTE',directive_all, @dir_note);
  1017. AddDirective('NOTES',directive_all, @dir_notes);
  1018. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1019. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1020. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1021. AddDirective('OUTPUT_FORMAT',directive_all, @dir_output_format);
  1022. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1023. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1024. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1025. {$IFDEF TestVarsets}
  1026. AddDirective('PACKSET',directive_all, @dir_packset);
  1027. {$ENDIF}
  1028. AddDirective('POP',directive_mac, @dir_pop);
  1029. AddDirective('PROFILE',directive_all, @dir_profile);
  1030. AddDirective('PUSH',directive_mac, @dir_push);
  1031. AddDirective('R',directive_all, @dir_resource);
  1032. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1033. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1034. AddDirective('RESOURCE',directive_all, @dir_resource);
  1035. AddDirective('SATURATION',directive_all, @dir_saturation);
  1036. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1037. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1038. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1039. AddDirective('STATIC',directive_all, @dir_static);
  1040. AddDirective('STOP',directive_all, @dir_stop);
  1041. {$ifdef powerpc}
  1042. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1043. {$endif powerpc}
  1044. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1045. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1046. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1047. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1048. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1049. AddDirective('VERSION',directive_all, @dir_version);
  1050. AddDirective('WAIT',directive_all, @dir_wait);
  1051. AddDirective('WARN',directive_all, @dir_warnings);
  1052. AddDirective('WARNING',directive_all, @dir_warning);
  1053. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1054. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1055. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1056. AddDirective('Z1',directive_all, @dir_z1);
  1057. AddDirective('Z2',directive_all, @dir_z2);
  1058. AddDirective('Z4',directive_all, @dir_z4);
  1059. end;
  1060. begin
  1061. localswitchesstackpos:= 0;
  1062. end.