scanner.pas 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  1. {
  2. $Id$
  3. Copyright (c) 1993,97 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. {$ifdef tp}
  19. {$F+,N+,E+,R-}
  20. {$endif}
  21. unit scanner;
  22. interface
  23. uses
  24. {$ifdef Delphi}
  25. dmisc,
  26. {$endif Delphi}
  27. globtype,version,tokens,
  28. cobjects,globals,verbose,comphook,files;
  29. const
  30. {$ifdef TP}
  31. maxmacrolen=1024;
  32. {$else}
  33. maxmacrolen=16*1024;
  34. {$endif}
  35. Newline = #10;
  36. type
  37. pmacrobuffer = ^tmacrobuffer;
  38. tmacrobuffer = array[0..maxmacrolen-1] of char;
  39. preproctyp = (pp_ifdef,pp_ifndef,pp_if,pp_ifopt,pp_else);
  40. ppreprocstack = ^tpreprocstack;
  41. tpreprocstack = object
  42. typ : preproctyp;
  43. accept : boolean;
  44. next : ppreprocstack;
  45. name : stringid;
  46. line_nb : longint;
  47. constructor init(atyp:preproctyp;a:boolean;n:ppreprocstack);
  48. destructor done;
  49. end;
  50. pscannerfile = ^tscannerfile;
  51. tscannerfile = object
  52. inputfile : pinputfile; { current inputfile list }
  53. inputbuffer, { input buffer }
  54. inputpointer : pchar;
  55. inputstart : longint;
  56. line_no, { line }
  57. lastlinepos : longint;
  58. lasttokenpos : longint; { token }
  59. lasttoken,
  60. nexttoken : ttoken;
  61. comment_level,
  62. yylexcount : longint;
  63. lastasmgetchar : char;
  64. preprocstack : ppreprocstack;
  65. invalid : boolean; { flag if sourcefiles have been destroyed ! }
  66. constructor init(const fn:string);
  67. destructor done;
  68. { File buffer things }
  69. function openinputfile:boolean;
  70. procedure closeinputfile;
  71. function tempopeninputfile:boolean;
  72. procedure tempcloseinputfile;
  73. procedure saveinputfile;
  74. procedure restoreinputfile;
  75. procedure nextfile;
  76. procedure addfile(hp:pinputfile);
  77. procedure reload;
  78. procedure insertmacro(p:pchar;len:longint);
  79. { Scanner things }
  80. procedure gettokenpos;
  81. procedure inc_comment_level;
  82. procedure dec_comment_level;
  83. procedure checkpreprocstack;
  84. procedure poppreprocstack;
  85. procedure addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:tmsgconst);
  86. procedure elsepreprocstack;
  87. procedure linebreak;
  88. procedure readchar;
  89. procedure readstring;
  90. procedure readnumber;
  91. function readid:string;
  92. function readval:longint;
  93. function readcomment:string;
  94. function readstate:char;
  95. procedure skipspace;
  96. procedure skipuntildirective;
  97. procedure skipcomment;
  98. procedure skipdelphicomment;
  99. procedure skipoldtpcomment;
  100. procedure skipccomment;
  101. procedure readtoken;
  102. function readpreproc:ttoken;
  103. function asmgetchar:char;
  104. end;
  105. var
  106. c : char;
  107. orgpattern,
  108. pattern : string;
  109. current_scanner : pscannerfile;
  110. implementation
  111. uses
  112. dos,systems,symtable,switches;
  113. {*****************************************************************************
  114. Helper routines
  115. *****************************************************************************}
  116. type
  117. tokenidxrec=record
  118. first,last : ttoken;
  119. end;
  120. var
  121. tokenidx:array[2..tokenidlen,'A'..'Z'] of tokenidxrec;
  122. const
  123. { use any special name that is an invalid file name to avoid problems }
  124. macro_special_name = '____Macro____';
  125. preprocstring : array [preproctyp] of string[7]
  126. = ('$IFDEF','$IFNDEF','$IF','$IFOPT','$ELSE');
  127. procedure create_tokenidx;
  128. { create an index with the first and last token for every possible token
  129. length, so a search only will be done in that small part }
  130. var
  131. t : ttoken;
  132. begin
  133. fillchar(tokenidx,sizeof(tokenidx),0);
  134. for t:=low(ttoken) to high(ttoken) do
  135. begin
  136. if not tokeninfo[t].special then
  137. begin
  138. if ord(tokenidx[length(tokeninfo[t].str),tokeninfo[t].str[1]].first)=0 then
  139. tokenidx[length(tokeninfo[t].str),tokeninfo[t].str[1]].first:=t;
  140. tokenidx[length(tokeninfo[t].str),tokeninfo[t].str[1]].last:=t;
  141. end;
  142. end;
  143. end;
  144. function is_keyword(const s:string):boolean;
  145. var
  146. low,high,mid : longint;
  147. begin
  148. if not (length(s) in [2..tokenidlen]) then
  149. begin
  150. is_keyword:=false;
  151. exit;
  152. end;
  153. low:=ord(tokenidx[length(s),s[1]].first);
  154. high:=ord(tokenidx[length(s),s[1]].last);
  155. while low<high do
  156. begin
  157. mid:=(high+low+1) shr 1;
  158. if pattern<tokeninfo[ttoken(mid)].str then
  159. high:=mid-1
  160. else
  161. low:=mid;
  162. end;
  163. is_keyword:=(pattern=tokeninfo[ttoken(high)].str) and
  164. (tokeninfo[ttoken(high)].keyword in aktmodeswitches);
  165. end;
  166. {*****************************************************************************
  167. TPreProcStack
  168. *****************************************************************************}
  169. constructor tpreprocstack.init(atyp : preproctyp;a:boolean;n:ppreprocstack);
  170. begin
  171. accept:=a;
  172. typ:=atyp;
  173. next:=n;
  174. end;
  175. destructor tpreprocstack.done;
  176. begin
  177. end;
  178. {****************************************************************************
  179. TSCANNERFILE
  180. ****************************************************************************}
  181. constructor tscannerfile.init(const fn:string);
  182. begin
  183. inputfile:=new(pinputfile,init(fn));
  184. current_module^.sourcefiles^.register_file(inputfile);
  185. { reset localinput }
  186. inputbuffer:=nil;
  187. inputpointer:=nil;
  188. inputstart:=0;
  189. { reset scanner }
  190. preprocstack:=nil;
  191. comment_level:=0;
  192. yylexcount:=0;
  193. block_type:=bt_general;
  194. line_no:=0;
  195. lastlinepos:=0;
  196. lasttokenpos:=0;
  197. lasttoken:=NOTOKEN;
  198. nexttoken:=NOTOKEN;
  199. lastasmgetchar:=#0;
  200. invalid:=false;
  201. { load block }
  202. if not openinputfile then
  203. Message1(scan_f_cannot_open_input,fn);
  204. reload;
  205. end;
  206. destructor tscannerfile.done;
  207. begin
  208. if not invalid then
  209. begin
  210. if status.errorcount=0 then
  211. checkpreprocstack;
  212. { close file, but only if we are the first compile }
  213. { probably not necessary anymore with invalid flag PM }
  214. if not current_module^.in_second_compile then
  215. begin
  216. if not inputfile^.closed then
  217. closeinputfile;
  218. end;
  219. end;
  220. end;
  221. function tscannerfile.openinputfile:boolean;
  222. begin
  223. openinputfile:=inputfile^.open;
  224. { load buffer }
  225. inputbuffer:=inputfile^.buf;
  226. inputpointer:=inputfile^.buf;
  227. inputstart:=inputfile^.bufstart;
  228. { line }
  229. line_no:=0;
  230. lastlinepos:=0;
  231. lasttokenpos:=0;
  232. end;
  233. procedure tscannerfile.closeinputfile;
  234. begin
  235. inputfile^.close;
  236. { reset buffer }
  237. inputbuffer:=nil;
  238. inputpointer:=nil;
  239. inputstart:=0;
  240. { reset line }
  241. line_no:=0;
  242. lastlinepos:=0;
  243. lasttokenpos:=0;
  244. end;
  245. function tscannerfile.tempopeninputfile:boolean;
  246. begin
  247. tempopeninputfile:=inputfile^.tempopen;
  248. { reload buffer }
  249. inputbuffer:=inputfile^.buf;
  250. inputpointer:=inputfile^.buf;
  251. inputstart:=inputfile^.bufstart;
  252. end;
  253. procedure tscannerfile.tempcloseinputfile;
  254. begin
  255. inputfile^.setpos(inputstart+(inputpointer-inputbuffer));
  256. inputfile^.tempclose;
  257. { reset buffer }
  258. inputbuffer:=nil;
  259. inputpointer:=nil;
  260. inputstart:=0;
  261. end;
  262. procedure tscannerfile.saveinputfile;
  263. begin
  264. inputfile^.saveinputpointer:=inputpointer;
  265. inputfile^.savelastlinepos:=lastlinepos;
  266. inputfile^.saveline_no:=line_no;
  267. end;
  268. procedure tscannerfile.restoreinputfile;
  269. begin
  270. inputpointer:=inputfile^.saveinputpointer;
  271. lastlinepos:=inputfile^.savelastlinepos;
  272. line_no:=inputfile^.saveline_no;
  273. if not inputfile^.is_macro then
  274. parser_current_file:=inputfile^.name^;
  275. end;
  276. procedure tscannerfile.nextfile;
  277. var
  278. to_dispose : pinputfile;
  279. begin
  280. if assigned(inputfile^.next) then
  281. begin
  282. if inputfile^.is_macro then
  283. to_dispose:=inputfile
  284. else
  285. to_dispose:=nil;
  286. { we can allways close the file, no ? }
  287. inputfile^.close;
  288. inputfile:=inputfile^.next;
  289. if assigned(to_dispose) then
  290. dispose(to_dispose,done);
  291. restoreinputfile;
  292. end;
  293. end;
  294. procedure tscannerfile.addfile(hp:pinputfile);
  295. begin
  296. saveinputfile;
  297. { add to list }
  298. hp^.next:=inputfile;
  299. inputfile:=hp;
  300. { load new inputfile }
  301. restoreinputfile;
  302. end;
  303. procedure tscannerfile.reload;
  304. begin
  305. with inputfile^ do
  306. begin
  307. repeat
  308. { still more to read?, then change the #0 to a space so its seen
  309. as a seperator }
  310. if (c=#0) and (bufsize>0) and (inputpointer-inputbuffer<bufsize) then
  311. begin
  312. c:=' ';
  313. inc(longint(inputpointer));
  314. exit;
  315. end;
  316. { can we read more from this file ? }
  317. if (c<>#26) and (not endoffile) then
  318. begin
  319. readbuf;
  320. inputpointer:=buf;
  321. inputbuffer:=buf;
  322. inputstart:=bufstart;
  323. { first line? }
  324. if line_no=0 then
  325. begin
  326. line_no:=1;
  327. if cs_asm_source in aktglobalswitches then
  328. inputfile^.setline(line_no,bufstart);
  329. end;
  330. end
  331. else
  332. begin
  333. { load eof position in tokenpos/aktfilepos }
  334. gettokenpos;
  335. { close file }
  336. closeinputfile;
  337. { no next module, than EOF }
  338. if not assigned(inputfile^.next) then
  339. begin
  340. c:=#26;
  341. exit;
  342. end;
  343. { load next file and reopen it }
  344. nextfile;
  345. tempopeninputfile;
  346. { status }
  347. Message1(scan_t_back_in,inputfile^.name^);
  348. end;
  349. { load next char }
  350. c:=inputpointer^;
  351. inc(longint(inputpointer));
  352. until c<>#0; { if also end, then reload again }
  353. end;
  354. end;
  355. procedure tscannerfile.insertmacro(p:pchar;len:longint);
  356. var
  357. hp : pinputfile;
  358. begin
  359. { save old postion and decrease linebreak }
  360. if c=newline then
  361. dec(line_no);
  362. dec(longint(inputpointer));
  363. tempcloseinputfile;
  364. { create macro 'file' }
  365. { use special name to dispose after !! }
  366. hp:=new(pinputfile,init(macro_special_name));
  367. addfile(hp);
  368. with inputfile^ do
  369. begin
  370. setmacro(p,len);
  371. { local buffer }
  372. inputbuffer:=buf;
  373. inputpointer:=buf;
  374. inputstart:=bufstart;
  375. end;
  376. { reset line }
  377. line_no:=0;
  378. lastlinepos:=0;
  379. lasttokenpos:=0;
  380. { load new c }
  381. c:=inputpointer^;
  382. inc(longint(inputpointer));
  383. end;
  384. procedure tscannerfile.gettokenpos;
  385. { load the values of tokenpos and lasttokenpos }
  386. begin
  387. lasttokenpos:=inputstart+(inputpointer-inputbuffer);
  388. tokenpos.line:=line_no;
  389. tokenpos.column:=lasttokenpos-lastlinepos;
  390. tokenpos.fileindex:=inputfile^.ref_index;
  391. aktfilepos:=tokenpos;
  392. end;
  393. procedure tscannerfile.inc_comment_level;
  394. var
  395. oldaktfilepos : tfileposinfo;
  396. begin
  397. if (m_nested_comment in aktmodeswitches) then
  398. inc(comment_level)
  399. else
  400. comment_level:=1;
  401. if (comment_level>1) then
  402. begin
  403. oldaktfilepos:=aktfilepos;
  404. gettokenpos; { update for warning }
  405. Message1(scan_w_comment_level,tostr(comment_level));
  406. aktfilepos:=oldaktfilepos;
  407. end;
  408. end;
  409. procedure tscannerfile.dec_comment_level;
  410. begin
  411. if (m_nested_comment in aktmodeswitches) then
  412. dec(comment_level)
  413. else
  414. comment_level:=0;
  415. end;
  416. procedure tscannerfile.linebreak;
  417. var
  418. cur : char;
  419. oldtokenpos,
  420. oldaktfilepos : tfileposinfo;
  421. begin
  422. with inputfile^ do
  423. begin
  424. if (byte(inputpointer^)=0) and not(endoffile) then
  425. begin
  426. cur:=c;
  427. reload;
  428. if byte(cur)+byte(c)<>23 then
  429. dec(longint(inputpointer));
  430. end
  431. else
  432. begin
  433. { Fix linebreak to be only newline (=#10) for all types of linebreaks }
  434. if (byte(inputpointer^)+byte(c)=23) then
  435. inc(longint(inputpointer));
  436. end;
  437. c:=newline;
  438. { increase line counters }
  439. lastlinepos:=bufstart+(inputpointer-inputbuffer);
  440. inc(line_no);
  441. { update linebuffer }
  442. if cs_asm_source in aktglobalswitches then
  443. inputfile^.setline(line_no,lastlinepos);
  444. { update for status and call the show status routine,
  445. but don't touch aktfilepos ! }
  446. oldaktfilepos:=aktfilepos;
  447. oldtokenpos:=tokenpos;
  448. gettokenpos; { update for v_status }
  449. inc(status.compiledlines);
  450. ShowStatus;
  451. aktfilepos:=oldaktfilepos;
  452. tokenpos:=oldtokenpos;
  453. end;
  454. end;
  455. procedure tscannerfile.checkpreprocstack;
  456. begin
  457. { check for missing ifdefs }
  458. while assigned(preprocstack) do
  459. begin
  460. Message3(scan_e_endif_expected,preprocstring[preprocstack^.typ],preprocstack^.name,tostr(preprocstack^.line_nb));
  461. poppreprocstack;
  462. end;
  463. end;
  464. procedure tscannerfile.poppreprocstack;
  465. var
  466. hp : ppreprocstack;
  467. begin
  468. if assigned(preprocstack) then
  469. begin
  470. Message1(scan_c_endif_found,preprocstack^.name);
  471. hp:=preprocstack^.next;
  472. dispose(preprocstack,done);
  473. preprocstack:=hp;
  474. end
  475. else
  476. Message(scan_e_endif_without_if);
  477. end;
  478. procedure tscannerfile.addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:tmsgconst);
  479. begin
  480. preprocstack:=new(ppreprocstack,init(atyp,((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  481. preprocstack^.name:=s;
  482. preprocstack^.line_nb:=line_no;
  483. if preprocstack^.accept then
  484. Message2(w,preprocstack^.name,'accepted')
  485. else
  486. Message2(w,preprocstack^.name,'rejected');
  487. end;
  488. procedure tscannerfile.elsepreprocstack;
  489. begin
  490. if assigned(preprocstack) then
  491. begin
  492. preprocstack^.typ:=pp_else;
  493. preprocstack^.line_nb:=line_no;
  494. if not(assigned(preprocstack^.next)) or (preprocstack^.next^.accept) then
  495. preprocstack^.accept:=not preprocstack^.accept;
  496. if preprocstack^.accept then
  497. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  498. else
  499. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  500. end
  501. else
  502. Message(scan_e_endif_without_if);
  503. end;
  504. procedure tscannerfile.readchar;
  505. begin
  506. c:=inputpointer^;
  507. if c=#0 then
  508. reload
  509. else
  510. inc(longint(inputpointer));
  511. case c of
  512. #26 : reload;
  513. #10,
  514. #13 : linebreak;
  515. end;
  516. end;
  517. procedure tscannerfile.readstring;
  518. var
  519. i : longint;
  520. begin
  521. i:=0;
  522. repeat
  523. case c of
  524. '_',
  525. '0'..'9',
  526. 'A'..'Z' : begin
  527. if i<255 then
  528. begin
  529. inc(i);
  530. orgpattern[i]:=c;
  531. pattern[i]:=c;
  532. end;
  533. c:=inputpointer^;
  534. inc(longint(inputpointer));
  535. end;
  536. 'a'..'z' : begin
  537. if i<255 then
  538. begin
  539. inc(i);
  540. orgpattern[i]:=c;
  541. pattern[i]:=chr(ord(c)-32)
  542. end;
  543. c:=inputpointer^;
  544. inc(longint(inputpointer));
  545. end;
  546. #0 : reload;
  547. #26 : begin
  548. reload;
  549. if c=#26 then
  550. break;
  551. end;
  552. #13,#10 : begin
  553. linebreak;
  554. break;
  555. end;
  556. else
  557. break;
  558. end;
  559. until false;
  560. {$ifndef TP}
  561. {$ifopt H+}
  562. setlength(orgpattern,i);
  563. setlength(pattern,i);
  564. {$else}
  565. orgpattern[0]:=chr(i);
  566. pattern[0]:=chr(i);
  567. {$endif}
  568. {$else}
  569. orgpattern[0]:=chr(i);
  570. pattern[0]:=chr(i);
  571. {$endif}
  572. end;
  573. procedure tscannerfile.readnumber;
  574. var
  575. base,
  576. i : longint;
  577. begin
  578. case c of
  579. '%' : begin
  580. readchar;
  581. base:=2;
  582. pattern[1]:='%';
  583. i:=1;
  584. end;
  585. '$' : begin
  586. readchar;
  587. base:=16;
  588. pattern[1]:='$';
  589. i:=1;
  590. end;
  591. else
  592. begin
  593. base:=10;
  594. i:=0;
  595. end;
  596. end;
  597. while ((base>=10) and (c in ['0'..'9'])) or
  598. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  599. ((base=2) and (c in ['0'..'1'])) do
  600. begin
  601. if i<255 then
  602. begin
  603. inc(i);
  604. pattern[i]:=c;
  605. end;
  606. { get next char }
  607. c:=inputpointer^;
  608. if c=#0 then
  609. reload
  610. else
  611. inc(longint(inputpointer));
  612. end;
  613. { was the next char a linebreak ? }
  614. case c of
  615. #26 : reload;
  616. #10,
  617. #13 : linebreak;
  618. end;
  619. {$ifndef TP}
  620. {$ifopt H+}
  621. setlength(pattern,i);
  622. {$else}
  623. pattern[0]:=chr(i);
  624. {$endif}
  625. {$else}
  626. pattern[0]:=chr(i);
  627. {$endif}
  628. end;
  629. function tscannerfile.readid:string;
  630. begin
  631. readstring;
  632. readid:=pattern;
  633. end;
  634. function tscannerfile.readval:longint;
  635. var
  636. l : longint;
  637. w : integer;
  638. begin
  639. readnumber;
  640. valint(pattern,l,w);
  641. readval:=l;
  642. end;
  643. function tscannerfile.readcomment:string;
  644. var
  645. i : longint;
  646. begin
  647. i:=0;
  648. repeat
  649. case c of
  650. '}' : begin
  651. readchar;
  652. dec_comment_level;
  653. break;
  654. end;
  655. #26 : Message(scan_f_end_of_file);
  656. else
  657. begin
  658. if (i<255) then
  659. begin
  660. inc(i);
  661. readcomment[i]:=c;
  662. end;
  663. end;
  664. end;
  665. c:=inputpointer^;
  666. if c=#0 then
  667. reload
  668. else
  669. inc(longint(inputpointer));
  670. if c in [#10,#13] then
  671. linebreak;
  672. until false;
  673. {$ifndef TP}
  674. {$ifopt H+}
  675. setlength(readcomment,i);
  676. {$else}
  677. readcomment[0]:=chr(i);
  678. {$endif}
  679. {$else}
  680. readcomment[0]:=chr(i);
  681. {$endif}
  682. end;
  683. function tscannerfile.readstate:char;
  684. var
  685. state : char;
  686. begin
  687. state:=' ';
  688. if c=' ' then
  689. begin
  690. current_scanner^.skipspace;
  691. current_scanner^.readid;
  692. if pattern='ON' then
  693. state:='+'
  694. else
  695. if pattern='OFF' then
  696. state:='-';
  697. end
  698. else
  699. state:=c;
  700. if not (state in ['+','-']) then
  701. Message(scan_e_wrong_switch_toggle);
  702. readstate:=state;
  703. end;
  704. procedure tscannerfile.skipspace;
  705. begin
  706. while c in [' ',#9..#13] do
  707. begin
  708. c:=inputpointer^;
  709. if c=#0 then
  710. reload
  711. else
  712. inc(longint(inputpointer));
  713. case c of
  714. #26 : reload;
  715. #10,
  716. #13 : linebreak;
  717. end;
  718. end;
  719. end;
  720. procedure tscannerfile.skipuntildirective;
  721. var
  722. found : longint;
  723. next_char_loaded : boolean;
  724. begin
  725. found:=0;
  726. next_char_loaded:=false;
  727. repeat
  728. case c of
  729. #26 :
  730. Message(scan_f_end_of_file);
  731. '{' :
  732. begin
  733. if comment_level=0 then
  734. found:=1;
  735. inc_comment_level;
  736. end;
  737. '}' :
  738. begin
  739. dec_comment_level;
  740. found:=0;
  741. end;
  742. '$' :
  743. begin
  744. if found=1 then
  745. found:=2;
  746. end;
  747. '(' :
  748. if (m_tp in aktmodeswitches) then
  749. begin
  750. readchar;
  751. if c='*' then
  752. skipoldtpcomment
  753. else
  754. next_char_loaded:=true;
  755. end;
  756. else
  757. found:=0;
  758. end;
  759. if next_char_loaded then
  760. next_char_loaded:=false
  761. else
  762. begin
  763. c:=inputpointer^;
  764. if c=#0 then
  765. reload
  766. else
  767. inc(longint(inputpointer));
  768. case c of
  769. #26 : reload;
  770. #10,
  771. #13 : linebreak;
  772. end;
  773. end;
  774. until (found=2);
  775. end;
  776. {$i scandir.inc}
  777. procedure tscannerfile.skipcomment;
  778. begin
  779. readchar;
  780. inc_comment_level;
  781. { handle compiler switches }
  782. if (c='$') then
  783. handledirectives;
  784. { handle_switches can dec comment_level, }
  785. while (comment_level>0) do
  786. begin
  787. case c of
  788. '{' : inc_comment_level;
  789. '}' : dec_comment_level;
  790. #26 : Message(scan_f_end_of_file);
  791. end;
  792. c:=inputpointer^;
  793. if c=#0 then
  794. reload
  795. else
  796. inc(longint(inputpointer));
  797. case c of
  798. #26 : reload;
  799. #10,
  800. #13 : linebreak;
  801. end;
  802. end;
  803. end;
  804. procedure tscannerfile.skipdelphicomment;
  805. begin
  806. inc_comment_level;
  807. readchar;
  808. { this is currently not supported }
  809. if c='$' then
  810. Message(scan_e_wrong_styled_switch);
  811. { skip comment }
  812. while c<>newline do
  813. begin
  814. if c=#26 then
  815. Message(scan_f_end_of_file);
  816. readchar;
  817. end;
  818. dec_comment_level;
  819. end;
  820. procedure tscannerfile.skipoldtpcomment;
  821. var
  822. found : longint;
  823. begin
  824. inc_comment_level;
  825. readchar;
  826. { this is currently not supported }
  827. if c='$' then
  828. Message(scan_e_wrong_styled_switch);
  829. { skip comment }
  830. while (comment_level>0) do
  831. begin
  832. found:=0;
  833. repeat
  834. case c of
  835. #26 : Message(scan_f_end_of_file);
  836. '*' : begin
  837. if found=3 then
  838. begin
  839. inc_comment_level;
  840. found:=0;
  841. end
  842. else
  843. found:=1;
  844. end;
  845. ')' : begin
  846. if found=1 then
  847. begin
  848. dec_comment_level;
  849. if comment_level=0 then
  850. found:=2
  851. else
  852. found:=0;
  853. end;
  854. end;
  855. '(' : found:=3;
  856. else
  857. found:=0;
  858. end;
  859. c:=inputpointer^;
  860. if c=#0 then
  861. reload
  862. else
  863. inc(longint(inputpointer));
  864. case c of
  865. #26 : reload;
  866. #10,
  867. #13 : linebreak;
  868. end;
  869. until (found=2);
  870. end;
  871. end;
  872. procedure tscannerfile.skipccomment;
  873. var
  874. found : longint;
  875. begin
  876. inc_comment_level;
  877. readchar;
  878. { this is currently not supported }
  879. if c='$' then
  880. Message(scan_e_wrong_styled_switch);
  881. { skip comment }
  882. while (comment_level>0) do
  883. begin
  884. found:=0;
  885. repeat
  886. case c of
  887. #26 : Message(scan_f_end_of_file);
  888. '*' : begin
  889. if found=3 then
  890. begin
  891. inc_comment_level;
  892. found:=0;
  893. end
  894. else
  895. found:=1;
  896. end;
  897. '/' : begin
  898. if found=1 then
  899. begin
  900. dec_comment_level;
  901. if comment_level=0 then
  902. found:=2
  903. else
  904. found:=0;
  905. end
  906. else found:=3;
  907. end;
  908. else
  909. found:=0;
  910. end;
  911. c:=inputpointer^;
  912. if c=#0 then
  913. reload
  914. else
  915. inc(longint(inputpointer));
  916. case c of
  917. #26 : reload;
  918. #10,
  919. #13 : linebreak;
  920. end;
  921. until (found=2);
  922. end;
  923. end;
  924. procedure tscannerfile.readtoken;
  925. var
  926. code : integer;
  927. low,high,mid : longint;
  928. m : longint;
  929. mac : pmacrosym;
  930. asciinr : string[3];
  931. label
  932. exit_label;
  933. begin
  934. { was there already a token read, then return that token }
  935. if nexttoken<>NOTOKEN then
  936. begin
  937. token:=nexttoken;
  938. nexttoken:=NOTOKEN;
  939. goto exit_label;
  940. end;
  941. { Skip all spaces and comments }
  942. repeat
  943. case c of
  944. '{' :
  945. skipcomment;
  946. ' ',#9..#13 :
  947. skipspace;
  948. else
  949. break;
  950. end;
  951. until false;
  952. { Save current token position, for EOF its already loaded }
  953. if c<>#26 then
  954. gettokenpos;
  955. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  956. if c in ['A'..'Z','a'..'z','_'] then
  957. begin
  958. readstring;
  959. token:=ID;
  960. idtoken:=ID;
  961. { keyword or any other known token,
  962. pattern is always uppercased }
  963. if (pattern[1]<>'_') and (length(pattern) in [2..tokenidlen]) then
  964. begin
  965. low:=ord(tokenidx[length(pattern),pattern[1]].first);
  966. high:=ord(tokenidx[length(pattern),pattern[1]].last);
  967. while low<high do
  968. begin
  969. mid:=(high+low+1) shr 1;
  970. if pattern<tokeninfo[ttoken(mid)].str then
  971. high:=mid-1
  972. else
  973. low:=mid;
  974. end;
  975. if pattern=tokeninfo[ttoken(high)].str then
  976. begin
  977. if tokeninfo[ttoken(high)].keyword in aktmodeswitches then
  978. token:=ttoken(high);
  979. idtoken:=ttoken(high);
  980. end;
  981. end;
  982. { Only process identifiers and not keywords }
  983. if token=ID then
  984. begin
  985. { this takes some time ... }
  986. if (cs_support_macro in aktmoduleswitches) then
  987. begin
  988. mac:=pmacrosym(macros^.search(pattern));
  989. if assigned(mac) and (assigned(mac^.buftext)) then
  990. begin
  991. insertmacro(mac^.buftext,mac^.buflen);
  992. { handle empty macros }
  993. if c=#0 then
  994. reload;
  995. { play it again ... }
  996. inc(yylexcount);
  997. if yylexcount>16 then
  998. Message(scan_w_macro_deep_ten);
  999. readtoken;
  1000. { that's all folks }
  1001. dec(yylexcount);
  1002. exit;
  1003. end;
  1004. end;
  1005. end;
  1006. { return token }
  1007. goto exit_label;
  1008. end
  1009. else
  1010. begin
  1011. idtoken:=NOID;
  1012. case c of
  1013. '$' :
  1014. begin
  1015. readnumber;
  1016. token:=INTCONST;
  1017. goto exit_label;
  1018. end;
  1019. '%' :
  1020. begin
  1021. readnumber;
  1022. token:=INTCONST;
  1023. goto exit_label;
  1024. end;
  1025. '0'..'9' :
  1026. begin
  1027. readnumber;
  1028. if (c in ['.','e','E']) then
  1029. begin
  1030. { first check for a . }
  1031. if c='.' then
  1032. begin
  1033. readchar;
  1034. { is it a .. from a range? }
  1035. case c of
  1036. '.' :
  1037. begin
  1038. readchar;
  1039. token:=INTCONST;
  1040. nexttoken:=POINTPOINT;
  1041. goto exit_label;
  1042. end;
  1043. ')' :
  1044. begin
  1045. readchar;
  1046. token:=INTCONST;
  1047. nexttoken:=RECKKLAMMER;
  1048. goto exit_label;
  1049. end;
  1050. end;
  1051. { insert the number after the . }
  1052. pattern:=pattern+'.';
  1053. while c in ['0'..'9'] do
  1054. begin
  1055. pattern:=pattern+c;
  1056. readchar;
  1057. end;
  1058. end;
  1059. { E can also follow after a point is scanned }
  1060. if c in ['e','E'] then
  1061. begin
  1062. pattern:=pattern+'E';
  1063. readchar;
  1064. if c in ['-','+'] then
  1065. begin
  1066. pattern:=pattern+c;
  1067. readchar;
  1068. end;
  1069. if not(c in ['0'..'9']) then
  1070. Message(scan_f_illegal_char);
  1071. while c in ['0'..'9'] do
  1072. begin
  1073. pattern:=pattern+c;
  1074. readchar;
  1075. end;
  1076. end;
  1077. token:=REALNUMBER;
  1078. goto exit_label;
  1079. end;
  1080. token:=INTCONST;
  1081. goto exit_label;
  1082. end;
  1083. ';' :
  1084. begin
  1085. readchar;
  1086. token:=SEMICOLON;
  1087. goto exit_label;
  1088. end;
  1089. '[' :
  1090. begin
  1091. readchar;
  1092. token:=LECKKLAMMER;
  1093. goto exit_label;
  1094. end;
  1095. ']' :
  1096. begin
  1097. readchar;
  1098. token:=RECKKLAMMER;
  1099. goto exit_label;
  1100. end;
  1101. '(' :
  1102. begin
  1103. readchar;
  1104. case c of
  1105. '*' :
  1106. begin
  1107. skipoldtpcomment;
  1108. readtoken;
  1109. exit;
  1110. end;
  1111. '.' :
  1112. begin
  1113. readchar;
  1114. token:=LECKKLAMMER;
  1115. goto exit_label;
  1116. end;
  1117. end;
  1118. token:=LKLAMMER;
  1119. goto exit_label;
  1120. end;
  1121. ')' :
  1122. begin
  1123. readchar;
  1124. token:=RKLAMMER;
  1125. goto exit_label;
  1126. end;
  1127. '+' :
  1128. begin
  1129. readchar;
  1130. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1131. begin
  1132. readchar;
  1133. token:=_PLUSASN;
  1134. goto exit_label;
  1135. end;
  1136. token:=PLUS;
  1137. goto exit_label;
  1138. end;
  1139. '-' :
  1140. begin
  1141. readchar;
  1142. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1143. begin
  1144. readchar;
  1145. token:=_MINUSASN;
  1146. goto exit_label;
  1147. end;
  1148. token:=MINUS;
  1149. goto exit_label;
  1150. end;
  1151. ':' :
  1152. begin
  1153. readchar;
  1154. if c='=' then
  1155. begin
  1156. readchar;
  1157. token:=ASSIGNMENT;
  1158. goto exit_label;
  1159. end;
  1160. token:=COLON;
  1161. goto exit_label;
  1162. end;
  1163. '*' :
  1164. begin
  1165. readchar;
  1166. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1167. begin
  1168. readchar;
  1169. token:=_STARASN;
  1170. end
  1171. else
  1172. if c='*' then
  1173. begin
  1174. readchar;
  1175. token:=STARSTAR;
  1176. end
  1177. else
  1178. token:=STAR;
  1179. goto exit_label;
  1180. end;
  1181. '/' :
  1182. begin
  1183. readchar;
  1184. case c of
  1185. '=' :
  1186. begin
  1187. if (cs_support_c_operators in aktmoduleswitches) then
  1188. begin
  1189. readchar;
  1190. token:=_SLASHASN;
  1191. goto exit_label;
  1192. end;
  1193. end;
  1194. '/' :
  1195. begin
  1196. skipdelphicomment;
  1197. readtoken;
  1198. exit;
  1199. end;
  1200. '*' :
  1201. begin
  1202. skipccomment;
  1203. readtoken;
  1204. exit;
  1205. end;
  1206. end;
  1207. token:=SLASH;
  1208. goto exit_label;
  1209. end;
  1210. '=' :
  1211. begin
  1212. readchar;
  1213. token:=EQUAL;
  1214. goto exit_label;
  1215. end;
  1216. '.' :
  1217. begin
  1218. readchar;
  1219. case c of
  1220. '.' :
  1221. begin
  1222. readchar;
  1223. token:=POINTPOINT;
  1224. goto exit_label;
  1225. end;
  1226. ')' :
  1227. begin
  1228. readchar;
  1229. token:=RECKKLAMMER;
  1230. goto exit_label;
  1231. end;
  1232. end;
  1233. token:=POINT;
  1234. goto exit_label;
  1235. end;
  1236. '@' :
  1237. begin
  1238. readchar;
  1239. if c='@' then
  1240. begin
  1241. readchar;
  1242. token:=DOUBLEADDR;
  1243. end
  1244. else
  1245. token:=KLAMMERAFFE;
  1246. goto exit_label;
  1247. end;
  1248. ',' :
  1249. begin
  1250. readchar;
  1251. token:=COMMA;
  1252. goto exit_label;
  1253. end;
  1254. '''','#','^' :
  1255. begin
  1256. if c='^' then
  1257. begin
  1258. readchar;
  1259. c:=upcase(c);
  1260. if (block_type=bt_type) or
  1261. (lasttoken=ID) or
  1262. (lasttoken=RKLAMMER) or (lasttoken=RECKKLAMMER) or (lasttoken=CARET) then
  1263. begin
  1264. token:=CARET;
  1265. goto exit_label;
  1266. end
  1267. else
  1268. begin
  1269. if c<#64 then
  1270. pattern:=chr(ord(c)+64)
  1271. else
  1272. pattern:=chr(ord(c)-64);
  1273. readchar;
  1274. end;
  1275. end
  1276. else
  1277. pattern:='';
  1278. repeat
  1279. case c of
  1280. '#' :
  1281. begin
  1282. readchar; { read # }
  1283. if c='$' then
  1284. begin
  1285. readchar; { read leading $ }
  1286. asciinr:='$';
  1287. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<3) do
  1288. begin
  1289. asciinr:=asciinr+c;
  1290. readchar;
  1291. end;
  1292. end
  1293. else
  1294. begin
  1295. asciinr:='';
  1296. while (c in ['0'..'9']) and (length(asciinr)<3) do
  1297. begin
  1298. asciinr:=asciinr+c;
  1299. readchar;
  1300. end;
  1301. end;
  1302. valint(asciinr,m,code);
  1303. if (asciinr='') or (code<>0) or
  1304. (m<0) or (m>255) then
  1305. Message(scan_e_illegal_char_const);
  1306. pattern:=pattern+chr(m);
  1307. end;
  1308. '''' :
  1309. begin
  1310. repeat
  1311. readchar;
  1312. case c of
  1313. #26 :
  1314. Message(scan_f_end_of_file);
  1315. newline :
  1316. Message(scan_f_string_exceeds_line);
  1317. '''' :
  1318. begin
  1319. readchar;
  1320. if c<>'''' then
  1321. break;
  1322. end;
  1323. end;
  1324. pattern:=pattern+c;
  1325. until false;
  1326. end;
  1327. '^' :
  1328. begin
  1329. readchar;
  1330. if c<#64 then
  1331. c:=chr(ord(c)+64)
  1332. else
  1333. c:=chr(ord(c)-64);
  1334. pattern:=pattern+c;
  1335. readchar;
  1336. end;
  1337. else
  1338. break;
  1339. end;
  1340. until false;
  1341. { strings with length 1 become const chars }
  1342. if length(pattern)=1 then
  1343. token:=CCHAR
  1344. else
  1345. token:=CSTRING;
  1346. goto exit_label;
  1347. end;
  1348. '>' :
  1349. begin
  1350. readchar;
  1351. case c of
  1352. '=' :
  1353. begin
  1354. readchar;
  1355. token:=GTE;
  1356. goto exit_label;
  1357. end;
  1358. '>' :
  1359. begin
  1360. readchar;
  1361. token:=_SHR;
  1362. goto exit_label;
  1363. end;
  1364. '<' :
  1365. begin { >< is for a symetric diff for sets }
  1366. readchar;
  1367. token:=SYMDIF;
  1368. goto exit_label;
  1369. end;
  1370. end;
  1371. token:=GT;
  1372. goto exit_label;
  1373. end;
  1374. '<' :
  1375. begin
  1376. readchar;
  1377. case c of
  1378. '>' :
  1379. begin
  1380. readchar;
  1381. token:=UNEQUAL;
  1382. goto exit_label;
  1383. end;
  1384. '=' :
  1385. begin
  1386. readchar;
  1387. token:=LTE;
  1388. goto exit_label;
  1389. end;
  1390. '<' :
  1391. begin
  1392. readchar;
  1393. token:=_SHL;
  1394. goto exit_label;
  1395. end;
  1396. end;
  1397. token:=LT;
  1398. goto exit_label;
  1399. end;
  1400. #26 :
  1401. begin
  1402. token:=_EOF;
  1403. checkpreprocstack;
  1404. goto exit_label;
  1405. end;
  1406. else
  1407. begin
  1408. Message(scan_f_illegal_char);
  1409. end;
  1410. end;
  1411. end;
  1412. exit_label:
  1413. lasttoken:=token;
  1414. end;
  1415. function tscannerfile.readpreproc:ttoken;
  1416. begin
  1417. skipspace;
  1418. case c of
  1419. 'A'..'Z',
  1420. 'a'..'z',
  1421. '_','0'..'9' : begin
  1422. preprocpat:=readid;
  1423. readpreproc:=ID;
  1424. end;
  1425. '(' : begin
  1426. readchar;
  1427. readpreproc:=LKLAMMER;
  1428. end;
  1429. ')' : begin
  1430. readchar;
  1431. readpreproc:=RKLAMMER;
  1432. end;
  1433. '+' : begin
  1434. readchar;
  1435. readpreproc:=PLUS;
  1436. end;
  1437. '-' : begin
  1438. readchar;
  1439. readpreproc:=MINUS;
  1440. end;
  1441. '*' : begin
  1442. readchar;
  1443. readpreproc:=STAR;
  1444. end;
  1445. '/' : begin
  1446. readchar;
  1447. readpreproc:=SLASH;
  1448. end;
  1449. '=' : begin
  1450. readchar;
  1451. readpreproc:=EQUAL;
  1452. end;
  1453. '>' : begin
  1454. readchar;
  1455. if c='=' then
  1456. begin
  1457. readchar;
  1458. readpreproc:=GTE;
  1459. end
  1460. else
  1461. readpreproc:=GT;
  1462. end;
  1463. '<' : begin
  1464. readchar;
  1465. case c of
  1466. '>' : begin
  1467. readchar;
  1468. readpreproc:=UNEQUAL;
  1469. end;
  1470. '=' : begin
  1471. readchar;
  1472. readpreproc:=LTE;
  1473. end;
  1474. else readpreproc:=LT;
  1475. end;
  1476. end;
  1477. #26 : begin
  1478. checkpreprocstack;
  1479. Message(scan_f_end_of_file);
  1480. end;
  1481. else
  1482. begin
  1483. readpreproc:=_EOF;
  1484. checkpreprocstack;
  1485. end;
  1486. end;
  1487. end;
  1488. function tscannerfile.asmgetchar : char;
  1489. begin
  1490. if lastasmgetchar<>#0 then
  1491. begin
  1492. c:=lastasmgetchar;
  1493. lastasmgetchar:=#0;
  1494. end
  1495. else
  1496. readchar;
  1497. case c of
  1498. '{' : begin
  1499. skipcomment;
  1500. asmgetchar:=c;
  1501. exit;
  1502. end;
  1503. '/' : begin
  1504. readchar;
  1505. if c='/' then
  1506. begin
  1507. skipdelphicomment;
  1508. asmgetchar:=c;
  1509. end
  1510. else
  1511. begin
  1512. asmgetchar:='/';
  1513. lastasmgetchar:=c;
  1514. end;
  1515. exit;
  1516. end;
  1517. '(' : begin
  1518. readchar;
  1519. if c='*' then
  1520. begin
  1521. skipoldtpcomment;
  1522. asmgetchar:=c;
  1523. end
  1524. else
  1525. begin
  1526. asmgetchar:='(';
  1527. lastasmgetchar:=c;
  1528. end;
  1529. exit;
  1530. end;
  1531. else
  1532. begin
  1533. asmgetchar:=c;
  1534. end;
  1535. end;
  1536. end;
  1537. begin
  1538. create_tokenidx;
  1539. end.
  1540. {
  1541. $Log$
  1542. Revision 1.86 1999-06-02 22:44:19 pierre
  1543. * previous wrong log corrected
  1544. Revision 1.85 1999/06/02 22:25:49 pierre
  1545. * changed $ifdef FPC @ into $ifndef TP
  1546. Revision 1.84 1999/05/31 23:28:42 pierre
  1547. * problem with main file end without newline
  1548. Revision 1.83 1999/05/20 14:57:29 peter
  1549. * fixed line counting with macro's
  1550. Revision 1.82 1999/05/04 21:45:04 florian
  1551. * changes to compile it with Delphi 4.0
  1552. Revision 1.81 1999/04/07 14:36:44 pierre
  1553. + better preproc stack checking and report
  1554. Revision 1.80 1999/04/06 11:20:59 peter
  1555. * more hashing for keyword table
  1556. Revision 1.79 1999/04/01 22:05:59 peter
  1557. * '1.' is now parsed as a real
  1558. Revision 1.78 1999/03/26 19:10:06 peter
  1559. * support also ^^
  1560. Revision 1.77 1999/03/26 00:05:45 peter
  1561. * released valintern
  1562. + deffile is now removed when compiling is finished
  1563. * ^( compiles now correct
  1564. + static directive
  1565. * shrd fixed
  1566. Revision 1.76 1999/03/24 23:17:24 peter
  1567. * fixed bugs 212,222,225,227,229,231,233
  1568. Revision 1.75 1999/03/16 21:00:27 peter
  1569. * fixed old tp comment behaviour within directives
  1570. Revision 1.74 1999/03/11 10:46:29 daniel
  1571. * Reverted C styled comments
  1572. Revision 1.73 1999/03/02 22:49:35 peter
  1573. * fixed nested comments for old style tp and c
  1574. Revision 1.72 1999/02/02 00:15:10 florian
  1575. + c styled comments
  1576. Revision 1.71 1999/01/27 13:05:45 pierre
  1577. * give include file name on error
  1578. Revision 1.70 1999/01/19 12:14:38 peter
  1579. * fixed eof bug with includefiles
  1580. Revision 1.69 1998/12/11 00:03:46 peter
  1581. + globtype,tokens,version unit splitted from globals
  1582. Revision 1.68 1998/11/16 15:41:44 peter
  1583. * tp7 didn't like my ifopt H+ :(
  1584. Revision 1.67 1998/11/16 12:18:06 peter
  1585. * H+ fixes
  1586. Revision 1.66 1998/11/05 23:48:29 peter
  1587. * recordtype.field support in constant expressions
  1588. * fixed imul for oa_imm8 which was not allowed
  1589. * fixed reading of local typed constants
  1590. * fixed comment reading which is not any longer a separator
  1591. Revision 1.65 1998/11/03 11:35:02 peter
  1592. * don't check for endif if error
  1593. Revision 1.64 1998/10/21 20:16:05 peter
  1594. * beter line info for conditionals
  1595. Revision 1.63 1998/10/16 14:20:57 daniel
  1596. * Faster keyword scanning.
  1597. * Import library and smartlink library in one file.
  1598. Revision 1.62 1998/10/15 12:22:23 pierre
  1599. * close include files immediately after end reading
  1600. instead of waiting until unit compilation ended !
  1601. Revision 1.61 1998/10/09 11:08:15 peter
  1602. * fixed inputfile^.name^ bug
  1603. Revision 1.60 1998/10/09 08:56:31 pierre
  1604. * several memory leaks fixed
  1605. Revision 1.59 1998/10/08 23:29:05 peter
  1606. * -vu shows unit info, -vt shows tried/used files
  1607. Revision 1.58 1998/10/08 17:17:30 pierre
  1608. * current_module old scanner tagged as invalid if unit is recompiled
  1609. + added ppheap for better info on tracegetmem of heaptrc
  1610. (adds line column and file index)
  1611. * several memory leaks removed ith help of heaptrc !!
  1612. Revision 1.57 1998/10/08 13:45:25 peter
  1613. * EOF position is now correctly saved in aktfilepos
  1614. Revision 1.56 1998/09/30 16:43:38 peter
  1615. * fixed unit interdependency with circular uses
  1616. Revision 1.55 1998/09/28 16:57:26 pierre
  1617. * changed all length(p^.value_str^) into str_length(p)
  1618. to get it work with and without ansistrings
  1619. * changed sourcefiles field of tmodule to a pointer
  1620. Revision 1.54 1998/09/26 17:45:41 peter
  1621. + idtoken and only one token table
  1622. Revision 1.53 1998/09/24 23:49:20 peter
  1623. + aktmodeswitches
  1624. Revision 1.52 1998/09/18 16:03:45 florian
  1625. * some changes to compile with Delphi
  1626. Revision 1.51 1998/09/16 16:41:49 peter
  1627. * merged fixes
  1628. Revision 1.50.2.1 1998/09/16 16:09:49 peter
  1629. * on/off support also for the local/module switches
  1630. Revision 1.50 1998/09/04 08:36:06 peter
  1631. + (. and .) which are equal to [ and ]
  1632. Revision 1.49 1998/09/03 11:24:03 peter
  1633. * moved more inputfile things from tscannerfile to tinputfile
  1634. * changed ifdef Sourceline to cs_asm_source
  1635. Revision 1.48 1998/09/01 12:51:02 peter
  1636. * close also resets lastlinepos
  1637. Revision 1.47 1998/09/01 09:01:52 peter
  1638. * initialize all object variables in .init
  1639. Revision 1.46 1998/08/29 13:49:00 peter
  1640. * fixed freemem calls which had the wrong size sometimes
  1641. Revision 1.45 1998/08/26 15:35:35 peter
  1642. * fixed scannerfiles for macros
  1643. + $I %<environment>%
  1644. Revision 1.44 1998/08/20 16:09:55 pierre
  1645. * tokenpos has to be restored also after
  1646. printstatus
  1647. Revision 1.43 1998/08/20 09:26:45 pierre
  1648. + funcret setting in underproc testing
  1649. compile with _dTEST_FUNCRET
  1650. Revision 1.42 1998/08/19 14:57:51 peter
  1651. * small fix for aktfilepos
  1652. Revision 1.41 1998/08/18 14:17:10 pierre
  1653. * bug about assigning the return value of a function to
  1654. a procvar fixed : warning
  1655. assigning a proc to a procvar need @ in FPC mode !!
  1656. * missing file/line info restored
  1657. Revision 1.40 1998/08/11 14:04:33 peter
  1658. * auto close an open file and better error msg
  1659. Revision 1.39 1998/08/10 14:50:26 peter
  1660. + localswitches, moduleswitches, globalswitches splitting
  1661. Revision 1.38 1998/08/10 10:18:34 peter
  1662. + Compiler,Comphook unit which are the new interface units to the
  1663. compiler
  1664. Revision 1.37 1998/07/23 12:40:41 michael
  1665. No nested comments in Delphi mode.
  1666. Revision 1.36 1998/07/20 22:17:17 florian
  1667. * hex constants in numeric char (#$54#$43 ...) are now allowed
  1668. * there was a bug in record_var_dec which prevents the used
  1669. of nested variant records (for example drivers.tevent of tv)
  1670. Revision 1.35 1998/07/14 21:38:13 peter
  1671. + support for with p^do constructs
  1672. Revision 1.34 1998/07/14 14:47:04 peter
  1673. * released NEWINPUT
  1674. Revision 1.33 1998/07/10 10:48:40 peter
  1675. * fixed realnumber scanning
  1676. * [] after asmblock was not uppercased anymore
  1677. Revision 1.31 1998/07/07 17:39:38 peter
  1678. * fixed $I with following eof
  1679. Revision 1.30 1998/07/07 12:32:55 peter
  1680. * status.currentsource is now calculated in verbose (more accurated)
  1681. Revision 1.29 1998/07/07 11:20:11 peter
  1682. + NEWINPUT for a better inputfile and scanner object
  1683. Revision 1.28 1998/07/01 15:26:57 peter
  1684. * better bufferfile.reset error handling
  1685. Revision 1.27 1998/06/25 08:48:19 florian
  1686. * first version of rtti support
  1687. Revision 1.26 1998/06/16 08:56:30 peter
  1688. + targetcpu
  1689. * cleaner pmodules for newppu
  1690. Revision 1.25 1998/06/13 00:10:15 peter
  1691. * working browser and newppu
  1692. * some small fixes against crashes which occured in bp7 (but not in
  1693. fpc?!)
  1694. Revision 1.24 1998/06/12 10:32:36 pierre
  1695. * column problem hopefully solved
  1696. + C vars declaration changed
  1697. Revision 1.23 1998/06/03 22:49:02 peter
  1698. + wordbool,longbool
  1699. * rename bis,von -> high,low
  1700. * moved some systemunit loading/creating to psystem.pas
  1701. Revision 1.21 1998/05/27 00:20:32 peter
  1702. * some scanner optimizes
  1703. * automaticly aout2exe for go32v1
  1704. * fixed dynamiclinker option which was added at the wrong place
  1705. Revision 1.20 1998/05/23 01:21:30 peter
  1706. + aktasmmode, aktoptprocessor, aktoutputformat
  1707. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  1708. + $LIBNAME to set the library name where the unit will be put in
  1709. * splitted cgi386 a bit (codeseg to large for bp7)
  1710. * nasm, tasm works again. nasm moved to ag386nsm.pas
  1711. Revision 1.19 1998/05/20 09:42:37 pierre
  1712. + UseTokenInfo now default
  1713. * unit in interface uses and implementation uses gives error now
  1714. * only one error for unknown symbol (uses lastsymknown boolean)
  1715. the problem came from the label code !
  1716. + first inlined procedures and function work
  1717. (warning there might be allowed cases were the result is still wrong !!)
  1718. * UseBrower updated gives a global list of all position of all used symbols
  1719. with switch -gb
  1720. Revision 1.18 1998/05/12 10:47:00 peter
  1721. * moved printstatus to verb_def
  1722. + V_Normal which is between V_Error and V_Warning and doesn't have a
  1723. prefix like error: warning: and is included in V_Default
  1724. * fixed some messages
  1725. * first time parameter scan is only for -v and -T
  1726. - removed old style messages
  1727. Revision 1.17 1998/05/06 08:38:47 pierre
  1728. * better position info with UseTokenInfo
  1729. UseTokenInfo greatly simplified
  1730. + added check for changed tree after first time firstpass
  1731. (if we could remove all the cases were it happen
  1732. we could skip all firstpass if firstpasscount > 1)
  1733. Only with ExtDebug
  1734. Revision 1.16 1998/05/04 17:54:28 peter
  1735. + smartlinking works (only case jumptable left todo)
  1736. * redesign of systems.pas to support assemblers and linkers
  1737. + Unitname is now also in the PPU-file, increased version to 14
  1738. Revision 1.15 1998/05/01 16:38:46 florian
  1739. * handling of private and protected fixed
  1740. + change_keywords_to_tp implemented to remove
  1741. keywords which aren't supported by tp
  1742. * break and continue are now symbols of the system unit
  1743. + widestring, longstring and ansistring type released
  1744. Revision 1.14 1998/04/30 15:59:42 pierre
  1745. * GDB works again better :
  1746. correct type info in one pass
  1747. + UseTokenInfo for better source position
  1748. * fixed one remaining bug in scanner for line counts
  1749. * several little fixes
  1750. Revision 1.13 1998/04/29 13:42:27 peter
  1751. + $IOCHECKS and $ALIGN to test already, other will follow soon
  1752. * fixed the wrong linecounting with comments
  1753. Revision 1.12 1998/04/29 10:34:04 pierre
  1754. + added some code for ansistring (not complete nor working yet)
  1755. * corrected operator overloading
  1756. * corrected nasm output
  1757. + started inline procedures
  1758. + added starstarn : use ** for exponentiation (^ gave problems)
  1759. + started UseTokenInfo cond to get accurate positions
  1760. Revision 1.11 1998/04/27 23:10:29 peter
  1761. + new scanner
  1762. * $makelib -> if smartlink
  1763. * small filename fixes pmodule.setfilename
  1764. * moved import from files.pas -> import.pas
  1765. }