ncal.pas 100 KB

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