scandir.inc 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487
  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 : tinputfile;
  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. { save old postion and decrease linebreak }
  658. if c=newline then
  659. dec(current_scanner^.line_no);
  660. dec(longint(current_scanner^.inputpointer));
  661. { shutdown current file }
  662. current_scanner^.tempcloseinputfile;
  663. { load new file }
  664. hp:=do_openinputfile(path+name+ext);
  665. current_scanner^.addfile(hp);
  666. if not current_scanner^.openinputfile then
  667. Message1(scan_f_cannot_open_includefile,hs);
  668. Message1(scan_t_start_include_file,current_scanner^.inputfile.path^+current_scanner^.inputfile.name^);
  669. current_scanner^.reload;
  670. { process first read char }
  671. case c of
  672. #26 : current_scanner^.reload;
  673. #10,
  674. #13 : current_scanner^.linebreak;
  675. end;
  676. { register for refs }
  677. current_module.sourcefiles.register_file(hp);
  678. end;
  679. end;
  680. procedure dir_description(t:tdirectivetoken);
  681. begin
  682. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then
  683. Message(scan_w_decription_not_support);
  684. { change description global var in all cases }
  685. { it not used but in win32, os2 and netware }
  686. current_scanner^.skipspace;
  687. description:=current_scanner^.readcomment;
  688. end;
  689. procedure dir_version(t:tdirectivetoken);
  690. var
  691. major, minor, revision : longint;
  692. error : integer;
  693. begin
  694. if not (target_info.target in [target_i386_os2,target_i386_win32,target_i386_netware]) then // AD
  695. begin
  696. Message(scan_n_version_not_support);
  697. exit;
  698. end;
  699. if (compile_level<>1) then
  700. Message(scan_n_only_exe_version)
  701. else
  702. begin
  703. { change description global var in all cases }
  704. { it not used but in win32, os2 and netware }
  705. current_scanner^.skipspace;
  706. { we should only accept Major.Minor format for win32 and os2 }
  707. current_scanner^.readnumber;
  708. major:=0;
  709. minor:=0;
  710. revision:=0;
  711. valint(pattern,major,error);
  712. if error<>0 then
  713. begin
  714. Message1(scan_w_wrong_version_ignored,pattern);
  715. exit;
  716. end;
  717. if c='.' then
  718. begin
  719. current_scanner^.readchar;
  720. current_scanner^.readnumber;
  721. valint(pattern,minor,error);
  722. if error<>0 then
  723. begin
  724. Message1(scan_w_wrong_version_ignored,tostr(major)+'.'+pattern);
  725. exit;
  726. end;
  727. if (c='.') and
  728. (target_info.target = target_i386_netware) then // AD
  729. begin
  730. current_scanner^.readchar;
  731. current_scanner^.readnumber;
  732. valint(pattern,revision,error);
  733. if error<>0 then
  734. begin
  735. Message1(scan_w_wrong_version_ignored,tostr(revision)+'.'+pattern);
  736. exit;
  737. end;
  738. dllmajor:=major;
  739. dllminor:=minor;
  740. dllrevision:=revision;
  741. dllversion:=tostr(major)+','+tostr(minor)+','+tostr(revision);
  742. end
  743. else
  744. begin
  745. dllmajor:=major;
  746. dllminor:=minor;
  747. dllversion:=tostr(major)+'.'+tostr(minor);
  748. end;
  749. end
  750. else
  751. dllversion:=tostr(major);
  752. end;
  753. end;
  754. procedure dir_linkobject(t:tdirectivetoken);
  755. var
  756. s : string;
  757. begin
  758. current_scanner^.skipspace;
  759. s:=AddExtension(FixFileName(current_scanner^.readcomment),target_info.objext);
  760. current_module.linkotherofiles.add(s,link_allways);
  761. end;
  762. procedure dir_resource(t:tdirectivetoken);
  763. var
  764. s : string;
  765. begin
  766. current_scanner^.skipspace;
  767. s:=current_scanner^.readcomment;
  768. { replace * with current module name.
  769. This should always be defined. }
  770. if s[1]='*' then
  771. if Assigned(Current_Module) then
  772. begin
  773. delete(S,1,1);
  774. insert(lower(current_module.modulename^),S,1);
  775. end;
  776. s:=AddExtension(FixFileName(s),target_info.resext);
  777. if target_info.res<>res_none then
  778. if (target_info.res = res_i386_emx) and
  779. not (Current_module.ResourceFiles.Empty) then
  780. Message(scan_w_only_one_resourcefile_supported)
  781. else
  782. current_module.resourcefiles.insert(FixFileName(s))
  783. else
  784. Message(scan_e_resourcefiles_not_supported);
  785. end;
  786. {$ifndef PAVEL_LINKLIB}
  787. procedure dir_linklib(t:tdirectivetoken);
  788. var
  789. s : string;
  790. quote : char;
  791. begin
  792. current_scanner^.skipspace;
  793. { This way spaces are also allowed in library names
  794. if quoted PM }
  795. if (c='''') or (c='"') then
  796. begin
  797. quote:=c;
  798. current_scanner^.readchar;
  799. s:=current_scanner^.readcomment;
  800. if pos(quote,s)>0 then
  801. s:=copy(s,1,pos(quote,s)-1);
  802. end
  803. else
  804. begin
  805. current_scanner^.readstring;
  806. s:=orgpattern;
  807. if c='.' then
  808. begin
  809. s:=s+'.';
  810. current_scanner^.readchar;
  811. current_scanner^.readstring;
  812. s:=s+orgpattern;
  813. end;
  814. end;
  815. current_module.linkOtherSharedLibs.add(s,link_allways);
  816. end;
  817. {$else PAVEL_LINKLIB}
  818. procedure dir_linklib(t:tdirectivetoken);
  819. var
  820. s:string;
  821. libname,linkmodeStr:string;
  822. p:longint;
  823. type
  824. tLinkMode=(lm_dynamic,lm_static);
  825. var
  826. linkMode:tLinkMode;
  827. function ExtractLinkMode:tLinkMode;
  828. var
  829. p:longint;
  830. begin
  831. p:=pos(',',linkmodeStr);
  832. if p>0 then
  833. linkmodeStr:=copy(linkmodeStr,1,pred(p));
  834. for p:=1 to length(linkmodeStr)do
  835. linkmodeStr[p]:=upcase(linkmodeStr[p]);
  836. if linkmodeStr='STATIC' then
  837. ExtractLinkMode:=lm_static
  838. else
  839. ExtractLinkMode:=lm_dynamic
  840. end;
  841. procedure MangleLibName(mode:tLinkMode);
  842. begin
  843. if (libname[1]='''')and(libname[length(libname)]='''')then
  844. begin
  845. delete(libname,1,1);
  846. delete(libname,length(libname),1);
  847. end
  848. else
  849. begin
  850. libname:=target_os.libprefix+libname;
  851. case mode of
  852. lm_static:
  853. libname:=AddExtension(FixFileName(libname),target_os.staticlibext);
  854. lm_dynamic:
  855. libname:=AddExtension(FixFileName(libname),target_os.sharedlibext);
  856. end;
  857. end;
  858. end;
  859. begin
  860. current_scanner^.skipspace;
  861. s:=current_scanner^.readcomment;
  862. p:=pos(',',s);
  863. if p=0 then
  864. begin
  865. libname:=s;
  866. linkmodeStr:=''
  867. end
  868. else
  869. begin
  870. libname:=copy(s,1,pred(p));
  871. linkmodeStr:=copy(s,succ(p),255);
  872. end;
  873. if(libname='')or(libname='''''')then
  874. exit;
  875. linkMode:=ExtractLinkMode;
  876. MangleLibName(linkMode);
  877. if linkMode=lm_static then
  878. current_module.linkOtherStaticLibs.add(FixFileName(libname),link_allways)
  879. else
  880. current_module.linkOtherSharedLibs.add(FixFileName(libname),link_allways);
  881. end;
  882. {$endif PAVEL_LINKLIB}
  883. procedure dir_outputformat(t:tdirectivetoken);
  884. begin
  885. if not current_module.in_global then
  886. Message(scan_w_switch_is_global)
  887. else
  888. begin
  889. current_scanner^.skipspace;
  890. if set_string_asm(current_scanner^.readid) then
  891. aktoutputformat:=target_asm.id
  892. else
  893. Message1(scan_w_illegal_switch,pattern);
  894. end;
  895. end;
  896. procedure dir_unitpath(t:tdirectivetoken);
  897. begin
  898. if not current_module.in_global then
  899. Message(scan_w_switch_is_global)
  900. else
  901. begin
  902. current_scanner^.skipspace;
  903. current_module.localunitsearchpath.AddPath(current_scanner^.readcomment,false);
  904. end;
  905. end;
  906. procedure dir_includepath(t:tdirectivetoken);
  907. begin
  908. if not current_module.in_global then
  909. Message(scan_w_switch_is_global)
  910. else
  911. begin
  912. current_scanner^.skipspace;
  913. current_module.localincludesearchpath.AddPath(current_scanner^.readcomment,false);
  914. end;
  915. end;
  916. procedure dir_librarypath(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.locallibrarysearchpath.AddPath(current_scanner^.readcomment,false);
  924. end;
  925. end;
  926. procedure dir_objectpath(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.localobjectsearchpath.AddPath(current_scanner^.readcomment,false);
  934. end;
  935. end;
  936. procedure dir_mode(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_scanner^.readstring;
  944. if not SetCompileMode(pattern,false) then
  945. Message1(scan_w_illegal_switch,pattern);
  946. end;
  947. end;
  948. procedure dir_packrecords(t:tdirectivetoken);
  949. var
  950. hs : string;
  951. begin
  952. current_scanner^.skipspace;
  953. if not(c in ['0'..'9']) then
  954. begin
  955. hs:=current_scanner^.readid;
  956. if (hs='C') then
  957. aktpackrecords:=packrecord_C
  958. else
  959. if (hs='NORMAL') or (hs='DEFAULT') then
  960. aktpackrecords:=packrecord_2
  961. else
  962. Message(scan_w_only_pack_records);
  963. end
  964. else
  965. begin
  966. case current_scanner^.readval of
  967. 1 : aktpackrecords:=packrecord_1;
  968. 2 : aktpackrecords:=packrecord_2;
  969. 4 : aktpackrecords:=packrecord_4;
  970. 8 : aktpackrecords:=packrecord_8;
  971. 16 : aktpackrecords:=packrecord_16;
  972. 32 : aktpackrecords:=packrecord_32;
  973. else
  974. Message(scan_w_only_pack_records);
  975. end;
  976. end;
  977. end;
  978. procedure dir_maxfpuregisters(t:tdirectivetoken);
  979. var
  980. l : longint;
  981. hs : string;
  982. begin
  983. current_scanner^.skipspace;
  984. if not(c in ['0'..'9']) then
  985. begin
  986. hs:=current_scanner^.readid;
  987. if (hs='NORMAL') or (hs='DEFAULT') then
  988. aktmaxfpuregisters:=-1
  989. else
  990. Message(scan_e_invalid_maxfpureg_value);
  991. end
  992. else
  993. begin
  994. l:=current_scanner^.readval;
  995. case l of
  996. 0..8:
  997. aktmaxfpuregisters:=l;
  998. else
  999. Message(scan_e_invalid_maxfpureg_value);
  1000. end;
  1001. end;
  1002. end;
  1003. procedure dir_packenum(t:tdirectivetoken);
  1004. var
  1005. hs : string;
  1006. begin
  1007. if t in [_DIR_Z1,_DIR_Z2,_DIR_Z4] then
  1008. begin
  1009. aktpackenum:=ord(pattern[2])-ord('0');
  1010. exit;
  1011. end;
  1012. current_scanner^.skipspace;
  1013. if not(c in ['0'..'9']) then
  1014. begin
  1015. hs:=current_scanner^.readid;
  1016. if (hs='NORMAL') or (hs='DEFAULT') then
  1017. aktpackenum:=4
  1018. else
  1019. Message(scan_w_only_pack_enum);
  1020. end
  1021. else
  1022. begin
  1023. case current_scanner^.readval of
  1024. 1 : aktpackenum:=1;
  1025. 2 : aktpackenum:=2;
  1026. 4 : aktpackenum:=4;
  1027. else
  1028. Message(scan_w_only_pack_enum);
  1029. end;
  1030. end;
  1031. end;
  1032. {$ifdef testvarsets}
  1033. procedure dir_setalloc(t:tdirectivetoken);
  1034. var
  1035. hs : string;
  1036. begin
  1037. current_scanner^.skipspace;
  1038. if not(c in ['1','2','4']) then
  1039. begin
  1040. hs:=current_scanner^.readid;
  1041. if (hs='FIXED') or ((hs='DEFAULT') OR (hs='NORMAL')) then
  1042. aktsetalloc:=0 {Fixed mode, sets are 4 or 32 bytes}
  1043. else
  1044. Message(scan_w_only_packset);
  1045. end
  1046. else
  1047. begin
  1048. case current_scanner^.readval of
  1049. 1 : aktpackenum:=1;
  1050. 2 : aktpackenum:=2;
  1051. 4 : aktpackenum:=4;
  1052. else
  1053. Message(scan_w_only_packset);
  1054. end;
  1055. end;
  1056. end;
  1057. {$ENDIF}
  1058. procedure dir_apptype(t:tdirectivetoken);
  1059. var
  1060. hs : string;
  1061. begin
  1062. if target_info.target<>target_i386_win32 then
  1063. Message(scan_w_app_type_not_support);
  1064. if not current_module.in_global then
  1065. Message(scan_w_switch_is_global)
  1066. else
  1067. begin
  1068. current_scanner^.skipspace;
  1069. hs:=current_scanner^.readid;
  1070. if hs='GUI' then
  1071. apptype:=app_gui
  1072. else if hs='CONSOLE' then
  1073. apptype:=app_cui
  1074. else
  1075. Message1(scan_w_unsupported_app_type,hs);
  1076. end;
  1077. end;
  1078. procedure dir_wait(t:tdirectivetoken);
  1079. var had_info : boolean;
  1080. begin
  1081. had_info:=(status.verbosity and V_Info)<>0;
  1082. { this message should allways appear !! }
  1083. status.verbosity:=status.verbosity or V_Info;
  1084. Message(scan_i_press_enter);
  1085. readln;
  1086. If not(had_info) then
  1087. status.verbosity:=status.verbosity and (not V_Info);
  1088. end;
  1089. procedure dir_asmmode(t:tdirectivetoken);
  1090. var
  1091. s : string;
  1092. begin
  1093. current_scanner^.skipspace;
  1094. s:=current_scanner^.readid;
  1095. If Inside_asm_statement then
  1096. Message1(scan_w_no_asm_reader_switch_inside_asm,s);
  1097. if s='DEFAULT' then
  1098. aktasmmode:=initasmmode
  1099. else
  1100. if not set_string_asmmode(s,aktasmmode) then
  1101. Message1(scan_w_unsupported_asmmode_specifier,s);
  1102. end;
  1103. procedure dir_oldasmmode(t:tdirectivetoken);
  1104. begin
  1105. If Inside_asm_statement then
  1106. Message1(scan_w_no_asm_reader_switch_inside_asm,directive[t]);
  1107. {$ifdef i386}
  1108. case t of
  1109. _DIR_I386_ATT : aktasmmode:=asmmode_i386_att;
  1110. _DIR_I386_DIRECT : aktasmmode:=asmmode_i386_direct;
  1111. _DIR_I386_INTEL : aktasmmode:=asmmode_i386_intel;
  1112. end;
  1113. {$endif i386}
  1114. end;
  1115. procedure dir_delphiswitch(t:tdirectivetoken);
  1116. var
  1117. sw,state : char;
  1118. begin
  1119. case t of
  1120. _DIR_ALIGN : sw:='A';
  1121. _DIR_ASSERTIONS : sw:='C';
  1122. _DIR_BOOLEVAL : sw:='B';
  1123. _DIR_DEBUGINFO : sw:='D';
  1124. _DIR_IOCHECKS : sw:='I';
  1125. _DIR_LOCALSYMBOLS : sw:='L';
  1126. _DIR_LONGSTRINGS : sw:='H';
  1127. _DIR_OPENSTRINGS : sw:='P';
  1128. _DIR_OVERFLOWCHECKS : sw:='Q';
  1129. _DIR_RANGECHECKS : sw:='R';
  1130. _DIR_REFERENCEINFO : sw:='Y';
  1131. _DIR_STACKFRAMES : sw:='W';
  1132. _DIR_TYPEDADDRESS : sw:='T';
  1133. _DIR_TYPEINFO : sw:='M';
  1134. _DIR_VARSTRINGCHECKS : sw:='V';
  1135. else
  1136. exit;
  1137. end;
  1138. { c contains the next char, a + or - would be fine }
  1139. state:=current_scanner^.readstate;
  1140. if state in ['-','+'] then
  1141. HandleSwitch(sw,state);
  1142. end;
  1143. procedure dir_memory(t:tdirectivetoken);
  1144. var
  1145. l : longint;
  1146. begin
  1147. current_scanner^.skipspace;
  1148. l:=current_scanner^.readval;
  1149. if l>1024 then
  1150. stacksize:=l;
  1151. current_scanner^.skipspace;
  1152. if c=',' then
  1153. begin
  1154. current_scanner^.readchar;
  1155. current_scanner^.skipspace;
  1156. l:=current_scanner^.readval;
  1157. if l>1024 then
  1158. heapsize:=l;
  1159. end;
  1160. if c=',' then
  1161. begin
  1162. current_scanner^.readchar;
  1163. current_scanner^.skipspace;
  1164. l:=current_scanner^.readval;
  1165. { Ignore this value, because the limit is set by the OS
  1166. info and shouldn't be changed by the user (PFV) }
  1167. end;
  1168. end;
  1169. procedure dir_setverbose(t:tdirectivetoken);
  1170. var
  1171. flag,
  1172. state : char;
  1173. begin
  1174. case t of
  1175. _DIR_HINTS : flag:='H';
  1176. _DIR_WARNINGS : flag:='W';
  1177. _DIR_NOTES : flag:='N';
  1178. else
  1179. exit;
  1180. end;
  1181. { support ON/OFF }
  1182. state:=current_scanner^.ReadState;
  1183. SetVerbosity(flag+state);
  1184. end;
  1185. type
  1186. tdirectiveproc=procedure(t:tdirectivetoken);
  1187. const
  1188. directiveproc:array[tdirectivetoken] of tdirectiveproc=(
  1189. {_DIR_NONE} nil,
  1190. {_DIR_ALIGN} dir_delphiswitch,
  1191. {_DIR_APPTYPE} dir_apptype,
  1192. {_DIR_ASMMODE} dir_asmmode,
  1193. {_DIR_ASSERTION} dir_delphiswitch,
  1194. {_DIR_BOOLEVAL} dir_delphiswitch,
  1195. {_DIR_D} dir_description,
  1196. {_DIR_DEBUGINFO} dir_delphiswitch,
  1197. {_DIR_DEFINE} dir_define,
  1198. {_DIR_DESCRIPTION} dir_description,
  1199. {_DIR_ELSE} dir_conditional,
  1200. {_DIR_ENDIF} dir_conditional,
  1201. {_DIR_ERROR} dir_message,
  1202. {_DIR_EXTENDEDSYNTAX} dir_delphiswitch,
  1203. {_DIR_FATAL} dir_message,
  1204. {_DIR_GOTO} dir_moduleswitch,
  1205. {_DIR_HINT} dir_message,
  1206. {_DIR_HINTS} dir_setverbose,
  1207. {_DIR_I} dir_include,
  1208. {_DIR_I386_ATT} dir_oldasmmode,
  1209. {_DIR_I386_DIRECT} dir_oldasmmode,
  1210. {_DIR_I386_INTEL} dir_oldasmmode,
  1211. {_DIR_IOCHECKS} dir_delphiswitch,
  1212. {_DIR_IF} dir_conditional,
  1213. {_DIR_IFDEF} dir_conditional,
  1214. {_DIR_IFNDEF} dir_conditional,
  1215. {_DIR_IFOPT} dir_conditional,
  1216. {_DIR_INCLUDE} dir_include,
  1217. {_DIR_INCLUDEPATH} dir_includepath,
  1218. {_DIR_INFO} dir_message,
  1219. {_DIR_INLINE} dir_moduleswitch,
  1220. {_DIR_INTERFACES} dir_interfacesswitch,
  1221. {_DIR_L} dir_linkobject,
  1222. {_DIR_LIBRARYPATH} dir_librarypath,
  1223. {_DIR_LINK} dir_linkobject,
  1224. {_DIR_LINKLIB} dir_linklib,
  1225. {_DIR_LOCALSYMBOLS} dir_delphiswitch,
  1226. {_DIR_LONGSTRINGS} dir_delphiswitch,
  1227. {_DIR_M} dir_memory,
  1228. {_DIR_MACRO} dir_moduleswitch,
  1229. {_DIR_MAXFPUREGISTERS} dir_maxfpuregisters,
  1230. {_DIR_MEMORY} dir_memory,
  1231. {_DIR_MESSAGE} dir_message,
  1232. {_DIR_MINENUMSIZE} dir_packenum,
  1233. {_DIR_MMX} dir_localswitch,
  1234. {_DIR_MODE} dir_mode,
  1235. {_DIR_NOTE} dir_message,
  1236. {_DIR_NOTES} dir_setverbose,
  1237. {_DIR_OBJECTPATH} dir_objectpath,
  1238. {_DIR_OPENSTRINGS} dir_delphiswitch,
  1239. {_DIR_OUTPUT_FORMAT} dir_outputformat,
  1240. {_DIR_OVERFLOWCHECKS} dir_delphiswitch,
  1241. {_DIR_PACKENUM} dir_packenum,
  1242. {_DIR_PACKRECORDS} dir_packrecords,
  1243. {$IFDEF TestVarsets}
  1244. {_DIR_PACKSET} dir_packset,
  1245. {$ENDIF}
  1246. {_DIR_R} dir_resource,
  1247. {_DIR_RANGECHECKS} dir_delphiswitch,
  1248. {_DIR_REFERENCEINFO} dir_delphiswitch,
  1249. {_DIR_SATURATION} dir_localswitch,
  1250. {_DIR_SMARTLINK} dir_moduleswitch,
  1251. {_DIR_STACKFRAMES} dir_delphiswitch,
  1252. {_DIR_STATIC} dir_moduleswitch,
  1253. {_DIR_STOP} dir_message,
  1254. {_DIR_TYPEDADDRESS} dir_delphiswitch,
  1255. {_DIR_TYPEINFO} dir_delphiswitch,
  1256. {_DIR_UNDEF} dir_undef,
  1257. {_DIR_UNITPATH} dir_unitpath,
  1258. {_DIR_VARSTRINGCHECKS} dir_delphiswitch,
  1259. {_DIR_VERSION} dir_version,
  1260. {_DIR_WAIT} dir_wait,
  1261. {_DIR_WARNING} dir_message,
  1262. {_DIR_WARNINGS} dir_setverbose,
  1263. {_DIR_Z1} dir_packenum,
  1264. {_DIR_Z2} dir_packenum,
  1265. {_DIR_Z4} dir_packenum
  1266. );
  1267. {-------------------------------------------
  1268. Main switches handling
  1269. -------------------------------------------}
  1270. procedure handledirectives;
  1271. var
  1272. t : tdirectivetoken;
  1273. p : tdirectiveproc;
  1274. hs : string;
  1275. begin
  1276. current_scanner^.gettokenpos;
  1277. current_scanner^.readchar; {Remove the $}
  1278. hs:=current_scanner^.readid;
  1279. {$ifdef PREPROCWRITE}
  1280. if parapreprocess then
  1281. begin
  1282. t:=Get_Directive(hs);
  1283. if not(is_conditional(t) or (t=_DIR_DEFINE) or (t=_DIR_UNDEF)) then
  1284. begin
  1285. preprocfile^.AddSpace;
  1286. preprocfile^.Add('{$'+hs+current_scanner^.readcomment+'}');
  1287. exit;
  1288. end;
  1289. end;
  1290. {$endif PREPROCWRITE}
  1291. { skip this directive? }
  1292. if (current_scanner^.ignoredirectives.find(hs)<>nil) then
  1293. begin
  1294. if (current_scanner^.comment_level>0) then
  1295. current_scanner^.readcomment;
  1296. { we've read the whole comment }
  1297. aktcommentstyle:=comment_none;
  1298. exit;
  1299. end;
  1300. if hs='' then
  1301. begin
  1302. Message1(scan_w_illegal_switch,'$'+hs);
  1303. end;
  1304. { Check for compiler switches }
  1305. while (length(hs)=1) and (c in ['-','+']) do
  1306. begin
  1307. HandleSwitch(hs[1],c);
  1308. current_scanner^.readchar; {Remove + or -}
  1309. if c=',' then
  1310. begin
  1311. current_scanner^.readchar; {Remove , }
  1312. { read next switch, support $v+,$+}
  1313. hs:=current_scanner^.readid;
  1314. if (hs='') then
  1315. begin
  1316. if (c='$') and (m_fpc in aktmodeswitches) then
  1317. begin
  1318. current_scanner^.readchar; { skip $ }
  1319. hs:=current_scanner^.readid;
  1320. end;
  1321. if (hs='') then
  1322. Message1(scan_w_illegal_directive,'$'+c);
  1323. end
  1324. else
  1325. Message1(scan_d_handling_switch,'$'+hs);
  1326. end
  1327. else
  1328. hs:='';
  1329. end;
  1330. { directives may follow switches after a , }
  1331. if hs<>'' then
  1332. begin
  1333. t:=Get_Directive(hs);
  1334. if t<>_DIR_NONE then
  1335. begin
  1336. p:=directiveproc[t];
  1337. if {$ifndef FPCPROCVAR}@{$endif}p<>nil then
  1338. p(t);
  1339. end
  1340. else
  1341. begin
  1342. current_scanner^.ignoredirectives.insert(hs);
  1343. Message1(scan_w_illegal_directive,'$'+hs);
  1344. end;
  1345. { conditionals already read the comment }
  1346. if (current_scanner^.comment_level>0) then
  1347. current_scanner^.readcomment;
  1348. { we've read the whole comment }
  1349. aktcommentstyle:=comment_none;
  1350. end;
  1351. end;
  1352. {
  1353. $Log$
  1354. Revision 1.15 2000-12-25 00:07:28 peter
  1355. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1356. tlinkedlist objects)
  1357. Revision 1.14 2000/12/24 12:24:38 peter
  1358. * moved preprocessfile into a conditional
  1359. Revision 1.13 2000/12/12 19:48:52 peter
  1360. * fixed lost char after $I directive (merged)
  1361. Revision 1.12 2000/11/12 22:17:47 peter
  1362. * some realname updates for messages
  1363. Revision 1.11 2000/11/04 14:25:21 florian
  1364. + merged Attila's changes for interfaces, not tested yet
  1365. Revision 1.10 2000/10/31 22:02:51 peter
  1366. * symtable splitted, no real code changes
  1367. Revision 1.9 2000/09/26 10:50:41 jonas
  1368. * initmodeswitches is changed is you change the compiler mode from the
  1369. command line (the -S<x> switches didn't work anymore for changing the
  1370. compiler mode) (merged from fixes branch)
  1371. Revision 1.8 2000/09/24 21:33:47 peter
  1372. * message updates merges
  1373. Revision 1.7 2000/09/24 15:06:27 peter
  1374. * use defines.inc
  1375. Revision 1.6 2000/09/11 17:00:23 florian
  1376. + first implementation of Netware Module support, thanks to
  1377. Armin Diehl ([email protected]) for providing the patches
  1378. Revision 1.5 2000/09/10 21:18:15 peter
  1379. * macro warning (merged)
  1380. Revision 1.4 2000/08/12 15:30:44 peter
  1381. * IDE patch for stream reading (merged)
  1382. Revision 1.3 2000/08/08 19:28:57 peter
  1383. * memdebug/memory patches (merged)
  1384. * only once illegal directive (merged)
  1385. Revision 1.2 2000/07/13 11:32:49 michael
  1386. + removed logs
  1387. }