nmem.pas 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Type checking and register allocation for memory related nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nmem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,
  22. symdef,symsym,symtable,symtype;
  23. type
  24. tloadvmtaddrnode = class(tunarynode)
  25. { unless this is for a call, we have to send the "class" message to
  26. the objctype because the type information only gets initialized
  27. after the first message has been sent -> crash if you pass an
  28. uninitialized type to e.g. class_getInstanceSize() or so. No need
  29. to save to/restore from ppu. }
  30. forcall: boolean;
  31. constructor create(l : tnode);virtual;
  32. function pass_1 : tnode;override;
  33. function pass_typecheck:tnode;override;
  34. function docompare(p: tnode): boolean; override;
  35. function dogetcopy: tnode; override;
  36. end;
  37. tloadvmtaddrnodeclass = class of tloadvmtaddrnode;
  38. tloadparentfpkind = (
  39. { as parameter to a nested routine (current routine's frame) }
  40. lpf_forpara,
  41. { to load a local from a parent routine in the current nested routine
  42. (some parent routine's frame) }
  43. lpf_forload
  44. );
  45. tloadparentfpnode = class(tunarynode)
  46. parentpd : tprocdef;
  47. parentpdderef : tderef;
  48. kind: tloadparentfpkind;
  49. constructor create(pd: tprocdef; fpkind: tloadparentfpkind);virtual;
  50. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  51. procedure ppuwrite(ppufile:tcompilerppufile);override;
  52. procedure buildderefimpl;override;
  53. procedure derefimpl;override;
  54. function pass_1 : tnode;override;
  55. function pass_typecheck:tnode;override;
  56. function docompare(p: tnode): boolean; override;
  57. function dogetcopy : tnode;override;
  58. end;
  59. tloadparentfpnodeclass = class of tloadparentfpnode;
  60. taddrnode = class(tunarynode)
  61. getprocvardef : tprocvardef;
  62. getprocvardefderef : tderef;
  63. constructor create(l : tnode);virtual;
  64. constructor create_internal(l : tnode); virtual;
  65. constructor create_internal_nomark(l : tnode); virtual;
  66. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  67. procedure ppuwrite(ppufile:tcompilerppufile);override;
  68. procedure mark_write;override;
  69. procedure buildderefimpl;override;
  70. procedure derefimpl;override;
  71. function docompare(p: tnode): boolean; override;
  72. function dogetcopy : tnode;override;
  73. function pass_1 : tnode;override;
  74. function pass_typecheck:tnode;override;
  75. function simplify(forinline : boolean) : tnode; override;
  76. protected
  77. mark_read_written: boolean;
  78. function typecheck_non_proc(realsource: tnode; out res: tnode): boolean; virtual;
  79. end;
  80. taddrnodeclass = class of taddrnode;
  81. tderefnode = class(tunarynode)
  82. constructor create(l : tnode);virtual;
  83. function pass_1 : tnode;override;
  84. function pass_typecheck:tnode;override;
  85. procedure mark_write;override;
  86. end;
  87. tderefnodeclass = class of tderefnode;
  88. tsubscriptnode = class(tunarynode)
  89. vs : tfieldvarsym;
  90. vsderef : tderef;
  91. constructor create(varsym : tsym;l : tnode);virtual;
  92. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  93. procedure ppuwrite(ppufile:tcompilerppufile);override;
  94. procedure buildderefimpl;override;
  95. procedure derefimpl;override;
  96. function dogetcopy : tnode;override;
  97. function pass_1 : tnode;override;
  98. function docompare(p: tnode): boolean; override;
  99. function pass_typecheck:tnode;override;
  100. procedure mark_write;override;
  101. end;
  102. tsubscriptnodeclass = class of tsubscriptnode;
  103. tvecnode = class(tbinarynode)
  104. protected
  105. function first_arraydef: tnode; virtual;
  106. function gen_array_rangecheck: tnode; virtual;
  107. public
  108. constructor create(l,r : tnode);virtual;
  109. function pass_1 : tnode;override;
  110. function pass_typecheck:tnode;override;
  111. procedure mark_write;override;
  112. end;
  113. tvecnodeclass = class of tvecnode;
  114. twithnode = class(tunarynode)
  115. constructor create(l:tnode);
  116. destructor destroy;override;
  117. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  118. procedure ppuwrite(ppufile:tcompilerppufile);override;
  119. function dogetcopy : tnode;override;
  120. function pass_1 : tnode;override;
  121. function docompare(p: tnode): boolean; override;
  122. function pass_typecheck:tnode;override;
  123. end;
  124. twithnodeclass = class of twithnode;
  125. var
  126. cloadvmtaddrnode : tloadvmtaddrnodeclass= tloadvmtaddrnode;
  127. caddrnode : taddrnodeclass= taddrnode;
  128. cderefnode : tderefnodeclass= tderefnode;
  129. csubscriptnode : tsubscriptnodeclass= tsubscriptnode;
  130. cvecnode : tvecnodeclass= tvecnode;
  131. cwithnode : twithnodeclass= twithnode;
  132. cloadparentfpnode : tloadparentfpnodeclass = tloadparentfpnode;
  133. function is_big_untyped_addrnode(p: tnode): boolean;
  134. implementation
  135. uses
  136. globtype,systems,constexp,
  137. cutils,verbose,globals,
  138. symconst,symbase,defutil,defcmp,
  139. nadd,nbas,nflw,ninl,nutils,objcutil,
  140. wpobase,
  141. {$ifdef i8086}
  142. cpuinfo,
  143. {$endif i8086}
  144. htypechk,pass_1,ncal,nld,ncon,ncnv,cgbase,procinfo
  145. ;
  146. {*****************************************************************************
  147. TLOADVMTADDRNODE
  148. *****************************************************************************}
  149. constructor tloadvmtaddrnode.create(l : tnode);
  150. begin
  151. inherited create(loadvmtaddrn,l);
  152. end;
  153. function tloadvmtaddrnode.pass_typecheck:tnode;
  154. var
  155. defaultresultdef : boolean;
  156. begin
  157. result:=nil;
  158. typecheckpass(left);
  159. if codegenerror then
  160. exit;
  161. case left.resultdef.typ of
  162. classrefdef :
  163. resultdef:=left.resultdef;
  164. recorddef,
  165. objectdef:
  166. begin
  167. if (left.resultdef.typ=objectdef) or
  168. ((target_info.system in systems_jvm) and
  169. (left.resultdef.typ=recorddef)) then
  170. begin
  171. { access to the classtype while specializing? }
  172. if (df_generic in left.resultdef.defoptions) then
  173. begin
  174. defaultresultdef:=true;
  175. if assigned(current_structdef) then
  176. begin
  177. if assigned(current_structdef.genericdef) then
  178. if current_structdef.genericdef=left.resultdef then
  179. begin
  180. resultdef:=cclassrefdef.create(current_structdef);
  181. defaultresultdef:=false;
  182. end
  183. else
  184. CGMessage(parser_e_cant_create_generics_of_this_type);
  185. end
  186. else
  187. message(parser_e_cant_create_generics_of_this_type);
  188. if defaultresultdef then
  189. resultdef:=cclassrefdef.create(left.resultdef);
  190. end
  191. else
  192. resultdef:=cclassrefdef.create(left.resultdef);
  193. end
  194. else
  195. CGMessage(parser_e_pointer_to_class_expected);
  196. end
  197. else
  198. CGMessage(parser_e_pointer_to_class_expected);
  199. end;
  200. end;
  201. function tloadvmtaddrnode.docompare(p: tnode): boolean;
  202. begin
  203. result:=inherited docompare(p);
  204. if result then
  205. result:=forcall=tloadvmtaddrnode(p).forcall;
  206. end;
  207. function tloadvmtaddrnode.dogetcopy: tnode;
  208. begin
  209. result:=inherited dogetcopy;
  210. tloadvmtaddrnode(result).forcall:=forcall;
  211. end;
  212. function tloadvmtaddrnode.pass_1 : tnode;
  213. var
  214. vs: tsym;
  215. begin
  216. result:=nil;
  217. expectloc:=LOC_REGISTER;
  218. if (left.nodetype=typen) and
  219. (cs_create_pic in current_settings.moduleswitches) then
  220. include(current_procinfo.flags,pi_needs_got);
  221. if left.nodetype<>typen then
  222. begin
  223. if (is_objc_class_or_protocol(left.resultdef) or
  224. is_objcclassref(left.resultdef)) then
  225. begin
  226. { on non-fragile ABI platforms, the ISA pointer may be opaque
  227. and we must call Object_getClass to obtain the real ISA
  228. pointer }
  229. if target_info.system in systems_objc_nfabi then
  230. begin
  231. result:=ccallnode.createinternfromunit('OBJC','OBJECT_GETCLASS',ccallparanode.create(left,nil));
  232. inserttypeconv_explicit(result,resultdef);
  233. end
  234. else
  235. result:=objcloadbasefield(left,'ISA');
  236. end
  237. else
  238. result:=ctypeconvnode.create_internal(load_vmt_for_self_node(left),resultdef);
  239. { reused }
  240. left:=nil;
  241. end
  242. else if not is_objcclass(left.resultdef) and
  243. not is_objcclassref(left.resultdef) then
  244. begin
  245. if not(nf_ignore_for_wpo in flags) and
  246. (not assigned(current_procinfo) or
  247. (po_inline in current_procinfo.procdef.procoptions) or
  248. wpoinfomanager.symbol_live(current_procinfo.procdef.mangledname)) then
  249. begin
  250. { keep track of which classes might be instantiated via a classrefdef }
  251. if (left.resultdef.typ=classrefdef) then
  252. tobjectdef(tclassrefdef(left.resultdef).pointeddef).register_maybe_created_object_type
  253. else if (left.resultdef.typ=objectdef) then
  254. tobjectdef(left.resultdef).register_maybe_created_object_type
  255. end
  256. end
  257. else if is_objcclass(left.resultdef) and
  258. not(forcall) then
  259. begin
  260. { call "class" method (= "classclass" in FPC), because otherwise
  261. we may use the class information before it has been
  262. initialized }
  263. vs:=search_struct_member(tobjectdef(left.resultdef),'CLASSCLASS');
  264. if not assigned(vs) or
  265. (vs.typ<>procsym) then
  266. internalerror(2011080601);
  267. { can't reuse "self", because it will be freed when we return }
  268. result:=ccallnode.create(nil,tprocsym(vs),vs.owner,self.getcopy,[],nil);
  269. end;
  270. end;
  271. {*****************************************************************************
  272. TLOADPARENTFPNODE
  273. *****************************************************************************}
  274. constructor tloadparentfpnode.create(pd: tprocdef; fpkind: tloadparentfpkind);
  275. begin
  276. inherited create(loadparentfpn,nil);
  277. if not assigned(pd) then
  278. internalerror(200309288);
  279. if (pd.parast.symtablelevel>current_procinfo.procdef.parast.symtablelevel) then
  280. internalerror(200309284);
  281. parentpd:=pd;
  282. kind:=fpkind;
  283. end;
  284. constructor tloadparentfpnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  285. begin
  286. inherited ppuload(t,ppufile);
  287. ppufile.getderef(parentpdderef);
  288. kind:=tloadparentfpkind(ppufile.getbyte);
  289. end;
  290. procedure tloadparentfpnode.ppuwrite(ppufile:tcompilerppufile);
  291. begin
  292. inherited ppuwrite(ppufile);
  293. ppufile.putderef(parentpdderef);
  294. ppufile.putbyte(byte(kind));
  295. end;
  296. procedure tloadparentfpnode.buildderefimpl;
  297. begin
  298. inherited buildderefimpl;
  299. parentpdderef.build(parentpd);
  300. end;
  301. procedure tloadparentfpnode.derefimpl;
  302. begin
  303. inherited derefimpl;
  304. parentpd:=tprocdef(parentpdderef.resolve);
  305. end;
  306. function tloadparentfpnode.docompare(p: tnode): boolean;
  307. begin
  308. result:=
  309. inherited docompare(p) and
  310. (tloadparentfpnode(p).parentpd=parentpd) and
  311. (tloadparentfpnode(p).kind=kind);
  312. end;
  313. function tloadparentfpnode.dogetcopy : tnode;
  314. var
  315. p : tloadparentfpnode;
  316. begin
  317. p:=tloadparentfpnode(inherited dogetcopy);
  318. p.parentpd:=parentpd;
  319. p.kind:=kind;
  320. dogetcopy:=p;
  321. end;
  322. function tloadparentfpnode.pass_typecheck:tnode;
  323. {$ifdef dummy}
  324. var
  325. currpi : tprocinfo;
  326. hsym : tparavarsym;
  327. {$endif dummy}
  328. begin
  329. result:=nil;
  330. resultdef:=parentfpvoidpointertype;
  331. {$ifdef dummy}
  332. { currently parentfps are never loaded in registers (FK) }
  333. if (current_procinfo.procdef.parast.symtablelevel<>parentpd.parast.symtablelevel) then
  334. begin
  335. currpi:=current_procinfo;
  336. { walk parents }
  337. while (currpi.procdef.owner.symtablelevel>parentpd.parast.symtablelevel) do
  338. begin
  339. currpi:=currpi.parent;
  340. if not assigned(currpi) then
  341. internalerror(2005040602);
  342. hsym:=tparavarsym(currpi.procdef.parast.Find('parentfp'));
  343. if not assigned(hsym) then
  344. internalerror(2005040601);
  345. hsym.varregable:=vr_none;
  346. end;
  347. end;
  348. {$endif dummy}
  349. end;
  350. function tloadparentfpnode.pass_1 : tnode;
  351. begin
  352. result:=nil;
  353. expectloc:=LOC_REGISTER;
  354. end;
  355. {*****************************************************************************
  356. TADDRNODE
  357. *****************************************************************************}
  358. constructor taddrnode.create(l : tnode);
  359. begin
  360. inherited create(addrn,l);
  361. getprocvardef:=nil;
  362. mark_read_written := true;
  363. end;
  364. constructor taddrnode.create_internal(l : tnode);
  365. begin
  366. self.create(l);
  367. include(flags,nf_internal);
  368. end;
  369. constructor taddrnode.create_internal_nomark(l : tnode);
  370. begin
  371. self.create_internal(l);
  372. mark_read_written := false;
  373. end;
  374. constructor taddrnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  375. begin
  376. inherited ppuload(t,ppufile);
  377. ppufile.getderef(getprocvardefderef);
  378. end;
  379. procedure taddrnode.ppuwrite(ppufile:tcompilerppufile);
  380. begin
  381. inherited ppuwrite(ppufile);
  382. ppufile.putderef(getprocvardefderef);
  383. end;
  384. procedure Taddrnode.mark_write;
  385. begin
  386. {@procvar:=nil is legal in Delphi mode.}
  387. left.mark_write;
  388. end;
  389. procedure taddrnode.buildderefimpl;
  390. begin
  391. inherited buildderefimpl;
  392. getprocvardefderef.build(getprocvardef);
  393. end;
  394. procedure taddrnode.derefimpl;
  395. begin
  396. inherited derefimpl;
  397. getprocvardef:=tprocvardef(getprocvardefderef.resolve);
  398. end;
  399. function taddrnode.docompare(p: tnode): boolean;
  400. begin
  401. result:=
  402. inherited docompare(p) and
  403. (taddrnode(p).getprocvardef=getprocvardef);
  404. end;
  405. function taddrnode.dogetcopy : tnode;
  406. var
  407. p : taddrnode;
  408. begin
  409. p:=taddrnode(inherited dogetcopy);
  410. p.getprocvardef:=getprocvardef;
  411. dogetcopy:=p;
  412. end;
  413. function taddrnode.pass_typecheck:tnode;
  414. var
  415. hp : tnode;
  416. hsym : tfieldvarsym;
  417. isprocvar : boolean;
  418. procpointertype: tdef;
  419. begin
  420. result:=nil;
  421. typecheckpass(left);
  422. if codegenerror then
  423. exit;
  424. make_not_regable(left,[ra_addr_regable,ra_addr_taken]);
  425. { don't allow constants, for internal use we also
  426. allow taking the address of strings and sets }
  427. if is_constnode(left) and
  428. not(
  429. (nf_internal in flags) and
  430. (left.nodetype in [stringconstn,setconstn])
  431. ) then
  432. begin
  433. CGMessagePos(left.fileinfo,type_e_no_addr_of_constant);
  434. exit;
  435. end;
  436. { Handle @proc special, also @procvar in tp-mode needs
  437. special handling }
  438. if (left.resultdef.typ=procdef) or
  439. (
  440. { in case of nf_internal, follow the normal FPC semantics so that
  441. we can easily get the actual address of a procvar }
  442. not(nf_internal in flags) and
  443. (left.resultdef.typ=procvardef) and
  444. ((m_tp_procvar in current_settings.modeswitches) or
  445. (m_mac_procvar in current_settings.modeswitches))
  446. ) then
  447. begin
  448. isprocvar:=(left.resultdef.typ=procvardef);
  449. if not isprocvar then
  450. begin
  451. left:=ctypeconvnode.create_proc_to_procvar(left);
  452. left.fileinfo:=fileinfo;
  453. typecheckpass(left);
  454. end;
  455. { In tp procvar mode the result is always a voidpointer. Insert
  456. a typeconversion to voidpointer. For methodpointers we need
  457. to load the proc field }
  458. if (m_tp_procvar in current_settings.modeswitches) or
  459. (m_mac_procvar in current_settings.modeswitches) then
  460. begin
  461. if tabstractprocdef(left.resultdef).is_addressonly then
  462. begin
  463. result:=ctypeconvnode.create_internal(left,tabstractprocdef(left.resultdef).address_type);
  464. include(result.flags,nf_load_procvar);
  465. left:=nil;
  466. end
  467. else
  468. begin
  469. { For procvars and for nested routines we need to return
  470. the proc field of the methodpointer }
  471. if isprocvar or
  472. is_nested_pd(tabstractprocdef(left.resultdef)) then
  473. begin
  474. if tabstractprocdef(left.resultdef).is_methodpointer then
  475. procpointertype:=methodpointertype
  476. else
  477. procpointertype:=nestedprocpointertype;
  478. { find proc field in methodpointer record }
  479. hsym:=tfieldvarsym(trecorddef(procpointertype).symtable.Find('proc'));
  480. if not assigned(hsym) then
  481. internalerror(200412041);
  482. { Load tmehodpointer(left).proc }
  483. result:=csubscriptnode.create(
  484. hsym,
  485. ctypeconvnode.create_internal(left,procpointertype));
  486. left:=nil;
  487. end
  488. else
  489. CGMessage(type_e_variable_id_expected);
  490. end;
  491. end
  492. else
  493. begin
  494. { Return the typeconvn only }
  495. result:=left;
  496. left:=nil;
  497. end;
  498. end
  499. else
  500. begin
  501. hp:=left;
  502. while assigned(hp) and (hp.nodetype in [typeconvn,derefn,subscriptn]) do
  503. hp:=tunarynode(hp).left;
  504. if not assigned(hp) then
  505. internalerror(200412042);
  506. if typecheck_non_proc(hp,result) then
  507. begin
  508. if assigned(result) then
  509. exit;
  510. end
  511. else
  512. CGMessage(type_e_variable_id_expected);
  513. end;
  514. if mark_read_written then
  515. begin
  516. { This is actually only "read", but treat it nevertheless as }
  517. { modified due to the possible use of pointers }
  518. { To avoid false positives regarding "uninitialised" }
  519. { warnings when using arrays, perform it in two steps }
  520. set_varstate(left,vs_written,[]);
  521. { vsf_must_be_valid so it doesn't get changed into }
  522. { vsf_referred_not_inited }
  523. set_varstate(left,vs_read,[vsf_must_be_valid]);
  524. end;
  525. if not(assigned(result)) then
  526. result:=simplify(false);
  527. end;
  528. function taddrnode.simplify(forinline : boolean) : tnode;
  529. var
  530. hsym : tfieldvarsym;
  531. begin
  532. result:=nil;
  533. if ((left.nodetype=subscriptn) and
  534. (tsubscriptnode(left).left.nodetype=derefn) and
  535. (tsubscriptnode(left).left.resultdef.typ=recorddef) and
  536. (tderefnode(tsubscriptnode(left).left).left.nodetype=niln)) or
  537. ((left.nodetype=subscriptn) and
  538. (tsubscriptnode(left).left.nodetype=typeconvn) and
  539. (tsubscriptnode(left).left.resultdef.typ=recorddef) and
  540. (ttypeconvnode(tsubscriptnode(left).left).left.nodetype=derefn) and
  541. (tderefnode(ttypeconvnode(tsubscriptnode(left).left).left).left.nodetype=niln)) then
  542. begin
  543. hsym:=tsubscriptnode(left).vs;
  544. if tabstractrecordsymtable(hsym.owner).is_packed then
  545. result:=cpointerconstnode.create(hsym.fieldoffset div 8,resultdef)
  546. else
  547. result:=cpointerconstnode.create(hsym.fieldoffset,resultdef);
  548. end;
  549. end;
  550. function taddrnode.typecheck_non_proc(realsource: tnode; out res: tnode): boolean;
  551. var
  552. hp : tnode;
  553. hsym : tfieldvarsym;
  554. offset: asizeint;
  555. begin
  556. result:=false;
  557. res:=nil;
  558. if (realsource.nodetype=loadn) and
  559. (tloadnode(realsource).symtableentry.typ=absolutevarsym) and
  560. (tabsolutevarsym(tloadnode(realsource).symtableentry).abstyp=toaddr) then
  561. begin
  562. offset:=tabsolutevarsym(tloadnode(realsource).symtableentry).addroffset;
  563. hp:=left;
  564. while assigned(hp)and(hp.nodetype=subscriptn) do
  565. begin
  566. hsym:=tsubscriptnode(hp).vs;
  567. if tabstractrecordsymtable(hsym.owner).is_packed then
  568. begin
  569. { can't calculate the address of a non-byte aligned field }
  570. if (hsym.fieldoffset mod 8)<>0 then
  571. begin
  572. CGMessagePos(hp.fileinfo,parser_e_packed_element_no_var_addr);
  573. exit
  574. end;
  575. inc(offset,hsym.fieldoffset div 8)
  576. end
  577. else
  578. inc(offset,hsym.fieldoffset);
  579. hp:=tunarynode(hp).left;
  580. end;
  581. if nf_typedaddr in flags then
  582. res:=cpointerconstnode.create(offset,cpointerdef.getreusable(left.resultdef))
  583. else
  584. res:=cpointerconstnode.create(offset,voidpointertype);
  585. result:=true;
  586. end
  587. else if (nf_internal in flags) or
  588. valid_for_addr(left,true) then
  589. begin
  590. if not(nf_typedaddr in flags) then
  591. resultdef:=voidpointertype
  592. else
  593. resultdef:=cpointerdef.getreusable(left.resultdef);
  594. result:=true;
  595. end
  596. end;
  597. function taddrnode.pass_1 : tnode;
  598. begin
  599. result:=nil;
  600. firstpass(left);
  601. if codegenerror then
  602. exit;
  603. { is this right for object of methods ?? }
  604. expectloc:=LOC_REGISTER;
  605. end;
  606. {*****************************************************************************
  607. TDEREFNODE
  608. *****************************************************************************}
  609. constructor tderefnode.create(l : tnode);
  610. begin
  611. inherited create(derefn,l);
  612. end;
  613. function tderefnode.pass_typecheck:tnode;
  614. begin
  615. result:=nil;
  616. typecheckpass(left);
  617. set_varstate(left,vs_read,[vsf_must_be_valid]);
  618. if codegenerror then
  619. exit;
  620. { tp procvar support }
  621. maybe_call_procvar(left,true);
  622. if left.resultdef.typ=pointerdef then
  623. resultdef:=tpointerdef(left.resultdef).pointeddef
  624. else
  625. CGMessage(parser_e_invalid_qualifier);
  626. end;
  627. procedure Tderefnode.mark_write;
  628. begin
  629. include(flags,nf_write);
  630. end;
  631. function tderefnode.pass_1 : tnode;
  632. begin
  633. result:=nil;
  634. firstpass(left);
  635. if codegenerror then
  636. exit;
  637. expectloc:=LOC_REFERENCE;
  638. end;
  639. {*****************************************************************************
  640. TSUBSCRIPTNODE
  641. *****************************************************************************}
  642. constructor tsubscriptnode.create(varsym : tsym;l : tnode);
  643. begin
  644. inherited create(subscriptn,l);
  645. { vs should be changed to tsym! }
  646. vs:=tfieldvarsym(varsym);
  647. end;
  648. constructor tsubscriptnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  649. begin
  650. inherited ppuload(t,ppufile);
  651. ppufile.getderef(vsderef);
  652. end;
  653. procedure tsubscriptnode.ppuwrite(ppufile:tcompilerppufile);
  654. begin
  655. inherited ppuwrite(ppufile);
  656. ppufile.putderef(vsderef);
  657. end;
  658. procedure tsubscriptnode.buildderefimpl;
  659. begin
  660. inherited buildderefimpl;
  661. vsderef.build(vs);
  662. end;
  663. procedure tsubscriptnode.derefimpl;
  664. begin
  665. inherited derefimpl;
  666. vs:=tfieldvarsym(vsderef.resolve);
  667. end;
  668. function tsubscriptnode.dogetcopy : tnode;
  669. var
  670. p : tsubscriptnode;
  671. begin
  672. p:=tsubscriptnode(inherited dogetcopy);
  673. p.vs:=vs;
  674. dogetcopy:=p;
  675. end;
  676. function tsubscriptnode.pass_typecheck:tnode;
  677. begin
  678. result:=nil;
  679. typecheckpass(left);
  680. { tp procvar support }
  681. maybe_call_procvar(left,true);
  682. resultdef:=vs.vardef;
  683. // don't put records from which we load float fields
  684. // in integer registers
  685. if (left.resultdef.typ=recorddef) and
  686. (resultdef.typ=floatdef) then
  687. make_not_regable(left,[ra_addr_regable]);
  688. end;
  689. procedure Tsubscriptnode.mark_write;
  690. begin
  691. include(flags,nf_write);
  692. { if an element of a record is written, then the whole record is changed/it is written to it,
  693. for data types being implicit pointers this does not apply as the object itself does not change }
  694. if not(is_implicit_pointer_object_type(left.resultdef)) then
  695. left.mark_write;
  696. end;
  697. function tsubscriptnode.pass_1 : tnode;
  698. begin
  699. result:=nil;
  700. firstpass(left);
  701. if codegenerror then
  702. exit;
  703. { several object types must be dereferenced implicitly }
  704. if is_implicit_pointer_object_type(left.resultdef) then
  705. expectloc:=LOC_REFERENCE
  706. else
  707. begin
  708. case left.expectloc of
  709. { if a floating point value is casted into a record, it
  710. can happen that we get here an fpu or mm register }
  711. LOC_CMMREGISTER,
  712. LOC_CFPUREGISTER,
  713. LOC_MMREGISTER,
  714. LOC_FPUREGISTER,
  715. LOC_CONSTANT,
  716. LOC_REGISTER,
  717. LOC_SUBSETREG:
  718. // can happen for function results on win32 and darwin/x86
  719. if (left.resultdef.size > sizeof(pint)) then
  720. expectloc:=LOC_REFERENCE
  721. else
  722. expectloc:=LOC_SUBSETREG;
  723. LOC_CREGISTER,
  724. LOC_CSUBSETREG:
  725. expectloc:=LOC_CSUBSETREG;
  726. LOC_REFERENCE,
  727. LOC_CREFERENCE:
  728. expectloc:=left.expectloc;
  729. else internalerror(20060521);
  730. end;
  731. end;
  732. end;
  733. function tsubscriptnode.docompare(p: tnode): boolean;
  734. begin
  735. docompare :=
  736. inherited docompare(p) and
  737. (vs = tsubscriptnode(p).vs);
  738. end;
  739. {*****************************************************************************
  740. TVECNODE
  741. *****************************************************************************}
  742. constructor tvecnode.create(l,r : tnode);
  743. begin
  744. inherited create(vecn,l,r);
  745. end;
  746. function tvecnode.pass_typecheck:tnode;
  747. var
  748. htype,elementdef,elementptrdef : tdef;
  749. newordtyp: tordtype;
  750. valid : boolean;
  751. begin
  752. result:=nil;
  753. typecheckpass(left);
  754. typecheckpass(right);
  755. { implicitly convert stringconstant to stringdef,
  756. see tbs/tb0476.pp for a test }
  757. if (left.nodetype=stringconstn) and
  758. (tstringconstnode(left).cst_type=cst_conststring) then
  759. begin
  760. if tstringconstnode(left).len>255 then
  761. inserttypeconv(left,getansistringdef)
  762. else
  763. inserttypeconv(left,cshortstringtype);
  764. end;
  765. { In p[1] p is always valid, it is not possible to
  766. declared a shortstring or normal array that has
  767. undefined number of elements. Dynamic array and
  768. ansi/widestring needs to be valid }
  769. valid:=is_dynamic_array(left.resultdef) or
  770. is_ansistring(left.resultdef) or
  771. is_wide_or_unicode_string(left.resultdef) or
  772. { implicit pointer dereference -> pointer is read }
  773. (left.resultdef.typ = pointerdef);
  774. if valid then
  775. set_varstate(left,vs_read,[vsf_must_be_valid]);
  776. {
  777. A vecn is, just like a loadn, always part of an expression with its
  778. own read/write and must_be_valid semantics. Therefore we don't have
  779. to do anything else here, just like for loadn's
  780. }
  781. set_varstate(right,vs_read,[vsf_must_be_valid]);
  782. if codegenerror then
  783. exit;
  784. { maybe type conversion for the index value, but
  785. do not convert range nodes }
  786. if (right.nodetype<>rangen) then
  787. case left.resultdef.typ of
  788. arraydef:
  789. begin
  790. htype:=Tarraydef(left.resultdef).rangedef;
  791. if ado_isvariant in Tarraydef(left.resultdef).arrayoptions then
  792. {Variant arrays are a special array, can have negative indexes and would therefore
  793. need s32bit. However, they should not appear in a vecn, as they are handled in
  794. handle_variantarray in pexpr.pas. Therefore, encountering a variant array is an
  795. internal error... }
  796. internalerror(200707031)
  797. { open array and array constructor range checking is handled
  798. below at the node level, where the validity of the index
  799. will be checked -> use a regular type conversion to either
  800. the signed or unsigned native int type to prevent another
  801. range check from getting inserted here (unless the type is
  802. larger than the int type). Exception: if it's an ordinal
  803. constant, because then this check should be performed at
  804. compile time }
  805. else if is_open_array(left.resultdef) or
  806. is_array_constructor(left.resultdef) then
  807. begin
  808. if is_signed(right.resultdef) and
  809. not is_constnode(right) then
  810. inserttypeconv(right,sinttype)
  811. else
  812. inserttypeconv(right,uinttype)
  813. end
  814. else if is_special_array(left.resultdef) then
  815. {Arrays without a high bound (dynamic arrays, open arrays) are zero based,
  816. convert indexes into these arrays to aword.}
  817. inserttypeconv(right,uinttype)
  818. { note: <> rather than </>, because indexing e.g. an array 0..0
  819. must not result in truncating the indexing value from 2/4/8
  820. bytes to 1 byte (with range checking off, the full index
  821. value must be used) }
  822. else if (htype.typ=enumdef) and
  823. (right.resultdef.typ=enumdef) and
  824. (tenumdef(htype).basedef=tenumdef(right.resultdef).basedef) and
  825. ((tarraydef(left.resultdef).lowrange<>tenumdef(htype).min) or
  826. (tarraydef(left.resultdef).highrange<>tenumdef(htype).max)) then
  827. {Convert array indexes to low_bound..high_bound.}
  828. inserttypeconv(right,cenumdef.create_subrange(tenumdef(right.resultdef),
  829. asizeint(Tarraydef(left.resultdef).lowrange),
  830. asizeint(Tarraydef(left.resultdef).highrange)
  831. ))
  832. else if (htype.typ=orddef) and
  833. { right can also be a variant or another type with
  834. overloaded assignment }
  835. (right.resultdef.typ=orddef) and
  836. { don't try to create boolean types with custom ranges }
  837. not is_boolean(right.resultdef) and
  838. { ordtype determines the size of the loaded value -> make
  839. sure we don't truncate }
  840. ((Torddef(right.resultdef).ordtype<>torddef(htype).ordtype) or
  841. (tarraydef(left.resultdef).lowrange<>torddef(htype).low) or
  842. (tarraydef(left.resultdef).highrange<>torddef(htype).high)) then
  843. {Convert array indexes to low_bound..high_bound.}
  844. begin
  845. if (right.resultdef.typ=orddef)
  846. {$ifndef cpu64bitaddr}
  847. { do truncate 64 bit values on 32 bit cpus, since
  848. a) the arrays cannot be > 32 bit anyway
  849. b) their code generators can't directly handle 64 bit
  850. loads
  851. }
  852. and not is_64bit(right.resultdef)
  853. {$endif not cpu64bitaddr}
  854. then
  855. newordtyp:=Torddef(right.resultdef).ordtype
  856. else
  857. newordtyp:=torddef(ptrsinttype).ordtype;
  858. inserttypeconv(right,corddef.create(newordtyp,
  859. int64(Tarraydef(left.resultdef).lowrange),
  860. int64(Tarraydef(left.resultdef).highrange),
  861. true
  862. ))
  863. end
  864. else
  865. inserttypeconv(right,htype)
  866. end;
  867. stringdef:
  868. if is_open_string(left.resultdef) then
  869. inserttypeconv(right,u8inttype)
  870. else if is_shortstring(left.resultdef) then
  871. {Convert shortstring indexes to 0..length.}
  872. inserttypeconv(right,corddef.create(u8bit,0,int64(Tstringdef(left.resultdef).len),true))
  873. else
  874. {Convert indexes into dynamically allocated strings to aword.}
  875. inserttypeconv(right,uinttype);
  876. pointerdef:
  877. inserttypeconv(right,tpointerdef(left.resultdef).pointer_arithmetic_int_type);
  878. else
  879. {Others, (are there any?) indexes to aint.}
  880. inserttypeconv(right,sinttype);
  881. end;
  882. { although we never put regular arrays or shortstrings in registers,
  883. it's possible that another type was typecasted to a small record
  884. that has a field of one of these types -> in that case the record
  885. can't be a regvar either }
  886. if ((left.resultdef.typ=arraydef) and
  887. not is_special_array(left.resultdef)) or
  888. ((left.resultdef.typ=stringdef) and
  889. (tstringdef(left.resultdef).stringtype in [st_shortstring,st_longstring])) then
  890. make_not_regable(left,[ra_addr_regable]);
  891. case left.resultdef.typ of
  892. arraydef :
  893. begin
  894. { check type of the index value }
  895. if (compare_defs(right.resultdef,tarraydef(left.resultdef).rangedef,right.nodetype)=te_incompatible) then
  896. IncompatibleTypes(right.resultdef,tarraydef(left.resultdef).rangedef);
  897. if right.nodetype=rangen then
  898. resultdef:=left.resultdef
  899. else
  900. resultdef:=Tarraydef(left.resultdef).elementdef;
  901. result:=gen_array_rangecheck;
  902. if assigned(result) then
  903. exit;
  904. { in case of a bitpacked array of enums that are size 2 (due to
  905. packenum 2) but whose values all fit in one byte, the size of
  906. bitpacked array elements will be 1 byte while the resultdef of
  907. will currently say it's two bytes) -> create a temp enumdef
  908. with packenum=1 for the resultdef as subtype of the main
  909. enumdef }
  910. if is_enum(resultdef) and
  911. is_packed_array(left.resultdef) and
  912. ((tarraydef(left.resultdef).elepackedbitsize div 8) <> resultdef.size) then
  913. begin
  914. resultdef:=cenumdef.create_subrange(tenumdef(resultdef),tenumdef(resultdef).min,tenumdef(resultdef).max);
  915. tenumdef(resultdef).calcsavesize(1);
  916. end
  917. end;
  918. pointerdef :
  919. begin
  920. { are we accessing a pointer[], then convert the pointer to
  921. an array first, in FPC this is allowed for all pointers
  922. (except voidpointer) in delphi/tp7 it's only allowed for pchars. }
  923. if not is_voidpointer(left.resultdef) and
  924. (
  925. (cs_pointermath in current_settings.localswitches) or
  926. tpointerdef(left.resultdef).has_pointer_math or
  927. is_pchar(left.resultdef) or
  928. is_pwidechar(left.resultdef)
  929. ) then
  930. begin
  931. { convert pointer to array }
  932. htype:=carraydef.create_from_pointer(tpointerdef(left.resultdef));
  933. inserttypeconv(left,htype);
  934. if right.nodetype=rangen then
  935. resultdef:=htype
  936. else
  937. resultdef:=tarraydef(htype).elementdef;
  938. end
  939. else
  940. CGMessage(type_e_array_required);
  941. end;
  942. stringdef :
  943. begin
  944. case tstringdef(left.resultdef).stringtype of
  945. st_unicodestring,
  946. st_widestring :
  947. begin
  948. elementdef:=cwidechartype;
  949. elementptrdef:=widecharpointertype;
  950. end;
  951. st_ansistring,
  952. st_longstring,
  953. st_shortstring :
  954. begin
  955. elementdef:=cansichartype;
  956. elementptrdef:=charpointertype;
  957. end;
  958. else
  959. internalerror(2013112902);
  960. end;
  961. if right.nodetype=rangen then
  962. begin
  963. htype:=carraydef.create_from_pointer(tpointerdef(elementptrdef));
  964. resultdef:=htype;
  965. end
  966. else
  967. begin
  968. { indexed access to 0 element is only allowed for shortstrings or if
  969. zero based strings is turned on }
  970. if (right.nodetype=ordconstn) and
  971. (Tordconstnode(right).value.svalue=0) and
  972. not is_shortstring(left.resultdef) and
  973. not(cs_zerobasedstrings in current_settings.localswitches) then
  974. CGMessage(cg_e_can_access_element_zero);
  975. resultdef:=elementdef;
  976. end;
  977. end;
  978. variantdef :
  979. resultdef:=cvarianttype;
  980. else
  981. CGMessage(type_e_array_required);
  982. end;
  983. end;
  984. procedure Tvecnode.mark_write;
  985. begin
  986. include(flags,nf_write);
  987. { see comment in tsubscriptnode.mark_write }
  988. if not(is_implicit_pointer_object_type(left.resultdef)) then
  989. left.mark_write;
  990. end;
  991. function tvecnode.pass_1 : tnode;
  992. begin
  993. result:=nil;
  994. firstpass(left);
  995. firstpass(right);
  996. if codegenerror then
  997. exit;
  998. if (nf_callunique in flags) and
  999. (is_ansistring(left.resultdef) or
  1000. is_unicodestring(left.resultdef) or
  1001. (is_widestring(left.resultdef) and not(tf_winlikewidestring in target_info.flags))) then
  1002. begin
  1003. left := ctypeconvnode.create_internal(ccallnode.createintern('fpc_'+tstringdef(left.resultdef).stringtypname+'_unique',
  1004. ccallparanode.create(
  1005. ctypeconvnode.create_internal(left,voidpointertype),nil)),
  1006. left.resultdef);
  1007. firstpass(left);
  1008. { double resultdef passes somwhere else may cause this to be }
  1009. { reset though :/ }
  1010. exclude(flags,nf_callunique);
  1011. end
  1012. else if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
  1013. exclude(flags,nf_callunique);
  1014. { a range node as array index can only appear in function calls, and
  1015. those convert the range node into something else in
  1016. tcallnode.gen_high_tree }
  1017. if (right.nodetype=rangen) then
  1018. CGMessagePos(right.fileinfo,parser_e_illegal_expression)
  1019. else if left.resultdef.typ=arraydef then
  1020. result:=first_arraydef
  1021. else
  1022. begin
  1023. if left.expectloc=LOC_CREFERENCE then
  1024. expectloc:=LOC_CREFERENCE
  1025. else
  1026. expectloc:=LOC_REFERENCE
  1027. end;
  1028. end;
  1029. function tvecnode.first_arraydef: tnode;
  1030. begin
  1031. result:=nil;
  1032. if (not is_packed_array(left.resultdef)) or
  1033. ((tarraydef(left.resultdef).elepackedbitsize mod 8) = 0) then
  1034. if left.expectloc=LOC_CREFERENCE then
  1035. expectloc:=LOC_CREFERENCE
  1036. else
  1037. expectloc:=LOC_REFERENCE
  1038. else
  1039. if left.expectloc=LOC_CREFERENCE then
  1040. expectloc:=LOC_CSUBSETREF
  1041. else
  1042. expectloc:=LOC_SUBSETREF;
  1043. end;
  1044. function tvecnode.gen_array_rangecheck: tnode;
  1045. var
  1046. htype: tdef;
  1047. temp: ttempcreatenode;
  1048. stat: tstatementnode;
  1049. indextree: tnode;
  1050. hightree: tnode;
  1051. begin
  1052. result:=nil;
  1053. { Range checking an array of const/open array/dynamic array is
  1054. more complicated than regular arrays, because the bounds must
  1055. be checked dynamically. Additionally, in case of array of const
  1056. and open array we need the high parameter, which must not be
  1057. made a regvar in case this is a nested rountine relative to the
  1058. array parameter -> generate te check at the node tree level
  1059. rather than in the code generator }
  1060. if (cs_check_range in current_settings.localswitches) and
  1061. (is_open_array(left.resultdef) or
  1062. is_array_of_const(left.resultdef)) and
  1063. (right.nodetype<>rangen) then
  1064. begin
  1065. { expect to find the load node }
  1066. if get_open_const_array(left).nodetype<>loadn then
  1067. internalerror(2014040601);
  1068. { cdecl functions don't have high() so we can not check the range }
  1069. { (can't use current_procdef, since it may be a nested procedure) }
  1070. if not(tprocdef(tparasymtable(tparavarsym(tloadnode(get_open_const_array(left)).symtableentry).owner).defowner).proccalloption in cdecl_pocalls) then
  1071. begin
  1072. temp:=nil;
  1073. result:=internalstatements(stat);
  1074. { can't use node_complexity here, assumes that the code has
  1075. already been firstpassed }
  1076. if not is_const(right) then
  1077. begin
  1078. temp:=ctempcreatenode.create(right.resultdef,right.resultdef.size,tt_persistent,true);
  1079. addstatement(stat,temp);
  1080. { needed so we can typecheck its temprefnodes }
  1081. typecheckpass(tnode(temp));
  1082. addstatement(stat,cassignmentnode.create(
  1083. ctemprefnode.create(temp),right)
  1084. );
  1085. right:=ctemprefnode.create(temp);
  1086. { right.resultdef is used below }
  1087. typecheckpass(right);
  1088. end;
  1089. { range check will be made explicit here }
  1090. exclude(localswitches,cs_check_range);
  1091. hightree:=load_high_value_node(tparavarsym(tloadnode(
  1092. get_open_const_array(left)).symtableentry));
  1093. { make index unsigned so we only need one comparison;
  1094. lower bound is always zero for these arrays, but
  1095. hightree can be -1 in case the array was empty ->
  1096. add 1 before comparing (ignoring overflows) }
  1097. htype:=get_unsigned_inttype(right.resultdef);
  1098. inserttypeconv_explicit(hightree,htype);
  1099. hightree:=caddnode.create(addn,hightree,genintconstnode(1));
  1100. hightree.localswitches:=hightree.localswitches-[cs_check_range,
  1101. cs_check_overflow];
  1102. indextree:=ctypeconvnode.create_explicit(right.getcopy,htype);
  1103. { range error if index >= hightree+1 }
  1104. addstatement(stat,
  1105. cifnode.create_internal(
  1106. caddnode.create_internal(gten,indextree,hightree),
  1107. ccallnode.createintern('fpc_rangeerror',nil),
  1108. nil
  1109. )
  1110. );
  1111. if assigned(temp) then
  1112. addstatement(stat,ctempdeletenode.create_normal_temp(temp));
  1113. addstatement(stat,self.getcopy);
  1114. end;
  1115. end;
  1116. end;
  1117. {*****************************************************************************
  1118. TWITHNODE
  1119. *****************************************************************************}
  1120. constructor twithnode.create(l:tnode);
  1121. begin
  1122. inherited create(withn,l);
  1123. fileinfo:=l.fileinfo;
  1124. end;
  1125. destructor twithnode.destroy;
  1126. begin
  1127. inherited destroy;
  1128. end;
  1129. constructor twithnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1130. begin
  1131. inherited ppuload(t,ppufile);
  1132. end;
  1133. procedure twithnode.ppuwrite(ppufile:tcompilerppufile);
  1134. begin
  1135. inherited ppuwrite(ppufile);
  1136. end;
  1137. function twithnode.dogetcopy : tnode;
  1138. var
  1139. p : twithnode;
  1140. begin
  1141. p:=twithnode(inherited dogetcopy);
  1142. result:=p;
  1143. end;
  1144. function twithnode.pass_typecheck:tnode;
  1145. begin
  1146. result:=nil;
  1147. resultdef:=voidtype;
  1148. if assigned(left) then
  1149. typecheckpass(left);
  1150. end;
  1151. function twithnode.pass_1 : tnode;
  1152. begin
  1153. result:=nil;
  1154. expectloc:=LOC_VOID;
  1155. end;
  1156. function twithnode.docompare(p: tnode): boolean;
  1157. begin
  1158. docompare :=
  1159. inherited docompare(p);
  1160. end;
  1161. function is_big_untyped_addrnode(p: tnode): boolean;
  1162. begin
  1163. is_big_untyped_addrnode:=(p.nodetype=addrn) and
  1164. not (nf_typedaddr in p.flags) and (taddrnode(p).left.resultdef.size > 1);
  1165. end;
  1166. end.