pexpr.pas 188 KB

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