pexpr.pas 207 KB

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