scanner.pas 96 KB

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