scandir.pas 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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,cpuinfo,
  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_a1;
  159. begin
  160. aktpackrecords:=1;
  161. end;
  162. procedure dir_a2;
  163. begin
  164. aktpackrecords:=2;
  165. end;
  166. procedure dir_a4;
  167. begin
  168. aktpackrecords:=4;
  169. end;
  170. procedure dir_a8;
  171. begin
  172. aktpackrecords:=8;
  173. end;
  174. procedure dir_asmmode;
  175. var
  176. s : string;
  177. begin
  178. current_scanner.skipspace;
  179. s:=current_scanner.readid;
  180. If Inside_asm_statement then
  181. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  182. if s='DEFAULT' then
  183. aktasmmode:=initasmmode
  184. else
  185. if not SetAsmReadMode(s,aktasmmode) then
  186. Message1(scan_e_illegal_asmmode_specifier,s);
  187. end;
  188. {$if defined(m68k) or defined(arm)}
  189. procedure dir_appid;
  190. begin
  191. if target_info.system<>system_m68k_palmos then
  192. Message(scan_w_appid_not_support);
  193. { change description global var in all cases }
  194. { it not used but in win32 and os2 }
  195. current_scanner.skipspace;
  196. palmos_applicationid:=current_scanner.readcomment;
  197. end;
  198. procedure dir_appname;
  199. begin
  200. if target_info.system<>system_m68k_palmos then
  201. Message(scan_w_appname_not_support);
  202. { change description global var in all cases }
  203. { it not used but in win32 and os2 }
  204. current_scanner.skipspace;
  205. palmos_applicationname:=current_scanner.readcomment;
  206. end;
  207. {$endif defined(m68k) or defined(arm)}
  208. procedure dir_apptype;
  209. var
  210. hs : string;
  211. begin
  212. if not (target_info.system in system_all_windows + [system_i386_os2,
  213. system_i386_emx, system_powerpc_macos]) then
  214. begin
  215. if m_delphi in aktmodeswitches then
  216. Message(scan_n_app_type_not_support)
  217. else
  218. Message(scan_w_app_type_not_support);
  219. end
  220. else
  221. begin
  222. if not current_module.in_global then
  223. Message(scan_w_switch_is_global)
  224. else
  225. begin
  226. current_scanner.skipspace;
  227. hs:=current_scanner.readid;
  228. if hs='GUI' then
  229. apptype:=app_gui
  230. else if hs='CONSOLE' then
  231. apptype:=app_cui
  232. else if (hs='NATIVE') and (target_info.system in system_windows) then
  233. apptype:=app_native
  234. else if (hs='FS') and (target_info.system in [system_i386_os2,
  235. system_i386_emx]) then
  236. apptype:=app_fs
  237. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  238. apptype:=app_tool
  239. else
  240. Message1(scan_w_unsupported_app_type,hs);
  241. end;
  242. end;
  243. end;
  244. procedure dir_calling;
  245. var
  246. hs : string;
  247. begin
  248. current_scanner.skipspace;
  249. hs:=current_scanner.readid;
  250. if not SetAktProcCall(hs,aktdefproccall) then
  251. begin
  252. if (hs <> '') then
  253. Message1(parser_w_unknown_proc_directive_ignored,hs)
  254. else
  255. Message(parser_e_proc_directive_expected);
  256. end;
  257. end;
  258. procedure dir_checkpointer;
  259. begin
  260. do_localswitchdefault(cs_checkpointer);
  261. end;
  262. procedure dir_objectchecks;
  263. begin
  264. do_localswitch(cs_check_object);
  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 [system_i386_os2,system_i386_emx,
  281. system_i386_win32,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. { current_scanner.undef_macro('FPU'+fputypestr[aktfputype]); }
  329. if not(SetFPUType(upper(current_scanner.readcomment),aktfputype)) then
  330. comment(V_Error,'Illegal FPU type');
  331. { current_scanner.def_macro('FPU'+fputypestr[aktfputype]); }
  332. end;
  333. procedure dir_goto;
  334. begin
  335. do_moduleswitch(cs_support_goto);
  336. end;
  337. procedure dir_hint;
  338. begin
  339. do_message(scan_h_user_defined);
  340. end;
  341. procedure dir_hints;
  342. begin
  343. do_setverbose('H');
  344. end;
  345. procedure dir_implicitexceptions;
  346. begin
  347. do_moduleswitch(cs_implicit_exceptions);
  348. end;
  349. procedure dir_includepath;
  350. begin
  351. if not current_module.in_global then
  352. Message(scan_w_switch_is_global)
  353. else
  354. begin
  355. current_scanner.skipspace;
  356. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  357. end;
  358. end;
  359. procedure dir_info;
  360. begin
  361. do_message(scan_i_user_defined);
  362. end;
  363. procedure dir_inline;
  364. begin
  365. do_moduleswitch(cs_support_inline);
  366. end;
  367. procedure dir_interfaces;
  368. var
  369. hs : string;
  370. begin
  371. {corba/com/default}
  372. current_scanner.skipspace;
  373. hs:=current_scanner.readid;
  374. if (hs='CORBA') then
  375. aktinterfacetype:=it_interfacecorba
  376. else if (hs='COM') then
  377. aktinterfacetype:=it_interfacecom
  378. else if (hs='DEFAULT') then
  379. aktinterfacetype:=initinterfacetype
  380. else
  381. Message(scan_e_invalid_interface_type);
  382. end;
  383. procedure dir_iochecks;
  384. begin
  385. do_delphiswitch('I');
  386. end;
  387. procedure dir_libexport;
  388. begin
  389. {not implemented}
  390. end;
  391. procedure dir_librarypath;
  392. begin
  393. if not current_module.in_global then
  394. Message(scan_w_switch_is_global)
  395. else
  396. begin
  397. current_scanner.skipspace;
  398. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  399. end;
  400. end;
  401. procedure dir_link;
  402. var
  403. s : string;
  404. begin
  405. current_scanner.skipspace;
  406. if scanner.c = '''' then
  407. begin
  408. s:= current_scanner.readquotedstring;
  409. current_scanner.readcomment
  410. end
  411. else
  412. s:= trimspace(current_scanner.readcomment);
  413. s:=AddExtension(FixFileName(s),target_info.objext);
  414. current_module.linkotherofiles.add(s,link_always);
  415. end;
  416. procedure dir_linklib;
  417. type
  418. tLinkMode=(lm_shared,lm_static);
  419. var
  420. s : string;
  421. quote : char;
  422. libext,
  423. libname,
  424. linkmodestr : string;
  425. p : longint;
  426. linkMode : tLinkMode;
  427. begin
  428. current_scanner.skipspace;
  429. if scanner.c = '''' then
  430. begin
  431. libname:= current_scanner.readquotedstring;
  432. s:= current_scanner.readcomment;
  433. p:=pos(',',s);
  434. end
  435. else
  436. begin
  437. s:= current_scanner.readcomment;
  438. p:=pos(',',s);
  439. if p=0 then
  440. libname:=TrimSpace(s)
  441. else
  442. libname:=TrimSpace(copy(s,1,p-1));
  443. end;
  444. if p=0 then
  445. linkmodeStr:=''
  446. else
  447. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  448. if (libname='') or (libname='''''') or (libname='""') then
  449. exit;
  450. { create library name }
  451. if libname[1] in ['''','"'] then
  452. begin
  453. quote:=libname[1];
  454. Delete(libname,1,1);
  455. p:=pos(quote,libname);
  456. if p>0 then
  457. Delete(libname,p,1);
  458. end;
  459. libname:=FixFileName(libname);
  460. { get linkmode, default is to check the extension for
  461. the static library, otherwise shared linking is assumed }
  462. linkmode:=lm_shared;
  463. if linkModeStr='' then
  464. begin
  465. libext:=SplitExtension(libname);
  466. if libext=target_info.staticClibext then
  467. linkMode:=lm_static;
  468. end
  469. else if linkModeStr='STATIC' then
  470. linkmode:=lm_static
  471. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  472. linkmode:=lm_shared
  473. else
  474. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  475. { add to the list of other libraries }
  476. if linkMode=lm_static then
  477. current_module.linkOtherStaticLibs.add(libname,link_always)
  478. else
  479. current_module.linkOtherSharedLibs.add(libname,link_always);
  480. end;
  481. procedure dir_localsymbols;
  482. begin
  483. do_delphiswitch('L');
  484. end;
  485. procedure dir_longstrings;
  486. begin
  487. do_delphiswitch('H');
  488. end;
  489. procedure dir_macro;
  490. begin
  491. do_moduleswitch(cs_support_macro);
  492. end;
  493. procedure dir_maxfpuregisters;
  494. var
  495. l : integer;
  496. hs : string;
  497. begin
  498. current_scanner.skipspace;
  499. if not(c in ['0'..'9']) then
  500. begin
  501. hs:=current_scanner.readid;
  502. if (hs='NORMAL') or (hs='DEFAULT') then
  503. aktmaxfpuregisters:=-1
  504. else
  505. Message(scan_e_invalid_maxfpureg_value);
  506. end
  507. else
  508. begin
  509. l:=current_scanner.readval;
  510. case l of
  511. 0..8:
  512. aktmaxfpuregisters:=l;
  513. else
  514. Message(scan_e_invalid_maxfpureg_value);
  515. end;
  516. end;
  517. end;
  518. procedure dir_memory;
  519. var
  520. l : longint;
  521. begin
  522. current_scanner.skipspace;
  523. l:=current_scanner.readval;
  524. if l>1024 then
  525. stacksize:=l;
  526. if c=',' then
  527. begin
  528. current_scanner.readchar;
  529. current_scanner.skipspace;
  530. l:=current_scanner.readval;
  531. if l>1024 then
  532. heapsize:=l;
  533. end;
  534. end;
  535. procedure dir_message;
  536. var
  537. hs : string;
  538. w : longint;
  539. begin
  540. w:=0;
  541. current_scanner.skipspace;
  542. { Message level specified? }
  543. if c='''' then
  544. w:=scan_n_user_defined
  545. else
  546. begin
  547. hs:=current_scanner.readid;
  548. if (hs='WARN') or (hs='WARNING') then
  549. w:=scan_w_user_defined
  550. else
  551. if (hs='ERROR') then
  552. w:=scan_e_user_defined
  553. else
  554. if (hs='FATAL') then
  555. w:=scan_f_user_defined
  556. else
  557. if (hs='HINT') then
  558. w:=scan_h_user_defined
  559. else
  560. if (hs='NOTE') then
  561. w:=scan_n_user_defined
  562. else
  563. Message1(scan_w_illegal_directive,hs);
  564. end;
  565. { Only print message when there was no error }
  566. if w<>0 then
  567. begin
  568. current_scanner.skipspace;
  569. if c='''' then
  570. hs:=current_scanner.readquotedstring
  571. else
  572. hs:=current_scanner.readcomment;
  573. Message1(w,hs);
  574. end
  575. else
  576. current_scanner.readcomment;
  577. end;
  578. procedure dir_mode;
  579. begin
  580. if not current_module.in_global then
  581. Message(scan_w_switch_is_global)
  582. else
  583. begin
  584. current_scanner.skipspace;
  585. current_scanner.readstring;
  586. if not current_module.mode_switch_allowed and
  587. not ((m_mac in aktmodeswitches) and (pattern='MACPAS')) then
  588. Message1(scan_e_mode_switch_not_allowed,pattern)
  589. else if not SetCompileMode(pattern,false) then
  590. Message1(scan_w_illegal_switch,pattern)
  591. end;
  592. current_module.mode_switch_allowed:= false;
  593. end;
  594. procedure dir_mmx;
  595. begin
  596. do_localswitch(cs_mmx);
  597. end;
  598. procedure dir_note;
  599. begin
  600. do_message(scan_n_user_defined);
  601. end;
  602. procedure dir_notes;
  603. begin
  604. do_setverbose('N');
  605. end;
  606. procedure dir_objectpath;
  607. begin
  608. if not current_module.in_global then
  609. Message(scan_w_switch_is_global)
  610. else
  611. begin
  612. current_scanner.skipspace;
  613. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  614. end;
  615. end;
  616. procedure dir_openstrings;
  617. begin
  618. do_delphiswitch('P');
  619. end;
  620. procedure dir_optimization;
  621. var
  622. hs : string;
  623. begin
  624. current_scanner.skipspace;
  625. { Support also the ON and OFF as switch }
  626. hs:=current_scanner.readid;
  627. if (hs='ON') then
  628. aktoptimizerswitches:=level2optimizerswitches
  629. else if (hs='OFF') then
  630. aktoptimizerswitches:=[]
  631. else if (hs='DEFAULT') then
  632. aktoptimizerswitches:=initoptimizerswitches
  633. else
  634. begin
  635. if not UpdateOptimizerStr(hs,aktoptimizerswitches) then
  636. Message1(scan_e_illegal_optimization_specifier,hs);
  637. end;
  638. end;
  639. procedure dir_overflowchecks;
  640. begin
  641. do_delphiswitch('Q');
  642. end;
  643. procedure dir_packenum;
  644. var
  645. hs : string;
  646. begin
  647. current_scanner.skipspace;
  648. if not(c in ['0'..'9']) then
  649. begin
  650. hs:=current_scanner.readid;
  651. if (hs='NORMAL') or (hs='DEFAULT') then
  652. aktpackenum:=4
  653. else
  654. Message1(scan_e_illegal_pack_enum, hs);
  655. end
  656. else
  657. begin
  658. case current_scanner.readval of
  659. 1 : aktpackenum:=1;
  660. 2 : aktpackenum:=2;
  661. 4 : aktpackenum:=4;
  662. else
  663. Message1(scan_e_illegal_pack_enum, pattern);
  664. end;
  665. end;
  666. end;
  667. procedure dir_packrecords;
  668. var
  669. hs : string;
  670. begin
  671. current_scanner.skipspace;
  672. if not(c in ['0'..'9']) then
  673. begin
  674. hs:=current_scanner.readid;
  675. { C has the special recordalignmax of -1 }
  676. if (hs='C') then
  677. aktpackrecords:=-1
  678. else
  679. if (hs='NORMAL') or (hs='DEFAULT') then
  680. aktpackrecords:=0
  681. else
  682. Message1(scan_e_illegal_pack_records,hs);
  683. end
  684. else
  685. begin
  686. case current_scanner.readval of
  687. 1 : aktpackrecords:=1;
  688. 2 : aktpackrecords:=2;
  689. 4 : aktpackrecords:=4;
  690. 8 : aktpackrecords:=8;
  691. 16 : aktpackrecords:=16;
  692. 32 : aktpackrecords:=32;
  693. else
  694. Message1(scan_e_illegal_pack_records,pattern);
  695. end;
  696. end;
  697. end;
  698. {$ifdef testvarsets}
  699. procedure dir_packset;
  700. var
  701. hs : string;
  702. begin
  703. current_scanner.skipspace;
  704. if not(c in ['1','2','4']) then
  705. begin
  706. hs:=current_scanner.readid;
  707. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  708. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  709. else
  710. Message(scan_w_only_packset);
  711. end
  712. else
  713. begin
  714. case current_scanner.readval of
  715. 1 : aktsetalloc:=1;
  716. 2 : aktsetalloc:=2;
  717. 4 : aktsetalloc:=4;
  718. else
  719. Message(scan_w_only_packset);
  720. end;
  721. end;
  722. end;
  723. {$ENDIF}
  724. procedure dir_pic;
  725. begin
  726. do_moduleswitch(cs_create_pic);
  727. end;
  728. procedure dir_pop;
  729. begin
  730. if localswitchesstackpos < 1 then
  731. Message(scan_e_too_many_pop);
  732. if not localswitcheschanged then
  733. nextaktlocalswitches:=aktlocalswitches;
  734. Dec(localswitchesstackpos);
  735. nextaktlocalswitches:= localswitchesstack[localswitchesstackpos];
  736. localswitcheschanged:=true;
  737. end;
  738. procedure dir_profile;
  739. begin
  740. do_moduleswitch(cs_profile);
  741. { defined/undefine FPC_PROFILE }
  742. if cs_profile in aktmoduleswitches then
  743. def_system_macro('FPC_PROFILE')
  744. else
  745. undef_system_macro('FPC_PROFILE');
  746. end;
  747. procedure dir_push;
  748. begin
  749. if localswitchesstackpos > localswitchesstackmax then
  750. Message(scan_e_too_many_push);
  751. if localswitcheschanged then
  752. begin
  753. aktlocalswitches:=nextaktlocalswitches;
  754. localswitcheschanged:=false;
  755. end;
  756. localswitchesstack[localswitchesstackpos]:= aktlocalswitches;
  757. Inc(localswitchesstackpos);
  758. end;
  759. procedure dir_rangechecks;
  760. begin
  761. do_delphiswitch('R');
  762. end;
  763. procedure dir_referenceinfo;
  764. begin
  765. do_delphiswitch('Y');
  766. end;
  767. procedure dir_resource;
  768. var
  769. s : string;
  770. begin
  771. current_scanner.skipspace;
  772. if scanner.c = '''' then
  773. begin
  774. s:= current_scanner.readquotedstring;
  775. current_scanner.readcomment
  776. end
  777. else
  778. s:= trimspace(current_scanner.readcomment);
  779. { replace * with current module name.
  780. This should always be defined. }
  781. if s[1]='*' then
  782. if Assigned(Current_Module) then
  783. begin
  784. delete(S,1,1);
  785. if m_delphi in aktmodeswitches then
  786. insert(current_module.realmodulename^,S,1)
  787. else
  788. insert(lower(current_module.modulename^),S,1);
  789. end;
  790. s:=AddExtension(FixFileName(s),target_info.resext);
  791. if target_info.res<>res_none then
  792. begin
  793. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  794. if (target_info.res = res_emxbind) and
  795. not (Current_module.ResourceFiles.Empty) then
  796. Message(scan_w_only_one_resourcefile_supported)
  797. else
  798. current_module.resourcefiles.insert(FixFileName(s));
  799. end
  800. else
  801. Message(scan_e_resourcefiles_not_supported);
  802. end;
  803. procedure dir_saturation;
  804. begin
  805. do_localswitch(cs_mmx_saturation);
  806. end;
  807. procedure dir_smartlink;
  808. begin
  809. do_moduleswitch(cs_create_smart);
  810. end;
  811. procedure dir_stackframes;
  812. begin
  813. do_delphiswitch('W');
  814. end;
  815. procedure dir_static;
  816. begin
  817. do_moduleswitch(cs_static_keyword);
  818. end;
  819. procedure dir_stop;
  820. begin
  821. do_message(scan_f_user_defined);
  822. end;
  823. {$ifdef powerpc}
  824. procedure dir_syscall;
  825. var
  826. sctype : string;
  827. begin
  828. { not needed on amiga/m68k for now, because there's only one }
  829. { syscall convention (legacy) (KB) }
  830. { not needed on amiga/powerpc because there's only one }
  831. { syscall convention (sysv) (KB) }
  832. if not (target_info.system in [system_powerpc_morphos]) then
  833. comment (V_Warning,'Syscall directive is useless on this target.');
  834. current_scanner.skipspace;
  835. sctype:=current_scanner.readid;
  836. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  837. (sctype='BASESYSV') or (sctype='R12BASE') then
  838. syscall_convention:=sctype
  839. else
  840. comment (V_Warning,'Invalid Syscall directive ignored.');
  841. end;
  842. {$endif}
  843. procedure dir_typedaddress;
  844. begin
  845. do_delphiswitch('T');
  846. end;
  847. procedure dir_typeinfo;
  848. begin
  849. do_delphiswitch('M');
  850. end;
  851. procedure dir_unitpath;
  852. begin
  853. if not current_module.in_global then
  854. Message(scan_w_switch_is_global)
  855. else
  856. with current_scanner,current_module,localunitsearchpath do
  857. begin
  858. skipspace;
  859. AddPath(path^,readcomment,false);
  860. end;
  861. end;
  862. procedure dir_varstringchecks;
  863. begin
  864. do_delphiswitch('V');
  865. end;
  866. procedure dir_version;
  867. var
  868. major, minor, revision : longint;
  869. error : integer;
  870. begin
  871. if not (target_info.system in [system_i386_os2,system_i386_emx,
  872. system_i386_win32,system_i386_netware,system_i386_wdosx,
  873. system_i386_netwlibc]) then
  874. begin
  875. Message(scan_n_version_not_support);
  876. exit;
  877. end;
  878. if (compile_level<>1) then
  879. Message(scan_n_only_exe_version)
  880. else
  881. begin
  882. { change description global var in all cases }
  883. { it not used but in win32, os2 and netware }
  884. current_scanner.skipspace;
  885. { we should only accept Major.Minor format for win32 and os2 }
  886. current_scanner.readnumber;
  887. major:=0;
  888. minor:=0;
  889. revision:=0;
  890. val(pattern,major,error);
  891. if (error<>0) or (major > high(word)) or (major < 0) then
  892. begin
  893. Message1(scan_w_wrong_version_ignored,pattern);
  894. exit;
  895. end;
  896. if c='.' then
  897. begin
  898. current_scanner.readchar;
  899. current_scanner.readnumber;
  900. val(pattern,minor,error);
  901. if (error<>0) or (minor > high(word)) or (minor < 0) then
  902. begin
  903. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  904. exit;
  905. end;
  906. if (c='.') and
  907. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  908. begin
  909. current_scanner.readchar;
  910. current_scanner.readnumber;
  911. val(pattern,revision,error);
  912. if (error<>0) or (revision > high(word)) or (revision < 0) then
  913. begin
  914. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  915. exit;
  916. end;
  917. dllmajor:=word(major);
  918. dllminor:=word(minor);
  919. dllrevision:=word(revision);
  920. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  921. end
  922. else
  923. begin
  924. dllmajor:=word(major);
  925. dllminor:=word(minor);
  926. dllversion:=tostr(major)+'.'+tostr(minor);
  927. end;
  928. end
  929. else
  930. dllversion:=tostr(major);
  931. end;
  932. end;
  933. procedure dir_wait;
  934. var
  935. had_info : boolean;
  936. begin
  937. had_info:=(status.verbosity and V_Info)<>0;
  938. { this message should allways appear !! }
  939. status.verbosity:=status.verbosity or V_Info;
  940. Message(scan_i_press_enter);
  941. readln;
  942. If not(had_info) then
  943. status.verbosity:=status.verbosity and (not V_Info);
  944. end;
  945. procedure dir_warn;
  946. var
  947. warning_string,state : string;
  948. begin
  949. current_scanner.skipspace;
  950. warning_string:=current_scanner.readid;
  951. if (upper(warning_string)='ON') then
  952. begin
  953. end
  954. else if (upper(warning_string)='ON') then
  955. else
  956. begin
  957. current_scanner.skipspace;
  958. state:=current_scanner.readid;
  959. end;
  960. end;
  961. procedure dir_warning;
  962. begin
  963. do_message(scan_w_user_defined);
  964. end;
  965. procedure dir_warnings;
  966. begin
  967. do_setverbose('W');
  968. end;
  969. procedure dir_writeableconst;
  970. begin
  971. do_delphiswitch('J');
  972. end;
  973. procedure dir_z1;
  974. begin
  975. aktpackenum:=1;
  976. end;
  977. procedure dir_z2;
  978. begin
  979. aktpackenum:=2;
  980. end;
  981. procedure dir_z4;
  982. begin
  983. aktpackenum:=4;
  984. end;
  985. procedure dir_externalsym;
  986. begin
  987. end;
  988. procedure dir_nodefine;
  989. begin
  990. end;
  991. procedure dir_hppemit;
  992. begin
  993. end;
  994. procedure dir_weakpackageunit;
  995. begin
  996. end;
  997. procedure dir_codealign;
  998. var
  999. s : string;
  1000. begin
  1001. current_scanner.skipspace;
  1002. s:=current_scanner.readcomment;
  1003. UpdateAlignmentStr(s,aktalignment);
  1004. end;
  1005. procedure dir_codepage;
  1006. var
  1007. s : string;
  1008. begin
  1009. if not current_module.in_global then
  1010. Message(scan_w_switch_is_global)
  1011. else
  1012. begin
  1013. current_scanner.skipspace;
  1014. s:=current_scanner.readcomment;
  1015. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1016. aktsourcecodepage:='utf8'
  1017. else if not(cpavailable(s)) then
  1018. Message1(option_code_page_not_available,s)
  1019. else
  1020. aktsourcecodepage:=s;
  1021. end;
  1022. end;
  1023. procedure dir_coperators;
  1024. begin
  1025. do_moduleswitch(cs_support_c_operators);
  1026. end;
  1027. {****************************************************************************
  1028. Initialize Directives
  1029. ****************************************************************************}
  1030. procedure InitScannerDirectives;
  1031. begin
  1032. AddDirective('A1',directive_all, @dir_a1);
  1033. AddDirective('A2',directive_all, @dir_a2);
  1034. AddDirective('A4',directive_all, @dir_a4);
  1035. AddDirective('A8',directive_all, @dir_a8);
  1036. AddDirective('ALIGN',directive_all, @dir_align);
  1037. {$ifdef m68k}
  1038. AddDirective('APPID',directive_all, @dir_appid);
  1039. AddDirective('APPNAME',directive_all, @dir_appname);
  1040. {$endif m68k}
  1041. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1042. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1043. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1044. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1045. AddDirective('CALLING',directive_all, @dir_calling);
  1046. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1047. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1048. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1049. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1050. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1051. AddDirective('D',directive_all, @dir_description);
  1052. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1053. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1054. AddDirective('ERROR',directive_all, @dir_error);
  1055. AddDirective('ERRORC',directive_mac, @dir_error);
  1056. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1057. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1058. AddDirective('FATAL',directive_all, @dir_fatal);
  1059. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1060. AddDirective('GOTO',directive_all, @dir_goto);
  1061. AddDirective('HINT',directive_all, @dir_hint);
  1062. AddDirective('HINTS',directive_all, @dir_hints);
  1063. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1064. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1065. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1066. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1067. AddDirective('INFO',directive_all, @dir_info);
  1068. AddDirective('INLINE',directive_all, @dir_inline);
  1069. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1070. AddDirective('L',directive_all, @dir_link);
  1071. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1072. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1073. AddDirective('LINK',directive_all, @dir_link);
  1074. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1075. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1076. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1077. AddDirective('M',directive_all, @dir_memory);
  1078. AddDirective('MACRO',directive_all, @dir_macro);
  1079. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1080. AddDirective('MEMORY',directive_all, @dir_memory);
  1081. AddDirective('MESSAGE',directive_all, @dir_message);
  1082. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1083. AddDirective('MMX',directive_all, @dir_mmx);
  1084. AddDirective('MODE',directive_all, @dir_mode);
  1085. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1086. AddDirective('NOTE',directive_all, @dir_note);
  1087. AddDirective('NOTES',directive_all, @dir_notes);
  1088. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1089. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1090. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1091. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1092. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1093. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1094. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1095. {$IFDEF TestVarsets}
  1096. AddDirective('PACKSET',directive_all, @dir_packset);
  1097. {$ENDIF}
  1098. AddDirective('PIC',directive_all, @dir_pic);
  1099. AddDirective('POP',directive_mac, @dir_pop);
  1100. AddDirective('PROFILE',directive_all, @dir_profile);
  1101. AddDirective('PUSH',directive_mac, @dir_push);
  1102. AddDirective('R',directive_all, @dir_resource);
  1103. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1104. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1105. AddDirective('RESOURCE',directive_all, @dir_resource);
  1106. AddDirective('SATURATION',directive_all, @dir_saturation);
  1107. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1108. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1109. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1110. AddDirective('STATIC',directive_all, @dir_static);
  1111. AddDirective('STOP',directive_all, @dir_stop);
  1112. {$ifdef powerpc}
  1113. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1114. {$endif powerpc}
  1115. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1116. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1117. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1118. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1119. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1120. AddDirective('VERSION',directive_all, @dir_version);
  1121. AddDirective('WAIT',directive_all, @dir_wait);
  1122. AddDirective('WARN',directive_all, @dir_warn);
  1123. AddDirective('WARNING',directive_all, @dir_warning);
  1124. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1125. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1126. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1127. AddDirective('Z1',directive_all, @dir_z1);
  1128. AddDirective('Z2',directive_all, @dir_z2);
  1129. AddDirective('Z4',directive_all, @dir_z4);
  1130. end;
  1131. begin
  1132. localswitchesstackpos:= 0;
  1133. end.