scandir.pas 55 KB

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