scanner.pas 92 KB

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