pexpr.pas 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764
  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;
  24. { reads a whole expression }
  25. function expr : tnode;
  26. { reads an expression without assignements and .. }
  27. function comp_expr(accept_equal : boolean):tnode;
  28. { reads a single factor }
  29. function factor(getaddr : boolean) : tnode;
  30. procedure string_dec(var t: ttype);
  31. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  32. function node_to_symlist(p1:tnode):tsymlist;
  33. function parse_paras(__colon : boolean;end_of_paras : ttoken) : tnode;
  34. { the ID token has to be consumed before calling this function }
  35. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callflags:tcallnodeflags);
  36. function get_intconst:TConstExprInt;
  37. function get_stringconst:string;
  38. implementation
  39. uses
  40. { common }
  41. cutils,
  42. { global }
  43. verbose,
  44. systems,widestr,
  45. { symtable }
  46. symconst,symtable,symsym,defutil,defcmp,
  47. { module }
  48. fmodule,ppu,
  49. { pass 1 }
  50. pass_1,htypechk,
  51. nmat,nadd,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  52. { parser }
  53. scanner,
  54. pbase,pinline,ptype,
  55. { codegen }
  56. cgbase,procinfo,cpuinfo
  57. ;
  58. { sub_expr(opmultiply) is need to get -1 ** 4 to be
  59. read as - (1**4) and not (-1)**4 PM }
  60. type
  61. Toperator_precedence=(opcompare,opaddition,opmultiply,oppower);
  62. const
  63. highest_precedence = oppower;
  64. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;forward;
  65. const
  66. { true, if the inherited call is anonymous }
  67. anon_inherited : boolean = false;
  68. procedure string_dec(var t: ttype);
  69. { reads a string type with optional length }
  70. { and returns a pointer to the string }
  71. { definition }
  72. var
  73. p : tnode;
  74. begin
  75. t:=cshortstringtype;
  76. consume(_STRING);
  77. if try_to_consume(_LECKKLAMMER) then
  78. begin
  79. p:=comp_expr(true);
  80. if not is_constintnode(p) then
  81. begin
  82. Message(parser_e_illegal_expression);
  83. { error recovery }
  84. consume(_RECKKLAMMER);
  85. end
  86. else
  87. begin
  88. if (tordconstnode(p).value<=0) then
  89. begin
  90. Message(parser_e_invalid_string_size);
  91. tordconstnode(p).value:=255;
  92. end;
  93. consume(_RECKKLAMMER);
  94. if tordconstnode(p).value>255 then
  95. begin
  96. { longstring is currently unsupported (CEC)! }
  97. { t.setdef(tstringdef.createlong(tordconstnode(p).value))}
  98. Message(parser_e_invalid_string_size);
  99. tordconstnode(p).value:=255;
  100. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  101. end
  102. else
  103. if tordconstnode(p).value<>255 then
  104. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  105. end;
  106. p.free;
  107. end
  108. else
  109. begin
  110. if cs_ansistrings in aktlocalswitches then
  111. t:=cansistringtype
  112. else
  113. t:=cshortstringtype;
  114. end;
  115. end;
  116. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  117. var
  118. plist : psymlistitem;
  119. begin
  120. plist:=pl.firstsym;
  121. while assigned(plist) do
  122. begin
  123. case plist^.sltype of
  124. sl_load :
  125. begin
  126. addsymref(plist^.sym);
  127. if not assigned(st) then
  128. st:=plist^.sym.owner;
  129. { p1 can already contain the loadnode of
  130. the class variable. When there is no tree yet we
  131. may need to load it for with or objects }
  132. if not assigned(p1) then
  133. begin
  134. case st.symtabletype of
  135. withsymtable :
  136. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  137. objectsymtable :
  138. p1:=load_self_node;
  139. end;
  140. end;
  141. if assigned(p1) then
  142. p1:=csubscriptnode.create(plist^.sym,p1)
  143. else
  144. p1:=cloadnode.create(plist^.sym,st);
  145. end;
  146. sl_subscript :
  147. begin
  148. addsymref(plist^.sym);
  149. p1:=csubscriptnode.create(plist^.sym,p1);
  150. end;
  151. sl_typeconv :
  152. p1:=ctypeconvnode.create_explicit(p1,plist^.tt);
  153. sl_absolutetype :
  154. begin
  155. p1:=ctypeconvnode.create(p1,plist^.tt);
  156. include(p1.flags,nf_absolute);
  157. end;
  158. sl_vec :
  159. p1:=cvecnode.create(p1,cordconstnode.create(plist^.value,plist^.valuett,true));
  160. else
  161. internalerror(200110205);
  162. end;
  163. plist:=plist^.next;
  164. end;
  165. end;
  166. function node_to_symlist(p1:tnode):tsymlist;
  167. var
  168. sl : tsymlist;
  169. procedure addnode(p:tnode);
  170. begin
  171. case p.nodetype of
  172. subscriptn :
  173. begin
  174. addnode(tsubscriptnode(p).left);
  175. sl.addsym(sl_subscript,tsubscriptnode(p).vs);
  176. end;
  177. typeconvn :
  178. begin
  179. addnode(ttypeconvnode(p).left);
  180. if nf_absolute in ttypeconvnode(p).flags then
  181. sl.addtype(sl_absolutetype,ttypeconvnode(p).totype)
  182. else
  183. sl.addtype(sl_typeconv,ttypeconvnode(p).totype);
  184. end;
  185. vecn :
  186. begin
  187. addnode(tvecnode(p).left);
  188. if tvecnode(p).right.nodetype=ordconstn then
  189. sl.addconst(sl_vec,tordconstnode(tvecnode(p).right).value,tvecnode(p).right.resulttype)
  190. else
  191. begin
  192. Message(parser_e_illegal_expression);
  193. { recovery }
  194. sl.addconst(sl_vec,0,tvecnode(p).right.resulttype);
  195. end;
  196. end;
  197. loadn :
  198. sl.addsym(sl_load,tloadnode(p).symtableentry);
  199. else
  200. internalerror(200310282);
  201. end;
  202. end;
  203. begin
  204. sl:=tsymlist.create;
  205. addnode(p1);
  206. result:=sl;
  207. end;
  208. function parse_paras(__colon : boolean;end_of_paras : ttoken) : tnode;
  209. var
  210. p1,p2 : tnode;
  211. prev_in_args : boolean;
  212. old_allow_array_constructor : boolean;
  213. begin
  214. if token=end_of_paras then
  215. begin
  216. parse_paras:=nil;
  217. exit;
  218. end;
  219. { save old values }
  220. prev_in_args:=in_args;
  221. old_allow_array_constructor:=allow_array_constructor;
  222. { set para parsing values }
  223. in_args:=true;
  224. inc(parsing_para_level);
  225. allow_array_constructor:=true;
  226. p2:=nil;
  227. repeat
  228. p1:=comp_expr(true);
  229. p2:=ccallparanode.create(p1,p2);
  230. { it's for the str(l:5,s); }
  231. if __colon and (token=_COLON) then
  232. begin
  233. consume(_COLON);
  234. p1:=comp_expr(true);
  235. p2:=ccallparanode.create(p1,p2);
  236. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  237. if try_to_consume(_COLON) then
  238. begin
  239. p1:=comp_expr(true);
  240. p2:=ccallparanode.create(p1,p2);
  241. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  242. end
  243. end;
  244. until not try_to_consume(_COMMA);
  245. allow_array_constructor:=old_allow_array_constructor;
  246. dec(parsing_para_level);
  247. in_args:=prev_in_args;
  248. parse_paras:=p2;
  249. end;
  250. function gen_c_style_operator(ntyp:tnodetype;p1,p2:tnode) : tnode;
  251. var
  252. hp : tnode;
  253. htype : ttype;
  254. temp : ttempcreatenode;
  255. newstatement : tstatementnode;
  256. begin
  257. { Properties are not allowed, because the write can
  258. be different from the read }
  259. if (nf_isproperty in p1.flags) then
  260. begin
  261. Message(type_e_variable_id_expected);
  262. { We can continue with the loading,
  263. it'll not create errors. Only the expected
  264. result can be wrong }
  265. end;
  266. hp:=p1;
  267. while assigned(hp) and
  268. (hp.nodetype in [derefn,subscriptn,vecn,typeconvn]) do
  269. hp:=tunarynode(hp).left;
  270. if not assigned(hp) then
  271. internalerror(200410121);
  272. if (hp.nodetype=calln) then
  273. begin
  274. resulttypepass(p1);
  275. result:=internalstatements(newstatement);
  276. htype.setdef(tpointerdef.create(p1.resulttype));
  277. temp:=ctempcreatenode.create(htype,sizeof(aint),tt_persistent,false);
  278. addstatement(newstatement,temp);
  279. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),caddrnode.create_internal(p1)));
  280. addstatement(newstatement,cassignmentnode.create(
  281. cderefnode.create(ctemprefnode.create(temp)),
  282. caddnode.create(ntyp,
  283. cderefnode.create(ctemprefnode.create(temp)),
  284. p2)));
  285. addstatement(newstatement,ctempdeletenode.create(temp));
  286. end
  287. else
  288. result:=cassignmentnode.create(p1,caddnode.create(ntyp,p1.getcopy,p2));
  289. end;
  290. function statement_syssym(l : byte) : tnode;
  291. var
  292. p1,p2,paras : tnode;
  293. err,
  294. prev_in_args : boolean;
  295. begin
  296. prev_in_args:=in_args;
  297. case l of
  298. in_new_x :
  299. begin
  300. if afterassignment or in_args then
  301. statement_syssym:=new_function
  302. else
  303. statement_syssym:=new_dispose_statement(true);
  304. end;
  305. in_dispose_x :
  306. begin
  307. statement_syssym:=new_dispose_statement(false);
  308. end;
  309. in_ord_x :
  310. begin
  311. consume(_LKLAMMER);
  312. in_args:=true;
  313. p1:=comp_expr(true);
  314. consume(_RKLAMMER);
  315. p1:=geninlinenode(in_ord_x,false,p1);
  316. statement_syssym := p1;
  317. end;
  318. in_exit :
  319. begin
  320. if try_to_consume(_LKLAMMER) then
  321. begin
  322. if not (m_mac in aktmodeswitches) then
  323. begin
  324. if not(try_to_consume(_RKLAMMER)) then
  325. begin
  326. p1:=comp_expr(true);
  327. consume(_RKLAMMER);
  328. if (block_type=bt_except) then
  329. begin
  330. Message(parser_e_exit_with_argument_not__possible);
  331. { recovery }
  332. p1.free;
  333. p1:=nil;
  334. end
  335. else if (not assigned(current_procinfo) or
  336. is_void(current_procinfo.procdef.rettype.def)) then
  337. begin
  338. Message(parser_e_void_function);
  339. { recovery }
  340. p1.free;
  341. p1:=nil;
  342. end;
  343. end
  344. else
  345. p1:=nil;
  346. end
  347. else
  348. begin
  349. if not (current_procinfo.procdef.procsym.name = pattern) then
  350. Message(parser_e_macpas_exit_wrong_param);
  351. consume(_ID);
  352. consume(_RKLAMMER);
  353. p1:=nil;
  354. end
  355. end
  356. else
  357. p1:=nil;
  358. statement_syssym:=cexitnode.create(p1);
  359. end;
  360. in_break :
  361. begin
  362. if not (m_mac in aktmodeswitches) then
  363. statement_syssym:=cbreaknode.create
  364. else
  365. begin
  366. Message1(sym_e_id_not_found, orgpattern);
  367. statement_syssym:=cerrornode.create;
  368. end;
  369. end;
  370. in_continue :
  371. begin
  372. if not (m_mac in aktmodeswitches) then
  373. statement_syssym:=ccontinuenode.create
  374. else
  375. begin
  376. Message1(sym_e_id_not_found, orgpattern);
  377. statement_syssym:=cerrornode.create;
  378. end;
  379. end;
  380. in_leave :
  381. begin
  382. if m_mac in aktmodeswitches then
  383. statement_syssym:=cbreaknode.create
  384. else
  385. begin
  386. Message1(sym_e_id_not_found, orgpattern);
  387. statement_syssym:=cerrornode.create;
  388. end;
  389. end;
  390. in_cycle :
  391. begin
  392. if m_mac in aktmodeswitches then
  393. statement_syssym:=ccontinuenode.create
  394. else
  395. begin
  396. Message1(sym_e_id_not_found, orgpattern);
  397. statement_syssym:=cerrornode.create;
  398. end;
  399. end;
  400. in_typeof_x :
  401. begin
  402. consume(_LKLAMMER);
  403. in_args:=true;
  404. p1:=comp_expr(true);
  405. consume(_RKLAMMER);
  406. if p1.nodetype=typen then
  407. ttypenode(p1).allowed:=true;
  408. { Allow classrefdef, which is required for
  409. Typeof(self) in static class methods }
  410. if (p1.resulttype.def.deftype = objectdef) or
  411. (assigned(current_procinfo) and
  412. ((po_classmethod in current_procinfo.procdef.procoptions) or
  413. (po_staticmethod in current_procinfo.procdef.procoptions)) and
  414. (p1.resulttype.def.deftype=classrefdef)) then
  415. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  416. else
  417. begin
  418. Message(parser_e_class_id_expected);
  419. p1.destroy;
  420. statement_syssym:=cerrornode.create;
  421. end;
  422. end;
  423. in_sizeof_x,
  424. in_bitsizeof_x :
  425. begin
  426. consume(_LKLAMMER);
  427. in_args:=true;
  428. p1:=comp_expr(true);
  429. consume(_RKLAMMER);
  430. if (p1.nodetype<>typen) and
  431. (
  432. (is_object(p1.resulttype.def) and
  433. (oo_has_constructor in tobjectdef(p1.resulttype.def).objectoptions)) or
  434. is_open_array(p1.resulttype.def) or
  435. is_array_of_const(p1.resulttype.def) or
  436. is_open_string(p1.resulttype.def)
  437. ) then
  438. begin
  439. statement_syssym:=geninlinenode(in_sizeof_x,false,p1);
  440. { no packed bit support for these things }
  441. if (l = in_bitsizeof_x) then
  442. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sinttype,true));
  443. end
  444. else
  445. begin
  446. if (l = in_sizeof_x) or
  447. (not((p1.nodetype = vecn) and
  448. is_packed_array(tvecnode(p1).left.resulttype.def)) and
  449. not((p1.nodetype = subscriptn) and
  450. is_packed_record_or_object(tsubscriptnode(p1).left.resulttype.def))) then
  451. begin
  452. statement_syssym:=cordconstnode.create(p1.resulttype.def.size,sinttype,true);
  453. if (l = in_bitsizeof_x) then
  454. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sinttype,true));
  455. end
  456. else
  457. statement_syssym:=cordconstnode.create(p1.resulttype.def.packedbitsize,sinttype,true);
  458. { p1 not needed !}
  459. p1.destroy;
  460. end;
  461. end;
  462. in_typeinfo_x :
  463. begin
  464. consume(_LKLAMMER);
  465. in_args:=true;
  466. p1:=comp_expr(true);
  467. { When reading a class type it is parsed as loadvmtaddrn,
  468. typeinfo only needs the type so we remove the loadvmtaddrn }
  469. if p1.nodetype=loadvmtaddrn then
  470. begin
  471. p2:=tloadvmtaddrnode(p1).left;
  472. tloadvmtaddrnode(p1).left:=nil;
  473. p1.free;
  474. p1:=p2;
  475. end;
  476. if p1.nodetype=typen then
  477. ttypenode(p1).allowed:=true
  478. else
  479. begin
  480. p1.destroy;
  481. p1:=cerrornode.create;
  482. Message(parser_e_illegal_parameter_list);
  483. end;
  484. consume(_RKLAMMER);
  485. p2:=geninlinenode(in_typeinfo_x,false,p1);
  486. statement_syssym:=p2;
  487. end;
  488. {$ifdef SUPPORT_UNALIGNED}
  489. in_unaligned_x :
  490. begin
  491. err:=false;
  492. consume(_LKLAMMER);
  493. in_args:=true;
  494. p1:=comp_expr(true);
  495. p2:=ccallparanode.create(p1,nil);
  496. p2:=geninlinenode(in_unaligned_x,false,p2);
  497. consume(_RKLAMMER);
  498. statement_syssym:=p2;
  499. end;
  500. {$endif SUPPORT_UNALIGNED}
  501. in_assigned_x :
  502. begin
  503. err:=false;
  504. consume(_LKLAMMER);
  505. in_args:=true;
  506. p1:=comp_expr(true);
  507. { When reading a class type it is parsed as loadvmtaddrn,
  508. typeinfo only needs the type so we remove the loadvmtaddrn }
  509. if p1.nodetype=loadvmtaddrn then
  510. begin
  511. p2:=tloadvmtaddrnode(p1).left;
  512. tloadvmtaddrnode(p1).left:=nil;
  513. p1.free;
  514. p1:=p2;
  515. end;
  516. if not codegenerror then
  517. begin
  518. case p1.resulttype.def.deftype of
  519. procdef, { procvar }
  520. pointerdef,
  521. procvardef,
  522. classrefdef : ;
  523. objectdef :
  524. if not is_class_or_interface(p1.resulttype.def) then
  525. begin
  526. Message(parser_e_illegal_parameter_list);
  527. err:=true;
  528. end;
  529. arraydef :
  530. if not is_dynamic_array(p1.resulttype.def) then
  531. begin
  532. Message(parser_e_illegal_parameter_list);
  533. err:=true;
  534. end;
  535. else
  536. begin
  537. Message(parser_e_illegal_parameter_list);
  538. err:=true;
  539. end;
  540. end;
  541. end
  542. else
  543. err:=true;
  544. if not err then
  545. begin
  546. p2:=ccallparanode.create(p1,nil);
  547. p2:=geninlinenode(in_assigned_x,false,p2);
  548. end
  549. else
  550. begin
  551. p1.free;
  552. p2:=cerrornode.create;
  553. end;
  554. consume(_RKLAMMER);
  555. statement_syssym:=p2;
  556. end;
  557. in_addr_x :
  558. begin
  559. consume(_LKLAMMER);
  560. in_args:=true;
  561. p1:=comp_expr(true);
  562. p1:=caddrnode.create(p1);
  563. if cs_typed_addresses in aktlocalswitches then
  564. include(p1.flags,nf_typedaddr);
  565. consume(_RKLAMMER);
  566. statement_syssym:=p1;
  567. end;
  568. in_ofs_x :
  569. begin
  570. consume(_LKLAMMER);
  571. in_args:=true;
  572. p1:=comp_expr(true);
  573. p1:=caddrnode.create(p1);
  574. do_resulttypepass(p1);
  575. { Ofs() returns a cardinal/qword, not a pointer }
  576. p1.resulttype:=uinttype;
  577. consume(_RKLAMMER);
  578. statement_syssym:=p1;
  579. end;
  580. in_seg_x :
  581. begin
  582. consume(_LKLAMMER);
  583. in_args:=true;
  584. p1:=comp_expr(true);
  585. p1:=geninlinenode(in_seg_x,false,p1);
  586. consume(_RKLAMMER);
  587. statement_syssym:=p1;
  588. end;
  589. in_high_x,
  590. in_low_x :
  591. begin
  592. consume(_LKLAMMER);
  593. in_args:=true;
  594. p1:=comp_expr(true);
  595. p2:=geninlinenode(l,false,p1);
  596. consume(_RKLAMMER);
  597. statement_syssym:=p2;
  598. end;
  599. in_succ_x,
  600. in_pred_x :
  601. begin
  602. consume(_LKLAMMER);
  603. in_args:=true;
  604. p1:=comp_expr(true);
  605. p2:=geninlinenode(l,false,p1);
  606. consume(_RKLAMMER);
  607. statement_syssym:=p2;
  608. end;
  609. in_inc_x,
  610. in_dec_x :
  611. begin
  612. consume(_LKLAMMER);
  613. in_args:=true;
  614. p1:=comp_expr(true);
  615. if try_to_consume(_COMMA) then
  616. p2:=ccallparanode.create(comp_expr(true),nil)
  617. else
  618. p2:=nil;
  619. p2:=ccallparanode.create(p1,p2);
  620. statement_syssym:=geninlinenode(l,false,p2);
  621. consume(_RKLAMMER);
  622. end;
  623. in_slice_x:
  624. begin
  625. if not(in_args) then
  626. begin
  627. message(parser_e_illegal_slice);
  628. consume(_LKLAMMER);
  629. in_args:=true;
  630. comp_expr(true).free;
  631. if try_to_consume(_COMMA) then
  632. comp_expr(true).free;
  633. statement_syssym:=cerrornode.create;
  634. consume(_RKLAMMER);
  635. end
  636. else
  637. begin
  638. consume(_LKLAMMER);
  639. in_args:=true;
  640. p1:=comp_expr(true);
  641. Consume(_COMMA);
  642. if not(codegenerror) then
  643. p2:=ccallparanode.create(comp_expr(true),nil)
  644. else
  645. p2:=cerrornode.create;
  646. p2:=ccallparanode.create(p1,p2);
  647. statement_syssym:=geninlinenode(l,false,p2);
  648. consume(_RKLAMMER);
  649. end;
  650. end;
  651. in_initialize_x:
  652. begin
  653. statement_syssym:=inline_initialize;
  654. end;
  655. in_finalize_x:
  656. begin
  657. statement_syssym:=inline_finalize;
  658. end;
  659. in_copy_x:
  660. begin
  661. statement_syssym:=inline_copy;
  662. end;
  663. in_concat_x :
  664. begin
  665. consume(_LKLAMMER);
  666. in_args:=true;
  667. { Translate to x:=x+y[+z]. The addnode will do the
  668. type checking }
  669. p2:=nil;
  670. repeat
  671. p1:=comp_expr(true);
  672. if p2<>nil then
  673. p2:=caddnode.create(addn,p2,p1)
  674. else
  675. begin
  676. { Force string type if it isn't yet }
  677. if not(
  678. (p1.resulttype.def.deftype=stringdef) or
  679. is_chararray(p1.resulttype.def) or
  680. is_char(p1.resulttype.def)
  681. ) then
  682. inserttypeconv(p1,cshortstringtype);
  683. p2:=p1;
  684. end;
  685. until not try_to_consume(_COMMA);
  686. consume(_RKLAMMER);
  687. statement_syssym:=p2;
  688. end;
  689. in_read_x,
  690. in_readln_x :
  691. begin
  692. if try_to_consume(_LKLAMMER) then
  693. begin
  694. paras:=parse_paras(false,_RKLAMMER);
  695. consume(_RKLAMMER);
  696. end
  697. else
  698. paras:=nil;
  699. p1:=geninlinenode(l,false,paras);
  700. statement_syssym := p1;
  701. end;
  702. in_setlength_x:
  703. begin
  704. statement_syssym := inline_setlength;
  705. end;
  706. in_length_x:
  707. begin
  708. consume(_LKLAMMER);
  709. in_args:=true;
  710. p1:=comp_expr(true);
  711. p2:=geninlinenode(l,false,p1);
  712. consume(_RKLAMMER);
  713. statement_syssym:=p2;
  714. end;
  715. in_write_x,
  716. in_writeln_x :
  717. begin
  718. if try_to_consume(_LKLAMMER) then
  719. begin
  720. paras:=parse_paras(true,_RKLAMMER);
  721. consume(_RKLAMMER);
  722. end
  723. else
  724. paras:=nil;
  725. p1 := geninlinenode(l,false,paras);
  726. statement_syssym := p1;
  727. end;
  728. in_str_x_string :
  729. begin
  730. consume(_LKLAMMER);
  731. paras:=parse_paras(true,_RKLAMMER);
  732. consume(_RKLAMMER);
  733. p1 := geninlinenode(l,false,paras);
  734. statement_syssym := p1;
  735. end;
  736. in_val_x:
  737. Begin
  738. consume(_LKLAMMER);
  739. in_args := true;
  740. p1:= ccallparanode.create(comp_expr(true), nil);
  741. consume(_COMMA);
  742. p2 := ccallparanode.create(comp_expr(true),p1);
  743. if try_to_consume(_COMMA) then
  744. p2 := ccallparanode.create(comp_expr(true),p2);
  745. consume(_RKLAMMER);
  746. p2 := geninlinenode(l,false,p2);
  747. statement_syssym := p2;
  748. End;
  749. in_include_x_y,
  750. in_exclude_x_y :
  751. begin
  752. consume(_LKLAMMER);
  753. in_args:=true;
  754. p1:=comp_expr(true);
  755. consume(_COMMA);
  756. p2:=comp_expr(true);
  757. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  758. consume(_RKLAMMER);
  759. end;
  760. in_pack_x_y_z,
  761. in_unpack_x_y_z :
  762. begin
  763. consume(_LKLAMMER);
  764. in_args:=true;
  765. p1:=comp_expr(true);
  766. consume(_COMMA);
  767. p2:=comp_expr(true);
  768. consume(_COMMA);
  769. paras:=comp_expr(true);
  770. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,ccallparanode.create(paras,nil))));
  771. consume(_RKLAMMER);
  772. end;
  773. in_assert_x_y :
  774. begin
  775. consume(_LKLAMMER);
  776. in_args:=true;
  777. p1:=comp_expr(true);
  778. if try_to_consume(_COMMA) then
  779. p2:=comp_expr(true)
  780. else
  781. begin
  782. { then insert an empty string }
  783. p2:=cstringconstnode.createstr('');
  784. end;
  785. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  786. consume(_RKLAMMER);
  787. end;
  788. in_get_frame:
  789. begin
  790. statement_syssym:=geninlinenode(l,false,nil);
  791. end;
  792. in_get_caller_frame:
  793. begin
  794. if try_to_consume(_LKLAMMER) then
  795. begin
  796. {You used to call get_caller_frame as get_caller_frame(get_frame),
  797. however, as a stack frame may not exist, it does more harm than
  798. good, so ignore it.}
  799. in_args:=true;
  800. p1:=comp_expr(true);
  801. p1.destroy;
  802. consume(_RKLAMMER);
  803. end;
  804. statement_syssym:=geninlinenode(l,false,nil);
  805. end;
  806. else
  807. internalerror(15);
  808. end;
  809. in_args:=prev_in_args;
  810. end;
  811. function maybe_load_methodpointer(st:tsymtable;var p1:tnode):boolean;
  812. begin
  813. maybe_load_methodpointer:=false;
  814. if not assigned(p1) then
  815. begin
  816. case st.symtabletype of
  817. withsymtable :
  818. begin
  819. if (st.defowner.deftype=objectdef) then
  820. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  821. end;
  822. objectsymtable :
  823. begin
  824. p1:=load_self_node;
  825. { We are calling a member }
  826. maybe_load_methodpointer:=true;
  827. end;
  828. end;
  829. end;
  830. end;
  831. { reads the parameter for a subroutine call }
  832. procedure do_proc_call(sym:tsym;st:tsymtable;obj:tobjectdef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags);
  833. var
  834. membercall,
  835. prevafterassn : boolean;
  836. i : integer;
  837. para,p2 : tnode;
  838. currpara : tparavarsym;
  839. aprocdef : tprocdef;
  840. begin
  841. prevafterassn:=afterassignment;
  842. afterassignment:=false;
  843. membercall:=false;
  844. aprocdef:=nil;
  845. { when it is a call to a member we need to load the
  846. methodpointer first }
  847. membercall:=maybe_load_methodpointer(st,p1);
  848. { When we are expecting a procvar we also need
  849. to get the address in some cases }
  850. if assigned(getprocvardef) then
  851. begin
  852. if (block_type=bt_const) or
  853. getaddr then
  854. begin
  855. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  856. getaddr:=true;
  857. end
  858. else
  859. if (m_tp_procvar in aktmodeswitches) or
  860. (m_mac_procvar in aktmodeswitches) then
  861. begin
  862. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  863. if assigned(aprocdef) then
  864. getaddr:=true;
  865. end;
  866. end;
  867. { only need to get the address of the procedure? }
  868. if getaddr then
  869. begin
  870. { Retrieve info which procvar to call. For tp_procvar the
  871. aprocdef is already loaded above so we can reuse it }
  872. if not assigned(aprocdef) and
  873. assigned(getprocvardef) then
  874. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  875. { generate a methodcallnode or proccallnode }
  876. { we shouldn't convert things like @tcollection.load }
  877. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  878. if assigned(p1) then
  879. begin
  880. { for loading methodpointer of an inherited function
  881. we use self as instance and load the address of
  882. the function directly and not through the vmt (PFV) }
  883. if (cnf_inherited in callflags) then
  884. begin
  885. include(p2.flags,nf_inherited);
  886. p1.free;
  887. p1:=load_self_node;
  888. end;
  889. if (p1.nodetype<>typen) then
  890. tloadnode(p2).set_mp(p1)
  891. else
  892. p1.free;
  893. end;
  894. p1:=p2;
  895. { no postfix operators }
  896. again:=false;
  897. end
  898. else
  899. begin
  900. para:=nil;
  901. if anon_inherited then
  902. begin
  903. if not assigned(current_procinfo) then
  904. internalerror(200305054);
  905. for i:=0 to current_procinfo.procdef.paras.count-1 do
  906. begin
  907. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  908. if not(vo_is_hidden_para in currpara.varoptions) then
  909. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  910. end;
  911. end
  912. else
  913. begin
  914. if try_to_consume(_LKLAMMER) then
  915. begin
  916. para:=parse_paras(false,_RKLAMMER);
  917. consume(_RKLAMMER);
  918. end;
  919. end;
  920. { indicate if this call was generated by a member and
  921. no explicit self is used, this is needed to determine
  922. how to handle a destructor call (PFV) }
  923. if membercall then
  924. include(callflags,cnf_member_call);
  925. if assigned(obj) then
  926. begin
  927. if (st.symtabletype<>objectsymtable) then
  928. internalerror(200310031);
  929. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags);
  930. end
  931. else
  932. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags);
  933. end;
  934. afterassignment:=prevafterassn;
  935. end;
  936. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  937. var
  938. hp,hp2 : tnode;
  939. hpp : ^tnode;
  940. currprocdef : tprocdef;
  941. begin
  942. if not assigned(pv) then
  943. internalerror(200301121);
  944. if (m_tp_procvar in aktmodeswitches) or
  945. (m_mac_procvar in aktmodeswitches) then
  946. begin
  947. hp:=p2;
  948. hpp:=@p2;
  949. while assigned(hp) and
  950. (hp.nodetype=typeconvn) do
  951. begin
  952. hp:=ttypeconvnode(hp).left;
  953. { save orignal address of the old tree so we can replace the node }
  954. hpp:=@hp;
  955. end;
  956. if (hp.nodetype=calln) and
  957. { a procvar can't have parameters! }
  958. not assigned(tcallnode(hp).left) then
  959. begin
  960. currprocdef:=tcallnode(hp).symtableprocentry.search_procdef_byprocvardef(pv);
  961. if assigned(currprocdef) then
  962. begin
  963. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  964. if (po_methodpointer in pv.procoptions) then
  965. tloadnode(hp2).set_mp(tcallnode(hp).get_load_methodpointer);
  966. hp.destroy;
  967. { replace the old callnode with the new loadnode }
  968. hpp^:=hp2;
  969. end;
  970. end;
  971. end;
  972. end;
  973. { the following procedure handles the access to a property symbol }
  974. procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode);
  975. var
  976. paras : tnode;
  977. p2 : tnode;
  978. membercall : boolean;
  979. callflags : tcallnodeflags;
  980. begin
  981. paras:=nil;
  982. { property parameters? read them only if the property really }
  983. { has parameters }
  984. if (ppo_hasparameters in tpropertysym(sym).propoptions) then
  985. begin
  986. if try_to_consume(_LECKKLAMMER) then
  987. begin
  988. paras:=parse_paras(false,_RECKKLAMMER);
  989. consume(_RECKKLAMMER);
  990. end;
  991. end;
  992. { indexed property }
  993. if (ppo_indexed in tpropertysym(sym).propoptions) then
  994. begin
  995. p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype,true);
  996. paras:=ccallparanode.create(p2,paras);
  997. end;
  998. { we need only a write property if a := follows }
  999. { if not(afterassignment) and not(in_args) then }
  1000. if token=_ASSIGNMENT then
  1001. begin
  1002. { write property: }
  1003. if not tpropertysym(sym).writeaccess.empty then
  1004. begin
  1005. case tpropertysym(sym).writeaccess.firstsym^.sym.typ of
  1006. procsym :
  1007. begin
  1008. callflags:=[];
  1009. { generate the method call }
  1010. membercall:=maybe_load_methodpointer(st,p1);
  1011. if membercall then
  1012. include(callflags,cnf_member_call);
  1013. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1,callflags);
  1014. addsymref(tpropertysym(sym).writeaccess.firstsym^.sym);
  1015. paras:=nil;
  1016. consume(_ASSIGNMENT);
  1017. { read the expression }
  1018. if tpropertysym(sym).proptype.def.deftype=procvardef then
  1019. getprocvardef:=tprocvardef(tpropertysym(sym).proptype.def);
  1020. p2:=comp_expr(true);
  1021. if assigned(getprocvardef) then
  1022. handle_procvar(getprocvardef,p2);
  1023. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1024. { mark as property, both the tcallnode and the real call block }
  1025. include(p1.flags,nf_isproperty);
  1026. getprocvardef:=nil;
  1027. end;
  1028. fieldvarsym :
  1029. begin
  1030. { generate access code }
  1031. symlist_to_node(p1,st,tpropertysym(sym).writeaccess);
  1032. include(p1.flags,nf_isproperty);
  1033. consume(_ASSIGNMENT);
  1034. { read the expression }
  1035. p2:=comp_expr(true);
  1036. p1:=cassignmentnode.create(p1,p2);
  1037. end
  1038. else
  1039. begin
  1040. p1:=cerrornode.create;
  1041. Message(parser_e_no_procedure_to_access_property);
  1042. end;
  1043. end;
  1044. end
  1045. else
  1046. begin
  1047. p1:=cerrornode.create;
  1048. Message(parser_e_no_procedure_to_access_property);
  1049. end;
  1050. end
  1051. else
  1052. begin
  1053. { read property: }
  1054. if not tpropertysym(sym).readaccess.empty then
  1055. begin
  1056. case tpropertysym(sym).readaccess.firstsym^.sym.typ of
  1057. fieldvarsym :
  1058. begin
  1059. { generate access code }
  1060. symlist_to_node(p1,st,tpropertysym(sym).readaccess);
  1061. include(p1.flags,nf_isproperty);
  1062. end;
  1063. procsym :
  1064. begin
  1065. callflags:=[];
  1066. { generate the method call }
  1067. membercall:=maybe_load_methodpointer(st,p1);
  1068. if membercall then
  1069. include(callflags,cnf_member_call);
  1070. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1,callflags);
  1071. paras:=nil;
  1072. include(p1.flags,nf_isproperty);
  1073. end
  1074. else
  1075. begin
  1076. p1:=cerrornode.create;
  1077. Message(type_e_mismatch);
  1078. end;
  1079. end;
  1080. end
  1081. else
  1082. begin
  1083. { error, no function to read property }
  1084. p1:=cerrornode.create;
  1085. Message(parser_e_no_procedure_to_access_property);
  1086. end;
  1087. end;
  1088. { release paras if not used }
  1089. if assigned(paras) then
  1090. paras.free;
  1091. end;
  1092. { the ID token has to be consumed before calling this function }
  1093. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callflags:tcallnodeflags);
  1094. var
  1095. static_name : string;
  1096. isclassref : boolean;
  1097. srsymtable : tsymtable;
  1098. begin
  1099. if sym=nil then
  1100. begin
  1101. { pattern is still valid unless
  1102. there is another ID just after the ID of sym }
  1103. Message1(sym_e_id_no_member,orgpattern);
  1104. p1.free;
  1105. p1:=cerrornode.create;
  1106. { try to clean up }
  1107. again:=false;
  1108. end
  1109. else
  1110. begin
  1111. if assigned(p1) then
  1112. begin
  1113. if not assigned(p1.resulttype.def) then
  1114. do_resulttypepass(p1);
  1115. isclassref:=(p1.resulttype.def.deftype=classrefdef);
  1116. end
  1117. else
  1118. isclassref:=false;
  1119. { we assume, that only procsyms and varsyms are in an object }
  1120. { symbol table, for classes, properties are allowed }
  1121. case sym.typ of
  1122. procsym:
  1123. begin
  1124. do_proc_call(sym,sym.owner,classh,
  1125. (getaddr and not(token in [_CARET,_POINT])),
  1126. again,p1,callflags);
  1127. { we need to know which procedure is called }
  1128. do_resulttypepass(p1);
  1129. { calling using classref? }
  1130. if isclassref and
  1131. (p1.nodetype=calln) and
  1132. assigned(tcallnode(p1).procdefinition) and
  1133. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1134. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1135. Message(parser_e_only_class_methods_via_class_ref);
  1136. end;
  1137. fieldvarsym:
  1138. begin
  1139. if (sp_static in sym.symoptions) then
  1140. begin
  1141. static_name:=lower(sym.owner.name^)+'_'+sym.name;
  1142. searchsym(static_name,sym,srsymtable);
  1143. if assigned(sym) then
  1144. check_hints(sym,sym.symoptions);
  1145. p1.free;
  1146. p1:=cloadnode.create(sym,srsymtable);
  1147. end
  1148. else
  1149. begin
  1150. if isclassref then
  1151. Message(parser_e_only_class_methods_via_class_ref);
  1152. p1:=csubscriptnode.create(sym,p1);
  1153. end;
  1154. end;
  1155. propertysym:
  1156. begin
  1157. if isclassref then
  1158. Message(parser_e_only_class_methods_via_class_ref);
  1159. handle_propertysym(sym,sym.owner,p1);
  1160. end;
  1161. else internalerror(16);
  1162. end;
  1163. end;
  1164. end;
  1165. {****************************************************************************
  1166. Factor
  1167. ****************************************************************************}
  1168. {$maxfpuregisters 0}
  1169. function factor(getaddr : boolean) : tnode;
  1170. {---------------------------------------------
  1171. Factor_read_id
  1172. ---------------------------------------------}
  1173. procedure factor_read_id(var p1:tnode;var again:boolean);
  1174. var
  1175. pc : pchar;
  1176. len : longint;
  1177. srsym : tsym;
  1178. possible_error : boolean;
  1179. srsymtable : tsymtable;
  1180. hdef : tdef;
  1181. htype : ttype;
  1182. static_name : string;
  1183. begin
  1184. { allow post fix operators }
  1185. again:=true;
  1186. consume_sym(srsym,srsymtable);
  1187. { Access to funcret or need to call the function? }
  1188. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  1189. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  1190. (
  1191. (token=_LKLAMMER) or
  1192. (
  1193. (
  1194. (m_tp7 in aktmodeswitches) or
  1195. (m_delphi in aktmodeswitches)
  1196. ) and
  1197. (afterassignment or in_args) and
  1198. not(vo_is_result in tabstractvarsym(srsym).varoptions)
  1199. )
  1200. ) then
  1201. begin
  1202. hdef:=tdef(srsym.owner.defowner);
  1203. if assigned(hdef) and
  1204. (hdef.deftype=procdef) then
  1205. srsym:=tprocdef(hdef).procsym
  1206. else
  1207. begin
  1208. Message(parser_e_illegal_expression);
  1209. srsym:=generrorsym;
  1210. end;
  1211. srsymtable:=srsym.owner;
  1212. {
  1213. storesymtablestack:=symtablestack;
  1214. symtablestack:=srsym.owner.next;
  1215. searchsym(srsym.name,srsym,srsymtable);
  1216. if not assigned(srsym) then
  1217. srsym:=generrorsym;
  1218. if (srsym.typ<>procsym) then
  1219. Message(parser_e_illegal_expression);
  1220. symtablestack:=storesymtablestack;
  1221. }
  1222. end;
  1223. begin
  1224. case srsym.typ of
  1225. absolutevarsym :
  1226. begin
  1227. if (tabsolutevarsym(srsym).abstyp=tovar) then
  1228. begin
  1229. p1:=nil;
  1230. symlist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  1231. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vartype);
  1232. include(p1.flags,nf_absolute);
  1233. end
  1234. else
  1235. p1:=cloadnode.create(srsym,srsymtable);
  1236. end;
  1237. globalvarsym,
  1238. localvarsym,
  1239. paravarsym,
  1240. fieldvarsym :
  1241. begin
  1242. if (sp_static in srsym.symoptions) then
  1243. begin
  1244. static_name:=lower(srsym.owner.name^)+'_'+srsym.name;
  1245. searchsym(static_name,srsym,srsymtable);
  1246. if assigned(srsym) then
  1247. check_hints(srsym,srsym.symoptions);
  1248. end
  1249. else
  1250. begin
  1251. { are we in a class method, we check here the
  1252. srsymtable, because a field in another object
  1253. also has objectsymtable. And withsymtable is
  1254. not possible for self in class methods (PFV) }
  1255. if (srsymtable.symtabletype=objectsymtable) and
  1256. assigned(current_procinfo) and
  1257. (po_classmethod in current_procinfo.procdef.procoptions) then
  1258. Message(parser_e_only_class_methods);
  1259. end;
  1260. case srsymtable.symtabletype of
  1261. objectsymtable :
  1262. begin
  1263. p1:=csubscriptnode.create(srsym,load_self_node);
  1264. node_tree_set_filepos(p1,aktfilepos);
  1265. end;
  1266. withsymtable :
  1267. begin
  1268. p1:=csubscriptnode.create(srsym,tnode(twithsymtable(srsymtable).withrefnode).getcopy);
  1269. node_tree_set_filepos(p1,aktfilepos);
  1270. end;
  1271. else
  1272. p1:=cloadnode.create(srsym,srsymtable);
  1273. end;
  1274. end;
  1275. typedconstsym :
  1276. begin
  1277. p1:=cloadnode.create(srsym,srsymtable);
  1278. end;
  1279. syssym :
  1280. begin
  1281. p1:=statement_syssym(tsyssym(srsym).number);
  1282. end;
  1283. typesym :
  1284. begin
  1285. htype.setsym(srsym);
  1286. if not assigned(htype.def) then
  1287. begin
  1288. again:=false;
  1289. end
  1290. else
  1291. begin
  1292. { We need to know if this unit uses Variants }
  1293. if (htype.def=cvarianttype.def) and
  1294. not(cs_compilesystem in aktmoduleswitches) then
  1295. current_module.flags:=current_module.flags or uf_uses_variants;
  1296. if (block_type<>bt_specialize) and
  1297. try_to_consume(_LKLAMMER) then
  1298. begin
  1299. p1:=comp_expr(true);
  1300. consume(_RKLAMMER);
  1301. p1:=ctypeconvnode.create_explicit(p1,htype);
  1302. end
  1303. else { not LKLAMMER }
  1304. if (token=_POINT) and
  1305. is_object(htype.def) then
  1306. begin
  1307. consume(_POINT);
  1308. if assigned(current_procinfo) and
  1309. assigned(current_procinfo.procdef._class) and
  1310. not(getaddr) then
  1311. begin
  1312. if current_procinfo.procdef._class.is_related(tobjectdef(htype.def)) then
  1313. begin
  1314. p1:=ctypenode.create(htype);
  1315. { search also in inherited methods }
  1316. searchsym_in_class(tobjectdef(htype.def),current_procinfo.procdef._class,pattern,srsym,srsymtable);
  1317. if assigned(srsym) then
  1318. check_hints(srsym,srsym.symoptions);
  1319. consume(_ID);
  1320. do_member_read(tobjectdef(htype.def),false,srsym,p1,again,[]);
  1321. end
  1322. else
  1323. begin
  1324. Message(parser_e_no_super_class);
  1325. again:=false;
  1326. end;
  1327. end
  1328. else
  1329. begin
  1330. { allows @TObject.Load }
  1331. { also allows static methods and variables }
  1332. p1:=ctypenode.create(htype);
  1333. { TP allows also @TMenu.Load if Load is only }
  1334. { defined in an anchestor class }
  1335. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1336. if assigned(srsym) then
  1337. begin
  1338. check_hints(srsym,srsym.symoptions);
  1339. if not(getaddr) and not(sp_static in srsym.symoptions) then
  1340. Message(sym_e_only_static_in_static)
  1341. else
  1342. begin
  1343. consume(_ID);
  1344. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1345. end;
  1346. end
  1347. else
  1348. Message1(sym_e_id_no_member,orgpattern);
  1349. end;
  1350. end
  1351. else
  1352. begin
  1353. { class reference ? }
  1354. if is_class(htype.def) then
  1355. begin
  1356. if getaddr and (token=_POINT) then
  1357. begin
  1358. consume(_POINT);
  1359. { allows @Object.Method }
  1360. { also allows static methods and variables }
  1361. p1:=ctypenode.create(htype);
  1362. { TP allows also @TMenu.Load if Load is only }
  1363. { defined in an anchestor class }
  1364. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1365. if assigned(srsym) then
  1366. begin
  1367. check_hints(srsym,srsym.symoptions);
  1368. consume(_ID);
  1369. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1370. end
  1371. else
  1372. begin
  1373. Message1(sym_e_id_no_member,orgpattern);
  1374. consume(_ID);
  1375. end;
  1376. end
  1377. else
  1378. begin
  1379. p1:=ctypenode.create(htype);
  1380. { For a type block we simply return only
  1381. the type. For all other blocks we return
  1382. a loadvmt node }
  1383. if not(block_type in [bt_type,bt_specialize]) then
  1384. p1:=cloadvmtaddrnode.create(p1);
  1385. end;
  1386. end
  1387. else
  1388. p1:=ctypenode.create(htype);
  1389. end;
  1390. end;
  1391. end;
  1392. enumsym :
  1393. begin
  1394. p1:=genenumnode(tenumsym(srsym));
  1395. end;
  1396. constsym :
  1397. begin
  1398. case tconstsym(srsym).consttyp of
  1399. constord :
  1400. begin
  1401. if tconstsym(srsym).consttype.def=nil then
  1402. internalerror(200403232);
  1403. p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
  1404. end;
  1405. conststring :
  1406. begin
  1407. len:=tconstsym(srsym).value.len;
  1408. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1409. len:=255;
  1410. getmem(pc,len+1);
  1411. move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
  1412. pc[len]:=#0;
  1413. p1:=cstringconstnode.createpchar(pc,len);
  1414. end;
  1415. constwstring :
  1416. p1:=cstringconstnode.createwstr(pcompilerwidestring(tconstsym(srsym).value.valueptr));
  1417. constreal :
  1418. p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
  1419. constset :
  1420. p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
  1421. constpointer :
  1422. p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
  1423. constnil :
  1424. p1:=cnilnode.create;
  1425. constresourcestring:
  1426. begin
  1427. p1:=cloadnode.create(srsym,srsymtable);
  1428. do_resulttypepass(p1);
  1429. p1.resulttype:=cansistringtype;
  1430. end;
  1431. constguid :
  1432. p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
  1433. else
  1434. internalerror(200507181);
  1435. end;
  1436. end;
  1437. procsym :
  1438. begin
  1439. { are we in a class method ? }
  1440. possible_error:=(srsymtable.symtabletype<>withsymtable) and
  1441. (srsym.owner.symtabletype=objectsymtable) and
  1442. not(is_interface(tdef(srsym.owner.defowner))) and
  1443. assigned(current_procinfo) and
  1444. (po_classmethod in current_procinfo.procdef.procoptions);
  1445. do_proc_call(srsym,srsymtable,nil,
  1446. (getaddr and not(token in [_CARET,_POINT])),
  1447. again,p1,[]);
  1448. { we need to know which procedure is called }
  1449. if possible_error then
  1450. begin
  1451. do_resulttypepass(p1);
  1452. if (p1.nodetype=calln) and
  1453. assigned(tcallnode(p1).procdefinition) and
  1454. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1455. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) then
  1456. Message(parser_e_only_class_methods);
  1457. end;
  1458. end;
  1459. propertysym :
  1460. begin
  1461. { access to property in a method }
  1462. { are we in a class method ? }
  1463. if (srsymtable.symtabletype=objectsymtable) and
  1464. assigned(current_procinfo) and
  1465. (po_classmethod in current_procinfo.procdef.procoptions) then
  1466. Message(parser_e_only_class_methods);
  1467. { no method pointer }
  1468. p1:=nil;
  1469. handle_propertysym(srsym,srsymtable,p1);
  1470. end;
  1471. labelsym :
  1472. begin
  1473. { Support @label }
  1474. if getaddr then
  1475. p1:=cloadnode.create(srsym,srsym.owner)
  1476. else
  1477. begin
  1478. consume(_COLON);
  1479. if tlabelsym(srsym).defined then
  1480. Message(sym_e_label_already_defined);
  1481. tlabelsym(srsym).defined:=true;
  1482. p1:=clabelnode.create(nil);
  1483. tlabelsym(srsym).code:=p1;
  1484. end;
  1485. end;
  1486. errorsym :
  1487. begin
  1488. p1:=cerrornode.create;
  1489. if try_to_consume(_LKLAMMER) then
  1490. begin
  1491. parse_paras(false,_RKLAMMER);
  1492. consume(_RKLAMMER);
  1493. end;
  1494. end;
  1495. else
  1496. begin
  1497. p1:=cerrornode.create;
  1498. Message(parser_e_illegal_expression);
  1499. end;
  1500. end; { end case }
  1501. end;
  1502. end;
  1503. {---------------------------------------------
  1504. Factor_Read_Set
  1505. ---------------------------------------------}
  1506. { Read a set between [] }
  1507. function factor_read_set:tnode;
  1508. var
  1509. p1,p2 : tnode;
  1510. lastp,
  1511. buildp : tarrayconstructornode;
  1512. begin
  1513. buildp:=nil;
  1514. { be sure that a least one arrayconstructn is used, also for an
  1515. empty [] }
  1516. if token=_RECKKLAMMER then
  1517. buildp:=carrayconstructornode.create(nil,buildp)
  1518. else
  1519. repeat
  1520. p1:=comp_expr(true);
  1521. if try_to_consume(_POINTPOINT) then
  1522. begin
  1523. p2:=comp_expr(true);
  1524. p1:=carrayconstructorrangenode.create(p1,p2);
  1525. end;
  1526. { insert at the end of the tree, to get the correct order }
  1527. if not assigned(buildp) then
  1528. begin
  1529. buildp:=carrayconstructornode.create(p1,nil);
  1530. lastp:=buildp;
  1531. end
  1532. else
  1533. begin
  1534. lastp.right:=carrayconstructornode.create(p1,nil);
  1535. lastp:=tarrayconstructornode(lastp.right);
  1536. end;
  1537. { there could be more elements }
  1538. until not try_to_consume(_COMMA);
  1539. factor_read_set:=buildp;
  1540. end;
  1541. {---------------------------------------------
  1542. PostFixOperators
  1543. ---------------------------------------------}
  1544. procedure postfixoperators(var p1:tnode;var again:boolean);
  1545. { tries to avoid syntax errors after invalid qualifiers }
  1546. procedure recoverconsume_postfixops;
  1547. begin
  1548. repeat
  1549. if not try_to_consume(_CARET) then
  1550. if try_to_consume(_POINT) then
  1551. try_to_consume(_ID)
  1552. else if try_to_consume(_LECKKLAMMER) then
  1553. begin
  1554. repeat
  1555. comp_expr(true);
  1556. until not try_to_consume(_COMMA);
  1557. consume(_RECKKLAMMER);
  1558. end
  1559. else
  1560. break;
  1561. until false;
  1562. end;
  1563. procedure handle_variantarray;
  1564. var
  1565. p4 : tnode;
  1566. newstatement : tstatementnode;
  1567. tempresultvariant,
  1568. temp : ttempcreatenode;
  1569. paras : tcallparanode;
  1570. newblock : tnode;
  1571. countindices : aint;
  1572. begin
  1573. { create statements with call initialize the arguments and
  1574. call fpc_dynarr_setlength }
  1575. newblock:=internalstatements(newstatement);
  1576. { get temp for array of indicies,
  1577. we set the real size later }
  1578. temp:=ctempcreatenode.create(sinttype,4,tt_persistent,false);
  1579. addstatement(newstatement,temp);
  1580. countindices:=0;
  1581. repeat
  1582. p4:=comp_expr(true);
  1583. addstatement(newstatement,cassignmentnode.create(
  1584. ctemprefnode.create_offset(temp,countindices*sinttype.def.size),p4));
  1585. inc(countindices);
  1586. until not try_to_consume(_COMMA);
  1587. { set real size }
  1588. temp.size:=countindices*sinttype.def.size;
  1589. consume(_RECKKLAMMER);
  1590. { we need only a write access if a := follows }
  1591. if token=_ASSIGNMENT then
  1592. begin
  1593. consume(_ASSIGNMENT);
  1594. p4:=comp_expr(true);
  1595. { create call to fpc_vararray_put }
  1596. paras:=ccallparanode.create(cordconstnode.create
  1597. (countindices,sinttype,true),
  1598. ccallparanode.create(caddrnode.create_internal
  1599. (ctemprefnode.create(temp)),
  1600. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1601. ccallparanode.create(p1
  1602. ,nil))));
  1603. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1604. addstatement(newstatement,ctempdeletenode.create(temp));
  1605. end
  1606. else
  1607. begin
  1608. { create temp for result }
  1609. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.def.size,tt_persistent,true);
  1610. addstatement(newstatement,tempresultvariant);
  1611. { create call to fpc_vararray_get }
  1612. paras:=ccallparanode.create(cordconstnode.create
  1613. (countindices,sinttype,true),
  1614. ccallparanode.create(caddrnode.create_internal
  1615. (ctemprefnode.create(temp)),
  1616. ccallparanode.create(p1,
  1617. ccallparanode.create(
  1618. ctemprefnode.create(tempresultvariant)
  1619. ,nil))));
  1620. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1621. addstatement(newstatement,ctempdeletenode.create(temp));
  1622. { the last statement should return the value as
  1623. location and type, this is done be referencing the
  1624. temp and converting it first from a persistent temp to
  1625. normal temp }
  1626. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1627. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1628. end;
  1629. p1:=newblock;
  1630. end;
  1631. var
  1632. store_static : boolean;
  1633. protsym : tpropertysym;
  1634. p2,p3 : tnode;
  1635. srsym : tsym;
  1636. srsymtable : tsymtable;
  1637. classh : tobjectdef;
  1638. label
  1639. skipreckklammercheck;
  1640. begin
  1641. again:=true;
  1642. while again do
  1643. begin
  1644. { we need the resulttype }
  1645. do_resulttypepass(p1);
  1646. if codegenerror then
  1647. begin
  1648. recoverconsume_postfixops;
  1649. exit;
  1650. end;
  1651. { handle token }
  1652. case token of
  1653. _CARET:
  1654. begin
  1655. consume(_CARET);
  1656. { support tp/mac procvar^ if the procvar returns a
  1657. pointer type }
  1658. if ((m_tp_procvar in aktmodeswitches) or
  1659. (m_mac_procvar in aktmodeswitches)) and
  1660. (p1.resulttype.def.deftype=procvardef) and
  1661. (tprocvardef(p1.resulttype.def).rettype.def.deftype=pointerdef) then
  1662. begin
  1663. p1:=ccallnode.create_procvar(nil,p1);
  1664. resulttypepass(p1);
  1665. end;
  1666. if (p1.resulttype.def.deftype<>pointerdef) then
  1667. begin
  1668. { ^ as binary operator is a problem!!!! (FK) }
  1669. again:=false;
  1670. Message(parser_e_invalid_qualifier);
  1671. recoverconsume_postfixops;
  1672. p1.destroy;
  1673. p1:=cerrornode.create;
  1674. end
  1675. else
  1676. p1:=cderefnode.create(p1);
  1677. end;
  1678. _LECKKLAMMER:
  1679. begin
  1680. if is_class_or_interface(p1.resulttype.def) then
  1681. begin
  1682. { default property }
  1683. protsym:=search_default_property(tobjectdef(p1.resulttype.def));
  1684. if not(assigned(protsym)) then
  1685. begin
  1686. p1.destroy;
  1687. p1:=cerrornode.create;
  1688. again:=false;
  1689. message(parser_e_no_default_property_available);
  1690. end
  1691. else
  1692. begin
  1693. { The property symbol is referenced indirect }
  1694. inc(protsym.refs);
  1695. handle_propertysym(protsym,protsym.owner,p1);
  1696. end;
  1697. end
  1698. else
  1699. begin
  1700. consume(_LECKKLAMMER);
  1701. repeat
  1702. case p1.resulttype.def.deftype of
  1703. pointerdef:
  1704. begin
  1705. { support delphi autoderef }
  1706. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=arraydef) and
  1707. (m_autoderef in aktmodeswitches) then
  1708. begin
  1709. p1:=cderefnode.create(p1);
  1710. end;
  1711. p2:=comp_expr(true);
  1712. p1:=cvecnode.create(p1,p2);
  1713. end;
  1714. variantdef:
  1715. begin
  1716. handle_variantarray;
  1717. { the RECKKLAMMER is already read }
  1718. goto skipreckklammercheck;
  1719. end;
  1720. stringdef :
  1721. begin
  1722. p2:=comp_expr(true);
  1723. p1:=cvecnode.create(p1,p2);
  1724. end;
  1725. arraydef :
  1726. begin
  1727. p2:=comp_expr(true);
  1728. { support SEG:OFS for go32v2 Mem[] }
  1729. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1730. (p1.nodetype=loadn) and
  1731. assigned(tloadnode(p1).symtableentry) and
  1732. assigned(tloadnode(p1).symtableentry.owner.name) and
  1733. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1734. ((tloadnode(p1).symtableentry.name='MEM') or
  1735. (tloadnode(p1).symtableentry.name='MEMW') or
  1736. (tloadnode(p1).symtableentry.name='MEML')) then
  1737. begin
  1738. if try_to_consume(_COLON) then
  1739. begin
  1740. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1741. p2:=comp_expr(true);
  1742. p2:=caddnode.create(addn,p2,p3);
  1743. p1:=cvecnode.create(p1,p2);
  1744. include(tvecnode(p1).flags,nf_memseg);
  1745. include(tvecnode(p1).flags,nf_memindex);
  1746. end
  1747. else
  1748. begin
  1749. p1:=cvecnode.create(p1,p2);
  1750. include(tvecnode(p1).flags,nf_memindex);
  1751. end;
  1752. end
  1753. else
  1754. p1:=cvecnode.create(p1,p2);
  1755. end;
  1756. else
  1757. begin
  1758. Message(parser_e_invalid_qualifier);
  1759. p1.destroy;
  1760. p1:=cerrornode.create;
  1761. comp_expr(true);
  1762. again:=false;
  1763. end;
  1764. end;
  1765. do_resulttypepass(p1);
  1766. until not try_to_consume(_COMMA);
  1767. consume(_RECKKLAMMER);
  1768. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1769. skipreckklammercheck:
  1770. end;
  1771. end;
  1772. _POINT :
  1773. begin
  1774. consume(_POINT);
  1775. if (p1.resulttype.def.deftype=pointerdef) and
  1776. (m_autoderef in aktmodeswitches) then
  1777. begin
  1778. p1:=cderefnode.create(p1);
  1779. do_resulttypepass(p1);
  1780. end;
  1781. case p1.resulttype.def.deftype of
  1782. recorddef:
  1783. begin
  1784. if token=_ID then
  1785. begin
  1786. srsym:=tsym(trecorddef(p1.resulttype.def).symtable.search(pattern));
  1787. if assigned(srsym) and
  1788. (srsym.typ=fieldvarsym) then
  1789. begin
  1790. check_hints(srsym,srsym.symoptions);
  1791. p1:=csubscriptnode.create(srsym,p1)
  1792. end
  1793. else
  1794. begin
  1795. Message1(sym_e_illegal_field,pattern);
  1796. p1.destroy;
  1797. p1:=cerrornode.create;
  1798. end;
  1799. end;
  1800. consume(_ID);
  1801. end;
  1802. variantdef:
  1803. begin
  1804. { dispatch call }
  1805. if token=_ID then
  1806. begin
  1807. consume(_ID);
  1808. end;
  1809. end;
  1810. classrefdef:
  1811. begin
  1812. if token=_ID then
  1813. begin
  1814. classh:=tobjectdef(tclassrefdef(p1.resulttype.def).pointertype.def);
  1815. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1816. if assigned(srsym) then
  1817. begin
  1818. check_hints(srsym,srsym.symoptions);
  1819. consume(_ID);
  1820. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1821. end
  1822. else
  1823. begin
  1824. Message1(sym_e_id_no_member,orgpattern);
  1825. p1.destroy;
  1826. p1:=cerrornode.create;
  1827. { try to clean up }
  1828. consume(_ID);
  1829. end;
  1830. end
  1831. else { Error }
  1832. Consume(_ID);
  1833. end;
  1834. objectdef:
  1835. begin
  1836. if token=_ID then
  1837. begin
  1838. store_static:=allow_only_static;
  1839. allow_only_static:=false;
  1840. classh:=tobjectdef(p1.resulttype.def);
  1841. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1842. allow_only_static:=store_static;
  1843. if assigned(srsym) then
  1844. begin
  1845. check_hints(srsym,srsym.symoptions);
  1846. consume(_ID);
  1847. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1848. end
  1849. else
  1850. begin
  1851. Message1(sym_e_id_no_member,orgpattern);
  1852. p1.destroy;
  1853. p1:=cerrornode.create;
  1854. { try to clean up }
  1855. consume(_ID);
  1856. end;
  1857. end
  1858. else { Error }
  1859. Consume(_ID);
  1860. end;
  1861. pointerdef:
  1862. begin
  1863. Message(parser_e_invalid_qualifier);
  1864. if tpointerdef(p1.resulttype.def).pointertype.def.deftype in [recorddef,objectdef,classrefdef] then
  1865. Message(parser_h_maybe_deref_caret_missing);
  1866. end;
  1867. else
  1868. begin
  1869. Message(parser_e_invalid_qualifier);
  1870. p1.destroy;
  1871. p1:=cerrornode.create;
  1872. { Error }
  1873. consume(_ID);
  1874. end;
  1875. end;
  1876. end;
  1877. else
  1878. begin
  1879. { is this a procedure variable ? }
  1880. if assigned(p1.resulttype.def) and
  1881. (p1.resulttype.def.deftype=procvardef) then
  1882. begin
  1883. if assigned(getprocvardef) and
  1884. equal_defs(p1.resulttype.def,getprocvardef) then
  1885. again:=false
  1886. else
  1887. begin
  1888. if try_to_consume(_LKLAMMER) then
  1889. begin
  1890. p2:=parse_paras(false,_RKLAMMER);
  1891. consume(_RKLAMMER);
  1892. p1:=ccallnode.create_procvar(p2,p1);
  1893. { proc():= is never possible }
  1894. if token=_ASSIGNMENT then
  1895. begin
  1896. Message(parser_e_illegal_expression);
  1897. p1.free;
  1898. p1:=cerrornode.create;
  1899. again:=false;
  1900. end;
  1901. end
  1902. else
  1903. again:=false;
  1904. end;
  1905. end
  1906. else
  1907. again:=false;
  1908. end;
  1909. end;
  1910. end; { while again }
  1911. end;
  1912. {---------------------------------------------
  1913. Factor (Main)
  1914. ---------------------------------------------}
  1915. var
  1916. l : longint;
  1917. ic : int64;
  1918. qc : qword;
  1919. {$ifndef cpu64}
  1920. card : cardinal;
  1921. {$endif cpu64}
  1922. oldp1,
  1923. p1 : tnode;
  1924. code : integer;
  1925. again : boolean;
  1926. srsym : tsym;
  1927. srsymtable : tsymtable;
  1928. pd : tprocdef;
  1929. classh : tobjectdef;
  1930. d : bestreal;
  1931. hs,hsorg : string;
  1932. htype : ttype;
  1933. filepos : tfileposinfo;
  1934. begin
  1935. oldp1:=nil;
  1936. p1:=nil;
  1937. filepos:=akttokenpos;
  1938. again:=false;
  1939. if token=_ID then
  1940. begin
  1941. again:=true;
  1942. { Handle references to self }
  1943. if (idtoken=_SELF) and
  1944. not(block_type in [bt_const,bt_type]) and
  1945. assigned(current_procinfo) and
  1946. assigned(current_procinfo.procdef._class) then
  1947. begin
  1948. p1:=load_self_node;
  1949. consume(_ID);
  1950. again:=true;
  1951. end
  1952. else
  1953. factor_read_id(p1,again);
  1954. if again then
  1955. begin
  1956. if (p1<>oldp1) then
  1957. begin
  1958. if assigned(p1) then
  1959. p1.fileinfo:=filepos;
  1960. oldp1:=p1;
  1961. filepos:=akttokenpos;
  1962. end;
  1963. { handle post fix operators }
  1964. postfixoperators(p1,again);
  1965. end;
  1966. end
  1967. else
  1968. case token of
  1969. _RETURN :
  1970. begin
  1971. consume(_RETURN);
  1972. p1 := cexitnode.create(comp_expr(true));
  1973. end;
  1974. _INHERITED :
  1975. begin
  1976. again:=true;
  1977. consume(_INHERITED);
  1978. if assigned(current_procinfo) and
  1979. assigned(current_procinfo.procdef._class) then
  1980. begin
  1981. classh:=current_procinfo.procdef._class.childof;
  1982. { if inherited; only then we need the method with
  1983. the same name }
  1984. if token in endtokens then
  1985. begin
  1986. hs:=current_procinfo.procdef.procsym.name;
  1987. hsorg:=current_procinfo.procdef.procsym.realname;
  1988. anon_inherited:=true;
  1989. { For message methods we need to search using the message
  1990. number or string }
  1991. pd:=tprocsym(current_procinfo.procdef.procsym).first_procdef;
  1992. if (po_msgint in pd.procoptions) then
  1993. searchsym_in_class_by_msgint(classh,pd.messageinf.i,srsym,srsymtable)
  1994. else
  1995. if (po_msgstr in pd.procoptions) then
  1996. searchsym_in_class_by_msgstr(classh,pd.messageinf.str^,srsym,srsymtable)
  1997. else
  1998. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  1999. end
  2000. else
  2001. begin
  2002. hs:=pattern;
  2003. hsorg:=orgpattern;
  2004. consume(_ID);
  2005. anon_inherited:=false;
  2006. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  2007. end;
  2008. if assigned(srsym) then
  2009. begin
  2010. check_hints(srsym,srsym.symoptions);
  2011. { load the procdef from the inherited class and
  2012. not from self }
  2013. if srsym.typ in [procsym,propertysym] then
  2014. begin
  2015. if (srsym.typ = procsym) then
  2016. begin
  2017. htype.setdef(classh);
  2018. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2019. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2020. htype.setdef(tclassrefdef.create(htype));
  2021. p1:=ctypenode.create(htype);
  2022. end;
  2023. end
  2024. else
  2025. begin
  2026. Message(parser_e_methode_id_expected);
  2027. p1:=cerrornode.create;
  2028. end;
  2029. do_member_read(classh,getaddr,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
  2030. end
  2031. else
  2032. begin
  2033. if anon_inherited then
  2034. begin
  2035. { For message methods we need to call DefaultHandler }
  2036. if (po_msgint in pd.procoptions) or
  2037. (po_msgstr in pd.procoptions) then
  2038. begin
  2039. searchsym_in_class(classh,classh,'DEFAULTHANDLER',srsym,srsymtable);
  2040. if not assigned(srsym) or
  2041. (srsym.typ<>procsym) then
  2042. internalerror(200303171);
  2043. p1:=nil;
  2044. do_proc_call(srsym,srsym.owner,classh,false,again,p1,[]);
  2045. end
  2046. else
  2047. begin
  2048. { we need to ignore the inherited; }
  2049. p1:=cnothingnode.create;
  2050. end;
  2051. end
  2052. else
  2053. begin
  2054. Message1(sym_e_id_no_member,hsorg);
  2055. p1:=cerrornode.create;
  2056. end;
  2057. again:=false;
  2058. end;
  2059. { turn auto inheriting off }
  2060. anon_inherited:=false;
  2061. end
  2062. else
  2063. begin
  2064. Message(parser_e_generic_methods_only_in_methods);
  2065. again:=false;
  2066. p1:=cerrornode.create;
  2067. end;
  2068. postfixoperators(p1,again);
  2069. end;
  2070. _INTCONST :
  2071. begin
  2072. {$ifdef cpu64}
  2073. { when already running under 64bit must read int64 constant, because reading
  2074. cardinal first will also succeed (code=0) for values > maxcardinal, because
  2075. range checking is off by default (PFV) }
  2076. val(pattern,ic,code);
  2077. if code=0 then
  2078. begin
  2079. consume(_INTCONST);
  2080. int_to_type(ic,htype);
  2081. p1:=cordconstnode.create(ic,htype,true);
  2082. end
  2083. else
  2084. begin
  2085. { try qword next }
  2086. val(pattern,qc,code);
  2087. if code=0 then
  2088. begin
  2089. consume(_INTCONST);
  2090. htype:=u64inttype;
  2091. p1:=cordconstnode.create(qc,htype,true);
  2092. end;
  2093. end;
  2094. {$else}
  2095. { try cardinal first }
  2096. val(pattern,card,code);
  2097. if code=0 then
  2098. begin
  2099. consume(_INTCONST);
  2100. int_to_type(card,htype);
  2101. p1:=cordconstnode.create(card,htype,true);
  2102. end
  2103. else
  2104. begin
  2105. { then longint }
  2106. val(pattern,l,code);
  2107. if code = 0 then
  2108. begin
  2109. consume(_INTCONST);
  2110. int_to_type(l,htype);
  2111. p1:=cordconstnode.create(l,htype,true);
  2112. end
  2113. else
  2114. begin
  2115. { then int64 }
  2116. val(pattern,ic,code);
  2117. if code=0 then
  2118. begin
  2119. consume(_INTCONST);
  2120. int_to_type(ic,htype);
  2121. p1:=cordconstnode.create(ic,htype,true);
  2122. end
  2123. else
  2124. begin
  2125. { try qword next }
  2126. val(pattern,qc,code);
  2127. if code=0 then
  2128. begin
  2129. consume(_INTCONST);
  2130. htype:=u64inttype;
  2131. p1:=cordconstnode.create(tconstexprint(qc),htype,true);
  2132. end;
  2133. end;
  2134. end;
  2135. end;
  2136. {$endif}
  2137. if code<>0 then
  2138. begin
  2139. { finally float }
  2140. val(pattern,d,code);
  2141. if code<>0 then
  2142. begin
  2143. Message(parser_e_invalid_integer);
  2144. consume(_INTCONST);
  2145. l:=1;
  2146. p1:=cordconstnode.create(l,sinttype,true);
  2147. end
  2148. else
  2149. begin
  2150. consume(_INTCONST);
  2151. p1:=crealconstnode.create(d,pbestrealtype^);
  2152. end;
  2153. end;
  2154. end;
  2155. _REALNUMBER :
  2156. begin
  2157. val(pattern,d,code);
  2158. if code<>0 then
  2159. begin
  2160. Message(parser_e_error_in_real);
  2161. d:=1.0;
  2162. end;
  2163. consume(_REALNUMBER);
  2164. p1:=crealconstnode.create(d,pbestrealtype^);
  2165. end;
  2166. _STRING :
  2167. begin
  2168. string_dec(htype);
  2169. { STRING can be also a type cast }
  2170. if try_to_consume(_LKLAMMER) then
  2171. begin
  2172. p1:=comp_expr(true);
  2173. consume(_RKLAMMER);
  2174. p1:=ctypeconvnode.create_explicit(p1,htype);
  2175. { handle postfix operators here e.g. string(a)[10] }
  2176. again:=true;
  2177. postfixoperators(p1,again);
  2178. end
  2179. else
  2180. p1:=ctypenode.create(htype);
  2181. end;
  2182. _FILE :
  2183. begin
  2184. htype:=cfiletype;
  2185. consume(_FILE);
  2186. { FILE can be also a type cast }
  2187. if try_to_consume(_LKLAMMER) then
  2188. begin
  2189. p1:=comp_expr(true);
  2190. consume(_RKLAMMER);
  2191. p1:=ctypeconvnode.create_explicit(p1,htype);
  2192. { handle postfix operators here e.g. string(a)[10] }
  2193. again:=true;
  2194. postfixoperators(p1,again);
  2195. end
  2196. else
  2197. begin
  2198. p1:=ctypenode.create(htype);
  2199. end;
  2200. end;
  2201. _CSTRING :
  2202. begin
  2203. p1:=cstringconstnode.createstr(pattern);
  2204. consume(_CSTRING);
  2205. end;
  2206. _CCHAR :
  2207. begin
  2208. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  2209. consume(_CCHAR);
  2210. end;
  2211. _CWSTRING:
  2212. begin
  2213. p1:=cstringconstnode.createwstr(patternw);
  2214. consume(_CWSTRING);
  2215. end;
  2216. _CWCHAR:
  2217. begin
  2218. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  2219. consume(_CWCHAR);
  2220. end;
  2221. _KLAMMERAFFE :
  2222. begin
  2223. consume(_KLAMMERAFFE);
  2224. got_addrn:=true;
  2225. { support both @<x> and @(<x>) }
  2226. if try_to_consume(_LKLAMMER) then
  2227. begin
  2228. p1:=factor(true);
  2229. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2230. begin
  2231. again:=true;
  2232. postfixoperators(p1,again);
  2233. end;
  2234. consume(_RKLAMMER);
  2235. end
  2236. else
  2237. p1:=factor(true);
  2238. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2239. begin
  2240. again:=true;
  2241. postfixoperators(p1,again);
  2242. end;
  2243. got_addrn:=false;
  2244. p1:=caddrnode.create(p1);
  2245. if cs_typed_addresses in aktlocalswitches then
  2246. include(p1.flags,nf_typedaddr);
  2247. { Store the procvar that we are expecting, the
  2248. addrn will use the information to find the correct
  2249. procdef or it will return an error }
  2250. if assigned(getprocvardef) and
  2251. (taddrnode(p1).left.nodetype = loadn) then
  2252. taddrnode(p1).getprocvardef:=getprocvardef;
  2253. end;
  2254. _LKLAMMER :
  2255. begin
  2256. consume(_LKLAMMER);
  2257. p1:=comp_expr(true);
  2258. consume(_RKLAMMER);
  2259. { it's not a good solution }
  2260. { but (a+b)^ makes some problems }
  2261. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2262. begin
  2263. again:=true;
  2264. postfixoperators(p1,again);
  2265. end;
  2266. end;
  2267. _LECKKLAMMER :
  2268. begin
  2269. consume(_LECKKLAMMER);
  2270. p1:=factor_read_set;
  2271. consume(_RECKKLAMMER);
  2272. end;
  2273. _PLUS :
  2274. begin
  2275. consume(_PLUS);
  2276. p1:=factor(false);
  2277. { we must generate a new node to do 0+<p1> otherwise the + will
  2278. not be checked }
  2279. p1:=caddnode.create(addn,genintconstnode(0),p1);
  2280. end;
  2281. _MINUS :
  2282. begin
  2283. consume(_MINUS);
  2284. if (token = _INTCONST) then
  2285. begin
  2286. { ugly hack, but necessary to be able to parse }
  2287. { -9223372036854775808 as int64 (JM) }
  2288. pattern := '-'+pattern;
  2289. p1:=sub_expr(oppower,false);
  2290. { -1 ** 4 should be - (1 ** 4) and not
  2291. (-1) ** 4
  2292. This was the reason of tw0869.pp test failure PM }
  2293. if p1.nodetype=starstarn then
  2294. begin
  2295. if tbinarynode(p1).left.nodetype=ordconstn then
  2296. begin
  2297. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  2298. p1:=cunaryminusnode.create(p1);
  2299. end
  2300. else if tbinarynode(p1).left.nodetype=realconstn then
  2301. begin
  2302. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  2303. p1:=cunaryminusnode.create(p1);
  2304. end
  2305. else
  2306. internalerror(20021029);
  2307. end;
  2308. end
  2309. else
  2310. begin
  2311. p1:=sub_expr(oppower,false);
  2312. p1:=cunaryminusnode.create(p1);
  2313. end;
  2314. end;
  2315. _OP_NOT :
  2316. begin
  2317. consume(_OP_NOT);
  2318. p1:=factor(false);
  2319. p1:=cnotnode.create(p1);
  2320. end;
  2321. _TRUE :
  2322. begin
  2323. consume(_TRUE);
  2324. p1:=cordconstnode.create(1,booltype,false);
  2325. end;
  2326. _FALSE :
  2327. begin
  2328. consume(_FALSE);
  2329. p1:=cordconstnode.create(0,booltype,false);
  2330. end;
  2331. _NIL :
  2332. begin
  2333. consume(_NIL);
  2334. p1:=cnilnode.create;
  2335. { It's really ugly code nil^, but delphi allows it }
  2336. if token in [_CARET] then
  2337. begin
  2338. again:=true;
  2339. postfixoperators(p1,again);
  2340. end;
  2341. end;
  2342. else
  2343. begin
  2344. Message(parser_e_illegal_expression);
  2345. p1:=cerrornode.create;
  2346. { recover }
  2347. consume(token);
  2348. end;
  2349. end;
  2350. { generate error node if no node is created }
  2351. if not assigned(p1) then
  2352. begin
  2353. {$ifdef EXTDEBUG}
  2354. Comment(V_Warning,'factor: p1=nil');
  2355. {$endif}
  2356. p1:=cerrornode.create;
  2357. end;
  2358. { get the resulttype for the node }
  2359. if (not assigned(p1.resulttype.def)) then
  2360. do_resulttypepass(p1);
  2361. if assigned(p1) and
  2362. (p1<>oldp1) then
  2363. p1.fileinfo:=filepos;
  2364. factor:=p1;
  2365. end;
  2366. {$maxfpuregisters default}
  2367. {****************************************************************************
  2368. Sub_Expr
  2369. ****************************************************************************}
  2370. const
  2371. { Warning these stay be ordered !! }
  2372. operator_levels:array[Toperator_precedence] of set of Ttoken=
  2373. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN],
  2374. [_PLUS,_MINUS,_OP_OR,_PIPE,_OP_XOR],
  2375. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2376. _OP_AS,_OP_IS,_OP_AND,_AMPERSAND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2377. [_STARSTAR] );
  2378. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;
  2379. {Reads a subexpression while the operators are of the current precedence
  2380. level, or any higher level. Replaces the old term, simpl_expr and
  2381. simpl2_expr.}
  2382. var
  2383. p1,p2 : tnode;
  2384. oldt : Ttoken;
  2385. filepos : tfileposinfo;
  2386. begin
  2387. if pred_level=highest_precedence then
  2388. p1:=factor(false)
  2389. else
  2390. p1:=sub_expr(succ(pred_level),true);
  2391. repeat
  2392. if (token in operator_levels[pred_level]) and
  2393. ((token<>_EQUAL) or accept_equal) then
  2394. begin
  2395. oldt:=token;
  2396. filepos:=akttokenpos;
  2397. consume(token);
  2398. if pred_level=highest_precedence then
  2399. p2:=factor(false)
  2400. else
  2401. p2:=sub_expr(succ(pred_level),true);
  2402. case oldt of
  2403. _PLUS :
  2404. p1:=caddnode.create(addn,p1,p2);
  2405. _MINUS :
  2406. p1:=caddnode.create(subn,p1,p2);
  2407. _STAR :
  2408. p1:=caddnode.create(muln,p1,p2);
  2409. _SLASH :
  2410. p1:=caddnode.create(slashn,p1,p2);
  2411. _EQUAL :
  2412. p1:=caddnode.create(equaln,p1,p2);
  2413. _GT :
  2414. p1:=caddnode.create(gtn,p1,p2);
  2415. _LT :
  2416. p1:=caddnode.create(ltn,p1,p2);
  2417. _GTE :
  2418. p1:=caddnode.create(gten,p1,p2);
  2419. _LTE :
  2420. p1:=caddnode.create(lten,p1,p2);
  2421. _SYMDIF :
  2422. p1:=caddnode.create(symdifn,p1,p2);
  2423. _STARSTAR :
  2424. p1:=caddnode.create(starstarn,p1,p2);
  2425. _OP_AS :
  2426. p1:=casnode.create(p1,p2);
  2427. _OP_IN :
  2428. p1:=cinnode.create(p1,p2);
  2429. _OP_IS :
  2430. p1:=cisnode.create(p1,p2);
  2431. _OP_OR,
  2432. _PIPE {macpas only} :
  2433. begin
  2434. p1:=caddnode.create(orn,p1,p2);
  2435. if (oldt = _PIPE) then
  2436. include(p1.flags,nf_short_bool);
  2437. end;
  2438. _OP_AND,
  2439. _AMPERSAND {macpas only} :
  2440. begin
  2441. p1:=caddnode.create(andn,p1,p2);
  2442. if (oldt = _AMPERSAND) then
  2443. include(p1.flags,nf_short_bool);
  2444. end;
  2445. _OP_DIV :
  2446. p1:=cmoddivnode.create(divn,p1,p2);
  2447. _OP_NOT :
  2448. p1:=cnotnode.create(p1);
  2449. _OP_MOD :
  2450. p1:=cmoddivnode.create(modn,p1,p2);
  2451. _OP_SHL :
  2452. p1:=cshlshrnode.create(shln,p1,p2);
  2453. _OP_SHR :
  2454. p1:=cshlshrnode.create(shrn,p1,p2);
  2455. _OP_XOR :
  2456. p1:=caddnode.create(xorn,p1,p2);
  2457. _ASSIGNMENT :
  2458. p1:=cassignmentnode.create(p1,p2);
  2459. _CARET :
  2460. p1:=caddnode.create(caretn,p1,p2);
  2461. _UNEQUAL :
  2462. p1:=caddnode.create(unequaln,p1,p2);
  2463. end;
  2464. p1.fileinfo:=filepos;
  2465. end
  2466. else
  2467. break;
  2468. until false;
  2469. sub_expr:=p1;
  2470. end;
  2471. function comp_expr(accept_equal : boolean):tnode;
  2472. var
  2473. oldafterassignment : boolean;
  2474. p1 : tnode;
  2475. begin
  2476. oldafterassignment:=afterassignment;
  2477. afterassignment:=true;
  2478. p1:=sub_expr(opcompare,accept_equal);
  2479. { get the resulttype for this expression }
  2480. if not assigned(p1.resulttype.def) then
  2481. do_resulttypepass(p1);
  2482. afterassignment:=oldafterassignment;
  2483. comp_expr:=p1;
  2484. end;
  2485. function expr : tnode;
  2486. var
  2487. p1,p2 : tnode;
  2488. oldafterassignment : boolean;
  2489. oldp1 : tnode;
  2490. filepos : tfileposinfo;
  2491. begin
  2492. oldafterassignment:=afterassignment;
  2493. p1:=sub_expr(opcompare,true);
  2494. { get the resulttype for this expression }
  2495. if not assigned(p1.resulttype.def) then
  2496. do_resulttypepass(p1);
  2497. filepos:=akttokenpos;
  2498. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  2499. afterassignment:=true;
  2500. oldp1:=p1;
  2501. case token of
  2502. _POINTPOINT :
  2503. begin
  2504. consume(_POINTPOINT);
  2505. p2:=sub_expr(opcompare,true);
  2506. p1:=crangenode.create(p1,p2);
  2507. end;
  2508. _ASSIGNMENT :
  2509. begin
  2510. consume(_ASSIGNMENT);
  2511. if (p1.resulttype.def.deftype=procvardef) then
  2512. getprocvardef:=tprocvardef(p1.resulttype.def);
  2513. p2:=sub_expr(opcompare,true);
  2514. if assigned(getprocvardef) then
  2515. handle_procvar(getprocvardef,p2);
  2516. getprocvardef:=nil;
  2517. p1:=cassignmentnode.create(p1,p2);
  2518. end;
  2519. _PLUSASN :
  2520. begin
  2521. consume(_PLUSASN);
  2522. p2:=sub_expr(opcompare,true);
  2523. p1:=gen_c_style_operator(addn,p1,p2);
  2524. end;
  2525. _MINUSASN :
  2526. begin
  2527. consume(_MINUSASN);
  2528. p2:=sub_expr(opcompare,true);
  2529. p1:=gen_c_style_operator(subn,p1,p2);
  2530. end;
  2531. _STARASN :
  2532. begin
  2533. consume(_STARASN );
  2534. p2:=sub_expr(opcompare,true);
  2535. p1:=gen_c_style_operator(muln,p1,p2);
  2536. end;
  2537. _SLASHASN :
  2538. begin
  2539. consume(_SLASHASN );
  2540. p2:=sub_expr(opcompare,true);
  2541. p1:=gen_c_style_operator(slashn,p1,p2);
  2542. end;
  2543. end;
  2544. { get the resulttype for this expression }
  2545. if not assigned(p1.resulttype.def) then
  2546. do_resulttypepass(p1);
  2547. afterassignment:=oldafterassignment;
  2548. if p1<>oldp1 then
  2549. p1.fileinfo:=filepos;
  2550. expr:=p1;
  2551. end;
  2552. function get_intconst:TConstExprInt;
  2553. {Reads an expression, tries to evalute it and check if it is an integer
  2554. constant. Then the constant is returned.}
  2555. var
  2556. p:tnode;
  2557. begin
  2558. result:=0;
  2559. p:=comp_expr(true);
  2560. if not codegenerror then
  2561. begin
  2562. if (p.nodetype<>ordconstn) or
  2563. not(is_integer(p.resulttype.def)) then
  2564. Message(parser_e_illegal_expression)
  2565. else
  2566. result:=tordconstnode(p).value;
  2567. end;
  2568. p.free;
  2569. end;
  2570. function get_stringconst:string;
  2571. {Reads an expression, tries to evaluate it and checks if it is a string
  2572. constant. Then the constant is returned.}
  2573. var
  2574. p:tnode;
  2575. begin
  2576. get_stringconst:='';
  2577. p:=comp_expr(true);
  2578. if p.nodetype<>stringconstn then
  2579. begin
  2580. if (p.nodetype=ordconstn) and is_char(p.resulttype.def) then
  2581. get_stringconst:=char(tordconstnode(p).value)
  2582. else
  2583. Message(parser_e_illegal_expression);
  2584. end
  2585. else
  2586. get_stringconst:=strpas(tstringconstnode(p).value_str);
  2587. p.free;
  2588. end;
  2589. end.