scandir.pas 34 KB

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