scanner.pas 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141
  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. found : longint;
  1685. next_char_loaded : boolean;
  1686. begin
  1687. found:=0;
  1688. next_char_loaded:=false;
  1689. repeat
  1690. case c of
  1691. #10,
  1692. #13 :
  1693. linebreak;
  1694. #26 :
  1695. begin
  1696. reload;
  1697. if (c=#26) and not assigned(inputfile.next) then
  1698. end_of_file;
  1699. continue;
  1700. end;
  1701. '{' :
  1702. begin
  1703. if (aktcommentstyle in [comment_tp,comment_none]) then
  1704. begin
  1705. aktcommentstyle:=comment_tp;
  1706. if (comment_level=0) then
  1707. found:=1;
  1708. inc_comment_level;
  1709. end;
  1710. end;
  1711. '*' :
  1712. begin
  1713. if (aktcommentstyle=comment_oldtp) then
  1714. begin
  1715. readchar;
  1716. if c=')' then
  1717. begin
  1718. dec_comment_level;
  1719. found:=0;
  1720. aktcommentstyle:=comment_none;
  1721. end
  1722. else
  1723. next_char_loaded:=true;
  1724. end
  1725. else
  1726. found := 0;
  1727. end;
  1728. '}' :
  1729. begin
  1730. if (aktcommentstyle=comment_tp) then
  1731. begin
  1732. dec_comment_level;
  1733. if (comment_level=0) then
  1734. aktcommentstyle:=comment_none;
  1735. found:=0;
  1736. end;
  1737. end;
  1738. '$' :
  1739. begin
  1740. if found=1 then
  1741. found:=2;
  1742. end;
  1743. '''' :
  1744. if (aktcommentstyle=comment_none) then
  1745. begin
  1746. repeat
  1747. readchar;
  1748. case c of
  1749. #26 :
  1750. end_of_file;
  1751. #10,#13 :
  1752. break;
  1753. '''' :
  1754. begin
  1755. readchar;
  1756. if c<>'''' then
  1757. begin
  1758. next_char_loaded:=true;
  1759. break;
  1760. end;
  1761. end;
  1762. end;
  1763. until false;
  1764. end;
  1765. '(' :
  1766. begin
  1767. if (aktcommentstyle=comment_none) then
  1768. begin
  1769. readchar;
  1770. if c='*' then
  1771. begin
  1772. readchar;
  1773. if c='$' then
  1774. begin
  1775. found:=2;
  1776. inc_comment_level;
  1777. aktcommentstyle:=comment_oldtp;
  1778. end
  1779. else
  1780. begin
  1781. skipoldtpcomment;
  1782. next_char_loaded:=true;
  1783. end;
  1784. end
  1785. else
  1786. next_char_loaded:=true;
  1787. end
  1788. else
  1789. found:=0;
  1790. end;
  1791. '/' :
  1792. begin
  1793. if (aktcommentstyle=comment_none) then
  1794. begin
  1795. readchar;
  1796. if c='/' then
  1797. skipdelphicomment;
  1798. next_char_loaded:=true;
  1799. end
  1800. else
  1801. found:=0;
  1802. end;
  1803. else
  1804. found:=0;
  1805. end;
  1806. if next_char_loaded then
  1807. next_char_loaded:=false
  1808. else
  1809. readchar;
  1810. until (found=2);
  1811. end;
  1812. {****************************************************************************
  1813. Comment Handling
  1814. ****************************************************************************}
  1815. procedure tscannerfile.skipcomment;
  1816. begin
  1817. aktcommentstyle:=comment_tp;
  1818. readchar;
  1819. inc_comment_level;
  1820. { handle compiler switches }
  1821. if (c='$') then
  1822. handledirectives;
  1823. { handle_switches can dec comment_level, }
  1824. while (comment_level>0) do
  1825. begin
  1826. case c of
  1827. '{' :
  1828. inc_comment_level;
  1829. '}' :
  1830. dec_comment_level;
  1831. #10,#13 :
  1832. linebreak;
  1833. #26 :
  1834. begin
  1835. reload;
  1836. if (c=#26) and not assigned(inputfile.next) then
  1837. end_of_file;
  1838. continue;
  1839. end;
  1840. end;
  1841. readchar;
  1842. end;
  1843. aktcommentstyle:=comment_none;
  1844. end;
  1845. procedure tscannerfile.skipdelphicomment;
  1846. begin
  1847. aktcommentstyle:=comment_delphi;
  1848. inc_comment_level;
  1849. readchar;
  1850. { this is not supported }
  1851. if c='$' then
  1852. Message(scan_e_wrong_styled_switch);
  1853. { skip comment }
  1854. while not (c in [#10,#13,#26]) do
  1855. readchar;
  1856. dec_comment_level;
  1857. aktcommentstyle:=comment_none;
  1858. end;
  1859. procedure tscannerfile.skipoldtpcomment;
  1860. var
  1861. found : longint;
  1862. begin
  1863. aktcommentstyle:=comment_oldtp;
  1864. inc_comment_level;
  1865. { only load a char if last already processed,
  1866. was cause of bug1634 PM }
  1867. if c=#0 then
  1868. readchar;
  1869. { this is now supported }
  1870. if (c='$') then
  1871. handledirectives;
  1872. { skip comment }
  1873. while (comment_level>0) do
  1874. begin
  1875. found:=0;
  1876. repeat
  1877. case c of
  1878. #26 :
  1879. begin
  1880. reload;
  1881. if (c=#26) and not assigned(inputfile.next) then
  1882. end_of_file;
  1883. continue;
  1884. end;
  1885. #10,#13 :
  1886. linebreak;
  1887. '*' :
  1888. begin
  1889. if found=3 then
  1890. found:=4
  1891. else
  1892. found:=1;
  1893. end;
  1894. ')' :
  1895. begin
  1896. if found in [1,4] then
  1897. begin
  1898. dec_comment_level;
  1899. if comment_level=0 then
  1900. found:=2
  1901. else
  1902. found:=0;
  1903. end;
  1904. end;
  1905. '(' :
  1906. begin
  1907. if found=4 then
  1908. inc_comment_level;
  1909. found:=3;
  1910. end;
  1911. else
  1912. begin
  1913. if found=4 then
  1914. inc_comment_level;
  1915. found:=0;
  1916. end;
  1917. end;
  1918. readchar;
  1919. until (found=2);
  1920. end;
  1921. aktcommentstyle:=comment_none;
  1922. end;
  1923. {****************************************************************************
  1924. Token Scanner
  1925. ****************************************************************************}
  1926. procedure tscannerfile.readtoken;
  1927. var
  1928. code : integer;
  1929. len,
  1930. low,high,mid : longint;
  1931. m : longint;
  1932. mac : tmacro;
  1933. asciinr : string[6];
  1934. msgwritten,
  1935. iswidestring : boolean;
  1936. label
  1937. exit_label;
  1938. begin
  1939. if localswitcheschanged then
  1940. begin
  1941. aktlocalswitches:=nextaktlocalswitches;
  1942. localswitcheschanged:=false;
  1943. end;
  1944. { was there already a token read, then return that token }
  1945. if nexttoken<>NOTOKEN then
  1946. begin
  1947. token:=nexttoken;
  1948. nexttoken:=NOTOKEN;
  1949. goto exit_label;
  1950. end;
  1951. { Skip all spaces and comments }
  1952. repeat
  1953. case c of
  1954. '{' :
  1955. skipcomment;
  1956. #26 :
  1957. begin
  1958. reload;
  1959. if (c=#26) and not assigned(inputfile.next) then
  1960. break;
  1961. end;
  1962. ' ',#9..#13 :
  1963. begin
  1964. {$ifdef PREPROCWRITE}
  1965. if parapreprocess then
  1966. begin
  1967. if c=#10 then
  1968. preprocfile.eolfound:=true
  1969. else
  1970. preprocfile.spacefound:=true;
  1971. end;
  1972. {$endif PREPROCWRITE}
  1973. skipspace;
  1974. end
  1975. else
  1976. break;
  1977. end;
  1978. until false;
  1979. { Save current token position, for EOF its already loaded }
  1980. if c<>#26 then
  1981. gettokenpos;
  1982. { Check first for a identifier/keyword, this is 20+% faster (PFV) }
  1983. if c in ['A'..'Z','a'..'z','_'] then
  1984. begin
  1985. readstring;
  1986. token:=_ID;
  1987. idtoken:=_ID;
  1988. { keyword or any other known token,
  1989. pattern is always uppercased }
  1990. if (pattern[1]<>'_') and (length(pattern) in [tokenlenmin..tokenlenmax]) then
  1991. begin
  1992. low:=ord(tokenidx^[length(pattern),pattern[1]].first);
  1993. high:=ord(tokenidx^[length(pattern),pattern[1]].last);
  1994. while low<high do
  1995. begin
  1996. mid:=(high+low+1) shr 1;
  1997. if pattern<tokeninfo^[ttoken(mid)].str then
  1998. high:=mid-1
  1999. else
  2000. low:=mid;
  2001. end;
  2002. with tokeninfo^[ttoken(high)] do
  2003. if pattern=str then
  2004. begin
  2005. if keyword in aktmodeswitches then
  2006. if op=NOTOKEN then
  2007. token:=ttoken(high)
  2008. else
  2009. token:=op;
  2010. idtoken:=ttoken(high);
  2011. end;
  2012. end;
  2013. { Only process identifiers and not keywords }
  2014. if token=_ID then
  2015. begin
  2016. { this takes some time ... }
  2017. if (cs_support_macro in aktmoduleswitches) then
  2018. begin
  2019. mac:=tmacro(macros.search(pattern));
  2020. if assigned(mac) and (assigned(mac.buftext)) then
  2021. begin
  2022. if yylexcount<max_macro_nesting then
  2023. begin
  2024. inc(yylexcount);
  2025. insertmacro(pattern,mac.buftext,mac.buflen,
  2026. mac.fileinfo.line,mac.fileinfo.fileindex);
  2027. { handle empty macros }
  2028. if c=#0 then
  2029. reload;
  2030. readtoken;
  2031. { that's all folks }
  2032. dec(yylexcount);
  2033. exit;
  2034. end
  2035. else
  2036. Message(scan_w_macro_deep_ten);
  2037. end;
  2038. end;
  2039. end;
  2040. { return token }
  2041. goto exit_label;
  2042. end
  2043. else
  2044. begin
  2045. idtoken:=_NOID;
  2046. case c of
  2047. '$' :
  2048. begin
  2049. readnumber;
  2050. token:=_INTCONST;
  2051. goto exit_label;
  2052. end;
  2053. '%' :
  2054. begin
  2055. if not(m_fpc in aktmodeswitches) then
  2056. Illegal_Char(c)
  2057. else
  2058. begin
  2059. readnumber;
  2060. token:=_INTCONST;
  2061. goto exit_label;
  2062. end;
  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. '0'..'9' :
  2076. begin
  2077. readnumber;
  2078. if (c in ['.','e','E']) then
  2079. begin
  2080. { first check for a . }
  2081. if c='.' then
  2082. begin
  2083. readchar;
  2084. { is it a .. from a range? }
  2085. case c of
  2086. '.' :
  2087. begin
  2088. readchar;
  2089. token:=_INTCONST;
  2090. nexttoken:=_POINTPOINT;
  2091. goto exit_label;
  2092. end;
  2093. ')' :
  2094. begin
  2095. readchar;
  2096. token:=_INTCONST;
  2097. nexttoken:=_RECKKLAMMER;
  2098. goto exit_label;
  2099. end;
  2100. end;
  2101. { insert the number after the . }
  2102. pattern:=pattern+'.';
  2103. while c in ['0'..'9'] do
  2104. begin
  2105. pattern:=pattern+c;
  2106. readchar;
  2107. end;
  2108. end;
  2109. { E can also follow after a point is scanned }
  2110. if c in ['e','E'] then
  2111. begin
  2112. pattern:=pattern+'E';
  2113. readchar;
  2114. if c in ['-','+'] then
  2115. begin
  2116. pattern:=pattern+c;
  2117. readchar;
  2118. end;
  2119. if not(c in ['0'..'9']) then
  2120. Illegal_Char(c);
  2121. while c in ['0'..'9'] do
  2122. begin
  2123. pattern:=pattern+c;
  2124. readchar;
  2125. end;
  2126. end;
  2127. token:=_REALNUMBER;
  2128. goto exit_label;
  2129. end;
  2130. token:=_INTCONST;
  2131. goto exit_label;
  2132. end;
  2133. ';' :
  2134. begin
  2135. readchar;
  2136. token:=_SEMICOLON;
  2137. goto exit_label;
  2138. end;
  2139. '[' :
  2140. begin
  2141. readchar;
  2142. token:=_LECKKLAMMER;
  2143. goto exit_label;
  2144. end;
  2145. ']' :
  2146. begin
  2147. readchar;
  2148. token:=_RECKKLAMMER;
  2149. goto exit_label;
  2150. end;
  2151. '(' :
  2152. begin
  2153. readchar;
  2154. case c of
  2155. '*' :
  2156. begin
  2157. c:=#0;{Signal skipoldtpcomment to reload a char }
  2158. skipoldtpcomment;
  2159. readtoken;
  2160. exit;
  2161. end;
  2162. '.' :
  2163. begin
  2164. readchar;
  2165. token:=_LECKKLAMMER;
  2166. goto exit_label;
  2167. end;
  2168. end;
  2169. token:=_LKLAMMER;
  2170. goto exit_label;
  2171. end;
  2172. ')' :
  2173. begin
  2174. readchar;
  2175. token:=_RKLAMMER;
  2176. goto exit_label;
  2177. end;
  2178. '+' :
  2179. begin
  2180. readchar;
  2181. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2182. begin
  2183. readchar;
  2184. token:=_PLUSASN;
  2185. goto exit_label;
  2186. end;
  2187. token:=_PLUS;
  2188. goto exit_label;
  2189. end;
  2190. '-' :
  2191. begin
  2192. readchar;
  2193. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2194. begin
  2195. readchar;
  2196. token:=_MINUSASN;
  2197. goto exit_label;
  2198. end;
  2199. token:=_MINUS;
  2200. goto exit_label;
  2201. end;
  2202. ':' :
  2203. begin
  2204. readchar;
  2205. if c='=' then
  2206. begin
  2207. readchar;
  2208. token:=_ASSIGNMENT;
  2209. goto exit_label;
  2210. end;
  2211. token:=_COLON;
  2212. goto exit_label;
  2213. end;
  2214. '*' :
  2215. begin
  2216. readchar;
  2217. if (c='=') and (cs_support_c_operators in aktmoduleswitches) then
  2218. begin
  2219. readchar;
  2220. token:=_STARASN;
  2221. end
  2222. else
  2223. if c='*' then
  2224. begin
  2225. readchar;
  2226. token:=_STARSTAR;
  2227. end
  2228. else
  2229. token:=_STAR;
  2230. goto exit_label;
  2231. end;
  2232. '/' :
  2233. begin
  2234. readchar;
  2235. case c of
  2236. '=' :
  2237. begin
  2238. if (cs_support_c_operators in aktmoduleswitches) then
  2239. begin
  2240. readchar;
  2241. token:=_SLASHASN;
  2242. goto exit_label;
  2243. end;
  2244. end;
  2245. '/' :
  2246. begin
  2247. skipdelphicomment;
  2248. readtoken;
  2249. exit;
  2250. end;
  2251. end;
  2252. token:=_SLASH;
  2253. goto exit_label;
  2254. end;
  2255. '=' :
  2256. begin
  2257. readchar;
  2258. token:=_EQUAL;
  2259. goto exit_label;
  2260. end;
  2261. '.' :
  2262. begin
  2263. readchar;
  2264. case c of
  2265. '.' :
  2266. begin
  2267. readchar;
  2268. token:=_POINTPOINT;
  2269. goto exit_label;
  2270. end;
  2271. ')' :
  2272. begin
  2273. readchar;
  2274. token:=_RECKKLAMMER;
  2275. goto exit_label;
  2276. end;
  2277. end;
  2278. token:=_POINT;
  2279. goto exit_label;
  2280. end;
  2281. '@' :
  2282. begin
  2283. readchar;
  2284. token:=_KLAMMERAFFE;
  2285. goto exit_label;
  2286. end;
  2287. ',' :
  2288. begin
  2289. readchar;
  2290. token:=_COMMA;
  2291. goto exit_label;
  2292. end;
  2293. '''','#','^' :
  2294. begin
  2295. len:=0;
  2296. msgwritten:=false;
  2297. pattern:='';
  2298. iswidestring:=false;
  2299. if c='^' then
  2300. begin
  2301. readchar;
  2302. c:=upcase(c);
  2303. if (block_type=bt_type) or
  2304. (lasttoken=_ID) or (lasttoken=_NIL) or
  2305. (lasttoken=_RKLAMMER) or (lasttoken=_RECKKLAMMER) or (lasttoken=_CARET) then
  2306. begin
  2307. token:=_CARET;
  2308. goto exit_label;
  2309. end
  2310. else
  2311. begin
  2312. inc(len);
  2313. if c<#64 then
  2314. pattern[len]:=chr(ord(c)+64)
  2315. else
  2316. pattern[len]:=chr(ord(c)-64);
  2317. readchar;
  2318. end;
  2319. end;
  2320. repeat
  2321. case c of
  2322. '#' :
  2323. begin
  2324. readchar; { read # }
  2325. if c='$' then
  2326. begin
  2327. readchar; { read leading $ }
  2328. asciinr:='$';
  2329. while (upcase(c) in ['A'..'F','0'..'9']) and (length(asciinr)<6) do
  2330. begin
  2331. asciinr:=asciinr+c;
  2332. readchar;
  2333. end;
  2334. end
  2335. else
  2336. begin
  2337. asciinr:='';
  2338. while (c in ['0'..'9']) and (length(asciinr)<6) do
  2339. begin
  2340. asciinr:=asciinr+c;
  2341. readchar;
  2342. end;
  2343. end;
  2344. valint(asciinr,m,code);
  2345. if (asciinr='') or (code<>0) then
  2346. Message(scan_e_illegal_char_const)
  2347. else if (m<0) or (m>255) or (length(asciinr)>3) then
  2348. begin
  2349. if (m>=0) and (m<=65535) then
  2350. begin
  2351. if not iswidestring then
  2352. begin
  2353. ascii2unicode(@pattern[1],len,patternw);
  2354. iswidestring:=true;
  2355. len:=0;
  2356. end;
  2357. concatwidestringchar(patternw,tcompilerwidechar(m));
  2358. end
  2359. else
  2360. Message(scan_e_illegal_char_const)
  2361. end
  2362. else if iswidestring then
  2363. concatwidestringchar(patternw,asciichar2unicode(char(m)))
  2364. else
  2365. begin
  2366. if len<255 then
  2367. begin
  2368. inc(len);
  2369. pattern[len]:=chr(m);
  2370. end
  2371. else
  2372. begin
  2373. if not msgwritten then
  2374. begin
  2375. Message(scan_e_string_exceeds_255_chars);
  2376. msgwritten:=true;
  2377. end;
  2378. end;
  2379. end;
  2380. end;
  2381. '''' :
  2382. begin
  2383. repeat
  2384. readchar;
  2385. case c of
  2386. #26 :
  2387. end_of_file;
  2388. #10,#13 :
  2389. Message(scan_f_string_exceeds_line);
  2390. '''' :
  2391. begin
  2392. readchar;
  2393. if c<>'''' then
  2394. break;
  2395. end;
  2396. end;
  2397. if iswidestring then
  2398. concatwidestringchar(patternw,asciichar2unicode(c))
  2399. else
  2400. begin
  2401. if len<255 then
  2402. begin
  2403. inc(len);
  2404. pattern[len]:=c;
  2405. end
  2406. else
  2407. begin
  2408. if not msgwritten then
  2409. begin
  2410. Message(scan_e_string_exceeds_255_chars);
  2411. msgwritten:=true;
  2412. end;
  2413. end;
  2414. end;
  2415. until false;
  2416. end;
  2417. '^' :
  2418. begin
  2419. readchar;
  2420. c:=upcase(c);
  2421. if c<#64 then
  2422. c:=chr(ord(c)+64)
  2423. else
  2424. c:=chr(ord(c)-64);
  2425. if iswidestring then
  2426. concatwidestringchar(patternw,asciichar2unicode(c))
  2427. else
  2428. begin
  2429. if len<255 then
  2430. begin
  2431. inc(len);
  2432. pattern[len]:=c;
  2433. end
  2434. else
  2435. begin
  2436. if not msgwritten then
  2437. begin
  2438. Message(scan_e_string_exceeds_255_chars);
  2439. msgwritten:=true;
  2440. end;
  2441. end;
  2442. end;
  2443. readchar;
  2444. end;
  2445. else
  2446. break;
  2447. end;
  2448. until false;
  2449. { strings with length 1 become const chars }
  2450. if iswidestring then
  2451. begin
  2452. if patternw^.len=1 then
  2453. token:=_CWCHAR
  2454. else
  2455. token:=_CWSTRING;
  2456. end
  2457. else
  2458. begin
  2459. pattern[0]:=chr(len);
  2460. if len=1 then
  2461. token:=_CCHAR
  2462. else
  2463. token:=_CSTRING;
  2464. end;
  2465. goto exit_label;
  2466. end;
  2467. '>' :
  2468. begin
  2469. readchar;
  2470. case c of
  2471. '=' :
  2472. begin
  2473. readchar;
  2474. token:=_GTE;
  2475. goto exit_label;
  2476. end;
  2477. '>' :
  2478. begin
  2479. readchar;
  2480. token:=_OP_SHR;
  2481. goto exit_label;
  2482. end;
  2483. '<' :
  2484. begin { >< is for a symetric diff for sets }
  2485. readchar;
  2486. token:=_SYMDIF;
  2487. goto exit_label;
  2488. end;
  2489. end;
  2490. token:=_GT;
  2491. goto exit_label;
  2492. end;
  2493. '<' :
  2494. begin
  2495. readchar;
  2496. case c of
  2497. '>' :
  2498. begin
  2499. readchar;
  2500. token:=_UNEQUAL;
  2501. goto exit_label;
  2502. end;
  2503. '=' :
  2504. begin
  2505. readchar;
  2506. token:=_LTE;
  2507. goto exit_label;
  2508. end;
  2509. '<' :
  2510. begin
  2511. readchar;
  2512. token:=_OP_SHL;
  2513. goto exit_label;
  2514. end;
  2515. end;
  2516. token:=_LT;
  2517. goto exit_label;
  2518. end;
  2519. #26 :
  2520. begin
  2521. token:=_EOF;
  2522. checkpreprocstack;
  2523. goto exit_label;
  2524. end;
  2525. else
  2526. Illegal_Char(c);
  2527. end;
  2528. end;
  2529. exit_label:
  2530. lasttoken:=token;
  2531. end;
  2532. function tscannerfile.readpreproc:ttoken;
  2533. begin
  2534. skipspace;
  2535. case c of
  2536. 'A'..'Z',
  2537. 'a'..'z',
  2538. '_','0'..'9' : begin
  2539. current_scanner.preproc_pattern:=readid;
  2540. readpreproc:=_ID;
  2541. end;
  2542. '$' : if (m_mac in aktmodeswitches) then
  2543. begin {for hexadecimal numbers, allowed in mode mac OR}
  2544. current_scanner.preproc_pattern:=readval_asstring;
  2545. readpreproc:=_ID;
  2546. end
  2547. else
  2548. begin
  2549. readpreproc:=_EOF;
  2550. checkpreprocstack;
  2551. end;
  2552. '}' : begin
  2553. readpreproc:=_END;
  2554. end;
  2555. '(' : begin
  2556. readchar;
  2557. readpreproc:=_LKLAMMER;
  2558. end;
  2559. ')' : begin
  2560. readchar;
  2561. readpreproc:=_RKLAMMER;
  2562. end;
  2563. '+' : begin
  2564. readchar;
  2565. readpreproc:=_PLUS;
  2566. end;
  2567. '-' : begin
  2568. readchar;
  2569. readpreproc:=_MINUS;
  2570. end;
  2571. '*' : begin
  2572. readchar;
  2573. readpreproc:=_STAR;
  2574. end;
  2575. '/' : begin
  2576. readchar;
  2577. readpreproc:=_SLASH;
  2578. end;
  2579. '=' : begin
  2580. readchar;
  2581. readpreproc:=_EQUAL;
  2582. end;
  2583. '>' : begin
  2584. readchar;
  2585. if c='=' then
  2586. begin
  2587. readchar;
  2588. readpreproc:=_GTE;
  2589. end
  2590. else
  2591. readpreproc:=_GT;
  2592. end;
  2593. '<' : begin
  2594. readchar;
  2595. case c of
  2596. '>' : begin
  2597. readchar;
  2598. readpreproc:=_UNEQUAL;
  2599. end;
  2600. '=' : begin
  2601. readchar;
  2602. readpreproc:=_LTE;
  2603. end;
  2604. else readpreproc:=_LT;
  2605. end;
  2606. end;
  2607. #26 :
  2608. end_of_file;
  2609. else
  2610. begin
  2611. readpreproc:=_EOF;
  2612. checkpreprocstack;
  2613. end;
  2614. end;
  2615. end;
  2616. function tscannerfile.asmgetcharstart : char;
  2617. begin
  2618. { return first the character already
  2619. available in c }
  2620. lastasmgetchar:=c;
  2621. result:=asmgetchar;
  2622. end;
  2623. function tscannerfile.asmgetchar : char;
  2624. begin
  2625. if lastasmgetchar<>#0 then
  2626. begin
  2627. c:=lastasmgetchar;
  2628. lastasmgetchar:=#0;
  2629. end
  2630. else
  2631. readchar;
  2632. if in_asm_string then
  2633. begin
  2634. asmgetchar:=c;
  2635. exit;
  2636. end;
  2637. repeat
  2638. case c of
  2639. {$ifndef arm}
  2640. // the { ... } is used in ARM assembler to define register sets, so we can't used
  2641. // it as comment, either (* ... *), /* ... */ or // ... should be used instead
  2642. '{' :
  2643. skipcomment;
  2644. {$endif arm}
  2645. #10,#13 :
  2646. begin
  2647. linebreak;
  2648. asmgetchar:=c;
  2649. exit;
  2650. end;
  2651. #26 :
  2652. begin
  2653. reload;
  2654. if (c=#26) and not assigned(inputfile.next) then
  2655. end_of_file;
  2656. continue;
  2657. end;
  2658. '/' :
  2659. begin
  2660. readchar;
  2661. if c='/' then
  2662. skipdelphicomment
  2663. else
  2664. begin
  2665. asmgetchar:='/';
  2666. lastasmgetchar:=c;
  2667. exit;
  2668. end;
  2669. end;
  2670. '(' :
  2671. begin
  2672. readchar;
  2673. if c='*' then
  2674. begin
  2675. c:=#0;{Signal skipoldtpcomment to reload a char }
  2676. skipoldtpcomment;
  2677. end
  2678. else
  2679. begin
  2680. asmgetchar:='(';
  2681. lastasmgetchar:=c;
  2682. exit;
  2683. end;
  2684. end;
  2685. else
  2686. begin
  2687. asmgetchar:=c;
  2688. exit;
  2689. end;
  2690. end;
  2691. until false;
  2692. end;
  2693. {*****************************************************************************
  2694. Helpers
  2695. *****************************************************************************}
  2696. procedure AddDirective(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  2697. begin
  2698. if dm in [directive_all, directive_turbo] then
  2699. turbo_scannerdirectives.insert(tdirectiveitem.create(s,p));
  2700. if dm in [directive_all, directive_mac] then
  2701. mac_scannerdirectives.insert(tdirectiveitem.create(s,p));
  2702. end;
  2703. procedure AddConditional(const s:string; dm: tdirectivemode; p:tdirectiveproc);
  2704. begin
  2705. if dm in [directive_all, directive_turbo] then
  2706. turbo_scannerdirectives.insert(tdirectiveitem.createcond(s,p));
  2707. if dm in [directive_all, directive_mac] then
  2708. mac_scannerdirectives.insert(tdirectiveitem.createcond(s,p));
  2709. end;
  2710. {*****************************************************************************
  2711. Initialization
  2712. *****************************************************************************}
  2713. procedure InitScanner;
  2714. begin
  2715. InitWideString(patternw);
  2716. turbo_scannerdirectives:=TDictionary.Create;
  2717. mac_scannerdirectives:=TDictionary.Create;
  2718. { Default directives and conditionals for all modes }
  2719. AddDirective('I',directive_all, {$ifdef FPCPROCVAR}@{$endif}dir_include);
  2720. { Default Turbo directives and conditionals }
  2721. AddDirective('DEFINE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_define);
  2722. AddDirective('UNDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_undef);
  2723. AddDirective('INCLUDE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_include);
  2724. AddConditional('ELSE',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_else);
  2725. AddConditional('ENDIF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2726. AddConditional('IFEND',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2727. AddConditional('IF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_if);
  2728. AddConditional('IFDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifdef);
  2729. AddConditional('IFNDEF',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifndef);
  2730. AddConditional('IFOPT',directive_turbo, {$ifdef FPCPROCVAR}@{$endif}dir_ifopt);
  2731. { Default Mac directives and conditionals: }
  2732. AddDirective('SETC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_setc);
  2733. AddConditional('IFC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_if);
  2734. AddConditional('ELSEC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_else);
  2735. AddConditional('ENDC',directive_mac, {$ifdef FPCPROCVAR}@{$endif}dir_endif);
  2736. end;
  2737. procedure DoneScanner;
  2738. begin
  2739. turbo_scannerdirectives.Free;
  2740. mac_scannerdirectives.Free;
  2741. DoneWideString(patternw);
  2742. end;
  2743. end.
  2744. {
  2745. $Log$
  2746. Revision 1.74 2004-02-29 13:28:57 peter
  2747. * more fixes for skipuntildirective
  2748. Revision 1.73 2004/02/27 11:50:13 michael
  2749. + Patch from peter to fix webtb[fs]/tw2853*.pp
  2750. Revision 1.72 2004/02/26 16:15:45 peter
  2751. * resursive macro's fixed in preprocessor
  2752. Revision 1.71 2004/02/25 00:54:47 olle
  2753. + mode mac: preproc support for hexadecimal numbers
  2754. + mode mac: preproc support for TRUE, FALSE
  2755. Revision 1.70 2004/02/23 23:38:25 olle
  2756. + mode mac: added UNDEFINED construct
  2757. + mode mac: added support for include $I
  2758. * renamed one of the readpreproc to preproc_substitutedtoken to avoid confusement
  2759. Revision 1.69 2004/02/11 14:46:59 daniel
  2760. * Better fix for case sensitive macro handling
  2761. Revision 1.68 2004/02/11 14:13:10 daniel
  2762. * Compiler was partially case sensitive in macro expansion
  2763. * Multiple and/or preprocessor statements caused problems
  2764. Revision 1.67 2004/02/07 23:28:34 daniel
  2765. * Take advantage of our new with statement optimization
  2766. Revision 1.66 2003/11/12 16:57:59 peter
  2767. * do nothing for macro's in tempcloseinput,tempopeninput
  2768. Revision 1.65 2003/11/10 19:08:59 peter
  2769. + $IF DECLARED() added
  2770. Revision 1.64 2003/11/10 19:08:32 peter
  2771. * line numbering is now only done when #10, #10#13 is really parsed
  2772. instead of when it is the next character
  2773. Revision 1.63 2003/10/29 21:02:51 peter
  2774. * set ms_compiled after the program/unit is parsed
  2775. * check for ms_compiled before checking preproc matches
  2776. Revision 1.62 2003/09/17 22:30:19 olle
  2777. + support for a different set of compiler directives under $MODE MAC
  2778. + added mac directives $SETC $IFC $ELSEC $ENDC
  2779. Revision 1.61 2003/09/03 11:18:37 florian
  2780. * fixed arm concatcopy
  2781. + arm support in the common compiler sources added
  2782. * moved some generic cg code around
  2783. + tfputype added
  2784. * ...
  2785. Revision 1.60 2003/08/10 17:25:23 peter
  2786. * fixed some reported bugs
  2787. Revision 1.59 2003/05/25 10:26:43 peter
  2788. * recursive include depth check
  2789. Revision 1.58 2003/04/26 00:30:27 peter
  2790. * don't close inputfile when still closed
  2791. Revision 1.57 2003/01/09 21:52:37 peter
  2792. * merged some verbosity options.
  2793. * V_LineInfo is a verbosity flag to include line info
  2794. Revision 1.56 2002/12/29 14:57:50 peter
  2795. * unit loading changed to first register units and load them
  2796. afterwards. This is needed to support uses xxx in yyy correctly
  2797. * unit dependency check fixed
  2798. Revision 1.55 2002/12/27 18:05:58 peter
  2799. * use gettoken to get filename for include
  2800. Revision 1.54 2002/12/27 16:45:50 peter
  2801. * fix delphi comment parsing when skipping preproc directive
  2802. Revision 1.53 2002/12/27 15:26:43 peter
  2803. * give an error when no symbol is specified after $if(n)def
  2804. Revision 1.52 2002/12/24 23:32:02 peter
  2805. * support quotes around include filenames
  2806. Revision 1.51 2002/12/05 19:27:00 carl
  2807. * remove a stupid thing that i commited
  2808. Revision 1.50 2002/11/29 22:31:19 carl
  2809. + unimplemented hint directive added
  2810. * hint directive parsing implemented
  2811. * warning on these directives
  2812. Revision 1.49 2002/11/26 22:56:40 peter
  2813. * fix macro nesting check
  2814. Revision 1.48 2002/09/16 19:05:48 peter
  2815. * parse ^ after nil as caret
  2816. Revision 1.47 2002/09/06 14:58:42 carl
  2817. * bugfix of bug report 2072 (merged)
  2818. Revision 1.46 2002/09/05 19:27:05 peter
  2819. * fixed crash when current_module becomes nil
  2820. Revision 1.45 2002/09/05 14:17:27 pierre
  2821. * fix for bug 2004 merged
  2822. Revision 1.44 2002/08/12 16:46:04 peter
  2823. * tscannerfile is now destroyed in tmodule.reset and current_scanner
  2824. is updated accordingly. This removes all the loading and saving of
  2825. the old scanner and the invalid flag marking
  2826. Revision 1.43 2002/08/11 14:28:19 peter
  2827. * TScannerFile.SetInvalid added that will also reset inputfile
  2828. Revision 1.42 2002/08/10 14:46:31 carl
  2829. + moved target_cpu_string to cpuinfo
  2830. * renamed asmmode enum.
  2831. * assembler reader has now less ifdef's
  2832. * move from nppcmem.pas -> ncgmem.pas vec. node.
  2833. Revision 1.41 2002/08/06 21:12:16 florian
  2834. + support for octal constants, they are specified by a leading &
  2835. Revision 1.40 2002/07/20 17:35:52 florian
  2836. + char constants specified with #.. with more than 3 digits are handled as widechar
  2837. Revision 1.39 2002/05/18 13:34:17 peter
  2838. * readded missing revisions
  2839. Revision 1.38 2002/05/16 19:46:44 carl
  2840. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2841. + try to fix temp allocation (still in ifdef)
  2842. + generic constructor calls
  2843. + start of tassembler / tmodulebase class cleanup
  2844. Revision 1.36 2002/04/21 18:57:23 peter
  2845. * fixed memleaks when file can't be opened
  2846. Revision 1.35 2002/04/21 15:22:26 carl
  2847. * first check .inc file extension
  2848. Revision 1.34 2002/04/21 07:24:09 carl
  2849. - remove my fixes until Peter agrees on the fix (sorry Peter)
  2850. Revision 1.32 2002/04/19 15:42:11 peter
  2851. * default extension checking for include files
  2852. Revision 1.31 2002/03/01 14:39:44 peter
  2853. * fixed // and (* parsing to not be done when already parsing a
  2854. tp comment in skipuntildirective
  2855. Revision 1.30 2002/03/01 12:39:26 peter
  2856. * support // parsing in skipuntildirective
  2857. Revision 1.29 2002/01/27 21:44:26 peter
  2858. * FPCTARGETOS/FPCTARGETCPU added as internal environment variable
  2859. Revision 1.28 2002/01/24 18:25:50 peter
  2860. * implicit result variable generation for assembler routines
  2861. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2862. }