pexpr.pas 176 KB

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