scandir.pas 52 KB

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