ncal.pas 98 KB

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