scandir.pas 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. unit scandir;
  19. {$i fpcdefs.inc}
  20. interface
  21. procedure InitScannerDirectives;
  22. implementation
  23. uses
  24. cutils,
  25. globtype,globals,systems,widestr,
  26. verbose,comphook,
  27. scanner,switches,
  28. fmodule,
  29. rabase;
  30. {*****************************************************************************
  31. Helpers
  32. *****************************************************************************}
  33. procedure do_delphiswitch(sw:char);
  34. var
  35. state : char;
  36. begin
  37. { c contains the next char, a + or - would be fine }
  38. state:=current_scanner.readstate;
  39. if state in ['-','+'] then
  40. HandleSwitch(sw,state);
  41. end;
  42. procedure do_setverbose(flag:char);
  43. var
  44. state : char;
  45. begin
  46. { support ON/OFF }
  47. state:=current_scanner.ReadState;
  48. SetVerbosity(flag+state);
  49. end;
  50. procedure do_moduleswitch(sw:tmoduleswitch);
  51. var
  52. state : char;
  53. begin
  54. state:=current_scanner.readstate;
  55. if (sw<>cs_modulenone) and (state in ['-','+']) then
  56. begin
  57. if state='-' then
  58. exclude(aktmoduleswitches,sw)
  59. else
  60. include(aktmoduleswitches,sw);
  61. end;
  62. end;
  63. procedure do_localswitch(sw:tlocalswitch);
  64. var
  65. state : char;
  66. begin
  67. state:=current_scanner.readstate;
  68. if (sw<>cs_localnone) and (state in ['-','+']) then
  69. begin
  70. if not localswitcheschanged then
  71. nextaktlocalswitches:=aktlocalswitches;
  72. if state='-' then
  73. exclude(nextaktlocalswitches,sw)
  74. else
  75. include(nextaktlocalswitches,sw);
  76. localswitcheschanged:=true;
  77. end;
  78. end;
  79. procedure do_message(w:integer);
  80. begin
  81. current_scanner.skipspace;
  82. Message1(w,current_scanner.readcomment);
  83. end;
  84. {*****************************************************************************
  85. Directive Callbacks
  86. *****************************************************************************}
  87. procedure dir_align;
  88. var
  89. hs : string;
  90. begin
  91. current_scanner.skipspace;
  92. if not(c in ['0'..'9']) then
  93. begin
  94. { Support also the ON and OFF as switch }
  95. hs:=current_scanner.readid;
  96. if (hs='ON') then
  97. aktpackrecords:=4
  98. else if (hs='OFF') then
  99. aktpackrecords:=1
  100. else if m_mac in aktmodeswitches then
  101. begin
  102. { Support switches used in Apples Universal Interfaces}
  103. if (hs='MAC68K') then
  104. aktpackrecords:=2
  105. else if (hs='POWER') then
  106. aktpackrecords:=4
  107. else if (hs='RESET') then
  108. aktpackrecords:=0
  109. end
  110. else
  111. Message(scan_w_only_pack_records);
  112. end
  113. else
  114. begin
  115. case current_scanner.readval of
  116. 1 : aktpackrecords:=1;
  117. 2 : aktpackrecords:=2;
  118. 4 : aktpackrecords:=4;
  119. 8 : aktpackrecords:=8;
  120. 16 : aktpackrecords:=16;
  121. 32 : aktpackrecords:=32;
  122. else
  123. Message(scan_w_only_pack_records);
  124. end;
  125. end;
  126. end;
  127. procedure dir_asmmode;
  128. var
  129. s : string;
  130. begin
  131. current_scanner.skipspace;
  132. s:=current_scanner.readid;
  133. If Inside_asm_statement then
  134. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  135. if s='DEFAULT' then
  136. aktasmmode:=initasmmode
  137. else
  138. if not SetAsmReadMode(s,aktasmmode) then
  139. Message1(scan_e_illegal_asmmode_specifier,s);
  140. end;
  141. {$ifdef m68k}
  142. procedure dir_appid;
  143. begin
  144. if target_info.system<>system_m68k_palmos then
  145. Message(scan_w_appid_not_support);
  146. { change description global var in all cases }
  147. { it not used but in win32 and os2 }
  148. current_scanner.skipspace;
  149. palmos_applicationid:=current_scanner.readcomment;
  150. end;
  151. procedure dir_appname;
  152. begin
  153. if target_info.system<>system_m68k_palmos then
  154. Message(scan_w_appname_not_support);
  155. { change description global var in all cases }
  156. { it not used but in win32 and os2 }
  157. current_scanner.skipspace;
  158. palmos_applicationname:=current_scanner.readcomment;
  159. end;
  160. {$endif m68k}
  161. procedure dir_apptype;
  162. var
  163. hs : string;
  164. begin
  165. if not (target_info.system in [system_i386_win32,system_i386_os2,
  166. system_i386_emx, system_powerpc_macos]) then
  167. Message(scan_w_app_type_not_support);
  168. if not current_module.in_global then
  169. Message(scan_w_switch_is_global)
  170. else
  171. begin
  172. current_scanner.skipspace;
  173. hs:=current_scanner.readid;
  174. if hs='GUI' then
  175. apptype:=app_gui
  176. else if hs='CONSOLE' then
  177. apptype:=app_cui
  178. else if (hs='FS') and (target_info.system in [system_i386_os2,
  179. system_i386_emx]) then
  180. apptype:=app_fs
  181. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  182. apptype:=app_tool
  183. else
  184. Message1(scan_w_unsupported_app_type,hs);
  185. end;
  186. end;
  187. procedure dir_calling;
  188. var
  189. hs : string;
  190. begin
  191. current_scanner.skipspace;
  192. hs:=current_scanner.readid;
  193. if not SetAktProcCall(hs,false) then
  194. Message1(parser_w_unknown_proc_directive_ignored,hs);
  195. end;
  196. procedure dir_objectchecks;
  197. begin
  198. do_localswitch(cs_check_object);
  199. end;
  200. procedure dir_assertions;
  201. begin
  202. do_delphiswitch('C');
  203. end;
  204. procedure dir_booleval;
  205. begin
  206. do_delphiswitch('B');
  207. end;
  208. procedure dir_debuginfo;
  209. begin
  210. do_delphiswitch('D');
  211. end;
  212. procedure dir_description;
  213. begin
  214. if not (target_info.system in [system_i386_os2,system_i386_emx,
  215. system_i386_win32,system_i386_netware,system_i386_wdosx]) then
  216. Message(scan_w_description_not_support);
  217. { change description global var in all cases }
  218. { it not used but in win32, os2 and netware }
  219. current_scanner.skipspace;
  220. description:=current_scanner.readcomment;
  221. end;
  222. procedure dir_screenname; {ad}
  223. begin
  224. if target_info.system <> system_i386_netware then
  225. {Message(scan_w_decription_not_support);}
  226. comment (V_Warning,'Screenname only supported for target netware');
  227. current_scanner.skipspace;
  228. nwscreenname:=current_scanner.readcomment;
  229. end;
  230. procedure dir_threadname; {ad}
  231. begin
  232. if target_info.system <> system_i386_netware then
  233. {Message(scan_w_decription_not_support);}
  234. comment (V_Warning,'Threadname only supported for target netware');
  235. current_scanner.skipspace;
  236. nwthreadname:=current_scanner.readcomment;
  237. end;
  238. procedure dir_copyright; {ad}
  239. begin
  240. if target_info.system <> system_i386_netware then
  241. {Message(scan_w_decription_not_support);}
  242. comment (V_Warning,'Copyright only supported for target netware');
  243. current_scanner.skipspace;
  244. nwcopyright:=current_scanner.readcomment;
  245. end;
  246. procedure dir_error;
  247. begin
  248. do_message(scan_e_user_defined);
  249. end;
  250. procedure dir_extendedsyntax;
  251. begin
  252. do_delphiswitch('X');
  253. end;
  254. procedure dir_fatal;
  255. begin
  256. do_message(scan_f_user_defined);
  257. end;
  258. procedure dir_fputype;
  259. begin
  260. current_scanner.skipspace;
  261. if not(SetFPUType(upper(current_scanner.readcomment),false)) then
  262. comment(V_Error,'Illegal FPU type');
  263. end;
  264. procedure dir_goto;
  265. begin
  266. do_moduleswitch(cs_support_goto);
  267. end;
  268. procedure dir_hint;
  269. begin
  270. do_message(scan_h_user_defined);
  271. end;
  272. procedure dir_hints;
  273. begin
  274. do_setverbose('H');
  275. end;
  276. procedure dir_implicitexceptions;
  277. begin
  278. do_moduleswitch(cs_implicit_exceptions);
  279. end;
  280. procedure dir_includepath;
  281. begin
  282. if not current_module.in_global then
  283. Message(scan_w_switch_is_global)
  284. else
  285. begin
  286. current_scanner.skipspace;
  287. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  288. end;
  289. end;
  290. procedure dir_info;
  291. begin
  292. do_message(scan_i_user_defined);
  293. end;
  294. procedure dir_inline;
  295. begin
  296. do_moduleswitch(cs_support_inline);
  297. end;
  298. procedure dir_interfaces;
  299. var
  300. hs : string;
  301. begin
  302. {corba/com/default}
  303. current_scanner.skipspace;
  304. hs:=current_scanner.readid;
  305. if (hs='CORBA') then
  306. aktinterfacetype:=it_interfacecorba
  307. else if (hs='COM') then
  308. aktinterfacetype:=it_interfacecom
  309. else if (hs='DEFAULT') then
  310. aktinterfacetype:=initinterfacetype
  311. else
  312. Message(scan_e_invalid_interface_type);
  313. end;
  314. procedure dir_iochecks;
  315. begin
  316. do_delphiswitch('I');
  317. end;
  318. procedure dir_librarypath;
  319. begin
  320. if not current_module.in_global then
  321. Message(scan_w_switch_is_global)
  322. else
  323. begin
  324. current_scanner.skipspace;
  325. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  326. end;
  327. end;
  328. procedure dir_link;
  329. var
  330. s : string;
  331. begin
  332. current_scanner.skipspace;
  333. s:=AddExtension(FixFileName(current_scanner.readcomment),target_info.objext);
  334. current_module.linkotherofiles.add(s,link_allways);
  335. end;
  336. procedure dir_linklib;
  337. type
  338. tLinkMode=(lm_shared,lm_static);
  339. var
  340. s : string;
  341. quote : char;
  342. libname,
  343. linkmodestr : string;
  344. p : longint;
  345. linkMode : tLinkMode;
  346. begin
  347. current_scanner.skipspace;
  348. s:=current_scanner.readcomment;
  349. p:=pos(',',s);
  350. if p=0 then
  351. begin
  352. libname:=TrimSpace(s);
  353. linkmodeStr:='';
  354. end
  355. else
  356. begin
  357. libname:=TrimSpace(copy(s,1,p-1));
  358. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  359. end;
  360. if (libname='') or (libname='''''') or (libname='""') then
  361. exit;
  362. { get linkmode, default is shared linking }
  363. if linkModeStr='STATIC' then
  364. linkmode:=lm_static
  365. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  366. linkmode:=lm_shared
  367. else
  368. begin
  369. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  370. exit;
  371. end;
  372. { create library name }
  373. if libname[1] in ['''','"'] then
  374. begin
  375. quote:=libname[1];
  376. Delete(libname,1,1);
  377. p:=pos(quote,libname);
  378. if p>0 then
  379. Delete(libname,p,1);
  380. end;
  381. { add to the list of libraries to link }
  382. if linkMode=lm_static then
  383. current_module.linkOtherStaticLibs.add(FixFileName(libname),link_allways)
  384. else
  385. current_module.linkOtherSharedLibs.add(FixFileName(libname),link_allways);
  386. end;
  387. procedure dir_localsymbols;
  388. begin
  389. do_delphiswitch('L');
  390. end;
  391. procedure dir_longstrings;
  392. begin
  393. do_delphiswitch('H');
  394. end;
  395. procedure dir_macro;
  396. begin
  397. do_moduleswitch(cs_support_macro);
  398. end;
  399. procedure dir_maxfpuregisters;
  400. var
  401. l : integer;
  402. hs : string;
  403. begin
  404. current_scanner.skipspace;
  405. if not(c in ['0'..'9']) then
  406. begin
  407. hs:=current_scanner.readid;
  408. if (hs='NORMAL') or (hs='DEFAULT') then
  409. aktmaxfpuregisters:=-1
  410. else
  411. Message(scan_e_invalid_maxfpureg_value);
  412. end
  413. else
  414. begin
  415. l:=current_scanner.readval;
  416. case l of
  417. 0..8:
  418. aktmaxfpuregisters:=l;
  419. else
  420. Message(scan_e_invalid_maxfpureg_value);
  421. end;
  422. end;
  423. end;
  424. procedure dir_memory;
  425. var
  426. l : longint;
  427. begin
  428. current_scanner.skipspace;
  429. l:=current_scanner.readval;
  430. if l>1024 then
  431. stacksize:=l;
  432. current_scanner.skipspace;
  433. if c=',' then
  434. begin
  435. current_scanner.readchar;
  436. current_scanner.skipspace;
  437. l:=current_scanner.readval;
  438. if l>1024 then
  439. heapsize:=l;
  440. end;
  441. if c=',' then
  442. begin
  443. current_scanner.readchar;
  444. current_scanner.skipspace;
  445. l:=current_scanner.readval;
  446. { Ignore this value, because the limit is set by the OS
  447. info and shouldn't be changed by the user (PFV) }
  448. end;
  449. end;
  450. procedure dir_message;
  451. var
  452. hs : string;
  453. w : longint;
  454. begin
  455. w:=0;
  456. current_scanner.skipspace;
  457. { Message level specified? }
  458. if c='''' then
  459. w:=scan_n_user_defined
  460. else
  461. begin
  462. hs:=current_scanner.readid;
  463. if (hs='WARN') or (hs='WARNING') then
  464. w:=scan_w_user_defined
  465. else
  466. if (hs='ERROR') then
  467. w:=scan_e_user_defined
  468. else
  469. if (hs='FATAL') then
  470. w:=scan_f_user_defined
  471. else
  472. if (hs='HINT') then
  473. w:=scan_h_user_defined
  474. else
  475. if (hs='NOTE') then
  476. w:=scan_n_user_defined
  477. else
  478. Message1(scan_w_illegal_directive,hs);
  479. end;
  480. { Only print message when there was no error }
  481. if w<>0 then
  482. begin
  483. current_scanner.skipspace;
  484. if c='''' then
  485. hs:=current_scanner.readquotedstring
  486. else
  487. hs:=current_scanner.readcomment;
  488. Message1(w,hs);
  489. end
  490. else
  491. current_scanner.readcomment;
  492. end;
  493. procedure dir_mode;
  494. begin
  495. if not current_module.in_global then
  496. Message(scan_w_switch_is_global)
  497. else
  498. begin
  499. current_scanner.skipspace;
  500. current_scanner.readstring;
  501. if not SetCompileMode(pattern,false) then
  502. Message1(scan_w_illegal_switch,pattern);
  503. end;
  504. end;
  505. procedure dir_mmx;
  506. begin
  507. do_localswitch(cs_mmx);
  508. end;
  509. procedure dir_note;
  510. begin
  511. do_message(scan_n_user_defined);
  512. end;
  513. procedure dir_notes;
  514. begin
  515. do_setverbose('N');
  516. end;
  517. procedure dir_objectpath;
  518. begin
  519. if not current_module.in_global then
  520. Message(scan_w_switch_is_global)
  521. else
  522. begin
  523. current_scanner.skipspace;
  524. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  525. end;
  526. end;
  527. procedure dir_openstrings;
  528. begin
  529. do_delphiswitch('P');
  530. end;
  531. procedure dir_output_format;
  532. begin
  533. if not current_module.in_global then
  534. Message(scan_w_switch_is_global)
  535. else
  536. begin
  537. current_scanner.skipspace;
  538. if set_target_asm_by_string(current_scanner.readid) then
  539. aktoutputformat:=target_asm.id
  540. else
  541. Message1(scan_w_illegal_switch,pattern);
  542. end;
  543. end;
  544. procedure dir_overflowchecks;
  545. begin
  546. do_delphiswitch('Q');
  547. end;
  548. procedure dir_packenum;
  549. var
  550. hs : string;
  551. begin
  552. current_scanner.skipspace;
  553. if not(c in ['0'..'9']) then
  554. begin
  555. hs:=current_scanner.readid;
  556. if (hs='NORMAL') or (hs='DEFAULT') then
  557. aktpackenum:=4
  558. else
  559. Message(scan_w_only_pack_enum);
  560. end
  561. else
  562. begin
  563. case current_scanner.readval of
  564. 1 : aktpackenum:=1;
  565. 2 : aktpackenum:=2;
  566. 4 : aktpackenum:=4;
  567. else
  568. Message(scan_w_only_pack_enum);
  569. end;
  570. end;
  571. end;
  572. procedure dir_packrecords;
  573. var
  574. hs : string;
  575. begin
  576. current_scanner.skipspace;
  577. if not(c in ['0'..'9']) then
  578. begin
  579. hs:=current_scanner.readid;
  580. { C has the special recordalignmax of -1 }
  581. if (hs='C') then
  582. aktpackrecords:=-1
  583. else
  584. if (hs='NORMAL') or (hs='DEFAULT') then
  585. aktpackrecords:=0
  586. else
  587. Message(scan_w_only_pack_records);
  588. end
  589. else
  590. begin
  591. case current_scanner.readval of
  592. 1 : aktpackrecords:=1;
  593. 2 : aktpackrecords:=2;
  594. 4 : aktpackrecords:=4;
  595. 8 : aktpackrecords:=8;
  596. 16 : aktpackrecords:=16;
  597. 32 : aktpackrecords:=32;
  598. else
  599. Message(scan_w_only_pack_records);
  600. end;
  601. end;
  602. end;
  603. {$ifdef testvarsets}
  604. procedure dir_packset;
  605. var
  606. hs : string;
  607. begin
  608. current_scanner.skipspace;
  609. if not(c in ['1','2','4']) then
  610. begin
  611. hs:=current_scanner.readid;
  612. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  613. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  614. else
  615. Message(scan_w_only_packset);
  616. end
  617. else
  618. begin
  619. case current_scanner.readval of
  620. 1 : aktsetalloc:=1;
  621. 2 : aktsetalloc:=2;
  622. 4 : aktsetalloc:=4;
  623. else
  624. Message(scan_w_only_packset);
  625. end;
  626. end;
  627. end;
  628. {$ENDIF}
  629. procedure dir_profile;
  630. var
  631. mac : tmacro;
  632. begin
  633. do_moduleswitch(cs_profile);
  634. { defined/undefine FPC_PROFILE }
  635. mac:=tmacro(current_scanner.macros.search('FPC_PROFILE'));
  636. if not assigned(mac) then
  637. begin
  638. mac:=tmacro.create('FPC_PROFILE');
  639. current_scanner.macros.insert(mac);
  640. end;
  641. mac.defined:=(cs_profile in aktmoduleswitches);
  642. end;
  643. procedure dir_rangechecks;
  644. begin
  645. do_delphiswitch('R');
  646. end;
  647. procedure dir_referenceinfo;
  648. begin
  649. do_delphiswitch('Y');
  650. end;
  651. procedure dir_resource;
  652. var
  653. s : string;
  654. begin
  655. current_scanner.skipspace;
  656. s:=current_scanner.readcomment;
  657. { replace * with current module name.
  658. This should always be defined. }
  659. if s[1]='*' then
  660. if Assigned(Current_Module) then
  661. begin
  662. delete(S,1,1);
  663. insert(lower(current_module.modulename^),S,1);
  664. end;
  665. s:=AddExtension(FixFileName(s),target_info.resext);
  666. if target_info.res<>res_none then
  667. if (target_info.res = res_emxbind) and
  668. not (Current_module.ResourceFiles.Empty) then
  669. Message(scan_w_only_one_resourcefile_supported)
  670. else
  671. current_module.resourcefiles.insert(FixFileName(s))
  672. else
  673. Message(scan_e_resourcefiles_not_supported);
  674. end;
  675. procedure dir_saturation;
  676. begin
  677. do_localswitch(cs_mmx_saturation);
  678. end;
  679. procedure dir_smartlink;
  680. begin
  681. do_moduleswitch(cs_create_smart);
  682. end;
  683. procedure dir_stackframes;
  684. begin
  685. do_delphiswitch('W');
  686. end;
  687. procedure dir_static;
  688. begin
  689. do_moduleswitch(cs_static_keyword);
  690. end;
  691. procedure dir_stop;
  692. begin
  693. do_message(scan_f_user_defined);
  694. end;
  695. procedure dir_threading;
  696. var
  697. mac : tmacro;
  698. begin
  699. do_moduleswitch(cs_threading);
  700. { defined/undefine FPC_THREADING }
  701. mac:=tmacro(current_scanner.macros.search('FPC_THREADING'));
  702. if not assigned(mac) then
  703. begin
  704. mac:=tmacro.create('FPC_THREADING');
  705. current_scanner.macros.insert(mac);
  706. end;
  707. mac.defined:=(cs_threading in aktmoduleswitches);
  708. end;
  709. procedure dir_typedaddress;
  710. begin
  711. do_delphiswitch('T');
  712. end;
  713. procedure dir_typeinfo;
  714. begin
  715. do_delphiswitch('M');
  716. end;
  717. procedure dir_unitpath;
  718. begin
  719. if not current_module.in_global then
  720. Message(scan_w_switch_is_global)
  721. else
  722. with current_scanner,current_module,localunitsearchpath do
  723. begin
  724. skipspace;
  725. AddPath(path^,readcomment,false);
  726. end;
  727. end;
  728. procedure dir_varstringchecks;
  729. begin
  730. do_delphiswitch('V');
  731. end;
  732. procedure dir_version;
  733. var
  734. major, minor, revision : longint;
  735. error : integer;
  736. begin
  737. if not (target_info.system in [system_i386_os2,system_i386_emx,
  738. system_i386_win32,system_i386_netware,system_i386_wdosx]) then
  739. begin
  740. Message(scan_n_version_not_support);
  741. exit;
  742. end;
  743. if (compile_level<>1) then
  744. Message(scan_n_only_exe_version)
  745. else
  746. begin
  747. { change description global var in all cases }
  748. { it not used but in win32, os2 and netware }
  749. current_scanner.skipspace;
  750. { we should only accept Major.Minor format for win32 and os2 }
  751. current_scanner.readnumber;
  752. major:=0;
  753. minor:=0;
  754. revision:=0;
  755. valint(pattern,major,error);
  756. if (error<>0) or (major > high(word)) or (major < 0) then
  757. begin
  758. Message1(scan_w_wrong_version_ignored,pattern);
  759. exit;
  760. end;
  761. if c='.' then
  762. begin
  763. current_scanner.readchar;
  764. current_scanner.readnumber;
  765. valint(pattern,minor,error);
  766. if (error<>0) or (minor > high(word)) or (minor < 0) then
  767. begin
  768. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  769. exit;
  770. end;
  771. if (c='.') and
  772. (target_info.system = system_i386_netware) then
  773. begin
  774. current_scanner.readchar;
  775. current_scanner.readnumber;
  776. valint(pattern,revision,error);
  777. if (error<>0) or (revision > high(word)) or (revision < 0) then
  778. begin
  779. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  780. exit;
  781. end;
  782. dllmajor:=word(major);
  783. dllminor:=word(minor);
  784. dllrevision:=word(revision);
  785. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  786. end
  787. else
  788. begin
  789. dllmajor:=word(major);
  790. dllminor:=word(minor);
  791. dllversion:=tostr(major)+'.'+tostr(minor);
  792. end;
  793. end
  794. else
  795. dllversion:=tostr(major);
  796. end;
  797. end;
  798. procedure dir_wait;
  799. var
  800. had_info : boolean;
  801. begin
  802. had_info:=(status.verbosity and V_Info)<>0;
  803. { this message should allways appear !! }
  804. status.verbosity:=status.verbosity or V_Info;
  805. Message(scan_i_press_enter);
  806. readln;
  807. If not(had_info) then
  808. status.verbosity:=status.verbosity and (not V_Info);
  809. end;
  810. procedure dir_warning;
  811. begin
  812. do_message(scan_w_user_defined);
  813. end;
  814. procedure dir_warnings;
  815. begin
  816. do_setverbose('W');
  817. end;
  818. procedure dir_writeableconst;
  819. begin
  820. do_delphiswitch('J');
  821. end;
  822. procedure dir_z1;
  823. begin
  824. aktpackenum:=1;
  825. end;
  826. procedure dir_z2;
  827. begin
  828. aktpackenum:=2;
  829. end;
  830. procedure dir_z4;
  831. begin
  832. aktpackenum:=4;
  833. end;
  834. procedure dir_externalsym;
  835. begin
  836. end;
  837. procedure dir_codepage;
  838. var
  839. s : string;
  840. begin
  841. if not current_module.in_global then
  842. Message(scan_w_switch_is_global)
  843. else
  844. begin
  845. current_scanner.skipspace;
  846. s:=current_scanner.readcomment;
  847. if not(cpavailable(s)) then
  848. Message1(option_code_page_not_available,s)
  849. else
  850. aktsourcecodepage:=s;
  851. end;
  852. end;
  853. {****************************************************************************
  854. Initialize Directives
  855. ****************************************************************************}
  856. procedure InitScannerDirectives;
  857. begin
  858. AddDirective('ALIGN',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_align);
  859. {$ifdef m68k}
  860. AddDirective('APPID',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_appid);
  861. AddDirective('APPNAME',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_appname);
  862. {$endif m68k}
  863. AddDirective('APPTYPE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_apptype);
  864. AddDirective('ASMMODE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_asmmode);
  865. AddDirective('ASSERTIONS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_assertions);
  866. AddDirective('BOOLEVAL',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_booleval);
  867. AddDirective('CALLING',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_calling);
  868. AddDirective('CODEPAGE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_codepage);
  869. AddDirective('COPYRIGHT',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_copyright);
  870. AddDirective('D',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_description);
  871. AddDirective('DEBUGINFO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_debuginfo);
  872. AddDirective('DESCRIPTION',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_description);
  873. AddDirective('ERROR',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_error);
  874. AddDirective('EXTENDEDSYNTAX',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_extendedsyntax);
  875. AddDirective('EXTERNALSYM',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_externalsym);
  876. AddDirective('FATAL',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_fatal);
  877. AddDirective('FPUTYPE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_fputype);
  878. AddDirective('GOTO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_goto);
  879. AddDirective('HINT',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_hint);
  880. AddDirective('HINTS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_hints);
  881. AddDirective('IOCHECKS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_iochecks);
  882. AddDirective('IMPLICITEXCEPTIONS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_implicitexceptions);
  883. AddDirective('INCLUDEPATH',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_includepath);
  884. AddDirective('INFO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_info);
  885. AddDirective('INLINE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_inline);
  886. AddDirective('INTERFACES',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_interfaces);
  887. AddDirective('L',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_link);
  888. AddDirective('LIBRARYPATH',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_librarypath);
  889. AddDirective('LINK',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_link);
  890. AddDirective('LINKLIB',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_linklib);
  891. AddDirective('LOCALSYMBOLS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_localsymbols);
  892. AddDirective('LONGSTRINGS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_longstrings);
  893. AddDirective('M',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_memory);
  894. AddDirective('MACRO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_macro);
  895. AddDirective('MAXFPUREGISTERS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_maxfpuregisters);
  896. AddDirective('MEMORY',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_memory);
  897. AddDirective('MESSAGE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_message);
  898. AddDirective('MINENUMSIZE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_packenum);
  899. AddDirective('MMX',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_mmx);
  900. AddDirective('MODE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_mode);
  901. AddDirective('NOTE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_note);
  902. AddDirective('NOTES',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_notes);
  903. AddDirective('OBJECTCHECKS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_objectchecks);
  904. AddDirective('OBJECTPATH',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_objectpath);
  905. AddDirective('OPENSTRINGS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_openstrings);
  906. AddDirective('OUTPUT_FORMAT',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_output_format);
  907. AddDirective('OVERFLOWCHECKS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_overflowchecks);
  908. AddDirective('PACKENUM',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_packenum);
  909. AddDirective('PACKRECORDS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_packrecords);
  910. {$IFDEF TestVarsets}
  911. AddDirective('PACKSET',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_packset);
  912. {$ENDIF}
  913. AddDirective('PROFILE',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_profile);
  914. AddDirective('R',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_resource);
  915. AddDirective('RANGECHECKS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_rangechecks);
  916. AddDirective('REFERENCEINFO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_referenceinfo);
  917. AddDirective('SATURATION',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_saturation);
  918. AddDirective('SCREENNAME',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_screenname);
  919. AddDirective('SMARTLINK',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_smartlink);
  920. AddDirective('STACKFRAMES',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_stackframes);
  921. AddDirective('STATIC',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_static);
  922. AddDirective('STOP',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_stop);
  923. AddDirective('THREADING',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_threading);
  924. AddDirective('THREADNAME',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_threadname);
  925. AddDirective('TYPEDADDRESS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_typedaddress);
  926. AddDirective('TYPEINFO',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_typeinfo);
  927. AddDirective('UNITPATH',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_unitpath);
  928. AddDirective('VARSTRINGCHECKS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_varstringchecks);
  929. AddDirective('VERSION',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_version);
  930. AddDirective('WAIT',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_wait);
  931. AddDirective('WARNING',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_warning);
  932. AddDirective('WARNINGS',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_warnings);
  933. AddDirective('WRITEABLECONST',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_writeableconst);
  934. AddDirective('Z1',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_z1);
  935. AddDirective('Z2',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_z2);
  936. AddDirective('Z4',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_z4);
  937. end;
  938. end.
  939. {
  940. $Log$
  941. Revision 1.35 2004-05-19 23:29:56 peter
  942. * $message directive compatible with delphi
  943. Revision 1.34 2004/05/11 22:51:34 olle
  944. * Performanceimprovement
  945. Revision 1.33 2004/05/11 18:30:50 olle
  946. + mode macpas: support for Apples align directives
  947. Revision 1.32 2004/04/04 18:46:09 olle
  948. + added $APPTYPE TOOL for MPW tools on MacOS
  949. Revision 1.31 2004/03/14 20:08:37 peter
  950. * packrecords fixed for settings from $PACKRECORDS
  951. * default packrecords now uses value 0 and uses info from aligment
  952. structure only, initpackrecords removed
  953. Revision 1.30 2004/01/28 22:16:31 peter
  954. * more record alignment fixes
  955. Revision 1.29 2003/12/25 01:07:09 florian
  956. + $fputype directive support
  957. + single data type operations with sse unit
  958. * fixed more x86-64 stuff
  959. Revision 1.28 2003/11/12 16:05:39 florian
  960. * assembler readers OOPed
  961. + typed currency constants
  962. + typed 128 bit float constants if the CPU supports it
  963. Revision 1.27 2003/11/07 15:58:32 florian
  964. * Florian's culmutative nr. 1; contains:
  965. - invalid calling conventions for a certain cpu are rejected
  966. - arm softfloat calling conventions
  967. - -Sp for cpu dependend code generation
  968. - several arm fixes
  969. - remaining code for value open array paras on heap
  970. Revision 1.26 2003/09/17 22:30:19 olle
  971. + support for a different set of compiler directives under $MODE MAC
  972. + added mac directives $SETC $IFC $ELSEC $ENDC
  973. Revision 1.25 2003/03/23 23:20:38 hajny
  974. + emx target added
  975. Revision 1.24 2003/01/03 21:25:01 peter
  976. * OBJECTCHECKS added, equivalent of -CR
  977. * WRITEABLECONST added, equivalent of $J
  978. Revision 1.23 2002/12/07 14:06:20 carl
  979. * stricter version / revision checking (also remove some warnings)
  980. Revision 1.22 2002/11/20 11:12:46 mazen
  981. + module path is now passed to AddPath to fix relative unit path
  982. Revision 1.21 2002/10/16 19:01:43 peter
  983. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  984. implicit exception frames for procedures with initialized variables
  985. and for constructors. The default is on for compatibility
  986. Revision 1.20 2002/10/14 19:43:41 peter
  987. * threading switch, defines the symbol FPC_THREADING
  988. Revision 1.19 2002/08/13 18:01:52 carl
  989. * rename swatoperands to swapoperands
  990. + m68k first compilable version (still needs a lot of testing):
  991. assembler generator, system information , inline
  992. assembler reader.
  993. Revision 1.18 2002/07/26 21:15:42 florian
  994. * rewrote the system handling
  995. Revision 1.17 2002/07/20 17:16:03 florian
  996. + source code page support
  997. Revision 1.16 2002/07/16 15:37:58 florian
  998. + Directive $EXTERNALSYM added, it is ignored for now
  999. Revision 1.15 2002/05/18 13:34:17 peter
  1000. * readded missing revisions
  1001. Revision 1.14 2002/05/16 19:46:44 carl
  1002. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1003. + try to fix temp allocation (still in ifdef)
  1004. + generic constructor calls
  1005. + start of tassembler / tmodulebase class cleanup
  1006. Revision 1.12 2002/04/07 13:34:20 carl
  1007. + wdosx target
  1008. Revision 1.11 2002/04/04 19:06:05 peter
  1009. * removed unused units
  1010. * use tlocation.size in cg.a_*loc*() routines
  1011. }