ncal.pas 101 KB

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