scandir.pas 36 KB

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