scandir.pas 40 KB

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