scandir.pas 34 KB

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