pexpr.pas 93 KB

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