pexpr.pas 194 KB

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