pexpr.pas 208 KB

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