scandir.pas 36 KB

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