pexpr.pas 99 KB

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