scandir.pas 37 KB

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