scandir.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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. SysUtils,
  24. cutils,cfileutl,
  25. globtype,globals,systems,widestr,cpuinfo,
  26. verbose,comphook,ppu,
  27. scanner,switches,
  28. fmodule,
  29. symconst,symtable,
  30. rabase;
  31. const
  32. localswitchesstackmax = 20;
  33. var
  34. localswitchesstack: array[0..localswitchesstackmax] of tlocalswitches;
  35. localswitchesstackpos: Integer;
  36. {*****************************************************************************
  37. Helpers
  38. *****************************************************************************}
  39. procedure do_delphiswitch(sw:char);
  40. var
  41. state : char;
  42. begin
  43. { c contains the next char, a + or - would be fine }
  44. state:=current_scanner.readstate;
  45. if state in ['-','+'] then
  46. HandleSwitch(sw,state);
  47. end;
  48. procedure do_setverbose(flag:char);
  49. var
  50. state : char;
  51. begin
  52. { support ON/OFF }
  53. state:=current_scanner.ReadState;
  54. SetVerbosity(flag+state);
  55. end;
  56. procedure do_moduleswitch(sw:tmoduleswitch);
  57. var
  58. state : char;
  59. begin
  60. state:=current_scanner.readstate;
  61. if (sw<>cs_modulenone) and (state in ['-','+']) then
  62. begin
  63. if state='-' then
  64. exclude(current_settings.moduleswitches,sw)
  65. else
  66. include(current_settings.moduleswitches,sw);
  67. end;
  68. end;
  69. procedure do_localswitch(sw:tlocalswitch);
  70. var
  71. state : char;
  72. begin
  73. state:=current_scanner.readstate;
  74. if (sw<>cs_localnone) and (state in ['-','+']) then
  75. begin
  76. if not localswitcheschanged then
  77. nextlocalswitches:=current_settings.localswitches;
  78. if state='-' then
  79. exclude(nextlocalswitches,sw)
  80. else
  81. include(nextlocalswitches,sw);
  82. localswitcheschanged:=true;
  83. end;
  84. end;
  85. procedure do_localswitchdefault(sw:tlocalswitch);
  86. var
  87. state : char;
  88. begin
  89. state:=current_scanner.readstatedefault;
  90. if (sw<>cs_localnone) and (state in ['-','+','*']) then
  91. begin
  92. if not localswitcheschanged then
  93. nextlocalswitches:=current_settings.localswitches;
  94. if state='-' then
  95. exclude(nextlocalswitches,sw)
  96. else
  97. if state='+' then
  98. include(nextlocalswitches,sw)
  99. else
  100. begin
  101. if sw in init_settings.localswitches then
  102. include(nextlocalswitches,sw)
  103. else
  104. exclude(nextlocalswitches,sw);
  105. end;
  106. localswitcheschanged:=true;
  107. end;
  108. end;
  109. procedure do_message(w:integer);
  110. begin
  111. current_scanner.skipspace;
  112. Message1(w,current_scanner.readcomment);
  113. end;
  114. {*****************************************************************************
  115. Directive Callbacks
  116. *****************************************************************************}
  117. procedure dir_align;
  118. var
  119. hs : string;
  120. begin
  121. current_scanner.skipspace;
  122. if not(c in ['0'..'9']) then
  123. begin
  124. { Support also the ON and OFF as switch }
  125. hs:=current_scanner.readid;
  126. if (hs='ON') then
  127. current_settings.packrecords:=4
  128. else if (hs='OFF') then
  129. current_settings.packrecords:=1
  130. else if m_mac in current_settings.modeswitches then
  131. begin
  132. { Support switches used in Apples Universal Interfaces}
  133. if (hs='MAC68K') then
  134. current_settings.packrecords:=2
  135. else if (hs='POWER') then
  136. current_settings.packrecords:=4
  137. else if (hs='RESET') then
  138. current_settings.packrecords:=0
  139. else
  140. Message1(scan_e_illegal_pack_records,hs);
  141. end
  142. else
  143. Message1(scan_e_illegal_pack_records,hs);
  144. end
  145. else
  146. begin
  147. case current_scanner.readval of
  148. 1 : current_settings.packrecords:=1;
  149. 2 : current_settings.packrecords:=2;
  150. 4 : current_settings.packrecords:=4;
  151. 8 : current_settings.packrecords:=8;
  152. 16 : current_settings.packrecords:=16;
  153. 32 : current_settings.packrecords:=32;
  154. else
  155. Message1(scan_e_illegal_pack_records,hs);
  156. end;
  157. end;
  158. end;
  159. procedure dir_a1;
  160. begin
  161. current_settings.packrecords:=1;
  162. end;
  163. procedure dir_a2;
  164. begin
  165. current_settings.packrecords:=2;
  166. end;
  167. procedure dir_a4;
  168. begin
  169. current_settings.packrecords:=4;
  170. end;
  171. procedure dir_a8;
  172. begin
  173. current_settings.packrecords:=8;
  174. end;
  175. procedure dir_asmmode;
  176. var
  177. s : string;
  178. begin
  179. current_scanner.skipspace;
  180. s:=current_scanner.readid;
  181. If Inside_asm_statement then
  182. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  183. if s='DEFAULT' then
  184. current_settings.asmmode:=init_settings.asmmode
  185. else
  186. if not SetAsmReadMode(s,current_settings.asmmode) then
  187. Message1(scan_e_illegal_asmmode_specifier,s);
  188. end;
  189. {$if defined(m68k) or defined(arm)}
  190. procedure dir_appid;
  191. begin
  192. if target_info.system<>system_m68k_palmos then
  193. Message(scan_w_appid_not_support);
  194. { change description global var in all cases }
  195. { it not used but in win32 and os2 }
  196. current_scanner.skipspace;
  197. palmos_applicationid:=current_scanner.readcomment;
  198. end;
  199. procedure dir_appname;
  200. begin
  201. if target_info.system<>system_m68k_palmos then
  202. Message(scan_w_appname_not_support);
  203. { change description global var in all cases }
  204. { it not used but in win32 and os2 }
  205. current_scanner.skipspace;
  206. palmos_applicationname:=current_scanner.readcomment;
  207. end;
  208. {$endif defined(m68k) or defined(arm)}
  209. procedure dir_apptype;
  210. var
  211. hs : string;
  212. begin
  213. if not (target_info.system in system_all_windows + [system_i386_os2,
  214. system_i386_emx, system_powerpc_macos,
  215. system_arm_nds]) then
  216. begin
  217. if m_delphi in current_settings.modeswitches then
  218. Message(scan_n_app_type_not_support)
  219. else
  220. Message(scan_w_app_type_not_support);
  221. end
  222. else
  223. begin
  224. if not current_module.in_global then
  225. Message(scan_w_switch_is_global)
  226. else
  227. begin
  228. current_scanner.skipspace;
  229. hs:=current_scanner.readid;
  230. if hs='GUI' then
  231. apptype:=app_gui
  232. else if hs='CONSOLE' then
  233. apptype:=app_cui
  234. else if (hs='NATIVE') and (target_info.system in system_windows) then
  235. apptype:=app_native
  236. else if (hs='FS') and (target_info.system in [system_i386_os2,
  237. system_i386_emx]) then
  238. apptype:=app_fs
  239. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  240. apptype:=app_tool
  241. else if (hs='ARM9') and (target_info.system in [system_arm_nds]) then
  242. apptype:=app_arm9
  243. else if (hs='ARM7') and (target_info.system in [system_arm_nds]) then
  244. apptype:=app_arm7
  245. else
  246. Message1(scan_w_unsupported_app_type,hs);
  247. end;
  248. end;
  249. end;
  250. procedure dir_calling;
  251. var
  252. hs : string;
  253. begin
  254. current_scanner.skipspace;
  255. hs:=current_scanner.readid;
  256. if not SetAktProcCall(hs,current_settings.defproccall) then
  257. begin
  258. if (hs <> '') then
  259. Message1(parser_w_unknown_proc_directive_ignored,hs)
  260. else
  261. Message(parser_e_proc_directive_expected);
  262. end;
  263. end;
  264. procedure dir_checkpointer;
  265. begin
  266. do_localswitchdefault(cs_checkpointer);
  267. end;
  268. procedure dir_objectchecks;
  269. begin
  270. do_localswitch(cs_check_object);
  271. end;
  272. procedure dir_assertions;
  273. begin
  274. do_delphiswitch('C');
  275. end;
  276. procedure dir_booleval;
  277. begin
  278. do_delphiswitch('B');
  279. end;
  280. procedure dir_debuginfo;
  281. begin
  282. do_delphiswitch('D');
  283. end;
  284. procedure dir_description;
  285. begin
  286. if not (target_info.system in [system_i386_os2,system_i386_emx,
  287. system_i386_win32,system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  288. Message(scan_w_description_not_support);
  289. { change description global var in all cases }
  290. { it not used but in win32, os2 and netware }
  291. current_scanner.skipspace;
  292. description:=current_scanner.readcomment;
  293. DescriptionSetExplicity:=true;
  294. end;
  295. procedure dir_screenname; {ad}
  296. begin
  297. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  298. {Message(scan_w_decription_not_support);}
  299. comment (V_Warning,'Screenname only supported for target netware');
  300. current_scanner.skipspace;
  301. nwscreenname:=current_scanner.readcomment;
  302. end;
  303. procedure dir_threadname; {ad}
  304. begin
  305. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  306. {Message(scan_w_decription_not_support);}
  307. comment (V_Warning,'Threadname only supported for target netware');
  308. current_scanner.skipspace;
  309. nwthreadname:=current_scanner.readcomment;
  310. end;
  311. procedure dir_copyright; {ad}
  312. begin
  313. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  314. {Message(scan_w_decription_not_support);}
  315. comment (V_Warning,'Copyright only supported for target netware');
  316. current_scanner.skipspace;
  317. nwcopyright:=current_scanner.readcomment;
  318. end;
  319. procedure dir_error;
  320. begin
  321. do_message(scan_e_user_defined);
  322. end;
  323. procedure dir_extendedsyntax;
  324. begin
  325. do_delphiswitch('X');
  326. end;
  327. procedure dir_fatal;
  328. begin
  329. do_message(scan_f_user_defined);
  330. end;
  331. procedure dir_fputype;
  332. begin
  333. current_scanner.skipspace;
  334. undef_system_macro('FPU'+fputypestr[current_settings.fputype]);
  335. if not(SetFPUType(upper(current_scanner.readcomment),current_settings.fputype)) then
  336. comment(V_Error,'Illegal FPU type');
  337. def_system_macro('FPU'+fputypestr[current_settings.fputype]);
  338. end;
  339. procedure dir_frameworkpath;
  340. begin
  341. if not current_module.in_global then
  342. Message(scan_w_switch_is_global)
  343. else if not(target_info.system in systems_darwin) then
  344. begin
  345. Message(scan_w_frameworks_darwin_only);
  346. current_scanner.skipspace;
  347. current_scanner.readcomment
  348. end
  349. else
  350. begin
  351. current_scanner.skipspace;
  352. current_module.localframeworksearchpath.AddPath(current_scanner.readcomment,false);
  353. end;
  354. end;
  355. procedure dir_goto;
  356. begin
  357. do_moduleswitch(cs_support_goto);
  358. end;
  359. procedure dir_hint;
  360. begin
  361. do_message(scan_h_user_defined);
  362. end;
  363. procedure dir_hints;
  364. begin
  365. do_setverbose('H');
  366. end;
  367. procedure dir_imagebase;
  368. begin
  369. if not (target_info.system in (system_windows+system_wince)) then
  370. Message(scan_w_imagebase_not_support);
  371. current_scanner.skipspace;
  372. imagebase:=current_scanner.readval;
  373. ImageBaseSetExplicity:=true
  374. end;
  375. procedure dir_implicitexceptions;
  376. begin
  377. do_moduleswitch(cs_implicit_exceptions);
  378. end;
  379. procedure dir_includepath;
  380. begin
  381. if not current_module.in_global then
  382. Message(scan_w_switch_is_global)
  383. else
  384. begin
  385. current_scanner.skipspace;
  386. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  387. end;
  388. end;
  389. procedure dir_info;
  390. begin
  391. do_message(scan_i_user_defined);
  392. end;
  393. procedure dir_inline;
  394. begin
  395. do_localswitch(cs_do_inline);
  396. end;
  397. procedure dir_interfaces;
  398. var
  399. hs : string;
  400. begin
  401. {corba/com/default}
  402. current_scanner.skipspace;
  403. hs:=current_scanner.readid;
  404. if (hs='CORBA') then
  405. current_settings.interfacetype:=it_interfacecorba
  406. else if (hs='COM') then
  407. current_settings.interfacetype:=it_interfacecom
  408. else if (hs='DEFAULT') then
  409. current_settings.interfacetype:=init_settings.interfacetype
  410. else
  411. Message(scan_e_invalid_interface_type);
  412. end;
  413. procedure dir_iochecks;
  414. begin
  415. do_delphiswitch('I');
  416. end;
  417. procedure dir_libexport;
  418. begin
  419. {not implemented}
  420. end;
  421. procedure dir_librarypath;
  422. begin
  423. if not current_module.in_global then
  424. Message(scan_w_switch_is_global)
  425. else
  426. begin
  427. current_scanner.skipspace;
  428. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  429. end;
  430. end;
  431. procedure dir_link;
  432. var
  433. s : string;
  434. begin
  435. current_scanner.skipspace;
  436. if scanner.c = '''' then
  437. begin
  438. s:= current_scanner.readquotedstring;
  439. current_scanner.readcomment
  440. end
  441. else
  442. s:= trimspace(current_scanner.readcomment);
  443. s:=FixFileName(s);
  444. if ExtractFileExt(s)='' then
  445. s:=ChangeFileExt(s,target_info.objext);
  446. current_module.linkotherofiles.add(s,link_always);
  447. end;
  448. procedure dir_linkframework;
  449. var
  450. s : string;
  451. begin
  452. current_scanner.skipspace;
  453. if scanner.c = '''' then
  454. begin
  455. s:= current_scanner.readquotedstring;
  456. current_scanner.readcomment
  457. end
  458. else
  459. s:= trimspace(current_scanner.readcomment);
  460. s:=FixFileName(s);
  461. if (target_info.system in systems_darwin) then
  462. current_module.linkotherframeworks.add(s,link_always)
  463. else
  464. Message(scan_w_frameworks_darwin_only);
  465. end;
  466. procedure dir_linklib;
  467. type
  468. tLinkMode=(lm_shared,lm_static);
  469. var
  470. s : string;
  471. quote : char;
  472. libext,
  473. libname,
  474. linkmodestr : string;
  475. p : longint;
  476. linkMode : tLinkMode;
  477. begin
  478. current_scanner.skipspace;
  479. if scanner.c = '''' then
  480. begin
  481. libname:= current_scanner.readquotedstring;
  482. s:= current_scanner.readcomment;
  483. p:=pos(',',s);
  484. end
  485. else
  486. begin
  487. s:= current_scanner.readcomment;
  488. p:=pos(',',s);
  489. if p=0 then
  490. libname:=TrimSpace(s)
  491. else
  492. libname:=TrimSpace(copy(s,1,p-1));
  493. end;
  494. if p=0 then
  495. linkmodeStr:=''
  496. else
  497. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  498. if (libname='') or (libname='''''') or (libname='""') then
  499. exit;
  500. { create library name }
  501. if libname[1] in ['''','"'] then
  502. begin
  503. quote:=libname[1];
  504. Delete(libname,1,1);
  505. p:=pos(quote,libname);
  506. if p>0 then
  507. Delete(libname,p,1);
  508. end;
  509. libname:=FixFileName(libname);
  510. { get linkmode, default is to check the extension for
  511. the static library, otherwise shared linking is assumed }
  512. linkmode:=lm_shared;
  513. if linkModeStr='' then
  514. begin
  515. libext:=ExtractFileExt(libname);
  516. if libext=target_info.staticClibext then
  517. linkMode:=lm_static;
  518. end
  519. else if linkModeStr='STATIC' then
  520. linkmode:=lm_static
  521. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  522. linkmode:=lm_shared
  523. else
  524. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  525. { add to the list of other libraries }
  526. if linkMode=lm_static then
  527. current_module.linkOtherStaticLibs.add(libname,link_always)
  528. else
  529. current_module.linkOtherSharedLibs.add(libname,link_always);
  530. end;
  531. procedure dir_localsymbols;
  532. begin
  533. do_delphiswitch('L');
  534. end;
  535. procedure dir_longstrings;
  536. begin
  537. do_delphiswitch('H');
  538. end;
  539. procedure dir_macro;
  540. begin
  541. do_moduleswitch(cs_support_macro);
  542. end;
  543. procedure dir_maxfpuregisters;
  544. var
  545. l : integer;
  546. hs : string;
  547. begin
  548. current_scanner.skipspace;
  549. if not(c in ['0'..'9']) then
  550. begin
  551. hs:=current_scanner.readid;
  552. if (hs='NORMAL') or (hs='DEFAULT') then
  553. current_settings.maxfpuregisters:=-1
  554. else
  555. Message(scan_e_invalid_maxfpureg_value);
  556. end
  557. else
  558. begin
  559. l:=current_scanner.readval;
  560. case l of
  561. 0..8:
  562. current_settings.maxfpuregisters:=l;
  563. else
  564. Message(scan_e_invalid_maxfpureg_value);
  565. end;
  566. end;
  567. end;
  568. procedure dir_maxstacksize;
  569. begin
  570. if not (target_info.system in (system_windows+system_wince)) then
  571. Message(scan_w_maxstacksize_not_support);
  572. current_scanner.skipspace;
  573. maxstacksize:=current_scanner.readval;
  574. MaxStackSizeSetExplicity:=true;
  575. end;
  576. procedure dir_memory;
  577. var
  578. l : longint;
  579. begin
  580. current_scanner.skipspace;
  581. l:=current_scanner.readval;
  582. if l>1024 then
  583. stacksize:=l;
  584. if c=',' then
  585. begin
  586. current_scanner.readchar;
  587. current_scanner.skipspace;
  588. l:=current_scanner.readval;
  589. if l>1024 then
  590. heapsize:=l;
  591. end;
  592. end;
  593. procedure dir_message;
  594. var
  595. hs : string;
  596. w : longint;
  597. begin
  598. w:=0;
  599. current_scanner.skipspace;
  600. { Message level specified? }
  601. if c='''' then
  602. w:=scan_n_user_defined
  603. else
  604. begin
  605. hs:=current_scanner.readid;
  606. if (hs='WARN') or (hs='WARNING') then
  607. w:=scan_w_user_defined
  608. else
  609. if (hs='ERROR') then
  610. w:=scan_e_user_defined
  611. else
  612. if (hs='FATAL') then
  613. w:=scan_f_user_defined
  614. else
  615. if (hs='HINT') then
  616. w:=scan_h_user_defined
  617. else
  618. if (hs='NOTE') then
  619. w:=scan_n_user_defined
  620. else
  621. Message1(scan_w_illegal_directive,hs);
  622. end;
  623. { Only print message when there was no error }
  624. if w<>0 then
  625. begin
  626. current_scanner.skipspace;
  627. if c='''' then
  628. hs:=current_scanner.readquotedstring
  629. else
  630. hs:=current_scanner.readcomment;
  631. Message1(w,hs);
  632. end
  633. else
  634. current_scanner.readcomment;
  635. end;
  636. procedure dir_minstacksize;
  637. begin
  638. if not (target_info.system in (system_windows+system_wince)) then
  639. Message(scan_w_minstacksize_not_support);
  640. current_scanner.skipspace;
  641. minstacksize:=current_scanner.readval;
  642. MinStackSizeSetExplicity:=true;
  643. end;
  644. procedure dir_mode;
  645. begin
  646. if not current_module.in_global then
  647. Message(scan_w_switch_is_global)
  648. else
  649. begin
  650. current_scanner.skipspace;
  651. current_scanner.readstring;
  652. if not current_module.mode_switch_allowed and
  653. not ((m_mac in current_settings.modeswitches) and (pattern='MACPAS')) then
  654. Message1(scan_e_mode_switch_not_allowed,pattern)
  655. else if not SetCompileMode(pattern,false) then
  656. Message1(scan_w_illegal_switch,pattern)
  657. end;
  658. current_module.mode_switch_allowed:= false;
  659. end;
  660. procedure dir_mmx;
  661. begin
  662. do_localswitch(cs_mmx);
  663. end;
  664. procedure dir_note;
  665. begin
  666. do_message(scan_n_user_defined);
  667. end;
  668. procedure dir_notes;
  669. begin
  670. do_setverbose('N');
  671. end;
  672. procedure dir_objectpath;
  673. begin
  674. if not current_module.in_global then
  675. Message(scan_w_switch_is_global)
  676. else
  677. begin
  678. current_scanner.skipspace;
  679. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  680. end;
  681. end;
  682. procedure dir_openstrings;
  683. begin
  684. do_delphiswitch('P');
  685. end;
  686. procedure dir_optimization;
  687. var
  688. hs : string;
  689. begin
  690. current_scanner.skipspace;
  691. { Support also the ON and OFF as switch }
  692. hs:=current_scanner.readid;
  693. if (hs='ON') then
  694. current_settings.optimizerswitches:=level2optimizerswitches
  695. else if (hs='OFF') then
  696. current_settings.optimizerswitches:=[]
  697. else if (hs='DEFAULT') then
  698. current_settings.optimizerswitches:=init_settings.optimizerswitches
  699. else
  700. begin
  701. if not UpdateOptimizerStr(hs,current_settings.optimizerswitches) then
  702. Message1(scan_e_illegal_optimization_specifier,hs);
  703. end;
  704. end;
  705. procedure dir_overflowchecks;
  706. begin
  707. do_delphiswitch('Q');
  708. end;
  709. procedure dir_packenum;
  710. var
  711. hs : string;
  712. begin
  713. current_scanner.skipspace;
  714. if not(c in ['0'..'9']) then
  715. begin
  716. hs:=current_scanner.readid;
  717. if (hs='NORMAL') or (hs='DEFAULT') then
  718. current_settings.packenum:=4
  719. else
  720. Message1(scan_e_illegal_pack_enum, hs);
  721. end
  722. else
  723. begin
  724. case current_scanner.readval of
  725. 1 : current_settings.packenum:=1;
  726. 2 : current_settings.packenum:=2;
  727. 4 : current_settings.packenum:=4;
  728. else
  729. Message1(scan_e_illegal_pack_enum, pattern);
  730. end;
  731. end;
  732. end;
  733. procedure dir_minfpconstprec;
  734. begin
  735. current_scanner.skipspace;
  736. if not SetMinFPConstPrec(current_scanner.readid,current_settings.minfpconstprec) then
  737. Message1(scan_e_illegal_minfpconstprec, pattern);
  738. end;
  739. procedure dir_packrecords;
  740. var
  741. hs : string;
  742. begin
  743. current_scanner.skipspace;
  744. if not(c in ['0'..'9']) then
  745. begin
  746. hs:=current_scanner.readid;
  747. { C has the special recordalignmax of C_alignment }
  748. if (hs='C') then
  749. current_settings.packrecords:=C_alignment
  750. else
  751. if (hs='NORMAL') or (hs='DEFAULT') then
  752. current_settings.packrecords:=0
  753. else
  754. Message1(scan_e_illegal_pack_records,hs);
  755. end
  756. else
  757. begin
  758. case current_scanner.readval of
  759. 1 : current_settings.packrecords:=1;
  760. 2 : current_settings.packrecords:=2;
  761. 4 : current_settings.packrecords:=4;
  762. 8 : current_settings.packrecords:=8;
  763. 16 : current_settings.packrecords:=16;
  764. 32 : current_settings.packrecords:=32;
  765. else
  766. Message1(scan_e_illegal_pack_records,pattern);
  767. end;
  768. end;
  769. end;
  770. procedure dir_packset;
  771. var
  772. hs : string;
  773. begin
  774. current_scanner.skipspace;
  775. if not(c in ['1','2','4','8']) then
  776. begin
  777. hs:=current_scanner.readid;
  778. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  779. current_settings.setalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  780. else
  781. Message(scan_e_only_packset);
  782. end
  783. else
  784. begin
  785. case current_scanner.readval of
  786. 1 : current_settings.setalloc:=1;
  787. 2 : current_settings.setalloc:=2;
  788. 4 : current_settings.setalloc:=4;
  789. 8 : current_settings.setalloc:=8;
  790. else
  791. Message(scan_e_only_packset);
  792. end;
  793. end;
  794. end;
  795. procedure dir_pic;
  796. begin
  797. { windows doesn't need/support pic }
  798. if tf_no_pic_supported in target_info.flags then
  799. message(scan_w_pic_ignored)
  800. else
  801. do_moduleswitch(cs_create_pic);
  802. end;
  803. procedure dir_pop;
  804. begin
  805. if localswitchesstackpos < 1 then
  806. Message(scan_e_too_many_pop);
  807. if not localswitcheschanged then
  808. nextlocalswitches:=current_settings.localswitches;
  809. Dec(localswitchesstackpos);
  810. nextlocalswitches:= localswitchesstack[localswitchesstackpos];
  811. localswitcheschanged:=true;
  812. end;
  813. procedure dir_profile;
  814. begin
  815. do_moduleswitch(cs_profile);
  816. { defined/undefine FPC_PROFILE }
  817. if cs_profile in current_settings.moduleswitches then
  818. def_system_macro('FPC_PROFILE')
  819. else
  820. undef_system_macro('FPC_PROFILE');
  821. end;
  822. procedure dir_push;
  823. begin
  824. if localswitchesstackpos > localswitchesstackmax then
  825. Message(scan_e_too_many_push);
  826. if localswitcheschanged then
  827. begin
  828. current_settings.localswitches:=nextlocalswitches;
  829. localswitcheschanged:=false;
  830. end;
  831. localswitchesstack[localswitchesstackpos]:= current_settings.localswitches;
  832. Inc(localswitchesstackpos);
  833. end;
  834. procedure dir_rangechecks;
  835. begin
  836. do_delphiswitch('R');
  837. end;
  838. procedure dir_referenceinfo;
  839. begin
  840. do_delphiswitch('Y');
  841. end;
  842. procedure dir_resource;
  843. var
  844. s : string;
  845. begin
  846. current_scanner.skipspace;
  847. if scanner.c = '''' then
  848. begin
  849. s:= current_scanner.readquotedstring;
  850. current_scanner.readcomment
  851. end
  852. else
  853. s:= trimspace(current_scanner.readcomment);
  854. { replace * with the name of the main source.
  855. This should always be defined. }
  856. if s[1]='*' then
  857. if Assigned(Current_Module) then
  858. begin
  859. delete(S,1,1);
  860. insert(ChangeFileExt(ExtractFileName(current_module.mainsource^),''),S,1 );
  861. end;
  862. s:=FixFileName(s);
  863. if ExtractFileExt(s)='' then
  864. s:=ChangeFileExt(s,target_info.resext);
  865. if target_info.res<>res_none then
  866. begin
  867. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  868. if (target_info.res = res_emxbind) and
  869. not (Current_module.ResourceFiles.Empty) then
  870. Message(scan_w_only_one_resourcefile_supported)
  871. else
  872. current_module.resourcefiles.insert(FixFileName(s));
  873. end
  874. else
  875. Message(scan_e_resourcefiles_not_supported);
  876. end;
  877. procedure dir_saturation;
  878. begin
  879. do_localswitch(cs_mmx_saturation);
  880. end;
  881. procedure dir_safefpuexceptions;
  882. begin
  883. do_localswitch(cs_fpu_fwait);
  884. end;
  885. procedure dir_setpeflags;
  886. begin
  887. if not (target_info.system in (system_windows+system_wince)) then
  888. Message(scan_w_setpeflags_not_support);
  889. current_scanner.skipspace;
  890. peflags:=current_scanner.readval;
  891. SetPEFlagsSetExplicity:=true;
  892. end;
  893. procedure dir_smartlink;
  894. begin
  895. do_moduleswitch(cs_create_smart);
  896. end;
  897. procedure dir_stackframes;
  898. begin
  899. do_delphiswitch('W');
  900. end;
  901. procedure dir_static;
  902. begin
  903. do_moduleswitch(cs_static_keyword);
  904. end;
  905. procedure dir_stop;
  906. begin
  907. do_message(scan_f_user_defined);
  908. end;
  909. {$ifdef powerpc}
  910. procedure dir_syscall;
  911. var
  912. sctype : string;
  913. begin
  914. { not needed on amiga/m68k for now, because there's only one }
  915. { syscall convention (legacy) (KB) }
  916. { not needed on amiga/powerpc because there's only one }
  917. { syscall convention (sysv) (KB) }
  918. if not (target_info.system in [system_powerpc_morphos]) then
  919. comment (V_Warning,'Syscall directive is useless on this target.');
  920. current_scanner.skipspace;
  921. sctype:=current_scanner.readid;
  922. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  923. (sctype='BASESYSV') or (sctype='R12BASE') then
  924. syscall_convention:=sctype
  925. else
  926. comment (V_Warning,'Invalid Syscall directive ignored.');
  927. end;
  928. {$endif}
  929. procedure dir_typedaddress;
  930. begin
  931. do_delphiswitch('T');
  932. end;
  933. procedure dir_typeinfo;
  934. begin
  935. do_delphiswitch('M');
  936. end;
  937. procedure dir_unitpath;
  938. begin
  939. if not current_module.in_global then
  940. Message(scan_w_switch_is_global)
  941. else
  942. with current_scanner,current_module,localunitsearchpath do
  943. begin
  944. skipspace;
  945. AddPath(path^,readcomment,false);
  946. end;
  947. end;
  948. procedure dir_varstringchecks;
  949. begin
  950. do_delphiswitch('V');
  951. end;
  952. procedure dir_version;
  953. var
  954. major, minor, revision : longint;
  955. error : integer;
  956. begin
  957. if not (target_info.system in [system_i386_os2,system_i386_emx,
  958. system_i386_win32,system_i386_netware,system_i386_wdosx,
  959. system_i386_netwlibc]) then
  960. begin
  961. Message(scan_n_version_not_support);
  962. exit;
  963. end;
  964. if (compile_level<>1) then
  965. Message(scan_n_only_exe_version)
  966. else
  967. begin
  968. { change description global var in all cases }
  969. { it not used but in win32, os2 and netware }
  970. current_scanner.skipspace;
  971. { we should only accept Major.Minor format for win32 and os2 }
  972. current_scanner.readnumber;
  973. major:=0;
  974. minor:=0;
  975. revision:=0;
  976. val(pattern,major,error);
  977. if (error<>0) or (major > high(word)) or (major < 0) then
  978. begin
  979. Message1(scan_w_wrong_version_ignored,pattern);
  980. exit;
  981. end;
  982. if c='.' then
  983. begin
  984. current_scanner.readchar;
  985. current_scanner.readnumber;
  986. val(pattern,minor,error);
  987. if (error<>0) or (minor > high(word)) or (minor < 0) then
  988. begin
  989. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  990. exit;
  991. end;
  992. if (c='.') and
  993. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  994. begin
  995. current_scanner.readchar;
  996. current_scanner.readnumber;
  997. val(pattern,revision,error);
  998. if (error<>0) or (revision > high(word)) or (revision < 0) then
  999. begin
  1000. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  1001. exit;
  1002. end;
  1003. dllmajor:=word(major);
  1004. dllminor:=word(minor);
  1005. dllrevision:=word(revision);
  1006. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  1007. end
  1008. else
  1009. begin
  1010. dllmajor:=word(major);
  1011. dllminor:=word(minor);
  1012. dllversion:=tostr(major)+'.'+tostr(minor);
  1013. end;
  1014. end
  1015. else
  1016. dllversion:=tostr(major);
  1017. end;
  1018. end;
  1019. procedure dir_wait;
  1020. var
  1021. had_info : boolean;
  1022. begin
  1023. had_info:=(status.verbosity and V_Info)<>0;
  1024. { this message should allways appear !! }
  1025. status.verbosity:=status.verbosity or V_Info;
  1026. Message(scan_i_press_enter);
  1027. readln;
  1028. If not(had_info) then
  1029. status.verbosity:=status.verbosity and (not V_Info);
  1030. end;
  1031. { delphi compatible warn directive:
  1032. $warn <identifier> on
  1033. $warn <identifier> off
  1034. not implemented yet
  1035. }
  1036. procedure dir_warn;
  1037. var
  1038. warning_string,state : string;
  1039. begin
  1040. current_scanner.skipspace;
  1041. warning_string:=current_scanner.readid;
  1042. current_scanner.skipspace;
  1043. state:=current_scanner.readid;
  1044. if (upper(state)='ON') then
  1045. begin
  1046. end
  1047. else if (upper(state)='OFF') then
  1048. begin
  1049. end
  1050. else
  1051. Message1(scanner_e_illegal_warn_state,state);
  1052. end;
  1053. procedure dir_warning;
  1054. begin
  1055. do_message(scan_w_user_defined);
  1056. end;
  1057. procedure dir_warnings;
  1058. begin
  1059. do_setverbose('W');
  1060. end;
  1061. procedure dir_writeableconst;
  1062. begin
  1063. do_delphiswitch('J');
  1064. end;
  1065. procedure dir_z1;
  1066. begin
  1067. current_settings.packenum:=1;
  1068. end;
  1069. procedure dir_z2;
  1070. begin
  1071. current_settings.packenum:=2;
  1072. end;
  1073. procedure dir_z4;
  1074. begin
  1075. current_settings.packenum:=4;
  1076. end;
  1077. procedure dir_externalsym;
  1078. begin
  1079. end;
  1080. procedure dir_nodefine;
  1081. begin
  1082. end;
  1083. procedure dir_hppemit;
  1084. begin
  1085. end;
  1086. procedure dir_weakpackageunit;
  1087. begin
  1088. end;
  1089. procedure dir_codealign;
  1090. var
  1091. s : string;
  1092. begin
  1093. current_scanner.skipspace;
  1094. s:=current_scanner.readcomment;
  1095. UpdateAlignmentStr(s,current_settings.alignment);
  1096. end;
  1097. procedure dir_codepage;
  1098. var
  1099. s : string;
  1100. begin
  1101. if not current_module.in_global then
  1102. Message(scan_w_switch_is_global)
  1103. else
  1104. begin
  1105. current_scanner.skipspace;
  1106. s:=current_scanner.readcomment;
  1107. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1108. current_settings.sourcecodepage:='utf8'
  1109. else if not(cpavailable(s)) then
  1110. Message1(option_code_page_not_available,s)
  1111. else
  1112. current_settings.sourcecodepage:=s;
  1113. end;
  1114. end;
  1115. procedure dir_coperators;
  1116. begin
  1117. do_moduleswitch(cs_support_c_operators);
  1118. end;
  1119. procedure dir_bitpacking;
  1120. begin
  1121. do_localswitch(cs_bitpacking);
  1122. end;
  1123. {****************************************************************************
  1124. Initialize Directives
  1125. ****************************************************************************}
  1126. procedure InitScannerDirectives;
  1127. begin
  1128. AddDirective('A1',directive_all, @dir_a1);
  1129. AddDirective('A2',directive_all, @dir_a2);
  1130. AddDirective('A4',directive_all, @dir_a4);
  1131. AddDirective('A8',directive_all, @dir_a8);
  1132. AddDirective('ALIGN',directive_all, @dir_align);
  1133. {$ifdef m68k}
  1134. AddDirective('APPID',directive_all, @dir_appid);
  1135. AddDirective('APPNAME',directive_all, @dir_appname);
  1136. {$endif m68k}
  1137. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1138. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1139. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1140. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1141. AddDirective('BITPACKING',directive_all, @dir_bitpacking);
  1142. AddDirective('CALLING',directive_all, @dir_calling);
  1143. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1144. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1145. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1146. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1147. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1148. AddDirective('D',directive_all, @dir_description);
  1149. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1150. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1151. AddDirective('ERROR',directive_all, @dir_error);
  1152. AddDirective('ERRORC',directive_mac, @dir_error);
  1153. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1154. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1155. AddDirective('FATAL',directive_all, @dir_fatal);
  1156. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1157. AddDirective('FRAMEWORKPATH',directive_all, @dir_frameworkpath);
  1158. AddDirective('GOTO',directive_all, @dir_goto);
  1159. AddDirective('HINT',directive_all, @dir_hint);
  1160. AddDirective('HINTS',directive_all, @dir_hints);
  1161. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1162. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1163. AddDirective('IMAGEBASE',directive_all, @dir_imagebase);
  1164. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1165. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1166. AddDirective('INFO',directive_all, @dir_info);
  1167. AddDirective('INLINE',directive_all, @dir_inline);
  1168. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1169. AddDirective('L',directive_all, @dir_link);
  1170. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1171. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1172. AddDirective('LINK',directive_all, @dir_link);
  1173. AddDirective('LINKFRAMEWORK',directive_all, @dir_linkframework);
  1174. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1175. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1176. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1177. AddDirective('M',directive_all, @dir_memory);
  1178. AddDirective('MACRO',directive_all, @dir_macro);
  1179. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1180. AddDirective('MAXSTACKSIZE',directive_all, @dir_maxstacksize);
  1181. AddDirective('MEMORY',directive_all, @dir_memory);
  1182. AddDirective('MESSAGE',directive_all, @dir_message);
  1183. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1184. AddDirective('MINFPCONSTPREC',directive_all, @dir_minfpconstprec);
  1185. AddDirective('MINSTACKSIZE',directive_all, @dir_minstacksize);
  1186. AddDirective('MMX',directive_all, @dir_mmx);
  1187. AddDirective('MODE',directive_all, @dir_mode);
  1188. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1189. AddDirective('NOTE',directive_all, @dir_note);
  1190. AddDirective('NOTES',directive_all, @dir_notes);
  1191. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1192. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1193. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1194. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1195. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1196. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1197. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1198. AddDirective('PACKSET',directive_all, @dir_packset);
  1199. AddDirective('PIC',directive_all, @dir_pic);
  1200. AddDirective('POP',directive_mac, @dir_pop);
  1201. AddDirective('PROFILE',directive_all, @dir_profile);
  1202. AddDirective('PUSH',directive_mac, @dir_push);
  1203. AddDirective('R',directive_all, @dir_resource);
  1204. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1205. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1206. AddDirective('RESOURCE',directive_all, @dir_resource);
  1207. AddDirective('SATURATION',directive_all, @dir_saturation);
  1208. AddDirective('SAFEFPUEXCEPTIONS',directive_all, @dir_safefpuexceptions);
  1209. AddDirective('SETPEFLAGS', directive_all, @dir_setpeflags);
  1210. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1211. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1212. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1213. AddDirective('STATIC',directive_all, @dir_static);
  1214. AddDirective('STOP',directive_all, @dir_stop);
  1215. {$ifdef powerpc}
  1216. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1217. {$endif powerpc}
  1218. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1219. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1220. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1221. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1222. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1223. AddDirective('VERSION',directive_all, @dir_version);
  1224. AddDirective('WAIT',directive_all, @dir_wait);
  1225. AddDirective('WARN',directive_all, @dir_warn);
  1226. AddDirective('WARNING',directive_all, @dir_warning);
  1227. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1228. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1229. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1230. AddDirective('Z1',directive_all, @dir_z1);
  1231. AddDirective('Z2',directive_all, @dir_z2);
  1232. AddDirective('Z4',directive_all, @dir_z4);
  1233. end;
  1234. begin
  1235. localswitchesstackpos:= 0;
  1236. end.