scandir.pas 35 KB

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