scandir.pas 36 KB

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