scandir.pas 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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. procedure InitScannerDirectives;
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutils,
  25. globtype,globals,systems,widestr,cpuinfo,
  26. verbose,comphook,ppu,
  27. scanner,switches,
  28. fmodule,
  29. symconst,symtable,
  30. rabase;
  31. const
  32. localswitchesstackmax = 20;
  33. var
  34. localswitchesstack: array[0..localswitchesstackmax] of tlocalswitches;
  35. localswitchesstackpos: Integer;
  36. {*****************************************************************************
  37. Helpers
  38. *****************************************************************************}
  39. procedure do_delphiswitch(sw:char);
  40. var
  41. state : char;
  42. begin
  43. { c contains the next char, a + or - would be fine }
  44. state:=current_scanner.readstate;
  45. if state in ['-','+'] then
  46. HandleSwitch(sw,state);
  47. end;
  48. procedure do_setverbose(flag:char);
  49. var
  50. state : char;
  51. begin
  52. { support ON/OFF }
  53. state:=current_scanner.ReadState;
  54. SetVerbosity(flag+state);
  55. end;
  56. procedure do_moduleswitch(sw:tmoduleswitch);
  57. var
  58. state : char;
  59. begin
  60. state:=current_scanner.readstate;
  61. if (sw<>cs_modulenone) and (state in ['-','+']) then
  62. begin
  63. if state='-' then
  64. exclude(current_settings.moduleswitches,sw)
  65. else
  66. include(current_settings.moduleswitches,sw);
  67. end;
  68. end;
  69. procedure do_localswitch(sw:tlocalswitch);
  70. var
  71. state : char;
  72. begin
  73. state:=current_scanner.readstate;
  74. if (sw<>cs_localnone) and (state in ['-','+']) then
  75. begin
  76. if not localswitcheschanged then
  77. nextlocalswitches:=current_settings.localswitches;
  78. if state='-' then
  79. exclude(nextlocalswitches,sw)
  80. else
  81. include(nextlocalswitches,sw);
  82. localswitcheschanged:=true;
  83. end;
  84. end;
  85. procedure do_localswitchdefault(sw:tlocalswitch);
  86. var
  87. state : char;
  88. begin
  89. state:=current_scanner.readstatedefault;
  90. if (sw<>cs_localnone) and (state in ['-','+','*']) then
  91. begin
  92. if not localswitcheschanged then
  93. nextlocalswitches:=current_settings.localswitches;
  94. if state='-' then
  95. exclude(nextlocalswitches,sw)
  96. else
  97. if state='+' then
  98. include(nextlocalswitches,sw)
  99. else
  100. begin
  101. if sw in init_settings.localswitches then
  102. include(nextlocalswitches,sw)
  103. else
  104. exclude(nextlocalswitches,sw);
  105. end;
  106. localswitcheschanged:=true;
  107. end;
  108. end;
  109. procedure do_message(w:integer);
  110. begin
  111. current_scanner.skipspace;
  112. Message1(w,current_scanner.readcomment);
  113. end;
  114. {*****************************************************************************
  115. Directive Callbacks
  116. *****************************************************************************}
  117. procedure dir_align;
  118. var
  119. hs : string;
  120. begin
  121. current_scanner.skipspace;
  122. if not(c in ['0'..'9']) then
  123. begin
  124. { Support also the ON and OFF as switch }
  125. hs:=current_scanner.readid;
  126. if (hs='ON') then
  127. current_settings.packrecords:=4
  128. else if (hs='OFF') then
  129. current_settings.packrecords:=1
  130. else if m_mac in current_settings.modeswitches then
  131. begin
  132. { Support switches used in Apples Universal Interfaces}
  133. if (hs='MAC68K') then
  134. current_settings.packrecords:=2
  135. else if (hs='POWER') then
  136. current_settings.packrecords:=4
  137. else if (hs='RESET') then
  138. current_settings.packrecords:=0
  139. else
  140. Message1(scan_e_illegal_pack_records,hs);
  141. end
  142. else
  143. Message1(scan_e_illegal_pack_records,hs);
  144. end
  145. else
  146. begin
  147. case current_scanner.readval of
  148. 1 : current_settings.packrecords:=1;
  149. 2 : current_settings.packrecords:=2;
  150. 4 : current_settings.packrecords:=4;
  151. 8 : current_settings.packrecords:=8;
  152. 16 : current_settings.packrecords:=16;
  153. 32 : current_settings.packrecords:=32;
  154. else
  155. Message1(scan_e_illegal_pack_records,hs);
  156. end;
  157. end;
  158. end;
  159. procedure dir_a1;
  160. begin
  161. current_settings.packrecords:=1;
  162. end;
  163. procedure dir_a2;
  164. begin
  165. current_settings.packrecords:=2;
  166. end;
  167. procedure dir_a4;
  168. begin
  169. current_settings.packrecords:=4;
  170. end;
  171. procedure dir_a8;
  172. begin
  173. current_settings.packrecords:=8;
  174. end;
  175. procedure dir_asmmode;
  176. var
  177. s : string;
  178. begin
  179. current_scanner.skipspace;
  180. s:=current_scanner.readid;
  181. If Inside_asm_statement then
  182. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  183. if s='DEFAULT' then
  184. current_settings.asmmode:=init_settings.asmmode
  185. else
  186. if not SetAsmReadMode(s,current_settings.asmmode) then
  187. Message1(scan_e_illegal_asmmode_specifier,s);
  188. end;
  189. {$if defined(m68k) or defined(arm)}
  190. procedure dir_appid;
  191. begin
  192. if target_info.system<>system_m68k_palmos then
  193. Message(scan_w_appid_not_support);
  194. { change description global var in all cases }
  195. { it not used but in win32 and os2 }
  196. current_scanner.skipspace;
  197. palmos_applicationid:=current_scanner.readcomment;
  198. end;
  199. procedure dir_appname;
  200. begin
  201. if target_info.system<>system_m68k_palmos then
  202. Message(scan_w_appname_not_support);
  203. { change description global var in all cases }
  204. { it not used but in win32 and os2 }
  205. current_scanner.skipspace;
  206. palmos_applicationname:=current_scanner.readcomment;
  207. end;
  208. {$endif defined(m68k) or defined(arm)}
  209. procedure dir_apptype;
  210. var
  211. hs : string;
  212. begin
  213. if not (target_info.system in system_all_windows + [system_i386_os2,
  214. system_i386_emx, system_powerpc_macos]) then
  215. begin
  216. if m_delphi in current_settings.modeswitches then
  217. Message(scan_n_app_type_not_support)
  218. else
  219. Message(scan_w_app_type_not_support);
  220. end
  221. else
  222. begin
  223. if not current_module.in_global then
  224. Message(scan_w_switch_is_global)
  225. else
  226. begin
  227. current_scanner.skipspace;
  228. hs:=current_scanner.readid;
  229. if hs='GUI' then
  230. apptype:=app_gui
  231. else if hs='CONSOLE' then
  232. apptype:=app_cui
  233. else if (hs='NATIVE') and (target_info.system in system_windows) then
  234. apptype:=app_native
  235. else if (hs='FS') and (target_info.system in [system_i386_os2,
  236. system_i386_emx]) then
  237. apptype:=app_fs
  238. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  239. apptype:=app_tool
  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 not SetAktProcCall(hs,current_settings.defproccall) then
  252. begin
  253. if (hs <> '') then
  254. Message1(parser_w_unknown_proc_directive_ignored,hs)
  255. else
  256. Message(parser_e_proc_directive_expected);
  257. end;
  258. end;
  259. procedure dir_checkpointer;
  260. begin
  261. do_localswitchdefault(cs_checkpointer);
  262. end;
  263. procedure dir_objectchecks;
  264. begin
  265. do_localswitch(cs_check_object);
  266. end;
  267. procedure dir_assertions;
  268. begin
  269. do_delphiswitch('C');
  270. end;
  271. procedure dir_booleval;
  272. begin
  273. do_delphiswitch('B');
  274. end;
  275. procedure dir_debuginfo;
  276. begin
  277. do_delphiswitch('D');
  278. end;
  279. procedure dir_description;
  280. begin
  281. if not (target_info.system in [system_i386_os2,system_i386_emx,
  282. system_i386_win32,system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  283. Message(scan_w_description_not_support);
  284. { change description global var in all cases }
  285. { it not used but in win32, os2 and netware }
  286. current_scanner.skipspace;
  287. description:=current_scanner.readcomment;
  288. DescriptionSetExplicity:=true;
  289. end;
  290. procedure dir_screenname; {ad}
  291. begin
  292. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  293. {Message(scan_w_decription_not_support);}
  294. comment (V_Warning,'Screenname only supported for target netware');
  295. current_scanner.skipspace;
  296. nwscreenname:=current_scanner.readcomment;
  297. end;
  298. procedure dir_threadname; {ad}
  299. begin
  300. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  301. {Message(scan_w_decription_not_support);}
  302. comment (V_Warning,'Threadname only supported for target netware');
  303. current_scanner.skipspace;
  304. nwthreadname:=current_scanner.readcomment;
  305. end;
  306. procedure dir_copyright; {ad}
  307. begin
  308. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  309. {Message(scan_w_decription_not_support);}
  310. comment (V_Warning,'Copyright only supported for target netware');
  311. current_scanner.skipspace;
  312. nwcopyright:=current_scanner.readcomment;
  313. end;
  314. procedure dir_error;
  315. begin
  316. do_message(scan_e_user_defined);
  317. end;
  318. procedure dir_extendedsyntax;
  319. begin
  320. do_delphiswitch('X');
  321. end;
  322. procedure dir_fatal;
  323. begin
  324. do_message(scan_f_user_defined);
  325. end;
  326. procedure dir_fputype;
  327. begin
  328. current_scanner.skipspace;
  329. { current_scanner.undef_macro('FPU'+fputypestr[current_settings.fputype]); }
  330. if not(SetFPUType(upper(current_scanner.readcomment),current_settings.fputype)) then
  331. comment(V_Error,'Illegal FPU type');
  332. { current_scanner.def_macro('FPU'+fputypestr[current_settings.fputype]); }
  333. end;
  334. procedure dir_goto;
  335. begin
  336. do_moduleswitch(cs_support_goto);
  337. end;
  338. procedure dir_hint;
  339. begin
  340. do_message(scan_h_user_defined);
  341. end;
  342. procedure dir_hints;
  343. begin
  344. do_setverbose('H');
  345. end;
  346. procedure dir_imagebase;
  347. begin
  348. if not (target_info.system in (system_windows+system_wince)) then
  349. Message(scan_w_imagebase_not_support);
  350. current_scanner.skipspace;
  351. imagebase:=current_scanner.readval;
  352. ImageBaseSetExplicity:=true
  353. end;
  354. procedure dir_implicitexceptions;
  355. begin
  356. do_moduleswitch(cs_implicit_exceptions);
  357. end;
  358. procedure dir_includepath;
  359. begin
  360. if not current_module.in_global then
  361. Message(scan_w_switch_is_global)
  362. else
  363. begin
  364. current_scanner.skipspace;
  365. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  366. end;
  367. end;
  368. procedure dir_info;
  369. begin
  370. do_message(scan_i_user_defined);
  371. end;
  372. procedure dir_inline;
  373. begin
  374. do_localswitch(cs_do_inline);
  375. end;
  376. procedure dir_interfaces;
  377. var
  378. hs : string;
  379. begin
  380. {corba/com/default}
  381. current_scanner.skipspace;
  382. hs:=current_scanner.readid;
  383. if (hs='CORBA') then
  384. current_settings.interfacetype:=it_interfacecorba
  385. else if (hs='COM') then
  386. current_settings.interfacetype:=it_interfacecom
  387. else if (hs='DEFAULT') then
  388. current_settings.interfacetype:=init_settings.interfacetype
  389. else
  390. Message(scan_e_invalid_interface_type);
  391. end;
  392. procedure dir_iochecks;
  393. begin
  394. do_delphiswitch('I');
  395. end;
  396. procedure dir_libexport;
  397. begin
  398. {not implemented}
  399. end;
  400. procedure dir_librarypath;
  401. begin
  402. if not current_module.in_global then
  403. Message(scan_w_switch_is_global)
  404. else
  405. begin
  406. current_scanner.skipspace;
  407. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  408. end;
  409. end;
  410. procedure dir_link;
  411. var
  412. s : string;
  413. begin
  414. current_scanner.skipspace;
  415. if scanner.c = '''' then
  416. begin
  417. s:= current_scanner.readquotedstring;
  418. current_scanner.readcomment
  419. end
  420. else
  421. s:= trimspace(current_scanner.readcomment);
  422. s:=ChangeFileExt(FixFileName(s),target_info.objext);
  423. current_module.linkotherofiles.add(s,link_always);
  424. end;
  425. procedure dir_linklib;
  426. type
  427. tLinkMode=(lm_shared,lm_static);
  428. var
  429. s : string;
  430. quote : char;
  431. libext,
  432. libname,
  433. linkmodestr : string;
  434. p : longint;
  435. linkMode : tLinkMode;
  436. begin
  437. current_scanner.skipspace;
  438. if scanner.c = '''' then
  439. begin
  440. libname:= current_scanner.readquotedstring;
  441. s:= current_scanner.readcomment;
  442. p:=pos(',',s);
  443. end
  444. else
  445. begin
  446. s:= current_scanner.readcomment;
  447. p:=pos(',',s);
  448. if p=0 then
  449. libname:=TrimSpace(s)
  450. else
  451. libname:=TrimSpace(copy(s,1,p-1));
  452. end;
  453. if p=0 then
  454. linkmodeStr:=''
  455. else
  456. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  457. if (libname='') or (libname='''''') or (libname='""') then
  458. exit;
  459. { create library name }
  460. if libname[1] in ['''','"'] then
  461. begin
  462. quote:=libname[1];
  463. Delete(libname,1,1);
  464. p:=pos(quote,libname);
  465. if p>0 then
  466. Delete(libname,p,1);
  467. end;
  468. libname:=FixFileName(libname);
  469. { get linkmode, default is to check the extension for
  470. the static library, otherwise shared linking is assumed }
  471. linkmode:=lm_shared;
  472. if linkModeStr='' then
  473. begin
  474. libext:=ExtractFileExt(libname);
  475. if libext=target_info.staticClibext then
  476. linkMode:=lm_static;
  477. end
  478. else if linkModeStr='STATIC' then
  479. linkmode:=lm_static
  480. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  481. linkmode:=lm_shared
  482. else
  483. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  484. { add to the list of other libraries }
  485. if linkMode=lm_static then
  486. current_module.linkOtherStaticLibs.add(libname,link_always)
  487. else
  488. current_module.linkOtherSharedLibs.add(libname,link_always);
  489. end;
  490. procedure dir_localsymbols;
  491. begin
  492. do_delphiswitch('L');
  493. end;
  494. procedure dir_longstrings;
  495. begin
  496. do_delphiswitch('H');
  497. end;
  498. procedure dir_macro;
  499. begin
  500. do_moduleswitch(cs_support_macro);
  501. end;
  502. procedure dir_maxfpuregisters;
  503. var
  504. l : integer;
  505. hs : string;
  506. begin
  507. current_scanner.skipspace;
  508. if not(c in ['0'..'9']) then
  509. begin
  510. hs:=current_scanner.readid;
  511. if (hs='NORMAL') or (hs='DEFAULT') then
  512. current_settings.maxfpuregisters:=-1
  513. else
  514. Message(scan_e_invalid_maxfpureg_value);
  515. end
  516. else
  517. begin
  518. l:=current_scanner.readval;
  519. case l of
  520. 0..8:
  521. current_settings.maxfpuregisters:=l;
  522. else
  523. Message(scan_e_invalid_maxfpureg_value);
  524. end;
  525. end;
  526. end;
  527. procedure dir_maxstacksize;
  528. begin
  529. if not (target_info.system in (system_windows+system_wince)) then
  530. Message(scan_w_maxstacksize_not_support);
  531. current_scanner.skipspace;
  532. maxstacksize:=current_scanner.readval;
  533. MaxStackSizeSetExplicity:=true;
  534. end;
  535. procedure dir_memory;
  536. var
  537. l : longint;
  538. begin
  539. current_scanner.skipspace;
  540. l:=current_scanner.readval;
  541. if l>1024 then
  542. stacksize:=l;
  543. if c=',' then
  544. begin
  545. current_scanner.readchar;
  546. current_scanner.skipspace;
  547. l:=current_scanner.readval;
  548. if l>1024 then
  549. heapsize:=l;
  550. end;
  551. end;
  552. procedure dir_message;
  553. var
  554. hs : string;
  555. w : longint;
  556. begin
  557. w:=0;
  558. current_scanner.skipspace;
  559. { Message level specified? }
  560. if c='''' then
  561. w:=scan_n_user_defined
  562. else
  563. begin
  564. hs:=current_scanner.readid;
  565. if (hs='WARN') or (hs='WARNING') then
  566. w:=scan_w_user_defined
  567. else
  568. if (hs='ERROR') then
  569. w:=scan_e_user_defined
  570. else
  571. if (hs='FATAL') then
  572. w:=scan_f_user_defined
  573. else
  574. if (hs='HINT') then
  575. w:=scan_h_user_defined
  576. else
  577. if (hs='NOTE') then
  578. w:=scan_n_user_defined
  579. else
  580. Message1(scan_w_illegal_directive,hs);
  581. end;
  582. { Only print message when there was no error }
  583. if w<>0 then
  584. begin
  585. current_scanner.skipspace;
  586. if c='''' then
  587. hs:=current_scanner.readquotedstring
  588. else
  589. hs:=current_scanner.readcomment;
  590. Message1(w,hs);
  591. end
  592. else
  593. current_scanner.readcomment;
  594. end;
  595. procedure dir_minstacksize;
  596. begin
  597. if not (target_info.system in (system_windows+system_wince)) then
  598. Message(scan_w_minstacksize_not_support);
  599. current_scanner.skipspace;
  600. minstacksize:=current_scanner.readval;
  601. MinStackSizeSetExplicity:=true;
  602. end;
  603. procedure dir_mode;
  604. begin
  605. if not current_module.in_global then
  606. Message(scan_w_switch_is_global)
  607. else
  608. begin
  609. current_scanner.skipspace;
  610. current_scanner.readstring;
  611. if not current_module.mode_switch_allowed and
  612. not ((m_mac in current_settings.modeswitches) and (pattern='MACPAS')) then
  613. Message1(scan_e_mode_switch_not_allowed,pattern)
  614. else if not SetCompileMode(pattern,false) then
  615. Message1(scan_w_illegal_switch,pattern)
  616. end;
  617. current_module.mode_switch_allowed:= false;
  618. end;
  619. procedure dir_mmx;
  620. begin
  621. do_localswitch(cs_mmx);
  622. end;
  623. procedure dir_note;
  624. begin
  625. do_message(scan_n_user_defined);
  626. end;
  627. procedure dir_notes;
  628. begin
  629. do_setverbose('N');
  630. end;
  631. procedure dir_objectpath;
  632. begin
  633. if not current_module.in_global then
  634. Message(scan_w_switch_is_global)
  635. else
  636. begin
  637. current_scanner.skipspace;
  638. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  639. end;
  640. end;
  641. procedure dir_openstrings;
  642. begin
  643. do_delphiswitch('P');
  644. end;
  645. procedure dir_optimization;
  646. var
  647. hs : string;
  648. begin
  649. current_scanner.skipspace;
  650. { Support also the ON and OFF as switch }
  651. hs:=current_scanner.readid;
  652. if (hs='ON') then
  653. current_settings.optimizerswitches:=level2optimizerswitches
  654. else if (hs='OFF') then
  655. current_settings.optimizerswitches:=[]
  656. else if (hs='DEFAULT') then
  657. current_settings.optimizerswitches:=init_settings.optimizerswitches
  658. else
  659. begin
  660. if not UpdateOptimizerStr(hs,current_settings.optimizerswitches) then
  661. Message1(scan_e_illegal_optimization_specifier,hs);
  662. end;
  663. end;
  664. procedure dir_overflowchecks;
  665. begin
  666. do_delphiswitch('Q');
  667. end;
  668. procedure dir_packenum;
  669. var
  670. hs : string;
  671. begin
  672. current_scanner.skipspace;
  673. if not(c in ['0'..'9']) then
  674. begin
  675. hs:=current_scanner.readid;
  676. if (hs='NORMAL') or (hs='DEFAULT') then
  677. current_settings.packenum:=4
  678. else
  679. Message1(scan_e_illegal_pack_enum, hs);
  680. end
  681. else
  682. begin
  683. case current_scanner.readval of
  684. 1 : current_settings.packenum:=1;
  685. 2 : current_settings.packenum:=2;
  686. 4 : current_settings.packenum:=4;
  687. else
  688. Message1(scan_e_illegal_pack_enum, pattern);
  689. end;
  690. end;
  691. end;
  692. procedure dir_packrecords;
  693. var
  694. hs : string;
  695. begin
  696. current_scanner.skipspace;
  697. if not(c in ['0'..'9']) then
  698. begin
  699. hs:=current_scanner.readid;
  700. { C has the special recordalignmax of C_alignment }
  701. if (hs='C') then
  702. current_settings.packrecords:=C_alignment
  703. else
  704. if (hs='NORMAL') or (hs='DEFAULT') then
  705. current_settings.packrecords:=0
  706. else
  707. Message1(scan_e_illegal_pack_records,hs);
  708. end
  709. else
  710. begin
  711. case current_scanner.readval of
  712. 1 : current_settings.packrecords:=1;
  713. 2 : current_settings.packrecords:=2;
  714. 4 : current_settings.packrecords:=4;
  715. 8 : current_settings.packrecords:=8;
  716. 16 : current_settings.packrecords:=16;
  717. 32 : current_settings.packrecords:=32;
  718. else
  719. Message1(scan_e_illegal_pack_records,pattern);
  720. end;
  721. end;
  722. end;
  723. procedure dir_packset;
  724. var
  725. hs : string;
  726. begin
  727. current_scanner.skipspace;
  728. if not(c in ['1','2','4','8']) then
  729. begin
  730. hs:=current_scanner.readid;
  731. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  732. current_settings.setalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  733. else
  734. Message(scan_e_only_packset);
  735. end
  736. else
  737. begin
  738. case current_scanner.readval of
  739. 1 : current_settings.setalloc:=1;
  740. 2 : current_settings.setalloc:=2;
  741. 4 : current_settings.setalloc:=4;
  742. 8 : current_settings.setalloc:=8;
  743. else
  744. Message(scan_e_only_packset);
  745. end;
  746. end;
  747. end;
  748. procedure dir_pic;
  749. begin
  750. do_moduleswitch(cs_create_pic);
  751. end;
  752. procedure dir_pop;
  753. begin
  754. if localswitchesstackpos < 1 then
  755. Message(scan_e_too_many_pop);
  756. if not localswitcheschanged then
  757. nextlocalswitches:=current_settings.localswitches;
  758. Dec(localswitchesstackpos);
  759. nextlocalswitches:= localswitchesstack[localswitchesstackpos];
  760. localswitcheschanged:=true;
  761. end;
  762. procedure dir_profile;
  763. begin
  764. do_moduleswitch(cs_profile);
  765. { defined/undefine FPC_PROFILE }
  766. if cs_profile in current_settings.moduleswitches then
  767. def_system_macro('FPC_PROFILE')
  768. else
  769. undef_system_macro('FPC_PROFILE');
  770. end;
  771. procedure dir_push;
  772. begin
  773. if localswitchesstackpos > localswitchesstackmax then
  774. Message(scan_e_too_many_push);
  775. if localswitcheschanged then
  776. begin
  777. current_settings.localswitches:=nextlocalswitches;
  778. localswitcheschanged:=false;
  779. end;
  780. localswitchesstack[localswitchesstackpos]:= current_settings.localswitches;
  781. Inc(localswitchesstackpos);
  782. end;
  783. procedure dir_rangechecks;
  784. begin
  785. do_delphiswitch('R');
  786. end;
  787. procedure dir_referenceinfo;
  788. begin
  789. do_delphiswitch('Y');
  790. end;
  791. procedure dir_resource;
  792. var
  793. s : string;
  794. begin
  795. current_scanner.skipspace;
  796. if scanner.c = '''' then
  797. begin
  798. s:= current_scanner.readquotedstring;
  799. current_scanner.readcomment
  800. end
  801. else
  802. s:= trimspace(current_scanner.readcomment);
  803. { replace * with the name of the main source.
  804. This should always be defined. }
  805. if s[1]='*' then
  806. if Assigned(Current_Module) then
  807. begin
  808. delete(S,1,1);
  809. insert(ExtractFileName(current_module.mainsource^),S,1);
  810. end;
  811. s:=ChangeFileExt(FixFileName(s),target_info.resext);
  812. if target_info.res<>res_none then
  813. begin
  814. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  815. if (target_info.res = res_emxbind) and
  816. not (Current_module.ResourceFiles.Empty) then
  817. Message(scan_w_only_one_resourcefile_supported)
  818. else
  819. current_module.resourcefiles.insert(FixFileName(s));
  820. end
  821. else
  822. Message(scan_e_resourcefiles_not_supported);
  823. end;
  824. procedure dir_saturation;
  825. begin
  826. do_localswitch(cs_mmx_saturation);
  827. end;
  828. procedure dir_savefpuexceptions;
  829. begin
  830. do_localswitch(cs_fpu_fwait);
  831. end;
  832. procedure dir_setpeflags;
  833. begin
  834. if not (target_info.system in (system_windows+system_wince)) then
  835. Message(scan_w_setpeflags_not_support);
  836. current_scanner.skipspace;
  837. peflags:=current_scanner.readval;
  838. SetPEFlagsSetExplicity:=true;
  839. end;
  840. procedure dir_smartlink;
  841. begin
  842. do_moduleswitch(cs_create_smart);
  843. end;
  844. procedure dir_stackframes;
  845. begin
  846. do_delphiswitch('W');
  847. end;
  848. procedure dir_static;
  849. begin
  850. do_moduleswitch(cs_static_keyword);
  851. end;
  852. procedure dir_stop;
  853. begin
  854. do_message(scan_f_user_defined);
  855. end;
  856. {$ifdef powerpc}
  857. procedure dir_syscall;
  858. var
  859. sctype : string;
  860. begin
  861. { not needed on amiga/m68k for now, because there's only one }
  862. { syscall convention (legacy) (KB) }
  863. { not needed on amiga/powerpc because there's only one }
  864. { syscall convention (sysv) (KB) }
  865. if not (target_info.system in [system_powerpc_morphos]) then
  866. comment (V_Warning,'Syscall directive is useless on this target.');
  867. current_scanner.skipspace;
  868. sctype:=current_scanner.readid;
  869. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  870. (sctype='BASESYSV') or (sctype='R12BASE') then
  871. syscall_convention:=sctype
  872. else
  873. comment (V_Warning,'Invalid Syscall directive ignored.');
  874. end;
  875. {$endif}
  876. procedure dir_typedaddress;
  877. begin
  878. do_delphiswitch('T');
  879. end;
  880. procedure dir_typeinfo;
  881. begin
  882. do_delphiswitch('M');
  883. end;
  884. procedure dir_unitpath;
  885. begin
  886. if not current_module.in_global then
  887. Message(scan_w_switch_is_global)
  888. else
  889. with current_scanner,current_module,localunitsearchpath do
  890. begin
  891. skipspace;
  892. AddPath(path^,readcomment,false);
  893. end;
  894. end;
  895. procedure dir_varstringchecks;
  896. begin
  897. do_delphiswitch('V');
  898. end;
  899. procedure dir_version;
  900. var
  901. major, minor, revision : longint;
  902. error : integer;
  903. begin
  904. if not (target_info.system in [system_i386_os2,system_i386_emx,
  905. system_i386_win32,system_i386_netware,system_i386_wdosx,
  906. system_i386_netwlibc]) then
  907. begin
  908. Message(scan_n_version_not_support);
  909. exit;
  910. end;
  911. if (compile_level<>1) then
  912. Message(scan_n_only_exe_version)
  913. else
  914. begin
  915. { change description global var in all cases }
  916. { it not used but in win32, os2 and netware }
  917. current_scanner.skipspace;
  918. { we should only accept Major.Minor format for win32 and os2 }
  919. current_scanner.readnumber;
  920. major:=0;
  921. minor:=0;
  922. revision:=0;
  923. val(pattern,major,error);
  924. if (error<>0) or (major > high(word)) or (major < 0) then
  925. begin
  926. Message1(scan_w_wrong_version_ignored,pattern);
  927. exit;
  928. end;
  929. if c='.' then
  930. begin
  931. current_scanner.readchar;
  932. current_scanner.readnumber;
  933. val(pattern,minor,error);
  934. if (error<>0) or (minor > high(word)) or (minor < 0) then
  935. begin
  936. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  937. exit;
  938. end;
  939. if (c='.') and
  940. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  941. begin
  942. current_scanner.readchar;
  943. current_scanner.readnumber;
  944. val(pattern,revision,error);
  945. if (error<>0) or (revision > high(word)) or (revision < 0) then
  946. begin
  947. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  948. exit;
  949. end;
  950. dllmajor:=word(major);
  951. dllminor:=word(minor);
  952. dllrevision:=word(revision);
  953. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  954. end
  955. else
  956. begin
  957. dllmajor:=word(major);
  958. dllminor:=word(minor);
  959. dllversion:=tostr(major)+'.'+tostr(minor);
  960. end;
  961. end
  962. else
  963. dllversion:=tostr(major);
  964. end;
  965. end;
  966. procedure dir_wait;
  967. var
  968. had_info : boolean;
  969. begin
  970. had_info:=(status.verbosity and V_Info)<>0;
  971. { this message should allways appear !! }
  972. status.verbosity:=status.verbosity or V_Info;
  973. Message(scan_i_press_enter);
  974. readln;
  975. If not(had_info) then
  976. status.verbosity:=status.verbosity and (not V_Info);
  977. end;
  978. { delphi compatible warn directive:
  979. $warn <identifier> on
  980. $warn <identifier> off
  981. not implemented yet
  982. }
  983. procedure dir_warn;
  984. var
  985. warning_string,state : string;
  986. begin
  987. current_scanner.skipspace;
  988. warning_string:=current_scanner.readid;
  989. current_scanner.skipspace;
  990. state:=current_scanner.readid;
  991. if (upper(state)='ON') then
  992. begin
  993. end
  994. else if (upper(state)='OFF') then
  995. begin
  996. end
  997. else
  998. Message1(scanner_e_illegal_warn_state,state);
  999. end;
  1000. procedure dir_warning;
  1001. begin
  1002. do_message(scan_w_user_defined);
  1003. end;
  1004. procedure dir_warnings;
  1005. begin
  1006. do_setverbose('W');
  1007. end;
  1008. procedure dir_writeableconst;
  1009. begin
  1010. do_delphiswitch('J');
  1011. end;
  1012. procedure dir_z1;
  1013. begin
  1014. current_settings.packenum:=1;
  1015. end;
  1016. procedure dir_z2;
  1017. begin
  1018. current_settings.packenum:=2;
  1019. end;
  1020. procedure dir_z4;
  1021. begin
  1022. current_settings.packenum:=4;
  1023. end;
  1024. procedure dir_externalsym;
  1025. begin
  1026. end;
  1027. procedure dir_nodefine;
  1028. begin
  1029. end;
  1030. procedure dir_hppemit;
  1031. begin
  1032. end;
  1033. procedure dir_weakpackageunit;
  1034. begin
  1035. end;
  1036. procedure dir_codealign;
  1037. var
  1038. s : string;
  1039. begin
  1040. current_scanner.skipspace;
  1041. s:=current_scanner.readcomment;
  1042. UpdateAlignmentStr(s,current_settings.alignment);
  1043. end;
  1044. procedure dir_codepage;
  1045. var
  1046. s : string;
  1047. begin
  1048. if not current_module.in_global then
  1049. Message(scan_w_switch_is_global)
  1050. else
  1051. begin
  1052. current_scanner.skipspace;
  1053. s:=current_scanner.readcomment;
  1054. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1055. current_settings.sourcecodepage:='utf8'
  1056. else if not(cpavailable(s)) then
  1057. Message1(option_code_page_not_available,s)
  1058. else
  1059. current_settings.sourcecodepage:=s;
  1060. end;
  1061. end;
  1062. procedure dir_coperators;
  1063. begin
  1064. do_moduleswitch(cs_support_c_operators);
  1065. end;
  1066. procedure dir_bitpacking;
  1067. begin
  1068. do_localswitch(cs_bitpacking);
  1069. end;
  1070. {****************************************************************************
  1071. Initialize Directives
  1072. ****************************************************************************}
  1073. procedure InitScannerDirectives;
  1074. begin
  1075. AddDirective('A1',directive_all, @dir_a1);
  1076. AddDirective('A2',directive_all, @dir_a2);
  1077. AddDirective('A4',directive_all, @dir_a4);
  1078. AddDirective('A8',directive_all, @dir_a8);
  1079. AddDirective('ALIGN',directive_all, @dir_align);
  1080. {$ifdef m68k}
  1081. AddDirective('APPID',directive_all, @dir_appid);
  1082. AddDirective('APPNAME',directive_all, @dir_appname);
  1083. {$endif m68k}
  1084. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1085. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1086. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1087. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1088. AddDirective('BITPACKING',directive_all, @dir_bitpacking);
  1089. AddDirective('CALLING',directive_all, @dir_calling);
  1090. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1091. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1092. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1093. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1094. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1095. AddDirective('D',directive_all, @dir_description);
  1096. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1097. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1098. AddDirective('ERROR',directive_all, @dir_error);
  1099. AddDirective('ERRORC',directive_mac, @dir_error);
  1100. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1101. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1102. AddDirective('FATAL',directive_all, @dir_fatal);
  1103. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1104. AddDirective('GOTO',directive_all, @dir_goto);
  1105. AddDirective('HINT',directive_all, @dir_hint);
  1106. AddDirective('HINTS',directive_all, @dir_hints);
  1107. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1108. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1109. AddDirective('IMAGEBASE',directive_all, @dir_imagebase);
  1110. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1111. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1112. AddDirective('INFO',directive_all, @dir_info);
  1113. AddDirective('INLINE',directive_all, @dir_inline);
  1114. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1115. AddDirective('L',directive_all, @dir_link);
  1116. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1117. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1118. AddDirective('LINK',directive_all, @dir_link);
  1119. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1120. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1121. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1122. AddDirective('M',directive_all, @dir_memory);
  1123. AddDirective('MACRO',directive_all, @dir_macro);
  1124. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1125. AddDirective('MAXSTACKSIZE',directive_all, @dir_maxstacksize);
  1126. AddDirective('MEMORY',directive_all, @dir_memory);
  1127. AddDirective('MESSAGE',directive_all, @dir_message);
  1128. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1129. AddDirective('MINSTACKSIZE',directive_all, @dir_minstacksize);
  1130. AddDirective('MMX',directive_all, @dir_mmx);
  1131. AddDirective('MODE',directive_all, @dir_mode);
  1132. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1133. AddDirective('NOTE',directive_all, @dir_note);
  1134. AddDirective('NOTES',directive_all, @dir_notes);
  1135. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1136. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1137. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1138. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1139. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1140. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1141. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1142. AddDirective('PACKSET',directive_all, @dir_packset);
  1143. AddDirective('PIC',directive_all, @dir_pic);
  1144. AddDirective('POP',directive_mac, @dir_pop);
  1145. AddDirective('PROFILE',directive_all, @dir_profile);
  1146. AddDirective('PUSH',directive_mac, @dir_push);
  1147. AddDirective('R',directive_all, @dir_resource);
  1148. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1149. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1150. AddDirective('RESOURCE',directive_all, @dir_resource);
  1151. AddDirective('SATURATION',directive_all, @dir_saturation);
  1152. AddDirective('SAVEFPUEXCEPTIONS',directive_all, @dir_savefpuexceptions);
  1153. AddDirective('SETPEFLAGS', directive_all, @dir_setpeflags);
  1154. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1155. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1156. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1157. AddDirective('STATIC',directive_all, @dir_static);
  1158. AddDirective('STOP',directive_all, @dir_stop);
  1159. {$ifdef powerpc}
  1160. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1161. {$endif powerpc}
  1162. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1163. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1164. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1165. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1166. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1167. AddDirective('VERSION',directive_all, @dir_version);
  1168. AddDirective('WAIT',directive_all, @dir_wait);
  1169. AddDirective('WARN',directive_all, @dir_warn);
  1170. AddDirective('WARNING',directive_all, @dir_warning);
  1171. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1172. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1173. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1174. AddDirective('Z1',directive_all, @dir_z1);
  1175. AddDirective('Z2',directive_all, @dir_z2);
  1176. AddDirective('Z4',directive_all, @dir_z4);
  1177. end;
  1178. begin
  1179. localswitchesstackpos:= 0;
  1180. end.