scandir.pas 36 KB

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