scanner.pas 56 KB

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