scandir.pas 53 KB

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