pexpr.pas 205 KB

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