scandir.pas 37 KB

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