pexpr.pas 190 KB

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