pexpr.pas 88 KB

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