scandir.pas 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  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. uses
  21. globtype;
  22. const
  23. switchesstatestackmax = 20;
  24. type
  25. tsavedswitchesstate = record
  26. localsw: tlocalswitches;
  27. verbosity: longint;
  28. pmessage : pmessagestaterecord;
  29. end;
  30. type
  31. tswitchesstatestack = array[0..switchesstatestackmax] of tsavedswitchesstate;
  32. var
  33. switchesstatestack:tswitchesstatestack;
  34. switchesstatestackpos: Integer;
  35. procedure InitScannerDirectives;
  36. implementation
  37. uses
  38. SysUtils,
  39. cutils,cfileutl,
  40. globals,systems,widestr,cpuinfo,
  41. verbose,comphook,ppu,
  42. scanner,switches,
  43. fmodule,
  44. defutil,
  45. dirparse,link,
  46. symconst,symtable,symbase,symtype,symsym,
  47. rabase;
  48. {*****************************************************************************
  49. Helpers
  50. *****************************************************************************}
  51. procedure do_delphiswitch(sw:char);
  52. var
  53. state : char;
  54. begin
  55. { c contains the next char, a + or - would be fine }
  56. state:=current_scanner.readstate;
  57. if state in ['-','+'] then
  58. HandleSwitch(sw,state);
  59. end;
  60. procedure do_setverbose(flag:char);
  61. var
  62. state : char;
  63. begin
  64. { support ON/OFF }
  65. state:=current_scanner.ReadState;
  66. recordpendingverbosityswitch(flag,state);
  67. end;
  68. procedure do_moduleswitch(sw:tmoduleswitch);
  69. var
  70. state : char;
  71. begin
  72. state:=current_scanner.readstate;
  73. if (sw<>cs_modulenone) and (state in ['-','+']) then
  74. begin
  75. if state='-' then
  76. exclude(current_settings.moduleswitches,sw)
  77. else
  78. include(current_settings.moduleswitches,sw);
  79. end;
  80. end;
  81. procedure do_localswitch(sw:tlocalswitch);
  82. var
  83. state : char;
  84. begin
  85. state:=current_scanner.readstate;
  86. if (sw<>cs_localnone) and (state in ['-','+']) then
  87. recordpendinglocalswitch(sw,state);
  88. end;
  89. function do_localswitchdefault(sw:tlocalswitch): char;
  90. begin
  91. result:=current_scanner.readstatedefault;
  92. if (sw<>cs_localnone) and (result in ['-','+','*']) then
  93. recordpendinglocalswitch(sw,result);
  94. end;
  95. procedure do_message(w:integer);
  96. begin
  97. current_scanner.skipspace;
  98. Message1(w,current_scanner.readcomment);
  99. end;
  100. {*****************************************************************************
  101. Directive Callbacks
  102. *****************************************************************************}
  103. procedure dir_align;
  104. var
  105. hs : string;
  106. b : byte;
  107. begin
  108. current_scanner.skipspace;
  109. if not(c in ['0'..'9']) then
  110. begin
  111. { Support also the ON and OFF as switch }
  112. hs:=current_scanner.readid;
  113. if (hs='ON') then
  114. current_settings.packrecords:=4
  115. else if (hs='OFF') then
  116. current_settings.packrecords:=1
  117. else if m_mac in current_settings.modeswitches then
  118. begin
  119. { Support switches used in Apples Universal Interfaces}
  120. if (hs='MAC68K') then
  121. current_settings.packrecords:=mac68k_alignment
  122. { "power" alignment is the default C packrecords setting on
  123. Mac OS X }
  124. else if (hs='POWER') or (hs='POWERPC') then
  125. current_settings.packrecords:=C_alignment
  126. else if (hs='RESET') then
  127. current_settings.packrecords:=default_settings.packrecords
  128. else
  129. Message1(scan_e_illegal_pack_records,hs);
  130. end
  131. else
  132. Message1(scan_e_illegal_pack_records,hs);
  133. end
  134. else
  135. begin
  136. b:=current_scanner.readval;
  137. case b of
  138. 1 : current_settings.packrecords:=1;
  139. 2 : current_settings.packrecords:=2;
  140. 4 : current_settings.packrecords:=4;
  141. 8 : current_settings.packrecords:=8;
  142. 16 : current_settings.packrecords:=16;
  143. 32 : current_settings.packrecords:=32;
  144. else
  145. Message1(scan_e_illegal_pack_records,tostr(b));
  146. end;
  147. end;
  148. end;
  149. procedure dir_a1;
  150. begin
  151. current_settings.packrecords:=1;
  152. end;
  153. procedure dir_a2;
  154. begin
  155. current_settings.packrecords:=2;
  156. end;
  157. procedure dir_a4;
  158. begin
  159. current_settings.packrecords:=4;
  160. end;
  161. procedure dir_a8;
  162. begin
  163. current_settings.packrecords:=8;
  164. end;
  165. procedure dir_asmcpu;
  166. var
  167. s : string;
  168. cpu: tcputype;
  169. found: Boolean;
  170. begin
  171. current_scanner.skipspace;
  172. s:=current_scanner.readid;
  173. If Inside_asm_statement then
  174. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  175. if s='ANY' then
  176. current_settings.asmcputype:=cpu_none
  177. else if s='CURRENT' then
  178. current_settings.asmcputype:=current_settings.cputype
  179. else
  180. begin
  181. found:=false;
  182. for cpu:=succ(low(tcputype)) to high(tcputype) do
  183. if s=cputypestr[cpu] then
  184. begin
  185. found:=true;
  186. current_settings.asmcputype:=cpu;
  187. break;
  188. end;
  189. if not found then
  190. Message1(scan_e_illegal_asmcpu_specifier,s);
  191. end;
  192. end;
  193. procedure dir_asmmode;
  194. var
  195. s : string;
  196. begin
  197. current_scanner.skipspace;
  198. s:=current_scanner.readid;
  199. If Inside_asm_statement then
  200. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  201. if s='DEFAULT' then
  202. current_settings.asmmode:=init_settings.asmmode
  203. else
  204. if not SetAsmReadMode(s,current_settings.asmmode) then
  205. Message1(scan_e_illegal_asmmode_specifier,s);
  206. end;
  207. {$if defined(m68k) or defined(arm)}
  208. procedure dir_appid;
  209. begin
  210. if target_info.system<>system_m68k_palmos then
  211. Message(scan_w_appid_not_support);
  212. { change description global var in all cases }
  213. { it not used but in win32 and os2 }
  214. current_scanner.skipspace;
  215. palmos_applicationid:=current_scanner.readcomment;
  216. end;
  217. procedure dir_appname;
  218. begin
  219. if target_info.system<>system_m68k_palmos then
  220. Message(scan_w_appname_not_support);
  221. { change description global var in all cases }
  222. { it not used but in win32 and os2 }
  223. current_scanner.skipspace;
  224. palmos_applicationname:=current_scanner.readcomment;
  225. end;
  226. {$endif defined(m68k) or defined(arm)}
  227. procedure dir_apptype;
  228. var
  229. hs : string;
  230. begin
  231. if not (target_info.system in systems_all_windows + [system_i386_os2,
  232. system_i386_emx, system_powerpc_macos,
  233. system_arm_nds, system_i8086_msdos] +
  234. systems_nativent) then
  235. begin
  236. if m_delphi in current_settings.modeswitches then
  237. Message(scan_n_app_type_not_support)
  238. else
  239. Message(scan_w_app_type_not_support);
  240. end
  241. else
  242. begin
  243. if not current_module.in_global then
  244. Message(scan_w_switch_is_global)
  245. else
  246. begin
  247. current_scanner.skipspace;
  248. hs:=current_scanner.readid;
  249. if (hs='GUI') and not (target_info.system in [system_i8086_msdos]) then
  250. SetApptype(app_gui)
  251. else if (hs='CONSOLE') and not (target_info.system in [system_i8086_msdos]) then
  252. SetApptype(app_cui)
  253. else if (hs='NATIVE') and (target_info.system in systems_windows + systems_nativent) then
  254. SetApptype(app_native)
  255. else if (hs='FS') and (target_info.system in [system_i386_os2,
  256. system_i386_emx]) then
  257. SetApptype(app_fs)
  258. else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
  259. SetApptype(app_tool)
  260. else if (hs='ARM9') and (target_info.system in [system_arm_nds]) then
  261. SetApptype(app_arm9)
  262. else if (hs='ARM7') and (target_info.system in [system_arm_nds]) then
  263. SetApptype(app_arm7)
  264. else if (hs='COM') and (target_info.system in [system_i8086_msdos]) then
  265. SetApptype(app_com)
  266. else if (hs='EXE') and (target_info.system in [system_i8086_msdos]) then
  267. SetApptype(app_cui)
  268. else
  269. Message1(scan_w_unsupported_app_type,hs);
  270. end;
  271. end;
  272. end;
  273. procedure dir_calling;
  274. var
  275. hs : string;
  276. begin
  277. current_scanner.skipspace;
  278. hs:=current_scanner.readid;
  279. if (hs='') then
  280. Message(parser_e_proc_directive_expected)
  281. else
  282. recordpendingcallingswitch(hs);
  283. end;
  284. procedure dir_checklowaddrloads;
  285. begin
  286. do_localswitchdefault(cs_check_low_addr_load);
  287. end;
  288. procedure dir_checkpointer;
  289. var
  290. switch: char;
  291. begin
  292. switch:=do_localswitchdefault(cs_checkpointer);
  293. if (switch='+') and
  294. not(target_info.system in systems_support_checkpointer) then
  295. Message1(scan_e_unsupported_switch,'CHECKPOINTER+');
  296. end;
  297. procedure dir_objectchecks;
  298. begin
  299. do_localswitch(cs_check_object);
  300. end;
  301. procedure dir_ieeeerrors;
  302. begin
  303. do_localswitch(cs_ieee_errors);
  304. end;
  305. procedure dir_assertions;
  306. begin
  307. do_delphiswitch('C');
  308. end;
  309. procedure dir_booleval;
  310. begin
  311. do_delphiswitch('B');
  312. end;
  313. procedure dir_debuginfo;
  314. begin
  315. do_delphiswitch('D');
  316. end;
  317. procedure dir_description;
  318. begin
  319. if not (target_info.system in systems_all_windows+[system_i386_os2,system_i386_emx,
  320. system_i386_netware,system_i386_wdosx,system_i386_netwlibc]) then
  321. Message(scan_w_description_not_support);
  322. { change description global var in all cases }
  323. { it not used but in win32, os2 and netware }
  324. current_scanner.skipspace;
  325. description:=current_scanner.readcomment;
  326. DescriptionSetExplicity:=true;
  327. end;
  328. procedure dir_screenname; {ad}
  329. begin
  330. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  331. {Message(scan_w_decription_not_support);}
  332. comment (V_Warning,'Screenname only supported for target netware');
  333. current_scanner.skipspace;
  334. nwscreenname:=current_scanner.readcomment;
  335. end;
  336. procedure dir_threadname; {ad}
  337. begin
  338. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  339. {Message(scan_w_decription_not_support);}
  340. comment (V_Warning,'Threadname only supported for target netware');
  341. current_scanner.skipspace;
  342. nwthreadname:=current_scanner.readcomment;
  343. end;
  344. procedure dir_copyright; {ad}
  345. begin
  346. if not (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  347. {Message(scan_w_decription_not_support);}
  348. comment (V_Warning,'Copyright only supported for target netware');
  349. current_scanner.skipspace;
  350. nwcopyright:=current_scanner.readcomment;
  351. end;
  352. procedure dir_error;
  353. begin
  354. do_message(scan_e_user_defined);
  355. end;
  356. procedure dir_extendedsyntax;
  357. begin
  358. do_delphiswitch('X');
  359. end;
  360. procedure dir_forcefarcalls;
  361. begin
  362. if (target_info.system<>system_i8086_msdos)
  363. {$ifdef i8086}
  364. or (current_settings.x86memorymodel in x86_near_code_models)
  365. {$endif i8086}
  366. then
  367. begin
  368. Message1(scan_n_ignored_switch,pattern);
  369. exit;
  370. end;
  371. do_localswitch(cs_force_far_calls);
  372. end;
  373. procedure dir_fatal;
  374. begin
  375. do_message(scan_f_user_defined);
  376. end;
  377. procedure dir_fputype;
  378. begin
  379. current_scanner.skipspace;
  380. undef_system_macro('FPU'+fputypestr[current_settings.fputype]);
  381. if not(SetFPUType(upper(current_scanner.readcomment),current_settings.fputype)) then
  382. comment(V_Error,'Illegal FPU type');
  383. def_system_macro('FPU'+fputypestr[current_settings.fputype]);
  384. end;
  385. procedure dir_frameworkpath;
  386. begin
  387. if not current_module.in_global then
  388. Message(scan_w_switch_is_global)
  389. else if not(target_info.system in systems_darwin) then
  390. begin
  391. Message(scan_w_frameworks_darwin_only);
  392. current_scanner.skipspace;
  393. current_scanner.readcomment
  394. end
  395. else
  396. begin
  397. current_scanner.skipspace;
  398. current_module.localframeworksearchpath.AddPath(current_scanner.readcomment,false);
  399. end;
  400. end;
  401. procedure dir_goto;
  402. begin
  403. do_moduleswitch(cs_support_goto);
  404. end;
  405. procedure dir_hint;
  406. begin
  407. do_message(scan_h_user_defined);
  408. end;
  409. procedure dir_hints;
  410. begin
  411. do_setverbose('H');
  412. end;
  413. procedure dir_imagebase;
  414. begin
  415. if not (target_info.system in (systems_windows+systems_wince)) then
  416. Message(scan_w_imagebase_not_support);
  417. current_scanner.skipspace;
  418. imagebase:=current_scanner.readval;
  419. ImageBaseSetExplicity:=true
  420. end;
  421. procedure dir_implicitexceptions;
  422. begin
  423. do_moduleswitch(cs_implicit_exceptions);
  424. end;
  425. procedure dir_importeddata;
  426. begin
  427. do_delphiswitch('G');
  428. end;
  429. procedure dir_includepath;
  430. begin
  431. if not current_module.in_global then
  432. Message(scan_w_switch_is_global)
  433. else
  434. begin
  435. current_scanner.skipspace;
  436. current_module.localincludesearchpath.AddPath(current_scanner.readcomment,false);
  437. end;
  438. end;
  439. procedure dir_info;
  440. begin
  441. do_message(scan_i_user_defined);
  442. end;
  443. procedure dir_inline;
  444. begin
  445. do_localswitch(cs_do_inline);
  446. end;
  447. procedure dir_interfaces;
  448. var
  449. hs : string;
  450. begin
  451. {corba/com/default}
  452. current_scanner.skipspace;
  453. hs:=current_scanner.readid;
  454. {$ifndef jvm}
  455. if (hs='CORBA') then
  456. current_settings.interfacetype:=it_interfacecorba
  457. else if (hs='COM') then
  458. current_settings.interfacetype:=it_interfacecom
  459. else
  460. {$endif jvm}
  461. if (hs='DEFAULT') then
  462. current_settings.interfacetype:=init_settings.interfacetype
  463. else
  464. Message(scan_e_invalid_interface_type);
  465. end;
  466. procedure dir_iochecks;
  467. begin
  468. do_delphiswitch('I');
  469. end;
  470. procedure dir_libexport;
  471. begin
  472. {not implemented}
  473. end;
  474. procedure dir_librarypath;
  475. begin
  476. if not current_module.in_global then
  477. Message(scan_w_switch_is_global)
  478. else
  479. begin
  480. current_scanner.skipspace;
  481. current_module.locallibrarysearchpath.AddPath(current_scanner.readcomment,false);
  482. end;
  483. end;
  484. procedure dir_link;
  485. var
  486. s : string;
  487. begin
  488. current_scanner.skipspace;
  489. if scanner.c = '''' then
  490. begin
  491. s:= current_scanner.readquotedstring;
  492. current_scanner.readcomment
  493. end
  494. else
  495. s:= trimspace(current_scanner.readcomment);
  496. s:=FixFileName(s);
  497. if ExtractFileExt(s)='' then
  498. s:=ChangeFileExt(s,target_info.objext);
  499. current_module.linkotherofiles.add(s,link_always);
  500. end;
  501. procedure dir_linkframework;
  502. var
  503. s : string;
  504. begin
  505. current_scanner.skipspace;
  506. if scanner.c = '''' then
  507. begin
  508. s:= current_scanner.readquotedstring;
  509. current_scanner.readcomment
  510. end
  511. else
  512. s:= trimspace(current_scanner.readcomment);
  513. s:=FixFileName(s);
  514. if (target_info.system in systems_darwin) then
  515. current_module.linkotherframeworks.add(s,link_always)
  516. else
  517. Message(scan_w_frameworks_darwin_only);
  518. end;
  519. procedure dir_linklib;
  520. type
  521. tLinkMode=(lm_shared,lm_static);
  522. var
  523. s : string;
  524. quote : char;
  525. libext,
  526. libname,
  527. linkmodestr : string;
  528. p : longint;
  529. linkMode : tLinkMode;
  530. begin
  531. current_scanner.skipspace;
  532. if scanner.c = '''' then
  533. begin
  534. libname:= current_scanner.readquotedstring;
  535. s:= current_scanner.readcomment;
  536. p:=pos(',',s);
  537. end
  538. else
  539. begin
  540. s:= current_scanner.readcomment;
  541. p:=pos(',',s);
  542. if p=0 then
  543. libname:=TrimSpace(s)
  544. else
  545. libname:=TrimSpace(copy(s,1,p-1));
  546. end;
  547. if p=0 then
  548. linkmodeStr:=''
  549. else
  550. linkmodeStr:=Upper(TrimSpace(copy(s,p+1,255)));
  551. if (libname='') or (libname='''''') or (libname='""') then
  552. exit;
  553. { create library name }
  554. if libname[1] in ['''','"'] then
  555. begin
  556. quote:=libname[1];
  557. Delete(libname,1,1);
  558. p:=pos(quote,libname);
  559. if p>0 then
  560. Delete(libname,p,1);
  561. end;
  562. libname:=FixFileName(libname);
  563. { get linkmode, default is to check the extension for
  564. the static library, otherwise shared linking is assumed }
  565. linkmode:=lm_shared;
  566. if linkModeStr='' then
  567. begin
  568. libext:=ExtractFileExt(libname);
  569. if libext=target_info.staticClibext then
  570. linkMode:=lm_static;
  571. end
  572. else if linkModeStr='STATIC' then
  573. linkmode:=lm_static
  574. else if (LinkModeStr='SHARED') or (LinkModeStr='') then
  575. linkmode:=lm_shared
  576. else
  577. Comment(V_Error,'Wrong link mode specified: "'+Linkmodestr+'"');
  578. { add to the list of other libraries }
  579. if linkMode=lm_static then
  580. current_module.linkOtherStaticLibs.add(libname,link_always)
  581. else
  582. current_module.linkOtherSharedLibs.add(libname,link_always);
  583. end;
  584. procedure dir_localsymbols;
  585. begin
  586. do_delphiswitch('L');
  587. end;
  588. procedure dir_longstrings;
  589. begin
  590. do_delphiswitch('H');
  591. end;
  592. procedure dir_macro;
  593. begin
  594. do_moduleswitch(cs_support_macro);
  595. end;
  596. procedure dir_pascalmainname;
  597. var
  598. s: string;
  599. begin
  600. current_scanner.skipspace;
  601. s:=trimspace(current_scanner.readcomment);
  602. if assigned(current_module.mainname) and
  603. (s<>current_module.mainname^) then
  604. begin
  605. Message1(scan_w_multiple_main_name_overrides,current_module.mainname^);
  606. stringdispose(current_module.mainname)
  607. end
  608. else if (mainaliasname<>defaultmainaliasname) and
  609. (mainaliasname<>s) then
  610. Message1(scan_w_multiple_main_name_overrides,mainaliasname);
  611. mainaliasname:=s;
  612. if (mainaliasname<>defaultmainaliasname) then
  613. current_module.mainname:=stringdup(mainaliasname);
  614. end;
  615. procedure dir_maxfpuregisters;
  616. var
  617. l : integer;
  618. hs : string;
  619. begin
  620. current_scanner.skipspace;
  621. if not(c in ['0'..'9']) then
  622. begin
  623. hs:=current_scanner.readid;
  624. if (hs='NORMAL') or (hs='DEFAULT') then
  625. current_settings.maxfpuregisters:=-1
  626. else
  627. Message(scan_e_invalid_maxfpureg_value);
  628. end
  629. else
  630. begin
  631. l:=current_scanner.readval;
  632. case l of
  633. 0..8:
  634. current_settings.maxfpuregisters:=l;
  635. else
  636. Message(scan_e_invalid_maxfpureg_value);
  637. end;
  638. end;
  639. end;
  640. procedure dir_maxstacksize;
  641. begin
  642. if not (target_info.system in (systems_windows+systems_wince)) then
  643. Message(scan_w_maxstacksize_not_support);
  644. current_scanner.skipspace;
  645. maxstacksize:=current_scanner.readval;
  646. MaxStackSizeSetExplicity:=true;
  647. end;
  648. procedure dir_memory;
  649. var
  650. l : longint;
  651. heapsize_limit: longint;
  652. maxheapsize_limit: longint;
  653. begin
  654. {$if defined(i8086)}
  655. if current_settings.x86memorymodel in x86_far_data_models then
  656. begin
  657. heapsize_limit:=655360;
  658. maxheapsize_limit:=655360;
  659. end
  660. else
  661. begin
  662. heapsize_limit:=65520;
  663. maxheapsize_limit:=65520;
  664. end;
  665. {$elseif defined(cpu16bitaddr)}
  666. heapsize_limit:=65520;
  667. maxheapsize_limit:=65520;
  668. {$else}
  669. heapsize_limit:=high(heapsize);
  670. maxheapsize_limit:=high(maxheapsize);
  671. {$endif}
  672. current_scanner.skipspace;
  673. l:=current_scanner.readval;
  674. if (l>=1024)
  675. {$ifdef cpu16bitaddr}
  676. and (l<=65521) { TP7's $M directive allows specifying a stack size of
  677. 65521, but it actually sets the stack size to 65520 }
  678. {$else cpu16bitaddr}
  679. and (l<67107840)
  680. {$endif cpu16bitaddr}
  681. then
  682. stacksize:=min(l,{$ifdef cpu16bitaddr}65520{$else}67107839{$endif})
  683. else
  684. Message(scan_w_invalid_stacksize);
  685. if c=',' then
  686. begin
  687. current_scanner.readchar;
  688. current_scanner.skipspace;
  689. l:=current_scanner.readval;
  690. if l>=1024 then
  691. heapsize:=min(l,heapsize_limit);
  692. if c=',' then
  693. begin
  694. current_scanner.readchar;
  695. current_scanner.skipspace;
  696. l:=current_scanner.readval;
  697. if l>=heapsize then
  698. maxheapsize:=min(l,maxheapsize_limit)
  699. else
  700. Message(scan_w_heapmax_lessthan_heapmin);
  701. end;
  702. end;
  703. end;
  704. procedure dir_message;
  705. var
  706. hs : string;
  707. w : longint;
  708. begin
  709. w:=0;
  710. current_scanner.skipspace;
  711. { Message level specified? }
  712. if c='''' then
  713. w:=scan_n_user_defined
  714. else
  715. begin
  716. hs:=current_scanner.readid;
  717. if (hs='WARN') or (hs='WARNING') then
  718. w:=scan_w_user_defined
  719. else
  720. if (hs='ERROR') then
  721. w:=scan_e_user_defined
  722. else
  723. if (hs='FATAL') then
  724. w:=scan_f_user_defined
  725. else
  726. if (hs='HINT') then
  727. w:=scan_h_user_defined
  728. else
  729. if (hs='NOTE') then
  730. w:=scan_n_user_defined
  731. else
  732. Message1(scan_w_illegal_directive,hs);
  733. end;
  734. { Only print message when there was no error }
  735. if w<>0 then
  736. begin
  737. current_scanner.skipspace;
  738. if c='''' then
  739. hs:=current_scanner.readquotedstring
  740. else
  741. hs:=current_scanner.readcomment;
  742. Message1(w,hs);
  743. end
  744. else
  745. current_scanner.readcomment;
  746. end;
  747. procedure dir_minstacksize;
  748. begin
  749. if not (target_info.system in (systems_windows+systems_wince)) then
  750. Message(scan_w_minstacksize_not_support);
  751. current_scanner.skipspace;
  752. minstacksize:=current_scanner.readval;
  753. MinStackSizeSetExplicity:=true;
  754. end;
  755. procedure dir_mode;
  756. begin
  757. if not current_module.in_global then
  758. Message(scan_w_switch_is_global)
  759. else
  760. begin
  761. current_scanner.skipspace;
  762. current_scanner.readstring;
  763. if not current_module.mode_switch_allowed and
  764. not ((m_mac in current_settings.modeswitches) and (pattern='MACPAS')) then
  765. Message1(scan_e_mode_switch_not_allowed,pattern)
  766. else if not SetCompileMode(pattern,false) then
  767. Message1(scan_w_illegal_switch,pattern)
  768. end;
  769. current_module.mode_switch_allowed:= false;
  770. end;
  771. procedure dir_modeswitch;
  772. var
  773. s : string;
  774. begin
  775. if not current_module.in_global then
  776. Message(scan_w_switch_is_global)
  777. else
  778. begin
  779. current_scanner.skipspace;
  780. current_scanner.readstring;
  781. s:=pattern;
  782. if c in ['+','-'] then
  783. s:=s+current_scanner.readstate;
  784. if not SetCompileModeSwitch(s,false) then
  785. Message1(scan_w_illegal_switch,s)
  786. end;
  787. end;
  788. procedure dir_namespace;
  789. var
  790. s : string;
  791. begin
  792. { used to define Java package names for all types declared in the
  793. current unit }
  794. if not current_module.in_global then
  795. Message(scan_w_switch_is_global)
  796. else
  797. begin
  798. current_scanner.skipspace;
  799. current_scanner.readstring;
  800. s:=orgpattern;
  801. while c='.' do
  802. begin
  803. current_scanner.readchar;
  804. current_scanner.readstring;
  805. s:=s+'.'+orgpattern;
  806. end;
  807. disposestr(current_module.namespace);
  808. current_module.namespace:=stringdup(s);
  809. end;
  810. end;
  811. procedure dir_mmx;
  812. begin
  813. do_localswitch(cs_mmx);
  814. end;
  815. procedure dir_note;
  816. begin
  817. do_message(scan_n_user_defined);
  818. end;
  819. procedure dir_notes;
  820. begin
  821. do_setverbose('N');
  822. end;
  823. procedure dir_objectpath;
  824. begin
  825. if not current_module.in_global then
  826. Message(scan_w_switch_is_global)
  827. else
  828. begin
  829. current_scanner.skipspace;
  830. current_module.localobjectsearchpath.AddPath(current_scanner.readcomment,false);
  831. end;
  832. end;
  833. procedure dir_openstrings;
  834. begin
  835. do_delphiswitch('P');
  836. end;
  837. procedure dir_optimization;
  838. var
  839. hs : string;
  840. begin
  841. current_scanner.skipspace;
  842. { Support also the ON and OFF as switch }
  843. hs:=current_scanner.readid;
  844. if (hs='ON') then
  845. current_settings.optimizerswitches:=level2optimizerswitches
  846. else if (hs='OFF') then
  847. current_settings.optimizerswitches:=[]
  848. else if (hs='DEFAULT') then
  849. current_settings.optimizerswitches:=init_settings.optimizerswitches
  850. else
  851. begin
  852. if not UpdateOptimizerStr(hs,current_settings.optimizerswitches) then
  853. Message1(scan_e_illegal_optimization_specifier,hs);
  854. end;
  855. end;
  856. procedure dir_overflowchecks;
  857. begin
  858. do_delphiswitch('Q');
  859. end;
  860. procedure dir_packenum;
  861. var
  862. hs : string;
  863. begin
  864. current_scanner.skipspace;
  865. if not(c in ['0'..'9']) then
  866. begin
  867. hs:=current_scanner.readid;
  868. if (hs='NORMAL') or (hs='DEFAULT') then
  869. current_settings.packenum:=4
  870. else
  871. Message1(scan_e_illegal_pack_enum, hs);
  872. end
  873. else
  874. begin
  875. case current_scanner.readval of
  876. 1 : current_settings.packenum:=1;
  877. 2 : current_settings.packenum:=2;
  878. 4 : current_settings.packenum:=4;
  879. else
  880. Message1(scan_e_illegal_pack_enum, pattern);
  881. end;
  882. end;
  883. end;
  884. procedure dir_minfpconstprec;
  885. begin
  886. current_scanner.skipspace;
  887. if not SetMinFPConstPrec(current_scanner.readid,current_settings.minfpconstprec) then
  888. Message1(scan_e_illegal_minfpconstprec, pattern);
  889. end;
  890. procedure dir_packrecords;
  891. var
  892. hs : string;
  893. begin
  894. { can't change packrecords setting on managed vm targets }
  895. if target_info.system in systems_managed_vm then
  896. Message1(scanner_w_directive_ignored_on_target, 'PACKRECORDS');
  897. current_scanner.skipspace;
  898. if not(c in ['0'..'9']) then
  899. begin
  900. hs:=current_scanner.readid;
  901. { C has the special recordalignmax of C_alignment }
  902. if (hs='C') then
  903. current_settings.packrecords:=C_alignment
  904. else
  905. if (hs='NORMAL') or (hs='DEFAULT') then
  906. current_settings.packrecords:=default_settings.packrecords
  907. else
  908. Message1(scan_e_illegal_pack_records,hs);
  909. end
  910. else
  911. begin
  912. case current_scanner.readval of
  913. 1 : current_settings.packrecords:=1;
  914. 2 : current_settings.packrecords:=2;
  915. 4 : current_settings.packrecords:=4;
  916. 8 : current_settings.packrecords:=8;
  917. 16 : current_settings.packrecords:=16;
  918. 32 : current_settings.packrecords:=32;
  919. else
  920. Message1(scan_e_illegal_pack_records,pattern);
  921. end;
  922. end;
  923. end;
  924. procedure dir_packset;
  925. var
  926. hs : string;
  927. begin
  928. current_scanner.skipspace;
  929. if not(c in ['1','2','4','8']) then
  930. begin
  931. hs:=current_scanner.readid;
  932. if (hs='FIXED') or (hs='DEFAULT') OR (hs='NORMAL') then
  933. current_settings.setalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  934. else
  935. Message(scan_e_only_packset);
  936. end
  937. else
  938. begin
  939. case current_scanner.readval of
  940. 1 : current_settings.setalloc:=1;
  941. 2 : current_settings.setalloc:=2;
  942. 4 : current_settings.setalloc:=4;
  943. 8 : current_settings.setalloc:=8;
  944. else
  945. Message(scan_e_only_packset);
  946. end;
  947. end;
  948. end;
  949. procedure dir_pic;
  950. begin
  951. { windows doesn't need/support pic }
  952. if tf_no_pic_supported in target_info.flags then
  953. message(scan_w_pic_ignored)
  954. else
  955. do_moduleswitch(cs_create_pic);
  956. end;
  957. procedure dir_pop;
  958. begin
  959. if switchesstatestackpos < 1 then
  960. Message(scan_e_too_many_pop);
  961. Dec(switchesstatestackpos);
  962. recordpendinglocalfullswitch(switchesstatestack[switchesstatestackpos].localsw);
  963. recordpendingverbosityfullswitch(switchesstatestack[switchesstatestackpos].verbosity);
  964. pendingstate.nextmessagerecord:=switchesstatestack[switchesstatestackpos].pmessage;
  965. { Reset verbosity and forget previous pmeesage }
  966. RestoreLocalVerbosity(nil);
  967. current_settings.pmessage:=nil;
  968. { Do not yet activate these changes, as otherwise
  969. you get problem idf you put a $pop just right after
  970. a addition for instance fro which you explicitly truned the overflow check
  971. out by using $Q- after a $push PM 2012-08-29 }
  972. // flushpendingswitchesstate;
  973. end;
  974. procedure dir_pointermath;
  975. begin
  976. do_localswitch(cs_pointermath);
  977. end;
  978. procedure dir_profile;
  979. begin
  980. do_moduleswitch(cs_profile);
  981. { defined/undefine FPC_PROFILE }
  982. if cs_profile in current_settings.moduleswitches then
  983. def_system_macro('FPC_PROFILE')
  984. else
  985. undef_system_macro('FPC_PROFILE');
  986. end;
  987. procedure dir_push;
  988. begin
  989. if switchesstatestackpos > switchesstatestackmax then
  990. Message(scan_e_too_many_push);
  991. flushpendingswitchesstate;
  992. switchesstatestack[switchesstatestackpos].localsw:= current_settings.localswitches;
  993. switchesstatestack[switchesstatestackpos].pmessage:= current_settings.pmessage;
  994. switchesstatestack[switchesstatestackpos].verbosity:=status.verbosity;
  995. Inc(switchesstatestackpos);
  996. end;
  997. procedure dir_rangechecks;
  998. begin
  999. do_delphiswitch('R');
  1000. end;
  1001. procedure dir_referenceinfo;
  1002. begin
  1003. do_delphiswitch('Y');
  1004. end;
  1005. procedure dir_resource;
  1006. var
  1007. s : string;
  1008. begin
  1009. current_scanner.skipspace;
  1010. if scanner.c = '''' then
  1011. begin
  1012. s:= current_scanner.readquotedstring;
  1013. current_scanner.readcomment
  1014. end
  1015. else
  1016. s:= trimspace(current_scanner.readcomment);
  1017. { replace * with the name of the main source.
  1018. This should always be defined. }
  1019. if s[1]='*' then
  1020. if Assigned(Current_Module) then
  1021. begin
  1022. delete(S,1,1);
  1023. insert(ChangeFileExt(ExtractFileName(current_module.mainsource),''),S,1 );
  1024. end;
  1025. s:=FixFileName(s);
  1026. if ExtractFileExt(s)='' then
  1027. s:=ChangeFileExt(s,target_info.resext);
  1028. if target_info.res<>res_none then
  1029. begin
  1030. current_module.flags:=current_module.flags or uf_has_resourcefiles;
  1031. if (res_single_file in target_res.resflags) and
  1032. not (Current_module.ResourceFiles.Empty) then
  1033. Message(scan_w_only_one_resourcefile_supported)
  1034. else
  1035. current_module.resourcefiles.insert(FixFileName(s));
  1036. end
  1037. else
  1038. Message(scan_e_resourcefiles_not_supported);
  1039. end;
  1040. procedure dir_saturation;
  1041. begin
  1042. do_localswitch(cs_mmx_saturation);
  1043. end;
  1044. procedure dir_safefpuexceptions;
  1045. begin
  1046. do_localswitch(cs_fpu_fwait);
  1047. end;
  1048. procedure dir_scopedenums;
  1049. begin
  1050. do_localswitch(cs_scopedenums);
  1051. end;
  1052. function get_peflag_const(const ident:string;error:longint):longint;
  1053. var
  1054. srsym : tsym;
  1055. srsymtable : tsymtable;
  1056. begin
  1057. result:=0;
  1058. if searchsym(ident,srsym,srsymtable) then
  1059. if (srsym.typ=constsym) and
  1060. (tconstsym(srsym).consttyp=constord) and
  1061. is_integer(tconstsym(srsym).constdef) then
  1062. with tconstsym(srsym).value.valueord do
  1063. if signed then
  1064. result:=tconstsym(srsym).value.valueord.svalue
  1065. else
  1066. result:=tconstsym(srsym).value.valueord.uvalue
  1067. else
  1068. message(error)
  1069. else
  1070. message1(sym_e_id_not_found,ident);
  1071. end;
  1072. procedure dir_setpeflags;
  1073. var
  1074. ident : string;
  1075. begin
  1076. if not (target_info.system in (systems_all_windows)) then
  1077. Message(scan_w_setpeflags_not_support);
  1078. current_scanner.skipspace;
  1079. ident:=current_scanner.readid;
  1080. if ident<>'' then
  1081. peflags:=peflags or get_peflag_const(ident,scan_e_illegal_peflag)
  1082. else
  1083. peflags:=peflags or current_scanner.readval;
  1084. SetPEFlagsSetExplicity:=true;
  1085. end;
  1086. procedure dir_setpeoptflags;
  1087. var
  1088. ident : string;
  1089. begin
  1090. if not (target_info.system in (systems_all_windows)) then
  1091. Message(scan_w_setpeoptflags_not_support);
  1092. current_scanner.skipspace;
  1093. ident:=current_scanner.readid;
  1094. if ident<>'' then
  1095. peoptflags:=peoptflags or get_peflag_const(ident,scan_e_illegal_peoptflag)
  1096. else
  1097. peoptflags:=peoptflags or current_scanner.readval;
  1098. SetPEOptFlagsSetExplicity:=true;
  1099. end;
  1100. procedure dir_smartlink;
  1101. begin
  1102. do_moduleswitch(cs_create_smart);
  1103. if (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
  1104. not(target_info.system in (systems_darwin+[system_i8086_msdos])) and
  1105. { smart linking does not yet work with DWARF debug info on most targets }
  1106. (cs_create_smart in current_settings.moduleswitches) and
  1107. not (af_outputbinary in target_asm.flags) then
  1108. begin
  1109. Message(option_dwarf_smart_linking);
  1110. Exclude(current_settings.moduleswitches,cs_create_smart);
  1111. end;
  1112. { Also create a smartlinked version, on an assembler that
  1113. does not support smartlink sections like nasm?
  1114. This is not compatible with using internal linker. }
  1115. if ((cs_link_smart in current_settings.globalswitches) or
  1116. (cs_create_smart in current_settings.moduleswitches)) and
  1117. (af_needar in target_asm.flags) and
  1118. not (af_smartlink_sections in target_asm.flags) and
  1119. not (cs_link_extern in current_settings.globalswitches) then
  1120. begin
  1121. DoneLinker;
  1122. Message(option_smart_link_requires_external_linker);
  1123. include(current_settings.globalswitches,cs_link_extern);
  1124. InitLinker;
  1125. end
  1126. end;
  1127. procedure dir_stackframes;
  1128. begin
  1129. do_delphiswitch('W');
  1130. end;
  1131. procedure dir_stop;
  1132. begin
  1133. do_message(scan_f_user_defined);
  1134. end;
  1135. procedure dir_stringchecks;
  1136. begin
  1137. // Delphi adds checks that ansistring and unicodestring are correct in
  1138. // different places. Skip it for now.
  1139. end;
  1140. {$ifdef powerpc}
  1141. procedure dir_syscall;
  1142. var
  1143. sctype : string;
  1144. begin
  1145. { not needed on amiga/m68k for now, because there's only one }
  1146. { syscall convention (legacy) (KB) }
  1147. { not needed on amiga/powerpc because there's only one }
  1148. { syscall convention (sysv) (KB) }
  1149. if not (target_info.system in [system_powerpc_morphos]) then
  1150. comment (V_Warning,'Syscall directive is useless on this target.');
  1151. current_scanner.skipspace;
  1152. sctype:=current_scanner.readid;
  1153. if (sctype='LEGACY') or (sctype='SYSV') or (sctype='SYSVBASE') or
  1154. (sctype='BASESYSV') or (sctype='R12BASE') then
  1155. syscall_convention:=sctype
  1156. else
  1157. comment (V_Warning,'Invalid Syscall directive ignored.');
  1158. end;
  1159. {$endif}
  1160. procedure dir_targetswitch;
  1161. var
  1162. name, value: string;
  1163. begin
  1164. { note: *not* recorded in the tokenstream, so not replayed for generics }
  1165. current_scanner.skipspace;
  1166. name:=current_scanner.readid;
  1167. if c='=' then
  1168. begin
  1169. current_scanner.readchar;
  1170. current_scanner.readid;
  1171. value:=orgpattern;
  1172. UpdateTargetSwitchStr(name+'='+value,current_settings.targetswitches,current_module.in_global);
  1173. end
  1174. else if c='-' then
  1175. begin
  1176. current_scanner.readchar;
  1177. UpdateTargetSwitchStr(name+'-',current_settings.targetswitches,current_module.in_global);
  1178. end
  1179. else
  1180. UpdateTargetSwitchStr(name,current_settings.targetswitches,current_module.in_global);
  1181. end;
  1182. procedure dir_typedaddress;
  1183. begin
  1184. do_delphiswitch('T');
  1185. end;
  1186. procedure dir_typeinfo;
  1187. begin
  1188. do_delphiswitch('M');
  1189. end;
  1190. procedure dir_unitpath;
  1191. begin
  1192. if not current_module.in_global then
  1193. Message(scan_w_switch_is_global)
  1194. else
  1195. with current_scanner,current_module,localunitsearchpath do
  1196. begin
  1197. skipspace;
  1198. AddPath(path,readcomment,false);
  1199. end;
  1200. end;
  1201. procedure dir_varparacopyoutcheck;
  1202. begin
  1203. if not(target_info.system in systems_jvm) then
  1204. begin
  1205. Message1(scan_w_illegal_switch,pattern);
  1206. exit;
  1207. end;
  1208. do_localswitch(cs_check_var_copyout);
  1209. end;
  1210. procedure dir_varpropsetter;
  1211. begin
  1212. do_localswitch(cs_varpropsetter);
  1213. end;
  1214. procedure dir_varstringchecks;
  1215. begin
  1216. do_delphiswitch('V');
  1217. end;
  1218. procedure dir_version;
  1219. var
  1220. major, minor, revision : longint;
  1221. error : integer;
  1222. begin
  1223. if not (target_info.system in systems_all_windows+[system_i386_os2,system_i386_emx,
  1224. system_i386_netware,system_i386_wdosx,
  1225. system_i386_netwlibc]) then
  1226. begin
  1227. Message(scan_n_version_not_support);
  1228. exit;
  1229. end;
  1230. if (compile_level<>1) then
  1231. Message(scan_n_only_exe_version)
  1232. else
  1233. begin
  1234. { change description global var in all cases }
  1235. { it not used but in win32, os2 and netware }
  1236. current_scanner.skipspace;
  1237. { we should only accept Major.Minor format for win32 and os2 }
  1238. current_scanner.readnumber;
  1239. major:=0;
  1240. minor:=0;
  1241. revision:=0;
  1242. val(pattern,major,error);
  1243. if (error<>0) or (major > high(word)) or (major < 0) then
  1244. begin
  1245. Message1(scan_w_wrong_version_ignored,pattern);
  1246. exit;
  1247. end;
  1248. if c='.' then
  1249. begin
  1250. current_scanner.readchar;
  1251. current_scanner.readnumber;
  1252. val(pattern,minor,error);
  1253. if (error<>0) or (minor > high(word)) or (minor < 0) then
  1254. begin
  1255. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  1256. exit;
  1257. end;
  1258. if (c='.') and
  1259. (target_info.system in [system_i386_netware,system_i386_netwlibc]) then
  1260. begin
  1261. current_scanner.readchar;
  1262. current_scanner.readnumber;
  1263. val(pattern,revision,error);
  1264. if (error<>0) or (revision > high(word)) or (revision < 0) then
  1265. begin
  1266. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  1267. exit;
  1268. end;
  1269. dllmajor:=word(major);
  1270. dllminor:=word(minor);
  1271. dllrevision:=word(revision);
  1272. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  1273. end
  1274. else
  1275. begin
  1276. dllmajor:=word(major);
  1277. dllminor:=word(minor);
  1278. dllversion:=tostr(major)+'.'+tostr(minor);
  1279. end;
  1280. end
  1281. else
  1282. dllversion:=tostr(major);
  1283. end;
  1284. end;
  1285. procedure dir_wait;
  1286. var
  1287. had_info : boolean;
  1288. begin
  1289. had_info:=(status.verbosity and V_Info)<>0;
  1290. { this message should allways appear !! }
  1291. status.verbosity:=status.verbosity or V_Info;
  1292. Message(scan_i_press_enter);
  1293. readln;
  1294. If not(had_info) then
  1295. status.verbosity:=status.verbosity and (not V_Info);
  1296. end;
  1297. { delphi compatible warn directive:
  1298. $warn <identifier> on
  1299. $warn <identifier> off
  1300. $warn <identifier> error
  1301. }
  1302. procedure dir_warn;
  1303. var
  1304. ident : string;
  1305. state : string;
  1306. msgstate : tmsgstate;
  1307. i : integer;
  1308. begin
  1309. current_scanner.skipspace;
  1310. ident:=current_scanner.readid;
  1311. current_scanner.skipspace;
  1312. state:=current_scanner.readid;
  1313. { support both delphi and fpc switches }
  1314. { use local ms_on/off/error tmsgstate values }
  1315. if (state='ON') or (state='+') then
  1316. msgstate:=ms_on
  1317. else
  1318. if (state='OFF') or (state='-') then
  1319. msgstate:=ms_off
  1320. else
  1321. if (state='ERROR') then
  1322. msgstate:=ms_error
  1323. else
  1324. begin
  1325. Message1(scanner_e_illegal_warn_state,state);
  1326. exit;
  1327. end;
  1328. if ident='CONSTRUCTING_ABSTRACT' then
  1329. begin
  1330. recordpendingmessagestate(type_w_instance_with_abstract, msgstate);
  1331. recordpendingmessagestate(type_w_instance_abstract_class, msgstate);
  1332. end
  1333. else
  1334. if ident='IMPLICIT_VARIANTS' then
  1335. recordpendingmessagestate(parser_w_implicit_uses_of_variants_unit, msgstate)
  1336. else
  1337. if ident='NO_RETVAL' then
  1338. recordpendingmessagestate(sym_w_function_result_not_set, msgstate)
  1339. else
  1340. if ident='SYMBOL_DEPRECATED' then
  1341. begin
  1342. recordpendingmessagestate(sym_w_deprecated_symbol, msgstate);
  1343. recordpendingmessagestate(sym_w_deprecated_symbol_with_msg, msgstate);
  1344. end
  1345. else
  1346. if ident='SYMBOL_EXPERIMENTAL' then
  1347. recordpendingmessagestate(sym_w_experimental_symbol, msgstate)
  1348. else
  1349. if ident='SYMBOL_LIBRARY' then
  1350. recordpendingmessagestate(sym_w_library_symbol, msgstate)
  1351. else
  1352. if ident='SYMBOL_PLATFORM' then
  1353. recordpendingmessagestate(sym_w_non_portable_symbol, msgstate)
  1354. else
  1355. if ident='SYMBOL_UNIMPLEMENTED' then
  1356. recordpendingmessagestate(sym_w_non_implemented_symbol, msgstate)
  1357. else
  1358. if ident='UNIT_DEPRECATED' then
  1359. begin
  1360. recordpendingmessagestate(sym_w_deprecated_unit, msgstate);
  1361. recordpendingmessagestate(sym_w_deprecated_unit_with_msg, msgstate);
  1362. end
  1363. else
  1364. if ident='UNIT_EXPERIMENTAL' then
  1365. recordpendingmessagestate(sym_w_experimental_unit, msgstate)
  1366. else
  1367. if ident='UNIT_LIBRARY' then
  1368. recordpendingmessagestate(sym_w_library_unit, msgstate)
  1369. else
  1370. if ident='UNIT_PLATFORM' then
  1371. recordpendingmessagestate(sym_w_non_portable_unit, msgstate)
  1372. else
  1373. if ident='UNIT_UNIMPLEMENTED' then
  1374. recordpendingmessagestate(sym_w_non_implemented_unit, msgstate)
  1375. else
  1376. if ident='ZERO_NIL_COMPAT' then
  1377. recordpendingmessagestate(type_w_zero_to_nil, msgstate)
  1378. else
  1379. if ident='IMPLICIT_STRING_CAST' then
  1380. recordpendingmessagestate(type_w_implicit_string_cast, msgstate)
  1381. else
  1382. if ident='IMPLICIT_STRING_CAST_LOSS' then
  1383. recordpendingmessagestate(type_w_implicit_string_cast_loss, msgstate)
  1384. else
  1385. if ident='EXPLICIT_STRING_CAST' then
  1386. recordpendingmessagestate(type_w_explicit_string_cast, msgstate)
  1387. else
  1388. if ident='EXPLICIT_STRING_CAST_LOSS' then
  1389. recordpendingmessagestate(type_w_explicit_string_cast_loss, msgstate)
  1390. else
  1391. if ident='CVT_NARROWING_STRING_LOST' then
  1392. recordpendingmessagestate(type_w_unicode_data_loss, msgstate)
  1393. else
  1394. if ident='INTF_RAISE_VISIBILITY' then
  1395. recordpendingmessagestate(type_w_interface_lower_visibility, msgstate)
  1396. else
  1397. begin
  1398. i:=0;
  1399. if not ChangeMessageVerbosity(ident,i,msgstate) then
  1400. Message1(scanner_w_illegal_warn_identifier,ident);
  1401. end;
  1402. end;
  1403. procedure dir_warning;
  1404. begin
  1405. do_message(scan_w_user_defined);
  1406. end;
  1407. procedure dir_warnings;
  1408. begin
  1409. do_setverbose('W');
  1410. end;
  1411. procedure dir_writeableconst;
  1412. begin
  1413. do_delphiswitch('J');
  1414. end;
  1415. procedure dir_z1;
  1416. begin
  1417. current_settings.packenum:=1;
  1418. end;
  1419. procedure dir_z2;
  1420. begin
  1421. current_settings.packenum:=2;
  1422. end;
  1423. procedure dir_z4;
  1424. begin
  1425. current_settings.packenum:=4;
  1426. end;
  1427. procedure dir_externalsym;
  1428. begin
  1429. end;
  1430. procedure dir_nodefine;
  1431. begin
  1432. end;
  1433. procedure dir_hppemit;
  1434. begin
  1435. end;
  1436. procedure dir_hugecode;
  1437. begin
  1438. if (target_info.system<>system_i8086_msdos)
  1439. {$ifdef i8086}
  1440. or (current_settings.x86memorymodel in x86_near_code_models)
  1441. {$endif i8086}
  1442. then
  1443. begin
  1444. Message1(scan_n_ignored_switch,pattern);
  1445. exit;
  1446. end;
  1447. do_moduleswitch(cs_huge_code);
  1448. end;
  1449. procedure dir_hugepointernormalization;
  1450. var
  1451. hs : string;
  1452. begin
  1453. if target_info.system<>system_i8086_msdos then
  1454. begin
  1455. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERNORMALIZATION');
  1456. exit;
  1457. end;
  1458. current_scanner.skipspace;
  1459. hs:=current_scanner.readid;
  1460. case hs of
  1461. 'BORLANDC':
  1462. begin
  1463. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'+');
  1464. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'+');
  1465. end;
  1466. 'MICROSOFTC':
  1467. begin
  1468. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'-');
  1469. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'-');
  1470. end;
  1471. 'WATCOMC':
  1472. begin
  1473. recordpendinglocalswitch(cs_hugeptr_arithmetic_normalization,'-');
  1474. recordpendinglocalswitch(cs_hugeptr_comparison_normalization,'+');
  1475. end;
  1476. else
  1477. Message(scan_e_illegal_hugepointernormalization);
  1478. end;
  1479. end;
  1480. procedure dir_hugepointerarithmeticnormalization;
  1481. begin
  1482. if target_info.system<>system_i8086_msdos then
  1483. begin
  1484. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERARITHMETICNORMALIZATION');
  1485. exit;
  1486. end;
  1487. do_localswitch(cs_hugeptr_arithmetic_normalization);
  1488. end;
  1489. procedure dir_hugepointercomparisonnormalization;
  1490. begin
  1491. if target_info.system<>system_i8086_msdos then
  1492. begin
  1493. Message1(scanner_w_directive_ignored_on_target, 'HUGEPOINTERCOMPARISONNORMALIZATION');
  1494. exit;
  1495. end;
  1496. do_localswitch(cs_hugeptr_comparison_normalization);
  1497. end;
  1498. procedure dir_weakpackageunit;
  1499. begin
  1500. end;
  1501. procedure dir_codealign;
  1502. var
  1503. s : string;
  1504. begin
  1505. current_scanner.skipspace;
  1506. s:=current_scanner.readcomment;
  1507. if not(UpdateAlignmentStr(s,current_settings.alignment)) then
  1508. message(scanner_e_illegal_alignment_directive);
  1509. end;
  1510. procedure dir_codepage;
  1511. var
  1512. s : string;
  1513. begin
  1514. if not current_module.in_global then
  1515. Message(scan_w_switch_is_global)
  1516. else
  1517. begin
  1518. current_scanner.skipspace;
  1519. s:=current_scanner.readcomment;
  1520. if (upper(s)='UTF8') or (upper(s)='UTF-8') then
  1521. current_settings.sourcecodepage:=CP_UTF8
  1522. else if not cpavailable(s) then
  1523. Message1(option_code_page_not_available,s)
  1524. else
  1525. current_settings.sourcecodepage:=codepagebyname(s);
  1526. { we're not using the system code page now }
  1527. exclude(current_settings.modeswitches,m_systemcodepage);
  1528. exclude(current_settings.moduleswitches,cs_system_codepage);
  1529. include(current_settings.moduleswitches,cs_explicit_codepage);
  1530. end;
  1531. end;
  1532. procedure dir_coperators;
  1533. begin
  1534. do_moduleswitch(cs_support_c_operators);
  1535. end;
  1536. procedure dir_bitpacking;
  1537. begin
  1538. do_localswitch(cs_bitpacking);
  1539. end;
  1540. procedure dir_region;
  1541. begin
  1542. end;
  1543. procedure dir_endregion;
  1544. begin
  1545. end;
  1546. procedure dir_zerobasesstrings;
  1547. begin
  1548. do_localswitch(cs_zerobasedstrings);
  1549. end;
  1550. {****************************************************************************
  1551. Initialize Directives
  1552. ****************************************************************************}
  1553. procedure InitScannerDirectives;
  1554. begin
  1555. AddDirective('A1',directive_all, @dir_a1);
  1556. AddDirective('A2',directive_all, @dir_a2);
  1557. AddDirective('A4',directive_all, @dir_a4);
  1558. AddDirective('A8',directive_all, @dir_a8);
  1559. AddDirective('ALIGN',directive_all, @dir_align);
  1560. {$ifdef m68k}
  1561. AddDirective('APPID',directive_all, @dir_appid);
  1562. AddDirective('APPNAME',directive_all, @dir_appname);
  1563. {$endif m68k}
  1564. AddDirective('APPTYPE',directive_all, @dir_apptype);
  1565. AddDirective('ASMCPU',directive_all, @dir_asmcpu);
  1566. AddDirective('ASMMODE',directive_all, @dir_asmmode);
  1567. AddDirective('ASSERTIONS',directive_all, @dir_assertions);
  1568. AddDirective('BOOLEVAL',directive_all, @dir_booleval);
  1569. AddDirective('BITPACKING',directive_all, @dir_bitpacking);
  1570. AddDirective('CALLING',directive_all, @dir_calling);
  1571. AddDirective('CHECKLOWADDRLOADS',directive_all, @dir_checklowaddrloads);
  1572. AddDirective('CHECKPOINTER',directive_all, @dir_checkpointer);
  1573. AddDirective('CODEALIGN',directive_all, @dir_codealign);
  1574. AddDirective('CODEPAGE',directive_all, @dir_codepage);
  1575. AddDirective('COPERATORS',directive_all, @dir_coperators);
  1576. AddDirective('COPYRIGHT',directive_all, @dir_copyright);
  1577. AddDirective('D',directive_all, @dir_description);
  1578. AddDirective('DEBUGINFO',directive_all, @dir_debuginfo);
  1579. AddDirective('DESCRIPTION',directive_all, @dir_description);
  1580. AddDirective('ENDREGION',directive_all, @dir_endregion);
  1581. AddDirective('ERROR',directive_all, @dir_error);
  1582. AddDirective('ERRORC',directive_mac, @dir_error);
  1583. AddDirective('EXTENDEDSYNTAX',directive_all, @dir_extendedsyntax);
  1584. AddDirective('EXTERNALSYM',directive_all, @dir_externalsym);
  1585. AddDirective('F',directive_all, @dir_forcefarcalls);
  1586. AddDirective('FATAL',directive_all, @dir_fatal);
  1587. AddDirective('FPUTYPE',directive_all, @dir_fputype);
  1588. AddDirective('FRAMEWORKPATH',directive_all, @dir_frameworkpath);
  1589. AddDirective('GOTO',directive_all, @dir_goto);
  1590. AddDirective('HINT',directive_all, @dir_hint);
  1591. AddDirective('HINTS',directive_all, @dir_hints);
  1592. AddDirective('HPPEMIT',directive_all, @dir_hppemit);
  1593. AddDirective('HUGECODE',directive_all, @dir_hugecode);
  1594. AddDirective('HUGEPOINTERNORMALIZATION',directive_all,@dir_hugepointernormalization);
  1595. AddDirective('HUGEPOINTERARITHMETICNORMALIZATION',directive_all,@dir_hugepointerarithmeticnormalization);
  1596. AddDirective('HUGEPOINTERCOMPARISONNORMALIZATION',directive_all,@dir_hugepointercomparisonnormalization);
  1597. AddDirective('IEEEERRORS',directive_all,@dir_ieeeerrors);
  1598. AddDirective('IOCHECKS',directive_all, @dir_iochecks);
  1599. AddDirective('IMAGEBASE',directive_all, @dir_imagebase);
  1600. AddDirective('IMPLICITEXCEPTIONS',directive_all, @dir_implicitexceptions);
  1601. AddDirective('IMPORTEDDATA',directive_all, @dir_importeddata);
  1602. AddDirective('INCLUDEPATH',directive_all, @dir_includepath);
  1603. AddDirective('INFO',directive_all, @dir_info);
  1604. AddDirective('INLINE',directive_all, @dir_inline);
  1605. AddDirective('INTERFACES',directive_all, @dir_interfaces);
  1606. AddDirective('L',directive_all, @dir_link);
  1607. AddDirective('LIBEXPORT',directive_mac, @dir_libexport);
  1608. AddDirective('LIBRARYPATH',directive_all, @dir_librarypath);
  1609. AddDirective('LINK',directive_all, @dir_link);
  1610. AddDirective('LINKFRAMEWORK',directive_all, @dir_linkframework);
  1611. AddDirective('LINKLIB',directive_all, @dir_linklib);
  1612. AddDirective('LOCALSYMBOLS',directive_all, @dir_localsymbols);
  1613. AddDirective('LONGSTRINGS',directive_all, @dir_longstrings);
  1614. AddDirective('M',directive_all, @dir_memory);
  1615. AddDirective('MACRO',directive_all, @dir_macro);
  1616. AddDirective('MAXFPUREGISTERS',directive_all, @dir_maxfpuregisters);
  1617. AddDirective('MAXSTACKSIZE',directive_all, @dir_maxstacksize);
  1618. AddDirective('MEMORY',directive_all, @dir_memory);
  1619. AddDirective('MESSAGE',directive_all, @dir_message);
  1620. AddDirective('MINENUMSIZE',directive_all, @dir_packenum);
  1621. AddDirective('MINFPCONSTPREC',directive_all, @dir_minfpconstprec);
  1622. AddDirective('MINSTACKSIZE',directive_all, @dir_minstacksize);
  1623. AddDirective('MMX',directive_all, @dir_mmx);
  1624. AddDirective('MODE',directive_all, @dir_mode);
  1625. AddDirective('MODESWITCH',directive_all, @dir_modeswitch);
  1626. AddDirective('NAMESPACE',directive_all, @dir_namespace);
  1627. AddDirective('NODEFINE',directive_all, @dir_nodefine);
  1628. AddDirective('NOTE',directive_all, @dir_note);
  1629. AddDirective('NOTES',directive_all, @dir_notes);
  1630. AddDirective('OBJECTCHECKS',directive_all, @dir_objectchecks);
  1631. AddDirective('OBJECTPATH',directive_all, @dir_objectpath);
  1632. AddDirective('OPENSTRINGS',directive_all, @dir_openstrings);
  1633. AddDirective('OPTIMIZATION',directive_all, @dir_optimization);
  1634. AddDirective('OV',directive_mac, @dir_overflowchecks);
  1635. AddDirective('OVERFLOWCHECKS',directive_all, @dir_overflowchecks);
  1636. AddDirective('PACKENUM',directive_all, @dir_packenum);
  1637. AddDirective('PACKRECORDS',directive_all, @dir_packrecords);
  1638. AddDirective('PACKSET',directive_all, @dir_packset);
  1639. AddDirective('PASCALMAINNAME',directive_all, @dir_pascalmainname);
  1640. AddDirective('PIC',directive_all, @dir_pic);
  1641. AddDirective('POINTERMATH',directive_all, @dir_pointermath);
  1642. AddDirective('POP',directive_all, @dir_pop);
  1643. AddDirective('PROFILE',directive_all, @dir_profile);
  1644. AddDirective('PUSH',directive_all, @dir_push);
  1645. AddDirective('R',directive_all, @dir_resource);
  1646. AddDirective('RANGECHECKS',directive_all, @dir_rangechecks);
  1647. AddDirective('REFERENCEINFO',directive_all, @dir_referenceinfo);
  1648. AddDirective('REGION',directive_all, @dir_region);
  1649. AddDirective('RESOURCE',directive_all, @dir_resource);
  1650. AddDirective('SATURATION',directive_all, @dir_saturation);
  1651. AddDirective('SAFEFPUEXCEPTIONS',directive_all, @dir_safefpuexceptions);
  1652. AddDirective('SCOPEDENUMS',directive_all, @dir_scopedenums);
  1653. AddDirective('SETPEFLAGS', directive_all, @dir_setpeflags);
  1654. AddDirective('SETPEOPTFLAGS', directive_all, @dir_setpeoptflags);
  1655. AddDirective('SCREENNAME',directive_all, @dir_screenname);
  1656. AddDirective('SMARTLINK',directive_all, @dir_smartlink);
  1657. AddDirective('STACKFRAMES',directive_all, @dir_stackframes);
  1658. AddDirective('STOP',directive_all, @dir_stop);
  1659. AddDirective('STRINGCHECKS', directive_all, @dir_stringchecks);
  1660. {$ifdef powerpc}
  1661. AddDirective('SYSCALL',directive_all, @dir_syscall);
  1662. {$endif powerpc}
  1663. AddDirective('TARGETSWITCH',directive_all, @dir_targetswitch);
  1664. AddDirective('THREADNAME',directive_all, @dir_threadname);
  1665. AddDirective('TYPEDADDRESS',directive_all, @dir_typedaddress);
  1666. AddDirective('TYPEINFO',directive_all, @dir_typeinfo);
  1667. AddDirective('UNITPATH',directive_all, @dir_unitpath);
  1668. AddDirective('VARPARACOPYOUTCHECK',directive_all, @dir_varparacopyoutcheck);
  1669. AddDirective('VARPROPSETTER',directive_all, @dir_varpropsetter);
  1670. AddDirective('VARSTRINGCHECKS',directive_all, @dir_varstringchecks);
  1671. AddDirective('VERSION',directive_all, @dir_version);
  1672. AddDirective('WAIT',directive_all, @dir_wait);
  1673. AddDirective('WARN',directive_all, @dir_warn);
  1674. AddDirective('WARNING',directive_all, @dir_warning);
  1675. AddDirective('WARNINGS',directive_all, @dir_warnings);
  1676. AddDirective('WEAKPACKAGEUNIT',directive_all, @dir_weakpackageunit);
  1677. AddDirective('WRITEABLECONST',directive_all, @dir_writeableconst);
  1678. AddDirective('Z1',directive_all, @dir_z1);
  1679. AddDirective('Z2',directive_all, @dir_z2);
  1680. AddDirective('Z4',directive_all, @dir_z4);
  1681. AddDirective('ZEROBASEDSTRINGS',directive_all, @dir_zerobasesstrings);
  1682. end;
  1683. end.