ncal.pas 100 KB

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