scanner.pas 95 KB

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