scanner.pas 94 KB

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