scandir.pas 75 KB

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