ncal.pas 100 KB

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