pexpr.pas 203 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does parsing of expression for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pexpr;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,symdef,symbase,
  22. node,ncal,compinnr,
  23. tokens,globtype,globals,constexp,
  24. pgentype;
  25. type
  26. texprflag = (
  27. ef_accept_equal,
  28. ef_type_only,
  29. ef_had_specialize,
  30. ef_check_attr_suffix
  31. );
  32. texprflags = set of texprflag;
  33. { reads a whole expression }
  34. function expr(dotypecheck:boolean) : tnode;
  35. { reads an expression without assignements and .. }
  36. function comp_expr(flags:texprflags):tnode;
  37. { reads a single factor }
  38. function factor(getaddr:boolean;flags:texprflags) : tnode;
  39. procedure string_dec(var def: tdef; allowtypedef: boolean);
  40. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  41. { the ID token has to be consumed before calling this function }
  42. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags;spezcontext:tspecializationcontext);
  43. function get_intconst:TConstExprInt;
  44. function get_stringconst:string;
  45. { Does some postprocessing for a generic type (especially when nested types
  46. of the specialization are used) }
  47. procedure post_comp_expr_gendef(var def: tdef);
  48. implementation
  49. uses
  50. { common }
  51. cutils,cclasses,
  52. { global }
  53. verbose,
  54. systems,widestr,
  55. { symtable }
  56. symconst,symtable,symsym,symcpu,defutil,defcmp,
  57. { module }
  58. fmodule,ppu,
  59. { pass 1 }
  60. pass_1,
  61. nmat,nadd,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  62. { parser }
  63. scanner,
  64. pbase,pinline,ptype,pgenutil,psub,procinfo,cpuinfo
  65. ;
  66. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;forward;
  67. const
  68. { true, if the inherited call is anonymous }
  69. anon_inherited : boolean = false;
  70. { last def found, only used by anon. inherited calls to insert proper type casts }
  71. srdef : tdef = nil;
  72. procedure string_dec(var def:tdef; allowtypedef: boolean);
  73. { reads a string type with optional length }
  74. { and returns a pointer to the string }
  75. { definition }
  76. var
  77. p : tnode;
  78. begin
  79. def:=cshortstringtype;
  80. consume(_STRING);
  81. if token=_LECKKLAMMER then
  82. begin
  83. if not(allowtypedef) then
  84. Message(parser_e_no_local_para_def);
  85. consume(_LECKKLAMMER);
  86. p:=comp_expr([ef_accept_equal]);
  87. if not is_constintnode(p) then
  88. begin
  89. Message(parser_e_illegal_expression);
  90. { error recovery }
  91. consume(_RECKKLAMMER);
  92. end
  93. else
  94. begin
  95. { the node is a generic param while parsing a generic def
  96. so disable the range checking for the string }
  97. if parse_generic and
  98. (nf_generic_para in p.flags) then
  99. tordconstnode(p).value:=255;
  100. if tordconstnode(p).value<=0 then
  101. begin
  102. Message(parser_e_invalid_string_size);
  103. tordconstnode(p).value:=255;
  104. end;
  105. if tordconstnode(p).value>255 then
  106. begin
  107. { longstring is currently unsupported (CEC)! }
  108. { t:=cstringdef.createlong(tordconstnode(p).value))}
  109. Message(parser_e_invalid_string_size);
  110. tordconstnode(p).value:=255;
  111. def:=cstringdef.createshort(int64(tordconstnode(p).value),true);
  112. end
  113. else
  114. if tordconstnode(p).value<>255 then
  115. def:=cstringdef.createshort(int64(tordconstnode(p).value),true);
  116. consume(_RECKKLAMMER);
  117. end;
  118. p.free;
  119. end
  120. else
  121. begin
  122. // string[x] is allowed in system unit since it is a shortstring.
  123. if cs_compilesystem in current_settings.moduleswitches then
  124. Message(parser_e_nostringaliasinsystem);
  125. if cs_refcountedstrings in current_settings.localswitches then
  126. begin
  127. if m_default_unicodestring in current_settings.modeswitches then
  128. def:=cunicodestringtype
  129. else
  130. def:=cansistringtype
  131. end
  132. else
  133. def:=cshortstringtype;
  134. end;
  135. end;
  136. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  137. var
  138. p1,p2,argname : tnode;
  139. prev_in_args,
  140. old_named_args_allowed : boolean;
  141. begin
  142. if token=end_of_paras then
  143. begin
  144. parse_paras:=nil;
  145. exit;
  146. end;
  147. { save old values }
  148. prev_in_args:=in_args;
  149. old_named_args_allowed:=named_args_allowed;
  150. { set para parsing values }
  151. in_args:=true;
  152. named_args_allowed:=false;
  153. p2:=nil;
  154. repeat
  155. if __namedpara then
  156. begin
  157. if token=_COMMA then
  158. begin
  159. { empty parameter }
  160. p2:=ccallparanode.create(cnothingnode.create,p2);
  161. end
  162. else
  163. begin
  164. named_args_allowed:=true;
  165. p1:=comp_expr([ef_accept_equal]);
  166. named_args_allowed:=false;
  167. if found_arg_name then
  168. begin
  169. argname:=p1;
  170. p1:=comp_expr([ef_accept_equal]);
  171. p2:=ccallparanode.create(p1,p2);
  172. tcallparanode(p2).parametername:=argname;
  173. end
  174. else
  175. p2:=ccallparanode.create(p1,p2);
  176. found_arg_name:=false;
  177. end;
  178. end
  179. else
  180. begin
  181. p1:=comp_expr([ef_accept_equal]);
  182. p2:=ccallparanode.create(p1,p2);
  183. end;
  184. { it's for the str(l:5,s); }
  185. if __colon and (token=_COLON) then
  186. begin
  187. consume(_COLON);
  188. p1:=comp_expr([ef_accept_equal]);
  189. p2:=ccallparanode.create(p1,p2);
  190. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  191. if try_to_consume(_COLON) then
  192. begin
  193. p1:=comp_expr([ef_accept_equal]);
  194. p2:=ccallparanode.create(p1,p2);
  195. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  196. end
  197. end;
  198. until not try_to_consume(_COMMA);
  199. in_args:=prev_in_args;
  200. named_args_allowed:=old_named_args_allowed;
  201. parse_paras:=p2;
  202. end;
  203. function gen_c_style_operator(ntyp:tnodetype;p1,p2:tnode) : tnode;
  204. var
  205. hdef : tdef;
  206. temp : ttempcreatenode;
  207. newstatement : tstatementnode;
  208. begin
  209. { Properties are not allowed, because the write can
  210. be different from the read }
  211. if (nf_isproperty in p1.flags) then
  212. begin
  213. Message(type_e_variable_id_expected);
  214. { We can continue with the loading,
  215. it'll not create errors. Only the expected
  216. result can be wrong }
  217. end;
  218. if might_have_sideeffects(p1,[]) then
  219. begin
  220. typecheckpass(p1);
  221. result:=internalstatements(newstatement);
  222. hdef:=cpointerdef.getreusable(p1.resultdef);
  223. temp:=ctempcreatenode.create(hdef,sizeof(pint),tt_persistent,false);
  224. addstatement(newstatement,temp);
  225. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),caddrnode.create_internal(p1)));
  226. addstatement(newstatement,cassignmentnode.create(
  227. cderefnode.create(ctemprefnode.create(temp)),
  228. caddnode.create(ntyp,
  229. cderefnode.create(ctemprefnode.create(temp)),
  230. p2)));
  231. addstatement(newstatement,ctempdeletenode.create(temp));
  232. end
  233. else
  234. result:=cassignmentnode.create(p1,caddnode.create(ntyp,p1.getcopy,p2));
  235. end;
  236. function statement_syssym(l : tinlinenumber) : tnode;
  237. var
  238. p1,p2,paras : tnode;
  239. err,
  240. prev_in_args : boolean;
  241. def : tdef;
  242. exit_procinfo: tprocinfo;
  243. begin
  244. prev_in_args:=in_args;
  245. case l of
  246. in_new_x :
  247. begin
  248. if afterassignment or in_args then
  249. statement_syssym:=new_function
  250. else
  251. statement_syssym:=new_dispose_statement(true);
  252. end;
  253. in_dispose_x :
  254. begin
  255. statement_syssym:=new_dispose_statement(false);
  256. end;
  257. in_ord_x,
  258. in_chr_byte:
  259. begin
  260. consume(_LKLAMMER);
  261. in_args:=true;
  262. p1:=comp_expr([ef_accept_equal]);
  263. consume(_RKLAMMER);
  264. p1:=geninlinenode(l,false,p1);
  265. statement_syssym := p1;
  266. end;
  267. in_exit :
  268. begin
  269. statement_syssym:=nil;
  270. if try_to_consume(_LKLAMMER) then
  271. begin
  272. if not (m_mac in current_settings.modeswitches) then
  273. begin
  274. if not(try_to_consume(_RKLAMMER)) then
  275. begin
  276. p1:=comp_expr([ef_accept_equal]);
  277. consume(_RKLAMMER);
  278. if not assigned(current_procinfo) or
  279. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  280. is_void(current_procinfo.procdef.returndef) then
  281. begin
  282. Message(parser_e_void_function);
  283. { recovery }
  284. p1.free;
  285. p1:=nil;
  286. end;
  287. end
  288. else
  289. p1:=nil;
  290. end
  291. else
  292. begin
  293. { non local exit ? }
  294. if current_procinfo.procdef.procsym.name<>pattern then
  295. begin
  296. exit_procinfo:=current_procinfo.parent;
  297. while assigned(exit_procinfo) do
  298. begin
  299. if exit_procinfo.procdef.procsym.name=pattern then
  300. break;
  301. exit_procinfo:=exit_procinfo.parent;
  302. end;
  303. if assigned(exit_procinfo) then
  304. begin
  305. if not(assigned(exit_procinfo.nestedexitlabel)) then
  306. begin
  307. include(current_procinfo.flags,pi_has_nested_exit);
  308. exclude(current_procinfo.procdef.procoptions,po_inline);
  309. if is_nested_pd(current_procinfo.procdef) then
  310. current_procinfo.set_needs_parentfp(exit_procinfo.procdef.parast.symtablelevel);
  311. exit_procinfo.nestedexitlabel:=clabelsym.create('$nestedexit');
  312. { the compiler is responsible to define this label }
  313. exit_procinfo.nestedexitlabel.defined:=true;
  314. exit_procinfo.nestedexitlabel.used:=true;
  315. exit_procinfo.nestedexitlabel.jumpbuf:=clocalvarsym.create('LABEL$_'+exit_procinfo.nestedexitlabel.name,vs_value,rec_jmp_buf,[]);
  316. exit_procinfo.procdef.localst.insertsym(exit_procinfo.nestedexitlabel);
  317. exit_procinfo.procdef.localst.insertsym(exit_procinfo.nestedexitlabel.jumpbuf);
  318. end;
  319. statement_syssym:=cgotonode.create(exit_procinfo.nestedexitlabel);
  320. tgotonode(statement_syssym).labelsym:=exit_procinfo.nestedexitlabel;
  321. end
  322. else
  323. Message(parser_e_macpas_exit_wrong_param);
  324. end;
  325. consume(_ID);
  326. consume(_RKLAMMER);
  327. p1:=nil;
  328. end
  329. end
  330. else
  331. p1:=nil;
  332. if not assigned(statement_syssym) then
  333. statement_syssym:=cexitnode.create(p1);
  334. end;
  335. in_break :
  336. begin
  337. statement_syssym:=cbreaknode.create
  338. end;
  339. in_continue :
  340. begin
  341. statement_syssym:=ccontinuenode.create
  342. end;
  343. in_leave :
  344. begin
  345. if m_mac in current_settings.modeswitches then
  346. statement_syssym:=cbreaknode.create
  347. else
  348. begin
  349. Message1(sym_e_id_not_found, orgpattern);
  350. statement_syssym:=cerrornode.create;
  351. end;
  352. end;
  353. in_cycle :
  354. begin
  355. if m_mac in current_settings.modeswitches then
  356. statement_syssym:=ccontinuenode.create
  357. else
  358. begin
  359. Message1(sym_e_id_not_found, orgpattern);
  360. statement_syssym:=cerrornode.create;
  361. end;
  362. end;
  363. in_typeof_x :
  364. begin
  365. consume(_LKLAMMER);
  366. in_args:=true;
  367. p1:=comp_expr([ef_accept_equal]);
  368. consume(_RKLAMMER);
  369. if p1.nodetype=typen then
  370. ttypenode(p1).allowed:=true;
  371. { Allow classrefdef, which is required for
  372. Typeof(self) in static class methods }
  373. if not(is_objc_class_or_protocol(p1.resultdef)) and
  374. not(is_java_class_or_interface(p1.resultdef)) and
  375. ((p1.resultdef.typ = objectdef) or
  376. (assigned(current_procinfo) and
  377. ((po_classmethod in current_procinfo.procdef.procoptions) or
  378. (po_staticmethod in current_procinfo.procdef.procoptions)) and
  379. (p1.resultdef.typ=classrefdef))) then
  380. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  381. else
  382. begin
  383. Message(parser_e_class_id_expected);
  384. p1.destroy;
  385. statement_syssym:=cerrornode.create;
  386. end;
  387. end;
  388. in_sizeof_x,
  389. in_bitsizeof_x :
  390. begin
  391. consume(_LKLAMMER);
  392. in_args:=true;
  393. p1:=comp_expr([ef_accept_equal]);
  394. consume(_RKLAMMER);
  395. if ((p1.nodetype<>typen) and
  396. (
  397. (is_object(p1.resultdef) and
  398. (oo_has_constructor in tobjectdef(p1.resultdef).objectoptions)) or
  399. is_open_array(p1.resultdef) or
  400. is_array_of_const(p1.resultdef) or
  401. is_open_string(p1.resultdef)
  402. )) or
  403. { keep the function call if it is a type parameter to avoid arithmetic errors due to constant folding }
  404. is_typeparam(p1.resultdef) then
  405. begin
  406. statement_syssym:=geninlinenode(in_sizeof_x,false,p1);
  407. { no packed bit support for these things }
  408. if l=in_bitsizeof_x then
  409. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sizesinttype,true));
  410. { type sym is a generic parameter }
  411. if assigned(p1.resultdef.typesym) and (sp_generic_para in p1.resultdef.typesym.symoptions) then
  412. include(statement_syssym.flags,nf_generic_para);
  413. end
  414. else
  415. begin
  416. { allow helpers for SizeOf and BitSizeOf }
  417. if p1.nodetype=typen then
  418. ttypenode(p1).helperallowed:=true;
  419. if (p1.resultdef.typ=forwarddef) then
  420. Message1(type_e_type_is_not_completly_defined,tforwarddef(p1.resultdef).tosymname^);
  421. if (l = in_sizeof_x) or
  422. (not((p1.nodetype = vecn) and
  423. is_packed_array(tvecnode(p1).left.resultdef)) and
  424. not((p1.nodetype = subscriptn) and
  425. is_packed_record_or_object(tsubscriptnode(p1).left.resultdef))) then
  426. begin
  427. statement_syssym:=genintconstnode(p1.resultdef.size,sizesinttype);
  428. if (l = in_bitsizeof_x) then
  429. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sizesinttype,true));
  430. end
  431. else
  432. statement_syssym:=genintconstnode(p1.resultdef.packedbitsize,sizesinttype);
  433. { type def is a struct with generic fields }
  434. if df_has_generic_fields in p1.resultdef.defoptions then
  435. include(statement_syssym.flags,nf_generic_para);
  436. { p1 not needed !}
  437. p1.destroy;
  438. end;
  439. end;
  440. in_typeinfo_x,
  441. in_objc_encode_x,
  442. in_gettypekind_x,
  443. in_ismanagedtype_x:
  444. begin
  445. if (l in [in_typeinfo_x,in_gettypekind_x,in_ismanagedtype_x]) or
  446. (m_objectivec1 in current_settings.modeswitches) then
  447. begin
  448. consume(_LKLAMMER);
  449. in_args:=true;
  450. p1:=comp_expr([ef_accept_equal]);
  451. { When reading a class type it is parsed as loadvmtaddrn,
  452. typeinfo only needs the type so we remove the loadvmtaddrn }
  453. if p1.nodetype=loadvmtaddrn then
  454. begin
  455. p2:=tloadvmtaddrnode(p1).left;
  456. tloadvmtaddrnode(p1).left:=nil;
  457. p1.free;
  458. p1:=p2;
  459. end;
  460. if p1.nodetype=typen then
  461. begin
  462. ttypenode(p1).allowed:=true;
  463. { allow helpers for TypeInfo }
  464. if l in [in_typeinfo_x,in_gettypekind_x,in_ismanagedtype_x] then
  465. ttypenode(p1).helperallowed:=true;
  466. end;
  467. { else
  468. begin
  469. p1.destroy;
  470. p1:=cerrornode.create;
  471. Message(parser_e_illegal_parameter_list);
  472. end;}
  473. consume(_RKLAMMER);
  474. p2:=geninlinenode(l,false,p1);
  475. statement_syssym:=p2;
  476. end
  477. else
  478. begin
  479. Message1(sym_e_id_not_found, orgpattern);
  480. statement_syssym:=cerrornode.create;
  481. end;
  482. end;
  483. in_isconstvalue_x:
  484. begin
  485. consume(_LKLAMMER);
  486. in_args:=true;
  487. p1:=comp_expr([ef_accept_equal]);
  488. consume(_RKLAMMER);
  489. p2:=geninlinenode(l,false,p1);
  490. statement_syssym:=p2;
  491. end;
  492. in_aligned_x,
  493. in_unaligned_x,
  494. in_volatile_x:
  495. begin
  496. err:=false;
  497. consume(_LKLAMMER);
  498. in_args:=true;
  499. p1:=comp_expr([ef_accept_equal]);
  500. p2:=ccallparanode.create(p1,nil);
  501. p2:=geninlinenode(l,false,p2);
  502. consume(_RKLAMMER);
  503. statement_syssym:=p2;
  504. end;
  505. in_assigned_x :
  506. begin
  507. err:=false;
  508. consume(_LKLAMMER);
  509. in_args:=true;
  510. p1:=comp_expr([ef_accept_equal]);
  511. { When reading a class type it is parsed as loadvmtaddrn,
  512. typeinfo only needs the type so we remove the loadvmtaddrn }
  513. if p1.nodetype=loadvmtaddrn then
  514. begin
  515. p2:=tloadvmtaddrnode(p1).left;
  516. tloadvmtaddrnode(p1).left:=nil;
  517. p1.free;
  518. p1:=p2;
  519. end;
  520. if not codegenerror then
  521. begin
  522. case p1.resultdef.typ of
  523. procdef, { procvar }
  524. pointerdef,
  525. procvardef,
  526. classrefdef : ;
  527. objectdef :
  528. if not is_implicit_pointer_object_type(p1.resultdef) then
  529. begin
  530. Message(parser_e_illegal_parameter_list);
  531. err:=true;
  532. end;
  533. arraydef :
  534. if not is_dynamic_array(p1.resultdef) then
  535. begin
  536. Message(parser_e_illegal_parameter_list);
  537. err:=true;
  538. end;
  539. else
  540. if p1.resultdef.typ<>undefineddef then
  541. begin
  542. Message(parser_e_illegal_parameter_list);
  543. err:=true;
  544. end;
  545. end;
  546. end
  547. else
  548. err:=true;
  549. if not err then
  550. begin
  551. p2:=ccallparanode.create(p1,nil);
  552. p2:=geninlinenode(in_assigned_x,false,p2);
  553. end
  554. else
  555. begin
  556. p1.free;
  557. p2:=cerrornode.create;
  558. end;
  559. consume(_RKLAMMER);
  560. statement_syssym:=p2;
  561. end;
  562. in_addr_x :
  563. begin
  564. consume(_LKLAMMER);
  565. got_addrn:=true;
  566. p1:=factor(true,[]);
  567. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  568. if token<>_RKLAMMER then
  569. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  570. p1:=caddrnode.create(p1);
  571. got_addrn:=false;
  572. consume(_RKLAMMER);
  573. statement_syssym:=p1;
  574. end;
  575. {$ifdef i8086}
  576. in_faraddr_x :
  577. begin
  578. consume(_LKLAMMER);
  579. got_addrn:=true;
  580. p1:=factor(true,[]);
  581. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  582. if token<>_RKLAMMER then
  583. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  584. p1:=geninlinenode(in_faraddr_x,false,p1);
  585. got_addrn:=false;
  586. consume(_RKLAMMER);
  587. statement_syssym:=p1;
  588. end;
  589. {$endif i8086}
  590. in_ofs_x :
  591. begin
  592. if target_info.system in systems_managed_vm then
  593. message(parser_e_feature_unsupported_for_vm);
  594. consume(_LKLAMMER);
  595. got_addrn:=true;
  596. p1:=factor(true,[]);
  597. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  598. if token<>_RKLAMMER then
  599. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  600. p1:=caddrnode.create(p1);
  601. include(taddrnode(p1).addrnodeflags,anf_ofs);
  602. got_addrn:=false;
  603. { Ofs() returns a cardinal/qword, not a pointer }
  604. inserttypeconv_internal(p1,uinttype);
  605. consume(_RKLAMMER);
  606. statement_syssym:=p1;
  607. end;
  608. in_seg_x :
  609. begin
  610. consume(_LKLAMMER);
  611. got_addrn:=true;
  612. p1:=factor(true,[]);
  613. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  614. if token<>_RKLAMMER then
  615. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  616. p1:=geninlinenode(in_seg_x,false,p1);
  617. got_addrn:=false;
  618. consume(_RKLAMMER);
  619. statement_syssym:=p1;
  620. end;
  621. in_high_x,
  622. in_low_x :
  623. begin
  624. consume(_LKLAMMER);
  625. in_args:=true;
  626. p1:=comp_expr([ef_accept_equal]);
  627. p2:=geninlinenode(l,false,p1);
  628. consume(_RKLAMMER);
  629. statement_syssym:=p2;
  630. end;
  631. in_succ_x,
  632. in_pred_x :
  633. begin
  634. consume(_LKLAMMER);
  635. in_args:=true;
  636. p1:=comp_expr([ef_accept_equal]);
  637. p2:=geninlinenode(l,false,p1);
  638. consume(_RKLAMMER);
  639. statement_syssym:=p2;
  640. end;
  641. in_inc_x,
  642. in_dec_x :
  643. begin
  644. consume(_LKLAMMER);
  645. in_args:=true;
  646. p1:=comp_expr([ef_accept_equal]);
  647. if try_to_consume(_COMMA) then
  648. p2:=ccallparanode.create(comp_expr([ef_accept_equal]),nil)
  649. else
  650. p2:=nil;
  651. p2:=ccallparanode.create(p1,p2);
  652. statement_syssym:=geninlinenode(l,false,p2);
  653. consume(_RKLAMMER);
  654. end;
  655. in_slice_x:
  656. begin
  657. if not(in_args) then
  658. begin
  659. message(parser_e_illegal_slice);
  660. consume(_LKLAMMER);
  661. in_args:=true;
  662. comp_expr([ef_accept_equal]).free;
  663. if try_to_consume(_COMMA) then
  664. comp_expr([ef_accept_equal]).free;
  665. statement_syssym:=cerrornode.create;
  666. consume(_RKLAMMER);
  667. end
  668. else
  669. begin
  670. consume(_LKLAMMER);
  671. in_args:=true;
  672. p1:=comp_expr([ef_accept_equal]);
  673. Consume(_COMMA);
  674. if not(codegenerror) then
  675. p2:=ccallparanode.create(comp_expr([ef_accept_equal]),nil)
  676. else
  677. p2:=cerrornode.create;
  678. p2:=ccallparanode.create(p1,p2);
  679. statement_syssym:=geninlinenode(l,false,p2);
  680. consume(_RKLAMMER);
  681. end;
  682. end;
  683. in_initialize_x:
  684. begin
  685. statement_syssym:=inline_initialize;
  686. end;
  687. in_finalize_x:
  688. begin
  689. statement_syssym:=inline_finalize;
  690. end;
  691. in_copy_x:
  692. begin
  693. statement_syssym:=inline_copy;
  694. end;
  695. in_concat_x :
  696. begin
  697. statement_syssym:=inline_concat;
  698. end;
  699. in_read_x,
  700. in_readln_x,
  701. in_readstr_x:
  702. begin
  703. if try_to_consume(_LKLAMMER) then
  704. begin
  705. paras:=parse_paras(false,false,_RKLAMMER);
  706. consume(_RKLAMMER);
  707. end
  708. else
  709. paras:=nil;
  710. p1:=geninlinenode(l,false,paras);
  711. statement_syssym := p1;
  712. end;
  713. in_setlength_x:
  714. begin
  715. statement_syssym := inline_setlength;
  716. end;
  717. in_objc_selector_x:
  718. begin
  719. if (m_objectivec1 in current_settings.modeswitches) then
  720. begin
  721. consume(_LKLAMMER);
  722. in_args:=true;
  723. { don't turn procsyms into calls (getaddr = true) }
  724. p1:=factor(true,[]);
  725. p2:=geninlinenode(l,false,p1);
  726. consume(_RKLAMMER);
  727. statement_syssym:=p2;
  728. end
  729. else
  730. begin
  731. Message1(sym_e_id_not_found, orgpattern);
  732. statement_syssym:=cerrornode.create;
  733. end;
  734. end;
  735. in_length_x:
  736. begin
  737. consume(_LKLAMMER);
  738. in_args:=true;
  739. p1:=comp_expr([ef_accept_equal]);
  740. p2:=geninlinenode(l,false,p1);
  741. consume(_RKLAMMER);
  742. statement_syssym:=p2;
  743. end;
  744. in_write_x,
  745. in_writeln_x,
  746. in_writestr_x :
  747. begin
  748. if try_to_consume(_LKLAMMER) then
  749. begin
  750. paras:=parse_paras(true,false,_RKLAMMER);
  751. consume(_RKLAMMER);
  752. end
  753. else
  754. paras:=nil;
  755. p1 := geninlinenode(l,false,paras);
  756. statement_syssym := p1;
  757. end;
  758. in_str_x_string :
  759. begin
  760. consume(_LKLAMMER);
  761. paras:=parse_paras(true,false,_RKLAMMER);
  762. consume(_RKLAMMER);
  763. p1 := geninlinenode(l,false,paras);
  764. statement_syssym := p1;
  765. end;
  766. in_val_x:
  767. Begin
  768. consume(_LKLAMMER);
  769. in_args := true;
  770. p1:= ccallparanode.create(comp_expr([ef_accept_equal]), nil);
  771. consume(_COMMA);
  772. p2 := ccallparanode.create(comp_expr([ef_accept_equal]),p1);
  773. if try_to_consume(_COMMA) then
  774. p2 := ccallparanode.create(comp_expr([ef_accept_equal]),p2);
  775. consume(_RKLAMMER);
  776. p2 := geninlinenode(l,false,p2);
  777. statement_syssym := p2;
  778. End;
  779. in_include_x_y,
  780. in_exclude_x_y :
  781. begin
  782. consume(_LKLAMMER);
  783. in_args:=true;
  784. p1:=comp_expr([ef_accept_equal]);
  785. consume(_COMMA);
  786. p2:=comp_expr([ef_accept_equal]);
  787. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  788. consume(_RKLAMMER);
  789. end;
  790. in_pack_x_y_z,
  791. in_unpack_x_y_z :
  792. begin
  793. consume(_LKLAMMER);
  794. in_args:=true;
  795. p1:=comp_expr([ef_accept_equal]);
  796. consume(_COMMA);
  797. p2:=comp_expr([ef_accept_equal]);
  798. consume(_COMMA);
  799. paras:=comp_expr([ef_accept_equal]);
  800. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,ccallparanode.create(paras,nil))));
  801. consume(_RKLAMMER);
  802. end;
  803. in_assert_x_y :
  804. begin
  805. consume(_LKLAMMER);
  806. in_args:=true;
  807. p1:=comp_expr([ef_accept_equal]);
  808. if try_to_consume(_COMMA) then
  809. p2:=comp_expr([ef_accept_equal])
  810. else
  811. begin
  812. { then insert an empty string }
  813. p2:=cstringconstnode.createstr('');
  814. end;
  815. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  816. consume(_RKLAMMER);
  817. end;
  818. in_get_frame:
  819. begin
  820. statement_syssym:=geninlinenode(l,false,nil);
  821. end;
  822. (*
  823. in_get_caller_frame:
  824. begin
  825. if try_to_consume(_LKLAMMER) then
  826. begin
  827. {You used to call get_caller_frame as get_caller_frame(get_frame),
  828. however, as a stack frame may not exist, it does more harm than
  829. good, so ignore it.}
  830. in_args:=true;
  831. p1:=comp_expr([ef_accept_equal]);
  832. p1.destroy;
  833. consume(_RKLAMMER);
  834. end;
  835. statement_syssym:=geninlinenode(l,false,nil);
  836. end;
  837. *)
  838. in_default_x:
  839. begin
  840. consume(_LKLAMMER);
  841. in_args:=true;
  842. def:=nil;
  843. single_type(def,[stoAllowSpecialization]);
  844. statement_syssym:=cerrornode.create;
  845. if def<>generrordef then
  846. { "type expected" error is already done by single_type }
  847. if def.typ=forwarddef then
  848. Message1(type_e_type_is_not_completly_defined,tforwarddef(def).tosymname^)
  849. else
  850. begin
  851. statement_syssym.free;
  852. statement_syssym:=geninlinenode(in_default_x,false,ctypenode.create(def));
  853. end;
  854. { consume the right bracket here for a nicer error position }
  855. consume(_RKLAMMER);
  856. end;
  857. in_setstring_x_y_z:
  858. begin
  859. statement_syssym := inline_setstring;
  860. end;
  861. in_delete_x_y_z:
  862. begin
  863. statement_syssym:=inline_delete;
  864. end;
  865. in_insert_x_y_z:
  866. begin
  867. statement_syssym:=inline_insert;
  868. end;
  869. in_const_eh_return_data_regno:
  870. begin
  871. consume(_LKLAMMER);
  872. in_args:=true;
  873. p1:=comp_expr([ef_accept_equal]);
  874. p2:=geninlinenode(l,true,p1);
  875. consume(_RKLAMMER);
  876. statement_syssym:=p2;
  877. end;
  878. else
  879. internalerror(15);
  880. end;
  881. in_args:=prev_in_args;
  882. end;
  883. function maybe_load_methodpointer(st:TSymtable;var p1:tnode):boolean;
  884. var
  885. pd: tprocdef;
  886. begin
  887. maybe_load_methodpointer:=false;
  888. if not assigned(p1) then
  889. begin
  890. case st.symtabletype of
  891. withsymtable :
  892. begin
  893. if (st.defowner.typ=objectdef) then
  894. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  895. end;
  896. ObjectSymtable,
  897. recordsymtable:
  898. begin
  899. { Escape nested procedures }
  900. if assigned(current_procinfo) then
  901. begin
  902. pd:=current_procinfo.get_normal_proc.procdef;
  903. { We are calling from the static class method which has no self node }
  904. if assigned(pd) and pd.no_self_node then
  905. if st.symtabletype=recordsymtable then
  906. p1:=ctypenode.create(pd.struct)
  907. else
  908. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  909. else
  910. p1:=load_self_node;
  911. end
  912. else
  913. p1:=load_self_node;
  914. { don't try to call the invokable again }
  915. if is_invokable(tdef(st.defowner)) then
  916. include(p1.flags,nf_load_procvar);
  917. { We are calling a member }
  918. maybe_load_methodpointer:=true;
  919. end;
  920. else
  921. ;
  922. end;
  923. end;
  924. end;
  925. { reads the parameter for a subroutine call }
  926. procedure do_proc_call(sym:tsym;st:TSymtable;obj:tabstractrecorddef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags;spezcontext:tspecializationcontext);
  927. var
  928. membercall,
  929. prevafterassn : boolean;
  930. i : integer;
  931. para,p2 : tnode;
  932. currpara : tparavarsym;
  933. aprocdef : tprocdef;
  934. begin
  935. prevafterassn:=afterassignment;
  936. afterassignment:=false;
  937. membercall:=false;
  938. aprocdef:=nil;
  939. { when it is a call to a member we need to load the
  940. methodpointer first
  941. }
  942. membercall:=maybe_load_methodpointer(st,p1);
  943. { When we are expecting a procvar we also need
  944. to get the address in some cases }
  945. if assigned(getprocvardef) or assigned(getfuncrefdef) then
  946. begin
  947. if (block_type=bt_const) or
  948. getaddr then
  949. begin
  950. if assigned(getfuncrefdef) then
  951. aprocdef:=Tprocsym(sym).Find_procdef_byfuncrefdef(getfuncrefdef)
  952. else
  953. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  954. getaddr:=true;
  955. end
  956. else
  957. if ((m_tp_procvar in current_settings.modeswitches) or
  958. (m_mac_procvar in current_settings.modeswitches)) and
  959. not(token in [_CARET,_POINT,_LKLAMMER]) then
  960. begin
  961. if assigned(getfuncrefdef) then
  962. aprocdef:=Tprocsym(sym).Find_procdef_byfuncrefdef(getfuncrefdef)
  963. else
  964. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  965. if assigned(aprocdef) then
  966. getaddr:=true;
  967. end;
  968. end;
  969. { only need to get the address of the procedure? Check token because
  970. in the case of opening parenthesis is possible to get pointer to
  971. function result (lack of checking for token was the reason of
  972. tw10933.pp test failure) }
  973. if getaddr and (token<>_LKLAMMER) then
  974. begin
  975. { for now we don't support pointers to generic functions, but since
  976. this is only temporary we use a non translated message }
  977. if assigned(spezcontext) then
  978. begin
  979. comment(v_error, 'Pointers to generics functions not implemented');
  980. p1:=cerrornode.create;
  981. spezcontext.free;
  982. exit;
  983. end;
  984. { Retrieve info which procvar to call. For tp_procvar the
  985. aprocdef is already loaded above so we can reuse it }
  986. if not assigned(aprocdef) and
  987. assigned(getprocvardef) then
  988. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  989. if not assigned(aprocdef) and
  990. assigned(getfuncrefdef) then
  991. aprocdef:=Tprocsym(sym).Find_procdef_byfuncrefdef(getfuncrefdef);
  992. { generate a methodcallnode or proccallnode }
  993. { we shouldn't convert things like @tcollection.load }
  994. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  995. if assigned(p1) then
  996. begin
  997. { for loading methodpointer of an inherited function
  998. we use self as instance and load the address of
  999. the function directly and not through the vmt (PFV) }
  1000. if (cnf_inherited in callflags) then
  1001. begin
  1002. include(tloadnode(p2).loadnodeflags,loadnf_inherited);
  1003. p1.free;
  1004. p1:=load_self_node;
  1005. end;
  1006. if (p1.nodetype<>typen) then
  1007. tloadnode(p2).set_mp(p1)
  1008. else
  1009. begin
  1010. typecheckpass(p1);
  1011. if (p1.resultdef.typ=classrefdef) and
  1012. (
  1013. assigned(getprocvardef) or
  1014. assigned(getfuncrefdef)
  1015. ) then
  1016. begin
  1017. p1:=cloadvmtaddrnode.create(p1);
  1018. tloadnode(p2).set_mp(p1);
  1019. end
  1020. else if (p1.resultdef.typ=objectdef) then
  1021. { so we can create the correct method pointer again in case
  1022. this is a "objectprocvar:[email protected]" expression }
  1023. tloadnode(p2).symtable:=tobjectdef(p1.resultdef).symtable
  1024. else
  1025. p1.free;
  1026. end;
  1027. end;
  1028. p1:=p2;
  1029. { no postfix operators }
  1030. again:=false;
  1031. end
  1032. else
  1033. begin
  1034. para:=nil;
  1035. if anon_inherited then
  1036. begin
  1037. if not assigned(current_procinfo) then
  1038. internalerror(200305054);
  1039. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1040. begin
  1041. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1042. if not(vo_is_hidden_para in currpara.varoptions) then
  1043. begin
  1044. { inheritance by msgint? }
  1045. if assigned(srdef) then
  1046. { anonymous inherited via msgid calls only require a var parameter for
  1047. both methods, so we need some type casting here }
  1048. para:=ccallparanode.create(ctypeconvnode.create_internal(ctypeconvnode.create_internal(
  1049. cloadnode.create(currpara,currpara.owner),cformaltype),tparavarsym(tprocdef(srdef).paras[i]).vardef),
  1050. para)
  1051. else
  1052. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  1053. end;
  1054. end;
  1055. end
  1056. else
  1057. begin
  1058. if try_to_consume(_LKLAMMER) then
  1059. begin
  1060. para:=parse_paras(false,false,_RKLAMMER);
  1061. consume(_RKLAMMER);
  1062. end;
  1063. end;
  1064. { indicate if this call was generated by a member and
  1065. no explicit self is used, this is needed to determine
  1066. how to handle a destructor call (PFV) }
  1067. if membercall then
  1068. include(callflags,cnf_member_call);
  1069. if assigned(obj) then
  1070. begin
  1071. if not (st.symtabletype in [ObjectSymtable,recordsymtable]) then
  1072. internalerror(200310031);
  1073. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags,spezcontext);
  1074. end
  1075. else
  1076. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags,spezcontext);
  1077. { in case of calling an anonynmous function we already know the concrete
  1078. procdef that is going to be called }
  1079. if (tprocsym(sym).ProcdefList.count=1) and (po_anonymous in tprocdef(tprocsym(sym).procdeflist[0]).procoptions) then
  1080. tcallnode(p1).procdefinition:=tprocdef(tprocsym(sym).procdeflist[0]);
  1081. end;
  1082. afterassignment:=prevafterassn;
  1083. end;
  1084. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  1085. var
  1086. hp,hp2 : tnode;
  1087. hpp : ^tnode;
  1088. currprocdef : tprocdef;
  1089. begin
  1090. if not assigned(pv) then
  1091. internalerror(200301121);
  1092. if (m_tp_procvar in current_settings.modeswitches) or
  1093. (m_mac_procvar in current_settings.modeswitches) then
  1094. begin
  1095. hp:=p2;
  1096. hpp:=@p2;
  1097. while assigned(hp) and
  1098. (hp.nodetype=typeconvn) do
  1099. begin
  1100. hp:=ttypeconvnode(hp).left;
  1101. { save orignal address of the old tree so we can replace the node }
  1102. hpp:=@hp;
  1103. end;
  1104. if (hp.nodetype=calln) and
  1105. { a procvar can't have parameters! }
  1106. not assigned(tcallnode(hp).left) then
  1107. begin
  1108. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byprocvardef(pv);
  1109. if assigned(currprocdef) then
  1110. begin
  1111. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  1112. if (po_methodpointer in pv.procoptions) then
  1113. tloadnode(hp2).set_mp(tcallnode(hp).methodpointer.getcopy);
  1114. hp.free;
  1115. { replace the old callnode with the new loadnode }
  1116. hpp^:=hp2;
  1117. end;
  1118. end;
  1119. end;
  1120. end;
  1121. procedure handle_funcref(fr:tobjectdef;var p2:tnode);
  1122. var
  1123. hp,hp2 : tnode;
  1124. hpp : ^tnode;
  1125. currprocdef : tprocdef;
  1126. begin
  1127. if not assigned(fr) then
  1128. internalerror(2022032401);
  1129. if not is_invokable(fr) then
  1130. internalerror(2022032402);
  1131. if (m_tp_procvar in current_settings.modeswitches) or
  1132. (m_mac_procvar in current_settings.modeswitches) then
  1133. begin
  1134. hp:=p2;
  1135. hpp:=@p2;
  1136. while assigned(hp) and
  1137. (hp.nodetype=typeconvn) do
  1138. begin
  1139. hp:=ttypeconvnode(hp).left;
  1140. { save orignal address of the old tree so we can replace the node }
  1141. hpp:=@hp;
  1142. end;
  1143. if (hp.nodetype=calln) and
  1144. { a procvar can't have parameters! }
  1145. not assigned(tcallnode(hp).left) then
  1146. begin
  1147. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byfuncrefdef(fr);
  1148. if assigned(currprocdef) then
  1149. begin
  1150. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  1151. hp.free;
  1152. { replace the old callnode with the new loadnode }
  1153. hpp^:=hp2;
  1154. end;
  1155. end;
  1156. end;
  1157. end;
  1158. { the following procedure handles the access to a property symbol }
  1159. procedure handle_propertysym(propsym : tpropertysym;st : TSymtable;var p1 : tnode);
  1160. var
  1161. paras : tnode;
  1162. p2 : tnode;
  1163. membercall : boolean;
  1164. callflags : tcallnodeflags;
  1165. propaccesslist : tpropaccesslist;
  1166. sym: tsym;
  1167. begin
  1168. { property parameters? read them only if the property really }
  1169. { has parameters }
  1170. paras:=nil;
  1171. if (ppo_hasparameters in propsym.propoptions) then
  1172. begin
  1173. if try_to_consume(_LECKKLAMMER) then
  1174. begin
  1175. paras:=parse_paras(false,false,_RECKKLAMMER);
  1176. consume(_RECKKLAMMER);
  1177. end;
  1178. end;
  1179. { indexed property }
  1180. if (ppo_indexed in propsym.propoptions) then
  1181. begin
  1182. p2:=cordconstnode.create(propsym.index,propsym.indexdef,true);
  1183. paras:=ccallparanode.create(p2,paras);
  1184. end;
  1185. { we need only a write property if a := follows }
  1186. { if not(afterassignment) and not(in_args) then }
  1187. if token=_ASSIGNMENT then
  1188. begin
  1189. if propsym.getpropaccesslist(palt_write,propaccesslist) then
  1190. begin
  1191. sym:=propaccesslist.firstsym^.sym;
  1192. case sym.typ of
  1193. procsym :
  1194. begin
  1195. callflags:=[];
  1196. { generate the method call }
  1197. membercall:=maybe_load_methodpointer(st,p1);
  1198. if membercall then
  1199. include(callflags,cnf_member_call);
  1200. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags,nil);
  1201. addsymref(sym);
  1202. paras:=nil;
  1203. consume(_ASSIGNMENT);
  1204. { read the expression }
  1205. if propsym.propdef.typ=procvardef then
  1206. getprocvardef:=tprocvardef(propsym.propdef)
  1207. else if is_invokable(propsym.propdef) then
  1208. getfuncrefdef:=tobjectdef(propsym.propdef);
  1209. p2:=comp_expr([ef_accept_equal]);
  1210. if assigned(getprocvardef) then
  1211. handle_procvar(getprocvardef,p2)
  1212. else if assigned(getfuncrefdef) then
  1213. handle_funcref(getfuncrefdef,p2);
  1214. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1215. { mark as property, both the tcallnode and the real call block }
  1216. include(p1.flags,nf_isproperty);
  1217. getprocvardef:=nil;
  1218. getfuncrefdef:=nil;
  1219. end;
  1220. fieldvarsym :
  1221. begin
  1222. { generate access code }
  1223. if not handle_staticfield_access(sym,p1) then
  1224. propaccesslist_to_node(p1,st,propaccesslist);
  1225. include(p1.flags,nf_isproperty);
  1226. consume(_ASSIGNMENT);
  1227. { read the expression }
  1228. if propsym.propdef.typ=procvardef then
  1229. getprocvardef:=tprocvardef(propsym.propdef)
  1230. else if is_invokable(propsym.propdef) then
  1231. getfuncrefdef:=tobjectdef(propsym.propdef);
  1232. p2:=comp_expr([ef_accept_equal]);
  1233. if assigned(getprocvardef) then
  1234. handle_procvar(getprocvardef,p2)
  1235. else if assigned(getfuncrefdef) then
  1236. handle_funcref(getfuncrefdef,p2);
  1237. getprocvardef:=nil;
  1238. getfuncrefdef:=nil;
  1239. p1:=cassignmentnode.create(p1,p2);
  1240. end
  1241. else
  1242. begin
  1243. p1:=cerrornode.create;
  1244. Message(parser_e_no_procedure_to_access_property);
  1245. end;
  1246. end;
  1247. end
  1248. else
  1249. begin
  1250. p1:=cerrornode.create;
  1251. Message(parser_e_no_procedure_to_access_property);
  1252. end;
  1253. end
  1254. else
  1255. begin
  1256. if propsym.getpropaccesslist(palt_read,propaccesslist) then
  1257. begin
  1258. sym := propaccesslist.firstsym^.sym;
  1259. case sym.typ of
  1260. fieldvarsym :
  1261. begin
  1262. { generate access code }
  1263. if not handle_staticfield_access(sym,p1) then
  1264. propaccesslist_to_node(p1,st,propaccesslist);
  1265. include(p1.flags,nf_isproperty);
  1266. { catch expressions like "(propx):=1;" }
  1267. include(p1.flags,nf_no_lvalue);
  1268. end;
  1269. procsym :
  1270. begin
  1271. callflags:=[];
  1272. { generate the method call }
  1273. membercall:=maybe_load_methodpointer(st,p1);
  1274. if membercall then
  1275. include(callflags,cnf_member_call);
  1276. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags,nil);
  1277. paras:=nil;
  1278. include(p1.flags,nf_isproperty);
  1279. include(p1.flags,nf_no_lvalue);
  1280. end
  1281. else
  1282. begin
  1283. p1:=cerrornode.create;
  1284. Message(type_e_mismatch);
  1285. end;
  1286. end;
  1287. end
  1288. else
  1289. begin
  1290. { error, no function to read property }
  1291. p1:=cerrornode.create;
  1292. Message(parser_e_no_procedure_to_access_property);
  1293. end;
  1294. end;
  1295. { release paras if not used }
  1296. if assigned(paras) then
  1297. paras.free;
  1298. end;
  1299. { the ID token has to be consumed before calling this function }
  1300. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags;spezcontext:tspecializationcontext);
  1301. var
  1302. isclassref:boolean;
  1303. isrecordtype:boolean;
  1304. isobjecttype:boolean;
  1305. ishelpertype:boolean;
  1306. begin
  1307. if sym=nil then
  1308. begin
  1309. { pattern is still valid unless
  1310. there is another ID just after the ID of sym }
  1311. Message1(sym_e_id_no_member,orgpattern);
  1312. p1.free;
  1313. p1:=cerrornode.create;
  1314. { try to clean up }
  1315. spezcontext.free;
  1316. again:=false;
  1317. end
  1318. else
  1319. begin
  1320. if assigned(p1) then
  1321. begin
  1322. if not assigned(p1.resultdef) then
  1323. do_typecheckpass(p1);
  1324. isclassref:=(p1.resultdef.typ=classrefdef);
  1325. isrecordtype:=(p1.nodetype=typen) and (p1.resultdef.typ=recorddef);
  1326. isobjecttype:=(p1.nodetype=typen) and is_object(p1.resultdef);
  1327. ishelpertype:=is_objectpascal_helper(tdef(sym.owner.defowner)) and
  1328. (p1.nodetype=typen) and
  1329. not is_objectpascal_helper(p1.resultdef)
  1330. {and
  1331. not (cnf_inherited in callflags)};
  1332. end
  1333. else
  1334. begin
  1335. isclassref:=false;
  1336. isrecordtype:=false;
  1337. isobjecttype:=false;
  1338. ishelpertype:=false;
  1339. end;
  1340. if assigned(spezcontext) and not (sym.typ=procsym) then
  1341. internalerror(2015091801);
  1342. { we assume, that only procsyms and varsyms are in an object }
  1343. { symbol table, for classes, properties are allowed }
  1344. case sym.typ of
  1345. procsym:
  1346. begin
  1347. do_proc_call(sym,sym.owner,structh,
  1348. (getaddr and not(token in [_CARET,_POINT])),
  1349. again,p1,callflags,spezcontext);
  1350. { we need to know which procedure is called }
  1351. do_typecheckpass(p1);
  1352. { We are loading... }
  1353. if p1.nodetype=loadn then
  1354. begin
  1355. { an instance method }
  1356. if not (po_classmethod in tloadnode(p1).procdef.procoptions) and
  1357. { into a method pointer (not just taking a code address) }
  1358. not getaddr and
  1359. { and the selfarg is... }
  1360. (
  1361. { either a record/object/helper type, }
  1362. not assigned(tloadnode(p1).left) or
  1363. { or a class/metaclass type, or a class reference }
  1364. (tloadnode(p1).left.resultdef.typ=classrefdef)
  1365. ) then
  1366. Message(parser_e_only_class_members_via_class_ref);
  1367. end
  1368. { calling using classref? }
  1369. else if (
  1370. isclassref or
  1371. (
  1372. (isobjecttype or
  1373. isrecordtype or
  1374. ishelpertype) and
  1375. not (cnf_inherited in callflags)
  1376. )
  1377. ) and
  1378. (p1.nodetype=calln) and
  1379. assigned(tcallnode(p1).procdefinition) then
  1380. begin
  1381. if not isobjecttype then
  1382. begin
  1383. if not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1384. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1385. Message(parser_e_only_class_members_via_class_ref);
  1386. end
  1387. else
  1388. begin
  1389. { with objects, you can also do this:
  1390. type
  1391. tparent = object
  1392. procedure test;
  1393. end;
  1394. tchild = object(tchild)
  1395. procedure test;
  1396. end;
  1397. procedure tparent.test;
  1398. begin
  1399. end;
  1400. procedure tchild.test;
  1401. begin
  1402. tparent.test;
  1403. end;
  1404. }
  1405. if (tcallnode(p1).procdefinition.proctypeoption<>potype_constructor) and
  1406. not(po_staticmethod in tcallnode(p1).procdefinition.procoptions) and
  1407. (not assigned(current_structdef) or
  1408. not def_is_related(current_structdef,structh)) then
  1409. begin
  1410. p1.free;
  1411. p1:=cerrornode.create;
  1412. Message(parser_e_only_static_members_via_object_type);
  1413. exit;
  1414. end;
  1415. end;
  1416. { in Java, constructors are not automatically inherited
  1417. -> calling a constructor from a parent type will create
  1418. an instance of that parent type! }
  1419. if is_javaclass(structh) and
  1420. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1421. (tcallnode(p1).procdefinition.owner.defowner<>find_real_class_definition(tobjectdef(structh),false)) then
  1422. Message(parser_e_java_no_inherited_constructor);
  1423. { Provide a warning if we try to create an instance of a
  1424. abstract class using the type name of that class. We
  1425. must not provide a warning if we use a "class of"
  1426. variable of that type though as we don't know the
  1427. type of the class
  1428. Note: structh might be Nil in case of a type helper }
  1429. if assigned(structh) and
  1430. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1431. (oo_is_abstract in structh.objectoptions) and
  1432. assigned(tcallnode(p1).methodpointer) and
  1433. (tcallnode(p1).methodpointer.nodetype=loadvmtaddrn) then
  1434. Message1(type_w_instance_abstract_class,structh.RttiName);
  1435. end
  1436. end;
  1437. fieldvarsym:
  1438. begin
  1439. if not handle_staticfield_access(sym,p1) then
  1440. begin
  1441. if isclassref then
  1442. if assigned(p1) and
  1443. (
  1444. is_self_node(p1) or
  1445. (assigned(current_procinfo) and (current_procinfo.get_normal_proc.procdef.no_self_node) and
  1446. (current_procinfo.procdef.struct=structh))) then
  1447. Message(parser_e_only_class_members)
  1448. else
  1449. Message(parser_e_only_class_members_via_class_ref);
  1450. p1:=csubscriptnode.create(sym,p1);
  1451. end;
  1452. end;
  1453. propertysym:
  1454. begin
  1455. if isclassref and not (sp_static in sym.symoptions) then
  1456. Message(parser_e_only_class_members_via_class_ref);
  1457. handle_propertysym(tpropertysym(sym),sym.owner,p1);
  1458. end;
  1459. typesym:
  1460. begin
  1461. p1.free;
  1462. if try_to_consume(_LKLAMMER) then
  1463. begin
  1464. p1:=comp_expr([ef_accept_equal]);
  1465. consume(_RKLAMMER);
  1466. p1:=ctypeconvnode.create_explicit(p1,ttypesym(sym).typedef);
  1467. end
  1468. else
  1469. begin
  1470. p1:=ctypenode.create(ttypesym(sym).typedef);
  1471. if (is_class(ttypesym(sym).typedef) or
  1472. is_objcclass(ttypesym(sym).typedef) or
  1473. is_javaclass(ttypesym(sym).typedef)) and
  1474. not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1475. p1:=cloadvmtaddrnode.create(p1);
  1476. end;
  1477. end;
  1478. constsym:
  1479. begin
  1480. p1.free;
  1481. p1:=genconstsymtree(tconstsym(sym));
  1482. end;
  1483. staticvarsym:
  1484. begin
  1485. { typed constant is a staticvarsym
  1486. now they are absolutevarsym }
  1487. p1.free;
  1488. p1:=cloadnode.create(sym,sym.Owner);
  1489. end;
  1490. absolutevarsym:
  1491. begin
  1492. p1.free;
  1493. p1:=nil;
  1494. { typed constants are absolutebarsyms now to handle storage properly }
  1495. propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
  1496. end
  1497. else
  1498. internalerror(16);
  1499. end;
  1500. end;
  1501. end;
  1502. function handle_specialize_inline_specialization(var srsym:tsym;enforce_unit:boolean;out srsymtable:tsymtable;out spezcontext:tspecializationcontext):boolean;
  1503. var
  1504. spezdef : tdef;
  1505. symname : tsymstr;
  1506. begin
  1507. result:=false;
  1508. spezcontext:=nil;
  1509. srsymtable:=nil;
  1510. if not assigned(srsym) then
  1511. message1(sym_e_id_no_member,orgpattern)
  1512. else
  1513. if not (srsym.typ in [typesym,procsym]) then
  1514. message(type_e_type_id_expected)
  1515. else
  1516. begin
  1517. if srsym.typ=typesym then
  1518. spezdef:=ttypesym(srsym).typedef
  1519. else if tprocsym(srsym).procdeflist.count>0 then
  1520. spezdef:=tdef(tprocsym(srsym).procdeflist[0])
  1521. else
  1522. spezdef:=nil;
  1523. if (not assigned(spezdef) or (spezdef.typ=errordef)) and (sp_generic_dummy in srsym.symoptions) then
  1524. symname:=srsym.RealName
  1525. else
  1526. symname:='';
  1527. spezdef:=generate_specialization_phase1(spezcontext,spezdef,enforce_unit,symname,srsym.owner);
  1528. case spezdef.typ of
  1529. errordef:
  1530. begin
  1531. spezcontext.free;
  1532. spezcontext:=nil;
  1533. srsym:=generrorsym;
  1534. end;
  1535. procdef:
  1536. begin
  1537. if block_type<>bt_body then
  1538. begin
  1539. message(parser_e_illegal_expression);
  1540. spezcontext.free;
  1541. spezcontext:=nil;
  1542. srsym:=generrorsym;
  1543. end
  1544. else
  1545. begin
  1546. srsym:=tprocdef(spezdef).procsym;
  1547. srsymtable:=srsym.owner;
  1548. result:=true;
  1549. end;
  1550. end;
  1551. objectdef,
  1552. recorddef,
  1553. arraydef,
  1554. procvardef:
  1555. begin
  1556. spezdef:=generate_specialization_phase2(spezcontext,tstoreddef(spezdef),false,'');
  1557. spezcontext.free;
  1558. spezcontext:=nil;
  1559. if spezdef<>generrordef then
  1560. begin
  1561. srsym:=spezdef.typesym;
  1562. srsymtable:=srsym.owner;
  1563. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1564. result:=true;
  1565. end;
  1566. end;
  1567. else
  1568. internalerror(2015070302);
  1569. end;
  1570. end;
  1571. end;
  1572. function handle_factor_typenode(hdef:tdef;getaddr:boolean;var again:boolean;sym:tsym;typeonly:boolean):tnode;
  1573. var
  1574. srsym : tsym;
  1575. srsymtable : tsymtable;
  1576. erroroutresult,
  1577. isspecialize : boolean;
  1578. spezcontext : tspecializationcontext;
  1579. savedfilepos : tfileposinfo;
  1580. begin
  1581. spezcontext:=nil;
  1582. if sym=nil then
  1583. sym:=hdef.typesym;
  1584. { allow Ordinal(Value) for type declarations since it
  1585. can be an enummeration declaration or a set lke:
  1586. (OrdinalType(const1)..OrdinalType(const2) }
  1587. if (not typeonly or is_ordinal(hdef)) and
  1588. try_to_consume(_LKLAMMER) then
  1589. begin
  1590. result:=comp_expr([ef_accept_equal]);
  1591. consume(_RKLAMMER);
  1592. { type casts to class helpers aren't allowed }
  1593. if is_objectpascal_helper(hdef) then
  1594. Message(parser_e_no_category_as_types)
  1595. { recovery by not creating a conversion node }
  1596. else
  1597. result:=ctypeconvnode.create_explicit(result,hdef);
  1598. end
  1599. { not LKLAMMER }
  1600. else if (token=_POINT) and
  1601. (is_object(hdef) or is_record(hdef)) then
  1602. begin
  1603. consume(_POINT);
  1604. { handles calling methods declared in parent objects
  1605. using "parentobject.methodname()" }
  1606. if assigned(current_structdef) and
  1607. not(getaddr) and
  1608. def_is_related(current_structdef,hdef) then
  1609. begin
  1610. result:=ctypenode.create(hdef);
  1611. ttypenode(result).typesym:=sym;
  1612. if not (m_delphi in current_settings.modeswitches) and
  1613. (block_type in inline_specialization_block_types) and
  1614. (token=_ID) and
  1615. (idtoken=_SPECIALIZE) then
  1616. begin
  1617. consume(_ID);
  1618. if token<>_ID then
  1619. message(type_e_type_id_expected);
  1620. isspecialize:=true;
  1621. end
  1622. else
  1623. isspecialize:=false;
  1624. { search also in inherited methods }
  1625. searchsym_in_class(tobjectdef(hdef),tobjectdef(current_structdef),pattern,srsym,srsymtable,[ssf_search_helper]);
  1626. if isspecialize then
  1627. begin
  1628. consume(_ID);
  1629. if not handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  1630. begin
  1631. result.free;
  1632. result:=cerrornode.create;
  1633. end;
  1634. end
  1635. else
  1636. begin
  1637. if assigned(srsym) then
  1638. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1639. consume(_ID);
  1640. end;
  1641. if result.nodetype<>errorn then
  1642. do_member_read(tabstractrecorddef(hdef),false,srsym,result,again,[],spezcontext)
  1643. else
  1644. spezcontext.free;
  1645. end
  1646. else
  1647. begin
  1648. { handles:
  1649. * @TObject.Load
  1650. * static methods and variables }
  1651. result:=ctypenode.create(hdef);
  1652. ttypenode(result).typesym:=sym;
  1653. if not (m_delphi in current_settings.modeswitches) and
  1654. (block_type in inline_specialization_block_types) and
  1655. (token=_ID) and
  1656. (idtoken=_SPECIALIZE) then
  1657. begin
  1658. consume(_ID);
  1659. if token<>_ID then
  1660. message(type_e_type_id_expected);
  1661. isspecialize:=true;
  1662. end
  1663. else
  1664. isspecialize:=false;
  1665. erroroutresult:=true;
  1666. { TP allows also @TMenu.Load if Load is only }
  1667. { defined in an anchestor class }
  1668. srsym:=search_struct_member(tabstractrecorddef(hdef),pattern);
  1669. if isspecialize and assigned(srsym) then
  1670. begin
  1671. consume(_ID);
  1672. if handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  1673. erroroutresult:=false;
  1674. end
  1675. else
  1676. begin
  1677. if assigned(srsym) then
  1678. begin
  1679. savedfilepos:=current_filepos;
  1680. consume(_ID);
  1681. if not (sp_generic_dummy in srsym.symoptions) or
  1682. not (token in [_LT,_LSHARPBRACKET]) then
  1683. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,savedfilepos)
  1684. else
  1685. result:=cspecializenode.create(result,getaddr,srsym,false);
  1686. erroroutresult:=false;
  1687. end
  1688. else
  1689. Message1(sym_e_id_no_member,orgpattern);
  1690. end;
  1691. if erroroutresult then
  1692. begin
  1693. result.free;
  1694. result:=cerrornode.create;
  1695. end
  1696. else
  1697. if result.nodetype<>specializen then
  1698. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],spezcontext);
  1699. end;
  1700. end
  1701. else
  1702. begin
  1703. { Normally here would be the check against the usage
  1704. of "TClassHelper.Something", but as that might be
  1705. used inside of system symbols like sizeof and
  1706. typeinfo this check is put into ttypenode.pass_1
  1707. (for "TClassHelper" alone) and tcallnode.pass_1
  1708. (for "TClassHelper.Something") }
  1709. { class reference ? }
  1710. if is_class(hdef) or
  1711. is_objcclass(hdef) or
  1712. { Java interfaces also can have loadvmtaddrnodes,
  1713. e.g. for expressions such as JLClass(intftype) }
  1714. is_java_class_or_interface(hdef) then
  1715. begin
  1716. if getaddr and (token=_POINT) and
  1717. not is_javainterface(hdef) then
  1718. begin
  1719. consume(_POINT);
  1720. { allows @Object.Method }
  1721. { also allows static methods and variables }
  1722. result:=ctypenode.create(hdef);
  1723. ttypenode(result).typesym:=sym;
  1724. { TP allows also @TMenu.Load if Load is only }
  1725. { defined in an anchestor class }
  1726. srsym:=search_struct_member(tobjectdef(hdef),pattern);
  1727. if assigned(srsym) then
  1728. begin
  1729. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1730. consume(_ID);
  1731. { in case of @Object.Method1.Method2, we have to call
  1732. Method1 -> create a loadvmtaddr node as self instead of
  1733. a typen (the typenode would be changed to self of the
  1734. current method in case Method1 is a constructor, see
  1735. mantis #24844) }
  1736. if not(block_type in [bt_type,bt_const_type,bt_var_type]) and
  1737. (srsym.typ=procsym) and
  1738. (token in [_CARET,_POINT]) then
  1739. result:=cloadvmtaddrnode.create(result);
  1740. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil);
  1741. end
  1742. else
  1743. begin
  1744. Message1(sym_e_id_no_member,orgpattern);
  1745. consume(_ID);
  1746. end;
  1747. end
  1748. else
  1749. begin
  1750. result:=ctypenode.create(hdef);
  1751. ttypenode(result).typesym:=sym;
  1752. { For a type block we simply return only
  1753. the type. For all other blocks we return
  1754. a loadvmt node }
  1755. if not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1756. result:=cloadvmtaddrnode.create(result);
  1757. end;
  1758. end
  1759. else
  1760. begin
  1761. result:=ctypenode.create(hdef);
  1762. ttypenode(result).typesym:=sym;
  1763. end;
  1764. end;
  1765. end;
  1766. {****************************************************************************
  1767. Factor
  1768. ****************************************************************************}
  1769. function real_const_node_from_pattern(const s:string):tnode;
  1770. var
  1771. d : bestreal;
  1772. code : integer;
  1773. cur : currency;
  1774. begin
  1775. val(s,d,code);
  1776. if code<>0 then
  1777. begin
  1778. Message(parser_e_error_in_real);
  1779. d:=1.0;
  1780. end;
  1781. if current_settings.fputype=fpu_none then
  1782. begin
  1783. Message(parser_e_unsupported_real);
  1784. result:=cerrornode.create;
  1785. exit;
  1786. end;
  1787. if (current_settings.minfpconstprec=s32real) and
  1788. (d = single(d)) then
  1789. result:=crealconstnode.create(d,s32floattype)
  1790. else if (current_settings.minfpconstprec=s64real) and
  1791. (d = double(d)) then
  1792. result:=crealconstnode.create(d,s64floattype)
  1793. else
  1794. result:=crealconstnode.create(d,pbestrealtype^);
  1795. val(pattern,cur,code);
  1796. if code=0 then
  1797. trealconstnode(result).value_currency:=cur;
  1798. end;
  1799. {---------------------------------------------
  1800. PostFixOperators
  1801. ---------------------------------------------}
  1802. { returns whether or not p1 has been changed }
  1803. function postfixoperators(var p1:tnode;var again:boolean;getaddr:boolean): boolean;
  1804. { tries to avoid syntax errors after invalid qualifiers }
  1805. procedure recoverconsume_postfixops;
  1806. begin
  1807. repeat
  1808. if not try_to_consume(_CARET) then
  1809. if try_to_consume(_POINT) then
  1810. try_to_consume(_ID)
  1811. else if try_to_consume(_LECKKLAMMER) then
  1812. begin
  1813. repeat
  1814. comp_expr([ef_accept_equal]);
  1815. until not try_to_consume(_COMMA);
  1816. consume(_RECKKLAMMER);
  1817. end
  1818. else if try_to_consume(_LKLAMMER) then
  1819. begin
  1820. repeat
  1821. comp_expr([ef_accept_equal]);
  1822. until not try_to_consume(_COMMA);
  1823. consume(_RKLAMMER);
  1824. end
  1825. else
  1826. break;
  1827. until false;
  1828. end;
  1829. procedure handle_variantarray;
  1830. var
  1831. p4 : tnode;
  1832. newstatement : tstatementnode;
  1833. tempresultvariant,
  1834. temp : ttempcreatenode;
  1835. paras : tcallparanode;
  1836. newblock : tnode;
  1837. countindices : longint;
  1838. elements: tfplist;
  1839. arraydef: tdef;
  1840. begin
  1841. { create statements with call initialize the arguments and
  1842. call fpc_dynarr_setlength }
  1843. newblock:=internalstatements(newstatement);
  1844. { store all indices in a temporary array }
  1845. countindices:=0;
  1846. elements:=tfplist.Create;
  1847. repeat
  1848. p4:=comp_expr([ef_accept_equal]);
  1849. elements.add(p4);
  1850. until not try_to_consume(_COMMA);
  1851. arraydef:=carraydef.getreusable(s32inttype,elements.count);
  1852. temp:=ctempcreatenode.create(arraydef,arraydef.size,tt_persistent,false);
  1853. addstatement(newstatement,temp);
  1854. for countindices:=0 to elements.count-1 do
  1855. begin
  1856. addstatement(newstatement,
  1857. cassignmentnode.create(
  1858. cvecnode.create(
  1859. ctemprefnode.create(temp),
  1860. genintconstnode(countindices)
  1861. ),
  1862. tnode(elements[countindices])
  1863. )
  1864. );
  1865. end;
  1866. countindices:=elements.count;
  1867. elements.free;
  1868. consume(_RECKKLAMMER);
  1869. { we need only a write access if a := follows }
  1870. if token=_ASSIGNMENT then
  1871. begin
  1872. consume(_ASSIGNMENT);
  1873. p4:=comp_expr([ef_accept_equal]);
  1874. { create call to fpc_vararray_put }
  1875. paras:=ccallparanode.create(cordconstnode.create
  1876. (countindices,s32inttype,true),
  1877. ccallparanode.create(caddrnode.create_internal
  1878. (cvecnode.create(ctemprefnode.create(temp),genintconstnode(0))),
  1879. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1880. ccallparanode.create(ctypeconvnode.create_internal(p1,cvarianttype)
  1881. ,nil))));
  1882. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1883. addstatement(newstatement,ctempdeletenode.create(temp));
  1884. end
  1885. else
  1886. begin
  1887. { create temp for result }
  1888. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.size,tt_persistent,true);
  1889. addstatement(newstatement,tempresultvariant);
  1890. { create call to fpc_vararray_get }
  1891. paras:=ccallparanode.create(cordconstnode.create
  1892. (countindices,s32inttype,true),
  1893. ccallparanode.create(caddrnode.create_internal
  1894. (ctemprefnode.create(temp)),
  1895. ccallparanode.create(p1,
  1896. ccallparanode.create(
  1897. ctemprefnode.create(tempresultvariant)
  1898. ,nil))));
  1899. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1900. addstatement(newstatement,ctempdeletenode.create(temp));
  1901. { the last statement should return the value as
  1902. location and type, this is done be referencing the
  1903. temp and converting it first from a persistent temp to
  1904. normal temp }
  1905. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1906. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1907. end;
  1908. p1:=newblock;
  1909. end;
  1910. function parse_array_constructor(arrdef:tarraydef): tnode;
  1911. var
  1912. newstatement,assstatement:tstatementnode;
  1913. arrnode:ttempcreatenode;
  1914. temp2:ttempcreatenode;
  1915. assnode:tnode;
  1916. paracount:integer;
  1917. begin
  1918. result:=internalstatements(newstatement);
  1919. { create temp for result }
  1920. arrnode:=ctempcreatenode.create(arrdef,arrdef.size,tt_persistent,true);
  1921. addstatement(newstatement,arrnode);
  1922. paracount:=0;
  1923. { check arguments and create an assignment calls }
  1924. if try_to_consume(_LKLAMMER) then
  1925. begin
  1926. assnode:=internalstatements(assstatement);
  1927. repeat
  1928. { arr[i] := param_i }
  1929. addstatement(assstatement,
  1930. cassignmentnode.create(
  1931. cvecnode.create(
  1932. ctemprefnode.create(arrnode),
  1933. cordconstnode.create(paracount,arrdef.rangedef,false)),
  1934. comp_expr([ef_accept_equal])));
  1935. inc(paracount);
  1936. until not try_to_consume(_COMMA);
  1937. consume(_RKLAMMER);
  1938. end
  1939. else
  1940. assnode:=nil;
  1941. { get temp for array of lengths }
  1942. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1943. addstatement(newstatement,temp2);
  1944. { one dimensional }
  1945. addstatement(newstatement,cassignmentnode.create(
  1946. ctemprefnode.create(temp2),
  1947. cordconstnode.create
  1948. (paracount,s32inttype,true)));
  1949. { create call to fpc_dynarr_setlength }
  1950. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1951. ccallparanode.create(caddrnode.create_internal
  1952. (ctemprefnode.create(temp2)),
  1953. ccallparanode.create(cordconstnode.create
  1954. (1,s32inttype,true),
  1955. ccallparanode.create(caddrnode.create_internal
  1956. (crttinode.create(tstoreddef(arrdef),initrtti,rdt_normal)),
  1957. ccallparanode.create(
  1958. ctypeconvnode.create_internal(
  1959. ctemprefnode.create(arrnode),voidpointertype),
  1960. nil))))
  1961. ));
  1962. { add assignment statememnts }
  1963. addstatement(newstatement,ctempdeletenode.create(temp2));
  1964. if assigned(assnode) then
  1965. addstatement(newstatement,assnode);
  1966. { the last statement should return the value as
  1967. location and type, this is done be referencing the
  1968. temp and converting it first from a persistent temp to
  1969. normal temp }
  1970. addstatement(newstatement,ctempdeletenode.create_normal_temp(arrnode));
  1971. addstatement(newstatement,ctemprefnode.create(arrnode));
  1972. end;
  1973. function try_type_helper(var node:tnode;def:tdef):boolean;
  1974. var
  1975. srsym : tsym;
  1976. srsymtable : tsymtable;
  1977. n : tnode;
  1978. newstatement : tstatementnode;
  1979. temp : ttempcreatenode;
  1980. extdef : tdef;
  1981. begin
  1982. result:=false;
  1983. if (token=_ID) and (block_type in [bt_body,bt_general,bt_except,bt_const]) then
  1984. begin
  1985. if not assigned(def) then
  1986. if node.nodetype=addrn then
  1987. { always use the pointer type for addr nodes as otherwise
  1988. we'll have an anonymous pointertype with no name }
  1989. def:=voidpointertype
  1990. else
  1991. def:=node.resultdef;
  1992. result:=search_objectpascal_helper(def,nil,pattern,srsym,srsymtable);
  1993. if result then
  1994. begin
  1995. if not (srsymtable.symtabletype=objectsymtable) or
  1996. not is_objectpascal_helper(tdef(srsymtable.defowner)) then
  1997. internalerror(2013011401);
  1998. { convert const node to temp node of the extended type }
  1999. if node.nodetype in (nodetype_const+[addrn]) then
  2000. begin
  2001. extdef:=tobjectdef(srsymtable.defowner).extendeddef;
  2002. newstatement:=nil;
  2003. n:=internalstatements(newstatement);
  2004. temp:=ctempcreatenode.create(extdef,extdef.size,tt_persistent,false);
  2005. addstatement(newstatement,temp);
  2006. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),node));
  2007. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2008. addstatement(newstatement,ctemprefnode.create(temp));
  2009. node:=n;
  2010. do_typecheckpass(node)
  2011. end;
  2012. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2013. consume(_ID);
  2014. do_member_read(nil,getaddr,srsym,node,again,[],nil);
  2015. end;
  2016. end;
  2017. end;
  2018. var
  2019. protsym : tpropertysym;
  2020. p2,p3 : tnode;
  2021. srsym : tsym;
  2022. srsymtable : TSymtable;
  2023. structh : tabstractrecorddef;
  2024. { shouldn't be used that often, so the extra overhead is ok to save
  2025. stack space }
  2026. dispatchstring : ansistring;
  2027. autoderef,
  2028. erroroutp1,
  2029. allowspecialize,
  2030. isspecialize,
  2031. found,
  2032. haderror,
  2033. nodechanged : boolean;
  2034. calltype: tdispcalltype;
  2035. valstr,expstr : string;
  2036. intval : qword;
  2037. code : integer;
  2038. strdef : tdef;
  2039. spezcontext : tspecializationcontext;
  2040. old_current_filepos : tfileposinfo;
  2041. label
  2042. skipreckklammercheck,
  2043. skippointdefcheck;
  2044. begin
  2045. result:=false;
  2046. again:=true;
  2047. while again do
  2048. begin
  2049. spezcontext:=nil;
  2050. { we need the resultdef }
  2051. do_typecheckpass_changed(p1,nodechanged);
  2052. result:=result or nodechanged;
  2053. if codegenerror then
  2054. begin
  2055. recoverconsume_postfixops;
  2056. exit;
  2057. end;
  2058. { handle token }
  2059. case token of
  2060. _CARET:
  2061. begin
  2062. consume(_CARET);
  2063. { support in tp/mac procvar mode procvar^ if the procvar returns a
  2064. pointer type }
  2065. if ((m_tp_procvar in current_settings.modeswitches) or
  2066. (m_mac_procvar in current_settings.modeswitches)) and
  2067. (p1.resultdef.typ=procvardef) and
  2068. (tprocvardef(p1.resultdef).returndef.typ=pointerdef) then
  2069. begin
  2070. p1:=ccallnode.create_procvar(nil,p1);
  2071. typecheckpass(p1);
  2072. end;
  2073. { iso file buf access? }
  2074. if (m_isolike_io in current_settings.modeswitches) and
  2075. (p1.resultdef.typ=filedef) then
  2076. begin
  2077. case tfiledef(p1.resultdef).filetyp of
  2078. ft_text:
  2079. begin
  2080. p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf_text',ccallparanode.create(p1,nil)));
  2081. typecheckpass(p1);
  2082. end;
  2083. ft_typed:
  2084. begin
  2085. p1:=cderefnode.create(ctypeconvnode.create_internal(ccallnode.createintern('fpc_getbuf_typedfile',ccallparanode.create(p1,nil)),
  2086. cpointerdef.getreusable(tfiledef(p1.resultdef).typedfiledef)));
  2087. typecheckpass(p1);
  2088. end;
  2089. else
  2090. internalerror(2019050530);
  2091. end;
  2092. end
  2093. else if not(p1.resultdef.typ in [pointerdef,undefineddef]) then
  2094. begin
  2095. { ^ as binary operator is a problem!!!! (FK) }
  2096. again:=false;
  2097. Message(parser_e_invalid_qualifier);
  2098. recoverconsume_postfixops;
  2099. p1.destroy;
  2100. p1:=cerrornode.create;
  2101. end
  2102. else
  2103. p1:=cderefnode.create(p1);
  2104. end;
  2105. _LECKKLAMMER:
  2106. begin
  2107. { support in tp/mac procvar mode procvar[] if the procvar returns an
  2108. array type }
  2109. if ((m_tp_procvar in current_settings.modeswitches) or
  2110. (m_mac_procvar in current_settings.modeswitches)) and
  2111. (p1.resultdef.typ=procvardef) and
  2112. (tprocvardef(p1.resultdef).returndef.typ=arraydef) then
  2113. begin
  2114. p1:=ccallnode.create_procvar(nil,p1);
  2115. typecheckpass(p1);
  2116. end;
  2117. if is_class_or_interface_or_object(p1.resultdef) or
  2118. is_dispinterface(p1.resultdef) or
  2119. is_record(p1.resultdef) or
  2120. is_javaclass(p1.resultdef) then
  2121. begin
  2122. { default property }
  2123. protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
  2124. if not(assigned(protsym)) then
  2125. begin
  2126. p1.destroy;
  2127. p1:=cerrornode.create;
  2128. again:=false;
  2129. message(parser_e_no_default_property_available);
  2130. end
  2131. else
  2132. begin
  2133. { The property symbol is referenced indirect }
  2134. protsym.IncRefCount;
  2135. handle_propertysym(protsym,protsym.owner,p1);
  2136. end;
  2137. end
  2138. else
  2139. begin
  2140. consume(_LECKKLAMMER);
  2141. repeat
  2142. { in all of the cases below, p1 is changed }
  2143. case p1.resultdef.typ of
  2144. pointerdef:
  2145. begin
  2146. { support delphi autoderef }
  2147. if (tpointerdef(p1.resultdef).pointeddef.typ=arraydef) and
  2148. (m_autoderef in current_settings.modeswitches) then
  2149. p1:=cderefnode.create(p1);
  2150. p2:=comp_expr([ef_accept_equal]);
  2151. { Support Pbytevar[0..9] which returns array [0..9].}
  2152. if try_to_consume(_POINTPOINT) then
  2153. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2154. p1:=cvecnode.create(p1,p2);
  2155. end;
  2156. variantdef:
  2157. begin
  2158. handle_variantarray;
  2159. { the RECKKLAMMER is already read }
  2160. goto skipreckklammercheck;
  2161. end;
  2162. stringdef :
  2163. begin
  2164. p2:=comp_expr([ef_accept_equal]);
  2165. { Support string[0..9] which returns array [0..9] of char.}
  2166. if try_to_consume(_POINTPOINT) then
  2167. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2168. p1:=cvecnode.create(p1,p2);
  2169. end;
  2170. arraydef:
  2171. begin
  2172. p2:=comp_expr([ef_accept_equal]);
  2173. { support SEG:OFS for go32v2/msdos Mem[] }
  2174. if (target_info.system in [system_i386_go32v2,system_i386_watcom,system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  2175. (p1.nodetype=loadn) and
  2176. assigned(tloadnode(p1).symtableentry) and
  2177. assigned(tloadnode(p1).symtableentry.owner.name) and
  2178. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  2179. ((tloadnode(p1).symtableentry.name='MEM') or
  2180. (tloadnode(p1).symtableentry.name='MEMW') or
  2181. (tloadnode(p1).symtableentry.name='MEML')) then
  2182. begin
  2183. {$if defined(i8086)}
  2184. consume(_COLON);
  2185. inserttypeconv(p2,u16inttype);
  2186. inserttypeconv_internal(p2,u32inttype);
  2187. p3:=cshlshrnode.create(shln,p2,cordconstnode.create($10,s16inttype,false));
  2188. p2:=comp_expr([ef_accept_equal]);
  2189. inserttypeconv(p2,u16inttype);
  2190. inserttypeconv_internal(p2,u32inttype);
  2191. p2:=caddnode.create(addn,p2,p3);
  2192. case tloadnode(p1).symtableentry.name of
  2193. 'MEM': p2:=ctypeconvnode.create_internal(p2,bytefarpointertype);
  2194. 'MEMW': p2:=ctypeconvnode.create_internal(p2,wordfarpointertype);
  2195. 'MEML': p2:=ctypeconvnode.create_internal(p2,longintfarpointertype);
  2196. else
  2197. internalerror(2013053102);
  2198. end;
  2199. p1:=cderefnode.create(p2);
  2200. {$elseif defined(i386)}
  2201. if try_to_consume(_COLON) then
  2202. begin
  2203. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  2204. p2:=comp_expr([ef_accept_equal]);
  2205. p2:=caddnode.create(addn,p2,p3);
  2206. if try_to_consume(_POINTPOINT) then
  2207. { Support mem[$a000:$0000..$07ff] which returns array [0..$7ff] of memtype.}
  2208. p2:=crangenode.create(p2,caddnode.create(addn,comp_expr([ef_accept_equal]),p3.getcopy));
  2209. p1:=cvecnode.create(p1,p2);
  2210. include(tvecnode(p1).flags,nf_memseg);
  2211. include(tvecnode(p1).flags,nf_memindex);
  2212. end
  2213. else
  2214. begin
  2215. if try_to_consume(_POINTPOINT) then
  2216. { Support mem[$80000000..$80000002] which returns array [0..2] of memtype.}
  2217. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2218. p1:=cvecnode.create(p1,p2);
  2219. include(tvecnode(p1).flags,nf_memindex);
  2220. end;
  2221. {$else}
  2222. internalerror(2013053105);
  2223. {$endif}
  2224. end
  2225. else
  2226. begin
  2227. if try_to_consume(_POINTPOINT) then
  2228. { Support arrayvar[0..9] which returns array [0..9] of arraytype.}
  2229. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2230. p1:=cvecnode.create(p1,p2);
  2231. end;
  2232. end;
  2233. else
  2234. begin
  2235. if p1.resultdef.typ<>undefineddef then
  2236. Message(parser_e_invalid_qualifier);
  2237. p1.destroy;
  2238. p1:=cerrornode.create;
  2239. comp_expr([ef_accept_equal]);
  2240. again:=false;
  2241. end;
  2242. end;
  2243. do_typecheckpass(p1);
  2244. until not try_to_consume(_COMMA);
  2245. consume(_RECKKLAMMER);
  2246. { handle_variantarray eats the RECKKLAMMER and jumps here }
  2247. skipreckklammercheck:
  2248. end;
  2249. end;
  2250. _POINT :
  2251. begin
  2252. consume(_POINT);
  2253. allowspecialize:=not (m_delphi in current_settings.modeswitches) and (block_type in inline_specialization_block_types);
  2254. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  2255. begin
  2256. //consume(_ID);
  2257. isspecialize:=true;
  2258. end
  2259. else
  2260. isspecialize:=false;
  2261. autoderef:=false;
  2262. if (p1.resultdef.typ=pointerdef) and
  2263. (m_autoderef in current_settings.modeswitches) and
  2264. { don't auto-deref objc.id, because then the code
  2265. below for supporting id.anyobjcmethod isn't triggered }
  2266. (p1.resultdef<>objc_idtype) then
  2267. begin
  2268. p1:=cderefnode.create(p1);
  2269. do_typecheckpass(p1);
  2270. autoderef:=true;
  2271. end;
  2272. { procvar.<something> can never mean anything so always
  2273. try to call it in case it returns a record/object/... }
  2274. maybe_call_procvar(p1,is_invokable(p1.resultdef) and not is_funcref(p1.resultdef));
  2275. if (p1.nodetype=ordconstn) and
  2276. not is_boolean(p1.resultdef) and
  2277. not is_enum(p1.resultdef) then
  2278. begin
  2279. { type helpers are checked first }
  2280. if (token=_ID) and try_type_helper(p1,nil) then
  2281. goto skippointdefcheck;
  2282. { only an "e" or "E" can follow an intconst with a ".", the
  2283. other case (another intconst) is handled by the scanner }
  2284. if (token=_ID) and (pattern[1]='E') then
  2285. begin
  2286. haderror:=false;
  2287. if length(pattern)>1 then
  2288. begin
  2289. expstr:=copy(pattern,2,length(pattern)-1);
  2290. val(expstr,intval,code);
  2291. if code<>0 then
  2292. begin
  2293. haderror:=true;
  2294. intval:=intval; // Hackfix the "var assigned but never used" note.
  2295. end;
  2296. end
  2297. else
  2298. expstr:='';
  2299. consume(token);
  2300. if tordconstnode(p1).value.signed then
  2301. str(tordconstnode(p1).value.svalue,valstr)
  2302. else
  2303. str(tordconstnode(p1).value.uvalue,valstr);
  2304. valstr:=valstr+'.0E';
  2305. if expstr='' then
  2306. case token of
  2307. _MINUS:
  2308. begin
  2309. consume(token);
  2310. if token=_INTCONST then
  2311. begin
  2312. valstr:=valstr+'-'+pattern;
  2313. consume(token);
  2314. end
  2315. else
  2316. haderror:=true;
  2317. end;
  2318. _PLUS:
  2319. begin
  2320. consume(token);
  2321. if token=_INTCONST then
  2322. begin
  2323. valstr:=valstr+pattern;
  2324. consume(token);
  2325. end
  2326. else
  2327. haderror:=true;
  2328. end;
  2329. _INTCONST:
  2330. begin
  2331. valstr:=valstr+pattern;
  2332. consume(_INTCONST);
  2333. end;
  2334. else
  2335. haderror:=true;
  2336. end
  2337. else
  2338. valstr:=valstr+expstr;
  2339. if haderror then
  2340. begin
  2341. Message(parser_e_error_in_real);
  2342. p2:=cerrornode.create;
  2343. end
  2344. else
  2345. p2:=real_const_node_from_pattern(valstr);
  2346. p1.free;
  2347. p1:=p2;
  2348. again:=false;
  2349. goto skippointdefcheck;
  2350. end
  2351. else
  2352. begin
  2353. { just convert the ordconst to a realconst }
  2354. p2:=crealconstnode.create(tordconstnode(p1).value,pbestrealtype^);
  2355. p1.free;
  2356. p1:=p2;
  2357. again:=false;
  2358. goto skippointdefcheck;
  2359. end;
  2360. end;
  2361. if (p1.nodetype=stringconstn) and (token=_ID) then
  2362. begin
  2363. strdef:=nil;
  2364. { the def of a string const is an array }
  2365. case tstringconstnode(p1).cst_type of
  2366. cst_conststring:
  2367. if cs_refcountedstrings in current_settings.localswitches then
  2368. if m_default_unicodestring in current_settings.modeswitches then
  2369. strdef:=cunicodestringtype
  2370. else
  2371. strdef:=cansistringtype
  2372. else
  2373. strdef:=cshortstringtype;
  2374. cst_shortstring:
  2375. strdef:=cshortstringtype;
  2376. cst_ansistring:
  2377. { use getansistringdef? }
  2378. strdef:=cansistringtype;
  2379. cst_widestring:
  2380. strdef:=cwidestringtype;
  2381. cst_unicodestring:
  2382. strdef:=cunicodestringtype;
  2383. cst_longstring:
  2384. { let's see when someone stumbles upon this...}
  2385. internalerror(201301111);
  2386. end;
  2387. if try_type_helper(p1,strdef) then
  2388. goto skippointdefcheck;
  2389. end;
  2390. { this is skipped if label skippointdefcheck is used }
  2391. case p1.resultdef.typ of
  2392. recorddef:
  2393. begin
  2394. if isspecialize or (token=_ID) then
  2395. begin
  2396. erroroutp1:=true;
  2397. srsym:=nil;
  2398. structh:=tabstractrecorddef(p1.resultdef);
  2399. if isspecialize then
  2400. begin
  2401. { consume the specialize }
  2402. consume(_ID);
  2403. if token<>_ID then
  2404. consume(_ID)
  2405. else
  2406. begin
  2407. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2408. consume(_ID);
  2409. if handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  2410. erroroutp1:=false;
  2411. end;
  2412. end
  2413. else
  2414. begin
  2415. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2416. if assigned(srsym) then
  2417. begin
  2418. old_current_filepos:=current_filepos;
  2419. consume(_ID);
  2420. if not (sp_generic_dummy in srsym.symoptions) or
  2421. not (token in [_LT,_LSHARPBRACKET]) then
  2422. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2423. else
  2424. p1:=cspecializenode.create(p1,getaddr,srsym,false);
  2425. erroroutp1:=false;
  2426. end
  2427. else
  2428. begin
  2429. Message1(sym_e_id_no_member,orgpattern);
  2430. { try to clean up }
  2431. consume(_ID);
  2432. end;
  2433. end;
  2434. if erroroutp1 then
  2435. begin
  2436. p1.free;
  2437. p1:=cerrornode.create;
  2438. end
  2439. else
  2440. if p1.nodetype<>specializen then
  2441. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2442. end
  2443. else
  2444. consume(_ID);
  2445. end;
  2446. enumdef:
  2447. begin
  2448. if token=_ID then
  2449. begin
  2450. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  2451. if assigned(srsym) and (srsym.typ=enumsym) and (p1.nodetype=typen) then
  2452. begin
  2453. p1.destroy;
  2454. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2455. p1:=genenumnode(tenumsym(srsym));
  2456. consume(_ID);
  2457. end
  2458. else
  2459. if not try_type_helper(p1,nil) then
  2460. begin
  2461. p1.destroy;
  2462. Message1(sym_e_id_no_member,orgpattern);
  2463. p1:=cerrornode.create;
  2464. consume(_ID);
  2465. end;
  2466. end;
  2467. end;
  2468. arraydef:
  2469. begin
  2470. if is_dynamic_array(p1.resultdef) then
  2471. begin
  2472. if token=_ID then
  2473. begin
  2474. if not try_type_helper(p1,nil) then
  2475. begin
  2476. if p1.nodetype=typen then
  2477. begin
  2478. if pattern='CREATE' then
  2479. begin
  2480. consume(_ID);
  2481. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  2482. p1.destroy;
  2483. p1:=p2;
  2484. end
  2485. else
  2486. begin
  2487. Message2(scan_f_syn_expected,'CREATE',pattern);
  2488. p1.destroy;
  2489. p1:=cerrornode.create;
  2490. consume(_ID);
  2491. end;
  2492. end
  2493. else
  2494. begin
  2495. Message(parser_e_invalid_qualifier);
  2496. p1.destroy;
  2497. p1:=cerrornode.create;
  2498. consume(_ID);
  2499. end;
  2500. end;
  2501. end
  2502. else
  2503. begin
  2504. Message(parser_e_invalid_qualifier);
  2505. p1.destroy;
  2506. p1:=cerrornode.create;
  2507. consume(_ID);
  2508. end;
  2509. end
  2510. else
  2511. if (token<>_ID) or not try_type_helper(p1,nil) then
  2512. begin
  2513. Message(parser_e_invalid_qualifier);
  2514. p1.destroy;
  2515. p1:=cerrornode.create;
  2516. consume(_ID);
  2517. end;
  2518. end;
  2519. variantdef:
  2520. begin
  2521. { dispatch call? }
  2522. { lhs := v.ident[parameters] -> property get
  2523. lhs := v.ident(parameters) -> method call
  2524. v.ident[parameters] := rhs -> property put
  2525. v.ident(parameters) := rhs -> also property put }
  2526. if token=_ID then
  2527. begin
  2528. if not try_type_helper(p1,nil) then
  2529. begin
  2530. dispatchstring:=orgpattern;
  2531. consume(_ID);
  2532. calltype:=dct_method;
  2533. if try_to_consume(_LKLAMMER) then
  2534. begin
  2535. p2:=parse_paras(false,true,_RKLAMMER);
  2536. consume(_RKLAMMER);
  2537. end
  2538. else if try_to_consume(_LECKKLAMMER) then
  2539. begin
  2540. p2:=parse_paras(false,true,_RECKKLAMMER);
  2541. consume(_RECKKLAMMER);
  2542. calltype:=dct_propget;
  2543. end
  2544. else
  2545. p2:=nil;
  2546. { property setter? }
  2547. if (token=_ASSIGNMENT) and not(afterassignment) then
  2548. begin
  2549. consume(_ASSIGNMENT);
  2550. { read the expression }
  2551. p3:=comp_expr([ef_accept_equal]);
  2552. { concat value parameter too }
  2553. p2:=ccallparanode.create(p3,p2);
  2554. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  2555. end
  2556. else
  2557. { this is only an approximation
  2558. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  2559. if afterassignment or in_args or (token<>_SEMICOLON) then
  2560. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  2561. else
  2562. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  2563. end;
  2564. end
  2565. else { Error }
  2566. Consume(_ID);
  2567. end;
  2568. classrefdef:
  2569. begin
  2570. erroroutp1:=true;
  2571. if token=_ID then
  2572. begin
  2573. srsym:=nil;
  2574. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  2575. if isspecialize then
  2576. begin
  2577. { consume the specialize }
  2578. consume(_ID);
  2579. if token<>_ID then
  2580. consume(_ID)
  2581. else
  2582. begin
  2583. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2584. consume(_ID);
  2585. if handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  2586. erroroutp1:=false;
  2587. end;
  2588. end
  2589. else
  2590. begin
  2591. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2592. if assigned(srsym) then
  2593. begin
  2594. old_current_filepos:=current_filepos;
  2595. consume(_ID);
  2596. if not (sp_generic_dummy in srsym.symoptions) or
  2597. not (token in [_LT,_LSHARPBRACKET]) then
  2598. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2599. else
  2600. p1:=cspecializenode.create(p1,getaddr,srsym,false);
  2601. erroroutp1:=false;
  2602. end
  2603. else
  2604. begin
  2605. Message1(sym_e_id_no_member,orgpattern);
  2606. { try to clean up }
  2607. consume(_ID);
  2608. end;
  2609. end;
  2610. if erroroutp1 then
  2611. begin
  2612. p1.free;
  2613. p1:=cerrornode.create;
  2614. end
  2615. else
  2616. if p1.nodetype<>specializen then
  2617. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2618. end
  2619. else { Error }
  2620. Consume(_ID);
  2621. end;
  2622. objectdef:
  2623. begin
  2624. if isspecialize or (token=_ID) then
  2625. begin
  2626. erroroutp1:=true;
  2627. srsym:=nil;
  2628. structh:=tobjectdef(p1.resultdef);
  2629. if isspecialize then
  2630. begin
  2631. { consume the "specialize" }
  2632. consume(_ID);
  2633. if token<>_ID then
  2634. consume(_ID)
  2635. else
  2636. begin
  2637. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2638. consume(_ID);
  2639. if handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  2640. erroroutp1:=false;
  2641. end;
  2642. end
  2643. else
  2644. begin
  2645. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2646. if assigned(srsym) then
  2647. begin
  2648. old_current_filepos:=current_filepos;
  2649. consume(_ID);
  2650. if not (sp_generic_dummy in srsym.symoptions) or
  2651. not (token in [_LT,_LSHARPBRACKET]) then
  2652. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2653. else
  2654. p1:=cspecializenode.create(p1,getaddr,srsym,false);
  2655. erroroutp1:=false;
  2656. end
  2657. else
  2658. begin
  2659. Message1(sym_e_id_no_member,orgpattern);
  2660. { try to clean up }
  2661. consume(_ID);
  2662. end;
  2663. end;
  2664. if erroroutp1 then
  2665. begin
  2666. p1.free;
  2667. p1:=cerrornode.create;
  2668. end
  2669. else
  2670. if p1.nodetype<>specializen then
  2671. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2672. end
  2673. else { Error }
  2674. Consume(_ID);
  2675. end;
  2676. pointerdef:
  2677. begin
  2678. if (p1.resultdef=objc_idtype) then
  2679. begin
  2680. { objc's id type can be used to call any
  2681. Objective-C method of any Objective-C class
  2682. type that's currently in scope }
  2683. if search_objc_method(pattern,srsym,srsymtable) then
  2684. begin
  2685. consume(_ID);
  2686. do_proc_call(srsym,srsymtable,nil,
  2687. (getaddr and not(token in [_CARET,_POINT])),
  2688. again,p1,[cnf_objc_id_call],nil);
  2689. { we need to know which procedure is called }
  2690. do_typecheckpass(p1);
  2691. end
  2692. else
  2693. begin
  2694. consume(_ID);
  2695. Message(parser_e_methode_id_expected);
  2696. end;
  2697. end
  2698. else
  2699. begin
  2700. if not try_type_helper(p1,nil) then
  2701. begin
  2702. Message(parser_e_invalid_qualifier);
  2703. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  2704. Message(parser_h_maybe_deref_caret_missing);
  2705. end;
  2706. end
  2707. end;
  2708. else
  2709. begin
  2710. if autoderef then
  2711. begin
  2712. { always try with the not dereferenced node }
  2713. p2:=tderefnode(p1).left;
  2714. found:=try_type_helper(p2,nil);
  2715. if found then
  2716. begin
  2717. tderefnode(p1).left:=nil;
  2718. p1.destroy;
  2719. p1:=p2;
  2720. end;
  2721. end
  2722. else
  2723. found:=try_type_helper(p1,nil);
  2724. if not found then
  2725. begin
  2726. if p1.resultdef.typ<>undefineddef then
  2727. Message(parser_e_invalid_qualifier);
  2728. p1.destroy;
  2729. p1:=cerrornode.create;
  2730. { Error }
  2731. consume(_ID);
  2732. end;
  2733. end;
  2734. end;
  2735. { processing an ordconstnode avoids the resultdef check }
  2736. skippointdefcheck:
  2737. end;
  2738. else
  2739. begin
  2740. { is this a procedure variable ? }
  2741. if is_invokable(p1.resultdef) and
  2742. (token=_LKLAMMER) then
  2743. begin
  2744. if not searchsym_in_class(tobjectdef(p1.resultdef),tobjectdef(p1.resultdef),method_name_funcref_invoke_find,srsym,srsymtable,[]) then
  2745. internalerror(2021040202);
  2746. include(p1.flags,nf_load_procvar);
  2747. do_proc_call(srsym,srsymtable,tabstractrecorddef(p1.resultdef),false,again,p1,[],nil);
  2748. end
  2749. else if assigned(p1.resultdef) and
  2750. (p1.resultdef.typ=procvardef) then
  2751. begin
  2752. { Typenode for typecasting or expecting a procvar }
  2753. if (p1.nodetype=typen) or
  2754. (
  2755. assigned(getprocvardef) and
  2756. equal_defs(p1.resultdef,getprocvardef)
  2757. ) or
  2758. (
  2759. assigned(getfuncrefdef) and
  2760. equal_defs(p1.resultdef,getfuncrefdef)
  2761. ) then
  2762. begin
  2763. if try_to_consume(_LKLAMMER) then
  2764. begin
  2765. p1:=comp_expr([ef_accept_equal]);
  2766. consume(_RKLAMMER);
  2767. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  2768. end
  2769. else
  2770. again:=false
  2771. end
  2772. else
  2773. begin
  2774. if try_to_consume(_LKLAMMER) then
  2775. begin
  2776. p2:=parse_paras(false,false,_RKLAMMER);
  2777. consume(_RKLAMMER);
  2778. p1:=ccallnode.create_procvar(p2,p1);
  2779. { proc():= is never possible }
  2780. if token=_ASSIGNMENT then
  2781. begin
  2782. Message(parser_e_illegal_expression);
  2783. p1.free;
  2784. p1:=cerrornode.create;
  2785. again:=false;
  2786. end;
  2787. end
  2788. else
  2789. again:=false;
  2790. end;
  2791. end
  2792. else
  2793. again:=false;
  2794. end;
  2795. end;
  2796. { we only try again if p1 was changed }
  2797. if again or
  2798. (p1.nodetype=errorn) then
  2799. result:=true;
  2800. end; { while again }
  2801. end;
  2802. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  2803. out memberparentdef: tdef): boolean;
  2804. var
  2805. hdef : tdef;
  2806. begin
  2807. result:=true;
  2808. memberparentdef:=nil;
  2809. case st.symtabletype of
  2810. ObjectSymtable,
  2811. recordsymtable:
  2812. begin
  2813. memberparentdef:=tdef(st.defowner);
  2814. exit;
  2815. end;
  2816. WithSymtable:
  2817. begin
  2818. if assigned(p1) then
  2819. internalerror(2007012002);
  2820. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  2821. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  2822. if not(hdef.typ in [objectdef,classrefdef]) then
  2823. exit;
  2824. if (hdef.typ=classrefdef) then
  2825. hdef:=tclassrefdef(hdef).pointeddef;
  2826. memberparentdef:=hdef;
  2827. end;
  2828. else
  2829. result:=false;
  2830. end;
  2831. end;
  2832. {$maxfpuregisters 0}
  2833. function factor_handle_sym(srsym:tsym;srsymtable:tsymtable;var again:boolean;getaddr:boolean;unit_found:boolean;flags:texprflags;var spezcontext:tspecializationcontext):tnode;
  2834. var
  2835. hdef : tdef;
  2836. pd : tprocdef;
  2837. callflags : tcallnodeflags;
  2838. tmpgetaddr : boolean;
  2839. begin
  2840. hdef:=nil;
  2841. result:=nil;
  2842. case srsym.typ of
  2843. absolutevarsym :
  2844. begin
  2845. if (tabsolutevarsym(srsym).abstyp=tovar) then
  2846. begin
  2847. result:=nil;
  2848. propaccesslist_to_node(result,nil,tabsolutevarsym(srsym).ref);
  2849. result:=ctypeconvnode.create(result,tabsolutevarsym(srsym).vardef);
  2850. include(result.flags,nf_absolute);
  2851. end
  2852. else
  2853. result:=cloadnode.create(srsym,srsymtable);
  2854. end;
  2855. staticvarsym,
  2856. localvarsym,
  2857. paravarsym,
  2858. fieldvarsym :
  2859. begin
  2860. { check if we are reading a field of an object/class/ }
  2861. { record. is_member_read() will deal with withsymtables }
  2862. { if needed. }
  2863. result:=nil;
  2864. if is_member_read(srsym,srsymtable,result,hdef) then
  2865. begin
  2866. { if the field was originally found in an }
  2867. { objectsymtable, it means it's part of self }
  2868. { if only method from which it was called is }
  2869. { not class static }
  2870. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2871. { if we are accessing a owner procsym from the nested }
  2872. { class we need to call it as a class member }
  2873. if assigned(current_structdef) and
  2874. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2875. (sp_static in srsym.symoptions)) then
  2876. if srsymtable.symtabletype=recordsymtable then
  2877. result:=ctypenode.create(hdef)
  2878. else
  2879. result:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2880. else
  2881. begin
  2882. if assigned(current_procinfo) then
  2883. begin
  2884. pd:=current_procinfo.get_normal_proc.procdef;
  2885. if assigned(pd) and pd.no_self_node then
  2886. result:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  2887. else
  2888. result:=load_self_node;
  2889. end
  2890. else
  2891. result:=load_self_node;
  2892. end;
  2893. { now, if the field itself is part of an objectsymtab }
  2894. { (it can be even if it was found in a withsymtable, }
  2895. { e.g., "with classinstance do field := 5"), then }
  2896. { let do_member_read handle it }
  2897. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2898. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil)
  2899. else
  2900. { otherwise it's a regular record subscript }
  2901. result:=csubscriptnode.create(srsym,result);
  2902. end
  2903. else
  2904. { regular non-field load }
  2905. result:=cloadnode.create(srsym,srsymtable);
  2906. end;
  2907. syssym :
  2908. begin
  2909. result:=statement_syssym(tsyssym(srsym).number);
  2910. end;
  2911. typesym :
  2912. begin
  2913. hdef:=ttypesym(srsym).typedef;
  2914. if not assigned(hdef) then
  2915. begin
  2916. again:=false;
  2917. end
  2918. else
  2919. begin
  2920. if (m_delphi in current_settings.modeswitches) and
  2921. (sp_generic_dummy in srsym.symoptions) and
  2922. (token in [_LT,_LSHARPBRACKET]) then
  2923. begin
  2924. if block_type in [bt_type,bt_const_type,bt_var_type] then
  2925. begin
  2926. if not handle_specialize_inline_specialization(srsym,unit_found,srsymtable,spezcontext) or (srsym.typ=procsym) then
  2927. begin
  2928. spezcontext.free;
  2929. result:=cerrornode.create;
  2930. if try_to_consume(_LKLAMMER) then
  2931. begin
  2932. parse_paras(false,false,_RKLAMMER);
  2933. consume(_RKLAMMER);
  2934. end;
  2935. end
  2936. else
  2937. begin
  2938. if srsym.typ<>typesym then
  2939. internalerror(2015071705);
  2940. hdef:=ttypesym(srsym).typedef;
  2941. result:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  2942. end;
  2943. end
  2944. else
  2945. result:=cspecializenode.create(nil,getaddr,srsym,unit_found)
  2946. end
  2947. else
  2948. begin
  2949. { We need to know if this unit uses Variants }
  2950. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  2951. not(cs_compilesystem in current_settings.moduleswitches) then
  2952. include(current_module.moduleflags,mf_uses_variants);
  2953. result:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  2954. end;
  2955. end;
  2956. end;
  2957. enumsym :
  2958. begin
  2959. result:=genenumnode(tenumsym(srsym));
  2960. end;
  2961. constsym :
  2962. begin
  2963. if tconstsym(srsym).consttyp=constresourcestring then
  2964. begin
  2965. result:=cloadnode.create(srsym,srsymtable);
  2966. do_typecheckpass(result);
  2967. result.resultdef:=getansistringdef;
  2968. end
  2969. else
  2970. result:=genconstsymtree(tconstsym(srsym));
  2971. end;
  2972. procsym :
  2973. begin
  2974. result:=nil;
  2975. if (m_delphi in current_settings.modeswitches) and
  2976. (sp_generic_dummy in srsym.symoptions) and
  2977. (token in [_LT,_LSHARPBRACKET]) then
  2978. begin
  2979. result:=cspecializenode.create(nil,getaddr,srsym,unit_found)
  2980. end
  2981. { check if it's a method/class method }
  2982. else if is_member_read(srsym,srsymtable,result,hdef) then
  2983. begin
  2984. { if we are accessing a owner procsym from the nested }
  2985. { class we need to call it as a class member }
  2986. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2987. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2988. result:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2989. { not srsymtable.symtabletype since that can be }
  2990. { withsymtable as well }
  2991. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2992. begin
  2993. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],spezcontext);
  2994. spezcontext:=nil;
  2995. end
  2996. else
  2997. { no procsyms in records (yet) }
  2998. internalerror(2007012006);
  2999. end
  3000. else
  3001. begin
  3002. { regular procedure/function call }
  3003. if not unit_found then
  3004. callflags:=[]
  3005. else
  3006. callflags:=[cnf_unit_specified];
  3007. { TP7 uglyness: @proc^ is parsed as (@proc)^,
  3008. but @notproc^ is parsed as @(notproc^) }
  3009. if m_tp_procvar in current_settings.modeswitches then
  3010. tmpgetaddr:=getaddr and not(token in [_POINT,_LECKKLAMMER])
  3011. else
  3012. tmpgetaddr:=getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER]);
  3013. do_proc_call(srsym,srsymtable,nil,tmpgetaddr,
  3014. again,result,callflags,spezcontext);
  3015. spezcontext:=nil;
  3016. end;
  3017. end;
  3018. propertysym :
  3019. begin
  3020. result:=nil;
  3021. { property of a class/object? }
  3022. if is_member_read(srsym,srsymtable,result,hdef) then
  3023. begin
  3024. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3025. { if we are accessing a owner procsym from the nested }
  3026. { class or from a static class method we need to call }
  3027. { it as a class member }
  3028. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3029. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  3030. begin
  3031. result:=ctypenode.create(hdef);
  3032. if not is_record(hdef) then
  3033. result:=cloadvmtaddrnode.create(result);
  3034. end
  3035. else
  3036. result:=load_self_node;
  3037. { not srsymtable.symtabletype since that can be }
  3038. { withsymtable as well }
  3039. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3040. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil)
  3041. else
  3042. { no propertysyms in records (yet) }
  3043. internalerror(2009111510);
  3044. end
  3045. else
  3046. { no method pointer }
  3047. begin
  3048. handle_propertysym(tpropertysym(srsym),srsymtable,result);
  3049. end;
  3050. end;
  3051. labelsym :
  3052. begin
  3053. { Support @label }
  3054. if getaddr then
  3055. begin
  3056. if srsym.owner<>current_procinfo.procdef.localst then
  3057. CGMessage(parser_e_label_outside_proc);
  3058. result:=cloadnode.create(srsym,srsym.owner)
  3059. end
  3060. else
  3061. begin
  3062. consume(_COLON);
  3063. if tlabelsym(srsym).defined then
  3064. Message(sym_e_label_already_defined);
  3065. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  3066. begin
  3067. include(current_procinfo.flags,pi_has_interproclabel);
  3068. if (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  3069. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  3070. end;
  3071. tlabelsym(srsym).defined:=true;
  3072. result:=clabelnode.create(nil,tlabelsym(srsym));
  3073. tlabelsym(srsym).code:=result;
  3074. end;
  3075. end;
  3076. undefinedsym :
  3077. begin
  3078. result:=cnothingnode.Create;
  3079. result.resultdef:=cundefineddef.create(true);
  3080. { clean up previously created dummy symbol }
  3081. srsym.free;
  3082. end;
  3083. errorsym :
  3084. begin
  3085. result:=cerrornode.create;
  3086. if try_to_consume(_LKLAMMER) then
  3087. begin
  3088. parse_paras(false,false,_RKLAMMER);
  3089. consume(_RKLAMMER);
  3090. end;
  3091. end;
  3092. else
  3093. begin
  3094. result:=cerrornode.create;
  3095. Message(parser_e_illegal_expression);
  3096. end;
  3097. end; { end case }
  3098. end;
  3099. function factor(getaddr:boolean;flags:texprflags) : tnode;
  3100. {---------------------------------------------
  3101. Factor_read_id
  3102. ---------------------------------------------}
  3103. procedure factor_read_id(out p1:tnode;out again:boolean);
  3104. function findwithsymtable : boolean;
  3105. var
  3106. hp : psymtablestackitem;
  3107. begin
  3108. result:=true;
  3109. hp:=symtablestack.stack;
  3110. while assigned(hp) do
  3111. begin
  3112. if hp^.symtable.symtabletype=withsymtable then
  3113. exit;
  3114. hp:=hp^.next;
  3115. end;
  3116. result:=false;
  3117. end;
  3118. var
  3119. srsym: tsym;
  3120. srsymtable: TSymtable;
  3121. hdef: tdef;
  3122. orgstoredpattern,
  3123. storedpattern: string;
  3124. t : ttoken;
  3125. consumeid,
  3126. wasgenericdummy,
  3127. allowspecialize,
  3128. isspecialize,
  3129. unit_found : boolean;
  3130. dummypos,
  3131. tokenpos: tfileposinfo;
  3132. spezcontext : tspecializationcontext;
  3133. cufflags : tconsume_unitsym_flags;
  3134. begin
  3135. { allow post fix operators }
  3136. again:=true;
  3137. { preinitalize tokenpos }
  3138. tokenpos:=current_filepos;
  3139. p1:=nil;
  3140. spezcontext:=nil;
  3141. { avoid warning }
  3142. fillchar(dummypos,sizeof(dummypos),0);
  3143. allowspecialize:=not (m_delphi in current_settings.modeswitches) and
  3144. not (ef_had_specialize in flags) and
  3145. (block_type in inline_specialization_block_types);
  3146. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  3147. begin
  3148. consume(_ID);
  3149. isspecialize:=true;
  3150. end
  3151. else
  3152. isspecialize:=ef_had_specialize in flags;
  3153. { first check for identifier }
  3154. if token<>_ID then
  3155. begin
  3156. srsym:=generrorsym;
  3157. srsymtable:=nil;
  3158. consume(_ID);
  3159. unit_found:=false;
  3160. end
  3161. else
  3162. begin
  3163. storedpattern:=pattern;
  3164. orgstoredpattern:=orgpattern;
  3165. { store the position of the token before consuming it }
  3166. tokenpos:=current_filepos;
  3167. consumeid:=true;
  3168. srsym:=nil;
  3169. if ef_check_attr_suffix in flags then
  3170. begin
  3171. if not (ef_type_only in flags) then
  3172. internalerror(2019063001);
  3173. consume(_ID);
  3174. consumeid:=false;
  3175. if token<>_POINT then
  3176. searchsym_type(storedpattern+custom_attribute_suffix,srsym,srsymtable);
  3177. end;
  3178. if not assigned(srsym) then
  3179. begin
  3180. if ef_type_only in flags then
  3181. searchsym_type(storedpattern,srsym,srsymtable)
  3182. else
  3183. searchsym(storedpattern,srsym,srsymtable);
  3184. end;
  3185. { handle unit specification like System.Writeln }
  3186. if not isspecialize then
  3187. begin
  3188. cufflags:=[];
  3189. if consumeid then
  3190. include(cufflags,cuf_consume_id);
  3191. if allowspecialize then
  3192. include(cufflags,cuf_allow_specialize);
  3193. if ef_check_attr_suffix in flags then
  3194. include(cufflags,cuf_check_attr_suffix);
  3195. unit_found:=try_consume_unitsym(srsym,srsymtable,t,cufflags,isspecialize,pattern);
  3196. if unit_found then
  3197. consumeid:=true;
  3198. end
  3199. else
  3200. begin
  3201. unit_found:=false;
  3202. t:=_ID;
  3203. end;
  3204. if consumeid then
  3205. begin
  3206. storedpattern:=pattern;
  3207. orgstoredpattern:=orgpattern;
  3208. { store the position of the token before consuming it }
  3209. tokenpos:=current_filepos;
  3210. consume(t);
  3211. end;
  3212. { named parameter support }
  3213. found_arg_name:=false;
  3214. if not(unit_found) and
  3215. not isspecialize and
  3216. named_args_allowed and
  3217. (token=_ASSIGNMENT) then
  3218. begin
  3219. found_arg_name:=true;
  3220. p1:=cstringconstnode.createstr(orgstoredpattern);
  3221. consume(_ASSIGNMENT);
  3222. exit;
  3223. end;
  3224. if isspecialize then
  3225. begin
  3226. if not assigned(srsym) then
  3227. begin
  3228. identifier_not_found(orgstoredpattern,tokenpos);
  3229. srsym:=generrorsym;
  3230. srsymtable:=nil;
  3231. end
  3232. else
  3233. begin
  3234. if not unit_found then
  3235. srsymtable:=nil;
  3236. {$push}
  3237. {$warn 5036 off}
  3238. hdef:=generate_specialization_phase1(spezcontext,nil,unit_found,nil,orgstoredpattern,srsymtable,dummypos);
  3239. {$pop}
  3240. if hdef=generrordef then
  3241. begin
  3242. spezcontext.free;
  3243. spezcontext:=nil;
  3244. srsym:=generrorsym;
  3245. srsymtable:=nil;
  3246. end
  3247. else
  3248. begin
  3249. if hdef.typ in [objectdef,recorddef,procvardef,arraydef] then
  3250. begin
  3251. hdef:=generate_specialization_phase2(spezcontext,tstoreddef(hdef),false,'');
  3252. spezcontext.free;
  3253. spezcontext:=nil;
  3254. if hdef<>generrordef then
  3255. begin
  3256. srsym:=hdef.typesym;
  3257. srsymtable:=srsym.owner;
  3258. end
  3259. else
  3260. begin
  3261. srsym:=generrorsym;
  3262. srsymtable:=nil;
  3263. end;
  3264. end
  3265. else
  3266. if hdef.typ=procdef then
  3267. begin
  3268. if block_type<>bt_body then
  3269. message(parser_e_illegal_expression);
  3270. srsym:=tprocdef(hdef).procsym;
  3271. if assigned(spezcontext.symtable) then
  3272. srsymtable:=spezcontext.symtable
  3273. else
  3274. srsymtable:=srsym.owner;
  3275. end
  3276. else
  3277. internalerror(2015061204);
  3278. end;
  3279. end;
  3280. end;
  3281. wasgenericdummy:=false;
  3282. if assigned(srsym) and
  3283. (sp_generic_dummy in srsym.symoptions) and
  3284. (srsym.typ in [procsym,typesym]) and
  3285. (
  3286. (
  3287. (m_delphi in current_settings.modeswitches) and
  3288. not (token in [_LT, _LSHARPBRACKET]) and
  3289. (
  3290. (
  3291. (srsym.typ=typesym) and
  3292. (ttypesym(srsym).typedef.typ=undefineddef)
  3293. ) or (
  3294. (srsym.typ=procsym) and
  3295. (tprocsym(srsym).procdeflist.count=0)
  3296. )
  3297. )
  3298. )
  3299. or
  3300. (
  3301. not (m_delphi in current_settings.modeswitches) and
  3302. not isspecialize and
  3303. (
  3304. not parse_generic or
  3305. not (
  3306. assigned(current_structdef) and
  3307. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3308. )
  3309. )
  3310. )
  3311. ) then
  3312. begin
  3313. srsym:=resolve_generic_dummysym(srsym.name);
  3314. if assigned(srsym) then
  3315. srsymtable:=srsym.owner
  3316. else
  3317. begin
  3318. srsymtable:=nil;
  3319. wasgenericdummy:=true;
  3320. end;
  3321. end;
  3322. { check hints, but only if it isn't a potential generic symbol;
  3323. that is checked in sub_expr if it isn't a generic }
  3324. if assigned(srsym) and
  3325. not (
  3326. (srsym.typ=typesym) and
  3327. (
  3328. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) or
  3329. (
  3330. (ttypesym(srsym).typedef.typ=errordef) and
  3331. (sp_generic_dummy in srsym.symoptions)
  3332. )
  3333. ) and
  3334. not (sp_generic_para in srsym.symoptions) and
  3335. (token in [_LT, _LSHARPBRACKET])
  3336. ) then
  3337. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3338. { if nothing found give error and return errorsym }
  3339. if not assigned(srsym) or
  3340. { is this a generic dummy symbol? }
  3341. ((srsym.typ=typesym) and
  3342. assigned(ttypesym(srsym).typedef) and
  3343. (ttypesym(srsym).typedef.typ=undefineddef) and
  3344. not (sp_generic_para in srsym.symoptions) and
  3345. not (token in [_LT, _LSHARPBRACKET]) and
  3346. not (
  3347. { in non-Delphi modes the generic class' name without a
  3348. "specialization" or "<T>" may be used to identify the
  3349. current class }
  3350. (sp_generic_dummy in srsym.symoptions) and
  3351. assigned(current_structdef) and
  3352. (df_generic in current_structdef.defoptions) and
  3353. not (m_delphi in current_settings.modeswitches) and
  3354. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3355. )) and
  3356. { it could be a rename of a generic para }
  3357. { Note: if this generates false positives we'll need to
  3358. include a "basesym" to tsym to track the original
  3359. symbol }
  3360. not (sp_explicitrename in srsym.symoptions) then
  3361. begin
  3362. { if a generic is parsed and when we are inside an with block,
  3363. a symbol might not be defined }
  3364. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  3365. findwithsymtable then
  3366. begin
  3367. { create dummy symbol, it will be freed later on }
  3368. srsym:=tstoredsym.create(undefinedsym,'$undefinedsym');
  3369. srsymtable:=nil;
  3370. end
  3371. else
  3372. begin
  3373. if wasgenericdummy then
  3374. messagepos(tokenpos,parser_e_no_generics_as_types)
  3375. else
  3376. identifier_not_found(orgstoredpattern,tokenpos);
  3377. srsym:=generrorsym;
  3378. srsymtable:=nil;
  3379. end;
  3380. end;
  3381. end;
  3382. { Access to funcret or need to call the function? }
  3383. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  3384. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  3385. { result(x) is not allowed }
  3386. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  3387. (
  3388. (token=_LKLAMMER) or
  3389. (
  3390. (([m_tp7,m_delphi,m_mac,m_iso,m_extpas] * current_settings.modeswitches) <> []) and
  3391. (afterassignment or in_args)
  3392. )
  3393. ) then
  3394. begin
  3395. hdef:=tdef(srsym.owner.defowner);
  3396. if assigned(hdef) and
  3397. (hdef.typ=procdef) then
  3398. srsym:=tprocdef(hdef).procsym
  3399. else
  3400. begin
  3401. Message(parser_e_illegal_expression);
  3402. srsym:=generrorsym;
  3403. end;
  3404. srsymtable:=srsym.owner;
  3405. end;
  3406. begin
  3407. p1:=factor_handle_sym(srsym,srsymtable,again,getaddr,unit_found,flags,spezcontext);
  3408. if assigned(spezcontext) then
  3409. internalerror(2015061207);
  3410. if assigned(p1) and (p1.nodetype<>errorn) then
  3411. p1.fileinfo:=tokenpos;
  3412. end;
  3413. end;
  3414. {---------------------------------------------
  3415. Factor_Read_Set
  3416. ---------------------------------------------}
  3417. { Read a set between [] }
  3418. function factor_read_set:tnode;
  3419. var
  3420. p1,p2 : tnode;
  3421. lastp,
  3422. buildp : tarrayconstructornode;
  3423. begin
  3424. buildp:=nil;
  3425. lastp:=nil;
  3426. { be sure that a least one arrayconstructn is used, also for an
  3427. empty [] }
  3428. if token=_RECKKLAMMER then
  3429. buildp:=carrayconstructornode.create(nil,buildp)
  3430. else
  3431. repeat
  3432. p1:=comp_expr([ef_accept_equal]);
  3433. if try_to_consume(_POINTPOINT) then
  3434. begin
  3435. p2:=comp_expr([ef_accept_equal]);
  3436. p1:=carrayconstructorrangenode.create(p1,p2);
  3437. end;
  3438. { insert at the end of the tree, to get the correct order }
  3439. if not assigned(buildp) then
  3440. begin
  3441. buildp:=carrayconstructornode.create(p1,nil);
  3442. lastp:=buildp;
  3443. end
  3444. else
  3445. begin
  3446. lastp.right:=carrayconstructornode.create(p1,nil);
  3447. lastp:=tarrayconstructornode(lastp.right);
  3448. end;
  3449. { there could be more elements }
  3450. until not try_to_consume(_COMMA);
  3451. buildp.allow_array_constructor:=block_type in [bt_body,bt_except];
  3452. factor_read_set:=buildp;
  3453. end;
  3454. function can_load_self_node: boolean;
  3455. begin
  3456. result:=false;
  3457. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3458. not assigned(current_structdef) or
  3459. not assigned(current_procinfo) then
  3460. exit;
  3461. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  3462. end;
  3463. {---------------------------------------------
  3464. Factor (Main)
  3465. ---------------------------------------------}
  3466. var
  3467. l : longint;
  3468. ic : int64;
  3469. qc : qword;
  3470. p1 : tnode;
  3471. code : integer;
  3472. srsym : tsym;
  3473. srsymtable : TSymtable;
  3474. pd : tprocdef;
  3475. hclassdef : tobjectdef;
  3476. d : bestreal;
  3477. hs,hsorg : string;
  3478. hdef : tdef;
  3479. filepos : tfileposinfo;
  3480. callflags : tcallnodeflags;
  3481. idstr : tidstring;
  3482. spezcontext : tspecializationcontext;
  3483. isspecialize,
  3484. mightbegeneric,
  3485. useself,
  3486. dopostfix,
  3487. again,
  3488. updatefpos,
  3489. nodechanged : boolean;
  3490. oldprocvardef : tprocvardef;
  3491. oldfuncrefdef : tobjectdef;
  3492. begin
  3493. { can't keep a copy of p1 and compare pointers afterwards, because
  3494. p1 may be freed and reallocated in the same place! }
  3495. dopostfix:=true;
  3496. updatefpos:=false;
  3497. p1:=nil;
  3498. filepos:=current_tokenpos;
  3499. again:=false;
  3500. pd:=nil;
  3501. isspecialize:=false;
  3502. if token=_ID then
  3503. begin
  3504. again:=true;
  3505. { Handle references to self }
  3506. if (idtoken=_SELF) and can_load_self_node then
  3507. begin
  3508. p1:=load_self_node;
  3509. consume(_ID);
  3510. again:=true;
  3511. end
  3512. else
  3513. factor_read_id(p1,again);
  3514. if assigned(p1) then
  3515. begin
  3516. { factor_read_id will set the filepos to after the id,
  3517. and in case of _SELF the filepos will already be the
  3518. same as filepos (so setting it again doesn't hurt). }
  3519. p1.fileinfo:=filepos;
  3520. filepos:=current_tokenpos;
  3521. end;
  3522. { handle post fix operators }
  3523. if (p1.nodetype=specializen) then
  3524. { post fix operators are handled after specialization }
  3525. dopostfix:=false
  3526. else
  3527. if (m_delphi in current_settings.modeswitches) and
  3528. (block_type=bt_body) and
  3529. (token in [_LT,_LSHARPBRACKET]) then
  3530. begin
  3531. idstr:='';
  3532. case p1.nodetype of
  3533. typen:
  3534. idstr:=ttypenode(p1).typesym.name;
  3535. loadvmtaddrn:
  3536. if tloadvmtaddrnode(p1).left.nodetype=typen then
  3537. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name;
  3538. loadn:
  3539. idstr:=tloadnode(p1).symtableentry.name;
  3540. calln:
  3541. idstr:=tcallnode(p1).symtableprocentry.name;
  3542. else
  3543. ;
  3544. end;
  3545. { if this is the case then the postfix handling is done in
  3546. sub_expr if necessary }
  3547. dopostfix:=not could_be_generic(idstr);
  3548. end;
  3549. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^ is parsed
  3550. as @(notproc^) }
  3551. if (m_tp_procvar in current_settings.modeswitches) and (token=_CARET) and
  3552. getaddr and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym) then
  3553. dopostfix:=false;
  3554. { maybe an additional parameter instead of misusing hadspezialize? }
  3555. if dopostfix and not (ef_had_specialize in flags) then
  3556. updatefpos:=postfixoperators(p1,again,getaddr);
  3557. end
  3558. else
  3559. begin
  3560. updatefpos:=true;
  3561. case token of
  3562. _RETURN :
  3563. begin
  3564. consume(_RETURN);
  3565. p1:=nil;
  3566. if not(token in [_SEMICOLON,_ELSE,_END]) then
  3567. begin
  3568. p1:=comp_expr([ef_accept_equal]);
  3569. if not assigned(current_procinfo) or
  3570. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  3571. is_void(current_procinfo.procdef.returndef) then
  3572. begin
  3573. Message(parser_e_void_function);
  3574. { recovery }
  3575. p1.free;
  3576. p1:=nil;
  3577. end;
  3578. end;
  3579. p1 := cexitnode.create(p1);
  3580. end;
  3581. _INHERITED :
  3582. begin
  3583. again:=true;
  3584. consume(_INHERITED);
  3585. if assigned(current_procinfo) and
  3586. assigned(current_structdef) and
  3587. ((current_structdef.typ=objectdef) or
  3588. ((target_info.system in systems_jvm) and
  3589. (current_structdef.typ=recorddef)))then
  3590. begin
  3591. { for record helpers in mode Delphi "inherited" is not
  3592. allowed }
  3593. if is_objectpascal_helper(current_structdef) and
  3594. (m_delphi in current_settings.modeswitches) and
  3595. (tobjectdef(current_structdef).helpertype=ht_record) then
  3596. Message(parser_e_inherited_not_in_record);
  3597. if (current_structdef.typ=objectdef) then
  3598. begin
  3599. hclassdef:=tobjectdef(current_structdef).childof;
  3600. { Objective-C categories *replace* methods in the class
  3601. they extend, or add methods to it. So calling an
  3602. inherited method always calls the method inherited from
  3603. the parent of the extended class }
  3604. if is_objccategory(current_structdef) then
  3605. hclassdef:=hclassdef.childof;
  3606. end
  3607. else if target_info.system in systems_jvm then
  3608. hclassdef:=java_fpcbaserecordtype
  3609. else
  3610. internalerror(2012012401);
  3611. spezcontext:=nil;
  3612. { if inherited; only then we need the method with
  3613. the same name }
  3614. if token <> _ID then
  3615. begin
  3616. hs:=current_procinfo.procdef.procsym.name;
  3617. hsorg:=current_procinfo.procdef.procsym.realname;
  3618. anon_inherited:=true;
  3619. { For message methods we need to search using the message
  3620. number or string }
  3621. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3622. srdef:=nil;
  3623. if (po_msgint in pd.procoptions) then
  3624. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3625. else
  3626. if (po_msgstr in pd.procoptions) then
  3627. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3628. else
  3629. { helpers have their own ways of dealing with inherited }
  3630. if is_objectpascal_helper(current_structdef) then
  3631. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3632. else
  3633. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3634. end
  3635. else
  3636. begin
  3637. if not (m_delphi in current_settings.modeswitches) and
  3638. (block_type in inline_specialization_block_types) and
  3639. (token=_ID) and
  3640. (idtoken=_SPECIALIZE) then
  3641. begin
  3642. consume(_ID);
  3643. if token<>_ID then
  3644. message(parser_e_methode_id_expected);
  3645. isspecialize:=true;
  3646. end
  3647. else
  3648. isspecialize:=false;
  3649. hs:=pattern;
  3650. hsorg:=orgpattern;
  3651. consume(_ID);
  3652. anon_inherited:=false;
  3653. { helpers have their own ways of dealing with inherited }
  3654. if is_objectpascal_helper(current_structdef) then
  3655. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3656. else
  3657. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3658. if isspecialize and assigned(srsym) then
  3659. begin
  3660. if not handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  3661. srsym:=nil;
  3662. end;
  3663. end;
  3664. if assigned(srsym) then
  3665. begin
  3666. mightbegeneric:=(m_delphi in current_settings.modeswitches) and
  3667. (token in [_LT,_LSHARPBRACKET]) and
  3668. (sp_generic_dummy in srsym.symoptions);
  3669. { load the procdef from the inherited class and
  3670. not from self }
  3671. case srsym.typ of
  3672. typesym,
  3673. procsym:
  3674. begin
  3675. { typesym is only a valid choice if we're dealing
  3676. with a potential generic }
  3677. if (srsym.typ=typesym) and not mightbegeneric then
  3678. begin
  3679. Message(parser_e_methode_id_expected);
  3680. p1:=cerrornode.create;
  3681. end
  3682. else
  3683. begin
  3684. useself:=false;
  3685. if is_objectpascal_helper(current_structdef) then
  3686. begin
  3687. { for a helper load the procdef either from the
  3688. extended type, from the parent helper or from
  3689. the extended type of the parent helper
  3690. depending on the def the found symbol belongs
  3691. to }
  3692. if (srsym.Owner.defowner.typ=objectdef) and
  3693. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3694. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3695. assigned(tobjectdef(current_structdef).childof) then
  3696. hdef:=tobjectdef(current_structdef).childof
  3697. else
  3698. begin
  3699. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef;
  3700. useself:=true;
  3701. end
  3702. else
  3703. begin
  3704. hdef:=tdef(srsym.Owner.defowner);
  3705. useself:=true;
  3706. end;
  3707. end
  3708. else
  3709. hdef:=hclassdef;
  3710. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3711. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3712. hdef:=cclassrefdef.create(hdef);
  3713. if useself then
  3714. begin
  3715. p1:=ctypeconvnode.create_internal(load_self_node,hdef);
  3716. end
  3717. else
  3718. begin
  3719. p1:=ctypenode.create(hdef);
  3720. { we need to allow helpers here }
  3721. ttypenode(p1).helperallowed:=true;
  3722. end;
  3723. end;
  3724. end;
  3725. propertysym:
  3726. ;
  3727. else
  3728. begin
  3729. Message(parser_e_methode_id_expected);
  3730. p1:=cerrornode.create;
  3731. end;
  3732. end;
  3733. if mightbegeneric then
  3734. begin
  3735. p1:=cspecializenode.create_inherited(p1,getaddr,srsym,hclassdef);
  3736. end
  3737. else
  3738. begin
  3739. if not isspecialize then
  3740. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3741. callflags:=[cnf_inherited];
  3742. include(current_procinfo.flags,pi_has_inherited);
  3743. if anon_inherited then
  3744. include(callflags,cnf_anon_inherited);
  3745. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags,spezcontext);
  3746. end;
  3747. if p1.nodetype=errorn then
  3748. spezcontext.free;
  3749. end
  3750. else
  3751. begin
  3752. if anon_inherited then
  3753. begin
  3754. { For message methods we need to call DefaultHandler }
  3755. if (po_msgint in pd.procoptions) or
  3756. (po_msgstr in pd.procoptions) then
  3757. begin
  3758. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3759. if not assigned(srsym) or
  3760. (srsym.typ<>procsym) then
  3761. internalerror(200303171);
  3762. p1:=nil;
  3763. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[],nil);
  3764. end
  3765. else
  3766. begin
  3767. { we need to ignore the inherited; }
  3768. p1:=cnothingnode.create;
  3769. end;
  3770. end
  3771. else
  3772. begin
  3773. Message1(sym_e_id_no_member,hsorg);
  3774. p1:=cerrornode.create;
  3775. end;
  3776. again:=false;
  3777. end;
  3778. { turn auto inheriting off }
  3779. anon_inherited:=false;
  3780. end
  3781. else
  3782. begin
  3783. { in case of records we use a more clear error message }
  3784. if assigned(current_structdef) and
  3785. (current_structdef.typ=recorddef) then
  3786. Message(parser_e_inherited_not_in_record)
  3787. else
  3788. Message(parser_e_generic_methods_only_in_methods);
  3789. again:=false;
  3790. p1:=cerrornode.create;
  3791. end;
  3792. if p1.nodetype<>specializen then
  3793. postfixoperators(p1,again,getaddr);
  3794. end;
  3795. _INTCONST :
  3796. begin
  3797. {Try first wether the value fits in an int64.}
  3798. val(pattern,ic,code);
  3799. if code=0 then
  3800. begin
  3801. consume(_INTCONST);
  3802. int_to_type(ic,hdef);
  3803. p1:=cordconstnode.create(ic,hdef,true);
  3804. end
  3805. else
  3806. begin
  3807. { try qword next }
  3808. val(pattern,qc,code);
  3809. if code=0 then
  3810. begin
  3811. consume(_INTCONST);
  3812. int_to_type(qc,hdef);
  3813. p1:=cordconstnode.create(qc,hdef,true);
  3814. end;
  3815. end;
  3816. if code<>0 then
  3817. begin
  3818. { finally float }
  3819. val(pattern,d,code);
  3820. if code<>0 then
  3821. begin
  3822. Message(parser_e_invalid_integer);
  3823. consume(_INTCONST);
  3824. l:=1;
  3825. p1:=cordconstnode.create(l,sinttype,true);
  3826. end
  3827. else
  3828. begin
  3829. consume(_INTCONST);
  3830. p1:=crealconstnode.create(d,pbestrealtype^);
  3831. end;
  3832. end
  3833. else
  3834. { the necessary range checking has already been done by val }
  3835. tordconstnode(p1).rangecheck:=false;
  3836. if token=_POINT then
  3837. begin
  3838. again:=true;
  3839. postfixoperators(p1,again,getaddr);
  3840. end;
  3841. end;
  3842. _REALNUMBER :
  3843. begin
  3844. p1:=real_const_node_from_pattern(pattern);
  3845. consume(_REALNUMBER);
  3846. if token=_POINT then
  3847. begin
  3848. again:=true;
  3849. postfixoperators(p1,again,getaddr);
  3850. end;
  3851. end;
  3852. _STRING :
  3853. begin
  3854. if cs_compilesystem in current_settings.moduleswitches then
  3855. Message(parser_e_nostringaliasinsystem);
  3856. string_dec(hdef,true);
  3857. { STRING can be also a type cast }
  3858. if try_to_consume(_LKLAMMER) then
  3859. begin
  3860. p1:=comp_expr([ef_accept_equal]);
  3861. consume(_RKLAMMER);
  3862. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3863. { handle postfix operators here e.g. string(a)[10] }
  3864. again:=true;
  3865. postfixoperators(p1,again,getaddr);
  3866. end
  3867. else
  3868. begin
  3869. p1:=ctypenode.create(hdef);
  3870. if token=_POINT then
  3871. begin
  3872. again:=true;
  3873. { handle type helpers here }
  3874. postfixoperators(p1,again,getaddr);
  3875. end;
  3876. end;
  3877. end;
  3878. _FILE :
  3879. begin
  3880. hdef:=cfiletype;
  3881. consume(_FILE);
  3882. { FILE can be also a type cast }
  3883. if try_to_consume(_LKLAMMER) then
  3884. begin
  3885. p1:=comp_expr([ef_accept_equal]);
  3886. consume(_RKLAMMER);
  3887. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3888. { handle postfix operators here e.g. string(a)[10] }
  3889. again:=true;
  3890. postfixoperators(p1,again,getaddr);
  3891. end
  3892. else
  3893. begin
  3894. p1:=ctypenode.create(hdef);
  3895. end;
  3896. end;
  3897. _CSTRING :
  3898. begin
  3899. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3900. consume(_CSTRING);
  3901. if token in postfixoperator_tokens then
  3902. begin
  3903. again:=true;
  3904. postfixoperators(p1,again,getaddr);
  3905. end;
  3906. end;
  3907. _CCHAR :
  3908. begin
  3909. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3910. consume(_CCHAR);
  3911. if token=_POINT then
  3912. begin
  3913. again:=true;
  3914. postfixoperators(p1,again,getaddr);
  3915. end;
  3916. end;
  3917. _CWSTRING:
  3918. begin
  3919. if getlengthwidestring(patternw)=1 then
  3920. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
  3921. else
  3922. p1:=cstringconstnode.createunistr(patternw);
  3923. consume(_CWSTRING);
  3924. if token in postfixoperator_tokens then
  3925. begin
  3926. again:=true;
  3927. postfixoperators(p1,again,getaddr);
  3928. end;
  3929. end;
  3930. _CWCHAR:
  3931. begin
  3932. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3933. consume(_CWCHAR);
  3934. if token=_POINT then
  3935. begin
  3936. again:=true;
  3937. postfixoperators(p1,again,getaddr);
  3938. end;
  3939. end;
  3940. _KLAMMERAFFE :
  3941. begin
  3942. consume(_KLAMMERAFFE);
  3943. got_addrn:=true;
  3944. { support both @<x> and @(<x>) }
  3945. if try_to_consume(_LKLAMMER) then
  3946. begin
  3947. p1:=factor(true,[]);
  3948. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3949. if token<>_RKLAMMER then
  3950. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  3951. consume(_RKLAMMER);
  3952. end
  3953. else
  3954. p1:=factor(true,[]);
  3955. if (token in postfixoperator_tokens) and
  3956. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^
  3957. is parsed as @(notproc^) }
  3958. not
  3959. (
  3960. (m_tp_procvar in current_settings.modeswitches) and
  3961. (token=_CARET) and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym)
  3962. )
  3963. then
  3964. begin
  3965. again:=true;
  3966. postfixoperators(p1,again,getaddr);
  3967. end;
  3968. got_addrn:=false;
  3969. p1:=caddrnode.create(p1);
  3970. p1.fileinfo:=filepos;
  3971. if cs_typed_addresses in current_settings.localswitches then
  3972. include(taddrnode(p1).addrnodeflags,anf_typedaddr);
  3973. { Store the procvar that we are expecting, the
  3974. addrn will use the information to find the correct
  3975. procdef or it will return an error }
  3976. if assigned(getprocvardef) and
  3977. (taddrnode(p1).left.nodetype = loadn) then
  3978. taddrnode(p1).getprocvardef:=getprocvardef;
  3979. if (token in postfixoperator_tokens) then
  3980. begin
  3981. again:=true;
  3982. postfixoperators(p1,again,getaddr);
  3983. end;
  3984. end;
  3985. _LKLAMMER :
  3986. begin
  3987. consume(_LKLAMMER);
  3988. p1:=comp_expr([ef_accept_equal]);
  3989. consume(_RKLAMMER);
  3990. { it's not a good solution
  3991. but (a+b)^ makes some problems }
  3992. if token in postfixoperator_tokens then
  3993. begin
  3994. again:=true;
  3995. postfixoperators(p1,again,getaddr);
  3996. end;
  3997. end;
  3998. _LECKKLAMMER :
  3999. begin
  4000. consume(_LECKKLAMMER);
  4001. p1:=factor_read_set;
  4002. consume(_RECKKLAMMER);
  4003. end;
  4004. _PLUS :
  4005. begin
  4006. consume(_PLUS);
  4007. p1:=factor(false,[]);
  4008. p1:=cunaryplusnode.create(p1);
  4009. end;
  4010. _MINUS :
  4011. begin
  4012. consume(_MINUS);
  4013. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  4014. begin
  4015. { ugly hack, but necessary to be able to parse }
  4016. { -9223372036854775808 as int64 (JM) }
  4017. pattern := '-'+pattern;
  4018. p1:=sub_expr(oppower,[],nil);
  4019. { -1 ** 4 should be - (1 ** 4) and not
  4020. (-1) ** 4
  4021. This was the reason of tw0869.pp test failure PM }
  4022. if p1.nodetype=starstarn then
  4023. begin
  4024. if tbinarynode(p1).left.nodetype=ordconstn then
  4025. begin
  4026. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  4027. p1:=cunaryminusnode.create(p1);
  4028. end
  4029. else if tbinarynode(p1).left.nodetype=realconstn then
  4030. begin
  4031. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  4032. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  4033. p1:=cunaryminusnode.create(p1);
  4034. end
  4035. else
  4036. internalerror(20021029);
  4037. end;
  4038. end
  4039. else
  4040. begin
  4041. if m_isolike_unary_minus in current_settings.modeswitches then
  4042. p1:=sub_expr(opmultiply,[],nil)
  4043. else
  4044. p1:=sub_expr(oppower,[],nil);
  4045. p1:=cunaryminusnode.create(p1);
  4046. end;
  4047. end;
  4048. _OP_NOT :
  4049. begin
  4050. consume(_OP_NOT);
  4051. p1:=factor(false,[]);
  4052. p1:=cnotnode.create(p1);
  4053. end;
  4054. _NIL :
  4055. begin
  4056. consume(_NIL);
  4057. p1:=cnilnode.create;
  4058. { It's really ugly code nil^, but delphi allows it }
  4059. if token in [_CARET,_POINT] then
  4060. begin
  4061. again:=true;
  4062. postfixoperators(p1,again,getaddr);
  4063. end;
  4064. end;
  4065. _OBJCPROTOCOL:
  4066. begin
  4067. { The @protocol keyword is used in two ways in Objective-C:
  4068. 1) to declare protocols (~ Object Pascal interfaces)
  4069. 2) to obtain the metaclass (~ Object Pascal) "class of")
  4070. of a declared protocol
  4071. This code is for handling the second case. Because of 1),
  4072. we cannot simply use a system unit symbol.
  4073. }
  4074. consume(_OBJCPROTOCOL);
  4075. consume(_LKLAMMER);
  4076. p1:=factor(false,[]);
  4077. consume(_RKLAMMER);
  4078. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  4079. end;
  4080. _PROCEDURE,
  4081. _FUNCTION:
  4082. begin
  4083. if (block_type=bt_body) and
  4084. (m_anonymous_functions in current_settings.modeswitches) then
  4085. begin
  4086. oldprocvardef:=getprocvardef;
  4087. oldfuncrefdef:=getfuncrefdef;
  4088. getprocvardef:=nil;
  4089. getfuncrefdef:=nil;
  4090. pd:=read_proc([rpf_anonymous],nil);
  4091. getprocvardef:=oldprocvardef;
  4092. getfuncrefdef:=oldfuncrefdef;
  4093. { assume that we try to get the address except if certain
  4094. tokens follow that indicate a call }
  4095. do_proc_call(pd.procsym,pd.owner,nil,not (token in [_POINT,_CARET,_LECKKLAMMER]),
  4096. again,p1,[],nil);
  4097. end
  4098. else
  4099. begin
  4100. Message(parser_e_illegal_expression);
  4101. p1:=cerrornode.create;
  4102. { recover }
  4103. consume(token);
  4104. end;
  4105. end
  4106. else
  4107. begin
  4108. Message(parser_e_illegal_expression);
  4109. p1:=cerrornode.create;
  4110. { recover }
  4111. consume(token);
  4112. end;
  4113. end;
  4114. end;
  4115. { generate error node if no node is created }
  4116. if not assigned(p1) then
  4117. begin
  4118. {$ifdef EXTDEBUG}
  4119. Comment(V_Warning,'factor: p1=nil');
  4120. {$endif}
  4121. p1:=cerrornode.create;
  4122. updatefpos:=true;
  4123. end;
  4124. { get the resultdef for the node if nothing stops us }
  4125. if (not assigned(p1.resultdef)) and dopostfix then
  4126. begin
  4127. do_typecheckpass_changed(p1,nodechanged);
  4128. updatefpos:=updatefpos or nodechanged;
  4129. end;
  4130. if assigned(p1) and
  4131. updatefpos then
  4132. p1.fileinfo:=filepos;
  4133. factor:=p1;
  4134. end;
  4135. {$maxfpuregisters default}
  4136. procedure post_comp_expr_gendef(var def: tdef);
  4137. var
  4138. p1 : tnode;
  4139. again : boolean;
  4140. begin
  4141. if not assigned(def) then
  4142. internalerror(2011053001);
  4143. again:=false;
  4144. { handle potential typecasts, etc }
  4145. p1:=handle_factor_typenode(def,false,again,nil,false);
  4146. { parse postfix operators }
  4147. postfixoperators(p1,again,false);
  4148. if assigned(p1) and (p1.nodetype=typen) then
  4149. def:=ttypenode(p1).typedef
  4150. else
  4151. def:=generrordef;
  4152. end;
  4153. {****************************************************************************
  4154. Sub_Expr
  4155. ****************************************************************************}
  4156. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;
  4157. {Reads a subexpression while the operators are of the current precedence
  4158. level, or any higher level. Replaces the old term, simpl_expr and
  4159. simpl2_expr.}
  4160. function istypenode(n:tnode):boolean;inline;
  4161. { Checks whether the given node is a type node or a VMT node containing a
  4162. typenode. This is used in the code for inline specializations in the
  4163. _LT branch below }
  4164. begin
  4165. result:=assigned(n) and
  4166. (
  4167. (n.nodetype=typen) or
  4168. (
  4169. (n.nodetype=loadvmtaddrn) and
  4170. (tloadvmtaddrnode(n).left.nodetype=typen)
  4171. )
  4172. );
  4173. end;
  4174. function gettypedef(n:tnode):tdef;inline;
  4175. { This returns the typedef that belongs to the given typenode or
  4176. loadvmtaddrnode. n must not be Nil! }
  4177. begin
  4178. if n.nodetype=typen then
  4179. result:=ttypenode(n).typedef
  4180. else
  4181. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  4182. end;
  4183. function gettypedef(sym:tsym):tdef;inline;
  4184. begin
  4185. result:=nil;
  4186. case sym.typ of
  4187. typesym:
  4188. result:=ttypesym(sym).typedef;
  4189. procsym:
  4190. if not (sp_generic_dummy in sym.symoptions) or (tprocsym(sym).procdeflist.count>0) then
  4191. result:=tdef(tprocsym(sym).procdeflist[0]);
  4192. else
  4193. internalerror(2015092701);
  4194. end;
  4195. end;
  4196. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  4197. var
  4198. srsymtable : tsymtable;
  4199. begin
  4200. srsym:=nil;
  4201. case n.nodetype of
  4202. typen:
  4203. srsym:=ttypenode(n).typedef.typesym;
  4204. loadvmtaddrn:
  4205. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  4206. loadn:
  4207. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  4208. srsym:=nil;
  4209. calln:
  4210. srsym:=tcallnode(n).symtableprocentry;
  4211. specializen:
  4212. srsym:=tspecializenode(n).sym;
  4213. { TODO : handle const nodes }
  4214. else
  4215. ;
  4216. end;
  4217. result:=assigned(srsym);
  4218. end;
  4219. function generate_inline_specialization(gendef:tdef;n:tnode;filepos:tfileposinfo;parseddef:tdef;gensym:tsym;p2:tnode):tnode;
  4220. var
  4221. again,
  4222. getaddr,
  4223. unitspecific : boolean;
  4224. pload : tnode;
  4225. spezcontext : tspecializationcontext;
  4226. structdef,
  4227. inheriteddef : tabstractrecorddef;
  4228. callflags : tcallnodeflags;
  4229. begin
  4230. if n.nodetype=specializen then
  4231. begin
  4232. getaddr:=tspecializenode(n).getaddr;
  4233. pload:=tspecializenode(n).left;
  4234. inheriteddef:=tabstractrecorddef(tspecializenode(n).inheriteddef);
  4235. unitspecific:=tspecializenode(n).unit_specific;
  4236. tspecializenode(n).left:=nil;
  4237. end
  4238. else
  4239. begin
  4240. getaddr:=false;
  4241. pload:=nil;
  4242. inheriteddef:=nil;
  4243. unitspecific:=false;
  4244. end;
  4245. if assigned(parseddef) and assigned(gensym) and assigned(p2) then
  4246. gendef:=generate_specialization_phase1(spezcontext,gendef,unitspecific,parseddef,gensym.realname,gensym.owner,p2.fileinfo)
  4247. else
  4248. gendef:=generate_specialization_phase1(spezcontext,gendef,unitspecific);
  4249. case gendef.typ of
  4250. errordef:
  4251. begin
  4252. spezcontext.free;
  4253. spezcontext:=nil;
  4254. gensym:=generrorsym;
  4255. end;
  4256. objectdef,
  4257. recorddef,
  4258. procvardef,
  4259. arraydef:
  4260. begin
  4261. gendef:=generate_specialization_phase2(spezcontext,tstoreddef(gendef),false,'');
  4262. spezcontext.free;
  4263. spezcontext:=nil;
  4264. if gendef.typ=errordef then
  4265. gensym:=generrorsym
  4266. else
  4267. gensym:=gendef.typesym;
  4268. end;
  4269. procdef:
  4270. begin
  4271. if block_type<>bt_body then
  4272. begin
  4273. message(parser_e_illegal_expression);
  4274. gensym:=generrorsym;
  4275. end
  4276. else
  4277. begin
  4278. gensym:=tprocdef(gendef).procsym;
  4279. end;
  4280. end;
  4281. else
  4282. internalerror(2015092702);
  4283. end;
  4284. { in case of a class or a record the specialized generic
  4285. is always a classrefdef }
  4286. again:=false;
  4287. if assigned(pload) then
  4288. begin
  4289. result:=pload;
  4290. typecheckpass(result);
  4291. structdef:=inheriteddef;
  4292. if not assigned(structdef) then
  4293. case result.resultdef.typ of
  4294. objectdef,
  4295. recorddef:
  4296. begin
  4297. structdef:=tabstractrecorddef(result.resultdef);
  4298. end;
  4299. classrefdef:
  4300. begin
  4301. structdef:=tabstractrecorddef(tclassrefdef(result.resultdef).pointeddef);
  4302. end;
  4303. else
  4304. internalerror(2015092703);
  4305. end;
  4306. if not (structdef.typ in [recorddef,objectdef]) then
  4307. internalerror(2018092101);
  4308. if assigned(inheriteddef) then
  4309. begin
  4310. callflags:=[cnf_inherited];
  4311. include(current_procinfo.flags,pi_has_inherited);
  4312. end
  4313. else
  4314. callflags:=[];
  4315. do_member_read(structdef,getaddr,gensym,result,again,callflags,spezcontext);
  4316. spezcontext:=nil;
  4317. end
  4318. else
  4319. begin
  4320. if gensym.typ=procsym then
  4321. begin
  4322. result:=nil;
  4323. { check if it's a method/class method }
  4324. if is_member_read(gensym,gensym.owner,result,parseddef) then
  4325. begin
  4326. { if we are accessing a owner procsym from the nested }
  4327. { class we need to call it as a class member }
  4328. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  4329. assigned(current_structdef) and (current_structdef<>parseddef) and is_owned_by(current_structdef,parseddef) then
  4330. result:=cloadvmtaddrnode.create(ctypenode.create(parseddef));
  4331. { not srsymtable.symtabletype since that can be }
  4332. { withsymtable as well }
  4333. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  4334. begin
  4335. do_member_read(tabstractrecorddef(parseddef),getaddr,gensym,result,again,[],spezcontext);
  4336. spezcontext:=nil;
  4337. end
  4338. else
  4339. { no procsyms in records (yet) }
  4340. internalerror(2015092704);
  4341. end
  4342. else
  4343. begin
  4344. { regular procedure/function call }
  4345. do_proc_call(gensym,gensym.owner,nil,
  4346. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  4347. again,result,[],spezcontext);
  4348. spezcontext:=nil;
  4349. end;
  4350. end
  4351. else
  4352. { handle potential typecasts, etc }
  4353. result:=handle_factor_typenode(gendef,false,again,nil,false);
  4354. end;
  4355. { parse postfix operators }
  4356. if postfixoperators(result,again,false) then
  4357. if assigned(result) then
  4358. result.fileinfo:=filepos
  4359. else
  4360. result:=cerrornode.create;
  4361. spezcontext.free;
  4362. end;
  4363. function maybe_handle_specialization(var p1,p2:tnode;filepos:tfileposinfo):boolean;
  4364. var
  4365. gensym : tsym;
  4366. parseddef,
  4367. gendef : tdef;
  4368. ptmp : tnode;
  4369. begin
  4370. result:=false;
  4371. { we need to decide whether we have an inline specialization
  4372. (type nodes to the left and right of "<", mode Delphi and
  4373. ">" or "," following) or a normal "<" comparison }
  4374. { TODO : p1 could be a non type if e.g. a variable with the
  4375. same name is defined in the same unit where the
  4376. generic is defined (though "same unit" is not
  4377. necessarily needed) }
  4378. if getgenericsym(p1,gensym) and
  4379. { Attention: when nested specializations are supported
  4380. p2 could be a loadn if a "<" follows }
  4381. istypenode(p2) and
  4382. (m_delphi in current_settings.modeswitches) and
  4383. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  4384. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  4385. begin
  4386. { this is an inline specialization }
  4387. { retrieve the defs of two nodes }
  4388. if p1.nodetype=specializen then
  4389. gendef:=gettypedef(tspecializenode(p1).sym)
  4390. else
  4391. gendef:=nil;
  4392. parseddef:=gettypedef(p2);
  4393. { check the hints for parseddef }
  4394. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg,p1.fileinfo);
  4395. ptmp:=generate_inline_specialization(gendef,p1,filepos,parseddef,gensym,p2);
  4396. { we don't need these nodes anymore }
  4397. p1.free;
  4398. p2.free;
  4399. p1:=ptmp;
  4400. result:=true;
  4401. end;
  4402. end;
  4403. label
  4404. SubExprStart;
  4405. var
  4406. p1,p2,ptmp : tnode;
  4407. oldt : Ttoken;
  4408. filepos : tfileposinfo;
  4409. gendef,parseddef : tdef;
  4410. gensym : tsym;
  4411. genlist : tfpobjectlist;
  4412. dummyagain : boolean;
  4413. dummyspezctxt : tspecializationcontext;
  4414. begin
  4415. SubExprStart:
  4416. if pred_level=highest_precedence then
  4417. begin
  4418. if factornode=nil then
  4419. p1:=factor(false,flags)
  4420. else
  4421. p1:=factornode;
  4422. end
  4423. else
  4424. p1:=sub_expr(succ(pred_level),flags+[ef_accept_equal],factornode);
  4425. repeat
  4426. if (token in [NOTOKEN..last_operator]) and
  4427. (token in operator_levels[pred_level]) and
  4428. ((token<>_EQ) or (ef_accept_equal in flags)) then
  4429. begin
  4430. oldt:=token;
  4431. filepos:=current_tokenpos;
  4432. consume(token);
  4433. if pred_level=highest_precedence then
  4434. p2:=factor(false,[])
  4435. else
  4436. p2:=sub_expr(succ(pred_level),flags+[ef_accept_equal],nil);
  4437. case oldt of
  4438. _PLUS :
  4439. p1:=caddnode.create(addn,p1,p2);
  4440. _MINUS :
  4441. p1:=caddnode.create(subn,p1,p2);
  4442. _STAR :
  4443. p1:=caddnode.create(muln,p1,p2);
  4444. _SLASH :
  4445. p1:=caddnode.create(slashn,p1,p2);
  4446. _EQ:
  4447. p1:=caddnode.create(equaln,p1,p2);
  4448. _GT :
  4449. p1:=caddnode.create(gtn,p1,p2);
  4450. _LT :
  4451. begin
  4452. if maybe_handle_specialization(p1,p2,filepos) then
  4453. begin
  4454. { with p1 now set we are in reality directly behind the
  4455. call to "factor" thus we need to call down to that
  4456. again }
  4457. { This is disabled until specializations on the right
  4458. hand side work as well, because
  4459. "not working expressions" is better than "half working
  4460. expressions" }
  4461. {factornode:=p1;
  4462. goto SubExprStart;}
  4463. end
  4464. else
  4465. begin
  4466. { this is a normal "<" comparison }
  4467. { potential generic types that are followed by a "<": }
  4468. if p1.nodetype=specializen then
  4469. begin
  4470. genlist:=tfpobjectlist(current_module.genericdummysyms.find(tspecializenode(p1).sym.name));
  4471. if assigned(genlist) and (genlist.count>0) then
  4472. begin
  4473. gensym:=tgenericdummyentry(genlist.last).resolvedsym;
  4474. check_hints(gensym,gensym.symoptions,gensym.deprecatedmsg,p1.fileinfo);
  4475. dummyagain:=false;
  4476. dummyspezctxt:=nil;
  4477. ptmp:=factor_handle_sym(gensym,
  4478. gensym.owner,
  4479. dummyagain,
  4480. tspecializenode(p1).getaddr,
  4481. false,
  4482. flags,
  4483. dummyspezctxt);
  4484. if dummyagain then
  4485. internalerror(2022012201);
  4486. p1.free;
  4487. p1:=ptmp;
  4488. end
  4489. else
  4490. begin
  4491. identifier_not_found(tspecializenode(p1).sym.realname);
  4492. p1.free;
  4493. p1:=cerrornode.create;
  4494. end;
  4495. end;
  4496. { a) might not have their resultdef set }
  4497. if not assigned(p1.resultdef) then
  4498. do_typecheckpass(p1);
  4499. { b) are not checked whether they are an undefined def,
  4500. but not a generic parameter }
  4501. if (p1.nodetype=typen) and
  4502. (ttypenode(p1).typedef.typ=undefineddef) and
  4503. assigned(ttypenode(p1).typedef.typesym) and
  4504. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  4505. begin
  4506. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  4507. p1.Free;
  4508. p1:=cerrornode.create;
  4509. end;
  4510. { c) don't have their hints checked }
  4511. if istypenode(p1) then
  4512. begin
  4513. gendef:=gettypedef(p1);
  4514. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4515. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4516. end;
  4517. { Note: the second part of the expression will be needed
  4518. for nested specializations }
  4519. if istypenode(p2) {and
  4520. not (token in [_LT, _LSHARPBRACKET])} then
  4521. begin
  4522. gendef:=gettypedef(p2);
  4523. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4524. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4525. end;
  4526. { create the comparison node for "<" }
  4527. p1:=caddnode.create(ltn,p1,p2)
  4528. end;
  4529. end;
  4530. _GTE :
  4531. p1:=caddnode.create(gten,p1,p2);
  4532. _LTE :
  4533. p1:=caddnode.create(lten,p1,p2);
  4534. _SYMDIF :
  4535. p1:=caddnode.create(symdifn,p1,p2);
  4536. _STARSTAR :
  4537. p1:=caddnode.create(starstarn,p1,p2);
  4538. _OP_AS,
  4539. _OP_IS :
  4540. begin
  4541. if (m_delphi in current_settings.modeswitches) and
  4542. (token in [_LT, _LSHARPBRACKET]) and
  4543. getgenericsym(p2,gensym) then
  4544. begin
  4545. { for now we're handling this as a generic declaration;
  4546. there could be cases though (because of operator
  4547. overloading) where this is the wrong decision... }
  4548. if gensym.typ=typesym then
  4549. gendef:=ttypesym(gensym).typedef
  4550. else
  4551. if gensym.typ=procsym then
  4552. gendef:=tdef(tprocsym(gensym).procdeflist[0])
  4553. else
  4554. internalerror(2015072401);
  4555. ptmp:=generate_inline_specialization(gendef,p2,filepos,nil,nil,nil);
  4556. { we don't need the old p2 anymore }
  4557. p2.Free;
  4558. p2:=ptmp;
  4559. { here we don't need to call back down to "factor", thus
  4560. no "goto" }
  4561. end;
  4562. { now generate the "is" or "as" node }
  4563. case oldt of
  4564. _OP_AS:
  4565. p1:=casnode.create(p1,p2);
  4566. _OP_IS:
  4567. p1:=cisnode.create(p1,p2);
  4568. else
  4569. internalerror(2019050528);
  4570. end;
  4571. end;
  4572. _OP_IN :
  4573. p1:=cinnode.create(p1,p2);
  4574. _OP_OR,
  4575. _PIPE {macpas only} :
  4576. begin
  4577. p1:=caddnode.create(orn,p1,p2);
  4578. if (oldt = _PIPE) then
  4579. include(p1.flags,nf_short_bool);
  4580. end;
  4581. _OP_AND,
  4582. _AMPERSAND {macpas only} :
  4583. begin
  4584. p1:=caddnode.create(andn,p1,p2);
  4585. if (oldt = _AMPERSAND) then
  4586. include(p1.flags,nf_short_bool);
  4587. end;
  4588. _OP_DIV :
  4589. p1:=cmoddivnode.create(divn,p1,p2);
  4590. _OP_NOT :
  4591. p1:=cnotnode.create(p1);
  4592. _OP_MOD :
  4593. begin
  4594. p1:=cmoddivnode.create(modn,p1,p2);
  4595. if m_isolike_mod in current_settings.modeswitches then
  4596. include(p1.flags,nf_isomod);
  4597. end;
  4598. _OP_SHL :
  4599. p1:=cshlshrnode.create(shln,p1,p2);
  4600. _OP_SHR :
  4601. p1:=cshlshrnode.create(shrn,p1,p2);
  4602. _OP_XOR :
  4603. p1:=caddnode.create(xorn,p1,p2);
  4604. _ASSIGNMENT :
  4605. p1:=cassignmentnode.create(p1,p2);
  4606. _NE :
  4607. p1:=caddnode.create(unequaln,p1,p2);
  4608. else
  4609. internalerror(2019050529);
  4610. end;
  4611. p1.fileinfo:=filepos;
  4612. end
  4613. else
  4614. break;
  4615. until false;
  4616. if (p1.nodetype=specializen) and
  4617. (token=_LSHARPBRACKET) and
  4618. (m_delphi in current_settings.modeswitches) then
  4619. begin
  4620. filepos:=current_tokenpos;
  4621. consume(token);
  4622. p2:=factor(false,[]);
  4623. if maybe_handle_specialization(p1,p2,filepos) then
  4624. begin
  4625. { with p1 now set we are in reality directly behind the
  4626. call to "factor" thus we need to call down to that
  4627. again }
  4628. { This is disabled until specializations on the right
  4629. hand side work as well, because
  4630. "not working expressions" is better than "half working
  4631. expressions" }
  4632. {factornode:=p1;
  4633. goto SubExprStart;}
  4634. end else
  4635. message(parser_e_illegal_expression);
  4636. end;
  4637. sub_expr:=p1;
  4638. end;
  4639. function comp_expr(flags:texprflags):tnode;
  4640. var
  4641. oldafterassignment : boolean;
  4642. p1 : tnode;
  4643. begin
  4644. oldafterassignment:=afterassignment;
  4645. afterassignment:=true;
  4646. p1:=sub_expr(opcompare,flags,nil);
  4647. { get the resultdef for this expression }
  4648. if not assigned(p1.resultdef) then
  4649. do_typecheckpass(p1);
  4650. afterassignment:=oldafterassignment;
  4651. comp_expr:=p1;
  4652. end;
  4653. function expr(dotypecheck : boolean) : tnode;
  4654. var
  4655. p1,p2 : tnode;
  4656. filepos : tfileposinfo;
  4657. oldafterassignment,
  4658. updatefpos : boolean;
  4659. oldflags : tnodeflags;
  4660. begin
  4661. oldafterassignment:=afterassignment;
  4662. p1:=sub_expr(opcompare,[ef_accept_equal],nil);
  4663. { get the resultdef for this expression }
  4664. if not assigned(p1.resultdef) and
  4665. dotypecheck then
  4666. do_typecheckpass(p1);
  4667. filepos:=current_tokenpos;
  4668. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  4669. afterassignment:=true;
  4670. updatefpos:=true;
  4671. case token of
  4672. _POINTPOINT :
  4673. begin
  4674. consume(_POINTPOINT);
  4675. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4676. p1:=crangenode.create(p1,p2);
  4677. end;
  4678. _ASSIGNMENT :
  4679. begin
  4680. consume(_ASSIGNMENT);
  4681. if assigned(p1.resultdef) then
  4682. if (p1.resultdef.typ=procvardef) then
  4683. getprocvardef:=tprocvardef(p1.resultdef)
  4684. else if is_invokable(p1.resultdef) then
  4685. getfuncrefdef:=tobjectdef(p1.resultdef);
  4686. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4687. if assigned(getprocvardef) then
  4688. handle_procvar(getprocvardef,p2)
  4689. else if assigned(getfuncrefdef) then
  4690. handle_funcref(getfuncrefdef,p2);
  4691. getprocvardef:=nil;
  4692. getfuncrefdef:=nil;
  4693. p1:=cassignmentnode.create(p1,p2);
  4694. end;
  4695. _PLUSASN :
  4696. begin
  4697. consume(_PLUSASN);
  4698. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4699. p1:=gen_c_style_operator(addn,p1,p2);
  4700. end;
  4701. _MINUSASN :
  4702. begin
  4703. consume(_MINUSASN);
  4704. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4705. p1:=gen_c_style_operator(subn,p1,p2);
  4706. end;
  4707. _STARASN :
  4708. begin
  4709. consume(_STARASN );
  4710. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4711. p1:=gen_c_style_operator(muln,p1,p2);
  4712. end;
  4713. _SLASHASN :
  4714. begin
  4715. consume(_SLASHASN );
  4716. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4717. p1:=gen_c_style_operator(slashn,p1,p2);
  4718. end;
  4719. else
  4720. updatefpos:=false;
  4721. end;
  4722. oldflags:=p1.flags;
  4723. { get the resultdef for this expression }
  4724. if not assigned(p1.resultdef) and
  4725. dotypecheck then
  4726. do_typecheckpass(p1);
  4727. { transfer generic parameter flag }
  4728. if nf_generic_para in oldflags then
  4729. include(p1.flags,nf_generic_para);
  4730. afterassignment:=oldafterassignment;
  4731. if updatefpos then
  4732. p1.fileinfo:=filepos;
  4733. expr:=p1;
  4734. end;
  4735. function get_intconst:TConstExprInt;
  4736. {Reads an expression, tries to evalute it and check if it is an integer
  4737. constant. Then the constant is returned.}
  4738. var
  4739. p:tnode;
  4740. begin
  4741. result:=0;
  4742. p:=comp_expr([ef_accept_equal]);
  4743. if not codegenerror then
  4744. begin
  4745. if (p.nodetype<>ordconstn) or
  4746. not(is_integer(p.resultdef)) then
  4747. Message(parser_e_illegal_expression)
  4748. else
  4749. result:=tordconstnode(p).value;
  4750. end;
  4751. p.free;
  4752. end;
  4753. function get_stringconst:string;
  4754. {Reads an expression, tries to evaluate it and checks if it is a string
  4755. constant. Then the constant is returned.}
  4756. var
  4757. p:tnode;
  4758. begin
  4759. get_stringconst:='';
  4760. p:=comp_expr([ef_accept_equal]);
  4761. if p.nodetype<>stringconstn then
  4762. begin
  4763. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  4764. get_stringconst:=char(int64(tordconstnode(p).value))
  4765. else
  4766. Message(parser_e_illegal_expression);
  4767. end
  4768. else
  4769. get_stringconst:=strpas(tstringconstnode(p).value_str);
  4770. p.free;
  4771. end;
  4772. end.