scanner.pas 58 KB

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