scandir.pas 75 KB

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