scandir.pas 37 KB

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