scanner.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  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. cobjects,globals,verbose,comphook,files;
  25. const
  26. {$ifdef TP}
  27. maxmacrolen=1024;
  28. linebufincrease=64;
  29. {$else}
  30. maxmacrolen=16*1024;
  31. linebufincrease=512;
  32. {$endif}
  33. id_len = 14;
  34. Newline = #10;
  35. type
  36. ident = string[id_len];
  37. const
  38. max_keywords = 70;
  39. anz_keywords : longint = max_keywords;
  40. { the following keywords are no keywords in TP, they
  41. are internal procedures
  42. CONTINUE, DISPOSE, EXIT, FAIL, FALSE, NEW, SELF
  43. TRUE
  44. }
  45. { INLINE is a keyword in TP, but only an modifier in FPC }
  46. keyword : array[1..max_keywords] of ident = (
  47. { 'ABSOLUTE',}
  48. 'AND',
  49. 'ARRAY','AS','ASM',
  50. { 'ASSEMBLER',}
  51. 'BEGIN',
  52. 'CASE','CLASS',
  53. 'CONST','CONSTRUCTOR',
  54. 'DESTRUCTOR','DISPOSE','DIV','DO','DOWNTO','ELSE','END',
  55. 'EXCEPT',
  56. 'EXIT',
  57. { 'EXPORT',}
  58. 'EXPORTS',
  59. { 'EXTERNAL',}
  60. 'FAIL','FALSE',
  61. { 'FAR',}
  62. 'FILE','FINALIZATION','FINALLY','FOR',
  63. { 'FORWARD',}
  64. 'FUNCTION','GOTO','IF','IMPLEMENTATION','IN',
  65. 'INHERITED','INITIALIZATION',
  66. { 'INLINE',} {INLINE is a reserved word in TP. Why?}
  67. 'INTERFACE',
  68. { 'INTERRUPT',}
  69. 'IS',
  70. 'LABEL','LIBRARY','MOD',
  71. { 'NEAR',}
  72. 'NEW','NIL','NOT','OBJECT',
  73. 'OF','ON','OPERATOR','OR','OTHERWISE','PACKED',
  74. 'PROCEDURE','PROGRAM','PROPERTY',
  75. 'RAISE','RECORD','REPEAT','SELF',
  76. 'SET','SHL','SHR','STRING','THEN','TO',
  77. 'TRUE','TRY','TYPE','UNIT','UNTIL',
  78. 'USES','VAR',
  79. { 'VIRTUAL',}
  80. 'WHILE','WITH','XOR');
  81. keyword_token : array[1..max_keywords] of ttoken = (
  82. { _ABSOLUTE,}
  83. _AND,
  84. _ARRAY,_AS,_ASM,
  85. { _ASSEMBLER,}
  86. _BEGIN,
  87. _CASE,_CLASS,
  88. _CONST,_CONSTRUCTOR,
  89. _DESTRUCTOR,_DISPOSE,_DIV,_DO,_DOWNTO,
  90. _ELSE,_END,_EXCEPT,
  91. _EXIT,
  92. { _EXPORT,}
  93. _EXPORTS,
  94. { _EXTERNAL,}
  95. _FAIL,_FALSE,
  96. { _FAR,}
  97. _FILE,_FINALIZATION,_FINALLY,_FOR,
  98. { _FORWARD,}
  99. _FUNCTION,_GOTO,_IF,_IMPLEMENTATION,_IN,
  100. _INHERITED,_INITIALIZATION,
  101. { _INLINE,}
  102. _INTERFACE,
  103. { _INTERRUPT,}
  104. _IS,
  105. _LABEL,_LIBRARY,_MOD,
  106. { _NEAR,}
  107. _NEW,_NIL,_NOT,_OBJECT,
  108. _OF,_ON,_OPERATOR,_OR,_OTHERWISE,_PACKED,
  109. _PROCEDURE,_PROGRAM,_PROPERTY,
  110. _RAISE,_RECORD,_REPEAT,_SELF,
  111. _SET,_SHL,_SHR,_STRING,_THEN,_TO,
  112. _TRUE,_TRY,_TYPE,_UNIT,_UNTIL,
  113. _USES,_VAR,
  114. { _VIRTUAL,}
  115. _WHILE,_WITH,_XOR);
  116. type
  117. pmacrobuffer = ^tmacrobuffer;
  118. tmacrobuffer = array[0..maxmacrolen-1] of char;
  119. ppreprocstack = ^tpreprocstack;
  120. tpreprocstack = object
  121. accept : boolean;
  122. next : ppreprocstack;
  123. name : stringid;
  124. line_nb : longint;
  125. constructor init(a:boolean;n:ppreprocstack);
  126. destructor done;
  127. end;
  128. pscannerfile = ^tscannerfile;
  129. tscannerfile = object
  130. inputfile : pinputfile; { current inputfile list }
  131. { these fields are called save* in inputfile, and are here
  132. for speed reasons (PFV) }
  133. bufstart,
  134. bufsize,
  135. line_no,
  136. lastlinepos : longint;
  137. inputbuffer,
  138. inputpointer : pchar;
  139. lasttokenpos : longint;
  140. lasttoken : ttoken;
  141. do_special, { 1=point after nr, 2=caret after id }
  142. comment_level,
  143. yylexcount : longint;
  144. lastasmgetchar : char;
  145. preprocstack : ppreprocstack;
  146. constructor init(const fn:string);
  147. destructor done;
  148. { File buffer things }
  149. function open:boolean;
  150. procedure close;
  151. procedure tempclose;
  152. function tempopen:boolean;
  153. procedure seekbuf(fpos:longint);
  154. procedure readbuf;
  155. procedure saveinputfile;
  156. procedure restoreinputfile;
  157. procedure nextfile;
  158. procedure addfile(hp:pinputfile);
  159. procedure reload;
  160. procedure setbuf(p:pchar;l:longint);
  161. procedure insertmacro(p:pchar;len:longint);
  162. { Scanner things }
  163. procedure gettokenpos;
  164. procedure inc_comment_level;
  165. procedure dec_comment_level;
  166. procedure checkpreprocstack;
  167. procedure poppreprocstack;
  168. procedure addpreprocstack(a:boolean;const s:string;w:tmsgconst);
  169. procedure elsepreprocstack;
  170. procedure linebreak;
  171. procedure readchar;
  172. procedure readstring;
  173. procedure readnumber;
  174. function readid:string;
  175. function readval:longint;
  176. function readcomment:string;
  177. procedure skipspace;
  178. procedure skipuntildirective;
  179. procedure skipcomment;
  180. procedure skipdelphicomment;
  181. procedure skipoldtpcomment;
  182. function yylex:ttoken;
  183. function readpreproc:ttoken;
  184. function asmgetchar:char;
  185. end;
  186. var
  187. c : char;
  188. orgpattern,
  189. pattern : string;
  190. current_scanner : pscannerfile;
  191. { changes to keywords to be tp compatible }
  192. procedure change_to_tp_keywords;
  193. implementation
  194. uses
  195. dos,systems,symtable,switches;
  196. {*****************************************************************************
  197. Helper routines
  198. *****************************************************************************}
  199. function is_keyword(var token : ttoken) : boolean;
  200. var
  201. high,low,mid : longint;
  202. begin
  203. low:=1;
  204. high:=anz_keywords;
  205. while low<high do
  206. begin
  207. mid:=(high+low+1) shr 1;
  208. if pattern<keyword[mid] then
  209. high:=mid-1
  210. else
  211. low:=mid;
  212. end;
  213. if pattern=keyword[high] then
  214. begin
  215. token:=keyword_token[high];
  216. is_keyword:=true;
  217. end
  218. else
  219. is_keyword:=false;
  220. end;
  221. procedure remove_keyword(const s : string);
  222. var
  223. i,j : longint;
  224. begin
  225. for i:=1 to anz_keywords do
  226. begin
  227. if keyword[i]=s then
  228. begin
  229. for j:=i to anz_keywords-1 do
  230. begin
  231. keyword[j]:=keyword[j+1];
  232. keyword_token[j]:=keyword_token[j+1];
  233. end;
  234. dec(anz_keywords);
  235. break;
  236. end;
  237. end;
  238. end;
  239. procedure change_to_tp_keywords;
  240. const
  241. non_tp : array[0..14] of string[id_len] = (
  242. 'AS','CLASS','EXCEPT','FINALLY','INITIALIZATION','IS',
  243. 'ON','OPERATOR','OTHERWISE','PROPERTY','RAISE','TRY',
  244. 'EXPORTS','LIBRARY','FINALIZATION');
  245. var
  246. i : longint;
  247. begin
  248. for i:=0 to 13 do
  249. remove_keyword(non_tp[i]);
  250. end;
  251. {*****************************************************************************
  252. TPreProcStack
  253. *****************************************************************************}
  254. constructor tpreprocstack.init(a:boolean;n:ppreprocstack);
  255. begin
  256. accept:=a;
  257. next:=n;
  258. end;
  259. destructor tpreprocstack.done;
  260. begin
  261. end;
  262. {****************************************************************************
  263. TSCANNERFILE
  264. ****************************************************************************}
  265. constructor tscannerfile.init(const fn:string);
  266. begin
  267. inputfile:=new(pinputfile,init(fn));
  268. current_module^.sourcefiles.register_file(inputfile);
  269. current_module^.current_index:=inputfile^.ref_index;
  270. { load inputfile values }
  271. restoreinputfile;
  272. { reset scanner }
  273. preprocstack:=nil;
  274. comment_level:=0;
  275. do_special:=0;
  276. yylexcount:=0;
  277. block_type:=bt_general;
  278. lasttokenpos:=0;
  279. lasttoken:=_END;
  280. lastasmgetchar:=#0;
  281. { load block }
  282. if not open then
  283. Message1(scan_f_cannot_open_input,fn);
  284. reload;
  285. end;
  286. destructor tscannerfile.done;
  287. begin
  288. checkpreprocstack;
  289. { close file }
  290. if not inputfile^.closed then
  291. close;
  292. end;
  293. procedure tscannerfile.seekbuf(fpos:longint);
  294. begin
  295. with inputfile^ do
  296. begin
  297. if closed then
  298. exit;
  299. seek(f,fpos);
  300. bufstart:=fpos;
  301. bufsize:=0;
  302. end;
  303. end;
  304. procedure tscannerfile.readbuf;
  305. {$ifdef TP}
  306. var
  307. w : word;
  308. {$endif}
  309. begin
  310. with inputfile^ do
  311. begin
  312. if is_macro then
  313. endoffile:=true;
  314. if closed then
  315. exit;
  316. inc(bufstart,bufsize);
  317. {$ifdef TP}
  318. blockread(f,inputbuffer^,inputbufsize-1,w);
  319. bufsize:=w;
  320. {$else}
  321. blockread(f,inputbuffer^,inputbufsize-1,bufsize);
  322. {$endif}
  323. inputbuffer[bufsize]:=#0;
  324. endoffile:=not(bufsize=inputbufsize-1);
  325. end;
  326. end;
  327. function tscannerfile.open:boolean;
  328. var
  329. ofm : byte;
  330. begin
  331. with inputfile^ do
  332. begin
  333. open:=false;
  334. if not closed then
  335. Close;
  336. ofm:=filemode;
  337. filemode:=0;
  338. Assign(f,path^+name^);
  339. {$I-}
  340. reset(f,1);
  341. {$I+}
  342. filemode:=ofm;
  343. if ioresult<>0 then
  344. exit;
  345. { file }
  346. endoffile:=false;
  347. closed:=false;
  348. Getmem(inputbuffer,inputbufsize);
  349. inputpointer:=inputbuffer;
  350. bufstart:=0;
  351. bufsize:=0;
  352. { line }
  353. line_no:=0;
  354. lastlinepos:=0;
  355. lasttokenpos:=0;
  356. open:=true;
  357. end;
  358. end;
  359. procedure tscannerfile.close;
  360. var
  361. i : word;
  362. begin
  363. with inputfile^ do
  364. begin
  365. if is_macro then
  366. begin
  367. Freemem(inputbuffer,inputbufsize);
  368. is_macro:=false;
  369. closed:=true;
  370. exit;
  371. end;
  372. if not closed then
  373. begin
  374. {$I-}
  375. system.close(f);
  376. {$I+}
  377. i:=ioresult;
  378. Freemem(inputbuffer,inputbufsize);
  379. closed:=true;
  380. end;
  381. inputbuffer:=nil;
  382. inputpointer:=nil;
  383. lastlinepos:=0;
  384. lasttokenpos:=0;
  385. bufstart:=0;
  386. end;
  387. end;
  388. procedure tscannerfile.tempclose;
  389. var
  390. i : word;
  391. begin
  392. with inputfile^ do
  393. begin
  394. inc(bufstart,inputpointer-inputbuffer);
  395. if is_macro then
  396. exit;
  397. if not closed then
  398. begin
  399. {$I-}
  400. system.close(f);
  401. {$I+}
  402. i:=ioresult;
  403. Freemem(inputbuffer,inputbufsize);
  404. inputbuffer:=nil;
  405. inputpointer:=nil;
  406. closed:=true;
  407. end;
  408. end;
  409. end;
  410. function tscannerfile.tempopen:boolean;
  411. var
  412. ofm : byte;
  413. begin
  414. with inputfile^ do
  415. begin
  416. tempopen:=false;
  417. if is_macro then
  418. begin
  419. tempopen:=true;
  420. exit;
  421. end;
  422. if not closed then
  423. exit;
  424. ofm:=filemode;
  425. filemode:=0;
  426. Assign(f,path^+name^);
  427. {$I-}
  428. reset(f,1);
  429. {$I+}
  430. filemode:=ofm;
  431. if ioresult<>0 then
  432. exit;
  433. closed:=false;
  434. { get new mem }
  435. Getmem(inputbuffer,inputbufsize);
  436. inputpointer:=inputbuffer;
  437. { restore state }
  438. seek(f,BufStart);
  439. bufsize:=0;
  440. readbuf;
  441. tempopen:=true;
  442. end;
  443. end;
  444. procedure tscannerfile.saveinputfile;
  445. begin
  446. inputfile^.savebufstart:=bufstart;
  447. inputfile^.savebufsize:=bufsize;
  448. inputfile^.saveinputbuffer:=inputbuffer;
  449. inputfile^.saveinputpointer:=inputpointer;
  450. inputfile^.savelastlinepos:=lastlinepos;
  451. inputfile^.saveline_no:=line_no;
  452. end;
  453. procedure tscannerfile.restoreinputfile;
  454. begin
  455. bufstart:=inputfile^.savebufstart;
  456. bufsize:=inputfile^.savebufsize;
  457. lastlinepos:=inputfile^.savelastlinepos;
  458. line_no:=inputfile^.saveline_no;
  459. inputbuffer:=inputfile^.saveinputbuffer;
  460. inputpointer:=inputfile^.saveinputpointer;
  461. end;
  462. procedure tscannerfile.nextfile;
  463. begin
  464. if assigned(inputfile^.next) then
  465. begin
  466. inputfile:=inputfile^.next;
  467. restoreinputfile;
  468. end;
  469. end;
  470. procedure tscannerfile.addfile(hp:pinputfile);
  471. begin
  472. saveinputfile;
  473. { add to list }
  474. hp^.next:=inputfile;
  475. inputfile:=hp;
  476. { load new inputfile }
  477. restoreinputfile;
  478. end;
  479. procedure tscannerfile.reload;
  480. begin
  481. with inputfile^ do
  482. begin
  483. repeat
  484. { still more to read?, then change the #0 to a space so its seen
  485. as a seperator }
  486. if (bufsize>0) and (inputpointer-inputbuffer<bufsize) then
  487. begin
  488. c:=' ';
  489. inc(longint(inputpointer));
  490. exit;
  491. end;
  492. { can we read more from this file ? }
  493. if not endoffile then
  494. begin
  495. readbuf;
  496. if line_no=0 then
  497. line_no:=1;
  498. inputpointer:=inputbuffer;
  499. end
  500. else
  501. begin
  502. close;
  503. { no next module, than EOF }
  504. if not assigned(inputfile^.next) then
  505. begin
  506. c:=#26;
  507. exit;
  508. end;
  509. { load next file and reopen it }
  510. nextfile;
  511. tempopen;
  512. { status }
  513. Message1(scan_d_back_in,inputfile^.name^);
  514. { load some current_module fields }
  515. current_module^.current_index:=inputfile^.ref_index;
  516. end;
  517. { load next char }
  518. c:=inputpointer^;
  519. inc(longint(inputpointer));
  520. until c<>#0; { if also end, then reload again }
  521. end;
  522. end;
  523. procedure tscannerfile.setbuf(p:pchar;l:longint);
  524. begin
  525. with inputfile^ do
  526. begin
  527. inputbufsize:=l;
  528. inputbuffer:=p;
  529. inputpointer:=p;
  530. end;
  531. end;
  532. procedure tscannerfile.insertmacro(p:pchar;len:longint);
  533. { load the values of tokenpos and lasttokenpos }
  534. var
  535. macbuf : pchar;
  536. hp : pinputfile;
  537. begin
  538. { save old postion }
  539. dec(longint(inputpointer));
  540. current_scanner^.tempclose;
  541. { create macro 'file' }
  542. hp:=new(pinputfile,init('Macro'));
  543. addfile(hp);
  544. getmem(macbuf,len+1);
  545. setbuf(macbuf,len+1);
  546. { fill buffer }
  547. with inputfile^ do
  548. begin
  549. move(p^,inputbuffer^,len);
  550. inputbuffer[len]:=#0;
  551. { reset }
  552. inputpointer:=inputbuffer;
  553. bufstart:=0;
  554. bufsize:=len;
  555. line_no:=0;
  556. lastlinepos:=0;
  557. lasttokenpos:=0;
  558. is_macro:=true;
  559. endoffile:=true;
  560. closed:=true;
  561. { load new c }
  562. c:=inputpointer^;
  563. inc(longint(inputpointer));
  564. end;
  565. end;
  566. procedure tscannerfile.gettokenpos;
  567. { load the values of tokenpos and lasttokenpos }
  568. begin
  569. lasttokenpos:=bufstart+(inputpointer-inputbuffer);
  570. tokenpos.line:=line_no;
  571. tokenpos.column:=lasttokenpos-lastlinepos;
  572. tokenpos.fileindex:=current_module^.current_index;
  573. aktfilepos:=tokenpos;
  574. end;
  575. procedure tscannerfile.inc_comment_level;
  576. var
  577. oldaktfilepos : tfileposinfo;
  578. begin
  579. inc(comment_level);
  580. if (comment_level>1) then
  581. begin
  582. oldaktfilepos:=aktfilepos;
  583. gettokenpos; { update for warning }
  584. Message1(scan_w_comment_level,tostr(comment_level));
  585. aktfilepos:=oldaktfilepos;
  586. end;
  587. end;
  588. procedure tscannerfile.dec_comment_level;
  589. begin
  590. if (cs_tp_compatible in aktmoduleswitches) or
  591. (cs_delphi2_compatible in aktmoduleswitches) then
  592. comment_level:=0
  593. else
  594. dec(comment_level);
  595. end;
  596. procedure tscannerfile.linebreak;
  597. var
  598. cur : char;
  599. {$ifdef SourceLine}
  600. hp : plongint;
  601. {$endif SourceLine}
  602. oldtokenpos,oldaktfilepos : tfileposinfo;
  603. begin
  604. with inputfile^ do
  605. begin
  606. if (byte(inputpointer^)=0) and not(endoffile) then
  607. begin
  608. cur:=c;
  609. reload;
  610. if byte(cur)+byte(c)<>23 then
  611. dec(longint(inputpointer));
  612. end
  613. else
  614. begin
  615. { Fix linebreak to be only newline (=#10) for all types of linebreaks }
  616. if (byte(inputpointer^)+byte(c)=23) then
  617. inc(longint(inputpointer));
  618. end;
  619. c:=newline;
  620. { increase line counters }
  621. lastlinepos:=bufstart+(inputpointer-inputbuffer);
  622. inc(line_no);
  623. { update linebuffer }
  624. {$ifdef SourceLine}
  625. if line_no>maxlinebuf then
  626. begin
  627. { create new linebuf and move old info }
  628. getmem(hp,maxlinebuf+linebufincrease);
  629. if assigned(linebuf) then
  630. begin
  631. move(linebuf^,hp^,maxlinebuf shl 2);
  632. freemem(linebuf,maxlinebuf);
  633. end;
  634. { set new linebuf }
  635. linebuf:=hp;
  636. inc(maxlinebuf,linebufincrease);
  637. end;
  638. plongint(longint(linebuf)+line_no*2)^:=lastlinepos;
  639. {$endif SourceLine}
  640. { update for status and call the show status routine,
  641. but don't touch aktfilepos ! }
  642. oldaktfilepos:=aktfilepos;
  643. oldtokenpos:=tokenpos;
  644. gettokenpos; { update for v_status }
  645. inc(status.compiledlines);
  646. ShowStatus;
  647. aktfilepos:=oldaktfilepos;
  648. tokenpos:=oldtokenpos;
  649. end;
  650. end;
  651. procedure tscannerfile.checkpreprocstack;
  652. begin
  653. { check for missing ifdefs }
  654. while assigned(preprocstack) do
  655. begin
  656. Message3(scan_e_endif_expected,'$IF(N)(DEF)',preprocstack^.name,tostr(preprocstack^.line_nb));
  657. poppreprocstack;
  658. end;
  659. end;
  660. procedure tscannerfile.poppreprocstack;
  661. var
  662. hp : ppreprocstack;
  663. begin
  664. if assigned(preprocstack) then
  665. begin
  666. hp:=preprocstack^.next;
  667. dispose(preprocstack,done);
  668. preprocstack:=hp;
  669. end
  670. else
  671. Message(scan_e_endif_without_if);
  672. end;
  673. procedure tscannerfile.addpreprocstack(a:boolean;const s:string;w:tmsgconst);
  674. begin
  675. preprocstack:=new(ppreprocstack,init(((preprocstack=nil) or preprocstack^.accept) and a,preprocstack));
  676. preprocstack^.name:=s;
  677. preprocstack^.line_nb:=line_no;
  678. if preprocstack^.accept then
  679. Message2(w,preprocstack^.name,'accepted')
  680. else
  681. Message2(w,preprocstack^.name,'rejected');
  682. end;
  683. procedure tscannerfile.elsepreprocstack;
  684. begin
  685. if assigned(preprocstack) then
  686. begin
  687. if not(assigned(preprocstack^.next)) or (preprocstack^.next^.accept) then
  688. preprocstack^.accept:=not preprocstack^.accept;
  689. if preprocstack^.accept then
  690. Message2(scan_c_else_found,preprocstack^.name,'accepted')
  691. else
  692. Message2(scan_c_else_found,preprocstack^.name,'rejected');
  693. end
  694. else
  695. Message(scan_e_endif_without_if);
  696. end;
  697. procedure tscannerfile.readchar;
  698. begin
  699. c:=inputpointer^;
  700. if c=#0 then
  701. reload
  702. else
  703. inc(longint(inputpointer));
  704. if c in [#10,#13] then
  705. linebreak;
  706. end;
  707. procedure tscannerfile.readstring;
  708. var
  709. i : longint;
  710. begin
  711. i:=0;
  712. repeat
  713. case c of
  714. '_',
  715. '0'..'9',
  716. 'A'..'Z' : begin
  717. if i<255 then
  718. begin
  719. inc(i);
  720. orgpattern[i]:=c;
  721. pattern[i]:=c;
  722. end;
  723. c:=inputpointer^;
  724. inc(longint(inputpointer));
  725. end;
  726. 'a'..'z' : begin
  727. if i<255 then
  728. begin
  729. inc(i);
  730. orgpattern[i]:=c;
  731. pattern[i]:=chr(ord(c)-32)
  732. end;
  733. c:=inputpointer^;
  734. inc(longint(inputpointer));
  735. end;
  736. #0 : reload;
  737. #13,#10 : begin
  738. linebreak;
  739. break;
  740. end;
  741. else
  742. break;
  743. end;
  744. until false;
  745. orgpattern[0]:=chr(i);
  746. pattern[0]:=chr(i);
  747. end;
  748. procedure tscannerfile.readnumber;
  749. var
  750. base,
  751. i : longint;
  752. begin
  753. case c of
  754. '%' : begin
  755. readchar;
  756. base:=2;
  757. pattern[1]:='%';
  758. i:=1;
  759. end;
  760. '$' : begin
  761. readchar;
  762. base:=16;
  763. pattern[1]:='$';
  764. i:=1;
  765. end;
  766. else
  767. begin
  768. base:=10;
  769. i:=0;
  770. end;
  771. end;
  772. while ((base>=10) and (c in ['0'..'9'])) or
  773. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  774. ((base=2) and (c in ['0'..'1'])) do
  775. begin
  776. if i<255 then
  777. begin
  778. inc(i);
  779. pattern[i]:=c;
  780. end;
  781. { get next char }
  782. c:=inputpointer^;
  783. if c=#0 then
  784. reload
  785. else
  786. inc(longint(inputpointer));
  787. end;
  788. { was the next char a linebreak ? }
  789. if c in [#10,#13] then
  790. linebreak;
  791. pattern[0]:=chr(i);
  792. end;
  793. function tscannerfile.readid:string;
  794. begin
  795. readstring;
  796. readid:=pattern;
  797. end;
  798. function tscannerfile.readval:longint;
  799. var
  800. l : longint;
  801. w : word;
  802. begin
  803. readnumber;
  804. valint(pattern,l,w);
  805. readval:=l;
  806. end;
  807. function tscannerfile.readcomment:string;
  808. var
  809. i : longint;
  810. begin
  811. i:=0;
  812. repeat
  813. case c of
  814. '}' : begin
  815. readchar;
  816. dec_comment_level;
  817. break;
  818. end;
  819. #26 : Message(scan_f_end_of_file);
  820. else
  821. begin
  822. if (i<255) then
  823. begin
  824. inc(i);
  825. readcomment[i]:=c;
  826. end;
  827. end;
  828. end;
  829. c:=inputpointer^;
  830. if c=#0 then
  831. reload
  832. else
  833. inc(longint(inputpointer));
  834. if c in [#10,#13] then
  835. linebreak;
  836. until false;
  837. readcomment[0]:=chr(i);
  838. end;
  839. procedure tscannerfile.skipspace;
  840. begin
  841. while c in [' ',#9..#13] do
  842. begin
  843. c:=inputpointer^;
  844. if c=#0 then
  845. reload
  846. else
  847. inc(longint(inputpointer));
  848. if c in [#10,#13] then
  849. linebreak;
  850. end;
  851. end;
  852. procedure tscannerfile.skipuntildirective;
  853. var
  854. found : longint;
  855. begin
  856. found:=0;
  857. repeat
  858. case c of
  859. #26 : Message(scan_f_end_of_file);
  860. '{' : begin
  861. if comment_level=0 then
  862. found:=1;
  863. inc_comment_level;
  864. end;
  865. '}' : begin
  866. dec_comment_level;
  867. found:=0;
  868. end;
  869. '$' : begin
  870. if found=1 then
  871. found:=2;
  872. end;
  873. else
  874. found:=0;
  875. end;
  876. c:=inputpointer^;
  877. if c=#0 then
  878. reload
  879. else
  880. inc(longint(inputpointer));
  881. if c in [#10,#13] then
  882. linebreak;
  883. until (found=2);
  884. end;
  885. {$i scandir.inc}
  886. procedure tscannerfile.skipcomment;
  887. begin
  888. readchar;
  889. inc_comment_level;
  890. { handle compiler switches }
  891. if (c='$') then
  892. handledirectives;
  893. { handle_switches can dec comment_level, }
  894. while (comment_level>0) do
  895. begin
  896. case c of
  897. '{' : inc_comment_level;
  898. '}' : dec_comment_level;
  899. #26 : Message(scan_f_end_of_file);
  900. end;
  901. c:=inputpointer^;
  902. if c=#0 then
  903. reload
  904. else
  905. inc(longint(inputpointer));
  906. if c in [#10,#13] then
  907. linebreak;
  908. end;
  909. end;
  910. procedure tscannerfile.skipdelphicomment;
  911. begin
  912. inc_comment_level;
  913. readchar;
  914. { this is currently not supported }
  915. if c='$' then
  916. Message(scan_e_wrong_styled_switch);
  917. { skip comment }
  918. while c<>newline do
  919. begin
  920. if c=#26 then
  921. Message(scan_f_end_of_file);
  922. readchar;
  923. end;
  924. dec_comment_level;
  925. end;
  926. procedure tscannerfile.skipoldtpcomment;
  927. var
  928. found : longint;
  929. begin
  930. inc_comment_level;
  931. readchar;
  932. { this is currently not supported }
  933. if c='$' then
  934. Message(scan_e_wrong_styled_switch);
  935. { skip comment }
  936. while (comment_level>0) do
  937. begin
  938. found:=0;
  939. repeat
  940. case c of
  941. #26 : Message(scan_f_end_of_file);
  942. '*' : begin
  943. if found=3 then
  944. inc_comment_level
  945. else
  946. found:=1;
  947. end;
  948. ')' : begin
  949. if found=1 then
  950. begin
  951. dec_comment_level;
  952. if comment_level=0 then
  953. found:=2;
  954. end;
  955. end;
  956. '(' : found:=3;
  957. else
  958. found:=0;
  959. end;
  960. c:=inputpointer^;
  961. if c=#0 then
  962. reload
  963. else
  964. inc(longint(inputpointer));
  965. if c in [#10,#13] then
  966. linebreak;
  967. until (found=2);
  968. end;
  969. end;
  970. function tscannerfile.yylex : ttoken;
  971. var
  972. y : ttoken;
  973. code : word;
  974. l : longint;
  975. mac : pmacrosym;
  976. asciinr : string[3];
  977. label
  978. exit_label;
  979. begin
  980. { was the last character a point ? }
  981. { this code is needed because the scanner if there is a 1. found if }
  982. { this is a floating point number or range like 1..3 }
  983. if do_special>0 then
  984. begin
  985. gettokenpos;
  986. l:=do_special;
  987. do_special:=0;
  988. case l of
  989. 1 : begin
  990. if c='.' then
  991. begin
  992. readchar;
  993. yylex:=POINTPOINT;
  994. goto exit_label;
  995. end;
  996. yylex:=POINT;
  997. goto exit_label;
  998. end;
  999. 2 : begin
  1000. yylex:=CARET;
  1001. readchar;
  1002. goto exit_label;
  1003. end;
  1004. end;
  1005. end;
  1006. { Skip all spaces and comments }
  1007. repeat
  1008. case c of
  1009. '{' : skipcomment;
  1010. ' ',#9..#13 : skipspace;
  1011. else
  1012. break;
  1013. end;
  1014. until false;
  1015. { Save current token position }
  1016. gettokenpos;
  1017. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  1018. if c in ['_','A'..'Z','a'..'z'] then
  1019. begin
  1020. readstring;
  1021. if (length(pattern) in [2..id_len]) and is_keyword(y) then
  1022. yylex:=y
  1023. else
  1024. begin
  1025. { this takes some time ... }
  1026. if (cs_support_macro in aktmoduleswitches) then
  1027. begin
  1028. mac:=pmacrosym(macros^.search(pattern));
  1029. if assigned(mac) and (assigned(mac^.buftext)) then
  1030. begin
  1031. insertmacro(mac^.buftext,mac^.buflen);
  1032. { handle empty macros }
  1033. if c=#0 then
  1034. reload;
  1035. { play it again ... }
  1036. inc(yylexcount);
  1037. if yylexcount>16 then
  1038. Message(scan_w_macro_deep_ten);
  1039. {$ifdef TP}
  1040. yylex:=yylex;
  1041. {$else}
  1042. yylex:=yylex();
  1043. {$endif}
  1044. { that's all folks }
  1045. dec(yylexcount);
  1046. exit;
  1047. end;
  1048. end;
  1049. yylex:=ID;
  1050. end;
  1051. if (c='^') then
  1052. do_special:=2;
  1053. goto exit_label;
  1054. end
  1055. else
  1056. begin
  1057. case c of
  1058. '$' : begin
  1059. readnumber;
  1060. yylex:=INTCONST;
  1061. goto exit_label;
  1062. end;
  1063. '%' : begin
  1064. readnumber;
  1065. yylex:=INTCONST;
  1066. goto exit_label;
  1067. end;
  1068. '0'..'9' : begin
  1069. readnumber;
  1070. if (c in ['.','e','E']) then
  1071. begin
  1072. { first check for a . }
  1073. if c='.' then
  1074. begin
  1075. readchar;
  1076. if not(c in ['0'..'9']) then
  1077. begin
  1078. do_special:=1;
  1079. yylex:=INTCONST;
  1080. goto exit_label;
  1081. end;
  1082. pattern:=pattern+'.';
  1083. while c in ['0'..'9'] do
  1084. begin
  1085. pattern:=pattern+c;
  1086. readchar;
  1087. end;
  1088. end;
  1089. { E can also follow after a point is scanned }
  1090. if c in ['e','E'] then
  1091. begin
  1092. pattern:=pattern+'E';
  1093. readchar;
  1094. if c in ['-','+'] then
  1095. begin
  1096. pattern:=pattern+c;
  1097. readchar;
  1098. end;
  1099. if not(c in ['0'..'9']) then
  1100. Message(scan_f_illegal_char);
  1101. while c in ['0'..'9'] do
  1102. begin
  1103. pattern:=pattern+c;
  1104. readchar;
  1105. end;
  1106. end;
  1107. yylex:=REALNUMBER;
  1108. goto exit_label;
  1109. end;
  1110. yylex:=INTCONST;
  1111. goto exit_label;
  1112. end;
  1113. ';' : begin
  1114. readchar;
  1115. yylex:=SEMICOLON;
  1116. goto exit_label;
  1117. end;
  1118. '[' : begin
  1119. readchar;
  1120. yylex:=LECKKLAMMER;
  1121. goto exit_label;
  1122. end;
  1123. ']' : begin
  1124. readchar;
  1125. yylex:=RECKKLAMMER;
  1126. goto exit_label;
  1127. end;
  1128. '(' : begin
  1129. readchar;
  1130. if c='*' then
  1131. begin
  1132. skipoldtpcomment;
  1133. {$ifndef TP}
  1134. yylex:=yylex();
  1135. {$else}
  1136. yylex:=yylex;
  1137. {$endif}
  1138. exit;
  1139. end;
  1140. yylex:=LKLAMMER;
  1141. goto exit_label;
  1142. end;
  1143. ')' : begin
  1144. readchar;
  1145. yylex:=RKLAMMER;
  1146. goto exit_label;
  1147. end;
  1148. '+' : begin
  1149. readchar;
  1150. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1151. begin
  1152. readchar;
  1153. yylex:=_PLUSASN;
  1154. goto exit_label;
  1155. end;
  1156. yylex:=PLUS;
  1157. goto exit_label;
  1158. end;
  1159. '-' : begin
  1160. readchar;
  1161. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1162. begin
  1163. readchar;
  1164. yylex:=_MINUSASN;
  1165. goto exit_label;
  1166. end;
  1167. yylex:=MINUS;
  1168. goto exit_label;
  1169. end;
  1170. ':' : begin
  1171. readchar;
  1172. if c='=' then
  1173. begin
  1174. readchar;
  1175. yylex:=ASSIGNMENT;
  1176. goto exit_label;
  1177. end;
  1178. yylex:=COLON;
  1179. goto exit_label;
  1180. end;
  1181. '*' : begin
  1182. readchar;
  1183. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  1184. begin
  1185. readchar;
  1186. yylex:=_STARASN;
  1187. end
  1188. else
  1189. if c='*' then
  1190. begin
  1191. readchar;
  1192. yylex:=STARSTAR;
  1193. end
  1194. else
  1195. yylex:=STAR;
  1196. goto exit_label;
  1197. end;
  1198. '/' : begin
  1199. readchar;
  1200. case c of
  1201. '=' : begin
  1202. if (cs_support_c_operators in aktmoduleswitches) then
  1203. begin
  1204. readchar;
  1205. yylex:=_SLASHASN;
  1206. goto exit_label;
  1207. end;
  1208. end;
  1209. '/' : begin
  1210. skipdelphicomment;
  1211. {$ifndef TP}
  1212. yylex:=yylex();
  1213. {$else TP}
  1214. yylex:=yylex;
  1215. {$endif TP}
  1216. exit;
  1217. end;
  1218. end;
  1219. yylex:=SLASH;
  1220. goto exit_label;
  1221. end;
  1222. '=' : begin
  1223. readchar;
  1224. yylex:=EQUAL;
  1225. goto exit_label;
  1226. end;
  1227. '.' : begin
  1228. readchar;
  1229. if c='.' then
  1230. begin
  1231. readchar;
  1232. yylex:=POINTPOINT;
  1233. goto exit_label;
  1234. end
  1235. else
  1236. yylex:=POINT;
  1237. goto exit_label;
  1238. end;
  1239. '@' : begin
  1240. readchar;
  1241. if c='@' then
  1242. begin
  1243. readchar;
  1244. yylex:=DOUBLEADDR;
  1245. end
  1246. else
  1247. yylex:=KLAMMERAFFE;
  1248. goto exit_label;
  1249. end;
  1250. ',' : begin
  1251. readchar;
  1252. yylex:=COMMA;
  1253. goto exit_label;
  1254. end;
  1255. '''','#','^' : begin
  1256. if c='^' then
  1257. begin
  1258. readchar;
  1259. c:=upcase(c);
  1260. if not(block_type=bt_type) and (c in ['A'..'Z']) then
  1261. begin
  1262. pattern:=chr(ord(c)-64);
  1263. readchar;
  1264. end
  1265. else
  1266. begin
  1267. yylex:=CARET;
  1268. goto exit_label;
  1269. end;
  1270. end
  1271. else
  1272. pattern:='';
  1273. repeat
  1274. case c of
  1275. '#' : begin
  1276. readchar; { read # }
  1277. if c='$' then
  1278. begin
  1279. readchar; { read leading $ }
  1280. asciinr:='$';
  1281. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<3) do
  1282. begin
  1283. asciinr:=asciinr+c;
  1284. readchar;
  1285. end;
  1286. end
  1287. else
  1288. begin
  1289. asciinr:='';
  1290. while (c in ['0'..'9']) and (length(asciinr)<3) do
  1291. begin
  1292. asciinr:=asciinr+c;
  1293. readchar;
  1294. end;
  1295. end;
  1296. valint(asciinr,l,code);
  1297. if (asciinr='') or (code<>0) or
  1298. (l<0) or (l>255) then
  1299. Message(scan_e_illegal_char_const);
  1300. pattern:=pattern+chr(l);
  1301. end;
  1302. '''' : begin
  1303. repeat
  1304. readchar;
  1305. case c of
  1306. #26 : Message(scan_f_end_of_file);
  1307. newline : Message(scan_f_string_exceeds_line);
  1308. '''' : begin
  1309. readchar;
  1310. if c<>'''' then
  1311. break;
  1312. end;
  1313. end;
  1314. pattern:=pattern+c;
  1315. until false;
  1316. end;
  1317. '^' : begin
  1318. readchar;
  1319. if c<#64 then
  1320. c:=chr(ord(c)+64)
  1321. else
  1322. c:=chr(ord(c)-64);
  1323. pattern:=pattern+c;
  1324. readchar;
  1325. end;
  1326. else
  1327. break;
  1328. end;
  1329. until false;
  1330. { strings with length 1 become const chars }
  1331. if length(pattern)=1 then
  1332. yylex:=CCHAR
  1333. else
  1334. yylex:=CSTRING;
  1335. goto exit_label;
  1336. end;
  1337. '>' : begin
  1338. readchar;
  1339. case c of
  1340. '=' : begin
  1341. readchar;
  1342. yylex:=GTE;
  1343. goto exit_label;
  1344. end;
  1345. '>' : begin
  1346. readchar;
  1347. yylex:=_SHR;
  1348. goto exit_label;
  1349. end;
  1350. '<' : begin { >< is for a symetric diff for sets }
  1351. readchar;
  1352. yylex:=SYMDIF;
  1353. goto exit_label;
  1354. end;
  1355. end;
  1356. yylex:=GT;
  1357. goto exit_label;
  1358. end;
  1359. '<' : begin
  1360. readchar;
  1361. case c of
  1362. '>' : begin
  1363. readchar;
  1364. yylex:=UNEQUAL;
  1365. goto exit_label;
  1366. end;
  1367. '=' : begin
  1368. readchar;
  1369. yylex:=LTE;
  1370. goto exit_label;
  1371. end;
  1372. '<' : begin
  1373. readchar;
  1374. yylex:=_SHL;
  1375. goto exit_label;
  1376. end;
  1377. end;
  1378. yylex:=LT;
  1379. goto exit_label;
  1380. end;
  1381. #26 : begin
  1382. yylex:=_EOF;
  1383. goto exit_label;
  1384. end;
  1385. else
  1386. begin
  1387. Message(scan_f_illegal_char);
  1388. end;
  1389. end;
  1390. end;
  1391. exit_label:
  1392. end;
  1393. function tscannerfile.readpreproc:ttoken;
  1394. begin
  1395. skipspace;
  1396. case c of
  1397. 'A'..'Z',
  1398. 'a'..'z',
  1399. '_','0'..'9' : begin
  1400. preprocpat:=readid;
  1401. readpreproc:=ID;
  1402. end;
  1403. '(' : begin
  1404. readchar;
  1405. readpreproc:=LKLAMMER;
  1406. end;
  1407. ')' : begin
  1408. readchar;
  1409. readpreproc:=RKLAMMER;
  1410. end;
  1411. '+' : begin
  1412. readchar;
  1413. readpreproc:=PLUS;
  1414. end;
  1415. '-' : begin
  1416. readchar;
  1417. readpreproc:=MINUS;
  1418. end;
  1419. '*' : begin
  1420. readchar;
  1421. readpreproc:=STAR;
  1422. end;
  1423. '/' : begin
  1424. readchar;
  1425. readpreproc:=SLASH;
  1426. end;
  1427. '=' : begin
  1428. readchar;
  1429. readpreproc:=EQUAL;
  1430. end;
  1431. '>' : begin
  1432. readchar;
  1433. if c='=' then
  1434. begin
  1435. readchar;
  1436. readpreproc:=GTE;
  1437. end
  1438. else
  1439. readpreproc:=GT;
  1440. end;
  1441. '<' : begin
  1442. readchar;
  1443. case c of
  1444. '>' : begin
  1445. readchar;
  1446. readpreproc:=UNEQUAL;
  1447. end;
  1448. '=' : begin
  1449. readchar;
  1450. readpreproc:=LTE;
  1451. end;
  1452. else readpreproc:=LT;
  1453. end;
  1454. end;
  1455. #26 : Message(scan_f_end_of_file);
  1456. else
  1457. begin
  1458. readpreproc:=_EOF;
  1459. end;
  1460. end;
  1461. end;
  1462. function tscannerfile.asmgetchar : char;
  1463. begin
  1464. if lastasmgetchar<>#0 then
  1465. begin
  1466. c:=lastasmgetchar;
  1467. lastasmgetchar:=#0;
  1468. end
  1469. else
  1470. readchar;
  1471. case c of
  1472. '{' : begin
  1473. skipcomment;
  1474. lastasmgetchar:=c;
  1475. asmgetchar:=';';
  1476. exit;
  1477. end;
  1478. '/' : begin
  1479. readchar;
  1480. if c='/' then
  1481. begin
  1482. skipdelphicomment;
  1483. asmgetchar:=';';
  1484. end
  1485. else
  1486. asmgetchar:='/';
  1487. lastasmgetchar:=c;
  1488. exit;
  1489. end;
  1490. '(' : begin
  1491. readchar;
  1492. if c='*' then
  1493. begin
  1494. skipoldtpcomment;
  1495. asmgetchar:=';';
  1496. end
  1497. else
  1498. asmgetchar:='(';
  1499. lastasmgetchar:=c;
  1500. exit;
  1501. end;
  1502. else
  1503. begin
  1504. asmgetchar:=c;
  1505. end;
  1506. end;
  1507. end;
  1508. end.
  1509. {
  1510. $Log$
  1511. Revision 1.48 1998-09-01 12:51:02 peter
  1512. * close also resets lastlinepos
  1513. Revision 1.47 1998/09/01 09:01:52 peter
  1514. * initialize all object variables in .init
  1515. Revision 1.46 1998/08/29 13:49:00 peter
  1516. * fixed freemem calls which had the wrong size sometimes
  1517. Revision 1.45 1998/08/26 15:35:35 peter
  1518. * fixed scannerfiles for macros
  1519. + $I %<environment>%
  1520. Revision 1.44 1998/08/20 16:09:55 pierre
  1521. * tokenpos has to be restored also after
  1522. printstatus
  1523. Revision 1.43 1998/08/20 09:26:45 pierre
  1524. + funcret setting in underproc testing
  1525. compile with _dTEST_FUNCRET
  1526. Revision 1.42 1998/08/19 14:57:51 peter
  1527. * small fix for aktfilepos
  1528. Revision 1.41 1998/08/18 14:17:10 pierre
  1529. * bug about assigning the return value of a function to
  1530. a procvar fixed : warning
  1531. assigning a proc to a procvar need @ in FPC mode !!
  1532. * missing file/line info restored
  1533. Revision 1.40 1998/08/11 14:04:33 peter
  1534. * auto close an open file and better error msg
  1535. Revision 1.39 1998/08/10 14:50:26 peter
  1536. + localswitches, moduleswitches, globalswitches splitting
  1537. Revision 1.38 1998/08/10 10:18:34 peter
  1538. + Compiler,Comphook unit which are the new interface units to the
  1539. compiler
  1540. Revision 1.37 1998/07/23 12:40:41 michael
  1541. No nested comments in Delphi mode.
  1542. Revision 1.36 1998/07/20 22:17:17 florian
  1543. * hex constants in numeric char (#$54#$43 ...) are now allowed
  1544. * there was a bug in record_var_dec which prevents the used
  1545. of nested variant records (for example drivers.tevent of tv)
  1546. Revision 1.35 1998/07/14 21:38:13 peter
  1547. + support for with p^do constructs
  1548. Revision 1.34 1998/07/14 14:47:04 peter
  1549. * released NEWINPUT
  1550. Revision 1.33 1998/07/10 10:48:40 peter
  1551. * fixed realnumber scanning
  1552. * [] after asmblock was not uppercased anymore
  1553. Revision 1.31 1998/07/07 17:39:38 peter
  1554. * fixed $I with following eof
  1555. Revision 1.30 1998/07/07 12:32:55 peter
  1556. * status.currentsource is now calculated in verbose (more accurated)
  1557. Revision 1.29 1998/07/07 11:20:11 peter
  1558. + NEWINPUT for a better inputfile and scanner object
  1559. Revision 1.28 1998/07/01 15:26:57 peter
  1560. * better bufferfile.reset error handling
  1561. Revision 1.27 1998/06/25 08:48:19 florian
  1562. * first version of rtti support
  1563. Revision 1.26 1998/06/16 08:56:30 peter
  1564. + targetcpu
  1565. * cleaner pmodules for newppu
  1566. Revision 1.25 1998/06/13 00:10:15 peter
  1567. * working browser and newppu
  1568. * some small fixes against crashes which occured in bp7 (but not in
  1569. fpc?!)
  1570. Revision 1.24 1998/06/12 10:32:36 pierre
  1571. * column problem hopefully solved
  1572. + C vars declaration changed
  1573. Revision 1.23 1998/06/03 22:49:02 peter
  1574. + wordbool,longbool
  1575. * rename bis,von -> high,low
  1576. * moved some systemunit loading/creating to psystem.pas
  1577. Revision 1.21 1998/05/27 00:20:32 peter
  1578. * some scanner optimizes
  1579. * automaticly aout2exe for go32v1
  1580. * fixed dynamiclinker option which was added at the wrong place
  1581. Revision 1.20 1998/05/23 01:21:30 peter
  1582. + aktasmmode, aktoptprocessor, aktoutputformat
  1583. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  1584. + $LIBNAME to set the library name where the unit will be put in
  1585. * splitted cgi386 a bit (codeseg to large for bp7)
  1586. * nasm, tasm works again. nasm moved to ag386nsm.pas
  1587. Revision 1.19 1998/05/20 09:42:37 pierre
  1588. + UseTokenInfo now default
  1589. * unit in interface uses and implementation uses gives error now
  1590. * only one error for unknown symbol (uses lastsymknown boolean)
  1591. the problem came from the label code !
  1592. + first inlined procedures and function work
  1593. (warning there might be allowed cases were the result is still wrong !!)
  1594. * UseBrower updated gives a global list of all position of all used symbols
  1595. with switch -gb
  1596. Revision 1.18 1998/05/12 10:47:00 peter
  1597. * moved printstatus to verb_def
  1598. + V_Normal which is between V_Error and V_Warning and doesn't have a
  1599. prefix like error: warning: and is included in V_Default
  1600. * fixed some messages
  1601. * first time parameter scan is only for -v and -T
  1602. - removed old style messages
  1603. Revision 1.17 1998/05/06 08:38:47 pierre
  1604. * better position info with UseTokenInfo
  1605. UseTokenInfo greatly simplified
  1606. + added check for changed tree after first time firstpass
  1607. (if we could remove all the cases were it happen
  1608. we could skip all firstpass if firstpasscount > 1)
  1609. Only with ExtDebug
  1610. Revision 1.16 1998/05/04 17:54:28 peter
  1611. + smartlinking works (only case jumptable left todo)
  1612. * redesign of systems.pas to support assemblers and linkers
  1613. + Unitname is now also in the PPU-file, increased version to 14
  1614. Revision 1.15 1998/05/01 16:38:46 florian
  1615. * handling of private and protected fixed
  1616. + change_keywords_to_tp implemented to remove
  1617. keywords which aren't supported by tp
  1618. * break and continue are now symbols of the system unit
  1619. + widestring, longstring and ansistring type released
  1620. Revision 1.14 1998/04/30 15:59:42 pierre
  1621. * GDB works again better :
  1622. correct type info in one pass
  1623. + UseTokenInfo for better source position
  1624. * fixed one remaining bug in scanner for line counts
  1625. * several little fixes
  1626. Revision 1.13 1998/04/29 13:42:27 peter
  1627. + $IOCHECKS and $ALIGN to test already, other will follow soon
  1628. * fixed the wrong linecounting with comments
  1629. Revision 1.12 1998/04/29 10:34:04 pierre
  1630. + added some code for ansistring (not complete nor working yet)
  1631. * corrected operator overloading
  1632. * corrected nasm output
  1633. + started inline procedures
  1634. + added starstarn : use ** for exponentiation (^ gave problems)
  1635. + started UseTokenInfo cond to get accurate positions
  1636. Revision 1.11 1998/04/27 23:10:29 peter
  1637. + new scanner
  1638. * $makelib -> if smartlink
  1639. * small filename fixes pmodule.setfilename
  1640. * moved import from files.pas -> import.pas
  1641. }