scandir.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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_typedaddress;
  794. begin
  795. do_delphiswitch('T');
  796. end;
  797. procedure dir_typeinfo;
  798. begin
  799. do_delphiswitch('M');
  800. end;
  801. procedure dir_unitpath;
  802. begin
  803. if not current_module.in_global then
  804. Message(scan_w_switch_is_global)
  805. else
  806. with current_scanner,current_module,localunitsearchpath do
  807. begin
  808. skipspace;
  809. AddPath(path^,readcomment,false);
  810. end;
  811. end;
  812. procedure dir_varstringchecks;
  813. begin
  814. do_delphiswitch('V');
  815. end;
  816. procedure dir_version;
  817. var
  818. major, minor, revision : longint;
  819. error : integer;
  820. begin
  821. if not (target_info.system in [system_i386_os2,system_i386_emx,
  822. system_i386_win32,system_i386_netware,system_i386_wdosx,
  823. system_i386_netwlibc]) then
  824. begin
  825. Message(scan_n_version_not_support);
  826. exit;
  827. end;
  828. if (compile_level<>1) then
  829. Message(scan_n_only_exe_version)
  830. else
  831. begin
  832. { change description global var in all cases }
  833. { it not used but in win32, os2 and netware }
  834. current_scanner.skipspace;
  835. { we should only accept Major.Minor format for win32 and os2 }
  836. current_scanner.readnumber;
  837. major:=0;
  838. minor:=0;
  839. revision:=0;
  840. val(pattern,major,error);
  841. if (error<>0) or (major > high(word)) or (major < 0) then
  842. begin
  843. Message1(scan_w_wrong_version_ignored,pattern);
  844. exit;
  845. end;
  846. if c='.' then
  847. begin
  848. current_scanner.readchar;
  849. current_scanner.readnumber;
  850. val(pattern,minor,error);
  851. if (error<>0) or (minor > high(word)) or (minor < 0) then
  852. begin
  853. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  854. exit;
  855. end;
  856. if (c='.') and
  857. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  858. begin
  859. current_scanner.readchar;
  860. current_scanner.readnumber;
  861. val(pattern,revision,error);
  862. if (error<>0) or (revision > high(word)) or (revision < 0) then
  863. begin
  864. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  865. exit;
  866. end;
  867. dllmajor:=word(major);
  868. dllminor:=word(minor);
  869. dllrevision:=word(revision);
  870. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  871. end
  872. else
  873. begin
  874. dllmajor:=word(major);
  875. dllminor:=word(minor);
  876. dllversion:=tostr(major)+'.'+tostr(minor);
  877. end;
  878. end
  879. else
  880. dllversion:=tostr(major);
  881. end;
  882. end;
  883. procedure dir_wait;
  884. var
  885. had_info : boolean;
  886. begin
  887. had_info:=(status.verbosity and V_Info)<>0;
  888. { this message should allways appear !! }
  889. status.verbosity:=status.verbosity or V_Info;
  890. Message(scan_i_press_enter);
  891. readln;
  892. If not(had_info) then
  893. status.verbosity:=status.verbosity and (not V_Info);
  894. end;
  895. procedure dir_warning;
  896. begin
  897. do_message(scan_w_user_defined);
  898. end;
  899. procedure dir_warnings;
  900. begin
  901. do_setverbose('W');
  902. end;
  903. procedure dir_writeableconst;
  904. begin
  905. do_delphiswitch('J');
  906. end;
  907. procedure dir_z1;
  908. begin
  909. aktpackenum:=1;
  910. end;
  911. procedure dir_z2;
  912. begin
  913. aktpackenum:=2;
  914. end;
  915. procedure dir_z4;
  916. begin
  917. aktpackenum:=4;
  918. end;
  919. procedure dir_externalsym;
  920. begin
  921. end;
  922. procedure dir_nodefine;
  923. begin
  924. end;
  925. procedure dir_hppemit;
  926. begin
  927. end;
  928. procedure dir_weakpackageunit;
  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. procedure dir_coperators;
  948. begin
  949. do_moduleswitch(cs_support_c_operators);
  950. end;
  951. {****************************************************************************
  952. Initialize Directives
  953. ****************************************************************************}
  954. procedure InitScannerDirectives;
  955. begin
  956. AddDirective('ALIGN',directive_all, @dir_align);
  957. {$ifdef m68k}
  958. AddDirective('APPID',directive_all, @dir_appid);
  959. AddDirective('APPNAME',directive_all, @dir_appname);
  960. {$endif m68k}
  961. AddDirective('APPTYPE',directive_all, @dir_apptype);
  962. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  963. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  964. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  965. AddDirective('CALLING',directive_all, @dir_calling);
  966. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  967. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  968. AddDirective('COPERATORS',directive_all, @dir_coperators);
  969. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  970. AddDirective('D',directive_all, @dir_description);
  971. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  972. AddDirective('DESCRIPTION',directive_all, @dir_description);
  973. AddDirective('ERROR',directive_all, @dir_error);
  974. AddDirective('ERRORC',directive_mac, @dir_error);
  975. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  976. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  977. AddDirective('FATAL',directive_all, @dir_fatal);
  978. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  979. AddDirective('GOTO',directive_all, @dir_goto);
  980. AddDirective('HINT',directive_all, @dir_hint);
  981. AddDirective('HINTS',directive_all, @dir_hints);
  982. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  983. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  984. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  985. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  986. AddDirective('INFO',directive_all, @dir_info);
  987. AddDirective('INLINE',directive_all, @dir_inline);
  988. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  989. AddDirective('L',directive_all, @dir_link);
  990. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  991. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  992. AddDirective('LINK',directive_all, @dir_link);
  993. AddDirective('LINKLIB',directive_all, @dir_linklib);
  994. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  995. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  996. AddDirective('M',directive_all, @dir_memory);
  997. AddDirective('MACRO',directive_all, @dir_macro);
  998. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  999. AddDirective('MEMORY',directive_all, @dir_memory);
  1000. AddDirective('MESSAGE',directive_all, @dir_message);
  1001. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1002. AddDirective('MMX',directive_all, @dir_mmx);
  1003. AddDirective('MODE',directive_all, @dir_mode);
  1004. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1005. AddDirective('NOTE',directive_all, @dir_note);
  1006. AddDirective('NOTES',directive_all, @dir_notes);
  1007. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1008. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1009. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1010. AddDirective('OUTPUT_FORMAT',directive_all, @dir_output_format);
  1011. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1012. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1013. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1014. {$IFDEF TestVarsets}
  1015. AddDirective('PACKSET',directive_all, @dir_packset);
  1016. {$ENDIF}
  1017. AddDirective('POP',directive_mac, @dir_pop);
  1018. AddDirective('PROFILE',directive_all, @dir_profile);
  1019. AddDirective('PUSH',directive_mac, @dir_push);
  1020. AddDirective('R',directive_all, @dir_resource);
  1021. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1022. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1023. AddDirective('RESOURCE',directive_all, @dir_resource);
  1024. AddDirective('SATURATION',directive_all, @dir_saturation);
  1025. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1026. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1027. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1028. AddDirective('STATIC',directive_all, @dir_static);
  1029. AddDirective('STOP',directive_all, @dir_stop);
  1030. {$ifdef powerpc}
  1031. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1032. {$endif powerpc}
  1033. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1034. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1035. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1036. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1037. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1038. AddDirective('VERSION',directive_all, @dir_version);
  1039. AddDirective('WAIT',directive_all, @dir_wait);
  1040. AddDirective('WARNING',directive_all, @dir_warning);
  1041. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1042. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1043. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1044. AddDirective('Z1',directive_all, @dir_z1);
  1045. AddDirective('Z2',directive_all, @dir_z2);
  1046. AddDirective('Z4',directive_all, @dir_z4);
  1047. end;
  1048. begin
  1049. localswitchesstackpos:= 0;
  1050. end.
  1051. {
  1052. $Log$
  1053. Revision 1.56 2005-02-14 17:13:07 peter
  1054. * truncate log
  1055. Revision 1.55 2005/02/06 11:15:32 peter
  1056. * removed $threading
  1057. Revision 1.54 2005/01/20 17:32:33 peter
  1058. * $COPERATORS added
  1059. Revision 1.53 2005/01/20 17:05:53 peter
  1060. * use val() for decoding integers
  1061. Revision 1.52 2005/01/18 15:44:43 peter
  1062. * ignore more delphi directives
  1063. Revision 1.51 2005/01/09 20:24:43 olle
  1064. * rework of macro subsystem
  1065. + exportable macros for mode macpas
  1066. Revision 1.50 2005/01/06 02:13:03 karoly
  1067. * more SysV call support stuff for MorphOS
  1068. Revision 1.49 2005/01/04 17:40:33 karoly
  1069. + sysv style syscalls added for MorphOS
  1070. Revision 1.48 2005/01/04 16:18:57 florian
  1071. * prepared for fpu mode depended define
  1072. }