scandir.pas 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  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,cpuinfo,
  25. verbose,comphook,ppu,
  26. scanner,switches,
  27. fmodule,
  28. symconst,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_a1;
  159. begin
  160. aktpackrecords:=1;
  161. end;
  162. procedure dir_a2;
  163. begin
  164. aktpackrecords:=2;
  165. end;
  166. procedure dir_a4;
  167. begin
  168. aktpackrecords:=4;
  169. end;
  170. procedure dir_a8;
  171. begin
  172. aktpackrecords:=8;
  173. end;
  174. procedure dir_asmmode;
  175. var
  176. s : string;
  177. begin
  178. current_scanner.skipspace;
  179. s:=current_scanner.readid;
  180. If Inside_asm_statement then
  181. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  182. if s='DEFAULT' then
  183. aktasmmode:=initasmmode
  184. else
  185. if not SetAsmReadMode(s,aktasmmode) then
  186. Message1(scan_e_illegal_asmmode_specifier,s);
  187. end;
  188. {$if defined(m68k) or defined(arm)}
  189. procedure dir_appid;
  190. begin
  191. if target_info.system<>system_m68k_palmos then
  192. Message(scan_w_appid_not_support);
  193. { change description global var in all cases }
  194. { it not used but in win32 and os2 }
  195. current_scanner.skipspace;
  196. palmos_applicationid:=current_scanner.readcomment;
  197. end;
  198. procedure dir_appname;
  199. begin
  200. if target_info.system<>system_m68k_palmos then
  201. Message(scan_w_appname_not_support);
  202. { change description global var in all cases }
  203. { it not used but in win32 and os2 }
  204. current_scanner.skipspace;
  205. palmos_applicationname:=current_scanner.readcomment;
  206. end;
  207. {$endif defined(m68k) or defined(arm)}
  208. procedure dir_apptype;
  209. var
  210. hs : string;
  211. begin
  212. if not (target_info.system in system_all_windows + [system_i386_os2,
  213. system_i386_emx, system_powerpc_macos]) then
  214. begin
  215. if m_delphi in aktmodeswitches then
  216. Message(scan_n_app_type_not_support)
  217. else
  218. Message(scan_w_app_type_not_support);
  219. end
  220. else
  221. begin
  222. if not current_module.in_global then
  223. Message(scan_w_switch_is_global)
  224. else
  225. begin
  226. current_scanner.skipspace;
  227. hs:=current_scanner.readid;
  228. if hs='GUI' then
  229. apptype:=app_gui
  230. else if hs='CONSOLE' then
  231. apptype:=app_cui
  232. else if (hs='NATIVE') and (target_info.system in system_windows) then
  233. apptype:=app_native
  234. else if (hs='FS') and (target_info.system in [system_i386_os2,
  235. system_i386_emx]) then
  236. apptype:=app_fs
  237. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  238. apptype:=app_tool
  239. else
  240. Message1(scan_w_unsupported_app_type,hs);
  241. end;
  242. end;
  243. end;
  244. procedure dir_calling;
  245. var
  246. hs : string;
  247. begin
  248. current_scanner.skipspace;
  249. hs:=current_scanner.readid;
  250. if not SetAktProcCall(hs,aktdefproccall) then
  251. begin
  252. if (hs <> '') then
  253. Message1(parser_w_unknown_proc_directive_ignored,hs)
  254. else
  255. Message(parser_e_proc_directive_expected);
  256. end;
  257. end;
  258. procedure dir_checkpointer;
  259. begin
  260. do_localswitchdefault(cs_checkpointer);
  261. end;
  262. procedure dir_objectchecks;
  263. begin
  264. do_localswitch(cs_check_object);
  265. end;
  266. procedure dir_assertions;
  267. begin
  268. do_delphiswitch('C');
  269. end;
  270. procedure dir_booleval;
  271. begin
  272. do_delphiswitch('B');
  273. end;
  274. procedure dir_debuginfo;
  275. begin
  276. do_delphiswitch('D');
  277. end;
  278. procedure dir_description;
  279. begin
  280. if not (target_info.system in [system_i386_os2,system_i386_emx,
  281. system_i386_win32,system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  282. Message(scan_w_description_not_support);
  283. { change description global var in all cases }
  284. { it not used but in win32, os2 and netware }
  285. current_scanner.skipspace;
  286. description:=current_scanner.readcomment;
  287. DescriptionSetExplicity:=true;
  288. end;
  289. procedure dir_screenname; {ad}
  290. begin
  291. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  292. {Message(scan_w_decription_not_support);}
  293. comment (V_Warning,'Screenname only supported for target netware');
  294. current_scanner.skipspace;
  295. nwscreenname:=current_scanner.readcomment;
  296. end;
  297. procedure dir_threadname; {ad}
  298. begin
  299. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  300. {Message(scan_w_decription_not_support);}
  301. comment (V_Warning,'Threadname only supported for target netware');
  302. current_scanner.skipspace;
  303. nwthreadname:=current_scanner.readcomment;
  304. end;
  305. procedure dir_copyright; {ad}
  306. begin
  307. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  308. {Message(scan_w_decription_not_support);}
  309. comment (V_Warning,'Copyright only supported for target netware');
  310. current_scanner.skipspace;
  311. nwcopyright:=current_scanner.readcomment;
  312. end;
  313. procedure dir_error;
  314. begin
  315. do_message(scan_e_user_defined);
  316. end;
  317. procedure dir_extendedsyntax;
  318. begin
  319. do_delphiswitch('X');
  320. end;
  321. procedure dir_fatal;
  322. begin
  323. do_message(scan_f_user_defined);
  324. end;
  325. procedure dir_fputype;
  326. begin
  327. current_scanner.skipspace;
  328. { current_scanner.undef_macro('FPU'+fputypestr[aktfputype]); }
  329. if not(SetFPUType(upper(current_scanner.readcomment),aktfputype)) then
  330. comment(V_Error,'Illegal FPU type');
  331. { current_scanner.def_macro('FPU'+fputypestr[aktfputype]); }
  332. end;
  333. procedure dir_goto;
  334. begin
  335. do_moduleswitch(cs_support_goto);
  336. end;
  337. procedure dir_hint;
  338. begin
  339. do_message(scan_h_user_defined);
  340. end;
  341. procedure dir_hints;
  342. begin
  343. do_setverbose('H');
  344. end;
  345. procedure dir_imagebase;
  346. begin
  347. if not (target_info.system in (system_windows+system_wince)) then
  348. Message(scan_w_imagebase_not_support);
  349. current_scanner.skipspace;
  350. imagebase:=current_scanner.readval;
  351. ImageBaseSetExplicity:=true
  352. end;
  353. procedure dir_implicitexceptions;
  354. begin
  355. do_moduleswitch(cs_implicit_exceptions);
  356. end;
  357. procedure dir_includepath;
  358. begin
  359. if not current_module.in_global then
  360. Message(scan_w_switch_is_global)
  361. else
  362. begin
  363. current_scanner.skipspace;
  364. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  365. end;
  366. end;
  367. procedure dir_info;
  368. begin
  369. do_message(scan_i_user_defined);
  370. end;
  371. procedure dir_inline;
  372. begin
  373. do_localswitch(cs_do_inline);
  374. end;
  375. procedure dir_interfaces;
  376. var
  377. hs : string;
  378. begin
  379. {corba/com/default}
  380. current_scanner.skipspace;
  381. hs:=current_scanner.readid;
  382. if (hs='CORBA') then
  383. aktinterfacetype:=it_interfacecorba
  384. else if (hs='COM') then
  385. aktinterfacetype:=it_interfacecom
  386. else if (hs='DEFAULT') then
  387. aktinterfacetype:=initinterfacetype
  388. else
  389. Message(scan_e_invalid_interface_type);
  390. end;
  391. procedure dir_iochecks;
  392. begin
  393. do_delphiswitch('I');
  394. end;
  395. procedure dir_libexport;
  396. begin
  397. {not implemented}
  398. end;
  399. procedure dir_librarypath;
  400. begin
  401. if not current_module.in_global then
  402. Message(scan_w_switch_is_global)
  403. else
  404. begin
  405. current_scanner.skipspace;
  406. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  407. end;
  408. end;
  409. procedure dir_link;
  410. var
  411. s : string;
  412. begin
  413. current_scanner.skipspace;
  414. if scanner.c = '''' then
  415. begin
  416. s:= current_scanner.readquotedstring;
  417. current_scanner.readcomment
  418. end
  419. else
  420. s:= trimspace(current_scanner.readcomment);
  421. s:=AddExtension(FixFileName(s),target_info.objext);
  422. current_module.linkotherofiles.add(s,link_always);
  423. end;
  424. procedure dir_linklib;
  425. type
  426. tLinkMode=(lm_shared,lm_static);
  427. var
  428. s : string;
  429. quote : char;
  430. libext,
  431. libname,
  432. linkmodestr : string;
  433. p : longint;
  434. linkMode : tLinkMode;
  435. begin
  436. current_scanner.skipspace;
  437. if scanner.c = '''' then
  438. begin
  439. libname:= current_scanner.readquotedstring;
  440. s:= current_scanner.readcomment;
  441. p:=pos(',',s);
  442. end
  443. else
  444. begin
  445. s:= current_scanner.readcomment;
  446. p:=pos(',',s);
  447. if p=0 then
  448. libname:=TrimSpace(s)
  449. else
  450. libname:=TrimSpace(copy(s,1,p-1));
  451. end;
  452. if p=0 then
  453. linkmodeStr:=''
  454. else
  455. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  456. if (libname='') or (libname='''''') or (libname='""') then
  457. exit;
  458. { create library name }
  459. if libname[1] in ['''','"'] then
  460. begin
  461. quote:=libname[1];
  462. Delete(libname,1,1);
  463. p:=pos(quote,libname);
  464. if p>0 then
  465. Delete(libname,p,1);
  466. end;
  467. libname:=FixFileName(libname);
  468. { get linkmode, default is to check the extension for
  469. the static library, otherwise shared linking is assumed }
  470. linkmode:=lm_shared;
  471. if linkModeStr='' then
  472. begin
  473. libext:=SplitExtension(libname);
  474. if libext=target_info.staticClibext then
  475. linkMode:=lm_static;
  476. end
  477. else if linkModeStr='STATIC' then
  478. linkmode:=lm_static
  479. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  480. linkmode:=lm_shared
  481. else
  482. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  483. { add to the list of other libraries }
  484. if linkMode=lm_static then
  485. current_module.linkOtherStaticLibs.add(libname,link_always)
  486. else
  487. current_module.linkOtherSharedLibs.add(libname,link_always);
  488. end;
  489. procedure dir_localsymbols;
  490. begin
  491. do_delphiswitch('L');
  492. end;
  493. procedure dir_longstrings;
  494. begin
  495. do_delphiswitch('H');
  496. end;
  497. procedure dir_macro;
  498. begin
  499. do_moduleswitch(cs_support_macro);
  500. end;
  501. procedure dir_maxfpuregisters;
  502. var
  503. l : integer;
  504. hs : string;
  505. begin
  506. current_scanner.skipspace;
  507. if not(c in ['0'..'9']) then
  508. begin
  509. hs:=current_scanner.readid;
  510. if (hs='NORMAL') or (hs='DEFAULT') then
  511. aktmaxfpuregisters:=-1
  512. else
  513. Message(scan_e_invalid_maxfpureg_value);
  514. end
  515. else
  516. begin
  517. l:=current_scanner.readval;
  518. case l of
  519. 0..8:
  520. aktmaxfpuregisters:=l;
  521. else
  522. Message(scan_e_invalid_maxfpureg_value);
  523. end;
  524. end;
  525. end;
  526. procedure dir_maxstacksize;
  527. begin
  528. if not (target_info.system in (system_windows+system_wince)) then
  529. Message(scan_w_maxstacksize_not_support);
  530. current_scanner.skipspace;
  531. maxstacksize:=current_scanner.readval;
  532. MaxStackSizeSetExplicity:=true;
  533. end;
  534. procedure dir_memory;
  535. var
  536. l : longint;
  537. begin
  538. current_scanner.skipspace;
  539. l:=current_scanner.readval;
  540. if l>1024 then
  541. stacksize:=l;
  542. if c=',' then
  543. begin
  544. current_scanner.readchar;
  545. current_scanner.skipspace;
  546. l:=current_scanner.readval;
  547. if l>1024 then
  548. heapsize:=l;
  549. end;
  550. end;
  551. procedure dir_message;
  552. var
  553. hs : string;
  554. w : longint;
  555. begin
  556. w:=0;
  557. current_scanner.skipspace;
  558. { Message level specified? }
  559. if c='''' then
  560. w:=scan_n_user_defined
  561. else
  562. begin
  563. hs:=current_scanner.readid;
  564. if (hs='WARN') or (hs='WARNING') then
  565. w:=scan_w_user_defined
  566. else
  567. if (hs='ERROR') then
  568. w:=scan_e_user_defined
  569. else
  570. if (hs='FATAL') then
  571. w:=scan_f_user_defined
  572. else
  573. if (hs='HINT') then
  574. w:=scan_h_user_defined
  575. else
  576. if (hs='NOTE') then
  577. w:=scan_n_user_defined
  578. else
  579. Message1(scan_w_illegal_directive,hs);
  580. end;
  581. { Only print message when there was no error }
  582. if w<>0 then
  583. begin
  584. current_scanner.skipspace;
  585. if c='''' then
  586. hs:=current_scanner.readquotedstring
  587. else
  588. hs:=current_scanner.readcomment;
  589. Message1(w,hs);
  590. end
  591. else
  592. current_scanner.readcomment;
  593. end;
  594. procedure dir_minstacksize;
  595. begin
  596. if not (target_info.system in (system_windows+system_wince)) then
  597. Message(scan_w_minstacksize_not_support);
  598. current_scanner.skipspace;
  599. minstacksize:=current_scanner.readval;
  600. MinStackSizeSetExplicity:=true;
  601. end;
  602. procedure dir_mode;
  603. begin
  604. if not current_module.in_global then
  605. Message(scan_w_switch_is_global)
  606. else
  607. begin
  608. current_scanner.skipspace;
  609. current_scanner.readstring;
  610. if not current_module.mode_switch_allowed and
  611. not ((m_mac in aktmodeswitches) and (pattern='MACPAS')) then
  612. Message1(scan_e_mode_switch_not_allowed,pattern)
  613. else if not SetCompileMode(pattern,false) then
  614. Message1(scan_w_illegal_switch,pattern)
  615. end;
  616. current_module.mode_switch_allowed:= false;
  617. end;
  618. procedure dir_mmx;
  619. begin
  620. do_localswitch(cs_mmx);
  621. end;
  622. procedure dir_note;
  623. begin
  624. do_message(scan_n_user_defined);
  625. end;
  626. procedure dir_notes;
  627. begin
  628. do_setverbose('N');
  629. end;
  630. procedure dir_objectpath;
  631. begin
  632. if not current_module.in_global then
  633. Message(scan_w_switch_is_global)
  634. else
  635. begin
  636. current_scanner.skipspace;
  637. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  638. end;
  639. end;
  640. procedure dir_openstrings;
  641. begin
  642. do_delphiswitch('P');
  643. end;
  644. procedure dir_optimization;
  645. var
  646. hs : string;
  647. begin
  648. current_scanner.skipspace;
  649. { Support also the ON and OFF as switch }
  650. hs:=current_scanner.readid;
  651. if (hs='ON') then
  652. aktoptimizerswitches:=level2optimizerswitches
  653. else if (hs='OFF') then
  654. aktoptimizerswitches:=[]
  655. else if (hs='DEFAULT') then
  656. aktoptimizerswitches:=initoptimizerswitches
  657. else
  658. begin
  659. if not UpdateOptimizerStr(hs,aktoptimizerswitches) then
  660. Message1(scan_e_illegal_optimization_specifier,hs);
  661. end;
  662. end;
  663. procedure dir_overflowchecks;
  664. begin
  665. do_delphiswitch('Q');
  666. end;
  667. procedure dir_packenum;
  668. var
  669. hs : string;
  670. begin
  671. current_scanner.skipspace;
  672. if not(c in ['0'..'9']) then
  673. begin
  674. hs:=current_scanner.readid;
  675. if (hs='NORMAL') or (hs='DEFAULT') then
  676. aktpackenum:=4
  677. else
  678. Message1(scan_e_illegal_pack_enum, hs);
  679. end
  680. else
  681. begin
  682. case current_scanner.readval of
  683. 1 : aktpackenum:=1;
  684. 2 : aktpackenum:=2;
  685. 4 : aktpackenum:=4;
  686. else
  687. Message1(scan_e_illegal_pack_enum, pattern);
  688. end;
  689. end;
  690. end;
  691. procedure dir_packrecords;
  692. var
  693. hs : string;
  694. begin
  695. current_scanner.skipspace;
  696. if not(c in ['0'..'9']) then
  697. begin
  698. hs:=current_scanner.readid;
  699. { C has the special recordalignmax of C_alignment }
  700. if (hs='C') then
  701. aktpackrecords:=C_alignment
  702. else
  703. if (hs='NORMAL') or (hs='DEFAULT') then
  704. aktpackrecords:=0
  705. else
  706. Message1(scan_e_illegal_pack_records,hs);
  707. end
  708. else
  709. begin
  710. case current_scanner.readval of
  711. 1 : aktpackrecords:=1;
  712. 2 : aktpackrecords:=2;
  713. 4 : aktpackrecords:=4;
  714. 8 : aktpackrecords:=8;
  715. 16 : aktpackrecords:=16;
  716. 32 : aktpackrecords:=32;
  717. else
  718. Message1(scan_e_illegal_pack_records,pattern);
  719. end;
  720. end;
  721. end;
  722. procedure dir_packset;
  723. var
  724. hs : string;
  725. begin
  726. current_scanner.skipspace;
  727. if not(c in ['1','2','4','8']) then
  728. begin
  729. hs:=current_scanner.readid;
  730. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  731. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  732. else
  733. Message(scan_e_only_packset);
  734. end
  735. else
  736. begin
  737. case current_scanner.readval of
  738. 1 : aktsetalloc:=1;
  739. 2 : aktsetalloc:=2;
  740. 4 : aktsetalloc:=4;
  741. 8 : aktsetalloc:=8;
  742. else
  743. Message(scan_e_only_packset);
  744. end;
  745. end;
  746. end;
  747. procedure dir_pic;
  748. begin
  749. do_moduleswitch(cs_create_pic);
  750. end;
  751. procedure dir_pop;
  752. begin
  753. if localswitchesstackpos < 1 then
  754. Message(scan_e_too_many_pop);
  755. if not localswitcheschanged then
  756. nextaktlocalswitches:=aktlocalswitches;
  757. Dec(localswitchesstackpos);
  758. nextaktlocalswitches:= localswitchesstack[localswitchesstackpos];
  759. localswitcheschanged:=true;
  760. end;
  761. procedure dir_profile;
  762. begin
  763. do_moduleswitch(cs_profile);
  764. { defined/undefine FPC_PROFILE }
  765. if cs_profile in aktmoduleswitches then
  766. def_system_macro('FPC_PROFILE')
  767. else
  768. undef_system_macro('FPC_PROFILE');
  769. end;
  770. procedure dir_push;
  771. begin
  772. if localswitchesstackpos > localswitchesstackmax then
  773. Message(scan_e_too_many_push);
  774. if localswitcheschanged then
  775. begin
  776. aktlocalswitches:=nextaktlocalswitches;
  777. localswitcheschanged:=false;
  778. end;
  779. localswitchesstack[localswitchesstackpos]:= aktlocalswitches;
  780. Inc(localswitchesstackpos);
  781. end;
  782. procedure dir_rangechecks;
  783. begin
  784. do_delphiswitch('R');
  785. end;
  786. procedure dir_referenceinfo;
  787. begin
  788. do_delphiswitch('Y');
  789. end;
  790. procedure dir_resource;
  791. var
  792. s : string;
  793. begin
  794. current_scanner.skipspace;
  795. if scanner.c = '''' then
  796. begin
  797. s:= current_scanner.readquotedstring;
  798. current_scanner.readcomment
  799. end
  800. else
  801. s:= trimspace(current_scanner.readcomment);
  802. { replace * with the name of the main source.
  803. This should always be defined. }
  804. if s[1]='*' then
  805. if Assigned(Current_Module) then
  806. begin
  807. delete(S,1,1);
  808. insert(SplitName(current_module.mainsource^),S,1);
  809. end;
  810. s:=AddExtension(FixFileName(s),target_info.resext);
  811. if target_info.res<>res_none then
  812. begin
  813. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  814. if (target_info.res = res_emxbind) and
  815. not (Current_module.ResourceFiles.Empty) then
  816. Message(scan_w_only_one_resourcefile_supported)
  817. else
  818. current_module.resourcefiles.insert(FixFileName(s));
  819. end
  820. else
  821. Message(scan_e_resourcefiles_not_supported);
  822. end;
  823. procedure dir_saturation;
  824. begin
  825. do_localswitch(cs_mmx_saturation);
  826. end;
  827. procedure dir_savefpuexceptions;
  828. begin
  829. do_localswitch(cs_fpu_fwait);
  830. end;
  831. procedure dir_setpeflags;
  832. begin
  833. if not (target_info.system in (system_windows+system_wince)) then
  834. Message(scan_w_setpeflags_not_support);
  835. current_scanner.skipspace;
  836. peflags:=current_scanner.readval;
  837. SetPEFlagsSetExplicity:=true;
  838. end;
  839. procedure dir_smartlink;
  840. begin
  841. do_moduleswitch(cs_create_smart);
  842. end;
  843. procedure dir_stackframes;
  844. begin
  845. do_delphiswitch('W');
  846. end;
  847. procedure dir_static;
  848. begin
  849. do_moduleswitch(cs_static_keyword);
  850. end;
  851. procedure dir_stop;
  852. begin
  853. do_message(scan_f_user_defined);
  854. end;
  855. {$ifdef powerpc}
  856. procedure dir_syscall;
  857. var
  858. sctype : string;
  859. begin
  860. { not needed on amiga/m68k for now, because there's only one }
  861. { syscall convention (legacy) (KB) }
  862. { not needed on amiga/powerpc because there's only one }
  863. { syscall convention (sysv) (KB) }
  864. if not (target_info.system in [system_powerpc_morphos]) then
  865. comment (V_Warning,'Syscall directive is useless on this target.');
  866. current_scanner.skipspace;
  867. sctype:=current_scanner.readid;
  868. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  869. (sctype='BASESYSV') or (sctype='R12BASE') then
  870. syscall_convention:=sctype
  871. else
  872. comment (V_Warning,'Invalid Syscall directive ignored.');
  873. end;
  874. {$endif}
  875. procedure dir_typedaddress;
  876. begin
  877. do_delphiswitch('T');
  878. end;
  879. procedure dir_typeinfo;
  880. begin
  881. do_delphiswitch('M');
  882. end;
  883. procedure dir_unitpath;
  884. begin
  885. if not current_module.in_global then
  886. Message(scan_w_switch_is_global)
  887. else
  888. with current_scanner,current_module,localunitsearchpath do
  889. begin
  890. skipspace;
  891. AddPath(path^,readcomment,false);
  892. end;
  893. end;
  894. procedure dir_varstringchecks;
  895. begin
  896. do_delphiswitch('V');
  897. end;
  898. procedure dir_version;
  899. var
  900. major, minor, revision : longint;
  901. error : integer;
  902. begin
  903. if not (target_info.system in [system_i386_os2,system_i386_emx,
  904. system_i386_win32,system_i386_netware,system_i386_wdosx,
  905. system_i386_netwlibc]) then
  906. begin
  907. Message(scan_n_version_not_support);
  908. exit;
  909. end;
  910. if (compile_level<>1) then
  911. Message(scan_n_only_exe_version)
  912. else
  913. begin
  914. { change description global var in all cases }
  915. { it not used but in win32, os2 and netware }
  916. current_scanner.skipspace;
  917. { we should only accept Major.Minor format for win32 and os2 }
  918. current_scanner.readnumber;
  919. major:=0;
  920. minor:=0;
  921. revision:=0;
  922. val(pattern,major,error);
  923. if (error<>0) or (major > high(word)) or (major < 0) then
  924. begin
  925. Message1(scan_w_wrong_version_ignored,pattern);
  926. exit;
  927. end;
  928. if c='.' then
  929. begin
  930. current_scanner.readchar;
  931. current_scanner.readnumber;
  932. val(pattern,minor,error);
  933. if (error<>0) or (minor > high(word)) or (minor < 0) then
  934. begin
  935. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  936. exit;
  937. end;
  938. if (c='.') and
  939. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  940. begin
  941. current_scanner.readchar;
  942. current_scanner.readnumber;
  943. val(pattern,revision,error);
  944. if (error<>0) or (revision > high(word)) or (revision < 0) then
  945. begin
  946. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  947. exit;
  948. end;
  949. dllmajor:=word(major);
  950. dllminor:=word(minor);
  951. dllrevision:=word(revision);
  952. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  953. end
  954. else
  955. begin
  956. dllmajor:=word(major);
  957. dllminor:=word(minor);
  958. dllversion:=tostr(major)+'.'+tostr(minor);
  959. end;
  960. end
  961. else
  962. dllversion:=tostr(major);
  963. end;
  964. end;
  965. procedure dir_wait;
  966. var
  967. had_info : boolean;
  968. begin
  969. had_info:=(status.verbosity and V_Info)<>0;
  970. { this message should allways appear !! }
  971. status.verbosity:=status.verbosity or V_Info;
  972. Message(scan_i_press_enter);
  973. readln;
  974. If not(had_info) then
  975. status.verbosity:=status.verbosity and (not V_Info);
  976. end;
  977. { delphi compatible warn directive:
  978. $warn <identifier> on
  979. $warn <identifier> off
  980. not implemented yet
  981. }
  982. procedure dir_warn;
  983. var
  984. warning_string,state : string;
  985. begin
  986. current_scanner.skipspace;
  987. warning_string:=current_scanner.readid;
  988. current_scanner.skipspace;
  989. state:=current_scanner.readid;
  990. if (upper(state)='ON') then
  991. begin
  992. end
  993. else if (upper(state)='OFF') then
  994. begin
  995. end
  996. else
  997. Message1(scanner_e_illegal_warn_state,state);
  998. end;
  999. procedure dir_warning;
  1000. begin
  1001. do_message(scan_w_user_defined);
  1002. end;
  1003. procedure dir_warnings;
  1004. begin
  1005. do_setverbose('W');
  1006. end;
  1007. procedure dir_writeableconst;
  1008. begin
  1009. do_delphiswitch('J');
  1010. end;
  1011. procedure dir_z1;
  1012. begin
  1013. aktpackenum:=1;
  1014. end;
  1015. procedure dir_z2;
  1016. begin
  1017. aktpackenum:=2;
  1018. end;
  1019. procedure dir_z4;
  1020. begin
  1021. aktpackenum:=4;
  1022. end;
  1023. procedure dir_externalsym;
  1024. begin
  1025. end;
  1026. procedure dir_nodefine;
  1027. begin
  1028. end;
  1029. procedure dir_hppemit;
  1030. begin
  1031. end;
  1032. procedure dir_weakpackageunit;
  1033. begin
  1034. end;
  1035. procedure dir_codealign;
  1036. var
  1037. s : string;
  1038. begin
  1039. current_scanner.skipspace;
  1040. s:=current_scanner.readcomment;
  1041. UpdateAlignmentStr(s,aktalignment);
  1042. end;
  1043. procedure dir_codepage;
  1044. var
  1045. s : string;
  1046. begin
  1047. if not current_module.in_global then
  1048. Message(scan_w_switch_is_global)
  1049. else
  1050. begin
  1051. current_scanner.skipspace;
  1052. s:=current_scanner.readcomment;
  1053. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1054. aktsourcecodepage:='utf8'
  1055. else if not(cpavailable(s)) then
  1056. Message1(option_code_page_not_available,s)
  1057. else
  1058. aktsourcecodepage:=s;
  1059. end;
  1060. end;
  1061. procedure dir_coperators;
  1062. begin
  1063. do_moduleswitch(cs_support_c_operators);
  1064. end;
  1065. procedure dir_bitpacking;
  1066. begin
  1067. do_localswitch(cs_bitpacking);
  1068. end;
  1069. {****************************************************************************
  1070. Initialize Directives
  1071. ****************************************************************************}
  1072. procedure InitScannerDirectives;
  1073. begin
  1074. AddDirective('A1',directive_all, @dir_a1);
  1075. AddDirective('A2',directive_all, @dir_a2);
  1076. AddDirective('A4',directive_all, @dir_a4);
  1077. AddDirective('A8',directive_all, @dir_a8);
  1078. AddDirective('ALIGN',directive_all, @dir_align);
  1079. {$ifdef m68k}
  1080. AddDirective('APPID',directive_all, @dir_appid);
  1081. AddDirective('APPNAME',directive_all, @dir_appname);
  1082. {$endif m68k}
  1083. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1084. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1085. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1086. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1087. AddDirective('BITPACKING',directive_all, @dir_bitpacking);
  1088. AddDirective('CALLING',directive_all, @dir_calling);
  1089. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1090. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1091. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1092. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1093. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1094. AddDirective('D',directive_all, @dir_description);
  1095. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1096. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1097. AddDirective('ERROR',directive_all, @dir_error);
  1098. AddDirective('ERRORC',directive_mac, @dir_error);
  1099. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1100. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1101. AddDirective('FATAL',directive_all, @dir_fatal);
  1102. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1103. AddDirective('GOTO',directive_all, @dir_goto);
  1104. AddDirective('HINT',directive_all, @dir_hint);
  1105. AddDirective('HINTS',directive_all, @dir_hints);
  1106. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1107. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1108. AddDirective('IMAGEBASE',directive_all, @dir_imagebase);
  1109. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1110. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1111. AddDirective('INFO',directive_all, @dir_info);
  1112. AddDirective('INLINE',directive_all, @dir_inline);
  1113. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1114. AddDirective('L',directive_all, @dir_link);
  1115. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1116. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1117. AddDirective('LINK',directive_all, @dir_link);
  1118. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1119. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1120. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1121. AddDirective('M',directive_all, @dir_memory);
  1122. AddDirective('MACRO',directive_all, @dir_macro);
  1123. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1124. AddDirective('MAXSTACKSIZE',directive_all, @dir_maxstacksize);
  1125. AddDirective('MEMORY',directive_all, @dir_memory);
  1126. AddDirective('MESSAGE',directive_all, @dir_message);
  1127. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1128. AddDirective('MINSTACKSIZE',directive_all, @dir_minstacksize);
  1129. AddDirective('MMX',directive_all, @dir_mmx);
  1130. AddDirective('MODE',directive_all, @dir_mode);
  1131. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1132. AddDirective('NOTE',directive_all, @dir_note);
  1133. AddDirective('NOTES',directive_all, @dir_notes);
  1134. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1135. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1136. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1137. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1138. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1139. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1140. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1141. AddDirective('PACKSET',directive_all, @dir_packset);
  1142. AddDirective('PIC',directive_all, @dir_pic);
  1143. AddDirective('POP',directive_mac, @dir_pop);
  1144. AddDirective('PROFILE',directive_all, @dir_profile);
  1145. AddDirective('PUSH',directive_mac, @dir_push);
  1146. AddDirective('R',directive_all, @dir_resource);
  1147. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1148. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1149. AddDirective('RESOURCE',directive_all, @dir_resource);
  1150. AddDirective('SATURATION',directive_all, @dir_saturation);
  1151. AddDirective('SAVEFPUEXCEPTIONS',directive_all, @dir_savefpuexceptions);
  1152. AddDirective('SETPEFLAGS', directive_all, @dir_setpeflags);
  1153. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1154. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1155. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1156. AddDirective('STATIC',directive_all, @dir_static);
  1157. AddDirective('STOP',directive_all, @dir_stop);
  1158. {$ifdef powerpc}
  1159. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1160. {$endif powerpc}
  1161. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1162. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1163. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1164. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1165. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1166. AddDirective('VERSION',directive_all, @dir_version);
  1167. AddDirective('WAIT',directive_all, @dir_wait);
  1168. AddDirective('WARN',directive_all, @dir_warn);
  1169. AddDirective('WARNING',directive_all, @dir_warning);
  1170. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1171. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1172. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1173. AddDirective('Z1',directive_all, @dir_z1);
  1174. AddDirective('Z2',directive_all, @dir_z2);
  1175. AddDirective('Z4',directive_all, @dir_z4);
  1176. end;
  1177. begin
  1178. localswitchesstackpos:= 0;
  1179. end.