scandir.pas 34 KB

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