ncal.pas 97 KB

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