ncal.pas 97 KB

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