scanner.pas 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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. unit scanner;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. globtype,globals,version,tokens,
  24. verbose,comphook,
  25. finput,
  26. widestr,cpuinfo;
  27. const
  28. max_include_nesting=32;
  29. max_macro_nesting=16;
  30. maxmacrolen=16*1024;
  31. preprocbufsize=32*1024;
  32. type
  33. tcommentstyle = (comment_none,comment_tp,comment_oldtp,comment_delphi,comment_c);
  34. pmacrobuffer = ^tmacrobuffer;
  35. tmacrobuffer = array[0..maxmacrolen-1] of char;
  36. tscannerfile = class;
  37. tmacro = class(TNamedIndexItem)
  38. defined,
  39. defined_at_startup,
  40. is_used : boolean;
  41. buftext : pchar;
  42. buflen : longint;
  43. fileinfo : tfileposinfo;
  44. constructor Create(const n : string);
  45. destructor destroy;override;
  46. end;
  47. preproctyp = (pp_ifdef,pp_ifndef,pp_if,pp_ifopt,pp_else);
  48. tpreprocstack = class
  49. typ : preproctyp;
  50. accept : boolean;
  51. next : tpreprocstack;
  52. name : stringid;
  53. line_nb : longint;
  54. owner : tscannerfile;
  55. constructor Create(atyp:preproctyp;a:boolean;n:tpreprocstack);
  56. end;
  57. tdirectiveproc=procedure;
  58. tdirectiveitem = class(TNamedIndexItem)
  59. public
  60. is_conditional : boolean;
  61. proc : tdirectiveproc;
  62. constructor Create(const n:string;p:tdirectiveproc);
  63. constructor CreateCond(const n:string;p:tdirectiveproc);
  64. end;
  65. tscannerfile = class
  66. public
  67. inputfile : tinputfile; { current inputfile list }
  68. inputfilecount : longint;
  69. inputbuffer, { input buffer }
  70. inputpointer : pchar;
  71. inputstart : longint;
  72. line_no, { line }
  73. lastlinepos : longint;
  74. lasttokenpos : longint; { token }
  75. lasttoken,
  76. nexttoken : ttoken;
  77. comment_level,
  78. yylexcount : longint;
  79. lastasmgetchar : char;
  80. ignoredirectives : tstringlist; { ignore directives, used to give warnings only once }
  81. preprocstack : tpreprocstack;
  82. macros : Tdictionary;
  83. in_asm_string : boolean;
  84. preproc_pattern : string;
  85. preproc_token : ttoken;
  86. constructor Create(const fn:string);
  87. destructor Destroy;override;
  88. { File buffer things }
  89. function openinputfile:boolean;
  90. procedure closeinputfile;
  91. function tempopeninputfile:boolean;
  92. procedure tempcloseinputfile;
  93. procedure saveinputfile;
  94. procedure restoreinputfile;
  95. procedure firstfile;
  96. procedure nextfile;
  97. procedure addfile(hp:tinputfile);
  98. procedure reload;
  99. procedure insertmacro(const macname:string;p:pchar;len,line,fileindex:longint);
  100. { Scanner things }
  101. procedure def_macro(const s : string);
  102. procedure set_macro(const s : string;value : string);
  103. procedure gettokenpos;
  104. procedure inc_comment_level;
  105. procedure dec_comment_level;
  106. procedure illegal_char(c:char);
  107. procedure end_of_file;
  108. procedure checkpreprocstack;
  109. procedure poppreprocstack;
  110. procedure addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:longint);
  111. procedure elsepreprocstack;
  112. procedure handleconditional(p:tdirectiveitem);
  113. procedure handledirectives;
  114. procedure linebreak;
  115. procedure readchar;
  116. procedure readstring;
  117. procedure readnumber;
  118. function readid:string;
  119. function readval:longint;
  120. function readcomment:string;
  121. function readstate:char;
  122. procedure skipspace;
  123. procedure skipuntildirective;
  124. procedure skipcomment;
  125. procedure skipdelphicomment;
  126. procedure skipoldtpcomment;
  127. procedure readtoken;
  128. function readpreproc:ttoken;
  129. function asmgetcharstart : char;
  130. function asmgetchar:char;
  131. end;
  132. {$ifdef PREPROCWRITE}
  133. tpreprocfile=class
  134. f : text;
  135. buf : pointer;
  136. spacefound,
  137. eolfound : boolean;
  138. constructor create(const fn:string);
  139. destructor destroy;
  140. procedure Add(const s:string);
  141. procedure AddSpace;
  142. end;
  143. {$endif PREPROCWRITE}
  144. var
  145. { read strings }
  146. c : char;
  147. orgpattern,
  148. pattern : string;
  149. patternw : pcompilerwidestring;
  150. { token }
  151. token, { current token being parsed }
  152. idtoken : ttoken; { holds the token if the pattern is a known word }
  153. current_scanner : tscannerfile; { current scanner in use }
  154. aktcommentstyle : tcommentstyle; { needed to use read_comment from directives }
  155. {$ifdef PREPROCWRITE}
  156. preprocfile : tpreprocfile; { used with only preprocessing }
  157. {$endif PREPROCWRITE}
  158. type
  159. tdirectivemode = (directive_all, directive_turbo, directive_mac);
  160. procedure AddDirective(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  161. procedure AddConditional(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  162. procedure InitScanner;
  163. procedure DoneScanner;
  164. implementation
  165. uses
  166. {$ifdef delphi}
  167. dmisc,
  168. {$else}
  169. dos,
  170. {$endif delphi}
  171. cutils,
  172. systems,
  173. switches,
  174. symbase,symtable,symtype,
  175. fmodule;
  176. var
  177. { dictionaries with the supported directives }
  178. turbo_scannerdirectives : tdictionary; { for other modes }
  179. mac_scannerdirectives : tdictionary; { for mode mac }
  180. {*****************************************************************************
  181. Helper routines
  182. *****************************************************************************}
  183. const
  184. { use any special name that is an invalid file name to avoid problems }
  185. preprocstring : array [preproctyp] of string[7]
  186. = ('$IFDEF','$IFNDEF','$IF','$IFOPT','$ELSE');
  187. function is_keyword(const s:string):boolean;
  188. var
  189. low,high,mid : longint;
  190. begin
  191. if not (length(s) in [tokenlenmin..tokenlenmax]) then
  192. begin
  193. is_keyword:=false;
  194. exit;
  195. end;
  196. low:=ord(tokenidx^[length(s),s[1]].first);
  197. high:=ord(tokenidx^[length(s),s[1]].last);
  198. while low<high do
  199. begin
  200. mid:=(high+low+1) shr 1;
  201. if pattern<tokeninfo^[ttoken(mid)].str then
  202. high:=mid-1
  203. else
  204. low:=mid;
  205. end;
  206. is_keyword:=(pattern=tokeninfo^[ttoken(high)].str) and
  207. (tokeninfo^[ttoken(high)].keyword in aktmodeswitches);
  208. end;
  209. {*****************************************************************************
  210. Conditional Directives
  211. *****************************************************************************}
  212. procedure dir_else;
  213. begin
  214. current_scanner.elsepreprocstack;
  215. end;
  216. procedure dir_endif;
  217. begin
  218. current_scanner.poppreprocstack;
  219. end;
  220. procedure dir_ifdef;
  221. var
  222. hs : string;
  223. mac : tmacro;
  224. begin
  225. current_scanner.skipspace;
  226. hs:=current_scanner.readid;
  227. if hs='' then
  228. Message(scan_e_error_in_preproc_expr);
  229. mac:=tmacro(current_scanner.macros.search(hs));
  230. if assigned(mac) then
  231. mac.is_used:=true;
  232. current_scanner.addpreprocstack(pp_ifdef,assigned(mac) and mac.defined,hs,scan_c_ifdef_found);
  233. end;
  234. procedure dir_ifndef;
  235. var
  236. hs : string;
  237. mac : tmacro;
  238. begin
  239. current_scanner.skipspace;
  240. hs:=current_scanner.readid;
  241. if hs='' then
  242. Message(scan_e_error_in_preproc_expr);
  243. mac:=tmacro(current_scanner.macros.search(hs));
  244. if assigned(mac) then
  245. mac.is_used:=true;
  246. current_scanner.addpreprocstack(pp_ifndef,not(assigned(mac) and mac.defined),hs,scan_c_ifndef_found);
  247. end;
  248. procedure dir_ifopt;
  249. var
  250. hs : string;
  251. found : boolean;
  252. state : char;
  253. begin
  254. current_scanner.skipspace;
  255. hs:=current_scanner.readid;
  256. if (length(hs)>1) then
  257. Message1(scan_w_illegal_switch,hs)
  258. else
  259. begin
  260. state:=current_scanner.ReadState;
  261. if state in ['-','+'] then
  262. found:=CheckSwitch(hs[1],state);
  263. end;
  264. current_scanner.addpreprocstack(pp_ifopt,found,hs,scan_c_ifopt_found);
  265. end;
  266. function parse_compiler_expr:string;
  267. function read_expr : string; forward;
  268. procedure preproc_consume(t : ttoken);
  269. begin
  270. if t<>current_scanner.preproc_token then
  271. Message(scan_e_preproc_syntax_error);
  272. current_scanner.preproc_token:=current_scanner.readpreproc;
  273. end;
  274. function readpreproc: string;
  275. var
  276. hs: string;
  277. mac : tmacro;
  278. len : integer;
  279. begin
  280. hs := current_scanner.preproc_pattern;
  281. mac:=tmacro(current_scanner.macros.search(hs));
  282. if assigned(mac) then
  283. begin
  284. if mac.defined and assigned(mac.buftext) then
  285. begin
  286. if mac.buflen>255 then
  287. begin
  288. len:=255;
  289. Message(scan_w_macro_cut_after_255_chars);
  290. end
  291. else
  292. len:=mac.buflen;
  293. hs[0]:=char(len);
  294. move(mac.buftext^,hs[1],len);
  295. end;
  296. end;
  297. readpreproc := hs;
  298. end;
  299. function read_factor : string;
  300. var
  301. hs : string;
  302. mac: tmacro;
  303. srsym : tsym;
  304. srsymtable : tsymtable;
  305. begin
  306. if current_scanner.preproc_token=_ID then
  307. begin
  308. if readpreproc='DEFINED' then
  309. begin
  310. preproc_consume(_ID);
  311. current_scanner.skipspace;
  312. if current_scanner.preproc_token =_LKLAMMER then
  313. begin
  314. preproc_consume(_LKLAMMER);
  315. current_scanner.skipspace;
  316. end
  317. else
  318. Message(scan_e_error_in_preproc_expr);
  319. if current_scanner.preproc_token =_ID then
  320. begin
  321. hs := current_scanner.preproc_pattern;
  322. mac := tmacro(current_scanner.macros.search(hs));
  323. if assigned(mac) then
  324. hs := '1'
  325. else
  326. hs := '0';
  327. read_factor := hs;
  328. preproc_consume(_ID);
  329. current_scanner.skipspace;
  330. end
  331. else
  332. Message(scan_e_error_in_preproc_expr);
  333. if current_scanner.preproc_token =_RKLAMMER then
  334. preproc_consume(_RKLAMMER)
  335. else
  336. Message(scan_e_error_in_preproc_expr);
  337. end
  338. else
  339. if readpreproc='DECLARED' then
  340. begin
  341. preproc_consume(_ID);
  342. current_scanner.skipspace;
  343. if current_scanner.preproc_token =_LKLAMMER then
  344. begin
  345. preproc_consume(_LKLAMMER);
  346. current_scanner.skipspace;
  347. end
  348. else
  349. Message(scan_e_error_in_preproc_expr);
  350. if current_scanner.preproc_token =_ID then
  351. begin
  352. hs := upper(current_scanner.preproc_pattern);
  353. if searchsym(hs,srsym,srsymtable) then
  354. hs := '1'
  355. else
  356. hs := '0';
  357. read_factor := hs;
  358. preproc_consume(_ID);
  359. current_scanner.skipspace;
  360. end
  361. else
  362. Message(scan_e_error_in_preproc_expr);
  363. if current_scanner.preproc_token =_RKLAMMER then
  364. preproc_consume(_RKLAMMER)
  365. else
  366. Message(scan_e_error_in_preproc_expr);
  367. end
  368. else
  369. if readpreproc='NOT' then
  370. begin
  371. preproc_consume(_ID);
  372. hs:=read_expr;
  373. if hs='0' then
  374. read_factor:='1'
  375. else
  376. read_factor:='0';
  377. end
  378. else
  379. begin
  380. hs:=readpreproc;
  381. preproc_consume(_ID);
  382. read_factor:=hs;
  383. end
  384. end
  385. else if current_scanner.preproc_token =_LKLAMMER then
  386. begin
  387. preproc_consume(_LKLAMMER);
  388. read_factor:=read_expr;
  389. preproc_consume(_RKLAMMER);
  390. end
  391. else
  392. Message(scan_e_error_in_preproc_expr);
  393. end;
  394. function read_term : string;
  395. var
  396. hs1,hs2 : string;
  397. l1,l2 : longint;
  398. w : integer;
  399. begin
  400. hs1:=read_factor;
  401. while true do
  402. begin
  403. if (current_scanner.preproc_token=_ID) then
  404. begin
  405. if readpreproc='AND' then
  406. begin
  407. preproc_consume(_ID);
  408. hs2:=read_expr;
  409. valint(hs1,l1,w); valint(hs2,l2,w);
  410. if (l1>0) and (l2>0) then
  411. hs1:='1'
  412. else
  413. hs1:='0';
  414. read_term := hs1;
  415. exit;
  416. end
  417. else
  418. break;
  419. end
  420. else
  421. break;
  422. end;
  423. read_term:=hs1;
  424. end;
  425. function read_simple_expr : string;
  426. var
  427. hs1,hs2 : string;
  428. l1,l2 : longint;
  429. w : integer;
  430. begin
  431. hs1:=read_term;
  432. while true do
  433. begin
  434. if (current_scanner.preproc_token=_ID) then
  435. begin
  436. if readpreproc='OR' then
  437. begin
  438. preproc_consume(_ID);
  439. hs2:=read_expr;
  440. valint(hs1,l1,w); valint(hs2,l2,w);
  441. if (l1>0) or (l2>0) then
  442. hs1:='1'
  443. else
  444. hs1:='0';
  445. read_simple_expr := hs1;
  446. exit;
  447. end
  448. else
  449. break;
  450. end
  451. else
  452. break;
  453. end;
  454. read_simple_expr:=hs1;
  455. end;
  456. function read_expr : string;
  457. var
  458. hs1,hs2 : string;
  459. b : boolean;
  460. t : ttoken;
  461. w : integer;
  462. l1,l2 : longint;
  463. begin
  464. hs1:=read_simple_expr;
  465. t:=current_scanner.preproc_token;
  466. if not(t in [_EQUAL,_UNEQUAL,_LT,_GT,_LTE,_GTE]) then
  467. begin
  468. read_expr:=hs1;
  469. exit;
  470. end;
  471. preproc_consume(t);
  472. hs2:=read_simple_expr;
  473. if is_number(hs1) and is_number(hs2) then
  474. begin
  475. valint(hs1,l1,w);
  476. valint(hs2,l2,w);
  477. case t of
  478. _EQUAL : b:=l1=l2;
  479. _UNEQUAL : b:=l1<>l2;
  480. _LT : b:=l1<l2;
  481. _GT : b:=l1>l2;
  482. _GTE : b:=l1>=l2;
  483. _LTE : b:=l1<=l2;
  484. end;
  485. end
  486. else
  487. begin
  488. case t of
  489. _EQUAL : b:=hs1=hs2;
  490. _UNEQUAL : b:=hs1<>hs2;
  491. _LT : b:=hs1<hs2;
  492. _GT : b:=hs1>hs2;
  493. _GTE : b:=hs1>=hs2;
  494. _LTE : b:=hs1<=hs2;
  495. end;
  496. end;
  497. if b then
  498. read_expr:='1'
  499. else
  500. read_expr:='0';
  501. end;
  502. begin
  503. current_scanner.skipspace;
  504. { start preproc expression scanner }
  505. current_scanner.preproc_token:=current_scanner.readpreproc;
  506. parse_compiler_expr:=read_expr;
  507. end;
  508. procedure dir_if;
  509. var
  510. hs : string;
  511. begin
  512. hs:=parse_compiler_expr;
  513. current_scanner.addpreprocstack(pp_if,hs<>'0',hs,scan_c_if_found);
  514. end;
  515. procedure dir_define;
  516. var
  517. hs : string;
  518. bracketcount : longint;
  519. mac : tmacro;
  520. macropos : longint;
  521. macrobuffer : pmacrobuffer;
  522. begin
  523. current_scanner.skipspace;
  524. hs:=current_scanner.readid;
  525. mac:=tmacro(current_scanner.macros.search(hs));
  526. if not assigned(mac) then
  527. begin
  528. mac:=tmacro.create(hs);
  529. mac.defined:=true;
  530. Message1(parser_c_macro_defined,mac.name);
  531. current_scanner.macros.insert(mac);
  532. end
  533. else
  534. begin
  535. Message1(parser_c_macro_defined,mac.name);
  536. mac.defined:=true;
  537. { delete old definition }
  538. if assigned(mac.buftext) then
  539. begin
  540. freemem(mac.buftext,mac.buflen);
  541. mac.buftext:=nil;
  542. end;
  543. end;
  544. mac.is_used:=true;
  545. if (cs_support_macro in aktmoduleswitches) then
  546. begin
  547. { key words are never substituted }
  548. if is_keyword(hs) then
  549. Message(scan_e_keyword_cant_be_a_macro);
  550. { !!!!!! handle macro params, need we this? }
  551. current_scanner.skipspace;
  552. { may be a macro? }
  553. if c=':' then
  554. begin
  555. current_scanner.readchar;
  556. if c='=' then
  557. begin
  558. new(macrobuffer);
  559. macropos:=0;
  560. { parse macro, brackets are counted so it's possible
  561. to have a $ifdef etc. in the macro }
  562. bracketcount:=0;
  563. repeat
  564. current_scanner.readchar;
  565. case c of
  566. '}' :
  567. if (bracketcount=0) then
  568. break
  569. else
  570. dec(bracketcount);
  571. '{' :
  572. inc(bracketcount);
  573. #10,#13 :
  574. current_scanner.linebreak;
  575. #26 :
  576. current_scanner.end_of_file;
  577. end;
  578. macrobuffer^[macropos]:=c;
  579. inc(macropos);
  580. if macropos>maxmacrolen then
  581. Message(scan_f_macro_buffer_overflow);
  582. until false;
  583. { free buffer of macro ?}
  584. if assigned(mac.buftext) then
  585. freemem(mac.buftext,mac.buflen);
  586. { get new mem }
  587. getmem(mac.buftext,macropos);
  588. mac.buflen:=macropos;
  589. { copy the text }
  590. move(macrobuffer^,mac.buftext^,macropos);
  591. dispose(macrobuffer);
  592. end;
  593. end;
  594. end
  595. else
  596. begin
  597. { check if there is an assignment, then we need to give a
  598. warning }
  599. current_scanner.skipspace;
  600. if c=':' then
  601. begin
  602. current_scanner.readchar;
  603. if c='=' then
  604. Message(scan_w_macro_support_turned_off);
  605. end;
  606. end;
  607. end;
  608. procedure dir_setc;
  609. var
  610. hs : string;
  611. mac : tmacro;
  612. begin
  613. current_scanner.skipspace;
  614. hs:=current_scanner.readid;
  615. mac:=tmacro(current_scanner.macros.search(hs));
  616. if not assigned(mac) then
  617. begin
  618. mac:=tmacro.create(hs);
  619. mac.defined:=true;
  620. Message1(parser_c_macro_defined,mac.name);
  621. current_scanner.macros.insert(mac);
  622. end
  623. else
  624. begin
  625. Message1(parser_c_macro_defined,mac.name);
  626. mac.defined:=true;
  627. { delete old definition }
  628. if assigned(mac.buftext) then
  629. begin
  630. freemem(mac.buftext,mac.buflen);
  631. mac.buftext:=nil;
  632. end;
  633. end;
  634. mac.is_used:=true;
  635. { key words are never substituted }
  636. if is_keyword(hs) then
  637. Message(scan_e_keyword_cant_be_a_macro);
  638. { !!!!!! handle macro params, need we this? }
  639. current_scanner.skipspace;
  640. { may be a macro? }
  641. //both versions with := and = are allowed
  642. if c=':' then
  643. current_scanner.readchar;
  644. if c='=' then
  645. begin
  646. current_scanner.readchar;
  647. hs:= parse_compiler_expr;
  648. if length(hs) <> 0 then
  649. begin
  650. { free buffer of macro ?}
  651. if assigned(mac.buftext) then
  652. freemem(mac.buftext,mac.buflen);
  653. { get new mem }
  654. getmem(mac.buftext,length(hs));
  655. mac.buflen:=length(hs);
  656. { copy the text }
  657. move(hs[1],mac.buftext^,mac.buflen);
  658. end
  659. else
  660. Message(scan_e_preproc_syntax_error);
  661. end
  662. else
  663. Message(scan_e_preproc_syntax_error);
  664. end;
  665. procedure dir_undef;
  666. var
  667. hs : string;
  668. mac : tmacro;
  669. begin
  670. current_scanner.skipspace;
  671. hs:=current_scanner.readid;
  672. mac:=tmacro(current_scanner.macros.search(hs));
  673. if not assigned(mac) then
  674. begin
  675. mac:=tmacro.create(hs);
  676. Message1(parser_c_macro_undefined,mac.name);
  677. mac.defined:=false;
  678. current_scanner.macros.insert(mac);
  679. end
  680. else
  681. begin
  682. Message1(parser_c_macro_undefined,mac.name);
  683. mac.defined:=false;
  684. { delete old definition }
  685. if assigned(mac.buftext) then
  686. begin
  687. freemem(mac.buftext,mac.buflen);
  688. mac.buftext:=nil;
  689. end;
  690. end;
  691. mac.is_used:=true;
  692. end;
  693. procedure dir_include;
  694. function findincludefile(const path,name,ext:string;var foundfile:string):boolean;
  695. var
  696. found : boolean;
  697. hpath : string;
  698. begin
  699. { look for the include file
  700. 1. specified path,path of current inputfile,current dir
  701. 2. local includepath
  702. 3. global includepath }
  703. found:=false;
  704. foundfile:='';
  705. hpath:='';
  706. if path<>'' then
  707. begin
  708. if not path_absolute(path) then
  709. hpath:=current_scanner.inputfile.path^+path
  710. else
  711. hpath:=path+';'+current_scanner.inputfile.path^;
  712. end
  713. else
  714. hpath:=current_scanner.inputfile.path^;
  715. found:=FindFile(name+ext,hpath+';.'+source_info.DirSep,foundfile);
  716. if (not found) then
  717. found:=current_module.localincludesearchpath.FindFile(name+ext,foundfile);
  718. if (not found) then
  719. found:=includesearchpath.FindFile(name+ext,foundfile);
  720. findincludefile:=found;
  721. end;
  722. var
  723. args,
  724. foundfile,
  725. hs : string;
  726. path : dirstr;
  727. name : namestr;
  728. ext : extstr;
  729. hp : tinputfile;
  730. found : boolean;
  731. begin
  732. current_scanner.skipspace;
  733. args:=current_scanner.readcomment;
  734. hs:=GetToken(args,' ');
  735. if hs='' then
  736. exit;
  737. if (hs[1]='%') then
  738. begin
  739. { case insensitive }
  740. hs:=upper(hs);
  741. { remove %'s }
  742. Delete(hs,1,1);
  743. if hs[length(hs)]='%' then
  744. Delete(hs,length(hs),1);
  745. { save old }
  746. path:=hs;
  747. { first check for internal macros }
  748. if hs='TIME' then
  749. hs:=gettimestr
  750. else
  751. if hs='DATE' then
  752. hs:=getdatestr
  753. else
  754. if hs='FILE' then
  755. hs:=current_module.sourcefiles.get_file_name(aktfilepos.fileindex)
  756. else
  757. if hs='LINE' then
  758. hs:=tostr(aktfilepos.line)
  759. else
  760. if hs='FPCVERSION' then
  761. hs:=version_string
  762. else
  763. if hs='FPCTARGET' then
  764. hs:=target_cpu_string
  765. else
  766. if hs='FPCTARGETCPU' then
  767. hs:=target_cpu_string
  768. else
  769. if hs='FPCTARGETOS' then
  770. hs:=target_info.shortname
  771. else
  772. hs:=getenv(hs);
  773. if hs='' then
  774. Message1(scan_w_include_env_not_found,path);
  775. { make it a stringconst }
  776. hs:=''''+hs+'''';
  777. current_scanner.insertmacro(path,@hs[1],length(hs),
  778. current_scanner.line_no,current_scanner.inputfile.ref_index);
  779. end
  780. else
  781. begin
  782. hs:=FixFileName(hs);
  783. fsplit(hs,path,name,ext);
  784. { try to find the file }
  785. found:=findincludefile(path,name,ext,foundfile);
  786. if (ext='') then
  787. begin
  788. { try default extensions .inc , .pp and .pas }
  789. if (not found) then
  790. found:=findincludefile(path,name,'.inc',foundfile);
  791. if (not found) then
  792. found:=findincludefile(path,name,target_info.sourceext,foundfile);
  793. if (not found) then
  794. found:=findincludefile(path,name,target_info.pasext,foundfile);
  795. end;
  796. if current_scanner.inputfilecount<max_include_nesting then
  797. begin
  798. inc(current_scanner.inputfilecount);
  799. { we need to reread the current char }
  800. dec(current_scanner.inputpointer);
  801. { shutdown current file }
  802. current_scanner.tempcloseinputfile;
  803. { load new file }
  804. hp:=do_openinputfile(foundfile);
  805. current_scanner.addfile(hp);
  806. current_module.sourcefiles.register_file(hp);
  807. if not current_scanner.openinputfile then
  808. Message1(scan_f_cannot_open_includefile,hs);
  809. Message1(scan_t_start_include_file,current_scanner.inputfile.path^+current_scanner.inputfile.name^);
  810. current_scanner.reload;
  811. end
  812. else
  813. Message(scan_f_include_deep_ten);
  814. end;
  815. end;
  816. {*****************************************************************************
  817. TMacro
  818. *****************************************************************************}
  819. constructor tmacro.create(const n : string);
  820. begin
  821. inherited createname(n);
  822. defined:=true;
  823. defined_at_startup:=false;
  824. fileinfo:=akttokenpos;
  825. is_used:=false;
  826. buftext:=nil;
  827. buflen:=0;
  828. end;
  829. destructor tmacro.destroy;
  830. begin
  831. if assigned(buftext) then
  832. freemem(buftext,buflen);
  833. inherited destroy;
  834. end;
  835. {*****************************************************************************
  836. Preprocessor writting
  837. *****************************************************************************}
  838. {$ifdef PREPROCWRITE}
  839. constructor tpreprocfile.create(const fn:string);
  840. begin
  841. { open outputfile }
  842. assign(f,fn);
  843. {$I-}
  844. rewrite(f);
  845. {$I+}
  846. if ioresult<>0 then
  847. Comment(V_Fatal,'can''t create file '+fn);
  848. getmem(buf,preprocbufsize);
  849. settextbuf(f,buf^,preprocbufsize);
  850. { reset }
  851. eolfound:=false;
  852. spacefound:=false;
  853. end;
  854. destructor tpreprocfile.destroy;
  855. begin
  856. close(f);
  857. freemem(buf,preprocbufsize);
  858. end;
  859. procedure tpreprocfile.add(const s:string);
  860. begin
  861. write(f,s);
  862. end;
  863. procedure tpreprocfile.addspace;
  864. begin
  865. if eolfound then
  866. begin
  867. writeln(f,'');
  868. eolfound:=false;
  869. spacefound:=false;
  870. end
  871. else
  872. if spacefound then
  873. begin
  874. write(f,' ');
  875. spacefound:=false;
  876. end;
  877. end;
  878. {$endif PREPROCWRITE}
  879. {*****************************************************************************
  880. TPreProcStack
  881. *****************************************************************************}
  882. constructor tpreprocstack.create(atyp : preproctyp;a:boolean;n:tpreprocstack);
  883. begin
  884. accept:=a;
  885. typ:=atyp;
  886. next:=n;
  887. end;
  888. {*****************************************************************************
  889. TDirectiveItem
  890. *****************************************************************************}
  891. constructor TDirectiveItem.Create(const n:string;p:tdirectiveproc);
  892. begin
  893. inherited CreateName(n);
  894. is_conditional:=false;
  895. proc:={$ifndef FPCPROCVAR}@{$endif}p;
  896. end;
  897. constructor TDirectiveItem.CreateCond(const n:string;p:tdirectiveproc);
  898. begin
  899. inherited CreateName(n);
  900. is_conditional:=true;
  901. proc:={$ifndef FPCPROCVAR}@{$endif}p;
  902. end;
  903. {****************************************************************************
  904. TSCANNERFILE
  905. ****************************************************************************}
  906. constructor tscannerfile.create(const fn:string);
  907. begin
  908. inputfile:=do_openinputfile(fn);
  909. if assigned(current_module) then
  910. current_module.sourcefiles.register_file(inputfile);
  911. { reset localinput }
  912. inputbuffer:=nil;
  913. inputpointer:=nil;
  914. inputstart:=0;
  915. { reset scanner }
  916. preprocstack:=nil;
  917. comment_level:=0;
  918. yylexcount:=0;
  919. block_type:=bt_general;
  920. line_no:=0;
  921. lastlinepos:=0;
  922. lasttokenpos:=0;
  923. lasttoken:=NOTOKEN;
  924. nexttoken:=NOTOKEN;
  925. lastasmgetchar:=#0;
  926. ignoredirectives:=TStringList.Create;
  927. in_asm_string:=false;
  928. macros:=tdictionary.create;
  929. end;
  930. procedure tscannerfile.firstfile;
  931. begin
  932. { load block }
  933. if not openinputfile then
  934. Message1(scan_f_cannot_open_input,inputfile.name^);
  935. reload;
  936. end;
  937. destructor tscannerfile.destroy;
  938. begin
  939. if assigned(current_module) and
  940. (current_module.state=ms_compiled) and
  941. (status.errorcount=0) then
  942. checkpreprocstack
  943. else
  944. begin
  945. while assigned(preprocstack) do
  946. poppreprocstack;
  947. end;
  948. if not inputfile.closed then
  949. closeinputfile;
  950. ignoredirectives.free;
  951. macros.free;
  952. end;
  953. procedure tscannerfile.def_macro(const s : string);
  954. var
  955. mac : tmacro;
  956. begin
  957. mac:=tmacro(macros.search(s));
  958. if mac=nil then
  959. begin
  960. mac:=tmacro.create(s);
  961. Message1(parser_c_macro_defined,mac.name);
  962. macros.insert(mac);
  963. end;
  964. mac.defined:=true;
  965. mac.defined_at_startup:=true;
  966. end;
  967. procedure tscannerfile.set_macro(const s : string;value : string);
  968. var
  969. mac : tmacro;
  970. begin
  971. mac:=tmacro(macros.search(s));
  972. if mac=nil then
  973. begin
  974. mac:=tmacro.create(s);
  975. macros.insert(mac);
  976. end
  977. else
  978. begin
  979. if assigned(mac.buftext) then
  980. freemem(mac.buftext,mac.buflen);
  981. end;
  982. Message2(parser_c_macro_set_to,mac.name,value);
  983. mac.buflen:=length(value);
  984. getmem(mac.buftext,mac.buflen);
  985. move(value[1],mac.buftext^,mac.buflen);
  986. mac.defined:=true;
  987. mac.defined_at_startup:=true;
  988. end;
  989. function tscannerfile.openinputfile:boolean;
  990. begin
  991. openinputfile:=inputfile.open;
  992. { load buffer }
  993. inputbuffer:=inputfile.buf;
  994. inputpointer:=inputfile.buf;
  995. inputstart:=inputfile.bufstart;
  996. { line }
  997. line_no:=0;
  998. lastlinepos:=0;
  999. lasttokenpos:=0;
  1000. end;
  1001. procedure tscannerfile.closeinputfile;
  1002. begin
  1003. inputfile.close;
  1004. { reset buffer }
  1005. inputbuffer:=nil;
  1006. inputpointer:=nil;
  1007. inputstart:=0;
  1008. { reset line }
  1009. line_no:=0;
  1010. lastlinepos:=0;
  1011. lasttokenpos:=0;
  1012. end;
  1013. function tscannerfile.tempopeninputfile:boolean;
  1014. begin
  1015. if inputfile.is_macro then
  1016. exit;
  1017. tempopeninputfile:=inputfile.tempopen;
  1018. { reload buffer }
  1019. inputbuffer:=inputfile.buf;
  1020. inputpointer:=inputfile.buf;
  1021. inputstart:=inputfile.bufstart;
  1022. end;
  1023. procedure tscannerfile.tempcloseinputfile;
  1024. begin
  1025. if inputfile.closed or inputfile.is_macro then
  1026. exit;
  1027. inputfile.setpos(inputstart+(inputpointer-inputbuffer));
  1028. inputfile.tempclose;
  1029. { reset buffer }
  1030. inputbuffer:=nil;
  1031. inputpointer:=nil;
  1032. inputstart:=0;
  1033. end;
  1034. procedure tscannerfile.saveinputfile;
  1035. begin
  1036. inputfile.saveinputpointer:=inputpointer;
  1037. inputfile.savelastlinepos:=lastlinepos;
  1038. inputfile.saveline_no:=line_no;
  1039. end;
  1040. procedure tscannerfile.restoreinputfile;
  1041. begin
  1042. inputpointer:=inputfile.saveinputpointer;
  1043. lastlinepos:=inputfile.savelastlinepos;
  1044. line_no:=inputfile.saveline_no;
  1045. if not inputfile.is_macro then
  1046. parser_current_file:=inputfile.name^;
  1047. end;
  1048. procedure tscannerfile.nextfile;
  1049. var
  1050. to_dispose : tinputfile;
  1051. begin
  1052. if assigned(inputfile.next) then
  1053. begin
  1054. if inputfile.is_macro then
  1055. to_dispose:=inputfile
  1056. else
  1057. begin
  1058. to_dispose:=nil;
  1059. dec(inputfilecount);
  1060. end;
  1061. { we can allways close the file, no ? }
  1062. inputfile.close;
  1063. inputfile:=inputfile.next;
  1064. if assigned(to_dispose) then
  1065. to_dispose.free;
  1066. restoreinputfile;
  1067. end;
  1068. end;
  1069. procedure tscannerfile.addfile(hp:tinputfile);
  1070. begin
  1071. saveinputfile;
  1072. { add to list }
  1073. hp.next:=inputfile;
  1074. inputfile:=hp;
  1075. { load new inputfile }
  1076. restoreinputfile;
  1077. end;
  1078. procedure tscannerfile.reload;
  1079. begin
  1080. with inputfile do
  1081. begin
  1082. { when nothing more to read then leave immediatly, so we
  1083. don't change the aktfilepos and leave it point to the last
  1084. char }
  1085. if (c=#26) and (not assigned(next)) then
  1086. exit;
  1087. repeat
  1088. { still more to read?, then change the #0 to a space so its seen
  1089. as a seperator, this can't be used for macro's which can change
  1090. the place of the #0 in the buffer with tempopen }
  1091. if (c=#0) and (bufsize>0) and
  1092. not(inputfile.is_macro) and
  1093. (inputpointer-inputbuffer<bufsize) then
  1094. begin
  1095. c:=' ';
  1096. inc(inputpointer);
  1097. exit;
  1098. end;
  1099. { can we read more from this file ? }
  1100. if (c<>#26) and (not endoffile) then
  1101. begin
  1102. readbuf;
  1103. inputpointer:=buf;
  1104. inputbuffer:=buf;
  1105. inputstart:=bufstart;
  1106. { first line? }
  1107. if line_no=0 then
  1108. begin
  1109. line_no:=1;
  1110. if cs_asm_source in aktglobalswitches then
  1111. inputfile.setline(line_no,bufstart);
  1112. end;
  1113. end
  1114. else
  1115. begin
  1116. { load eof position in tokenpos/aktfilepos }
  1117. gettokenpos;
  1118. { close file }
  1119. closeinputfile;
  1120. { no next module, than EOF }
  1121. if not assigned(inputfile.next) then
  1122. begin
  1123. c:=#26;
  1124. exit;
  1125. end;
  1126. { load next file and reopen it }
  1127. nextfile;
  1128. tempopeninputfile;
  1129. { status }
  1130. Message1(scan_t_back_in,inputfile.name^);
  1131. end;
  1132. { load next char }
  1133. c:=inputpointer^;
  1134. inc(inputpointer);
  1135. until c<>#0; { if also end, then reload again }
  1136. end;
  1137. end;
  1138. procedure tscannerfile.insertmacro(const macname:string;p:pchar;len,line,fileindex:longint);
  1139. var
  1140. hp : tinputfile;
  1141. begin
  1142. { save old postion }
  1143. dec(inputpointer);
  1144. tempcloseinputfile;
  1145. { create macro 'file' }
  1146. { use special name to dispose after !! }
  1147. hp:=do_openinputfile('_Macro_.'+macname);
  1148. addfile(hp);
  1149. with inputfile do
  1150. begin
  1151. setmacro(p,len);
  1152. { local buffer }
  1153. inputbuffer:=buf;
  1154. inputpointer:=buf;
  1155. inputstart:=bufstart;
  1156. ref_index:=fileindex;
  1157. end;
  1158. { reset line }
  1159. line_no:=line;
  1160. lastlinepos:=0;
  1161. lasttokenpos:=0;
  1162. { load new c }
  1163. c:=inputpointer^;
  1164. inc(inputpointer);
  1165. end;
  1166. procedure tscannerfile.gettokenpos;
  1167. { load the values of tokenpos and lasttokenpos }
  1168. begin
  1169. lasttokenpos:=inputstart+(inputpointer-inputbuffer);
  1170. akttokenpos.line:=line_no;
  1171. akttokenpos.column:=lasttokenpos-lastlinepos;
  1172. akttokenpos.fileindex:=inputfile.ref_index;
  1173. aktfilepos:=akttokenpos;
  1174. end;
  1175. procedure tscannerfile.inc_comment_level;
  1176. var
  1177. oldaktfilepos : tfileposinfo;
  1178. begin
  1179. if (m_nested_comment in aktmodeswitches) then
  1180. inc(comment_level)
  1181. else
  1182. comment_level:=1;
  1183. if (comment_level>1) then
  1184. begin
  1185. oldaktfilepos:=aktfilepos;
  1186. gettokenpos; { update for warning }
  1187. Message1(scan_w_comment_level,tostr(comment_level));
  1188. aktfilepos:=oldaktfilepos;
  1189. end;
  1190. end;
  1191. procedure tscannerfile.dec_comment_level;
  1192. begin
  1193. if (m_nested_comment in aktmodeswitches) then
  1194. dec(comment_level)
  1195. else
  1196. comment_level:=0;
  1197. end;
  1198. procedure tscannerfile.linebreak;
  1199. var
  1200. cur : char;
  1201. oldtokenpos,
  1202. oldaktfilepos : tfileposinfo;
  1203. begin
  1204. with inputfile do
  1205. begin
  1206. if (byte(inputpointer^)=0) and not(endoffile) then
  1207. begin
  1208. cur:=c;
  1209. reload;
  1210. if byte(cur)+byte(c)<>23 then
  1211. dec(inputpointer);
  1212. end
  1213. else
  1214. begin
  1215. { Support all combination of #10 and #13 as line break }
  1216. if (byte(inputpointer^)+byte(c)=23) then
  1217. inc(inputpointer);
  1218. end;
  1219. { Always return #10 as line break }
  1220. c:=#10;
  1221. { increase line counters }
  1222. lastlinepos:=bufstart+(inputpointer-inputbuffer);
  1223. inc(line_no);
  1224. { update linebuffer }
  1225. if cs_asm_source in aktglobalswitches then
  1226. inputfile.setline(line_no,lastlinepos);
  1227. { update for status and call the show status routine,
  1228. but don't touch aktfilepos ! }
  1229. oldaktfilepos:=aktfilepos;
  1230. oldtokenpos:=akttokenpos;
  1231. gettokenpos; { update for v_status }
  1232. inc(status.compiledlines);
  1233. ShowStatus;
  1234. aktfilepos:=oldaktfilepos;
  1235. akttokenpos:=oldtokenpos;
  1236. end;
  1237. end;
  1238. procedure tscannerfile.illegal_char(c:char);
  1239. var
  1240. s : string;
  1241. begin
  1242. if c in [#32..#255] then
  1243. s:=''''+c+''''
  1244. else
  1245. s:='#'+tostr(ord(c));
  1246. Message2(scan_f_illegal_char,s,'$'+hexstr(ord(c),2));
  1247. end;
  1248. procedure tscannerfile.end_of_file;
  1249. begin
  1250. checkpreprocstack;
  1251. Message(scan_f_end_of_file);
  1252. end;
  1253. {-------------------------------------------
  1254. IF Conditional Handling
  1255. -------------------------------------------}
  1256. procedure tscannerfile.checkpreprocstack;
  1257. begin
  1258. { check for missing ifdefs }
  1259. while assigned(preprocstack) do
  1260. begin
  1261. Message4(scan_e_endif_expected,preprocstring[preprocstack.typ],preprocstack.name,
  1262. preprocstack.owner.inputfile.name^,tostr(preprocstack.line_nb));
  1263. poppreprocstack;
  1264. end;
  1265. end;
  1266. procedure tscannerfile.poppreprocstack;
  1267. var
  1268. hp : tpreprocstack;
  1269. begin
  1270. if assigned(preprocstack) then
  1271. begin
  1272. Message1(scan_c_endif_found,preprocstack.name);
  1273. hp:=preprocstack.next;
  1274. preprocstack.free;
  1275. preprocstack:=hp;
  1276. end
  1277. else
  1278. Message(scan_e_endif_without_if);
  1279. end;
  1280. procedure tscannerfile.addpreprocstack(atyp : preproctyp;a:boolean;const s:string;w:longint);
  1281. begin
  1282. preprocstack:=tpreprocstack.create(atyp,((preprocstack=nil) or preprocstack.accept) and a,preprocstack);
  1283. preprocstack.name:=s;
  1284. preprocstack.line_nb:=line_no;
  1285. preprocstack.owner:=self;
  1286. if preprocstack.accept then
  1287. Message2(w,preprocstack.name,'accepted')
  1288. else
  1289. Message2(w,preprocstack.name,'rejected');
  1290. end;
  1291. procedure tscannerfile.elsepreprocstack;
  1292. begin
  1293. if assigned(preprocstack) then
  1294. begin
  1295. preprocstack.typ:=pp_else;
  1296. preprocstack.line_nb:=line_no;
  1297. if not(assigned(preprocstack.next)) or (preprocstack.next.accept) then
  1298. preprocstack.accept:=not preprocstack.accept;
  1299. if preprocstack.accept then
  1300. Message2(scan_c_else_found,preprocstack.name,'accepted')
  1301. else
  1302. Message2(scan_c_else_found,preprocstack.name,'rejected');
  1303. end
  1304. else
  1305. Message(scan_e_endif_without_if);
  1306. end;
  1307. procedure tscannerfile.handleconditional(p:tdirectiveitem);
  1308. var
  1309. oldaktfilepos : tfileposinfo;
  1310. begin
  1311. oldaktfilepos:=aktfilepos;
  1312. repeat
  1313. current_scanner.gettokenpos;
  1314. p.proc{$ifdef FPCPROCVAR}(){$endif};
  1315. { accept the text ? }
  1316. if (current_scanner.preprocstack=nil) or current_scanner.preprocstack.accept then
  1317. break
  1318. else
  1319. begin
  1320. current_scanner.gettokenpos;
  1321. Message(scan_c_skipping_until);
  1322. repeat
  1323. current_scanner.skipuntildirective;
  1324. if not (m_mac in aktmodeswitches) then
  1325. p:=tdirectiveitem(turbo_scannerdirectives.search(current_scanner.readid))
  1326. else
  1327. p:=tdirectiveitem(mac_scannerdirectives.search(current_scanner.readid));
  1328. until assigned(p) and (p.is_conditional);
  1329. current_scanner.gettokenpos;
  1330. Message1(scan_d_handling_switch,'$'+p.name);
  1331. end;
  1332. until false;
  1333. aktfilepos:=oldaktfilepos;
  1334. end;
  1335. procedure tscannerfile.handledirectives;
  1336. var
  1337. t : tdirectiveitem;
  1338. hs : string;
  1339. begin
  1340. gettokenpos;
  1341. readchar; {Remove the $}
  1342. hs:=readid;
  1343. {$ifdef PREPROCWRITE}
  1344. if parapreprocess then
  1345. begin
  1346. t:=Get_Directive(hs);
  1347. if not(is_conditional(t) or (t=_DIR_DEFINE) or (t=_DIR_UNDEF)) then
  1348. begin
  1349. preprocfile^.AddSpace;
  1350. preprocfile^.Add('{$'+hs+current_scanner.readcomment+'}');
  1351. exit;
  1352. end;
  1353. end;
  1354. {$endif PREPROCWRITE}
  1355. { skip this directive? }
  1356. if (ignoredirectives.find(hs)<>nil) then
  1357. begin
  1358. if (comment_level>0) then
  1359. readcomment;
  1360. { we've read the whole comment }
  1361. aktcommentstyle:=comment_none;
  1362. exit;
  1363. end;
  1364. if hs='' then
  1365. begin
  1366. Message1(scan_w_illegal_switch,'$'+hs);
  1367. end;
  1368. { Check for compiler switches }
  1369. while (length(hs)=1) and (c in ['-','+']) do
  1370. begin
  1371. HandleSwitch(hs[1],c);
  1372. current_scanner.readchar; {Remove + or -}
  1373. if c=',' then
  1374. begin
  1375. current_scanner.readchar; {Remove , }
  1376. { read next switch, support $v+,$+}
  1377. hs:=current_scanner.readid;
  1378. if (hs='') then
  1379. begin
  1380. if (c='$') and (m_fpc in aktmodeswitches) then
  1381. begin
  1382. current_scanner.readchar; { skip $ }
  1383. hs:=current_scanner.readid;
  1384. end;
  1385. if (hs='') then
  1386. Message1(scan_w_illegal_directive,'$'+c);
  1387. end
  1388. else
  1389. Message1(scan_d_handling_switch,'$'+hs);
  1390. end
  1391. else
  1392. hs:='';
  1393. end;
  1394. { directives may follow switches after a , }
  1395. if hs<>'' then
  1396. begin
  1397. if not (m_mac in aktmodeswitches) then
  1398. t:=tdirectiveitem(turbo_scannerdirectives.search(hs))
  1399. else
  1400. t:=tdirectiveitem(mac_scannerdirectives.search(hs));
  1401. if assigned(t) then
  1402. begin
  1403. if t.is_conditional then
  1404. handleconditional(t)
  1405. else
  1406. begin
  1407. Message1(scan_d_handling_switch,'$'+hs);
  1408. t.proc{$ifdef FPCPROCVAR}(){$endif};
  1409. end;
  1410. end
  1411. else
  1412. begin
  1413. current_scanner.ignoredirectives.insert(hs);
  1414. Message1(scan_w_illegal_directive,'$'+hs);
  1415. end;
  1416. { conditionals already read the comment }
  1417. if (current_scanner.comment_level>0) then
  1418. current_scanner.readcomment;
  1419. { we've read the whole comment }
  1420. aktcommentstyle:=comment_none;
  1421. end;
  1422. end;
  1423. procedure tscannerfile.readchar;
  1424. begin
  1425. c:=inputpointer^;
  1426. if c=#0 then
  1427. reload
  1428. else
  1429. inc(inputpointer);
  1430. end;
  1431. procedure tscannerfile.readstring;
  1432. var
  1433. i : longint;
  1434. begin
  1435. i:=0;
  1436. repeat
  1437. case c of
  1438. '_',
  1439. '0'..'9',
  1440. 'A'..'Z' :
  1441. begin
  1442. if i<255 then
  1443. begin
  1444. inc(i);
  1445. orgpattern[i]:=c;
  1446. pattern[i]:=c;
  1447. end;
  1448. c:=inputpointer^;
  1449. inc(inputpointer);
  1450. end;
  1451. 'a'..'z' :
  1452. begin
  1453. if i<255 then
  1454. begin
  1455. inc(i);
  1456. orgpattern[i]:=c;
  1457. pattern[i]:=chr(ord(c)-32)
  1458. end;
  1459. c:=inputpointer^;
  1460. inc(inputpointer);
  1461. end;
  1462. #0 :
  1463. reload;
  1464. else
  1465. break;
  1466. end;
  1467. until false;
  1468. orgpattern[0]:=chr(i);
  1469. pattern[0]:=chr(i);
  1470. end;
  1471. procedure tscannerfile.readnumber;
  1472. var
  1473. base,
  1474. i : longint;
  1475. begin
  1476. case c of
  1477. '%' :
  1478. begin
  1479. readchar;
  1480. base:=2;
  1481. pattern[1]:='%';
  1482. i:=1;
  1483. end;
  1484. '&' :
  1485. begin
  1486. readchar;
  1487. base:=8;
  1488. pattern[1]:='&';
  1489. i:=1;
  1490. end;
  1491. '$' :
  1492. begin
  1493. readchar;
  1494. base:=16;
  1495. pattern[1]:='$';
  1496. i:=1;
  1497. end;
  1498. else
  1499. begin
  1500. base:=10;
  1501. i:=0;
  1502. end;
  1503. end;
  1504. while ((base>=10) and (c in ['0'..'9'])) or
  1505. ((base=16) and (c in ['A'..'F','a'..'f'])) or
  1506. ((base=8) and (c in ['0'..'7'])) or
  1507. ((base=2) and (c in ['0'..'1'])) do
  1508. begin
  1509. if i<255 then
  1510. begin
  1511. inc(i);
  1512. pattern[i]:=c;
  1513. end;
  1514. readchar;
  1515. end;
  1516. pattern[0]:=chr(i);
  1517. end;
  1518. function tscannerfile.readid:string;
  1519. begin
  1520. readstring;
  1521. readid:=pattern;
  1522. end;
  1523. function tscannerfile.readval:longint;
  1524. var
  1525. l : longint;
  1526. w : integer;
  1527. begin
  1528. readnumber;
  1529. valint(pattern,l,w);
  1530. readval:=l;
  1531. end;
  1532. function tscannerfile.readcomment:string;
  1533. var
  1534. i : longint;
  1535. begin
  1536. i:=0;
  1537. repeat
  1538. case c of
  1539. '{' :
  1540. begin
  1541. if aktcommentstyle=comment_tp then
  1542. inc_comment_level;
  1543. end;
  1544. '}' :
  1545. begin
  1546. if aktcommentstyle=comment_tp then
  1547. begin
  1548. readchar;
  1549. dec_comment_level;
  1550. if comment_level=0 then
  1551. break
  1552. else
  1553. continue;
  1554. end;
  1555. end;
  1556. '*' :
  1557. begin
  1558. if aktcommentstyle=comment_oldtp then
  1559. begin
  1560. readchar;
  1561. if c=')' then
  1562. begin
  1563. readchar;
  1564. dec_comment_level;
  1565. break;
  1566. end
  1567. else
  1568. { Add both characters !!}
  1569. if (i<255) then
  1570. begin
  1571. inc(i);
  1572. readcomment[i]:='*';
  1573. if (i<255) then
  1574. begin
  1575. inc(i);
  1576. readcomment[i]:='*';
  1577. end;
  1578. end;
  1579. end
  1580. else
  1581. { Not old TP comment, so add...}
  1582. begin
  1583. if (i<255) then
  1584. begin
  1585. inc(i);
  1586. readcomment[i]:='*';
  1587. end;
  1588. end;
  1589. end;
  1590. #10,#13 :
  1591. linebreak;
  1592. #26 :
  1593. end_of_file;
  1594. else
  1595. begin
  1596. if (i<255) then
  1597. begin
  1598. inc(i);
  1599. readcomment[i]:=c;
  1600. end;
  1601. end;
  1602. end;
  1603. readchar;
  1604. until false;
  1605. readcomment[0]:=chr(i);
  1606. end;
  1607. function tscannerfile.readstate:char;
  1608. var
  1609. state : char;
  1610. begin
  1611. state:=' ';
  1612. if c=' ' then
  1613. begin
  1614. current_scanner.skipspace;
  1615. current_scanner.readid;
  1616. if pattern='ON' then
  1617. state:='+'
  1618. else
  1619. if pattern='OFF' then
  1620. state:='-';
  1621. end
  1622. else
  1623. state:=c;
  1624. if not (state in ['+','-']) then
  1625. Message(scan_e_wrong_switch_toggle);
  1626. readstate:=state;
  1627. end;
  1628. procedure tscannerfile.skipspace;
  1629. begin
  1630. repeat
  1631. case c of
  1632. #26 :
  1633. begin
  1634. reload;
  1635. if (c=#26) and not assigned(inputfile.next) then
  1636. break;
  1637. continue;
  1638. end;
  1639. #10,
  1640. #13 :
  1641. linebreak;
  1642. #9,#11,#12,' ' :
  1643. ;
  1644. else
  1645. break;
  1646. end;
  1647. readchar;
  1648. until false;
  1649. end;
  1650. procedure tscannerfile.skipuntildirective;
  1651. var
  1652. incomment : boolean;
  1653. found : longint;
  1654. next_char_loaded : boolean;
  1655. oldcommentstyle : tcommentstyle;
  1656. begin
  1657. found:=0;
  1658. next_char_loaded:=false;
  1659. incomment:=true;
  1660. oldcommentstyle:=aktcommentstyle;
  1661. repeat
  1662. case c of
  1663. #10,
  1664. #13 :
  1665. linebreak;
  1666. #26 :
  1667. begin
  1668. reload;
  1669. if (c=#26) and not assigned(inputfile.next) then
  1670. end_of_file;
  1671. continue;
  1672. end;
  1673. '{' :
  1674. begin
  1675. if not(m_nested_comment in aktmodeswitches) or
  1676. (comment_level=0) then
  1677. begin
  1678. found:=1;
  1679. aktcommentstyle:=comment_tp;
  1680. end;
  1681. inc_comment_level;
  1682. incomment:=true;
  1683. end;
  1684. '*' :
  1685. begin
  1686. if incomment then
  1687. begin
  1688. readchar;
  1689. if c=')' then
  1690. begin
  1691. dec_comment_level;
  1692. found:=0;
  1693. incomment:=false;
  1694. end
  1695. else
  1696. next_char_loaded:=true;
  1697. end
  1698. else
  1699. found := 0;
  1700. end;
  1701. '}' :
  1702. begin
  1703. dec_comment_level;
  1704. found:=0;
  1705. incomment:=false;
  1706. end;
  1707. '$' :
  1708. begin
  1709. if found=1 then
  1710. found:=2;
  1711. end;
  1712. '''' :
  1713. if not incomment then
  1714. begin
  1715. repeat
  1716. readchar;
  1717. case c of
  1718. #26 :
  1719. end_of_file;
  1720. #10,#13 :
  1721. break;
  1722. '''' :
  1723. begin
  1724. readchar;
  1725. if c<>'''' then
  1726. begin
  1727. next_char_loaded:=true;
  1728. break;
  1729. end;
  1730. end;
  1731. end;
  1732. until false;
  1733. end;
  1734. '(' :
  1735. begin
  1736. if not incomment then
  1737. begin
  1738. readchar;
  1739. if c='*' then
  1740. begin
  1741. readchar;
  1742. if c='$' then
  1743. begin
  1744. found:=2;
  1745. inc_comment_level;
  1746. aktcommentstyle:=comment_oldtp;
  1747. end
  1748. else
  1749. begin
  1750. skipoldtpcomment;
  1751. aktcommentstyle:=oldcommentstyle;
  1752. end;
  1753. end;
  1754. next_char_loaded:=true;
  1755. end
  1756. else
  1757. found:=0;
  1758. end;
  1759. '/' :
  1760. begin
  1761. if not incomment then
  1762. begin
  1763. readchar;
  1764. if c='/' then
  1765. begin
  1766. skipdelphicomment;
  1767. aktcommentstyle:=oldcommentstyle;
  1768. end;
  1769. next_char_loaded:=true;
  1770. end
  1771. else
  1772. found:=0;
  1773. end;
  1774. else
  1775. found:=0;
  1776. end;
  1777. if next_char_loaded then
  1778. next_char_loaded:=false
  1779. else
  1780. readchar;
  1781. until (found=2);
  1782. end;
  1783. {****************************************************************************
  1784. Comment Handling
  1785. ****************************************************************************}
  1786. procedure tscannerfile.skipcomment;
  1787. begin
  1788. aktcommentstyle:=comment_tp;
  1789. readchar;
  1790. inc_comment_level;
  1791. { handle compiler switches }
  1792. if (c='$') then
  1793. handledirectives;
  1794. { handle_switches can dec comment_level, }
  1795. while (comment_level>0) do
  1796. begin
  1797. case c of
  1798. '{' :
  1799. inc_comment_level;
  1800. '}' :
  1801. dec_comment_level;
  1802. #10,#13 :
  1803. linebreak;
  1804. #26 :
  1805. begin
  1806. reload;
  1807. if (c=#26) and not assigned(inputfile.next) then
  1808. end_of_file;
  1809. continue;
  1810. end;
  1811. end;
  1812. readchar;
  1813. end;
  1814. aktcommentstyle:=comment_none;
  1815. end;
  1816. procedure tscannerfile.skipdelphicomment;
  1817. begin
  1818. aktcommentstyle:=comment_delphi;
  1819. inc_comment_level;
  1820. readchar;
  1821. { this is not supported }
  1822. if c='$' then
  1823. Message(scan_e_wrong_styled_switch);
  1824. { skip comment }
  1825. while not (c in [#10,#13,#26]) do
  1826. readchar;
  1827. dec_comment_level;
  1828. aktcommentstyle:=comment_none;
  1829. end;
  1830. procedure tscannerfile.skipoldtpcomment;
  1831. var
  1832. found : longint;
  1833. begin
  1834. aktcommentstyle:=comment_oldtp;
  1835. inc_comment_level;
  1836. { only load a char if last already processed,
  1837. was cause of bug1634 PM }
  1838. if c=#0 then
  1839. readchar;
  1840. { this is now supported }
  1841. if (c='$') then
  1842. handledirectives;
  1843. { skip comment }
  1844. while (comment_level>0) do
  1845. begin
  1846. found:=0;
  1847. repeat
  1848. case c of
  1849. #26 :
  1850. begin
  1851. reload;
  1852. if (c=#26) and not assigned(inputfile.next) then
  1853. end_of_file;
  1854. continue;
  1855. end;
  1856. #10,#13 :
  1857. linebreak;
  1858. '*' :
  1859. begin
  1860. if found=3 then
  1861. found:=4
  1862. else
  1863. found:=1;
  1864. end;
  1865. ')' :
  1866. begin
  1867. if found in [1,4] then
  1868. begin
  1869. dec_comment_level;
  1870. if comment_level=0 then
  1871. found:=2
  1872. else
  1873. found:=0;
  1874. end;
  1875. end;
  1876. '(' :
  1877. begin
  1878. if found=4 then
  1879. inc_comment_level;
  1880. found:=3;
  1881. end;
  1882. else
  1883. begin
  1884. if found=4 then
  1885. inc_comment_level;
  1886. found:=0;
  1887. end;
  1888. end;
  1889. readchar;
  1890. until (found=2);
  1891. end;
  1892. aktcommentstyle:=comment_none;
  1893. end;
  1894. {****************************************************************************
  1895. Token Scanner
  1896. ****************************************************************************}
  1897. procedure tscannerfile.readtoken;
  1898. var
  1899. code : integer;
  1900. len,
  1901. low,high,mid : longint;
  1902. m : longint;
  1903. mac : tmacro;
  1904. asciinr : string[6];
  1905. msgwritten,
  1906. iswidestring : boolean;
  1907. label
  1908. exit_label;
  1909. begin
  1910. if localswitcheschanged then
  1911. begin
  1912. aktlocalswitches:=nextaktlocalswitches;
  1913. localswitcheschanged:=false;
  1914. end;
  1915. { was there already a token read, then return that token }
  1916. if nexttoken<>NOTOKEN then
  1917. begin
  1918. token:=nexttoken;
  1919. nexttoken:=NOTOKEN;
  1920. goto exit_label;
  1921. end;
  1922. { Skip all spaces and comments }
  1923. repeat
  1924. case c of
  1925. '{' :
  1926. skipcomment;
  1927. #26 :
  1928. begin
  1929. reload;
  1930. if (c=#26) and not assigned(inputfile.next) then
  1931. break;
  1932. end;
  1933. ' ',#9..#13 :
  1934. begin
  1935. {$ifdef PREPROCWRITE}
  1936. if parapreprocess then
  1937. begin
  1938. if c=#10 then
  1939. preprocfile.eolfound:=true
  1940. else
  1941. preprocfile.spacefound:=true;
  1942. end;
  1943. {$endif PREPROCWRITE}
  1944. skipspace;
  1945. end
  1946. else
  1947. break;
  1948. end;
  1949. until false;
  1950. { Save current token position, for EOF its already loaded }
  1951. if c<>#26 then
  1952. gettokenpos;
  1953. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  1954. if c in ['A'..'Z','a'..'z','_'] then
  1955. begin
  1956. readstring;
  1957. token:=_ID;
  1958. idtoken:=_ID;
  1959. { keyword or any other known token,
  1960. pattern is always uppercased }
  1961. if (pattern[1]<>'_') and (length(pattern) in [tokenlenmin..tokenlenmax]) then
  1962. begin
  1963. low:=ord(tokenidx^[length(pattern),pattern[1]].first);
  1964. high:=ord(tokenidx^[length(pattern),pattern[1]].last);
  1965. while low<high do
  1966. begin
  1967. mid:=(high+low+1) shr 1;
  1968. if pattern<tokeninfo^[ttoken(mid)].str then
  1969. high:=mid-1
  1970. else
  1971. low:=mid;
  1972. end;
  1973. if pattern=tokeninfo^[ttoken(high)].str then
  1974. begin
  1975. if tokeninfo^[ttoken(high)].keyword in aktmodeswitches then
  1976. if tokeninfo^[ttoken(high)].op=NOTOKEN then
  1977. token:=ttoken(high)
  1978. else
  1979. token:=tokeninfo^[ttoken(high)].op;
  1980. idtoken:=ttoken(high);
  1981. end;
  1982. end;
  1983. { Only process identifiers and not keywords }
  1984. if token=_ID then
  1985. begin
  1986. { this takes some time ... }
  1987. if (cs_support_macro in aktmoduleswitches) then
  1988. begin
  1989. mac:=tmacro(macros.search(pattern));
  1990. if assigned(mac) and (assigned(mac.buftext)) then
  1991. begin
  1992. if yylexcount<max_macro_nesting then
  1993. begin
  1994. inc(yylexcount);
  1995. insertmacro(pattern,mac.buftext,mac.buflen,
  1996. mac.fileinfo.line,mac.fileinfo.fileindex);
  1997. { handle empty macros }
  1998. if c=#0 then
  1999. reload;
  2000. readtoken;
  2001. { that's all folks }
  2002. dec(yylexcount);
  2003. exit;
  2004. end
  2005. else
  2006. Message(scan_w_macro_deep_ten);
  2007. end;
  2008. end;
  2009. end;
  2010. { return token }
  2011. goto exit_label;
  2012. end
  2013. else
  2014. begin
  2015. idtoken:=_NOID;
  2016. case c of
  2017. '$' :
  2018. begin
  2019. readnumber;
  2020. token:=_INTCONST;
  2021. goto exit_label;
  2022. end;
  2023. '%' :
  2024. begin
  2025. if not(m_fpc in aktmodeswitches) then
  2026. Illegal_Char(c)
  2027. else
  2028. begin
  2029. readnumber;
  2030. token:=_INTCONST;
  2031. goto exit_label;
  2032. end;
  2033. end;
  2034. '&' :
  2035. begin
  2036. if not(m_fpc in aktmodeswitches) then
  2037. Illegal_Char(c)
  2038. else
  2039. begin
  2040. readnumber;
  2041. token:=_INTCONST;
  2042. goto exit_label;
  2043. end;
  2044. end;
  2045. '0'..'9' :
  2046. begin
  2047. readnumber;
  2048. if (c in ['.','e','E']) then
  2049. begin
  2050. { first check for a . }
  2051. if c='.' then
  2052. begin
  2053. readchar;
  2054. { is it a .. from a range? }
  2055. case c of
  2056. '.' :
  2057. begin
  2058. readchar;
  2059. token:=_INTCONST;
  2060. nexttoken:=_POINTPOINT;
  2061. goto exit_label;
  2062. end;
  2063. ')' :
  2064. begin
  2065. readchar;
  2066. token:=_INTCONST;
  2067. nexttoken:=_RECKKLAMMER;
  2068. goto exit_label;
  2069. end;
  2070. end;
  2071. { insert the number after the . }
  2072. pattern:=pattern+'.';
  2073. while c in ['0'..'9'] do
  2074. begin
  2075. pattern:=pattern+c;
  2076. readchar;
  2077. end;
  2078. end;
  2079. { E can also follow after a point is scanned }
  2080. if c in ['e','E'] then
  2081. begin
  2082. pattern:=pattern+'E';
  2083. readchar;
  2084. if c in ['-','+'] then
  2085. begin
  2086. pattern:=pattern+c;
  2087. readchar;
  2088. end;
  2089. if not(c in ['0'..'9']) then
  2090. Illegal_Char(c);
  2091. while c in ['0'..'9'] do
  2092. begin
  2093. pattern:=pattern+c;
  2094. readchar;
  2095. end;
  2096. end;
  2097. token:=_REALNUMBER;
  2098. goto exit_label;
  2099. end;
  2100. token:=_INTCONST;
  2101. goto exit_label;
  2102. end;
  2103. ';' :
  2104. begin
  2105. readchar;
  2106. token:=_SEMICOLON;
  2107. goto exit_label;
  2108. end;
  2109. '[' :
  2110. begin
  2111. readchar;
  2112. token:=_LECKKLAMMER;
  2113. goto exit_label;
  2114. end;
  2115. ']' :
  2116. begin
  2117. readchar;
  2118. token:=_RECKKLAMMER;
  2119. goto exit_label;
  2120. end;
  2121. '(' :
  2122. begin
  2123. readchar;
  2124. case c of
  2125. '*' :
  2126. begin
  2127. c:=#0;{Signal skipoldtpcomment to reload a char }
  2128. skipoldtpcomment;
  2129. readtoken;
  2130. exit;
  2131. end;
  2132. '.' :
  2133. begin
  2134. readchar;
  2135. token:=_LECKKLAMMER;
  2136. goto exit_label;
  2137. end;
  2138. end;
  2139. token:=_LKLAMMER;
  2140. goto exit_label;
  2141. end;
  2142. ')' :
  2143. begin
  2144. readchar;
  2145. token:=_RKLAMMER;
  2146. goto exit_label;
  2147. end;
  2148. '+' :
  2149. begin
  2150. readchar;
  2151. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2152. begin
  2153. readchar;
  2154. token:=_PLUSASN;
  2155. goto exit_label;
  2156. end;
  2157. token:=_PLUS;
  2158. goto exit_label;
  2159. end;
  2160. '-' :
  2161. begin
  2162. readchar;
  2163. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2164. begin
  2165. readchar;
  2166. token:=_MINUSASN;
  2167. goto exit_label;
  2168. end;
  2169. token:=_MINUS;
  2170. goto exit_label;
  2171. end;
  2172. ':' :
  2173. begin
  2174. readchar;
  2175. if c='=' then
  2176. begin
  2177. readchar;
  2178. token:=_ASSIGNMENT;
  2179. goto exit_label;
  2180. end;
  2181. token:=_COLON;
  2182. goto exit_label;
  2183. end;
  2184. '*' :
  2185. begin
  2186. readchar;
  2187. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2188. begin
  2189. readchar;
  2190. token:=_STARASN;
  2191. end
  2192. else
  2193. if c='*' then
  2194. begin
  2195. readchar;
  2196. token:=_STARSTAR;
  2197. end
  2198. else
  2199. token:=_STAR;
  2200. goto exit_label;
  2201. end;
  2202. '/' :
  2203. begin
  2204. readchar;
  2205. case c of
  2206. '=' :
  2207. begin
  2208. if (cs_support_c_operators in aktmoduleswitches) then
  2209. begin
  2210. readchar;
  2211. token:=_SLASHASN;
  2212. goto exit_label;
  2213. end;
  2214. end;
  2215. '/' :
  2216. begin
  2217. skipdelphicomment;
  2218. readtoken;
  2219. exit;
  2220. end;
  2221. end;
  2222. token:=_SLASH;
  2223. goto exit_label;
  2224. end;
  2225. '=' :
  2226. begin
  2227. readchar;
  2228. token:=_EQUAL;
  2229. goto exit_label;
  2230. end;
  2231. '.' :
  2232. begin
  2233. readchar;
  2234. case c of
  2235. '.' :
  2236. begin
  2237. readchar;
  2238. token:=_POINTPOINT;
  2239. goto exit_label;
  2240. end;
  2241. ')' :
  2242. begin
  2243. readchar;
  2244. token:=_RECKKLAMMER;
  2245. goto exit_label;
  2246. end;
  2247. end;
  2248. token:=_POINT;
  2249. goto exit_label;
  2250. end;
  2251. '@' :
  2252. begin
  2253. readchar;
  2254. token:=_KLAMMERAFFE;
  2255. goto exit_label;
  2256. end;
  2257. ',' :
  2258. begin
  2259. readchar;
  2260. token:=_COMMA;
  2261. goto exit_label;
  2262. end;
  2263. '''','#','^' :
  2264. begin
  2265. len:=0;
  2266. msgwritten:=false;
  2267. pattern:='';
  2268. iswidestring:=false;
  2269. if c='^' then
  2270. begin
  2271. readchar;
  2272. c:=upcase(c);
  2273. if (block_type=bt_type) or
  2274. (lasttoken=_ID) or (lasttoken=_NIL) or
  2275. (lasttoken=_RKLAMMER) or (lasttoken=_RECKKLAMMER) or (lasttoken=_CARET) then
  2276. begin
  2277. token:=_CARET;
  2278. goto exit_label;
  2279. end
  2280. else
  2281. begin
  2282. inc(len);
  2283. if c<#64 then
  2284. pattern[len]:=chr(ord(c)+64)
  2285. else
  2286. pattern[len]:=chr(ord(c)-64);
  2287. readchar;
  2288. end;
  2289. end;
  2290. repeat
  2291. case c of
  2292. '#' :
  2293. begin
  2294. readchar; { read # }
  2295. if c='$' then
  2296. begin
  2297. readchar; { read leading $ }
  2298. asciinr:='$';
  2299. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<6) do
  2300. begin
  2301. asciinr:=asciinr+c;
  2302. readchar;
  2303. end;
  2304. end
  2305. else
  2306. begin
  2307. asciinr:='';
  2308. while (c in ['0'..'9']) and (length(asciinr)<6) do
  2309. begin
  2310. asciinr:=asciinr+c;
  2311. readchar;
  2312. end;
  2313. end;
  2314. valint(asciinr,m,code);
  2315. if (asciinr='') or (code<>0) then
  2316. Message(scan_e_illegal_char_const)
  2317. else if (m<0) or (m>255) or (length(asciinr)>3) then
  2318. begin
  2319. if (m>=0) and (m<=65535) then
  2320. begin
  2321. if not iswidestring then
  2322. begin
  2323. ascii2unicode(@pattern[1],len,patternw);
  2324. iswidestring:=true;
  2325. len:=0;
  2326. end;
  2327. concatwidestringchar(patternw,tcompilerwidechar(m));
  2328. end
  2329. else
  2330. Message(scan_e_illegal_char_const)
  2331. end
  2332. else if iswidestring then
  2333. concatwidestringchar(patternw,asciichar2unicode(char(m)))
  2334. else
  2335. begin
  2336. if len<255 then
  2337. begin
  2338. inc(len);
  2339. pattern[len]:=chr(m);
  2340. end
  2341. else
  2342. begin
  2343. if not msgwritten then
  2344. begin
  2345. Message(scan_e_string_exceeds_255_chars);
  2346. msgwritten:=true;
  2347. end;
  2348. end;
  2349. end;
  2350. end;
  2351. '''' :
  2352. begin
  2353. repeat
  2354. readchar;
  2355. case c of
  2356. #26 :
  2357. end_of_file;
  2358. #10,#13 :
  2359. Message(scan_f_string_exceeds_line);
  2360. '''' :
  2361. begin
  2362. readchar;
  2363. if c<>'''' then
  2364. break;
  2365. end;
  2366. end;
  2367. if iswidestring then
  2368. concatwidestringchar(patternw,asciichar2unicode(c))
  2369. else
  2370. begin
  2371. if len<255 then
  2372. begin
  2373. inc(len);
  2374. pattern[len]:=c;
  2375. end
  2376. else
  2377. begin
  2378. if not msgwritten then
  2379. begin
  2380. Message(scan_e_string_exceeds_255_chars);
  2381. msgwritten:=true;
  2382. end;
  2383. end;
  2384. end;
  2385. until false;
  2386. end;
  2387. '^' :
  2388. begin
  2389. readchar;
  2390. c:=upcase(c);
  2391. if c<#64 then
  2392. c:=chr(ord(c)+64)
  2393. else
  2394. c:=chr(ord(c)-64);
  2395. if iswidestring then
  2396. concatwidestringchar(patternw,asciichar2unicode(c))
  2397. else
  2398. begin
  2399. if len<255 then
  2400. begin
  2401. inc(len);
  2402. pattern[len]:=c;
  2403. end
  2404. else
  2405. begin
  2406. if not msgwritten then
  2407. begin
  2408. Message(scan_e_string_exceeds_255_chars);
  2409. msgwritten:=true;
  2410. end;
  2411. end;
  2412. end;
  2413. readchar;
  2414. end;
  2415. else
  2416. break;
  2417. end;
  2418. until false;
  2419. { strings with length 1 become const chars }
  2420. if iswidestring then
  2421. begin
  2422. if patternw^.len=1 then
  2423. token:=_CWCHAR
  2424. else
  2425. token:=_CWSTRING;
  2426. end
  2427. else
  2428. begin
  2429. pattern[0]:=chr(len);
  2430. if len=1 then
  2431. token:=_CCHAR
  2432. else
  2433. token:=_CSTRING;
  2434. end;
  2435. goto exit_label;
  2436. end;
  2437. '>' :
  2438. begin
  2439. readchar;
  2440. case c of
  2441. '=' :
  2442. begin
  2443. readchar;
  2444. token:=_GTE;
  2445. goto exit_label;
  2446. end;
  2447. '>' :
  2448. begin
  2449. readchar;
  2450. token:=_OP_SHR;
  2451. goto exit_label;
  2452. end;
  2453. '<' :
  2454. begin { >< is for a symetric diff for sets }
  2455. readchar;
  2456. token:=_SYMDIF;
  2457. goto exit_label;
  2458. end;
  2459. end;
  2460. token:=_GT;
  2461. goto exit_label;
  2462. end;
  2463. '<' :
  2464. begin
  2465. readchar;
  2466. case c of
  2467. '>' :
  2468. begin
  2469. readchar;
  2470. token:=_UNEQUAL;
  2471. goto exit_label;
  2472. end;
  2473. '=' :
  2474. begin
  2475. readchar;
  2476. token:=_LTE;
  2477. goto exit_label;
  2478. end;
  2479. '<' :
  2480. begin
  2481. readchar;
  2482. token:=_OP_SHL;
  2483. goto exit_label;
  2484. end;
  2485. end;
  2486. token:=_LT;
  2487. goto exit_label;
  2488. end;
  2489. #26 :
  2490. begin
  2491. token:=_EOF;
  2492. checkpreprocstack;
  2493. goto exit_label;
  2494. end;
  2495. else
  2496. Illegal_Char(c);
  2497. end;
  2498. end;
  2499. exit_label:
  2500. lasttoken:=token;
  2501. end;
  2502. function tscannerfile.readpreproc:ttoken;
  2503. begin
  2504. skipspace;
  2505. case c of
  2506. 'A'..'Z',
  2507. 'a'..'z',
  2508. '_','0'..'9' : begin
  2509. current_scanner.preproc_pattern:=readid;
  2510. readpreproc:=_ID;
  2511. end;
  2512. '}' : begin
  2513. readpreproc:=_END;
  2514. end;
  2515. '(' : begin
  2516. readchar;
  2517. readpreproc:=_LKLAMMER;
  2518. end;
  2519. ')' : begin
  2520. readchar;
  2521. readpreproc:=_RKLAMMER;
  2522. end;
  2523. '+' : begin
  2524. readchar;
  2525. readpreproc:=_PLUS;
  2526. end;
  2527. '-' : begin
  2528. readchar;
  2529. readpreproc:=_MINUS;
  2530. end;
  2531. '*' : begin
  2532. readchar;
  2533. readpreproc:=_STAR;
  2534. end;
  2535. '/' : begin
  2536. readchar;
  2537. readpreproc:=_SLASH;
  2538. end;
  2539. '=' : begin
  2540. readchar;
  2541. readpreproc:=_EQUAL;
  2542. end;
  2543. '>' : begin
  2544. readchar;
  2545. if c='=' then
  2546. begin
  2547. readchar;
  2548. readpreproc:=_GTE;
  2549. end
  2550. else
  2551. readpreproc:=_GT;
  2552. end;
  2553. '<' : begin
  2554. readchar;
  2555. case c of
  2556. '>' : begin
  2557. readchar;
  2558. readpreproc:=_UNEQUAL;
  2559. end;
  2560. '=' : begin
  2561. readchar;
  2562. readpreproc:=_LTE;
  2563. end;
  2564. else readpreproc:=_LT;
  2565. end;
  2566. end;
  2567. #26 :
  2568. end_of_file;
  2569. else
  2570. begin
  2571. readpreproc:=_EOF;
  2572. checkpreprocstack;
  2573. end;
  2574. end;
  2575. end;
  2576. function tscannerfile.asmgetcharstart : char;
  2577. begin
  2578. { return first the character already
  2579. available in c }
  2580. lastasmgetchar:=c;
  2581. result:=asmgetchar;
  2582. end;
  2583. function tscannerfile.asmgetchar : char;
  2584. begin
  2585. if lastasmgetchar<>#0 then
  2586. begin
  2587. c:=lastasmgetchar;
  2588. lastasmgetchar:=#0;
  2589. end
  2590. else
  2591. readchar;
  2592. if in_asm_string then
  2593. begin
  2594. asmgetchar:=c;
  2595. exit;
  2596. end;
  2597. repeat
  2598. case c of
  2599. {$ifndef arm}
  2600. // the { ... } is used in ARM assembler to define register sets, so we can't used
  2601. // it as comment, either (* ... *), /* ... */ or // ... should be used instead
  2602. '{' :
  2603. skipcomment;
  2604. {$endif arm}
  2605. #10,#13 :
  2606. begin
  2607. linebreak;
  2608. asmgetchar:=c;
  2609. exit;
  2610. end;
  2611. #26 :
  2612. begin
  2613. reload;
  2614. if (c=#26) and not assigned(inputfile.next) then
  2615. end_of_file;
  2616. continue;
  2617. end;
  2618. '/' :
  2619. begin
  2620. readchar;
  2621. if c='/' then
  2622. skipdelphicomment
  2623. else
  2624. begin
  2625. asmgetchar:='/';
  2626. lastasmgetchar:=c;
  2627. exit;
  2628. end;
  2629. end;
  2630. '(' :
  2631. begin
  2632. readchar;
  2633. if c='*' then
  2634. begin
  2635. c:=#0;{Signal skipoldtpcomment to reload a char }
  2636. skipoldtpcomment;
  2637. end
  2638. else
  2639. begin
  2640. asmgetchar:='(';
  2641. lastasmgetchar:=c;
  2642. exit;
  2643. end;
  2644. end;
  2645. else
  2646. begin
  2647. asmgetchar:=c;
  2648. exit;
  2649. end;
  2650. end;
  2651. until false;
  2652. end;
  2653. {*****************************************************************************
  2654. Helpers
  2655. *****************************************************************************}
  2656. procedure AddDirective(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  2657. begin
  2658. if dm in [directive_all, directive_turbo] then
  2659. turbo_scannerdirectives.insert(tdirectiveitem.create(s,p));
  2660. if dm in [directive_all, directive_mac] then
  2661. mac_scannerdirectives.insert(tdirectiveitem.create(s,p));
  2662. end;
  2663. procedure AddConditional(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  2664. begin
  2665. if dm in [directive_all, directive_turbo] then
  2666. turbo_scannerdirectives.insert(tdirectiveitem.createcond(s,p));
  2667. if dm in [directive_all, directive_mac] then
  2668. mac_scannerdirectives.insert(tdirectiveitem.createcond(s,p));
  2669. end;
  2670. {*****************************************************************************
  2671. Initialization
  2672. *****************************************************************************}
  2673. procedure InitScanner;
  2674. begin
  2675. InitWideString(patternw);
  2676. turbo_scannerdirectives:=TDictionary.Create;
  2677. mac_scannerdirectives:=TDictionary.Create;
  2678. { Default Turbo directives and conditionals }
  2679. AddDirective('DEFINE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_define);
  2680. AddDirective('UNDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_undef);
  2681. AddDirective('I',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_include);
  2682. AddDirective('INCLUDE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_include);
  2683. AddConditional('ELSE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_else);
  2684. AddConditional('ENDIF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2685. AddConditional('IFEND',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2686. AddConditional('IF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_if);
  2687. AddConditional('IFDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifdef);
  2688. AddConditional('IFNDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifndef);
  2689. AddConditional('IFOPT',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifopt);
  2690. { Default Mac directives and conditionals: }
  2691. AddDirective('SETC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_setc);
  2692. AddConditional('IFC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_if);
  2693. AddConditional('ELSEC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_else);
  2694. AddConditional('ENDC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2695. end;
  2696. procedure DoneScanner;
  2697. begin
  2698. turbo_scannerdirectives.Free;
  2699. mac_scannerdirectives.Free;
  2700. DoneWideString(patternw);
  2701. end;
  2702. end.
  2703. {
  2704. $Log$
  2705. Revision 1.66 2003-11-12 16:57:59 peter
  2706. * do nothing for macro's in tempcloseinput,tempopeninput
  2707. Revision 1.65 2003/11/10 19:08:59 peter
  2708. + $IF DECLARED() added
  2709. Revision 1.64 2003/11/10 19:08:32 peter
  2710. * line numbering is now only done when #10, #10#13 is really parsed
  2711. instead of when it is the next character
  2712. Revision 1.63 2003/10/29 21:02:51 peter
  2713. * set ms_compiled after the program/unit is parsed
  2714. * check for ms_compiled before checking preproc matches
  2715. Revision 1.62 2003/09/17 22:30:19 olle
  2716. + support for a different set of compiler directives under $MODE MAC
  2717. + added mac directives $SETC $IFC $ELSEC $ENDC
  2718. Revision 1.61 2003/09/03 11:18:37 florian
  2719. * fixed arm concatcopy
  2720. + arm support in the common compiler sources added
  2721. * moved some generic cg code around
  2722. + tfputype added
  2723. * ...
  2724. Revision 1.60 2003/08/10 17:25:23 peter
  2725. * fixed some reported bugs
  2726. Revision 1.59 2003/05/25 10:26:43 peter
  2727. * recursive include depth check
  2728. Revision 1.58 2003/04/26 00:30:27 peter
  2729. * don't close inputfile when still closed
  2730. Revision 1.57 2003/01/09 21:52:37 peter
  2731. * merged some verbosity options.
  2732. * V_LineInfo is a verbosity flag to include line info
  2733. Revision 1.56 2002/12/29 14:57:50 peter
  2734. * unit loading changed to first register units and load them
  2735. afterwards. This is needed to support uses xxx in yyy correctly
  2736. * unit dependency check fixed
  2737. Revision 1.55 2002/12/27 18:05:58 peter
  2738. * use gettoken to get filename for include
  2739. Revision 1.54 2002/12/27 16:45:50 peter
  2740. * fix delphi comment parsing when skipping preproc directive
  2741. Revision 1.53 2002/12/27 15:26:43 peter
  2742. * give an error when no symbol is specified after $if(n)def
  2743. Revision 1.52 2002/12/24 23:32:02 peter
  2744. * support quotes around include filenames
  2745. Revision 1.51 2002/12/05 19:27:00 carl
  2746. * remove a stupid thing that i commited
  2747. Revision 1.50 2002/11/29 22:31:19 carl
  2748. + unimplemented hint directive added
  2749. * hint directive parsing implemented
  2750. * warning on these directives
  2751. Revision 1.49 2002/11/26 22:56:40 peter
  2752. * fix macro nesting check
  2753. Revision 1.48 2002/09/16 19:05:48 peter
  2754. * parse ^ after nil as caret
  2755. Revision 1.47 2002/09/06 14:58:42 carl
  2756. * bugfix of bug report 2072 (merged)
  2757. Revision 1.46 2002/09/05 19:27:05 peter
  2758. * fixed crash when current_module becomes nil
  2759. Revision 1.45 2002/09/05 14:17:27 pierre
  2760. * fix for bug 2004 merged
  2761. Revision 1.44 2002/08/12 16:46:04 peter
  2762. * tscannerfile is now destroyed in tmodule.reset and current_scanner
  2763. is updated accordingly. This removes all the loading and saving of
  2764. the old scanner and the invalid flag marking
  2765. Revision 1.43 2002/08/11 14:28:19 peter
  2766. * TScannerFile.SetInvalid added that will also reset inputfile
  2767. Revision 1.42 2002/08/10 14:46:31 carl
  2768. + moved target_cpu_string to cpuinfo
  2769. * renamed asmmode enum.
  2770. * assembler reader has now less ifdef's
  2771. * move from nppcmem.pas -> ncgmem.pas vec. node.
  2772. Revision 1.41 2002/08/06 21:12:16 florian
  2773. + support for octal constants, they are specified by a leading &
  2774. Revision 1.40 2002/07/20 17:35:52 florian
  2775. + char constants specified with #.. with more than 3 digits are handled as widechar
  2776. Revision 1.39 2002/05/18 13:34:17 peter
  2777. * readded missing revisions
  2778. Revision 1.38 2002/05/16 19:46:44 carl
  2779. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2780. + try to fix temp allocation (still in ifdef)
  2781. + generic constructor calls
  2782. + start of tassembler / tmodulebase class cleanup
  2783. Revision 1.36 2002/04/21 18:57:23 peter
  2784. * fixed memleaks when file can't be opened
  2785. Revision 1.35 2002/04/21 15:22:26 carl
  2786. * first check .inc file extension
  2787. Revision 1.34 2002/04/21 07:24:09 carl
  2788. - remove my fixes until Peter agrees on the fix (sorry Peter)
  2789. Revision 1.32 2002/04/19 15:42:11 peter
  2790. * default extension checking for include files
  2791. Revision 1.31 2002/03/01 14:39:44 peter
  2792. * fixed // and (* parsing to not be done when already parsing a
  2793. tp comment in skipuntildirective
  2794. Revision 1.30 2002/03/01 12:39:26 peter
  2795. * support // parsing in skipuntildirective
  2796. Revision 1.29 2002/01/27 21:44:26 peter
  2797. * FPCTARGETOS/FPCTARGETCPU added as internal environment variable
  2798. Revision 1.28 2002/01/24 18:25:50 peter
  2799. * implicit result variable generation for assembler routines
  2800. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2801. }