scandir.pas 53 KB

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