scanner.pas 58 KB

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