scanner.pas 58 KB

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