scandir.pas 36 KB

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