ncal.pas 99 KB

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