pexpr.pas 178 KB

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