scandir.pas 37 KB

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