pexpr.pas 192 KB

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