pexpr.pas 177 KB

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