pexpr.pas 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752
  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. if assigned(spezcontext.symtable) then
  2887. srsymtable:=spezcontext.symtable
  2888. else
  2889. srsymtable:=srsym.owner;
  2890. end;
  2891. end
  2892. else
  2893. internalerror(2015061204);
  2894. end;
  2895. end;
  2896. end;
  2897. wasgenericdummy:=false;
  2898. if assigned(srsym) and
  2899. (sp_generic_dummy in srsym.symoptions) and
  2900. (srsym.typ=typesym) and
  2901. (
  2902. (
  2903. (m_delphi in current_settings.modeswitches) and
  2904. not (token in [_LT, _LSHARPBRACKET]) and
  2905. (ttypesym(srsym).typedef.typ=undefineddef)
  2906. )
  2907. or
  2908. (
  2909. not (m_delphi in current_settings.modeswitches) and
  2910. not isspecialize and
  2911. (
  2912. not parse_generic or
  2913. not (
  2914. assigned(current_structdef) and
  2915. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2916. )
  2917. )
  2918. )
  2919. ) then
  2920. begin
  2921. srsym:=resolve_generic_dummysym(srsym.name);
  2922. if assigned(srsym) then
  2923. srsymtable:=srsym.owner
  2924. else
  2925. begin
  2926. srsymtable:=nil;
  2927. wasgenericdummy:=true;
  2928. end;
  2929. end;
  2930. { check hints, but only if it isn't a potential generic symbol;
  2931. that is checked in sub_expr if it isn't a generic }
  2932. if assigned(srsym) and
  2933. not (
  2934. (srsym.typ=typesym) and
  2935. (
  2936. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) or
  2937. (
  2938. (ttypesym(srsym).typedef.typ=errordef) and
  2939. (sp_generic_dummy in srsym.symoptions)
  2940. )
  2941. ) and
  2942. not (sp_generic_para in srsym.symoptions) and
  2943. (token in [_LT, _LSHARPBRACKET])
  2944. ) then
  2945. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2946. { if nothing found give error and return errorsym }
  2947. if not assigned(srsym) or
  2948. { is this a generic dummy symbol? }
  2949. ((srsym.typ=typesym) and
  2950. assigned(ttypesym(srsym).typedef) and
  2951. (ttypesym(srsym).typedef.typ=undefineddef) and
  2952. not (sp_generic_para in srsym.symoptions) and
  2953. not (token in [_LT, _LSHARPBRACKET]) and
  2954. not (
  2955. { in non-Delphi modes the generic class' name without a
  2956. "specialization" or "<T>" may be used to identify the
  2957. current class }
  2958. (sp_generic_dummy in srsym.symoptions) and
  2959. assigned(current_structdef) and
  2960. (df_generic in current_structdef.defoptions) and
  2961. not (m_delphi in current_settings.modeswitches) and
  2962. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2963. )) and
  2964. { it could be a rename of a generic para }
  2965. { Note: if this generates false positives we'll need to
  2966. include a "basesym" to tsym to track the original
  2967. symbol }
  2968. not (sp_explicitrename in srsym.symoptions) then
  2969. begin
  2970. { if a generic is parsed and when we are inside an with block,
  2971. a symbol might not be defined }
  2972. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  2973. findwithsymtable then
  2974. begin
  2975. { create dummy symbol, it will be freed later on }
  2976. srsym:=tstoredsym.create(undefinedsym,'$undefinedsym');
  2977. srsymtable:=nil;
  2978. end
  2979. else
  2980. begin
  2981. if wasgenericdummy then
  2982. messagepos(tokenpos,parser_e_no_generics_as_types)
  2983. else
  2984. identifier_not_found(orgstoredpattern,tokenpos);
  2985. srsym:=generrorsym;
  2986. srsymtable:=nil;
  2987. end;
  2988. end;
  2989. end;
  2990. { Access to funcret or need to call the function? }
  2991. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  2992. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  2993. { result(x) is not allowed }
  2994. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  2995. (
  2996. (token=_LKLAMMER) or
  2997. (
  2998. (([m_tp7,m_delphi,m_mac,m_iso,m_extpas] * current_settings.modeswitches) <> []) and
  2999. (afterassignment or in_args)
  3000. )
  3001. ) then
  3002. begin
  3003. hdef:=tdef(srsym.owner.defowner);
  3004. if assigned(hdef) and
  3005. (hdef.typ=procdef) then
  3006. srsym:=tprocdef(hdef).procsym
  3007. else
  3008. begin
  3009. Message(parser_e_illegal_expression);
  3010. srsym:=generrorsym;
  3011. end;
  3012. srsymtable:=srsym.owner;
  3013. end;
  3014. begin
  3015. case srsym.typ of
  3016. absolutevarsym :
  3017. begin
  3018. if (tabsolutevarsym(srsym).abstyp=tovar) then
  3019. begin
  3020. p1:=nil;
  3021. propaccesslist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  3022. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vardef);
  3023. include(p1.flags,nf_absolute);
  3024. end
  3025. else
  3026. p1:=cloadnode.create(srsym,srsymtable);
  3027. end;
  3028. staticvarsym,
  3029. localvarsym,
  3030. paravarsym,
  3031. fieldvarsym :
  3032. begin
  3033. { check if we are reading a field of an object/class/ }
  3034. { record. is_member_read() will deal with withsymtables }
  3035. { if needed. }
  3036. p1:=nil;
  3037. if is_member_read(srsym,srsymtable,p1,hdef) then
  3038. begin
  3039. { if the field was originally found in an }
  3040. { objectsymtable, it means it's part of self }
  3041. { if only method from which it was called is }
  3042. { not class static }
  3043. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3044. { if we are accessing a owner procsym from the nested }
  3045. { class we need to call it as a class member }
  3046. if assigned(current_structdef) and
  3047. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3048. (sp_static in srsym.symoptions)) then
  3049. if srsymtable.symtabletype=recordsymtable then
  3050. p1:=ctypenode.create(hdef)
  3051. else
  3052. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  3053. else
  3054. begin
  3055. if assigned(current_procinfo) then
  3056. begin
  3057. pd:=current_procinfo.get_normal_proc.procdef;
  3058. if assigned(pd) and pd.no_self_node then
  3059. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  3060. else
  3061. p1:=load_self_node;
  3062. end
  3063. else
  3064. p1:=load_self_node;
  3065. end;
  3066. { now, if the field itself is part of an objectsymtab }
  3067. { (it can be even if it was found in a withsymtable, }
  3068. { e.g., "with classinstance do field := 5"), then }
  3069. { let do_member_read handle it }
  3070. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3071. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],nil)
  3072. else
  3073. { otherwise it's a regular record subscript }
  3074. p1:=csubscriptnode.create(srsym,p1);
  3075. end
  3076. else
  3077. { regular non-field load }
  3078. p1:=cloadnode.create(srsym,srsymtable);
  3079. end;
  3080. syssym :
  3081. begin
  3082. p1:=statement_syssym(tsyssym(srsym).number);
  3083. end;
  3084. typesym :
  3085. begin
  3086. hdef:=ttypesym(srsym).typedef;
  3087. if not assigned(hdef) then
  3088. begin
  3089. again:=false;
  3090. end
  3091. else
  3092. begin
  3093. if (m_delphi in current_settings.modeswitches) and
  3094. (sp_generic_dummy in srsym.symoptions) and
  3095. (token in [_LT,_LSHARPBRACKET]) then
  3096. begin
  3097. if block_type in [bt_type,bt_const_type,bt_var_type] then
  3098. begin
  3099. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) or (srsym.typ=procsym) then
  3100. begin
  3101. spezcontext.free;
  3102. p1:=cerrornode.create;
  3103. if try_to_consume(_LKLAMMER) then
  3104. begin
  3105. parse_paras(false,false,_RKLAMMER);
  3106. consume(_RKLAMMER);
  3107. end;
  3108. end
  3109. else
  3110. begin
  3111. if srsym.typ<>typesym then
  3112. internalerror(2015071705);
  3113. hdef:=ttypesym(srsym).typedef;
  3114. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  3115. end;
  3116. end
  3117. else
  3118. p1:=cspecializenode.create(nil,getaddr,srsym)
  3119. end
  3120. else
  3121. begin
  3122. { We need to know if this unit uses Variants }
  3123. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  3124. not(cs_compilesystem in current_settings.moduleswitches) then
  3125. include(current_module.moduleflags,mf_uses_variants);
  3126. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  3127. end;
  3128. end;
  3129. end;
  3130. enumsym :
  3131. begin
  3132. p1:=genenumnode(tenumsym(srsym));
  3133. end;
  3134. constsym :
  3135. begin
  3136. if tconstsym(srsym).consttyp=constresourcestring then
  3137. begin
  3138. p1:=cloadnode.create(srsym,srsymtable);
  3139. do_typecheckpass(p1);
  3140. p1.resultdef:=getansistringdef;
  3141. end
  3142. else
  3143. p1:=genconstsymtree(tconstsym(srsym));
  3144. end;
  3145. procsym :
  3146. begin
  3147. p1:=nil;
  3148. { check if it's a method/class method }
  3149. if is_member_read(srsym,srsymtable,p1,hdef) then
  3150. begin
  3151. { if we are accessing a owner procsym from the nested }
  3152. { class we need to call it as a class member }
  3153. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  3154. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  3155. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  3156. { not srsymtable.symtabletype since that can be }
  3157. { withsymtable as well }
  3158. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3159. begin
  3160. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],spezcontext);
  3161. spezcontext:=nil;
  3162. end
  3163. else
  3164. { no procsyms in records (yet) }
  3165. internalerror(2007012006);
  3166. end
  3167. else
  3168. begin
  3169. { regular procedure/function call }
  3170. if not unit_found then
  3171. callflags:=[]
  3172. else
  3173. callflags:=[cnf_unit_specified];
  3174. { TP7 uglyness: @proc^ is parsed as (@proc)^,
  3175. but @notproc^ is parsed as @(notproc^) }
  3176. if m_tp_procvar in current_settings.modeswitches then
  3177. tmpgetaddr:=getaddr and not(token in [_POINT,_LECKKLAMMER])
  3178. else
  3179. tmpgetaddr:=getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER]);
  3180. do_proc_call(srsym,srsymtable,nil,tmpgetaddr,
  3181. again,p1,callflags,spezcontext);
  3182. spezcontext:=nil;
  3183. end;
  3184. end;
  3185. propertysym :
  3186. begin
  3187. p1:=nil;
  3188. { property of a class/object? }
  3189. if is_member_read(srsym,srsymtable,p1,hdef) then
  3190. begin
  3191. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3192. { if we are accessing a owner procsym from the nested }
  3193. { class or from a static class method we need to call }
  3194. { it as a class member }
  3195. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3196. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  3197. begin
  3198. p1:=ctypenode.create(hdef);
  3199. if not is_record(hdef) then
  3200. p1:=cloadvmtaddrnode.create(p1);
  3201. end
  3202. else
  3203. p1:=load_self_node;
  3204. { not srsymtable.symtabletype since that can be }
  3205. { withsymtable as well }
  3206. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3207. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],nil)
  3208. else
  3209. { no propertysyms in records (yet) }
  3210. internalerror(2009111510);
  3211. end
  3212. else
  3213. { no method pointer }
  3214. begin
  3215. handle_propertysym(tpropertysym(srsym),srsymtable,p1);
  3216. end;
  3217. end;
  3218. labelsym :
  3219. begin
  3220. { Support @label }
  3221. if getaddr then
  3222. begin
  3223. if srsym.owner<>current_procinfo.procdef.localst then
  3224. CGMessage(parser_e_label_outside_proc);
  3225. p1:=cloadnode.create(srsym,srsym.owner)
  3226. end
  3227. else
  3228. begin
  3229. consume(_COLON);
  3230. if tlabelsym(srsym).defined then
  3231. Message(sym_e_label_already_defined);
  3232. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  3233. begin
  3234. include(current_procinfo.flags,pi_has_interproclabel);
  3235. if (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  3236. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  3237. end;
  3238. tlabelsym(srsym).defined:=true;
  3239. p1:=clabelnode.create(nil,tlabelsym(srsym));
  3240. tlabelsym(srsym).code:=p1;
  3241. end;
  3242. end;
  3243. undefinedsym :
  3244. begin
  3245. p1:=cnothingnode.Create;
  3246. p1.resultdef:=cundefineddef.create(true);
  3247. { clean up previously created dummy symbol }
  3248. srsym.free;
  3249. end;
  3250. errorsym :
  3251. begin
  3252. p1:=cerrornode.create;
  3253. if try_to_consume(_LKLAMMER) then
  3254. begin
  3255. parse_paras(false,false,_RKLAMMER);
  3256. consume(_RKLAMMER);
  3257. end;
  3258. end;
  3259. else
  3260. begin
  3261. p1:=cerrornode.create;
  3262. Message(parser_e_illegal_expression);
  3263. end;
  3264. end; { end case }
  3265. if assigned(spezcontext) then
  3266. internalerror(2015061207);
  3267. if assigned(p1) and (p1.nodetype<>errorn) then
  3268. p1.fileinfo:=tokenpos;
  3269. end;
  3270. end;
  3271. {---------------------------------------------
  3272. Factor_Read_Set
  3273. ---------------------------------------------}
  3274. { Read a set between [] }
  3275. function factor_read_set:tnode;
  3276. var
  3277. p1,p2 : tnode;
  3278. lastp,
  3279. buildp : tarrayconstructornode;
  3280. begin
  3281. buildp:=nil;
  3282. lastp:=nil;
  3283. { be sure that a least one arrayconstructn is used, also for an
  3284. empty [] }
  3285. if token=_RECKKLAMMER then
  3286. buildp:=carrayconstructornode.create(nil,buildp)
  3287. else
  3288. repeat
  3289. p1:=comp_expr([ef_accept_equal]);
  3290. if try_to_consume(_POINTPOINT) then
  3291. begin
  3292. p2:=comp_expr([ef_accept_equal]);
  3293. p1:=carrayconstructorrangenode.create(p1,p2);
  3294. end;
  3295. { insert at the end of the tree, to get the correct order }
  3296. if not assigned(buildp) then
  3297. begin
  3298. buildp:=carrayconstructornode.create(p1,nil);
  3299. lastp:=buildp;
  3300. end
  3301. else
  3302. begin
  3303. lastp.right:=carrayconstructornode.create(p1,nil);
  3304. lastp:=tarrayconstructornode(lastp.right);
  3305. end;
  3306. { there could be more elements }
  3307. until not try_to_consume(_COMMA);
  3308. buildp.allow_array_constructor:=block_type in [bt_body,bt_except];
  3309. factor_read_set:=buildp;
  3310. end;
  3311. function can_load_self_node: boolean;
  3312. begin
  3313. result:=false;
  3314. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3315. not assigned(current_structdef) or
  3316. not assigned(current_procinfo) then
  3317. exit;
  3318. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  3319. end;
  3320. {---------------------------------------------
  3321. Factor (Main)
  3322. ---------------------------------------------}
  3323. var
  3324. l : longint;
  3325. ic : int64;
  3326. qc : qword;
  3327. p1 : tnode;
  3328. code : integer;
  3329. srsym : tsym;
  3330. srsymtable : TSymtable;
  3331. pd : tprocdef;
  3332. hclassdef : tobjectdef;
  3333. d : bestreal;
  3334. hs,hsorg : string;
  3335. hdef : tdef;
  3336. filepos : tfileposinfo;
  3337. callflags : tcallnodeflags;
  3338. idstr : tidstring;
  3339. spezcontext : tspecializationcontext;
  3340. isspecialize,
  3341. mightbegeneric,
  3342. useself,
  3343. dopostfix,
  3344. again,
  3345. updatefpos,
  3346. nodechanged : boolean;
  3347. begin
  3348. { can't keep a copy of p1 and compare pointers afterwards, because
  3349. p1 may be freed and reallocated in the same place! }
  3350. dopostfix:=true;
  3351. updatefpos:=false;
  3352. p1:=nil;
  3353. filepos:=current_tokenpos;
  3354. again:=false;
  3355. pd:=nil;
  3356. isspecialize:=false;
  3357. if token=_ID then
  3358. begin
  3359. again:=true;
  3360. { Handle references to self }
  3361. if (idtoken=_SELF) and can_load_self_node then
  3362. begin
  3363. p1:=load_self_node;
  3364. consume(_ID);
  3365. again:=true;
  3366. end
  3367. else
  3368. factor_read_id(p1,again);
  3369. if assigned(p1) then
  3370. begin
  3371. { factor_read_id will set the filepos to after the id,
  3372. and in case of _SELF the filepos will already be the
  3373. same as filepos (so setting it again doesn't hurt). }
  3374. p1.fileinfo:=filepos;
  3375. filepos:=current_tokenpos;
  3376. end;
  3377. { handle post fix operators }
  3378. if (p1.nodetype=specializen) then
  3379. { post fix operators are handled after specialization }
  3380. dopostfix:=false
  3381. else
  3382. if (m_delphi in current_settings.modeswitches) and
  3383. (block_type=bt_body) and
  3384. (token in [_LT,_LSHARPBRACKET]) then
  3385. begin
  3386. if p1.nodetype=typen then
  3387. idstr:=ttypenode(p1).typesym.name
  3388. else
  3389. if (p1.nodetype=loadvmtaddrn) and
  3390. (tloadvmtaddrnode(p1).left.nodetype=typen) then
  3391. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name
  3392. else
  3393. if (p1.nodetype=loadn) then
  3394. idstr:=tloadnode(p1).symtableentry.name
  3395. else
  3396. idstr:='';
  3397. { if this is the case then the postfix handling is done in
  3398. sub_expr if necessary }
  3399. dopostfix:=not could_be_generic(idstr);
  3400. end;
  3401. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^ is parsed
  3402. as @(notproc^) }
  3403. if (m_tp_procvar in current_settings.modeswitches) and (token=_CARET) and
  3404. getaddr and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym) then
  3405. dopostfix:=false;
  3406. { maybe an additional parameter instead of misusing hadspezialize? }
  3407. if dopostfix and not (ef_had_specialize in flags) then
  3408. updatefpos:=postfixoperators(p1,again,getaddr);
  3409. end
  3410. else
  3411. begin
  3412. updatefpos:=true;
  3413. case token of
  3414. _RETURN :
  3415. begin
  3416. consume(_RETURN);
  3417. p1:=nil;
  3418. if not(token in [_SEMICOLON,_ELSE,_END]) then
  3419. begin
  3420. p1:=comp_expr([ef_accept_equal]);
  3421. if not assigned(current_procinfo) or
  3422. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  3423. is_void(current_procinfo.procdef.returndef) then
  3424. begin
  3425. Message(parser_e_void_function);
  3426. { recovery }
  3427. p1.free;
  3428. p1:=nil;
  3429. end;
  3430. end;
  3431. p1 := cexitnode.create(p1);
  3432. end;
  3433. _INHERITED :
  3434. begin
  3435. again:=true;
  3436. consume(_INHERITED);
  3437. if assigned(current_procinfo) and
  3438. assigned(current_structdef) and
  3439. ((current_structdef.typ=objectdef) or
  3440. ((target_info.system in systems_jvm) and
  3441. (current_structdef.typ=recorddef)))then
  3442. begin
  3443. { for record helpers in mode Delphi "inherited" is not
  3444. allowed }
  3445. if is_objectpascal_helper(current_structdef) and
  3446. (m_delphi in current_settings.modeswitches) and
  3447. (tobjectdef(current_structdef).helpertype=ht_record) then
  3448. Message(parser_e_inherited_not_in_record);
  3449. if (current_structdef.typ=objectdef) then
  3450. begin
  3451. hclassdef:=tobjectdef(current_structdef).childof;
  3452. { Objective-C categories *replace* methods in the class
  3453. they extend, or add methods to it. So calling an
  3454. inherited method always calls the method inherited from
  3455. the parent of the extended class }
  3456. if is_objccategory(current_structdef) then
  3457. hclassdef:=hclassdef.childof;
  3458. end
  3459. else if target_info.system in systems_jvm then
  3460. hclassdef:=java_fpcbaserecordtype
  3461. else
  3462. internalerror(2012012401);
  3463. spezcontext:=nil;
  3464. { if inherited; only then we need the method with
  3465. the same name }
  3466. if token <> _ID then
  3467. begin
  3468. hs:=current_procinfo.procdef.procsym.name;
  3469. hsorg:=current_procinfo.procdef.procsym.realname;
  3470. anon_inherited:=true;
  3471. { For message methods we need to search using the message
  3472. number or string }
  3473. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3474. srdef:=nil;
  3475. if (po_msgint in pd.procoptions) then
  3476. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3477. else
  3478. if (po_msgstr in pd.procoptions) then
  3479. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3480. else
  3481. { helpers have their own ways of dealing with inherited }
  3482. if is_objectpascal_helper(current_structdef) then
  3483. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3484. else
  3485. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3486. end
  3487. else
  3488. begin
  3489. if not (m_delphi in current_settings.modeswitches) and
  3490. (block_type in inline_specialization_block_types) and
  3491. (token=_ID) and
  3492. (idtoken=_SPECIALIZE) then
  3493. begin
  3494. consume(_ID);
  3495. if token<>_ID then
  3496. message(parser_e_methode_id_expected);
  3497. isspecialize:=true;
  3498. end
  3499. else
  3500. isspecialize:=false;
  3501. hs:=pattern;
  3502. hsorg:=orgpattern;
  3503. consume(_ID);
  3504. anon_inherited:=false;
  3505. { helpers have their own ways of dealing with inherited }
  3506. if is_objectpascal_helper(current_structdef) then
  3507. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3508. else
  3509. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3510. if isspecialize and assigned(srsym) then
  3511. begin
  3512. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  3513. srsym:=nil;
  3514. end;
  3515. end;
  3516. if assigned(srsym) then
  3517. begin
  3518. mightbegeneric:=(m_delphi in current_settings.modeswitches) and
  3519. (token in [_LT,_LSHARPBRACKET]) and
  3520. (sp_generic_dummy in srsym.symoptions);
  3521. { load the procdef from the inherited class and
  3522. not from self }
  3523. case srsym.typ of
  3524. typesym,
  3525. procsym:
  3526. begin
  3527. { typesym is only a valid choice if we're dealing
  3528. with a potential generic }
  3529. if (srsym.typ=typesym) and not mightbegeneric then
  3530. begin
  3531. Message(parser_e_methode_id_expected);
  3532. p1:=cerrornode.create;
  3533. end
  3534. else
  3535. begin
  3536. useself:=false;
  3537. if is_objectpascal_helper(current_structdef) then
  3538. begin
  3539. { for a helper load the procdef either from the
  3540. extended type, from the parent helper or from
  3541. the extended type of the parent helper
  3542. depending on the def the found symbol belongs
  3543. to }
  3544. if (srsym.Owner.defowner.typ=objectdef) and
  3545. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3546. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3547. assigned(tobjectdef(current_structdef).childof) then
  3548. hdef:=tobjectdef(current_structdef).childof
  3549. else
  3550. begin
  3551. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef;
  3552. useself:=true;
  3553. end
  3554. else
  3555. begin
  3556. hdef:=tdef(srsym.Owner.defowner);
  3557. useself:=true;
  3558. end;
  3559. end
  3560. else
  3561. hdef:=hclassdef;
  3562. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3563. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3564. hdef:=cclassrefdef.create(hdef);
  3565. if useself then
  3566. begin
  3567. p1:=ctypeconvnode.create_internal(load_self_node,hdef);
  3568. end
  3569. else
  3570. begin
  3571. p1:=ctypenode.create(hdef);
  3572. { we need to allow helpers here }
  3573. ttypenode(p1).helperallowed:=true;
  3574. end;
  3575. end;
  3576. end;
  3577. propertysym:
  3578. ;
  3579. else
  3580. begin
  3581. Message(parser_e_methode_id_expected);
  3582. p1:=cerrornode.create;
  3583. end;
  3584. end;
  3585. if mightbegeneric then
  3586. begin
  3587. p1:=cspecializenode.create_inherited(p1,getaddr,srsym,hclassdef);
  3588. end
  3589. else
  3590. begin
  3591. if not isspecialize then
  3592. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3593. callflags:=[cnf_inherited];
  3594. include(current_procinfo.flags,pi_has_inherited);
  3595. if anon_inherited then
  3596. include(callflags,cnf_anon_inherited);
  3597. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags,spezcontext);
  3598. end;
  3599. if p1.nodetype=errorn then
  3600. spezcontext.free;
  3601. end
  3602. else
  3603. begin
  3604. if anon_inherited then
  3605. begin
  3606. { For message methods we need to call DefaultHandler }
  3607. if (po_msgint in pd.procoptions) or
  3608. (po_msgstr in pd.procoptions) then
  3609. begin
  3610. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3611. if not assigned(srsym) or
  3612. (srsym.typ<>procsym) then
  3613. internalerror(200303171);
  3614. p1:=nil;
  3615. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[],nil);
  3616. end
  3617. else
  3618. begin
  3619. { we need to ignore the inherited; }
  3620. p1:=cnothingnode.create;
  3621. end;
  3622. end
  3623. else
  3624. begin
  3625. Message1(sym_e_id_no_member,hsorg);
  3626. p1:=cerrornode.create;
  3627. end;
  3628. again:=false;
  3629. end;
  3630. { turn auto inheriting off }
  3631. anon_inherited:=false;
  3632. end
  3633. else
  3634. begin
  3635. { in case of records we use a more clear error message }
  3636. if assigned(current_structdef) and
  3637. (current_structdef.typ=recorddef) then
  3638. Message(parser_e_inherited_not_in_record)
  3639. else
  3640. Message(parser_e_generic_methods_only_in_methods);
  3641. again:=false;
  3642. p1:=cerrornode.create;
  3643. end;
  3644. if p1.nodetype<>specializen then
  3645. postfixoperators(p1,again,getaddr);
  3646. end;
  3647. _INTCONST :
  3648. begin
  3649. {Try first wether the value fits in an int64.}
  3650. val(pattern,ic,code);
  3651. if code=0 then
  3652. begin
  3653. consume(_INTCONST);
  3654. int_to_type(ic,hdef);
  3655. p1:=cordconstnode.create(ic,hdef,true);
  3656. end
  3657. else
  3658. begin
  3659. { try qword next }
  3660. val(pattern,qc,code);
  3661. if code=0 then
  3662. begin
  3663. consume(_INTCONST);
  3664. int_to_type(qc,hdef);
  3665. p1:=cordconstnode.create(qc,hdef,true);
  3666. end;
  3667. end;
  3668. if code<>0 then
  3669. begin
  3670. { finally float }
  3671. val(pattern,d,code);
  3672. if code<>0 then
  3673. begin
  3674. Message(parser_e_invalid_integer);
  3675. consume(_INTCONST);
  3676. l:=1;
  3677. p1:=cordconstnode.create(l,sinttype,true);
  3678. end
  3679. else
  3680. begin
  3681. consume(_INTCONST);
  3682. p1:=crealconstnode.create(d,pbestrealtype^);
  3683. end;
  3684. end
  3685. else
  3686. { the necessary range checking has already been done by val }
  3687. tordconstnode(p1).rangecheck:=false;
  3688. if token=_POINT then
  3689. begin
  3690. again:=true;
  3691. postfixoperators(p1,again,getaddr);
  3692. end;
  3693. end;
  3694. _REALNUMBER :
  3695. begin
  3696. p1:=real_const_node_from_pattern(pattern);
  3697. consume(_REALNUMBER);
  3698. if token=_POINT then
  3699. begin
  3700. again:=true;
  3701. postfixoperators(p1,again,getaddr);
  3702. end;
  3703. end;
  3704. _STRING :
  3705. begin
  3706. string_dec(hdef,true);
  3707. { STRING can be also a type cast }
  3708. if try_to_consume(_LKLAMMER) then
  3709. begin
  3710. p1:=comp_expr([ef_accept_equal]);
  3711. consume(_RKLAMMER);
  3712. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3713. { handle postfix operators here e.g. string(a)[10] }
  3714. again:=true;
  3715. postfixoperators(p1,again,getaddr);
  3716. end
  3717. else
  3718. begin
  3719. p1:=ctypenode.create(hdef);
  3720. if token=_POINT then
  3721. begin
  3722. again:=true;
  3723. { handle type helpers here }
  3724. postfixoperators(p1,again,getaddr);
  3725. end;
  3726. end;
  3727. end;
  3728. _FILE :
  3729. begin
  3730. hdef:=cfiletype;
  3731. consume(_FILE);
  3732. { FILE can be also a type cast }
  3733. if try_to_consume(_LKLAMMER) then
  3734. begin
  3735. p1:=comp_expr([ef_accept_equal]);
  3736. consume(_RKLAMMER);
  3737. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3738. { handle postfix operators here e.g. string(a)[10] }
  3739. again:=true;
  3740. postfixoperators(p1,again,getaddr);
  3741. end
  3742. else
  3743. begin
  3744. p1:=ctypenode.create(hdef);
  3745. end;
  3746. end;
  3747. _CSTRING :
  3748. begin
  3749. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3750. consume(_CSTRING);
  3751. if token in postfixoperator_tokens then
  3752. begin
  3753. again:=true;
  3754. postfixoperators(p1,again,getaddr);
  3755. end;
  3756. end;
  3757. _CCHAR :
  3758. begin
  3759. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3760. consume(_CCHAR);
  3761. if token=_POINT then
  3762. begin
  3763. again:=true;
  3764. postfixoperators(p1,again,getaddr);
  3765. end;
  3766. end;
  3767. _CWSTRING:
  3768. begin
  3769. if getlengthwidestring(patternw)=1 then
  3770. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
  3771. else
  3772. p1:=cstringconstnode.createunistr(patternw);
  3773. consume(_CWSTRING);
  3774. if token in postfixoperator_tokens then
  3775. begin
  3776. again:=true;
  3777. postfixoperators(p1,again,getaddr);
  3778. end;
  3779. end;
  3780. _CWCHAR:
  3781. begin
  3782. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3783. consume(_CWCHAR);
  3784. if token=_POINT then
  3785. begin
  3786. again:=true;
  3787. postfixoperators(p1,again,getaddr);
  3788. end;
  3789. end;
  3790. _KLAMMERAFFE :
  3791. begin
  3792. consume(_KLAMMERAFFE);
  3793. got_addrn:=true;
  3794. { support both @<x> and @(<x>) }
  3795. if try_to_consume(_LKLAMMER) then
  3796. begin
  3797. p1:=factor(true,[]);
  3798. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3799. if token<>_RKLAMMER then
  3800. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  3801. consume(_RKLAMMER);
  3802. end
  3803. else
  3804. p1:=factor(true,[]);
  3805. if (token in postfixoperator_tokens) and
  3806. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^
  3807. is parsed as @(notproc^) }
  3808. not
  3809. (
  3810. (m_tp_procvar in current_settings.modeswitches) and
  3811. (token=_CARET) and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym)
  3812. )
  3813. then
  3814. begin
  3815. again:=true;
  3816. postfixoperators(p1,again,getaddr);
  3817. end;
  3818. got_addrn:=false;
  3819. p1:=caddrnode.create(p1);
  3820. p1.fileinfo:=filepos;
  3821. if cs_typed_addresses in current_settings.localswitches then
  3822. include(taddrnode(p1).addrnodeflags,anf_typedaddr);
  3823. { Store the procvar that we are expecting, the
  3824. addrn will use the information to find the correct
  3825. procdef or it will return an error }
  3826. if assigned(getprocvardef) and
  3827. (taddrnode(p1).left.nodetype = loadn) then
  3828. taddrnode(p1).getprocvardef:=getprocvardef;
  3829. if (token in postfixoperator_tokens) then
  3830. begin
  3831. again:=true;
  3832. postfixoperators(p1,again,getaddr);
  3833. end;
  3834. end;
  3835. _LKLAMMER :
  3836. begin
  3837. consume(_LKLAMMER);
  3838. p1:=comp_expr([ef_accept_equal]);
  3839. consume(_RKLAMMER);
  3840. { it's not a good solution
  3841. but (a+b)^ makes some problems }
  3842. if token in postfixoperator_tokens then
  3843. begin
  3844. again:=true;
  3845. postfixoperators(p1,again,getaddr);
  3846. end;
  3847. end;
  3848. _LECKKLAMMER :
  3849. begin
  3850. consume(_LECKKLAMMER);
  3851. p1:=factor_read_set;
  3852. consume(_RECKKLAMMER);
  3853. end;
  3854. _PLUS :
  3855. begin
  3856. consume(_PLUS);
  3857. p1:=factor(false,[]);
  3858. p1:=cunaryplusnode.create(p1);
  3859. end;
  3860. _MINUS :
  3861. begin
  3862. consume(_MINUS);
  3863. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  3864. begin
  3865. { ugly hack, but necessary to be able to parse }
  3866. { -9223372036854775808 as int64 (JM) }
  3867. pattern := '-'+pattern;
  3868. p1:=sub_expr(oppower,[],nil);
  3869. { -1 ** 4 should be - (1 ** 4) and not
  3870. (-1) ** 4
  3871. This was the reason of tw0869.pp test failure PM }
  3872. if p1.nodetype=starstarn then
  3873. begin
  3874. if tbinarynode(p1).left.nodetype=ordconstn then
  3875. begin
  3876. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  3877. p1:=cunaryminusnode.create(p1);
  3878. end
  3879. else if tbinarynode(p1).left.nodetype=realconstn then
  3880. begin
  3881. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  3882. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  3883. p1:=cunaryminusnode.create(p1);
  3884. end
  3885. else
  3886. internalerror(20021029);
  3887. end;
  3888. end
  3889. else
  3890. begin
  3891. if m_isolike_unary_minus in current_settings.modeswitches then
  3892. p1:=sub_expr(opmultiply,[],nil)
  3893. else
  3894. p1:=sub_expr(oppower,[],nil);
  3895. p1:=cunaryminusnode.create(p1);
  3896. end;
  3897. end;
  3898. _OP_NOT :
  3899. begin
  3900. consume(_OP_NOT);
  3901. p1:=factor(false,[]);
  3902. p1:=cnotnode.create(p1);
  3903. end;
  3904. _NIL :
  3905. begin
  3906. consume(_NIL);
  3907. p1:=cnilnode.create;
  3908. { It's really ugly code nil^, but delphi allows it }
  3909. if token in [_CARET,_POINT] then
  3910. begin
  3911. again:=true;
  3912. postfixoperators(p1,again,getaddr);
  3913. end;
  3914. end;
  3915. _OBJCPROTOCOL:
  3916. begin
  3917. { The @protocol keyword is used in two ways in Objective-C:
  3918. 1) to declare protocols (~ Object Pascal interfaces)
  3919. 2) to obtain the metaclass (~ Object Pascal) "class of")
  3920. of a declared protocol
  3921. This code is for handling the second case. Because of 1),
  3922. we cannot simply use a system unit symbol.
  3923. }
  3924. consume(_OBJCPROTOCOL);
  3925. consume(_LKLAMMER);
  3926. p1:=factor(false,[]);
  3927. consume(_RKLAMMER);
  3928. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  3929. end;
  3930. else
  3931. begin
  3932. Message(parser_e_illegal_expression);
  3933. p1:=cerrornode.create;
  3934. { recover }
  3935. consume(token);
  3936. end;
  3937. end;
  3938. end;
  3939. { generate error node if no node is created }
  3940. if not assigned(p1) then
  3941. begin
  3942. {$ifdef EXTDEBUG}
  3943. Comment(V_Warning,'factor: p1=nil');
  3944. {$endif}
  3945. p1:=cerrornode.create;
  3946. updatefpos:=true;
  3947. end;
  3948. { get the resultdef for the node if nothing stops us }
  3949. if (not assigned(p1.resultdef)) and dopostfix then
  3950. begin
  3951. do_typecheckpass_changed(p1,nodechanged);
  3952. updatefpos:=updatefpos or nodechanged;
  3953. end;
  3954. if assigned(p1) and
  3955. updatefpos then
  3956. p1.fileinfo:=filepos;
  3957. factor:=p1;
  3958. end;
  3959. {$maxfpuregisters default}
  3960. procedure post_comp_expr_gendef(var def: tdef);
  3961. var
  3962. p1 : tnode;
  3963. again : boolean;
  3964. begin
  3965. if not assigned(def) then
  3966. internalerror(2011053001);
  3967. again:=false;
  3968. { handle potential typecasts, etc }
  3969. p1:=handle_factor_typenode(def,false,again,nil,false);
  3970. { parse postfix operators }
  3971. postfixoperators(p1,again,false);
  3972. if assigned(p1) and (p1.nodetype=typen) then
  3973. def:=ttypenode(p1).typedef
  3974. else
  3975. def:=generrordef;
  3976. end;
  3977. {****************************************************************************
  3978. Sub_Expr
  3979. ****************************************************************************}
  3980. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;
  3981. {Reads a subexpression while the operators are of the current precedence
  3982. level, or any higher level. Replaces the old term, simpl_expr and
  3983. simpl2_expr.}
  3984. function istypenode(n:tnode):boolean;inline;
  3985. { Checks whether the given node is a type node or a VMT node containing a
  3986. typenode. This is used in the code for inline specializations in the
  3987. _LT branch below }
  3988. begin
  3989. result:=assigned(n) and
  3990. (
  3991. (n.nodetype=typen) or
  3992. (
  3993. (n.nodetype=loadvmtaddrn) and
  3994. (tloadvmtaddrnode(n).left.nodetype=typen)
  3995. )
  3996. );
  3997. end;
  3998. function gettypedef(n:tnode):tdef;inline;
  3999. { This returns the typedef that belongs to the given typenode or
  4000. loadvmtaddrnode. n must not be Nil! }
  4001. begin
  4002. if n.nodetype=typen then
  4003. result:=ttypenode(n).typedef
  4004. else
  4005. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  4006. end;
  4007. function gettypedef(sym:tsym):tdef;inline;
  4008. begin
  4009. result:=nil;
  4010. case sym.typ of
  4011. typesym:
  4012. result:=ttypesym(sym).typedef;
  4013. procsym:
  4014. result:=tdef(tprocsym(sym).procdeflist[0]);
  4015. else
  4016. internalerror(2015092701);
  4017. end;
  4018. end;
  4019. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  4020. var
  4021. srsymtable : tsymtable;
  4022. begin
  4023. srsym:=nil;
  4024. case n.nodetype of
  4025. typen:
  4026. srsym:=ttypenode(n).typedef.typesym;
  4027. loadvmtaddrn:
  4028. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  4029. loadn:
  4030. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  4031. srsym:=nil;
  4032. specializen:
  4033. srsym:=tspecializenode(n).sym;
  4034. { TODO : handle const nodes }
  4035. else
  4036. ;
  4037. end;
  4038. result:=assigned(srsym);
  4039. end;
  4040. function generate_inline_specialization(gendef:tdef;n:tnode;filepos:tfileposinfo;parseddef:tdef;gensym:tsym;p2:tnode):tnode;
  4041. var
  4042. again,
  4043. getaddr : boolean;
  4044. pload : tnode;
  4045. spezcontext : tspecializationcontext;
  4046. structdef,
  4047. inheriteddef : tabstractrecorddef;
  4048. callflags : tcallnodeflags;
  4049. begin
  4050. if n.nodetype=specializen then
  4051. begin
  4052. getaddr:=tspecializenode(n).getaddr;
  4053. pload:=tspecializenode(n).left;
  4054. inheriteddef:=tabstractrecorddef(tspecializenode(n).inheriteddef);
  4055. tspecializenode(n).left:=nil;
  4056. end
  4057. else
  4058. begin
  4059. getaddr:=false;
  4060. pload:=nil;
  4061. inheriteddef:=nil;
  4062. end;
  4063. if assigned(parseddef) and assigned(gensym) and assigned(p2) then
  4064. gendef:=generate_specialization_phase1(spezcontext,gendef,parseddef,gensym.realname,p2.fileinfo)
  4065. else
  4066. gendef:=generate_specialization_phase1(spezcontext,gendef);
  4067. case gendef.typ of
  4068. errordef:
  4069. begin
  4070. spezcontext.free;
  4071. spezcontext:=nil;
  4072. gensym:=generrorsym;
  4073. end;
  4074. objectdef,
  4075. recorddef,
  4076. procvardef,
  4077. arraydef:
  4078. begin
  4079. gendef:=generate_specialization_phase2(spezcontext,tstoreddef(gendef),false,'');
  4080. spezcontext.free;
  4081. spezcontext:=nil;
  4082. if gendef.typ=errordef then
  4083. gensym:=generrorsym
  4084. else
  4085. gensym:=gendef.typesym;
  4086. end;
  4087. procdef:
  4088. begin
  4089. if block_type<>bt_body then
  4090. begin
  4091. message(parser_e_illegal_expression);
  4092. gensym:=generrorsym;
  4093. end
  4094. else
  4095. begin
  4096. gensym:=tprocdef(gendef).procsym;
  4097. end;
  4098. end;
  4099. else
  4100. internalerror(2015092702);
  4101. end;
  4102. { in case of a class or a record the specialized generic
  4103. is always a classrefdef }
  4104. again:=false;
  4105. if assigned(pload) then
  4106. begin
  4107. result:=pload;
  4108. typecheckpass(result);
  4109. structdef:=inheriteddef;
  4110. if not assigned(structdef) then
  4111. case result.resultdef.typ of
  4112. objectdef,
  4113. recorddef:
  4114. begin
  4115. structdef:=tabstractrecorddef(result.resultdef);
  4116. end;
  4117. classrefdef:
  4118. begin
  4119. structdef:=tabstractrecorddef(tclassrefdef(result.resultdef).pointeddef);
  4120. end;
  4121. else
  4122. internalerror(2015092703);
  4123. end;
  4124. if not (structdef.typ in [recorddef,objectdef]) then
  4125. internalerror(2018092101);
  4126. if assigned(inheriteddef) then
  4127. begin
  4128. callflags:=[cnf_inherited];
  4129. include(current_procinfo.flags,pi_has_inherited);
  4130. end
  4131. else
  4132. callflags:=[];
  4133. do_member_read(structdef,getaddr,gensym,result,again,callflags,spezcontext);
  4134. spezcontext:=nil;
  4135. end
  4136. else
  4137. begin
  4138. if gensym.typ=procsym then
  4139. begin
  4140. result:=nil;
  4141. { check if it's a method/class method }
  4142. if is_member_read(gensym,gensym.owner,result,parseddef) then
  4143. begin
  4144. { if we are accessing a owner procsym from the nested }
  4145. { class we need to call it as a class member }
  4146. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  4147. assigned(current_structdef) and (current_structdef<>parseddef) and is_owned_by(current_structdef,parseddef) then
  4148. result:=cloadvmtaddrnode.create(ctypenode.create(parseddef));
  4149. { not srsymtable.symtabletype since that can be }
  4150. { withsymtable as well }
  4151. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  4152. begin
  4153. do_member_read(tabstractrecorddef(parseddef),getaddr,gensym,result,again,[],spezcontext);
  4154. spezcontext:=nil;
  4155. end
  4156. else
  4157. { no procsyms in records (yet) }
  4158. internalerror(2015092704);
  4159. end
  4160. else
  4161. begin
  4162. { regular procedure/function call }
  4163. do_proc_call(gensym,gensym.owner,nil,
  4164. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  4165. again,result,[],spezcontext);
  4166. spezcontext:=nil;
  4167. end;
  4168. end
  4169. else
  4170. { handle potential typecasts, etc }
  4171. result:=handle_factor_typenode(gendef,false,again,nil,false);
  4172. end;
  4173. { parse postfix operators }
  4174. if postfixoperators(result,again,false) then
  4175. if assigned(result) then
  4176. result.fileinfo:=filepos
  4177. else
  4178. result:=cerrornode.create;
  4179. spezcontext.free;
  4180. end;
  4181. label
  4182. SubExprStart;
  4183. var
  4184. p1,p2,ptmp : tnode;
  4185. oldt : Ttoken;
  4186. filepos : tfileposinfo;
  4187. gendef,parseddef : tdef;
  4188. gensym : tsym;
  4189. begin
  4190. SubExprStart:
  4191. if pred_level=highest_precedence then
  4192. begin
  4193. if factornode=nil then
  4194. p1:=factor(false,flags)
  4195. else
  4196. p1:=factornode;
  4197. end
  4198. else
  4199. p1:=sub_expr(succ(pred_level),flags+[ef_accept_equal],factornode);
  4200. repeat
  4201. if (token in [NOTOKEN..last_operator]) and
  4202. (token in operator_levels[pred_level]) and
  4203. ((token<>_EQ) or (ef_accept_equal in flags)) then
  4204. begin
  4205. oldt:=token;
  4206. filepos:=current_tokenpos;
  4207. consume(token);
  4208. if pred_level=highest_precedence then
  4209. p2:=factor(false,[])
  4210. else
  4211. p2:=sub_expr(succ(pred_level),flags+[ef_accept_equal],nil);
  4212. case oldt of
  4213. _PLUS :
  4214. p1:=caddnode.create(addn,p1,p2);
  4215. _MINUS :
  4216. p1:=caddnode.create(subn,p1,p2);
  4217. _STAR :
  4218. p1:=caddnode.create(muln,p1,p2);
  4219. _SLASH :
  4220. p1:=caddnode.create(slashn,p1,p2);
  4221. _EQ:
  4222. p1:=caddnode.create(equaln,p1,p2);
  4223. _GT :
  4224. p1:=caddnode.create(gtn,p1,p2);
  4225. _LT :
  4226. begin
  4227. { we need to decice whether we have an inline specialization
  4228. (type nodes to the left and right of "<", mode Delphi and
  4229. ">" or "," following) or a normal "<" comparison }
  4230. { TODO : p1 could be a non type if e.g. a variable with the
  4231. same name is defined in the same unit where the
  4232. generic is defined (though "same unit" is not
  4233. necessarily needed) }
  4234. if getgenericsym(p1,gensym) and
  4235. { Attention: when nested specializations are supported
  4236. p2 could be a loadn if a "<" follows }
  4237. istypenode(p2) and
  4238. (m_delphi in current_settings.modeswitches) and
  4239. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  4240. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  4241. begin
  4242. { this is an inline specialization }
  4243. { retrieve the defs of two nodes }
  4244. if p1.nodetype=specializen then
  4245. gendef:=gettypedef(tspecializenode(p1).sym)
  4246. else
  4247. gendef:=nil;
  4248. parseddef:=gettypedef(p2);
  4249. { check the hints for parseddef }
  4250. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg,p1.fileinfo);
  4251. ptmp:=generate_inline_specialization(gendef,p1,filepos,parseddef,gensym,p2);
  4252. { we don't need these nodes anymore }
  4253. p1.free;
  4254. p2.free;
  4255. p1:=ptmp;
  4256. { with p1 now set we are in reality directly behind the
  4257. call to "factor" thus we need to call down to that
  4258. again }
  4259. { This is disabled until specializations on the right
  4260. hand side work as well, because
  4261. "not working expressions" is better than "half working
  4262. expressions" }
  4263. {factornode:=p1;
  4264. goto SubExprStart;}
  4265. end
  4266. else
  4267. begin
  4268. { this is a normal "<" comparison }
  4269. { potential generic types that are followed by a "<": }
  4270. { a) might not have their resultdef set }
  4271. if not assigned(p1.resultdef) then
  4272. do_typecheckpass(p1);
  4273. { b) are not checked whether they are an undefined def,
  4274. but not a generic parameter }
  4275. if (p1.nodetype=typen) and
  4276. (ttypenode(p1).typedef.typ=undefineddef) and
  4277. assigned(ttypenode(p1).typedef.typesym) and
  4278. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  4279. begin
  4280. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  4281. p1.Free;
  4282. p1:=cerrornode.create;
  4283. end;
  4284. { c) don't have their hints checked }
  4285. if istypenode(p1) then
  4286. begin
  4287. gendef:=gettypedef(p1);
  4288. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4289. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4290. end;
  4291. { Note: the second part of the expression will be needed
  4292. for nested specializations }
  4293. if istypenode(p2) {and
  4294. not (token in [_LT, _LSHARPBRACKET])} then
  4295. begin
  4296. gendef:=gettypedef(p2);
  4297. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4298. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4299. end;
  4300. { create the comparison node for "<" }
  4301. p1:=caddnode.create(ltn,p1,p2)
  4302. end;
  4303. end;
  4304. _GTE :
  4305. p1:=caddnode.create(gten,p1,p2);
  4306. _LTE :
  4307. p1:=caddnode.create(lten,p1,p2);
  4308. _SYMDIF :
  4309. p1:=caddnode.create(symdifn,p1,p2);
  4310. _STARSTAR :
  4311. p1:=caddnode.create(starstarn,p1,p2);
  4312. _OP_AS,
  4313. _OP_IS :
  4314. begin
  4315. if (m_delphi in current_settings.modeswitches) and
  4316. (token in [_LT, _LSHARPBRACKET]) and
  4317. getgenericsym(p2,gensym) then
  4318. begin
  4319. { for now we're handling this as a generic declaration;
  4320. there could be cases though (because of operator
  4321. overloading) where this is the wrong decision... }
  4322. if gensym.typ=typesym then
  4323. gendef:=ttypesym(gensym).typedef
  4324. else
  4325. if gensym.typ=procsym then
  4326. gendef:=tdef(tprocsym(gensym).procdeflist[0])
  4327. else
  4328. internalerror(2015072401);
  4329. ptmp:=generate_inline_specialization(gendef,p2,filepos,nil,nil,nil);
  4330. { we don't need the old p2 anymore }
  4331. p2.Free;
  4332. p2:=ptmp;
  4333. { here we don't need to call back down to "factor", thus
  4334. no "goto" }
  4335. end;
  4336. { now generate the "is" or "as" node }
  4337. case oldt of
  4338. _OP_AS:
  4339. p1:=casnode.create(p1,p2);
  4340. _OP_IS:
  4341. p1:=cisnode.create(p1,p2);
  4342. else
  4343. internalerror(2019050528);
  4344. end;
  4345. end;
  4346. _OP_IN :
  4347. p1:=cinnode.create(p1,p2);
  4348. _OP_OR,
  4349. _PIPE {macpas only} :
  4350. begin
  4351. p1:=caddnode.create(orn,p1,p2);
  4352. if (oldt = _PIPE) then
  4353. include(p1.flags,nf_short_bool);
  4354. end;
  4355. _OP_AND,
  4356. _AMPERSAND {macpas only} :
  4357. begin
  4358. p1:=caddnode.create(andn,p1,p2);
  4359. if (oldt = _AMPERSAND) then
  4360. include(p1.flags,nf_short_bool);
  4361. end;
  4362. _OP_DIV :
  4363. p1:=cmoddivnode.create(divn,p1,p2);
  4364. _OP_NOT :
  4365. p1:=cnotnode.create(p1);
  4366. _OP_MOD :
  4367. begin
  4368. p1:=cmoddivnode.create(modn,p1,p2);
  4369. if m_isolike_mod in current_settings.modeswitches then
  4370. include(p1.flags,nf_isomod);
  4371. end;
  4372. _OP_SHL :
  4373. p1:=cshlshrnode.create(shln,p1,p2);
  4374. _OP_SHR :
  4375. p1:=cshlshrnode.create(shrn,p1,p2);
  4376. _OP_XOR :
  4377. p1:=caddnode.create(xorn,p1,p2);
  4378. _ASSIGNMENT :
  4379. p1:=cassignmentnode.create(p1,p2);
  4380. _NE :
  4381. p1:=caddnode.create(unequaln,p1,p2);
  4382. else
  4383. internalerror(2019050529);
  4384. end;
  4385. p1.fileinfo:=filepos;
  4386. end
  4387. else
  4388. break;
  4389. until false;
  4390. sub_expr:=p1;
  4391. end;
  4392. function comp_expr(flags:texprflags):tnode;
  4393. var
  4394. oldafterassignment : boolean;
  4395. p1 : tnode;
  4396. begin
  4397. oldafterassignment:=afterassignment;
  4398. afterassignment:=true;
  4399. p1:=sub_expr(opcompare,flags,nil);
  4400. { get the resultdef for this expression }
  4401. if not assigned(p1.resultdef) then
  4402. do_typecheckpass(p1);
  4403. afterassignment:=oldafterassignment;
  4404. comp_expr:=p1;
  4405. end;
  4406. function expr(dotypecheck : boolean) : tnode;
  4407. var
  4408. p1,p2 : tnode;
  4409. filepos : tfileposinfo;
  4410. oldafterassignment,
  4411. updatefpos : boolean;
  4412. oldflags : tnodeflags;
  4413. begin
  4414. oldafterassignment:=afterassignment;
  4415. p1:=sub_expr(opcompare,[ef_accept_equal],nil);
  4416. { get the resultdef for this expression }
  4417. if not assigned(p1.resultdef) and
  4418. dotypecheck then
  4419. do_typecheckpass(p1);
  4420. filepos:=current_tokenpos;
  4421. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  4422. afterassignment:=true;
  4423. updatefpos:=true;
  4424. case token of
  4425. _POINTPOINT :
  4426. begin
  4427. consume(_POINTPOINT);
  4428. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4429. p1:=crangenode.create(p1,p2);
  4430. end;
  4431. _ASSIGNMENT :
  4432. begin
  4433. consume(_ASSIGNMENT);
  4434. if assigned(p1.resultdef) and (p1.resultdef.typ=procvardef) then
  4435. getprocvardef:=tprocvardef(p1.resultdef);
  4436. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4437. if assigned(getprocvardef) then
  4438. handle_procvar(getprocvardef,p2);
  4439. getprocvardef:=nil;
  4440. p1:=cassignmentnode.create(p1,p2);
  4441. end;
  4442. _PLUSASN :
  4443. begin
  4444. consume(_PLUSASN);
  4445. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4446. p1:=gen_c_style_operator(addn,p1,p2);
  4447. end;
  4448. _MINUSASN :
  4449. begin
  4450. consume(_MINUSASN);
  4451. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4452. p1:=gen_c_style_operator(subn,p1,p2);
  4453. end;
  4454. _STARASN :
  4455. begin
  4456. consume(_STARASN );
  4457. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4458. p1:=gen_c_style_operator(muln,p1,p2);
  4459. end;
  4460. _SLASHASN :
  4461. begin
  4462. consume(_SLASHASN );
  4463. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4464. p1:=gen_c_style_operator(slashn,p1,p2);
  4465. end;
  4466. else
  4467. updatefpos:=false;
  4468. end;
  4469. oldflags:=p1.flags;
  4470. { get the resultdef for this expression }
  4471. if not assigned(p1.resultdef) and
  4472. dotypecheck then
  4473. do_typecheckpass(p1);
  4474. { transfer generic paramter flag }
  4475. if nf_generic_para in oldflags then
  4476. include(p1.flags,nf_generic_para);
  4477. afterassignment:=oldafterassignment;
  4478. if updatefpos then
  4479. p1.fileinfo:=filepos;
  4480. expr:=p1;
  4481. end;
  4482. function get_intconst:TConstExprInt;
  4483. {Reads an expression, tries to evalute it and check if it is an integer
  4484. constant. Then the constant is returned.}
  4485. var
  4486. p:tnode;
  4487. begin
  4488. result:=0;
  4489. p:=comp_expr([ef_accept_equal]);
  4490. if not codegenerror then
  4491. begin
  4492. if (p.nodetype<>ordconstn) or
  4493. not(is_integer(p.resultdef)) then
  4494. Message(parser_e_illegal_expression)
  4495. else
  4496. result:=tordconstnode(p).value;
  4497. end;
  4498. p.free;
  4499. end;
  4500. function get_stringconst:string;
  4501. {Reads an expression, tries to evaluate it and checks if it is a string
  4502. constant. Then the constant is returned.}
  4503. var
  4504. p:tnode;
  4505. begin
  4506. get_stringconst:='';
  4507. p:=comp_expr([ef_accept_equal]);
  4508. if p.nodetype<>stringconstn then
  4509. begin
  4510. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  4511. get_stringconst:=char(int64(tordconstnode(p).value))
  4512. else
  4513. Message(parser_e_illegal_expression);
  4514. end
  4515. else
  4516. get_stringconst:=strpas(tstringconstnode(p).value_str);
  4517. p.free;
  4518. end;
  4519. end.