scanner.pas 56 KB

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