ncal.pas 98 KB

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