ncal.pas 100 KB

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