scanner.pas 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements the scanner part and handling of the switches
  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. unit scanner;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. cobjects,
  23. globtype,globals,version,tokens,
  24. verbose,comphook,
  25. finput,
  26. widestr;
  27. const
  28. maxmacrolen=16*1024;
  29. preprocbufsize=32*1024;
  30. Newline = #10;
  31. type
  32. tcommentstyle = (comment_none,comment_tp,comment_oldtp,comment_delphi,comment_c);
  33. pmacrobuffer = ^tmacrobuffer;
  34. tmacrobuffer = array[0..maxmacrolen-1] of char;
  35. pmacro = ^tmacro;
  36. tmacro = object(tnamedindexobject)
  37. defined,
  38. defined_at_startup,
  39. is_used : boolean;
  40. buftext : pchar;
  41. buflen : longint;
  42. constructor init(const n : string);
  43. destructor done;virtual;
  44. end;
  45. preproctyp = (pp_ifdef,pp_ifndef,pp_if,pp_ifopt,pp_else);
  46. ppreprocstack = ^tpreprocstack;
  47. tpreprocstack = object
  48. typ : preproctyp;
  49. accept : boolean;
  50. next : ppreprocstack;
  51. name : stringid;
  52. line_nb : longint;
  53. constructor init(atyp:preproctyp;a:boolean;n:ppreprocstack);
  54. destructor done;
  55. end;
  56. pscannerfile = ^tscannerfile;
  57. tscannerfile = object
  58. inputfile : pinputfile; { current inputfile list }
  59. inputbuffer, { input buffer }
  60. inputpointer : pchar;
  61. inputstart : longint;
  62. line_no, { line }
  63. lastlinepos : longint;
  64. lasttokenpos : longint; { token }
  65. lasttoken,
  66. nexttoken : ttoken;
  67. comment_level,
  68. yylexcount : longint;
  69. lastasmgetchar : char;
  70. ignoredirectives : tstringcontainer; { ignore directives, used to give warnings only once }
  71. preprocstack : ppreprocstack;
  72. invalid : boolean; { flag if sourcefiles have been destroyed ! }
  73. macros : pdictionary;
  74. in_asm_string : boolean;
  75. constructor init(const fn:string);
  76. destructor done;
  77. { File buffer things }
  78. function openinputfile:boolean;
  79. procedure closeinputfile;
  80. function tempopeninputfile:boolean;
  81. procedure tempcloseinputfile;
  82. procedure saveinputfile;
  83. procedure restoreinputfile;
  84. procedure nextfile;
  85. procedure addfile(hp:pinputfile);
  86. procedure reload;
  87. procedure insertmacro(const macname:string;p:pchar;len:longint);
  88. { Scanner things }
  89. procedure def_macro(const s : string);
  90. procedure set_macro(const s : string;value : string);
  91. procedure gettokenpos;
  92. procedure inc_comment_level;
  93. procedure dec_comment_level;
  94. procedure illegal_char(c:char);
  95. procedure end_of_file;
  96. procedure checkpreprocstack;
  97. procedure poppreprocstack;
  98. procedure addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:longint);
  99. procedure elsepreprocstack;
  100. procedure linebreak;
  101. procedure readchar;
  102. procedure readstring;
  103. procedure readnumber;
  104. function readid:string;
  105. function readval:longint;
  106. function readcomment:string;
  107. function readstate:char;
  108. procedure skipspace;
  109. procedure skipuntildirective;
  110. procedure skipcomment;
  111. procedure skipdelphicomment;
  112. procedure skipoldtpcomment;
  113. procedure readtoken;
  114. function readpreproc:ttoken;
  115. function asmgetchar:char;
  116. end;
  117. ppreprocfile=^tpreprocfile;
  118. tpreprocfile=object
  119. f : text;
  120. buf : pointer;
  121. spacefound,
  122. eolfound : boolean;
  123. constructor init(const fn:string);
  124. destructor done;
  125. procedure Add(const s:string);
  126. procedure AddSpace;
  127. end;
  128. var
  129. { read strings }
  130. c : char;
  131. orgpattern,
  132. pattern : string;
  133. patternw : tcompilerwidestring;
  134. { token }
  135. token, { current token being parsed }
  136. idtoken : ttoken; { holds the token if the pattern is a known word }
  137. current_scanner : pscannerfile;
  138. aktcommentstyle : tcommentstyle; { needed to use read_comment from directives }
  139. preprocfile : ppreprocfile; { used with only preprocessing }
  140. implementation
  141. uses
  142. {$ifdef delphi}
  143. dmisc,
  144. {$else}
  145. dos,
  146. {$endif delphi}
  147. cutils,
  148. systems,
  149. switches,
  150. fmodule;
  151. {*****************************************************************************
  152. Helper routines
  153. *****************************************************************************}
  154. const
  155. { use any special name that is an invalid file name to avoid problems }
  156. preprocstring : array [preproctyp] of string[7]
  157. = ('$IFDEF','$IFNDEF','$IF','$IFOPT','$ELSE');
  158. function is_keyword(const s:string):boolean;
  159. var
  160. low,high,mid : longint;
  161. begin
  162. if not (length(s) in [2..tokenidlen]) then
  163. begin
  164. is_keyword:=false;
  165. exit;
  166. end;
  167. low:=ord(tokenidx^[length(s),s[1]].first);
  168. high:=ord(tokenidx^[length(s),s[1]].last);
  169. while low<high do
  170. begin
  171. mid:=(high+low+1) shr 1;
  172. if pattern<tokeninfo^[ttoken(mid)].str then
  173. high:=mid-1
  174. else
  175. low:=mid;
  176. end;
  177. is_keyword:=(pattern=tokeninfo^[ttoken(high)].str) and
  178. (tokeninfo^[ttoken(high)].keyword in aktmodeswitches);
  179. end;
  180. {*****************************************************************************
  181. TMacro
  182. *****************************************************************************}
  183. constructor tmacro.init(const n : string);
  184. begin
  185. inherited initname(n);
  186. defined:=true;
  187. defined_at_startup:=false;
  188. is_used:=false;
  189. buftext:=nil;
  190. buflen:=0;
  191. end;
  192. destructor tmacro.done;
  193. begin
  194. if assigned(buftext) then
  195. freemem(buftext,buflen);
  196. inherited done;
  197. end;
  198. {*****************************************************************************
  199. Preprocessor writting
  200. *****************************************************************************}
  201. constructor tpreprocfile.init(const fn:string);
  202. begin
  203. { open outputfile }
  204. assign(f,fn);
  205. {$I-}
  206. rewrite(f);
  207. {$I+}
  208. if ioresult<>0 then
  209. Comment(V_Fatal,'can''t create file '+fn);
  210. getmem(buf,preprocbufsize);
  211. settextbuf(f,buf^,preprocbufsize);
  212. { reset }
  213. eolfound:=false;
  214. spacefound:=false;
  215. end;
  216. destructor tpreprocfile.done;
  217. begin
  218. close(f);
  219. freemem(buf,preprocbufsize);
  220. end;
  221. procedure tpreprocfile.add(const s:string);
  222. begin
  223. write(f,s);
  224. end;
  225. procedure tpreprocfile.addspace;
  226. begin
  227. if eolfound then
  228. begin
  229. writeln(f,'');
  230. eolfound:=false;
  231. spacefound:=false;
  232. end
  233. else
  234. if spacefound then
  235. begin
  236. write(f,' ');
  237. spacefound:=false;
  238. end;
  239. end;
  240. {*****************************************************************************
  241. TPreProcStack
  242. *****************************************************************************}
  243. constructor tpreprocstack.init(atyp : preproctyp;a:boolean;n:ppreprocstack);
  244. begin
  245. accept:=a;
  246. typ:=atyp;
  247. next:=n;
  248. end;
  249. destructor tpreprocstack.done;
  250. begin
  251. end;
  252. {****************************************************************************
  253. TSCANNERFILE
  254. ****************************************************************************}
  255. constructor tscannerfile.init(const fn:string);
  256. begin
  257. inputfile:=do_openinputfile(fn);
  258. if assigned(current_module) then
  259. current_module^.sourcefiles^.register_file(inputfile);
  260. { reset localinput }
  261. inputbuffer:=nil;
  262. inputpointer:=nil;
  263. inputstart:=0;
  264. { reset scanner }
  265. preprocstack:=nil;
  266. comment_level:=0;
  267. yylexcount:=0;
  268. block_type:=bt_general;
  269. line_no:=0;
  270. lastlinepos:=0;
  271. lasttokenpos:=0;
  272. lasttoken:=NOTOKEN;
  273. nexttoken:=NOTOKEN;
  274. lastasmgetchar:=#0;
  275. ignoredirectives.init;
  276. invalid:=false;
  277. in_asm_string:=false;
  278. new(macros,init);
  279. { load block }
  280. if not openinputfile then
  281. Message1(scan_f_cannot_open_input,fn);
  282. reload;
  283. { process first read char }
  284. case c of
  285. #26 : reload;
  286. #10,
  287. #13 : linebreak;
  288. end;
  289. end;
  290. destructor tscannerfile.done;
  291. begin
  292. if not invalid then
  293. begin
  294. if status.errorcount=0 then
  295. checkpreprocstack;
  296. { close file, but only if we are the first compile }
  297. { probably not necessary anymore with invalid flag PM }
  298. if not current_module^.in_second_compile then
  299. begin
  300. if not inputfile^.closed then
  301. closeinputfile;
  302. end;
  303. end;
  304. ignoredirectives.done;
  305. dispose(macros,done);
  306. end;
  307. procedure tscannerfile.def_macro(const s : string);
  308. var
  309. mac : pmacro;
  310. begin
  311. mac:=pmacro(macros^.search(s));
  312. if mac=nil then
  313. begin
  314. mac:=new(pmacro,init(s));
  315. Message1(parser_m_macro_defined,mac^.name);
  316. macros^.insert(mac);
  317. end;
  318. mac^.defined:=true;
  319. mac^.defined_at_startup:=true;
  320. end;
  321. procedure tscannerfile.set_macro(const s : string;value : string);
  322. var
  323. mac : pmacro;
  324. begin
  325. mac:=pmacro(macros^.search(s));
  326. if mac=nil then
  327. begin
  328. mac:=new(pmacro,init(s));
  329. macros^.insert(mac);
  330. end
  331. else
  332. begin
  333. if assigned(mac^.buftext) then
  334. freemem(mac^.buftext,mac^.buflen);
  335. end;
  336. Message2(parser_m_macro_set_to,mac^.name,value);
  337. mac^.buflen:=length(value);
  338. getmem(mac^.buftext,mac^.buflen);
  339. move(value[1],mac^.buftext^,mac^.buflen);
  340. mac^.defined:=true;
  341. mac^.defined_at_startup:=true;
  342. end;
  343. function tscannerfile.openinputfile:boolean;
  344. begin
  345. openinputfile:=inputfile^.open;
  346. { load buffer }
  347. inputbuffer:=inputfile^.buf;
  348. inputpointer:=inputfile^.buf;
  349. inputstart:=inputfile^.bufstart;
  350. { line }
  351. line_no:=0;
  352. lastlinepos:=0;
  353. lasttokenpos:=0;
  354. end;
  355. procedure tscannerfile.closeinputfile;
  356. begin
  357. inputfile^.close;
  358. { reset buffer }
  359. inputbuffer:=nil;
  360. inputpointer:=nil;
  361. inputstart:=0;
  362. { reset line }
  363. line_no:=0;
  364. lastlinepos:=0;
  365. lasttokenpos:=0;
  366. end;
  367. function tscannerfile.tempopeninputfile:boolean;
  368. begin
  369. tempopeninputfile:=inputfile^.tempopen;
  370. { reload buffer }
  371. inputbuffer:=inputfile^.buf;
  372. inputpointer:=inputfile^.buf;
  373. inputstart:=inputfile^.bufstart;
  374. end;
  375. procedure tscannerfile.tempcloseinputfile;
  376. begin
  377. inputfile^.setpos(inputstart+(inputpointer-inputbuffer));
  378. inputfile^.tempclose;
  379. { reset buffer }
  380. inputbuffer:=nil;
  381. inputpointer:=nil;
  382. inputstart:=0;
  383. end;
  384. procedure tscannerfile.saveinputfile;
  385. begin
  386. inputfile^.saveinputpointer:=inputpointer;
  387. inputfile^.savelastlinepos:=lastlinepos;
  388. inputfile^.saveline_no:=line_no;
  389. end;
  390. procedure tscannerfile.restoreinputfile;
  391. begin
  392. inputpointer:=inputfile^.saveinputpointer;
  393. lastlinepos:=inputfile^.savelastlinepos;
  394. line_no:=inputfile^.saveline_no;
  395. if not inputfile^.is_macro then
  396. parser_current_file:=inputfile^.name^;
  397. end;
  398. procedure tscannerfile.nextfile;
  399. var
  400. to_dispose : pinputfile;
  401. begin
  402. if assigned(inputfile^.next) then
  403. begin
  404. if inputfile^.is_macro then
  405. to_dispose:=inputfile
  406. else
  407. to_dispose:=nil;
  408. { we can allways close the file, no ? }
  409. inputfile^.close;
  410. inputfile:=inputfile^.next;
  411. if assigned(to_dispose) then
  412. dispose(to_dispose,done);
  413. restoreinputfile;
  414. end;
  415. end;
  416. procedure tscannerfile.addfile(hp:pinputfile);
  417. begin
  418. saveinputfile;
  419. { add to list }
  420. hp^.next:=inputfile;
  421. inputfile:=hp;
  422. { load new inputfile }
  423. restoreinputfile;
  424. end;
  425. procedure tscannerfile.reload;
  426. begin
  427. with inputfile^ do
  428. begin
  429. { when nothing more to read then leave immediatly, so we
  430. don't change the aktfilepos and leave it point to the last
  431. char }
  432. if (c=#26) and (not assigned(next)) then
  433. exit;
  434. repeat
  435. { still more to read?, then change the #0 to a space so its seen
  436. as a seperator, this can't be used for macro's which can change
  437. the place of the #0 in the buffer with tempopen }
  438. if (c=#0) and (bufsize>0) and
  439. not(inputfile^.is_macro) and
  440. (inputpointer-inputbuffer<bufsize) then
  441. begin
  442. c:=' ';
  443. inc(longint(inputpointer));
  444. exit;
  445. end;
  446. { can we read more from this file ? }
  447. if (c<>#26) and (not endoffile) then
  448. begin
  449. readbuf;
  450. inputpointer:=buf;
  451. inputbuffer:=buf;
  452. inputstart:=bufstart;
  453. { first line? }
  454. if line_no=0 then
  455. begin
  456. line_no:=1;
  457. if cs_asm_source in aktglobalswitches then
  458. inputfile^.setline(line_no,bufstart);
  459. end;
  460. end
  461. else
  462. begin
  463. { load eof position in tokenpos/aktfilepos }
  464. gettokenpos;
  465. { close file }
  466. closeinputfile;
  467. { no next module, than EOF }
  468. if not assigned(inputfile^.next) then
  469. begin
  470. c:=#26;
  471. exit;
  472. end;
  473. { load next file and reopen it }
  474. nextfile;
  475. tempopeninputfile;
  476. { status }
  477. Message1(scan_t_back_in,inputfile^.name^);
  478. end;
  479. { load next char }
  480. c:=inputpointer^;
  481. inc(longint(inputpointer));
  482. until c<>#0; { if also end, then reload again }
  483. end;
  484. end;
  485. procedure tscannerfile.insertmacro(const macname:string;p:pchar;len:longint);
  486. var
  487. hp : pinputfile;
  488. begin
  489. { save old postion and decrease linebreak }
  490. if c=newline then
  491. dec(line_no);
  492. dec(longint(inputpointer));
  493. tempcloseinputfile;
  494. { create macro 'file' }
  495. { use special name to dispose after !! }
  496. hp:=do_openinputfile('_Macro_.'+macname);
  497. addfile(hp);
  498. with inputfile^ do
  499. begin
  500. setmacro(p,len);
  501. { local buffer }
  502. inputbuffer:=buf;
  503. inputpointer:=buf;
  504. inputstart:=bufstart;
  505. end;
  506. { reset line }
  507. line_no:=0;
  508. lastlinepos:=0;
  509. lasttokenpos:=0;
  510. { load new c }
  511. c:=inputpointer^;
  512. inc(longint(inputpointer));
  513. end;
  514. procedure tscannerfile.gettokenpos;
  515. { load the values of tokenpos and lasttokenpos }
  516. begin
  517. lasttokenpos:=inputstart+(inputpointer-inputbuffer);
  518. akttokenpos.line:=line_no;
  519. akttokenpos.column:=lasttokenpos-lastlinepos;
  520. akttokenpos.fileindex:=inputfile^.ref_index;
  521. aktfilepos:=akttokenpos;
  522. end;
  523. procedure tscannerfile.inc_comment_level;
  524. var
  525. oldaktfilepos : tfileposinfo;
  526. begin
  527. if (m_nested_comment in aktmodeswitches) then
  528. inc(comment_level)
  529. else
  530. comment_level:=1;
  531. if (comment_level>1) then
  532. begin
  533. oldaktfilepos:=aktfilepos;
  534. gettokenpos; { update for warning }
  535. Message1(scan_w_comment_level,tostr(comment_level));
  536. aktfilepos:=oldaktfilepos;
  537. end;
  538. end;
  539. procedure tscannerfile.dec_comment_level;
  540. begin
  541. if (m_nested_comment in aktmodeswitches) then
  542. dec(comment_level)
  543. else
  544. comment_level:=0;
  545. end;
  546. procedure tscannerfile.linebreak;
  547. var
  548. cur : char;
  549. oldtokenpos,
  550. oldaktfilepos : tfileposinfo;
  551. begin
  552. with inputfile^ do
  553. begin
  554. if (byte(inputpointer^)=0) and not(endoffile) then
  555. begin
  556. cur:=c;
  557. reload;
  558. if byte(cur)+byte(c)<>23 then
  559. dec(longint(inputpointer));
  560. end
  561. else
  562. begin
  563. { Fix linebreak to be only newline (=#10) for all types of linebreaks }
  564. if (byte(inputpointer^)+byte(c)=23) then
  565. inc(longint(inputpointer));
  566. end;
  567. c:=newline;
  568. { increase line counters }
  569. lastlinepos:=bufstart+(inputpointer-inputbuffer);
  570. inc(line_no);
  571. { update linebuffer }
  572. if cs_asm_source in aktglobalswitches then
  573. inputfile^.setline(line_no,lastlinepos);
  574. { update for status and call the show status routine,
  575. but don't touch aktfilepos ! }
  576. oldaktfilepos:=aktfilepos;
  577. oldtokenpos:=akttokenpos;
  578. gettokenpos; { update for v_status }
  579. inc(status.compiledlines);
  580. ShowStatus;
  581. aktfilepos:=oldaktfilepos;
  582. akttokenpos:=oldtokenpos;
  583. end;
  584. end;
  585. procedure tscannerfile.illegal_char(c:char);
  586. var
  587. s : string;
  588. begin
  589. if c in [#32..#255] then
  590. s:=''''+c+''''
  591. else
  592. s:='#'+tostr(ord(c));
  593. Message2(scan_f_illegal_char,s,'$'+hexstr(ord(c),2));
  594. end;
  595. procedure tscannerfile.end_of_file;
  596. begin
  597. checkpreprocstack;
  598. Message(scan_f_end_of_file);
  599. end;
  600. procedure tscannerfile.checkpreprocstack;
  601. begin
  602. { check for missing ifdefs }
  603. while assigned(preprocstack) do
  604. begin
  605. Message3(scan_e_endif_expected,preprocstring[preprocstack^.typ],preprocstack^.name,tostr(preprocstack^.line_nb));
  606. poppreprocstack;
  607. end;
  608. end;
  609. procedure tscannerfile.poppreprocstack;
  610. var
  611. hp : ppreprocstack;
  612. begin
  613. if assigned(preprocstack) then
  614. begin
  615. Message1(scan_c_endif_found,preprocstack^.name);
  616. hp:=preprocstack^.next;
  617. dispose(preprocstack,done);
  618. preprocstack:=hp;
  619. end
  620. else
  621. Message(scan_e_endif_without_if);
  622. end;
  623. procedure tscannerfile.addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:longint);
  624. begin
  625. preprocstack:=new(ppreprocstack,init(atyp,((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  626. preprocstack^.name:=s;
  627. preprocstack^.line_nb:=line_no;
  628. if preprocstack^.accept then
  629. Message2(w,preprocstack^.name,'accepted')
  630. else
  631. Message2(w,preprocstack^.name,'rejected');
  632. end;
  633. procedure tscannerfile.elsepreprocstack;
  634. begin
  635. if assigned(preprocstack) then
  636. begin
  637. preprocstack^.typ:=pp_else;
  638. preprocstack^.line_nb:=line_no;
  639. if not(assigned(preprocstack^.next)) or (preprocstack^.next^.accept) then
  640. preprocstack^.accept:=not preprocstack^.accept;
  641. if preprocstack^.accept then
  642. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  643. else
  644. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  645. end
  646. else
  647. Message(scan_e_endif_without_if);
  648. end;
  649. procedure tscannerfile.readchar;
  650. begin
  651. c:=inputpointer^;
  652. if c=#0 then
  653. reload
  654. else
  655. inc(longint(inputpointer));
  656. case c of
  657. #26 : reload;
  658. #10,
  659. #13 : linebreak;
  660. end;
  661. end;
  662. procedure tscannerfile.readstring;
  663. var
  664. i : longint;
  665. begin
  666. i:=0;
  667. repeat
  668. case c of
  669. '_',
  670. '0'..'9',
  671. 'A'..'Z' : begin
  672. if i<255 then
  673. begin
  674. inc(i);
  675. orgpattern[i]:=c;
  676. pattern[i]:=c;
  677. end;
  678. c:=inputpointer^;
  679. inc(longint(inputpointer));
  680. end;
  681. 'a'..'z' : begin
  682. if i<255 then
  683. begin
  684. inc(i);
  685. orgpattern[i]:=c;
  686. pattern[i]:=chr(ord(c)-32)
  687. end;
  688. c:=inputpointer^;
  689. inc(longint(inputpointer));
  690. end;
  691. #0 : reload;
  692. #26 : begin
  693. reload;
  694. if c=#26 then
  695. break;
  696. end;
  697. #13,#10 : begin
  698. linebreak;
  699. break;
  700. end;
  701. else
  702. break;
  703. end;
  704. until false;
  705. orgpattern[0]:=chr(i);
  706. pattern[0]:=chr(i);
  707. end;
  708. procedure tscannerfile.readnumber;
  709. var
  710. base,
  711. i : longint;
  712. begin
  713. case c of
  714. '%' : begin
  715. readchar;
  716. base:=2;
  717. pattern[1]:='%';
  718. i:=1;
  719. end;
  720. '$' : begin
  721. readchar;
  722. base:=16;
  723. pattern[1]:='$';
  724. i:=1;
  725. end;
  726. else
  727. begin
  728. base:=10;
  729. i:=0;
  730. end;
  731. end;
  732. while ((base>=10) and (c in ['0'..'9'])) or
  733. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  734. ((base=2) and (c in ['0'..'1'])) do
  735. begin
  736. if i<255 then
  737. begin
  738. inc(i);
  739. pattern[i]:=c;
  740. end;
  741. { get next char }
  742. c:=inputpointer^;
  743. if c=#0 then
  744. reload
  745. else
  746. inc(longint(inputpointer));
  747. end;
  748. { was the next char a linebreak ? }
  749. case c of
  750. #26 : reload;
  751. #10,
  752. #13 : linebreak;
  753. end;
  754. pattern[0]:=chr(i);
  755. end;
  756. function tscannerfile.readid:string;
  757. begin
  758. readstring;
  759. readid:=pattern;
  760. end;
  761. function tscannerfile.readval:longint;
  762. var
  763. l : longint;
  764. w : integer;
  765. begin
  766. readnumber;
  767. valint(pattern,l,w);
  768. readval:=l;
  769. end;
  770. function tscannerfile.readcomment:string;
  771. var
  772. i : longint;
  773. begin
  774. i:=0;
  775. repeat
  776. case c of
  777. '{' :
  778. if aktcommentstyle=comment_tp then
  779. inc_comment_level;
  780. '}' :
  781. if aktcommentstyle=comment_tp then
  782. begin
  783. readchar;
  784. dec_comment_level;
  785. if comment_level=0 then
  786. break
  787. else
  788. continue;
  789. end;
  790. '*' :
  791. if aktcommentstyle=comment_oldtp then
  792. begin
  793. readchar;
  794. if c=')' then
  795. begin
  796. readchar;
  797. dec_comment_level;
  798. break;
  799. end
  800. else
  801. { Add both characters !!}
  802. if (i<255) then
  803. begin
  804. inc(i);
  805. readcomment[i]:='*';
  806. if (i<255) then
  807. begin
  808. inc(i);
  809. readcomment[i]:='*';
  810. end;
  811. end;
  812. end
  813. else
  814. { Not old TP comment, so add...}
  815. begin
  816. if (i<255) then
  817. begin
  818. inc(i);
  819. readcomment[i]:='*';
  820. end;
  821. end;
  822. #26 :
  823. end_of_file;
  824. else
  825. begin
  826. if (i<255) then
  827. begin
  828. inc(i);
  829. readcomment[i]:=c;
  830. end;
  831. end;
  832. end;
  833. c:=inputpointer^;
  834. if c=#0 then
  835. reload
  836. else
  837. inc(longint(inputpointer));
  838. if c in [#10,#13] then
  839. linebreak;
  840. until false;
  841. readcomment[0]:=chr(i);
  842. end;
  843. function tscannerfile.readstate:char;
  844. var
  845. state : char;
  846. begin
  847. state:=' ';
  848. if c=' ' then
  849. begin
  850. current_scanner^.skipspace;
  851. current_scanner^.readid;
  852. if pattern='ON' then
  853. state:='+'
  854. else
  855. if pattern='OFF' then
  856. state:='-';
  857. end
  858. else
  859. state:=c;
  860. if not (state in ['+','-']) then
  861. Message(scan_e_wrong_switch_toggle);
  862. readstate:=state;
  863. end;
  864. procedure tscannerfile.skipspace;
  865. begin
  866. while c in [' ',#9..#13] do
  867. begin
  868. c:=inputpointer^;
  869. if c=#0 then
  870. reload
  871. else
  872. inc(longint(inputpointer));
  873. case c of
  874. #26 :
  875. reload;
  876. #10,
  877. #13 :
  878. linebreak;
  879. end;
  880. end;
  881. end;
  882. procedure tscannerfile.skipuntildirective;
  883. var
  884. found : longint;
  885. next_char_loaded : boolean;
  886. oldcommentstyle : tcommentstyle;
  887. begin
  888. found:=0;
  889. next_char_loaded:=false;
  890. oldcommentstyle:=aktcommentstyle;
  891. repeat
  892. case c of
  893. #26 :
  894. end_of_file;
  895. '{' :
  896. begin
  897. if not(m_nested_comment in aktmodeswitches) or
  898. (comment_level=0) then
  899. begin
  900. found:=1;
  901. aktcommentstyle:=comment_tp;
  902. end;
  903. inc_comment_level;
  904. end;
  905. '}' :
  906. begin
  907. dec_comment_level;
  908. found:=0;
  909. end;
  910. '$' :
  911. begin
  912. if found=1 then
  913. found:=2;
  914. end;
  915. '''' :
  916. if not(m_nested_comment in aktmodeswitches) then
  917. begin
  918. repeat
  919. readchar;
  920. case c of
  921. #26 :
  922. end_of_file;
  923. newline :
  924. break;
  925. '''' :
  926. begin
  927. readchar;
  928. if c<>'''' then
  929. break;
  930. end;
  931. end;
  932. until false;
  933. end;
  934. '(' :
  935. begin
  936. readchar;
  937. if c='*' then
  938. begin
  939. readchar;
  940. if c='$' then
  941. begin
  942. found:=2;
  943. inc_comment_level;
  944. aktcommentstyle:=comment_oldtp;
  945. end
  946. else
  947. begin
  948. skipoldtpcomment;
  949. aktcommentstyle:=oldcommentstyle;
  950. end;
  951. end
  952. else
  953. next_char_loaded:=true;
  954. end;
  955. else
  956. found:=0;
  957. end;
  958. if next_char_loaded then
  959. next_char_loaded:=false
  960. else
  961. begin
  962. c:=inputpointer^;
  963. if c=#0 then
  964. reload
  965. else
  966. inc(longint(inputpointer));
  967. case c of
  968. #26 : reload;
  969. #10,
  970. #13 : linebreak;
  971. end;
  972. end;
  973. until (found=2);
  974. end;
  975. {****************************************************************************
  976. Include directive scanning/parsing
  977. ****************************************************************************}
  978. {$i scandir.inc}
  979. {****************************************************************************
  980. Comment Handling
  981. ****************************************************************************}
  982. procedure tscannerfile.skipcomment;
  983. begin
  984. aktcommentstyle:=comment_tp;
  985. readchar;
  986. inc_comment_level;
  987. { handle compiler switches }
  988. if (c='$') then
  989. handledirectives;
  990. { handle_switches can dec comment_level, }
  991. while (comment_level>0) do
  992. begin
  993. case c of
  994. '{' : inc_comment_level;
  995. '}' : dec_comment_level;
  996. #26 : end_of_file;
  997. end;
  998. c:=inputpointer^;
  999. if c=#0 then
  1000. reload
  1001. else
  1002. inc(longint(inputpointer));
  1003. case c of
  1004. #26 : reload;
  1005. #10,
  1006. #13 : linebreak;
  1007. end;
  1008. end;
  1009. aktcommentstyle:=comment_none;
  1010. end;
  1011. procedure tscannerfile.skipdelphicomment;
  1012. begin
  1013. aktcommentstyle:=comment_delphi;
  1014. inc_comment_level;
  1015. readchar;
  1016. { this is currently not supported }
  1017. if c='$' then
  1018. Message(scan_e_wrong_styled_switch);
  1019. { skip comment }
  1020. while c<>newline do
  1021. begin
  1022. if c=#26 then
  1023. end_of_file;
  1024. readchar;
  1025. end;
  1026. dec_comment_level;
  1027. aktcommentstyle:=comment_none;
  1028. end;
  1029. procedure tscannerfile.skipoldtpcomment;
  1030. var
  1031. found : longint;
  1032. begin
  1033. aktcommentstyle:=comment_oldtp;
  1034. inc_comment_level;
  1035. readchar;
  1036. { this is currently not supported }
  1037. if (c='$') then
  1038. handledirectives;
  1039. { skip comment }
  1040. while (comment_level>0) do
  1041. begin
  1042. found:=0;
  1043. repeat
  1044. case c of
  1045. #26 :
  1046. end_of_file;
  1047. '*' :
  1048. begin
  1049. if found=3 then
  1050. found:=4
  1051. else
  1052. found:=1;
  1053. end;
  1054. ')' :
  1055. begin
  1056. if found in [1,4] then
  1057. begin
  1058. dec_comment_level;
  1059. if comment_level=0 then
  1060. found:=2
  1061. else
  1062. found:=0;
  1063. end;
  1064. end;
  1065. '(' :
  1066. begin
  1067. if found=4 then
  1068. inc_comment_level;
  1069. found:=3;
  1070. end;
  1071. else
  1072. begin
  1073. if found=4 then
  1074. inc_comment_level;
  1075. found:=0;
  1076. end;
  1077. end;
  1078. c:=inputpointer^;
  1079. if c=#0 then
  1080. reload
  1081. else
  1082. inc(longint(inputpointer));
  1083. case c of
  1084. #26 : reload;
  1085. #10,
  1086. #13 : linebreak;
  1087. end;
  1088. until (found=2);
  1089. end;
  1090. aktcommentstyle:=comment_none;
  1091. end;
  1092. {****************************************************************************
  1093. Token Scanner
  1094. ****************************************************************************}
  1095. procedure tscannerfile.readtoken;
  1096. var
  1097. code : integer;
  1098. low,high,mid : longint;
  1099. m : longint;
  1100. mac : pmacro;
  1101. asciinr : string[6];
  1102. iswidestring : boolean;
  1103. label
  1104. exit_label;
  1105. begin
  1106. if localswitcheschanged then
  1107. begin
  1108. aktlocalswitches:=nextaktlocalswitches;
  1109. localswitcheschanged:=false;
  1110. end;
  1111. { was there already a token read, then return that token }
  1112. if nexttoken<>NOTOKEN then
  1113. begin
  1114. token:=nexttoken;
  1115. nexttoken:=NOTOKEN;
  1116. goto exit_label;
  1117. end;
  1118. { Skip all spaces and comments }
  1119. repeat
  1120. case c of
  1121. '{' :
  1122. skipcomment;
  1123. ' ',#9..#13 :
  1124. begin
  1125. if parapreprocess then
  1126. begin
  1127. if c=#10 then
  1128. preprocfile^.eolfound:=true
  1129. else
  1130. preprocfile^.spacefound:=true;
  1131. end;
  1132. skipspace;
  1133. end
  1134. else
  1135. break;
  1136. end;
  1137. until false;
  1138. { Save current token position, for EOF its already loaded }
  1139. if c<>#26 then
  1140. gettokenpos;
  1141. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  1142. if c in ['A'..'Z','a'..'z','_'] then
  1143. begin
  1144. readstring;
  1145. token:=_ID;
  1146. idtoken:=_ID;
  1147. { keyword or any other known token,
  1148. pattern is always uppercased }
  1149. if (pattern[1]<>'_') and (length(pattern) in [2..tokenidlen]) then
  1150. begin
  1151. low:=ord(tokenidx^[length(pattern),pattern[1]].first);
  1152. high:=ord(tokenidx^[length(pattern),pattern[1]].last);
  1153. while low<high do
  1154. begin
  1155. mid:=(high+low+1) shr 1;
  1156. if pattern<tokeninfo^[ttoken(mid)].str then
  1157. high:=mid-1
  1158. else
  1159. low:=mid;
  1160. end;
  1161. if pattern=tokeninfo^[ttoken(high)].str then
  1162. begin
  1163. if tokeninfo^[ttoken(high)].keyword in aktmodeswitches then
  1164. if tokeninfo^[ttoken(high)].op=NOTOKEN then
  1165. token:=ttoken(high)
  1166. else
  1167. token:=tokeninfo^[ttoken(high)].op;
  1168. idtoken:=ttoken(high);
  1169. end;
  1170. end;
  1171. { Only process identifiers and not keywords }
  1172. if token=_ID then
  1173. begin
  1174. { this takes some time ... }
  1175. if (cs_support_macro in aktmoduleswitches) then
  1176. begin
  1177. mac:=pmacro(macros^.search(pattern));
  1178. if assigned(mac) and (assigned(mac^.buftext)) then
  1179. begin
  1180. insertmacro(pattern,mac^.buftext,mac^.buflen);
  1181. { handle empty macros }
  1182. if c=#0 then
  1183. begin
  1184. reload;
  1185. case c of
  1186. #26 : reload;
  1187. #10,
  1188. #13 : linebreak;
  1189. end;
  1190. end;
  1191. { play it again ... }
  1192. inc(yylexcount);
  1193. if yylexcount>16 then
  1194. Message(scan_w_macro_deep_ten);
  1195. readtoken;
  1196. { that's all folks }
  1197. dec(yylexcount);
  1198. exit;
  1199. end;
  1200. end;
  1201. end;
  1202. { return token }
  1203. goto exit_label;
  1204. end
  1205. else
  1206. begin
  1207. idtoken:=_NOID;
  1208. case c of
  1209. '$' :
  1210. begin
  1211. readnumber;
  1212. token:=_INTCONST;
  1213. goto exit_label;
  1214. end;
  1215. '%' :
  1216. begin
  1217. if (m_tp in aktmodeswitches) then
  1218. Illegal_Char(c)
  1219. else
  1220. begin
  1221. readnumber;
  1222. token:=_INTCONST;
  1223. goto exit_label;
  1224. end;
  1225. end;
  1226. '0'..'9' :
  1227. begin
  1228. readnumber;
  1229. if (c in ['.','e','E']) then
  1230. begin
  1231. { first check for a . }
  1232. if c='.' then
  1233. begin
  1234. readchar;
  1235. { is it a .. from a range? }
  1236. case c of
  1237. '.' :
  1238. begin
  1239. readchar;
  1240. token:=_INTCONST;
  1241. nexttoken:=_POINTPOINT;
  1242. goto exit_label;
  1243. end;
  1244. ')' :
  1245. begin
  1246. readchar;
  1247. token:=_INTCONST;
  1248. nexttoken:=_RECKKLAMMER;
  1249. goto exit_label;
  1250. end;
  1251. end;
  1252. { insert the number after the . }
  1253. pattern:=pattern+'.';
  1254. while c in ['0'..'9'] do
  1255. begin
  1256. pattern:=pattern+c;
  1257. readchar;
  1258. end;
  1259. end;
  1260. { E can also follow after a point is scanned }
  1261. if c in ['e','E'] then
  1262. begin
  1263. pattern:=pattern+'E';
  1264. readchar;
  1265. if c in ['-','+'] then
  1266. begin
  1267. pattern:=pattern+c;
  1268. readchar;
  1269. end;
  1270. if not(c in ['0'..'9']) then
  1271. Illegal_Char(c);
  1272. while c in ['0'..'9'] do
  1273. begin
  1274. pattern:=pattern+c;
  1275. readchar;
  1276. end;
  1277. end;
  1278. token:=_REALNUMBER;
  1279. goto exit_label;
  1280. end;
  1281. token:=_INTCONST;
  1282. goto exit_label;
  1283. end;
  1284. ';' :
  1285. begin
  1286. readchar;
  1287. token:=_SEMICOLON;
  1288. goto exit_label;
  1289. end;
  1290. '[' :
  1291. begin
  1292. readchar;
  1293. token:=_LECKKLAMMER;
  1294. goto exit_label;
  1295. end;
  1296. ']' :
  1297. begin
  1298. readchar;
  1299. token:=_RECKKLAMMER;
  1300. goto exit_label;
  1301. end;
  1302. '(' :
  1303. begin
  1304. readchar;
  1305. case c of
  1306. '*' :
  1307. begin
  1308. skipoldtpcomment;
  1309. readtoken;
  1310. exit;
  1311. end;
  1312. '.' :
  1313. begin
  1314. readchar;
  1315. token:=_LECKKLAMMER;
  1316. goto exit_label;
  1317. end;
  1318. end;
  1319. token:=_LKLAMMER;
  1320. goto exit_label;
  1321. end;
  1322. ')' :
  1323. begin
  1324. readchar;
  1325. token:=_RKLAMMER;
  1326. goto exit_label;
  1327. end;
  1328. '+' :
  1329. begin
  1330. readchar;
  1331. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1332. begin
  1333. readchar;
  1334. token:=_PLUSASN;
  1335. goto exit_label;
  1336. end;
  1337. token:=_PLUS;
  1338. goto exit_label;
  1339. end;
  1340. '-' :
  1341. begin
  1342. readchar;
  1343. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1344. begin
  1345. readchar;
  1346. token:=_MINUSASN;
  1347. goto exit_label;
  1348. end;
  1349. token:=_MINUS;
  1350. goto exit_label;
  1351. end;
  1352. ':' :
  1353. begin
  1354. readchar;
  1355. if c='=' then
  1356. begin
  1357. readchar;
  1358. token:=_ASSIGNMENT;
  1359. goto exit_label;
  1360. end;
  1361. token:=_COLON;
  1362. goto exit_label;
  1363. end;
  1364. '*' :
  1365. begin
  1366. readchar;
  1367. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1368. begin
  1369. readchar;
  1370. token:=_STARASN;
  1371. end
  1372. else
  1373. if c='*' then
  1374. begin
  1375. readchar;
  1376. token:=_STARSTAR;
  1377. end
  1378. else
  1379. token:=_STAR;
  1380. goto exit_label;
  1381. end;
  1382. '/' :
  1383. begin
  1384. readchar;
  1385. case c of
  1386. '=' :
  1387. begin
  1388. if (cs_support_c_operators in aktmoduleswitches) then
  1389. begin
  1390. readchar;
  1391. token:=_SLASHASN;
  1392. goto exit_label;
  1393. end;
  1394. end;
  1395. '/' :
  1396. begin
  1397. skipdelphicomment;
  1398. readtoken;
  1399. exit;
  1400. end;
  1401. end;
  1402. token:=_SLASH;
  1403. goto exit_label;
  1404. end;
  1405. '=' :
  1406. begin
  1407. readchar;
  1408. token:=_EQUAL;
  1409. goto exit_label;
  1410. end;
  1411. '.' :
  1412. begin
  1413. readchar;
  1414. case c of
  1415. '.' :
  1416. begin
  1417. readchar;
  1418. token:=_POINTPOINT;
  1419. goto exit_label;
  1420. end;
  1421. ')' :
  1422. begin
  1423. readchar;
  1424. token:=_RECKKLAMMER;
  1425. goto exit_label;
  1426. end;
  1427. end;
  1428. token:=_POINT;
  1429. goto exit_label;
  1430. end;
  1431. '@' :
  1432. begin
  1433. readchar;
  1434. if c='@' then
  1435. begin
  1436. readchar;
  1437. token:=_DOUBLEADDR;
  1438. end
  1439. else
  1440. token:=_KLAMMERAFFE;
  1441. goto exit_label;
  1442. end;
  1443. ',' :
  1444. begin
  1445. readchar;
  1446. token:=_COMMA;
  1447. goto exit_label;
  1448. end;
  1449. '''','#','^' :
  1450. begin
  1451. iswidestring:=false;
  1452. if c='^' then
  1453. begin
  1454. readchar;
  1455. c:=upcase(c);
  1456. if (block_type=bt_type) or
  1457. (lasttoken=_ID) or
  1458. (lasttoken=_RKLAMMER) or (lasttoken=_RECKKLAMMER) or (lasttoken=_CARET) then
  1459. begin
  1460. token:=_CARET;
  1461. goto exit_label;
  1462. end
  1463. else
  1464. begin
  1465. if c<#64 then
  1466. pattern:=chr(ord(c)+64)
  1467. else
  1468. pattern:=chr(ord(c)-64);
  1469. readchar;
  1470. end;
  1471. end
  1472. else
  1473. pattern:='';
  1474. repeat
  1475. case c of
  1476. '#' :
  1477. begin
  1478. readchar; { read # }
  1479. if c='$' then
  1480. begin
  1481. readchar; { read leading $ }
  1482. asciinr:='$';
  1483. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<6) do
  1484. begin
  1485. asciinr:=asciinr+c;
  1486. readchar;
  1487. end;
  1488. end
  1489. else
  1490. begin
  1491. asciinr:='';
  1492. while (c in ['0'..'9']) and (length(asciinr)<6) do
  1493. begin
  1494. asciinr:=asciinr+c;
  1495. readchar;
  1496. end;
  1497. end;
  1498. valint(asciinr,m,code);
  1499. if (asciinr='') or (code<>0) then
  1500. Message(scan_e_illegal_char_const)
  1501. else if (m<0) or (m>255) then
  1502. begin
  1503. if (m>=0) and (m<=65535) then
  1504. begin
  1505. ascii2unicode(pattern,patternw);
  1506. concatwidestringchar(patternw,
  1507. tcompilerwidechar(m));
  1508. iswidestring:=true;
  1509. end
  1510. else
  1511. Message(scan_e_illegal_char_const)
  1512. end
  1513. else if iswidestring then
  1514. concatwidestringchar(patternw,asciichar2unicode(char(m)))
  1515. else
  1516. pattern:=pattern+chr(m);
  1517. end;
  1518. '''' :
  1519. begin
  1520. repeat
  1521. readchar;
  1522. case c of
  1523. #26 :
  1524. end_of_file;
  1525. newline :
  1526. Message(scan_f_string_exceeds_line);
  1527. '''' :
  1528. begin
  1529. readchar;
  1530. if c<>'''' then
  1531. break;
  1532. end;
  1533. end;
  1534. if iswidestring then
  1535. concatwidestringchar(patternw,
  1536. asciichar2unicode(c))
  1537. else
  1538. pattern:=pattern+c;
  1539. until false;
  1540. end;
  1541. '^' :
  1542. begin
  1543. readchar;
  1544. c:=upcase(c);
  1545. if c<#64 then
  1546. c:=chr(ord(c)+64)
  1547. else
  1548. c:=chr(ord(c)-64);
  1549. if iswidestring then
  1550. concatwidestringchar(patternw,
  1551. asciichar2unicode(c))
  1552. else
  1553. pattern:=pattern+c;
  1554. readchar;
  1555. end;
  1556. else
  1557. break;
  1558. end;
  1559. until false;
  1560. { strings with length 1 become const chars }
  1561. if iswidestring then
  1562. begin
  1563. if length(pattern)=1 then
  1564. token:=_CWCHAR
  1565. else
  1566. token:=_CWSTRING;
  1567. end
  1568. else
  1569. begin
  1570. if length(pattern)=1 then
  1571. token:=_CCHAR
  1572. else
  1573. token:=_CSTRING;
  1574. end;
  1575. goto exit_label;
  1576. end;
  1577. '>' :
  1578. begin
  1579. readchar;
  1580. case c of
  1581. '=' :
  1582. begin
  1583. readchar;
  1584. token:=_GTE;
  1585. goto exit_label;
  1586. end;
  1587. '>' :
  1588. begin
  1589. readchar;
  1590. token:=_OP_SHR;
  1591. goto exit_label;
  1592. end;
  1593. '<' :
  1594. begin { >< is for a symetric diff for sets }
  1595. readchar;
  1596. token:=_SYMDIF;
  1597. goto exit_label;
  1598. end;
  1599. end;
  1600. token:=_GT;
  1601. goto exit_label;
  1602. end;
  1603. '<' :
  1604. begin
  1605. readchar;
  1606. case c of
  1607. '>' :
  1608. begin
  1609. readchar;
  1610. token:=_UNEQUAL;
  1611. goto exit_label;
  1612. end;
  1613. '=' :
  1614. begin
  1615. readchar;
  1616. token:=_LTE;
  1617. goto exit_label;
  1618. end;
  1619. '<' :
  1620. begin
  1621. readchar;
  1622. token:=_OP_SHL;
  1623. goto exit_label;
  1624. end;
  1625. end;
  1626. token:=_LT;
  1627. goto exit_label;
  1628. end;
  1629. #26 :
  1630. begin
  1631. token:=_EOF;
  1632. checkpreprocstack;
  1633. goto exit_label;
  1634. end;
  1635. else
  1636. Illegal_Char(c);
  1637. end;
  1638. end;
  1639. exit_label:
  1640. lasttoken:=token;
  1641. end;
  1642. function tscannerfile.readpreproc:ttoken;
  1643. begin
  1644. skipspace;
  1645. case c of
  1646. 'A'..'Z',
  1647. 'a'..'z',
  1648. '_','0'..'9' : begin
  1649. preprocpat:=readid;
  1650. readpreproc:=_ID;
  1651. end;
  1652. '}' : begin
  1653. readpreproc:=_END;
  1654. end;
  1655. '(' : begin
  1656. readchar;
  1657. readpreproc:=_LKLAMMER;
  1658. end;
  1659. ')' : begin
  1660. readchar;
  1661. readpreproc:=_RKLAMMER;
  1662. end;
  1663. '+' : begin
  1664. readchar;
  1665. readpreproc:=_PLUS;
  1666. end;
  1667. '-' : begin
  1668. readchar;
  1669. readpreproc:=_MINUS;
  1670. end;
  1671. '*' : begin
  1672. readchar;
  1673. readpreproc:=_STAR;
  1674. end;
  1675. '/' : begin
  1676. readchar;
  1677. readpreproc:=_SLASH;
  1678. end;
  1679. '=' : begin
  1680. readchar;
  1681. readpreproc:=_EQUAL;
  1682. end;
  1683. '>' : begin
  1684. readchar;
  1685. if c='=' then
  1686. begin
  1687. readchar;
  1688. readpreproc:=_GTE;
  1689. end
  1690. else
  1691. readpreproc:=_GT;
  1692. end;
  1693. '<' : begin
  1694. readchar;
  1695. case c of
  1696. '>' : begin
  1697. readchar;
  1698. readpreproc:=_UNEQUAL;
  1699. end;
  1700. '=' : begin
  1701. readchar;
  1702. readpreproc:=_LTE;
  1703. end;
  1704. else readpreproc:=_LT;
  1705. end;
  1706. end;
  1707. #26 :
  1708. end_of_file;
  1709. else
  1710. begin
  1711. readpreproc:=_EOF;
  1712. checkpreprocstack;
  1713. end;
  1714. end;
  1715. end;
  1716. function tscannerfile.asmgetchar : char;
  1717. begin
  1718. if lastasmgetchar<>#0 then
  1719. begin
  1720. c:=lastasmgetchar;
  1721. lastasmgetchar:=#0;
  1722. end
  1723. else
  1724. readchar;
  1725. if in_asm_string then
  1726. begin
  1727. asmgetchar:=c;
  1728. exit;
  1729. end;
  1730. case c of
  1731. '{' : begin
  1732. skipcomment;
  1733. asmgetchar:=c;
  1734. exit;
  1735. end;
  1736. '/' : begin
  1737. readchar;
  1738. if c='/' then
  1739. begin
  1740. skipdelphicomment;
  1741. asmgetchar:=c;
  1742. end
  1743. else
  1744. begin
  1745. asmgetchar:='/';
  1746. lastasmgetchar:=c;
  1747. end;
  1748. exit;
  1749. end;
  1750. '(' : begin
  1751. readchar;
  1752. if c='*' then
  1753. begin
  1754. skipoldtpcomment;
  1755. asmgetchar:=c;
  1756. end
  1757. else
  1758. begin
  1759. asmgetchar:='(';
  1760. lastasmgetchar:=c;
  1761. end;
  1762. exit;
  1763. end;
  1764. else
  1765. begin
  1766. asmgetchar:=c;
  1767. end;
  1768. end;
  1769. end;
  1770. end.
  1771. {
  1772. $Log$
  1773. Revision 1.9 2000-11-30 20:27:51 peter
  1774. * merged fix for bug 1229
  1775. Revision 1.8 2000/11/29 00:30:40 florian
  1776. * unused units removed from uses clause
  1777. * some changes for widestrings
  1778. Revision 1.7 2000/10/31 22:02:51 peter
  1779. * symtable splitted, no real code changes
  1780. Revision 1.6 2000/09/24 15:06:28 peter
  1781. * use defines.inc
  1782. Revision 1.5 2000/08/27 16:11:53 peter
  1783. * moved some util functions from globals,cobjects to cutils
  1784. * splitted files into finput,fmodule
  1785. Revision 1.4 2000/08/12 15:30:44 peter
  1786. * IDE patch for stream reading (merged)
  1787. Revision 1.3 2000/08/08 19:28:57 peter
  1788. * memdebug/memory patches (merged)
  1789. * only once illegal directive (merged)
  1790. Revision 1.2 2000/07/13 11:32:49 michael
  1791. + removed logs
  1792. }