scandir.pas 40 KB

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