pexpr.pas 153 KB

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