scanner.pas 91 KB

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