scandir.inc 45 KB

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