pexpr.pas 187 KB

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