scanner.pas 58 KB

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