scandir.inc 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. {
  2. $Id$
  3. Copyright (c) 1998 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_L,_DIR_LIBRARYPATH,_DIR_LINK,_DIR_LINKLIB,_DIR_LOCALSYMBOLS,
  35. _DIR_LONGSTRINGS,
  36. _DIR_M,_DIR_MACRO,_DIR_MEMORY,_DIR_MESSAGE,_DIR_MINENUMSIZE,_DIR_MMX,_DIR_MODE,
  37. _DIR_NOTE,_DIR_NOTES,
  38. _DIR_OBJECTPATH,_DIR_OPENSTRINGS,_DIR_OUTPUT_FORMAT,_DIR_OVERFLOWCHECKS,
  39. _DIR_PACKENUM,_DIR_PACKRECORDS,
  40. _DIR_R,_DIR_RANGECHECKS,_DIR_REFERENCEINFO,
  41. _DIR_SATURATION,_DIR_SMARTLINK,_DIR_STACKFRAMES,_DIR_STATIC,_DIR_STOP,
  42. _DIR_TYPEDADDRESS,_DIR_TYPEINFO,
  43. _DIR_UNDEF,_DIR_UNITPATH,
  44. _DIR_VARSTRINGCHECKS,
  45. _DIR_WAIT,_DIR_WARNING,_DIR_WARNINGS,
  46. _DIR_Z1,_DIR_Z2,_DIR_Z4
  47. );
  48. const
  49. firstdirective=_DIR_NONE;
  50. lastdirective=_DIR_Z4;
  51. directive:array[tdirectivetoken] of directivestr=(
  52. {12345678901234567890 (To determine longest string.)}
  53. '',
  54. 'ALIGN',
  55. 'APPTYPE',
  56. 'ASMMODE',
  57. 'ASSERTIONS',
  58. 'BOOLEVAL',
  59. 'D',
  60. 'DEBUGINFO',
  61. 'DEFINE',
  62. 'DESCRIPTION',
  63. 'ELSE',
  64. 'ENDIF',
  65. 'ERROR',
  66. 'EXTENDEDSYNTAX',
  67. 'FATAL',
  68. 'GOTO',
  69. 'HINT',
  70. 'HINTS',
  71. 'I',
  72. {12345678901234567890 (To determine longest string.)}
  73. 'I386_ATT',
  74. 'I386_DIRECT',
  75. 'I386_INTEL',
  76. 'IOCHECKS',
  77. 'IF',
  78. 'IFDEF',
  79. 'IFNDEF',
  80. 'IFOPT',
  81. 'INCLUDE',
  82. 'INCLUDEPATH',
  83. 'INFO',
  84. 'INLINE',
  85. 'L',
  86. 'LIBRARYPATH',
  87. 'LINK',
  88. 'LINKLIB',
  89. 'LOCALSYMBOLS',
  90. 'LONGSTRINGS',
  91. 'M',
  92. {12345678901234567890 (To determine longest string.)}
  93. 'MACRO',
  94. 'MEMORY',
  95. 'MESSAGE',
  96. 'MINENUMSIZE',
  97. 'MMX',
  98. 'MODE',
  99. 'NOTE',
  100. 'NOTES',
  101. 'OBJECTPATH',
  102. 'OPENSTRINGS',
  103. 'OUTPUT_FORMAT',
  104. 'OVERFLOWCHECKS',
  105. 'PACKENUM',
  106. 'PACKRECORDS',
  107. 'R',
  108. 'RANGECHECKS',
  109. 'REFERENCEINFO',
  110. 'SATURATION',
  111. 'SMARTLINK',
  112. {12345678901234567890 (To determine longest string.)}
  113. 'STACKFRAMES',
  114. 'STATIC',
  115. 'STOP',
  116. 'TYPEDADDRESS',
  117. 'TYPEINFO',
  118. 'UNDEF',
  119. 'UNITPATH',
  120. 'VARSTRINGCHECKS',
  121. 'WAIT',
  122. 'WARNING',
  123. 'WARNINGS',
  124. 'Z1',
  125. 'Z2',
  126. 'Z4'
  127. );
  128. function Get_Directive(const hs:string):tdirectivetoken;
  129. var
  130. i : tdirectivetoken;
  131. begin
  132. for i:=firstdirective to lastdirective do
  133. if directive[i]=hs then
  134. begin
  135. Get_Directive:=i;
  136. exit;
  137. end;
  138. Get_Directive:=_DIR_NONE;
  139. end;
  140. {-------------------------------------------
  141. IF Conditional Handling
  142. -------------------------------------------}
  143. var
  144. preprocpat : string;
  145. preproc_token : ttoken;
  146. procedure preproc_consume(t : ttoken);
  147. begin
  148. if t<>preproc_token then
  149. Message(scan_e_preproc_syntax_error);
  150. preproc_token:=current_scanner^.readpreproc;
  151. end;
  152. function read_expr : string;forward;
  153. function read_factor : string;
  154. var
  155. hs : string;
  156. mac : pmacrosym;
  157. len : byte;
  158. begin
  159. if preproc_token=_ID then
  160. begin
  161. if preprocpat='NOT' then
  162. begin
  163. preproc_consume(_ID);
  164. hs:=read_expr;
  165. if hs='0' then
  166. read_factor:='1'
  167. else
  168. read_factor:='0';
  169. end
  170. else
  171. begin
  172. mac:=pmacrosym(macros^.search(hs));
  173. hs:=preprocpat;
  174. preproc_consume(_ID);
  175. if assigned(mac) then
  176. begin
  177. if mac^.defined and assigned(mac^.buftext) then
  178. begin
  179. if mac^.buflen>255 then
  180. begin
  181. len:=255;
  182. Message(scan_w_marco_cut_after_255_chars);
  183. end
  184. else
  185. len:=mac^.buflen;
  186. {$ifndef TP}
  187. {$ifopt H+}
  188. setlength(hs,len);
  189. {$else}
  190. hs[0]:=char(len);
  191. {$endif}
  192. {$else}
  193. hs[0]:=char(len);
  194. {$endif}
  195. move(mac^.buftext^,hs[1],len);
  196. end
  197. else
  198. read_factor:='';
  199. end
  200. else
  201. read_factor:=hs;
  202. end
  203. end
  204. else if preproc_token=_LKLAMMER then
  205. begin
  206. preproc_consume(_LKLAMMER);
  207. read_factor:=read_expr;
  208. preproc_consume(_RKLAMMER);
  209. end
  210. else
  211. Message(scan_e_error_in_preproc_expr);
  212. end;
  213. function read_term : string;
  214. var
  215. hs1,hs2 : string;
  216. begin
  217. hs1:=read_factor;
  218. while true do
  219. begin
  220. if (preproc_token=_ID) then
  221. begin
  222. if preprocpat='AND' then
  223. begin
  224. preproc_consume(_ID);
  225. hs2:=read_factor;
  226. if (hs1<>'0') and (hs2<>'0') then
  227. hs1:='1';
  228. end
  229. else
  230. break;
  231. end
  232. else
  233. break;
  234. end;
  235. read_term:=hs1;
  236. end;
  237. function read_simple_expr : string;
  238. var
  239. hs1,hs2 : string;
  240. begin
  241. hs1:=read_term;
  242. while true do
  243. begin
  244. if (preproc_token=_ID) then
  245. begin
  246. if preprocpat='OR' then
  247. begin
  248. preproc_consume(_ID);
  249. hs2:=read_term;
  250. if (hs1<>'0') or (hs2<>'0') then
  251. hs1:='1';
  252. end
  253. else
  254. break;
  255. end
  256. else
  257. break;
  258. end;
  259. read_simple_expr:=hs1;
  260. end;
  261. function read_expr : string;
  262. var
  263. hs1,hs2 : string;
  264. b : boolean;
  265. t : ttoken;
  266. w : integer;
  267. l1,l2 : longint;
  268. begin
  269. hs1:=read_simple_expr;
  270. t:=preproc_token;
  271. if not(t in [_EQUAL,_UNEQUAL,_LT,_GT,_LTE,_GTE]) then
  272. begin
  273. read_expr:=hs1;
  274. exit;
  275. end;
  276. preproc_consume(t);
  277. hs2:=read_simple_expr;
  278. if is_number(hs1) and is_number(hs2) then
  279. begin
  280. valint(hs1,l1,w);
  281. valint(hs2,l2,w);
  282. case t of
  283. _EQUAL : b:=l1=l2;
  284. _UNEQUAL : b:=l1<>l2;
  285. _LT : b:=l1<l2;
  286. _GT : b:=l1>l2;
  287. _GTE : b:=l1>=l2;
  288. _LTE : b:=l1<=l2;
  289. end;
  290. end
  291. else
  292. begin
  293. case t of
  294. _EQUAL : b:=hs1=hs2;
  295. _UNEQUAL : b:=hs1<>hs2;
  296. _LT : b:=hs1<hs2;
  297. _GT : b:=hs1>hs2;
  298. _GTE : b:=hs1>=hs2;
  299. _LTE : b:=hs1<=hs2;
  300. end;
  301. end;
  302. if b then
  303. read_expr:='1'
  304. else
  305. read_expr:='0';
  306. end;
  307. {-------------------------------------------
  308. Directives
  309. -------------------------------------------}
  310. function is_conditional(t:tdirectivetoken):boolean;
  311. begin
  312. is_conditional:=(t in [_DIR_ENDIF,_DIR_IFDEF,_DIR_IFNDEF,_DIR_IFOPT,_DIR_IF,_DIR_ELSE]);
  313. end;
  314. procedure dir_conditional(t:tdirectivetoken);
  315. var
  316. hs : string;
  317. mac : pmacrosym;
  318. found : boolean;
  319. state : char;
  320. oldaktfilepos : tfileposinfo;
  321. begin
  322. oldaktfilepos:=aktfilepos;
  323. while true do
  324. begin
  325. current_scanner^.gettokenpos;
  326. case t of
  327. _DIR_ENDIF : begin
  328. current_scanner^.poppreprocstack;
  329. end;
  330. _DIR_ELSE : begin
  331. current_scanner^.elsepreprocstack;
  332. end;
  333. _DIR_IFDEF : begin
  334. current_scanner^.skipspace;
  335. hs:=current_scanner^.readid;
  336. mac:=pmacrosym(macros^.search(hs));
  337. if assigned(mac) then
  338. mac^.is_used:=true;
  339. current_scanner^.addpreprocstack(pp_ifdef,assigned(mac) and mac^.defined,hs,scan_c_ifdef_found);
  340. end;
  341. _DIR_IFOPT : begin
  342. current_scanner^.skipspace;
  343. hs:=current_scanner^.readid;
  344. if (length(hs)>1) then
  345. Message(scan_w_illegal_switch)
  346. else
  347. begin
  348. state:=current_scanner^.ReadState;
  349. if state in ['-','+'] then
  350. found:=CheckSwitch(hs[1],state);
  351. end;
  352. current_scanner^.addpreprocstack(pp_ifopt,found,hs,scan_c_ifopt_found);
  353. end;
  354. _DIR_IF : begin
  355. current_scanner^.skipspace;
  356. { start preproc expression scanner }
  357. preproc_token:=current_scanner^.readpreproc;
  358. hs:=read_expr;
  359. current_scanner^.addpreprocstack(pp_if,hs<>'0',hs,scan_c_if_found);
  360. end;
  361. _DIR_IFNDEF : begin
  362. current_scanner^.skipspace;
  363. hs:=current_scanner^.readid;
  364. mac:=pmacrosym(macros^.search(hs));
  365. if assigned(mac) then
  366. mac^.is_used:=true;
  367. current_scanner^.addpreprocstack(pp_ifndef,not(assigned(mac) and mac^.defined),hs,scan_c_ifndef_found);
  368. end;
  369. end;
  370. { accept the text ? }
  371. if (current_scanner^.preprocstack=nil) or current_scanner^.preprocstack^.accept then
  372. break
  373. else
  374. begin
  375. current_scanner^.gettokenpos;
  376. Message(scan_c_skipping_until);
  377. repeat
  378. current_scanner^.skipuntildirective;
  379. t:=Get_Directive(current_scanner^.readid);
  380. until is_conditional(t);
  381. current_scanner^.gettokenpos;
  382. Message1(scan_d_handling_switch,'$'+directive[t]);
  383. end;
  384. end;
  385. oldaktfilepos:=aktfilepos;
  386. end;
  387. procedure dir_define(t:tdirectivetoken);
  388. var
  389. hs : string;
  390. bracketcount : longint;
  391. mac : pmacrosym;
  392. macropos : longint;
  393. macrobuffer : pmacrobuffer;
  394. begin
  395. current_scanner^.skipspace;
  396. hs:=current_scanner^.readid;
  397. mac:=pmacrosym(macros^.search(hs));
  398. if not assigned(mac) then
  399. begin
  400. mac:=new(pmacrosym,init(hs));
  401. mac^.defined:=true;
  402. Message1(parser_m_macro_defined,mac^.name);
  403. macros^.insert(mac);
  404. end
  405. else
  406. begin
  407. Message1(parser_m_macro_defined,mac^.name);
  408. mac^.defined:=true;
  409. { delete old definition }
  410. if assigned(mac^.buftext) then
  411. begin
  412. freemem(mac^.buftext,mac^.buflen);
  413. mac^.buftext:=nil;
  414. end;
  415. end;
  416. mac^.is_used:=true;
  417. if (cs_support_macro in aktmoduleswitches) then
  418. begin
  419. { key words are never substituted }
  420. if is_keyword(hs) then
  421. Message(scan_e_keyword_cant_be_a_macro);
  422. { !!!!!! handle macro params, need we this? }
  423. current_scanner^.skipspace;
  424. { may be a macro? }
  425. if c=':' then
  426. begin
  427. current_scanner^.readchar;
  428. if c='=' then
  429. begin
  430. new(macrobuffer);
  431. macropos:=0;
  432. { parse macro, brackets are counted so it's possible
  433. to have a $ifdef etc. in the macro }
  434. bracketcount:=0;
  435. repeat
  436. current_scanner^.readchar;
  437. case c of
  438. '}' :
  439. if (bracketcount=0) then
  440. break
  441. else
  442. dec(bracketcount);
  443. '{' :
  444. inc(bracketcount);
  445. #26 :
  446. current_scanner^.end_of_file;
  447. end;
  448. macrobuffer^[macropos]:=c;
  449. inc(macropos);
  450. if macropos>maxmacrolen then
  451. Message(scan_f_macro_buffer_overflow);
  452. until false;
  453. { free buffer of macro ?}
  454. if assigned(mac^.buftext) then
  455. freemem(mac^.buftext,mac^.buflen);
  456. { get new mem }
  457. getmem(mac^.buftext,macropos);
  458. mac^.buflen:=macropos;
  459. { copy the text }
  460. move(macrobuffer^,mac^.buftext^,macropos);
  461. dispose(macrobuffer);
  462. end;
  463. end;
  464. end;
  465. end;
  466. procedure dir_undef(t:tdirectivetoken);
  467. var
  468. hs : string;
  469. mac : pmacrosym;
  470. begin
  471. current_scanner^.skipspace;
  472. hs:=current_scanner^.readid;
  473. mac:=pmacrosym(macros^.search(hs));
  474. if not assigned(mac) then
  475. begin
  476. mac:=new(pmacrosym,init(hs));
  477. Message1(parser_m_macro_undefined,mac^.name);
  478. mac^.defined:=false;
  479. macros^.insert(mac);
  480. end
  481. else
  482. begin
  483. Message1(parser_m_macro_undefined,mac^.name);
  484. mac^.defined:=false;
  485. { delete old definition }
  486. if assigned(mac^.buftext) then
  487. begin
  488. freemem(mac^.buftext,mac^.buflen);
  489. mac^.buftext:=nil;
  490. end;
  491. end;
  492. mac^.is_used:=true;
  493. end;
  494. procedure dir_message(t:tdirectivetoken);
  495. var
  496. w : tmsgconst;
  497. begin
  498. case t of
  499. _DIR_STOP,
  500. _DIR_FATAL : w:=scan_f_user_defined;
  501. _DIR_ERROR : w:=scan_e_user_defined;
  502. _DIR_WARNING : w:=scan_w_user_defined;
  503. _DIR_HINT : w:=scan_h_user_defined;
  504. _DIR_NOTE : w:=scan_n_user_defined;
  505. _DIR_MESSAGE,
  506. _DIR_INFO : w:=scan_i_user_defined;
  507. end;
  508. current_scanner^.skipspace;
  509. Message1(w,current_scanner^.readcomment);
  510. end;
  511. procedure dir_moduleswitch(t:tdirectivetoken);
  512. var
  513. sw : tmoduleswitch;
  514. state : char;
  515. begin
  516. sw:=cs_modulenone;
  517. case t of
  518. _DIR_GOTO : sw:=cs_support_goto;
  519. _DIR_MACRO : sw:=cs_support_macro;
  520. _DIR_INLINE : sw:=cs_support_inline;
  521. _DIR_SMARTLINK : sw:=cs_create_smart;
  522. _DIR_STATIC : sw:=cs_static_keyword;
  523. end;
  524. state:=current_scanner^.readstate;
  525. if (sw<>cs_modulenone) and (state in ['-','+']) then
  526. begin
  527. if state='-' then
  528. aktmoduleswitches:=aktmoduleswitches-[sw]
  529. else
  530. aktmoduleswitches:=aktmoduleswitches+[sw];
  531. end;
  532. end;
  533. procedure dir_localswitch(t:tdirectivetoken);
  534. var
  535. sw : tlocalswitch;
  536. state : char;
  537. begin
  538. sw:=cs_localnone;
  539. {$ifdef SUPPORT_MMX}
  540. case t of
  541. _DIR_MMX : sw:=cs_mmx;
  542. _DIR_SATURATION : sw:=cs_mmx_saturation;
  543. end;
  544. {$endif}
  545. state:=current_scanner^.readstate;
  546. if (sw<>cs_localnone) and (state in ['-','+']) then
  547. begin
  548. if state='-' then
  549. aktlocalswitches:=aktlocalswitches-[sw]
  550. else
  551. aktlocalswitches:=aktlocalswitches+[sw];
  552. end;
  553. end;
  554. procedure dir_include(t:tdirectivetoken);
  555. var
  556. hs : string;
  557. path : dirstr;
  558. name : namestr;
  559. ext : extstr;
  560. hp : pinputfile;
  561. i : longint;
  562. found : boolean;
  563. begin
  564. current_scanner^.skipspace;
  565. hs:=current_scanner^.readcomment;
  566. i:=length(hs);
  567. while (i>0) and (hs[i]=' ') do
  568. dec(i);
  569. Delete(hs,i+1,length(hs)-i);
  570. if hs='' then
  571. exit;
  572. if (hs[1]='%') then
  573. begin
  574. { case insensitive }
  575. hs:=upper(hs);
  576. { remove %'s }
  577. Delete(hs,1,1);
  578. if hs[length(hs)]='%' then
  579. Delete(hs,length(hs),1);
  580. { save old }
  581. path:=hs;
  582. { first check for internal macros }
  583. if hs='TIME' then
  584. hs:=gettimestr
  585. else
  586. if hs='DATE' then
  587. hs:=getdatestr
  588. else
  589. if hs='FILE' then
  590. hs:=current_module^.sourcefiles^.get_file_name(aktfilepos.fileindex)
  591. else
  592. if hs='LINE' then
  593. hs:=tostr(aktfilepos.line)
  594. else
  595. if hs='FPCVERSION' then
  596. hs:=version_string
  597. else
  598. if hs='FPCTARGET' then
  599. hs:=target_cpu_string
  600. else
  601. hs:=getenv(hs);
  602. if hs='' then
  603. Message1(scan_w_include_env_not_found,path);
  604. { make it a stringconst }
  605. hs:=''''+hs+'''';
  606. current_scanner^.insertmacro(path,@hs[1],length(hs));
  607. end
  608. else
  609. begin
  610. hs:=FixFileName(hs);
  611. fsplit(hs,path,name,ext);
  612. { look for the include file
  613. 1. specified path,path of current inputfile,current dir
  614. 2. local includepath
  615. 3. global includepath }
  616. found:=false;
  617. path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';.',found);
  618. if (not found) and assigned(current_module^.localincludesearchpath) then
  619. path:=search(name+ext,current_module^.localincludesearchpath^,found);
  620. if (not found) then
  621. path:=search(name+ext,includesearchpath,found);
  622. { shutdown current file }
  623. current_scanner^.tempcloseinputfile;
  624. { load new file }
  625. hp:=new(pinputfile,init(path+name+ext));
  626. current_scanner^.addfile(hp);
  627. if not current_scanner^.openinputfile then
  628. Message1(scan_f_cannot_open_includefile,hs);
  629. Message1(scan_t_start_include_file,current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^);
  630. current_scanner^.reload;
  631. { process first read char }
  632. case c of
  633. #26 : current_scanner^.reload;
  634. #10,
  635. #13 : current_scanner^.linebreak;
  636. end;
  637. { register for refs }
  638. current_module^.sourcefiles^.register_file(hp);
  639. end;
  640. end;
  641. procedure dir_description(t:tdirectivetoken);
  642. begin
  643. end;
  644. procedure dir_linkobject(t:tdirectivetoken);
  645. var
  646. s : string;
  647. begin
  648. current_scanner^.skipspace;
  649. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.objext);
  650. current_module^.linkotherofiles.insert(s,link_allways);
  651. end;
  652. procedure dir_resource(t:tdirectivetoken);
  653. var
  654. s : string;
  655. begin
  656. current_scanner^.skipspace;
  657. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.resext);
  658. if target_info.res<>res_none then
  659. current_module^.resourcefiles.insert(FixFileName(s))
  660. else
  661. Message(scan_e_resourcefiles_not_supported);
  662. end;
  663. procedure dir_linklib(t:tdirectivetoken);
  664. begin
  665. current_scanner^.skipspace;
  666. current_scanner^.readstring;
  667. current_module^.linkOtherSharedLibs.insert(orgpattern,link_allways);
  668. end;
  669. procedure dir_outputformat(t:tdirectivetoken);
  670. begin
  671. if not current_module^.in_global then
  672. Message(scan_w_switch_is_global)
  673. else
  674. begin
  675. current_scanner^.skipspace;
  676. if set_string_asm(current_scanner^.readid) then
  677. aktoutputformat:=target_asm.id
  678. else
  679. Message(scan_w_illegal_switch);
  680. end;
  681. end;
  682. procedure dir_unitpath(t:tdirectivetoken);
  683. begin
  684. if not current_module^.in_global then
  685. Message(scan_w_switch_is_global)
  686. else
  687. begin
  688. current_scanner^.skipspace;
  689. if assigned(current_module^.localunitsearchpath) then
  690. stringdispose(current_module^.localunitsearchpath);
  691. current_module^.localunitsearchpath:=stringdup(current_scanner^.readcomment);
  692. end;
  693. end;
  694. procedure dir_includepath(t:tdirectivetoken);
  695. begin
  696. if not current_module^.in_global then
  697. Message(scan_w_switch_is_global)
  698. else
  699. begin
  700. current_scanner^.skipspace;
  701. if assigned(current_module^.localincludesearchpath) then
  702. stringdispose(current_module^.localincludesearchpath);
  703. current_module^.localincludesearchpath:=stringdup(current_scanner^.readcomment);
  704. end;
  705. end;
  706. procedure dir_librarypath(t:tdirectivetoken);
  707. begin
  708. if not current_module^.in_global then
  709. Message(scan_w_switch_is_global)
  710. else
  711. begin
  712. current_scanner^.skipspace;
  713. if assigned(current_module^.locallibrarysearchpath) then
  714. stringdispose(current_module^.locallibrarysearchpath);
  715. current_module^.locallibrarysearchpath:=stringdup(current_scanner^.readcomment);
  716. end;
  717. end;
  718. procedure dir_objectpath(t:tdirectivetoken);
  719. begin
  720. if not current_module^.in_global then
  721. Message(scan_w_switch_is_global)
  722. else
  723. begin
  724. current_scanner^.skipspace;
  725. if assigned(current_module^.localobjectsearchpath) then
  726. stringdispose(current_module^.localobjectsearchpath);
  727. current_module^.localobjectsearchpath:=stringdup(current_scanner^.readcomment);
  728. end;
  729. end;
  730. procedure dir_mode(t:tdirectivetoken);
  731. begin
  732. if not current_module^.in_global then
  733. Message(scan_w_switch_is_global)
  734. else
  735. begin
  736. current_scanner^.skipspace;
  737. current_scanner^.readstring;
  738. if pattern='DEFAULT' then
  739. aktmodeswitches:=initmodeswitches
  740. else
  741. if pattern='DELPHI' then
  742. aktmodeswitches:=delphimodeswitches
  743. else
  744. if pattern='TP' then
  745. aktmodeswitches:=tpmodeswitches
  746. else
  747. if pattern='FPC' then
  748. aktmodeswitches:=fpcmodeswitches
  749. else
  750. if pattern='OBJFPC' then
  751. aktmodeswitches:=objfpcmodeswitches
  752. else
  753. if pattern='GPC' then
  754. aktmodeswitches:=gpcmodeswitches
  755. else
  756. Message(scan_w_illegal_switch);
  757. end;
  758. end;
  759. procedure dir_packrecords(t:tdirectivetoken);
  760. var
  761. hs : string;
  762. begin
  763. current_scanner^.skipspace;
  764. if not(c in ['0'..'9']) then
  765. begin
  766. hs:=current_scanner^.readid;
  767. if (hs='C') then
  768. aktpackrecords:=packrecord_C
  769. else
  770. if (hs='NORMAL') or (hs='DEFAULT') then
  771. aktpackrecords:=packrecord_2
  772. else
  773. Message(scan_w_only_pack_records);
  774. end
  775. else
  776. begin
  777. case current_scanner^.readval of
  778. 1 : aktpackrecords:=packrecord_1;
  779. 2 : aktpackrecords:=packrecord_2;
  780. 4 : aktpackrecords:=packrecord_4;
  781. 8 : aktpackrecords:=packrecord_8;
  782. 16 : aktpackrecords:=packrecord_16;
  783. 32 : aktpackrecords:=packrecord_32;
  784. else
  785. Message(scan_w_only_pack_records);
  786. end;
  787. end;
  788. end;
  789. procedure dir_packenum(t:tdirectivetoken);
  790. var
  791. hs : string;
  792. begin
  793. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  794. begin
  795. aktpackenum:=ord(pattern[2])-ord('0');
  796. exit;
  797. end;
  798. current_scanner^.skipspace;
  799. if not(c in ['0'..'9']) then
  800. begin
  801. hs:=current_scanner^.readid;
  802. if (hs='NORMAL') or (hs='DEFAULT') then
  803. aktpackenum:=4
  804. else
  805. Message(scan_w_only_pack_enum);
  806. end
  807. else
  808. begin
  809. case current_scanner^.readval of
  810. 1 : aktpackenum:=1;
  811. 2 : aktpackenum:=2;
  812. 4 : aktpackenum:=4;
  813. else
  814. Message(scan_w_only_pack_enum);
  815. end;
  816. end;
  817. end;
  818. procedure dir_apptype(t:tdirectivetoken);
  819. var
  820. hs : string;
  821. begin
  822. if target_info.target<>target_i386_win32 then
  823. Message(scan_w_app_type_not_support);
  824. if not current_module^.in_global then
  825. Message(scan_w_switch_is_global)
  826. else
  827. begin
  828. current_scanner^.skipspace;
  829. hs:=current_scanner^.readid;
  830. if hs='GUI' then
  831. apptype:=at_gui
  832. else if hs='CONSOLE' then
  833. apptype:=at_cui
  834. else
  835. Message1(scan_w_unsupported_app_type,hs);
  836. end;
  837. end;
  838. procedure dir_wait(t:tdirectivetoken);
  839. var had_info : boolean;
  840. begin
  841. had_info:=(status.verbosity and V_Info)<>0;
  842. { this message should allways appear !! }
  843. status.verbosity:=status.verbosity or V_Info;
  844. Message(scan_i_press_enter);
  845. readln;
  846. If not(had_info) then
  847. status.verbosity:=status.verbosity and (not V_Info);
  848. end;
  849. procedure dir_asmmode(t:tdirectivetoken);
  850. var
  851. s : string;
  852. begin
  853. If Inside_asm_statement then
  854. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  855. current_scanner^.skipspace;
  856. s:=current_scanner^.readid;
  857. if s='DEFAULT' then
  858. aktasmmode:=initasmmode
  859. else
  860. if not set_string_asmmode(s,aktasmmode) then
  861. Message1(scan_w_unsupported_asmmode_specifier,s);
  862. end;
  863. procedure dir_oldasmmode(t:tdirectivetoken);
  864. begin
  865. If Inside_asm_statement then
  866. Message1(scan_w_no_asm_reader_switch_inside_asm,directive[t]);
  867. {$ifdef i386}
  868. case t of
  869. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  870. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  871. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  872. end;
  873. {$endif i386}
  874. end;
  875. procedure dir_delphiswitch(t:tdirectivetoken);
  876. var
  877. sw,state : char;
  878. begin
  879. case t of
  880. _DIR_ALIGN : sw:='A';
  881. _DIR_ASSERTIONS : sw:='C';
  882. _DIR_BOOLEVAL : sw:='B';
  883. _DIR_DEBUGINFO : sw:='D';
  884. _DIR_IOCHECKS : sw:='I';
  885. _DIR_LOCALSYMBOLS : sw:='L';
  886. _DIR_LONGSTRINGS : sw:='H';
  887. _DIR_OPENSTRINGS : sw:='P';
  888. _DIR_OVERFLOWCHECKS : sw:='Q';
  889. _DIR_RANGECHECKS : sw:='R';
  890. _DIR_REFERENCEINFO : sw:='Y';
  891. _DIR_STACKFRAMES : sw:='W';
  892. _DIR_TYPEDADDRESS : sw:='T';
  893. _DIR_TYPEINFO : sw:='M';
  894. _DIR_VARSTRINGCHECKS : sw:='V';
  895. else
  896. exit;
  897. end;
  898. { c contains the next char, a + or - would be fine }
  899. state:=current_scanner^.readstate;
  900. if state in ['-','+'] then
  901. HandleSwitch(sw,state);
  902. end;
  903. procedure dir_memory(t:tdirectivetoken);
  904. var
  905. l : longint;
  906. begin
  907. current_scanner^.skipspace;
  908. l:=current_scanner^.readval;
  909. if l>1024 then
  910. stacksize:=l;
  911. current_scanner^.skipspace;
  912. if c=',' then
  913. begin
  914. current_scanner^.readchar;
  915. current_scanner^.skipspace;
  916. l:=current_scanner^.readval;
  917. if l>1024 then
  918. heapsize:=l;
  919. end;
  920. if c=',' then
  921. begin
  922. current_scanner^.readchar;
  923. current_scanner^.skipspace;
  924. l:=current_scanner^.readval;
  925. { Ignore this value, because the limit is set by the OS
  926. info and shouldn't be changed by the user (PFV) }
  927. end;
  928. end;
  929. procedure dir_setverbose(t:tdirectivetoken);
  930. var
  931. flag,
  932. state : char;
  933. begin
  934. case t of
  935. _DIR_HINTS : flag:='H';
  936. _DIR_WARNINGS : flag:='W';
  937. _DIR_NOTES : flag:='N';
  938. else
  939. exit;
  940. end;
  941. { support ON/OFF }
  942. state:=current_scanner^.ReadState;
  943. SetVerbosity(flag+state);
  944. end;
  945. type
  946. tdirectiveproc=procedure(t:tdirectivetoken);
  947. const
  948. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  949. {_DIR_NONE} nil,
  950. {_DIR_ALIGN} dir_delphiswitch,
  951. {_DIR_APPTYPE} dir_apptype,
  952. {_DIR_ASMMODE} dir_asmmode,
  953. {_DIR_ASSERTION} dir_delphiswitch,
  954. {_DIR_BOOLEVAL} dir_delphiswitch,
  955. {_DIR_D} dir_description,
  956. {_DIR_DEBUGINFO} dir_delphiswitch,
  957. {_DIR_DEFINE} dir_define,
  958. {_DIR_DESCRIPTION} dir_description,
  959. {_DIR_ELSE} dir_conditional,
  960. {_DIR_ENDIF} dir_conditional,
  961. {_DIR_ERROR} dir_message,
  962. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  963. {_DIR_FATAL} dir_message,
  964. {_DIR_GOTO} dir_moduleswitch,
  965. {_DIR_HINT} dir_message,
  966. {_DIR_HINTS} dir_setverbose,
  967. {_DIR_I} dir_include,
  968. {_DIR_I386_ATT} dir_oldasmmode,
  969. {_DIR_I386_DIRECT} dir_oldasmmode,
  970. {_DIR_I386_INTEL} dir_oldasmmode,
  971. {_DIR_IOCHECKS} dir_delphiswitch,
  972. {_DIR_IF} dir_conditional,
  973. {_DIR_IFDEF} dir_conditional,
  974. {_DIR_IFNDEF} dir_conditional,
  975. {_DIR_IFOPT} dir_conditional,
  976. {_DIR_INCLUDE} dir_include,
  977. {_DIR_INCLUDEPATH} dir_includepath,
  978. {_DIR_INFO} dir_message,
  979. {_DIR_INLINE} dir_moduleswitch,
  980. {_DIR_L} dir_linkobject,
  981. {_DIR_LIBRARYPATH} dir_librarypath,
  982. {_DIR_LINK} dir_linkobject,
  983. {_DIR_LINKLIB} dir_linklib,
  984. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  985. {_DIR_LONGSTRINGS} dir_delphiswitch,
  986. {_DIR_M} dir_memory,
  987. {_DIR_MACRO} dir_moduleswitch,
  988. {_DIR_MEMORY} dir_memory,
  989. {_DIR_MESSAGE} dir_message,
  990. {_DIR_MINENUMSIZE} dir_packenum,
  991. {_DIR_MMX} dir_localswitch,
  992. {_DIR_MODE} dir_mode,
  993. {_DIR_NOTE} dir_message,
  994. {_DIR_NOTES} dir_setverbose,
  995. {_DIR_OBJECTPATH} dir_objectpath,
  996. {_DIR_OPENSTRINGS} dir_delphiswitch,
  997. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  998. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  999. {_DIR_PACKENUM} dir_packenum,
  1000. {_DIR_PACKRECORDS} dir_packrecords,
  1001. {_DIR_R} dir_resource,
  1002. {_DIR_RANGECHECKS} dir_delphiswitch,
  1003. {_DIR_REFERENCEINFO} dir_delphiswitch,
  1004. {_DIR_SATURATION} dir_localswitch,
  1005. {_DIR_SMARTLINK} dir_moduleswitch,
  1006. {_DIR_STACKFRAMES} dir_delphiswitch,
  1007. {_DIR_STATIC} dir_moduleswitch,
  1008. {_DIR_STOP} dir_message,
  1009. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  1010. {_DIR_TYPEINFO} dir_delphiswitch,
  1011. {_DIR_UNDEF} dir_undef,
  1012. {_DIR_UNITPATH} dir_unitpath,
  1013. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  1014. {_DIR_WAIT} dir_wait,
  1015. {_DIR_WARNING} dir_message,
  1016. {_DIR_WARNINGS} dir_setverbose,
  1017. {_DIR_Z1} dir_packenum,
  1018. {_DIR_Z2} dir_packenum,
  1019. {_DIR_Z4} dir_packenum
  1020. );
  1021. {-------------------------------------------
  1022. Main switches handling
  1023. -------------------------------------------}
  1024. procedure handledirectives;
  1025. var
  1026. t : tdirectivetoken;
  1027. p : tdirectiveproc;
  1028. hs : string;
  1029. begin
  1030. current_scanner^.gettokenpos;
  1031. current_scanner^.readchar; {Remove the $}
  1032. hs:=current_scanner^.readid;
  1033. Message1(scan_d_handling_switch,'$'+hs);
  1034. if hs='' then
  1035. Message1(scan_w_illegal_switch,'$'+hs);
  1036. { Check for compiler switches }
  1037. while (length(hs)=1) and (c in ['-','+']) do
  1038. begin
  1039. HandleSwitch(hs[1],c);
  1040. current_scanner^.readchar; {Remove + or -}
  1041. if c=',' then
  1042. begin
  1043. current_scanner^.readchar; {Remove , }
  1044. { read next switch, support $v+,$+}
  1045. hs:=current_scanner^.readid;
  1046. if (hs='') then
  1047. begin
  1048. if (c='$') and (m_fpc in aktmodeswitches) then
  1049. begin
  1050. current_scanner^.readchar; { skip $ }
  1051. hs:=current_scanner^.readid;
  1052. end;
  1053. if (hs='') then
  1054. Message1(scan_w_illegal_directive,'$'+c);
  1055. end
  1056. else
  1057. Message1(scan_d_handling_switch,'$'+hs);
  1058. end
  1059. else
  1060. hs:='';
  1061. end;
  1062. { directives may follow switches after a , }
  1063. if hs<>'' then
  1064. begin
  1065. t:=Get_Directive(hs);
  1066. if t<>_DIR_NONE then
  1067. begin
  1068. p:=directiveproc[t];
  1069. {$ifndef TP}
  1070. if assigned(p) then
  1071. {$else}
  1072. if @p<>nil then
  1073. {$endif}
  1074. p(t);
  1075. end
  1076. else
  1077. Message1(scan_w_illegal_directive,'$'+hs);
  1078. { conditionals already read the comment }
  1079. if (current_scanner^.comment_level>0) then
  1080. current_scanner^.readcomment;
  1081. { we've read the whole comment }
  1082. aktcommentstyle:=comment_none;
  1083. end;
  1084. end;
  1085. {
  1086. $Log$
  1087. Revision 1.66 1999-11-06 14:34:26 peter
  1088. * truncated log to 20 revs
  1089. Revision 1.65 1999/10/30 12:32:30 peter
  1090. * fixed line counter when the first line had #10 only. This was buggy
  1091. for both the main file as for include files
  1092. Revision 1.64 1999/09/27 23:38:17 peter
  1093. * bracket support for macro define
  1094. Revision 1.63 1999/09/20 16:39:02 peter
  1095. * cs_create_smart instead of cs_smartlink
  1096. * -CX is create smartlink
  1097. * -CD is create dynamic, but does nothing atm.
  1098. Revision 1.62 1999/09/03 10:00:49 peter
  1099. * included the 1.60 version of Pierre which was lost !
  1100. Revision 1.61 1999/09/02 18:47:46 daniel
  1101. * Could not compile with TP, some arrays moved to heap
  1102. * NOAG386BIN default for TP
  1103. * AG386* files were not compatible with TP, fixed.
  1104. Revision 1.60 1999/08/31 15:55:45 pierre
  1105. + tmacrosym.is_used set
  1106. Revision 1.59 1999/08/05 16:53:10 peter
  1107. * V_Fatal=1, all other V_ are also increased
  1108. * Check for local procedure when assigning procvar
  1109. * fixed comment parsing because directives
  1110. * oldtp mode directives better supported
  1111. * added some messages to errore.msg
  1112. Revision 1.58 1999/08/04 13:03:03 jonas
  1113. * all tokens now start with an underscore
  1114. * PowerPC compiles!!
  1115. Revision 1.57 1999/07/26 14:55:36 florian
  1116. * $mode gives now a warning if an unknown mode keyword follows
  1117. Revision 1.56 1999/07/23 16:05:27 peter
  1118. * alignment is now saved in the symtable
  1119. * C alignment added for records
  1120. * PPU version increased to solve .12 <-> .13 probs
  1121. Revision 1.55 1999/07/16 10:04:36 peter
  1122. * merged
  1123. Revision 1.54 1999/07/03 00:29:58 peter
  1124. * new link writing to the ppu, one .ppu is needed for all link types,
  1125. static (.o) is now always created also when smartlinking is used
  1126. Revision 1.53.2.1 1999/07/16 09:53:06 peter
  1127. * ignore maxheapsize
  1128. Revision 1.53 1999/06/02 22:44:18 pierre
  1129. * previous wrong log corrected
  1130. Revision 1.52 1999/06/02 22:25:48 pierre
  1131. * changed $ifdef FPC @ into $ifndef TP
  1132. Revision 1.51 1999/04/07 14:36:45 pierre
  1133. + better preproc stack checking and report
  1134. Revision 1.50 1999/03/31 13:55:20 peter
  1135. * assembler inlining working for ag386bin
  1136. Revision 1.49 1999/03/26 00:05:44 peter
  1137. * released valintern
  1138. + deffile is now removed when compiling is finished
  1139. * ^( compiles now correct
  1140. + static directive
  1141. * shrd fixed
  1142. Revision 1.48 1999/03/25 16:55:34 peter
  1143. + unitpath,librarypath,includepath,objectpath directives
  1144. Revision 1.47 1999/02/22 13:07:05 pierre
  1145. + -b and -bl options work !
  1146. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  1147. is not enabled when quitting global section
  1148. * local vars and procedures are not yet stored into PPU
  1149. }