pexpr.pas 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557
  1. {
  2. $Id$
  3. Copyright (c) 1998 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,aasm,pass_1,
  36. hcodegen,types,verbose,strings,tccal
  37. { parser specific stuff }
  38. ,pbase,pdecl
  39. { processor specific stuff }
  40. {$ifdef i386}
  41. ,i386base
  42. {$endif}
  43. {$ifdef m68k}
  44. ,m68k
  45. {$endif}
  46. ;
  47. const
  48. allow_type : boolean = true;
  49. got_addrn : boolean = false;
  50. function parse_paras(_colon,in_prop_paras : boolean) : ptree;
  51. var
  52. p1,p2 : ptree;
  53. end_of_paras : ttoken;
  54. begin
  55. if in_prop_paras then
  56. end_of_paras:=RECKKLAMMER
  57. else
  58. end_of_paras:=RKLAMMER;
  59. if token=end_of_paras then
  60. begin
  61. parse_paras:=nil;
  62. exit;
  63. end;
  64. p2:=nil;
  65. inc(parsing_para_level);
  66. while true do
  67. begin
  68. p1:=comp_expr(true);
  69. p2:=gencallparanode(p1,p2);
  70. { it's for the str(l:5,s); }
  71. if _colon and (token=COLON) then
  72. begin
  73. consume(COLON);
  74. p1:=comp_expr(true);
  75. p2:=gencallparanode(p1,p2);
  76. p2^.is_colon_para:=true;
  77. if token=COLON then
  78. begin
  79. consume(COLON);
  80. p1:=comp_expr(true);
  81. p2:=gencallparanode(p1,p2);
  82. p2^.is_colon_para:=true;
  83. end
  84. end;
  85. if token=COMMA then
  86. consume(COMMA)
  87. else
  88. break;
  89. end;
  90. dec(parsing_para_level);
  91. parse_paras:=p2;
  92. end;
  93. procedure check_tp_procvar(var p : ptree);
  94. var
  95. p1 : ptree;
  96. Store_valid : boolean;
  97. begin
  98. if (m_tp_procvar in aktmodeswitches) and
  99. (not got_addrn) and
  100. (not in_args) and
  101. (p^.treetype=loadn) then
  102. begin
  103. { support if procvar then for tp7 and many other expression like this }
  104. Store_valid:=Must_be_valid;
  105. Must_be_valid:=false;
  106. firstpass(p);
  107. Must_be_valid:=Store_valid;
  108. if not(getprocvar) and (p^.resulttype^.deftype=procvardef) then
  109. begin
  110. p1:=gencallnode(nil,nil);
  111. p1^.right:=p;
  112. p1^.resulttype:=pprocvardef(p^.resulttype)^.retdef;
  113. firstpass(p1);
  114. p:=p1;
  115. end;
  116. end;
  117. end;
  118. function statement_syssym(l : longint;var pd : pdef) : ptree;
  119. var
  120. p1,p2,paras : ptree;
  121. prev_in_args : boolean;
  122. Store_valid : boolean;
  123. begin
  124. prev_in_args:=in_args;
  125. Store_valid:=Must_be_valid;
  126. case l of
  127. in_ord_x :
  128. begin
  129. consume(LKLAMMER);
  130. in_args:=true;
  131. Must_be_valid:=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. Must_be_valid:=false;
  183. do_firstpass(p1);
  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. Must_be_valid:=false;
  219. do_firstpass(p1);
  220. if ((p1^.resulttype^.deftype=objectdef) and
  221. ((pobjectdef(p1^.resulttype)^.options and oo_hasconstructor)<>0)) or
  222. is_open_array(p1^.resulttype) or
  223. is_open_string(p1^.resulttype) then
  224. statement_syssym:=geninlinenode(in_sizeof_x,false,p1)
  225. else
  226. begin
  227. statement_syssym:=genordinalconstnode(p1^.resulttype^.size,pd);
  228. { p1 not needed !}
  229. disposetree(p1);
  230. end;
  231. end;
  232. end;
  233. in_assigned_x :
  234. begin
  235. consume(LKLAMMER);
  236. in_args:=true;
  237. p1:=comp_expr(true);
  238. Must_be_valid:=true;
  239. do_firstpass(p1);
  240. case p1^.resulttype^.deftype of
  241. pointerdef,
  242. procvardef,
  243. classrefdef : ;
  244. objectdef : if not(pobjectdef(p1^.resulttype)^.isclass) then
  245. Message(parser_e_illegal_parameter_list);
  246. else
  247. Message(parser_e_illegal_parameter_list);
  248. end;
  249. p2:=gencallparanode(p1,nil);
  250. p2:=geninlinenode(in_assigned_x,false,p2);
  251. consume(RKLAMMER);
  252. pd:=booldef;
  253. statement_syssym:=p2;
  254. end;
  255. in_ofs_x :
  256. begin
  257. consume(LKLAMMER);
  258. in_args:=true;
  259. p1:=comp_expr(true);
  260. p1:=gensinglenode(addrn,p1);
  261. Must_be_valid:=false;
  262. do_firstpass(p1);
  263. { Ofs() returns a longint, not a pointer }
  264. p1^.resulttype:=u32bitdef;
  265. pd:=p1^.resulttype;
  266. consume(RKLAMMER);
  267. statement_syssym:=p1;
  268. end;
  269. in_addr_x :
  270. begin
  271. consume(LKLAMMER);
  272. in_args:=true;
  273. p1:=comp_expr(true);
  274. p1:=gensinglenode(addrn,p1);
  275. Must_be_valid:=false;
  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. if p1^.location.loc<>LOC_REFERENCE then
  288. Message(cg_e_illegal_expression);
  289. p1:=genordinalconstnode(0,s32bitdef);
  290. Must_be_valid:=false;
  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. Must_be_valid:=false;
  307. p2:=geninlinenode(l,false,p1);
  308. consume(RKLAMMER);
  309. pd:=s32bitdef;
  310. statement_syssym:=p2;
  311. end;
  312. in_succ_x,
  313. in_pred_x :
  314. begin
  315. consume(LKLAMMER);
  316. in_args:=true;
  317. p1:=comp_expr(true);
  318. do_firstpass(p1);
  319. Must_be_valid:=false;
  320. p2:=geninlinenode(l,false,p1);
  321. consume(RKLAMMER);
  322. pd:=p1^.resulttype;
  323. statement_syssym:=p2;
  324. end;
  325. in_inc_x,
  326. in_dec_x :
  327. begin
  328. consume(LKLAMMER);
  329. in_args:=true;
  330. p1:=comp_expr(true);
  331. Must_be_valid:=false;
  332. if token=COMMA then
  333. begin
  334. consume(COMMA);
  335. p2:=gencallparanode(comp_expr(true),nil);
  336. end
  337. else
  338. p2:=nil;
  339. p2:=gencallparanode(p1,p2);
  340. statement_syssym:=geninlinenode(l,false,p2);
  341. consume(RKLAMMER);
  342. pd:=voiddef;
  343. end;
  344. in_concat_x :
  345. begin
  346. consume(LKLAMMER);
  347. in_args:=true;
  348. p2:=nil;
  349. while true do
  350. begin
  351. p1:=comp_expr(true);
  352. Must_be_valid:=true;
  353. do_firstpass(p1);
  354. if not((p1^.resulttype^.deftype=stringdef) or
  355. ((p1^.resulttype^.deftype=orddef) and
  356. (porddef(p1^.resulttype)^.typ=uchar))) then
  357. Message(parser_e_illegal_parameter_list);
  358. if p2<>nil then
  359. p2:=gennode(addn,p2,p1)
  360. else
  361. p2:=p1;
  362. if token=COMMA then
  363. consume(COMMA)
  364. else
  365. break;
  366. end;
  367. consume(RKLAMMER);
  368. pd:=cshortstringdef;
  369. statement_syssym:=p2;
  370. end;
  371. in_read_x,
  372. in_readln_x :
  373. begin
  374. if token=LKLAMMER then
  375. begin
  376. consume(LKLAMMER);
  377. in_args:=true;
  378. Must_be_valid:=false;
  379. paras:=parse_paras(false,false);
  380. consume(RKLAMMER);
  381. end
  382. else
  383. paras:=nil;
  384. pd:=voiddef;
  385. p1:=geninlinenode(l,false,paras);
  386. do_firstpass(p1);
  387. statement_syssym := p1;
  388. end;
  389. in_write_x,
  390. in_writeln_x :
  391. begin
  392. if token=LKLAMMER then
  393. begin
  394. consume(LKLAMMER);
  395. in_args:=true;
  396. Must_be_valid:=true;
  397. paras:=parse_paras(true,false);
  398. consume(RKLAMMER);
  399. end
  400. else
  401. paras:=nil;
  402. pd:=voiddef;
  403. p1 := geninlinenode(l,false,paras);
  404. do_firstpass(p1);
  405. statement_syssym := p1;
  406. end;
  407. in_str_x_string :
  408. begin
  409. consume(LKLAMMER);
  410. in_args:=true;
  411. paras:=parse_paras(true,false);
  412. consume(RKLAMMER);
  413. p1 := geninlinenode(l,false,paras);
  414. do_firstpass(p1);
  415. statement_syssym := p1;
  416. pd:=voiddef;
  417. end;
  418. in_val_x:
  419. Begin
  420. consume(LKLAMMER);
  421. in_args := true;
  422. p1:= gencallparanode(comp_expr(true), nil);
  423. Must_be_valid := False;
  424. consume(COMMA);
  425. p2 := gencallparanode(comp_expr(true),p1);
  426. if (token = COMMA) then
  427. Begin
  428. consume(COMMA);
  429. p2 := gencallparanode(comp_expr(true),p2)
  430. End;
  431. consume(RKLAMMER);
  432. p2 := geninlinenode(l,false,p2);
  433. do_firstpass(p2);
  434. statement_syssym := p2;
  435. pd := voiddef;
  436. End;
  437. in_include_x_y,
  438. in_exclude_x_y :
  439. begin
  440. consume(LKLAMMER);
  441. in_args:=true;
  442. p1:=comp_expr(true);
  443. Must_be_valid:=false;
  444. consume(COMMA);
  445. p2:=comp_expr(true);
  446. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  447. consume(RKLAMMER);
  448. pd:=voiddef;
  449. end;
  450. in_assert_x_y :
  451. begin
  452. consume(LKLAMMER);
  453. in_args:=true;
  454. p1:=comp_expr(true);
  455. if token=COMMA then
  456. begin
  457. consume(COMMA);
  458. p2:=comp_expr(true);
  459. end
  460. else
  461. begin
  462. { then insert an empty string }
  463. p2:=genstringconstnode('');
  464. end;
  465. statement_syssym:=geninlinenode(l,false,gencallparanode(p1,gencallparanode(p2,nil)));
  466. consume(RKLAMMER);
  467. pd:=voiddef;
  468. end;
  469. else
  470. internalerror(15);
  471. end;
  472. in_args:=prev_in_args;
  473. Must_be_valid:=Store_valid;
  474. end;
  475. { reads the parameter for a subroutine call }
  476. procedure do_proc_call(getaddr : boolean;var again : boolean;var p1:Ptree;var pd:Pdef);
  477. var
  478. prev_in_args : boolean;
  479. prevafterassn : boolean;
  480. begin
  481. prev_in_args:=in_args;
  482. prevafterassn:=afterassignment;
  483. afterassignment:=false;
  484. { want we only determine the address of }
  485. { a subroutine ? }
  486. if not(getaddr) then
  487. begin
  488. if token=LKLAMMER then
  489. begin
  490. consume(LKLAMMER);
  491. in_args:=true;
  492. p1^.left:=parse_paras(false,false);
  493. consume(RKLAMMER);
  494. end
  495. else p1^.left:=nil;
  496. { do firstpass because we need the }
  497. { result type }
  498. do_firstpass(p1);
  499. end
  500. else
  501. begin
  502. { address operator @: }
  503. p1^.left:=nil;
  504. { forget pd }
  505. pd:=nil;
  506. if (p1^.symtableproc^.symtabletype=withsymtable) and
  507. (p1^.symtableproc^.defowner^.deftype=objectdef) then
  508. begin
  509. p1^.methodpointer:=getcopy(pwithsymtable(p1^.symtableproc)^.withrefnode);
  510. end
  511. else if not(assigned(p1^.methodpointer)) then
  512. begin
  513. { we must provide a method pointer, if it isn't given, }
  514. { it is self }
  515. p1^.methodpointer:=genselfnode(procinfo._class);
  516. p1^.methodpointer^.resulttype:=procinfo._class;
  517. end;
  518. { no postfix operators }
  519. again:=false;
  520. end;
  521. pd:=p1^.resulttype;
  522. in_args:=prev_in_args;
  523. afterassignment:=prevafterassn;
  524. end;
  525. procedure handle_procvar(procvar : pprocvardef;var t : ptree);
  526. var
  527. hp : ptree;
  528. begin
  529. hp:=nil;
  530. if (proc_to_procvar_equal(pprocsym(t^.symtableentry)^.definition,procvar)) then
  531. begin
  532. if ((procvar^.options and pomethodpointer)<>0) then
  533. hp:=genloadmethodcallnode(pprocsym(t^.symtableprocentry),t^.symtable,getcopy(t^.methodpointer))
  534. else
  535. hp:=genloadcallnode(pprocsym(t^.symtableprocentry),t^.symtable);
  536. end;
  537. if assigned(hp) then
  538. begin
  539. disposetree(t);
  540. t:=hp;
  541. end;
  542. end;
  543. { the following procedure handles the access to a property symbol }
  544. procedure handle_propertysym(sym : psym;st : psymtable;var p1 : ptree;
  545. var pd : pdef);
  546. var
  547. paras : ptree;
  548. p2 : ptree;
  549. begin
  550. paras:=nil;
  551. { property parameters? }
  552. if token=LECKKLAMMER then
  553. begin
  554. consume(LECKKLAMMER);
  555. paras:=parse_paras(false,true);
  556. consume(RECKKLAMMER);
  557. end;
  558. { indexed property }
  559. if (ppropertysym(sym)^.options and ppo_indexed)<>0 then
  560. begin
  561. p2:=genordinalconstnode(ppropertysym(sym)^.index,s32bitdef);
  562. paras:=gencallparanode(p2,paras);
  563. end;
  564. { we need only a write property if a := follows }
  565. { if not(afterassignment) and not(in_args) then }
  566. if token=ASSIGNMENT then
  567. begin
  568. { write property: }
  569. { no result }
  570. pd:=voiddef;
  571. if assigned(ppropertysym(sym)^.writeaccesssym) then
  572. begin
  573. if ppropertysym(sym)^.writeaccesssym^.typ=procsym then
  574. begin
  575. { generate the method call }
  576. p1:=genmethodcallnode(pprocsym(
  577. ppropertysym(sym)^.writeaccesssym),st,p1);
  578. { we know the procedure to call, so
  579. force the usage of that procedure }
  580. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.writeaccessdef);
  581. p1^.left:=paras;
  582. consume(ASSIGNMENT);
  583. { read the expression }
  584. getprocvar:=ppropertysym(sym)^.proptype^.deftype=procvardef;
  585. p2:=comp_expr(true);
  586. if getprocvar then
  587. begin
  588. if (p2^.treetype=calln) then
  589. handle_procvar(pprocvardef(ppropertysym(sym)^.proptype),p2)
  590. else
  591. if (p2^.treetype=typeconvn) and
  592. (p2^.left^.treetype=calln) then
  593. handle_procvar(pprocvardef(ppropertysym(sym)^.proptype),p2^.left);
  594. end;
  595. p1^.left:=gencallparanode(p2,p1^.left);
  596. getprocvar:=false;
  597. end
  598. else if ppropertysym(sym)^.writeaccesssym^.typ=varsym then
  599. begin
  600. if assigned(paras) then
  601. message(parser_e_no_paras_allowed);
  602. { subscribed access? }
  603. if p1=nil then
  604. p1:=genloadnode(pvarsym(ppropertysym(sym)^.writeaccesssym),st)
  605. else
  606. p1:=gensubscriptnode(pvarsym(ppropertysym(sym)^.writeaccesssym),p1);
  607. consume(ASSIGNMENT);
  608. { read the expression }
  609. p2:=comp_expr(true);
  610. p1:=gennode(assignn,p1,p2);
  611. end
  612. else
  613. begin
  614. p1:=genzeronode(errorn);
  615. Message(parser_e_no_procedure_to_access_property);
  616. end;
  617. end
  618. else
  619. begin
  620. p1:=genzeronode(errorn);
  621. Message(parser_e_no_procedure_to_access_property);
  622. end;
  623. end
  624. else
  625. begin
  626. { read property: }
  627. pd:=ppropertysym(sym)^.proptype;
  628. if assigned(ppropertysym(sym)^.readaccesssym) then
  629. begin
  630. if ppropertysym(sym)^.readaccesssym^.typ=varsym then
  631. begin
  632. if assigned(paras) then
  633. message(parser_e_no_paras_allowed);
  634. { subscribed access? }
  635. if p1=nil then
  636. p1:=genloadnode(pvarsym(ppropertysym(sym)^.readaccesssym),st)
  637. else
  638. p1:=gensubscriptnode(pvarsym(ppropertysym(sym)^.readaccesssym),p1);
  639. end
  640. else if ppropertysym(sym)^.readaccesssym^.typ=procsym then
  641. begin
  642. { generate the method call }
  643. p1:=genmethodcallnode(pprocsym(ppropertysym(sym)^.readaccesssym),st,p1);
  644. { we know the procedure to call, so
  645. force the usage of that procedure }
  646. p1^.procdefinition:=pprocdef(ppropertysym(sym)^.readaccessdef);
  647. { insert paras }
  648. p1^.left:=paras;
  649. end
  650. else
  651. begin
  652. p1:=genzeronode(errorn);
  653. Message(type_e_mismatch);
  654. end;
  655. end
  656. else
  657. begin
  658. { error, no function to read property }
  659. p1:=genzeronode(errorn);
  660. Message(parser_e_no_procedure_to_access_property);
  661. end;
  662. end;
  663. end;
  664. { the ID token has to be consumed before calling this function }
  665. procedure do_member_read(getaddr : boolean;const sym : psym;var p1 : ptree;
  666. var pd : pdef;var again : boolean);
  667. var
  668. static_name : string;
  669. isclassref : boolean;
  670. begin
  671. if sym=nil then
  672. begin
  673. { pattern is still valid unless
  674. there is another ID just after the ID of sym }
  675. Message1(sym_e_id_no_member,pattern);
  676. disposetree(p1);
  677. p1:=genzeronode(errorn);
  678. { try to clean up }
  679. pd:=generrordef;
  680. again:=false;
  681. end
  682. else
  683. begin
  684. isclassref:=pd^.deftype=classrefdef;
  685. { check protected and private members }
  686. { please leave this code as it is, }
  687. { it has now the same behaviaor as TP/Delphi }
  688. if ((sym^.properties and sp_private)<>0) and
  689. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  690. Message(parser_e_cant_access_private_member);
  691. if ((sym^.properties and sp_protected)<>0) and
  692. (pobjectdef(pd)^.owner^.symtabletype=unitsymtable) then
  693. begin
  694. if assigned(aktprocsym^.definition^._class) then
  695. begin
  696. if not aktprocsym^.definition^._class^.isrelated(
  697. pobjectdef(sym^.owner^.defowner)) then
  698. Message(parser_e_cant_access_protected_member);
  699. end
  700. else
  701. Message(parser_e_cant_access_protected_member);
  702. end;
  703. { we assume, that only procsyms and varsyms are in an object }
  704. { symbol table, for classes, properties are allowed }
  705. case sym^.typ of
  706. procsym:
  707. begin
  708. p1:=genmethodcallnode(pprocsym(sym),srsymtable,p1);
  709. do_proc_call(getaddr or
  710. (getprocvar and
  711. (m_tp_procvar in aktmodeswitches) and
  712. proc_to_procvar_equal(pprocsym(sym)^.definition,getprocvardef))
  713. ,again,p1,pd);
  714. { now we know the real method e.g. we can check for }
  715. { a class method }
  716. if isclassref and ((p1^.procdefinition^.options and (poclassmethod or poconstructor))=0) then
  717. Message(parser_e_only_class_methods_via_class_ref);
  718. end;
  719. varsym:
  720. begin
  721. if isclassref then
  722. Message(parser_e_only_class_methods_via_class_ref);
  723. if (sym^.properties and sp_static)<>0 then
  724. begin
  725. { static_name:=lower(srsymtable^.name^)+'_'+sym^.name;
  726. this is wrong for static field in with symtable (PM) }
  727. static_name:=lower(srsym^.owner^.name^)+'_'+sym^.name;
  728. getsym(static_name,true);
  729. disposetree(p1);
  730. p1:=genloadnode(pvarsym(srsym),srsymtable);
  731. end
  732. else
  733. p1:=gensubscriptnode(pvarsym(sym),p1);
  734. pd:=pvarsym(sym)^.definition;
  735. end;
  736. propertysym:
  737. begin
  738. if isclassref then
  739. Message(parser_e_only_class_methods_via_class_ref);
  740. handle_propertysym(sym,srsymtable,p1,pd);
  741. end;
  742. else internalerror(16);
  743. end;
  744. end;
  745. end;
  746. {****************************************************************************
  747. Factor
  748. ****************************************************************************}
  749. function factor(getaddr : boolean) : ptree;
  750. var
  751. l : longint;
  752. oldp1,
  753. p1,p2,p3 : ptree;
  754. code : integer;
  755. pd,pd2 : pdef;
  756. possible_error,
  757. unit_specific,
  758. again : boolean;
  759. sym : pvarsym;
  760. classh : pobjectdef;
  761. d : bestreal;
  762. static_name : string;
  763. propsym : ppropertysym;
  764. filepos : tfileposinfo;
  765. {---------------------------------------------
  766. Is_func_ret
  767. ---------------------------------------------}
  768. function is_func_ret(sym : psym) : boolean;
  769. var
  770. p : pprocinfo;
  771. storesymtablestack : psymtable;
  772. begin
  773. is_func_ret:=false;
  774. if (sym^.typ<>funcretsym) and ((procinfo.flags and pi_operator)=0) then
  775. exit;
  776. p:=@procinfo;
  777. while system.assigned(p) do
  778. begin
  779. { is this an access to a function result ? }
  780. if assigned(p^.funcretsym) and
  781. ((pfuncretsym(sym)=p^.funcretsym) or
  782. ((pvarsym(sym)=opsym) and
  783. ((p^.flags and pi_operator)<>0))) and
  784. (p^.retdef<>pdef(voiddef)) and
  785. (token<>LKLAMMER) and
  786. (not ((m_tp in aktmodeswitches) and
  787. (afterassignment or in_args))) then
  788. begin
  789. if ((pvarsym(sym)=opsym) and
  790. ((p^.flags and pi_operator)<>0)) then
  791. inc(opsym^.refs);
  792. if ((pvarsym(sym)=opsym) and
  793. ((p^.flags and pi_operator)<>0)) then
  794. inc(opsym^.refs);
  795. p1:=genzeronode(funcretn);
  796. pd:=p^.retdef;
  797. p1^.funcretprocinfo:=p;
  798. p1^.retdef:=pd;
  799. is_func_ret:=true;
  800. exit;
  801. end;
  802. p:=p^.parent;
  803. end;
  804. { we must use the function call }
  805. if(sym^.typ=funcretsym) then
  806. begin
  807. storesymtablestack:=symtablestack;
  808. symtablestack:=srsymtable^.next;
  809. getsym(sym^.name,true);
  810. if srsym^.typ<>procsym then
  811. Message(cg_e_illegal_expression);
  812. symtablestack:=storesymtablestack;
  813. end;
  814. end;
  815. {---------------------------------------------
  816. Factor_read_id
  817. ---------------------------------------------}
  818. procedure factor_read_id;
  819. var
  820. pc : pchar;
  821. len : longint;
  822. begin
  823. { allow post fix operators }
  824. again:=true;
  825. if (m_result in aktmodeswitches) and
  826. (idtoken=_RESULT) and
  827. assigned(aktprocsym) and
  828. (procinfo.retdef<>pdef(voiddef)) then
  829. begin
  830. consume(ID);
  831. p1:=genzeronode(funcretn);
  832. pd:=procinfo.retdef;
  833. p1^.funcretprocinfo:=pointer(@procinfo);
  834. p1^.retdef:=pd;
  835. end
  836. else
  837. begin
  838. if lastsymknown then
  839. begin
  840. srsym:=lastsrsym;
  841. srsymtable:=lastsrsymtable;
  842. lastsymknown:=false;
  843. end
  844. else
  845. getsym(pattern,true);
  846. consume(ID);
  847. if not is_func_ret(srsym) then
  848. { else it's a normal symbol }
  849. begin
  850. { is it defined like UNIT.SYMBOL ? }
  851. if srsym^.typ=unitsym then
  852. begin
  853. consume(POINT);
  854. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  855. unit_specific:=true;
  856. consume(ID);
  857. end
  858. else
  859. unit_specific:=false;
  860. if not assigned(srsym) then
  861. Begin
  862. p1:=genzeronode(errorn);
  863. { try to clean up }
  864. pd:=generrordef;
  865. end
  866. else
  867. Begin
  868. { check semantics of private }
  869. if (srsym^.typ in [propertysym,procsym,varsym]) and
  870. (srsymtable^.symtabletype=objectsymtable) then
  871. begin
  872. if ((srsym^.properties and sp_private)<>0) and
  873. (pobjectdef(srsym^.owner^.defowner)^.owner^.symtabletype=unitsymtable) then
  874. Message(parser_e_cant_access_private_member);
  875. end;
  876. case srsym^.typ of
  877. absolutesym : begin
  878. p1:=genloadnode(pvarsym(srsym),srsymtable);
  879. pd:=pabsolutesym(srsym)^.definition;
  880. end;
  881. varsym : begin
  882. { are we in a class method ? }
  883. if (srsymtable^.symtabletype=objectsymtable) and
  884. assigned(aktprocsym) and
  885. ((aktprocsym^.definition^.options and poclassmethod)<>0) then
  886. Message(parser_e_only_class_methods);
  887. if (srsym^.properties and sp_static)<>0 then
  888. begin
  889. static_name:=lower(srsym^.owner^.name^)+'_'+srsym^.name;
  890. getsym(static_name,true);
  891. end;
  892. p1:=genloadnode(pvarsym(srsym),srsymtable);
  893. if pvarsym(srsym)^.is_valid=0 then
  894. begin
  895. p1^.is_first := true;
  896. { set special between first loaded until checked in firstpass }
  897. pvarsym(srsym)^.is_valid:=2;
  898. end;
  899. pd:=pvarsym(srsym)^.definition;
  900. end;
  901. typedconstsym : begin
  902. p1:=gentypedconstloadnode(ptypedconstsym(srsym),srsymtable);
  903. pd:=ptypedconstsym(srsym)^.definition;
  904. end;
  905. syssym : p1:=statement_syssym(psyssym(srsym)^.number,pd);
  906. typesym : begin
  907. pd:=ptypesym(srsym)^.definition;
  908. if not assigned(pd) then
  909. begin
  910. pd:=generrordef;
  911. again:=false;
  912. end
  913. else
  914. begin
  915. { illegal reference ? }
  916. if pd^.owner^.unitid=-1 then
  917. Comment(V_Error,'illegal type reference, unit '+pd^.owner^.name^+' is not in uses');
  918. { if we read a type declaration }
  919. { we have to return the type and }
  920. { nothing else }
  921. if block_type=bt_type then
  922. begin
  923. p1:=gentypenode(pd);
  924. { here we can also set resulttype !! }
  925. p1^.resulttype:=pd;
  926. pd:=voiddef;
  927. end
  928. else { not type block }
  929. begin
  930. if token=LKLAMMER then
  931. begin
  932. consume(LKLAMMER);
  933. p1:=comp_expr(true);
  934. consume(RKLAMMER);
  935. p1:=gentypeconvnode(p1,pd);
  936. p1^.explizit:=true;
  937. end
  938. else { not LKLAMMER}
  939. if (token=POINT) and
  940. (pd^.deftype=objectdef) and
  941. not(pobjectdef(pd)^.isclass) then
  942. begin
  943. consume(POINT);
  944. if assigned(procinfo._class) then
  945. begin
  946. if procinfo._class^.isrelated(pobjectdef(pd)) then
  947. begin
  948. p1:=gentypenode(pd);
  949. p1^.resulttype:=pd;
  950. srsymtable:=pobjectdef(pd)^.publicsyms;
  951. sym:=pvarsym(srsymtable^.search(pattern));
  952. { search also in inherited methods }
  953. while sym=nil do
  954. begin
  955. pd:=pobjectdef(pd)^.childof;
  956. srsymtable:=pobjectdef(pd)^.publicsyms;
  957. sym:=pvarsym(srsymtable^.search(pattern));
  958. end;
  959. consume(ID);
  960. do_member_read(false,sym,p1,pd,again);
  961. end
  962. else
  963. begin
  964. Message(parser_e_no_super_class);
  965. pd:=generrordef;
  966. again:=false;
  967. end;
  968. end
  969. else
  970. begin
  971. { allows @TObject.Load }
  972. { also allows static methods and variables }
  973. p1:=genzeronode(typen);
  974. p1^.resulttype:=pd;
  975. { srsymtable:=pobjectdef(pd)^.publicsyms;
  976. sym:=pvarsym(srsymtable^.search(pattern)); }
  977. { TP allows also @TMenu.Load if Load is only }
  978. { defined in an anchestor class }
  979. sym:=pvarsym(search_class_member(pobjectdef(pd),pattern));
  980. if not assigned(sym) then
  981. Message1(sym_e_id_no_member,pattern)
  982. else if not(getaddr) and ((sym^.properties and sp_static)=0) then
  983. Message(sym_e_only_static_in_static)
  984. else
  985. begin
  986. consume(ID);
  987. do_member_read(getaddr,sym,p1,pd,again);
  988. end;
  989. end;
  990. end
  991. else
  992. begin
  993. { class reference ? }
  994. if (pd^.deftype=objectdef)
  995. and pobjectdef(pd)^.isclass then
  996. begin
  997. p1:=gentypenode(pd);
  998. p1^.resulttype:=pd;
  999. pd:=new(pclassrefdef,init(pd));
  1000. p1:=gensinglenode(loadvmtn,p1);
  1001. p1^.resulttype:=pd;
  1002. end
  1003. else
  1004. begin
  1005. { generate a type node }
  1006. { (for typeof etc) }
  1007. if allow_type then
  1008. begin
  1009. p1:=gentypenode(pd);
  1010. { here we must use typenodetype explicitly !! PM
  1011. p1^.resulttype:=pd; }
  1012. pd:=voiddef;
  1013. end
  1014. else
  1015. Message(parser_e_no_type_not_allowed_here);
  1016. end;
  1017. end;
  1018. end;
  1019. end;
  1020. end;
  1021. enumsym : begin
  1022. p1:=genenumnode(penumsym(srsym));
  1023. pd:=p1^.resulttype;
  1024. end;
  1025. constsym : begin
  1026. case pconstsym(srsym)^.consttype of
  1027. constint :
  1028. p1:=genordinalconstnode(pconstsym(srsym)^.value,s32bitdef);
  1029. conststring :
  1030. begin
  1031. len:=pconstsym(srsym)^.len;
  1032. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1033. len:=255;
  1034. getmem(pc,len+1);
  1035. move(pchar(pconstsym(srsym)^.value)^,pc^,len);
  1036. pc[len]:=#0;
  1037. p1:=genpcharconstnode(pc,len);
  1038. end;
  1039. constchar :
  1040. p1:=genordinalconstnode(pconstsym(srsym)^.value,cchardef);
  1041. constreal :
  1042. p1:=genrealconstnode(pbestreal(pconstsym(srsym)^.value)^,bestrealdef^);
  1043. constbool :
  1044. p1:=genordinalconstnode(pconstsym(srsym)^.value,booldef);
  1045. constset :
  1046. p1:=gensetconstnode(pconstset(pconstsym(srsym)^.value),
  1047. psetdef(pconstsym(srsym)^.definition));
  1048. constord :
  1049. p1:=genordinalconstnode(pconstsym(srsym)^.value,
  1050. pconstsym(srsym)^.definition);
  1051. constnil :
  1052. p1:=genzeronode(niln);
  1053. constresourcestring:
  1054. begin
  1055. p1:=genloadnode(pvarsym(srsym),srsymtable);
  1056. p1^.resulttype:=cansistringdef;
  1057. end;
  1058. end;
  1059. pd:=p1^.resulttype;
  1060. end;
  1061. procsym : begin
  1062. { are we in a class method ? }
  1063. possible_error:=(srsymtable^.symtabletype=objectsymtable) and
  1064. assigned(aktprocsym) and
  1065. ((aktprocsym^.definition^.options and poclassmethod)<>0);
  1066. p1:=gencallnode(pprocsym(srsym),srsymtable);
  1067. p1^.unit_specific:=unit_specific;
  1068. do_proc_call(getaddr or
  1069. (getprocvar and
  1070. (m_tp_procvar in aktmodeswitches) and
  1071. proc_to_procvar_equal(pprocsym(srsym)^.definition,getprocvardef)),
  1072. again,p1,pd);
  1073. if possible_error and
  1074. ((p1^.procdefinition^.options and poclassmethod)=0) then
  1075. Message(parser_e_only_class_methods);
  1076. end;
  1077. propertysym : begin
  1078. { access to property in a method }
  1079. { are we in a class method ? }
  1080. if (srsymtable^.symtabletype=objectsymtable) and
  1081. assigned(aktprocsym) and
  1082. ((aktprocsym^.definition^.options and poclassmethod)<>0) then
  1083. Message(parser_e_only_class_methods);
  1084. { no method pointer }
  1085. p1:=nil;
  1086. handle_propertysym(srsym,srsymtable,p1,pd);
  1087. end;
  1088. errorsym : begin
  1089. p1:=genzeronode(errorn);
  1090. pd:=generrordef;
  1091. if token=LKLAMMER then
  1092. begin
  1093. consume(LKLAMMER);
  1094. parse_paras(false,false);
  1095. consume(RKLAMMER);
  1096. end;
  1097. end;
  1098. else
  1099. begin
  1100. p1:=genzeronode(errorn);
  1101. pd:=generrordef;
  1102. Message(cg_e_illegal_expression);
  1103. end;
  1104. end; { end case }
  1105. end;
  1106. end;
  1107. end;
  1108. end;
  1109. {---------------------------------------------
  1110. Factor_Read_Set
  1111. ---------------------------------------------}
  1112. { Read a set between [] }
  1113. function factor_read_set:ptree;
  1114. var
  1115. p1,
  1116. lastp,
  1117. buildp : ptree;
  1118. begin
  1119. buildp:=nil;
  1120. { be sure that a least one arrayconstructn is used, also for an
  1121. empty [] }
  1122. if token=RECKKLAMMER then
  1123. buildp:=gennode(arrayconstructn,nil,buildp)
  1124. else
  1125. begin
  1126. while true do
  1127. begin
  1128. p1:=comp_expr(true);
  1129. if token=POINTPOINT then
  1130. begin
  1131. consume(POINTPOINT);
  1132. p2:=comp_expr(true);
  1133. p1:=gennode(arrayconstructrangen,p1,p2);
  1134. end;
  1135. { insert at the end of the tree, to get the correct order }
  1136. if not assigned(buildp) then
  1137. begin
  1138. buildp:=gennode(arrayconstructn,p1,nil);
  1139. lastp:=buildp;
  1140. end
  1141. else
  1142. begin
  1143. lastp^.right:=gennode(arrayconstructn,p1,nil);
  1144. lastp:=lastp^.right;
  1145. end;
  1146. { there could be more elements }
  1147. if token=COMMA then
  1148. consume(COMMA)
  1149. else
  1150. break;
  1151. end;
  1152. end;
  1153. factor_read_set:=buildp;
  1154. end;
  1155. {---------------------------------------------
  1156. Helpers
  1157. ---------------------------------------------}
  1158. procedure check_tokenpos;
  1159. begin
  1160. if (p1<>oldp1) then
  1161. begin
  1162. if assigned(p1) then
  1163. set_tree_filepos(p1,filepos);
  1164. oldp1:=p1;
  1165. filepos:=tokenpos;
  1166. end;
  1167. end;
  1168. {---------------------------------------------
  1169. PostFixOperators
  1170. ---------------------------------------------}
  1171. procedure postfixoperators;
  1172. var
  1173. store_static : boolean;
  1174. { p1 and p2 must contain valid value_str }
  1175. begin
  1176. check_tokenpos;
  1177. while again do
  1178. begin
  1179. { prevent crashes with unknown types }
  1180. if not assigned(pd) then
  1181. begin
  1182. { try to recover }
  1183. repeat
  1184. case token of
  1185. CARET:
  1186. consume(CARET);
  1187. POINT:
  1188. begin
  1189. consume(POINT);
  1190. consume(ID);
  1191. end;
  1192. LECKKLAMMER:
  1193. begin
  1194. repeat
  1195. consume(token);
  1196. until token in [RECKKLAMMER,SEMICOLON];
  1197. end;
  1198. else
  1199. break;
  1200. end;
  1201. until false;
  1202. exit;
  1203. end;
  1204. { handle token }
  1205. case token of
  1206. CARET:
  1207. begin
  1208. consume(CARET);
  1209. if (pd^.deftype<>pointerdef) then
  1210. begin
  1211. { ^ as binary operator is a problem!!!! (FK) }
  1212. again:=false;
  1213. Message(cg_e_invalid_qualifier);
  1214. disposetree(p1);
  1215. p1:=genzeronode(errorn);
  1216. end
  1217. else
  1218. begin
  1219. p1:=gensinglenode(derefn,p1);
  1220. pd:=ppointerdef(pd)^.definition;
  1221. end;
  1222. end;
  1223. LECKKLAMMER:
  1224. begin
  1225. if (pd^.deftype=objectdef) and pobjectdef(pd)^.isclass then
  1226. begin
  1227. { default property }
  1228. propsym:=search_default_property(pobjectdef(pd));
  1229. if not(assigned(propsym)) then
  1230. begin
  1231. disposetree(p1);
  1232. p1:=genzeronode(errorn);
  1233. again:=false;
  1234. message(parser_e_no_default_property_available);
  1235. end
  1236. else
  1237. handle_propertysym(propsym,propsym^.owner,p1,pd);
  1238. end
  1239. else
  1240. begin
  1241. consume(LECKKLAMMER);
  1242. repeat
  1243. case pd^.deftype of
  1244. pointerdef:
  1245. begin
  1246. p2:=comp_expr(true);
  1247. p1:=gennode(vecn,p1,p2);
  1248. pd:=ppointerdef(pd)^.definition;
  1249. end;
  1250. stringdef : begin
  1251. p2:=comp_expr(true);
  1252. p1:=gennode(vecn,p1,p2);
  1253. pd:=cchardef
  1254. end;
  1255. arraydef : begin
  1256. p2:=comp_expr(true);
  1257. { support SEG:OFS for go32v2 Mem[] }
  1258. if (target_info.target=target_i386_go32v2) and
  1259. (p1^.treetype=loadn) and
  1260. assigned(p1^.symtableentry) and
  1261. assigned(p1^.symtableentry^.owner^.name) and
  1262. (p1^.symtableentry^.owner^.name^='SYSTEM') and
  1263. ((p1^.symtableentry^.name='MEM') or
  1264. (p1^.symtableentry^.name='MEMW') or
  1265. (p1^.symtableentry^.name='MEML')) then
  1266. begin
  1267. if (token=COLON) then
  1268. begin
  1269. consume(COLON);
  1270. p3:=gennode(muln,genordinalconstnode($10,s32bitdef),p2);
  1271. p2:=comp_expr(true);
  1272. p2:=gennode(addn,p2,p3);
  1273. p1:=gennode(vecn,p1,p2);
  1274. p1^.memseg:=true;
  1275. p1^.memindex:=true;
  1276. end
  1277. else
  1278. begin
  1279. p1:=gennode(vecn,p1,p2);
  1280. p1^.memindex:=true;
  1281. end;
  1282. end
  1283. else
  1284. p1:=gennode(vecn,p1,p2);
  1285. pd:=parraydef(pd)^.definition;
  1286. end;
  1287. else
  1288. begin
  1289. Message(cg_e_invalid_qualifier);
  1290. disposetree(p1);
  1291. p1:=genzeronode(errorn);
  1292. again:=false;
  1293. end;
  1294. end;
  1295. if token=COMMA then
  1296. consume(COMMA)
  1297. else
  1298. break;
  1299. until false;
  1300. consume(RECKKLAMMER);
  1301. end;
  1302. end;
  1303. POINT : begin
  1304. consume(POINT);
  1305. if (pd^.deftype=pointerdef) and
  1306. (m_autoderef in aktmodeswitches) then
  1307. begin
  1308. p1:=gensinglenode(derefn,p1);
  1309. pd:=ppointerdef(pd)^.definition;
  1310. end;
  1311. case pd^.deftype of
  1312. recorddef:
  1313. begin
  1314. sym:=pvarsym(precdef(pd)^.symtable^.search(pattern));
  1315. if sym=nil then
  1316. begin
  1317. Message1(sym_e_illegal_field,pattern);
  1318. disposetree(p1);
  1319. p1:=genzeronode(errorn);
  1320. end
  1321. else
  1322. begin
  1323. p1:=gensubscriptnode(sym,p1);
  1324. pd:=sym^.definition;
  1325. end;
  1326. consume(ID);
  1327. end;
  1328. classrefdef:
  1329. begin
  1330. classh:=pobjectdef(pclassrefdef(pd)^.definition);
  1331. sym:=nil;
  1332. while assigned(classh) do
  1333. begin
  1334. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1335. srsymtable:=classh^.publicsyms;
  1336. if assigned(sym) then
  1337. break;
  1338. classh:=classh^.childof;
  1339. end;
  1340. consume(ID);
  1341. do_member_read(getaddr,sym,p1,pd,again);
  1342. end;
  1343. objectdef:
  1344. begin
  1345. classh:=pobjectdef(pd);
  1346. sym:=nil;
  1347. store_static:=allow_only_static;
  1348. allow_only_static:=false;
  1349. while assigned(classh) do
  1350. begin
  1351. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1352. srsymtable:=classh^.publicsyms;
  1353. if assigned(sym) then
  1354. break;
  1355. classh:=classh^.childof;
  1356. end;
  1357. allow_only_static:=store_static;
  1358. consume(ID);
  1359. do_member_read(getaddr,sym,p1,pd,again);
  1360. end;
  1361. pointerdef:
  1362. begin
  1363. Message(cg_e_invalid_qualifier);
  1364. if ppointerdef(pd)^.definition^.deftype in [recorddef,objectdef,classrefdef] then
  1365. Message(parser_h_maybe_deref_caret_missing);
  1366. end;
  1367. else
  1368. begin
  1369. Message(cg_e_invalid_qualifier);
  1370. disposetree(p1);
  1371. p1:=genzeronode(errorn);
  1372. end;
  1373. end;
  1374. end;
  1375. else
  1376. begin
  1377. { is this a procedure variable ? }
  1378. if assigned(pd) then
  1379. begin
  1380. if (pd^.deftype=procvardef) then
  1381. begin
  1382. if getprocvar and is_equal(pd,getprocvardef) then
  1383. again:=false
  1384. else
  1385. if (token=LKLAMMER) or
  1386. ((pprocvardef(pd)^.para1=nil) and
  1387. (not((token in [ASSIGNMENT,UNEQUAL,EQUAL]))) and
  1388. (not afterassignment) and
  1389. (not in_args)) then
  1390. begin
  1391. { do this in a strange way }
  1392. { it's not a clean solution }
  1393. p2:=p1;
  1394. p1:=gencallnode(nil,nil);
  1395. p1^.right:=p2;
  1396. p1^.unit_specific:=unit_specific;
  1397. p1^.symtableprocentry:=pprocsym(sym);
  1398. if token=LKLAMMER then
  1399. begin
  1400. consume(LKLAMMER);
  1401. p1^.left:=parse_paras(false,false);
  1402. consume(RKLAMMER);
  1403. end;
  1404. pd:=pprocvardef(pd)^.retdef;
  1405. { proc():= is never possible }
  1406. if token=ASSIGNMENT then
  1407. begin
  1408. Message(cg_e_illegal_expression);
  1409. p1:=genzeronode(errorn);
  1410. again:=false;
  1411. end;
  1412. p1^.resulttype:=pd;
  1413. end
  1414. else
  1415. again:=false;
  1416. p1^.resulttype:=pd;
  1417. end
  1418. else
  1419. again:=false;
  1420. end
  1421. else
  1422. again:=false;
  1423. end;
  1424. end;
  1425. check_tokenpos;
  1426. end; { while again }
  1427. end;
  1428. {---------------------------------------------
  1429. Factor (Main)
  1430. ---------------------------------------------}
  1431. begin
  1432. oldp1:=nil;
  1433. p1:=nil;
  1434. filepos:=tokenpos;
  1435. if token=ID then
  1436. begin
  1437. factor_read_id;
  1438. { handle post fix operators }
  1439. postfixoperators;
  1440. end
  1441. else
  1442. case token of
  1443. _NEW : begin
  1444. consume(_NEW);
  1445. consume(LKLAMMER);
  1446. {allow_type:=true;}
  1447. p1:=factor(false);
  1448. {allow_type:=false;}
  1449. if p1^.treetype<>typen then
  1450. begin
  1451. Message(type_e_type_id_expected);
  1452. disposetree(p1);
  1453. pd:=generrordef;
  1454. end
  1455. else
  1456. pd:=p1^.typenodetype;
  1457. pd2:=pd;
  1458. if (pd^.deftype<>pointerdef) then
  1459. Message(type_e_pointer_type_expected)
  1460. else if {(ppointerdef(pd)^.definition^.deftype<>objectdef)}
  1461. token=RKLAMMER then
  1462. begin
  1463. if (ppointerdef(pd)^.definition^.deftype=objectdef) and
  1464. ((pobjectdef(ppointerdef(pd)^.definition)^.options and oo_hasvmt) <> 0) then
  1465. Message(parser_w_use_extended_syntax_for_objects);
  1466. p1:=gensinglenode(newn,nil);
  1467. p1^.resulttype:=pd2;
  1468. consume(RKLAMMER);
  1469. (*Message(parser_e_pointer_to_class_expected);
  1470. { if an error occurs, read til the end of
  1471. the new statement }
  1472. p1:=genzeronode(errorn);
  1473. l:=1;
  1474. while true do
  1475. begin
  1476. case token of
  1477. LKLAMMER : inc(l);
  1478. RKLAMMER : dec(l);
  1479. end;
  1480. consume(token);
  1481. if l=0 then
  1482. break;
  1483. end;*)
  1484. end
  1485. else
  1486. begin
  1487. disposetree(p1);
  1488. p1:=genzeronode(hnewn);
  1489. p1^.resulttype:=ppointerdef(pd)^.definition;
  1490. consume(COMMA);
  1491. afterassignment:=false;
  1492. { determines the current object defintion }
  1493. classh:=pobjectdef(ppointerdef(pd)^.definition);
  1494. { check for an abstract class }
  1495. if (classh^.options and oo_is_abstract)<>0 then
  1496. Message(sym_e_no_instance_of_abstract_object);
  1497. { search the constructor also in the symbol tables of
  1498. the parents }
  1499. { no constructor found }
  1500. sym:=nil;
  1501. while assigned(classh) do
  1502. begin
  1503. sym:=pvarsym(classh^.publicsyms^.search(pattern));
  1504. srsymtable:=classh^.publicsyms;
  1505. if assigned(sym) then
  1506. break;
  1507. classh:=classh^.childof;
  1508. end;
  1509. consume(ID);
  1510. do_member_read(false,sym,p1,pd,again);
  1511. if (p1^.treetype<>calln) or
  1512. (assigned(p1^.procdefinition) and
  1513. ((p1^.procdefinition^.options and poconstructor)=0)) then
  1514. Message(parser_e_expr_have_to_be_constructor_call);
  1515. p1:=gensinglenode(newn,p1);
  1516. { set the resulttype }
  1517. p1^.resulttype:=pd2;
  1518. consume(RKLAMMER);
  1519. end;
  1520. end;
  1521. _SELF : begin
  1522. again:=true;
  1523. consume(_SELF);
  1524. if not assigned(procinfo._class) then
  1525. begin
  1526. p1:=genzeronode(errorn);
  1527. pd:=generrordef;
  1528. again:=false;
  1529. Message(parser_e_self_not_in_method);
  1530. end
  1531. else
  1532. begin
  1533. if (aktprocsym^.definition^.options and poclassmethod)<>0 then
  1534. begin
  1535. { self in class methods is a class reference type }
  1536. pd:=new(pclassrefdef,init(procinfo._class));
  1537. p1:=genselfnode(pd);
  1538. p1^.resulttype:=pd;
  1539. end
  1540. else
  1541. begin
  1542. p1:=genselfnode(procinfo._class);
  1543. p1^.resulttype:=procinfo._class;
  1544. end;
  1545. pd:=p1^.resulttype;
  1546. postfixoperators;
  1547. end;
  1548. end;
  1549. _INHERITED : begin
  1550. again:=true;
  1551. consume(_INHERITED);
  1552. if assigned(procinfo._class) then
  1553. begin
  1554. classh:=procinfo._class^.childof;
  1555. while assigned(classh) do
  1556. begin
  1557. srsymtable:=pobjectdef(classh)^.publicsyms;
  1558. sym:=pvarsym(srsymtable^.search(pattern));
  1559. if assigned(sym) then
  1560. begin
  1561. p1:=genzeronode(typen);
  1562. p1^.resulttype:=classh;
  1563. pd:=p1^.resulttype;
  1564. consume(ID);
  1565. do_member_read(false,sym,p1,pd,again);
  1566. break;
  1567. end;
  1568. classh:=classh^.childof;
  1569. end;
  1570. if classh=nil then
  1571. begin
  1572. Message1(sym_e_id_no_member,pattern);
  1573. again:=false;
  1574. pd:=generrordef;
  1575. p1:=genzeronode(errorn);
  1576. end;
  1577. end
  1578. else
  1579. begin
  1580. Message(parser_e_generic_methods_only_in_methods);
  1581. again:=false;
  1582. pd:=generrordef;
  1583. p1:=genzeronode(errorn);
  1584. end;
  1585. postfixoperators;
  1586. end;
  1587. INTCONST : begin
  1588. valint(pattern,l,code);
  1589. if code<>0 then
  1590. begin
  1591. val(pattern,d,code);
  1592. if code<>0 then
  1593. begin
  1594. Message(cg_e_invalid_integer);
  1595. consume(INTCONST);
  1596. l:=1;
  1597. p1:=genordinalconstnode(l,s32bitdef);
  1598. end
  1599. else
  1600. begin
  1601. consume(INTCONST);
  1602. p1:=genrealconstnode(d,bestrealdef^);
  1603. end;
  1604. end
  1605. else
  1606. begin
  1607. consume(INTCONST);
  1608. p1:=genordinalconstnode(l,s32bitdef);
  1609. end;
  1610. end;
  1611. REALNUMBER : begin
  1612. val(pattern,d,code);
  1613. if code<>0 then
  1614. begin
  1615. Message(parser_e_error_in_real);
  1616. d:=1.0;
  1617. end;
  1618. consume(REALNUMBER);
  1619. p1:=genrealconstnode(d,bestrealdef^);
  1620. end;
  1621. _STRING : begin
  1622. pd:=stringtype;
  1623. { STRING can be also a type cast }
  1624. if token=LKLAMMER then
  1625. begin
  1626. consume(LKLAMMER);
  1627. p1:=comp_expr(true);
  1628. consume(RKLAMMER);
  1629. p1:=gentypeconvnode(p1,pd);
  1630. p1^.explizit:=true;
  1631. { handle postfix operators here e.g. string(a)[10] }
  1632. again:=true;
  1633. postfixoperators;
  1634. end
  1635. else
  1636. p1:=gentypenode(pd);
  1637. end;
  1638. _FILE : begin
  1639. pd:=cfiledef;
  1640. consume(_FILE);
  1641. { FILE can be also a type cast }
  1642. if token=LKLAMMER then
  1643. begin
  1644. consume(LKLAMMER);
  1645. p1:=comp_expr(true);
  1646. consume(RKLAMMER);
  1647. p1:=gentypeconvnode(p1,pd);
  1648. p1^.explizit:=true;
  1649. { handle postfix operators here e.g. string(a)[10] }
  1650. again:=true;
  1651. postfixoperators;
  1652. end
  1653. else
  1654. p1:=gentypenode(pd);
  1655. end;
  1656. CSTRING : begin
  1657. p1:=genstringconstnode(pattern);
  1658. consume(CSTRING);
  1659. end;
  1660. CCHAR : begin
  1661. p1:=genordinalconstnode(ord(pattern[1]),cchardef);
  1662. consume(CCHAR);
  1663. end;
  1664. KLAMMERAFFE : begin
  1665. consume(KLAMMERAFFE);
  1666. got_addrn:=true;
  1667. p1:=factor(true);
  1668. got_addrn:=false;
  1669. p1:=gensinglenode(addrn,p1);
  1670. end;
  1671. LKLAMMER : begin
  1672. consume(LKLAMMER);
  1673. p1:=comp_expr(true);
  1674. consume(RKLAMMER);
  1675. { it's not a good solution }
  1676. { but (a+b)^ makes some problems }
  1677. if token in [CARET,POINT,LECKKLAMMER] then
  1678. begin
  1679. { we need the resulttype }
  1680. { of the expression in pd }
  1681. do_firstpass(p1);
  1682. pd:=p1^.resulttype;
  1683. again:=true;
  1684. postfixoperators;
  1685. end;
  1686. end;
  1687. LECKKLAMMER : begin
  1688. consume(LECKKLAMMER);
  1689. p1:=factor_read_set;
  1690. consume(RECKKLAMMER);
  1691. end;
  1692. PLUS : begin
  1693. consume(PLUS);
  1694. p1:=factor(false);
  1695. end;
  1696. MINUS : begin
  1697. consume(MINUS);
  1698. p1:=factor(false);
  1699. p1:=gensinglenode(umminusn,p1);
  1700. end;
  1701. _NOT : begin
  1702. consume(_NOT);
  1703. p1:=factor(false);
  1704. p1:=gensinglenode(notn,p1);
  1705. end;
  1706. _TRUE : begin
  1707. consume(_TRUE);
  1708. p1:=genordinalconstnode(1,booldef);
  1709. end;
  1710. _FALSE : begin
  1711. consume(_FALSE);
  1712. p1:=genordinalconstnode(0,booldef);
  1713. end;
  1714. _NIL : begin
  1715. consume(_NIL);
  1716. p1:=genzeronode(niln);
  1717. end;
  1718. else
  1719. begin
  1720. p1:=genzeronode(errorn);
  1721. consume(token);
  1722. Message(cg_e_illegal_expression);
  1723. end;
  1724. end;
  1725. { generate error node if no node is created }
  1726. if not assigned(p1) then
  1727. p1:=genzeronode(errorn);
  1728. { tp7 procvar handling, but not if the next token
  1729. will be a := }
  1730. if (m_tp_procvar in aktmodeswitches) and
  1731. (token<>ASSIGNMENT) then
  1732. check_tp_procvar(p1);
  1733. factor:=p1;
  1734. check_tokenpos;
  1735. end;
  1736. {****************************************************************************
  1737. Sub_Expr
  1738. ****************************************************************************}
  1739. type
  1740. Toperator_precedence=(opcompare,opaddition,opmultiply);
  1741. Ttok2nodeRec=record
  1742. tok : ttoken;
  1743. nod : ttreetyp;
  1744. end;
  1745. const
  1746. tok2nodes=23;
  1747. tok2node:array[1..tok2nodes] of ttok2noderec=(
  1748. (tok:PLUS ;nod:addn),
  1749. (tok:MINUS ;nod:subn),
  1750. (tok:STAR ;nod:muln),
  1751. (tok:SLASH ;nod:slashn),
  1752. (tok:EQUAL ;nod:equaln),
  1753. (tok:GT ;nod:gtn),
  1754. (tok:LT ;nod:ltn),
  1755. (tok:GTE ;nod:gten),
  1756. (tok:LTE ;nod:lten),
  1757. (tok:SYMDIF ;nod:symdifn),
  1758. (tok:STARSTAR;nod:starstarn),
  1759. (tok:CARET ;nod:caretn),
  1760. (tok:UNEQUAL ;nod:unequaln),
  1761. (tok:_AS ;nod:asn),
  1762. (tok:_IN ;nod:inn),
  1763. (tok:_IS ;nod:isn),
  1764. (tok:_OR ;nod:orn),
  1765. (tok:_AND ;nod:andn),
  1766. (tok:_DIV ;nod:divn),
  1767. (tok:_MOD ;nod:modn),
  1768. (tok:_SHL ;nod:shln),
  1769. (tok:_SHR ;nod:shrn),
  1770. (tok:_XOR ;nod:xorn)
  1771. );
  1772. operator_levels:array[Toperator_precedence] of set of Ttoken=
  1773. ([LT,LTE,GT,GTE,EQUAL,UNEQUAL,_IN,_IS],
  1774. [PLUS,MINUS,_OR,_XOR],
  1775. [CARET,SYMDIF,STARSTAR,STAR,SLASH,_DIV,_MOD,_AND,_SHL,_SHR,_AS]);
  1776. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):Ptree;
  1777. {Reads a subexpression while the operators are of the current precedence
  1778. level, or any higher level. Replaces the old term, simpl_expr and
  1779. simpl2_expr.}
  1780. var
  1781. low,high,mid : longint;
  1782. p1,p2 : Ptree;
  1783. oldt : Ttoken;
  1784. filepos : tfileposinfo;
  1785. begin
  1786. if pred_level=opmultiply then
  1787. p1:=factor(false)
  1788. else
  1789. p1:=sub_expr(succ(pred_level),true);
  1790. repeat
  1791. if (token in operator_levels[pred_level]) and
  1792. ((token<>EQUAL) or accept_equal) then
  1793. begin
  1794. oldt:=token;
  1795. filepos:=tokenpos;
  1796. consume(token);
  1797. if pred_level=opmultiply then
  1798. p2:=factor(false)
  1799. else
  1800. p2:=sub_expr(succ(pred_level),true);
  1801. low:=1;
  1802. high:=tok2nodes;
  1803. while (low<high) do
  1804. begin
  1805. mid:=(low+high+1) shr 1;
  1806. if oldt<tok2node[mid].tok then
  1807. high:=mid-1
  1808. else
  1809. low:=mid;
  1810. end;
  1811. if tok2node[high].tok=oldt then
  1812. p1:=gennode(tok2node[high].nod,p1,p2)
  1813. else
  1814. p1:=gennode(nothingn,p1,p2);
  1815. set_tree_filepos(p1,filepos);
  1816. end
  1817. else
  1818. break;
  1819. until false;
  1820. sub_expr:=p1;
  1821. end;
  1822. function comp_expr(accept_equal : boolean):Ptree;
  1823. var
  1824. oldafterassignment : boolean;
  1825. p1 : ptree;
  1826. begin
  1827. oldafterassignment:=afterassignment;
  1828. afterassignment:=true;
  1829. p1:=sub_expr(opcompare,accept_equal);
  1830. afterassignment:=oldafterassignment;
  1831. comp_expr:=p1;
  1832. end;
  1833. function expr : ptree;
  1834. var
  1835. p1,p2 : ptree;
  1836. oldafterassignment : boolean;
  1837. oldp1 : ptree;
  1838. filepos : tfileposinfo;
  1839. begin
  1840. oldafterassignment:=afterassignment;
  1841. p1:=sub_expr(opcompare,true);
  1842. filepos:=tokenpos;
  1843. if (m_tp_procvar in aktmodeswitches) and
  1844. (token<>ASSIGNMENT) then
  1845. check_tp_procvar(p1);
  1846. if token in [ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  1847. afterassignment:=true;
  1848. oldp1:=p1;
  1849. case token of
  1850. POINTPOINT : begin
  1851. consume(POINTPOINT);
  1852. p2:=sub_expr(opcompare,true);
  1853. p1:=gennode(rangen,p1,p2);
  1854. end;
  1855. ASSIGNMENT : begin
  1856. consume(ASSIGNMENT);
  1857. { avoid a firstpass of a procedure if
  1858. it must be assigned to a procvar }
  1859. { should be recursive for a:=b:=c !!! }
  1860. if (p1^.resulttype<>nil) and (p1^.resulttype^.deftype=procvardef) then
  1861. begin
  1862. getprocvar:=true;
  1863. getprocvardef:=pprocvardef(p1^.resulttype);
  1864. end;
  1865. p2:=sub_expr(opcompare,true);
  1866. if getprocvar then
  1867. begin
  1868. if (p2^.treetype=calln) then
  1869. handle_procvar(getprocvardef,p2)
  1870. else
  1871. { also allow p:= proc(t); !! (PM) }
  1872. if (p2^.treetype=typeconvn) and
  1873. (p2^.left^.treetype=calln) then
  1874. handle_procvar(getprocvardef,p2^.left);
  1875. end;
  1876. getprocvar:=false;
  1877. p1:=gennode(assignn,p1,p2);
  1878. end;
  1879. { this is the code for C like assignements }
  1880. { from an improvement of Peter Schaefer }
  1881. _PLUSASN : begin
  1882. consume(_PLUSASN );
  1883. p2:=sub_expr(opcompare,true);
  1884. p1:=gennode(assignn,p1,gennode(addn,getcopy(p1),p2));
  1885. { was first
  1886. p1:=gennode(assignn,p1,gennode(addn,p1,p2));
  1887. but disposetree assumes that we have a real
  1888. *** tree *** }
  1889. end;
  1890. _MINUSASN : begin
  1891. consume(_MINUSASN );
  1892. p2:=sub_expr(opcompare,true);
  1893. p1:=gennode(assignn,p1,gennode(subn,getcopy(p1),p2));
  1894. end;
  1895. _STARASN : begin
  1896. consume(_STARASN );
  1897. p2:=sub_expr(opcompare,true);
  1898. p1:=gennode(assignn,p1,gennode(muln,getcopy(p1),p2));
  1899. end;
  1900. _SLASHASN : begin
  1901. consume(_SLASHASN );
  1902. p2:=sub_expr(opcompare,true);
  1903. p1:=gennode(assignn,p1,gennode(slashn,getcopy(p1),p2));
  1904. end;
  1905. end;
  1906. afterassignment:=oldafterassignment;
  1907. if p1<>oldp1 then
  1908. set_tree_filepos(p1,filepos);
  1909. expr:=p1;
  1910. end;
  1911. function get_intconst:longint;
  1912. {Reads an expression, tries to evalute it and check if it is an integer
  1913. constant. Then the constant is returned.}
  1914. var
  1915. p:Ptree;
  1916. begin
  1917. p:=comp_expr(true);
  1918. do_firstpass(p);
  1919. if not codegenerror then
  1920. begin
  1921. if (p^.treetype<>ordconstn) and
  1922. (p^.resulttype^.deftype=orddef) and
  1923. not(Porddef(p^.resulttype)^.typ in [uvoid,uchar,bool8bit,bool16bit,bool32bit]) then
  1924. Message(cg_e_illegal_expression)
  1925. else
  1926. get_intconst:=p^.value;
  1927. end;
  1928. disposetree(p);
  1929. end;
  1930. function get_stringconst:string;
  1931. {Reads an expression, tries to evaluate it and checks if it is a string
  1932. constant. Then the constant is returned.}
  1933. var
  1934. p:Ptree;
  1935. begin
  1936. get_stringconst:='';
  1937. p:=comp_expr(true);
  1938. do_firstpass(p);
  1939. if p^.treetype<>stringconstn then
  1940. begin
  1941. if (p^.treetype=ordconstn) and is_char(p^.resulttype) then
  1942. get_stringconst:=char(p^.value)
  1943. else
  1944. Message(cg_e_illegal_expression);
  1945. end
  1946. else
  1947. get_stringconst:=strpas(p^.value_str);
  1948. disposetree(p);
  1949. end;
  1950. end.
  1951. {
  1952. $Log$
  1953. Revision 1.124 1999-07-23 21:31:42 peter
  1954. * fixed crash with resourcestring
  1955. Revision 1.123 1999/07/23 11:37:46 peter
  1956. * error for illegal type reference, instead of 10998
  1957. Revision 1.122 1999/07/22 09:37:52 florian
  1958. + resourcestring implemented
  1959. + start of longstring support
  1960. Revision 1.121 1999/07/16 10:04:35 peter
  1961. * merged
  1962. Revision 1.120 1999/07/06 22:38:11 florian
  1963. * another fix for TP/Delphi styled procedure variables
  1964. Revision 1.119 1999/07/05 20:13:16 peter
  1965. * removed temp defines
  1966. Revision 1.118 1999/07/01 21:33:57 peter
  1967. * merged
  1968. Revision 1.117 1999/06/30 15:43:20 florian
  1969. * two bugs regarding method variables fixed
  1970. - if you take in a method the address of another method
  1971. don't need self anymore
  1972. - if the class pointer was in a register, wrong code for a method
  1973. variable load was generated
  1974. Revision 1.116 1999/06/26 00:24:53 pierre
  1975. * mereg from fixes-0_99_12 branch
  1976. Revision 1.112.2.8 1999/07/16 09:54:57 peter
  1977. * @procvar support in tp7 mode works again
  1978. Revision 1.112.2.7 1999/07/07 07:53:10 michael
  1979. + Merged patches from florian
  1980. Revision 1.112.2.6 1999/07/01 21:31:59 peter
  1981. * procvar fixes again
  1982. Revision 1.112.2.5 1999/07/01 15:17:17 peter
  1983. * methoidpointer fixes from florian
  1984. Revision 1.112.2.4 1999/06/26 00:22:30 pierre
  1985. * wrong warnings in -So mode suppressed
  1986. Revision 1.112.2.3 1999/06/17 12:51:44 pierre
  1987. * changed is_assignment_overloaded into
  1988. function assignment_overloaded : pprocdef
  1989. to allow overloading of assignment with only different result type
  1990. Revision 1.112.2.2 1999/06/15 18:54:52 peter
  1991. * more procvar fixes
  1992. Revision 1.112.2.1 1999/06/13 22:38:09 peter
  1993. * tp_procvar check for loading of procvars when getaddr=false
  1994. Revision 1.112 1999/06/02 22:44:11 pierre
  1995. * previous wrong log corrected
  1996. Revision 1.111 1999/06/02 22:25:43 pierre
  1997. * changed $ifdef FPC @ into $ifndef TP
  1998. * changes for correct procvar handling under tp mode
  1999. Revision 1.110 1999/06/01 19:27:55 peter
  2000. * better checks for procvar and methodpointer
  2001. Revision 1.109 1999/05/27 19:44:46 peter
  2002. * removed oldasm
  2003. * plabel -> pasmlabel
  2004. * -a switches to source writing automaticly
  2005. * assembler readers OOPed
  2006. * asmsymbol automaticly external
  2007. * jumptables and other label fixes for asm readers
  2008. Revision 1.108 1999/05/18 14:15:54 peter
  2009. * containsself fixes
  2010. * checktypes()
  2011. Revision 1.107 1999/05/18 09:52:18 peter
  2012. * procedure of object and addrn fixes
  2013. Revision 1.106 1999/05/16 17:06:31 peter
  2014. * remove firstcallparan which looks obsolete
  2015. Revision 1.105 1999/05/12 22:36:09 florian
  2016. * override isn't allowed in objects!
  2017. Revision 1.104 1999/05/07 10:35:23 florian
  2018. * first fix for a problem with method pointer properties, still doesn't work
  2019. with WITH
  2020. Revision 1.103 1999/05/06 21:40:16 peter
  2021. * fixed crash
  2022. Revision 1.101 1999/05/06 09:05:21 peter
  2023. * generic write_float and str_float
  2024. * fixed constant float conversions
  2025. Revision 1.100 1999/05/04 21:44:57 florian
  2026. * changes to compile it with Delphi 4.0
  2027. Revision 1.99 1999/05/01 13:24:31 peter
  2028. * merged nasm compiler
  2029. * old asm moved to oldasm/
  2030. Revision 1.98 1999/04/26 18:29:56 peter
  2031. * farpointerdef moved into pointerdef.is_far
  2032. Revision 1.97 1999/04/19 09:27:48 peter
  2033. * removed my property fix
  2034. Revision 1.96 1999/04/19 09:13:47 peter
  2035. * class property without write support
  2036. Revision 1.95 1999/04/19 06:10:08 florian
  2037. * property problem fixed: a propertysym is only a write
  2038. access if it is followed by a assignment token
  2039. Revision 1.94 1999/04/17 13:12:17 peter
  2040. * addr() internal
  2041. Revision 1.93 1999/04/15 09:00:08 peter
  2042. * fixed property write
  2043. Revision 1.92 1999/04/08 20:59:43 florian
  2044. * fixed problem with default properties which are a class
  2045. * case bug (from the mailing list with -O2) fixed, the
  2046. distance of the case labels can be greater than the positive
  2047. range of a longint => it is now a dword for fpc
  2048. Revision 1.91 1999/04/06 11:21:56 peter
  2049. * more use of ttoken
  2050. Revision 1.90 1999/03/31 13:55:12 peter
  2051. * assembler inlining working for ag386bin
  2052. Revision 1.89 1999/03/26 00:05:36 peter
  2053. * released valintern
  2054. + deffile is now removed when compiling is finished
  2055. * ^( compiles now correct
  2056. + static directive
  2057. * shrd fixed
  2058. Revision 1.88 1999/03/24 23:17:15 peter
  2059. * fixed bugs 212,222,225,227,229,231,233
  2060. Revision 1.87 1999/03/16 17:52:52 jonas
  2061. * changes for internal Val code (do a "make cycle OPT=-dvalintern" to test)
  2062. * in cgi386inl: also range checking for subrange types (compile with "-dreadrangecheck")
  2063. * in cgai386: also small fixes to emitrangecheck
  2064. Revision 1.86 1999/03/04 13:55:44 pierre
  2065. * some m68k fixes (still not compilable !)
  2066. * new(tobj) does not give warning if tobj has no VMT !
  2067. Revision 1.85 1999/02/22 15:09:39 florian
  2068. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2069. Revision 1.84 1999/02/22 02:15:26 peter
  2070. * updates for ag386bin
  2071. Revision 1.83 1999/02/11 09:46:25 pierre
  2072. * fix for normal method calls inside static methods :
  2073. WARNING there were both parser and codegen errors !!
  2074. added static_call boolean to calln tree
  2075. Revision 1.82 1999/01/28 14:06:47 florian
  2076. * small fix for method pointers
  2077. * found the annoying strpas bug, mainly nested call to type cast which
  2078. use ansistrings crash
  2079. Revision 1.81 1999/01/27 00:13:55 florian
  2080. * "procedure of object"-stuff fixed
  2081. Revision 1.80 1999/01/21 16:41:01 pierre
  2082. * fix for constructor inside with statements
  2083. Revision 1.79 1998/12/30 22:15:48 peter
  2084. + farpointer type
  2085. * absolutesym now also stores if its far
  2086. Revision 1.78 1998/12/11 00:03:32 peter
  2087. + globtype,tokens,version unit splitted from globals
  2088. Revision 1.77 1998/12/04 10:18:09 florian
  2089. * some stuff for procedures of object added
  2090. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  2091. Revision 1.76 1998/11/27 14:50:40 peter
  2092. + open strings, $P switch support
  2093. Revision 1.75 1998/11/25 19:12:51 pierre
  2094. * var:=new(pointer_type) support added
  2095. Revision 1.74 1998/11/13 10:18:11 peter
  2096. + nil constants
  2097. Revision 1.73 1998/11/05 12:02:52 peter
  2098. * released useansistring
  2099. * removed -Sv, its now available in fpc modes
  2100. Revision 1.72 1998/11/04 10:11:41 peter
  2101. * ansistring fixes
  2102. Revision 1.71 1998/10/22 23:57:29 peter
  2103. * fixed filedef for typenodetype
  2104. Revision 1.70 1998/10/21 15:12:54 pierre
  2105. * bug fix for IOCHECK inside a procedure with iocheck modifier
  2106. * removed the GPF for unexistant overloading
  2107. (firstcall was called with procedinition=nil !)
  2108. * changed typen to what Florian proposed
  2109. gentypenode(p : pdef) sets the typenodetype field
  2110. and resulttype is only set if inside bt_type block !
  2111. Revision 1.69 1998/10/20 15:10:19 pierre
  2112. * type ptree only allowed inside expression
  2113. if following sizeof typeof low high or as first arg of new !!
  2114. Revision 1.68 1998/10/20 11:15:44 pierre
  2115. * calling of private method allowed inside child object method
  2116. Revision 1.67 1998/10/19 08:54:57 pierre
  2117. * wrong stabs info corrected once again !!
  2118. + variable vmt offset with vmt field only if required
  2119. implemented now !!!
  2120. Revision 1.66 1998/10/15 15:13:28 pierre
  2121. + added oo_hasconstructor and oo_hasdestructor
  2122. for objects options
  2123. Revision 1.65 1998/10/13 13:10:24 peter
  2124. * new style for m68k/i386 infos and enums
  2125. Revision 1.64 1998/10/12 12:20:55 pierre
  2126. + added tai_const_symbol_offset
  2127. for r : pointer = @var.field;
  2128. * better message for different arg names on implementation
  2129. of function
  2130. Revision 1.63 1998/10/12 10:28:30 florian
  2131. + auto dereferencing of pointers to structured types in delphi mode
  2132. Revision 1.62 1998/10/12 10:05:41 peter
  2133. * fixed mem leak with arrayconstrutor
  2134. Revision 1.61 1998/10/05 13:57:15 peter
  2135. * crash preventions
  2136. Revision 1.60 1998/10/05 12:32:46 peter
  2137. + assert() support
  2138. Revision 1.59 1998/10/01 14:56:24 peter
  2139. * crash preventions
  2140. Revision 1.58 1998/09/30 07:40:35 florian
  2141. * better error recovering
  2142. Revision 1.57 1998/09/28 16:18:16 florian
  2143. * two fixes to get ansi strings work
  2144. Revision 1.56 1998/09/26 17:45:36 peter
  2145. + idtoken and only one token table
  2146. Revision 1.55 1998/09/24 23:49:10 peter
  2147. + aktmodeswitches
  2148. Revision 1.54 1998/09/23 15:46:39 florian
  2149. * problem with with and classes fixed
  2150. Revision 1.53 1998/09/23 09:58:54 peter
  2151. * first working array of const things
  2152. Revision 1.52 1998/09/20 09:38:45 florian
  2153. * hasharray for defs fixed
  2154. * ansistring code generation corrected (init/final, assignement)
  2155. Revision 1.51 1998/09/18 16:03:43 florian
  2156. * some changes to compile with Delphi
  2157. Revision 1.50 1998/09/17 13:41:18 pierre
  2158. sizeof(TPOINT) problem
  2159. Revision 1.49.2.1 1998/09/17 08:42:31 pierre
  2160. TPOINT sizeof fix
  2161. Revision 1.49 1998/09/09 11:50:53 pierre
  2162. * forward def are not put in record or objects
  2163. + added check for forwards also in record and objects
  2164. * dummy parasymtable for unit initialization removed from
  2165. symtable stack
  2166. Revision 1.48 1998/09/07 22:25:53 peter
  2167. * fixed str(boolean,string) which was allowed
  2168. * fixed write(' ':<int expression>) only constants where allowed :(
  2169. Revision 1.47 1998/09/07 18:46:10 peter
  2170. * update smartlinking, uses getdatalabel
  2171. * renamed ptree.value vars to value_str,value_real,value_set
  2172. Revision 1.46 1998/09/04 08:42:03 peter
  2173. * updated some error messages
  2174. Revision 1.45 1998/09/01 17:39:49 peter
  2175. + internal constant functions
  2176. Revision 1.44 1998/08/28 10:54:24 peter
  2177. * fixed smallset generation from elements, it has never worked before!
  2178. Revision 1.43 1998/08/23 16:07:24 florian
  2179. * internalerror with mod/div fixed
  2180. Revision 1.42 1998/08/21 14:08:50 pierre
  2181. + TEST_FUNCRET now default (old code removed)
  2182. works also for m68k (at least compiles)
  2183. Revision 1.41 1998/08/20 21:36:39 peter
  2184. * fixed 'with object do' bug
  2185. Revision 1.40 1998/08/20 09:26:41 pierre
  2186. + funcret setting in underproc testing
  2187. compile with _dTEST_FUNCRET
  2188. Revision 1.39 1998/08/18 16:48:48 pierre
  2189. * bug for -So proc assignment to p^rocvar fixed
  2190. Revision 1.38 1998/08/18 14:17:09 pierre
  2191. * bug about assigning the return value of a function to
  2192. a procvar fixed : warning
  2193. assigning a proc to a procvar need @ in FPC mode !!
  2194. * missing file/line info restored
  2195. Revision 1.37 1998/08/18 09:24:43 pierre
  2196. * small warning position bug fixed
  2197. * support_mmx switches splitting was missing
  2198. * rhide error and warning output corrected
  2199. Revision 1.36 1998/08/15 16:50:29 peter
  2200. * fixed proc()=expr which was not allowed anymore by my previous fix
  2201. Revision 1.35 1998/08/14 18:18:46 peter
  2202. + dynamic set contruction
  2203. * smallsets are now working (always longint size)
  2204. Revision 1.34 1998/08/13 11:00:12 peter
  2205. * fixed procedure<>procedure construct
  2206. Revision 1.33 1998/08/11 15:31:39 peter
  2207. * write extended to ppu file
  2208. * new version 0.99.7
  2209. Revision 1.32 1998/08/11 14:05:32 peter
  2210. * fixed sizeof(array of char)
  2211. Revision 1.31 1998/08/10 14:50:11 peter
  2212. + localswitches, moduleswitches, globalswitches splitting
  2213. Revision 1.30 1998/07/28 21:52:54 florian
  2214. + implementation of raise and try..finally
  2215. + some misc. exception stuff
  2216. Revision 1.29 1998/07/27 21:57:13 florian
  2217. * fix to allow tv like stream registration:
  2218. @tmenu.load doesn't work if load had parameters or if load was only
  2219. declared in an anchestor class of tmenu
  2220. Revision 1.28 1998/07/14 21:46:51 peter
  2221. * updated messages file
  2222. Revision 1.27 1998/06/25 14:04:23 peter
  2223. + internal inc/dec
  2224. Revision 1.26 1998/06/09 16:01:46 pierre
  2225. + added procedure directive parsing for procvars
  2226. (accepted are popstack cdecl and pascal)
  2227. + added C vars with the following syntax
  2228. var C calias 'true_c_name';(can be followed by external)
  2229. reason is that you must add the Cprefix
  2230. which is target dependent
  2231. Revision 1.25 1998/06/05 14:37:33 pierre
  2232. * fixes for inline for operators
  2233. * inline procedure more correctly restricted
  2234. Revision 1.24 1998/06/04 23:51:52 peter
  2235. * m68k compiles
  2236. + .def file creation moved to gendef.pas so it could also be used
  2237. for win32
  2238. Revision 1.23 1998/06/04 09:55:40 pierre
  2239. * demangled name of procsym reworked to become independant of the mangling scheme
  2240. Revision 1.22 1998/06/02 17:03:03 pierre
  2241. * with node corrected for objects
  2242. * small bugs for SUPPORT_MMX fixed
  2243. Revision 1.21 1998/05/27 19:45:05 peter
  2244. * symtable.pas splitted into includefiles
  2245. * symtable adapted for $ifdef NEWPPU
  2246. Revision 1.20 1998/05/26 07:53:59 pierre
  2247. * bug fix for empty sets (nil pd was dereferenced )
  2248. Revision 1.19 1998/05/25 17:11:43 pierre
  2249. * firstpasscount bug fixed
  2250. now all is already set correctly the first time
  2251. under EXTDEBUG try -gp to skip all other firstpasses
  2252. it works !!
  2253. * small bug fixes
  2254. - for smallsets with -dTESTSMALLSET
  2255. - some warnings removed (by correcting code !)
  2256. Revision 1.18 1998/05/23 01:21:20 peter
  2257. + aktasmmode, aktoptprocessor, aktoutputformat
  2258. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2259. + $LIBNAME to set the library name where the unit will be put in
  2260. * splitted cgi386 a bit (codeseg to large for bp7)
  2261. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2262. Revision 1.17 1998/05/22 12:37:03 carl
  2263. * crash bugfix (patched msanually to main branch)
  2264. Revision 1.16 1998/05/21 19:33:32 peter
  2265. + better procedure directive handling and only one table
  2266. Revision 1.15 1998/05/20 09:42:35 pierre
  2267. + UseTokenInfo now default
  2268. * unit in interface uses and implementation uses gives error now
  2269. * only one error for unknown symbol (uses lastsymknown boolean)
  2270. the problem came from the label code !
  2271. + first inlined procedures and function work
  2272. (warning there might be allowed cases were the result is still wrong !!)
  2273. * UseBrower updated gives a global list of all position of all used symbols
  2274. with switch -gb
  2275. Revision 1.14 1998/05/11 13:07:56 peter
  2276. + $ifdef NEWPPU for the new ppuformat
  2277. + $define GDB not longer required
  2278. * removed all warnings and stripped some log comments
  2279. * no findfirst/findnext anymore to remove smartlink *.o files
  2280. Revision 1.13 1998/05/06 08:38:45 pierre
  2281. * better position info with UseTokenInfo
  2282. UseTokenInfo greatly simplified
  2283. + added check for changed tree after first time firstpass
  2284. (if we could remove all the cases were it happen
  2285. we could skip all firstpass if firstpasscount > 1)
  2286. Only with ExtDebug
  2287. Revision 1.12 1998/05/05 12:05:42 florian
  2288. * problems with properties fixed
  2289. * crash fixed: i:=l when i and l are undefined, was a problem with
  2290. implementation of private/protected
  2291. Revision 1.11 1998/05/04 11:22:26 florian
  2292. * problem with DOM solved: it crashes when accessing a property in a method
  2293. Revision 1.10 1998/05/01 16:38:45 florian
  2294. * handling of private and protected fixed
  2295. + change_keywords_to_tp implemented to remove
  2296. keywords which aren't supported by tp
  2297. * break and continue are now symbols of the system unit
  2298. + widestring, longstring and ansistring type released
  2299. Revision 1.9 1998/04/29 10:33:58 pierre
  2300. + added some code for ansistring (not complete nor working yet)
  2301. * corrected operator overloading
  2302. * corrected nasm output
  2303. + started inline procedures
  2304. + added starstarn : use ** for exponentiation (^ gave problems)
  2305. + started UseTokenInfo cond to get accurate positions
  2306. Revision 1.8 1998/04/14 23:27:03 florian
  2307. + exclude/include with constant second parameter added
  2308. Revision 1.7 1998/04/09 23:02:15 florian
  2309. * small problems solved to get remake3 work
  2310. Revision 1.6 1998/04/09 22:16:35 florian
  2311. * problem with previous REGALLOC solved
  2312. * improved property support
  2313. Revision 1.5 1998/04/08 10:26:09 florian
  2314. * correct error handling of virtual constructors
  2315. * problem with new type declaration handling fixed
  2316. Revision 1.4 1998/04/07 22:45:05 florian
  2317. * bug0092, bug0115 and bug0121 fixed
  2318. + packed object/class/array
  2319. Revision 1.3 1998/04/07 13:19:46 pierre
  2320. * bugfixes for reset_gdb_info
  2321. in MEM parsing for go32v2
  2322. better external symbol creation
  2323. support for rhgdb.exe (lowercase file names)
  2324. }