scanner.pas 97 KB

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