scandir.inc 40 KB

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