ncal.pas 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608
  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. { for ordinals, floats and enums, verify if we might cause
  568. some range-check errors. }
  569. if (parasym.vartype.def.deftype in [enumdef,orddef,floatdef]) and
  570. (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) and
  571. (left.nodetype in [vecn,loadn,calln]) then
  572. begin
  573. if (left.resulttype.def.size>parasym.vartype.def.size) then
  574. begin
  575. if (cs_check_range in aktlocalswitches) then
  576. Message(type_w_smaller_possible_range_check)
  577. else
  578. Message(type_h_smaller_possible_range_check);
  579. end;
  580. end;
  581. inserttypeconv(left,parasym.vartype);
  582. end;
  583. if codegenerror then
  584. begin
  585. dec(parsing_para_level);
  586. exit;
  587. end;
  588. end;
  589. { check var strings }
  590. if (cs_strict_var_strings in aktlocalswitches) and
  591. is_shortstring(left.resulttype.def) and
  592. is_shortstring(parasym.vartype.def) and
  593. (parasym.varspez in [vs_out,vs_var]) and
  594. not(is_open_string(parasym.vartype.def)) and
  595. not(equal_defs(left.resulttype.def,parasym.vartype.def)) then
  596. begin
  597. aktfilepos:=left.fileinfo;
  598. CGMessage(type_e_strict_var_string_violation);
  599. end;
  600. { Handle formal parameters separate }
  601. if (parasym.vartype.def.deftype=formaldef) then
  602. begin
  603. { load procvar if a procedure is passed }
  604. if ((m_tp_procvar in aktmodeswitches) or
  605. (m_mac_procvar in aktmodeswitches)) and
  606. (left.nodetype=calln) and
  607. (is_void(left.resulttype.def)) then
  608. load_procvar_from_calln(left);
  609. case parasym.varspez of
  610. vs_var,
  611. vs_out :
  612. begin
  613. if not valid_for_formal_var(left,true) then
  614. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  615. end;
  616. vs_const :
  617. begin
  618. if not valid_for_formal_const(left,true) then
  619. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  620. end;
  621. end;
  622. end
  623. else
  624. begin
  625. { check if the argument is allowed }
  626. if (parasym.varspez in [vs_out,vs_var]) then
  627. valid_for_var(left,true);
  628. end;
  629. if parasym.varspez in [vs_var,vs_out] then
  630. set_unique(left);
  631. { When the address needs to be pushed then the register is
  632. not regable. Exception is when the location is also a var
  633. parameter and we can pass the address transparently }
  634. if (
  635. not(
  636. (vo_is_hidden_para in parasym.varoptions) and
  637. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  638. ) and
  639. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  640. aktcallnode.procdefinition.proccalloption) and
  641. not(
  642. (left.nodetype=loadn) and
  643. (tloadnode(left).is_addr_param_load)
  644. )
  645. ) then
  646. make_not_regable(left);
  647. if do_count then
  648. begin
  649. case parasym.varspez of
  650. vs_out :
  651. set_varstate(left,vs_written,[]);
  652. vs_var :
  653. set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
  654. else
  655. set_varstate(left,vs_read,[vsf_must_be_valid]);
  656. end;
  657. end;
  658. { must only be done after typeconv PM }
  659. resulttype:=parasym.vartype;
  660. end;
  661. end;
  662. { process next node }
  663. if assigned(right) then
  664. tcallparanode(right).insert_typeconv(do_count);
  665. dec(parsing_para_level);
  666. {$ifdef extdebug}
  667. if do_count then
  668. count_ref:=store_count_ref;
  669. {$endif def extdebug}
  670. end;
  671. procedure tcallparanode.det_registers;
  672. begin
  673. if assigned(right) then
  674. begin
  675. tcallparanode(right).det_registers;
  676. registersint:=right.registersint;
  677. registersfpu:=right.registersfpu;
  678. {$ifdef SUPPORT_MMX}
  679. registersmmx:=right.registersmmx;
  680. {$endif}
  681. end;
  682. firstpass(left);
  683. if left.registersint>registersint then
  684. registersint:=left.registersint;
  685. if left.registersfpu>registersfpu then
  686. registersfpu:=left.registersfpu;
  687. {$ifdef SUPPORT_MMX}
  688. if left.registersmmx>registersmmx then
  689. registersmmx:=left.registersmmx;
  690. {$endif SUPPORT_MMX}
  691. end;
  692. procedure tcallparanode.firstcallparan;
  693. begin
  694. if not assigned(left.resulttype.def) then
  695. get_paratype;
  696. det_registers;
  697. end;
  698. function tcallparanode.docompare(p: tnode): boolean;
  699. begin
  700. docompare :=
  701. inherited docompare(p) and
  702. (callparaflags = tcallparanode(p).callparaflags)
  703. ;
  704. end;
  705. procedure tcallparanode.printnodetree(var t:text);
  706. begin
  707. printnodelist(t);
  708. end;
  709. {****************************************************************************
  710. TCALLNODE
  711. ****************************************************************************}
  712. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);
  713. begin
  714. inherited create(calln,l,nil);
  715. symtableprocentry:=v;
  716. symtableproc:=st;
  717. callnodeflags:=callflags+[cnf_return_value_used];
  718. methodpointer:=mp;
  719. methodpointerinit:=nil;
  720. methodpointerdone:=nil;
  721. procdefinition:=nil;
  722. _funcretnode:=nil;
  723. {$ifdef PASS2INLINE}
  724. inlinecode:=nil;
  725. {$endif PASS2INLINE}
  726. paralength:=-1;
  727. varargsparas:=nil;
  728. end;
  729. constructor tcallnode.create_procvar(l,r:tnode);
  730. begin
  731. inherited create(calln,l,r);
  732. symtableprocentry:=nil;
  733. symtableproc:=nil;
  734. methodpointer:=nil;
  735. methodpointerinit:=nil;
  736. methodpointerdone:=nil;
  737. procdefinition:=nil;
  738. callnodeflags:=[cnf_return_value_used];
  739. _funcretnode:=nil;
  740. {$ifdef PASS2INLINE}
  741. inlinecode:=nil;
  742. {$endif PASS2INLINE}
  743. paralength:=-1;
  744. varargsparas:=nil;
  745. end;
  746. constructor tcallnode.createintern(const name: string; params: tnode);
  747. var
  748. srsym: tsym;
  749. symowner: tsymtable;
  750. begin
  751. if not (cs_compilesystem in aktmoduleswitches) then
  752. begin
  753. srsym := searchsymonlyin(systemunit,name);
  754. symowner := systemunit;
  755. end
  756. else
  757. begin
  758. searchsym(name,srsym,symowner);
  759. if not assigned(srsym) then
  760. searchsym(upper(name),srsym,symowner);
  761. end;
  762. if not assigned(srsym) or
  763. (srsym.typ <> procsym) then
  764. Message1(cg_f_unknown_compiler,name);
  765. self.create(params,tprocsym(srsym),symowner,nil,[]);
  766. end;
  767. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  768. begin
  769. self.createintern(name,params);
  770. restype := res;
  771. include(callnodeflags,cnf_restypeset);
  772. { both the normal and specified resulttype either have to be returned via a }
  773. { parameter or not, but no mixing (JM) }
  774. if paramanager.ret_in_param(restype.def,symtableprocentry.first_procdef.proccalloption) xor
  775. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  776. internalerror(200108291);
  777. end;
  778. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  779. begin
  780. self.createintern(name,params);
  781. _funcretnode:=returnnode;
  782. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  783. internalerror(200204247);
  784. end;
  785. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  786. var
  787. para: tcallparanode;
  788. begin
  789. if assigned(_funcretnode) then
  790. _funcretnode.free;
  791. _funcretnode := returnnode;
  792. { if the resulttype pass hasn't occurred yet, that one will do }
  793. { everything }
  794. if assigned(resulttype.def) then
  795. begin
  796. { these are returned as values, but we can optimize their loading }
  797. { as well }
  798. if is_ansistring(resulttype.def) or
  799. is_widestring(resulttype.def) then
  800. exit;
  801. para := tcallparanode(left);
  802. while assigned(para) do
  803. begin
  804. if (vo_is_hidden_para in para.parasym.varoptions) and
  805. (vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  806. begin
  807. para.left.free;
  808. para.left := _funcretnode.getcopy;
  809. exit;
  810. end;
  811. para := tcallparanode(para.right);
  812. end;
  813. { no hidden resultpara found, error! }
  814. if not(po_inline in procdefinition.procoptions) then
  815. internalerror(200306087);
  816. end;
  817. end;
  818. destructor tcallnode.destroy;
  819. var
  820. i : longint;
  821. begin
  822. methodpointer.free;
  823. methodpointerinit.free;
  824. methodpointerdone.free;
  825. _funcretnode.free;
  826. {$ifdef PASS2INLINE}
  827. inlinecode.free;
  828. {$endif PASS2INLINE}
  829. if assigned(varargsparas) then
  830. begin
  831. for i:=0 to varargsparas.count-1 do
  832. tparavarsym(varargsparas[i]).free;
  833. varargsparas.free;
  834. end;
  835. inherited destroy;
  836. end;
  837. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  838. begin
  839. inherited ppuload(t,ppufile);
  840. ppufile.getderef(symtableprocentryderef);
  841. {$ifdef fpc}
  842. {$warning FIXME: No withsymtable support}
  843. {$endif}
  844. symtableproc:=nil;
  845. ppufile.getderef(procdefinitionderef);
  846. ppufile.getsmallset(callnodeflags);
  847. methodpointer:=ppuloadnode(ppufile);
  848. methodpointerinit:=tblocknode(ppuloadnode(ppufile));
  849. methodpointerdone:=tblocknode(ppuloadnode(ppufile));
  850. _funcretnode:=ppuloadnode(ppufile);
  851. {$ifdef PASS2INLINE}
  852. inlinecode:=ppuloadnode(ppufile);
  853. {$endif PASS2INLINE}
  854. end;
  855. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  856. begin
  857. inherited ppuwrite(ppufile);
  858. ppufile.putderef(symtableprocentryderef);
  859. ppufile.putderef(procdefinitionderef);
  860. ppufile.putsmallset(callnodeflags);
  861. ppuwritenode(ppufile,methodpointer);
  862. ppuwritenode(ppufile,methodpointerinit);
  863. ppuwritenode(ppufile,methodpointerdone);
  864. ppuwritenode(ppufile,_funcretnode);
  865. {$ifdef PASS2INLINE}
  866. ppuwritenode(ppufile,inlinecode);
  867. {$endif PASS2INLINE}
  868. end;
  869. procedure tcallnode.buildderefimpl;
  870. begin
  871. inherited buildderefimpl;
  872. symtableprocentryderef.build(symtableprocentry);
  873. procdefinitionderef.build(procdefinition);
  874. if assigned(methodpointer) then
  875. methodpointer.buildderefimpl;
  876. if assigned(methodpointerinit) then
  877. methodpointerinit.buildderefimpl;
  878. if assigned(methodpointerdone) then
  879. methodpointerdone.buildderefimpl;
  880. if assigned(_funcretnode) then
  881. _funcretnode.buildderefimpl;
  882. {$ifdef PASS2INLINE}
  883. if assigned(inlinecode) then
  884. inlinecode.buildderefimpl;
  885. {$endif PASS2INLINE}
  886. end;
  887. procedure tcallnode.derefimpl;
  888. var
  889. pt : tcallparanode;
  890. i : integer;
  891. begin
  892. inherited derefimpl;
  893. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  894. if assigned(symtableprocentry) then
  895. symtableproc:=symtableprocentry.owner;
  896. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  897. if assigned(methodpointer) then
  898. methodpointer.derefimpl;
  899. if assigned(methodpointerinit) then
  900. methodpointerinit.derefimpl;
  901. if assigned(methodpointerdone) then
  902. methodpointerdone.derefimpl;
  903. if assigned(_funcretnode) then
  904. _funcretnode.derefimpl;
  905. {$ifdef PASS2INLINE}
  906. if assigned(inlinecode) then
  907. inlinecode.derefimpl;
  908. {$endif PASS2INLINE}
  909. { Connect parasyms }
  910. pt:=tcallparanode(left);
  911. while assigned(pt) and
  912. (cpf_varargs_para in pt.callparaflags) do
  913. pt:=tcallparanode(pt.right);
  914. for i:=procdefinition.paras.count-1 downto 0 do
  915. begin
  916. if not assigned(pt) then
  917. internalerror(200311077);
  918. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  919. pt:=tcallparanode(pt.right);
  920. end;
  921. if assigned(pt) then
  922. internalerror(200311078);
  923. end;
  924. function tcallnode.getcopy : tnode;
  925. var
  926. n : tcallnode;
  927. i : integer;
  928. hp,hpn : tparavarsym;
  929. oldleft : tnode;
  930. begin
  931. { Need to use a hack here to prevent the parameters from being copied.
  932. The parameters must be copied between methodpointerinit/methodpointerdone because
  933. the can reference methodpointer }
  934. oldleft:=left;
  935. left:=nil;
  936. n:=tcallnode(inherited getcopy);
  937. left:=oldleft;
  938. n.symtableprocentry:=symtableprocentry;
  939. n.symtableproc:=symtableproc;
  940. n.procdefinition:=procdefinition;
  941. n.restype := restype;
  942. n.callnodeflags := callnodeflags;
  943. if assigned(methodpointerinit) then
  944. n.methodpointerinit:=tblocknode(methodpointerinit.getcopy)
  945. else
  946. n.methodpointerinit:=nil;
  947. { methodpointerinit is copied, now references to the temp will also be copied
  948. correctly. We can now copy the parameters and methodpointer }
  949. if assigned(left) then
  950. n.left:=left.getcopy
  951. else
  952. n.left:=nil;
  953. if assigned(methodpointer) then
  954. n.methodpointer:=methodpointer.getcopy
  955. else
  956. n.methodpointer:=nil;
  957. if assigned(methodpointerdone) then
  958. n.methodpointerdone:=tblocknode(methodpointerdone.getcopy)
  959. else
  960. n.methodpointerdone:=nil;
  961. if assigned(_funcretnode) then
  962. n._funcretnode:=_funcretnode.getcopy
  963. else
  964. n._funcretnode:=nil;
  965. {$ifdef PASS2INLINE}
  966. if assigned(inlinecode) then
  967. n.inlinecode:=inlinecode.getcopy
  968. else
  969. n.inlinecode:=nil;
  970. {$endif PASS2INLINE}
  971. if assigned(varargsparas) then
  972. begin
  973. n.varargsparas:=tvarargsparalist.create;
  974. for i:=0 to varargsparas.count-1 do
  975. begin
  976. hp:=tparavarsym(varargsparas[i]);
  977. hpn:=tparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vartype,[]);
  978. n.varargsparas.add(hpn);
  979. end;
  980. end
  981. else
  982. n.varargsparas:=nil;
  983. result:=n;
  984. end;
  985. procedure tcallnode.insertintolist(l : tnodelist);
  986. begin
  987. end;
  988. procedure tcallnode.convert_carg_array_of_const;
  989. var
  990. hp : tarrayconstructornode;
  991. oldleft : tcallparanode;
  992. begin
  993. oldleft:=tcallparanode(left);
  994. if oldleft.left.nodetype<>arrayconstructorn then
  995. begin
  996. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
  997. exit;
  998. end;
  999. include(callnodeflags,cnf_uses_varargs);
  1000. { Get arrayconstructor node and insert typeconvs }
  1001. hp:=tarrayconstructornode(oldleft.left);
  1002. hp.insert_typeconvs;
  1003. { Add c args parameters }
  1004. { It could be an empty set }
  1005. if assigned(hp) and
  1006. assigned(hp.left) then
  1007. begin
  1008. while assigned(hp) do
  1009. begin
  1010. left:=ccallparanode.create(hp.left,left);
  1011. { set callparanode resulttype and flags }
  1012. left.resulttype:=hp.left.resulttype;
  1013. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  1014. hp.left:=nil;
  1015. hp:=tarrayconstructornode(hp.right);
  1016. end;
  1017. end;
  1018. { Remove value of old array of const parameter, but keep it
  1019. in the list because it is required for bind_parasym.
  1020. Generate a nothign to keep callparanoed.left valid }
  1021. oldleft.left.free;
  1022. oldleft.left:=cnothingnode.create;
  1023. end;
  1024. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  1025. var
  1026. hp : tprocdef;
  1027. j: integer;
  1028. begin
  1029. if (tsym(p).typ=procsym) then
  1030. begin
  1031. for j:=1 to tprocsym(p).procdef_count do
  1032. begin
  1033. { index starts at 1 }
  1034. hp:=tprocsym(p).procdef[j];
  1035. { If this is an abstract method insert into the list }
  1036. if (po_abstractmethod in hp.procoptions) then
  1037. AbstractMethodsList.Insert(hp.procsym.realname)
  1038. else
  1039. { If this symbol is a virtual (includes override) method,
  1040. then remove it from the list }
  1041. if po_virtualmethod in hp.procoptions then
  1042. AbstractMethodsList.Remove(hp.procsym.realname);
  1043. end;
  1044. end;
  1045. end;
  1046. procedure tcallnode.verifyabstractcalls;
  1047. var
  1048. objectdf : tobjectdef;
  1049. parents : tlinkedlist;
  1050. objectinfo : tobjectinfoitem;
  1051. stritem : tstringlistitem;
  1052. begin
  1053. objectdf := nil;
  1054. { verify if trying to create an instance of a class which contains
  1055. non-implemented abstract methods }
  1056. { first verify this class type, no class than exit }
  1057. { also, this checking can only be done if the constructor is directly
  1058. called, indirect constructor calls cannot be checked.
  1059. }
  1060. if assigned(methodpointer) then
  1061. begin
  1062. if (methodpointer.resulttype.def.deftype = objectdef) then
  1063. objectdf:=tobjectdef(methodpointer.resulttype.def)
  1064. else
  1065. if (methodpointer.resulttype.def.deftype = classrefdef) and
  1066. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  1067. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  1068. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  1069. end;
  1070. if not assigned(objectdf) then
  1071. exit;
  1072. parents := tlinkedlist.create;
  1073. AbstractMethodsList := tstringlist.create;
  1074. { insert all parents in this class : the first item in the
  1075. list will be the base parent of the class .
  1076. }
  1077. while assigned(objectdf) do
  1078. begin
  1079. objectinfo:=tobjectinfoitem.create(objectdf);
  1080. parents.insert(objectinfo);
  1081. objectdf := objectdf.childof;
  1082. end;
  1083. { now all parents are in the correct order
  1084. insert all abstract methods in the list, and remove
  1085. those which are overriden by parent classes.
  1086. }
  1087. objectinfo:=tobjectinfoitem(parents.first);
  1088. while assigned(objectinfo) do
  1089. begin
  1090. objectdf := objectinfo.objinfo;
  1091. if assigned(objectdf.symtable) then
  1092. objectdf.symtable.foreach(@verifyabstract,nil);
  1093. objectinfo:=tobjectinfoitem(objectinfo.next);
  1094. end;
  1095. if assigned(parents) then
  1096. parents.free;
  1097. { Finally give out a warning for each abstract method still in the list }
  1098. stritem := tstringlistitem(AbstractMethodsList.first);
  1099. if assigned(stritem) then
  1100. Message1(type_w_instance_with_abstract,objectdf.objrealname^);
  1101. while assigned(stritem) do
  1102. begin
  1103. if assigned(stritem.fpstr) then
  1104. Message1(sym_h_param_list,stritem.str);
  1105. stritem := tstringlistitem(stritem.next);
  1106. end;
  1107. if assigned(AbstractMethodsList) then
  1108. AbstractMethodsList.Free;
  1109. end;
  1110. function tcallnode.gen_self_tree_methodpointer:tnode;
  1111. var
  1112. hsym : tfieldvarsym;
  1113. begin
  1114. { find self field in methodpointer record }
  1115. hsym:=tfieldvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1116. if not assigned(hsym) then
  1117. internalerror(200305251);
  1118. { Load tmehodpointer(right).self }
  1119. result:=csubscriptnode.create(
  1120. hsym,
  1121. ctypeconvnode.create_internal(right.getcopy,methodpointertype));
  1122. end;
  1123. function tcallnode.gen_self_tree:tnode;
  1124. var
  1125. selftree : tnode;
  1126. begin
  1127. selftree:=nil;
  1128. { inherited }
  1129. if (cnf_inherited in callnodeflags) then
  1130. selftree:=load_self_node
  1131. else
  1132. { constructors }
  1133. if (procdefinition.proctypeoption=potype_constructor) then
  1134. begin
  1135. { push 0 as self when allocation is needed }
  1136. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1137. (cnf_new_call in callnodeflags) then
  1138. selftree:=cpointerconstnode.create(0,voidpointertype)
  1139. else
  1140. begin
  1141. if methodpointer.nodetype=typen then
  1142. selftree:=load_self_node
  1143. else
  1144. selftree:=methodpointer.getcopy;
  1145. end;
  1146. end
  1147. else
  1148. { Calling a static/class method }
  1149. if (po_classmethod in procdefinition.procoptions) or
  1150. (po_staticmethod in procdefinition.procoptions) then
  1151. begin
  1152. if (procdefinition.deftype<>procdef) then
  1153. internalerror(200305062);
  1154. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1155. begin
  1156. { we only need the vmt, loading self is not required and there is no
  1157. need to check for typen, because that will always get the
  1158. loadvmtaddrnode added }
  1159. selftree:=methodpointer.getcopy;
  1160. if methodpointer.resulttype.def.deftype<>classrefdef then
  1161. selftree:=cloadvmtaddrnode.create(selftree);
  1162. end
  1163. else
  1164. selftree:=cpointerconstnode.create(0,voidpointertype);
  1165. end
  1166. else
  1167. begin
  1168. if methodpointer.nodetype=typen then
  1169. selftree:=load_self_node
  1170. else
  1171. selftree:=methodpointer.getcopy;
  1172. end;
  1173. result:=selftree;
  1174. end;
  1175. function tcallnode.gen_vmt_tree:tnode;
  1176. var
  1177. vmttree : tnode;
  1178. begin
  1179. vmttree:=nil;
  1180. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1181. internalerror(200305051);
  1182. { Handle classes and legacy objects separate to make it
  1183. more maintainable }
  1184. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1185. begin
  1186. if not is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1187. internalerror(200501041);
  1188. { constructor call via classreference => allocate memory }
  1189. if (procdefinition.proctypeoption=potype_constructor) then
  1190. begin
  1191. vmttree:=methodpointer.getcopy;
  1192. { Only a typenode can be passed when it is called with <class of xx>.create }
  1193. if vmttree.nodetype=typen then
  1194. vmttree:=cloadvmtaddrnode.create(vmttree);
  1195. end
  1196. else
  1197. begin
  1198. { Call afterconstruction }
  1199. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1200. end;
  1201. end
  1202. else
  1203. { Class style objects }
  1204. if is_class(methodpointer.resulttype.def) then
  1205. begin
  1206. { inherited call, no create/destroy }
  1207. if (cnf_inherited in callnodeflags) then
  1208. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1209. else
  1210. { do not create/destroy when called from member function
  1211. without specifying self explicit }
  1212. if (cnf_member_call in callnodeflags) then
  1213. begin
  1214. { destructor: don't release instance, vmt=0
  1215. constructor:
  1216. if called from a constructor in the same class then
  1217. don't call afterconstruction, vmt=0
  1218. else
  1219. call afterconstrution, vmt=1 }
  1220. if (procdefinition.proctypeoption=potype_destructor) then
  1221. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1222. else
  1223. begin
  1224. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1225. (procdefinition.proctypeoption=potype_constructor) then
  1226. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1227. else
  1228. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1229. end;
  1230. end
  1231. else
  1232. { normal call to method like cl1.proc }
  1233. begin
  1234. { destructor: release instance, vmt=1
  1235. constructor:
  1236. if called from a constructor in the same class using self.create then
  1237. don't call afterconstruction, vmt=0
  1238. else
  1239. call afterconstrution, vmt=1 }
  1240. if (procdefinition.proctypeoption=potype_destructor) then
  1241. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1242. else
  1243. begin
  1244. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1245. (procdefinition.proctypeoption=potype_constructor) and
  1246. (nf_is_self in methodpointer.flags) then
  1247. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1248. else
  1249. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1250. end;
  1251. end;
  1252. end
  1253. else
  1254. { Old style object }
  1255. begin
  1256. { constructor with extended syntax called from new }
  1257. if (cnf_new_call in callnodeflags) then
  1258. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1259. else
  1260. { destructor with extended syntax called from dispose }
  1261. if (cnf_dispose_call in callnodeflags) then
  1262. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1263. else
  1264. { inherited call, no create/destroy }
  1265. if (cnf_inherited in callnodeflags) then
  1266. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1267. else
  1268. { do not create/destroy when called from member function
  1269. without specifying self explicit }
  1270. if (cnf_member_call in callnodeflags) then
  1271. begin
  1272. { destructor: don't release instance, vmt=0
  1273. constructor: don't initialize instance, vmt=0 }
  1274. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1275. end
  1276. else
  1277. { normal object call like obj.proc }
  1278. begin
  1279. { destructor: direct call, no dispose, vmt=0
  1280. constructor: initialize object, load vmt }
  1281. if (procdefinition.proctypeoption=potype_constructor) then
  1282. begin
  1283. { old styled inherited call? }
  1284. if (methodpointer.nodetype=typen) then
  1285. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1286. else
  1287. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1288. end
  1289. else
  1290. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1291. end;
  1292. end;
  1293. result:=vmttree;
  1294. end;
  1295. procedure tcallnode.bind_parasym;
  1296. var
  1297. i : integer;
  1298. pt : tcallparanode;
  1299. oldppt : ^tcallparanode;
  1300. varargspara,
  1301. currpara : tparavarsym;
  1302. used_by_callnode : boolean;
  1303. hiddentree : tnode;
  1304. newstatement : tstatementnode;
  1305. temp : ttempcreatenode;
  1306. begin
  1307. pt:=tcallparanode(left);
  1308. oldppt:=@left;
  1309. { flag all callparanodes that belong to the varargs }
  1310. i:=paralength;
  1311. while (i>procdefinition.maxparacount) do
  1312. begin
  1313. include(pt.callparaflags,cpf_varargs_para);
  1314. oldppt:[email protected];
  1315. pt:=tcallparanode(pt.right);
  1316. dec(i);
  1317. end;
  1318. { skip varargs that are inserted by array of const }
  1319. while assigned(pt) and
  1320. (cpf_varargs_para in pt.callparaflags) do
  1321. pt:=tcallparanode(pt.right);
  1322. { process normal parameters and insert hidden parameters }
  1323. for i:=procdefinition.paras.count-1 downto 0 do
  1324. begin
  1325. currpara:=tparavarsym(procdefinition.paras[i]);
  1326. if vo_is_hidden_para in currpara.varoptions then
  1327. begin
  1328. { generate hidden tree }
  1329. used_by_callnode:=false;
  1330. hiddentree:=nil;
  1331. if (vo_is_funcret in currpara.varoptions) then
  1332. begin
  1333. { Generate funcretnode if not specified }
  1334. if assigned(funcretnode) then
  1335. begin
  1336. hiddentree:=funcretnode.getcopy;
  1337. end
  1338. else
  1339. begin
  1340. hiddentree:=internalstatements(newstatement);
  1341. { need to use resulttype instead of procdefinition.rettype,
  1342. because they can be different }
  1343. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent,false);
  1344. addstatement(newstatement,temp);
  1345. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1346. addstatement(newstatement,ctemprefnode.create(temp));
  1347. end;
  1348. end
  1349. else
  1350. if vo_is_high_para in currpara.varoptions then
  1351. begin
  1352. if not assigned(pt) or
  1353. (i=0) then
  1354. internalerror(200304082);
  1355. { we need the information of the previous parameter }
  1356. hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vartype.def);
  1357. end
  1358. else
  1359. if vo_is_self in currpara.varoptions then
  1360. begin
  1361. if assigned(right) then
  1362. hiddentree:=gen_self_tree_methodpointer
  1363. else
  1364. hiddentree:=gen_self_tree;
  1365. end
  1366. else
  1367. if vo_is_vmt in currpara.varoptions then
  1368. begin
  1369. hiddentree:=gen_vmt_tree;
  1370. end
  1371. {$ifdef powerpc}
  1372. else
  1373. if vo_is_syscall_lib in currpara.varoptions then
  1374. begin
  1375. { lib parameter has no special type but proccalloptions must be a syscall }
  1376. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1377. end
  1378. {$endif powerpc}
  1379. else
  1380. if vo_is_parentfp in currpara.varoptions then
  1381. begin
  1382. if not(assigned(procdefinition.owner.defowner)) then
  1383. internalerror(200309287);
  1384. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1385. end;
  1386. { add the hidden parameter }
  1387. if not assigned(hiddentree) then
  1388. internalerror(200304073);
  1389. { Already insert para and let the previous node point to
  1390. this new node }
  1391. pt:=ccallparanode.create(hiddentree,oldppt^);
  1392. pt.used_by_callnode:=used_by_callnode;
  1393. oldppt^:=pt;
  1394. end;
  1395. if not assigned(pt) then
  1396. internalerror(200310052);
  1397. pt.parasym:=currpara;
  1398. oldppt:[email protected];
  1399. pt:=tcallparanode(pt.right);
  1400. end;
  1401. { Create parasyms for varargs, first count the number of varargs paras,
  1402. then insert the parameters with numbering in reverse order. The SortParas
  1403. will set the correct order at the end}
  1404. pt:=tcallparanode(left);
  1405. i:=0;
  1406. while assigned(pt) do
  1407. begin
  1408. if cpf_varargs_para in pt.callparaflags then
  1409. inc(i);
  1410. pt:=tcallparanode(pt.right);
  1411. end;
  1412. if (i>0) then
  1413. begin
  1414. varargsparas:=tvarargsparalist.create;
  1415. pt:=tcallparanode(left);
  1416. while assigned(pt) do
  1417. begin
  1418. if cpf_varargs_para in pt.callparaflags then
  1419. begin
  1420. varargspara:=tparavarsym.create('va'+tostr(i),i,vs_value,pt.resulttype,[]);
  1421. dec(i);
  1422. { varargspara is left-right, use insert
  1423. instead of concat }
  1424. varargsparas.add(varargspara);
  1425. pt.parasym:=varargspara;
  1426. end;
  1427. pt:=tcallparanode(pt.right);
  1428. end;
  1429. varargsparas.sortparas;
  1430. end;
  1431. end;
  1432. function tcallnode.det_resulttype:tnode;
  1433. var
  1434. candidates : tcallcandidates;
  1435. oldcallnode : tcallnode;
  1436. hpt : tnode;
  1437. pt : tcallparanode;
  1438. lastpara : longint;
  1439. paraidx,
  1440. cand_cnt : integer;
  1441. i : longint;
  1442. is_const : boolean;
  1443. label
  1444. errorexit;
  1445. begin
  1446. result:=nil;
  1447. candidates:=nil;
  1448. oldcallnode:=aktcallnode;
  1449. aktcallnode:=self;
  1450. { determine length of parameter list }
  1451. pt:=tcallparanode(left);
  1452. paralength:=0;
  1453. while assigned(pt) do
  1454. begin
  1455. inc(paralength);
  1456. pt:=tcallparanode(pt.right);
  1457. end;
  1458. { determine the type of the parameters }
  1459. if assigned(left) then
  1460. begin
  1461. tcallparanode(left).get_paratype;
  1462. if codegenerror then
  1463. goto errorexit;
  1464. end;
  1465. if assigned(methodpointer) then
  1466. begin
  1467. resulttypepass(methodpointer);
  1468. maybe_load_para_in_temp(methodpointer);
  1469. end;
  1470. { procedure variable ? }
  1471. if assigned(right) then
  1472. begin
  1473. set_varstate(right,vs_read,[vsf_must_be_valid]);
  1474. resulttypepass(right);
  1475. if codegenerror then
  1476. exit;
  1477. procdefinition:=tabstractprocdef(right.resulttype.def);
  1478. { Compare parameters from right to left }
  1479. paraidx:=procdefinition.Paras.count-1;
  1480. { Skip default parameters }
  1481. if not(po_varargs in procdefinition.procoptions) then
  1482. begin
  1483. { ignore hidden parameters }
  1484. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1485. dec(paraidx);
  1486. for i:=1 to procdefinition.maxparacount-paralength do
  1487. begin
  1488. if paraidx<0 then
  1489. internalerror(200402261);
  1490. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1491. begin
  1492. CGMessage(parser_e_wrong_parameter_size);
  1493. goto errorexit;
  1494. end;
  1495. dec(paraidx);
  1496. end;
  1497. end;
  1498. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1499. dec(paraidx);
  1500. pt:=tcallparanode(left);
  1501. lastpara:=paralength;
  1502. while (paraidx>=0) and assigned(pt) do
  1503. begin
  1504. { only goto next para if we're out of the varargs }
  1505. if not(po_varargs in procdefinition.procoptions) or
  1506. (lastpara<=procdefinition.maxparacount) then
  1507. begin
  1508. repeat
  1509. dec(paraidx);
  1510. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1511. end;
  1512. pt:=tcallparanode(pt.right);
  1513. dec(lastpara);
  1514. end;
  1515. if assigned(pt) or
  1516. ((paraidx>=0) and
  1517. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  1518. begin
  1519. if assigned(pt) then
  1520. aktfilepos:=pt.fileinfo;
  1521. CGMessage(parser_e_wrong_parameter_size);
  1522. goto errorexit;
  1523. end;
  1524. end
  1525. else
  1526. { not a procedure variable }
  1527. begin
  1528. { do we know the procedure to call ? }
  1529. if not(assigned(procdefinition)) then
  1530. begin
  1531. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags),
  1532. { ignore possible private in delphi mode for anon. inherited (FK) }
  1533. (m_delphi in aktmodeswitches) and (cnf_anon_inherited in callnodeflags));
  1534. { no procedures found? then there is something wrong
  1535. with the parameter size or the procedures are
  1536. not accessible }
  1537. if candidates.count=0 then
  1538. begin
  1539. { when it's an auto inherited call and there
  1540. is no procedure found, but the procedures
  1541. were defined with overload directive and at
  1542. least two procedures are defined then we ignore
  1543. this inherited by inserting a nothingn. Only
  1544. do this ugly hack in Delphi mode as it looks more
  1545. like a bug. It's also not documented }
  1546. if (m_delphi in aktmodeswitches) and
  1547. (cnf_anon_inherited in callnodeflags) and
  1548. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1549. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1550. (symtableprocentry.procdef_count>=2) then
  1551. result:=cnothingnode.create
  1552. else
  1553. begin
  1554. { in tp mode we can try to convert to procvar if
  1555. there are no parameters specified. Only try it
  1556. when there is only one proc definition, else the
  1557. loadnode will give a strange error }
  1558. if not(assigned(left)) and
  1559. not(cnf_inherited in callnodeflags) and
  1560. ((m_tp_procvar in aktmodeswitches) or
  1561. (m_mac_procvar in aktmodeswitches)) and
  1562. (symtableprocentry.procdef_count=1) and
  1563. (not assigned(methodpointer) or
  1564. (methodpointer.nodetype <> typen)) then
  1565. begin
  1566. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1567. if assigned(methodpointer) then
  1568. tloadnode(hpt).set_mp(get_load_methodpointer);
  1569. resulttypepass(hpt);
  1570. result:=hpt;
  1571. end
  1572. else
  1573. begin
  1574. if assigned(left) then
  1575. aktfilepos:=left.fileinfo;
  1576. CGMessage(parser_e_wrong_parameter_size);
  1577. symtableprocentry.write_parameter_lists(nil);
  1578. end;
  1579. end;
  1580. goto errorexit;
  1581. end;
  1582. { Retrieve information about the candidates }
  1583. candidates.get_information;
  1584. {$ifdef EXTDEBUG}
  1585. { Display info when multiple candidates are found }
  1586. if candidates.count>1 then
  1587. candidates.dump_info(V_Debug);
  1588. {$endif EXTDEBUG}
  1589. { Choose the best candidate and count the number of
  1590. candidates left }
  1591. cand_cnt:=candidates.choose_best(procdefinition);
  1592. { All parameters are checked, check if there are any
  1593. procedures left }
  1594. if cand_cnt>0 then
  1595. begin
  1596. { Multiple candidates left? }
  1597. if cand_cnt>1 then
  1598. begin
  1599. CGMessage(type_e_cant_choose_overload_function);
  1600. {$ifdef EXTDEBUG}
  1601. candidates.dump_info(V_Hint);
  1602. {$else EXTDEBUG}
  1603. candidates.list(false);
  1604. {$endif EXTDEBUG}
  1605. { we'll just use the first candidate to make the
  1606. call }
  1607. end;
  1608. { assign procdefinition }
  1609. if symtableproc=nil then
  1610. symtableproc:=procdefinition.owner;
  1611. { update browser information }
  1612. if make_ref then
  1613. begin
  1614. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1615. inc(tprocdef(procdefinition).refcount);
  1616. if tprocdef(procdefinition).defref=nil then
  1617. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1618. end;
  1619. end
  1620. else
  1621. begin
  1622. { No candidates left, this must be a type error,
  1623. because wrong size is already checked. procdefinition
  1624. is filled with the first (random) definition that is
  1625. found. We use this definition to display a nice error
  1626. message that the wrong type is passed }
  1627. candidates.find_wrong_para;
  1628. candidates.list(true);
  1629. {$ifdef EXTDEBUG}
  1630. candidates.dump_info(V_Hint);
  1631. {$endif EXTDEBUG}
  1632. { We can not proceed, release all procs and exit }
  1633. candidates.free;
  1634. goto errorexit;
  1635. end;
  1636. candidates.free;
  1637. end; { end of procedure to call determination }
  1638. end;
  1639. { add needed default parameters }
  1640. if assigned(procdefinition) and
  1641. (paralength<procdefinition.maxparacount) then
  1642. begin
  1643. paraidx:=0;
  1644. i:=0;
  1645. while (i<paralength) do
  1646. begin
  1647. if paraidx>=procdefinition.Paras.count then
  1648. internalerror(200306181);
  1649. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  1650. inc(i);
  1651. inc(paraidx);
  1652. end;
  1653. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1654. inc(paraidx);
  1655. while (paraidx<procdefinition.paras.count) do
  1656. begin
  1657. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1658. internalerror(200212142);
  1659. left:=ccallparanode.create(genconstsymtree(
  1660. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  1661. { Ignore vs_hidden parameters }
  1662. repeat
  1663. inc(paraidx);
  1664. until (paraidx>=procdefinition.paras.count) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1665. end;
  1666. end;
  1667. { handle predefined procedures }
  1668. is_const:=(po_internconst in procdefinition.procoptions) and
  1669. ((block_type in [bt_const,bt_type]) or
  1670. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1671. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1672. begin
  1673. if assigned(left) then
  1674. begin
  1675. { ptr and settextbuf needs two args }
  1676. if assigned(tcallparanode(left).right) then
  1677. begin
  1678. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1679. left:=nil;
  1680. end
  1681. else
  1682. begin
  1683. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1684. tcallparanode(left).left:=nil;
  1685. end;
  1686. end
  1687. else
  1688. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1689. result:=hpt;
  1690. goto errorexit;
  1691. end;
  1692. { ensure that the result type is set }
  1693. if not(cnf_restypeset in callnodeflags) then
  1694. begin
  1695. { constructors return their current class type, not the type where the
  1696. constructor is declared, this can be different because of inheritance }
  1697. if (procdefinition.proctypeoption=potype_constructor) and
  1698. assigned(methodpointer) and
  1699. assigned(methodpointer.resulttype.def) and
  1700. (methodpointer.resulttype.def.deftype=classrefdef) then
  1701. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1702. else
  1703. { Member call to a (inherited) constructor from the class, the return
  1704. value is always self, so we change it to voidtype to generate an
  1705. error and to prevent users from generating non-working code
  1706. when they expect to clone the current instance, see bug 3662 (PFV) }
  1707. if (procdefinition.proctypeoption=potype_constructor) and
  1708. is_class(tprocdef(procdefinition)._class) and
  1709. assigned(methodpointer) and
  1710. (nf_is_self in methodpointer.flags) then
  1711. resulttype:=voidtype
  1712. else
  1713. resulttype:=procdefinition.rettype;
  1714. end
  1715. else
  1716. resulttype:=restype;
  1717. {if resulttype.def.needs_inittable then
  1718. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1719. if assigned(methodpointer) then
  1720. begin
  1721. { when methodpointer is a callnode we must load it first into a
  1722. temp to prevent the processing callnode twice }
  1723. if (methodpointer.nodetype=calln) then
  1724. internalerror(200405121);
  1725. { direct call to inherited abstract method, then we
  1726. can already give a error in the compiler instead
  1727. of a runtime error }
  1728. if (cnf_inherited in callnodeflags) and
  1729. (po_abstractmethod in procdefinition.procoptions) then
  1730. CGMessage(cg_e_cant_call_abstract_method);
  1731. { if an inherited con- or destructor should be }
  1732. { called in a con- or destructor then a warning }
  1733. { will be made }
  1734. { con- and destructors need a pointer to the vmt }
  1735. if (cnf_inherited in callnodeflags) and
  1736. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1737. is_object(methodpointer.resulttype.def) and
  1738. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1739. CGMessage(cg_w_member_cd_call_from_method);
  1740. if methodpointer.nodetype<>typen then
  1741. begin
  1742. { Remove all postfix operators }
  1743. hpt:=methodpointer;
  1744. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1745. hpt:=tunarynode(hpt).left;
  1746. if (procdefinition.proctypeoption=potype_constructor) and
  1747. assigned(symtableproc) and
  1748. (symtableproc.symtabletype=withsymtable) and
  1749. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1750. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1751. { R.Init then R will be initialized by the constructor,
  1752. Also allow it for simple loads }
  1753. if (procdefinition.proctypeoption=potype_constructor) or
  1754. ((hpt.nodetype=loadn) and
  1755. (
  1756. (methodpointer.resulttype.def.deftype=classrefdef) or
  1757. (
  1758. (methodpointer.resulttype.def.deftype=objectdef) and
  1759. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1760. )
  1761. )
  1762. ) then
  1763. set_varstate(methodpointer,vs_read,[])
  1764. else
  1765. set_varstate(methodpointer,vs_read,[vsf_must_be_valid]);
  1766. { The object is already used if it is called once }
  1767. if (hpt.nodetype=loadn) and
  1768. (tloadnode(hpt).symtableentry.typ in [localvarsym,paravarsym,globalvarsym]) then
  1769. set_varstate(hpt,vs_read,[]);
  1770. // tabstractvarsym(tloadnode(hpt).symtableentry).varstate:=vs_readwritten;
  1771. end;
  1772. { if we are calling the constructor check for abstract
  1773. methods. Ignore inherited and member calls, because the
  1774. class is then already created }
  1775. if (procdefinition.proctypeoption=potype_constructor) and
  1776. not(cnf_inherited in callnodeflags) and
  1777. not(cnf_member_call in callnodeflags) then
  1778. verifyabstractcalls;
  1779. end
  1780. else
  1781. begin
  1782. { When this is method the methodpointer must be available }
  1783. if (right=nil) and
  1784. (procdefinition.owner.symtabletype=objectsymtable) then
  1785. internalerror(200305061);
  1786. end;
  1787. { Set flag that the procedure uses varargs, also if they are not passed it is still
  1788. needed for x86_64 to pass the number of SSE registers used }
  1789. if po_varargs in procdefinition.procoptions then
  1790. include(callnodeflags,cnf_uses_varargs);
  1791. { Change loading of array of const to varargs }
  1792. if assigned(left) and
  1793. is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vartype.def) and
  1794. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  1795. convert_carg_array_of_const;
  1796. { bind parasyms to the callparanodes and insert hidden parameters }
  1797. bind_parasym;
  1798. { insert type conversions for parameters }
  1799. if assigned(left) then
  1800. tcallparanode(left).insert_typeconv(true);
  1801. errorexit:
  1802. aktcallnode:=oldcallnode;
  1803. end;
  1804. procedure tcallnode.order_parameters;
  1805. var
  1806. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  1807. currloc : tcgloc;
  1808. begin
  1809. hpfirst:=nil;
  1810. hpcurr:=tcallparanode(left);
  1811. while assigned(hpcurr) do
  1812. begin
  1813. { pull out }
  1814. hpnext:=tcallparanode(hpcurr.right);
  1815. { pull in at the correct place.
  1816. Used order:
  1817. 1. LOC_REFERENCE with smallest offset (x86 only)
  1818. 2. LOC_REFERENCE with most registers
  1819. 3. LOC_REGISTER with most registers
  1820. For the moment we only look at the first parameter field. Combining it
  1821. with multiple parameter fields will make things a lot complexer (PFV) }
  1822. if not assigned(hpcurr.parasym.paraloc[callerside].location) then
  1823. internalerror(200412152);
  1824. currloc:=hpcurr.parasym.paraloc[callerside].location^.loc;
  1825. hpprev:=nil;
  1826. hp:=hpfirst;
  1827. while assigned(hp) do
  1828. begin
  1829. case currloc of
  1830. LOC_REFERENCE :
  1831. begin
  1832. case hp.parasym.paraloc[callerside].location^.loc of
  1833. LOC_REFERENCE :
  1834. begin
  1835. { Offset is calculated like:
  1836. sub esp,12
  1837. mov [esp+8],para3
  1838. mov [esp+4],para2
  1839. mov [esp],para1
  1840. call function
  1841. That means the for pushes the para with the
  1842. highest offset (see para3) needs to be pushed first
  1843. }
  1844. if (hpcurr.registersint>hp.registersint)
  1845. {$ifdef x86}
  1846. or (hpcurr.parasym.paraloc[callerside].location^.reference.offset>hp.parasym.paraloc[callerside].location^.reference.offset)
  1847. {$endif x86}
  1848. then
  1849. break;
  1850. end;
  1851. LOC_REGISTER,
  1852. LOC_FPUREGISTER :
  1853. break;
  1854. end;
  1855. end;
  1856. LOC_FPUREGISTER,
  1857. LOC_REGISTER :
  1858. begin
  1859. if (hp.parasym.paraloc[callerside].location^.loc=currloc) and
  1860. (hpcurr.registersint>hp.registersint) then
  1861. break;
  1862. end;
  1863. end;
  1864. hpprev:=hp;
  1865. hp:=tcallparanode(hp.right);
  1866. end;
  1867. hpcurr.right:=hp;
  1868. if assigned(hpprev) then
  1869. hpprev.right:=hpcurr
  1870. else
  1871. hpfirst:=hpcurr;
  1872. { next }
  1873. hpcurr:=hpnext;
  1874. end;
  1875. left:=hpfirst;
  1876. end;
  1877. function tcallnode.replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  1878. var
  1879. paras: tcallparanode;
  1880. temp: tnode;
  1881. begin
  1882. result := fen_false;
  1883. n.fileinfo := pfileposinfo(arg)^;
  1884. if (n.nodetype = loadn) then
  1885. begin
  1886. case tloadnode(n).symtableentry.typ of
  1887. paravarsym :
  1888. begin
  1889. paras := tcallparanode(left);
  1890. while assigned(paras) and
  1891. (paras.parasym <> tloadnode(n).symtableentry) do
  1892. paras := tcallparanode(paras.right);
  1893. if assigned(paras) then
  1894. begin
  1895. n.free;
  1896. n := paras.left.getcopy;
  1897. resulttypepass(n);
  1898. result := fen_true;
  1899. end;
  1900. end;
  1901. localvarsym :
  1902. begin
  1903. { local? }
  1904. if (tloadnode(n).symtableentry.owner <> tprocdef(procdefinition).localst) then
  1905. exit;
  1906. if (tloadnode(n).symtableentry.indexnr >= inlinelocals.count) or
  1907. not assigned(inlinelocals[tloadnode(n).symtableentry.indexnr]) then
  1908. internalerror(20040720);
  1909. temp := tnode(inlinelocals[tloadnode(n).symtableentry.indexnr]).getcopy;
  1910. n.free;
  1911. n := temp;
  1912. resulttypepass(n);
  1913. result := fen_true;
  1914. end;
  1915. end;
  1916. end;
  1917. end;
  1918. type
  1919. ptempnodes = ^ttempnodes;
  1920. ttempnodes = record
  1921. createstatement, deletestatement: tstatementnode;
  1922. end;
  1923. procedure tcallnode.createlocaltemps(p:TNamedIndexItem;arg:pointer);
  1924. var
  1925. tempinfo: ptempnodes absolute arg;
  1926. tempnode: ttempcreatenode;
  1927. begin
  1928. if (tsymentry(p).typ <> localvarsym) then
  1929. exit;
  1930. if (p.indexnr >= inlinelocals.count) then
  1931. inlinelocals.count:=p.indexnr+10;
  1932. if (vo_is_funcret in tabstractvarsym(p).varoptions) and
  1933. assigned(funcretnode) then
  1934. begin
  1935. if node_complexity(funcretnode) > 1 then
  1936. begin
  1937. { can this happen? }
  1938. { we may have to replace the funcretnode with the address of funcretnode }
  1939. { loaded in a temp in this case, because the expression may e.g. contain }
  1940. { a global variable that gets changed inside the function }
  1941. internalerror(2004072101);
  1942. end;
  1943. inlinelocals[tabstractvarsym(p).indexnr] := funcretnode.getcopy
  1944. end
  1945. else
  1946. begin
  1947. tempnode := ctempcreatenode.create(tabstractvarsym(p).vartype,tabstractvarsym(p).vartype.def.size,tt_persistent,tabstractvarsym(p).varregable<>vr_none);
  1948. addstatement(tempinfo^.createstatement,tempnode);
  1949. if assigned(tlocalvarsym(p).defaultconstsym) then
  1950. begin
  1951. { warning: duplicate from psub.pas:initializevars() -> must refactor }
  1952. addstatement(tempinfo^.createstatement,cassignmentnode.create(
  1953. ctemprefnode.create(tempnode),
  1954. cloadnode.create(tlocalvarsym(p).defaultconstsym,tlocalvarsym(p).defaultconstsym.owner)));
  1955. end;
  1956. if (vo_is_funcret in tlocalvarsym(p).varoptions) then
  1957. begin
  1958. funcretnode := ctemprefnode.create(tempnode);
  1959. addstatement(tempinfo^.deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  1960. end
  1961. else
  1962. addstatement(tempinfo^.deletestatement,ctempdeletenode.create(tempnode));
  1963. inlinelocals[p.indexnr] := ctemprefnode.create(tempnode);
  1964. end;
  1965. end;
  1966. procedure tcallnode.createinlineparas(var createstatement, deletestatement: tstatementnode);
  1967. var
  1968. para: tcallparanode;
  1969. tempnode: ttempcreatenode;
  1970. tempnodes: ttempnodes;
  1971. n: tnode;
  1972. begin
  1973. { parameters }
  1974. para := tcallparanode(left);
  1975. while assigned(para) do
  1976. begin
  1977. if (para.parasym.typ = paravarsym) and
  1978. { para.left will already be the same as funcretnode in the following case, so don't change }
  1979. (not(vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1980. (not assigned(funcretnode))) then
  1981. begin
  1982. { must take copy of para.left, because if it contains a }
  1983. { temprefn pointing to a copied temp (e.g. methodpointer), }
  1984. { then this parameter must be changed to point to the copy of }
  1985. { that temp (JM) }
  1986. n := para.left.getcopy;
  1987. para.left.free;
  1988. para.left := n;
  1989. { create temps for value parameters, function result and also for }
  1990. { const parameters which are passed by value instead of by reference }
  1991. { we need to take care that we use the type of the defined parameter and not of the
  1992. passed parameter, because these can be different in case of a formaldef (PFV) }
  1993. if
  1994. (
  1995. { the problem is that we can't take the address of a function result :( }
  1996. (vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1997. (para.parasym.varspez = vs_value) or
  1998. ((para.parasym.varspez = vs_const) and
  1999. (para.parasym.vartype.def.deftype<>formaldef) and
  2000. { the compiler expects that it can take the address of parameters passed by reference in
  2001. the case of const so we can't replace the node simply by a constant node
  2002. When playing with this code, ensure that
  2003. function f(const a,b : longint) : longint;inline;
  2004. begin
  2005. result:=a*b;
  2006. end;
  2007. [...]
  2008. ...:=f(10,20));
  2009. [...]
  2010. is still folded. (FK)
  2011. }
  2012. (
  2013. { this must be a not ... of course }
  2014. not(paramanager.push_addr_param(vs_const,para.parasym.vartype.def,procdefinition.proccalloption)) or
  2015. (node_complexity(para.left) >= NODE_COMPLEXITY_INF)
  2016. ))
  2017. ) then
  2018. begin
  2019. { in theory, this is always regable, but ncgcall can't }
  2020. { handle it yet in all situations (JM) }
  2021. tempnode := ctempcreatenode.create(para.parasym.vartype,para.parasym.vartype.def.size,tt_persistent,tparavarsym(para.parasym).varregable <> vr_none);
  2022. addstatement(createstatement,tempnode);
  2023. { assign the value of the parameter to the temp, except in case of the function result }
  2024. { (in that case, para.left is a block containing the creation of a new temp, while we }
  2025. { only need a temprefnode, so delete the old stuff) }
  2026. if not(vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  2027. begin
  2028. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2029. para.left));
  2030. para.left := ctemprefnode.create(tempnode);
  2031. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2032. end
  2033. else
  2034. begin
  2035. if not(assigned(funcretnode)) then
  2036. funcretnode := ctemprefnode.create(tempnode);
  2037. para.left.free;
  2038. para.left := ctemprefnode.create(tempnode);
  2039. addstatement(deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  2040. end
  2041. end
  2042. else if (node_complexity(para.left) > 1) then
  2043. begin
  2044. tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent,tparavarsym(para.parasym).varregable<>vr_none);
  2045. addstatement(createstatement,tempnode);
  2046. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2047. caddrnode.create_internal(para.left)));
  2048. para.left := ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),para.left.resulttype);
  2049. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2050. end;
  2051. end;
  2052. para := tcallparanode(para.right);
  2053. end;
  2054. { local variables }
  2055. if not assigned(tprocdef(procdefinition).localst) or
  2056. (tprocdef(procdefinition).localst.symindex.count = 0) then
  2057. exit;
  2058. tempnodes.createstatement := createstatement;
  2059. tempnodes.deletestatement := deletestatement;
  2060. inlinelocals.count:=tprocdef(procdefinition).localst.symindex.count;
  2061. tprocdef(procdefinition).localst.foreach(@createlocaltemps,@tempnodes);
  2062. createstatement := tempnodes.createstatement;
  2063. deletestatement := tempnodes.deletestatement;
  2064. end;
  2065. function tcallnode.pass1_inline:tnode;
  2066. var
  2067. createstatement,deletestatement: tstatementnode;
  2068. createblock,deleteblock: tblocknode;
  2069. body : tnode;
  2070. i: longint;
  2071. begin
  2072. if not(assigned(tprocdef(procdefinition).inlininginfo) and
  2073. assigned(tprocdef(procdefinition).inlininginfo^.code)) then
  2074. internalerror(200412021);
  2075. { inherit flags }
  2076. current_procinfo.flags := current_procinfo.flags + ((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  2077. { create blocks for loading/deleting of local data }
  2078. createblock:=internalstatements(createstatement);
  2079. deleteblock:=internalstatements(deletestatement);
  2080. { add methodpointer init code to init statement }
  2081. { (fini must be done later, as it will delete the hookoncopy info) }
  2082. if assigned(methodpointerinit) then
  2083. addstatement(createstatement,methodpointerinit.getcopy);
  2084. inlinelocals:=tlist.create;
  2085. { get copy of the procedure body }
  2086. body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
  2087. { replace complex parameters with temps }
  2088. createinlineparas(createstatement,deletestatement);
  2089. { replace the parameter loads with the parameter values }
  2090. foreachnode(body,@replaceparaload,@fileinfo);
  2091. { copy methodpointer fini code }
  2092. if assigned(methodpointerdone) then
  2093. addstatement(deletestatement,methodpointerdone.getcopy);
  2094. { free the temps for the locals }
  2095. for i := 0 to inlinelocals.count-1 do
  2096. if assigned(inlinelocals[i]) then
  2097. tnode(inlinelocals[i]).free;
  2098. inlinelocals.free;
  2099. inlinelocals:=nil;
  2100. addstatement(createstatement,body);
  2101. addstatement(createstatement,deleteblock);
  2102. { set function result location if necessary }
  2103. if assigned(funcretnode) and
  2104. (cnf_return_value_used in callnodeflags) then
  2105. addstatement(createstatement,funcretnode.getcopy);
  2106. { consider it must not be inlined if called
  2107. again inside the args or itself }
  2108. exclude(procdefinition.procoptions,po_inline);
  2109. firstpass(createblock);
  2110. include(procdefinition.procoptions,po_inline);
  2111. { return inlined block }
  2112. result := createblock;
  2113. {$ifdef DEBUGINLINE}
  2114. writeln;
  2115. writeln('**************************',tprocdef(procdefinition).mangledname);
  2116. printnode(output,result);
  2117. {$endif DEBUGINLINE}
  2118. end;
  2119. function tcallnode.pass_1 : tnode;
  2120. var
  2121. st : tsymtable;
  2122. begin
  2123. result:=nil;
  2124. { Can we inline the procedure? }
  2125. if ([po_inline,po_has_inlininginfo] <= procdefinition.procoptions) then
  2126. begin
  2127. { Check if we can inline the procedure when it references proc/var that
  2128. are not in the globally available }
  2129. st:=procdefinition.owner;
  2130. if (st.symtabletype=objectsymtable) then
  2131. st:=st.defowner.owner;
  2132. if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
  2133. (st.symtabletype=globalsymtable) and
  2134. (not st.iscurrentunit) then
  2135. begin
  2136. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
  2137. end
  2138. else
  2139. begin
  2140. result:=pass1_inline;
  2141. exit;
  2142. end;
  2143. end;
  2144. { calculate the parameter info for the procdef }
  2145. if not procdefinition.has_paraloc_info then
  2146. begin
  2147. procdefinition.requiredargarea:=paramanager.create_paraloc_info(procdefinition,callerside);
  2148. procdefinition.has_paraloc_info:=true;
  2149. end;
  2150. { calculate the parameter size needed for this call include varargs if they are available }
  2151. if assigned(varargsparas) then
  2152. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  2153. else
  2154. pushedparasize:=procdefinition.requiredargarea;
  2155. { record maximum parameter size used in this proc }
  2156. current_procinfo.allocate_push_parasize(pushedparasize);
  2157. { work trough all parameters to get the register requirements }
  2158. if assigned(left) then
  2159. tcallparanode(left).det_registers;
  2160. { order parameters }
  2161. order_parameters;
  2162. if assigned(methodpointerinit) then
  2163. firstpass(methodpointerinit);
  2164. if assigned(methodpointerdone) then
  2165. firstpass(methodpointerdone);
  2166. { function result node }
  2167. if assigned(_funcretnode) then
  2168. firstpass(_funcretnode);
  2169. { procedure variable ? }
  2170. if assigned(right) then
  2171. firstpass(right);
  2172. if not (block_type in [bt_const,bt_type]) then
  2173. include(current_procinfo.flags,pi_do_call);
  2174. { implicit finally needed ? }
  2175. if resulttype.def.needs_inittable and
  2176. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  2177. not assigned(funcretnode) then
  2178. include(current_procinfo.flags,pi_needs_implicit_finally);
  2179. { get a register for the return value }
  2180. if (not is_void(resulttype.def)) then
  2181. begin
  2182. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2183. begin
  2184. expectloc:=LOC_REFERENCE;
  2185. end
  2186. else
  2187. { for win32 records returned in EDX:EAX, we
  2188. move them to memory after ... }
  2189. if (resulttype.def.deftype=recorddef) then
  2190. begin
  2191. expectloc:=LOC_REFERENCE;
  2192. end
  2193. else
  2194. { ansi/widestrings must be registered, so we can dispose them }
  2195. if is_ansistring(resulttype.def) or
  2196. is_widestring(resulttype.def) then
  2197. begin
  2198. expectloc:=LOC_REFERENCE;
  2199. registersint:=1;
  2200. end
  2201. else
  2202. { we have only to handle the result if it is used }
  2203. if (cnf_return_value_used in callnodeflags) then
  2204. begin
  2205. case resulttype.def.deftype of
  2206. enumdef,
  2207. orddef :
  2208. begin
  2209. if (procdefinition.proctypeoption=potype_constructor) then
  2210. begin
  2211. expectloc:=LOC_REGISTER;
  2212. registersint:=1;
  2213. end
  2214. else
  2215. begin
  2216. expectloc:=LOC_REGISTER;
  2217. if is_64bit(resulttype.def) then
  2218. registersint:=2
  2219. else
  2220. registersint:=1;
  2221. end;
  2222. end;
  2223. floatdef :
  2224. begin
  2225. expectloc:=LOC_FPUREGISTER;
  2226. {$ifdef cpufpemu}
  2227. if (cs_fp_emulation in aktmoduleswitches) then
  2228. registersint:=1
  2229. else
  2230. {$endif cpufpemu}
  2231. {$ifdef m68k}
  2232. if (tfloatdef(resulttype.def).typ=s32real) then
  2233. registersint:=1
  2234. else
  2235. {$endif m68k}
  2236. registersfpu:=1;
  2237. end;
  2238. else
  2239. begin
  2240. expectloc:=LOC_REGISTER;
  2241. registersint:=1;
  2242. end;
  2243. end;
  2244. end
  2245. else
  2246. expectloc:=LOC_VOID;
  2247. end
  2248. else
  2249. expectloc:=LOC_VOID;
  2250. {$ifdef m68k}
  2251. { we need one more address register for virtual calls on m68k }
  2252. if (po_virtualmethod in procdefinition.procoptions) then
  2253. inc(registersint);
  2254. {$endif m68k}
  2255. { a fpu can be used in any procedure !! }
  2256. {$ifdef i386}
  2257. registersfpu:=procdefinition.fpu_used;
  2258. {$endif i386}
  2259. { if this is a call to a method calc the registers }
  2260. if (methodpointer<>nil) then
  2261. begin
  2262. if methodpointer.nodetype<>typen then
  2263. begin
  2264. firstpass(methodpointer);
  2265. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2266. registersint:=max(methodpointer.registersint,registersint);
  2267. {$ifdef SUPPORT_MMX }
  2268. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2269. {$endif SUPPORT_MMX}
  2270. end;
  2271. end;
  2272. { determine the registers of the procedure variable }
  2273. { is this OK for inlined procs also ?? (PM) }
  2274. if assigned(right) then
  2275. begin
  2276. registersfpu:=max(right.registersfpu,registersfpu);
  2277. registersint:=max(right.registersint,registersint);
  2278. {$ifdef SUPPORT_MMX}
  2279. registersmmx:=max(right.registersmmx,registersmmx);
  2280. {$endif SUPPORT_MMX}
  2281. end;
  2282. { determine the registers of the procedure }
  2283. if assigned(left) then
  2284. begin
  2285. registersfpu:=max(left.registersfpu,registersfpu);
  2286. registersint:=max(left.registersint,registersint);
  2287. {$ifdef SUPPORT_MMX}
  2288. registersmmx:=max(left.registersmmx,registersmmx);
  2289. {$endif SUPPORT_MMX}
  2290. end;
  2291. end;
  2292. {$ifdef state_tracking}
  2293. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2294. var hp:Tcallparanode;
  2295. value:Tnode;
  2296. begin
  2297. track_state_pass:=false;
  2298. hp:=Tcallparanode(left);
  2299. while assigned(hp) do
  2300. begin
  2301. if left.track_state_pass(exec_known) then
  2302. begin
  2303. left.resulttype.def:=nil;
  2304. do_resulttypepass(left);
  2305. end;
  2306. value:=aktstate.find_fact(hp.left);
  2307. if value<>nil then
  2308. begin
  2309. track_state_pass:=true;
  2310. hp.left.destroy;
  2311. hp.left:=value.getcopy;
  2312. do_resulttypepass(hp.left);
  2313. end;
  2314. hp:=Tcallparanode(hp.right);
  2315. end;
  2316. end;
  2317. {$endif}
  2318. function tcallnode.para_count:longint;
  2319. var
  2320. ppn : tcallparanode;
  2321. begin
  2322. result:=0;
  2323. ppn:=tcallparanode(left);
  2324. while assigned(ppn) do
  2325. begin
  2326. if not(assigned(ppn.parasym) and
  2327. (vo_is_hidden_para in ppn.parasym.varoptions)) then
  2328. inc(result);
  2329. ppn:=tcallparanode(ppn.right);
  2330. end;
  2331. end;
  2332. function tcallnode.get_load_methodpointer:tnode;
  2333. var
  2334. newstatement : tstatementnode;
  2335. begin
  2336. if assigned(methodpointerinit) then
  2337. begin
  2338. result:=internalstatements(newstatement);
  2339. addstatement(newstatement,methodpointerinit);
  2340. addstatement(newstatement,methodpointer);
  2341. addstatement(newstatement,methodpointerdone);
  2342. methodpointerinit:=nil;
  2343. methodpointer:=nil;
  2344. methodpointerdone:=nil;
  2345. end
  2346. else
  2347. begin
  2348. result:=methodpointer;
  2349. methodpointer:=nil;
  2350. end;
  2351. end;
  2352. function tcallnode.docompare(p: tnode): boolean;
  2353. begin
  2354. docompare :=
  2355. inherited docompare(p) and
  2356. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2357. (procdefinition = tcallnode(p).procdefinition) and
  2358. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2359. (((cnf_restypeset in callnodeflags) and (cnf_restypeset in tcallnode(p).callnodeflags) and
  2360. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2361. (not(cnf_restypeset in callnodeflags) and not(cnf_restypeset in tcallnode(p).callnodeflags)));
  2362. end;
  2363. procedure tcallnode.printnodedata(var t:text);
  2364. begin
  2365. if assigned(procdefinition) and
  2366. (procdefinition.deftype=procdef) then
  2367. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2368. else
  2369. begin
  2370. if assigned(symtableprocentry) then
  2371. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2372. else
  2373. writeln(t,printnodeindention,'proc = <nil>');
  2374. end;
  2375. printnode(t,methodpointer);
  2376. printnode(t,right);
  2377. printnode(t,left);
  2378. end;
  2379. begin
  2380. ccallnode:=tcallnode;
  2381. ccallparanode:=tcallparanode;
  2382. end.