pexpr.pas 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767
  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. {$ifdef fpc}
  1169. {$maxfpuregisters 0}
  1170. {$endif fpc}
  1171. function factor(getaddr : boolean) : tnode;
  1172. {---------------------------------------------
  1173. Factor_read_id
  1174. ---------------------------------------------}
  1175. procedure factor_read_id(var p1:tnode;var again:boolean);
  1176. var
  1177. pc : pchar;
  1178. len : longint;
  1179. srsym : tsym;
  1180. possible_error : boolean;
  1181. srsymtable : tsymtable;
  1182. hdef : tdef;
  1183. htype : ttype;
  1184. static_name : string;
  1185. begin
  1186. { allow post fix operators }
  1187. again:=true;
  1188. consume_sym(srsym,srsymtable);
  1189. { Access to funcret or need to call the function? }
  1190. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  1191. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  1192. (
  1193. (token=_LKLAMMER) or
  1194. (
  1195. (
  1196. (m_tp7 in aktmodeswitches) or
  1197. (m_delphi in aktmodeswitches)
  1198. ) and
  1199. (afterassignment or in_args) and
  1200. not(vo_is_result in tabstractvarsym(srsym).varoptions)
  1201. )
  1202. ) then
  1203. begin
  1204. hdef:=tdef(srsym.owner.defowner);
  1205. if assigned(hdef) and
  1206. (hdef.deftype=procdef) then
  1207. srsym:=tprocdef(hdef).procsym
  1208. else
  1209. begin
  1210. Message(parser_e_illegal_expression);
  1211. srsym:=generrorsym;
  1212. end;
  1213. srsymtable:=srsym.owner;
  1214. {
  1215. storesymtablestack:=symtablestack;
  1216. symtablestack:=srsym.owner.next;
  1217. searchsym(srsym.name,srsym,srsymtable);
  1218. if not assigned(srsym) then
  1219. srsym:=generrorsym;
  1220. if (srsym.typ<>procsym) then
  1221. Message(parser_e_illegal_expression);
  1222. symtablestack:=storesymtablestack;
  1223. }
  1224. end;
  1225. begin
  1226. case srsym.typ of
  1227. absolutevarsym :
  1228. begin
  1229. if (tabsolutevarsym(srsym).abstyp=tovar) then
  1230. begin
  1231. p1:=nil;
  1232. symlist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  1233. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vartype);
  1234. include(p1.flags,nf_absolute);
  1235. end
  1236. else
  1237. p1:=cloadnode.create(srsym,srsymtable);
  1238. end;
  1239. globalvarsym,
  1240. localvarsym,
  1241. paravarsym,
  1242. fieldvarsym :
  1243. begin
  1244. if (sp_static in srsym.symoptions) then
  1245. begin
  1246. static_name:=lower(srsym.owner.name^)+'_'+srsym.name;
  1247. searchsym(static_name,srsym,srsymtable);
  1248. if assigned(srsym) then
  1249. check_hints(srsym,srsym.symoptions);
  1250. end
  1251. else
  1252. begin
  1253. { are we in a class method, we check here the
  1254. srsymtable, because a field in another object
  1255. also has objectsymtable. And withsymtable is
  1256. not possible for self in class methods (PFV) }
  1257. if (srsymtable.symtabletype=objectsymtable) and
  1258. assigned(current_procinfo) and
  1259. (po_classmethod in current_procinfo.procdef.procoptions) then
  1260. Message(parser_e_only_class_methods);
  1261. end;
  1262. case srsymtable.symtabletype of
  1263. objectsymtable :
  1264. begin
  1265. p1:=csubscriptnode.create(srsym,load_self_node);
  1266. node_tree_set_filepos(p1,aktfilepos);
  1267. end;
  1268. withsymtable :
  1269. begin
  1270. p1:=csubscriptnode.create(srsym,tnode(twithsymtable(srsymtable).withrefnode).getcopy);
  1271. node_tree_set_filepos(p1,aktfilepos);
  1272. end;
  1273. else
  1274. p1:=cloadnode.create(srsym,srsymtable);
  1275. end;
  1276. end;
  1277. typedconstsym :
  1278. begin
  1279. p1:=cloadnode.create(srsym,srsymtable);
  1280. end;
  1281. syssym :
  1282. begin
  1283. p1:=statement_syssym(tsyssym(srsym).number);
  1284. end;
  1285. typesym :
  1286. begin
  1287. htype.setsym(srsym);
  1288. if not assigned(htype.def) then
  1289. begin
  1290. again:=false;
  1291. end
  1292. else
  1293. begin
  1294. { We need to know if this unit uses Variants }
  1295. if (htype.def=cvarianttype.def) and
  1296. not(cs_compilesystem in aktmoduleswitches) then
  1297. current_module.flags:=current_module.flags or uf_uses_variants;
  1298. if (block_type<>bt_specialize) and
  1299. try_to_consume(_LKLAMMER) then
  1300. begin
  1301. p1:=comp_expr(true);
  1302. consume(_RKLAMMER);
  1303. p1:=ctypeconvnode.create_explicit(p1,htype);
  1304. end
  1305. else { not LKLAMMER }
  1306. if (token=_POINT) and
  1307. is_object(htype.def) then
  1308. begin
  1309. consume(_POINT);
  1310. if assigned(current_procinfo) and
  1311. assigned(current_procinfo.procdef._class) and
  1312. not(getaddr) then
  1313. begin
  1314. if current_procinfo.procdef._class.is_related(tobjectdef(htype.def)) then
  1315. begin
  1316. p1:=ctypenode.create(htype);
  1317. { search also in inherited methods }
  1318. searchsym_in_class(tobjectdef(htype.def),current_procinfo.procdef._class,pattern,srsym,srsymtable);
  1319. if assigned(srsym) then
  1320. check_hints(srsym,srsym.symoptions);
  1321. consume(_ID);
  1322. do_member_read(tobjectdef(htype.def),false,srsym,p1,again,[]);
  1323. end
  1324. else
  1325. begin
  1326. Message(parser_e_no_super_class);
  1327. again:=false;
  1328. end;
  1329. end
  1330. else
  1331. begin
  1332. { allows @TObject.Load }
  1333. { also allows static methods and variables }
  1334. p1:=ctypenode.create(htype);
  1335. { TP allows also @TMenu.Load if Load is only }
  1336. { defined in an anchestor class }
  1337. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1338. if assigned(srsym) then
  1339. begin
  1340. check_hints(srsym,srsym.symoptions);
  1341. if not(getaddr) and not(sp_static in srsym.symoptions) then
  1342. Message(sym_e_only_static_in_static)
  1343. else
  1344. begin
  1345. consume(_ID);
  1346. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1347. end;
  1348. end
  1349. else
  1350. Message1(sym_e_id_no_member,orgpattern);
  1351. end;
  1352. end
  1353. else
  1354. begin
  1355. { class reference ? }
  1356. if is_class(htype.def) then
  1357. begin
  1358. if getaddr and (token=_POINT) then
  1359. begin
  1360. consume(_POINT);
  1361. { allows @Object.Method }
  1362. { also allows static methods and variables }
  1363. p1:=ctypenode.create(htype);
  1364. { TP allows also @TMenu.Load if Load is only }
  1365. { defined in an anchestor class }
  1366. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1367. if assigned(srsym) then
  1368. begin
  1369. check_hints(srsym,srsym.symoptions);
  1370. consume(_ID);
  1371. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1372. end
  1373. else
  1374. begin
  1375. Message1(sym_e_id_no_member,orgpattern);
  1376. consume(_ID);
  1377. end;
  1378. end
  1379. else
  1380. begin
  1381. p1:=ctypenode.create(htype);
  1382. { For a type block we simply return only
  1383. the type. For all other blocks we return
  1384. a loadvmt node }
  1385. if not(block_type in [bt_type,bt_specialize]) then
  1386. p1:=cloadvmtaddrnode.create(p1);
  1387. end;
  1388. end
  1389. else
  1390. p1:=ctypenode.create(htype);
  1391. end;
  1392. end;
  1393. end;
  1394. enumsym :
  1395. begin
  1396. p1:=genenumnode(tenumsym(srsym));
  1397. end;
  1398. constsym :
  1399. begin
  1400. case tconstsym(srsym).consttyp of
  1401. constord :
  1402. begin
  1403. if tconstsym(srsym).consttype.def=nil then
  1404. internalerror(200403232);
  1405. p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
  1406. end;
  1407. conststring :
  1408. begin
  1409. len:=tconstsym(srsym).value.len;
  1410. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1411. len:=255;
  1412. getmem(pc,len+1);
  1413. move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
  1414. pc[len]:=#0;
  1415. p1:=cstringconstnode.createpchar(pc,len);
  1416. end;
  1417. constwstring :
  1418. p1:=cstringconstnode.createwstr(pcompilerwidestring(tconstsym(srsym).value.valueptr));
  1419. constreal :
  1420. p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
  1421. constset :
  1422. p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
  1423. constpointer :
  1424. p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
  1425. constnil :
  1426. p1:=cnilnode.create;
  1427. constresourcestring:
  1428. begin
  1429. p1:=cloadnode.create(srsym,srsymtable);
  1430. do_resulttypepass(p1);
  1431. p1.resulttype:=cansistringtype;
  1432. end;
  1433. constguid :
  1434. p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
  1435. else
  1436. internalerror(200507181);
  1437. end;
  1438. end;
  1439. procsym :
  1440. begin
  1441. { are we in a class method ? }
  1442. possible_error:=(srsymtable.symtabletype<>withsymtable) and
  1443. (srsym.owner.symtabletype=objectsymtable) and
  1444. not(is_interface(tdef(srsym.owner.defowner))) and
  1445. assigned(current_procinfo) and
  1446. (po_classmethod in current_procinfo.procdef.procoptions);
  1447. do_proc_call(srsym,srsymtable,nil,
  1448. (getaddr and not(token in [_CARET,_POINT])),
  1449. again,p1,[]);
  1450. { we need to know which procedure is called }
  1451. if possible_error then
  1452. begin
  1453. do_resulttypepass(p1);
  1454. if (p1.nodetype=calln) and
  1455. assigned(tcallnode(p1).procdefinition) and
  1456. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1457. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) then
  1458. Message(parser_e_only_class_methods);
  1459. end;
  1460. end;
  1461. propertysym :
  1462. begin
  1463. { access to property in a method }
  1464. { are we in a class method ? }
  1465. if (srsymtable.symtabletype=objectsymtable) and
  1466. assigned(current_procinfo) and
  1467. (po_classmethod in current_procinfo.procdef.procoptions) then
  1468. Message(parser_e_only_class_methods);
  1469. { no method pointer }
  1470. p1:=nil;
  1471. handle_propertysym(srsym,srsymtable,p1);
  1472. end;
  1473. labelsym :
  1474. begin
  1475. { Support @label }
  1476. if getaddr then
  1477. p1:=cloadnode.create(srsym,srsym.owner)
  1478. else
  1479. begin
  1480. consume(_COLON);
  1481. if tlabelsym(srsym).defined then
  1482. Message(sym_e_label_already_defined);
  1483. tlabelsym(srsym).defined:=true;
  1484. p1:=clabelnode.create(nil);
  1485. tlabelsym(srsym).code:=p1;
  1486. end;
  1487. end;
  1488. errorsym :
  1489. begin
  1490. p1:=cerrornode.create;
  1491. if try_to_consume(_LKLAMMER) then
  1492. begin
  1493. parse_paras(false,_RKLAMMER);
  1494. consume(_RKLAMMER);
  1495. end;
  1496. end;
  1497. else
  1498. begin
  1499. p1:=cerrornode.create;
  1500. Message(parser_e_illegal_expression);
  1501. end;
  1502. end; { end case }
  1503. end;
  1504. end;
  1505. {---------------------------------------------
  1506. Factor_Read_Set
  1507. ---------------------------------------------}
  1508. { Read a set between [] }
  1509. function factor_read_set:tnode;
  1510. var
  1511. p1,p2 : tnode;
  1512. lastp,
  1513. buildp : tarrayconstructornode;
  1514. begin
  1515. buildp:=nil;
  1516. { be sure that a least one arrayconstructn is used, also for an
  1517. empty [] }
  1518. if token=_RECKKLAMMER then
  1519. buildp:=carrayconstructornode.create(nil,buildp)
  1520. else
  1521. repeat
  1522. p1:=comp_expr(true);
  1523. if try_to_consume(_POINTPOINT) then
  1524. begin
  1525. p2:=comp_expr(true);
  1526. p1:=carrayconstructorrangenode.create(p1,p2);
  1527. end;
  1528. { insert at the end of the tree, to get the correct order }
  1529. if not assigned(buildp) then
  1530. begin
  1531. buildp:=carrayconstructornode.create(p1,nil);
  1532. lastp:=buildp;
  1533. end
  1534. else
  1535. begin
  1536. lastp.right:=carrayconstructornode.create(p1,nil);
  1537. lastp:=tarrayconstructornode(lastp.right);
  1538. end;
  1539. { there could be more elements }
  1540. until not try_to_consume(_COMMA);
  1541. factor_read_set:=buildp;
  1542. end;
  1543. {---------------------------------------------
  1544. PostFixOperators
  1545. ---------------------------------------------}
  1546. procedure postfixoperators(var p1:tnode;var again:boolean);
  1547. { tries to avoid syntax errors after invalid qualifiers }
  1548. procedure recoverconsume_postfixops;
  1549. begin
  1550. repeat
  1551. if not try_to_consume(_CARET) then
  1552. if try_to_consume(_POINT) then
  1553. try_to_consume(_ID)
  1554. else if try_to_consume(_LECKKLAMMER) then
  1555. begin
  1556. repeat
  1557. comp_expr(true);
  1558. until not try_to_consume(_COMMA);
  1559. consume(_RECKKLAMMER);
  1560. end
  1561. else
  1562. break;
  1563. until false;
  1564. end;
  1565. procedure handle_variantarray;
  1566. var
  1567. p4 : tnode;
  1568. newstatement : tstatementnode;
  1569. tempresultvariant,
  1570. temp : ttempcreatenode;
  1571. paras : tcallparanode;
  1572. newblock : tnode;
  1573. countindices : aint;
  1574. begin
  1575. { create statements with call initialize the arguments and
  1576. call fpc_dynarr_setlength }
  1577. newblock:=internalstatements(newstatement);
  1578. { get temp for array of indicies,
  1579. we set the real size later }
  1580. temp:=ctempcreatenode.create(sinttype,4,tt_persistent,false);
  1581. addstatement(newstatement,temp);
  1582. countindices:=0;
  1583. repeat
  1584. p4:=comp_expr(true);
  1585. addstatement(newstatement,cassignmentnode.create(
  1586. ctemprefnode.create_offset(temp,countindices*sinttype.def.size),p4));
  1587. inc(countindices);
  1588. until not try_to_consume(_COMMA);
  1589. { set real size }
  1590. temp.size:=countindices*sinttype.def.size;
  1591. consume(_RECKKLAMMER);
  1592. { we need only a write access if a := follows }
  1593. if token=_ASSIGNMENT then
  1594. begin
  1595. consume(_ASSIGNMENT);
  1596. p4:=comp_expr(true);
  1597. { create call to fpc_vararray_put }
  1598. paras:=ccallparanode.create(cordconstnode.create
  1599. (countindices,sinttype,true),
  1600. ccallparanode.create(caddrnode.create_internal
  1601. (ctemprefnode.create(temp)),
  1602. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1603. ccallparanode.create(p1
  1604. ,nil))));
  1605. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1606. addstatement(newstatement,ctempdeletenode.create(temp));
  1607. end
  1608. else
  1609. begin
  1610. { create temp for result }
  1611. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.def.size,tt_persistent,true);
  1612. addstatement(newstatement,tempresultvariant);
  1613. { create call to fpc_vararray_get }
  1614. paras:=ccallparanode.create(cordconstnode.create
  1615. (countindices,sinttype,true),
  1616. ccallparanode.create(caddrnode.create_internal
  1617. (ctemprefnode.create(temp)),
  1618. ccallparanode.create(p1,
  1619. ccallparanode.create(
  1620. ctemprefnode.create(tempresultvariant)
  1621. ,nil))));
  1622. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1623. addstatement(newstatement,ctempdeletenode.create(temp));
  1624. { the last statement should return the value as
  1625. location and type, this is done be referencing the
  1626. temp and converting it first from a persistent temp to
  1627. normal temp }
  1628. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1629. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1630. end;
  1631. p1:=newblock;
  1632. end;
  1633. var
  1634. store_static : boolean;
  1635. protsym : tpropertysym;
  1636. p2,p3 : tnode;
  1637. srsym : tsym;
  1638. srsymtable : tsymtable;
  1639. classh : tobjectdef;
  1640. label
  1641. skipreckklammercheck;
  1642. begin
  1643. again:=true;
  1644. while again do
  1645. begin
  1646. { we need the resulttype }
  1647. do_resulttypepass(p1);
  1648. if codegenerror then
  1649. begin
  1650. recoverconsume_postfixops;
  1651. exit;
  1652. end;
  1653. { handle token }
  1654. case token of
  1655. _CARET:
  1656. begin
  1657. consume(_CARET);
  1658. { support tp/mac procvar^ if the procvar returns a
  1659. pointer type }
  1660. if ((m_tp_procvar in aktmodeswitches) or
  1661. (m_mac_procvar in aktmodeswitches)) and
  1662. (p1.resulttype.def.deftype=procvardef) and
  1663. (tprocvardef(p1.resulttype.def).rettype.def.deftype=pointerdef) then
  1664. begin
  1665. p1:=ccallnode.create_procvar(nil,p1);
  1666. resulttypepass(p1);
  1667. end;
  1668. if (p1.resulttype.def.deftype<>pointerdef) then
  1669. begin
  1670. { ^ as binary operator is a problem!!!! (FK) }
  1671. again:=false;
  1672. Message(parser_e_invalid_qualifier);
  1673. recoverconsume_postfixops;
  1674. p1.destroy;
  1675. p1:=cerrornode.create;
  1676. end
  1677. else
  1678. p1:=cderefnode.create(p1);
  1679. end;
  1680. _LECKKLAMMER:
  1681. begin
  1682. if is_class_or_interface(p1.resulttype.def) then
  1683. begin
  1684. { default property }
  1685. protsym:=search_default_property(tobjectdef(p1.resulttype.def));
  1686. if not(assigned(protsym)) then
  1687. begin
  1688. p1.destroy;
  1689. p1:=cerrornode.create;
  1690. again:=false;
  1691. message(parser_e_no_default_property_available);
  1692. end
  1693. else
  1694. begin
  1695. { The property symbol is referenced indirect }
  1696. inc(protsym.refs);
  1697. handle_propertysym(protsym,protsym.owner,p1);
  1698. end;
  1699. end
  1700. else
  1701. begin
  1702. consume(_LECKKLAMMER);
  1703. repeat
  1704. case p1.resulttype.def.deftype of
  1705. pointerdef:
  1706. begin
  1707. { support delphi autoderef }
  1708. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=arraydef) and
  1709. (m_autoderef in aktmodeswitches) then
  1710. begin
  1711. p1:=cderefnode.create(p1);
  1712. end;
  1713. p2:=comp_expr(true);
  1714. p1:=cvecnode.create(p1,p2);
  1715. end;
  1716. variantdef:
  1717. begin
  1718. handle_variantarray;
  1719. { the RECKKLAMMER is already read }
  1720. goto skipreckklammercheck;
  1721. end;
  1722. stringdef :
  1723. begin
  1724. p2:=comp_expr(true);
  1725. p1:=cvecnode.create(p1,p2);
  1726. end;
  1727. arraydef :
  1728. begin
  1729. p2:=comp_expr(true);
  1730. { support SEG:OFS for go32v2 Mem[] }
  1731. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1732. (p1.nodetype=loadn) and
  1733. assigned(tloadnode(p1).symtableentry) and
  1734. assigned(tloadnode(p1).symtableentry.owner.name) and
  1735. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1736. ((tloadnode(p1).symtableentry.name='MEM') or
  1737. (tloadnode(p1).symtableentry.name='MEMW') or
  1738. (tloadnode(p1).symtableentry.name='MEML')) then
  1739. begin
  1740. if try_to_consume(_COLON) then
  1741. begin
  1742. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1743. p2:=comp_expr(true);
  1744. p2:=caddnode.create(addn,p2,p3);
  1745. p1:=cvecnode.create(p1,p2);
  1746. include(tvecnode(p1).flags,nf_memseg);
  1747. include(tvecnode(p1).flags,nf_memindex);
  1748. end
  1749. else
  1750. begin
  1751. p1:=cvecnode.create(p1,p2);
  1752. include(tvecnode(p1).flags,nf_memindex);
  1753. end;
  1754. end
  1755. else
  1756. p1:=cvecnode.create(p1,p2);
  1757. end;
  1758. else
  1759. begin
  1760. Message(parser_e_invalid_qualifier);
  1761. p1.destroy;
  1762. p1:=cerrornode.create;
  1763. comp_expr(true);
  1764. again:=false;
  1765. end;
  1766. end;
  1767. do_resulttypepass(p1);
  1768. until not try_to_consume(_COMMA);
  1769. consume(_RECKKLAMMER);
  1770. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1771. skipreckklammercheck:
  1772. end;
  1773. end;
  1774. _POINT :
  1775. begin
  1776. consume(_POINT);
  1777. if (p1.resulttype.def.deftype=pointerdef) and
  1778. (m_autoderef in aktmodeswitches) then
  1779. begin
  1780. p1:=cderefnode.create(p1);
  1781. do_resulttypepass(p1);
  1782. end;
  1783. case p1.resulttype.def.deftype of
  1784. recorddef:
  1785. begin
  1786. if token=_ID then
  1787. begin
  1788. srsym:=tsym(trecorddef(p1.resulttype.def).symtable.search(pattern));
  1789. if assigned(srsym) and
  1790. (srsym.typ=fieldvarsym) then
  1791. begin
  1792. check_hints(srsym,srsym.symoptions);
  1793. p1:=csubscriptnode.create(srsym,p1)
  1794. end
  1795. else
  1796. begin
  1797. Message1(sym_e_illegal_field,pattern);
  1798. p1.destroy;
  1799. p1:=cerrornode.create;
  1800. end;
  1801. end;
  1802. consume(_ID);
  1803. end;
  1804. variantdef:
  1805. begin
  1806. { dispatch call }
  1807. if token=_ID then
  1808. begin
  1809. consume(_ID);
  1810. end;
  1811. end;
  1812. classrefdef:
  1813. begin
  1814. if token=_ID then
  1815. begin
  1816. classh:=tobjectdef(tclassrefdef(p1.resulttype.def).pointertype.def);
  1817. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1818. if assigned(srsym) then
  1819. begin
  1820. check_hints(srsym,srsym.symoptions);
  1821. consume(_ID);
  1822. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1823. end
  1824. else
  1825. begin
  1826. Message1(sym_e_id_no_member,orgpattern);
  1827. p1.destroy;
  1828. p1:=cerrornode.create;
  1829. { try to clean up }
  1830. consume(_ID);
  1831. end;
  1832. end
  1833. else { Error }
  1834. Consume(_ID);
  1835. end;
  1836. objectdef:
  1837. begin
  1838. if token=_ID then
  1839. begin
  1840. store_static:=allow_only_static;
  1841. allow_only_static:=false;
  1842. classh:=tobjectdef(p1.resulttype.def);
  1843. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1844. allow_only_static:=store_static;
  1845. if assigned(srsym) then
  1846. begin
  1847. check_hints(srsym,srsym.symoptions);
  1848. consume(_ID);
  1849. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1850. end
  1851. else
  1852. begin
  1853. Message1(sym_e_id_no_member,orgpattern);
  1854. p1.destroy;
  1855. p1:=cerrornode.create;
  1856. { try to clean up }
  1857. consume(_ID);
  1858. end;
  1859. end
  1860. else { Error }
  1861. Consume(_ID);
  1862. end;
  1863. pointerdef:
  1864. begin
  1865. Message(parser_e_invalid_qualifier);
  1866. if tpointerdef(p1.resulttype.def).pointertype.def.deftype in [recorddef,objectdef,classrefdef] then
  1867. Message(parser_h_maybe_deref_caret_missing);
  1868. end;
  1869. else
  1870. begin
  1871. Message(parser_e_invalid_qualifier);
  1872. p1.destroy;
  1873. p1:=cerrornode.create;
  1874. { Error }
  1875. consume(_ID);
  1876. end;
  1877. end;
  1878. end;
  1879. else
  1880. begin
  1881. { is this a procedure variable ? }
  1882. if assigned(p1.resulttype.def) and
  1883. (p1.resulttype.def.deftype=procvardef) then
  1884. begin
  1885. if assigned(getprocvardef) and
  1886. equal_defs(p1.resulttype.def,getprocvardef) then
  1887. again:=false
  1888. else
  1889. begin
  1890. if try_to_consume(_LKLAMMER) then
  1891. begin
  1892. p2:=parse_paras(false,_RKLAMMER);
  1893. consume(_RKLAMMER);
  1894. p1:=ccallnode.create_procvar(p2,p1);
  1895. { proc():= is never possible }
  1896. if token=_ASSIGNMENT then
  1897. begin
  1898. Message(parser_e_illegal_expression);
  1899. p1.free;
  1900. p1:=cerrornode.create;
  1901. again:=false;
  1902. end;
  1903. end
  1904. else
  1905. again:=false;
  1906. end;
  1907. end
  1908. else
  1909. again:=false;
  1910. end;
  1911. end;
  1912. end; { while again }
  1913. end;
  1914. {---------------------------------------------
  1915. Factor (Main)
  1916. ---------------------------------------------}
  1917. var
  1918. l : longint;
  1919. ic : int64;
  1920. qc : qword;
  1921. {$ifndef cpu64}
  1922. card : cardinal;
  1923. {$endif cpu64}
  1924. oldp1,
  1925. p1 : tnode;
  1926. code : integer;
  1927. again : boolean;
  1928. srsym : tsym;
  1929. srsymtable : tsymtable;
  1930. pd : tprocdef;
  1931. classh : tobjectdef;
  1932. d : bestreal;
  1933. hs,hsorg : string;
  1934. htype : ttype;
  1935. filepos : tfileposinfo;
  1936. begin
  1937. oldp1:=nil;
  1938. p1:=nil;
  1939. filepos:=akttokenpos;
  1940. again:=false;
  1941. if token=_ID then
  1942. begin
  1943. again:=true;
  1944. { Handle references to self }
  1945. if (idtoken=_SELF) and
  1946. not(block_type in [bt_const,bt_type]) and
  1947. assigned(current_procinfo) and
  1948. assigned(current_procinfo.procdef._class) then
  1949. begin
  1950. p1:=load_self_node;
  1951. consume(_ID);
  1952. again:=true;
  1953. end
  1954. else
  1955. factor_read_id(p1,again);
  1956. if again then
  1957. begin
  1958. if (p1<>oldp1) then
  1959. begin
  1960. if assigned(p1) then
  1961. p1.fileinfo:=filepos;
  1962. oldp1:=p1;
  1963. filepos:=akttokenpos;
  1964. end;
  1965. { handle post fix operators }
  1966. postfixoperators(p1,again);
  1967. end;
  1968. end
  1969. else
  1970. case token of
  1971. _RETURN :
  1972. begin
  1973. consume(_RETURN);
  1974. p1 := cexitnode.create(comp_expr(true));
  1975. end;
  1976. _INHERITED :
  1977. begin
  1978. again:=true;
  1979. consume(_INHERITED);
  1980. if assigned(current_procinfo) and
  1981. assigned(current_procinfo.procdef._class) then
  1982. begin
  1983. classh:=current_procinfo.procdef._class.childof;
  1984. { if inherited; only then we need the method with
  1985. the same name }
  1986. if token in endtokens then
  1987. begin
  1988. hs:=current_procinfo.procdef.procsym.name;
  1989. hsorg:=current_procinfo.procdef.procsym.realname;
  1990. anon_inherited:=true;
  1991. { For message methods we need to search using the message
  1992. number or string }
  1993. pd:=tprocsym(current_procinfo.procdef.procsym).first_procdef;
  1994. if (po_msgint in pd.procoptions) then
  1995. searchsym_in_class_by_msgint(classh,pd.messageinf.i,srsym,srsymtable)
  1996. else
  1997. if (po_msgstr in pd.procoptions) then
  1998. searchsym_in_class_by_msgstr(classh,pd.messageinf.str^,srsym,srsymtable)
  1999. else
  2000. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  2001. end
  2002. else
  2003. begin
  2004. hs:=pattern;
  2005. hsorg:=orgpattern;
  2006. consume(_ID);
  2007. anon_inherited:=false;
  2008. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  2009. end;
  2010. if assigned(srsym) then
  2011. begin
  2012. check_hints(srsym,srsym.symoptions);
  2013. { load the procdef from the inherited class and
  2014. not from self }
  2015. if srsym.typ in [procsym,propertysym] then
  2016. begin
  2017. if (srsym.typ = procsym) then
  2018. begin
  2019. htype.setdef(classh);
  2020. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2021. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2022. htype.setdef(tclassrefdef.create(htype));
  2023. p1:=ctypenode.create(htype);
  2024. end;
  2025. end
  2026. else
  2027. begin
  2028. Message(parser_e_methode_id_expected);
  2029. p1:=cerrornode.create;
  2030. end;
  2031. do_member_read(classh,getaddr,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
  2032. end
  2033. else
  2034. begin
  2035. if anon_inherited then
  2036. begin
  2037. { For message methods we need to call DefaultHandler }
  2038. if (po_msgint in pd.procoptions) or
  2039. (po_msgstr in pd.procoptions) then
  2040. begin
  2041. searchsym_in_class(classh,classh,'DEFAULTHANDLER',srsym,srsymtable);
  2042. if not assigned(srsym) or
  2043. (srsym.typ<>procsym) then
  2044. internalerror(200303171);
  2045. p1:=nil;
  2046. do_proc_call(srsym,srsym.owner,classh,false,again,p1,[]);
  2047. end
  2048. else
  2049. begin
  2050. { we need to ignore the inherited; }
  2051. p1:=cnothingnode.create;
  2052. end;
  2053. end
  2054. else
  2055. begin
  2056. Message1(sym_e_id_no_member,hsorg);
  2057. p1:=cerrornode.create;
  2058. end;
  2059. again:=false;
  2060. end;
  2061. { turn auto inheriting off }
  2062. anon_inherited:=false;
  2063. end
  2064. else
  2065. begin
  2066. Message(parser_e_generic_methods_only_in_methods);
  2067. again:=false;
  2068. p1:=cerrornode.create;
  2069. end;
  2070. postfixoperators(p1,again);
  2071. end;
  2072. _INTCONST :
  2073. begin
  2074. {$ifdef cpu64}
  2075. { when already running under 64bit must read int64 constant, because reading
  2076. cardinal first will also succeed (code=0) for values > maxcardinal, because
  2077. range checking is off by default (PFV) }
  2078. val(pattern,ic,code);
  2079. if code=0 then
  2080. begin
  2081. consume(_INTCONST);
  2082. int_to_type(ic,htype);
  2083. p1:=cordconstnode.create(ic,htype,true);
  2084. end
  2085. else
  2086. begin
  2087. { try qword next }
  2088. val(pattern,qc,code);
  2089. if code=0 then
  2090. begin
  2091. consume(_INTCONST);
  2092. htype:=u64inttype;
  2093. p1:=cordconstnode.create(qc,htype,true);
  2094. end;
  2095. end;
  2096. {$else}
  2097. { try cardinal first }
  2098. val(pattern,card,code);
  2099. if code=0 then
  2100. begin
  2101. consume(_INTCONST);
  2102. int_to_type(card,htype);
  2103. p1:=cordconstnode.create(card,htype,true);
  2104. end
  2105. else
  2106. begin
  2107. { then longint }
  2108. val(pattern,l,code);
  2109. if code = 0 then
  2110. begin
  2111. consume(_INTCONST);
  2112. int_to_type(l,htype);
  2113. p1:=cordconstnode.create(l,htype,true);
  2114. end
  2115. else
  2116. begin
  2117. { then int64 }
  2118. val(pattern,ic,code);
  2119. if code=0 then
  2120. begin
  2121. consume(_INTCONST);
  2122. int_to_type(ic,htype);
  2123. p1:=cordconstnode.create(ic,htype,true);
  2124. end
  2125. else
  2126. begin
  2127. { try qword next }
  2128. val(pattern,qc,code);
  2129. if code=0 then
  2130. begin
  2131. consume(_INTCONST);
  2132. htype:=u64inttype;
  2133. p1:=cordconstnode.create(tconstexprint(qc),htype,true);
  2134. end;
  2135. end;
  2136. end;
  2137. end;
  2138. {$endif}
  2139. if code<>0 then
  2140. begin
  2141. { finally float }
  2142. val(pattern,d,code);
  2143. if code<>0 then
  2144. begin
  2145. Message(parser_e_invalid_integer);
  2146. consume(_INTCONST);
  2147. l:=1;
  2148. p1:=cordconstnode.create(l,sinttype,true);
  2149. end
  2150. else
  2151. begin
  2152. consume(_INTCONST);
  2153. p1:=crealconstnode.create(d,pbestrealtype^);
  2154. end;
  2155. end;
  2156. end;
  2157. _REALNUMBER :
  2158. begin
  2159. val(pattern,d,code);
  2160. if code<>0 then
  2161. begin
  2162. Message(parser_e_error_in_real);
  2163. d:=1.0;
  2164. end;
  2165. consume(_REALNUMBER);
  2166. p1:=crealconstnode.create(d,pbestrealtype^);
  2167. end;
  2168. _STRING :
  2169. begin
  2170. string_dec(htype);
  2171. { STRING can be also a type cast }
  2172. if try_to_consume(_LKLAMMER) then
  2173. begin
  2174. p1:=comp_expr(true);
  2175. consume(_RKLAMMER);
  2176. p1:=ctypeconvnode.create_explicit(p1,htype);
  2177. { handle postfix operators here e.g. string(a)[10] }
  2178. again:=true;
  2179. postfixoperators(p1,again);
  2180. end
  2181. else
  2182. p1:=ctypenode.create(htype);
  2183. end;
  2184. _FILE :
  2185. begin
  2186. htype:=cfiletype;
  2187. consume(_FILE);
  2188. { FILE can be also a type cast }
  2189. if try_to_consume(_LKLAMMER) then
  2190. begin
  2191. p1:=comp_expr(true);
  2192. consume(_RKLAMMER);
  2193. p1:=ctypeconvnode.create_explicit(p1,htype);
  2194. { handle postfix operators here e.g. string(a)[10] }
  2195. again:=true;
  2196. postfixoperators(p1,again);
  2197. end
  2198. else
  2199. begin
  2200. p1:=ctypenode.create(htype);
  2201. end;
  2202. end;
  2203. _CSTRING :
  2204. begin
  2205. p1:=cstringconstnode.createstr(pattern);
  2206. consume(_CSTRING);
  2207. end;
  2208. _CCHAR :
  2209. begin
  2210. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  2211. consume(_CCHAR);
  2212. end;
  2213. _CWSTRING:
  2214. begin
  2215. p1:=cstringconstnode.createwstr(patternw);
  2216. consume(_CWSTRING);
  2217. end;
  2218. _CWCHAR:
  2219. begin
  2220. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  2221. consume(_CWCHAR);
  2222. end;
  2223. _KLAMMERAFFE :
  2224. begin
  2225. consume(_KLAMMERAFFE);
  2226. got_addrn:=true;
  2227. { support both @<x> and @(<x>) }
  2228. if try_to_consume(_LKLAMMER) then
  2229. begin
  2230. p1:=factor(true);
  2231. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2232. begin
  2233. again:=true;
  2234. postfixoperators(p1,again);
  2235. end;
  2236. consume(_RKLAMMER);
  2237. end
  2238. else
  2239. p1:=factor(true);
  2240. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2241. begin
  2242. again:=true;
  2243. postfixoperators(p1,again);
  2244. end;
  2245. got_addrn:=false;
  2246. p1:=caddrnode.create(p1);
  2247. if cs_typed_addresses in aktlocalswitches then
  2248. include(p1.flags,nf_typedaddr);
  2249. { Store the procvar that we are expecting, the
  2250. addrn will use the information to find the correct
  2251. procdef or it will return an error }
  2252. if assigned(getprocvardef) and
  2253. (taddrnode(p1).left.nodetype = loadn) then
  2254. taddrnode(p1).getprocvardef:=getprocvardef;
  2255. end;
  2256. _LKLAMMER :
  2257. begin
  2258. consume(_LKLAMMER);
  2259. p1:=comp_expr(true);
  2260. consume(_RKLAMMER);
  2261. { it's not a good solution }
  2262. { but (a+b)^ makes some problems }
  2263. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2264. begin
  2265. again:=true;
  2266. postfixoperators(p1,again);
  2267. end;
  2268. end;
  2269. _LECKKLAMMER :
  2270. begin
  2271. consume(_LECKKLAMMER);
  2272. p1:=factor_read_set;
  2273. consume(_RECKKLAMMER);
  2274. end;
  2275. _PLUS :
  2276. begin
  2277. consume(_PLUS);
  2278. p1:=factor(false);
  2279. { we must generate a new node to do 0+<p1> otherwise the + will
  2280. not be checked }
  2281. p1:=caddnode.create(addn,genintconstnode(0),p1);
  2282. end;
  2283. _MINUS :
  2284. begin
  2285. consume(_MINUS);
  2286. if (token = _INTCONST) then
  2287. begin
  2288. { ugly hack, but necessary to be able to parse }
  2289. { -9223372036854775808 as int64 (JM) }
  2290. pattern := '-'+pattern;
  2291. p1:=sub_expr(oppower,false);
  2292. { -1 ** 4 should be - (1 ** 4) and not
  2293. (-1) ** 4
  2294. This was the reason of tw0869.pp test failure PM }
  2295. if p1.nodetype=starstarn then
  2296. begin
  2297. if tbinarynode(p1).left.nodetype=ordconstn then
  2298. begin
  2299. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  2300. p1:=cunaryminusnode.create(p1);
  2301. end
  2302. else if tbinarynode(p1).left.nodetype=realconstn then
  2303. begin
  2304. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  2305. p1:=cunaryminusnode.create(p1);
  2306. end
  2307. else
  2308. internalerror(20021029);
  2309. end;
  2310. end
  2311. else
  2312. begin
  2313. p1:=sub_expr(oppower,false);
  2314. p1:=cunaryminusnode.create(p1);
  2315. end;
  2316. end;
  2317. _OP_NOT :
  2318. begin
  2319. consume(_OP_NOT);
  2320. p1:=factor(false);
  2321. p1:=cnotnode.create(p1);
  2322. end;
  2323. _TRUE :
  2324. begin
  2325. consume(_TRUE);
  2326. p1:=cordconstnode.create(1,booltype,false);
  2327. end;
  2328. _FALSE :
  2329. begin
  2330. consume(_FALSE);
  2331. p1:=cordconstnode.create(0,booltype,false);
  2332. end;
  2333. _NIL :
  2334. begin
  2335. consume(_NIL);
  2336. p1:=cnilnode.create;
  2337. { It's really ugly code nil^, but delphi allows it }
  2338. if token in [_CARET] then
  2339. begin
  2340. again:=true;
  2341. postfixoperators(p1,again);
  2342. end;
  2343. end;
  2344. else
  2345. begin
  2346. Message(parser_e_illegal_expression);
  2347. p1:=cerrornode.create;
  2348. { recover }
  2349. consume(token);
  2350. end;
  2351. end;
  2352. { generate error node if no node is created }
  2353. if not assigned(p1) then
  2354. begin
  2355. {$ifdef EXTDEBUG}
  2356. Comment(V_Warning,'factor: p1=nil');
  2357. {$endif}
  2358. p1:=cerrornode.create;
  2359. end;
  2360. { get the resulttype for the node }
  2361. if (not assigned(p1.resulttype.def)) then
  2362. do_resulttypepass(p1);
  2363. if assigned(p1) and
  2364. (p1<>oldp1) then
  2365. p1.fileinfo:=filepos;
  2366. factor:=p1;
  2367. end;
  2368. {$ifdef fpc}
  2369. {$maxfpuregisters default}
  2370. {$endif fpc}
  2371. {****************************************************************************
  2372. Sub_Expr
  2373. ****************************************************************************}
  2374. const
  2375. { Warning these stay be ordered !! }
  2376. operator_levels:array[Toperator_precedence] of set of Ttoken=
  2377. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN],
  2378. [_PLUS,_MINUS,_OP_OR,_PIPE,_OP_XOR],
  2379. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2380. _OP_AS,_OP_IS,_OP_AND,_AMPERSAND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2381. [_STARSTAR] );
  2382. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;
  2383. {Reads a subexpression while the operators are of the current precedence
  2384. level, or any higher level. Replaces the old term, simpl_expr and
  2385. simpl2_expr.}
  2386. var
  2387. p1,p2 : tnode;
  2388. oldt : Ttoken;
  2389. filepos : tfileposinfo;
  2390. begin
  2391. if pred_level=highest_precedence then
  2392. p1:=factor(false)
  2393. else
  2394. p1:=sub_expr(succ(pred_level),true);
  2395. repeat
  2396. if (token in operator_levels[pred_level]) and
  2397. ((token<>_EQUAL) or accept_equal) then
  2398. begin
  2399. oldt:=token;
  2400. filepos:=akttokenpos;
  2401. consume(token);
  2402. if pred_level=highest_precedence then
  2403. p2:=factor(false)
  2404. else
  2405. p2:=sub_expr(succ(pred_level),true);
  2406. case oldt of
  2407. _PLUS :
  2408. p1:=caddnode.create(addn,p1,p2);
  2409. _MINUS :
  2410. p1:=caddnode.create(subn,p1,p2);
  2411. _STAR :
  2412. p1:=caddnode.create(muln,p1,p2);
  2413. _SLASH :
  2414. p1:=caddnode.create(slashn,p1,p2);
  2415. _EQUAL :
  2416. p1:=caddnode.create(equaln,p1,p2);
  2417. _GT :
  2418. p1:=caddnode.create(gtn,p1,p2);
  2419. _LT :
  2420. p1:=caddnode.create(ltn,p1,p2);
  2421. _GTE :
  2422. p1:=caddnode.create(gten,p1,p2);
  2423. _LTE :
  2424. p1:=caddnode.create(lten,p1,p2);
  2425. _SYMDIF :
  2426. p1:=caddnode.create(symdifn,p1,p2);
  2427. _STARSTAR :
  2428. p1:=caddnode.create(starstarn,p1,p2);
  2429. _OP_AS :
  2430. p1:=casnode.create(p1,p2);
  2431. _OP_IN :
  2432. p1:=cinnode.create(p1,p2);
  2433. _OP_IS :
  2434. p1:=cisnode.create(p1,p2);
  2435. _OP_OR,
  2436. _PIPE {macpas only} :
  2437. begin
  2438. p1:=caddnode.create(orn,p1,p2);
  2439. if (oldt = _PIPE) then
  2440. include(p1.flags,nf_short_bool);
  2441. end;
  2442. _OP_AND,
  2443. _AMPERSAND {macpas only} :
  2444. begin
  2445. p1:=caddnode.create(andn,p1,p2);
  2446. if (oldt = _AMPERSAND) then
  2447. include(p1.flags,nf_short_bool);
  2448. end;
  2449. _OP_DIV :
  2450. p1:=cmoddivnode.create(divn,p1,p2);
  2451. _OP_NOT :
  2452. p1:=cnotnode.create(p1);
  2453. _OP_MOD :
  2454. p1:=cmoddivnode.create(modn,p1,p2);
  2455. _OP_SHL :
  2456. p1:=cshlshrnode.create(shln,p1,p2);
  2457. _OP_SHR :
  2458. p1:=cshlshrnode.create(shrn,p1,p2);
  2459. _OP_XOR :
  2460. p1:=caddnode.create(xorn,p1,p2);
  2461. _ASSIGNMENT :
  2462. p1:=cassignmentnode.create(p1,p2);
  2463. _CARET :
  2464. p1:=caddnode.create(caretn,p1,p2);
  2465. _UNEQUAL :
  2466. p1:=caddnode.create(unequaln,p1,p2);
  2467. end;
  2468. p1.fileinfo:=filepos;
  2469. end
  2470. else
  2471. break;
  2472. until false;
  2473. sub_expr:=p1;
  2474. end;
  2475. function comp_expr(accept_equal : boolean):tnode;
  2476. var
  2477. oldafterassignment : boolean;
  2478. p1 : tnode;
  2479. begin
  2480. oldafterassignment:=afterassignment;
  2481. afterassignment:=true;
  2482. p1:=sub_expr(opcompare,accept_equal);
  2483. { get the resulttype for this expression }
  2484. if not assigned(p1.resulttype.def) then
  2485. do_resulttypepass(p1);
  2486. afterassignment:=oldafterassignment;
  2487. comp_expr:=p1;
  2488. end;
  2489. function expr : tnode;
  2490. var
  2491. p1,p2 : tnode;
  2492. oldafterassignment : boolean;
  2493. oldp1 : tnode;
  2494. filepos : tfileposinfo;
  2495. begin
  2496. oldafterassignment:=afterassignment;
  2497. p1:=sub_expr(opcompare,true);
  2498. { get the resulttype for this expression }
  2499. if not assigned(p1.resulttype.def) then
  2500. do_resulttypepass(p1);
  2501. filepos:=akttokenpos;
  2502. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  2503. afterassignment:=true;
  2504. oldp1:=p1;
  2505. case token of
  2506. _POINTPOINT :
  2507. begin
  2508. consume(_POINTPOINT);
  2509. p2:=sub_expr(opcompare,true);
  2510. p1:=crangenode.create(p1,p2);
  2511. end;
  2512. _ASSIGNMENT :
  2513. begin
  2514. consume(_ASSIGNMENT);
  2515. if (p1.resulttype.def.deftype=procvardef) then
  2516. getprocvardef:=tprocvardef(p1.resulttype.def);
  2517. p2:=sub_expr(opcompare,true);
  2518. if assigned(getprocvardef) then
  2519. handle_procvar(getprocvardef,p2);
  2520. getprocvardef:=nil;
  2521. p1:=cassignmentnode.create(p1,p2);
  2522. end;
  2523. _PLUSASN :
  2524. begin
  2525. consume(_PLUSASN);
  2526. p2:=sub_expr(opcompare,true);
  2527. p1:=gen_c_style_operator(addn,p1,p2);
  2528. end;
  2529. _MINUSASN :
  2530. begin
  2531. consume(_MINUSASN);
  2532. p2:=sub_expr(opcompare,true);
  2533. p1:=gen_c_style_operator(subn,p1,p2);
  2534. end;
  2535. _STARASN :
  2536. begin
  2537. consume(_STARASN );
  2538. p2:=sub_expr(opcompare,true);
  2539. p1:=gen_c_style_operator(muln,p1,p2);
  2540. end;
  2541. _SLASHASN :
  2542. begin
  2543. consume(_SLASHASN );
  2544. p2:=sub_expr(opcompare,true);
  2545. p1:=gen_c_style_operator(slashn,p1,p2);
  2546. end;
  2547. end;
  2548. { get the resulttype for this expression }
  2549. if not assigned(p1.resulttype.def) then
  2550. do_resulttypepass(p1);
  2551. afterassignment:=oldafterassignment;
  2552. if p1<>oldp1 then
  2553. p1.fileinfo:=filepos;
  2554. expr:=p1;
  2555. end;
  2556. function get_intconst:TConstExprInt;
  2557. {Reads an expression, tries to evalute it and check if it is an integer
  2558. constant. Then the constant is returned.}
  2559. var
  2560. p:tnode;
  2561. begin
  2562. result:=0;
  2563. p:=comp_expr(true);
  2564. if not codegenerror then
  2565. begin
  2566. if (p.nodetype<>ordconstn) or
  2567. not(is_integer(p.resulttype.def)) then
  2568. Message(parser_e_illegal_expression)
  2569. else
  2570. result:=tordconstnode(p).value;
  2571. end;
  2572. p.free;
  2573. end;
  2574. function get_stringconst:string;
  2575. {Reads an expression, tries to evaluate it and checks if it is a string
  2576. constant. Then the constant is returned.}
  2577. var
  2578. p:tnode;
  2579. begin
  2580. get_stringconst:='';
  2581. p:=comp_expr(true);
  2582. if p.nodetype<>stringconstn then
  2583. begin
  2584. if (p.nodetype=ordconstn) and is_char(p.resulttype.def) then
  2585. get_stringconst:=char(tordconstnode(p).value)
  2586. else
  2587. Message(parser_e_illegal_expression);
  2588. end
  2589. else
  2590. get_stringconst:=strpas(tstringconstnode(p).value_str);
  2591. p.free;
  2592. end;
  2593. end.