scandir.pas 42 KB

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