pexpr.pas 180 KB

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