scandir.pas 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  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. uses
  21. globtype;
  22. const
  23. switchesstatestackmax = 20;
  24. type
  25. tsavedswitchesstate = record
  26. localsw: tlocalswitches;
  27. verbosity: longint;
  28. pmessage : pmessagestaterecord;
  29. end;
  30. type
  31. tswitchesstatestack = array[0..switchesstatestackmax] of tsavedswitchesstate;
  32. var
  33. switchesstatestack:tswitchesstatestack;
  34. switchesstatestackpos: Integer;
  35. procedure InitScannerDirectives;
  36. implementation
  37. uses
  38. SysUtils,
  39. cutils,cfileutl,
  40. globals,systems,widestr,cpuinfo,
  41. verbose,comphook,ppu,
  42. scanner,switches,
  43. fmodule,
  44. defutil,
  45. dirparse,link,
  46. syscinfo,
  47. symconst,symtable,symbase,symtype,symsym,
  48. rabase;
  49. {*****************************************************************************
  50. Helpers
  51. *****************************************************************************}
  52. procedure do_delphiswitch(sw:char);
  53. var
  54. state : char;
  55. begin
  56. { c contains the next char, a + or - would be fine }
  57. state:=current_scanner.readstate;
  58. if state in ['-','+'] then
  59. HandleSwitch(sw,state);
  60. end;
  61. procedure do_setverbose(flag:char);
  62. var
  63. state : char;
  64. begin
  65. { support ON/OFF }
  66. state:=current_scanner.ReadState;
  67. recordpendingverbosityswitch(flag,state);
  68. end;
  69. procedure do_moduleswitch(sw:tmoduleswitch);
  70. var
  71. state : char;
  72. begin
  73. state:=current_scanner.readstate;
  74. if (sw<>cs_modulenone) and (state in ['-','+']) then
  75. begin
  76. if state='-' then
  77. exclude(current_settings.moduleswitches,sw)
  78. else
  79. include(current_settings.moduleswitches,sw);
  80. end;
  81. end;
  82. procedure do_localswitch(sw:tlocalswitch);
  83. var
  84. state : char;
  85. begin
  86. state:=current_scanner.readstate;
  87. if (sw<>cs_localnone) and (state in ['-','+']) then
  88. recordpendinglocalswitch(sw,state);
  89. end;
  90. function do_localswitchdefault(sw:tlocalswitch): char;
  91. begin
  92. result:=current_scanner.readstatedefault;
  93. if (sw<>cs_localnone) and (result in ['-','+','*']) then
  94. recordpendinglocalswitch(sw,result);
  95. end;
  96. procedure do_moduleflagswitch(flag:cardinal;optional:boolean);
  97. var
  98. state : char;
  99. begin
  100. if optional then
  101. state:=current_scanner.readoptionalstate('+')
  102. else
  103. state:=current_scanner.readstate;
  104. if state='-' then
  105. current_module.flags:=current_module.flags and not flag
  106. else
  107. current_module.flags:=current_module.flags or flag;
  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. b : byte;
  121. begin
  122. current_scanner.skipspace;
  123. if not(c in ['0'..'9']) then
  124. begin
  125. { Support also the ON and OFF as switch }
  126. hs:=current_scanner.readid;
  127. if (hs='ON') then
  128. current_settings.packrecords:=4
  129. else if (hs='OFF') then
  130. current_settings.packrecords:=1
  131. else if m_mac in current_settings.modeswitches then
  132. begin
  133. { Support switches used in Apples Universal Interfaces}
  134. if (hs='MAC68K') then
  135. current_settings.packrecords:=mac68k_alignment
  136. { "power" alignment is the default C packrecords setting on
  137. Mac OS X }
  138. else if (hs='POWER') or (hs='POWERPC') then
  139. current_settings.packrecords:=C_alignment
  140. else if (hs='RESET') then
  141. current_settings.packrecords:=default_settings.packrecords
  142. else
  143. Message1(scan_e_illegal_pack_records,hs);
  144. end
  145. else
  146. Message1(scan_e_illegal_pack_records,hs);
  147. end
  148. else
  149. begin
  150. b:=current_scanner.readval;
  151. case b of
  152. 1 : current_settings.packrecords:=1;
  153. 2 : current_settings.packrecords:=2;
  154. 4 : current_settings.packrecords:=4;
  155. 8 : current_settings.packrecords:=8;
  156. 16 : current_settings.packrecords:=16;
  157. 32 : current_settings.packrecords:=32;
  158. else
  159. Message1(scan_e_illegal_pack_records,tostr(b));
  160. end;
  161. end;
  162. end;
  163. procedure dir_a1;
  164. begin
  165. current_settings.packrecords:=1;
  166. end;
  167. procedure dir_a2;
  168. begin
  169. current_settings.packrecords:=2;
  170. end;
  171. procedure dir_a4;
  172. begin
  173. current_settings.packrecords:=4;
  174. end;
  175. procedure dir_a8;
  176. begin
  177. current_settings.packrecords:=8;
  178. end;
  179. procedure dir_asmcpu;
  180. var
  181. s : string;
  182. cpu: tcputype;
  183. found: Boolean;
  184. begin
  185. current_scanner.skipspace;
  186. s:=current_scanner.readid;
  187. If Inside_asm_statement then
  188. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  189. if s='ANY' then
  190. current_settings.asmcputype:=cpu_none
  191. else if s='CURRENT' then
  192. current_settings.asmcputype:=current_settings.cputype
  193. else
  194. begin
  195. found:=false;
  196. for cpu:=succ(low(tcputype)) to high(tcputype) do
  197. if s=cputypestr[cpu] then
  198. begin
  199. found:=true;
  200. current_settings.asmcputype:=cpu;
  201. break;
  202. end;
  203. if not found then
  204. Message1(scan_e_illegal_asmcpu_specifier,s);
  205. end;
  206. end;
  207. procedure dir_asmmode;
  208. var
  209. s : string;
  210. begin
  211. current_scanner.skipspace;
  212. s:=current_scanner.readid;
  213. If Inside_asm_statement then
  214. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  215. if s='DEFAULT' then
  216. current_settings.asmmode:=init_settings.asmmode
  217. else
  218. if not SetAsmReadMode(s,current_settings.asmmode) then
  219. Message1(scan_e_illegal_asmmode_specifier,s);
  220. end;
  221. {$if defined(m68k) or defined(arm)}
  222. procedure dir_appid;
  223. begin
  224. if target_info.system<>system_m68k_palmos then
  225. Message(scan_w_appid_not_support);
  226. { change description global var in all cases }
  227. { it not used but in win32 and os2 }
  228. current_scanner.skipspace;
  229. palmos_applicationid:=current_scanner.readcomment;
  230. end;
  231. procedure dir_appname;
  232. begin
  233. if target_info.system<>system_m68k_palmos then
  234. Message(scan_w_appname_not_support);
  235. { change description global var in all cases }
  236. { it not used but in win32 and os2 }
  237. current_scanner.skipspace;
  238. palmos_applicationname:=current_scanner.readcomment;
  239. end;
  240. {$endif defined(m68k) or defined(arm)}
  241. procedure dir_apptype;
  242. var
  243. hs : string;
  244. begin
  245. if not (target_info.system in systems_all_windows + [system_i386_os2,
  246. system_i386_emx, system_powerpc_macos,
  247. system_arm_nds, system_i8086_msdos,
  248. system_i8086_embedded, system_m68k_atari] +
  249. systems_nativent) then
  250. begin
  251. if m_delphi in current_settings.modeswitches then
  252. Message(scan_n_app_type_not_support)
  253. else
  254. Message(scan_w_app_type_not_support);
  255. end
  256. else
  257. begin
  258. if not current_module.in_global then
  259. Message(scan_w_switch_is_global)
  260. else
  261. begin
  262. current_scanner.skipspace;
  263. hs:=current_scanner.readid;
  264. if (hs='GUI') and not (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  265. SetApptype(app_gui)
  266. else if (hs='CONSOLE') and not (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  267. SetApptype(app_cui)
  268. else if (hs='NATIVE') and (target_info.system in systems_windows + systems_nativent) then
  269. SetApptype(app_native)
  270. else if (hs='FS') and (target_info.system in [system_i386_os2,
  271. system_i386_emx]) then
  272. SetApptype(app_fs)
  273. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  274. SetApptype(app_tool)
  275. else if (hs='ARM9') and (target_info.system in [system_arm_nds]) then
  276. SetApptype(app_arm9)
  277. else if (hs='ARM7') and (target_info.system in [system_arm_nds]) then
  278. SetApptype(app_arm7)
  279. else if (hs='COM') and (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  280. SetApptype(app_com)
  281. else if (hs='EXE') and (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  282. SetApptype(app_cui)
  283. else
  284. Message1(scan_w_unsupported_app_type,hs);
  285. end;
  286. end;
  287. end;
  288. procedure dir_calling;
  289. var
  290. hs : string;
  291. begin
  292. current_scanner.skipspace;
  293. hs:=current_scanner.readid;
  294. if (hs='') then
  295. Message(parser_e_proc_directive_expected)
  296. else
  297. recordpendingcallingswitch(hs);
  298. end;
  299. procedure dir_checklowaddrloads;
  300. begin
  301. do_localswitchdefault(cs_check_low_addr_load);
  302. end;
  303. procedure dir_checkpointer;
  304. var
  305. switch: char;
  306. begin
  307. switch:=do_localswitchdefault(cs_checkpointer);
  308. if (switch='+') and
  309. not(target_info.system in systems_support_checkpointer) then
  310. Message1(scan_e_unsupported_switch,'CHECKPOINTER+');
  311. end;
  312. procedure dir_objectchecks;
  313. begin
  314. do_localswitch(cs_check_object);
  315. end;
  316. procedure dir_ieeeerrors;
  317. begin
  318. do_localswitch(cs_ieee_errors);
  319. end;
  320. procedure dir_assertions;
  321. begin
  322. do_delphiswitch('C');
  323. end;
  324. procedure dir_booleval;
  325. begin
  326. do_delphiswitch('B');
  327. end;
  328. procedure dir_debuginfo;
  329. begin
  330. do_delphiswitch('D');
  331. end;
  332. procedure dir_denypackageunit;
  333. begin
  334. do_moduleflagswitch(uf_package_deny,true);
  335. end;
  336. procedure dir_description;
  337. begin
  338. if not (target_info.system in systems_all_windows+[system_i386_os2,system_i386_emx,
  339. system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  340. Message(scan_w_description_not_support);
  341. { change description global var in all cases }
  342. { it not used but in win32, os2 and netware }
  343. current_scanner.skipspace;
  344. description:=current_scanner.readcomment;
  345. DescriptionSetExplicity:=true;
  346. end;
  347. procedure dir_screenname; {ad}
  348. begin
  349. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  350. {Message(scan_w_decription_not_support);}
  351. comment (V_Warning,'Screenname only supported for target netware');
  352. current_scanner.skipspace;
  353. nwscreenname:=current_scanner.readcomment;
  354. end;
  355. procedure dir_threadname; {ad}
  356. begin
  357. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  358. {Message(scan_w_decription_not_support);}
  359. comment (V_Warning,'Threadname only supported for target netware');
  360. current_scanner.skipspace;
  361. nwthreadname:=current_scanner.readcomment;
  362. end;
  363. procedure dir_copyright; {ad}
  364. begin
  365. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  366. {Message(scan_w_decription_not_support);}
  367. comment (V_Warning,'Copyright only supported for target netware');
  368. current_scanner.skipspace;
  369. nwcopyright:=current_scanner.readcomment;
  370. end;
  371. procedure dir_error;
  372. begin
  373. do_message(scan_e_user_defined);
  374. end;
  375. procedure dir_extendedsyntax;
  376. begin
  377. do_delphiswitch('X');
  378. end;
  379. procedure dir_forcefarcalls;
  380. begin
  381. if not (target_info.system in [system_i8086_msdos,system_i8086_embedded])
  382. {$ifdef i8086}
  383. or (current_settings.x86memorymodel in x86_near_code_models)
  384. {$endif i8086}
  385. then
  386. begin
  387. Message1(scan_n_ignored_switch,pattern);
  388. exit;
  389. end;
  390. do_localswitch(cs_force_far_calls);
  391. end;
  392. procedure dir_fatal;
  393. begin
  394. do_message(scan_f_user_defined);
  395. end;
  396. procedure dir_fputype;
  397. begin
  398. current_scanner.skipspace;
  399. undef_system_macro('FPU'+fputypestr[current_settings.fputype]);
  400. if not(SetFPUType(upper(current_scanner.readcomment),current_settings.fputype)) then
  401. comment(V_Error,'Illegal FPU type');
  402. def_system_macro('FPU'+fputypestr[current_settings.fputype]);
  403. end;
  404. procedure dir_frameworkpath;
  405. begin
  406. if not current_module.in_global then
  407. Message(scan_w_switch_is_global)
  408. else if not(target_info.system in systems_darwin) then
  409. begin
  410. Message(scan_w_frameworks_darwin_only);
  411. current_scanner.skipspace;
  412. current_scanner.readcomment
  413. end
  414. else
  415. begin
  416. current_scanner.skipspace;
  417. current_module.localframeworksearchpath.AddPath(current_scanner.readcomment,false);
  418. end;
  419. end;
  420. procedure dir_goto;
  421. begin
  422. do_moduleswitch(cs_support_goto);
  423. end;
  424. procedure dir_hint;
  425. begin
  426. do_message(scan_h_user_defined);
  427. end;
  428. procedure dir_hints;
  429. begin
  430. do_setverbose('H');
  431. end;
  432. procedure dir_imagebase;
  433. begin
  434. if not (target_info.system in (systems_windows+systems_wince)) then
  435. Message(scan_w_imagebase_not_support);
  436. current_scanner.skipspace;
  437. imagebase:=current_scanner.readval;
  438. ImageBaseSetExplicity:=true
  439. end;
  440. procedure dir_implicitexceptions;
  441. begin
  442. do_moduleswitch(cs_implicit_exceptions);
  443. end;
  444. procedure dir_importeddata;
  445. begin
  446. do_delphiswitch('G');
  447. end;
  448. procedure dir_includepath;
  449. begin
  450. if not current_module.in_global then
  451. Message(scan_w_switch_is_global)
  452. else
  453. begin
  454. current_scanner.skipspace;
  455. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  456. end;
  457. end;
  458. procedure dir_info;
  459. begin
  460. do_message(scan_i_user_defined);
  461. end;
  462. procedure dir_inline;
  463. begin
  464. do_localswitch(cs_do_inline);
  465. end;
  466. procedure dir_interfaces;
  467. var
  468. hs : string;
  469. begin
  470. {corba/com/default}
  471. current_scanner.skipspace;
  472. hs:=current_scanner.readid;
  473. {$ifndef jvm}
  474. if (hs='CORBA') then
  475. current_settings.interfacetype:=it_interfacecorba
  476. else if (hs='COM') then
  477. current_settings.interfacetype:=it_interfacecom
  478. else
  479. {$endif jvm}
  480. if (hs='DEFAULT') then
  481. current_settings.interfacetype:=init_settings.interfacetype
  482. else
  483. Message(scan_e_invalid_interface_type);
  484. end;
  485. procedure dir_iochecks;
  486. begin
  487. do_delphiswitch('I');
  488. end;
  489. procedure dir_libexport;
  490. begin
  491. {not implemented}
  492. end;
  493. procedure dir_librarypath;
  494. begin
  495. if not current_module.in_global then
  496. Message(scan_w_switch_is_global)
  497. else
  498. begin
  499. current_scanner.skipspace;
  500. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  501. end;
  502. end;
  503. procedure dir_link;
  504. var
  505. s : string;
  506. begin
  507. current_scanner.skipspace;
  508. if scanner.c = '''' then
  509. begin
  510. s:= current_scanner.readquotedstring;
  511. current_scanner.readcomment
  512. end
  513. else
  514. s:= trimspace(current_scanner.readcomment);
  515. s:=FixFileName(s);
  516. if ExtractFileExt(s)='' then
  517. s:=ChangeFileExt(s,target_info.objext);
  518. current_module.linkotherofiles.add(s,link_always);
  519. end;
  520. procedure dir_linkframework;
  521. var
  522. s : string;
  523. begin
  524. current_scanner.skipspace;
  525. if scanner.c = '''' then
  526. begin
  527. s:= current_scanner.readquotedstring;
  528. current_scanner.readcomment
  529. end
  530. else
  531. s:= trimspace(current_scanner.readcomment);
  532. s:=FixFileName(s);
  533. if (target_info.system in systems_darwin) then
  534. current_module.linkotherframeworks.add(s,link_always)
  535. else
  536. Message(scan_w_frameworks_darwin_only);
  537. end;
  538. procedure dir_linklib;
  539. type
  540. tLinkMode=(lm_shared,lm_static);
  541. var
  542. s : string;
  543. quote : char;
  544. libext,
  545. libname,
  546. linkmodestr : string;
  547. p : longint;
  548. linkMode : tLinkMode;
  549. begin
  550. current_scanner.skipspace;
  551. if scanner.c = '''' then
  552. begin
  553. libname:= current_scanner.readquotedstring;
  554. s:= current_scanner.readcomment;
  555. p:=pos(',',s);
  556. end
  557. else
  558. begin
  559. s:= current_scanner.readcomment;
  560. p:=pos(',',s);
  561. if p=0 then
  562. libname:=TrimSpace(s)
  563. else
  564. libname:=TrimSpace(copy(s,1,p-1));
  565. end;
  566. if p=0 then
  567. linkmodeStr:=''
  568. else
  569. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  570. if (libname='') or (libname='''''') or (libname='""') then
  571. exit;
  572. { create library name }
  573. if libname[1] in ['''','"'] then
  574. begin
  575. quote:=libname[1];
  576. Delete(libname,1,1);
  577. p:=pos(quote,libname);
  578. if p>0 then
  579. Delete(libname,p,1);
  580. end;
  581. libname:=FixFileName(libname);
  582. { get linkmode, default is to check the extension for
  583. the static library, otherwise shared linking is assumed }
  584. linkmode:=lm_shared;
  585. if linkModeStr='' then
  586. begin
  587. libext:=ExtractFileExt(libname);
  588. if libext=target_info.staticClibext then
  589. linkMode:=lm_static;
  590. end
  591. else if linkModeStr='STATIC' then
  592. linkmode:=lm_static
  593. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  594. linkmode:=lm_shared
  595. else
  596. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  597. { add to the list of other libraries }
  598. if linkMode=lm_static then
  599. current_module.linkOtherStaticLibs.add(libname,link_always)
  600. else
  601. current_module.linkOtherSharedLibs.add(libname,link_always);
  602. end;
  603. procedure dir_localsymbols;
  604. begin
  605. do_delphiswitch('L');
  606. end;
  607. procedure dir_longstrings;
  608. begin
  609. do_delphiswitch('H');
  610. end;
  611. procedure dir_macro;
  612. begin
  613. do_moduleswitch(cs_support_macro);
  614. end;
  615. procedure dir_pascalmainname;
  616. var
  617. s: string;
  618. begin
  619. current_scanner.skipspace;
  620. s:=trimspace(current_scanner.readcomment);
  621. if assigned(current_module.mainname) and
  622. (s<>current_module.mainname^) then
  623. begin
  624. Message1(scan_w_multiple_main_name_overrides,current_module.mainname^);
  625. stringdispose(current_module.mainname)
  626. end
  627. else if (mainaliasname<>defaultmainaliasname) and
  628. (mainaliasname<>s) then
  629. Message1(scan_w_multiple_main_name_overrides,mainaliasname);
  630. mainaliasname:=s;
  631. if (mainaliasname<>defaultmainaliasname) then
  632. current_module.mainname:=stringdup(mainaliasname);
  633. end;
  634. procedure dir_maxfpuregisters;
  635. var
  636. l : integer;
  637. hs : string;
  638. begin
  639. current_scanner.skipspace;
  640. if not(c in ['0'..'9']) then
  641. begin
  642. hs:=current_scanner.readid;
  643. if (hs='NORMAL') or (hs='DEFAULT') then
  644. current_settings.maxfpuregisters:=-1
  645. else
  646. Message(scan_e_invalid_maxfpureg_value);
  647. end
  648. else
  649. begin
  650. l:=current_scanner.readval;
  651. case l of
  652. 0..8:
  653. current_settings.maxfpuregisters:=l;
  654. else
  655. Message(scan_e_invalid_maxfpureg_value);
  656. end;
  657. end;
  658. end;
  659. procedure dir_maxstacksize;
  660. begin
  661. if not (target_info.system in (systems_windows+systems_wince)) then
  662. Message(scan_w_maxstacksize_not_support);
  663. current_scanner.skipspace;
  664. maxstacksize:=current_scanner.readval;
  665. MaxStackSizeSetExplicity:=true;
  666. end;
  667. procedure dir_memory;
  668. var
  669. l : longint;
  670. heapsize_limit: longint;
  671. maxheapsize_limit: longint;
  672. begin
  673. {$if defined(i8086)}
  674. if current_settings.x86memorymodel in x86_far_data_models then
  675. begin
  676. heapsize_limit:=655360;
  677. maxheapsize_limit:=655360;
  678. end
  679. else
  680. begin
  681. heapsize_limit:=65520;
  682. maxheapsize_limit:=65520;
  683. end;
  684. {$elseif defined(cpu16bitaddr)}
  685. heapsize_limit:=65520;
  686. maxheapsize_limit:=65520;
  687. {$else}
  688. heapsize_limit:=high(heapsize);
  689. maxheapsize_limit:=high(maxheapsize);
  690. {$endif}
  691. current_scanner.skipspace;
  692. l:=current_scanner.readval;
  693. if (l>=1024)
  694. {$ifdef cpu16bitaddr}
  695. and (l<=65521) { TP7's $M directive allows specifying a stack size of
  696. 65521, but it actually sets the stack size to 65520 }
  697. {$else cpu16bitaddr}
  698. and (l<67107840)
  699. {$endif cpu16bitaddr}
  700. then
  701. stacksize:=min(l,{$ifdef cpu16bitaddr}65520{$else}67107839{$endif})
  702. else
  703. Message(scan_w_invalid_stacksize);
  704. if c=',' then
  705. begin
  706. current_scanner.readchar;
  707. current_scanner.skipspace;
  708. l:=current_scanner.readval;
  709. if l>=1024 then
  710. heapsize:=min(l,heapsize_limit);
  711. if c=',' then
  712. begin
  713. current_scanner.readchar;
  714. current_scanner.skipspace;
  715. l:=current_scanner.readval;
  716. if l>=heapsize then
  717. maxheapsize:=min(l,maxheapsize_limit)
  718. else
  719. Message(scan_w_heapmax_lessthan_heapmin);
  720. end;
  721. end;
  722. end;
  723. procedure dir_message;
  724. var
  725. hs : string;
  726. w : longint;
  727. begin
  728. w:=0;
  729. current_scanner.skipspace;
  730. { Message level specified? }
  731. if c='''' then
  732. w:=scan_n_user_defined
  733. else
  734. begin
  735. hs:=current_scanner.readid;
  736. if (hs='WARN') or (hs='WARNING') then
  737. w:=scan_w_user_defined
  738. else
  739. if (hs='ERROR') then
  740. w:=scan_e_user_defined
  741. else
  742. if (hs='FATAL') then
  743. w:=scan_f_user_defined
  744. else
  745. if (hs='HINT') then
  746. w:=scan_h_user_defined
  747. else
  748. if (hs='NOTE') then
  749. w:=scan_n_user_defined
  750. else
  751. Message1(scan_w_illegal_directive,hs);
  752. end;
  753. { Only print message when there was no error }
  754. if w<>0 then
  755. begin
  756. current_scanner.skipspace;
  757. if c='''' then
  758. hs:=current_scanner.readquotedstring
  759. else
  760. hs:=current_scanner.readcomment;
  761. Message1(w,hs);
  762. end
  763. else
  764. current_scanner.readcomment;
  765. end;
  766. procedure dir_minstacksize;
  767. begin
  768. if not (target_info.system in (systems_windows+systems_wince)) then
  769. Message(scan_w_minstacksize_not_support);
  770. current_scanner.skipspace;
  771. minstacksize:=current_scanner.readval;
  772. MinStackSizeSetExplicity:=true;
  773. end;
  774. procedure dir_mode;
  775. begin
  776. if not current_module.in_global then
  777. Message(scan_w_switch_is_global)
  778. else
  779. begin
  780. current_scanner.skipspace;
  781. current_scanner.readstring;
  782. if not current_module.mode_switch_allowed and
  783. not ((m_mac in current_settings.modeswitches) and (pattern='MACPAS')) then
  784. Message1(scan_e_mode_switch_not_allowed,pattern)
  785. else if not SetCompileMode(pattern,false) then
  786. Message1(scan_w_illegal_switch,pattern)
  787. end;
  788. current_module.mode_switch_allowed:= false;
  789. end;
  790. procedure dir_modeswitch;
  791. var
  792. s : string;
  793. begin
  794. if not current_module.in_global then
  795. Message(scan_w_switch_is_global)
  796. else
  797. begin
  798. current_scanner.skipspace;
  799. current_scanner.readstring;
  800. s:=pattern;
  801. if c in ['+','-'] then
  802. s:=s+current_scanner.readstate;
  803. if not SetCompileModeSwitch(s,false) then
  804. Message1(scan_w_illegal_switch,s)
  805. end;
  806. end;
  807. procedure dir_namespace;
  808. var
  809. s : string;
  810. begin
  811. { used to define Java package names for all types declared in the
  812. current unit }
  813. if not current_module.in_global then
  814. Message(scan_w_switch_is_global)
  815. else
  816. begin
  817. current_scanner.skipspace;
  818. current_scanner.readstring;
  819. s:=orgpattern;
  820. while c='.' do
  821. begin
  822. current_scanner.readchar;
  823. current_scanner.readstring;
  824. s:=s+'.'+orgpattern;
  825. end;
  826. disposestr(current_module.namespace);
  827. current_module.namespace:=stringdup(s);
  828. end;
  829. end;
  830. procedure dir_mmx;
  831. begin
  832. do_localswitch(cs_mmx);
  833. end;
  834. procedure dir_note;
  835. begin
  836. do_message(scan_n_user_defined);
  837. end;
  838. procedure dir_notes;
  839. begin
  840. do_setverbose('N');
  841. end;
  842. procedure dir_objectpath;
  843. begin
  844. if not current_module.in_global then
  845. Message(scan_w_switch_is_global)
  846. else
  847. begin
  848. current_scanner.skipspace;
  849. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  850. end;
  851. end;
  852. procedure dir_openstrings;
  853. begin
  854. do_delphiswitch('P');
  855. end;
  856. procedure dir_optimization;
  857. var
  858. hs : string;
  859. begin
  860. current_scanner.skipspace;
  861. { Support also the ON and OFF as switch }
  862. hs:=current_scanner.readid;
  863. if (hs='ON') then
  864. current_settings.optimizerswitches:=level2optimizerswitches
  865. else if (hs='OFF') then
  866. current_settings.optimizerswitches:=[]
  867. else if (hs='DEFAULT') then
  868. current_settings.optimizerswitches:=init_settings.optimizerswitches
  869. else
  870. begin
  871. if not UpdateOptimizerStr(hs,current_settings.optimizerswitches) then
  872. Message1(scan_e_illegal_optimization_specifier,hs);
  873. end;
  874. end;
  875. procedure dir_overflowchecks;
  876. begin
  877. do_delphiswitch('Q');
  878. end;
  879. procedure dir_packenum;
  880. var
  881. hs : string;
  882. begin
  883. current_scanner.skipspace;
  884. if not(c in ['0'..'9']) then
  885. begin
  886. hs:=current_scanner.readid;
  887. if (hs='NORMAL') or (hs='DEFAULT') then
  888. current_settings.packenum:=4
  889. else
  890. Message1(scan_e_illegal_pack_enum, hs);
  891. end
  892. else
  893. begin
  894. case current_scanner.readval of
  895. 1 : current_settings.packenum:=1;
  896. 2 : current_settings.packenum:=2;
  897. 4 : current_settings.packenum:=4;
  898. else
  899. Message1(scan_e_illegal_pack_enum, pattern);
  900. end;
  901. end;
  902. end;
  903. procedure dir_minfpconstprec;
  904. begin
  905. current_scanner.skipspace;
  906. if not SetMinFPConstPrec(current_scanner.readid,current_settings.minfpconstprec) then
  907. Message1(scan_e_illegal_minfpconstprec, pattern);
  908. end;
  909. procedure dir_packrecords;
  910. var
  911. hs : string;
  912. begin
  913. { can't change packrecords setting on managed vm targets }
  914. if target_info.system in systems_managed_vm then
  915. Message1(scanner_w_directive_ignored_on_target, 'PACKRECORDS');
  916. current_scanner.skipspace;
  917. if not(c in ['0'..'9']) then
  918. begin
  919. hs:=current_scanner.readid;
  920. { C has the special recordalignmax of C_alignment }
  921. if (hs='C') then
  922. current_settings.packrecords:=C_alignment
  923. else
  924. if (hs='NORMAL') or (hs='DEFAULT') then
  925. current_settings.packrecords:=default_settings.packrecords
  926. else
  927. Message1(scan_e_illegal_pack_records,hs);
  928. end
  929. else
  930. begin
  931. case current_scanner.readval of
  932. 1 : current_settings.packrecords:=1;
  933. 2 : current_settings.packrecords:=2;
  934. 4 : current_settings.packrecords:=4;
  935. 8 : current_settings.packrecords:=8;
  936. 16 : current_settings.packrecords:=16;
  937. 32 : current_settings.packrecords:=32;
  938. else
  939. Message1(scan_e_illegal_pack_records,pattern);
  940. end;
  941. end;
  942. end;
  943. procedure dir_packset;
  944. var
  945. hs : string;
  946. begin
  947. current_scanner.skipspace;
  948. if not(c in ['1','2','4','8']) then
  949. begin
  950. hs:=current_scanner.readid;
  951. if (hs='FIXED') or (hs='DEFAULT') OR (hs='NORMAL') then
  952. current_settings.setalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  953. else
  954. Message(scan_e_only_packset);
  955. end
  956. else
  957. begin
  958. case current_scanner.readval of
  959. 1 : current_settings.setalloc:=1;
  960. 2 : current_settings.setalloc:=2;
  961. 4 : current_settings.setalloc:=4;
  962. 8 : current_settings.setalloc:=8;
  963. else
  964. Message(scan_e_only_packset);
  965. end;
  966. end;
  967. end;
  968. procedure dir_pic;
  969. begin
  970. { windows doesn't need/support pic }
  971. if tf_no_pic_supported in target_info.flags then
  972. message(scan_w_pic_ignored)
  973. else
  974. do_moduleswitch(cs_create_pic);
  975. end;
  976. procedure dir_pop;
  977. begin
  978. if switchesstatestackpos < 1 then
  979. Message(scan_e_too_many_pop);
  980. Dec(switchesstatestackpos);
  981. recordpendinglocalfullswitch(switchesstatestack[switchesstatestackpos].localsw);
  982. recordpendingverbosityfullswitch(switchesstatestack[switchesstatestackpos].verbosity);
  983. pendingstate.nextmessagerecord:=switchesstatestack[switchesstatestackpos].pmessage;
  984. { Reset verbosity and forget previous pmeesage }
  985. RestoreLocalVerbosity(nil);
  986. current_settings.pmessage:=nil;
  987. { Do not yet activate these changes, as otherwise
  988. you get problem idf you put a $pop just right after
  989. a addition for instance fro which you explicitly truned the overflow check
  990. out by using $Q- after a $push PM 2012-08-29 }
  991. // flushpendingswitchesstate;
  992. end;
  993. procedure dir_pointermath;
  994. begin
  995. do_localswitch(cs_pointermath);
  996. end;
  997. procedure dir_profile;
  998. begin
  999. do_moduleswitch(cs_profile);
  1000. { defined/undefine FPC_PROFILE }
  1001. if cs_profile in current_settings.moduleswitches then
  1002. def_system_macro('FPC_PROFILE')
  1003. else
  1004. undef_system_macro('FPC_PROFILE');
  1005. end;
  1006. procedure dir_push;
  1007. begin
  1008. if switchesstatestackpos > switchesstatestackmax then
  1009. Message(scan_e_too_many_push);
  1010. flushpendingswitchesstate;
  1011. switchesstatestack[switchesstatestackpos].localsw:= current_settings.localswitches;
  1012. switchesstatestack[switchesstatestackpos].pmessage:= current_settings.pmessage;
  1013. switchesstatestack[switchesstatestackpos].verbosity:=status.verbosity;
  1014. Inc(switchesstatestackpos);
  1015. end;
  1016. procedure dir_rangechecks;
  1017. begin
  1018. do_delphiswitch('R');
  1019. end;
  1020. procedure dir_referenceinfo;
  1021. begin
  1022. do_delphiswitch('Y');
  1023. end;
  1024. procedure dir_resource;
  1025. var
  1026. s : string;
  1027. begin
  1028. current_scanner.skipspace;
  1029. if scanner.c = '''' then
  1030. begin
  1031. s:= current_scanner.readquotedstring;
  1032. current_scanner.readcomment
  1033. end
  1034. else
  1035. s:= trimspace(current_scanner.readcomment);
  1036. { replace * with the name of the main source.
  1037. This should always be defined. }
  1038. if s[1]='*' then
  1039. if Assigned(Current_Module) then
  1040. begin
  1041. delete(S,1,1);
  1042. insert(ChangeFileExt(ExtractFileName(current_module.mainsource),''),S,1 );
  1043. end;
  1044. s:=FixFileName(s);
  1045. if ExtractFileExt(s)='' then
  1046. s:=ChangeFileExt(s,target_info.resext);
  1047. if target_info.res<>res_none then
  1048. begin
  1049. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  1050. if (res_single_file in target_res.resflags) and
  1051. not (Current_module.ResourceFiles.Empty) then
  1052. Message(scan_w_only_one_resourcefile_supported)
  1053. else
  1054. current_module.resourcefiles.insert(FixFileName(s));
  1055. end
  1056. else
  1057. Message(scan_e_resourcefiles_not_supported);
  1058. end;
  1059. procedure dir_saturation;
  1060. begin
  1061. do_localswitch(cs_mmx_saturation);
  1062. end;
  1063. procedure dir_safefpuexceptions;
  1064. begin
  1065. do_localswitch(cs_fpu_fwait);
  1066. end;
  1067. procedure dir_scopedenums;
  1068. begin
  1069. do_localswitch(cs_scopedenums);
  1070. end;
  1071. function get_peflag_const(const ident:string;error:longint):longint;
  1072. var
  1073. srsym : tsym;
  1074. srsymtable : tsymtable;
  1075. begin
  1076. result:=0;
  1077. if searchsym(ident,srsym,srsymtable) then
  1078. if (srsym.typ=constsym) and
  1079. (tconstsym(srsym).consttyp=constord) and
  1080. is_integer(tconstsym(srsym).constdef) then
  1081. with tconstsym(srsym).value.valueord do
  1082. if signed then
  1083. result:=tconstsym(srsym).value.valueord.svalue
  1084. else
  1085. result:=tconstsym(srsym).value.valueord.uvalue
  1086. else
  1087. message(error)
  1088. else
  1089. message1(sym_e_id_not_found,ident);
  1090. end;
  1091. procedure dir_setpeflags;
  1092. var
  1093. ident : string;
  1094. begin
  1095. if not (target_info.system in (systems_all_windows)) then
  1096. Message(scan_w_setpeflags_not_support);
  1097. current_scanner.skipspace;
  1098. ident:=current_scanner.readid;
  1099. if ident<>'' then
  1100. peflags:=peflags or get_peflag_const(ident,scan_e_illegal_peflag)
  1101. else
  1102. peflags:=peflags or current_scanner.readval;
  1103. SetPEFlagsSetExplicity:=true;
  1104. end;
  1105. procedure dir_setpeoptflags;
  1106. var
  1107. ident : string;
  1108. begin
  1109. if not (target_info.system in (systems_all_windows)) then
  1110. Message(scan_w_setpeoptflags_not_support);
  1111. current_scanner.skipspace;
  1112. ident:=current_scanner.readid;
  1113. if ident<>'' then
  1114. peoptflags:=peoptflags or get_peflag_const(ident,scan_e_illegal_peoptflag)
  1115. else
  1116. peoptflags:=peoptflags or current_scanner.readval;
  1117. SetPEOptFlagsSetExplicity:=true;
  1118. end;
  1119. procedure dir_smartlink;
  1120. begin
  1121. do_moduleswitch(cs_create_smart);
  1122. if (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  1123. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) and
  1124. { smart linking does not yet work with DWARF debug info on most targets }
  1125. (cs_create_smart in current_settings.moduleswitches) and
  1126. not (af_outputbinary in target_asm.flags) then
  1127. begin
  1128. Message(option_dwarf_smart_linking);
  1129. Exclude(current_settings.moduleswitches,cs_create_smart);
  1130. end;
  1131. { Also create a smartlinked version, on an assembler that
  1132. does not support smartlink sections like nasm?
  1133. This is not compatible with using internal linker. }
  1134. if ((cs_link_smart in current_settings.globalswitches) or
  1135. (cs_create_smart in current_settings.moduleswitches)) and
  1136. (af_needar in target_asm.flags) and
  1137. not (af_smartlink_sections in target_asm.flags) and
  1138. not (cs_link_extern in current_settings.globalswitches) then
  1139. begin
  1140. DoneLinker;
  1141. Message(option_smart_link_requires_external_linker);
  1142. include(current_settings.globalswitches,cs_link_extern);
  1143. InitLinker;
  1144. end
  1145. end;
  1146. procedure dir_stackframes;
  1147. begin
  1148. do_delphiswitch('W');
  1149. end;
  1150. procedure dir_stop;
  1151. begin
  1152. do_message(scan_f_user_defined);
  1153. end;
  1154. procedure dir_stringchecks;
  1155. begin
  1156. // Delphi adds checks that ansistring and unicodestring are correct in
  1157. // different places. Skip it for now.
  1158. end;
  1159. procedure dir_syscall;
  1160. var
  1161. sctype : string;
  1162. syscall : psyscallinfo;
  1163. begin
  1164. current_scanner.skipspace;
  1165. sctype:=current_scanner.readid;
  1166. syscall:=get_syscall_by_name(sctype);
  1167. if assigned(syscall) then
  1168. begin
  1169. if not (target_info.system in syscall^.validon) then
  1170. Message(scan_w_syscall_convention_not_useable_on_target)
  1171. else
  1172. set_default_syscall(syscall^.procoption);
  1173. exit;
  1174. end;
  1175. Message(scan_w_syscall_convention_invalid);
  1176. end;
  1177. procedure dir_targetswitch;
  1178. var
  1179. name, value: string;
  1180. begin
  1181. { note: *not* recorded in the tokenstream, so not replayed for generics }
  1182. current_scanner.skipspace;
  1183. name:=current_scanner.readid;
  1184. if c='=' then
  1185. begin
  1186. current_scanner.readchar;
  1187. current_scanner.readid;
  1188. value:=orgpattern;
  1189. UpdateTargetSwitchStr(name+'='+value,current_settings.targetswitches,current_module.in_global);
  1190. end
  1191. else if c='-' then
  1192. begin
  1193. current_scanner.readchar;
  1194. UpdateTargetSwitchStr(name+'-',current_settings.targetswitches,current_module.in_global);
  1195. end
  1196. else
  1197. UpdateTargetSwitchStr(name,current_settings.targetswitches,current_module.in_global);
  1198. end;
  1199. procedure dir_typedaddress;
  1200. begin
  1201. do_delphiswitch('T');
  1202. end;
  1203. procedure dir_typeinfo;
  1204. begin
  1205. do_delphiswitch('M');
  1206. end;
  1207. procedure dir_unitpath;
  1208. begin
  1209. if not current_module.in_global then
  1210. Message(scan_w_switch_is_global)
  1211. else
  1212. with current_scanner,current_module,localunitsearchpath do
  1213. begin
  1214. skipspace;
  1215. AddPath(path,readcomment,false);
  1216. end;
  1217. end;
  1218. procedure dir_varparacopyoutcheck;
  1219. begin
  1220. if not(target_info.system in systems_jvm) then
  1221. begin
  1222. Message1(scan_w_illegal_switch,pattern);
  1223. exit;
  1224. end;
  1225. do_localswitch(cs_check_var_copyout);
  1226. end;
  1227. procedure dir_varpropsetter;
  1228. begin
  1229. do_localswitch(cs_varpropsetter);
  1230. end;
  1231. procedure dir_varstringchecks;
  1232. begin
  1233. do_delphiswitch('V');
  1234. end;
  1235. procedure dir_version;
  1236. var
  1237. major, minor, revision : longint;
  1238. error : integer;
  1239. begin
  1240. if not (target_info.system in systems_all_windows+[system_i386_os2,system_i386_emx,
  1241. system_i386_netware,system_i386_wdosx,
  1242. system_i386_netwlibc]) then
  1243. begin
  1244. Message(scan_n_version_not_support);
  1245. exit;
  1246. end;
  1247. if (compile_level<>1) then
  1248. Message(scan_n_only_exe_version)
  1249. else
  1250. begin
  1251. { change description global var in all cases }
  1252. { it not used but in win32, os2 and netware }
  1253. current_scanner.skipspace;
  1254. { we should only accept Major.Minor format for win32 and os2 }
  1255. current_scanner.readnumber;
  1256. major:=0;
  1257. minor:=0;
  1258. revision:=0;
  1259. val(pattern,major,error);
  1260. if (error<>0) or (major > high(word)) or (major < 0) then
  1261. begin
  1262. Message1(scan_w_wrong_version_ignored,pattern);
  1263. exit;
  1264. end;
  1265. if c='.' then
  1266. begin
  1267. current_scanner.readchar;
  1268. current_scanner.readnumber;
  1269. val(pattern,minor,error);
  1270. if (error<>0) or (minor > high(word)) or (minor < 0) then
  1271. begin
  1272. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  1273. exit;
  1274. end;
  1275. if (c='.') and
  1276. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  1277. begin
  1278. current_scanner.readchar;
  1279. current_scanner.readnumber;
  1280. val(pattern,revision,error);
  1281. if (error<>0) or (revision > high(word)) or (revision < 0) then
  1282. begin
  1283. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  1284. exit;
  1285. end;
  1286. dllmajor:=word(major);
  1287. dllminor:=word(minor);
  1288. dllrevision:=word(revision);
  1289. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  1290. end
  1291. else
  1292. begin
  1293. dllmajor:=word(major);
  1294. dllminor:=word(minor);
  1295. dllversion:=tostr(major)+'.'+tostr(minor);
  1296. end;
  1297. end
  1298. else
  1299. dllversion:=tostr(major);
  1300. end;
  1301. end;
  1302. procedure dir_wait;
  1303. var
  1304. had_info : boolean;
  1305. begin
  1306. had_info:=(status.verbosity and V_Info)<>0;
  1307. { this message should allways appear !! }
  1308. status.verbosity:=status.verbosity or V_Info;
  1309. Message(scan_i_press_enter);
  1310. readln;
  1311. If not(had_info) then
  1312. status.verbosity:=status.verbosity and (not V_Info);
  1313. end;
  1314. { delphi compatible warn directive:
  1315. $warn <identifier> on
  1316. $warn <identifier> off
  1317. $warn <identifier> error
  1318. }
  1319. procedure dir_warn;
  1320. var
  1321. ident : string;
  1322. state : string;
  1323. msgstate : tmsgstate;
  1324. i : integer;
  1325. begin
  1326. current_scanner.skipspace;
  1327. ident:=current_scanner.readid;
  1328. current_scanner.skipspace;
  1329. state:=current_scanner.readid;
  1330. { support both delphi and fpc switches }
  1331. { use local ms_on/off/error tmsgstate values }
  1332. if (state='ON') or (state='+') then
  1333. msgstate:=ms_on
  1334. else
  1335. if (state='OFF') or (state='-') then
  1336. msgstate:=ms_off
  1337. else
  1338. if (state='ERROR') then
  1339. msgstate:=ms_error
  1340. else
  1341. begin
  1342. Message1(scanner_e_illegal_warn_state,state);
  1343. exit;
  1344. end;
  1345. if ident='CONSTRUCTING_ABSTRACT' then
  1346. begin
  1347. recordpendingmessagestate(type_w_instance_with_abstract, msgstate);
  1348. recordpendingmessagestate(type_w_instance_abstract_class, msgstate);
  1349. end
  1350. else
  1351. if ident='IMPLICIT_VARIANTS' then
  1352. recordpendingmessagestate(parser_w_implicit_uses_of_variants_unit, msgstate)
  1353. else
  1354. if ident='NO_RETVAL' then
  1355. recordpendingmessagestate(sym_w_function_result_not_set, msgstate)
  1356. else
  1357. if ident='SYMBOL_DEPRECATED' then
  1358. begin
  1359. recordpendingmessagestate(sym_w_deprecated_symbol, msgstate);
  1360. recordpendingmessagestate(sym_w_deprecated_symbol_with_msg, msgstate);
  1361. end
  1362. else
  1363. if ident='SYMBOL_EXPERIMENTAL' then
  1364. recordpendingmessagestate(sym_w_experimental_symbol, msgstate)
  1365. else
  1366. if ident='SYMBOL_LIBRARY' then
  1367. recordpendingmessagestate(sym_w_library_symbol, msgstate)
  1368. else
  1369. if ident='SYMBOL_PLATFORM' then
  1370. recordpendingmessagestate(sym_w_non_portable_symbol, msgstate)
  1371. else
  1372. if ident='SYMBOL_UNIMPLEMENTED' then
  1373. recordpendingmessagestate(sym_w_non_implemented_symbol, msgstate)
  1374. else
  1375. if ident='UNIT_DEPRECATED' then
  1376. begin
  1377. recordpendingmessagestate(sym_w_deprecated_unit, msgstate);
  1378. recordpendingmessagestate(sym_w_deprecated_unit_with_msg, msgstate);
  1379. end
  1380. else
  1381. if ident='UNIT_EXPERIMENTAL' then
  1382. recordpendingmessagestate(sym_w_experimental_unit, msgstate)
  1383. else
  1384. if ident='UNIT_LIBRARY' then
  1385. recordpendingmessagestate(sym_w_library_unit, msgstate)
  1386. else
  1387. if ident='UNIT_PLATFORM' then
  1388. recordpendingmessagestate(sym_w_non_portable_unit, msgstate)
  1389. else
  1390. if ident='UNIT_UNIMPLEMENTED' then
  1391. recordpendingmessagestate(sym_w_non_implemented_unit, msgstate)
  1392. else
  1393. if ident='ZERO_NIL_COMPAT' then
  1394. recordpendingmessagestate(type_w_zero_to_nil, msgstate)
  1395. else
  1396. if ident='IMPLICIT_STRING_CAST' then
  1397. recordpendingmessagestate(type_w_implicit_string_cast, msgstate)
  1398. else
  1399. if ident='IMPLICIT_STRING_CAST_LOSS' then
  1400. recordpendingmessagestate(type_w_implicit_string_cast_loss, msgstate)
  1401. else
  1402. if ident='EXPLICIT_STRING_CAST' then
  1403. recordpendingmessagestate(type_w_explicit_string_cast, msgstate)
  1404. else
  1405. if ident='EXPLICIT_STRING_CAST_LOSS' then
  1406. recordpendingmessagestate(type_w_explicit_string_cast_loss, msgstate)
  1407. else
  1408. if ident='CVT_NARROWING_STRING_LOST' then
  1409. recordpendingmessagestate(type_w_unicode_data_loss, msgstate)
  1410. else
  1411. if ident='INTF_RAISE_VISIBILITY' then
  1412. recordpendingmessagestate(type_w_interface_lower_visibility, msgstate)
  1413. else
  1414. begin
  1415. i:=0;
  1416. if not ChangeMessageVerbosity(ident,i,msgstate) then
  1417. Message1(scanner_w_illegal_warn_identifier,ident);
  1418. end;
  1419. end;
  1420. procedure dir_warning;
  1421. begin
  1422. do_message(scan_w_user_defined);
  1423. end;
  1424. procedure dir_warnings;
  1425. begin
  1426. do_setverbose('W');
  1427. end;
  1428. procedure dir_weakpackageunit;
  1429. begin
  1430. { old Delphi versions seem to use merely $WEAKPACKAGEUNIT while newer
  1431. Delphis have $WEAPACKAGEUNIT ON... :/ }
  1432. do_moduleflagswitch(uf_package_weak, true);
  1433. end;
  1434. procedure dir_writeableconst;
  1435. begin
  1436. do_delphiswitch('J');
  1437. end;
  1438. procedure dir_z1;
  1439. begin
  1440. current_settings.packenum:=1;
  1441. end;
  1442. procedure dir_z2;
  1443. begin
  1444. current_settings.packenum:=2;
  1445. end;
  1446. procedure dir_z4;
  1447. begin
  1448. current_settings.packenum:=4;
  1449. end;
  1450. procedure dir_externalsym;
  1451. begin
  1452. end;
  1453. procedure dir_nodefine;
  1454. begin
  1455. end;
  1456. procedure dir_hppemit;
  1457. begin
  1458. end;
  1459. procedure dir_hugecode;
  1460. begin
  1461. if not (target_info.system in [system_i8086_msdos,system_i8086_embedded])
  1462. {$ifdef i8086}
  1463. or (current_settings.x86memorymodel in x86_near_code_models)
  1464. {$endif i8086}
  1465. then
  1466. begin
  1467. Message1(scan_n_ignored_switch,pattern);
  1468. exit;
  1469. end;
  1470. do_moduleswitch(cs_huge_code);
  1471. end;
  1472. procedure dir_hugepointernormalization;
  1473. var
  1474. hs : string;
  1475. begin
  1476. if not (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  1477. begin
  1478. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERNORMALIZATION');
  1479. exit;
  1480. end;
  1481. current_scanner.skipspace;
  1482. hs:=current_scanner.readid;
  1483. case hs of
  1484. 'BORLANDC':
  1485. begin
  1486. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'+');
  1487. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'+');
  1488. end;
  1489. 'MICROSOFTC':
  1490. begin
  1491. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'-');
  1492. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'-');
  1493. end;
  1494. 'WATCOMC':
  1495. begin
  1496. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'-');
  1497. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'+');
  1498. end;
  1499. else
  1500. Message(scan_e_illegal_hugepointernormalization);
  1501. end;
  1502. end;
  1503. procedure dir_hugepointerarithmeticnormalization;
  1504. begin
  1505. if not (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  1506. begin
  1507. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERARITHMETICNORMALIZATION');
  1508. exit;
  1509. end;
  1510. do_localswitch(cs_hugeptr_arithmetic_normalization);
  1511. end;
  1512. procedure dir_hugepointercomparisonnormalization;
  1513. begin
  1514. if not (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  1515. begin
  1516. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERCOMPARISONNORMALIZATION');
  1517. exit;
  1518. end;
  1519. do_localswitch(cs_hugeptr_comparison_normalization);
  1520. end;
  1521. procedure dir_codealign;
  1522. var
  1523. s : string;
  1524. begin
  1525. current_scanner.skipspace;
  1526. s:=current_scanner.readcomment;
  1527. if not(UpdateAlignmentStr(s,current_settings.alignment)) then
  1528. message(scanner_e_illegal_alignment_directive);
  1529. end;
  1530. procedure dir_codepage;
  1531. var
  1532. s : string;
  1533. begin
  1534. if not current_module.in_global then
  1535. Message(scan_w_switch_is_global)
  1536. else
  1537. begin
  1538. current_scanner.skipspace;
  1539. s:=current_scanner.readcomment;
  1540. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1541. current_settings.sourcecodepage:=CP_UTF8
  1542. else if not cpavailable(s) then
  1543. Message1(option_code_page_not_available,s)
  1544. else
  1545. current_settings.sourcecodepage:=codepagebyname(s);
  1546. { we're not using the system code page now }
  1547. exclude(current_settings.modeswitches,m_systemcodepage);
  1548. exclude(current_settings.moduleswitches,cs_system_codepage);
  1549. include(current_settings.moduleswitches,cs_explicit_codepage);
  1550. end;
  1551. end;
  1552. procedure dir_coperators;
  1553. begin
  1554. do_moduleswitch(cs_support_c_operators);
  1555. end;
  1556. procedure dir_bitpacking;
  1557. begin
  1558. do_localswitch(cs_bitpacking);
  1559. end;
  1560. procedure dir_region;
  1561. begin
  1562. end;
  1563. procedure dir_endregion;
  1564. begin
  1565. end;
  1566. procedure dir_zerobasesstrings;
  1567. begin
  1568. do_localswitch(cs_zerobasedstrings);
  1569. end;
  1570. {****************************************************************************
  1571. Initialize Directives
  1572. ****************************************************************************}
  1573. procedure InitScannerDirectives;
  1574. begin
  1575. AddDirective('A1',directive_all, @dir_a1);
  1576. AddDirective('A2',directive_all, @dir_a2);
  1577. AddDirective('A4',directive_all, @dir_a4);
  1578. AddDirective('A8',directive_all, @dir_a8);
  1579. AddDirective('ALIGN',directive_all, @dir_align);
  1580. {$ifdef m68k}
  1581. AddDirective('APPID',directive_all, @dir_appid);
  1582. AddDirective('APPNAME',directive_all, @dir_appname);
  1583. {$endif m68k}
  1584. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1585. AddDirective('ASMCPU',directive_all, @dir_asmcpu);
  1586. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1587. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1588. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1589. AddDirective('BITPACKING',directive_all, @dir_bitpacking);
  1590. AddDirective('CALLING',directive_all, @dir_calling);
  1591. AddDirective('CHECKLOWADDRLOADS',directive_all, @dir_checklowaddrloads);
  1592. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1593. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1594. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1595. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1596. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1597. AddDirective('D',directive_all, @dir_description);
  1598. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1599. AddDirective('DENYPACKAGEUNIT',directive_all,@dir_denypackageunit);
  1600. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1601. AddDirective('ENDREGION',directive_all, @dir_endregion);
  1602. AddDirective('ERROR',directive_all, @dir_error);
  1603. AddDirective('ERRORC',directive_mac, @dir_error);
  1604. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1605. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1606. AddDirective('F',directive_all, @dir_forcefarcalls);
  1607. AddDirective('FATAL',directive_all, @dir_fatal);
  1608. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1609. AddDirective('FRAMEWORKPATH',directive_all, @dir_frameworkpath);
  1610. AddDirective('GOTO',directive_all, @dir_goto);
  1611. AddDirective('HINT',directive_all, @dir_hint);
  1612. AddDirective('HINTS',directive_all, @dir_hints);
  1613. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1614. AddDirective('HUGECODE',directive_all, @dir_hugecode);
  1615. AddDirective('HUGEPOINTERNORMALIZATION',directive_all,@dir_hugepointernormalization);
  1616. AddDirective('HUGEPOINTERARITHMETICNORMALIZATION',directive_all,@dir_hugepointerarithmeticnormalization);
  1617. AddDirective('HUGEPOINTERCOMPARISONNORMALIZATION',directive_all,@dir_hugepointercomparisonnormalization);
  1618. AddDirective('IEEEERRORS',directive_all,@dir_ieeeerrors);
  1619. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1620. AddDirective('IMAGEBASE',directive_all, @dir_imagebase);
  1621. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1622. AddDirective('IMPORTEDDATA',directive_all, @dir_importeddata);
  1623. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1624. AddDirective('INFO',directive_all, @dir_info);
  1625. AddDirective('INLINE',directive_all, @dir_inline);
  1626. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1627. AddDirective('L',directive_all, @dir_link);
  1628. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1629. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1630. AddDirective('LINK',directive_all, @dir_link);
  1631. AddDirective('LINKFRAMEWORK',directive_all, @dir_linkframework);
  1632. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1633. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1634. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1635. AddDirective('M',directive_all, @dir_memory);
  1636. AddDirective('MACRO',directive_all, @dir_macro);
  1637. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1638. AddDirective('MAXSTACKSIZE',directive_all, @dir_maxstacksize);
  1639. AddDirective('MEMORY',directive_all, @dir_memory);
  1640. AddDirective('MESSAGE',directive_all, @dir_message);
  1641. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1642. AddDirective('MINFPCONSTPREC',directive_all, @dir_minfpconstprec);
  1643. AddDirective('MINSTACKSIZE',directive_all, @dir_minstacksize);
  1644. AddDirective('MMX',directive_all, @dir_mmx);
  1645. AddDirective('MODE',directive_all, @dir_mode);
  1646. AddDirective('MODESWITCH',directive_all, @dir_modeswitch);
  1647. AddDirective('NAMESPACE',directive_all, @dir_namespace);
  1648. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1649. AddDirective('NOTE',directive_all, @dir_note);
  1650. AddDirective('NOTES',directive_all, @dir_notes);
  1651. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1652. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1653. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1654. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1655. AddDirective('OV',directive_mac, @dir_overflowchecks);
  1656. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1657. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1658. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1659. AddDirective('PACKSET',directive_all, @dir_packset);
  1660. AddDirective('PASCALMAINNAME',directive_all, @dir_pascalmainname);
  1661. AddDirective('PIC',directive_all, @dir_pic);
  1662. AddDirective('POINTERMATH',directive_all, @dir_pointermath);
  1663. AddDirective('POP',directive_all, @dir_pop);
  1664. AddDirective('PROFILE',directive_all, @dir_profile);
  1665. AddDirective('PUSH',directive_all, @dir_push);
  1666. AddDirective('R',directive_all, @dir_resource);
  1667. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1668. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1669. AddDirective('REGION',directive_all, @dir_region);
  1670. AddDirective('RESOURCE',directive_all, @dir_resource);
  1671. AddDirective('SATURATION',directive_all, @dir_saturation);
  1672. AddDirective('SAFEFPUEXCEPTIONS',directive_all, @dir_safefpuexceptions);
  1673. AddDirective('SCOPEDENUMS',directive_all, @dir_scopedenums);
  1674. AddDirective('SETPEFLAGS', directive_all, @dir_setpeflags);
  1675. AddDirective('SETPEOPTFLAGS', directive_all, @dir_setpeoptflags);
  1676. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1677. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1678. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1679. AddDirective('STOP',directive_all, @dir_stop);
  1680. AddDirective('STRINGCHECKS', directive_all, @dir_stringchecks);
  1681. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1682. AddDirective('TARGETSWITCH',directive_all, @dir_targetswitch);
  1683. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1684. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1685. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1686. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1687. AddDirective('VARPARACOPYOUTCHECK',directive_all, @dir_varparacopyoutcheck);
  1688. AddDirective('VARPROPSETTER',directive_all, @dir_varpropsetter);
  1689. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1690. AddDirective('VERSION',directive_all, @dir_version);
  1691. AddDirective('WAIT',directive_all, @dir_wait);
  1692. AddDirective('WARN',directive_all, @dir_warn);
  1693. AddDirective('WARNING',directive_all, @dir_warning);
  1694. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1695. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1696. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1697. AddDirective('Z1',directive_all, @dir_z1);
  1698. AddDirective('Z2',directive_all, @dir_z2);
  1699. AddDirective('Z4',directive_all, @dir_z4);
  1700. AddDirective('ZEROBASEDSTRINGS',directive_all, @dir_zerobasesstrings);
  1701. end;
  1702. end.