pexpr.pas 194 KB

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