scandir.pas 60 KB

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