pexpr.pas 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Does parsing of expression for Free Pascal
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pexpr;
  19. interface
  20. uses symtable,tree;
  21. { reads a whole expression }
  22. function expr : ptree;
  23. { reads an expression without assignements and .. }
  24. function comp_expr(accept_equal : boolean):Ptree;
  25. { reads a single factor }
  26. function factor(getaddr : boolean) : ptree;
  27. { the ID token has to be consumed before calling this function }
  28. procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : ptree;
  29. var pd : pdef;var again : boolean);
  30. function get_intconst:longint;
  31. function get_stringconst:string;
  32. implementation
  33. uses
  34. globtype,systems,tokens,
  35. cobjects,globals,scanner,
  36. symconst,aasm,
  37. {$ifdef newcg}
  38. cgbase,
  39. {$else}
  40. hcodegen,
  41. {$endif}
  42. types,verbose,strings,
  43. {$ifndef newcg}
  44. tccal,
  45. {$endif newcg}
  46. pass_1,
  47. { parser specific stuff }
  48. pbase,ptype,
  49. { processor specific stuff }
  50. cpubase,cpuinfo;
  51. const
  52. allow_type : boolean = true;
  53. got_addrn : boolean = false;
  54. function parse_paras(__colon,in_prop_paras : boolean) : ptree;
  55. var
  56. p1,p2 : ptree;
  57. end_of_paras : ttoken;
  58. begin
  59. if in_prop_paras then
  60. end_of_paras:=_RECKKLAMMER
  61. else
  62. end_of_paras:=_RKLAMMER;
  63. if token=end_of_paras then
  64. begin
  65. parse_paras:=nil;
  66. exit;
  67. end;
  68. p2:=nil;
  69. inc(parsing_para_level);
  70. while true do
  71. begin
  72. p1:=comp_expr(true);
  73. p2:=gencallparanode(p1,p2);
  74. { it's for the str(l:5,s); }
  75. if __colon and (token=_COLON) then
  76. begin
  77. consume(_COLON);
  78. p1:=comp_expr(true);
  79. p2:=gencallparanode(p1,p2);
  80. p2^.is_colon_para:=true;
  81. if token=_COLON then
  82. begin
  83. consume(_COLON);
  84. p1:=comp_expr(true);
  85. p2:=gencallparanode(p1,p2);
  86. p2^.is_colon_para:=true;
  87. end
  88. end;
  89. if token=_COMMA then
  90. consume(_COMMA)
  91. else
  92. break;
  93. end;
  94. dec(parsing_para_level);
  95. parse_paras:=p2;
  96. end;
  97. procedure check_tp_procvar(var p : ptree);
  98. var
  99. p1 : ptree;
  100. begin
  101. if (m_tp_procvar in aktmodeswitches) and
  102. (not got_addrn) and
  103. (not in_args) and
  104. (p^.treetype=loadn) then
  105. begin
  106. { support if procvar then for tp7 and many other expression like this }
  107. do_firstpass(p);
  108. set_varstate(p,false);
  109. { reset varstateset to maybe set used state later web bug769 PM }
  110. p^.varstateset:=false;
  111. if not(getprocvar) and (p^.resulttype^.deftype=procvardef) then
  112. begin
  113. p1:=gencallnode(nil,nil);
  114. p1^.right:=p;
  115. p1^.resulttype:=pprocvardef(p^.resulttype)^.rettype.def;
  116. firstpass(p1);
  117. p:=p1;
  118. end;
  119. end;
  120. end;
  121. function statement_syssym(l : longint;var pd : pdef) : ptree;
  122. var
  123. p1,p2,paras : ptree;
  124. prev_in_args : boolean;
  125. begin
  126. prev_in_args:=in_args;
  127. case l of
  128. in_ord_x :
  129. begin
  130. consume(_LKLAMMER);
  131. in_args:=true;
  132. p1:=comp_expr(true);
  133. consume(_RKLAMMER);
  134. do_firstpass(p1);
  135. p1:=geninlinenode(in_ord_x,false,p1);
  136. do_firstpass(p1);
  137. statement_syssym := p1;
  138. pd:=p1^.resulttype;
  139. end;
  140. in_break :
  141. begin
  142. statement_syssym:=genzeronode(breakn);
  143. pd:=voiddef;
  144. end;
  145. in_continue :
  146. begin
  147. statement_syssym:=genzeronode(continuen);
  148. pd:=voiddef;
  149. end;
  150. in_typeof_x :
  151. begin
  152. consume(_LKLAMMER);
  153. in_args:=true;
  154. {allow_type:=true;}
  155. p1:=comp_expr(true);
  156. {allow_type:=false;}
  157. consume(_RKLAMMER);
  158. pd:=voidpointerdef;
  159. if p1^.treetype=typen then
  160. begin
  161. if (p1^.typenodetype=nil) then
  162. begin
  163. Message(type_e_mismatch);
  164. statement_syssym:=genzeronode(errorn);
  165. end
  166. else
  167. if p1^.typenodetype^.deftype=objectdef then
  168. begin
  169. { we can use resulttype in pass_2 (PM) }
  170. p1^.resulttype:=p1^.typenodetype;
  171. statement_syssym:=geninlinenode(in_typeof_x,false,p1);
  172. end
  173. else
  174. begin
  175. Message(type_e_mismatch);
  176. disposetree(p1);
  177. statement_syssym:=genzeronode(errorn);
  178. end;
  179. end
  180. else { not a type node }
  181. begin
  182. do_firstpass(p1);
  183. set_varstate(p1,false);
  184. if (p1^.resulttype=nil) then
  185. begin
  186. Message(type_e_mismatch);
  187. disposetree(p1);
  188. statement_syssym:=genzeronode(errorn)
  189. end
  190. else
  191. if p1^.resulttype^.deftype=objectdef then
  192. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  193. else
  194. begin
  195. Message(type_e_mismatch);
  196. statement_syssym:=genzeronode(errorn);
  197. disposetree(p1);
  198. end;
  199. end;
  200. end;
  201. in_sizeof_x :
  202. begin
  203. consume(_LKLAMMER);
  204. in_args:=true;
  205. {allow_type:=true;}
  206. p1:=comp_expr(true);
  207. {allow_type:=false; }
  208. consume(_RKLAMMER);
  209. pd:=s32bitdef;
  210. if p1^.treetype=typen then
  211. begin
  212. statement_syssym:=genordinalconstnode(p1^.typenodetype^.size,pd);
  213. { p1 not needed !}
  214. disposetree(p1);
  215. end
  216. else
  217. begin
  218. do_firstpass(p1);
  219. if ((p1^.resulttype^.deftype=objectdef) and
  220. (oo_has_constructor in pobjectdef(p1^.resulttype)^.objectoptions)) or
  221. is_open_array(p1^.resulttype) or
  222. is_open_string(p1^.resulttype) then
  223. statement_syssym:=geninlinenode(in_sizeof_x,false,p1)
  224. else
  225. begin
  226. statement_syssym:=genordinalconstnode(p1^.resulttype^.size,pd);
  227. { p1 not needed !}
  228. disposetree(p1);
  229. end;
  230. end;
  231. end;
  232. in_assigned_x :
  233. begin
  234. consume(_LKLAMMER);
  235. in_args:=true;
  236. p1:=comp_expr(true);
  237. do_firstpass(p1);
  238. if not codegenerror then
  239. begin
  240. case p1^.resulttype^.deftype of
  241. pointerdef,
  242. procvardef,
  243. classrefdef : ;
  244. objectdef :
  245. if not(pobjectdef(p1^.resulttype)^.is_class) then
  246. Message(parser_e_illegal_parameter_list);
  247. else
  248. Message(parser_e_illegal_parameter_list);
  249. end;
  250. end;
  251. p2:=gencallparanode(p1,nil);
  252. p2:=geninlinenode(in_assigned_x,false,p2);
  253. consume(_RKLAMMER);
  254. pd:=booldef;
  255. statement_syssym:=p2;
  256. end;
  257. in_ofs_x :
  258. begin
  259. consume(_LKLAMMER);
  260. in_args:=true;
  261. p1:=comp_expr(true);
  262. p1:=gensinglenode(addrn,p1);
  263. do_firstpass(p1);
  264. { Ofs() returns a longint, not a pointer }
  265. p1^.resulttype:=u32bitdef;
  266. pd:=p1^.resulttype;
  267. consume(_RKLAMMER);
  268. statement_syssym:=p1;
  269. end;
  270. in_addr_x :
  271. begin
  272. consume(_LKLAMMER);
  273. in_args:=true;
  274. p1:=comp_expr(true);
  275. p1:=gensinglenode(addrn,p1);
  276. do_firstpass(p1);
  277. pd:=p1^.resulttype;
  278. consume(_RKLAMMER);
  279. statement_syssym:=p1;
  280. end;
  281. in_seg_x :
  282. begin
  283. consume(_LKLAMMER);
  284. in_args:=true;
  285. p1:=comp_expr(true);
  286. do_firstpass(p1);
  287. set_varstate(p1,false);
  288. if p1^.location.loc<>LOC_REFERENCE then
  289. Message(cg_e_illegal_expression);
  290. p1:=genordinalconstnode(0,s32bitdef);
  291. pd:=s32bitdef;
  292. consume(_RKLAMMER);
  293. statement_syssym:=p1;
  294. end;
  295. in_high_x,
  296. in_low_x :
  297. begin
  298. consume(_LKLAMMER);
  299. in_args:=true;
  300. {allow_type:=true;}
  301. p1:=comp_expr(true);
  302. {allow_type:=false;}
  303. do_firstpass(p1);
  304. if p1^.treetype=typen then
  305. p1^.resulttype:=p1^.typenodetype;
  306. p2:=geninlinenode(l,false,p1);
  307. consume(_RKLAMMER);
  308. pd:=s32bitdef;
  309. statement_syssym:=p2;
  310. end;
  311. in_succ_x,
  312. in_pred_x :
  313. begin
  314. consume(_LKLAMMER);
  315. in_args:=true;
  316. p1:=comp_expr(true);
  317. do_firstpass(p1);
  318. p2:=geninlinenode(l,false,p1);
  319. consume(_RKLAMMER);
  320. pd:=p1^.resulttype;
  321. statement_syssym:=p2;
  322. end;
  323. in_inc_x,
  324. in_dec_x :
  325. begin
  326. consume(_LKLAMMER);
  327. in_args:=true;
  328. p1:=comp_expr(true);
  329. if token=_COMMA then
  330. begin
  331. consume(_COMMA);
  332. p2:=gencallparanode(comp_expr(true),nil);
  333. end
  334. else
  335. p2:=nil;
  336. p2:=gencallparanode(p1,p2);
  337. statement_syssym:=geninlinenode(l,false,p2);
  338. consume(_RKLAMMER);
  339. pd:=voiddef;
  340. end;
  341. in_concat_x :
  342. begin
  343. consume(_LKLAMMER);
  344. in_args:=true;
  345. p2:=nil;
  346. while true do
  347. begin
  348. p1:=comp_expr(true);
  349. do_firstpass(p1);
  350. set_varstate(p1,true);
  351. if not((p1^.resulttype^.deftype=stringdef) or
  352. ((p1^.resulttype^.deftype=orddef) and
  353. (porddef(p1^.resulttype)^.typ=uchar))) then
  354. Message(parser_e_illegal_parameter_list);
  355. if p2<>nil then
  356. p2:=gennode(addn,p2,p1)
  357. else
  358. p2:=p1;
  359. if token=_COMMA then
  360. consume(_COMMA)
  361. else
  362. break;
  363. end;
  364. consume(_RKLAMMER);
  365. pd:=cshortstringdef;
  366. statement_syssym:=p2;
  367. end;
  368. in_read_x,
  369. in_readln_x :
  370. begin
  371. if token=_LKLAMMER then
  372. begin
  373. consume(_LKLAMMER);
  374. in_args:=true;
  375. paras:=parse_paras(false,false);
  376. consume(_RKLAMMER);
  377. end
  378. else
  379. paras:=nil;
  380. pd:=voiddef;
  381. p1:=geninlinenode(l,false,paras);
  382. do_firstpass(p1);
  383. statement_syssym := p1;
  384. end;
  385. in_write_x,
  386. in_writeln_x :
  387. begin
  388. if token=_LKLAMMER then
  389. begin
  390. consume(_LKLAMMER);
  391. in_args:=true;
  392. paras:=parse_paras(true,false);
  393. consume(_RKLAMMER);
  394. end
  395. else
  396. paras:=nil;
  397. pd:=voiddef;
  398. p1 := geninlinenode(l,false,paras);
  399. do_firstpass(p1);
  400. statement_syssym := p1;
  401. end;
  402. in_str_x_string :
  403. begin
  404. consume(_LKLAMMER);
  405. in_args:=true;
  406. paras:=parse_paras(true,false);
  407. consume(_RKLAMMER);
  408. p1 := geninlinenode(l,false,paras);
  409. do_firstpass(p1);
  410. statement_syssym := p1;
  411. pd:=voiddef;
  412. end;
  413. in_val_x:
  414. Begin
  415. consume(_LKLAMMER);
  416. in_args := true;
  417. p1:= gencallparanode(comp_expr(true), nil);
  418. consume(_COMMA);
  419. p2 := gencallparanode(comp_expr(true),p1);
  420. if (token = _COMMA) then
  421. Begin
  422. consume(_COMMA);
  423. p2 := gencallparanode(comp_expr(true),p2)
  424. End;
  425. consume(_RKLAMMER);
  426. p2 := geninlinenode(l,false,p2);
  427. do_firstpass(p2);
  428. statement_syssym := p2;
  429. pd := voiddef;
  430. End;
  431. in_include_x_y,
  432. in_exclude_x_y :
  433. begin
  434. consume(_LKLAMMER);
  435. in_args:=true;
  436. p1:=comp_expr(true);
  437. consume(_COMMA);
  438. p2:=comp_expr(true);
  439. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  440. consume(_RKLAMMER);
  441. pd:=voiddef;
  442. end;
  443. in_assert_x_y :
  444. begin
  445. consume(_LKLAMMER);
  446. in_args:=true;
  447. p1:=comp_expr(true);
  448. if token=_COMMA then
  449. begin
  450. consume(_COMMA);
  451. p2:=comp_expr(true);
  452. end
  453. else
  454. begin
  455. { then insert an empty string }
  456. p2:=genstringconstnode('',st_default);
  457. end;
  458. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  459. consume(_RKLAMMER);
  460. pd:=voiddef;
  461. end;
  462. else
  463. internalerror(15);
  464. end;
  465. in_args:=prev_in_args;
  466. end;
  467. { reads the parameter for a subroutine call }
  468. procedure do_proc_call(getaddr : boolean;var again : boolean;var p1:Ptree;var pd:Pdef);
  469. var
  470. prev_in_args : boolean;
  471. prevafterassn : boolean;
  472. begin
  473. prev_in_args:=in_args;
  474. prevafterassn:=afterassignment;
  475. afterassignment:=false;
  476. { want we only determine the address of }
  477. { a subroutine ? }
  478. if not(getaddr) then
  479. begin
  480. if token=_LKLAMMER then
  481. begin
  482. consume(_LKLAMMER);
  483. in_args:=true;
  484. p1^.left:=parse_paras(false,false);
  485. consume(_RKLAMMER);
  486. end
  487. else p1^.left:=nil;
  488. { do firstpass because we need the }
  489. { result type }
  490. do_firstpass(p1);
  491. {set_var_state is handled inside firstcalln }
  492. end
  493. else
  494. begin
  495. { address operator @: }
  496. p1^.left:=nil;
  497. { forget pd }
  498. pd:=nil;
  499. if (p1^.symtableproc^.symtabletype=withsymtable) and
  500. (p1^.symtableproc^.defowner^.deftype=objectdef) then
  501. begin
  502. p1^.methodpointer:=getcopy(pwithsymtable(p1^.symtableproc)^.withrefnode);
  503. end
  504. else if not(assigned(p1^.methodpointer)) then
  505. begin
  506. { we must provide a method pointer, if it isn't given, }
  507. { it is self }
  508. if assigned(procinfo) then
  509. begin
  510. p1^.methodpointer:=genselfnode(procinfo^._class);
  511. p1^.methodpointer^.resulttype:=procinfo^._class;
  512. end
  513. else
  514. begin
  515. p1^.methodpointer:=genselfnode(nil);
  516. p1^.methodpointer^.resulttype:=nil;
  517. end;
  518. end;
  519. { no postfix operators }
  520. again:=false;
  521. end;
  522. pd:=p1^.resulttype;
  523. in_args:=prev_in_args;
  524. afterassignment:=prevafterassn;
  525. end;
  526. procedure handle_procvar(pv : pprocvardef;var p2 : ptree);
  527. procedure doconv(procvar : pprocvardef;var t : ptree);
  528. var
  529. hp : ptree;
  530. begin
  531. hp:=nil;
  532. if (proc_to_procvar_equal(pprocsym(t^.symtableentry)^.definition,procvar)) then
  533. begin
  534. if (po_methodpointer in procvar^.procoptions) then
  535. hp:=genloadmethodcallnode(pprocsym(t^.symtableprocentry),t^.symtable,getcopy(t^.methodpointer))
  536. else
  537. hp:=genloadcallnode(pprocsym(t^.symtableprocentry),t^.symtable);
  538. end;
  539. if assigned(hp) then
  540. begin
  541. disposetree(t);
  542. t:=hp;
  543. end;
  544. end;
  545. begin
  546. if (p2^.treetype=calln) then
  547. doconv(pv,p2)
  548. else
  549. if (p2^.treetype=typeconvn) and
  550. (p2^.left^.treetype=calln) then
  551. doconv(pv,p2^.left);
  552. end;
  553. { the following procedure handles the access to a property symbol }
  554. procedure handle_propertysym(sym : psym;st : psymtable;var p1 : ptree;
  555. var pd : pdef);
  556. var
  557. paras : ptree;
  558. p2 : ptree;
  559. plist : psymlistitem;
  560. begin
  561. paras:=nil;
  562. { property parameters? read them only if the property really }
  563. { has parameters }
  564. if ppo_hasparameters in ppropertysym(sym)^.propoptions then
  565. begin
  566. if token=_LECKKLAMMER then
  567. begin
  568. consume(_LECKKLAMMER);
  569. paras:=parse_paras(false,true);
  570. consume(_RECKKLAMMER);
  571. end;
  572. { indexed property }
  573. if (ppo_indexed in ppropertysym(sym)^.propoptions) then
  574. begin
  575. p2:=genordinalconstnode(ppropertysym(sym)^.index,ppropertysym(sym)^.indextype.def);
  576. paras:=gencallparanode(p2,paras);
  577. end;
  578. end;
  579. { we need only a write property if a := follows }
  580. { if not(afterassignment) and not(in_args) then }
  581. if token=_ASSIGNMENT then
  582. begin
  583. { write property: }
  584. { no result }
  585. pd:=voiddef;
  586. if not ppropertysym(sym)^.writeaccess^.empty then
  587. begin
  588. case ppropertysym(sym)^.writeaccess^.firstsym^.sym^.typ of
  589. procsym :
  590. begin
  591. { generate the method call }
  592. p1:=genmethodcallnode(pprocsym(ppropertysym(sym)^.writeaccess^.firstsym^.sym),st,p1);
  593. { we know the procedure to call, so
  594. force the usage of that procedure }
  595. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.writeaccess^.def);
  596. p1^.left:=paras;
  597. consume(_ASSIGNMENT);
  598. { read the expression }
  599. getprocvar:=ppropertysym(sym)^.proptype.def^.deftype=procvardef;
  600. p2:=comp_expr(true);
  601. if getprocvar then
  602. handle_procvar(pprocvardef(ppropertysym(sym)^.proptype.def),p2);
  603. p1^.left:=gencallparanode(p2,p1^.left);
  604. p1^.isproperty:=true;
  605. getprocvar:=false;
  606. end;
  607. varsym :
  608. begin
  609. if assigned(paras) then
  610. message(parser_e_no_paras_allowed);
  611. { subscribed access? }
  612. plist:=ppropertysym(sym)^.writeaccess^.firstsym;
  613. while assigned(plist) do
  614. begin
  615. if p1=nil then
  616. p1:=genloadnode(pvarsym(plist^.sym),st)
  617. else
  618. p1:=gensubscriptnode(pvarsym(plist^.sym),p1);
  619. plist:=plist^.next;
  620. end;
  621. p1^.isproperty:=true;
  622. consume(_ASSIGNMENT);
  623. { read the expression }
  624. p2:=comp_expr(true);
  625. p1:=gennode(assignn,p1,p2);
  626. end
  627. else
  628. begin
  629. p1:=genzeronode(errorn);
  630. Message(parser_e_no_procedure_to_access_property);
  631. end;
  632. end;
  633. end
  634. else
  635. begin
  636. p1:=genzeronode(errorn);
  637. Message(parser_e_no_procedure_to_access_property);
  638. end;
  639. end
  640. else
  641. begin
  642. { read property: }
  643. pd:=ppropertysym(sym)^.proptype.def;
  644. if not ppropertysym(sym)^.readaccess^.empty then
  645. begin
  646. case ppropertysym(sym)^.readaccess^.firstsym^.sym^.typ of
  647. varsym :
  648. begin
  649. if assigned(paras) then
  650. message(parser_e_no_paras_allowed);
  651. { subscribed access? }
  652. plist:=ppropertysym(sym)^.readaccess^.firstsym;
  653. while assigned(plist) do
  654. begin
  655. if p1=nil then
  656. p1:=genloadnode(pvarsym(plist^.sym),st)
  657. else
  658. p1:=gensubscriptnode(pvarsym(plist^.sym),p1);
  659. plist:=plist^.next;
  660. end;
  661. p1^.isproperty:=true;
  662. end;
  663. procsym :
  664. begin
  665. { generate the method call }
  666. p1:=genmethodcallnode(pprocsym(ppropertysym(sym)^.readaccess^.firstsym^.sym),st,p1);
  667. { we know the procedure to call, so
  668. force the usage of that procedure }
  669. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.readaccess^.def);
  670. { insert paras }
  671. p1^.left:=paras;
  672. p1^.isproperty:=true;
  673. end
  674. else
  675. begin
  676. p1:=genzeronode(errorn);
  677. Message(type_e_mismatch);
  678. end;
  679. end;
  680. end
  681. else
  682. begin
  683. { error, no function to read property }
  684. p1:=genzeronode(errorn);
  685. Message(parser_e_no_procedure_to_access_property);
  686. end;
  687. end;
  688. end;
  689. { the ID token has to be consumed before calling this function }
  690. procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : ptree;
  691. var pd : pdef;var again : boolean);
  692. var
  693. static_name : string;
  694. isclassref : boolean;
  695. begin
  696. if sym=nil then
  697. begin
  698. { pattern is still valid unless
  699. there is another ID just after the ID of sym }
  700. Message1(sym_e_id_no_member,pattern);
  701. disposetree(p1);
  702. p1:=genzeronode(errorn);
  703. { try to clean up }
  704. pd:=generrordef;
  705. again:=false;
  706. end
  707. else
  708. begin
  709. isclassref:=pd^.deftype=classrefdef;
  710. { check protected and private members }
  711. { please leave this code as it is, }
  712. { it has now the same behaviaor as TP/Delphi }
  713. if (sp_private in sym^.symoptions) and
  714. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  715. Message(parser_e_cant_access_private_member);
  716. if (sp_protected in sym^.symoptions) and
  717. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  718. begin
  719. if assigned(aktprocsym^.definition^._class) then
  720. begin
  721. if not aktprocsym^.definition^._class^.is_related(pobjectdef(sym^.owner^.defowner)) then
  722. Message(parser_e_cant_access_protected_member);
  723. end
  724. else
  725. Message(parser_e_cant_access_protected_member);
  726. end;
  727. { we assume, that only procsyms and varsyms are in an object }
  728. { symbol table, for classes, properties are allowed }
  729. case sym^.typ of
  730. procsym:
  731. begin
  732. p1:=genmethodcallnode(pprocsym(sym),srsymtable,p1);
  733. do_proc_call(getaddr or
  734. (getprocvar and
  735. ((block_type=bt_const) or
  736. ((m_tp_procvar in aktmodeswitches) and
  737. proc_to_procvar_equal(pprocsym(sym)^.definition,getprocvardef)
  738. )
  739. )
  740. ),again,p1,pd);
  741. if (block_type=bt_const) and
  742. getprocvar then
  743. handle_procvar(getprocvardef,p1);
  744. { now we know the real method e.g. we can check for a class method }
  745. if isclassref and
  746. assigned(p1^.procdefinition) and
  747. not(po_classmethod in p1^.procdefinition^.procoptions) and
  748. not(p1^.procdefinition^.proctypeoption=potype_constructor) then
  749. Message(parser_e_only_class_methods_via_class_ref);
  750. end;
  751. varsym:
  752. begin
  753. if isclassref then
  754. Message(parser_e_only_class_methods_via_class_ref);
  755. if (sp_static in sym^.symoptions) then
  756. begin
  757. { static_name:=lower(srsymtable^.name^)+'_'+sym^.name;
  758. this is wrong for static field in with symtable (PM) }
  759. static_name:=lower(srsym^.owner^.name^)+'_'+sym^.name;
  760. getsym(static_name,true);
  761. disposetree(p1);
  762. p1:=genloadnode(pvarsym(srsym),srsymtable);
  763. end
  764. else
  765. p1:=gensubscriptnode(pvarsym(sym),p1);
  766. pd:=pvarsym(sym)^.vartype.def;
  767. end;
  768. propertysym:
  769. begin
  770. if isclassref then
  771. Message(parser_e_only_class_methods_via_class_ref);
  772. handle_propertysym(sym,srsymtable,p1,pd);
  773. end;
  774. else internalerror(16);
  775. end;
  776. end;
  777. end;
  778. {****************************************************************************
  779. Factor
  780. ****************************************************************************}
  781. function factor(getaddr : boolean) : ptree;
  782. var
  783. l : longint;
  784. oldp1,
  785. p1,p2,p3 : ptree;
  786. code : integer;
  787. pd,pd2 : pdef;
  788. possible_error,
  789. unit_specific,
  790. again : boolean;
  791. sym : pvarsym;
  792. classh : pobjectdef;
  793. d : bestreal;
  794. static_name : string;
  795. propsym : ppropertysym;
  796. filepos : tfileposinfo;
  797. {---------------------------------------------
  798. Is_func_ret
  799. ---------------------------------------------}
  800. function is_func_ret(sym : psym) : boolean;
  801. var
  802. p : pprocinfo;
  803. storesymtablestack : psymtable;
  804. begin
  805. is_func_ret:=false;
  806. if not assigned(procinfo) or
  807. ((sym^.typ<>funcretsym) and ((procinfo^.flags and pi_operator)=0)) then
  808. exit;
  809. p:=procinfo;
  810. while assigned(p) do
  811. begin
  812. { is this an access to a function result? Accessing _RESULT is
  813. always allowed and funcretn is generated }
  814. if assigned(p^.funcretsym) and
  815. ((pfuncretsym(sym)=p^.resultfuncretsym) or
  816. ((pfuncretsym(sym)=p^.funcretsym) or
  817. ((pvarsym(sym)=opsym) and ((p^.flags and pi_operator)<>0))) and
  818. (p^.returntype.def<>pdef(voiddef)) and
  819. (token<>_LKLAMMER) and
  820. (not ((m_tp in aktmodeswitches) and (afterassignment or in_args)))
  821. ) then
  822. begin
  823. if ((pvarsym(sym)=opsym) and
  824. ((p^.flags and pi_operator)<>0)) then
  825. inc(opsym^.refs);
  826. p1:=genzeronode(funcretn);
  827. pd:=p^.returntype.def;
  828. p1^.funcretprocinfo:=p;
  829. p1^.rettype.def:=pd;
  830. is_func_ret:=true;
  831. if p^.funcret_state=vs_declared then
  832. begin
  833. p^.funcret_state:=vs_declared_and_first_found;
  834. p1^.is_first_funcret:=true;
  835. end;
  836. exit;
  837. end;
  838. p:=p^.parent;
  839. end;
  840. { we must use the function call }
  841. if (sym^.typ=funcretsym) then
  842. begin
  843. storesymtablestack:=symtablestack;
  844. symtablestack:=srsymtable^.next;
  845. getsym(sym^.name,true);
  846. if srsym^.typ<>procsym then
  847. Message(cg_e_illegal_expression);
  848. symtablestack:=storesymtablestack;
  849. end;
  850. end;
  851. {---------------------------------------------
  852. Factor_read_id
  853. ---------------------------------------------}
  854. procedure factor_read_id;
  855. var
  856. pc : pchar;
  857. len : longint;
  858. begin
  859. { allow post fix operators }
  860. again:=true;
  861. begin
  862. if lastsymknown then
  863. begin
  864. srsym:=lastsrsym;
  865. srsymtable:=lastsrsymtable;
  866. lastsymknown:=false;
  867. end
  868. else
  869. getsym(pattern,true);
  870. consume(_ID);
  871. if not is_func_ret(srsym) then
  872. { else it's a normal symbol }
  873. begin
  874. { is it defined like UNIT.SYMBOL ? }
  875. if srsym^.typ=unitsym then
  876. begin
  877. consume(_POINT);
  878. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  879. unit_specific:=true;
  880. consume(_ID);
  881. end
  882. else
  883. unit_specific:=false;
  884. if not assigned(srsym) then
  885. Begin
  886. p1:=genzeronode(errorn);
  887. { try to clean up }
  888. pd:=generrordef;
  889. end
  890. else
  891. Begin
  892. { check semantics of private }
  893. if (srsym^.typ in [propertysym,procsym,varsym]) and
  894. (srsymtable^.symtabletype=objectsymtable) then
  895. begin
  896. if (sp_private in srsym^.symoptions) and
  897. (pobjectdef(srsym^.owner^.defowner)^.owner^.symtabletype=unitsymtable) then
  898. Message(parser_e_cant_access_private_member);
  899. end;
  900. case srsym^.typ of
  901. absolutesym : begin
  902. p1:=genloadnode(pvarsym(srsym),srsymtable);
  903. pd:=pabsolutesym(srsym)^.vartype.def;
  904. end;
  905. varsym : begin
  906. { are we in a class method ? }
  907. if (srsymtable^.symtabletype=objectsymtable) and
  908. assigned(aktprocsym) and
  909. (po_classmethod in aktprocsym^.definition^.procoptions) then
  910. Message(parser_e_only_class_methods);
  911. if (sp_static in srsym^.symoptions) then
  912. begin
  913. static_name:=lower(srsym^.owner^.name^)+'_'+srsym^.name;
  914. getsym(static_name,true);
  915. end;
  916. p1:=genloadnode(pvarsym(srsym),srsymtable);
  917. if pvarsym(srsym)^.varstate=vs_declared then
  918. begin
  919. p1^.is_first := true;
  920. { set special between first loaded until checked in firstpass }
  921. pvarsym(srsym)^.varstate:=vs_declared_and_first_found;
  922. end;
  923. pd:=pvarsym(srsym)^.vartype.def;
  924. end;
  925. typedconstsym : begin
  926. p1:=gentypedconstloadnode(ptypedconstsym(srsym),srsymtable);
  927. pd:=ptypedconstsym(srsym)^.typedconsttype.def;
  928. end;
  929. syssym : p1:=statement_syssym(psyssym(srsym)^.number,pd);
  930. typesym : begin
  931. pd:=ptypesym(srsym)^.restype.def;
  932. if not assigned(pd) then
  933. begin
  934. pd:=generrordef;
  935. again:=false;
  936. end
  937. else
  938. begin
  939. { if we read a type declaration }
  940. { we have to return the type and }
  941. { nothing else }
  942. if block_type=bt_type then
  943. begin
  944. { we don't need sym reference when it's in the
  945. current unit or system unit, because those
  946. units are always loaded (PFV) }
  947. if not(assigned(pd^.owner)) or
  948. (pd^.owner^.unitid=0) or
  949. (pd^.owner^.unitid=1) then
  950. p1:=gentypenode(pd,nil)
  951. else
  952. p1:=gentypenode(pd,ptypesym(srsym));
  953. { here we can also set resulttype !! }
  954. p1^.resulttype:=pd;
  955. pd:=voiddef;
  956. end
  957. else { not type block }
  958. begin
  959. if token=_LKLAMMER then
  960. begin
  961. consume(_LKLAMMER);
  962. p1:=comp_expr(true);
  963. consume(_RKLAMMER);
  964. p1:=gentypeconvnode(p1,pd);
  965. p1^.explizit:=true;
  966. end
  967. else { not LKLAMMER}
  968. if (token=_POINT) and
  969. (pd^.deftype=objectdef) and
  970. not(pobjectdef(pd)^.is_class) then
  971. begin
  972. consume(_POINT);
  973. if assigned(procinfo) and
  974. assigned(procinfo^._class) and
  975. not(getaddr) then
  976. begin
  977. if procinfo^._class^.is_related(pobjectdef(pd)) then
  978. begin
  979. p1:=gentypenode(pd,ptypesym(srsym));
  980. p1^.resulttype:=pd;
  981. { search also in inherited methods }
  982. repeat
  983. srsymtable:=pobjectdef(pd)^.symtable;
  984. sym:=pvarsym(srsymtable^.search(pattern));
  985. if assigned(sym) then
  986. break;
  987. pd:=pobjectdef(pd)^.childof;
  988. until not assigned(pd);
  989. consume(_ID);
  990. do_member_read(false,sym,p1,pd,again);
  991. end
  992. else
  993. begin
  994. Message(parser_e_no_super_class);
  995. pd:=generrordef;
  996. again:=false;
  997. end;
  998. end
  999. else
  1000. begin
  1001. { allows @TObject.Load }
  1002. { also allows static methods and variables }
  1003. p1:=genzeronode(typen);
  1004. p1^.resulttype:=pd;
  1005. { TP allows also @TMenu.Load if Load is only }
  1006. { defined in an anchestor class }
  1007. sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
  1008. if not assigned(sym) then
  1009. Message1(sym_e_id_no_member,pattern)
  1010. else if not(getaddr) and not(sp_static in sym^.symoptions) then
  1011. Message(sym_e_only_static_in_static)
  1012. else
  1013. begin
  1014. consume(_ID);
  1015. do_member_read(getaddr,sym,p1,pd,again);
  1016. end;
  1017. end;
  1018. end
  1019. else
  1020. begin
  1021. { class reference ? }
  1022. if (pd^.deftype=objectdef)
  1023. and pobjectdef(pd)^.is_class then
  1024. begin
  1025. p1:=gentypenode(pd,nil);
  1026. p1^.resulttype:=pd;
  1027. pd:=new(pclassrefdef,init(pd));
  1028. p1:=gensinglenode(loadvmtn,p1);
  1029. p1^.resulttype:=pd;
  1030. end
  1031. else
  1032. begin
  1033. { generate a type node }
  1034. { (for typeof etc) }
  1035. if allow_type then
  1036. begin
  1037. p1:=gentypenode(pd,nil);
  1038. { here we must use typenodetype explicitly !! PM
  1039. p1^.resulttype:=pd; }
  1040. pd:=voiddef;
  1041. end
  1042. else
  1043. Message(parser_e_no_type_not_allowed_here);
  1044. end;
  1045. end;
  1046. end;
  1047. end;
  1048. end;
  1049. enumsym : begin
  1050. p1:=genenumnode(penumsym(srsym));
  1051. pd:=p1^.resulttype;
  1052. end;
  1053. constsym : begin
  1054. case pconstsym(srsym)^.consttyp of
  1055. constint :
  1056. p1:=genordinalconstnode(pconstsym(srsym)^.value,s32bitdef);
  1057. conststring :
  1058. begin
  1059. len:=pconstsym(srsym)^.len;
  1060. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1061. len:=255;
  1062. getmem(pc,len+1);
  1063. move(pchar(pconstsym(srsym)^.value)^,pc^,len);
  1064. pc[len]:=#0;
  1065. p1:=genpcharconstnode(pc,len);
  1066. end;
  1067. constchar :
  1068. p1:=genordinalconstnode(pconstsym(srsym)^.value,cchardef);
  1069. constreal :
  1070. p1:=genrealconstnode(pbestreal(pconstsym(srsym)^.value)^,bestrealdef^);
  1071. constbool :
  1072. p1:=genordinalconstnode(pconstsym(srsym)^.value,booldef);
  1073. constset :
  1074. p1:=gensetconstnode(pconstset(pconstsym(srsym)^.value),
  1075. psetdef(pconstsym(srsym)^.consttype.def));
  1076. constord :
  1077. p1:=genordinalconstnode(pconstsym(srsym)^.value,
  1078. pconstsym(srsym)^.consttype.def);
  1079. constpointer :
  1080. p1:=genpointerconstnode(pconstsym(srsym)^.value,
  1081. pconstsym(srsym)^.consttype.def);
  1082. constnil :
  1083. p1:=genzeronode(niln);
  1084. constresourcestring:
  1085. begin
  1086. p1:=genloadnode(pvarsym(srsym),srsymtable);
  1087. p1^.resulttype:=cansistringdef;
  1088. end;
  1089. end;
  1090. pd:=p1^.resulttype;
  1091. end;
  1092. procsym : begin
  1093. { are we in a class method ? }
  1094. possible_error:=(srsymtable^.symtabletype=objectsymtable) and
  1095. assigned(aktprocsym) and
  1096. (po_classmethod in aktprocsym^.definition^.procoptions);
  1097. p1:=gencallnode(pprocsym(srsym),srsymtable);
  1098. p1^.unit_specific:=unit_specific;
  1099. do_proc_call(getaddr or
  1100. (getprocvar and
  1101. ((block_type=bt_const) or
  1102. ((m_tp_procvar in aktmodeswitches) and
  1103. proc_to_procvar_equal(pprocsym(srsym)^.definition,getprocvardef)
  1104. )
  1105. )
  1106. ),again,p1,pd);
  1107. if (block_type=bt_const) and
  1108. getprocvar then
  1109. handle_procvar(getprocvardef,p1);
  1110. if possible_error and
  1111. not(po_classmethod in p1^.procdefinition^.procoptions) then
  1112. Message(parser_e_only_class_methods);
  1113. end;
  1114. propertysym : begin
  1115. { access to property in a method }
  1116. { are we in a class method ? }
  1117. if (srsymtable^.symtabletype=objectsymtable) and
  1118. assigned(aktprocsym) and
  1119. (po_classmethod in aktprocsym^.definition^.procoptions) then
  1120. Message(parser_e_only_class_methods);
  1121. { no method pointer }
  1122. p1:=nil;
  1123. handle_propertysym(srsym,srsymtable,p1,pd);
  1124. end;
  1125. errorsym : begin
  1126. p1:=genzeronode(errorn);
  1127. p1^.resulttype:=generrordef;
  1128. pd:=generrordef;
  1129. if token=_LKLAMMER then
  1130. begin
  1131. consume(_LKLAMMER);
  1132. parse_paras(false,false);
  1133. consume(_RKLAMMER);
  1134. end;
  1135. end;
  1136. else
  1137. begin
  1138. p1:=genzeronode(errorn);
  1139. pd:=generrordef;
  1140. Message(cg_e_illegal_expression);
  1141. end;
  1142. end; { end case }
  1143. end;
  1144. end;
  1145. end;
  1146. end;
  1147. {---------------------------------------------
  1148. Factor_Read_Set
  1149. ---------------------------------------------}
  1150. { Read a set between [] }
  1151. function factor_read_set:ptree;
  1152. var
  1153. p1,
  1154. lastp,
  1155. buildp : ptree;
  1156. begin
  1157. buildp:=nil;
  1158. { be sure that a least one arrayconstructn is used, also for an
  1159. empty [] }
  1160. if token=_RECKKLAMMER then
  1161. buildp:=gennode(arrayconstructn,nil,buildp)
  1162. else
  1163. begin
  1164. while true do
  1165. begin
  1166. p1:=comp_expr(true);
  1167. if token=_POINTPOINT then
  1168. begin
  1169. consume(_POINTPOINT);
  1170. p2:=comp_expr(true);
  1171. p1:=gennode(arrayconstructrangen,p1,p2);
  1172. end;
  1173. { insert at the end of the tree, to get the correct order }
  1174. if not assigned(buildp) then
  1175. begin
  1176. buildp:=gennode(arrayconstructn,p1,nil);
  1177. lastp:=buildp;
  1178. end
  1179. else
  1180. begin
  1181. lastp^.right:=gennode(arrayconstructn,p1,nil);
  1182. lastp:=lastp^.right;
  1183. end;
  1184. { there could be more elements }
  1185. if token=_COMMA then
  1186. consume(_COMMA)
  1187. else
  1188. break;
  1189. end;
  1190. end;
  1191. factor_read_set:=buildp;
  1192. end;
  1193. {---------------------------------------------
  1194. Helpers
  1195. ---------------------------------------------}
  1196. procedure check_tokenpos;
  1197. begin
  1198. if (p1<>oldp1) then
  1199. begin
  1200. if assigned(p1) then
  1201. set_tree_filepos(p1,filepos);
  1202. oldp1:=p1;
  1203. filepos:=tokenpos;
  1204. end;
  1205. end;
  1206. {---------------------------------------------
  1207. PostFixOperators
  1208. ---------------------------------------------}
  1209. procedure postfixoperators;
  1210. var
  1211. store_static : boolean;
  1212. { p1 and p2 must contain valid value_str }
  1213. begin
  1214. check_tokenpos;
  1215. while again do
  1216. begin
  1217. { prevent crashes with unknown types }
  1218. if not assigned(pd) then
  1219. begin
  1220. { try to recover }
  1221. repeat
  1222. case token of
  1223. _CARET:
  1224. consume(_CARET);
  1225. _POINT:
  1226. begin
  1227. consume(_POINT);
  1228. consume(_ID);
  1229. end;
  1230. _LECKKLAMMER:
  1231. begin
  1232. repeat
  1233. consume(token);
  1234. until token in [_RECKKLAMMER,_SEMICOLON];
  1235. end;
  1236. else
  1237. break;
  1238. end;
  1239. until false;
  1240. exit;
  1241. end;
  1242. { handle token }
  1243. case token of
  1244. _CARET:
  1245. begin
  1246. consume(_CARET);
  1247. if (pd^.deftype<>pointerdef) then
  1248. begin
  1249. { ^ as binary operator is a problem!!!! (FK) }
  1250. again:=false;
  1251. Message(cg_e_invalid_qualifier);
  1252. disposetree(p1);
  1253. p1:=genzeronode(errorn);
  1254. end
  1255. else
  1256. begin
  1257. p1:=gensinglenode(derefn,p1);
  1258. pd:=ppointerdef(pd)^.pointertype.def;
  1259. end;
  1260. end;
  1261. _LECKKLAMMER:
  1262. begin
  1263. if (pd^.deftype=objectdef) and pobjectdef(pd)^.is_class then
  1264. begin
  1265. { default property }
  1266. propsym:=search_default_property(pobjectdef(pd));
  1267. if not(assigned(propsym)) then
  1268. begin
  1269. disposetree(p1);
  1270. p1:=genzeronode(errorn);
  1271. again:=false;
  1272. message(parser_e_no_default_property_available);
  1273. end
  1274. else
  1275. handle_propertysym(propsym,propsym^.owner,p1,pd);
  1276. end
  1277. else
  1278. begin
  1279. consume(_LECKKLAMMER);
  1280. repeat
  1281. case pd^.deftype of
  1282. pointerdef:
  1283. begin
  1284. p2:=comp_expr(true);
  1285. p1:=gennode(vecn,p1,p2);
  1286. pd:=ppointerdef(pd)^.pointertype.def;
  1287. end;
  1288. stringdef : begin
  1289. p2:=comp_expr(true);
  1290. p1:=gennode(vecn,p1,p2);
  1291. pd:=cchardef
  1292. end;
  1293. arraydef : begin
  1294. p2:=comp_expr(true);
  1295. { support SEG:OFS for go32v2 Mem[] }
  1296. if (target_info.target=target_i386_go32v2) and
  1297. (p1^.treetype=loadn) and
  1298. assigned(p1^.symtableentry) and
  1299. assigned(p1^.symtableentry^.owner^.name) and
  1300. (p1^.symtableentry^.owner^.name^='SYSTEM') and
  1301. ((p1^.symtableentry^.name='MEM') or
  1302. (p1^.symtableentry^.name='MEMW') or
  1303. (p1^.symtableentry^.name='MEML')) then
  1304. begin
  1305. if (token=_COLON) then
  1306. begin
  1307. consume(_COLON);
  1308. p3:=gennode(muln,genordinalconstnode($10,s32bitdef),p2);
  1309. p2:=comp_expr(true);
  1310. p2:=gennode(addn,p2,p3);
  1311. p1:=gennode(vecn,p1,p2);
  1312. p1^.memseg:=true;
  1313. p1^.memindex:=true;
  1314. end
  1315. else
  1316. begin
  1317. p1:=gennode(vecn,p1,p2);
  1318. p1^.memindex:=true;
  1319. end;
  1320. end
  1321. else
  1322. p1:=gennode(vecn,p1,p2);
  1323. pd:=parraydef(pd)^.elementtype.def;
  1324. end;
  1325. else
  1326. begin
  1327. Message(cg_e_invalid_qualifier);
  1328. disposetree(p1);
  1329. p1:=genzeronode(errorn);
  1330. again:=false;
  1331. end;
  1332. end;
  1333. if token=_COMMA then
  1334. consume(_COMMA)
  1335. else
  1336. break;
  1337. until false;
  1338. consume(_RECKKLAMMER);
  1339. end;
  1340. end;
  1341. _POINT : begin
  1342. consume(_POINT);
  1343. if (pd^.deftype=pointerdef) and
  1344. (m_autoderef in aktmodeswitches) then
  1345. begin
  1346. p1:=gensinglenode(derefn,p1);
  1347. pd:=ppointerdef(pd)^.pointertype.def;
  1348. end;
  1349. case pd^.deftype of
  1350. recorddef:
  1351. begin
  1352. sym:=pvarsym(precorddef(pd)^.symtable^.search(pattern));
  1353. if sym=nil then
  1354. begin
  1355. Message1(sym_e_illegal_field,pattern);
  1356. disposetree(p1);
  1357. p1:=genzeronode(errorn);
  1358. end
  1359. else
  1360. begin
  1361. p1:=gensubscriptnode(sym,p1);
  1362. pd:=sym^.vartype.def;
  1363. end;
  1364. consume(_ID);
  1365. end;
  1366. classrefdef:
  1367. begin
  1368. classh:=pobjectdef(pclassrefdef(pd)^.pointertype.def);
  1369. sym:=nil;
  1370. while assigned(classh) do
  1371. begin
  1372. sym:=pvarsym(classh^.symtable^.search(pattern));
  1373. srsymtable:=classh^.symtable;
  1374. if assigned(sym) then
  1375. break;
  1376. classh:=classh^.childof;
  1377. end;
  1378. if sym=nil then
  1379. begin
  1380. Message1(sym_e_id_no_member,pattern);
  1381. disposetree(p1);
  1382. p1:=genzeronode(errorn);
  1383. { try to clean up }
  1384. pd:=generrordef;
  1385. consume(_ID);
  1386. end
  1387. else
  1388. begin
  1389. consume(_ID);
  1390. do_member_read(getaddr,sym,p1,pd,again);
  1391. end;
  1392. end;
  1393. objectdef:
  1394. begin
  1395. classh:=pobjectdef(pd);
  1396. sym:=nil;
  1397. store_static:=allow_only_static;
  1398. allow_only_static:=false;
  1399. while assigned(classh) do
  1400. begin
  1401. sym:=pvarsym(classh^.symtable^.search(pattern));
  1402. srsymtable:=classh^.symtable;
  1403. if assigned(sym) then
  1404. break;
  1405. classh:=classh^.childof;
  1406. end;
  1407. allow_only_static:=store_static;
  1408. if sym=nil then
  1409. begin
  1410. Message1(sym_e_id_no_member,pattern);
  1411. disposetree(p1);
  1412. p1:=genzeronode(errorn);
  1413. { try to clean up }
  1414. pd:=generrordef;
  1415. consume(_ID);
  1416. end
  1417. else
  1418. begin
  1419. consume(_ID);
  1420. do_member_read(getaddr,sym,p1,pd,again);
  1421. end;
  1422. end;
  1423. pointerdef:
  1424. begin
  1425. Message(cg_e_invalid_qualifier);
  1426. if ppointerdef(pd)^.pointertype.def^.deftype in [recorddef,objectdef,classrefdef] then
  1427. Message(parser_h_maybe_deref_caret_missing);
  1428. end;
  1429. else
  1430. begin
  1431. Message(cg_e_invalid_qualifier);
  1432. disposetree(p1);
  1433. p1:=genzeronode(errorn);
  1434. end;
  1435. end;
  1436. end;
  1437. else
  1438. begin
  1439. { is this a procedure variable ? }
  1440. if assigned(pd) then
  1441. begin
  1442. if (pd^.deftype=procvardef) then
  1443. begin
  1444. if getprocvar and is_equal(pd,getprocvardef) then
  1445. again:=false
  1446. else
  1447. if (token=_LKLAMMER) or
  1448. ((pprocvardef(pd)^.para^.empty) and
  1449. (not((token in [_ASSIGNMENT,_UNEQUAL,_EQUAL]))) and
  1450. (not afterassignment) and
  1451. (not in_args)) then
  1452. begin
  1453. { do this in a strange way }
  1454. { it's not a clean solution }
  1455. p2:=p1;
  1456. p1:=gencallnode(nil,nil);
  1457. p1^.right:=p2;
  1458. p1^.unit_specific:=unit_specific;
  1459. p1^.symtableprocentry:=pprocsym(sym);
  1460. if token=_LKLAMMER then
  1461. begin
  1462. consume(_LKLAMMER);
  1463. p1^.left:=parse_paras(false,false);
  1464. consume(_RKLAMMER);
  1465. end;
  1466. pd:=pprocvardef(pd)^.rettype.def;
  1467. { proc():= is never possible }
  1468. if token=_ASSIGNMENT then
  1469. begin
  1470. Message(cg_e_illegal_expression);
  1471. p1:=genzeronode(errorn);
  1472. again:=false;
  1473. end;
  1474. p1^.resulttype:=pd;
  1475. end
  1476. else
  1477. again:=false;
  1478. p1^.resulttype:=pd;
  1479. end
  1480. else
  1481. again:=false;
  1482. end
  1483. else
  1484. again:=false;
  1485. end;
  1486. end;
  1487. check_tokenpos;
  1488. end; { while again }
  1489. end;
  1490. {---------------------------------------------
  1491. Factor (Main)
  1492. ---------------------------------------------}
  1493. begin
  1494. oldp1:=nil;
  1495. p1:=nil;
  1496. filepos:=tokenpos;
  1497. if token=_ID then
  1498. begin
  1499. factor_read_id;
  1500. { handle post fix operators }
  1501. postfixoperators;
  1502. end
  1503. else
  1504. case token of
  1505. _NEW : begin
  1506. consume(_NEW);
  1507. consume(_LKLAMMER);
  1508. {allow_type:=true;}
  1509. p1:=factor(false);
  1510. {allow_type:=false;}
  1511. if p1^.treetype<>typen then
  1512. begin
  1513. Message(type_e_type_id_expected);
  1514. disposetree(p1);
  1515. pd:=generrordef;
  1516. end
  1517. else
  1518. pd:=p1^.typenodetype;
  1519. pd2:=pd;
  1520. if (pd^.deftype<>pointerdef) then
  1521. Message1(type_e_pointer_type_expected,pd^.typename)
  1522. else
  1523. if token=_RKLAMMER then
  1524. begin
  1525. if (ppointerdef(pd)^.pointertype.def^.deftype=objectdef) and
  1526. (oo_has_vmt in pobjectdef(ppointerdef(pd)^.pointertype.def)^.objectoptions) then
  1527. Message(parser_w_use_extended_syntax_for_objects);
  1528. p1:=gensinglenode(newn,nil);
  1529. p1^.resulttype:=pd2;
  1530. consume(_RKLAMMER);
  1531. end
  1532. else
  1533. begin
  1534. disposetree(p1);
  1535. p1:=genzeronode(hnewn);
  1536. p1^.resulttype:=ppointerdef(pd)^.pointertype.def;
  1537. consume(_COMMA);
  1538. afterassignment:=false;
  1539. { determines the current object defintion }
  1540. classh:=pobjectdef(ppointerdef(pd)^.pointertype.def);
  1541. if classh^.deftype<>objectdef then
  1542. Message(parser_e_pointer_to_class_expected)
  1543. else
  1544. begin
  1545. { check for an abstract class }
  1546. if (oo_has_abstract in classh^.objectoptions) then
  1547. Message(sym_e_no_instance_of_abstract_object);
  1548. { search the constructor also in the symbol tables of
  1549. the parents }
  1550. sym:=nil;
  1551. while assigned(classh) do
  1552. begin
  1553. sym:=pvarsym(classh^.symtable^.search(pattern));
  1554. srsymtable:=classh^.symtable;
  1555. if assigned(sym) then
  1556. break;
  1557. classh:=classh^.childof;
  1558. end;
  1559. consume(_ID);
  1560. do_member_read(false,sym,p1,pd,again);
  1561. if (p1^.treetype<>calln) or
  1562. (assigned(p1^.procdefinition) and
  1563. (p1^.procdefinition^.proctypeoption<>potype_constructor)) then
  1564. Message(parser_e_expr_have_to_be_constructor_call);
  1565. end;
  1566. p1:=gensinglenode(newn,p1);
  1567. { set the resulttype }
  1568. p1^.resulttype:=pd2;
  1569. consume(_RKLAMMER);
  1570. end;
  1571. postfixoperators;
  1572. end;
  1573. _SELF : begin
  1574. again:=true;
  1575. consume(_SELF);
  1576. if not assigned(procinfo^._class) then
  1577. begin
  1578. p1:=genzeronode(errorn);
  1579. pd:=generrordef;
  1580. again:=false;
  1581. Message(parser_e_self_not_in_method);
  1582. end
  1583. else
  1584. begin
  1585. if (po_classmethod in aktprocsym^.definition^.procoptions) then
  1586. begin
  1587. { self in class methods is a class reference type }
  1588. pd:=new(pclassrefdef,init(procinfo^._class));
  1589. p1:=genselfnode(pd);
  1590. p1^.resulttype:=pd;
  1591. end
  1592. else
  1593. begin
  1594. p1:=genselfnode(procinfo^._class);
  1595. p1^.resulttype:=procinfo^._class;
  1596. end;
  1597. pd:=p1^.resulttype;
  1598. postfixoperators;
  1599. end;
  1600. end;
  1601. _INHERITED : begin
  1602. again:=true;
  1603. consume(_INHERITED);
  1604. if assigned(procinfo^._class) then
  1605. begin
  1606. classh:=procinfo^._class^.childof;
  1607. while assigned(classh) do
  1608. begin
  1609. srsymtable:=pobjectdef(classh)^.symtable;
  1610. sym:=pvarsym(srsymtable^.search(pattern));
  1611. if assigned(sym) then
  1612. begin
  1613. { only for procsyms we need to set the type (PFV) }
  1614. if sym^.typ=procsym then
  1615. begin
  1616. p1:=genzeronode(typen);
  1617. p1^.resulttype:=classh;
  1618. pd:=p1^.resulttype;
  1619. end
  1620. else
  1621. p1:=nil;
  1622. consume(_ID);
  1623. do_member_read(false,sym,p1,pd,again);
  1624. break;
  1625. end;
  1626. classh:=classh^.childof;
  1627. end;
  1628. if classh=nil then
  1629. begin
  1630. Message1(sym_e_id_no_member,pattern);
  1631. again:=false;
  1632. pd:=generrordef;
  1633. p1:=genzeronode(errorn);
  1634. end;
  1635. end
  1636. else
  1637. begin
  1638. Message(parser_e_generic_methods_only_in_methods);
  1639. again:=false;
  1640. pd:=generrordef;
  1641. p1:=genzeronode(errorn);
  1642. end;
  1643. postfixoperators;
  1644. end;
  1645. _INTCONST : begin
  1646. valint(pattern,l,code);
  1647. if code<>0 then
  1648. begin
  1649. val(pattern,d,code);
  1650. if code<>0 then
  1651. begin
  1652. Message(cg_e_invalid_integer);
  1653. consume(_INTCONST);
  1654. l:=1;
  1655. p1:=genordinalconstnode(l,s32bitdef);
  1656. end
  1657. else
  1658. begin
  1659. consume(_INTCONST);
  1660. p1:=genrealconstnode(d,bestrealdef^);
  1661. end;
  1662. end
  1663. else
  1664. begin
  1665. consume(_INTCONST);
  1666. p1:=genordinalconstnode(l,s32bitdef);
  1667. end;
  1668. end;
  1669. _REALNUMBER : begin
  1670. val(pattern,d,code);
  1671. if code<>0 then
  1672. begin
  1673. Message(parser_e_error_in_real);
  1674. d:=1.0;
  1675. end;
  1676. consume(_REALNUMBER);
  1677. p1:=genrealconstnode(d,bestrealdef^);
  1678. end;
  1679. _STRING : begin
  1680. pd:=string_dec;
  1681. { STRING can be also a type cast }
  1682. if token=_LKLAMMER then
  1683. begin
  1684. consume(_LKLAMMER);
  1685. p1:=comp_expr(true);
  1686. consume(_RKLAMMER);
  1687. p1:=gentypeconvnode(p1,pd);
  1688. p1^.explizit:=true;
  1689. { handle postfix operators here e.g. string(a)[10] }
  1690. again:=true;
  1691. postfixoperators;
  1692. end
  1693. else
  1694. p1:=gentypenode(pd,nil);
  1695. end;
  1696. _FILE : begin
  1697. pd:=cfiledef;
  1698. consume(_FILE);
  1699. { FILE can be also a type cast }
  1700. if token=_LKLAMMER then
  1701. begin
  1702. consume(_LKLAMMER);
  1703. p1:=comp_expr(true);
  1704. consume(_RKLAMMER);
  1705. p1:=gentypeconvnode(p1,pd);
  1706. p1^.explizit:=true;
  1707. { handle postfix operators here e.g. string(a)[10] }
  1708. again:=true;
  1709. postfixoperators;
  1710. end
  1711. else
  1712. p1:=gentypenode(pd,nil);
  1713. end;
  1714. _CSTRING : begin
  1715. p1:=genstringconstnode(pattern,st_default);
  1716. consume(_CSTRING);
  1717. end;
  1718. _CCHAR : begin
  1719. p1:=genordinalconstnode(ord(pattern[1]),cchardef);
  1720. consume(_CCHAR);
  1721. end;
  1722. _KLAMMERAFFE : begin
  1723. consume(_KLAMMERAFFE);
  1724. got_addrn:=true;
  1725. { support both @<x> and @(<x>) }
  1726. if token=_LKLAMMER then
  1727. begin
  1728. consume(_LKLAMMER);
  1729. p1:=factor(true);
  1730. consume(_RKLAMMER);
  1731. if token in [_CARET,_POINT,_LECKKLAMMER] then
  1732. begin
  1733. { we need the resulttype }
  1734. { of the expression in pd }
  1735. do_firstpass(p1);
  1736. pd:=p1^.resulttype;
  1737. again:=true;
  1738. postfixoperators;
  1739. end;
  1740. end
  1741. else
  1742. p1:=factor(true);
  1743. got_addrn:=false;
  1744. p1:=gensinglenode(addrn,p1);
  1745. end;
  1746. _LKLAMMER : begin
  1747. consume(_LKLAMMER);
  1748. p1:=comp_expr(true);
  1749. consume(_RKLAMMER);
  1750. { it's not a good solution }
  1751. { but (a+b)^ makes some problems }
  1752. if token in [_CARET,_POINT,_LECKKLAMMER] then
  1753. begin
  1754. { we need the resulttype }
  1755. { of the expression in pd }
  1756. do_firstpass(p1);
  1757. pd:=p1^.resulttype;
  1758. again:=true;
  1759. postfixoperators;
  1760. end;
  1761. end;
  1762. _LECKKLAMMER : begin
  1763. consume(_LECKKLAMMER);
  1764. p1:=factor_read_set;
  1765. consume(_RECKKLAMMER);
  1766. end;
  1767. _PLUS : begin
  1768. consume(_PLUS);
  1769. p1:=factor(false);
  1770. end;
  1771. _MINUS : begin
  1772. consume(_MINUS);
  1773. p1:=factor(false);
  1774. p1:=gensinglenode(unaryminusn,p1);
  1775. end;
  1776. _NOT : begin
  1777. consume(_NOT);
  1778. p1:=factor(false);
  1779. p1:=gensinglenode(notn,p1);
  1780. end;
  1781. _TRUE : begin
  1782. consume(_TRUE);
  1783. p1:=genordinalconstnode(1,booldef);
  1784. end;
  1785. _FALSE : begin
  1786. consume(_FALSE);
  1787. p1:=genordinalconstnode(0,booldef);
  1788. end;
  1789. _NIL : begin
  1790. consume(_NIL);
  1791. p1:=genzeronode(niln);
  1792. end;
  1793. else
  1794. begin
  1795. p1:=genzeronode(errorn);
  1796. consume(token);
  1797. Message(cg_e_illegal_expression);
  1798. end;
  1799. end;
  1800. { generate error node if no node is created }
  1801. if not assigned(p1) then
  1802. p1:=genzeronode(errorn);
  1803. { tp7 procvar handling, but not if the next token
  1804. will be a := }
  1805. if (m_tp_procvar in aktmodeswitches) and
  1806. (token<>_ASSIGNMENT) then
  1807. check_tp_procvar(p1);
  1808. factor:=p1;
  1809. check_tokenpos;
  1810. end;
  1811. {****************************************************************************
  1812. Sub_Expr
  1813. ****************************************************************************}
  1814. type
  1815. Toperator_precedence=(opcompare,opaddition,opmultiply);
  1816. Ttok2nodeRec=record
  1817. tok : ttoken;
  1818. nod : ttreetyp;
  1819. end;
  1820. const
  1821. tok2nodes=23;
  1822. tok2node:array[1..tok2nodes] of ttok2noderec=(
  1823. (tok:_PLUS ;nod:addn),
  1824. (tok:_MINUS ;nod:subn),
  1825. (tok:_STAR ;nod:muln),
  1826. (tok:_SLASH ;nod:slashn),
  1827. (tok:_EQUAL ;nod:equaln),
  1828. (tok:_GT ;nod:gtn),
  1829. (tok:_LT ;nod:ltn),
  1830. (tok:_GTE ;nod:gten),
  1831. (tok:_LTE ;nod:lten),
  1832. (tok:_SYMDIF ;nod:symdifn),
  1833. (tok:_STARSTAR;nod:starstarn),
  1834. (tok:_OP_AS ;nod:asn),
  1835. (tok:_OP_IN ;nod:inn),
  1836. (tok:_OP_IS ;nod:isn),
  1837. (tok:_OP_OR ;nod:orn),
  1838. (tok:_OP_AND ;nod:andn),
  1839. (tok:_OP_DIV ;nod:divn),
  1840. (tok:_OP_MOD ;nod:modn),
  1841. (tok:_OP_SHL ;nod:shln),
  1842. (tok:_OP_SHR ;nod:shrn),
  1843. (tok:_OP_XOR ;nod:xorn),
  1844. (tok:_CARET ;nod:caretn),
  1845. (tok:_UNEQUAL ;nod:unequaln)
  1846. );
  1847. { Warning these stay be ordered !! }
  1848. operator_levels:array[Toperator_precedence] of set of Ttoken=
  1849. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN,_OP_IS],
  1850. [_PLUS,_MINUS,_OP_OR,_OP_XOR],
  1851. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  1852. _OP_AS,_OP_AND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR]);
  1853. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):Ptree;
  1854. {Reads a subexpression while the operators are of the current precedence
  1855. level, or any higher level. Replaces the old term, simpl_expr and
  1856. simpl2_expr.}
  1857. var
  1858. low,high,mid : longint;
  1859. p1,p2 : Ptree;
  1860. oldt : Ttoken;
  1861. filepos : tfileposinfo;
  1862. begin
  1863. if pred_level=opmultiply then
  1864. p1:=factor(false)
  1865. else
  1866. p1:=sub_expr(succ(pred_level),true);
  1867. repeat
  1868. if (token in operator_levels[pred_level]) and
  1869. ((token<>_EQUAL) or accept_equal) then
  1870. begin
  1871. oldt:=token;
  1872. filepos:=tokenpos;
  1873. consume(token);
  1874. if pred_level=opmultiply then
  1875. p2:=factor(false)
  1876. else
  1877. p2:=sub_expr(succ(pred_level),true);
  1878. low:=1;
  1879. high:=tok2nodes;
  1880. while (low<high) do
  1881. begin
  1882. mid:=(low+high+1) shr 1;
  1883. if oldt<tok2node[mid].tok then
  1884. high:=mid-1
  1885. else
  1886. low:=mid;
  1887. end;
  1888. if tok2node[high].tok=oldt then
  1889. p1:=gennode(tok2node[high].nod,p1,p2)
  1890. else
  1891. p1:=gennode(nothingn,p1,p2);
  1892. set_tree_filepos(p1,filepos);
  1893. end
  1894. else
  1895. break;
  1896. until false;
  1897. sub_expr:=p1;
  1898. end;
  1899. function comp_expr(accept_equal : boolean):Ptree;
  1900. var
  1901. oldafterassignment : boolean;
  1902. p1 : ptree;
  1903. begin
  1904. oldafterassignment:=afterassignment;
  1905. afterassignment:=true;
  1906. p1:=sub_expr(opcompare,accept_equal);
  1907. afterassignment:=oldafterassignment;
  1908. comp_expr:=p1;
  1909. end;
  1910. function expr : ptree;
  1911. var
  1912. p1,p2 : ptree;
  1913. oldafterassignment : boolean;
  1914. oldp1 : ptree;
  1915. filepos : tfileposinfo;
  1916. begin
  1917. oldafterassignment:=afterassignment;
  1918. p1:=sub_expr(opcompare,true);
  1919. filepos:=tokenpos;
  1920. if (m_tp_procvar in aktmodeswitches) and
  1921. (token<>_ASSIGNMENT) then
  1922. check_tp_procvar(p1);
  1923. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  1924. afterassignment:=true;
  1925. oldp1:=p1;
  1926. case token of
  1927. _POINTPOINT : begin
  1928. consume(_POINTPOINT);
  1929. p2:=sub_expr(opcompare,true);
  1930. p1:=gennode(rangen,p1,p2);
  1931. end;
  1932. _ASSIGNMENT : begin
  1933. consume(_ASSIGNMENT);
  1934. { avoid a firstpass of a procedure if
  1935. it must be assigned to a procvar }
  1936. { should be recursive for a:=b:=c !!! }
  1937. if (p1^.resulttype<>nil) and (p1^.resulttype^.deftype=procvardef) then
  1938. begin
  1939. getprocvar:=true;
  1940. getprocvardef:=pprocvardef(p1^.resulttype);
  1941. end;
  1942. p2:=sub_expr(opcompare,true);
  1943. if getprocvar then
  1944. handle_procvar(getprocvardef,p2);
  1945. getprocvar:=false;
  1946. p1:=gennode(assignn,p1,p2);
  1947. end;
  1948. { this is the code for C like assignements }
  1949. { from an improvement of Peter Schaefer }
  1950. _PLUSASN : begin
  1951. consume(_PLUSASN );
  1952. p2:=sub_expr(opcompare,true);
  1953. p1:=gennode(assignn,p1,gennode(addn,getcopy(p1),p2));
  1954. { was first
  1955. p1:=gennode(assignn,p1,gennode(addn,p1,p2));
  1956. but disposetree assumes that we have a real
  1957. *** tree *** }
  1958. end;
  1959. _MINUSASN : begin
  1960. consume(_MINUSASN );
  1961. p2:=sub_expr(opcompare,true);
  1962. p1:=gennode(assignn,p1,gennode(subn,getcopy(p1),p2));
  1963. end;
  1964. _STARASN : begin
  1965. consume(_STARASN );
  1966. p2:=sub_expr(opcompare,true);
  1967. p1:=gennode(assignn,p1,gennode(muln,getcopy(p1),p2));
  1968. end;
  1969. _SLASHASN : begin
  1970. consume(_SLASHASN );
  1971. p2:=sub_expr(opcompare,true);
  1972. p1:=gennode(assignn,p1,gennode(slashn,getcopy(p1),p2));
  1973. end;
  1974. end;
  1975. afterassignment:=oldafterassignment;
  1976. if p1<>oldp1 then
  1977. set_tree_filepos(p1,filepos);
  1978. expr:=p1;
  1979. end;
  1980. function get_intconst:longint;
  1981. {Reads an expression, tries to evalute it and check if it is an integer
  1982. constant. Then the constant is returned.}
  1983. var
  1984. p:Ptree;
  1985. begin
  1986. p:=comp_expr(true);
  1987. do_firstpass(p);
  1988. if not codegenerror then
  1989. begin
  1990. if (p^.treetype<>ordconstn) and
  1991. (p^.resulttype^.deftype=orddef) and
  1992. not(Porddef(p^.resulttype)^.typ in [uvoid,uchar,bool8bit,bool16bit,bool32bit]) then
  1993. Message(cg_e_illegal_expression)
  1994. else
  1995. get_intconst:=p^.value;
  1996. end;
  1997. disposetree(p);
  1998. end;
  1999. function get_stringconst:string;
  2000. {Reads an expression, tries to evaluate it and checks if it is a string
  2001. constant. Then the constant is returned.}
  2002. var
  2003. p:Ptree;
  2004. begin
  2005. get_stringconst:='';
  2006. p:=comp_expr(true);
  2007. do_firstpass(p);
  2008. if p^.treetype<>stringconstn then
  2009. begin
  2010. if (p^.treetype=ordconstn) and is_char(p^.resulttype) then
  2011. get_stringconst:=char(p^.value)
  2012. else
  2013. Message(cg_e_illegal_expression);
  2014. end
  2015. else
  2016. get_stringconst:=strpas(p^.value_str);
  2017. disposetree(p);
  2018. end;
  2019. end.
  2020. {
  2021. $Log$
  2022. Revision 1.168 2000-02-09 13:22:56 peter
  2023. * log truncated
  2024. Revision 1.167 2000/01/19 22:41:58 florian
  2025. * corrected wrong error message of a member of a class/object/classref wasn't found
  2026. Revision 1.166 2000/01/09 23:16:05 peter
  2027. * added st_default stringtype
  2028. * genstringconstnode extended with stringtype parameter using st_default
  2029. will do the old behaviour
  2030. Revision 1.165 2000/01/07 01:14:28 peter
  2031. * updated copyright to 2000
  2032. Revision 1.164 1999/12/20 21:24:29 pierre
  2033. * web bug769 fix
  2034. Revision 1.163 1999/12/01 12:42:32 peter
  2035. * fixed bug 698
  2036. * removed some notes about unused vars
  2037. Revision 1.162 1999/11/30 10:40:44 peter
  2038. + ttype, tsymlist
  2039. Revision 1.161 1999/11/18 15:34:47 pierre
  2040. * Notes/Hints for local syms changed to
  2041. Set_varstate function
  2042. Revision 1.160 1999/11/17 17:05:01 pierre
  2043. * Notes/hints changes
  2044. Revision 1.159 1999/11/15 17:52:59 pierre
  2045. + one field added for ttoken record for operator
  2046. linking the id to the corresponding operator token that
  2047. can now now all be overloaded
  2048. * overloaded operators are resetted to nil in InitSymtable
  2049. (bug when trying to compile a uint that overloads operators twice)
  2050. Revision 1.158 1999/11/14 15:57:35 peter
  2051. * fixed crash with an errordef
  2052. Revision 1.157 1999/11/08 14:02:16 florian
  2053. * problem with "index X"-properties solved
  2054. * typed constants of class references are now allowed
  2055. Revision 1.156 1999/11/07 23:21:30 florian
  2056. * previous fix for 517 was imcomplete: there was a problem if the property
  2057. had only an index
  2058. Revision 1.155 1999/11/07 23:16:49 florian
  2059. * finally bug 517 solved ...
  2060. Revision 1.154 1999/11/06 14:34:21 peter
  2061. * truncated log to 20 revs
  2062. Revision 1.153 1999/11/05 00:10:30 peter
  2063. * fixed inherited with properties
  2064. Revision 1.152 1999/10/27 16:06:19 peter
  2065. * check for object in extended new
  2066. Revision 1.151 1999/10/26 12:30:44 peter
  2067. * const parameter is now checked
  2068. * better and generic check if a node can be used for assigning
  2069. * export fixes
  2070. * procvar equal works now (it never had worked at least from 0.99.8)
  2071. * defcoll changed to linkedlist with pparaitem so it can easily be
  2072. walked both directions
  2073. Revision 1.150 1999/10/22 14:37:30 peter
  2074. * error when properties are passed to var parameters
  2075. Revision 1.149 1999/10/22 10:39:34 peter
  2076. * split type reading from pdecl to ptype unit
  2077. * parameter_dec routine is now used for procedure and procvars
  2078. Revision 1.148 1999/10/14 14:57:52 florian
  2079. - removed the hcodegen use in the new cg, use cgbase instead
  2080. }