scandir.pas 34 KB

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