pexpr.pas 187 KB

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