scanner.pas 95 KB

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