pexpr.pas 187 KB

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