scandir.pas 35 KB

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