scandir.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. if c=',' then
  485. begin
  486. current_scanner.readchar;
  487. current_scanner.skipspace;
  488. l:=current_scanner.readval;
  489. if l>1024 then
  490. heapsize:=l;
  491. end;
  492. end;
  493. procedure dir_message;
  494. var
  495. hs : string;
  496. w : longint;
  497. begin
  498. w:=0;
  499. current_scanner.skipspace;
  500. { Message level specified? }
  501. if c='''' then
  502. w:=scan_n_user_defined
  503. else
  504. begin
  505. hs:=current_scanner.readid;
  506. if (hs='WARN') or (hs='WARNING') then
  507. w:=scan_w_user_defined
  508. else
  509. if (hs='ERROR') then
  510. w:=scan_e_user_defined
  511. else
  512. if (hs='FATAL') then
  513. w:=scan_f_user_defined
  514. else
  515. if (hs='HINT') then
  516. w:=scan_h_user_defined
  517. else
  518. if (hs='NOTE') then
  519. w:=scan_n_user_defined
  520. else
  521. Message1(scan_w_illegal_directive,hs);
  522. end;
  523. { Only print message when there was no error }
  524. if w<>0 then
  525. begin
  526. current_scanner.skipspace;
  527. if c='''' then
  528. hs:=current_scanner.readquotedstring
  529. else
  530. hs:=current_scanner.readcomment;
  531. Message1(w,hs);
  532. end
  533. else
  534. current_scanner.readcomment;
  535. end;
  536. procedure dir_mode;
  537. begin
  538. if not current_module.in_global then
  539. Message(scan_w_switch_is_global)
  540. else
  541. begin
  542. current_scanner.skipspace;
  543. current_scanner.readstring;
  544. if not SetCompileMode(pattern,false) then
  545. Message1(scan_w_illegal_switch,pattern);
  546. end;
  547. end;
  548. procedure dir_mmx;
  549. begin
  550. do_localswitch(cs_mmx);
  551. end;
  552. procedure dir_note;
  553. begin
  554. do_message(scan_n_user_defined);
  555. end;
  556. procedure dir_notes;
  557. begin
  558. do_setverbose('N');
  559. end;
  560. procedure dir_objectpath;
  561. begin
  562. if not current_module.in_global then
  563. Message(scan_w_switch_is_global)
  564. else
  565. begin
  566. current_scanner.skipspace;
  567. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  568. end;
  569. end;
  570. procedure dir_openstrings;
  571. begin
  572. do_delphiswitch('P');
  573. end;
  574. procedure dir_output_format;
  575. begin
  576. if not current_module.in_global then
  577. Message(scan_w_switch_is_global)
  578. else
  579. begin
  580. current_scanner.skipspace;
  581. if set_target_asm_by_string(current_scanner.readid) then
  582. aktoutputformat:=target_asm.id
  583. else
  584. Message1(scan_w_illegal_switch,pattern);
  585. end;
  586. end;
  587. procedure dir_overflowchecks;
  588. begin
  589. do_delphiswitch('Q');
  590. end;
  591. procedure dir_packenum;
  592. var
  593. hs : string;
  594. begin
  595. current_scanner.skipspace;
  596. if not(c in ['0'..'9']) then
  597. begin
  598. hs:=current_scanner.readid;
  599. if (hs='NORMAL') or (hs='DEFAULT') then
  600. aktpackenum:=4
  601. else
  602. Message(scan_w_only_pack_enum);
  603. end
  604. else
  605. begin
  606. case current_scanner.readval of
  607. 1 : aktpackenum:=1;
  608. 2 : aktpackenum:=2;
  609. 4 : aktpackenum:=4;
  610. else
  611. Message(scan_w_only_pack_enum);
  612. end;
  613. end;
  614. end;
  615. procedure dir_packrecords;
  616. var
  617. hs : string;
  618. begin
  619. current_scanner.skipspace;
  620. if not(c in ['0'..'9']) then
  621. begin
  622. hs:=current_scanner.readid;
  623. { C has the special recordalignmax of -1 }
  624. if (hs='C') then
  625. aktpackrecords:=-1
  626. else
  627. if (hs='NORMAL') or (hs='DEFAULT') then
  628. aktpackrecords:=0
  629. else
  630. Message(scan_w_only_pack_records);
  631. end
  632. else
  633. begin
  634. case current_scanner.readval of
  635. 1 : aktpackrecords:=1;
  636. 2 : aktpackrecords:=2;
  637. 4 : aktpackrecords:=4;
  638. 8 : aktpackrecords:=8;
  639. 16 : aktpackrecords:=16;
  640. 32 : aktpackrecords:=32;
  641. else
  642. Message(scan_w_only_pack_records);
  643. end;
  644. end;
  645. end;
  646. {$ifdef testvarsets}
  647. procedure dir_packset;
  648. var
  649. hs : string;
  650. begin
  651. current_scanner.skipspace;
  652. if not(c in ['1','2','4']) then
  653. begin
  654. hs:=current_scanner.readid;
  655. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  656. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  657. else
  658. Message(scan_w_only_packset);
  659. end
  660. else
  661. begin
  662. case current_scanner.readval of
  663. 1 : aktsetalloc:=1;
  664. 2 : aktsetalloc:=2;
  665. 4 : aktsetalloc:=4;
  666. else
  667. Message(scan_w_only_packset);
  668. end;
  669. end;
  670. end;
  671. {$ENDIF}
  672. procedure dir_pop;
  673. begin
  674. if localswitchesstackpos < 1 then
  675. Message(scan_e_too_many_pop);
  676. if not localswitcheschanged then
  677. nextaktlocalswitches:=aktlocalswitches;
  678. Dec(localswitchesstackpos);
  679. nextaktlocalswitches:= localswitchesstack[localswitchesstackpos];
  680. localswitcheschanged:=true;
  681. end;
  682. procedure dir_profile;
  683. var
  684. mac : tmacro;
  685. begin
  686. do_moduleswitch(cs_profile);
  687. { defined/undefine FPC_PROFILE }
  688. mac:=tmacro(current_scanner.macros.search('FPC_PROFILE'));
  689. if not assigned(mac) then
  690. begin
  691. mac:=tmacro.create('FPC_PROFILE');
  692. current_scanner.macros.insert(mac);
  693. end;
  694. mac.defined:=(cs_profile in aktmoduleswitches);
  695. end;
  696. procedure dir_push;
  697. begin
  698. if localswitchesstackpos > localswitchesstackmax then
  699. Message(scan_e_too_many_push);
  700. if localswitcheschanged then
  701. begin
  702. aktlocalswitches:=nextaktlocalswitches;
  703. localswitcheschanged:=false;
  704. end;
  705. localswitchesstack[localswitchesstackpos]:= aktlocalswitches;
  706. Inc(localswitchesstackpos);
  707. end;
  708. procedure dir_rangechecks;
  709. begin
  710. do_delphiswitch('R');
  711. end;
  712. procedure dir_referenceinfo;
  713. begin
  714. do_delphiswitch('Y');
  715. end;
  716. procedure dir_resource;
  717. var
  718. s : string;
  719. begin
  720. current_scanner.skipspace;
  721. if scanner.c = '''' then
  722. begin
  723. s:= current_scanner.readquotedstring;
  724. current_scanner.readcomment
  725. end
  726. else
  727. s:= trimspace(current_scanner.readcomment);
  728. { replace * with current module name.
  729. This should always be defined. }
  730. if s[1]='*' then
  731. if Assigned(Current_Module) then
  732. begin
  733. delete(S,1,1);
  734. insert(lower(current_module.modulename^),S,1);
  735. end;
  736. s:=AddExtension(FixFileName(s),target_info.resext);
  737. if target_info.res<>res_none then
  738. if (target_info.res = res_emxbind) and
  739. not (Current_module.ResourceFiles.Empty) then
  740. Message(scan_w_only_one_resourcefile_supported)
  741. else
  742. current_module.resourcefiles.insert(FixFileName(s))
  743. else
  744. Message(scan_e_resourcefiles_not_supported);
  745. end;
  746. procedure dir_saturation;
  747. begin
  748. do_localswitch(cs_mmx_saturation);
  749. end;
  750. procedure dir_smartlink;
  751. begin
  752. do_moduleswitch(cs_create_smart);
  753. end;
  754. procedure dir_stackframes;
  755. begin
  756. do_delphiswitch('W');
  757. end;
  758. procedure dir_static;
  759. begin
  760. do_moduleswitch(cs_static_keyword);
  761. end;
  762. procedure dir_stop;
  763. begin
  764. do_message(scan_f_user_defined);
  765. end;
  766. procedure dir_threading;
  767. var
  768. mac : tmacro;
  769. begin
  770. do_moduleswitch(cs_threading);
  771. { defined/undefine FPC_THREADING }
  772. mac:=tmacro(current_scanner.macros.search('FPC_THREADING'));
  773. if not assigned(mac) then
  774. begin
  775. mac:=tmacro.create('FPC_THREADING');
  776. current_scanner.macros.insert(mac);
  777. end;
  778. mac.defined:=(cs_threading in aktmoduleswitches);
  779. end;
  780. procedure dir_typedaddress;
  781. begin
  782. do_delphiswitch('T');
  783. end;
  784. procedure dir_typeinfo;
  785. begin
  786. do_delphiswitch('M');
  787. end;
  788. procedure dir_unitpath;
  789. begin
  790. if not current_module.in_global then
  791. Message(scan_w_switch_is_global)
  792. else
  793. with current_scanner,current_module,localunitsearchpath do
  794. begin
  795. skipspace;
  796. AddPath(path^,readcomment,false);
  797. end;
  798. end;
  799. procedure dir_varstringchecks;
  800. begin
  801. do_delphiswitch('V');
  802. end;
  803. procedure dir_version;
  804. var
  805. major, minor, revision : longint;
  806. error : integer;
  807. begin
  808. if not (target_info.system in [system_i386_os2,system_i386_emx,
  809. system_i386_win32,system_i386_netware,system_i386_wdosx,
  810. system_i386_netwlibc]) then
  811. begin
  812. Message(scan_n_version_not_support);
  813. exit;
  814. end;
  815. if (compile_level<>1) then
  816. Message(scan_n_only_exe_version)
  817. else
  818. begin
  819. { change description global var in all cases }
  820. { it not used but in win32, os2 and netware }
  821. current_scanner.skipspace;
  822. { we should only accept Major.Minor format for win32 and os2 }
  823. current_scanner.readnumber;
  824. major:=0;
  825. minor:=0;
  826. revision:=0;
  827. valint(pattern,major,error);
  828. if (error<>0) or (major > high(word)) or (major < 0) then
  829. begin
  830. Message1(scan_w_wrong_version_ignored,pattern);
  831. exit;
  832. end;
  833. if c='.' then
  834. begin
  835. current_scanner.readchar;
  836. current_scanner.readnumber;
  837. valint(pattern,minor,error);
  838. if (error<>0) or (minor > high(word)) or (minor < 0) then
  839. begin
  840. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  841. exit;
  842. end;
  843. if (c='.') and
  844. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  845. begin
  846. current_scanner.readchar;
  847. current_scanner.readnumber;
  848. valint(pattern,revision,error);
  849. if (error<>0) or (revision > high(word)) or (revision < 0) then
  850. begin
  851. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  852. exit;
  853. end;
  854. dllmajor:=word(major);
  855. dllminor:=word(minor);
  856. dllrevision:=word(revision);
  857. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  858. end
  859. else
  860. begin
  861. dllmajor:=word(major);
  862. dllminor:=word(minor);
  863. dllversion:=tostr(major)+'.'+tostr(minor);
  864. end;
  865. end
  866. else
  867. dllversion:=tostr(major);
  868. end;
  869. end;
  870. procedure dir_wait;
  871. var
  872. had_info : boolean;
  873. begin
  874. had_info:=(status.verbosity and V_Info)<>0;
  875. { this message should allways appear !! }
  876. status.verbosity:=status.verbosity or V_Info;
  877. Message(scan_i_press_enter);
  878. readln;
  879. If not(had_info) then
  880. status.verbosity:=status.verbosity and (not V_Info);
  881. end;
  882. procedure dir_warning;
  883. begin
  884. do_message(scan_w_user_defined);
  885. end;
  886. procedure dir_warnings;
  887. begin
  888. do_setverbose('W');
  889. end;
  890. procedure dir_writeableconst;
  891. begin
  892. do_delphiswitch('J');
  893. end;
  894. procedure dir_z1;
  895. begin
  896. aktpackenum:=1;
  897. end;
  898. procedure dir_z2;
  899. begin
  900. aktpackenum:=2;
  901. end;
  902. procedure dir_z4;
  903. begin
  904. aktpackenum:=4;
  905. end;
  906. procedure dir_externalsym;
  907. begin
  908. end;
  909. procedure dir_codepage;
  910. var
  911. s : string;
  912. begin
  913. if not current_module.in_global then
  914. Message(scan_w_switch_is_global)
  915. else
  916. begin
  917. current_scanner.skipspace;
  918. s:=current_scanner.readcomment;
  919. if not(cpavailable(s)) then
  920. Message1(option_code_page_not_available,s)
  921. else
  922. aktsourcecodepage:=s;
  923. end;
  924. end;
  925. {****************************************************************************
  926. Initialize Directives
  927. ****************************************************************************}
  928. procedure InitScannerDirectives;
  929. begin
  930. AddDirective('ALIGN',directive_all, @dir_align);
  931. {$ifdef m68k}
  932. AddDirective('APPID',directive_all, @dir_appid);
  933. AddDirective('APPNAME',directive_all, @dir_appname);
  934. {$endif m68k}
  935. AddDirective('APPTYPE',directive_all, @dir_apptype);
  936. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  937. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  938. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  939. AddDirective('CALLING',directive_all, @dir_calling);
  940. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  941. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  942. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  943. AddDirective('D',directive_all, @dir_description);
  944. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  945. AddDirective('DESCRIPTION',directive_all, @dir_description);
  946. AddDirective('ERROR',directive_all, @dir_error);
  947. AddDirective('ERRORC',directive_mac, @dir_error);
  948. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  949. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  950. AddDirective('FATAL',directive_all, @dir_fatal);
  951. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  952. AddDirective('GOTO',directive_all, @dir_goto);
  953. AddDirective('HINT',directive_all, @dir_hint);
  954. AddDirective('HINTS',directive_all, @dir_hints);
  955. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  956. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  957. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  958. AddDirective('INFO',directive_all, @dir_info);
  959. AddDirective('INLINE',directive_all, @dir_inline);
  960. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  961. AddDirective('L',directive_all, @dir_link);
  962. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  963. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  964. AddDirective('LINK',directive_all, @dir_link);
  965. AddDirective('LINKLIB',directive_all, @dir_linklib);
  966. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  967. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  968. AddDirective('M',directive_all, @dir_memory);
  969. AddDirective('MACRO',directive_all, @dir_macro);
  970. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  971. AddDirective('MEMORY',directive_all, @dir_memory);
  972. AddDirective('MESSAGE',directive_all, @dir_message);
  973. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  974. AddDirective('MMX',directive_all, @dir_mmx);
  975. AddDirective('MODE',directive_all, @dir_mode);
  976. AddDirective('NOTE',directive_all, @dir_note);
  977. AddDirective('NOTES',directive_all, @dir_notes);
  978. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  979. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  980. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  981. AddDirective('OUTPUT_FORMAT',directive_all, @dir_output_format);
  982. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  983. AddDirective('PACKENUM',directive_all, @dir_packenum);
  984. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  985. {$IFDEF TestVarsets}
  986. AddDirective('PACKSET',directive_all, @dir_packset);
  987. {$ENDIF}
  988. AddDirective('POP',directive_mac, @dir_pop);
  989. AddDirective('PROFILE',directive_all, @dir_profile);
  990. AddDirective('PUSH',directive_mac, @dir_push);
  991. AddDirective('R',directive_all, @dir_resource);
  992. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  993. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  994. AddDirective('RESOURCE',directive_all, @dir_resource);
  995. AddDirective('SATURATION',directive_all, @dir_saturation);
  996. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  997. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  998. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  999. AddDirective('STATIC',directive_all, @dir_static);
  1000. AddDirective('STOP',directive_all, @dir_stop);
  1001. AddDirective('THREADING',directive_all, @dir_threading);
  1002. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1003. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1004. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1005. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1006. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1007. AddDirective('VERSION',directive_all, @dir_version);
  1008. AddDirective('WAIT',directive_all, @dir_wait);
  1009. AddDirective('WARNING',directive_all, @dir_warning);
  1010. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1011. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1012. AddDirective('Z1',directive_all, @dir_z1);
  1013. AddDirective('Z2',directive_all, @dir_z2);
  1014. AddDirective('Z4',directive_all, @dir_z4);
  1015. end;
  1016. begin
  1017. localswitchesstackpos:= 0;
  1018. end.
  1019. {
  1020. $Log$
  1021. Revision 1.46 2004-10-26 15:11:01 peter
  1022. * -Ch for heapsize added again
  1023. * __heapsize contains the heapsize
  1024. Revision 1.45 2004/10/25 15:38:41 peter
  1025. * heap and heapsize removed
  1026. * checkpointer fixes
  1027. Revision 1.44 2004/10/15 09:14:17 mazen
  1028. - remove $IFDEF DELPHI and related code
  1029. - remove $IFDEF FPCPROCVAR and related code
  1030. Revision 1.43 2004/09/04 21:18:47 armin
  1031. * target netwlibc added (libc is preferred for newer netware versions)
  1032. Revision 1.42 2004/08/31 22:07:04 olle
  1033. + compiler directives which take filenames/paths, get these trimmed, and
  1034. also support quotes.
  1035. Revision 1.41 2004/08/22 10:17:27 peter
  1036. * support $RESOURCE
  1037. Revision 1.40 2004/08/16 11:34:25 olle
  1038. + added directive LibExport for macpas, which does nothing atm
  1039. Revision 1.39 2004/07/06 09:41:46 olle
  1040. * fixes compilation on 1.0.*
  1041. Revision 1.38 2004/07/05 21:49:43 olle
  1042. + macpas style: exit, cycle, leave
  1043. + macpas compiler directive: PUSH POP
  1044. Revision 1.37 2004/06/20 08:55:30 florian
  1045. * logs truncated
  1046. Revision 1.36 2004/06/16 20:07:09 florian
  1047. * dwarf branch merged
  1048. Revision 1.35 2004/05/19 23:29:56 peter
  1049. * $message directive compatible with delphi
  1050. Revision 1.34 2004/05/11 22:51:34 olle
  1051. * Performanceimprovement
  1052. Revision 1.33 2004/05/11 18:30:50 olle
  1053. + mode macpas: support for Apples align directives
  1054. Revision 1.32.2.1 2004/05/03 14:59:57 peter
  1055. * no dlltool needed for win32 linking executables
  1056. }