pexpr.pas 125 KB

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