scandir.inc 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. const
  19. directivelen=15;
  20. type
  21. directivestr=string[directivelen];
  22. tdirectivetoken=(
  23. _DIR_NONE,
  24. _DIR_ALIGN,_DIR_APPTYPE,_DIR_ASMMODE,_DIR_ASSERTIONS,
  25. _DIR_BOOLEVAL,
  26. _DIR_D,_DIR_DEBUGINFO,_DIR_DEFINE,_DIR_DESCRIPTION,
  27. _DIR_ELSE,_DIR_ENDIF,_DIR_ERROR,_DIR_EXTENDEDSYNTAX,
  28. _DIR_FATAL,
  29. _DIR_GOTO,
  30. _DIR_HINT,_DIR_HINTS,
  31. _DIR_I,_DIR_I386_ATT,_DIR_I386_DIRECT,_DIR_I386_INTEL,_DIR_IOCHECKS,
  32. _DIR_IF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_INCLUDE,_DIR_INCLUDEPATH,
  33. _DIR_INFO,_DIR_INLINE,
  34. _DIR_INTERFACES,
  35. _DIR_L,_DIR_LIBRARYPATH,_DIR_LINK,_DIR_LINKLIB,_DIR_LOCALSYMBOLS,
  36. _DIR_LONGSTRINGS,
  37. _DIR_M,_DIR_MACRO,_DIR_MAXFPUREGISTERS,_DIR_MEMORY,_DIR_MESSAGE,_DIR_MINENUMSIZE,_DIR_MMX,_DIR_MODE,
  38. _DIR_NOTE,_DIR_NOTES,
  39. _DIR_OBJECTPATH,_DIR_OPENSTRINGS,_DIR_OUTPUT_FORMAT,_DIR_OVERFLOWCHECKS,
  40. _DIR_PACKENUM,_DIR_PACKRECORDS,
  41. {$IFDEF Testvarsets}
  42. _DIR_PACKSET,
  43. {$ENDIF}
  44. _DIR_R,_DIR_RANGECHECKS,_DIR_REFERENCEINFO,
  45. _DIR_SATURATION,_DIR_SMARTLINK,_DIR_STACKFRAMES,_DIR_STATIC,_DIR_STOP,
  46. _DIR_TYPEDADDRESS,_DIR_TYPEINFO,
  47. _DIR_UNDEF,_DIR_UNITPATH,
  48. _DIR_VARSTRINGCHECKS,_DIR_VERSION,
  49. _DIR_WAIT,_DIR_WARNING,_DIR_WARNINGS,
  50. _DIR_Z1,_DIR_Z2,_DIR_Z4
  51. );
  52. const
  53. firstdirective=_DIR_NONE;
  54. lastdirective=_DIR_Z4;
  55. directive:array[tdirectivetoken] of directivestr=(
  56. {12345678901234567890 (To determine longest string.)}
  57. '',
  58. 'ALIGN',
  59. 'APPTYPE',
  60. 'ASMMODE',
  61. 'ASSERTIONS',
  62. 'BOOLEVAL',
  63. 'D',
  64. 'DEBUGINFO',
  65. 'DEFINE',
  66. 'DESCRIPTION',
  67. 'ELSE',
  68. 'ENDIF',
  69. 'ERROR',
  70. 'EXTENDEDSYNTAX',
  71. 'FATAL',
  72. 'GOTO',
  73. 'HINT',
  74. 'HINTS',
  75. 'I',
  76. {12345678901234567890 (To determine longest string.)}
  77. 'I386_ATT',
  78. 'I386_DIRECT',
  79. 'I386_INTEL',
  80. 'IOCHECKS',
  81. 'IF',
  82. 'IFDEF',
  83. 'IFNDEF',
  84. 'IFOPT',
  85. 'INCLUDE',
  86. 'INCLUDEPATH',
  87. 'INFO',
  88. 'INLINE',
  89. 'INTERFACES',
  90. 'L',
  91. 'LIBRARYPATH',
  92. 'LINK',
  93. 'LINKLIB',
  94. 'LOCALSYMBOLS',
  95. 'LONGSTRINGS',
  96. 'M',
  97. {12345678901234567890 (To determine longest string.)}
  98. 'MACRO',
  99. 'MAXFPUREGISTERS',
  100. 'MEMORY',
  101. 'MESSAGE',
  102. 'MINENUMSIZE',
  103. 'MMX',
  104. 'MODE',
  105. 'NOTE',
  106. 'NOTES',
  107. 'OBJECTPATH',
  108. 'OPENSTRINGS',
  109. 'OUTPUT_FORMAT',
  110. 'OVERFLOWCHECKS',
  111. 'PACKENUM',
  112. 'PACKRECORDS',
  113. {$IFDEF testvarsets}
  114. 'PACKSET',
  115. {$ENDIF}
  116. 'R',
  117. 'RANGECHECKS',
  118. 'REFERENCEINFO',
  119. 'SATURATION',
  120. 'SMARTLINK',
  121. {12345678901234567890 (To determine longest string.)}
  122. 'STACKFRAMES',
  123. 'STATIC',
  124. 'STOP',
  125. 'TYPEDADDRESS',
  126. 'TYPEINFO',
  127. 'UNDEF',
  128. 'UNITPATH',
  129. 'VARSTRINGCHECKS',
  130. 'VERSION',
  131. 'WAIT',
  132. 'WARNING',
  133. 'WARNINGS',
  134. 'Z1',
  135. 'Z2',
  136. 'Z4'
  137. );
  138. function Get_Directive(const hs:string):tdirectivetoken;
  139. var
  140. i : tdirectivetoken;
  141. begin
  142. for i:=firstdirective to lastdirective do
  143. if directive[i]=hs then
  144. begin
  145. Get_Directive:=i;
  146. exit;
  147. end;
  148. Get_Directive:=_DIR_NONE;
  149. end;
  150. {-------------------------------------------
  151. IF Conditional Handling
  152. -------------------------------------------}
  153. var
  154. preprocpat : string;
  155. preproc_token : ttoken;
  156. procedure preproc_consume(t : ttoken);
  157. begin
  158. if t<>preproc_token then
  159. Message(scan_e_preproc_syntax_error);
  160. preproc_token:=current_scanner^.readpreproc;
  161. end;
  162. function read_expr : string;forward;
  163. function read_factor : string;
  164. var
  165. hs : string;
  166. mac : pmacro;
  167. len : byte;
  168. begin
  169. if preproc_token=_ID then
  170. begin
  171. if preprocpat='NOT' then
  172. begin
  173. preproc_consume(_ID);
  174. hs:=read_expr;
  175. if hs='0' then
  176. read_factor:='1'
  177. else
  178. read_factor:='0';
  179. end
  180. else
  181. begin
  182. mac:=pmacro(current_scanner^.macros^.search(hs));
  183. hs:=preprocpat;
  184. preproc_consume(_ID);
  185. if assigned(mac) then
  186. begin
  187. if mac^.defined and assigned(mac^.buftext) then
  188. begin
  189. if mac^.buflen>255 then
  190. begin
  191. len:=255;
  192. Message(scan_w_macro_cut_after_255_chars);
  193. end
  194. else
  195. len:=mac^.buflen;
  196. hs[0]:=char(len);
  197. move(mac^.buftext^,hs[1],len);
  198. end
  199. else
  200. read_factor:='';
  201. end
  202. else
  203. read_factor:=hs;
  204. end
  205. end
  206. else if preproc_token=_LKLAMMER then
  207. begin
  208. preproc_consume(_LKLAMMER);
  209. read_factor:=read_expr;
  210. preproc_consume(_RKLAMMER);
  211. end
  212. else
  213. Message(scan_e_error_in_preproc_expr);
  214. end;
  215. function read_term : string;
  216. var
  217. hs1,hs2 : string;
  218. begin
  219. hs1:=read_factor;
  220. while true do
  221. begin
  222. if (preproc_token=_ID) then
  223. begin
  224. if preprocpat='AND' then
  225. begin
  226. preproc_consume(_ID);
  227. hs2:=read_factor;
  228. if (hs1<>'0') and (hs2<>'0') then
  229. hs1:='1';
  230. end
  231. else
  232. break;
  233. end
  234. else
  235. break;
  236. end;
  237. read_term:=hs1;
  238. end;
  239. function read_simple_expr : string;
  240. var
  241. hs1,hs2 : string;
  242. begin
  243. hs1:=read_term;
  244. while true do
  245. begin
  246. if (preproc_token=_ID) then
  247. begin
  248. if preprocpat='OR' then
  249. begin
  250. preproc_consume(_ID);
  251. hs2:=read_term;
  252. if (hs1<>'0') or (hs2<>'0') then
  253. hs1:='1';
  254. end
  255. else
  256. break;
  257. end
  258. else
  259. break;
  260. end;
  261. read_simple_expr:=hs1;
  262. end;
  263. function read_expr : string;
  264. var
  265. hs1,hs2 : string;
  266. b : boolean;
  267. t : ttoken;
  268. w : integer;
  269. l1,l2 : longint;
  270. begin
  271. hs1:=read_simple_expr;
  272. t:=preproc_token;
  273. if not(t in [_EQUAL,_UNEQUAL,_LT,_GT,_LTE,_GTE]) then
  274. begin
  275. read_expr:=hs1;
  276. exit;
  277. end;
  278. preproc_consume(t);
  279. hs2:=read_simple_expr;
  280. if is_number(hs1) and is_number(hs2) then
  281. begin
  282. valint(hs1,l1,w);
  283. valint(hs2,l2,w);
  284. case t of
  285. _EQUAL : b:=l1=l2;
  286. _UNEQUAL : b:=l1<>l2;
  287. _LT : b:=l1<l2;
  288. _GT : b:=l1>l2;
  289. _GTE : b:=l1>=l2;
  290. _LTE : b:=l1<=l2;
  291. end;
  292. end
  293. else
  294. begin
  295. case t of
  296. _EQUAL : b:=hs1=hs2;
  297. _UNEQUAL : b:=hs1<>hs2;
  298. _LT : b:=hs1<hs2;
  299. _GT : b:=hs1>hs2;
  300. _GTE : b:=hs1>=hs2;
  301. _LTE : b:=hs1<=hs2;
  302. end;
  303. end;
  304. if b then
  305. read_expr:='1'
  306. else
  307. read_expr:='0';
  308. end;
  309. {-------------------------------------------
  310. Directives
  311. -------------------------------------------}
  312. function is_conditional(t:tdirectivetoken):boolean;
  313. begin
  314. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  315. end;
  316. procedure dir_conditional(t:tdirectivetoken);
  317. var
  318. hs : string;
  319. mac : pmacro;
  320. found : boolean;
  321. state : char;
  322. oldaktfilepos : tfileposinfo;
  323. begin
  324. oldaktfilepos:=aktfilepos;
  325. while true do
  326. begin
  327. current_scanner^.gettokenpos;
  328. case t of
  329. _DIR_ENDIF : begin
  330. current_scanner^.poppreprocstack;
  331. end;
  332. _DIR_ELSE : begin
  333. current_scanner^.elsepreprocstack;
  334. end;
  335. _DIR_IFDEF : begin
  336. current_scanner^.skipspace;
  337. hs:=current_scanner^.readid;
  338. mac:=pmacro(current_scanner^.macros^.search(hs));
  339. if assigned(mac) then
  340. mac^.is_used:=true;
  341. current_scanner^.addpreprocstack(pp_ifdef,assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  342. end;
  343. _DIR_IFOPT : begin
  344. current_scanner^.skipspace;
  345. hs:=current_scanner^.readid;
  346. if (length(hs)>1) then
  347. Message1(scan_w_illegal_switch,hs)
  348. else
  349. begin
  350. state:=current_scanner^.ReadState;
  351. if state in ['-','+'] then
  352. found:=CheckSwitch(hs[1],state);
  353. end;
  354. current_scanner^.addpreprocstack(pp_ifopt,found,hs,scan_c_ifopt_found);
  355. end;
  356. _DIR_IF : begin
  357. current_scanner^.skipspace;
  358. { start preproc expression scanner }
  359. preproc_token:=current_scanner^.readpreproc;
  360. hs:=read_expr;
  361. current_scanner^.addpreprocstack(pp_if,hs<>'0',hs,scan_c_if_found);
  362. end;
  363. _DIR_IFNDEF : begin
  364. current_scanner^.skipspace;
  365. hs:=current_scanner^.readid;
  366. mac:=pmacro(current_scanner^.macros^.search(hs));
  367. if assigned(mac) then
  368. mac^.is_used:=true;
  369. current_scanner^.addpreprocstack(pp_ifndef,not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  370. end;
  371. end;
  372. { accept the text ? }
  373. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  374. break
  375. else
  376. begin
  377. current_scanner^.gettokenpos;
  378. Message(scan_c_skipping_until);
  379. repeat
  380. current_scanner^.skipuntildirective;
  381. t:=Get_Directive(current_scanner^.readid);
  382. until is_conditional(t);
  383. current_scanner^.gettokenpos;
  384. Message1(scan_d_handling_switch,'$'+directive[t]);
  385. end;
  386. end;
  387. aktfilepos:=oldaktfilepos;
  388. end;
  389. procedure dir_define(t:tdirectivetoken);
  390. var
  391. hs : string;
  392. bracketcount : longint;
  393. mac : pmacro;
  394. macropos : longint;
  395. macrobuffer : pmacrobuffer;
  396. begin
  397. current_scanner^.skipspace;
  398. hs:=current_scanner^.readid;
  399. mac:=pmacro(current_scanner^.macros^.search(hs));
  400. if not assigned(mac) then
  401. begin
  402. mac:=new(pmacro,init(hs));
  403. mac^.defined:=true;
  404. Message1(parser_m_macro_defined,mac^.name);
  405. current_scanner^.macros^.insert(mac);
  406. end
  407. else
  408. begin
  409. Message1(parser_m_macro_defined,mac^.name);
  410. mac^.defined:=true;
  411. { delete old definition }
  412. if assigned(mac^.buftext) then
  413. begin
  414. freemem(mac^.buftext,mac^.buflen);
  415. mac^.buftext:=nil;
  416. end;
  417. end;
  418. mac^.is_used:=true;
  419. if (cs_support_macro in aktmoduleswitches) then
  420. begin
  421. { key words are never substituted }
  422. if is_keyword(hs) then
  423. Message(scan_e_keyword_cant_be_a_macro);
  424. { !!!!!! handle macro params, need we this? }
  425. current_scanner^.skipspace;
  426. { may be a macro? }
  427. if c=':' then
  428. begin
  429. current_scanner^.readchar;
  430. if c='=' then
  431. begin
  432. new(macrobuffer);
  433. macropos:=0;
  434. { parse macro, brackets are counted so it's possible
  435. to have a $ifdef etc. in the macro }
  436. bracketcount:=0;
  437. repeat
  438. current_scanner^.readchar;
  439. case c of
  440. '}' :
  441. if (bracketcount=0) then
  442. break
  443. else
  444. dec(bracketcount);
  445. '{' :
  446. inc(bracketcount);
  447. #26 :
  448. current_scanner^.end_of_file;
  449. end;
  450. macrobuffer^[macropos]:=c;
  451. inc(macropos);
  452. if macropos>maxmacrolen then
  453. Message(scan_f_macro_buffer_overflow);
  454. until false;
  455. { free buffer of macro ?}
  456. if assigned(mac^.buftext) then
  457. freemem(mac^.buftext,mac^.buflen);
  458. { get new mem }
  459. getmem(mac^.buftext,macropos);
  460. mac^.buflen:=macropos;
  461. { copy the text }
  462. move(macrobuffer^,mac^.buftext^,macropos);
  463. dispose(macrobuffer);
  464. end;
  465. end;
  466. end
  467. else
  468. begin
  469. { check if there is an assignment, then we need to give a
  470. warning }
  471. current_scanner^.skipspace;
  472. if c=':' then
  473. begin
  474. current_scanner^.readchar;
  475. if c='=' then
  476. Message(scan_w_macro_support_turned_off);
  477. end;
  478. end;
  479. end;
  480. procedure dir_undef(t:tdirectivetoken);
  481. var
  482. hs : string;
  483. mac : pmacro;
  484. begin
  485. current_scanner^.skipspace;
  486. hs:=current_scanner^.readid;
  487. mac:=pmacro(current_scanner^.macros^.search(hs));
  488. if not assigned(mac) then
  489. begin
  490. mac:=new(pmacro,init(hs));
  491. Message1(parser_m_macro_undefined,mac^.name);
  492. mac^.defined:=false;
  493. current_scanner^.macros^.insert(mac);
  494. end
  495. else
  496. begin
  497. Message1(parser_m_macro_undefined,mac^.name);
  498. mac^.defined:=false;
  499. { delete old definition }
  500. if assigned(mac^.buftext) then
  501. begin
  502. freemem(mac^.buftext,mac^.buflen);
  503. mac^.buftext:=nil;
  504. end;
  505. end;
  506. mac^.is_used:=true;
  507. end;
  508. procedure dir_message(t:tdirectivetoken);
  509. var
  510. w : longint;
  511. begin
  512. case t of
  513. _DIR_STOP,
  514. _DIR_FATAL : w:=scan_f_user_defined;
  515. _DIR_ERROR : w:=scan_e_user_defined;
  516. _DIR_WARNING : w:=scan_w_user_defined;
  517. _DIR_HINT : w:=scan_h_user_defined;
  518. _DIR_NOTE : w:=scan_n_user_defined;
  519. _DIR_MESSAGE,
  520. _DIR_INFO : w:=scan_i_user_defined;
  521. end;
  522. current_scanner^.skipspace;
  523. Message1(w,current_scanner^.readcomment);
  524. end;
  525. procedure dir_moduleswitch(t:tdirectivetoken);
  526. var
  527. sw : tmoduleswitch;
  528. state : char;
  529. begin
  530. sw:=cs_modulenone;
  531. case t of
  532. _DIR_GOTO : sw:=cs_support_goto;
  533. _DIR_MACRO : sw:=cs_support_macro;
  534. _DIR_INLINE : sw:=cs_support_inline;
  535. _DIR_SMARTLINK : sw:=cs_create_smart;
  536. _DIR_STATIC : sw:=cs_static_keyword;
  537. end;
  538. state:=current_scanner^.readstate;
  539. if (sw<>cs_modulenone) and (state in ['-','+']) then
  540. begin
  541. if state='-' then
  542. aktmoduleswitches:=aktmoduleswitches-[sw]
  543. else
  544. aktmoduleswitches:=aktmoduleswitches+[sw];
  545. end;
  546. end;
  547. procedure dir_interfacesswitch(t:tdirectivetoken);
  548. var
  549. hs : string;
  550. begin
  551. {corba/com/default}
  552. current_scanner^.skipspace;
  553. hs:=current_scanner^.readid;
  554. if (hs='CORBA') then
  555. aktinterfacetype:=it_interfacecorba
  556. else if (hs='COM') then
  557. aktinterfacetype:=it_interfacecom
  558. else if (hs='DEFAULT') then
  559. aktinterfacetype:=initinterfacetype
  560. else
  561. Message(scan_e_invalid_interface_type);
  562. end;
  563. procedure dir_localswitch(t:tdirectivetoken);
  564. var
  565. sw : tlocalswitch;
  566. state : char;
  567. begin
  568. sw:=cs_localnone;
  569. {$ifdef SUPPORT_MMX}
  570. case t of
  571. _DIR_MMX : sw:=cs_mmx;
  572. _DIR_SATURATION : sw:=cs_mmx_saturation;
  573. end;
  574. {$endif}
  575. state:=current_scanner^.readstate;
  576. if (sw<>cs_localnone) and (state in ['-','+']) then
  577. begin
  578. if not localswitcheschanged then
  579. nextaktlocalswitches:=aktlocalswitches;
  580. if state='-' then
  581. nextaktlocalswitches:=nextaktlocalswitches-[sw]
  582. else
  583. nextaktlocalswitches:=nextaktlocalswitches+[sw];
  584. localswitcheschanged:=true;
  585. end;
  586. end;
  587. procedure dir_include(t:tdirectivetoken);
  588. var
  589. hs : string;
  590. path : dirstr;
  591. name : namestr;
  592. ext : extstr;
  593. hp : pinputfile;
  594. i : longint;
  595. found : boolean;
  596. begin
  597. current_scanner^.skipspace;
  598. hs:=current_scanner^.readcomment;
  599. i:=length(hs);
  600. while (i>0) and (hs[i]=' ') do
  601. dec(i);
  602. Delete(hs,i+1,length(hs)-i);
  603. if hs='' then
  604. exit;
  605. if (hs[1]='%') then
  606. begin
  607. { case insensitive }
  608. hs:=upper(hs);
  609. { remove %'s }
  610. Delete(hs,1,1);
  611. if hs[length(hs)]='%' then
  612. Delete(hs,length(hs),1);
  613. { save old }
  614. path:=hs;
  615. { first check for internal macros }
  616. if hs='TIME' then
  617. hs:=gettimestr
  618. else
  619. if hs='DATE' then
  620. hs:=getdatestr
  621. else
  622. if hs='FILE' then
  623. hs:=current_module^.sourcefiles^.get_file_name(aktfilepos.fileindex)
  624. else
  625. if hs='LINE' then
  626. hs:=tostr(aktfilepos.line)
  627. else
  628. if hs='FPCVERSION' then
  629. hs:=version_string
  630. else
  631. if hs='FPCTARGET' then
  632. hs:=target_cpu_string
  633. else
  634. hs:=getenv(hs);
  635. if hs='' then
  636. Message1(scan_w_include_env_not_found,path);
  637. { make it a stringconst }
  638. hs:=''''+hs+'''';
  639. current_scanner^.insertmacro(path,@hs[1],length(hs));
  640. end
  641. else
  642. begin
  643. hs:=FixFileName(hs);
  644. fsplit(hs,path,name,ext);
  645. { look for the include file
  646. 1. specified path,path of current inputfile,current dir
  647. 2. local includepath
  648. 3. global includepath }
  649. found:=false;
  650. if path<>'' then
  651. path:=path+';';
  652. path:=FindFile(name+ext,path+current_scanner^.inputfile^.path^+';.'+DirSep,found);
  653. if (not found) then
  654. path:=current_module^.localincludesearchpath.FindFile(name+ext,found);
  655. if (not found) then
  656. path:=includesearchpath.FindFile(name+ext,found);
  657. { shutdown current file }
  658. current_scanner^.tempcloseinputfile;
  659. { load new file }
  660. hp:=do_openinputfile(path+name+ext);
  661. current_scanner^.addfile(hp);
  662. if not current_scanner^.openinputfile then
  663. Message1(scan_f_cannot_open_includefile,hs);
  664. Message1(scan_t_start_include_file,current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^);
  665. current_scanner^.reload;
  666. { process first read char }
  667. case c of
  668. #26 : current_scanner^.reload;
  669. #10,
  670. #13 : current_scanner^.linebreak;
  671. end;
  672. { register for refs }
  673. current_module^.sourcefiles^.register_file(hp);
  674. end;
  675. end;
  676. procedure dir_description(t:tdirectivetoken);
  677. begin
  678. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then
  679. Message(scan_w_decription_not_support);
  680. { change description global var in all cases }
  681. { it not used but in win32, os2 and netware }
  682. current_scanner^.skipspace;
  683. description:=current_scanner^.readcomment;
  684. end;
  685. procedure dir_version(t:tdirectivetoken);
  686. var
  687. major, minor, revision : longint;
  688. error : integer;
  689. begin
  690. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then // AD
  691. begin
  692. Message(scan_n_version_not_support);
  693. exit;
  694. end;
  695. if (compile_level<>1) then
  696. Message(scan_n_only_exe_version)
  697. else
  698. begin
  699. { change description global var in all cases }
  700. { it not used but in win32, os2 and netware }
  701. current_scanner^.skipspace;
  702. { we should only accept Major.Minor format for win32 and os2 }
  703. current_scanner^.readnumber;
  704. major:=0;
  705. minor:=0;
  706. revision:=0;
  707. valint(pattern,major,error);
  708. if error<>0 then
  709. begin
  710. Message1(scan_w_wrong_version_ignored,pattern);
  711. exit;
  712. end;
  713. if c='.' then
  714. begin
  715. current_scanner^.readchar;
  716. current_scanner^.readnumber;
  717. valint(pattern,minor,error);
  718. if error<>0 then
  719. begin
  720. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  721. exit;
  722. end;
  723. if (c='.') and
  724. (target_info.target = target_i386_netware) then // AD
  725. begin
  726. current_scanner^.readchar;
  727. current_scanner^.readnumber;
  728. valint(pattern,revision,error);
  729. if error<>0 then
  730. begin
  731. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  732. exit;
  733. end;
  734. dllmajor:=major;
  735. dllminor:=minor;
  736. dllrevision:=revision;
  737. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  738. end
  739. else
  740. begin
  741. dllmajor:=major;
  742. dllminor:=minor;
  743. dllversion:=tostr(major)+'.'+tostr(minor);
  744. end;
  745. end
  746. else
  747. dllversion:=tostr(major);
  748. end;
  749. end;
  750. procedure dir_linkobject(t:tdirectivetoken);
  751. var
  752. s : string;
  753. begin
  754. current_scanner^.skipspace;
  755. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.objext);
  756. {$IFDEF NEWST}
  757. current_module^.linkotherofiles.
  758. insert(new(Plinkitem,init(s,link_allways)));
  759. {$ELSE}
  760. current_module^.linkotherofiles.
  761. insert(s,link_allways);
  762. {$ENDIF NEWST}
  763. end;
  764. procedure dir_resource(t:tdirectivetoken);
  765. var
  766. s : string;
  767. begin
  768. current_scanner^.skipspace;
  769. s:=current_scanner^.readcomment;
  770. { replace * with current module name.
  771. This should always be defined. }
  772. if s[1]='*' then
  773. if Assigned(Current_Module) then
  774. begin
  775. delete(S,1,1);
  776. insert(lower(current_module^.modulename^),S,1);
  777. end;
  778. s:=AddExtension(FixFileName(s),target_info.resext);
  779. if target_info.res<>res_none then
  780. if (target_info.res = res_i386_emx) and
  781. not (Current_Module^.ResourceFiles.Empty) then
  782. Message(scan_w_only_one_resourcefile_supported)
  783. else
  784. current_module^.resourcefiles.insert(FixFileName(s))
  785. else
  786. Message(scan_e_resourcefiles_not_supported);
  787. end;
  788. {$ifndef PAVEL_LINKLIB}
  789. procedure dir_linklib(t:tdirectivetoken);
  790. var
  791. s : string;
  792. quote : char;
  793. begin
  794. current_scanner^.skipspace;
  795. { This way spaces are also allowed in library names
  796. if quoted PM }
  797. if (c='''') or (c='"') then
  798. begin
  799. quote:=c;
  800. current_scanner^.readchar;
  801. s:=current_scanner^.readcomment;
  802. if pos(quote,s)>0 then
  803. s:=copy(s,1,pos(quote,s)-1);
  804. end
  805. else
  806. begin
  807. current_scanner^.readstring;
  808. s:=orgpattern;
  809. if c='.' then
  810. begin
  811. s:=s+'.';
  812. current_scanner^.readchar;
  813. current_scanner^.readstring;
  814. s:=s+orgpattern;
  815. end;
  816. end;
  817. {$IFDEF NEWST}
  818. current_module^.linkOtherSharedLibs.
  819. insert(new(Plinkitem,init(s,link_allways)));
  820. {$ELSE}
  821. current_module^.linkOtherSharedLibs.
  822. insert(s,link_allways);
  823. {$ENDIF}
  824. end;
  825. {$else PAVEL_LINKLIB}
  826. procedure dir_linklib(t:tdirectivetoken);
  827. var
  828. s:string;
  829. libname,linkmodeStr:string;
  830. p:longint;
  831. type
  832. tLinkMode=(lm_dynamic,lm_static);
  833. var
  834. linkMode:tLinkMode;
  835. function ExtractLinkMode:tLinkMode;
  836. var
  837. p:longint;
  838. begin
  839. p:=pos(',',linkmodeStr);
  840. if p>0 then
  841. linkmodeStr:=copy(linkmodeStr,1,pred(p));
  842. for p:=1 to length(linkmodeStr)do
  843. linkmodeStr[p]:=upcase(linkmodeStr[p]);
  844. if linkmodeStr='STATIC' then
  845. ExtractLinkMode:=lm_static
  846. else
  847. ExtractLinkMode:=lm_dynamic
  848. end;
  849. procedure MangleLibName(mode:tLinkMode);
  850. begin
  851. if (libname[1]='''')and(libname[length(libname)]='''')then
  852. begin
  853. delete(libname,1,1);
  854. delete(libname,length(libname),1);
  855. end
  856. else
  857. begin
  858. libname:=target_os.libprefix+libname;
  859. case mode of
  860. lm_static:
  861. libname:=AddExtension(FixFileName(libname),target_os.staticlibext);
  862. lm_dynamic:
  863. libname:=AddExtension(FixFileName(libname),target_os.sharedlibext);
  864. end;
  865. end;
  866. end;
  867. begin
  868. current_scanner^.skipspace;
  869. s:=current_scanner^.readcomment;
  870. p:=pos(',',s);
  871. if p=0 then
  872. begin
  873. libname:=s;
  874. linkmodeStr:=''
  875. end
  876. else
  877. begin
  878. libname:=copy(s,1,pred(p));
  879. linkmodeStr:=copy(s,succ(p),255);
  880. end;
  881. if(libname='')or(libname='''''')then
  882. exit;
  883. linkMode:=ExtractLinkMode;
  884. MangleLibName(linkMode);
  885. if linkMode=lm_static then
  886. {$IFDEF NEWST}
  887. current_module^.linkOtherStaticLibs.
  888. insert(new(Plinkitem,init(FixFileName(libname),link_allways)))
  889. {$ELSE}
  890. current_module^.linkOtherStaticLibs.
  891. insert(FixFileName(libname),link_allways)
  892. {$ENDIF}
  893. else
  894. {$IFDEF NEWST}
  895. current_module^.linkOtherSharedLibs.
  896. insert(new(Plinkitem,init(FixFileName(libname),link_allways)));
  897. {$ELSE}
  898. current_module^.linkOtherSharedLibs.
  899. insert(FixFileName(libname),link_allways);
  900. {$ENDIF}
  901. end;
  902. {$endif PAVEL_LINKLIB}
  903. procedure dir_outputformat(t:tdirectivetoken);
  904. begin
  905. if not current_module^.in_global then
  906. Message(scan_w_switch_is_global)
  907. else
  908. begin
  909. current_scanner^.skipspace;
  910. if set_string_asm(current_scanner^.readid) then
  911. aktoutputformat:=target_asm.id
  912. else
  913. Message1(scan_w_illegal_switch,pattern);
  914. end;
  915. end;
  916. procedure dir_unitpath(t:tdirectivetoken);
  917. begin
  918. if not current_module^.in_global then
  919. Message(scan_w_switch_is_global)
  920. else
  921. begin
  922. current_scanner^.skipspace;
  923. current_module^.localunitsearchpath.AddPath(current_scanner^.readcomment,false);
  924. end;
  925. end;
  926. procedure dir_includepath(t:tdirectivetoken);
  927. begin
  928. if not current_module^.in_global then
  929. Message(scan_w_switch_is_global)
  930. else
  931. begin
  932. current_scanner^.skipspace;
  933. current_module^.localincludesearchpath.AddPath(current_scanner^.readcomment,false);
  934. end;
  935. end;
  936. procedure dir_librarypath(t:tdirectivetoken);
  937. begin
  938. if not current_module^.in_global then
  939. Message(scan_w_switch_is_global)
  940. else
  941. begin
  942. current_scanner^.skipspace;
  943. current_module^.locallibrarysearchpath.AddPath(current_scanner^.readcomment,false);
  944. end;
  945. end;
  946. procedure dir_objectpath(t:tdirectivetoken);
  947. begin
  948. if not current_module^.in_global then
  949. Message(scan_w_switch_is_global)
  950. else
  951. begin
  952. current_scanner^.skipspace;
  953. current_module^.localobjectsearchpath.AddPath(current_scanner^.readcomment,false);
  954. end;
  955. end;
  956. procedure dir_mode(t:tdirectivetoken);
  957. begin
  958. if not current_module^.in_global then
  959. Message(scan_w_switch_is_global)
  960. else
  961. begin
  962. current_scanner^.skipspace;
  963. current_scanner^.readstring;
  964. if not SetCompileMode(pattern,false) then
  965. Message1(scan_w_illegal_switch,pattern);
  966. end;
  967. end;
  968. procedure dir_packrecords(t:tdirectivetoken);
  969. var
  970. hs : string;
  971. begin
  972. current_scanner^.skipspace;
  973. if not(c in ['0'..'9']) then
  974. begin
  975. hs:=current_scanner^.readid;
  976. if (hs='C') then
  977. aktpackrecords:=packrecord_C
  978. else
  979. if (hs='NORMAL') or (hs='DEFAULT') then
  980. aktpackrecords:=packrecord_2
  981. else
  982. Message(scan_w_only_pack_records);
  983. end
  984. else
  985. begin
  986. case current_scanner^.readval of
  987. 1 : aktpackrecords:=packrecord_1;
  988. 2 : aktpackrecords:=packrecord_2;
  989. 4 : aktpackrecords:=packrecord_4;
  990. 8 : aktpackrecords:=packrecord_8;
  991. 16 : aktpackrecords:=packrecord_16;
  992. 32 : aktpackrecords:=packrecord_32;
  993. else
  994. Message(scan_w_only_pack_records);
  995. end;
  996. end;
  997. end;
  998. procedure dir_maxfpuregisters(t:tdirectivetoken);
  999. var
  1000. l : longint;
  1001. hs : string;
  1002. begin
  1003. current_scanner^.skipspace;
  1004. if not(c in ['0'..'9']) then
  1005. begin
  1006. hs:=current_scanner^.readid;
  1007. if (hs='NORMAL') or (hs='DEFAULT') then
  1008. aktmaxfpuregisters:=-1
  1009. else
  1010. Message(scan_e_invalid_maxfpureg_value);
  1011. end
  1012. else
  1013. begin
  1014. l:=current_scanner^.readval;
  1015. case l of
  1016. 0..8:
  1017. aktmaxfpuregisters:=l;
  1018. else
  1019. Message(scan_e_invalid_maxfpureg_value);
  1020. end;
  1021. end;
  1022. end;
  1023. procedure dir_packenum(t:tdirectivetoken);
  1024. var
  1025. hs : string;
  1026. begin
  1027. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  1028. begin
  1029. aktpackenum:=ord(pattern[2])-ord('0');
  1030. exit;
  1031. end;
  1032. current_scanner^.skipspace;
  1033. if not(c in ['0'..'9']) then
  1034. begin
  1035. hs:=current_scanner^.readid;
  1036. if (hs='NORMAL') or (hs='DEFAULT') then
  1037. aktpackenum:=4
  1038. else
  1039. Message(scan_w_only_pack_enum);
  1040. end
  1041. else
  1042. begin
  1043. case current_scanner^.readval of
  1044. 1 : aktpackenum:=1;
  1045. 2 : aktpackenum:=2;
  1046. 4 : aktpackenum:=4;
  1047. else
  1048. Message(scan_w_only_pack_enum);
  1049. end;
  1050. end;
  1051. end;
  1052. {$ifdef testvarsets}
  1053. procedure dir_setalloc(t:tdirectivetoken);
  1054. var
  1055. hs : string;
  1056. begin
  1057. current_scanner^.skipspace;
  1058. if not(c in ['1','2','4']) then
  1059. begin
  1060. hs:=current_scanner^.readid;
  1061. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  1062. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  1063. else
  1064. Message(scan_w_only_packset);
  1065. end
  1066. else
  1067. begin
  1068. case current_scanner^.readval of
  1069. 1 : aktpackenum:=1;
  1070. 2 : aktpackenum:=2;
  1071. 4 : aktpackenum:=4;
  1072. else
  1073. Message(scan_w_only_packset);
  1074. end;
  1075. end;
  1076. end;
  1077. {$ENDIF}
  1078. procedure dir_apptype(t:tdirectivetoken);
  1079. var
  1080. hs : string;
  1081. begin
  1082. if target_info.target<>target_i386_win32 then
  1083. Message(scan_w_app_type_not_support);
  1084. if not current_module^.in_global then
  1085. Message(scan_w_switch_is_global)
  1086. else
  1087. begin
  1088. current_scanner^.skipspace;
  1089. hs:=current_scanner^.readid;
  1090. if hs='GUI' then
  1091. apptype:=at_gui
  1092. else if hs='CONSOLE' then
  1093. apptype:=at_cui
  1094. else
  1095. Message1(scan_w_unsupported_app_type,hs);
  1096. end;
  1097. end;
  1098. procedure dir_wait(t:tdirectivetoken);
  1099. var had_info : boolean;
  1100. begin
  1101. had_info:=(status.verbosity and V_Info)<>0;
  1102. { this message should allways appear !! }
  1103. status.verbosity:=status.verbosity or V_Info;
  1104. Message(scan_i_press_enter);
  1105. readln;
  1106. If not(had_info) then
  1107. status.verbosity:=status.verbosity and (not V_Info);
  1108. end;
  1109. procedure dir_asmmode(t:tdirectivetoken);
  1110. var
  1111. s : string;
  1112. begin
  1113. current_scanner^.skipspace;
  1114. s:=current_scanner^.readid;
  1115. If Inside_asm_statement then
  1116. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  1117. if s='DEFAULT' then
  1118. aktasmmode:=initasmmode
  1119. else
  1120. if not set_string_asmmode(s,aktasmmode) then
  1121. Message1(scan_w_unsupported_asmmode_specifier,s);
  1122. end;
  1123. procedure dir_oldasmmode(t:tdirectivetoken);
  1124. begin
  1125. If Inside_asm_statement then
  1126. Message1(scan_w_no_asm_reader_switch_inside_asm,directive[t]);
  1127. {$ifdef i386}
  1128. case t of
  1129. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  1130. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  1131. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  1132. end;
  1133. {$endif i386}
  1134. end;
  1135. procedure dir_delphiswitch(t:tdirectivetoken);
  1136. var
  1137. sw,state : char;
  1138. begin
  1139. case t of
  1140. _DIR_ALIGN : sw:='A';
  1141. _DIR_ASSERTIONS : sw:='C';
  1142. _DIR_BOOLEVAL : sw:='B';
  1143. _DIR_DEBUGINFO : sw:='D';
  1144. _DIR_IOCHECKS : sw:='I';
  1145. _DIR_LOCALSYMBOLS : sw:='L';
  1146. _DIR_LONGSTRINGS : sw:='H';
  1147. _DIR_OPENSTRINGS : sw:='P';
  1148. _DIR_OVERFLOWCHECKS : sw:='Q';
  1149. _DIR_RANGECHECKS : sw:='R';
  1150. _DIR_REFERENCEINFO : sw:='Y';
  1151. _DIR_STACKFRAMES : sw:='W';
  1152. _DIR_TYPEDADDRESS : sw:='T';
  1153. _DIR_TYPEINFO : sw:='M';
  1154. _DIR_VARSTRINGCHECKS : sw:='V';
  1155. else
  1156. exit;
  1157. end;
  1158. { c contains the next char, a + or - would be fine }
  1159. state:=current_scanner^.readstate;
  1160. if state in ['-','+'] then
  1161. HandleSwitch(sw,state);
  1162. end;
  1163. procedure dir_memory(t:tdirectivetoken);
  1164. var
  1165. l : longint;
  1166. begin
  1167. current_scanner^.skipspace;
  1168. l:=current_scanner^.readval;
  1169. if l>1024 then
  1170. stacksize:=l;
  1171. current_scanner^.skipspace;
  1172. if c=',' then
  1173. begin
  1174. current_scanner^.readchar;
  1175. current_scanner^.skipspace;
  1176. l:=current_scanner^.readval;
  1177. if l>1024 then
  1178. heapsize:=l;
  1179. end;
  1180. if c=',' then
  1181. begin
  1182. current_scanner^.readchar;
  1183. current_scanner^.skipspace;
  1184. l:=current_scanner^.readval;
  1185. { Ignore this value, because the limit is set by the OS
  1186. info and shouldn't be changed by the user (PFV) }
  1187. end;
  1188. end;
  1189. procedure dir_setverbose(t:tdirectivetoken);
  1190. var
  1191. flag,
  1192. state : char;
  1193. begin
  1194. case t of
  1195. _DIR_HINTS : flag:='H';
  1196. _DIR_WARNINGS : flag:='W';
  1197. _DIR_NOTES : flag:='N';
  1198. else
  1199. exit;
  1200. end;
  1201. { support ON/OFF }
  1202. state:=current_scanner^.ReadState;
  1203. SetVerbosity(flag+state);
  1204. end;
  1205. type
  1206. tdirectiveproc=procedure(t:tdirectivetoken);
  1207. const
  1208. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  1209. {_DIR_NONE} nil,
  1210. {_DIR_ALIGN} dir_delphiswitch,
  1211. {_DIR_APPTYPE} dir_apptype,
  1212. {_DIR_ASMMODE} dir_asmmode,
  1213. {_DIR_ASSERTION} dir_delphiswitch,
  1214. {_DIR_BOOLEVAL} dir_delphiswitch,
  1215. {_DIR_D} dir_description,
  1216. {_DIR_DEBUGINFO} dir_delphiswitch,
  1217. {_DIR_DEFINE} dir_define,
  1218. {_DIR_DESCRIPTION} dir_description,
  1219. {_DIR_ELSE} dir_conditional,
  1220. {_DIR_ENDIF} dir_conditional,
  1221. {_DIR_ERROR} dir_message,
  1222. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  1223. {_DIR_FATAL} dir_message,
  1224. {_DIR_GOTO} dir_moduleswitch,
  1225. {_DIR_HINT} dir_message,
  1226. {_DIR_HINTS} dir_setverbose,
  1227. {_DIR_I} dir_include,
  1228. {_DIR_I386_ATT} dir_oldasmmode,
  1229. {_DIR_I386_DIRECT} dir_oldasmmode,
  1230. {_DIR_I386_INTEL} dir_oldasmmode,
  1231. {_DIR_IOCHECKS} dir_delphiswitch,
  1232. {_DIR_IF} dir_conditional,
  1233. {_DIR_IFDEF} dir_conditional,
  1234. {_DIR_IFNDEF} dir_conditional,
  1235. {_DIR_IFOPT} dir_conditional,
  1236. {_DIR_INCLUDE} dir_include,
  1237. {_DIR_INCLUDEPATH} dir_includepath,
  1238. {_DIR_INFO} dir_message,
  1239. {_DIR_INLINE} dir_moduleswitch,
  1240. {_DIR_INTERFACES} dir_interfacesswitch,
  1241. {_DIR_L} dir_linkobject,
  1242. {_DIR_LIBRARYPATH} dir_librarypath,
  1243. {_DIR_LINK} dir_linkobject,
  1244. {_DIR_LINKLIB} dir_linklib,
  1245. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  1246. {_DIR_LONGSTRINGS} dir_delphiswitch,
  1247. {_DIR_M} dir_memory,
  1248. {_DIR_MACRO} dir_moduleswitch,
  1249. {_DIR_MAXFPUREGISTERS} dir_maxfpuregisters,
  1250. {_DIR_MEMORY} dir_memory,
  1251. {_DIR_MESSAGE} dir_message,
  1252. {_DIR_MINENUMSIZE} dir_packenum,
  1253. {_DIR_MMX} dir_localswitch,
  1254. {_DIR_MODE} dir_mode,
  1255. {_DIR_NOTE} dir_message,
  1256. {_DIR_NOTES} dir_setverbose,
  1257. {_DIR_OBJECTPATH} dir_objectpath,
  1258. {_DIR_OPENSTRINGS} dir_delphiswitch,
  1259. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  1260. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  1261. {_DIR_PACKENUM} dir_packenum,
  1262. {_DIR_PACKRECORDS} dir_packrecords,
  1263. {$IFDEF TestVarsets}
  1264. {_DIR_PACKSET} dir_packset,
  1265. {$ENDIF}
  1266. {_DIR_R} dir_resource,
  1267. {_DIR_RANGECHECKS} dir_delphiswitch,
  1268. {_DIR_REFERENCEINFO} dir_delphiswitch,
  1269. {_DIR_SATURATION} dir_localswitch,
  1270. {_DIR_SMARTLINK} dir_moduleswitch,
  1271. {_DIR_STACKFRAMES} dir_delphiswitch,
  1272. {_DIR_STATIC} dir_moduleswitch,
  1273. {_DIR_STOP} dir_message,
  1274. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  1275. {_DIR_TYPEINFO} dir_delphiswitch,
  1276. {_DIR_UNDEF} dir_undef,
  1277. {_DIR_UNITPATH} dir_unitpath,
  1278. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  1279. {_DIR_VERSION} dir_version,
  1280. {_DIR_WAIT} dir_wait,
  1281. {_DIR_WARNING} dir_message,
  1282. {_DIR_WARNINGS} dir_setverbose,
  1283. {_DIR_Z1} dir_packenum,
  1284. {_DIR_Z2} dir_packenum,
  1285. {_DIR_Z4} dir_packenum
  1286. );
  1287. {-------------------------------------------
  1288. Main switches handling
  1289. -------------------------------------------}
  1290. procedure handledirectives;
  1291. var
  1292. t : tdirectivetoken;
  1293. p : tdirectiveproc;
  1294. hs : string;
  1295. begin
  1296. current_scanner^.gettokenpos;
  1297. current_scanner^.readchar; {Remove the $}
  1298. hs:=current_scanner^.readid;
  1299. if parapreprocess then
  1300. begin
  1301. t:=Get_Directive(hs);
  1302. if not(is_conditional(t) or (t=_DIR_DEFINE) or (t=_DIR_UNDEF)) then
  1303. begin
  1304. preprocfile^.AddSpace;
  1305. preprocfile^.Add('{$'+hs+current_scanner^.readcomment+'}');
  1306. exit;
  1307. end;
  1308. end;
  1309. { skip this directive? }
  1310. if current_scanner^.ignoredirectives.find(hs) then
  1311. begin
  1312. if (current_scanner^.comment_level>0) then
  1313. current_scanner^.readcomment;
  1314. { we've read the whole comment }
  1315. aktcommentstyle:=comment_none;
  1316. exit;
  1317. end;
  1318. if hs='' then
  1319. begin
  1320. Message1(scan_w_illegal_switch,'$'+hs);
  1321. end;
  1322. { Check for compiler switches }
  1323. while (length(hs)=1) and (c in ['-','+']) do
  1324. begin
  1325. HandleSwitch(hs[1],c);
  1326. current_scanner^.readchar; {Remove + or -}
  1327. if c=',' then
  1328. begin
  1329. current_scanner^.readchar; {Remove , }
  1330. { read next switch, support $v+,$+}
  1331. hs:=current_scanner^.readid;
  1332. if (hs='') then
  1333. begin
  1334. if (c='$') and (m_fpc in aktmodeswitches) then
  1335. begin
  1336. current_scanner^.readchar; { skip $ }
  1337. hs:=current_scanner^.readid;
  1338. end;
  1339. if (hs='') then
  1340. Message1(scan_w_illegal_directive,'$'+c);
  1341. end
  1342. else
  1343. Message1(scan_d_handling_switch,'$'+hs);
  1344. end
  1345. else
  1346. hs:='';
  1347. end;
  1348. { directives may follow switches after a , }
  1349. if hs<>'' then
  1350. begin
  1351. t:=Get_Directive(hs);
  1352. if t<>_DIR_NONE then
  1353. begin
  1354. p:=directiveproc[t];
  1355. if {$ifndef FPCPROCVAR}@{$endif}p<>nil then
  1356. p(t);
  1357. end
  1358. else
  1359. begin
  1360. current_scanner^.ignoredirectives.insert(hs);
  1361. Message1(scan_w_illegal_directive,'$'+hs);
  1362. end;
  1363. { conditionals already read the comment }
  1364. if (current_scanner^.comment_level>0) then
  1365. current_scanner^.readcomment;
  1366. { we've read the whole comment }
  1367. aktcommentstyle:=comment_none;
  1368. end;
  1369. end;
  1370. {
  1371. $Log$
  1372. Revision 1.11 2000-11-04 14:25:21 florian
  1373. + merged Attila's changes for interfaces, not tested yet
  1374. Revision 1.10 2000/10/31 22:02:51 peter
  1375. * symtable splitted, no real code changes
  1376. Revision 1.9 2000/09/26 10:50:41 jonas
  1377. * initmodeswitches is changed is you change the compiler mode from the
  1378. command line (the -S<x> switches didn't work anymore for changing the
  1379. compiler mode) (merged from fixes branch)
  1380. Revision 1.8 2000/09/24 21:33:47 peter
  1381. * message updates merges
  1382. Revision 1.7 2000/09/24 15:06:27 peter
  1383. * use defines.inc
  1384. Revision 1.6 2000/09/11 17:00:23 florian
  1385. + first implementation of Netware Module support, thanks to
  1386. Armin Diehl ([email protected]) for providing the patches
  1387. Revision 1.5 2000/09/10 21:18:15 peter
  1388. * macro warning (merged)
  1389. Revision 1.4 2000/08/12 15:30:44 peter
  1390. * IDE patch for stream reading (merged)
  1391. Revision 1.3 2000/08/08 19:28:57 peter
  1392. * memdebug/memory patches (merged)
  1393. * only once illegal directive (merged)
  1394. Revision 1.2 2000/07/13 11:32:49 michael
  1395. + removed logs
  1396. }