ncal.pas 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This file implements the node for sub procedure calling.
  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 ncal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,cclasses,
  22. globtype,
  23. paramgr,parabase,
  24. node,nbas,nutils,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symsym,symdef,symtable;
  29. type
  30. tcallnodeflag = (
  31. cnf_restypeset,
  32. cnf_return_value_used,
  33. cnf_inherited,
  34. cnf_anon_inherited,
  35. cnf_new_call,
  36. cnf_dispose_call,
  37. cnf_member_call, { called with implicit methodpointer tree }
  38. cnf_uses_varargs { varargs are used in the declaration }
  39. );
  40. tcallnodeflags = set of tcallnodeflag;
  41. tcallnode = class(tbinarynode)
  42. private
  43. { info for inlining }
  44. inlinelocals: TList;
  45. { number of parameters passed from the source, this does not include the hidden parameters }
  46. paralength : smallint;
  47. function gen_self_tree_methodpointer:tnode;
  48. function gen_self_tree:tnode;
  49. function gen_vmt_tree:tnode;
  50. procedure bind_parasym;
  51. { function return node, this is used to pass the data for a
  52. ret_in_param return value }
  53. _funcretnode : tnode;
  54. procedure setfuncretnode(const returnnode: tnode);
  55. procedure convert_carg_array_of_const;
  56. procedure order_parameters;
  57. procedure createinlineparas(var createstatement, deletestatement: tstatementnode);
  58. function replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  59. procedure createlocaltemps(p:TNamedIndexItem;arg:pointer);
  60. function pass1_inline:tnode;
  61. protected
  62. pushedparasize : longint;
  63. public
  64. { the symbol containing the definition of the procedure }
  65. { to call }
  66. symtableprocentry : tprocsym;
  67. symtableprocentryderef : tderef;
  68. { symtable where the entry was found, needed for with support }
  69. symtableproc : tsymtable;
  70. { the definition of the procedure to call }
  71. procdefinition : tabstractprocdef;
  72. procdefinitionderef : tderef;
  73. { tree that contains the pointer to the object for this method }
  74. methodpointerinit,
  75. methodpointerdone : tblocknode;
  76. methodpointer : tnode;
  77. {$ifdef PASS2INLINE}
  78. { inline function body }
  79. inlinecode : tnode;
  80. {$endif PASS2INLINE}
  81. { varargs parasyms }
  82. varargsparas : tvarargsparalist;
  83. { node that specifies where the result should be put for calls }
  84. { that return their result in a parameter }
  85. property funcretnode: tnode read _funcretnode write setfuncretnode;
  86. { separately specified resulttype for some compilerprocs (e.g. }
  87. { you can't have a function with an "array of char" resulttype }
  88. { the RTL) (JM) }
  89. restype: ttype;
  90. callnodeflags : tcallnodeflags;
  91. { only the processor specific nodes need to override this }
  92. { constructor }
  93. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);virtual;
  94. constructor create_procvar(l,r:tnode);
  95. constructor createintern(const name: string; params: tnode);
  96. constructor createinternres(const name: string; params: tnode; const res: ttype);
  97. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  98. destructor destroy;override;
  99. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. procedure buildderefimpl;override;
  102. procedure derefimpl;override;
  103. function getcopy : tnode;override;
  104. { Goes through all symbols in a class and subclasses and calls
  105. verify abstract for each .
  106. }
  107. procedure verifyabstractcalls;
  108. { called for each definition in a class and verifies if a method
  109. is abstract or not, if it is abstract, give out a warning
  110. }
  111. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  112. procedure insertintolist(l : tnodelist);override;
  113. function pass_1 : tnode;override;
  114. function det_resulttype:tnode;override;
  115. {$ifdef state_tracking}
  116. function track_state_pass(exec_known:boolean):boolean;override;
  117. {$endif state_tracking}
  118. function docompare(p: tnode): boolean; override;
  119. procedure printnodedata(var t:text);override;
  120. function para_count:longint;
  121. function get_load_methodpointer:tnode;
  122. private
  123. AbstractMethodsList : TStringList;
  124. end;
  125. tcallnodeclass = class of tcallnode;
  126. tcallparaflag = (
  127. cpf_is_colon_para,
  128. cpf_varargs_para { belongs this para to varargs }
  129. );
  130. tcallparaflags = set of tcallparaflag;
  131. tcallparanode = class(tbinarynode)
  132. public
  133. callparaflags : tcallparaflags;
  134. parasym : tparavarsym;
  135. used_by_callnode : boolean;
  136. { only the processor specific nodes need to override this }
  137. { constructor }
  138. constructor create(expr,next : tnode);virtual;
  139. destructor destroy;override;
  140. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  141. procedure ppuwrite(ppufile:tcompilerppufile);override;
  142. function getcopy : tnode;override;
  143. procedure insertintolist(l : tnodelist);override;
  144. procedure get_paratype;
  145. procedure insert_typeconv(do_count : boolean);
  146. procedure det_registers;
  147. procedure firstcallparan;
  148. procedure secondcallparan;virtual;abstract;
  149. function docompare(p: tnode): boolean; override;
  150. procedure printnodetree(var t:text);override;
  151. end;
  152. tcallparanodeclass = class of tcallparanode;
  153. function reverseparameters(p: tcallparanode): tcallparanode;
  154. var
  155. ccallnode : tcallnodeclass;
  156. ccallparanode : tcallparanodeclass;
  157. { Current callnode, this is needed for having a link
  158. between the callparanodes and the callnode they belong to }
  159. aktcallnode : tcallnode;
  160. implementation
  161. uses
  162. systems,
  163. verbose,globals,
  164. symconst,defutil,defcmp,
  165. htypechk,pass_1,
  166. ncnv,nld,ninl,nadd,ncon,nmem,
  167. procinfo,
  168. cgbase
  169. ;
  170. type
  171. tobjectinfoitem = class(tlinkedlistitem)
  172. objinfo : tobjectdef;
  173. constructor create(def : tobjectdef);
  174. end;
  175. {****************************************************************************
  176. HELPERS
  177. ****************************************************************************}
  178. function reverseparameters(p: tcallparanode): tcallparanode;
  179. var
  180. hp1, hp2: tcallparanode;
  181. begin
  182. hp1:=nil;
  183. while assigned(p) do
  184. begin
  185. { pull out }
  186. hp2:=p;
  187. p:=tcallparanode(p.right);
  188. { pull in }
  189. hp2.right:=hp1;
  190. hp1:=hp2;
  191. end;
  192. reverseparameters:=hp1;
  193. end;
  194. procedure maybe_load_para_in_temp(var p:tnode);
  195. function is_simple_node(hp:tnode):boolean;
  196. begin
  197. is_simple_node:=(hp.nodetype in [typen,loadvmtaddrn,loadn,arrayconstructorn]);
  198. end;
  199. var
  200. hp,
  201. loadp,
  202. refp : tnode;
  203. htype : ttype;
  204. ptemp : ttempcreatenode;
  205. usederef : boolean;
  206. usevoidpointer : boolean;
  207. newinitstatement,
  208. newdonestatement : tstatementnode;
  209. begin
  210. if not assigned(aktcallnode) then
  211. internalerror(200410121);
  212. { Load all complex loads into a temp to prevent
  213. double calls to a function. We can't simply check for a hp.nodetype=calln
  214. }
  215. hp:=p;
  216. while assigned(hp) and
  217. (hp.nodetype=typeconvn) and
  218. (ttypeconvnode(hp).convtype=tc_equal) do
  219. hp:=tunarynode(hp).left;
  220. if assigned(hp) and
  221. not is_simple_node(hp) then
  222. begin
  223. if not assigned(aktcallnode.methodpointerinit) then
  224. begin
  225. aktcallnode.methodpointerinit:=internalstatements(newinitstatement);
  226. aktcallnode.methodpointerdone:=internalstatements(newdonestatement);
  227. end
  228. else
  229. begin
  230. newinitstatement:=laststatement(aktcallnode.methodpointerinit);
  231. newdonestatement:=laststatement(aktcallnode.methodpointerdone);
  232. end;
  233. { temp create }
  234. usederef:=(p.resulttype.def.deftype in [arraydef,recorddef]) or
  235. is_shortstring(p.resulttype.def) or
  236. is_object(p.resulttype.def);
  237. { avoid refcount increase }
  238. usevoidpointer:=is_interface(p.resulttype.def);
  239. if usederef then
  240. htype.setdef(tpointerdef.create(p.resulttype))
  241. else
  242. htype:=p.resulttype;
  243. if usevoidpointer then
  244. begin
  245. ptemp:=ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent,true);
  246. loadp := ctypeconvnode.create_internal(p,voidpointertype);
  247. refp:=ctypeconvnode.create_internal(ctemprefnode.create(ptemp),htype);
  248. end
  249. else
  250. begin
  251. ptemp:=ctempcreatenode.create(htype,htype.def.size,tt_persistent,true);
  252. if usederef then
  253. begin
  254. loadp:=caddrnode.create_internal(p);
  255. refp:=cderefnode.create(ctemprefnode.create(ptemp));
  256. end
  257. else
  258. begin
  259. loadp:=p;
  260. refp:=ctemprefnode.create(ptemp)
  261. end
  262. end;
  263. addstatement(newinitstatement,ptemp);
  264. addstatement(newinitstatement,cassignmentnode.create(
  265. ctemprefnode.create(ptemp),
  266. loadp));
  267. { new tree is only a temp reference }
  268. p:=refp;
  269. { temp release. We need to return a reference to the methodpointer
  270. otherwise the conversion from callnode to loadnode can't be done
  271. for the methodpointer unless the loadnode will also get a methodpointerinit and
  272. methodpointerdone node. For the moment we use register as temp and therefor
  273. don't create a temp-leak in the stackframe (PFV) }
  274. { the last statement should return the value as
  275. location and type, this is done be referencing the
  276. temp and converting it first from a persistent temp to
  277. normal temp }
  278. addstatement(newdonestatement,ctempdeletenode.create_normal_temp(ptemp));
  279. if usevoidpointer then
  280. addstatement(newdonestatement,ctypeconvnode.create_internal(
  281. ctemprefnode.create(ptemp),htype))
  282. else
  283. addstatement(newdonestatement,ctemprefnode.create(ptemp));
  284. { call resulttypepass for new nodes }
  285. resulttypepass(p);
  286. resulttypepass(aktcallnode.methodpointerinit);
  287. resulttypepass(aktcallnode.methodpointerdone);
  288. end;
  289. end;
  290. function gen_high_tree(var p:tnode;paradef:tdef):tnode;
  291. var
  292. temp: tnode;
  293. len : integer;
  294. loadconst : boolean;
  295. hightree : tnode;
  296. begin
  297. len:=-1;
  298. loadconst:=true;
  299. hightree:=nil;
  300. case p.resulttype.def.deftype of
  301. arraydef :
  302. begin
  303. if (paradef.deftype<>arraydef) then
  304. internalerror(200405241);
  305. { passing a string to an array of char }
  306. if (p.nodetype=stringconstn) then
  307. begin
  308. len:=str_length(p);
  309. if len>0 then
  310. dec(len);
  311. end
  312. else
  313. { handle special case of passing an single array to an array of array }
  314. if compare_defs(tarraydef(paradef).elementtype.def,p.resulttype.def,nothingn)>=te_equal then
  315. len:=0
  316. else
  317. begin
  318. { handle via a normal inline in_high_x node }
  319. loadconst:=false;
  320. { slice? }
  321. if (p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=in_slice_x) then
  322. begin
  323. hightree:=tcallparanode(tcallparanode(tinlinenode(p).left).right).left;
  324. hightree:=caddnode.create(subn,hightree,genintconstnode(1));
  325. tcallparanode(tcallparanode(tinlinenode(p).left).right).left:=nil;
  326. temp:=p;
  327. p:=tcallparanode(tinlinenode(p).left).left;
  328. tcallparanode(tinlinenode(temp).left).left:=nil;
  329. temp.free;
  330. resulttypepass(hightree);
  331. end
  332. else
  333. begin
  334. maybe_load_para_in_temp(p);
  335. hightree:=geninlinenode(in_high_x,false,p.getcopy);
  336. resulttypepass(hightree);
  337. { only substract low(array) if it's <> 0 }
  338. temp:=geninlinenode(in_low_x,false,p.getcopy);
  339. resulttypepass(temp);
  340. if (temp.nodetype <> ordconstn) or
  341. (tordconstnode(temp).value <> 0) then
  342. hightree := caddnode.create(subn,hightree,temp)
  343. else
  344. temp.free;
  345. end;
  346. end;
  347. end;
  348. stringdef :
  349. begin
  350. if is_open_string(paradef) then
  351. begin
  352. maybe_load_para_in_temp(p);
  353. { handle via a normal inline in_high_x node }
  354. loadconst := false;
  355. hightree := geninlinenode(in_high_x,false,p.getcopy);
  356. end
  357. else
  358. begin
  359. { passing a string to an array of char }
  360. if (p.nodetype=stringconstn) then
  361. begin
  362. len:=str_length(p);
  363. if len>0 then
  364. dec(len);
  365. end
  366. else
  367. begin
  368. maybe_load_para_in_temp(p);
  369. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  370. cordconstnode.create(1,s32inttype,false));
  371. loadconst:=false;
  372. end;
  373. end;
  374. end;
  375. else
  376. len:=0;
  377. end;
  378. if loadconst then
  379. hightree:=cordconstnode.create(len,s32inttype,true)
  380. else
  381. begin
  382. if not assigned(hightree) then
  383. internalerror(200304071);
  384. { Need to use explicit, because it can also be a enum }
  385. hightree:=ctypeconvnode.create_internal(hightree,s32inttype);
  386. end;
  387. result:=hightree;
  388. end;
  389. {****************************************************************************
  390. TOBJECTINFOITEM
  391. ****************************************************************************}
  392. constructor tobjectinfoitem.create(def : tobjectdef);
  393. begin
  394. inherited create;
  395. objinfo := def;
  396. end;
  397. {****************************************************************************
  398. TCALLPARANODE
  399. ****************************************************************************}
  400. constructor tcallparanode.create(expr,next : tnode);
  401. begin
  402. inherited create(callparan,expr,next);
  403. if not assigned(expr) then
  404. internalerror(200305091);
  405. expr.fileinfo:=fileinfo;
  406. callparaflags:=[];
  407. end;
  408. destructor tcallparanode.destroy;
  409. begin
  410. { When the node is used by callnode then
  411. we don't destroy left, the callnode takes care of it }
  412. if used_by_callnode then
  413. left:=nil;
  414. inherited destroy;
  415. end;
  416. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  417. begin
  418. inherited ppuload(t,ppufile);
  419. ppufile.getsmallset(callparaflags);
  420. end;
  421. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  422. begin
  423. inherited ppuwrite(ppufile);
  424. ppufile.putsmallset(callparaflags);
  425. end;
  426. function tcallparanode.getcopy : tnode;
  427. var
  428. n : tcallparanode;
  429. begin
  430. n:=tcallparanode(inherited getcopy);
  431. n.callparaflags:=callparaflags;
  432. n.parasym:=parasym;
  433. result:=n;
  434. end;
  435. procedure tcallparanode.insertintolist(l : tnodelist);
  436. begin
  437. end;
  438. procedure tcallparanode.get_paratype;
  439. var
  440. old_array_constructor : boolean;
  441. begin
  442. inc(parsing_para_level);
  443. if assigned(right) then
  444. tcallparanode(right).get_paratype;
  445. old_array_constructor:=allow_array_constructor;
  446. allow_array_constructor:=true;
  447. resulttypepass(left);
  448. allow_array_constructor:=old_array_constructor;
  449. if codegenerror then
  450. resulttype:=generrortype
  451. else
  452. resulttype:=left.resulttype;
  453. dec(parsing_para_level);
  454. end;
  455. procedure tcallparanode.insert_typeconv(do_count : boolean);
  456. var
  457. oldtype : ttype;
  458. hp : tnode;
  459. {$ifdef extdebug}
  460. store_count_ref : boolean;
  461. {$endif def extdebug}
  462. begin
  463. inc(parsing_para_level);
  464. {$ifdef extdebug}
  465. if do_count then
  466. begin
  467. store_count_ref:=count_ref;
  468. count_ref:=true;
  469. end;
  470. {$endif def extdebug}
  471. { Be sure to have the resulttype }
  472. if not assigned(left.resulttype.def) then
  473. resulttypepass(left);
  474. if (left.nodetype<>nothingn) then
  475. begin
  476. { Convert tp procvars, this is needs to be done
  477. here to make the change permanent. in the overload
  478. choosing the changes are only made temporary }
  479. if (left.resulttype.def.deftype=procvardef) and
  480. (parasym.vartype.def.deftype<>procvardef) then
  481. begin
  482. if maybe_call_procvar(left,true) then
  483. resulttype:=left.resulttype;
  484. end;
  485. { Remove implicitly inserted typecast to pointer for
  486. @procvar in macpas }
  487. if (m_mac_procvar in aktmodeswitches) and
  488. (parasym.vartype.def.deftype=procvardef) and
  489. (left.nodetype=typeconvn) and
  490. is_voidpointer(left.resulttype.def) and
  491. (ttypeconvnode(left).left.nodetype=typeconvn) and
  492. (ttypeconvnode(ttypeconvnode(left).left).convtype=tc_proc_2_procvar) then
  493. begin
  494. hp:=left;
  495. left:=ttypeconvnode(left).left;
  496. ttypeconvnode(hp).left:=nil;
  497. hp.free;
  498. end;
  499. { Handle varargs and hidden paras directly, no typeconvs or }
  500. { typechecking needed }
  501. if (cpf_varargs_para in callparaflags) then
  502. begin
  503. { convert pascal to C types }
  504. case left.resulttype.def.deftype of
  505. stringdef :
  506. inserttypeconv(left,charpointertype);
  507. floatdef :
  508. inserttypeconv(left,s64floattype);
  509. end;
  510. set_varstate(left,vs_read,[vsf_must_be_valid]);
  511. resulttype:=left.resulttype;
  512. { also update parasym type to get the correct parameter location
  513. for the new types }
  514. parasym.vartype:=left.resulttype;
  515. end
  516. else
  517. if (vo_is_hidden_para in parasym.varoptions) then
  518. begin
  519. set_varstate(left,vs_read,[vsf_must_be_valid]);
  520. resulttype:=left.resulttype;
  521. end
  522. else
  523. begin
  524. { Do we need arrayconstructor -> set conversion, then insert
  525. it here before the arrayconstructor node breaks the tree
  526. with its conversions of enum->ord }
  527. if (left.nodetype=arrayconstructorn) and
  528. (parasym.vartype.def.deftype=setdef) then
  529. inserttypeconv(left,parasym.vartype);
  530. { set some settings needed for arrayconstructor }
  531. if is_array_constructor(left.resulttype.def) then
  532. begin
  533. if left.nodetype<>arrayconstructorn then
  534. internalerror(200504041);
  535. if is_array_of_const(parasym.vartype.def) then
  536. begin
  537. { force variant array }
  538. include(left.flags,nf_forcevaria);
  539. end
  540. else
  541. begin
  542. include(left.flags,nf_novariaallowed);
  543. { now that the resultting type is know we can insert the required
  544. typeconvs for the array constructor }
  545. if parasym.vartype.def.deftype=arraydef then
  546. tarrayconstructornode(left).force_type(tarraydef(parasym.vartype.def).elementtype);
  547. end;
  548. end;
  549. { check if local proc/func is assigned to procvar }
  550. if left.resulttype.def.deftype=procvardef then
  551. test_local_to_procvar(tprocvardef(left.resulttype.def),parasym.vartype.def);
  552. { test conversions }
  553. if not(is_shortstring(left.resulttype.def) and
  554. is_shortstring(parasym.vartype.def)) and
  555. (parasym.vartype.def.deftype<>formaldef) then
  556. begin
  557. { Process open parameters }
  558. if paramanager.push_high_param(parasym.varspez,parasym.vartype.def,aktcallnode.procdefinition.proccalloption) then
  559. begin
  560. { insert type conv but hold the ranges of the array }
  561. oldtype:=left.resulttype;
  562. inserttypeconv(left,parasym.vartype);
  563. left.resulttype:=oldtype;
  564. end
  565. else
  566. begin
  567. check_ranges(left.fileinfo,left,parasym.vartype.def);
  568. inserttypeconv(left,parasym.vartype);
  569. end;
  570. if codegenerror then
  571. begin
  572. dec(parsing_para_level);
  573. exit;
  574. end;
  575. end;
  576. { check var strings }
  577. if (cs_strict_var_strings in aktlocalswitches) and
  578. is_shortstring(left.resulttype.def) and
  579. is_shortstring(parasym.vartype.def) and
  580. (parasym.varspez in [vs_out,vs_var]) and
  581. not(is_open_string(parasym.vartype.def)) and
  582. not(equal_defs(left.resulttype.def,parasym.vartype.def)) then
  583. begin
  584. aktfilepos:=left.fileinfo;
  585. CGMessage(type_e_strict_var_string_violation);
  586. end;
  587. { Handle formal parameters separate }
  588. if (parasym.vartype.def.deftype=formaldef) then
  589. begin
  590. { load procvar if a procedure is passed }
  591. if ((m_tp_procvar in aktmodeswitches) or
  592. (m_mac_procvar in aktmodeswitches)) and
  593. (left.nodetype=calln) and
  594. (is_void(left.resulttype.def)) then
  595. load_procvar_from_calln(left);
  596. case parasym.varspez of
  597. vs_var,
  598. vs_out :
  599. begin
  600. if not valid_for_formal_var(left,true) then
  601. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  602. end;
  603. vs_const :
  604. begin
  605. if not valid_for_formal_const(left,true) then
  606. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  607. end;
  608. end;
  609. end
  610. else
  611. begin
  612. { check if the argument is allowed }
  613. if (parasym.varspez in [vs_out,vs_var]) then
  614. valid_for_var(left,true);
  615. end;
  616. if parasym.varspez in [vs_var,vs_out] then
  617. set_unique(left);
  618. { When the address needs to be pushed then the register is
  619. not regable. Exception is when the location is also a var
  620. parameter and we can pass the address transparently }
  621. if (
  622. not(
  623. (vo_is_hidden_para in parasym.varoptions) and
  624. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  625. ) and
  626. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  627. aktcallnode.procdefinition.proccalloption) and
  628. not(
  629. (left.nodetype=loadn) and
  630. (tloadnode(left).is_addr_param_load)
  631. )
  632. ) then
  633. make_not_regable(left);
  634. if do_count then
  635. begin
  636. case parasym.varspez of
  637. vs_out :
  638. set_varstate(left,vs_written,[]);
  639. vs_var :
  640. set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
  641. else
  642. set_varstate(left,vs_read,[vsf_must_be_valid]);
  643. end;
  644. end;
  645. { must only be done after typeconv PM }
  646. resulttype:=parasym.vartype;
  647. end;
  648. end;
  649. { process next node }
  650. if assigned(right) then
  651. tcallparanode(right).insert_typeconv(do_count);
  652. dec(parsing_para_level);
  653. {$ifdef extdebug}
  654. if do_count then
  655. count_ref:=store_count_ref;
  656. {$endif def extdebug}
  657. end;
  658. procedure tcallparanode.det_registers;
  659. begin
  660. if assigned(right) then
  661. begin
  662. tcallparanode(right).det_registers;
  663. registersint:=right.registersint;
  664. registersfpu:=right.registersfpu;
  665. {$ifdef SUPPORT_MMX}
  666. registersmmx:=right.registersmmx;
  667. {$endif}
  668. end;
  669. firstpass(left);
  670. if left.registersint>registersint then
  671. registersint:=left.registersint;
  672. if left.registersfpu>registersfpu then
  673. registersfpu:=left.registersfpu;
  674. {$ifdef SUPPORT_MMX}
  675. if left.registersmmx>registersmmx then
  676. registersmmx:=left.registersmmx;
  677. {$endif SUPPORT_MMX}
  678. end;
  679. procedure tcallparanode.firstcallparan;
  680. begin
  681. if not assigned(left.resulttype.def) then
  682. get_paratype;
  683. det_registers;
  684. end;
  685. function tcallparanode.docompare(p: tnode): boolean;
  686. begin
  687. docompare :=
  688. inherited docompare(p) and
  689. (callparaflags = tcallparanode(p).callparaflags)
  690. ;
  691. end;
  692. procedure tcallparanode.printnodetree(var t:text);
  693. begin
  694. printnodelist(t);
  695. end;
  696. {****************************************************************************
  697. TCALLNODE
  698. ****************************************************************************}
  699. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);
  700. begin
  701. inherited create(calln,l,nil);
  702. symtableprocentry:=v;
  703. symtableproc:=st;
  704. callnodeflags:=callflags+[cnf_return_value_used];
  705. methodpointer:=mp;
  706. methodpointerinit:=nil;
  707. methodpointerdone:=nil;
  708. procdefinition:=nil;
  709. _funcretnode:=nil;
  710. {$ifdef PASS2INLINE}
  711. inlinecode:=nil;
  712. {$endif PASS2INLINE}
  713. paralength:=-1;
  714. varargsparas:=nil;
  715. end;
  716. constructor tcallnode.create_procvar(l,r:tnode);
  717. begin
  718. inherited create(calln,l,r);
  719. symtableprocentry:=nil;
  720. symtableproc:=nil;
  721. methodpointer:=nil;
  722. methodpointerinit:=nil;
  723. methodpointerdone:=nil;
  724. procdefinition:=nil;
  725. callnodeflags:=[cnf_return_value_used];
  726. _funcretnode:=nil;
  727. {$ifdef PASS2INLINE}
  728. inlinecode:=nil;
  729. {$endif PASS2INLINE}
  730. paralength:=-1;
  731. varargsparas:=nil;
  732. end;
  733. constructor tcallnode.createintern(const name: string; params: tnode);
  734. var
  735. srsym: tsym;
  736. symowner: tsymtable;
  737. begin
  738. if not (cs_compilesystem in aktmoduleswitches) then
  739. begin
  740. srsym := searchsymonlyin(systemunit,name);
  741. symowner := systemunit;
  742. end
  743. else
  744. begin
  745. searchsym(name,srsym,symowner);
  746. if not assigned(srsym) then
  747. searchsym(upper(name),srsym,symowner);
  748. end;
  749. if not assigned(srsym) or
  750. (srsym.typ <> procsym) then
  751. Message1(cg_f_unknown_compiler,name);
  752. self.create(params,tprocsym(srsym),symowner,nil,[]);
  753. end;
  754. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  755. begin
  756. self.createintern(name,params);
  757. restype := res;
  758. include(callnodeflags,cnf_restypeset);
  759. { both the normal and specified resulttype either have to be returned via a }
  760. { parameter or not, but no mixing (JM) }
  761. if paramanager.ret_in_param(restype.def,symtableprocentry.first_procdef.proccalloption) xor
  762. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  763. internalerror(200108291);
  764. end;
  765. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  766. begin
  767. self.createintern(name,params);
  768. _funcretnode:=returnnode;
  769. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  770. internalerror(200204247);
  771. end;
  772. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  773. var
  774. para: tcallparanode;
  775. begin
  776. if assigned(_funcretnode) then
  777. _funcretnode.free;
  778. _funcretnode := returnnode;
  779. { if the resulttype pass hasn't occurred yet, that one will do }
  780. { everything }
  781. if assigned(resulttype.def) then
  782. begin
  783. { these are returned as values, but we can optimize their loading }
  784. { as well }
  785. if is_ansistring(resulttype.def) or
  786. is_widestring(resulttype.def) then
  787. exit;
  788. para := tcallparanode(left);
  789. while assigned(para) do
  790. begin
  791. if (vo_is_hidden_para in para.parasym.varoptions) and
  792. (vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  793. begin
  794. para.left.free;
  795. para.left := _funcretnode.getcopy;
  796. exit;
  797. end;
  798. para := tcallparanode(para.right);
  799. end;
  800. { no hidden resultpara found, error! }
  801. if not(po_inline in procdefinition.procoptions) then
  802. internalerror(200306087);
  803. end;
  804. end;
  805. destructor tcallnode.destroy;
  806. var
  807. i : longint;
  808. begin
  809. methodpointer.free;
  810. methodpointerinit.free;
  811. methodpointerdone.free;
  812. _funcretnode.free;
  813. {$ifdef PASS2INLINE}
  814. inlinecode.free;
  815. {$endif PASS2INLINE}
  816. if assigned(varargsparas) then
  817. begin
  818. for i:=0 to varargsparas.count-1 do
  819. tparavarsym(varargsparas[i]).free;
  820. varargsparas.free;
  821. end;
  822. inherited destroy;
  823. end;
  824. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  825. begin
  826. inherited ppuload(t,ppufile);
  827. ppufile.getderef(symtableprocentryderef);
  828. {$ifdef fpc}
  829. {$warning FIXME: No withsymtable support}
  830. {$endif}
  831. symtableproc:=nil;
  832. ppufile.getderef(procdefinitionderef);
  833. ppufile.getsmallset(callnodeflags);
  834. methodpointer:=ppuloadnode(ppufile);
  835. methodpointerinit:=tblocknode(ppuloadnode(ppufile));
  836. methodpointerdone:=tblocknode(ppuloadnode(ppufile));
  837. _funcretnode:=ppuloadnode(ppufile);
  838. {$ifdef PASS2INLINE}
  839. inlinecode:=ppuloadnode(ppufile);
  840. {$endif PASS2INLINE}
  841. end;
  842. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  843. begin
  844. inherited ppuwrite(ppufile);
  845. ppufile.putderef(symtableprocentryderef);
  846. ppufile.putderef(procdefinitionderef);
  847. ppufile.putsmallset(callnodeflags);
  848. ppuwritenode(ppufile,methodpointer);
  849. ppuwritenode(ppufile,methodpointerinit);
  850. ppuwritenode(ppufile,methodpointerdone);
  851. ppuwritenode(ppufile,_funcretnode);
  852. {$ifdef PASS2INLINE}
  853. ppuwritenode(ppufile,inlinecode);
  854. {$endif PASS2INLINE}
  855. end;
  856. procedure tcallnode.buildderefimpl;
  857. begin
  858. inherited buildderefimpl;
  859. symtableprocentryderef.build(symtableprocentry);
  860. procdefinitionderef.build(procdefinition);
  861. if assigned(methodpointer) then
  862. methodpointer.buildderefimpl;
  863. if assigned(methodpointerinit) then
  864. methodpointerinit.buildderefimpl;
  865. if assigned(methodpointerdone) then
  866. methodpointerdone.buildderefimpl;
  867. if assigned(_funcretnode) then
  868. _funcretnode.buildderefimpl;
  869. {$ifdef PASS2INLINE}
  870. if assigned(inlinecode) then
  871. inlinecode.buildderefimpl;
  872. {$endif PASS2INLINE}
  873. end;
  874. procedure tcallnode.derefimpl;
  875. var
  876. pt : tcallparanode;
  877. i : integer;
  878. begin
  879. inherited derefimpl;
  880. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  881. if assigned(symtableprocentry) then
  882. symtableproc:=symtableprocentry.owner;
  883. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  884. if assigned(methodpointer) then
  885. methodpointer.derefimpl;
  886. if assigned(methodpointerinit) then
  887. methodpointerinit.derefimpl;
  888. if assigned(methodpointerdone) then
  889. methodpointerdone.derefimpl;
  890. if assigned(_funcretnode) then
  891. _funcretnode.derefimpl;
  892. {$ifdef PASS2INLINE}
  893. if assigned(inlinecode) then
  894. inlinecode.derefimpl;
  895. {$endif PASS2INLINE}
  896. { Connect parasyms }
  897. pt:=tcallparanode(left);
  898. while assigned(pt) and
  899. (cpf_varargs_para in pt.callparaflags) do
  900. pt:=tcallparanode(pt.right);
  901. for i:=procdefinition.paras.count-1 downto 0 do
  902. begin
  903. if not assigned(pt) then
  904. internalerror(200311077);
  905. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  906. pt:=tcallparanode(pt.right);
  907. end;
  908. if assigned(pt) then
  909. internalerror(200311078);
  910. end;
  911. function tcallnode.getcopy : tnode;
  912. var
  913. n : tcallnode;
  914. i : integer;
  915. hp,hpn : tparavarsym;
  916. oldleft : tnode;
  917. begin
  918. { Need to use a hack here to prevent the parameters from being copied.
  919. The parameters must be copied between methodpointerinit/methodpointerdone because
  920. the can reference methodpointer }
  921. oldleft:=left;
  922. left:=nil;
  923. n:=tcallnode(inherited getcopy);
  924. left:=oldleft;
  925. n.symtableprocentry:=symtableprocentry;
  926. n.symtableproc:=symtableproc;
  927. n.procdefinition:=procdefinition;
  928. n.restype := restype;
  929. n.callnodeflags := callnodeflags;
  930. if assigned(methodpointerinit) then
  931. n.methodpointerinit:=tblocknode(methodpointerinit.getcopy)
  932. else
  933. n.methodpointerinit:=nil;
  934. { methodpointerinit is copied, now references to the temp will also be copied
  935. correctly. We can now copy the parameters and methodpointer }
  936. if assigned(left) then
  937. n.left:=left.getcopy
  938. else
  939. n.left:=nil;
  940. if assigned(methodpointer) then
  941. n.methodpointer:=methodpointer.getcopy
  942. else
  943. n.methodpointer:=nil;
  944. if assigned(methodpointerdone) then
  945. n.methodpointerdone:=tblocknode(methodpointerdone.getcopy)
  946. else
  947. n.methodpointerdone:=nil;
  948. if assigned(_funcretnode) then
  949. n._funcretnode:=_funcretnode.getcopy
  950. else
  951. n._funcretnode:=nil;
  952. {$ifdef PASS2INLINE}
  953. if assigned(inlinecode) then
  954. n.inlinecode:=inlinecode.getcopy
  955. else
  956. n.inlinecode:=nil;
  957. {$endif PASS2INLINE}
  958. if assigned(varargsparas) then
  959. begin
  960. n.varargsparas:=tvarargsparalist.create;
  961. for i:=0 to varargsparas.count-1 do
  962. begin
  963. hp:=tparavarsym(varargsparas[i]);
  964. hpn:=tparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vartype,[]);
  965. n.varargsparas.add(hpn);
  966. end;
  967. end
  968. else
  969. n.varargsparas:=nil;
  970. result:=n;
  971. end;
  972. procedure tcallnode.insertintolist(l : tnodelist);
  973. begin
  974. end;
  975. procedure tcallnode.convert_carg_array_of_const;
  976. var
  977. hp : tarrayconstructornode;
  978. oldleft : tcallparanode;
  979. begin
  980. oldleft:=tcallparanode(left);
  981. if oldleft.left.nodetype<>arrayconstructorn then
  982. begin
  983. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
  984. exit;
  985. end;
  986. include(callnodeflags,cnf_uses_varargs);
  987. { Get arrayconstructor node and insert typeconvs }
  988. hp:=tarrayconstructornode(oldleft.left);
  989. hp.insert_typeconvs;
  990. { Add c args parameters }
  991. { It could be an empty set }
  992. if assigned(hp) and
  993. assigned(hp.left) then
  994. begin
  995. while assigned(hp) do
  996. begin
  997. left:=ccallparanode.create(hp.left,left);
  998. { set callparanode resulttype and flags }
  999. left.resulttype:=hp.left.resulttype;
  1000. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  1001. hp.left:=nil;
  1002. hp:=tarrayconstructornode(hp.right);
  1003. end;
  1004. end;
  1005. { Remove value of old array of const parameter, but keep it
  1006. in the list because it is required for bind_parasym.
  1007. Generate a nothign to keep callparanoed.left valid }
  1008. oldleft.left.free;
  1009. oldleft.left:=cnothingnode.create;
  1010. end;
  1011. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  1012. var
  1013. hp : tprocdef;
  1014. j: integer;
  1015. begin
  1016. if (tsym(p).typ=procsym) then
  1017. begin
  1018. for j:=1 to tprocsym(p).procdef_count do
  1019. begin
  1020. { index starts at 1 }
  1021. hp:=tprocsym(p).procdef[j];
  1022. { If this is an abstract method insert into the list }
  1023. if (po_abstractmethod in hp.procoptions) then
  1024. AbstractMethodsList.Insert(hp.procsym.realname)
  1025. else
  1026. { If this symbol is a virtual (includes override) method,
  1027. then remove it from the list }
  1028. if po_virtualmethod in hp.procoptions then
  1029. AbstractMethodsList.Remove(hp.procsym.realname);
  1030. end;
  1031. end;
  1032. end;
  1033. procedure tcallnode.verifyabstractcalls;
  1034. var
  1035. objectdf : tobjectdef;
  1036. parents : tlinkedlist;
  1037. objectinfo : tobjectinfoitem;
  1038. stritem : tstringlistitem;
  1039. begin
  1040. objectdf := nil;
  1041. { verify if trying to create an instance of a class which contains
  1042. non-implemented abstract methods }
  1043. { first verify this class type, no class than exit }
  1044. { also, this checking can only be done if the constructor is directly
  1045. called, indirect constructor calls cannot be checked.
  1046. }
  1047. if assigned(methodpointer) then
  1048. begin
  1049. if (methodpointer.resulttype.def.deftype = objectdef) then
  1050. objectdf:=tobjectdef(methodpointer.resulttype.def)
  1051. else
  1052. if (methodpointer.resulttype.def.deftype = classrefdef) and
  1053. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  1054. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  1055. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  1056. end;
  1057. if not assigned(objectdf) then
  1058. exit;
  1059. parents := tlinkedlist.create;
  1060. AbstractMethodsList := tstringlist.create;
  1061. { insert all parents in this class : the first item in the
  1062. list will be the base parent of the class .
  1063. }
  1064. while assigned(objectdf) do
  1065. begin
  1066. objectinfo:=tobjectinfoitem.create(objectdf);
  1067. parents.insert(objectinfo);
  1068. objectdf := objectdf.childof;
  1069. end;
  1070. { now all parents are in the correct order
  1071. insert all abstract methods in the list, and remove
  1072. those which are overriden by parent classes.
  1073. }
  1074. objectinfo:=tobjectinfoitem(parents.first);
  1075. while assigned(objectinfo) do
  1076. begin
  1077. objectdf := objectinfo.objinfo;
  1078. if assigned(objectdf.symtable) then
  1079. objectdf.symtable.foreach(@verifyabstract,nil);
  1080. objectinfo:=tobjectinfoitem(objectinfo.next);
  1081. end;
  1082. if assigned(parents) then
  1083. parents.free;
  1084. { Finally give out a warning for each abstract method still in the list }
  1085. stritem := tstringlistitem(AbstractMethodsList.first);
  1086. if assigned(stritem) then
  1087. Message1(type_w_instance_with_abstract,objectdf.objrealname^);
  1088. while assigned(stritem) do
  1089. begin
  1090. if assigned(stritem.fpstr) then
  1091. Message1(sym_h_param_list,stritem.str);
  1092. stritem := tstringlistitem(stritem.next);
  1093. end;
  1094. if assigned(AbstractMethodsList) then
  1095. AbstractMethodsList.Free;
  1096. end;
  1097. function tcallnode.gen_self_tree_methodpointer:tnode;
  1098. var
  1099. hsym : tfieldvarsym;
  1100. begin
  1101. { find self field in methodpointer record }
  1102. hsym:=tfieldvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1103. if not assigned(hsym) then
  1104. internalerror(200305251);
  1105. { Load tmehodpointer(right).self }
  1106. result:=csubscriptnode.create(
  1107. hsym,
  1108. ctypeconvnode.create_internal(right.getcopy,methodpointertype));
  1109. end;
  1110. function tcallnode.gen_self_tree:tnode;
  1111. var
  1112. selftree : tnode;
  1113. begin
  1114. selftree:=nil;
  1115. { inherited }
  1116. if (cnf_inherited in callnodeflags) then
  1117. selftree:=load_self_node
  1118. else
  1119. { constructors }
  1120. if (procdefinition.proctypeoption=potype_constructor) then
  1121. begin
  1122. { push 0 as self when allocation is needed }
  1123. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1124. (cnf_new_call in callnodeflags) then
  1125. selftree:=cpointerconstnode.create(0,voidpointertype)
  1126. else
  1127. begin
  1128. if methodpointer.nodetype=typen then
  1129. selftree:=load_self_node
  1130. else
  1131. selftree:=methodpointer.getcopy;
  1132. end;
  1133. end
  1134. else
  1135. { Calling a static/class method }
  1136. if (po_classmethod in procdefinition.procoptions) or
  1137. (po_staticmethod in procdefinition.procoptions) then
  1138. begin
  1139. if (procdefinition.deftype<>procdef) then
  1140. internalerror(200305062);
  1141. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1142. begin
  1143. { we only need the vmt, loading self is not required and there is no
  1144. need to check for typen, because that will always get the
  1145. loadvmtaddrnode added }
  1146. selftree:=methodpointer.getcopy;
  1147. if methodpointer.resulttype.def.deftype<>classrefdef then
  1148. selftree:=cloadvmtaddrnode.create(selftree);
  1149. end
  1150. else
  1151. selftree:=cpointerconstnode.create(0,voidpointertype);
  1152. end
  1153. else
  1154. begin
  1155. if methodpointer.nodetype=typen then
  1156. selftree:=load_self_node
  1157. else
  1158. selftree:=methodpointer.getcopy;
  1159. end;
  1160. result:=selftree;
  1161. end;
  1162. function tcallnode.gen_vmt_tree:tnode;
  1163. var
  1164. vmttree : tnode;
  1165. begin
  1166. vmttree:=nil;
  1167. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1168. internalerror(200305051);
  1169. { Handle classes and legacy objects separate to make it
  1170. more maintainable }
  1171. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1172. begin
  1173. if not is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1174. internalerror(200501041);
  1175. { constructor call via classreference => allocate memory }
  1176. if (procdefinition.proctypeoption=potype_constructor) then
  1177. begin
  1178. vmttree:=methodpointer.getcopy;
  1179. { Only a typenode can be passed when it is called with <class of xx>.create }
  1180. if vmttree.nodetype=typen then
  1181. vmttree:=cloadvmtaddrnode.create(vmttree);
  1182. end
  1183. else
  1184. begin
  1185. { Call afterconstruction }
  1186. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1187. end;
  1188. end
  1189. else
  1190. { Class style objects }
  1191. if is_class(methodpointer.resulttype.def) then
  1192. begin
  1193. { inherited call, no create/destroy }
  1194. if (cnf_inherited in callnodeflags) then
  1195. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1196. else
  1197. { do not create/destroy when called from member function
  1198. without specifying self explicit }
  1199. if (cnf_member_call in callnodeflags) then
  1200. begin
  1201. { destructor: don't release instance, vmt=0
  1202. constructor:
  1203. if called from a constructor in the same class then
  1204. don't call afterconstruction, vmt=0
  1205. else
  1206. call afterconstrution, vmt=1 }
  1207. if (procdefinition.proctypeoption=potype_destructor) then
  1208. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1209. else
  1210. begin
  1211. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1212. (procdefinition.proctypeoption=potype_constructor) then
  1213. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1214. else
  1215. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1216. end;
  1217. end
  1218. else
  1219. { normal call to method like cl1.proc }
  1220. begin
  1221. { destructor: release instance, vmt=1
  1222. constructor:
  1223. if called from a constructor in the same class using self.create then
  1224. don't call afterconstruction, vmt=0
  1225. else
  1226. call afterconstrution, vmt=1 }
  1227. if (procdefinition.proctypeoption=potype_destructor) then
  1228. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1229. else
  1230. begin
  1231. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1232. (procdefinition.proctypeoption=potype_constructor) and
  1233. (nf_is_self in methodpointer.flags) then
  1234. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1235. else
  1236. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1237. end;
  1238. end;
  1239. end
  1240. else
  1241. { Old style object }
  1242. begin
  1243. { constructor with extended syntax called from new }
  1244. if (cnf_new_call in callnodeflags) then
  1245. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1246. else
  1247. { destructor with extended syntax called from dispose }
  1248. if (cnf_dispose_call in callnodeflags) then
  1249. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1250. else
  1251. { inherited call, no create/destroy }
  1252. if (cnf_inherited in callnodeflags) then
  1253. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1254. else
  1255. { do not create/destroy when called from member function
  1256. without specifying self explicit }
  1257. if (cnf_member_call in callnodeflags) then
  1258. begin
  1259. { destructor: don't release instance, vmt=0
  1260. constructor: don't initialize instance, vmt=0 }
  1261. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1262. end
  1263. else
  1264. { normal object call like obj.proc }
  1265. begin
  1266. { destructor: direct call, no dispose, vmt=0
  1267. constructor: initialize object, load vmt }
  1268. if (procdefinition.proctypeoption=potype_constructor) then
  1269. begin
  1270. { old styled inherited call? }
  1271. if (methodpointer.nodetype=typen) then
  1272. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1273. else
  1274. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1275. end
  1276. else
  1277. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1278. end;
  1279. end;
  1280. result:=vmttree;
  1281. end;
  1282. procedure tcallnode.bind_parasym;
  1283. var
  1284. i : integer;
  1285. pt : tcallparanode;
  1286. oldppt : ^tcallparanode;
  1287. varargspara,
  1288. currpara : tparavarsym;
  1289. used_by_callnode : boolean;
  1290. hiddentree : tnode;
  1291. newstatement : tstatementnode;
  1292. temp : ttempcreatenode;
  1293. begin
  1294. pt:=tcallparanode(left);
  1295. oldppt:=@left;
  1296. { flag all callparanodes that belong to the varargs }
  1297. i:=paralength;
  1298. while (i>procdefinition.maxparacount) do
  1299. begin
  1300. include(pt.callparaflags,cpf_varargs_para);
  1301. oldppt:[email protected];
  1302. pt:=tcallparanode(pt.right);
  1303. dec(i);
  1304. end;
  1305. { skip varargs that are inserted by array of const }
  1306. while assigned(pt) and
  1307. (cpf_varargs_para in pt.callparaflags) do
  1308. pt:=tcallparanode(pt.right);
  1309. { process normal parameters and insert hidden parameters }
  1310. for i:=procdefinition.paras.count-1 downto 0 do
  1311. begin
  1312. currpara:=tparavarsym(procdefinition.paras[i]);
  1313. if vo_is_hidden_para in currpara.varoptions then
  1314. begin
  1315. { generate hidden tree }
  1316. used_by_callnode:=false;
  1317. hiddentree:=nil;
  1318. if (vo_is_funcret in currpara.varoptions) then
  1319. begin
  1320. { Generate funcretnode if not specified }
  1321. if assigned(funcretnode) then
  1322. begin
  1323. hiddentree:=funcretnode.getcopy;
  1324. end
  1325. else
  1326. begin
  1327. hiddentree:=internalstatements(newstatement);
  1328. { need to use resulttype instead of procdefinition.rettype,
  1329. because they can be different }
  1330. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent,false);
  1331. addstatement(newstatement,temp);
  1332. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1333. addstatement(newstatement,ctemprefnode.create(temp));
  1334. end;
  1335. end
  1336. else
  1337. if vo_is_high_para in currpara.varoptions then
  1338. begin
  1339. if not assigned(pt) or
  1340. (i=0) then
  1341. internalerror(200304082);
  1342. { we need the information of the previous parameter }
  1343. hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vartype.def);
  1344. end
  1345. else
  1346. if vo_is_self in currpara.varoptions then
  1347. begin
  1348. if assigned(right) then
  1349. hiddentree:=gen_self_tree_methodpointer
  1350. else
  1351. hiddentree:=gen_self_tree;
  1352. end
  1353. else
  1354. if vo_is_vmt in currpara.varoptions then
  1355. begin
  1356. hiddentree:=gen_vmt_tree;
  1357. end
  1358. {$ifdef powerpc}
  1359. else
  1360. if vo_is_syscall_lib in currpara.varoptions then
  1361. begin
  1362. { lib parameter has no special type but proccalloptions must be a syscall }
  1363. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1364. end
  1365. {$endif powerpc}
  1366. else
  1367. if vo_is_parentfp in currpara.varoptions then
  1368. begin
  1369. if not(assigned(procdefinition.owner.defowner)) then
  1370. internalerror(200309287);
  1371. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1372. end;
  1373. { add the hidden parameter }
  1374. if not assigned(hiddentree) then
  1375. internalerror(200304073);
  1376. { Already insert para and let the previous node point to
  1377. this new node }
  1378. pt:=ccallparanode.create(hiddentree,oldppt^);
  1379. pt.used_by_callnode:=used_by_callnode;
  1380. oldppt^:=pt;
  1381. end;
  1382. if not assigned(pt) then
  1383. internalerror(200310052);
  1384. pt.parasym:=currpara;
  1385. oldppt:[email protected];
  1386. pt:=tcallparanode(pt.right);
  1387. end;
  1388. { Create parasyms for varargs, first count the number of varargs paras,
  1389. then insert the parameters with numbering in reverse order. The SortParas
  1390. will set the correct order at the end}
  1391. pt:=tcallparanode(left);
  1392. i:=0;
  1393. while assigned(pt) do
  1394. begin
  1395. if cpf_varargs_para in pt.callparaflags then
  1396. inc(i);
  1397. pt:=tcallparanode(pt.right);
  1398. end;
  1399. if (i>0) then
  1400. begin
  1401. varargsparas:=tvarargsparalist.create;
  1402. pt:=tcallparanode(left);
  1403. while assigned(pt) do
  1404. begin
  1405. if cpf_varargs_para in pt.callparaflags then
  1406. begin
  1407. varargspara:=tparavarsym.create('va'+tostr(i),i,vs_value,pt.resulttype,[]);
  1408. dec(i);
  1409. { varargspara is left-right, use insert
  1410. instead of concat }
  1411. varargsparas.add(varargspara);
  1412. pt.parasym:=varargspara;
  1413. end;
  1414. pt:=tcallparanode(pt.right);
  1415. end;
  1416. varargsparas.sortparas;
  1417. end;
  1418. end;
  1419. function tcallnode.det_resulttype:tnode;
  1420. var
  1421. candidates : tcallcandidates;
  1422. oldcallnode : tcallnode;
  1423. hpt : tnode;
  1424. pt : tcallparanode;
  1425. lastpara : longint;
  1426. paraidx,
  1427. cand_cnt : integer;
  1428. i : longint;
  1429. is_const : boolean;
  1430. label
  1431. errorexit;
  1432. begin
  1433. result:=nil;
  1434. candidates:=nil;
  1435. oldcallnode:=aktcallnode;
  1436. aktcallnode:=self;
  1437. { determine length of parameter list }
  1438. pt:=tcallparanode(left);
  1439. paralength:=0;
  1440. while assigned(pt) do
  1441. begin
  1442. inc(paralength);
  1443. pt:=tcallparanode(pt.right);
  1444. end;
  1445. { determine the type of the parameters }
  1446. if assigned(left) then
  1447. begin
  1448. tcallparanode(left).get_paratype;
  1449. if codegenerror then
  1450. goto errorexit;
  1451. end;
  1452. if assigned(methodpointer) then
  1453. begin
  1454. resulttypepass(methodpointer);
  1455. maybe_load_para_in_temp(methodpointer);
  1456. end;
  1457. { procedure variable ? }
  1458. if assigned(right) then
  1459. begin
  1460. set_varstate(right,vs_read,[vsf_must_be_valid]);
  1461. resulttypepass(right);
  1462. if codegenerror then
  1463. exit;
  1464. procdefinition:=tabstractprocdef(right.resulttype.def);
  1465. { Compare parameters from right to left }
  1466. paraidx:=procdefinition.Paras.count-1;
  1467. { Skip default parameters }
  1468. if not(po_varargs in procdefinition.procoptions) then
  1469. begin
  1470. { ignore hidden parameters }
  1471. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1472. dec(paraidx);
  1473. for i:=1 to procdefinition.maxparacount-paralength do
  1474. begin
  1475. if paraidx<0 then
  1476. internalerror(200402261);
  1477. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1478. begin
  1479. CGMessage(parser_e_wrong_parameter_size);
  1480. goto errorexit;
  1481. end;
  1482. dec(paraidx);
  1483. end;
  1484. end;
  1485. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1486. dec(paraidx);
  1487. pt:=tcallparanode(left);
  1488. lastpara:=paralength;
  1489. while (paraidx>=0) and assigned(pt) do
  1490. begin
  1491. { only goto next para if we're out of the varargs }
  1492. if not(po_varargs in procdefinition.procoptions) or
  1493. (lastpara<=procdefinition.maxparacount) then
  1494. begin
  1495. repeat
  1496. dec(paraidx);
  1497. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1498. end;
  1499. pt:=tcallparanode(pt.right);
  1500. dec(lastpara);
  1501. end;
  1502. if assigned(pt) or
  1503. ((paraidx>=0) and
  1504. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  1505. begin
  1506. if assigned(pt) then
  1507. aktfilepos:=pt.fileinfo;
  1508. CGMessage(parser_e_wrong_parameter_size);
  1509. goto errorexit;
  1510. end;
  1511. end
  1512. else
  1513. { not a procedure variable }
  1514. begin
  1515. { do we know the procedure to call ? }
  1516. if not(assigned(procdefinition)) then
  1517. begin
  1518. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags),
  1519. { ignore possible private in delphi mode for anon. inherited (FK) }
  1520. (m_delphi in aktmodeswitches) and (cnf_anon_inherited in callnodeflags));
  1521. { no procedures found? then there is something wrong
  1522. with the parameter size or the procedures are
  1523. not accessible }
  1524. if candidates.count=0 then
  1525. begin
  1526. { when it's an auto inherited call and there
  1527. is no procedure found, but the procedures
  1528. were defined with overload directive and at
  1529. least two procedures are defined then we ignore
  1530. this inherited by inserting a nothingn. Only
  1531. do this ugly hack in Delphi mode as it looks more
  1532. like a bug. It's also not documented }
  1533. if (m_delphi in aktmodeswitches) and
  1534. (cnf_anon_inherited in callnodeflags) and
  1535. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1536. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1537. (symtableprocentry.procdef_count>=2) then
  1538. result:=cnothingnode.create
  1539. else
  1540. begin
  1541. { in tp mode we can try to convert to procvar if
  1542. there are no parameters specified }
  1543. if not(assigned(left)) and
  1544. not(cnf_inherited in callnodeflags) and
  1545. ((m_tp_procvar in aktmodeswitches) or
  1546. (m_mac_procvar in aktmodeswitches)) and
  1547. (not assigned(methodpointer) or
  1548. (methodpointer.nodetype <> typen)) then
  1549. begin
  1550. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1551. if assigned(methodpointer) then
  1552. tloadnode(hpt).set_mp(get_load_methodpointer);
  1553. resulttypepass(hpt);
  1554. result:=hpt;
  1555. end
  1556. else
  1557. begin
  1558. if assigned(left) then
  1559. aktfilepos:=left.fileinfo;
  1560. CGMessage(parser_e_wrong_parameter_size);
  1561. symtableprocentry.write_parameter_lists(nil);
  1562. end;
  1563. end;
  1564. goto errorexit;
  1565. end;
  1566. { Retrieve information about the candidates }
  1567. candidates.get_information;
  1568. {$ifdef EXTDEBUG}
  1569. { Display info when multiple candidates are found }
  1570. if candidates.count>1 then
  1571. candidates.dump_info(V_Debug);
  1572. {$endif EXTDEBUG}
  1573. { Choose the best candidate and count the number of
  1574. candidates left }
  1575. cand_cnt:=candidates.choose_best(procdefinition);
  1576. { All parameters are checked, check if there are any
  1577. procedures left }
  1578. if cand_cnt>0 then
  1579. begin
  1580. { Multiple candidates left? }
  1581. if cand_cnt>1 then
  1582. begin
  1583. CGMessage(type_e_cant_choose_overload_function);
  1584. {$ifdef EXTDEBUG}
  1585. candidates.dump_info(V_Hint);
  1586. {$else EXTDEBUG}
  1587. candidates.list(false);
  1588. {$endif EXTDEBUG}
  1589. { we'll just use the first candidate to make the
  1590. call }
  1591. end;
  1592. { assign procdefinition }
  1593. if symtableproc=nil then
  1594. symtableproc:=procdefinition.owner;
  1595. { update browser information }
  1596. if make_ref then
  1597. begin
  1598. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1599. inc(tprocdef(procdefinition).refcount);
  1600. if tprocdef(procdefinition).defref=nil then
  1601. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1602. end;
  1603. end
  1604. else
  1605. begin
  1606. { No candidates left, this must be a type error,
  1607. because wrong size is already checked. procdefinition
  1608. is filled with the first (random) definition that is
  1609. found. We use this definition to display a nice error
  1610. message that the wrong type is passed }
  1611. candidates.find_wrong_para;
  1612. candidates.list(true);
  1613. {$ifdef EXTDEBUG}
  1614. candidates.dump_info(V_Hint);
  1615. {$endif EXTDEBUG}
  1616. { We can not proceed, release all procs and exit }
  1617. candidates.free;
  1618. goto errorexit;
  1619. end;
  1620. candidates.free;
  1621. end; { end of procedure to call determination }
  1622. end;
  1623. { check for hints (deprecated etc) }
  1624. if (procdefinition.deftype = procdef) then
  1625. check_hints(tprocdef(procdefinition).procsym,tprocdef(procdefinition).symoptions);
  1626. { add needed default parameters }
  1627. if assigned(procdefinition) and
  1628. (paralength<procdefinition.maxparacount) then
  1629. begin
  1630. paraidx:=0;
  1631. i:=0;
  1632. while (i<paralength) do
  1633. begin
  1634. if paraidx>=procdefinition.Paras.count then
  1635. internalerror(200306181);
  1636. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  1637. inc(i);
  1638. inc(paraidx);
  1639. end;
  1640. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1641. inc(paraidx);
  1642. while (paraidx<procdefinition.paras.count) do
  1643. begin
  1644. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1645. internalerror(200212142);
  1646. left:=ccallparanode.create(genconstsymtree(
  1647. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  1648. { Ignore vs_hidden parameters }
  1649. repeat
  1650. inc(paraidx);
  1651. until (paraidx>=procdefinition.paras.count) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1652. end;
  1653. end;
  1654. { handle predefined procedures }
  1655. is_const:=(po_internconst in procdefinition.procoptions) and
  1656. ((block_type in [bt_const,bt_type]) or
  1657. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1658. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1659. begin
  1660. if assigned(left) then
  1661. begin
  1662. { ptr and settextbuf needs two args }
  1663. if assigned(tcallparanode(left).right) then
  1664. begin
  1665. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1666. left:=nil;
  1667. end
  1668. else
  1669. begin
  1670. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1671. tcallparanode(left).left:=nil;
  1672. end;
  1673. end
  1674. else
  1675. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1676. result:=hpt;
  1677. goto errorexit;
  1678. end;
  1679. { ensure that the result type is set }
  1680. if not(cnf_restypeset in callnodeflags) then
  1681. begin
  1682. { constructors return their current class type, not the type where the
  1683. constructor is declared, this can be different because of inheritance }
  1684. if (procdefinition.proctypeoption=potype_constructor) and
  1685. assigned(methodpointer) and
  1686. assigned(methodpointer.resulttype.def) and
  1687. (methodpointer.resulttype.def.deftype=classrefdef) then
  1688. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1689. else
  1690. { Member call to a (inherited) constructor from the class, the return
  1691. value is always self, so we change it to voidtype to generate an
  1692. error and to prevent users from generating non-working code
  1693. when they expect to clone the current instance, see bug 3662 (PFV) }
  1694. if (procdefinition.proctypeoption=potype_constructor) and
  1695. is_class(tprocdef(procdefinition)._class) and
  1696. assigned(methodpointer) and
  1697. (nf_is_self in methodpointer.flags) then
  1698. resulttype:=voidtype
  1699. else
  1700. resulttype:=procdefinition.rettype;
  1701. end
  1702. else
  1703. resulttype:=restype;
  1704. {if resulttype.def.needs_inittable then
  1705. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1706. if assigned(methodpointer) then
  1707. begin
  1708. { when methodpointer is a callnode we must load it first into a
  1709. temp to prevent the processing callnode twice }
  1710. if (methodpointer.nodetype=calln) then
  1711. internalerror(200405121);
  1712. { direct call to inherited abstract method, then we
  1713. can already give a error in the compiler instead
  1714. of a runtime error }
  1715. if (cnf_inherited in callnodeflags) and
  1716. (po_abstractmethod in procdefinition.procoptions) then
  1717. CGMessage(cg_e_cant_call_abstract_method);
  1718. { if an inherited con- or destructor should be }
  1719. { called in a con- or destructor then a warning }
  1720. { will be made }
  1721. { con- and destructors need a pointer to the vmt }
  1722. if (cnf_inherited in callnodeflags) and
  1723. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1724. is_object(methodpointer.resulttype.def) and
  1725. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1726. CGMessage(cg_w_member_cd_call_from_method);
  1727. if methodpointer.nodetype<>typen then
  1728. begin
  1729. { Remove all postfix operators }
  1730. hpt:=methodpointer;
  1731. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1732. hpt:=tunarynode(hpt).left;
  1733. if (procdefinition.proctypeoption=potype_constructor) and
  1734. assigned(symtableproc) and
  1735. (symtableproc.symtabletype=withsymtable) and
  1736. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1737. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1738. { R.Init then R will be initialized by the constructor,
  1739. Also allow it for simple loads }
  1740. if (procdefinition.proctypeoption=potype_constructor) or
  1741. ((hpt.nodetype=loadn) and
  1742. (
  1743. (methodpointer.resulttype.def.deftype=classrefdef) or
  1744. (
  1745. (methodpointer.resulttype.def.deftype=objectdef) and
  1746. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1747. )
  1748. )
  1749. ) then
  1750. set_varstate(methodpointer,vs_read,[])
  1751. else
  1752. set_varstate(methodpointer,vs_read,[vsf_must_be_valid]);
  1753. { The object is already used if it is called once }
  1754. if (hpt.nodetype=loadn) and
  1755. (tloadnode(hpt).symtableentry.typ in [localvarsym,paravarsym,globalvarsym]) then
  1756. set_varstate(hpt,vs_read,[]);
  1757. // tabstractvarsym(tloadnode(hpt).symtableentry).varstate:=vs_readwritten;
  1758. end;
  1759. { if we are calling the constructor check for abstract
  1760. methods. Ignore inherited and member calls, because the
  1761. class is then already created }
  1762. if (procdefinition.proctypeoption=potype_constructor) and
  1763. not(cnf_inherited in callnodeflags) and
  1764. not(cnf_member_call in callnodeflags) then
  1765. verifyabstractcalls;
  1766. end
  1767. else
  1768. begin
  1769. { When this is method the methodpointer must be available }
  1770. if (right=nil) and
  1771. (procdefinition.owner.symtabletype=objectsymtable) then
  1772. internalerror(200305061);
  1773. end;
  1774. { Set flag that the procedure uses varargs, also if they are not passed it is still
  1775. needed for x86_64 to pass the number of SSE registers used }
  1776. if po_varargs in procdefinition.procoptions then
  1777. include(callnodeflags,cnf_uses_varargs);
  1778. { Change loading of array of const to varargs }
  1779. if assigned(left) and
  1780. is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vartype.def) and
  1781. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  1782. convert_carg_array_of_const;
  1783. { bind parasyms to the callparanodes and insert hidden parameters }
  1784. bind_parasym;
  1785. { insert type conversions for parameters }
  1786. if assigned(left) then
  1787. tcallparanode(left).insert_typeconv(true);
  1788. errorexit:
  1789. aktcallnode:=oldcallnode;
  1790. end;
  1791. procedure tcallnode.order_parameters;
  1792. var
  1793. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  1794. currloc : tcgloc;
  1795. begin
  1796. hpfirst:=nil;
  1797. hpcurr:=tcallparanode(left);
  1798. while assigned(hpcurr) do
  1799. begin
  1800. { pull out }
  1801. hpnext:=tcallparanode(hpcurr.right);
  1802. { pull in at the correct place.
  1803. Used order:
  1804. 1. LOC_REFERENCE with smallest offset (x86 only)
  1805. 2. LOC_REFERENCE with most registers
  1806. 3. LOC_REGISTER with most registers
  1807. For the moment we only look at the first parameter field. Combining it
  1808. with multiple parameter fields will make things a lot complexer (PFV) }
  1809. if not assigned(hpcurr.parasym.paraloc[callerside].location) then
  1810. internalerror(200412152);
  1811. currloc:=hpcurr.parasym.paraloc[callerside].location^.loc;
  1812. hpprev:=nil;
  1813. hp:=hpfirst;
  1814. while assigned(hp) do
  1815. begin
  1816. case currloc of
  1817. LOC_REFERENCE :
  1818. begin
  1819. case hp.parasym.paraloc[callerside].location^.loc of
  1820. LOC_REFERENCE :
  1821. begin
  1822. { Offset is calculated like:
  1823. sub esp,12
  1824. mov [esp+8],para3
  1825. mov [esp+4],para2
  1826. mov [esp],para1
  1827. call function
  1828. That means the for pushes the para with the
  1829. highest offset (see para3) needs to be pushed first
  1830. }
  1831. if (hpcurr.registersint>hp.registersint)
  1832. {$ifdef x86}
  1833. or (hpcurr.parasym.paraloc[callerside].location^.reference.offset>hp.parasym.paraloc[callerside].location^.reference.offset)
  1834. {$endif x86}
  1835. then
  1836. break;
  1837. end;
  1838. LOC_REGISTER,
  1839. LOC_FPUREGISTER :
  1840. break;
  1841. end;
  1842. end;
  1843. LOC_FPUREGISTER,
  1844. LOC_REGISTER :
  1845. begin
  1846. if (hp.parasym.paraloc[callerside].location^.loc=currloc) and
  1847. (hpcurr.registersint>hp.registersint) then
  1848. break;
  1849. end;
  1850. end;
  1851. hpprev:=hp;
  1852. hp:=tcallparanode(hp.right);
  1853. end;
  1854. hpcurr.right:=hp;
  1855. if assigned(hpprev) then
  1856. hpprev.right:=hpcurr
  1857. else
  1858. hpfirst:=hpcurr;
  1859. { next }
  1860. hpcurr:=hpnext;
  1861. end;
  1862. left:=hpfirst;
  1863. end;
  1864. function tcallnode.replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  1865. var
  1866. paras: tcallparanode;
  1867. temp: tnode;
  1868. begin
  1869. result := fen_false;
  1870. n.fileinfo := pfileposinfo(arg)^;
  1871. if (n.nodetype = loadn) then
  1872. begin
  1873. case tloadnode(n).symtableentry.typ of
  1874. paravarsym :
  1875. begin
  1876. paras := tcallparanode(left);
  1877. while assigned(paras) and
  1878. (paras.parasym <> tloadnode(n).symtableentry) do
  1879. paras := tcallparanode(paras.right);
  1880. if assigned(paras) then
  1881. begin
  1882. n.free;
  1883. n := paras.left.getcopy;
  1884. resulttypepass(n);
  1885. result := fen_true;
  1886. end;
  1887. end;
  1888. localvarsym :
  1889. begin
  1890. { local? }
  1891. if (tloadnode(n).symtableentry.owner <> tprocdef(procdefinition).localst) then
  1892. exit;
  1893. if (tloadnode(n).symtableentry.indexnr >= inlinelocals.count) or
  1894. not assigned(inlinelocals[tloadnode(n).symtableentry.indexnr]) then
  1895. internalerror(20040720);
  1896. temp := tnode(inlinelocals[tloadnode(n).symtableentry.indexnr]).getcopy;
  1897. n.free;
  1898. n := temp;
  1899. resulttypepass(n);
  1900. result := fen_true;
  1901. end;
  1902. end;
  1903. end;
  1904. end;
  1905. type
  1906. ptempnodes = ^ttempnodes;
  1907. ttempnodes = record
  1908. createstatement, deletestatement: tstatementnode;
  1909. end;
  1910. procedure tcallnode.createlocaltemps(p:TNamedIndexItem;arg:pointer);
  1911. var
  1912. tempinfo: ptempnodes absolute arg;
  1913. tempnode: ttempcreatenode;
  1914. begin
  1915. if (tsymentry(p).typ <> localvarsym) then
  1916. exit;
  1917. if (p.indexnr >= inlinelocals.count) then
  1918. inlinelocals.count:=p.indexnr+10;
  1919. if (vo_is_funcret in tabstractvarsym(p).varoptions) and
  1920. assigned(funcretnode) then
  1921. begin
  1922. if node_complexity(funcretnode) > 1 then
  1923. begin
  1924. { can this happen? }
  1925. { we may have to replace the funcretnode with the address of funcretnode }
  1926. { loaded in a temp in this case, because the expression may e.g. contain }
  1927. { a global variable that gets changed inside the function }
  1928. internalerror(2004072101);
  1929. end;
  1930. inlinelocals[tabstractvarsym(p).indexnr] := funcretnode.getcopy
  1931. end
  1932. else
  1933. begin
  1934. tempnode := ctempcreatenode.create(tabstractvarsym(p).vartype,tabstractvarsym(p).vartype.def.size,tt_persistent,tabstractvarsym(p).varregable<>vr_none);
  1935. addstatement(tempinfo^.createstatement,tempnode);
  1936. if assigned(tlocalvarsym(p).defaultconstsym) then
  1937. begin
  1938. { warning: duplicate from psub.pas:initializevars() -> must refactor }
  1939. addstatement(tempinfo^.createstatement,cassignmentnode.create(
  1940. ctemprefnode.create(tempnode),
  1941. cloadnode.create(tlocalvarsym(p).defaultconstsym,tlocalvarsym(p).defaultconstsym.owner)));
  1942. end;
  1943. if (vo_is_funcret in tlocalvarsym(p).varoptions) then
  1944. begin
  1945. funcretnode := ctemprefnode.create(tempnode);
  1946. addstatement(tempinfo^.deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  1947. end
  1948. else
  1949. addstatement(tempinfo^.deletestatement,ctempdeletenode.create(tempnode));
  1950. inlinelocals[p.indexnr] := ctemprefnode.create(tempnode);
  1951. end;
  1952. end;
  1953. procedure tcallnode.createinlineparas(var createstatement, deletestatement: tstatementnode);
  1954. var
  1955. para: tcallparanode;
  1956. tempnode: ttempcreatenode;
  1957. tempnodes: ttempnodes;
  1958. n: tnode;
  1959. begin
  1960. { parameters }
  1961. para := tcallparanode(left);
  1962. while assigned(para) do
  1963. begin
  1964. if (para.parasym.typ = paravarsym) and
  1965. { para.left will already be the same as funcretnode in the following case, so don't change }
  1966. (not(vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1967. (not assigned(funcretnode))) then
  1968. begin
  1969. { must take copy of para.left, because if it contains a }
  1970. { temprefn pointing to a copied temp (e.g. methodpointer), }
  1971. { then this parameter must be changed to point to the copy of }
  1972. { that temp (JM) }
  1973. n := para.left.getcopy;
  1974. para.left.free;
  1975. para.left := n;
  1976. { create temps for value parameters, function result and also for }
  1977. { const parameters which are passed by value instead of by reference }
  1978. { we need to take care that we use the type of the defined parameter and not of the
  1979. passed parameter, because these can be different in case of a formaldef (PFV) }
  1980. if
  1981. (
  1982. { the problem is that we can't take the address of a function result :( }
  1983. (vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1984. (para.parasym.varspez = vs_value) or
  1985. ((para.parasym.varspez = vs_const) and
  1986. (para.parasym.vartype.def.deftype<>formaldef) and
  1987. { the compiler expects that it can take the address of parameters passed by reference in
  1988. the case of const so we can't replace the node simply by a constant node
  1989. When playing with this code, ensure that
  1990. function f(const a,b : longint) : longint;inline;
  1991. begin
  1992. result:=a*b;
  1993. end;
  1994. [...]
  1995. ...:=f(10,20));
  1996. [...]
  1997. is still folded. (FK)
  1998. }
  1999. (
  2000. { this must be a not ... of course }
  2001. not(paramanager.push_addr_param(vs_const,para.parasym.vartype.def,procdefinition.proccalloption)) or
  2002. (node_complexity(para.left) >= NODE_COMPLEXITY_INF)
  2003. ))
  2004. ) then
  2005. begin
  2006. { in theory, this is always regable, but ncgcall can't }
  2007. { handle it yet in all situations (JM) }
  2008. tempnode := ctempcreatenode.create(para.parasym.vartype,para.parasym.vartype.def.size,tt_persistent,tparavarsym(para.parasym).varregable <> vr_none);
  2009. addstatement(createstatement,tempnode);
  2010. { assign the value of the parameter to the temp, except in case of the function result }
  2011. { (in that case, para.left is a block containing the creation of a new temp, while we }
  2012. { only need a temprefnode, so delete the old stuff) }
  2013. if not(vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  2014. begin
  2015. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2016. para.left));
  2017. para.left := ctemprefnode.create(tempnode);
  2018. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2019. end
  2020. else
  2021. begin
  2022. if not(assigned(funcretnode)) then
  2023. funcretnode := ctemprefnode.create(tempnode);
  2024. para.left.free;
  2025. para.left := ctemprefnode.create(tempnode);
  2026. addstatement(deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  2027. end
  2028. end
  2029. else if (node_complexity(para.left) > 1) then
  2030. begin
  2031. tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent,tparavarsym(para.parasym).varregable<>vr_none);
  2032. addstatement(createstatement,tempnode);
  2033. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2034. caddrnode.create_internal(para.left)));
  2035. para.left := ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),para.left.resulttype);
  2036. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2037. end;
  2038. end;
  2039. para := tcallparanode(para.right);
  2040. end;
  2041. { local variables }
  2042. if not assigned(tprocdef(procdefinition).localst) or
  2043. (tprocdef(procdefinition).localst.symindex.count = 0) then
  2044. exit;
  2045. tempnodes.createstatement := createstatement;
  2046. tempnodes.deletestatement := deletestatement;
  2047. inlinelocals.count:=tprocdef(procdefinition).localst.symindex.count;
  2048. tprocdef(procdefinition).localst.foreach(@createlocaltemps,@tempnodes);
  2049. createstatement := tempnodes.createstatement;
  2050. deletestatement := tempnodes.deletestatement;
  2051. end;
  2052. function tcallnode.pass1_inline:tnode;
  2053. var
  2054. createstatement,deletestatement: tstatementnode;
  2055. createblock,deleteblock: tblocknode;
  2056. body : tnode;
  2057. i: longint;
  2058. begin
  2059. if not(assigned(tprocdef(procdefinition).inlininginfo) and
  2060. assigned(tprocdef(procdefinition).inlininginfo^.code)) then
  2061. internalerror(200412021);
  2062. { inherit flags }
  2063. current_procinfo.flags := current_procinfo.flags + ((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  2064. { create blocks for loading/deleting of local data }
  2065. createblock:=internalstatements(createstatement);
  2066. deleteblock:=internalstatements(deletestatement);
  2067. { add methodpointer init code to init statement }
  2068. { (fini must be done later, as it will delete the hookoncopy info) }
  2069. if assigned(methodpointerinit) then
  2070. addstatement(createstatement,methodpointerinit.getcopy);
  2071. inlinelocals:=tlist.create;
  2072. { get copy of the procedure body }
  2073. body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
  2074. { replace complex parameters with temps }
  2075. createinlineparas(createstatement,deletestatement);
  2076. { replace the parameter loads with the parameter values }
  2077. foreachnode(body,@replaceparaload,@fileinfo);
  2078. { copy methodpointer fini code }
  2079. if assigned(methodpointerdone) then
  2080. addstatement(deletestatement,methodpointerdone.getcopy);
  2081. { free the temps for the locals }
  2082. for i := 0 to inlinelocals.count-1 do
  2083. if assigned(inlinelocals[i]) then
  2084. tnode(inlinelocals[i]).free;
  2085. inlinelocals.free;
  2086. inlinelocals:=nil;
  2087. addstatement(createstatement,body);
  2088. addstatement(createstatement,deleteblock);
  2089. { set function result location if necessary }
  2090. if assigned(funcretnode) and
  2091. (cnf_return_value_used in callnodeflags) then
  2092. addstatement(createstatement,funcretnode.getcopy);
  2093. { consider it must not be inlined if called
  2094. again inside the args or itself }
  2095. exclude(procdefinition.procoptions,po_inline);
  2096. firstpass(createblock);
  2097. include(procdefinition.procoptions,po_inline);
  2098. { return inlined block }
  2099. result := createblock;
  2100. {$ifdef DEBUGINLINE}
  2101. writeln;
  2102. writeln('**************************',tprocdef(procdefinition).mangledname);
  2103. printnode(output,result);
  2104. {$endif DEBUGINLINE}
  2105. end;
  2106. function tcallnode.pass_1 : tnode;
  2107. var
  2108. st : tsymtable;
  2109. begin
  2110. result:=nil;
  2111. { Can we inline the procedure? }
  2112. if ([po_inline,po_has_inlininginfo] <= procdefinition.procoptions) then
  2113. begin
  2114. { Check if we can inline the procedure when it references proc/var that
  2115. are not in the globally available }
  2116. st:=procdefinition.owner;
  2117. if (st.symtabletype=objectsymtable) then
  2118. st:=st.defowner.owner;
  2119. if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
  2120. (st.symtabletype=globalsymtable) and
  2121. (not st.iscurrentunit) then
  2122. begin
  2123. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
  2124. end
  2125. else
  2126. begin
  2127. result:=pass1_inline;
  2128. exit;
  2129. end;
  2130. end;
  2131. { calculate the parameter info for the procdef }
  2132. if not procdefinition.has_paraloc_info then
  2133. begin
  2134. procdefinition.requiredargarea:=paramanager.create_paraloc_info(procdefinition,callerside);
  2135. procdefinition.has_paraloc_info:=true;
  2136. end;
  2137. { calculate the parameter size needed for this call include varargs if they are available }
  2138. if assigned(varargsparas) then
  2139. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  2140. else
  2141. pushedparasize:=procdefinition.requiredargarea;
  2142. { record maximum parameter size used in this proc }
  2143. current_procinfo.allocate_push_parasize(pushedparasize);
  2144. { work trough all parameters to get the register requirements }
  2145. if assigned(left) then
  2146. tcallparanode(left).det_registers;
  2147. { order parameters }
  2148. order_parameters;
  2149. if assigned(methodpointerinit) then
  2150. firstpass(methodpointerinit);
  2151. if assigned(methodpointerdone) then
  2152. firstpass(methodpointerdone);
  2153. { function result node }
  2154. if assigned(_funcretnode) then
  2155. firstpass(_funcretnode);
  2156. { procedure variable ? }
  2157. if assigned(right) then
  2158. firstpass(right);
  2159. if not (block_type in [bt_const,bt_type]) then
  2160. include(current_procinfo.flags,pi_do_call);
  2161. { implicit finally needed ? }
  2162. if resulttype.def.needs_inittable and
  2163. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  2164. not assigned(funcretnode) then
  2165. include(current_procinfo.flags,pi_needs_implicit_finally);
  2166. { get a register for the return value }
  2167. if (not is_void(resulttype.def)) then
  2168. begin
  2169. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2170. begin
  2171. expectloc:=LOC_REFERENCE;
  2172. end
  2173. else
  2174. { for win32 records returned in EDX:EAX, we
  2175. move them to memory after ... }
  2176. if (resulttype.def.deftype=recorddef) then
  2177. begin
  2178. expectloc:=LOC_REFERENCE;
  2179. end
  2180. else
  2181. { ansi/widestrings must be registered, so we can dispose them }
  2182. if is_ansistring(resulttype.def) or
  2183. is_widestring(resulttype.def) then
  2184. begin
  2185. expectloc:=LOC_REFERENCE;
  2186. registersint:=1;
  2187. end
  2188. else
  2189. { we have only to handle the result if it is used }
  2190. if (cnf_return_value_used in callnodeflags) then
  2191. begin
  2192. case resulttype.def.deftype of
  2193. enumdef,
  2194. orddef :
  2195. begin
  2196. if (procdefinition.proctypeoption=potype_constructor) then
  2197. begin
  2198. expectloc:=LOC_REGISTER;
  2199. registersint:=1;
  2200. end
  2201. else
  2202. begin
  2203. expectloc:=LOC_REGISTER;
  2204. if is_64bit(resulttype.def) then
  2205. registersint:=2
  2206. else
  2207. registersint:=1;
  2208. end;
  2209. end;
  2210. floatdef :
  2211. begin
  2212. expectloc:=LOC_FPUREGISTER;
  2213. {$ifdef cpufpemu}
  2214. if (cs_fp_emulation in aktmoduleswitches) then
  2215. registersint:=1
  2216. else
  2217. {$endif cpufpemu}
  2218. {$ifdef m68k}
  2219. if (tfloatdef(resulttype.def).typ=s32real) then
  2220. registersint:=1
  2221. else
  2222. {$endif m68k}
  2223. registersfpu:=1;
  2224. end;
  2225. else
  2226. begin
  2227. expectloc:=LOC_REGISTER;
  2228. registersint:=1;
  2229. end;
  2230. end;
  2231. end
  2232. else
  2233. expectloc:=LOC_VOID;
  2234. end
  2235. else
  2236. expectloc:=LOC_VOID;
  2237. {$ifdef m68k}
  2238. { we need one more address register for virtual calls on m68k }
  2239. if (po_virtualmethod in procdefinition.procoptions) then
  2240. inc(registersint);
  2241. {$endif m68k}
  2242. { a fpu can be used in any procedure !! }
  2243. {$ifdef i386}
  2244. registersfpu:=procdefinition.fpu_used;
  2245. {$endif i386}
  2246. { if this is a call to a method calc the registers }
  2247. if (methodpointer<>nil) then
  2248. begin
  2249. if methodpointer.nodetype<>typen then
  2250. begin
  2251. firstpass(methodpointer);
  2252. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2253. registersint:=max(methodpointer.registersint,registersint);
  2254. {$ifdef SUPPORT_MMX }
  2255. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2256. {$endif SUPPORT_MMX}
  2257. end;
  2258. end;
  2259. { determine the registers of the procedure variable }
  2260. { is this OK for inlined procs also ?? (PM) }
  2261. if assigned(right) then
  2262. begin
  2263. registersfpu:=max(right.registersfpu,registersfpu);
  2264. registersint:=max(right.registersint,registersint);
  2265. {$ifdef SUPPORT_MMX}
  2266. registersmmx:=max(right.registersmmx,registersmmx);
  2267. {$endif SUPPORT_MMX}
  2268. end;
  2269. { determine the registers of the procedure }
  2270. if assigned(left) then
  2271. begin
  2272. registersfpu:=max(left.registersfpu,registersfpu);
  2273. registersint:=max(left.registersint,registersint);
  2274. {$ifdef SUPPORT_MMX}
  2275. registersmmx:=max(left.registersmmx,registersmmx);
  2276. {$endif SUPPORT_MMX}
  2277. end;
  2278. end;
  2279. {$ifdef state_tracking}
  2280. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2281. var hp:Tcallparanode;
  2282. value:Tnode;
  2283. begin
  2284. track_state_pass:=false;
  2285. hp:=Tcallparanode(left);
  2286. while assigned(hp) do
  2287. begin
  2288. if left.track_state_pass(exec_known) then
  2289. begin
  2290. left.resulttype.def:=nil;
  2291. do_resulttypepass(left);
  2292. end;
  2293. value:=aktstate.find_fact(hp.left);
  2294. if value<>nil then
  2295. begin
  2296. track_state_pass:=true;
  2297. hp.left.destroy;
  2298. hp.left:=value.getcopy;
  2299. do_resulttypepass(hp.left);
  2300. end;
  2301. hp:=Tcallparanode(hp.right);
  2302. end;
  2303. end;
  2304. {$endif}
  2305. function tcallnode.para_count:longint;
  2306. var
  2307. ppn : tcallparanode;
  2308. begin
  2309. result:=0;
  2310. ppn:=tcallparanode(left);
  2311. while assigned(ppn) do
  2312. begin
  2313. if not(assigned(ppn.parasym) and
  2314. (vo_is_hidden_para in ppn.parasym.varoptions)) then
  2315. inc(result);
  2316. ppn:=tcallparanode(ppn.right);
  2317. end;
  2318. end;
  2319. function tcallnode.get_load_methodpointer:tnode;
  2320. var
  2321. newstatement : tstatementnode;
  2322. begin
  2323. if assigned(methodpointerinit) then
  2324. begin
  2325. result:=internalstatements(newstatement);
  2326. addstatement(newstatement,methodpointerinit);
  2327. addstatement(newstatement,methodpointer);
  2328. addstatement(newstatement,methodpointerdone);
  2329. methodpointerinit:=nil;
  2330. methodpointer:=nil;
  2331. methodpointerdone:=nil;
  2332. end
  2333. else
  2334. begin
  2335. result:=methodpointer;
  2336. methodpointer:=nil;
  2337. end;
  2338. end;
  2339. function tcallnode.docompare(p: tnode): boolean;
  2340. begin
  2341. docompare :=
  2342. inherited docompare(p) and
  2343. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2344. (procdefinition = tcallnode(p).procdefinition) and
  2345. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2346. (((cnf_restypeset in callnodeflags) and (cnf_restypeset in tcallnode(p).callnodeflags) and
  2347. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2348. (not(cnf_restypeset in callnodeflags) and not(cnf_restypeset in tcallnode(p).callnodeflags)));
  2349. end;
  2350. procedure tcallnode.printnodedata(var t:text);
  2351. begin
  2352. if assigned(procdefinition) and
  2353. (procdefinition.deftype=procdef) then
  2354. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2355. else
  2356. begin
  2357. if assigned(symtableprocentry) then
  2358. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2359. else
  2360. writeln(t,printnodeindention,'proc = <nil>');
  2361. end;
  2362. printnode(t,methodpointer);
  2363. printnode(t,right);
  2364. printnode(t,left);
  2365. end;
  2366. begin
  2367. ccallnode:=tcallnode;
  2368. ccallparanode:=tcallparanode;
  2369. end.