pexpr.pas 153 KB

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