ncal.pas 99 KB

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