scandir.pas 35 KB

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