scandir.pas 76 KB

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