ncal.pas 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170
  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,cpuinfo,
  24. paramgr,
  25. node,nbas,
  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. { number of parameters passed from the source, this does not include the hidden parameters }
  44. paralength : smallint;
  45. function gen_self_tree_methodpointer:tnode;
  46. function gen_self_tree:tnode;
  47. function gen_vmt_tree:tnode;
  48. procedure bind_paraitem;
  49. { function return node, this is used to pass the data for a
  50. ret_in_param return value }
  51. _funcretnode : tnode;
  52. procedure setfuncretnode(const returnnode: tnode);
  53. procedure convert_carg_array_of_const;
  54. procedure order_parameters;
  55. protected
  56. pushedparasize : longint;
  57. public
  58. { the symbol containing the definition of the procedure }
  59. { to call }
  60. symtableprocentry : tprocsym;
  61. symtableprocentryderef : tderef;
  62. { symtable where the entry was found, needed for with support }
  63. symtableproc : tsymtable;
  64. { the definition of the procedure to call }
  65. procdefinition : tabstractprocdef;
  66. procdefinitionderef : tderef;
  67. { tree that contains the pointer to the object for this method }
  68. methodpointerinit,
  69. methodpointerdone,
  70. methodpointer : tnode;
  71. { inline function body }
  72. inlinecode : tnode;
  73. { varargs tparaitems }
  74. varargsparas : tvarargspara;
  75. { node that specifies where the result should be put for calls }
  76. { that return their result in a parameter }
  77. property funcretnode: tnode read _funcretnode write setfuncretnode;
  78. { separately specified resulttype for some compilerprocs (e.g. }
  79. { you can't have a function with an "array of char" resulttype }
  80. { the RTL) (JM) }
  81. restype: ttype;
  82. callnodeflags : tcallnodeflags;
  83. { only the processor specific nodes need to override this }
  84. { constructor }
  85. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);virtual;
  86. constructor create_procvar(l,r:tnode);
  87. constructor createintern(const name: string; params: tnode);
  88. constructor createinternres(const name: string; params: tnode; const res: ttype);
  89. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  90. destructor destroy;override;
  91. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  92. procedure ppuwrite(ppufile:tcompilerppufile);override;
  93. procedure buildderefimpl;override;
  94. procedure derefimpl;override;
  95. function getcopy : tnode;override;
  96. { Goes through all symbols in a class and subclasses and calls
  97. verify abstract for each .
  98. }
  99. procedure verifyabstractcalls;
  100. { called for each definition in a class and verifies if a method
  101. is abstract or not, if it is abstract, give out a warning
  102. }
  103. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  104. procedure insertintolist(l : tnodelist);override;
  105. function pass_1 : tnode;override;
  106. function det_resulttype:tnode;override;
  107. {$ifdef state_tracking}
  108. function track_state_pass(exec_known:boolean):boolean;override;
  109. {$endif state_tracking}
  110. function docompare(p: tnode): boolean; override;
  111. procedure printnodedata(var t:text);override;
  112. function para_count:longint;
  113. private
  114. AbstractMethodsList : TStringList;
  115. end;
  116. tcallnodeclass = class of tcallnode;
  117. tcallparaflag = (
  118. cpf_is_colon_para,
  119. cpf_varargs_para { belongs this para to varargs }
  120. );
  121. tcallparaflags = set of tcallparaflag;
  122. tcallparanode = class(tbinarynode)
  123. public
  124. callparaflags : tcallparaflags;
  125. paraitem : tparaitem;
  126. used_by_callnode : boolean;
  127. { only the processor specific nodes need to override this }
  128. { constructor }
  129. constructor create(expr,next : tnode);virtual;
  130. destructor destroy;override;
  131. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  132. procedure ppuwrite(ppufile:tcompilerppufile);override;
  133. function getcopy : tnode;override;
  134. procedure insertintolist(l : tnodelist);override;
  135. procedure get_paratype;
  136. procedure insert_typeconv(do_count : boolean);
  137. procedure det_registers;
  138. procedure firstcallparan;
  139. procedure secondcallparan;virtual;abstract;
  140. function docompare(p: tnode): boolean; override;
  141. procedure printnodetree(var t:text);override;
  142. end;
  143. tcallparanodeclass = class of tcallparanode;
  144. function reverseparameters(p: tcallparanode): tcallparanode;
  145. var
  146. ccallnode : tcallnodeclass;
  147. ccallparanode : tcallparanodeclass;
  148. { Current callnode, this is needed for having a link
  149. between the callparanodes and the callnode they belong to }
  150. aktcallnode : tcallnode;
  151. implementation
  152. uses
  153. systems,
  154. verbose,globals,
  155. symconst,defutil,defcmp,
  156. htypechk,pass_1,
  157. ncnv,nld,ninl,nadd,ncon,nmem,nutils,
  158. procinfo,
  159. cgbase
  160. ;
  161. type
  162. tobjectinfoitem = class(tlinkedlistitem)
  163. objinfo : tobjectdef;
  164. constructor create(def : tobjectdef);
  165. end;
  166. {****************************************************************************
  167. HELPERS
  168. ****************************************************************************}
  169. function reverseparameters(p: tcallparanode): tcallparanode;
  170. var
  171. hp1, hp2: tcallparanode;
  172. begin
  173. hp1:=nil;
  174. while assigned(p) do
  175. begin
  176. { pull out }
  177. hp2:=p;
  178. p:=tcallparanode(p.right);
  179. { pull in }
  180. hp2.right:=hp1;
  181. hp1:=hp2;
  182. end;
  183. reverseparameters:=hp1;
  184. end;
  185. function gen_high_tree(p:tnode;paradef:tdef):tnode;
  186. var
  187. temp: tnode;
  188. len : integer;
  189. loadconst : boolean;
  190. hightree : tnode;
  191. begin
  192. len:=-1;
  193. loadconst:=true;
  194. hightree:=nil;
  195. case p.resulttype.def.deftype of
  196. arraydef :
  197. begin
  198. if (paradef.deftype<>arraydef) then
  199. internalerror(200405241);
  200. { handle special case of passing an single array to an array of array }
  201. if compare_defs(tarraydef(paradef).elementtype.def,p.resulttype.def,nothingn)>=te_equal then
  202. len:=0
  203. else
  204. begin
  205. { handle via a normal inline in_high_x node }
  206. loadconst := false;
  207. hightree := geninlinenode(in_high_x,false,p.getcopy);
  208. resulttypepass(hightree);
  209. { only substract low(array) if it's <> 0 }
  210. temp := geninlinenode(in_low_x,false,p.getcopy);
  211. resulttypepass(temp);
  212. if (temp.nodetype <> ordconstn) or
  213. (tordconstnode(temp).value <> 0) then
  214. hightree := caddnode.create(subn,hightree,temp)
  215. else
  216. temp.free;
  217. end;
  218. end;
  219. stringdef :
  220. begin
  221. if is_open_string(paradef) then
  222. begin
  223. { handle via a normal inline in_high_x node }
  224. loadconst := false;
  225. hightree := geninlinenode(in_high_x,false,p.getcopy);
  226. end
  227. else
  228. begin
  229. { passing a string to an array of char }
  230. if (p.nodetype=stringconstn) then
  231. begin
  232. len:=str_length(p);
  233. if len>0 then
  234. dec(len);
  235. end
  236. else
  237. begin
  238. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  239. cordconstnode.create(1,s32inttype,false));
  240. loadconst:=false;
  241. end;
  242. end;
  243. end;
  244. else
  245. len:=0;
  246. end;
  247. if loadconst then
  248. hightree:=cordconstnode.create(len,s32inttype,true)
  249. else
  250. begin
  251. if not assigned(hightree) then
  252. internalerror(200304071);
  253. { Need to use explicit, because it can also be a enum }
  254. hightree:=ctypeconvnode.create_explicit(hightree,s32inttype);
  255. end;
  256. result:=hightree;
  257. end;
  258. {****************************************************************************
  259. TOBJECTINFOITEM
  260. ****************************************************************************}
  261. constructor tobjectinfoitem.create(def : tobjectdef);
  262. begin
  263. inherited create;
  264. objinfo := def;
  265. end;
  266. {****************************************************************************
  267. TCALLPARANODE
  268. ****************************************************************************}
  269. constructor tcallparanode.create(expr,next : tnode);
  270. begin
  271. inherited create(callparan,expr,next);
  272. if not assigned(expr) then
  273. internalerror(200305091);
  274. expr.set_file_line(self);
  275. callparaflags:=[];
  276. end;
  277. destructor tcallparanode.destroy;
  278. begin
  279. { When the node is used by callnode then
  280. we don't destroy left, the callnode takes care of it }
  281. if used_by_callnode then
  282. left:=nil;
  283. inherited destroy;
  284. end;
  285. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  286. begin
  287. inherited ppuload(t,ppufile);
  288. ppufile.getsmallset(callparaflags);
  289. end;
  290. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  291. begin
  292. inherited ppuwrite(ppufile);
  293. ppufile.putsmallset(callparaflags);
  294. end;
  295. function tcallparanode.getcopy : tnode;
  296. var
  297. n : tcallparanode;
  298. begin
  299. n:=tcallparanode(inherited getcopy);
  300. n.callparaflags:=callparaflags;
  301. n.paraitem:=paraitem;
  302. result:=n;
  303. end;
  304. procedure tcallparanode.insertintolist(l : tnodelist);
  305. begin
  306. end;
  307. procedure tcallparanode.get_paratype;
  308. var
  309. old_array_constructor : boolean;
  310. begin
  311. inc(parsing_para_level);
  312. if assigned(right) then
  313. tcallparanode(right).get_paratype;
  314. old_array_constructor:=allow_array_constructor;
  315. allow_array_constructor:=true;
  316. resulttypepass(left);
  317. allow_array_constructor:=old_array_constructor;
  318. if codegenerror then
  319. resulttype:=generrortype
  320. else
  321. resulttype:=left.resulttype;
  322. dec(parsing_para_level);
  323. end;
  324. procedure tcallparanode.insert_typeconv(do_count : boolean);
  325. var
  326. oldtype : ttype;
  327. {$ifdef extdebug}
  328. store_count_ref : boolean;
  329. {$endif def extdebug}
  330. begin
  331. inc(parsing_para_level);
  332. {$ifdef extdebug}
  333. if do_count then
  334. begin
  335. store_count_ref:=count_ref;
  336. count_ref:=true;
  337. end;
  338. {$endif def extdebug}
  339. { Be sure to have the resulttype }
  340. if not assigned(left.resulttype.def) then
  341. resulttypepass(left);
  342. if (left.nodetype<>nothingn) then
  343. begin
  344. { Convert tp procvars, this is needs to be done
  345. here to make the change permanent. in the overload
  346. choosing the changes are only made temporary }
  347. if (left.resulttype.def.deftype=procvardef) and
  348. (paraitem.paratype.def.deftype<>procvardef) then
  349. begin
  350. if maybe_call_procvar(left,true) then
  351. resulttype:=left.resulttype;
  352. end;
  353. { Handle varargs and hidden paras directly, no typeconvs or }
  354. { typechecking needed }
  355. if (cpf_varargs_para in callparaflags) then
  356. begin
  357. { convert pascal to C types }
  358. case left.resulttype.def.deftype of
  359. stringdef :
  360. inserttypeconv(left,charpointertype);
  361. floatdef :
  362. inserttypeconv(left,s64floattype);
  363. end;
  364. set_varstate(left,vs_used,true);
  365. resulttype:=left.resulttype;
  366. { also update paraitem type to get the correct parameter location
  367. for the new types }
  368. paraitem.paratype:=left.resulttype;
  369. end
  370. else
  371. if (paraitem.is_hidden) then
  372. begin
  373. set_varstate(left,vs_used,true);
  374. resulttype:=left.resulttype;
  375. end
  376. else
  377. begin
  378. { Do we need arrayconstructor -> set conversion, then insert
  379. it here before the arrayconstructor node breaks the tree
  380. with its conversions of enum->ord }
  381. if (left.nodetype=arrayconstructorn) and
  382. (paraitem.paratype.def.deftype=setdef) then
  383. inserttypeconv(left,paraitem.paratype);
  384. { set some settings needed for arrayconstructor }
  385. if is_array_constructor(left.resulttype.def) then
  386. begin
  387. if is_array_of_const(paraitem.paratype.def) then
  388. begin
  389. { force variant array }
  390. include(left.flags,nf_forcevaria);
  391. end
  392. else
  393. begin
  394. include(left.flags,nf_novariaallowed);
  395. { now that the resultting type is know we can insert the required
  396. typeconvs for the array constructor }
  397. tarrayconstructornode(left).force_type(tarraydef(paraitem.paratype.def).elementtype);
  398. end;
  399. end;
  400. { check if local proc/func is assigned to procvar }
  401. if left.resulttype.def.deftype=procvardef then
  402. test_local_to_procvar(tprocvardef(left.resulttype.def),paraitem.paratype.def);
  403. { test conversions }
  404. if not(is_shortstring(left.resulttype.def) and
  405. is_shortstring(paraitem.paratype.def)) and
  406. (paraitem.paratype.def.deftype<>formaldef) then
  407. begin
  408. { Process open parameters }
  409. if paramanager.push_high_param(paraitem.paratyp,paraitem.paratype.def,aktcallnode.procdefinition.proccalloption) then
  410. begin
  411. { insert type conv but hold the ranges of the array }
  412. oldtype:=left.resulttype;
  413. inserttypeconv(left,paraitem.paratype);
  414. left.resulttype:=oldtype;
  415. end
  416. else
  417. begin
  418. { for ordinals, floats and enums, verify if we might cause
  419. some range-check errors. }
  420. if (paraitem.paratype.def.deftype in [enumdef,orddef,floatdef]) and
  421. (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) and
  422. (left.nodetype in [vecn,loadn,calln]) then
  423. begin
  424. if (left.resulttype.def.size>paraitem.paratype.def.size) then
  425. begin
  426. if (cs_check_range in aktlocalswitches) then
  427. Message(type_w_smaller_possible_range_check)
  428. else
  429. Message(type_h_smaller_possible_range_check);
  430. end;
  431. end;
  432. inserttypeconv(left,paraitem.paratype);
  433. end;
  434. if codegenerror then
  435. begin
  436. dec(parsing_para_level);
  437. exit;
  438. end;
  439. end;
  440. { check var strings }
  441. if (cs_strict_var_strings in aktlocalswitches) and
  442. is_shortstring(left.resulttype.def) and
  443. is_shortstring(paraitem.paratype.def) and
  444. (paraitem.paratyp in [vs_out,vs_var]) and
  445. not(is_open_string(paraitem.paratype.def)) and
  446. not(equal_defs(left.resulttype.def,paraitem.paratype.def)) then
  447. begin
  448. aktfilepos:=left.fileinfo;
  449. CGMessage(type_e_strict_var_string_violation);
  450. end;
  451. { Handle formal parameters separate }
  452. if (paraitem.paratype.def.deftype=formaldef) then
  453. begin
  454. { load procvar if a procedure is passed }
  455. if (m_tp_procvar in aktmodeswitches) and
  456. (left.nodetype=calln) and
  457. (is_void(left.resulttype.def)) then
  458. load_procvar_from_calln(left);
  459. case paraitem.paratyp of
  460. vs_var,
  461. vs_out :
  462. begin
  463. if not valid_for_formal_var(left) then
  464. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  465. end;
  466. vs_const :
  467. begin
  468. if not valid_for_formal_const(left) then
  469. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  470. end;
  471. end;
  472. end
  473. else
  474. begin
  475. { check if the argument is allowed }
  476. if (paraitem.paratyp in [vs_out,vs_var]) then
  477. valid_for_var(left);
  478. end;
  479. if paraitem.paratyp in [vs_var,vs_const] then
  480. begin
  481. { Causes problems with const ansistrings if also }
  482. { done for vs_const (JM) }
  483. if paraitem.paratyp = vs_var then
  484. set_unique(left);
  485. make_not_regable(left);
  486. end;
  487. { ansistrings out paramaters doesn't need to be }
  488. { unique, they are finalized }
  489. if paraitem.paratyp=vs_out then
  490. make_not_regable(left);
  491. if do_count then
  492. begin
  493. if paraitem.paratyp in [vs_var,vs_out] then
  494. set_varstate(left,vs_used,false)
  495. else
  496. set_varstate(left,vs_used,true);
  497. end;
  498. { must only be done after typeconv PM }
  499. resulttype:=paraitem.paratype;
  500. end;
  501. end;
  502. { process next node }
  503. if assigned(right) then
  504. tcallparanode(right).insert_typeconv(do_count);
  505. dec(parsing_para_level);
  506. {$ifdef extdebug}
  507. if do_count then
  508. count_ref:=store_count_ref;
  509. {$endif def extdebug}
  510. end;
  511. procedure tcallparanode.det_registers;
  512. begin
  513. if assigned(right) then
  514. begin
  515. tcallparanode(right).det_registers;
  516. registersint:=right.registersint;
  517. registersfpu:=right.registersfpu;
  518. {$ifdef SUPPORT_MMX}
  519. registersmmx:=right.registersmmx;
  520. {$endif}
  521. end;
  522. firstpass(left);
  523. if left.registersint>registersint then
  524. registersint:=left.registersint;
  525. if left.registersfpu>registersfpu then
  526. registersfpu:=left.registersfpu;
  527. {$ifdef SUPPORT_MMX}
  528. if left.registersmmx>registersmmx then
  529. registersmmx:=left.registersmmx;
  530. {$endif SUPPORT_MMX}
  531. end;
  532. procedure tcallparanode.firstcallparan;
  533. begin
  534. if not assigned(left.resulttype.def) then
  535. get_paratype;
  536. det_registers;
  537. end;
  538. function tcallparanode.docompare(p: tnode): boolean;
  539. begin
  540. docompare :=
  541. inherited docompare(p) and
  542. (callparaflags = tcallparanode(p).callparaflags)
  543. ;
  544. end;
  545. procedure tcallparanode.printnodetree(var t:text);
  546. begin
  547. printnodelist(t);
  548. end;
  549. {****************************************************************************
  550. TCALLNODE
  551. ****************************************************************************}
  552. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);
  553. begin
  554. inherited create(calln,l,nil);
  555. symtableprocentry:=v;
  556. symtableproc:=st;
  557. callnodeflags:=callflags+[cnf_return_value_used];
  558. methodpointer:=mp;
  559. methodpointerinit:=nil;
  560. methodpointerdone:=nil;
  561. procdefinition:=nil;
  562. _funcretnode:=nil;
  563. inlinecode:=nil;
  564. paralength:=-1;
  565. varargsparas:=nil;
  566. end;
  567. constructor tcallnode.create_procvar(l,r:tnode);
  568. begin
  569. inherited create(calln,l,r);
  570. symtableprocentry:=nil;
  571. symtableproc:=nil;
  572. methodpointer:=nil;
  573. methodpointerinit:=nil;
  574. methodpointerdone:=nil;
  575. procdefinition:=nil;
  576. callnodeflags:=[cnf_return_value_used];
  577. _funcretnode:=nil;
  578. inlinecode:=nil;
  579. paralength:=-1;
  580. varargsparas:=nil;
  581. end;
  582. constructor tcallnode.createintern(const name: string; params: tnode);
  583. var
  584. srsym: tsym;
  585. symowner: tsymtable;
  586. begin
  587. if not (cs_compilesystem in aktmoduleswitches) then
  588. begin
  589. srsym := searchsymonlyin(systemunit,name);
  590. symowner := systemunit;
  591. end
  592. else
  593. begin
  594. searchsym(name,srsym,symowner);
  595. if not assigned(srsym) then
  596. searchsym(upper(name),srsym,symowner);
  597. end;
  598. if not assigned(srsym) or
  599. (srsym.typ <> procsym) then
  600. begin
  601. {$ifdef EXTDEBUG}
  602. Comment(V_Error,'unknown compilerproc '+name);
  603. {$endif EXTDEBUG}
  604. internalerror(200107271);
  605. end;
  606. self.create(params,tprocsym(srsym),symowner,nil,[]);
  607. end;
  608. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  609. begin
  610. self.createintern(name,params);
  611. restype := res;
  612. include(callnodeflags,cnf_restypeset);
  613. { both the normal and specified resulttype either have to be returned via a }
  614. { parameter or not, but no mixing (JM) }
  615. if paramanager.ret_in_param(restype.def,pocall_compilerproc) xor
  616. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  617. internalerror(200108291);
  618. end;
  619. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  620. begin
  621. self.createintern(name,params);
  622. _funcretnode:=returnnode;
  623. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  624. internalerror(200204247);
  625. end;
  626. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  627. var
  628. para: tcallparanode;
  629. begin
  630. if assigned(_funcretnode) then
  631. _funcretnode.free;
  632. _funcretnode := returnnode;
  633. { if the resulttype pass hasn't occurred yet, that one will do }
  634. { everything }
  635. if assigned(resulttype.def) then
  636. begin
  637. { these are returned as values, but we can optimize their loading }
  638. { as well }
  639. if is_ansistring(resulttype.def) or
  640. is_widestring(resulttype.def) then
  641. exit;
  642. para := tcallparanode(left);
  643. while assigned(para) do
  644. begin
  645. if para.paraitem.is_hidden and
  646. (vo_is_funcret in tvarsym(para.paraitem.parasym).varoptions) then
  647. begin
  648. para.left.free;
  649. para.left := _funcretnode.getcopy;
  650. exit;
  651. end;
  652. para := tcallparanode(para.right);
  653. end;
  654. { no hidden resultpara found, error! }
  655. internalerror(200306087);
  656. end;
  657. end;
  658. destructor tcallnode.destroy;
  659. begin
  660. methodpointer.free;
  661. methodpointerinit.free;
  662. methodpointerdone.free;
  663. _funcretnode.free;
  664. inlinecode.free;
  665. if assigned(varargsparas) then
  666. varargsparas.free;
  667. inherited destroy;
  668. end;
  669. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  670. begin
  671. inherited ppuload(t,ppufile);
  672. ppufile.getderef(symtableprocentryderef);
  673. {$ifdef fpc}
  674. {$warning FIXME: No withsymtable support}
  675. {$endif}
  676. symtableproc:=nil;
  677. ppufile.getderef(procdefinitionderef);
  678. ppufile.getsmallset(callnodeflags);
  679. methodpointer:=ppuloadnode(ppufile);
  680. methodpointerinit:=ppuloadnode(ppufile);
  681. methodpointerdone:=ppuloadnode(ppufile);
  682. _funcretnode:=ppuloadnode(ppufile);
  683. inlinecode:=ppuloadnode(ppufile);
  684. end;
  685. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  686. begin
  687. inherited ppuwrite(ppufile);
  688. ppufile.putderef(symtableprocentryderef);
  689. ppufile.putderef(procdefinitionderef);
  690. ppufile.putsmallset(callnodeflags);
  691. ppuwritenode(ppufile,methodpointer);
  692. ppuwritenode(ppufile,methodpointerinit);
  693. ppuwritenode(ppufile,methodpointerdone);
  694. ppuwritenode(ppufile,_funcretnode);
  695. ppuwritenode(ppufile,inlinecode);
  696. end;
  697. procedure tcallnode.buildderefimpl;
  698. begin
  699. inherited buildderefimpl;
  700. symtableprocentryderef.build(symtableprocentry);
  701. procdefinitionderef.build(procdefinition);
  702. if assigned(methodpointer) then
  703. methodpointer.buildderefimpl;
  704. if assigned(methodpointerinit) then
  705. methodpointerinit.buildderefimpl;
  706. if assigned(methodpointerdone) then
  707. methodpointerdone.buildderefimpl;
  708. if assigned(_funcretnode) then
  709. _funcretnode.buildderefimpl;
  710. if assigned(inlinecode) then
  711. inlinecode.buildderefimpl;
  712. end;
  713. procedure tcallnode.derefimpl;
  714. var
  715. pt : tcallparanode;
  716. currpara : tparaitem;
  717. begin
  718. inherited derefimpl;
  719. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  720. symtableproc:=symtableprocentry.owner;
  721. procdefinition:=tprocdef(procdefinitionderef.resolve);
  722. if assigned(methodpointer) then
  723. methodpointer.derefimpl;
  724. if assigned(methodpointerinit) then
  725. methodpointerinit.derefimpl;
  726. if assigned(methodpointerdone) then
  727. methodpointerdone.derefimpl;
  728. if assigned(_funcretnode) then
  729. _funcretnode.derefimpl;
  730. if assigned(inlinecode) then
  731. inlinecode.derefimpl;
  732. { Connect paraitems }
  733. pt:=tcallparanode(left);
  734. while assigned(pt) and
  735. (cpf_varargs_para in pt.callparaflags) do
  736. pt:=tcallparanode(pt.right);
  737. currpara:=tparaitem(procdefinition.Para.last);
  738. while assigned(currpara) do
  739. begin
  740. if not assigned(pt) then
  741. internalerror(200311077);
  742. pt.paraitem:=currpara;
  743. pt:=tcallparanode(pt.right);
  744. currpara:=tparaitem(currpara.previous);
  745. end;
  746. if assigned(currpara) or assigned(pt) then
  747. internalerror(200311078);
  748. end;
  749. function tcallnode.getcopy : tnode;
  750. var
  751. n : tcallnode;
  752. hp : tparaitem;
  753. oldleft : tnode;
  754. begin
  755. { Need to use a hack here to prevent the parameters from being copied.
  756. The parameters must be copied between methodpointerinit/methodpointerdone because
  757. the can reference methodpointer }
  758. oldleft:=left;
  759. left:=nil;
  760. n:=tcallnode(inherited getcopy);
  761. left:=oldleft;
  762. n.symtableprocentry:=symtableprocentry;
  763. n.symtableproc:=symtableproc;
  764. n.procdefinition:=procdefinition;
  765. n.restype := restype;
  766. n.callnodeflags := callnodeflags;
  767. if assigned(methodpointerinit) then
  768. n.methodpointerinit:=methodpointerinit.getcopy
  769. else
  770. n.methodpointerinit:=nil;
  771. { methodpointerinit is copied, now references to the temp will also be copied
  772. correctly. We can now copy the parameters and methodpointer }
  773. if assigned(left) then
  774. n.left:=left.getcopy
  775. else
  776. n.left:=nil;
  777. if assigned(methodpointer) then
  778. n.methodpointer:=methodpointer.getcopy
  779. else
  780. n.methodpointer:=nil;
  781. if assigned(methodpointerdone) then
  782. n.methodpointerdone:=methodpointerdone.getcopy
  783. else
  784. n.methodpointerdone:=nil;
  785. if assigned(_funcretnode) then
  786. n._funcretnode:=_funcretnode.getcopy
  787. else
  788. n._funcretnode:=nil;
  789. if assigned(inlinecode) then
  790. n.inlinecode:=inlinecode.getcopy
  791. else
  792. n.inlinecode:=nil;
  793. if assigned(varargsparas) then
  794. begin
  795. n.varargsparas:=tvarargspara.create;
  796. hp:=tparaitem(varargsparas.first);
  797. while assigned(hp) do
  798. begin
  799. n.varargsparas.concat(hp.getcopy);
  800. hp:=tparaitem(hp.next);
  801. end;
  802. end
  803. else
  804. n.varargsparas:=nil;
  805. result:=n;
  806. end;
  807. procedure tcallnode.insertintolist(l : tnodelist);
  808. begin
  809. end;
  810. procedure tcallnode.convert_carg_array_of_const;
  811. var
  812. hp : tarrayconstructornode;
  813. oldleft : tcallparanode;
  814. begin
  815. oldleft:=tcallparanode(left);
  816. if oldleft.left.nodetype<>arrayconstructorn then
  817. begin
  818. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
  819. exit;
  820. end;
  821. { Get arrayconstructor node and insert typeconvs }
  822. hp:=tarrayconstructornode(oldleft.left);
  823. hp.insert_typeconvs;
  824. { Add c args parameters }
  825. { It could be an empty set }
  826. if assigned(hp) and
  827. assigned(hp.left) then
  828. begin
  829. while assigned(hp) do
  830. begin
  831. left:=ccallparanode.create(hp.left,left);
  832. { set callparanode resulttype and flags }
  833. left.resulttype:=hp.left.resulttype;
  834. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  835. hp.left:=nil;
  836. hp:=tarrayconstructornode(hp.right);
  837. end;
  838. end;
  839. { Remove value of old array of const parameter, but keep it
  840. in the list because it is required for bind_paraitem.
  841. Generate a nothign to keep callparanoed.left valid }
  842. oldleft.left.free;
  843. oldleft.left:=cnothingnode.create;
  844. end;
  845. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  846. var
  847. hp : tprocdef;
  848. j: integer;
  849. begin
  850. if (tsym(p).typ=procsym) then
  851. begin
  852. for j:=1 to tprocsym(p).procdef_count do
  853. begin
  854. { index starts at 1 }
  855. hp:=tprocsym(p).procdef[j];
  856. { If this is an abstract method insert into the list }
  857. if (po_abstractmethod in hp.procoptions) then
  858. AbstractMethodsList.Insert(hp.procsym.name)
  859. else
  860. { If this symbol is already in the list, and it is
  861. an overriding method or dynamic, then remove it from the list
  862. }
  863. begin
  864. { symbol was found }
  865. if AbstractMethodsList.Find(hp.procsym.name) <> nil then
  866. begin
  867. if po_overridingmethod in hp.procoptions then
  868. AbstractMethodsList.Remove(hp.procsym.name);
  869. end;
  870. end;
  871. end;
  872. end;
  873. end;
  874. procedure tcallnode.verifyabstractcalls;
  875. var
  876. objectdf : tobjectdef;
  877. parents : tlinkedlist;
  878. objectinfo : tobjectinfoitem;
  879. stritem : tstringlistitem;
  880. begin
  881. objectdf := nil;
  882. { verify if trying to create an instance of a class which contains
  883. non-implemented abstract methods }
  884. { first verify this class type, no class than exit }
  885. { also, this checking can only be done if the constructor is directly
  886. called, indirect constructor calls cannot be checked.
  887. }
  888. if assigned(methodpointer) then
  889. begin
  890. if (methodpointer.resulttype.def.deftype = objectdef) then
  891. objectdf:=tobjectdef(methodpointer.resulttype.def)
  892. else
  893. if (methodpointer.resulttype.def.deftype = classrefdef) and
  894. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  895. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  896. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  897. end;
  898. if not assigned(objectdf) then
  899. exit;
  900. parents := tlinkedlist.create;
  901. AbstractMethodsList := tstringlist.create;
  902. { insert all parents in this class : the first item in the
  903. list will be the base parent of the class .
  904. }
  905. while assigned(objectdf) do
  906. begin
  907. objectinfo:=tobjectinfoitem.create(objectdf);
  908. parents.insert(objectinfo);
  909. objectdf := objectdf.childof;
  910. end;
  911. { now all parents are in the correct order
  912. insert all abstract methods in the list, and remove
  913. those which are overriden by parent classes.
  914. }
  915. objectinfo:=tobjectinfoitem(parents.first);
  916. while assigned(objectinfo) do
  917. begin
  918. objectdf := objectinfo.objinfo;
  919. if assigned(objectdf.symtable) then
  920. objectdf.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}verifyabstract,nil);
  921. objectinfo:=tobjectinfoitem(objectinfo.next);
  922. end;
  923. if assigned(parents) then
  924. parents.free;
  925. { Finally give out a warning for each abstract method still in the list }
  926. stritem := tstringlistitem(AbstractMethodsList.first);
  927. if assigned(stritem) then
  928. Message1(type_w_instance_with_abstract,objectdf.objname^);
  929. while assigned(stritem) do
  930. begin
  931. if assigned(stritem.fpstr) then
  932. Message1(sym_h_param_list,stritem.str);
  933. stritem := tstringlistitem(stritem.next);
  934. end;
  935. if assigned(AbstractMethodsList) then
  936. AbstractMethodsList.Free;
  937. end;
  938. function tcallnode.gen_self_tree_methodpointer:tnode;
  939. var
  940. hsym : tvarsym;
  941. begin
  942. { find self field in methodpointer record }
  943. hsym:=tvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  944. if not assigned(hsym) then
  945. internalerror(200305251);
  946. { Load tmehodpointer(right).self }
  947. result:=csubscriptnode.create(
  948. hsym,
  949. ctypeconvnode.create_explicit(right.getcopy,methodpointertype));
  950. end;
  951. function tcallnode.gen_self_tree:tnode;
  952. var
  953. selftree : tnode;
  954. begin
  955. selftree:=nil;
  956. { inherited }
  957. if (cnf_inherited in callnodeflags) then
  958. selftree:=load_self_node
  959. else
  960. { constructors }
  961. if (procdefinition.proctypeoption=potype_constructor) then
  962. begin
  963. { push 0 as self when allocation is needed }
  964. if (methodpointer.resulttype.def.deftype=classrefdef) or
  965. (cnf_new_call in callnodeflags) then
  966. selftree:=cpointerconstnode.create(0,voidpointertype)
  967. else
  968. begin
  969. if methodpointer.nodetype=typen then
  970. selftree:=load_self_node
  971. else
  972. selftree:=methodpointer.getcopy;
  973. end;
  974. end
  975. else
  976. { Calling a static/class method }
  977. if (po_classmethod in procdefinition.procoptions) or
  978. (po_staticmethod in procdefinition.procoptions) then
  979. begin
  980. if (procdefinition.deftype<>procdef) then
  981. internalerror(200305062);
  982. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  983. begin
  984. { we only need the vmt, loading self is not required and there is no
  985. need to check for typen, because that will always get the
  986. loadvmtaddrnode added }
  987. selftree:=methodpointer.getcopy;
  988. if methodpointer.resulttype.def.deftype<>classrefdef then
  989. selftree:=cloadvmtaddrnode.create(selftree);
  990. end
  991. else
  992. selftree:=cpointerconstnode.create(0,voidpointertype);
  993. end
  994. else
  995. begin
  996. if methodpointer.nodetype=typen then
  997. selftree:=load_self_node
  998. else
  999. selftree:=methodpointer.getcopy;
  1000. end;
  1001. result:=selftree;
  1002. end;
  1003. function tcallnode.gen_vmt_tree:tnode;
  1004. var
  1005. vmttree : tnode;
  1006. begin
  1007. vmttree:=nil;
  1008. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1009. internalerror(200305051);
  1010. { inherited call, no create/destroy }
  1011. if (cnf_inherited in callnodeflags) then
  1012. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1013. else
  1014. { do not create/destroy when called from member function
  1015. without specifying self explicit }
  1016. if (cnf_member_call in callnodeflags) then
  1017. begin
  1018. if (methodpointer.resulttype.def.deftype=classrefdef) and
  1019. (procdefinition.proctypeoption=potype_constructor) then
  1020. vmttree:=methodpointer.getcopy
  1021. else
  1022. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1023. end
  1024. else
  1025. { constructor with extended syntax called from new }
  1026. if (cnf_new_call in callnodeflags) then
  1027. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1028. else
  1029. { destructor with extended syntax called from dispose }
  1030. if (cnf_dispose_call in callnodeflags) then
  1031. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1032. else
  1033. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1034. begin
  1035. { constructor call via classreference => allocate memory }
  1036. if (procdefinition.proctypeoption=potype_constructor) and
  1037. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1038. begin
  1039. vmttree:=methodpointer.getcopy;
  1040. { Only a typenode can be passed when it is called with <class of xx>.create }
  1041. if vmttree.nodetype=typen then
  1042. vmttree:=cloadvmtaddrnode.create(vmttree);
  1043. end
  1044. else
  1045. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1046. end
  1047. else
  1048. { class }
  1049. if is_class(methodpointer.resulttype.def) then
  1050. begin
  1051. { destructor: release instance, flag(vmt)=1
  1052. constructor: direct call, do nothing, leave vmt=0 }
  1053. if (procdefinition.proctypeoption=potype_destructor) then
  1054. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1055. else
  1056. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1057. end
  1058. else
  1059. { object }
  1060. begin
  1061. { destructor: direct call, no dispose, vmt=0
  1062. constructor: initialize object, load vmt }
  1063. if (procdefinition.proctypeoption=potype_constructor) then
  1064. { old styled inherited call? }
  1065. if (methodpointer.nodetype=typen) then
  1066. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1067. else
  1068. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1069. else
  1070. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1071. end;
  1072. result:=vmttree;
  1073. end;
  1074. procedure tcallnode.bind_paraitem;
  1075. var
  1076. i : integer;
  1077. pt : tcallparanode;
  1078. oldppt : ^tcallparanode;
  1079. varargspara,
  1080. currpara : tparaitem;
  1081. used_by_callnode : boolean;
  1082. hiddentree : tnode;
  1083. newstatement : tstatementnode;
  1084. temp : ttempcreatenode;
  1085. begin
  1086. pt:=tcallparanode(left);
  1087. oldppt:=@left;
  1088. { flag all callparanodes that belong to the varargs }
  1089. i:=paralength;
  1090. while (i>procdefinition.maxparacount) do
  1091. begin
  1092. include(pt.callparaflags,cpf_varargs_para);
  1093. oldppt:[email protected];
  1094. pt:=tcallparanode(pt.right);
  1095. dec(i);
  1096. end;
  1097. { skip varargs that are inserted by array of const }
  1098. while assigned(pt) and
  1099. (cpf_varargs_para in pt.callparaflags) do
  1100. pt:=tcallparanode(pt.right);
  1101. { process normal parameters and insert hidden parameters }
  1102. currpara:=tparaitem(procdefinition.Para.last);
  1103. while assigned(currpara) do
  1104. begin
  1105. if currpara.is_hidden then
  1106. begin
  1107. { generate hidden tree }
  1108. used_by_callnode:=false;
  1109. hiddentree:=nil;
  1110. if (vo_is_funcret in tvarsym(currpara.parasym).varoptions) then
  1111. begin
  1112. { Generate funcretnode if not specified }
  1113. if assigned(funcretnode) then
  1114. begin
  1115. hiddentree:=funcretnode.getcopy;
  1116. end
  1117. else
  1118. begin
  1119. hiddentree:=internalstatements(newstatement);
  1120. { need to use resulttype instead of procdefinition.rettype,
  1121. because they can be different }
  1122. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent);
  1123. addstatement(newstatement,temp);
  1124. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1125. addstatement(newstatement,ctemprefnode.create(temp));
  1126. end;
  1127. end
  1128. else
  1129. if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1130. begin
  1131. if not assigned(pt) then
  1132. internalerror(200304082);
  1133. { we need the information of the previous parameter }
  1134. hiddentree:=gen_high_tree(pt.left,tparaitem(currpara.previous).paratype.def);
  1135. end
  1136. else
  1137. if vo_is_self in tvarsym(currpara.parasym).varoptions then
  1138. begin
  1139. if assigned(right) then
  1140. hiddentree:=gen_self_tree_methodpointer
  1141. else
  1142. hiddentree:=gen_self_tree;
  1143. end
  1144. else
  1145. if vo_is_vmt in tvarsym(currpara.parasym).varoptions then
  1146. begin
  1147. hiddentree:=gen_vmt_tree;
  1148. end
  1149. else
  1150. if vo_is_parentfp in tvarsym(currpara.parasym).varoptions then
  1151. begin
  1152. if not(assigned(procdefinition.owner.defowner)) then
  1153. internalerror(200309287);
  1154. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1155. end
  1156. {$ifdef powerpc}
  1157. else
  1158. { lib parameter has no special type but proccalloptions must be a syscall }
  1159. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) and
  1160. (procdefinition.proccalloption=pocall_syscall) then
  1161. begin
  1162. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1163. end
  1164. {$endif powerpc}
  1165. else
  1166. { add the hidden parameter }
  1167. if not assigned(hiddentree) then
  1168. internalerror(200304073);
  1169. { Already insert para and let the previous node point to
  1170. this new node }
  1171. pt:=ccallparanode.create(hiddentree,oldppt^);
  1172. pt.used_by_callnode:=used_by_callnode;
  1173. oldppt^:=pt;
  1174. end;
  1175. if not assigned(pt) then
  1176. internalerror(200310052);
  1177. pt.paraitem:=currpara;
  1178. oldppt:[email protected];
  1179. pt:=tcallparanode(pt.right);
  1180. currpara:=tparaitem(currpara.previous)
  1181. end;
  1182. { Create paraitems for varargs }
  1183. pt:=tcallparanode(left);
  1184. while assigned(pt) do
  1185. begin
  1186. if cpf_varargs_para in pt.callparaflags then
  1187. begin
  1188. if not assigned(varargsparas) then
  1189. varargsparas:=tvarargspara.create;
  1190. varargspara:=tparaitem.create;
  1191. varargspara.paratyp:=vs_value;
  1192. varargspara.paratype:=pt.resulttype;
  1193. { varargspara is left-right, use insert
  1194. instead of concat }
  1195. varargsparas.insert(varargspara);
  1196. pt.paraitem:=varargspara;
  1197. end;
  1198. pt:=tcallparanode(pt.right);
  1199. end;
  1200. end;
  1201. function tcallnode.det_resulttype:tnode;
  1202. var
  1203. candidates : tcallcandidates;
  1204. oldcallnode : tcallnode;
  1205. hpt : tnode;
  1206. pt : tcallparanode;
  1207. lastpara : longint;
  1208. currpara : tparaitem;
  1209. cand_cnt : integer;
  1210. i : longint;
  1211. method_must_be_valid,
  1212. is_const : boolean;
  1213. hp : tnode;
  1214. mptemp : ttempcreatenode;
  1215. newstatement : tstatementnode;
  1216. label
  1217. errorexit;
  1218. begin
  1219. result:=nil;
  1220. candidates:=nil;
  1221. oldcallnode:=aktcallnode;
  1222. aktcallnode:=nil;
  1223. { determine length of parameter list }
  1224. pt:=tcallparanode(left);
  1225. paralength:=0;
  1226. while assigned(pt) do
  1227. begin
  1228. inc(paralength);
  1229. pt:=tcallparanode(pt.right);
  1230. end;
  1231. { determine the type of the parameters }
  1232. if assigned(left) then
  1233. begin
  1234. tcallparanode(left).get_paratype;
  1235. if codegenerror then
  1236. goto errorexit;
  1237. end;
  1238. if assigned(methodpointer) then
  1239. begin
  1240. resulttypepass(methodpointer);
  1241. hp:=methodpointer;
  1242. while assigned(hp) and
  1243. (hp.nodetype=typeconvn) do
  1244. hp:=tunarynode(hp).left;
  1245. if assigned(hp) and
  1246. (
  1247. { call result must always be loaded in temp to prevent
  1248. double creation }
  1249. (hp.nodetype=calln)
  1250. { Also optimize also complex loads }
  1251. {$warning Complex loads can also be optimized}
  1252. // not(hp.nodetype in [typen,loadvmtaddrn,loadn])
  1253. ) then
  1254. begin
  1255. { methodpointer loading }
  1256. methodpointerinit:=internalstatements(newstatement);
  1257. mptemp:=ctempcreatenode.create_reg(methodpointer.resulttype,methodpointer.resulttype.def.size,tt_persistent);
  1258. addstatement(newstatement,mptemp);
  1259. addstatement(newstatement,cassignmentnode.create(
  1260. ctemprefnode.create(mptemp),
  1261. methodpointer));
  1262. resulttypepass(methodpointerinit);
  1263. { new methodpointer is only a temp reference }
  1264. methodpointer:=ctemprefnode.create(mptemp);
  1265. resulttypepass(methodpointer);
  1266. { methodpointer cleanup }
  1267. methodpointerdone:=ctempdeletenode.create(mptemp);
  1268. resulttypepass(methodpointerdone);
  1269. end;
  1270. end;
  1271. { procedure variable ? }
  1272. if assigned(right) then
  1273. begin
  1274. set_varstate(right,vs_used,true);
  1275. resulttypepass(right);
  1276. if codegenerror then
  1277. exit;
  1278. procdefinition:=tabstractprocdef(right.resulttype.def);
  1279. { Compare parameters from right to left }
  1280. currpara:=tparaitem(procdefinition.Para.last);
  1281. { Skip default parameters }
  1282. if not(po_varargs in procdefinition.procoptions) then
  1283. begin
  1284. { ignore hidden parameters }
  1285. while assigned(currpara) and (currpara.is_hidden) do
  1286. currpara:=tparaitem(currpara.previous);
  1287. for i:=1 to procdefinition.maxparacount-paralength do
  1288. begin
  1289. if not assigned(currpara) then
  1290. internalerror(200402261);
  1291. if not assigned(currpara.defaultvalue) then
  1292. begin
  1293. CGMessage(parser_e_wrong_parameter_size);
  1294. goto errorexit;
  1295. end;
  1296. currpara:=tparaitem(currpara.previous);
  1297. end;
  1298. end;
  1299. while assigned(currpara) and (currpara.is_hidden) do
  1300. currpara:=tparaitem(currpara.previous);
  1301. pt:=tcallparanode(left);
  1302. lastpara:=paralength;
  1303. while assigned(currpara) and assigned(pt) do
  1304. begin
  1305. { only goto next para if we're out of the varargs }
  1306. if not(po_varargs in procdefinition.procoptions) or
  1307. (lastpara<=procdefinition.maxparacount) then
  1308. begin
  1309. repeat
  1310. currpara:=tparaitem(currpara.previous);
  1311. until (not assigned(currpara)) or (not currpara.is_hidden);
  1312. end;
  1313. pt:=tcallparanode(pt.right);
  1314. dec(lastpara);
  1315. end;
  1316. if assigned(pt) or
  1317. (assigned(currpara) and
  1318. not assigned(currpara.defaultvalue)) then
  1319. begin
  1320. if assigned(pt) then
  1321. aktfilepos:=pt.fileinfo;
  1322. CGMessage(parser_e_wrong_parameter_size);
  1323. goto errorexit;
  1324. end;
  1325. end
  1326. else
  1327. { not a procedure variable }
  1328. begin
  1329. { do we know the procedure to call ? }
  1330. if not(assigned(procdefinition)) then
  1331. begin
  1332. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags));
  1333. { no procedures found? then there is something wrong
  1334. with the parameter size or the procedures are
  1335. not accessible }
  1336. if candidates.count=0 then
  1337. begin
  1338. { when it's an auto inherited call and there
  1339. is no procedure found, but the procedures
  1340. were defined with overload directive and at
  1341. least two procedures are defined then we ignore
  1342. this inherited by inserting a nothingn. Only
  1343. do this ugly hack in Delphi mode as it looks more
  1344. like a bug. It's also not documented }
  1345. if (m_delphi in aktmodeswitches) and
  1346. (cnf_anon_inherited in callnodeflags) and
  1347. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1348. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1349. (symtableprocentry.procdef_count>=2) then
  1350. result:=cnothingnode.create
  1351. else
  1352. begin
  1353. { in tp mode we can try to convert to procvar if
  1354. there are no parameters specified. Only try it
  1355. when there is only one proc definition, else the
  1356. loadnode will give a strange error }
  1357. if not(assigned(left)) and
  1358. not(cnf_inherited in callnodeflags) and
  1359. (m_tp_procvar in aktmodeswitches) and
  1360. (symtableprocentry.procdef_count=1) then
  1361. begin
  1362. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1363. if assigned(methodpointer) then
  1364. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1365. resulttypepass(hpt);
  1366. result:=hpt;
  1367. end
  1368. else
  1369. begin
  1370. if assigned(left) then
  1371. aktfilepos:=left.fileinfo;
  1372. CGMessage(parser_e_wrong_parameter_size);
  1373. symtableprocentry.write_parameter_lists(nil);
  1374. end;
  1375. end;
  1376. goto errorexit;
  1377. end;
  1378. { Retrieve information about the candidates }
  1379. candidates.get_information;
  1380. {$ifdef EXTDEBUG}
  1381. { Display info when multiple candidates are found }
  1382. if candidates.count>1 then
  1383. candidates.dump_info(V_Debug);
  1384. {$endif EXTDEBUG}
  1385. { Choose the best candidate and count the number of
  1386. candidates left }
  1387. cand_cnt:=candidates.choose_best(procdefinition);
  1388. { All parameters are checked, check if there are any
  1389. procedures left }
  1390. if cand_cnt>0 then
  1391. begin
  1392. { Multiple candidates left? }
  1393. if cand_cnt>1 then
  1394. begin
  1395. CGMessage(type_e_cant_choose_overload_function);
  1396. {$ifdef EXTDEBUG}
  1397. candidates.dump_info(V_Hint);
  1398. {$else EXTDEBUG}
  1399. candidates.list(false);
  1400. {$endif EXTDEBUG}
  1401. { we'll just use the first candidate to make the
  1402. call }
  1403. end;
  1404. { assign procdefinition }
  1405. if symtableproc=nil then
  1406. symtableproc:=procdefinition.owner;
  1407. { update browser information }
  1408. if make_ref then
  1409. begin
  1410. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1411. inc(tprocdef(procdefinition).refcount);
  1412. if tprocdef(procdefinition).defref=nil then
  1413. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1414. end;
  1415. end
  1416. else
  1417. begin
  1418. { No candidates left, this must be a type error,
  1419. because wrong size is already checked. procdefinition
  1420. is filled with the first (random) definition that is
  1421. found. We use this definition to display a nice error
  1422. message that the wrong type is passed }
  1423. candidates.find_wrong_para;
  1424. candidates.list(true);
  1425. {$ifdef EXTDEBUG}
  1426. candidates.dump_info(V_Hint);
  1427. {$endif EXTDEBUG}
  1428. { We can not proceed, release all procs and exit }
  1429. candidates.free;
  1430. goto errorexit;
  1431. end;
  1432. candidates.free;
  1433. end; { end of procedure to call determination }
  1434. end;
  1435. { add needed default parameters }
  1436. if assigned(procdefinition) and
  1437. (paralength<procdefinition.maxparacount) then
  1438. begin
  1439. currpara:=tparaitem(procdefinition.Para.first);
  1440. i:=0;
  1441. while (i<paralength) do
  1442. begin
  1443. if not assigned(currpara) then
  1444. internalerror(200306181);
  1445. if not currpara.is_hidden then
  1446. inc(i);
  1447. currpara:=tparaitem(currpara.next);
  1448. end;
  1449. while assigned(currpara) and currpara.is_hidden do
  1450. currpara:=tparaitem(currpara.next);
  1451. while assigned(currpara) do
  1452. begin
  1453. if not assigned(currpara.defaultvalue) then
  1454. internalerror(200212142);
  1455. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1456. { Ignore vs_hidden parameters }
  1457. repeat
  1458. currpara:=tparaitem(currpara.next);
  1459. until (not assigned(currpara)) or (not currpara.is_hidden);
  1460. end;
  1461. end;
  1462. { handle predefined procedures }
  1463. is_const:=(po_internconst in procdefinition.procoptions) and
  1464. ((block_type in [bt_const,bt_type]) or
  1465. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1466. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1467. begin
  1468. if assigned(left) then
  1469. begin
  1470. { ptr and settextbuf needs two args }
  1471. if assigned(tcallparanode(left).right) then
  1472. begin
  1473. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1474. left:=nil;
  1475. end
  1476. else
  1477. begin
  1478. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1479. tcallparanode(left).left:=nil;
  1480. end;
  1481. end
  1482. else
  1483. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1484. result:=hpt;
  1485. goto errorexit;
  1486. end;
  1487. { ensure that the result type is set }
  1488. if not(cnf_restypeset in callnodeflags) then
  1489. begin
  1490. { constructors return their current class type, not the type where the
  1491. constructor is declared, this can be different because of inheritance }
  1492. if (procdefinition.proctypeoption=potype_constructor) and
  1493. assigned(methodpointer) and
  1494. assigned(methodpointer.resulttype.def) and
  1495. (methodpointer.resulttype.def.deftype=classrefdef) then
  1496. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1497. else
  1498. resulttype:=procdefinition.rettype;
  1499. end
  1500. else
  1501. resulttype:=restype;
  1502. {if resulttype.def.needs_inittable then
  1503. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1504. if assigned(methodpointer) then
  1505. begin
  1506. { when methodpointer is a callnode we must load it first into a
  1507. temp to prevent the processing callnode twice }
  1508. if (methodpointer.nodetype=calln) then
  1509. internalerror(200405121);
  1510. { direct call to inherited abstract method, then we
  1511. can already give a error in the compiler instead
  1512. of a runtime error }
  1513. if (cnf_inherited in callnodeflags) and
  1514. (po_abstractmethod in procdefinition.procoptions) then
  1515. CGMessage(cg_e_cant_call_abstract_method);
  1516. { if an inherited con- or destructor should be }
  1517. { called in a con- or destructor then a warning }
  1518. { will be made }
  1519. { con- and destructors need a pointer to the vmt }
  1520. if (cnf_inherited in callnodeflags) and
  1521. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1522. is_object(methodpointer.resulttype.def) and
  1523. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1524. CGMessage(cg_w_member_cd_call_from_method);
  1525. if methodpointer.nodetype<>typen then
  1526. begin
  1527. { Remove all postfix operators }
  1528. hpt:=methodpointer;
  1529. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1530. hpt:=tunarynode(hpt).left;
  1531. if (procdefinition.proctypeoption=potype_constructor) and
  1532. assigned(symtableproc) and
  1533. (symtableproc.symtabletype=withsymtable) and
  1534. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1535. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1536. { R.Init then R will be initialized by the constructor,
  1537. Also allow it for simple loads }
  1538. if (procdefinition.proctypeoption=potype_constructor) or
  1539. ((hpt.nodetype=loadn) and
  1540. (
  1541. (methodpointer.resulttype.def.deftype=classrefdef) or
  1542. (
  1543. (methodpointer.resulttype.def.deftype=objectdef) and
  1544. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1545. )
  1546. )
  1547. ) then
  1548. method_must_be_valid:=false
  1549. else
  1550. method_must_be_valid:=true;
  1551. set_varstate(methodpointer,vs_used,method_must_be_valid);
  1552. { The object is already used if it is called once }
  1553. if (hpt.nodetype=loadn) and
  1554. (tloadnode(hpt).symtableentry.typ=varsym) then
  1555. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  1556. end;
  1557. { if we are calling the constructor check for abstract
  1558. methods. Ignore inherited and member calls, because the
  1559. class is then already created }
  1560. if (procdefinition.proctypeoption=potype_constructor) and
  1561. not(cnf_inherited in callnodeflags) and
  1562. not(cnf_member_call in callnodeflags) then
  1563. verifyabstractcalls;
  1564. end
  1565. else
  1566. begin
  1567. { When this is method the methodpointer must be available }
  1568. if (right=nil) and
  1569. (procdefinition.owner.symtabletype=objectsymtable) then
  1570. internalerror(200305061);
  1571. end;
  1572. { Change loading of array of const to varargs }
  1573. if assigned(left) and
  1574. is_array_of_const(tparaitem(procdefinition.para.last).paratype.def) and
  1575. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  1576. convert_carg_array_of_const;
  1577. { bind paraitems to the callparanodes and insert hidden parameters }
  1578. aktcallnode:=self;
  1579. bind_paraitem;
  1580. { methodpointer is only needed for virtual calls, and
  1581. it should then be loaded with the VMT }
  1582. if (po_virtualmethod in procdefinition.procoptions) and
  1583. not(assigned(methodpointer) and
  1584. (methodpointer.nodetype=typen)) then
  1585. begin
  1586. if not assigned(methodpointer) then
  1587. internalerror(200305063);
  1588. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  1589. begin
  1590. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  1591. resulttypepass(methodpointer);
  1592. end;
  1593. end
  1594. else
  1595. begin
  1596. { not needed anymore }
  1597. methodpointer.free;
  1598. methodpointer:=nil;
  1599. end;
  1600. { insert type conversions for parameters }
  1601. if assigned(left) then
  1602. tcallparanode(left).insert_typeconv(true);
  1603. errorexit:
  1604. aktcallnode:=oldcallnode;
  1605. end;
  1606. procedure tcallnode.order_parameters;
  1607. var
  1608. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  1609. currloc : tcgloc;
  1610. begin
  1611. hpfirst:=nil;
  1612. hpcurr:=tcallparanode(left);
  1613. while assigned(hpcurr) do
  1614. begin
  1615. { pull out }
  1616. hpnext:=tcallparanode(hpcurr.right);
  1617. { pull in at the correct place.
  1618. Used order:
  1619. 1. LOC_REFERENCE with smallest offset (x86 only)
  1620. 2. LOC_REFERENCE with most registers
  1621. 3. LOC_REGISTER with most registers }
  1622. currloc:=hpcurr.paraitem.paraloc[callerside].loc;
  1623. hpprev:=nil;
  1624. hp:=hpfirst;
  1625. while assigned(hp) do
  1626. begin
  1627. case currloc of
  1628. LOC_REFERENCE :
  1629. begin
  1630. case hp.paraitem.paraloc[callerside].loc of
  1631. LOC_REFERENCE :
  1632. begin
  1633. { Offset is calculated like:
  1634. sub esp,12
  1635. mov [esp+8],para3
  1636. mov [esp+4],para2
  1637. mov [esp],para1
  1638. call function
  1639. That means the for pushes the para with the
  1640. highest offset (see para3) needs to be pushed first
  1641. }
  1642. if (hpcurr.registersint>hp.registersint)
  1643. {$ifdef x86}
  1644. or (hpcurr.paraitem.paraloc[callerside].reference.offset>hp.paraitem.paraloc[callerside].reference.offset)
  1645. {$endif x86}
  1646. then
  1647. break;
  1648. end;
  1649. LOC_REGISTER,
  1650. LOC_FPUREGISTER :
  1651. break;
  1652. end;
  1653. end;
  1654. LOC_FPUREGISTER,
  1655. LOC_REGISTER :
  1656. begin
  1657. if (hp.paraitem.paraloc[callerside].loc=currloc) and
  1658. (hpcurr.registersint>hp.registersint) then
  1659. break;
  1660. end;
  1661. end;
  1662. hpprev:=hp;
  1663. hp:=tcallparanode(hp.right);
  1664. end;
  1665. hpcurr.right:=hp;
  1666. if assigned(hpprev) then
  1667. hpprev.right:=hpcurr
  1668. else
  1669. hpfirst:=hpcurr;
  1670. { next }
  1671. hpcurr:=hpnext;
  1672. end;
  1673. left:=hpfirst;
  1674. end;
  1675. function tcallnode.pass_1 : tnode;
  1676. {$ifdef m68k}
  1677. var
  1678. regi : tregister;
  1679. {$endif}
  1680. label
  1681. errorexit;
  1682. begin
  1683. result:=nil;
  1684. { calculate the parameter info for the procdef }
  1685. if not procdefinition.has_paraloc_info then
  1686. begin
  1687. procdefinition.requiredargarea:=paramanager.create_paraloc_info(procdefinition,callerside);
  1688. procdefinition.has_paraloc_info:=true;
  1689. end;
  1690. { calculate the parameter size needed for this call include varargs if they are available }
  1691. if assigned(varargsparas) then
  1692. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  1693. else
  1694. pushedparasize:=procdefinition.requiredargarea;
  1695. { record maximum parameter size used in this proc }
  1696. current_procinfo.allocate_push_parasize(pushedparasize);
  1697. { work trough all parameters to get the register requirements }
  1698. if assigned(left) then
  1699. tcallparanode(left).det_registers;
  1700. { order parameters }
  1701. order_parameters;
  1702. if assigned(methodpointerinit) then
  1703. firstpass(methodpointerinit);
  1704. if assigned(methodpointerdone) then
  1705. firstpass(methodpointerdone);
  1706. { function result node }
  1707. if assigned(_funcretnode) then
  1708. firstpass(_funcretnode);
  1709. { procedure variable ? }
  1710. if assigned(right) then
  1711. begin
  1712. firstpass(right);
  1713. { procedure does a call }
  1714. if not (block_type in [bt_const,bt_type]) then
  1715. include(current_procinfo.flags,pi_do_call);
  1716. end
  1717. else
  1718. { not a procedure variable }
  1719. begin
  1720. { calc the correture value for the register }
  1721. { handle predefined procedures }
  1722. if (procdefinition.proccalloption=pocall_inline) then
  1723. begin
  1724. { inherit flags }
  1725. current_procinfo.flags:=current_procinfo.flags+((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  1726. if assigned(methodpointer) then
  1727. CGMessage(cg_e_unable_inline_object_methods);
  1728. if assigned(right) then
  1729. CGMessage(cg_e_unable_inline_procvar);
  1730. if not assigned(inlinecode) then
  1731. begin
  1732. if assigned(tprocdef(procdefinition).inlininginfo^.code) then
  1733. inlinecode:=tprocdef(procdefinition).inlininginfo^.code.getcopy
  1734. else
  1735. CGMessage(cg_e_no_code_for_inline_stored);
  1736. if assigned(inlinecode) then
  1737. begin
  1738. { consider it has not inlined if called
  1739. again inside the args }
  1740. procdefinition.proccalloption:=pocall_default;
  1741. firstpass(inlinecode);
  1742. end;
  1743. end;
  1744. end
  1745. else
  1746. begin
  1747. if not (block_type in [bt_const,bt_type]) then
  1748. include(current_procinfo.flags,pi_do_call);
  1749. end;
  1750. end;
  1751. { implicit finally needed ? }
  1752. if resulttype.def.needs_inittable and
  1753. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  1754. not assigned(funcretnode) then
  1755. include(current_procinfo.flags,pi_needs_implicit_finally);
  1756. { get a register for the return value }
  1757. if (not is_void(resulttype.def)) then
  1758. begin
  1759. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1760. begin
  1761. expectloc:=LOC_REFERENCE;
  1762. end
  1763. else
  1764. { for win32 records returned in EDX:EAX, we
  1765. move them to memory after ... }
  1766. if (resulttype.def.deftype=recorddef) then
  1767. begin
  1768. expectloc:=LOC_REFERENCE;
  1769. end
  1770. else
  1771. { ansi/widestrings must be registered, so we can dispose them }
  1772. if is_ansistring(resulttype.def) or
  1773. is_widestring(resulttype.def) then
  1774. begin
  1775. expectloc:=LOC_REFERENCE;
  1776. registersint:=1;
  1777. end
  1778. else
  1779. { we have only to handle the result if it is used }
  1780. if (cnf_return_value_used in callnodeflags) then
  1781. begin
  1782. case resulttype.def.deftype of
  1783. enumdef,
  1784. orddef :
  1785. begin
  1786. if (procdefinition.proctypeoption=potype_constructor) then
  1787. begin
  1788. expectloc:=LOC_REGISTER;
  1789. registersint:=1;
  1790. end
  1791. else
  1792. begin
  1793. expectloc:=LOC_REGISTER;
  1794. if is_64bit(resulttype.def) then
  1795. registersint:=2
  1796. else
  1797. registersint:=1;
  1798. end;
  1799. end;
  1800. floatdef :
  1801. begin
  1802. expectloc:=LOC_FPUREGISTER;
  1803. {$ifdef cpufpemu}
  1804. if (cs_fp_emulation in aktmoduleswitches) then
  1805. registersint:=1
  1806. else
  1807. {$endif cpufpemu}
  1808. {$ifdef m68k}
  1809. if (tfloatdef(resulttype.def).typ=s32real) then
  1810. registersint:=1
  1811. else
  1812. {$endif m68k}
  1813. registersfpu:=1;
  1814. end;
  1815. else
  1816. begin
  1817. expectloc:=LOC_REGISTER;
  1818. registersint:=1;
  1819. end;
  1820. end;
  1821. end
  1822. else
  1823. expectloc:=LOC_VOID;
  1824. end
  1825. else
  1826. expectloc:=LOC_VOID;
  1827. {$ifdef m68k}
  1828. { we need one more address register for virtual calls on m68k }
  1829. if (po_virtualmethod in procdefinition.procoptions) then
  1830. inc(registersint);
  1831. {$endif m68k}
  1832. { a fpu can be used in any procedure !! }
  1833. {$ifdef i386}
  1834. registersfpu:=procdefinition.fpu_used;
  1835. {$endif i386}
  1836. { if this is a call to a method calc the registers }
  1837. if (methodpointer<>nil) then
  1838. begin
  1839. if methodpointer.nodetype<>typen then
  1840. begin
  1841. firstpass(methodpointer);
  1842. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  1843. registersint:=max(methodpointer.registersint,registersint);
  1844. {$ifdef SUPPORT_MMX }
  1845. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  1846. {$endif SUPPORT_MMX}
  1847. end;
  1848. end;
  1849. { determine the registers of the procedure variable }
  1850. { is this OK for inlined procs also ?? (PM) }
  1851. if assigned(inlinecode) then
  1852. begin
  1853. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  1854. registersint:=max(inlinecode.registersint,registersint);
  1855. {$ifdef SUPPORT_MMX}
  1856. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  1857. {$endif SUPPORT_MMX}
  1858. end;
  1859. { determine the registers of the procedure variable }
  1860. { is this OK for inlined procs also ?? (PM) }
  1861. if assigned(right) then
  1862. begin
  1863. registersfpu:=max(right.registersfpu,registersfpu);
  1864. registersint:=max(right.registersint,registersint);
  1865. {$ifdef SUPPORT_MMX}
  1866. registersmmx:=max(right.registersmmx,registersmmx);
  1867. {$endif SUPPORT_MMX}
  1868. end;
  1869. { determine the registers of the procedure }
  1870. if assigned(left) then
  1871. begin
  1872. registersfpu:=max(left.registersfpu,registersfpu);
  1873. registersint:=max(left.registersint,registersint);
  1874. {$ifdef SUPPORT_MMX}
  1875. registersmmx:=max(left.registersmmx,registersmmx);
  1876. {$endif SUPPORT_MMX}
  1877. end;
  1878. errorexit:
  1879. if assigned(inlinecode) then
  1880. procdefinition.proccalloption:=pocall_inline;
  1881. end;
  1882. {$ifdef state_tracking}
  1883. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  1884. var hp:Tcallparanode;
  1885. value:Tnode;
  1886. begin
  1887. track_state_pass:=false;
  1888. hp:=Tcallparanode(left);
  1889. while assigned(hp) do
  1890. begin
  1891. if left.track_state_pass(exec_known) then
  1892. begin
  1893. left.resulttype.def:=nil;
  1894. do_resulttypepass(left);
  1895. end;
  1896. value:=aktstate.find_fact(hp.left);
  1897. if value<>nil then
  1898. begin
  1899. track_state_pass:=true;
  1900. hp.left.destroy;
  1901. hp.left:=value.getcopy;
  1902. do_resulttypepass(hp.left);
  1903. end;
  1904. hp:=Tcallparanode(hp.right);
  1905. end;
  1906. end;
  1907. {$endif}
  1908. function tcallnode.para_count:longint;
  1909. var
  1910. ppn : tcallparanode;
  1911. begin
  1912. result:=0;
  1913. ppn:=tcallparanode(left);
  1914. while assigned(ppn) do
  1915. begin
  1916. if not(assigned(ppn.paraitem) and
  1917. ppn.paraitem.is_hidden) then
  1918. inc(result);
  1919. ppn:=tcallparanode(ppn.right);
  1920. end;
  1921. end;
  1922. function tcallnode.docompare(p: tnode): boolean;
  1923. begin
  1924. docompare :=
  1925. inherited docompare(p) and
  1926. (symtableprocentry = tcallnode(p).symtableprocentry) and
  1927. (procdefinition = tcallnode(p).procdefinition) and
  1928. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  1929. (((cnf_restypeset in callnodeflags) and (cnf_restypeset in tcallnode(p).callnodeflags) and
  1930. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  1931. (not(cnf_restypeset in callnodeflags) and not(cnf_restypeset in tcallnode(p).callnodeflags)));
  1932. end;
  1933. procedure tcallnode.printnodedata(var t:text);
  1934. begin
  1935. if assigned(procdefinition) and
  1936. (procdefinition.deftype=procdef) then
  1937. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  1938. else
  1939. begin
  1940. if assigned(symtableprocentry) then
  1941. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  1942. else
  1943. writeln(t,printnodeindention,'proc = <nil>');
  1944. end;
  1945. printnode(t,methodpointer);
  1946. printnode(t,right);
  1947. printnode(t,left);
  1948. end;
  1949. begin
  1950. ccallnode:=tcallnode;
  1951. ccallparanode:=tcallparanode;
  1952. end.
  1953. {
  1954. $Log$
  1955. Revision 1.239 2004-06-20 08:55:29 florian
  1956. * logs truncated
  1957. Revision 1.238 2004/06/16 20:07:08 florian
  1958. * dwarf branch merged
  1959. Revision 1.237 2004/05/25 18:51:49 peter
  1960. * fix tcallnode.getcopy. the parameters need to be copied after
  1961. methodpointerinit is copied
  1962. Revision 1.236 2004/05/24 17:31:51 peter
  1963. * fix passing of array to open array of array (bug 3113)
  1964. Revision 1.235 2004/05/23 18:28:41 peter
  1965. * methodpointer is loaded into a temp when it was a calln
  1966. Revision 1.234 2004/05/23 15:06:20 peter
  1967. * implicit_finally flag must be set in pass1
  1968. * add check whether the implicit frame is generated when expected
  1969. }