ncal.pas 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592
  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. usevoidpointer : boolean;
  207. newinitstatement,
  208. newdonestatement : tstatementnode;
  209. begin
  210. if not assigned(aktcallnode) then
  211. internalerror(200410121);
  212. { Load all complex loads into a temp to prevent
  213. double calls to a function. We can't simply check for a hp.nodetype=calln
  214. }
  215. hp:=p;
  216. while assigned(hp) and
  217. (hp.nodetype=typeconvn) and
  218. (ttypeconvnode(hp).convtype=tc_equal) do
  219. hp:=tunarynode(hp).left;
  220. if assigned(hp) and
  221. not is_simple_node(hp) then
  222. begin
  223. if not assigned(aktcallnode.methodpointerinit) then
  224. begin
  225. aktcallnode.methodpointerinit:=internalstatements(newinitstatement);
  226. aktcallnode.methodpointerdone:=internalstatements(newdonestatement);
  227. end
  228. else
  229. begin
  230. newinitstatement:=laststatement(aktcallnode.methodpointerinit);
  231. newdonestatement:=laststatement(aktcallnode.methodpointerdone);
  232. end;
  233. { temp create }
  234. usederef:=(p.resulttype.def.deftype in [arraydef,recorddef]) or
  235. is_shortstring(p.resulttype.def) or
  236. is_object(p.resulttype.def);
  237. { avoid refcount increase }
  238. usevoidpointer:=is_interface(p.resulttype.def);
  239. if usederef then
  240. htype.setdef(tpointerdef.create(p.resulttype))
  241. else
  242. htype:=p.resulttype;
  243. if usevoidpointer then
  244. begin
  245. ptemp:=ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent,true);
  246. loadp := ctypeconvnode.create_internal(p,voidpointertype);
  247. refp:=ctypeconvnode.create_internal(ctemprefnode.create(ptemp),htype);
  248. end
  249. else
  250. begin
  251. ptemp:=ctempcreatenode.create(htype,htype.def.size,tt_persistent,true);
  252. if usederef then
  253. begin
  254. loadp:=caddrnode.create_internal(p);
  255. refp:=cderefnode.create(ctemprefnode.create(ptemp));
  256. end
  257. else
  258. begin
  259. loadp:=p;
  260. refp:=ctemprefnode.create(ptemp)
  261. end
  262. end;
  263. addstatement(newinitstatement,ptemp);
  264. addstatement(newinitstatement,cassignmentnode.create(
  265. ctemprefnode.create(ptemp),
  266. loadp));
  267. { new tree is only a temp reference }
  268. p:=refp;
  269. { temp release. We need to return a reference to the methodpointer
  270. otherwise the conversion from callnode to loadnode can't be done
  271. for the methodpointer unless the loadnode will also get a methodpointerinit and
  272. methodpointerdone node. For the moment we use register as temp and therefor
  273. don't create a temp-leak in the stackframe (PFV) }
  274. { the last statement should return the value as
  275. location and type, this is done be referencing the
  276. temp and converting it first from a persistent temp to
  277. normal temp }
  278. addstatement(newdonestatement,ctempdeletenode.create_normal_temp(ptemp));
  279. if usevoidpointer then
  280. addstatement(newdonestatement,ctypeconvnode.create_internal(
  281. ctemprefnode.create(ptemp),htype))
  282. else
  283. addstatement(newdonestatement,ctemprefnode.create(ptemp));
  284. { call resulttypepass for new nodes }
  285. resulttypepass(p);
  286. resulttypepass(aktcallnode.methodpointerinit);
  287. resulttypepass(aktcallnode.methodpointerdone);
  288. end;
  289. end;
  290. function gen_high_tree(var p:tnode;paradef:tdef):tnode;
  291. var
  292. temp: tnode;
  293. len : integer;
  294. loadconst : boolean;
  295. hightree : tnode;
  296. begin
  297. len:=-1;
  298. loadconst:=true;
  299. hightree:=nil;
  300. case p.resulttype.def.deftype of
  301. arraydef :
  302. begin
  303. if (paradef.deftype<>arraydef) then
  304. internalerror(200405241);
  305. { passing a string to an array of char }
  306. if (p.nodetype=stringconstn) then
  307. begin
  308. len:=str_length(p);
  309. if len>0 then
  310. dec(len);
  311. end
  312. else
  313. { handle special case of passing an single array to an array of array }
  314. if compare_defs(tarraydef(paradef).elementtype.def,p.resulttype.def,nothingn)>=te_equal then
  315. len:=0
  316. else
  317. begin
  318. { handle via a normal inline in_high_x node }
  319. loadconst:=false;
  320. { slice? }
  321. if (p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=in_slice_x) then
  322. begin
  323. hightree:=tcallparanode(tcallparanode(tinlinenode(p).left).right).left;
  324. hightree:=caddnode.create(subn,hightree,genintconstnode(1));
  325. tcallparanode(tcallparanode(tinlinenode(p).left).right).left:=nil;
  326. temp:=p;
  327. p:=tcallparanode(tinlinenode(p).left).left;
  328. tcallparanode(tinlinenode(temp).left).left:=nil;
  329. temp.free;
  330. resulttypepass(hightree);
  331. end
  332. else
  333. begin
  334. maybe_load_para_in_temp(p);
  335. hightree:=geninlinenode(in_high_x,false,p.getcopy);
  336. resulttypepass(hightree);
  337. { only substract low(array) if it's <> 0 }
  338. temp:=geninlinenode(in_low_x,false,p.getcopy);
  339. resulttypepass(temp);
  340. if (temp.nodetype <> ordconstn) or
  341. (tordconstnode(temp).value <> 0) then
  342. hightree := caddnode.create(subn,hightree,temp)
  343. else
  344. temp.free;
  345. end;
  346. end;
  347. end;
  348. stringdef :
  349. begin
  350. if is_open_string(paradef) then
  351. begin
  352. maybe_load_para_in_temp(p);
  353. { handle via a normal inline in_high_x node }
  354. loadconst := false;
  355. hightree := geninlinenode(in_high_x,false,p.getcopy);
  356. end
  357. else
  358. begin
  359. { passing a string to an array of char }
  360. if (p.nodetype=stringconstn) then
  361. begin
  362. len:=str_length(p);
  363. if len>0 then
  364. dec(len);
  365. end
  366. else
  367. begin
  368. maybe_load_para_in_temp(p);
  369. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  370. cordconstnode.create(1,s32inttype,false));
  371. loadconst:=false;
  372. end;
  373. end;
  374. end;
  375. else
  376. len:=0;
  377. end;
  378. if loadconst then
  379. hightree:=cordconstnode.create(len,s32inttype,true)
  380. else
  381. begin
  382. if not assigned(hightree) then
  383. internalerror(200304071);
  384. { Need to use explicit, because it can also be a enum }
  385. hightree:=ctypeconvnode.create_internal(hightree,s32inttype);
  386. end;
  387. result:=hightree;
  388. end;
  389. {****************************************************************************
  390. TOBJECTINFOITEM
  391. ****************************************************************************}
  392. constructor tobjectinfoitem.create(def : tobjectdef);
  393. begin
  394. inherited create;
  395. objinfo := def;
  396. end;
  397. {****************************************************************************
  398. TCALLPARANODE
  399. ****************************************************************************}
  400. constructor tcallparanode.create(expr,next : tnode);
  401. begin
  402. inherited create(callparan,expr,next);
  403. if not assigned(expr) then
  404. internalerror(200305091);
  405. expr.fileinfo:=fileinfo;
  406. callparaflags:=[];
  407. end;
  408. destructor tcallparanode.destroy;
  409. begin
  410. { When the node is used by callnode then
  411. we don't destroy left, the callnode takes care of it }
  412. if used_by_callnode then
  413. left:=nil;
  414. inherited destroy;
  415. end;
  416. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  417. begin
  418. inherited ppuload(t,ppufile);
  419. ppufile.getsmallset(callparaflags);
  420. end;
  421. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  422. begin
  423. inherited ppuwrite(ppufile);
  424. ppufile.putsmallset(callparaflags);
  425. end;
  426. function tcallparanode.getcopy : tnode;
  427. var
  428. n : tcallparanode;
  429. begin
  430. n:=tcallparanode(inherited getcopy);
  431. n.callparaflags:=callparaflags;
  432. n.parasym:=parasym;
  433. result:=n;
  434. end;
  435. procedure tcallparanode.insertintolist(l : tnodelist);
  436. begin
  437. end;
  438. procedure tcallparanode.get_paratype;
  439. var
  440. old_array_constructor : boolean;
  441. begin
  442. inc(parsing_para_level);
  443. if assigned(right) then
  444. tcallparanode(right).get_paratype;
  445. old_array_constructor:=allow_array_constructor;
  446. allow_array_constructor:=true;
  447. resulttypepass(left);
  448. allow_array_constructor:=old_array_constructor;
  449. if codegenerror then
  450. resulttype:=generrortype
  451. else
  452. resulttype:=left.resulttype;
  453. dec(parsing_para_level);
  454. end;
  455. procedure tcallparanode.insert_typeconv(do_count : boolean);
  456. var
  457. oldtype : ttype;
  458. hp : tnode;
  459. {$ifdef extdebug}
  460. store_count_ref : boolean;
  461. {$endif def extdebug}
  462. begin
  463. inc(parsing_para_level);
  464. {$ifdef extdebug}
  465. if do_count then
  466. begin
  467. store_count_ref:=count_ref;
  468. count_ref:=true;
  469. end;
  470. {$endif def extdebug}
  471. { Be sure to have the resulttype }
  472. if not assigned(left.resulttype.def) then
  473. resulttypepass(left);
  474. if (left.nodetype<>nothingn) then
  475. begin
  476. { Convert tp procvars, this is needs to be done
  477. here to make the change permanent. in the overload
  478. choosing the changes are only made temporary }
  479. if (left.resulttype.def.deftype=procvardef) and
  480. (parasym.vartype.def.deftype<>procvardef) then
  481. begin
  482. if maybe_call_procvar(left,true) then
  483. resulttype:=left.resulttype;
  484. end;
  485. { Remove implicitly inserted typecast to pointer for
  486. @procvar in macpas }
  487. if (m_mac_procvar in aktmodeswitches) and
  488. (parasym.vartype.def.deftype=procvardef) and
  489. (left.nodetype=typeconvn) and
  490. is_voidpointer(left.resulttype.def) and
  491. (ttypeconvnode(left).left.nodetype=typeconvn) and
  492. (ttypeconvnode(ttypeconvnode(left).left).convtype=tc_proc_2_procvar) then
  493. begin
  494. hp:=left;
  495. left:=ttypeconvnode(left).left;
  496. ttypeconvnode(hp).left:=nil;
  497. hp.free;
  498. end;
  499. { Handle varargs and hidden paras directly, no typeconvs or }
  500. { typechecking needed }
  501. if (cpf_varargs_para in callparaflags) then
  502. begin
  503. { this should only happen vor C varargs }
  504. { the necessary conversions have already been performed in }
  505. { tarrayconstructornode.insert_typeconvs }
  506. set_varstate(left,vs_read,[vsf_must_be_valid]);
  507. resulttype:=left.resulttype;
  508. { also update parasym type to get the correct parameter location
  509. for the new types }
  510. parasym.vartype:=left.resulttype;
  511. end
  512. else
  513. if (vo_is_hidden_para in parasym.varoptions) then
  514. begin
  515. set_varstate(left,vs_read,[vsf_must_be_valid]);
  516. resulttype:=left.resulttype;
  517. end
  518. else
  519. begin
  520. { Do we need arrayconstructor -> set conversion, then insert
  521. it here before the arrayconstructor node breaks the tree
  522. with its conversions of enum->ord }
  523. if (left.nodetype=arrayconstructorn) and
  524. (parasym.vartype.def.deftype=setdef) then
  525. inserttypeconv(left,parasym.vartype);
  526. { set some settings needed for arrayconstructor }
  527. if is_array_constructor(left.resulttype.def) then
  528. begin
  529. if left.nodetype<>arrayconstructorn then
  530. internalerror(200504041);
  531. if is_array_of_const(parasym.vartype.def) then
  532. begin
  533. { force variant array }
  534. include(left.flags,nf_forcevaria);
  535. end
  536. else
  537. begin
  538. include(left.flags,nf_novariaallowed);
  539. { now that the resultting type is know we can insert the required
  540. typeconvs for the array constructor }
  541. if parasym.vartype.def.deftype=arraydef then
  542. tarrayconstructornode(left).force_type(tarraydef(parasym.vartype.def).elementtype);
  543. end;
  544. end;
  545. { check if local proc/func is assigned to procvar }
  546. if left.resulttype.def.deftype=procvardef then
  547. test_local_to_procvar(tprocvardef(left.resulttype.def),parasym.vartype.def);
  548. { test conversions }
  549. if not(is_shortstring(left.resulttype.def) and
  550. is_shortstring(parasym.vartype.def)) and
  551. (parasym.vartype.def.deftype<>formaldef) then
  552. begin
  553. { Process open parameters }
  554. if paramanager.push_high_param(parasym.varspez,parasym.vartype.def,aktcallnode.procdefinition.proccalloption) then
  555. begin
  556. { insert type conv but hold the ranges of the array }
  557. oldtype:=left.resulttype;
  558. inserttypeconv(left,parasym.vartype);
  559. left.resulttype:=oldtype;
  560. end
  561. else
  562. begin
  563. check_ranges(left.fileinfo,left,parasym.vartype.def);
  564. inserttypeconv(left,parasym.vartype);
  565. end;
  566. if codegenerror then
  567. begin
  568. dec(parsing_para_level);
  569. exit;
  570. end;
  571. end;
  572. { check var strings }
  573. if (cs_strict_var_strings in aktlocalswitches) and
  574. is_shortstring(left.resulttype.def) and
  575. is_shortstring(parasym.vartype.def) and
  576. (parasym.varspez in [vs_out,vs_var]) and
  577. not(is_open_string(parasym.vartype.def)) and
  578. not(equal_defs(left.resulttype.def,parasym.vartype.def)) then
  579. begin
  580. aktfilepos:=left.fileinfo;
  581. CGMessage(type_e_strict_var_string_violation);
  582. end;
  583. { Handle formal parameters separate }
  584. if (parasym.vartype.def.deftype=formaldef) then
  585. begin
  586. { load procvar if a procedure is passed }
  587. if ((m_tp_procvar in aktmodeswitches) or
  588. (m_mac_procvar in aktmodeswitches)) and
  589. (left.nodetype=calln) and
  590. (is_void(left.resulttype.def)) then
  591. load_procvar_from_calln(left);
  592. case parasym.varspez of
  593. vs_var,
  594. vs_out :
  595. begin
  596. if not valid_for_formal_var(left,true) then
  597. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  598. end;
  599. vs_const :
  600. begin
  601. if not valid_for_formal_const(left,true) then
  602. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  603. end;
  604. end;
  605. end
  606. else
  607. begin
  608. { check if the argument is allowed }
  609. if (parasym.varspez in [vs_out,vs_var]) then
  610. valid_for_var(left,true);
  611. end;
  612. if parasym.varspez in [vs_var,vs_out] then
  613. set_unique(left);
  614. { When the address needs to be pushed then the register is
  615. not regable. Exception is when the location is also a var
  616. parameter and we can pass the address transparently }
  617. if (
  618. not(
  619. (vo_is_hidden_para in parasym.varoptions) and
  620. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  621. ) and
  622. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  623. aktcallnode.procdefinition.proccalloption) and
  624. not(
  625. (left.nodetype=loadn) and
  626. (tloadnode(left).is_addr_param_load)
  627. )
  628. ) then
  629. make_not_regable(left);
  630. if do_count then
  631. begin
  632. case parasym.varspez of
  633. vs_out :
  634. set_varstate(left,vs_written,[]);
  635. vs_var :
  636. set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
  637. else
  638. set_varstate(left,vs_read,[vsf_must_be_valid]);
  639. end;
  640. end;
  641. { must only be done after typeconv PM }
  642. resulttype:=parasym.vartype;
  643. end;
  644. end;
  645. { process next node }
  646. if assigned(right) then
  647. tcallparanode(right).insert_typeconv(do_count);
  648. dec(parsing_para_level);
  649. {$ifdef extdebug}
  650. if do_count then
  651. count_ref:=store_count_ref;
  652. {$endif def extdebug}
  653. end;
  654. procedure tcallparanode.det_registers;
  655. begin
  656. if assigned(right) then
  657. begin
  658. tcallparanode(right).det_registers;
  659. registersint:=right.registersint;
  660. registersfpu:=right.registersfpu;
  661. {$ifdef SUPPORT_MMX}
  662. registersmmx:=right.registersmmx;
  663. {$endif}
  664. end;
  665. firstpass(left);
  666. if left.registersint>registersint then
  667. registersint:=left.registersint;
  668. if left.registersfpu>registersfpu then
  669. registersfpu:=left.registersfpu;
  670. {$ifdef SUPPORT_MMX}
  671. if left.registersmmx>registersmmx then
  672. registersmmx:=left.registersmmx;
  673. {$endif SUPPORT_MMX}
  674. end;
  675. procedure tcallparanode.firstcallparan;
  676. begin
  677. if not assigned(left.resulttype.def) then
  678. get_paratype;
  679. det_registers;
  680. end;
  681. function tcallparanode.docompare(p: tnode): boolean;
  682. begin
  683. docompare :=
  684. inherited docompare(p) and
  685. (callparaflags = tcallparanode(p).callparaflags)
  686. ;
  687. end;
  688. procedure tcallparanode.printnodetree(var t:text);
  689. begin
  690. printnodelist(t);
  691. end;
  692. {****************************************************************************
  693. TCALLNODE
  694. ****************************************************************************}
  695. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);
  696. begin
  697. inherited create(calln,l,nil);
  698. symtableprocentry:=v;
  699. symtableproc:=st;
  700. callnodeflags:=callflags+[cnf_return_value_used];
  701. methodpointer:=mp;
  702. methodpointerinit:=nil;
  703. methodpointerdone:=nil;
  704. procdefinition:=nil;
  705. _funcretnode:=nil;
  706. {$ifdef PASS2INLINE}
  707. inlinecode:=nil;
  708. {$endif PASS2INLINE}
  709. paralength:=-1;
  710. varargsparas:=nil;
  711. end;
  712. constructor tcallnode.create_procvar(l,r:tnode);
  713. begin
  714. inherited create(calln,l,r);
  715. symtableprocentry:=nil;
  716. symtableproc:=nil;
  717. methodpointer:=nil;
  718. methodpointerinit:=nil;
  719. methodpointerdone:=nil;
  720. procdefinition:=nil;
  721. callnodeflags:=[cnf_return_value_used];
  722. _funcretnode:=nil;
  723. {$ifdef PASS2INLINE}
  724. inlinecode:=nil;
  725. {$endif PASS2INLINE}
  726. paralength:=-1;
  727. varargsparas:=nil;
  728. end;
  729. constructor tcallnode.createintern(const name: string; params: tnode);
  730. var
  731. srsym: tsym;
  732. symowner: tsymtable;
  733. begin
  734. if not (cs_compilesystem in aktmoduleswitches) then
  735. begin
  736. srsym := searchsymonlyin(systemunit,name);
  737. symowner := systemunit;
  738. end
  739. else
  740. begin
  741. searchsym(name,srsym,symowner);
  742. if not assigned(srsym) then
  743. searchsym(upper(name),srsym,symowner);
  744. end;
  745. if not assigned(srsym) or
  746. (srsym.typ <> procsym) then
  747. Message1(cg_f_unknown_compiler,name);
  748. self.create(params,tprocsym(srsym),symowner,nil,[]);
  749. end;
  750. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  751. begin
  752. self.createintern(name,params);
  753. restype := res;
  754. include(callnodeflags,cnf_restypeset);
  755. { both the normal and specified resulttype either have to be returned via a }
  756. { parameter or not, but no mixing (JM) }
  757. if paramanager.ret_in_param(restype.def,symtableprocentry.first_procdef.proccalloption) xor
  758. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  759. internalerror(200108291);
  760. end;
  761. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  762. begin
  763. self.createintern(name,params);
  764. _funcretnode:=returnnode;
  765. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  766. internalerror(200204247);
  767. end;
  768. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  769. var
  770. para: tcallparanode;
  771. begin
  772. if assigned(_funcretnode) then
  773. _funcretnode.free;
  774. _funcretnode := returnnode;
  775. { if the resulttype pass hasn't occurred yet, that one will do }
  776. { everything }
  777. if assigned(resulttype.def) then
  778. begin
  779. { these are returned as values, but we can optimize their loading }
  780. { as well }
  781. if is_ansistring(resulttype.def) or
  782. is_widestring(resulttype.def) then
  783. exit;
  784. para := tcallparanode(left);
  785. while assigned(para) do
  786. begin
  787. if (vo_is_hidden_para in para.parasym.varoptions) and
  788. (vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  789. begin
  790. para.left.free;
  791. para.left := _funcretnode.getcopy;
  792. exit;
  793. end;
  794. para := tcallparanode(para.right);
  795. end;
  796. { no hidden resultpara found, error! }
  797. if not(po_inline in procdefinition.procoptions) then
  798. internalerror(200306087);
  799. end;
  800. end;
  801. destructor tcallnode.destroy;
  802. var
  803. i : longint;
  804. begin
  805. methodpointer.free;
  806. methodpointerinit.free;
  807. methodpointerdone.free;
  808. _funcretnode.free;
  809. {$ifdef PASS2INLINE}
  810. inlinecode.free;
  811. {$endif PASS2INLINE}
  812. if assigned(varargsparas) then
  813. begin
  814. for i:=0 to varargsparas.count-1 do
  815. tparavarsym(varargsparas[i]).free;
  816. varargsparas.free;
  817. end;
  818. inherited destroy;
  819. end;
  820. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  821. begin
  822. inherited ppuload(t,ppufile);
  823. ppufile.getderef(symtableprocentryderef);
  824. {$ifdef fpc}
  825. {$warning FIXME: No withsymtable support}
  826. {$endif}
  827. symtableproc:=nil;
  828. ppufile.getderef(procdefinitionderef);
  829. ppufile.getsmallset(callnodeflags);
  830. methodpointer:=ppuloadnode(ppufile);
  831. methodpointerinit:=tblocknode(ppuloadnode(ppufile));
  832. methodpointerdone:=tblocknode(ppuloadnode(ppufile));
  833. _funcretnode:=ppuloadnode(ppufile);
  834. {$ifdef PASS2INLINE}
  835. inlinecode:=ppuloadnode(ppufile);
  836. {$endif PASS2INLINE}
  837. end;
  838. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  839. begin
  840. inherited ppuwrite(ppufile);
  841. ppufile.putderef(symtableprocentryderef);
  842. ppufile.putderef(procdefinitionderef);
  843. ppufile.putsmallset(callnodeflags);
  844. ppuwritenode(ppufile,methodpointer);
  845. ppuwritenode(ppufile,methodpointerinit);
  846. ppuwritenode(ppufile,methodpointerdone);
  847. ppuwritenode(ppufile,_funcretnode);
  848. {$ifdef PASS2INLINE}
  849. ppuwritenode(ppufile,inlinecode);
  850. {$endif PASS2INLINE}
  851. end;
  852. procedure tcallnode.buildderefimpl;
  853. begin
  854. inherited buildderefimpl;
  855. symtableprocentryderef.build(symtableprocentry);
  856. procdefinitionderef.build(procdefinition);
  857. if assigned(methodpointer) then
  858. methodpointer.buildderefimpl;
  859. if assigned(methodpointerinit) then
  860. methodpointerinit.buildderefimpl;
  861. if assigned(methodpointerdone) then
  862. methodpointerdone.buildderefimpl;
  863. if assigned(_funcretnode) then
  864. _funcretnode.buildderefimpl;
  865. {$ifdef PASS2INLINE}
  866. if assigned(inlinecode) then
  867. inlinecode.buildderefimpl;
  868. {$endif PASS2INLINE}
  869. end;
  870. procedure tcallnode.derefimpl;
  871. var
  872. pt : tcallparanode;
  873. i : integer;
  874. begin
  875. inherited derefimpl;
  876. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  877. if assigned(symtableprocentry) then
  878. symtableproc:=symtableprocentry.owner;
  879. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  880. if assigned(methodpointer) then
  881. methodpointer.derefimpl;
  882. if assigned(methodpointerinit) then
  883. methodpointerinit.derefimpl;
  884. if assigned(methodpointerdone) then
  885. methodpointerdone.derefimpl;
  886. if assigned(_funcretnode) then
  887. _funcretnode.derefimpl;
  888. {$ifdef PASS2INLINE}
  889. if assigned(inlinecode) then
  890. inlinecode.derefimpl;
  891. {$endif PASS2INLINE}
  892. { Connect parasyms }
  893. pt:=tcallparanode(left);
  894. while assigned(pt) and
  895. (cpf_varargs_para in pt.callparaflags) do
  896. pt:=tcallparanode(pt.right);
  897. for i:=procdefinition.paras.count-1 downto 0 do
  898. begin
  899. if not assigned(pt) then
  900. internalerror(200311077);
  901. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  902. pt:=tcallparanode(pt.right);
  903. end;
  904. if assigned(pt) then
  905. internalerror(200311078);
  906. end;
  907. function tcallnode.getcopy : tnode;
  908. var
  909. n : tcallnode;
  910. i : integer;
  911. hp,hpn : tparavarsym;
  912. oldleft : tnode;
  913. begin
  914. { Need to use a hack here to prevent the parameters from being copied.
  915. The parameters must be copied between methodpointerinit/methodpointerdone because
  916. the can reference methodpointer }
  917. oldleft:=left;
  918. left:=nil;
  919. n:=tcallnode(inherited getcopy);
  920. left:=oldleft;
  921. n.symtableprocentry:=symtableprocentry;
  922. n.symtableproc:=symtableproc;
  923. n.procdefinition:=procdefinition;
  924. n.restype := restype;
  925. n.callnodeflags := callnodeflags;
  926. if assigned(methodpointerinit) then
  927. n.methodpointerinit:=tblocknode(methodpointerinit.getcopy)
  928. else
  929. n.methodpointerinit:=nil;
  930. { methodpointerinit is copied, now references to the temp will also be copied
  931. correctly. We can now copy the parameters and methodpointer }
  932. if assigned(left) then
  933. n.left:=left.getcopy
  934. else
  935. n.left:=nil;
  936. if assigned(methodpointer) then
  937. n.methodpointer:=methodpointer.getcopy
  938. else
  939. n.methodpointer:=nil;
  940. if assigned(methodpointerdone) then
  941. n.methodpointerdone:=tblocknode(methodpointerdone.getcopy)
  942. else
  943. n.methodpointerdone:=nil;
  944. if assigned(_funcretnode) then
  945. n._funcretnode:=_funcretnode.getcopy
  946. else
  947. n._funcretnode:=nil;
  948. {$ifdef PASS2INLINE}
  949. if assigned(inlinecode) then
  950. n.inlinecode:=inlinecode.getcopy
  951. else
  952. n.inlinecode:=nil;
  953. {$endif PASS2INLINE}
  954. if assigned(varargsparas) then
  955. begin
  956. n.varargsparas:=tvarargsparalist.create;
  957. for i:=0 to varargsparas.count-1 do
  958. begin
  959. hp:=tparavarsym(varargsparas[i]);
  960. hpn:=tparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vartype,[]);
  961. n.varargsparas.add(hpn);
  962. end;
  963. end
  964. else
  965. n.varargsparas:=nil;
  966. result:=n;
  967. end;
  968. procedure tcallnode.insertintolist(l : tnodelist);
  969. begin
  970. end;
  971. procedure tcallnode.convert_carg_array_of_const;
  972. var
  973. hp : tarrayconstructornode;
  974. oldleft : tcallparanode;
  975. begin
  976. oldleft:=tcallparanode(left);
  977. if oldleft.left.nodetype<>arrayconstructorn then
  978. begin
  979. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
  980. exit;
  981. end;
  982. include(callnodeflags,cnf_uses_varargs);
  983. { Get arrayconstructor node and insert typeconvs }
  984. hp:=tarrayconstructornode(oldleft.left);
  985. hp.insert_typeconvs(true);
  986. { Add c args parameters }
  987. { It could be an empty set }
  988. if assigned(hp) and
  989. assigned(hp.left) then
  990. begin
  991. while assigned(hp) do
  992. begin
  993. left:=ccallparanode.create(hp.left,left);
  994. { set callparanode resulttype and flags }
  995. left.resulttype:=hp.left.resulttype;
  996. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  997. hp.left:=nil;
  998. hp:=tarrayconstructornode(hp.right);
  999. end;
  1000. end;
  1001. { Remove value of old array of const parameter, but keep it
  1002. in the list because it is required for bind_parasym.
  1003. Generate a nothign to keep callparanoed.left valid }
  1004. oldleft.left.free;
  1005. oldleft.left:=cnothingnode.create;
  1006. end;
  1007. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  1008. var
  1009. hp : tprocdef;
  1010. j: integer;
  1011. begin
  1012. if (tsym(p).typ=procsym) then
  1013. begin
  1014. for j:=1 to tprocsym(p).procdef_count do
  1015. begin
  1016. { index starts at 1 }
  1017. hp:=tprocsym(p).procdef[j];
  1018. { If this is an abstract method insert into the list }
  1019. if (po_abstractmethod in hp.procoptions) then
  1020. AbstractMethodsList.Insert(hp.procsym.realname)
  1021. else
  1022. { If this symbol is a virtual (includes override) method,
  1023. then remove it from the list }
  1024. if po_virtualmethod in hp.procoptions then
  1025. AbstractMethodsList.Remove(hp.procsym.realname);
  1026. end;
  1027. end;
  1028. end;
  1029. procedure tcallnode.verifyabstractcalls;
  1030. var
  1031. objectdf : tobjectdef;
  1032. parents : tlinkedlist;
  1033. objectinfo : tobjectinfoitem;
  1034. stritem : tstringlistitem;
  1035. begin
  1036. objectdf := nil;
  1037. { verify if trying to create an instance of a class which contains
  1038. non-implemented abstract methods }
  1039. { first verify this class type, no class than exit }
  1040. { also, this checking can only be done if the constructor is directly
  1041. called, indirect constructor calls cannot be checked.
  1042. }
  1043. if assigned(methodpointer) then
  1044. begin
  1045. if (methodpointer.resulttype.def.deftype = objectdef) then
  1046. objectdf:=tobjectdef(methodpointer.resulttype.def)
  1047. else
  1048. if (methodpointer.resulttype.def.deftype = classrefdef) and
  1049. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  1050. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  1051. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  1052. end;
  1053. if not assigned(objectdf) then
  1054. exit;
  1055. parents := tlinkedlist.create;
  1056. AbstractMethodsList := tstringlist.create;
  1057. { insert all parents in this class : the first item in the
  1058. list will be the base parent of the class .
  1059. }
  1060. while assigned(objectdf) do
  1061. begin
  1062. objectinfo:=tobjectinfoitem.create(objectdf);
  1063. parents.insert(objectinfo);
  1064. objectdf := objectdf.childof;
  1065. end;
  1066. { now all parents are in the correct order
  1067. insert all abstract methods in the list, and remove
  1068. those which are overriden by parent classes.
  1069. }
  1070. objectinfo:=tobjectinfoitem(parents.first);
  1071. while assigned(objectinfo) do
  1072. begin
  1073. objectdf := objectinfo.objinfo;
  1074. if assigned(objectdf.symtable) then
  1075. objectdf.symtable.foreach(@verifyabstract,nil);
  1076. objectinfo:=tobjectinfoitem(objectinfo.next);
  1077. end;
  1078. if assigned(parents) then
  1079. parents.free;
  1080. { Finally give out a warning for each abstract method still in the list }
  1081. stritem := tstringlistitem(AbstractMethodsList.first);
  1082. if assigned(stritem) then
  1083. Message1(type_w_instance_with_abstract,objectdf.objrealname^);
  1084. while assigned(stritem) do
  1085. begin
  1086. if assigned(stritem.fpstr) then
  1087. Message1(sym_h_param_list,stritem.str);
  1088. stritem := tstringlistitem(stritem.next);
  1089. end;
  1090. if assigned(AbstractMethodsList) then
  1091. AbstractMethodsList.Free;
  1092. end;
  1093. function tcallnode.gen_self_tree_methodpointer:tnode;
  1094. var
  1095. hsym : tfieldvarsym;
  1096. begin
  1097. { find self field in methodpointer record }
  1098. hsym:=tfieldvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1099. if not assigned(hsym) then
  1100. internalerror(200305251);
  1101. { Load tmehodpointer(right).self }
  1102. result:=csubscriptnode.create(
  1103. hsym,
  1104. ctypeconvnode.create_internal(right.getcopy,methodpointertype));
  1105. end;
  1106. function tcallnode.gen_self_tree:tnode;
  1107. var
  1108. selftree : tnode;
  1109. begin
  1110. selftree:=nil;
  1111. { inherited }
  1112. if (cnf_inherited in callnodeflags) then
  1113. selftree:=load_self_node
  1114. else
  1115. { constructors }
  1116. if (procdefinition.proctypeoption=potype_constructor) then
  1117. begin
  1118. { push 0 as self when allocation is needed }
  1119. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1120. (cnf_new_call in callnodeflags) then
  1121. selftree:=cpointerconstnode.create(0,voidpointertype)
  1122. else
  1123. begin
  1124. if methodpointer.nodetype=typen then
  1125. selftree:=load_self_node
  1126. else
  1127. selftree:=methodpointer.getcopy;
  1128. end;
  1129. end
  1130. else
  1131. { Calling a static/class method }
  1132. if (po_classmethod in procdefinition.procoptions) or
  1133. (po_staticmethod in procdefinition.procoptions) then
  1134. begin
  1135. if (procdefinition.deftype<>procdef) then
  1136. internalerror(200305062);
  1137. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1138. begin
  1139. { we only need the vmt, loading self is not required and there is no
  1140. need to check for typen, because that will always get the
  1141. loadvmtaddrnode added }
  1142. selftree:=methodpointer.getcopy;
  1143. if methodpointer.resulttype.def.deftype<>classrefdef then
  1144. selftree:=cloadvmtaddrnode.create(selftree);
  1145. end
  1146. else
  1147. selftree:=cpointerconstnode.create(0,voidpointertype);
  1148. end
  1149. else
  1150. begin
  1151. if methodpointer.nodetype=typen then
  1152. selftree:=load_self_node
  1153. else
  1154. selftree:=methodpointer.getcopy;
  1155. end;
  1156. result:=selftree;
  1157. end;
  1158. function tcallnode.gen_vmt_tree:tnode;
  1159. var
  1160. vmttree : tnode;
  1161. begin
  1162. vmttree:=nil;
  1163. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1164. internalerror(200305051);
  1165. { Handle classes and legacy objects separate to make it
  1166. more maintainable }
  1167. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1168. begin
  1169. if not is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1170. internalerror(200501041);
  1171. { constructor call via classreference => allocate memory }
  1172. if (procdefinition.proctypeoption=potype_constructor) then
  1173. begin
  1174. vmttree:=methodpointer.getcopy;
  1175. { Only a typenode can be passed when it is called with <class of xx>.create }
  1176. if vmttree.nodetype=typen then
  1177. vmttree:=cloadvmtaddrnode.create(vmttree);
  1178. end
  1179. else
  1180. begin
  1181. { Call afterconstruction }
  1182. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1183. end;
  1184. end
  1185. else
  1186. { Class style objects }
  1187. if is_class(methodpointer.resulttype.def) then
  1188. begin
  1189. { inherited call, no create/destroy }
  1190. if (cnf_inherited in callnodeflags) then
  1191. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1192. else
  1193. { do not create/destroy when called from member function
  1194. without specifying self explicit }
  1195. if (cnf_member_call in callnodeflags) then
  1196. begin
  1197. { destructor: don't release instance, vmt=0
  1198. constructor:
  1199. if called from a constructor in the same class then
  1200. don't call afterconstruction, vmt=0
  1201. else
  1202. call afterconstrution, vmt=1 }
  1203. if (procdefinition.proctypeoption=potype_destructor) then
  1204. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1205. else
  1206. begin
  1207. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1208. (procdefinition.proctypeoption=potype_constructor) then
  1209. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1210. else
  1211. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1212. end;
  1213. end
  1214. else
  1215. { normal call to method like cl1.proc }
  1216. begin
  1217. { destructor: release instance, vmt=1
  1218. constructor:
  1219. if called from a constructor in the same class using self.create then
  1220. don't call afterconstruction, vmt=0
  1221. else
  1222. call afterconstrution, vmt=1 }
  1223. if (procdefinition.proctypeoption=potype_destructor) then
  1224. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1225. else
  1226. begin
  1227. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1228. (procdefinition.proctypeoption=potype_constructor) and
  1229. (nf_is_self in methodpointer.flags) then
  1230. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1231. else
  1232. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1233. end;
  1234. end;
  1235. end
  1236. else
  1237. { Old style object }
  1238. begin
  1239. { constructor with extended syntax called from new }
  1240. if (cnf_new_call in callnodeflags) then
  1241. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1242. else
  1243. { destructor with extended syntax called from dispose }
  1244. if (cnf_dispose_call in callnodeflags) then
  1245. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1246. else
  1247. { inherited call, no create/destroy }
  1248. if (cnf_inherited in callnodeflags) then
  1249. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1250. else
  1251. { do not create/destroy when called from member function
  1252. without specifying self explicit }
  1253. if (cnf_member_call in callnodeflags) then
  1254. begin
  1255. { destructor: don't release instance, vmt=0
  1256. constructor: don't initialize instance, vmt=0 }
  1257. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1258. end
  1259. else
  1260. { normal object call like obj.proc }
  1261. begin
  1262. { destructor: direct call, no dispose, vmt=0
  1263. constructor: initialize object, load vmt }
  1264. if (procdefinition.proctypeoption=potype_constructor) then
  1265. begin
  1266. { old styled inherited call? }
  1267. if (methodpointer.nodetype=typen) then
  1268. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1269. else
  1270. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1271. end
  1272. else
  1273. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1274. end;
  1275. end;
  1276. result:=vmttree;
  1277. end;
  1278. procedure tcallnode.bind_parasym;
  1279. var
  1280. i : integer;
  1281. pt : tcallparanode;
  1282. oldppt : ^tcallparanode;
  1283. varargspara,
  1284. currpara : tparavarsym;
  1285. used_by_callnode : boolean;
  1286. hiddentree : tnode;
  1287. newstatement : tstatementnode;
  1288. temp : ttempcreatenode;
  1289. begin
  1290. pt:=tcallparanode(left);
  1291. oldppt:=@left;
  1292. { flag all callparanodes that belong to the varargs }
  1293. i:=paralength;
  1294. while (i>procdefinition.maxparacount) do
  1295. begin
  1296. include(pt.callparaflags,cpf_varargs_para);
  1297. oldppt:[email protected];
  1298. pt:=tcallparanode(pt.right);
  1299. dec(i);
  1300. end;
  1301. { skip varargs that are inserted by array of const }
  1302. while assigned(pt) and
  1303. (cpf_varargs_para in pt.callparaflags) do
  1304. pt:=tcallparanode(pt.right);
  1305. { process normal parameters and insert hidden parameters }
  1306. for i:=procdefinition.paras.count-1 downto 0 do
  1307. begin
  1308. currpara:=tparavarsym(procdefinition.paras[i]);
  1309. if vo_is_hidden_para in currpara.varoptions then
  1310. begin
  1311. { generate hidden tree }
  1312. used_by_callnode:=false;
  1313. hiddentree:=nil;
  1314. if (vo_is_funcret in currpara.varoptions) then
  1315. begin
  1316. { Generate funcretnode if not specified }
  1317. if assigned(funcretnode) then
  1318. begin
  1319. hiddentree:=funcretnode.getcopy;
  1320. end
  1321. else
  1322. begin
  1323. hiddentree:=internalstatements(newstatement);
  1324. { need to use resulttype instead of procdefinition.rettype,
  1325. because they can be different }
  1326. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent,false);
  1327. addstatement(newstatement,temp);
  1328. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1329. addstatement(newstatement,ctemprefnode.create(temp));
  1330. end;
  1331. end
  1332. else
  1333. if vo_is_high_para in currpara.varoptions then
  1334. begin
  1335. if not assigned(pt) or
  1336. (i=0) then
  1337. internalerror(200304082);
  1338. { we need the information of the previous parameter }
  1339. hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vartype.def);
  1340. end
  1341. else
  1342. if vo_is_self in currpara.varoptions then
  1343. begin
  1344. if assigned(right) then
  1345. hiddentree:=gen_self_tree_methodpointer
  1346. else
  1347. hiddentree:=gen_self_tree;
  1348. end
  1349. else
  1350. if vo_is_vmt in currpara.varoptions then
  1351. begin
  1352. hiddentree:=gen_vmt_tree;
  1353. end
  1354. {$ifdef powerpc}
  1355. else
  1356. if vo_is_syscall_lib in currpara.varoptions then
  1357. begin
  1358. { lib parameter has no special type but proccalloptions must be a syscall }
  1359. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1360. end
  1361. {$endif powerpc}
  1362. else
  1363. if vo_is_parentfp in currpara.varoptions then
  1364. begin
  1365. if not(assigned(procdefinition.owner.defowner)) then
  1366. internalerror(200309287);
  1367. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1368. end;
  1369. { add the hidden parameter }
  1370. if not assigned(hiddentree) then
  1371. internalerror(200304073);
  1372. { Already insert para and let the previous node point to
  1373. this new node }
  1374. pt:=ccallparanode.create(hiddentree,oldppt^);
  1375. pt.used_by_callnode:=used_by_callnode;
  1376. oldppt^:=pt;
  1377. end;
  1378. if not assigned(pt) then
  1379. internalerror(200310052);
  1380. pt.parasym:=currpara;
  1381. oldppt:[email protected];
  1382. pt:=tcallparanode(pt.right);
  1383. end;
  1384. { Create parasyms for varargs, first count the number of varargs paras,
  1385. then insert the parameters with numbering in reverse order. The SortParas
  1386. will set the correct order at the end}
  1387. pt:=tcallparanode(left);
  1388. i:=0;
  1389. while assigned(pt) do
  1390. begin
  1391. if cpf_varargs_para in pt.callparaflags then
  1392. inc(i);
  1393. pt:=tcallparanode(pt.right);
  1394. end;
  1395. if (i>0) then
  1396. begin
  1397. varargsparas:=tvarargsparalist.create;
  1398. pt:=tcallparanode(left);
  1399. while assigned(pt) do
  1400. begin
  1401. if cpf_varargs_para in pt.callparaflags then
  1402. begin
  1403. varargspara:=tparavarsym.create('va'+tostr(i),i,vs_value,pt.resulttype,[]);
  1404. dec(i);
  1405. { varargspara is left-right, use insert
  1406. instead of concat }
  1407. varargsparas.add(varargspara);
  1408. pt.parasym:=varargspara;
  1409. end;
  1410. pt:=tcallparanode(pt.right);
  1411. end;
  1412. varargsparas.sortparas;
  1413. end;
  1414. end;
  1415. function tcallnode.det_resulttype:tnode;
  1416. var
  1417. candidates : tcallcandidates;
  1418. oldcallnode : tcallnode;
  1419. hpt : tnode;
  1420. pt : tcallparanode;
  1421. lastpara : longint;
  1422. paraidx,
  1423. cand_cnt : integer;
  1424. i : longint;
  1425. is_const : boolean;
  1426. label
  1427. errorexit;
  1428. begin
  1429. result:=nil;
  1430. candidates:=nil;
  1431. oldcallnode:=aktcallnode;
  1432. aktcallnode:=self;
  1433. { determine length of parameter list }
  1434. pt:=tcallparanode(left);
  1435. paralength:=0;
  1436. while assigned(pt) do
  1437. begin
  1438. inc(paralength);
  1439. pt:=tcallparanode(pt.right);
  1440. end;
  1441. { determine the type of the parameters }
  1442. if assigned(left) then
  1443. begin
  1444. tcallparanode(left).get_paratype;
  1445. if codegenerror then
  1446. goto errorexit;
  1447. end;
  1448. if assigned(methodpointer) then
  1449. begin
  1450. resulttypepass(methodpointer);
  1451. maybe_load_para_in_temp(methodpointer);
  1452. end;
  1453. { procedure variable ? }
  1454. if assigned(right) then
  1455. begin
  1456. set_varstate(right,vs_read,[vsf_must_be_valid]);
  1457. resulttypepass(right);
  1458. if codegenerror then
  1459. exit;
  1460. procdefinition:=tabstractprocdef(right.resulttype.def);
  1461. { Compare parameters from right to left }
  1462. paraidx:=procdefinition.Paras.count-1;
  1463. { Skip default parameters }
  1464. if not(po_varargs in procdefinition.procoptions) then
  1465. begin
  1466. { ignore hidden parameters }
  1467. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1468. dec(paraidx);
  1469. for i:=1 to procdefinition.maxparacount-paralength do
  1470. begin
  1471. if paraidx<0 then
  1472. internalerror(200402261);
  1473. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1474. begin
  1475. CGMessage(parser_e_wrong_parameter_size);
  1476. goto errorexit;
  1477. end;
  1478. dec(paraidx);
  1479. end;
  1480. end;
  1481. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1482. dec(paraidx);
  1483. pt:=tcallparanode(left);
  1484. lastpara:=paralength;
  1485. while (paraidx>=0) and assigned(pt) do
  1486. begin
  1487. { only goto next para if we're out of the varargs }
  1488. if not(po_varargs in procdefinition.procoptions) or
  1489. (lastpara<=procdefinition.maxparacount) then
  1490. begin
  1491. repeat
  1492. dec(paraidx);
  1493. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1494. end;
  1495. pt:=tcallparanode(pt.right);
  1496. dec(lastpara);
  1497. end;
  1498. if assigned(pt) or
  1499. ((paraidx>=0) and
  1500. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  1501. begin
  1502. if assigned(pt) then
  1503. aktfilepos:=pt.fileinfo;
  1504. CGMessage(parser_e_wrong_parameter_size);
  1505. goto errorexit;
  1506. end;
  1507. end
  1508. else
  1509. { not a procedure variable }
  1510. begin
  1511. { do we know the procedure to call ? }
  1512. if not(assigned(procdefinition)) then
  1513. begin
  1514. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags),
  1515. { ignore possible private in delphi mode for anon. inherited (FK) }
  1516. (m_delphi in aktmodeswitches) and (cnf_anon_inherited in callnodeflags));
  1517. { no procedures found? then there is something wrong
  1518. with the parameter size or the procedures are
  1519. not accessible }
  1520. if candidates.count=0 then
  1521. begin
  1522. { when it's an auto inherited call and there
  1523. is no procedure found, but the procedures
  1524. were defined with overload directive and at
  1525. least two procedures are defined then we ignore
  1526. this inherited by inserting a nothingn. Only
  1527. do this ugly hack in Delphi mode as it looks more
  1528. like a bug. It's also not documented }
  1529. if (m_delphi in aktmodeswitches) and
  1530. (cnf_anon_inherited in callnodeflags) and
  1531. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1532. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1533. (symtableprocentry.procdef_count>=2) then
  1534. result:=cnothingnode.create
  1535. else
  1536. begin
  1537. { in tp mode we can try to convert to procvar if
  1538. there are no parameters specified }
  1539. if not(assigned(left)) and
  1540. not(cnf_inherited in callnodeflags) and
  1541. ((m_tp_procvar in aktmodeswitches) or
  1542. (m_mac_procvar in aktmodeswitches)) and
  1543. (not assigned(methodpointer) or
  1544. (methodpointer.nodetype <> typen)) then
  1545. begin
  1546. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1547. if assigned(methodpointer) then
  1548. tloadnode(hpt).set_mp(get_load_methodpointer);
  1549. resulttypepass(hpt);
  1550. result:=hpt;
  1551. end
  1552. else
  1553. begin
  1554. if assigned(left) then
  1555. aktfilepos:=left.fileinfo;
  1556. CGMessage(parser_e_wrong_parameter_size);
  1557. symtableprocentry.write_parameter_lists(nil);
  1558. end;
  1559. end;
  1560. goto errorexit;
  1561. end;
  1562. { Retrieve information about the candidates }
  1563. candidates.get_information;
  1564. {$ifdef EXTDEBUG}
  1565. { Display info when multiple candidates are found }
  1566. if candidates.count>1 then
  1567. candidates.dump_info(V_Debug);
  1568. {$endif EXTDEBUG}
  1569. { Choose the best candidate and count the number of
  1570. candidates left }
  1571. cand_cnt:=candidates.choose_best(procdefinition);
  1572. { All parameters are checked, check if there are any
  1573. procedures left }
  1574. if cand_cnt>0 then
  1575. begin
  1576. { Multiple candidates left? }
  1577. if cand_cnt>1 then
  1578. begin
  1579. CGMessage(type_e_cant_choose_overload_function);
  1580. {$ifdef EXTDEBUG}
  1581. candidates.dump_info(V_Hint);
  1582. {$else EXTDEBUG}
  1583. candidates.list(false);
  1584. {$endif EXTDEBUG}
  1585. { we'll just use the first candidate to make the
  1586. call }
  1587. end;
  1588. { assign procdefinition }
  1589. if symtableproc=nil then
  1590. symtableproc:=procdefinition.owner;
  1591. { update browser information }
  1592. if make_ref then
  1593. begin
  1594. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1595. inc(tprocdef(procdefinition).refcount);
  1596. if tprocdef(procdefinition).defref=nil then
  1597. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1598. end;
  1599. end
  1600. else
  1601. begin
  1602. { No candidates left, this must be a type error,
  1603. because wrong size is already checked. procdefinition
  1604. is filled with the first (random) definition that is
  1605. found. We use this definition to display a nice error
  1606. message that the wrong type is passed }
  1607. candidates.find_wrong_para;
  1608. candidates.list(true);
  1609. {$ifdef EXTDEBUG}
  1610. candidates.dump_info(V_Hint);
  1611. {$endif EXTDEBUG}
  1612. { We can not proceed, release all procs and exit }
  1613. candidates.free;
  1614. goto errorexit;
  1615. end;
  1616. candidates.free;
  1617. end; { end of procedure to call determination }
  1618. end;
  1619. { check for hints (deprecated etc) }
  1620. if (procdefinition.deftype = procdef) then
  1621. check_hints(tprocdef(procdefinition).procsym,tprocdef(procdefinition).symoptions);
  1622. { add needed default parameters }
  1623. if assigned(procdefinition) and
  1624. (paralength<procdefinition.maxparacount) then
  1625. begin
  1626. paraidx:=0;
  1627. i:=0;
  1628. while (i<paralength) do
  1629. begin
  1630. if paraidx>=procdefinition.Paras.count then
  1631. internalerror(200306181);
  1632. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  1633. inc(i);
  1634. inc(paraidx);
  1635. end;
  1636. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1637. inc(paraidx);
  1638. while (paraidx<procdefinition.paras.count) do
  1639. begin
  1640. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1641. internalerror(200212142);
  1642. left:=ccallparanode.create(genconstsymtree(
  1643. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  1644. { Ignore vs_hidden parameters }
  1645. repeat
  1646. inc(paraidx);
  1647. until (paraidx>=procdefinition.paras.count) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1648. end;
  1649. end;
  1650. { handle predefined procedures }
  1651. is_const:=(po_internconst in procdefinition.procoptions) and
  1652. ((block_type in [bt_const,bt_type]) or
  1653. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1654. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1655. begin
  1656. if assigned(left) then
  1657. begin
  1658. { ptr and settextbuf needs two args }
  1659. if assigned(tcallparanode(left).right) then
  1660. begin
  1661. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1662. left:=nil;
  1663. end
  1664. else
  1665. begin
  1666. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1667. tcallparanode(left).left:=nil;
  1668. end;
  1669. end
  1670. else
  1671. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1672. result:=hpt;
  1673. goto errorexit;
  1674. end;
  1675. { ensure that the result type is set }
  1676. if not(cnf_restypeset in callnodeflags) then
  1677. begin
  1678. { constructors return their current class type, not the type where the
  1679. constructor is declared, this can be different because of inheritance }
  1680. if (procdefinition.proctypeoption=potype_constructor) and
  1681. assigned(methodpointer) and
  1682. assigned(methodpointer.resulttype.def) and
  1683. (methodpointer.resulttype.def.deftype=classrefdef) then
  1684. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1685. else
  1686. { Member call to a (inherited) constructor from the class, the return
  1687. value is always self, so we change it to voidtype to generate an
  1688. error and to prevent users from generating non-working code
  1689. when they expect to clone the current instance, see bug 3662 (PFV) }
  1690. if (procdefinition.proctypeoption=potype_constructor) and
  1691. is_class(tprocdef(procdefinition)._class) and
  1692. assigned(methodpointer) and
  1693. (nf_is_self in methodpointer.flags) then
  1694. resulttype:=voidtype
  1695. else
  1696. resulttype:=procdefinition.rettype;
  1697. end
  1698. else
  1699. resulttype:=restype;
  1700. {if resulttype.def.needs_inittable then
  1701. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1702. if assigned(methodpointer) then
  1703. begin
  1704. { when methodpointer is a callnode we must load it first into a
  1705. temp to prevent the processing callnode twice }
  1706. if (methodpointer.nodetype=calln) then
  1707. internalerror(200405121);
  1708. { direct call to inherited abstract method, then we
  1709. can already give a error in the compiler instead
  1710. of a runtime error }
  1711. if (cnf_inherited in callnodeflags) and
  1712. (po_abstractmethod in procdefinition.procoptions) then
  1713. CGMessage(cg_e_cant_call_abstract_method);
  1714. { if an inherited con- or destructor should be }
  1715. { called in a con- or destructor then a warning }
  1716. { will be made }
  1717. { con- and destructors need a pointer to the vmt }
  1718. if (cnf_inherited in callnodeflags) and
  1719. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1720. is_object(methodpointer.resulttype.def) and
  1721. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1722. CGMessage(cg_w_member_cd_call_from_method);
  1723. if methodpointer.nodetype<>typen then
  1724. begin
  1725. { Remove all postfix operators }
  1726. hpt:=methodpointer;
  1727. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1728. hpt:=tunarynode(hpt).left;
  1729. if (procdefinition.proctypeoption=potype_constructor) and
  1730. assigned(symtableproc) and
  1731. (symtableproc.symtabletype=withsymtable) and
  1732. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1733. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1734. { R.Init then R will be initialized by the constructor,
  1735. Also allow it for simple loads }
  1736. if (procdefinition.proctypeoption=potype_constructor) or
  1737. ((hpt.nodetype=loadn) and
  1738. (
  1739. (methodpointer.resulttype.def.deftype=classrefdef) or
  1740. (
  1741. (methodpointer.resulttype.def.deftype=objectdef) and
  1742. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1743. )
  1744. )
  1745. ) then
  1746. set_varstate(methodpointer,vs_read,[])
  1747. else
  1748. set_varstate(methodpointer,vs_read,[vsf_must_be_valid]);
  1749. { The object is already used if it is called once }
  1750. if (hpt.nodetype=loadn) and
  1751. (tloadnode(hpt).symtableentry.typ in [localvarsym,paravarsym,globalvarsym]) then
  1752. set_varstate(hpt,vs_read,[]);
  1753. // tabstractvarsym(tloadnode(hpt).symtableentry).varstate:=vs_readwritten;
  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.