scandir.pas 52 KB

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