pexpr.pas 178 KB

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