scandir.pas 36 KB

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