ncal.pas 97 KB

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