pexpr.pas 185 KB

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