pexpr.pas 180 KB

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