pexpr.pas 189 KB

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