scanner.pas 58 KB

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