pexpr.pas 185 KB

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