scanner.pas 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
  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 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.end_of_file;
  461. begin
  462. checkpreprocstack;
  463. Message(scan_f_end_of_file);
  464. end;
  465. procedure tscannerfile.checkpreprocstack;
  466. begin
  467. { check for missing ifdefs }
  468. while assigned(preprocstack) do
  469. begin
  470. Message3(scan_e_endif_expected,preprocstring[preprocstack^.typ],preprocstack^.name,tostr(preprocstack^.line_nb));
  471. poppreprocstack;
  472. end;
  473. end;
  474. procedure tscannerfile.poppreprocstack;
  475. var
  476. hp : ppreprocstack;
  477. begin
  478. if assigned(preprocstack) then
  479. begin
  480. Message1(scan_c_endif_found,preprocstack^.name);
  481. hp:=preprocstack^.next;
  482. dispose(preprocstack,done);
  483. preprocstack:=hp;
  484. end
  485. else
  486. Message(scan_e_endif_without_if);
  487. end;
  488. procedure tscannerfile.addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:tmsgconst);
  489. begin
  490. preprocstack:=new(ppreprocstack,init(atyp,((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  491. preprocstack^.name:=s;
  492. preprocstack^.line_nb:=line_no;
  493. if preprocstack^.accept then
  494. Message2(w,preprocstack^.name,'accepted')
  495. else
  496. Message2(w,preprocstack^.name,'rejected');
  497. end;
  498. procedure tscannerfile.elsepreprocstack;
  499. begin
  500. if assigned(preprocstack) then
  501. begin
  502. preprocstack^.typ:=pp_else;
  503. preprocstack^.line_nb:=line_no;
  504. if not(assigned(preprocstack^.next)) or (preprocstack^.next^.accept) then
  505. preprocstack^.accept:=not preprocstack^.accept;
  506. if preprocstack^.accept then
  507. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  508. else
  509. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  510. end
  511. else
  512. Message(scan_e_endif_without_if);
  513. end;
  514. procedure tscannerfile.readchar;
  515. begin
  516. c:=inputpointer^;
  517. if c=#0 then
  518. reload
  519. else
  520. inc(longint(inputpointer));
  521. case c of
  522. #26 : reload;
  523. #10,
  524. #13 : linebreak;
  525. end;
  526. end;
  527. procedure tscannerfile.readstring;
  528. var
  529. i : longint;
  530. begin
  531. i:=0;
  532. repeat
  533. case c of
  534. '_',
  535. '0'..'9',
  536. 'A'..'Z' : begin
  537. if i<255 then
  538. begin
  539. inc(i);
  540. orgpattern[i]:=c;
  541. pattern[i]:=c;
  542. end;
  543. c:=inputpointer^;
  544. inc(longint(inputpointer));
  545. end;
  546. 'a'..'z' : begin
  547. if i<255 then
  548. begin
  549. inc(i);
  550. orgpattern[i]:=c;
  551. pattern[i]:=chr(ord(c)-32)
  552. end;
  553. c:=inputpointer^;
  554. inc(longint(inputpointer));
  555. end;
  556. #0 : reload;
  557. #26 : begin
  558. reload;
  559. if c=#26 then
  560. break;
  561. end;
  562. #13,#10 : begin
  563. linebreak;
  564. break;
  565. end;
  566. else
  567. break;
  568. end;
  569. until false;
  570. {$ifndef TP}
  571. {$ifopt H+}
  572. setlength(orgpattern,i);
  573. setlength(pattern,i);
  574. {$else}
  575. orgpattern[0]:=chr(i);
  576. pattern[0]:=chr(i);
  577. {$endif}
  578. {$else}
  579. orgpattern[0]:=chr(i);
  580. pattern[0]:=chr(i);
  581. {$endif}
  582. end;
  583. procedure tscannerfile.readnumber;
  584. var
  585. base,
  586. i : longint;
  587. begin
  588. case c of
  589. '%' : begin
  590. readchar;
  591. base:=2;
  592. pattern[1]:='%';
  593. i:=1;
  594. end;
  595. '$' : begin
  596. readchar;
  597. base:=16;
  598. pattern[1]:='$';
  599. i:=1;
  600. end;
  601. else
  602. begin
  603. base:=10;
  604. i:=0;
  605. end;
  606. end;
  607. while ((base>=10) and (c in ['0'..'9'])) or
  608. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  609. ((base=2) and (c in ['0'..'1'])) do
  610. begin
  611. if i<255 then
  612. begin
  613. inc(i);
  614. pattern[i]:=c;
  615. end;
  616. { get next char }
  617. c:=inputpointer^;
  618. if c=#0 then
  619. reload
  620. else
  621. inc(longint(inputpointer));
  622. end;
  623. { was the next char a linebreak ? }
  624. case c of
  625. #26 : reload;
  626. #10,
  627. #13 : linebreak;
  628. end;
  629. {$ifndef TP}
  630. {$ifopt H+}
  631. setlength(pattern,i);
  632. {$else}
  633. pattern[0]:=chr(i);
  634. {$endif}
  635. {$else}
  636. pattern[0]:=chr(i);
  637. {$endif}
  638. end;
  639. function tscannerfile.readid:string;
  640. begin
  641. readstring;
  642. readid:=pattern;
  643. end;
  644. function tscannerfile.readval:longint;
  645. var
  646. l : longint;
  647. w : integer;
  648. begin
  649. readnumber;
  650. valint(pattern,l,w);
  651. readval:=l;
  652. end;
  653. function tscannerfile.readcomment:string;
  654. var
  655. i : longint;
  656. begin
  657. i:=0;
  658. repeat
  659. case c of
  660. '}' :
  661. if aktcommentstyle=comment_tp then
  662. begin
  663. readchar;
  664. dec_comment_level;
  665. break;
  666. end;
  667. '*' :
  668. if aktcommentstyle=comment_oldtp then
  669. begin
  670. readchar;
  671. if c=')' then
  672. begin
  673. readchar;
  674. dec_comment_level;
  675. break;
  676. end;
  677. end;
  678. #26 :
  679. end_of_file;
  680. else
  681. begin
  682. if (i<255) then
  683. begin
  684. inc(i);
  685. readcomment[i]:=c;
  686. end;
  687. end;
  688. end;
  689. c:=inputpointer^;
  690. if c=#0 then
  691. reload
  692. else
  693. inc(longint(inputpointer));
  694. if c in [#10,#13] then
  695. linebreak;
  696. until false;
  697. {$ifndef TP}
  698. {$ifopt H+}
  699. setlength(readcomment,i);
  700. {$else}
  701. readcomment[0]:=chr(i);
  702. {$endif}
  703. {$else}
  704. readcomment[0]:=chr(i);
  705. {$endif}
  706. end;
  707. function tscannerfile.readstate:char;
  708. var
  709. state : char;
  710. begin
  711. state:=' ';
  712. if c=' ' then
  713. begin
  714. current_scanner^.skipspace;
  715. current_scanner^.readid;
  716. if pattern='ON' then
  717. state:='+'
  718. else
  719. if pattern='OFF' then
  720. state:='-';
  721. end
  722. else
  723. state:=c;
  724. if not (state in ['+','-']) then
  725. Message(scan_e_wrong_switch_toggle);
  726. readstate:=state;
  727. end;
  728. procedure tscannerfile.skipspace;
  729. begin
  730. while c in [' ',#9..#13] do
  731. begin
  732. c:=inputpointer^;
  733. if c=#0 then
  734. reload
  735. else
  736. inc(longint(inputpointer));
  737. case c of
  738. #26 : reload;
  739. #10,
  740. #13 : linebreak;
  741. end;
  742. end;
  743. end;
  744. procedure tscannerfile.skipuntildirective;
  745. var
  746. found : longint;
  747. next_char_loaded : boolean;
  748. oldcommentstyle : tcommentstyle;
  749. begin
  750. found:=0;
  751. next_char_loaded:=false;
  752. oldcommentstyle:=aktcommentstyle;
  753. repeat
  754. case c of
  755. #26 :
  756. end_of_file;
  757. '{' :
  758. begin
  759. if not(m_nested_comment in aktmodeswitches) or
  760. (comment_level=0) then
  761. begin
  762. found:=1;
  763. aktcommentstyle:=comment_tp;
  764. end;
  765. inc_comment_level;
  766. end;
  767. '}' :
  768. begin
  769. dec_comment_level;
  770. found:=0;
  771. end;
  772. '$' :
  773. begin
  774. if found=1 then
  775. found:=2;
  776. end;
  777. '''' :
  778. if (m_tp in aktmodeswitches) or
  779. (m_delphi in aktmodeswitches) then
  780. begin
  781. repeat
  782. readchar;
  783. case c of
  784. #26 :
  785. end_of_file;
  786. newline :
  787. break;
  788. '''' :
  789. begin
  790. readchar;
  791. if c<>'''' then
  792. break;
  793. end;
  794. end;
  795. until false;
  796. end;
  797. '(' :
  798. begin
  799. readchar;
  800. if c='*' then
  801. begin
  802. readchar;
  803. if c='$' then
  804. begin
  805. found:=2;
  806. inc_comment_level;
  807. aktcommentstyle:=comment_oldtp;
  808. end
  809. else
  810. begin
  811. skipoldtpcomment;
  812. aktcommentstyle:=oldcommentstyle;
  813. end;
  814. end
  815. else
  816. next_char_loaded:=true;
  817. end;
  818. else
  819. found:=0;
  820. end;
  821. if next_char_loaded then
  822. next_char_loaded:=false
  823. else
  824. begin
  825. c:=inputpointer^;
  826. if c=#0 then
  827. reload
  828. else
  829. inc(longint(inputpointer));
  830. case c of
  831. #26 : reload;
  832. #10,
  833. #13 : linebreak;
  834. end;
  835. end;
  836. until (found=2);
  837. end;
  838. {****************************************************************************
  839. Include directive scanning/parsing
  840. ****************************************************************************}
  841. {$i scandir.inc}
  842. {****************************************************************************
  843. Comment Handling
  844. ****************************************************************************}
  845. procedure tscannerfile.skipcomment;
  846. begin
  847. aktcommentstyle:=comment_tp;
  848. readchar;
  849. inc_comment_level;
  850. { handle compiler switches }
  851. if (c='$') then
  852. handledirectives;
  853. { handle_switches can dec comment_level, }
  854. while (comment_level>0) do
  855. begin
  856. case c of
  857. '{' : inc_comment_level;
  858. '}' : dec_comment_level;
  859. #26 : end_of_file;
  860. end;
  861. c:=inputpointer^;
  862. if c=#0 then
  863. reload
  864. else
  865. inc(longint(inputpointer));
  866. case c of
  867. #26 : reload;
  868. #10,
  869. #13 : linebreak;
  870. end;
  871. end;
  872. aktcommentstyle:=comment_none;
  873. end;
  874. procedure tscannerfile.skipdelphicomment;
  875. begin
  876. aktcommentstyle:=comment_delphi;
  877. inc_comment_level;
  878. readchar;
  879. { this is currently not supported }
  880. if c='$' then
  881. Message(scan_e_wrong_styled_switch);
  882. { skip comment }
  883. while c<>newline do
  884. begin
  885. if c=#26 then
  886. end_of_file;
  887. readchar;
  888. end;
  889. dec_comment_level;
  890. aktcommentstyle:=comment_none;
  891. end;
  892. procedure tscannerfile.skipoldtpcomment;
  893. var
  894. found : longint;
  895. begin
  896. aktcommentstyle:=comment_oldtp;
  897. inc_comment_level;
  898. readchar;
  899. { this is currently not supported }
  900. if (c='$') then
  901. handledirectives;
  902. { skip comment }
  903. while (comment_level>0) do
  904. begin
  905. found:=0;
  906. repeat
  907. case c of
  908. #26 :
  909. end_of_file;
  910. '*' :
  911. begin
  912. if found=3 then
  913. begin
  914. inc_comment_level;
  915. found:=0;
  916. end
  917. else
  918. found:=1;
  919. end;
  920. ')' :
  921. begin
  922. if found=1 then
  923. begin
  924. dec_comment_level;
  925. if comment_level=0 then
  926. found:=2
  927. else
  928. found:=0;
  929. end;
  930. end;
  931. '(' :
  932. found:=3;
  933. else
  934. found:=0;
  935. end;
  936. c:=inputpointer^;
  937. if c=#0 then
  938. reload
  939. else
  940. inc(longint(inputpointer));
  941. case c of
  942. #26 : reload;
  943. #10,
  944. #13 : linebreak;
  945. end;
  946. until (found=2);
  947. end;
  948. aktcommentstyle:=comment_none;
  949. end;
  950. {****************************************************************************
  951. Token Scanner
  952. ****************************************************************************}
  953. procedure tscannerfile.readtoken;
  954. var
  955. code : integer;
  956. low,high,mid : longint;
  957. m : longint;
  958. mac : pmacrosym;
  959. asciinr : string[3];
  960. label
  961. exit_label;
  962. begin
  963. { was there already a token read, then return that token }
  964. if nexttoken<>NOTOKEN then
  965. begin
  966. token:=nexttoken;
  967. nexttoken:=NOTOKEN;
  968. goto exit_label;
  969. end;
  970. { Skip all spaces and comments }
  971. repeat
  972. case c of
  973. '{' :
  974. skipcomment;
  975. ' ',#9..#13 :
  976. skipspace;
  977. else
  978. break;
  979. end;
  980. until false;
  981. { Save current token position, for EOF its already loaded }
  982. if c<>#26 then
  983. gettokenpos;
  984. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  985. if c in ['A'..'Z','a'..'z','_'] then
  986. begin
  987. readstring;
  988. token:=_ID;
  989. idtoken:=_ID;
  990. { keyword or any other known token,
  991. pattern is always uppercased }
  992. if (pattern[1]<>'_') and (length(pattern) in [2..tokenidlen]) then
  993. begin
  994. low:=ord(tokenidx[length(pattern),pattern[1]].first);
  995. high:=ord(tokenidx[length(pattern),pattern[1]].last);
  996. while low<high do
  997. begin
  998. mid:=(high+low+1) shr 1;
  999. if pattern<tokeninfo[ttoken(mid)].str then
  1000. high:=mid-1
  1001. else
  1002. low:=mid;
  1003. end;
  1004. if pattern=tokeninfo[ttoken(high)].str then
  1005. begin
  1006. if tokeninfo[ttoken(high)].keyword in aktmodeswitches then
  1007. token:=ttoken(high);
  1008. idtoken:=ttoken(high);
  1009. end;
  1010. end;
  1011. { Only process identifiers and not keywords }
  1012. if token=_ID then
  1013. begin
  1014. { this takes some time ... }
  1015. if (cs_support_macro in aktmoduleswitches) then
  1016. begin
  1017. mac:=pmacrosym(macros^.search(pattern));
  1018. if assigned(mac) and (assigned(mac^.buftext)) then
  1019. begin
  1020. insertmacro(mac^.buftext,mac^.buflen);
  1021. { handle empty macros }
  1022. if c=#0 then
  1023. reload;
  1024. { play it again ... }
  1025. inc(yylexcount);
  1026. if yylexcount>16 then
  1027. Message(scan_w_macro_deep_ten);
  1028. readtoken;
  1029. { that's all folks }
  1030. dec(yylexcount);
  1031. exit;
  1032. end;
  1033. end;
  1034. end;
  1035. { return token }
  1036. goto exit_label;
  1037. end
  1038. else
  1039. begin
  1040. idtoken:=_NOID;
  1041. case c of
  1042. '$' :
  1043. begin
  1044. readnumber;
  1045. token:=_INTCONST;
  1046. goto exit_label;
  1047. end;
  1048. '%' :
  1049. begin
  1050. readnumber;
  1051. token:=_INTCONST;
  1052. goto exit_label;
  1053. end;
  1054. '0'..'9' :
  1055. begin
  1056. readnumber;
  1057. if (c in ['.','e','E']) then
  1058. begin
  1059. { first check for a . }
  1060. if c='.' then
  1061. begin
  1062. readchar;
  1063. { is it a .. from a range? }
  1064. case c of
  1065. '.' :
  1066. begin
  1067. readchar;
  1068. token:=_INTCONST;
  1069. nexttoken:=_POINTPOINT;
  1070. goto exit_label;
  1071. end;
  1072. ')' :
  1073. begin
  1074. readchar;
  1075. token:=_INTCONST;
  1076. nexttoken:=_RECKKLAMMER;
  1077. goto exit_label;
  1078. end;
  1079. end;
  1080. { insert the number after the . }
  1081. pattern:=pattern+'.';
  1082. while c in ['0'..'9'] do
  1083. begin
  1084. pattern:=pattern+c;
  1085. readchar;
  1086. end;
  1087. end;
  1088. { E can also follow after a point is scanned }
  1089. if c in ['e','E'] then
  1090. begin
  1091. pattern:=pattern+'E';
  1092. readchar;
  1093. if c in ['-','+'] then
  1094. begin
  1095. pattern:=pattern+c;
  1096. readchar;
  1097. end;
  1098. if not(c in ['0'..'9']) then
  1099. Message(scan_f_illegal_char);
  1100. while c in ['0'..'9'] do
  1101. begin
  1102. pattern:=pattern+c;
  1103. readchar;
  1104. end;
  1105. end;
  1106. token:=_REALNUMBER;
  1107. goto exit_label;
  1108. end;
  1109. token:=_INTCONST;
  1110. goto exit_label;
  1111. end;
  1112. ';' :
  1113. begin
  1114. readchar;
  1115. token:=_SEMICOLON;
  1116. goto exit_label;
  1117. end;
  1118. '[' :
  1119. begin
  1120. readchar;
  1121. token:=_LECKKLAMMER;
  1122. goto exit_label;
  1123. end;
  1124. ']' :
  1125. begin
  1126. readchar;
  1127. token:=_RECKKLAMMER;
  1128. goto exit_label;
  1129. end;
  1130. '(' :
  1131. begin
  1132. readchar;
  1133. case c of
  1134. '*' :
  1135. begin
  1136. skipoldtpcomment;
  1137. readtoken;
  1138. exit;
  1139. end;
  1140. '.' :
  1141. begin
  1142. readchar;
  1143. token:=_LECKKLAMMER;
  1144. goto exit_label;
  1145. end;
  1146. end;
  1147. token:=_LKLAMMER;
  1148. goto exit_label;
  1149. end;
  1150. ')' :
  1151. begin
  1152. readchar;
  1153. token:=_RKLAMMER;
  1154. goto exit_label;
  1155. end;
  1156. '+' :
  1157. begin
  1158. readchar;
  1159. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1160. begin
  1161. readchar;
  1162. token:=_PLUSASN;
  1163. goto exit_label;
  1164. end;
  1165. token:=_PLUS;
  1166. goto exit_label;
  1167. end;
  1168. '-' :
  1169. begin
  1170. readchar;
  1171. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1172. begin
  1173. readchar;
  1174. token:=_MINUSASN;
  1175. goto exit_label;
  1176. end;
  1177. token:=_MINUS;
  1178. goto exit_label;
  1179. end;
  1180. ':' :
  1181. begin
  1182. readchar;
  1183. if c='=' then
  1184. begin
  1185. readchar;
  1186. token:=_ASSIGNMENT;
  1187. goto exit_label;
  1188. end;
  1189. token:=_COLON;
  1190. goto exit_label;
  1191. end;
  1192. '*' :
  1193. begin
  1194. readchar;
  1195. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1196. begin
  1197. readchar;
  1198. token:=_STARASN;
  1199. end
  1200. else
  1201. if c='*' then
  1202. begin
  1203. readchar;
  1204. token:=_STARSTAR;
  1205. end
  1206. else
  1207. token:=_STAR;
  1208. goto exit_label;
  1209. end;
  1210. '/' :
  1211. begin
  1212. readchar;
  1213. case c of
  1214. '=' :
  1215. begin
  1216. if (cs_support_c_operators in aktmoduleswitches) then
  1217. begin
  1218. readchar;
  1219. token:=_SLASHASN;
  1220. goto exit_label;
  1221. end;
  1222. end;
  1223. '/' :
  1224. begin
  1225. skipdelphicomment;
  1226. readtoken;
  1227. exit;
  1228. end;
  1229. end;
  1230. token:=_SLASH;
  1231. goto exit_label;
  1232. end;
  1233. '=' :
  1234. begin
  1235. readchar;
  1236. token:=_EQUAL;
  1237. goto exit_label;
  1238. end;
  1239. '.' :
  1240. begin
  1241. readchar;
  1242. case c of
  1243. '.' :
  1244. begin
  1245. readchar;
  1246. token:=_POINTPOINT;
  1247. goto exit_label;
  1248. end;
  1249. ')' :
  1250. begin
  1251. readchar;
  1252. token:=_RECKKLAMMER;
  1253. goto exit_label;
  1254. end;
  1255. end;
  1256. token:=_POINT;
  1257. goto exit_label;
  1258. end;
  1259. '@' :
  1260. begin
  1261. readchar;
  1262. if c='@' then
  1263. begin
  1264. readchar;
  1265. token:=_DOUBLEADDR;
  1266. end
  1267. else
  1268. token:=_KLAMMERAFFE;
  1269. goto exit_label;
  1270. end;
  1271. ',' :
  1272. begin
  1273. readchar;
  1274. token:=_COMMA;
  1275. goto exit_label;
  1276. end;
  1277. '''','#','^' :
  1278. begin
  1279. if c='^' then
  1280. begin
  1281. readchar;
  1282. c:=upcase(c);
  1283. if (block_type=bt_type) or
  1284. (lasttoken=_ID) or
  1285. (lasttoken=_RKLAMMER) or (lasttoken=_RECKKLAMMER) or (lasttoken=_CARET) then
  1286. begin
  1287. token:=_CARET;
  1288. goto exit_label;
  1289. end
  1290. else
  1291. begin
  1292. if c<#64 then
  1293. pattern:=chr(ord(c)+64)
  1294. else
  1295. pattern:=chr(ord(c)-64);
  1296. readchar;
  1297. end;
  1298. end
  1299. else
  1300. pattern:='';
  1301. repeat
  1302. case c of
  1303. '#' :
  1304. begin
  1305. readchar; { read # }
  1306. if c='$' then
  1307. begin
  1308. readchar; { read leading $ }
  1309. asciinr:='$';
  1310. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<3) do
  1311. begin
  1312. asciinr:=asciinr+c;
  1313. readchar;
  1314. end;
  1315. end
  1316. else
  1317. begin
  1318. asciinr:='';
  1319. while (c in ['0'..'9']) and (length(asciinr)<3) do
  1320. begin
  1321. asciinr:=asciinr+c;
  1322. readchar;
  1323. end;
  1324. end;
  1325. valint(asciinr,m,code);
  1326. if (asciinr='') or (code<>0) or
  1327. (m<0) or (m>255) then
  1328. Message(scan_e_illegal_char_const);
  1329. pattern:=pattern+chr(m);
  1330. end;
  1331. '''' :
  1332. begin
  1333. repeat
  1334. readchar;
  1335. case c of
  1336. #26 :
  1337. end_of_file;
  1338. newline :
  1339. Message(scan_f_string_exceeds_line);
  1340. '''' :
  1341. begin
  1342. readchar;
  1343. if c<>'''' then
  1344. break;
  1345. end;
  1346. end;
  1347. pattern:=pattern+c;
  1348. until false;
  1349. end;
  1350. '^' :
  1351. begin
  1352. readchar;
  1353. if c<#64 then
  1354. c:=chr(ord(c)+64)
  1355. else
  1356. c:=chr(ord(c)-64);
  1357. pattern:=pattern+c;
  1358. readchar;
  1359. end;
  1360. else
  1361. break;
  1362. end;
  1363. until false;
  1364. { strings with length 1 become const chars }
  1365. if length(pattern)=1 then
  1366. token:=_CCHAR
  1367. else
  1368. token:=_CSTRING;
  1369. goto exit_label;
  1370. end;
  1371. '>' :
  1372. begin
  1373. readchar;
  1374. case c of
  1375. '=' :
  1376. begin
  1377. readchar;
  1378. token:=_GTE;
  1379. goto exit_label;
  1380. end;
  1381. '>' :
  1382. begin
  1383. readchar;
  1384. token:=_SHR;
  1385. goto exit_label;
  1386. end;
  1387. '<' :
  1388. begin { >< is for a symetric diff for sets }
  1389. readchar;
  1390. token:=_SYMDIF;
  1391. goto exit_label;
  1392. end;
  1393. end;
  1394. token:=_GT;
  1395. goto exit_label;
  1396. end;
  1397. '<' :
  1398. begin
  1399. readchar;
  1400. case c of
  1401. '>' :
  1402. begin
  1403. readchar;
  1404. token:=_UNEQUAL;
  1405. goto exit_label;
  1406. end;
  1407. '=' :
  1408. begin
  1409. readchar;
  1410. token:=_LTE;
  1411. goto exit_label;
  1412. end;
  1413. '<' :
  1414. begin
  1415. readchar;
  1416. token:=_SHL;
  1417. goto exit_label;
  1418. end;
  1419. end;
  1420. token:=_LT;
  1421. goto exit_label;
  1422. end;
  1423. #26 :
  1424. begin
  1425. token:=_EOF;
  1426. checkpreprocstack;
  1427. goto exit_label;
  1428. end;
  1429. else
  1430. begin
  1431. Message(scan_f_illegal_char);
  1432. end;
  1433. end;
  1434. end;
  1435. exit_label:
  1436. lasttoken:=token;
  1437. end;
  1438. function tscannerfile.readpreproc:ttoken;
  1439. begin
  1440. skipspace;
  1441. case c of
  1442. 'A'..'Z',
  1443. 'a'..'z',
  1444. '_','0'..'9' : begin
  1445. preprocpat:=readid;
  1446. readpreproc:=_ID;
  1447. end;
  1448. '(' : begin
  1449. readchar;
  1450. readpreproc:=_LKLAMMER;
  1451. end;
  1452. ')' : begin
  1453. readchar;
  1454. readpreproc:=_RKLAMMER;
  1455. end;
  1456. '+' : begin
  1457. readchar;
  1458. readpreproc:=_PLUS;
  1459. end;
  1460. '-' : begin
  1461. readchar;
  1462. readpreproc:=_MINUS;
  1463. end;
  1464. '*' : begin
  1465. readchar;
  1466. readpreproc:=_STAR;
  1467. end;
  1468. '/' : begin
  1469. readchar;
  1470. readpreproc:=_SLASH;
  1471. end;
  1472. '=' : begin
  1473. readchar;
  1474. readpreproc:=_EQUAL;
  1475. end;
  1476. '>' : begin
  1477. readchar;
  1478. if c='=' then
  1479. begin
  1480. readchar;
  1481. readpreproc:=_GTE;
  1482. end
  1483. else
  1484. readpreproc:=_GT;
  1485. end;
  1486. '<' : begin
  1487. readchar;
  1488. case c of
  1489. '>' : begin
  1490. readchar;
  1491. readpreproc:=_UNEQUAL;
  1492. end;
  1493. '=' : begin
  1494. readchar;
  1495. readpreproc:=_LTE;
  1496. end;
  1497. else readpreproc:=_LT;
  1498. end;
  1499. end;
  1500. #26 :
  1501. end_of_file;
  1502. else
  1503. begin
  1504. readpreproc:=_EOF;
  1505. checkpreprocstack;
  1506. end;
  1507. end;
  1508. end;
  1509. function tscannerfile.asmgetchar : char;
  1510. begin
  1511. if lastasmgetchar<>#0 then
  1512. begin
  1513. c:=lastasmgetchar;
  1514. lastasmgetchar:=#0;
  1515. end
  1516. else
  1517. readchar;
  1518. case c of
  1519. '{' : begin
  1520. skipcomment;
  1521. asmgetchar:=c;
  1522. exit;
  1523. end;
  1524. '/' : begin
  1525. readchar;
  1526. if c='/' then
  1527. begin
  1528. skipdelphicomment;
  1529. asmgetchar:=c;
  1530. end
  1531. else
  1532. begin
  1533. asmgetchar:='/';
  1534. lastasmgetchar:=c;
  1535. end;
  1536. exit;
  1537. end;
  1538. '(' : begin
  1539. readchar;
  1540. if c='*' then
  1541. begin
  1542. skipoldtpcomment;
  1543. asmgetchar:=c;
  1544. end
  1545. else
  1546. begin
  1547. asmgetchar:='(';
  1548. lastasmgetchar:=c;
  1549. end;
  1550. exit;
  1551. end;
  1552. else
  1553. begin
  1554. asmgetchar:=c;
  1555. end;
  1556. end;
  1557. end;
  1558. begin
  1559. create_tokenidx;
  1560. end.
  1561. {
  1562. $Log$
  1563. Revision 1.92 1999-08-06 13:11:44 michael
  1564. * Removed C style comments.
  1565. Revision 1.91 1999/08/05 16:53:11 peter
  1566. * V_Fatal=1, all other V_ are also increased
  1567. * Check for local procedure when assigning procvar
  1568. * fixed comment parsing because directives
  1569. * oldtp mode directives better supported
  1570. * added some messages to errore.msg
  1571. Revision 1.90 1999/08/04 13:03:05 jonas
  1572. * all tokens now start with an underscore
  1573. * PowerPC compiles!!
  1574. Revision 1.89 1999/07/29 11:43:22 peter
  1575. * always output preprocstack when unexpected eof is found
  1576. * fixed tp7/delphi skipuntildirective parsing
  1577. Revision 1.88 1999/07/24 11:20:59 peter
  1578. * directives are allowed in (* *)
  1579. * fixed parsing of (* between conditional code
  1580. Revision 1.87 1999/07/18 10:20:02 florian
  1581. * made it compilable with Dlephi 4 again
  1582. + fixed problem with large stack allocations on win32
  1583. Revision 1.86 1999/06/02 22:44:19 pierre
  1584. * previous wrong log corrected
  1585. Revision 1.85 1999/06/02 22:25:49 pierre
  1586. * changed $ifdef FPC @ into $ifndef TP
  1587. Revision 1.84 1999/05/31 23:28:42 pierre
  1588. * problem with main file end without newline
  1589. Revision 1.83 1999/05/20 14:57:29 peter
  1590. * fixed line counting with macro's
  1591. Revision 1.82 1999/05/04 21:45:04 florian
  1592. * changes to compile it with Delphi 4.0
  1593. Revision 1.81 1999/04/07 14:36:44 pierre
  1594. + better preproc stack checking and report
  1595. Revision 1.80 1999/04/06 11:20:59 peter
  1596. * more hashing for keyword table
  1597. Revision 1.79 1999/04/01 22:05:59 peter
  1598. * '1.' is now parsed as a real
  1599. Revision 1.78 1999/03/26 19:10:06 peter
  1600. * support also ^^
  1601. Revision 1.77 1999/03/26 00:05:45 peter
  1602. * released valintern
  1603. + deffile is now removed when compiling is finished
  1604. * ^( compiles now correct
  1605. + static directive
  1606. * shrd fixed
  1607. Revision 1.76 1999/03/24 23:17:24 peter
  1608. * fixed bugs 212,222,225,227,229,231,233
  1609. Revision 1.75 1999/03/16 21:00:27 peter
  1610. * fixed old tp comment behaviour within directives
  1611. Revision 1.74 1999/03/11 10:46:29 daniel
  1612. * Reverted C styled comments
  1613. Revision 1.73 1999/03/02 22:49:35 peter
  1614. * fixed nested comments for old style tp and c
  1615. Revision 1.72 1999/02/02 00:15:10 florian
  1616. + c styled comments
  1617. Revision 1.71 1999/01/27 13:05:45 pierre
  1618. * give include file name on error
  1619. Revision 1.70 1999/01/19 12:14:38 peter
  1620. * fixed eof bug with includefiles
  1621. Revision 1.69 1998/12/11 00:03:46 peter
  1622. + globtype,tokens,version unit splitted from globals
  1623. Revision 1.68 1998/11/16 15:41:44 peter
  1624. * tp7 didn't like my ifopt H+ :(
  1625. Revision 1.67 1998/11/16 12:18:06 peter
  1626. * H+ fixes
  1627. Revision 1.66 1998/11/05 23:48:29 peter
  1628. * recordtype.field support in constant expressions
  1629. * fixed imul for oa_imm8 which was not allowed
  1630. * fixed reading of local typed constants
  1631. * fixed comment reading which is not any longer a separator
  1632. Revision 1.65 1998/11/03 11:35:02 peter
  1633. * don't check for endif if error
  1634. Revision 1.64 1998/10/21 20:16:05 peter
  1635. * beter line info for conditionals
  1636. Revision 1.63 1998/10/16 14:20:57 daniel
  1637. * Faster keyword scanning.
  1638. * Import library and smartlink library in one file.
  1639. Revision 1.62 1998/10/15 12:22:23 pierre
  1640. * close include files immediately after end reading
  1641. instead of waiting until unit compilation ended !
  1642. Revision 1.61 1998/10/09 11:08:15 peter
  1643. * fixed inputfile^.name^ bug
  1644. Revision 1.60 1998/10/09 08:56:31 pierre
  1645. * several memory leaks fixed
  1646. Revision 1.59 1998/10/08 23:29:05 peter
  1647. * -vu shows unit info, -vt shows tried/used files
  1648. Revision 1.58 1998/10/08 17:17:30 pierre
  1649. * current_module old scanner tagged as invalid if unit is recompiled
  1650. + added ppheap for better info on tracegetmem of heaptrc
  1651. (adds line column and file index)
  1652. * several memory leaks removed ith help of heaptrc !!
  1653. Revision 1.57 1998/10/08 13:45:25 peter
  1654. * EOF position is now correctly saved in aktfilepos
  1655. Revision 1.56 1998/09/30 16:43:38 peter
  1656. * fixed unit interdependency with circular uses
  1657. Revision 1.55 1998/09/28 16:57:26 pierre
  1658. * changed all length(p^.value_str^) into str_length(p)
  1659. to get it work with and without ansistrings
  1660. * changed sourcefiles field of tmodule to a pointer
  1661. Revision 1.54 1998/09/26 17:45:41 peter
  1662. + idtoken and only one token table
  1663. Revision 1.53 1998/09/24 23:49:20 peter
  1664. + aktmodeswitches
  1665. Revision 1.52 1998/09/18 16:03:45 florian
  1666. * some changes to compile with Delphi
  1667. Revision 1.51 1998/09/16 16:41:49 peter
  1668. * merged fixes
  1669. Revision 1.50.2.1 1998/09/16 16:09:49 peter
  1670. * on/off support also for the local/module switches
  1671. Revision 1.50 1998/09/04 08:36:06 peter
  1672. + (. and .) which are equal to [ and ]
  1673. Revision 1.49 1998/09/03 11:24:03 peter
  1674. * moved more inputfile things from tscannerfile to tinputfile
  1675. * changed ifdef Sourceline to cs_asm_source
  1676. Revision 1.48 1998/09/01 12:51:02 peter
  1677. * close also resets lastlinepos
  1678. Revision 1.47 1998/09/01 09:01:52 peter
  1679. * initialize all object variables in .init
  1680. Revision 1.46 1998/08/29 13:49:00 peter
  1681. * fixed freemem calls which had the wrong size sometimes
  1682. Revision 1.45 1998/08/26 15:35:35 peter
  1683. * fixed scannerfiles for macros
  1684. + $I %<environment>%
  1685. Revision 1.44 1998/08/20 16:09:55 pierre
  1686. * tokenpos has to be restored also after
  1687. printstatus
  1688. Revision 1.43 1998/08/20 09:26:45 pierre
  1689. + funcret setting in underproc testing
  1690. compile with _dTEST_FUNCRET
  1691. Revision 1.42 1998/08/19 14:57:51 peter
  1692. * small fix for aktfilepos
  1693. Revision 1.41 1998/08/18 14:17:10 pierre
  1694. * bug about assigning the return value of a function to
  1695. a procvar fixed : warning
  1696. assigning a proc to a procvar need @ in FPC mode !!
  1697. * missing file/line info restored
  1698. Revision 1.40 1998/08/11 14:04:33 peter
  1699. * auto close an open file and better error msg
  1700. Revision 1.39 1998/08/10 14:50:26 peter
  1701. + localswitches, moduleswitches, globalswitches splitting
  1702. Revision 1.38 1998/08/10 10:18:34 peter
  1703. + Compiler,Comphook unit which are the new interface units to the
  1704. compiler
  1705. Revision 1.37 1998/07/23 12:40:41 michael
  1706. No nested comments in Delphi mode.
  1707. Revision 1.36 1998/07/20 22:17:17 florian
  1708. * hex constants in numeric char (#$54#$43 ...) are now allowed
  1709. * there was a bug in record_var_dec which prevents the used
  1710. of nested variant records (for example drivers.tevent of tv)
  1711. Revision 1.35 1998/07/14 21:38:13 peter
  1712. + support for with p^do constructs
  1713. Revision 1.34 1998/07/14 14:47:04 peter
  1714. * released NEWINPUT
  1715. Revision 1.33 1998/07/10 10:48:40 peter
  1716. * fixed realnumber scanning
  1717. * [] after asmblock was not uppercased anymore
  1718. Revision 1.31 1998/07/07 17:39:38 peter
  1719. * fixed $I with following eof
  1720. Revision 1.30 1998/07/07 12:32:55 peter
  1721. * status.currentsource is now calculated in verbose (more accurated)
  1722. Revision 1.29 1998/07/07 11:20:11 peter
  1723. + NEWINPUT for a better inputfile and scanner object
  1724. Revision 1.28 1998/07/01 15:26:57 peter
  1725. * better bufferfile.reset error handling
  1726. Revision 1.27 1998/06/25 08:48:19 florian
  1727. * first version of rtti support
  1728. Revision 1.26 1998/06/16 08:56:30 peter
  1729. + targetcpu
  1730. * cleaner pmodules for newppu
  1731. Revision 1.25 1998/06/13 00:10:15 peter
  1732. * working browser and newppu
  1733. * some small fixes against crashes which occured in bp7 (but not in
  1734. fpc?!)
  1735. Revision 1.24 1998/06/12 10:32:36 pierre
  1736. * column problem hopefully solved
  1737. + C vars declaration changed
  1738. Revision 1.23 1998/06/03 22:49:02 peter
  1739. + wordbool,longbool
  1740. * rename bis,von -> high,low
  1741. * moved some systemunit loading/creating to psystem.pas
  1742. Revision 1.21 1998/05/27 00:20:32 peter
  1743. * some scanner optimizes
  1744. * automaticly aout2exe for go32v1
  1745. * fixed dynamiclinker option which was added at the wrong place
  1746. Revision 1.20 1998/05/23 01:21:30 peter
  1747. + aktasmmode, aktoptprocessor, aktoutputformat
  1748. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  1749. + $LIBNAME to set the library name where the unit will be put in
  1750. * splitted cgi386 a bit (codeseg to large for bp7)
  1751. * nasm, tasm works again. nasm moved to ag386nsm.pas
  1752. Revision 1.19 1998/05/20 09:42:37 pierre
  1753. + UseTokenInfo now default
  1754. * unit in interface uses and implementation uses gives error now
  1755. * only one error for unknown symbol (uses lastsymknown boolean)
  1756. the problem came from the label code !
  1757. + first inlined procedures and function work
  1758. (warning there might be allowed cases were the result is still wrong !!)
  1759. * UseBrower updated gives a global list of all position of all used symbols
  1760. with switch -gb
  1761. Revision 1.18 1998/05/12 10:47:00 peter
  1762. * moved printstatus to verb_def
  1763. + V_Normal which is between V_Error and V_Warning and doesn't have a
  1764. prefix like error: warning: and is included in V_Default
  1765. * fixed some messages
  1766. * first time parameter scan is only for -v and -T
  1767. - removed old style messages
  1768. Revision 1.17 1998/05/06 08:38:47 pierre
  1769. * better position info with UseTokenInfo
  1770. UseTokenInfo greatly simplified
  1771. + added check for changed tree after first time firstpass
  1772. (if we could remove all the cases were it happen
  1773. we could skip all firstpass if firstpasscount > 1)
  1774. Only with ExtDebug
  1775. Revision 1.16 1998/05/04 17:54:28 peter
  1776. + smartlinking works (only case jumptable left todo)
  1777. * redesign of systems.pas to support assemblers and linkers
  1778. + Unitname is now also in the PPU-file, increased version to 14
  1779. Revision 1.15 1998/05/01 16:38:46 florian
  1780. * handling of private and protected fixed
  1781. + change_keywords_to_tp implemented to remove
  1782. keywords which aren't supported by tp
  1783. * break and continue are now symbols of the system unit
  1784. + widestring, longstring and ansistring type released
  1785. Revision 1.14 1998/04/30 15:59:42 pierre
  1786. * GDB works again better :
  1787. correct type info in one pass
  1788. + UseTokenInfo for better source position
  1789. * fixed one remaining bug in scanner for line counts
  1790. * several little fixes
  1791. Revision 1.13 1998/04/29 13:42:27 peter
  1792. + $IOCHECKS and $ALIGN to test already, other will follow soon
  1793. * fixed the wrong linecounting with comments
  1794. Revision 1.12 1998/04/29 10:34:04 pierre
  1795. + added some code for ansistring (not complete nor working yet)
  1796. * corrected operator overloading
  1797. * corrected nasm output
  1798. + started inline procedures
  1799. + added starstarn : use ** for exponentiation (^ gave problems)
  1800. + started UseTokenInfo cond to get accurate positions
  1801. Revision 1.11 1998/04/27 23:10:29 peter
  1802. + new scanner
  1803. * $makelib -> if smartlink
  1804. * small filename fixes pmodule.setfilename
  1805. * moved import from files.pas -> import.pas
  1806. }