scandir.pas 55 KB

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