pexpr.pas 178 KB

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