scanner.pas 94 KB

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