scanner.pas 58 KB

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