pexpr.pas 193 KB

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