ncal.pas 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This file implements the node for sub procedure calling.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,cpuinfo,
  24. node,nbas,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symppu,symsym,symdef,symtable;
  29. type
  30. pcandidate = ^tcandidate;
  31. tcandidate = record
  32. next : pcandidate;
  33. data : tprocdef;
  34. wrongpara,
  35. firstpara : tparaitem;
  36. exact_count,
  37. equal_count,
  38. cl1_count,
  39. cl2_count,
  40. cl3_count,
  41. coper_count : integer; { should be signed }
  42. ordinal_distance : bestreal;
  43. invalid : boolean;
  44. wrongparanr : byte;
  45. end;
  46. tcallnode = class(tbinarynode)
  47. private
  48. paravisible : boolean;
  49. paralength : smallint;
  50. function candidates_find:pcandidate;
  51. procedure candidates_free(procs:pcandidate);
  52. procedure candidates_list(procs:pcandidate;all:boolean);
  53. procedure candidates_get_information(procs:pcandidate);
  54. function candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  55. procedure candidates_find_wrong_para(procs:pcandidate);
  56. {$ifdef EXTDEBUG}
  57. procedure candidates_dump_info(lvl:longint;procs:pcandidate);
  58. {$endif EXTDEBUG}
  59. function gen_self_tree_methodpointer:tnode;
  60. function gen_self_tree:tnode;
  61. function gen_vmt_tree:tnode;
  62. procedure bind_paraitem;
  63. { function return node, this is used to pass the data for a
  64. ret_in_param return value }
  65. _funcretnode : tnode;
  66. procedure setfuncretnode(const returnnode: tnode);
  67. procedure convert_carg_array_of_const;
  68. public
  69. { the symbol containing the definition of the procedure }
  70. { to call }
  71. symtableprocentry : tprocsym;
  72. symtableprocentryderef : tderef;
  73. { symtable where the entry was found, needed for with support }
  74. symtableproc : tsymtable;
  75. { the definition of the procedure to call }
  76. procdefinition : tabstractprocdef;
  77. procdefinitionderef : tderef;
  78. { tree that contains the pointer to the object for this method }
  79. methodpointer : tnode;
  80. { inline function body }
  81. inlinecode : tnode;
  82. { varargs tparaitems }
  83. varargsparas : tlinkedlist;
  84. { node that specifies where the result should be put for calls }
  85. { that return their result in a parameter }
  86. property funcretnode: tnode read _funcretnode write setfuncretnode;
  87. { separately specified resulttype for some compilerprocs (e.g. }
  88. { you can't have a function with an "array of char" resulttype }
  89. { the RTL) (JM) }
  90. restype: ttype;
  91. restypeset: boolean;
  92. { only the processor specific nodes need to override this }
  93. { constructor }
  94. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  95. constructor create_def(l:tnode;def:tprocdef;mp:tnode);virtual;
  96. constructor create_procvar(l,r:tnode);
  97. constructor createintern(const name: string; params: tnode);
  98. constructor createinternres(const name: string; params: tnode; const res: ttype);
  99. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  100. destructor destroy;override;
  101. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  102. procedure ppuwrite(ppufile:tcompilerppufile);override;
  103. procedure buildderefimpl;override;
  104. procedure derefimpl;override;
  105. function getcopy : tnode;override;
  106. { Goes through all symbols in a class and subclasses and calls
  107. verify abstract for each .
  108. }
  109. procedure verifyabstractcalls;
  110. { called for each definition in a class and verifies if a method
  111. is abstract or not, if it is abstract, give out a warning
  112. }
  113. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  114. procedure insertintolist(l : tnodelist);override;
  115. function pass_1 : tnode;override;
  116. function det_resulttype:tnode;override;
  117. {$ifdef state_tracking}
  118. function track_state_pass(exec_known:boolean):boolean;override;
  119. {$endif state_tracking}
  120. function docompare(p: tnode): boolean; override;
  121. procedure printnodedata(var t:text);override;
  122. function para_count:longint;
  123. private
  124. AbstractMethodsList : TStringList;
  125. end;
  126. tcallnodeclass = class of tcallnode;
  127. tcallparaflags = (
  128. { flags used by tcallparanode }
  129. cpf_is_colon_para
  130. );
  131. tcallparanode = class(tbinarynode)
  132. public
  133. callparaflags : set of tcallparaflags;
  134. paraitem : tparaitem;
  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,paramgr,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. function gen_high_tree(p:tnode;openstring:boolean):tnode;
  195. var
  196. temp: tnode;
  197. len : integer;
  198. loadconst : boolean;
  199. hightree : tnode;
  200. begin
  201. len:=-1;
  202. loadconst:=true;
  203. hightree:=nil;
  204. case p.resulttype.def.deftype of
  205. arraydef :
  206. begin
  207. { handle via a normal inline in_high_x node }
  208. loadconst := false;
  209. hightree := geninlinenode(in_high_x,false,p.getcopy);
  210. { only substract low(array) if it's <> 0 }
  211. temp := geninlinenode(in_low_x,false,p.getcopy);
  212. resulttypepass(temp);
  213. if (temp.nodetype <> ordconstn) or
  214. (tordconstnode(temp).value <> 0) then
  215. hightree := caddnode.create(subn,hightree,temp)
  216. else
  217. temp.free;
  218. end;
  219. stringdef :
  220. begin
  221. if openstring then
  222. begin
  223. { handle via a normal inline in_high_x node }
  224. loadconst := false;
  225. hightree := geninlinenode(in_high_x,false,p.getcopy);
  226. end
  227. else
  228. begin
  229. { passing a string to an array of char }
  230. if (p.nodetype=stringconstn) then
  231. begin
  232. len:=str_length(p);
  233. if len>0 then
  234. dec(len);
  235. end
  236. else
  237. begin
  238. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  239. cordconstnode.create(1,s32bittype,false));
  240. loadconst:=false;
  241. end;
  242. end;
  243. end;
  244. else
  245. len:=0;
  246. end;
  247. if loadconst then
  248. hightree:=cordconstnode.create(len,s32bittype,true)
  249. else
  250. begin
  251. if not assigned(hightree) then
  252. internalerror(200304071);
  253. hightree:=ctypeconvnode.create(hightree,s32bittype);
  254. end;
  255. result:=hightree;
  256. end;
  257. function is_better_candidate(currpd,bestpd:pcandidate):integer;
  258. var
  259. res : integer;
  260. begin
  261. {
  262. Return values:
  263. > 0 when currpd is better than bestpd
  264. < 0 when bestpd is better than currpd
  265. = 0 when both are equal
  266. To choose the best candidate we use the following order:
  267. - Incompatible flag
  268. - (Smaller) Number of convert operator parameters.
  269. - (Smaller) Number of convertlevel 2 parameters.
  270. - (Smaller) Number of convertlevel 1 parameters.
  271. - (Bigger) Number of exact parameters.
  272. - (Smaller) Number of equal parameters.
  273. - (Smaller) Total of ordinal distance. For example, the distance of a word
  274. to a byte is 65535-255=65280.
  275. }
  276. if bestpd^.invalid then
  277. begin
  278. if currpd^.invalid then
  279. res:=0
  280. else
  281. res:=1;
  282. end
  283. else
  284. if currpd^.invalid then
  285. res:=-1
  286. else
  287. begin
  288. { less operator parameters? }
  289. res:=(bestpd^.coper_count-currpd^.coper_count);
  290. if (res=0) then
  291. begin
  292. { less cl3 parameters? }
  293. res:=(bestpd^.cl3_count-currpd^.cl3_count);
  294. if (res=0) then
  295. begin
  296. { less cl2 parameters? }
  297. res:=(bestpd^.cl2_count-currpd^.cl2_count);
  298. if (res=0) then
  299. begin
  300. { less cl1 parameters? }
  301. res:=(bestpd^.cl1_count-currpd^.cl1_count);
  302. if (res=0) then
  303. begin
  304. { more exact parameters? }
  305. res:=(currpd^.exact_count-bestpd^.exact_count);
  306. if (res=0) then
  307. begin
  308. { less equal parameters? }
  309. res:=(bestpd^.equal_count-currpd^.equal_count);
  310. if (res=0) then
  311. begin
  312. { smaller ordinal distance? }
  313. if (currpd^.ordinal_distance<bestpd^.ordinal_distance) then
  314. res:=1
  315. else
  316. if (currpd^.ordinal_distance>bestpd^.ordinal_distance) then
  317. res:=-1
  318. else
  319. res:=0;
  320. end;
  321. end;
  322. end;
  323. end;
  324. end;
  325. end;
  326. end;
  327. is_better_candidate:=res;
  328. end;
  329. procedure var_para_allowed(var eq:tequaltype;def_from,def_to:Tdef);
  330. begin
  331. { Note: eq must be already valid, it will only be updated! }
  332. case def_to.deftype of
  333. formaldef :
  334. begin
  335. { all types can be passed to a formaldef }
  336. eq:=te_equal;
  337. end;
  338. orddef :
  339. begin
  340. { allows conversion from word to integer and
  341. byte to shortint, but only for TP7 compatibility }
  342. if (m_tp7 in aktmodeswitches) and
  343. (def_from.deftype=orddef) and
  344. (def_from.size=def_to.size) then
  345. eq:=te_convert_l1;
  346. end;
  347. pointerdef :
  348. begin
  349. { an implicit pointer conversion is allowed }
  350. if (def_from.deftype=pointerdef) then
  351. eq:=te_convert_l1;
  352. end;
  353. stringdef :
  354. begin
  355. { all shortstrings are allowed, size is not important }
  356. if is_shortstring(def_from) and
  357. is_shortstring(def_to) then
  358. eq:=te_equal;
  359. end;
  360. objectdef :
  361. begin
  362. { child objects can be also passed }
  363. { in non-delphi mode, otherwise }
  364. { they must match exactly, except }
  365. { if they are objects }
  366. if (def_from.deftype=objectdef) and
  367. (
  368. not(m_delphi in aktmodeswitches) or
  369. (
  370. (tobjectdef(def_from).objecttype=odt_object) and
  371. (tobjectdef(def_to).objecttype=odt_object)
  372. )
  373. ) and
  374. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  375. eq:=te_convert_l1;
  376. end;
  377. filedef :
  378. begin
  379. { an implicit file conversion is also allowed }
  380. { from a typed file to an untyped one }
  381. if (def_from.deftype=filedef) and
  382. (tfiledef(def_from).filetyp = ft_typed) and
  383. (tfiledef(def_to).filetyp = ft_untyped) then
  384. eq:=te_convert_l1;
  385. end;
  386. end;
  387. end;
  388. procedure para_allowed(var eq:tequaltype;p:tcallparanode;def_to:tdef);
  389. begin
  390. { Note: eq must be already valid, it will only be updated! }
  391. case def_to.deftype of
  392. formaldef :
  393. begin
  394. { all types can be passed to a formaldef }
  395. eq:=te_equal;
  396. end;
  397. stringdef :
  398. begin
  399. { to support ansi/long/wide strings in a proper way }
  400. { string and string[10] are assumed as equal }
  401. { when searching the correct overloaded procedure }
  402. if (p.resulttype.def.deftype=stringdef) and
  403. (tstringdef(def_to).string_typ=tstringdef(p.resulttype.def).string_typ) then
  404. eq:=te_equal
  405. else
  406. { Passing a constant char to ansistring or shortstring or
  407. a widechar to widestring then handle it as equal. }
  408. if (p.left.nodetype=ordconstn) and
  409. (
  410. is_char(p.resulttype.def) and
  411. (is_shortstring(def_to) or is_ansistring(def_to))
  412. ) or
  413. (
  414. is_widechar(p.resulttype.def) and
  415. is_widestring(def_to)
  416. ) then
  417. eq:=te_equal
  418. end;
  419. setdef :
  420. begin
  421. { set can also be a not yet converted array constructor }
  422. if (p.resulttype.def.deftype=arraydef) and
  423. (tarraydef(p.resulttype.def).IsConstructor) and
  424. not(tarraydef(p.resulttype.def).IsVariant) then
  425. eq:=te_equal;
  426. end;
  427. procvardef :
  428. begin
  429. { in tp7 mode proc -> procvar is allowed }
  430. if (m_tp_procvar in aktmodeswitches) and
  431. (p.left.nodetype=calln) and
  432. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def_to),true)>=te_equal) then
  433. eq:=te_equal;
  434. end;
  435. end;
  436. end;
  437. {****************************************************************************
  438. TOBJECTINFOITEM
  439. ****************************************************************************}
  440. constructor tobjectinfoitem.create(def : tobjectdef);
  441. begin
  442. inherited create;
  443. objinfo := def;
  444. end;
  445. {****************************************************************************
  446. TCALLPARANODE
  447. ****************************************************************************}
  448. constructor tcallparanode.create(expr,next : tnode);
  449. begin
  450. inherited create(callparan,expr,next);
  451. if not assigned(expr) then
  452. internalerror(200305091);
  453. expr.set_file_line(self);
  454. callparaflags:=[];
  455. end;
  456. destructor tcallparanode.destroy;
  457. begin
  458. { When the node is used by callnode then
  459. we don't destroy left, the callnode takes care of it }
  460. if used_by_callnode then
  461. left:=nil;
  462. inherited destroy;
  463. end;
  464. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  465. begin
  466. inherited ppuload(t,ppufile);
  467. ppufile.getsmallset(callparaflags);
  468. end;
  469. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  470. begin
  471. inherited ppuwrite(ppufile);
  472. ppufile.putsmallset(callparaflags);
  473. end;
  474. function tcallparanode.getcopy : tnode;
  475. var
  476. n : tcallparanode;
  477. begin
  478. n:=tcallparanode(inherited getcopy);
  479. n.callparaflags:=callparaflags;
  480. n.paraitem:=paraitem;
  481. result:=n;
  482. end;
  483. procedure tcallparanode.insertintolist(l : tnodelist);
  484. begin
  485. end;
  486. procedure tcallparanode.get_paratype;
  487. var
  488. old_array_constructor : boolean;
  489. begin
  490. inc(parsing_para_level);
  491. if assigned(right) then
  492. tcallparanode(right).get_paratype;
  493. old_array_constructor:=allow_array_constructor;
  494. allow_array_constructor:=true;
  495. resulttypepass(left);
  496. allow_array_constructor:=old_array_constructor;
  497. if codegenerror then
  498. resulttype:=generrortype
  499. else
  500. resulttype:=left.resulttype;
  501. dec(parsing_para_level);
  502. end;
  503. procedure tcallparanode.insert_typeconv(do_count : boolean);
  504. var
  505. oldtype : ttype;
  506. {$ifdef extdebug}
  507. store_count_ref : boolean;
  508. {$endif def extdebug}
  509. begin
  510. inc(parsing_para_level);
  511. {$ifdef extdebug}
  512. if do_count then
  513. begin
  514. store_count_ref:=count_ref;
  515. count_ref:=true;
  516. end;
  517. {$endif def extdebug}
  518. { Be sure to have the resulttype }
  519. if not assigned(left.resulttype.def) then
  520. resulttypepass(left);
  521. if (left.nodetype<>nothingn) then
  522. begin
  523. { Handle varargs and hidden paras directly, no typeconvs or }
  524. { typechecking needed }
  525. if (nf_varargs_para in flags) then
  526. begin
  527. { convert pascal to C types }
  528. case left.resulttype.def.deftype of
  529. stringdef :
  530. inserttypeconv(left,charpointertype);
  531. floatdef :
  532. inserttypeconv(left,s64floattype);
  533. end;
  534. set_varstate(left,vs_used,true);
  535. resulttype:=left.resulttype;
  536. end
  537. else
  538. if (paraitem.is_hidden) then
  539. begin
  540. set_varstate(left,vs_used,true);
  541. resulttype:=left.resulttype;
  542. end
  543. else
  544. begin
  545. { Do we need arrayconstructor -> set conversion, then insert
  546. it here before the arrayconstructor node breaks the tree
  547. with its conversions of enum->ord }
  548. if (left.nodetype=arrayconstructorn) and
  549. (paraitem.paratype.def.deftype=setdef) then
  550. inserttypeconv(left,paraitem.paratype);
  551. { set some settings needed for arrayconstructor }
  552. if is_array_constructor(left.resulttype.def) then
  553. begin
  554. if is_array_of_const(paraitem.paratype.def) then
  555. begin
  556. { force variant array }
  557. include(left.flags,nf_forcevaria);
  558. end
  559. else
  560. begin
  561. include(left.flags,nf_novariaallowed);
  562. { now that the resultting type is know we can insert the required
  563. typeconvs for the array constructor }
  564. tarrayconstructornode(left).force_type(tarraydef(paraitem.paratype.def).elementtype);
  565. end;
  566. end;
  567. { check if local proc/func is assigned to procvar }
  568. if left.resulttype.def.deftype=procvardef then
  569. test_local_to_procvar(tprocvardef(left.resulttype.def),paraitem.paratype.def);
  570. { test conversions }
  571. if not(is_shortstring(left.resulttype.def) and
  572. is_shortstring(paraitem.paratype.def)) and
  573. (paraitem.paratype.def.deftype<>formaldef) then
  574. begin
  575. { Process open parameters }
  576. if paramanager.push_high_param(paraitem.paratyp,paraitem.paratype.def,aktcallnode.procdefinition.proccalloption) then
  577. begin
  578. { insert type conv but hold the ranges of the array }
  579. oldtype:=left.resulttype;
  580. inserttypeconv(left,paraitem.paratype);
  581. left.resulttype:=oldtype;
  582. end
  583. else
  584. begin
  585. { for ordinals, floats and enums, verify if we might cause
  586. some range-check errors. }
  587. if (paraitem.paratype.def.deftype in [enumdef,orddef,floatdef]) and
  588. (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) and
  589. (left.nodetype in [vecn,loadn,calln]) then
  590. begin
  591. if (left.resulttype.def.size>paraitem.paratype.def.size) then
  592. begin
  593. if (cs_check_range in aktlocalswitches) then
  594. Message(type_w_smaller_possible_range_check)
  595. else
  596. Message(type_h_smaller_possible_range_check);
  597. end;
  598. end;
  599. inserttypeconv(left,paraitem.paratype);
  600. end;
  601. if codegenerror then
  602. begin
  603. dec(parsing_para_level);
  604. exit;
  605. end;
  606. end;
  607. { check var strings }
  608. if (cs_strict_var_strings in aktlocalswitches) and
  609. is_shortstring(left.resulttype.def) and
  610. is_shortstring(paraitem.paratype.def) and
  611. (paraitem.paratyp in [vs_out,vs_var]) and
  612. not(is_open_string(paraitem.paratype.def)) and
  613. not(equal_defs(left.resulttype.def,paraitem.paratype.def)) then
  614. begin
  615. aktfilepos:=left.fileinfo;
  616. CGMessage(type_e_strict_var_string_violation);
  617. end;
  618. { Handle formal parameters separate }
  619. if (paraitem.paratype.def.deftype=formaldef) then
  620. begin
  621. { load procvar if a procedure is passed }
  622. if (m_tp_procvar in aktmodeswitches) and
  623. (left.nodetype=calln) and
  624. (is_void(left.resulttype.def)) then
  625. load_procvar_from_calln(left);
  626. case paraitem.paratyp of
  627. vs_var,
  628. vs_out :
  629. begin
  630. if not valid_for_formal_var(left) then
  631. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  632. end;
  633. vs_const :
  634. begin
  635. if not valid_for_formal_const(left) then
  636. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  637. end;
  638. end;
  639. end
  640. else
  641. begin
  642. { check if the argument is allowed }
  643. if (paraitem.paratyp in [vs_out,vs_var]) then
  644. valid_for_var(left);
  645. end;
  646. if paraitem.paratyp in [vs_var,vs_const] then
  647. begin
  648. { Causes problems with const ansistrings if also }
  649. { done for vs_const (JM) }
  650. if paraitem.paratyp = vs_var then
  651. set_unique(left);
  652. make_not_regable(left);
  653. end;
  654. { ansistrings out paramaters doesn't need to be }
  655. { unique, they are finalized }
  656. if paraitem.paratyp=vs_out then
  657. make_not_regable(left);
  658. if do_count then
  659. begin
  660. if paraitem.paratyp in [vs_var,vs_out] then
  661. set_varstate(left,vs_used,false)
  662. else
  663. set_varstate(left,vs_used,true);
  664. end;
  665. { must only be done after typeconv PM }
  666. resulttype:=paraitem.paratype;
  667. end;
  668. end;
  669. { process next node }
  670. if assigned(right) then
  671. tcallparanode(right).insert_typeconv(do_count);
  672. dec(parsing_para_level);
  673. {$ifdef extdebug}
  674. if do_count then
  675. count_ref:=store_count_ref;
  676. {$endif def extdebug}
  677. end;
  678. procedure tcallparanode.det_registers;
  679. begin
  680. if assigned(right) then
  681. begin
  682. tcallparanode(right).det_registers;
  683. registers32:=right.registers32;
  684. registersfpu:=right.registersfpu;
  685. {$ifdef SUPPORT_MMX}
  686. registersmmx:=right.registersmmx;
  687. {$endif}
  688. end;
  689. firstpass(left);
  690. if left.registers32>registers32 then
  691. registers32:=left.registers32;
  692. if left.registersfpu>registersfpu then
  693. registersfpu:=left.registersfpu;
  694. {$ifdef SUPPORT_MMX}
  695. if left.registersmmx>registersmmx then
  696. registersmmx:=left.registersmmx;
  697. {$endif SUPPORT_MMX}
  698. end;
  699. procedure tcallparanode.firstcallparan;
  700. begin
  701. if not assigned(left.resulttype.def) then
  702. get_paratype;
  703. det_registers;
  704. end;
  705. function tcallparanode.docompare(p: tnode): boolean;
  706. begin
  707. docompare :=
  708. inherited docompare(p) and
  709. (callparaflags = tcallparanode(p).callparaflags)
  710. ;
  711. end;
  712. procedure tcallparanode.printnodetree(var t:text);
  713. begin
  714. printnodelist(t);
  715. end;
  716. {****************************************************************************
  717. TCALLNODE
  718. ****************************************************************************}
  719. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp : tnode);
  720. begin
  721. inherited create(calln,l,nil);
  722. symtableprocentry:=v;
  723. symtableproc:=st;
  724. include(flags,nf_return_value_used);
  725. methodpointer:=mp;
  726. procdefinition:=nil;
  727. restypeset:=false;
  728. _funcretnode:=nil;
  729. inlinecode:=nil;
  730. paralength:=-1;
  731. varargsparas:=nil;
  732. end;
  733. constructor tcallnode.create_def(l:tnode;def:tprocdef;mp:tnode);
  734. begin
  735. inherited create(calln,l,nil);
  736. symtableprocentry:=nil;
  737. symtableproc:=nil;
  738. include(flags,nf_return_value_used);
  739. methodpointer:=mp;
  740. procdefinition:=def;
  741. restypeset:=false;
  742. _funcretnode:=nil;
  743. inlinecode:=nil;
  744. paralength:=-1;
  745. varargsparas:=nil;
  746. end;
  747. constructor tcallnode.create_procvar(l,r:tnode);
  748. begin
  749. inherited create(calln,l,r);
  750. symtableprocentry:=nil;
  751. symtableproc:=nil;
  752. include(flags,nf_return_value_used);
  753. methodpointer:=nil;
  754. procdefinition:=nil;
  755. restypeset:=false;
  756. _funcretnode:=nil;
  757. inlinecode:=nil;
  758. paralength:=-1;
  759. varargsparas:=nil;
  760. end;
  761. constructor tcallnode.createintern(const name: string; params: tnode);
  762. var
  763. srsym: tsym;
  764. symowner: tsymtable;
  765. begin
  766. if not (cs_compilesystem in aktmoduleswitches) then
  767. begin
  768. srsym := searchsymonlyin(systemunit,name);
  769. symowner := systemunit;
  770. end
  771. else
  772. begin
  773. searchsym(name,srsym,symowner);
  774. if not assigned(srsym) then
  775. searchsym(upper(name),srsym,symowner);
  776. end;
  777. if not assigned(srsym) or
  778. (srsym.typ <> procsym) then
  779. begin
  780. {$ifdef EXTDEBUG}
  781. Comment(V_Error,'unknown compilerproc '+name);
  782. {$endif EXTDEBUG}
  783. internalerror(200107271);
  784. end;
  785. self.create(params,tprocsym(srsym),symowner,nil);
  786. end;
  787. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  788. begin
  789. self.createintern(name,params);
  790. restype := res;
  791. restypeset := true;
  792. { both the normal and specified resulttype either have to be returned via a }
  793. { parameter or not, but no mixing (JM) }
  794. if paramanager.ret_in_param(restype.def,pocall_compilerproc) xor
  795. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  796. internalerror(200108291);
  797. end;
  798. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  799. begin
  800. self.createintern(name,params);
  801. _funcretnode:=returnnode;
  802. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  803. internalerror(200204247);
  804. end;
  805. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  806. var
  807. para: tcallparanode;
  808. begin
  809. if assigned(_funcretnode) then
  810. _funcretnode.free;
  811. _funcretnode := returnnode;
  812. { if the resulttype pass hasn't occurred yet, that one will do }
  813. { everything }
  814. if assigned(resulttype.def) then
  815. begin
  816. { these are returned as values, but we can optimize their loading }
  817. { as well }
  818. if is_ansistring(resulttype.def) or
  819. is_widestring(resulttype.def) then
  820. exit;
  821. para := tcallparanode(left);
  822. while assigned(para) do
  823. begin
  824. if para.paraitem.is_hidden and
  825. (vo_is_funcret in tvarsym(para.paraitem.parasym).varoptions) then
  826. begin
  827. para.left.free;
  828. para.left := _funcretnode.getcopy;
  829. exit;
  830. end;
  831. para := tcallparanode(para.right);
  832. end;
  833. { no hidden resultpara found, error! }
  834. internalerror(200306087);
  835. end;
  836. end;
  837. destructor tcallnode.destroy;
  838. begin
  839. methodpointer.free;
  840. _funcretnode.free;
  841. inlinecode.free;
  842. if assigned(varargsparas) then
  843. varargsparas.free;
  844. inherited destroy;
  845. end;
  846. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  847. begin
  848. inherited ppuload(t,ppufile);
  849. ppufile.getderef(symtableprocentryderef);
  850. {$ifdef fpc}
  851. {$warning FIXME: No withsymtable support}
  852. {$endif}
  853. symtableproc:=nil;
  854. ppufile.getderef(procdefinitionderef);
  855. restypeset:=boolean(ppufile.getbyte);
  856. methodpointer:=ppuloadnode(ppufile);
  857. _funcretnode:=ppuloadnode(ppufile);
  858. inlinecode:=ppuloadnode(ppufile);
  859. end;
  860. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  861. begin
  862. inherited ppuwrite(ppufile);
  863. ppufile.putderef(symtableprocentryderef);
  864. ppufile.putderef(procdefinitionderef);
  865. ppufile.putbyte(byte(restypeset));
  866. ppuwritenode(ppufile,methodpointer);
  867. ppuwritenode(ppufile,_funcretnode);
  868. ppuwritenode(ppufile,inlinecode);
  869. end;
  870. procedure tcallnode.buildderefimpl;
  871. begin
  872. inherited buildderefimpl;
  873. symtableprocentryderef.build(symtableprocentry);
  874. procdefinitionderef.build(procdefinition);
  875. if assigned(methodpointer) then
  876. methodpointer.buildderefimpl;
  877. if assigned(_funcretnode) then
  878. _funcretnode.buildderefimpl;
  879. if assigned(inlinecode) then
  880. inlinecode.buildderefimpl;
  881. end;
  882. procedure tcallnode.derefimpl;
  883. begin
  884. inherited derefimpl;
  885. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  886. symtableproc:=symtableprocentry.owner;
  887. procdefinition:=tprocdef(procdefinitionderef.resolve);
  888. if assigned(methodpointer) then
  889. methodpointer.derefimpl;
  890. if assigned(_funcretnode) then
  891. _funcretnode.derefimpl;
  892. if assigned(inlinecode) then
  893. inlinecode.derefimpl;
  894. end;
  895. function tcallnode.getcopy : tnode;
  896. var
  897. n : tcallnode;
  898. hp : tparaitem;
  899. begin
  900. n:=tcallnode(inherited getcopy);
  901. n.symtableprocentry:=symtableprocentry;
  902. n.symtableproc:=symtableproc;
  903. n.procdefinition:=procdefinition;
  904. n.restype := restype;
  905. n.restypeset := restypeset;
  906. if assigned(methodpointer) then
  907. n.methodpointer:=methodpointer.getcopy
  908. else
  909. n.methodpointer:=nil;
  910. if assigned(_funcretnode) then
  911. n._funcretnode:=_funcretnode.getcopy
  912. else
  913. n._funcretnode:=nil;
  914. if assigned(inlinecode) then
  915. n.inlinecode:=inlinecode.getcopy
  916. else
  917. n.inlinecode:=nil;
  918. if assigned(varargsparas) then
  919. begin
  920. n.varargsparas:=tlinkedlist.create;
  921. hp:=tparaitem(varargsparas.first);
  922. while assigned(hp) do
  923. begin
  924. n.varargsparas.concat(hp.getcopy);
  925. hp:=tparaitem(hp.next);
  926. end;
  927. end
  928. else
  929. n.varargsparas:=nil;
  930. result:=n;
  931. end;
  932. procedure tcallnode.insertintolist(l : tnodelist);
  933. begin
  934. end;
  935. procedure tcallnode.convert_carg_array_of_const;
  936. var
  937. hp : tarrayconstructornode;
  938. oldleft : tcallparanode;
  939. begin
  940. oldleft:=tcallparanode(left);
  941. { Get arrayconstructor node and insert typeconvs }
  942. hp:=tarrayconstructornode(oldleft.left);
  943. hp.insert_typeconvs;
  944. { Add c args parameters }
  945. { It could be an empty set }
  946. if assigned(hp) and
  947. assigned(hp.left) then
  948. begin
  949. while assigned(hp) do
  950. begin
  951. left:=ccallparanode.create(hp.left,left);
  952. { set callparanode resulttype and flags }
  953. left.resulttype:=hp.left.resulttype;
  954. include(left.flags,nf_varargs_para);
  955. hp.left:=nil;
  956. hp:=tarrayconstructornode(hp.right);
  957. end;
  958. end;
  959. { Remove value of old array of const parameter, but keep it
  960. in the list because it is required for bind_paraitem.
  961. Generate a nothign to keep callparanoed.left valid }
  962. oldleft.left.free;
  963. oldleft.left:=cnothingnode.create;
  964. end;
  965. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  966. var
  967. hp : tprocdef;
  968. j: integer;
  969. begin
  970. if (tsym(p).typ=procsym) then
  971. begin
  972. for j:=1 to tprocsym(p).procdef_count do
  973. begin
  974. { index starts at 1 }
  975. hp:=tprocsym(p).procdef[j];
  976. { If this is an abstract method insert into the list }
  977. if (po_abstractmethod in hp.procoptions) then
  978. AbstractMethodsList.Insert(hp.procsym.name)
  979. else
  980. { If this symbol is already in the list, and it is
  981. an overriding method or dynamic, then remove it from the list
  982. }
  983. begin
  984. { symbol was found }
  985. if AbstractMethodsList.Find(hp.procsym.name) <> nil then
  986. begin
  987. if po_overridingmethod in hp.procoptions then
  988. AbstractMethodsList.Remove(hp.procsym.name);
  989. end;
  990. end;
  991. end;
  992. end;
  993. end;
  994. procedure tcallnode.verifyabstractcalls;
  995. var
  996. objectdf : tobjectdef;
  997. parents : tlinkedlist;
  998. objectinfo : tobjectinfoitem;
  999. stritem : tstringlistitem;
  1000. begin
  1001. objectdf := nil;
  1002. { verify if trying to create an instance of a class which contains
  1003. non-implemented abstract methods }
  1004. { first verify this class type, no class than exit }
  1005. { also, this checking can only be done if the constructor is directly
  1006. called, indirect constructor calls cannot be checked.
  1007. }
  1008. if assigned(methodpointer) then
  1009. begin
  1010. if (methodpointer.resulttype.def.deftype = objectdef) then
  1011. objectdf:=tobjectdef(methodpointer.resulttype.def)
  1012. else
  1013. if (methodpointer.resulttype.def.deftype = classrefdef) and
  1014. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  1015. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  1016. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  1017. end;
  1018. if not assigned(objectdf) then
  1019. exit;
  1020. parents := tlinkedlist.create;
  1021. AbstractMethodsList := tstringlist.create;
  1022. { insert all parents in this class : the first item in the
  1023. list will be the base parent of the class .
  1024. }
  1025. while assigned(objectdf) do
  1026. begin
  1027. objectinfo:=tobjectinfoitem.create(objectdf);
  1028. parents.insert(objectinfo);
  1029. objectdf := objectdf.childof;
  1030. end;
  1031. { now all parents are in the correct order
  1032. insert all abstract methods in the list, and remove
  1033. those which are overriden by parent classes.
  1034. }
  1035. objectinfo:=tobjectinfoitem(parents.first);
  1036. while assigned(objectinfo) do
  1037. begin
  1038. objectdf := objectinfo.objinfo;
  1039. if assigned(objectdf.symtable) then
  1040. objectdf.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}verifyabstract,nil);
  1041. objectinfo:=tobjectinfoitem(objectinfo.next);
  1042. end;
  1043. if assigned(parents) then
  1044. parents.free;
  1045. { Finally give out a warning for each abstract method still in the list }
  1046. stritem := tstringlistitem(AbstractMethodsList.first);
  1047. if assigned(stritem) then
  1048. Message1(type_w_instance_with_abstract,objectdf.objname^);
  1049. while assigned(stritem) do
  1050. begin
  1051. if assigned(stritem.fpstr) then
  1052. Message1(sym_h_param_list,stritem.str);
  1053. stritem := tstringlistitem(stritem.next);
  1054. end;
  1055. if assigned(AbstractMethodsList) then
  1056. AbstractMethodsList.Free;
  1057. end;
  1058. function Tcallnode.candidates_find:pcandidate;
  1059. var
  1060. j : integer;
  1061. pd : tprocdef;
  1062. procs,hp : pcandidate;
  1063. found,
  1064. has_overload_directive : boolean;
  1065. topclassh : tobjectdef;
  1066. srsymtable : tsymtable;
  1067. srprocsym : tprocsym;
  1068. procedure proc_add(pd:tprocdef);
  1069. var
  1070. i : integer;
  1071. begin
  1072. { generate new candidate entry }
  1073. new(hp);
  1074. fillchar(hp^,sizeof(tcandidate),0);
  1075. hp^.data:=pd;
  1076. hp^.next:=procs;
  1077. procs:=hp;
  1078. { Find last parameter, skip all default parameters
  1079. that are not passed. Ignore this skipping for varargs }
  1080. hp^.firstpara:=tparaitem(pd.Para.last);
  1081. if not(po_varargs in pd.procoptions) then
  1082. begin
  1083. for i:=1 to pd.maxparacount-paralength do
  1084. hp^.firstpara:=tparaitem(hp^.firstPara.previous);
  1085. end;
  1086. end;
  1087. begin
  1088. procs:=nil;
  1089. { when the definition has overload directive set, we search for
  1090. overloaded definitions in the class, this only needs to be done once
  1091. for class entries as the tree keeps always the same }
  1092. if (not symtableprocentry.overloadchecked) and
  1093. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1094. (
  1095. (
  1096. (symtableprocentry.first_procdef.proctypeoption=potype_constructor) and
  1097. is_class(tdef(symtableprocentry.owner.defowner))
  1098. ) or
  1099. (po_overload in symtableprocentry.first_procdef.procoptions)
  1100. ) then
  1101. search_class_overloads(symtableprocentry);
  1102. { when the class passed is defined in this unit we
  1103. need to use the scope of that class. This is a trick
  1104. that can be used to access protected members in other
  1105. units. At least kylix supports it this way (PFV) }
  1106. if assigned(symtableproc) and
  1107. (symtableproc.symtabletype=objectsymtable) and
  1108. (symtableproc.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1109. (symtableproc.defowner.owner.unitid=0) then
  1110. topclassh:=tobjectdef(symtableproc.defowner)
  1111. else
  1112. begin
  1113. if assigned(current_procinfo) then
  1114. topclassh:=current_procinfo.procdef._class
  1115. else
  1116. topclassh:=nil;
  1117. end;
  1118. { link all procedures which have the same # of parameters }
  1119. paravisible:=false;
  1120. for j:=1 to symtableprocentry.procdef_count do
  1121. begin
  1122. pd:=symtableprocentry.procdef[j];
  1123. { Is the procdef visible? This needs to be checked on
  1124. procdef level since a symbol can contain both private and
  1125. public declarations. But the check should not be done
  1126. when the callnode is generated by a property }
  1127. if (nf_isproperty in flags) or
  1128. (pd.owner.symtabletype<>objectsymtable) or
  1129. pd.is_visible_for_object(topclassh) then
  1130. begin
  1131. { we have at least one procedure that is visible }
  1132. paravisible:=true;
  1133. { only when the # of parameter are supported by the
  1134. procedure }
  1135. if (paralength>=pd.minparacount) and
  1136. ((po_varargs in pd.procoptions) or { varargs }
  1137. (paralength<=pd.maxparacount)) then
  1138. proc_add(pd);
  1139. end;
  1140. end;
  1141. { remember if the procedure is declared with the overload directive,
  1142. it's information is still needed also after all procs are removed }
  1143. has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
  1144. { when the definition has overload directive set, we search for
  1145. overloaded definitions in the symtablestack. The found
  1146. entries are only added to the procs list and not the procsym, because
  1147. the list can change in every situation }
  1148. if has_overload_directive and
  1149. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1150. begin
  1151. srsymtable:=symtableprocentry.owner.next;
  1152. while assigned(srsymtable) do
  1153. begin
  1154. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1155. begin
  1156. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1157. { process only visible procsyms }
  1158. if assigned(srprocsym) and
  1159. (srprocsym.typ=procsym) and
  1160. srprocsym.is_visible_for_object(topclassh) then
  1161. begin
  1162. { if this procedure doesn't have overload we can stop
  1163. searching }
  1164. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1165. break;
  1166. { process all overloaded definitions }
  1167. for j:=1 to srprocsym.procdef_count do
  1168. begin
  1169. pd:=srprocsym.procdef[j];
  1170. { only when the # of parameter are supported by the
  1171. procedure }
  1172. if (paralength>=pd.minparacount) and
  1173. ((po_varargs in pd.procoptions) or { varargs }
  1174. (paralength<=pd.maxparacount)) then
  1175. begin
  1176. found:=false;
  1177. hp:=procs;
  1178. while assigned(hp) do
  1179. begin
  1180. { Only compare visible parameters for the user }
  1181. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,false,true)>=te_equal then
  1182. begin
  1183. found:=true;
  1184. break;
  1185. end;
  1186. hp:=hp^.next;
  1187. end;
  1188. if not found then
  1189. proc_add(pd);
  1190. end;
  1191. end;
  1192. end;
  1193. end;
  1194. srsymtable:=srsymtable.next;
  1195. end;
  1196. end;
  1197. candidates_find:=procs;
  1198. end;
  1199. procedure tcallnode.candidates_free(procs:pcandidate);
  1200. var
  1201. hpnext,
  1202. hp : pcandidate;
  1203. begin
  1204. hp:=procs;
  1205. while assigned(hp) do
  1206. begin
  1207. hpnext:=hp^.next;
  1208. dispose(hp);
  1209. hp:=hpnext;
  1210. end;
  1211. end;
  1212. procedure tcallnode.candidates_list(procs:pcandidate;all:boolean);
  1213. var
  1214. hp : pcandidate;
  1215. begin
  1216. hp:=procs;
  1217. while assigned(hp) do
  1218. begin
  1219. if all or
  1220. (not hp^.invalid) then
  1221. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname(false));
  1222. hp:=hp^.next;
  1223. end;
  1224. end;
  1225. {$ifdef EXTDEBUG}
  1226. procedure Tcallnode.candidates_dump_info(lvl:longint;procs:pcandidate);
  1227. function ParaTreeStr(p:tcallparanode):string;
  1228. begin
  1229. result:='';
  1230. while assigned(p) do
  1231. begin
  1232. if result<>'' then
  1233. result:=result+',';
  1234. result:=result+p.resulttype.def.typename;
  1235. p:=tcallparanode(p.right);
  1236. end;
  1237. end;
  1238. var
  1239. hp : pcandidate;
  1240. currpara : tparaitem;
  1241. begin
  1242. if not CheckVerbosity(lvl) then
  1243. exit;
  1244. Comment(lvl+V_LineInfo,'Overloaded callnode: '+symtableprocentry.name+'('+ParaTreeStr(tcallparanode(left))+')');
  1245. hp:=procs;
  1246. while assigned(hp) do
  1247. begin
  1248. Comment(lvl,' '+hp^.data.fullprocname(false));
  1249. if (hp^.invalid) then
  1250. Comment(lvl,' invalid')
  1251. else
  1252. begin
  1253. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1254. ' eq: '+tostr(hp^.equal_count)+
  1255. ' l1: '+tostr(hp^.cl1_count)+
  1256. ' l2: '+tostr(hp^.cl2_count)+
  1257. ' l3: '+tostr(hp^.cl3_count)+
  1258. ' oper: '+tostr(hp^.coper_count)+
  1259. ' ord: '+realtostr(hp^.exact_count));
  1260. { Print parameters in left-right order }
  1261. currpara:=hp^.firstpara;
  1262. if assigned(currpara) then
  1263. begin
  1264. while assigned(currpara.next) do
  1265. currpara:=tparaitem(currpara.next);
  1266. end;
  1267. while assigned(currpara) do
  1268. begin
  1269. if (not currpara.is_hidden) then
  1270. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1271. currpara:=tparaitem(currpara.previous);
  1272. end;
  1273. end;
  1274. hp:=hp^.next;
  1275. end;
  1276. end;
  1277. {$endif EXTDEBUG}
  1278. procedure Tcallnode.candidates_get_information(procs:pcandidate);
  1279. var
  1280. hp : pcandidate;
  1281. currpara : tparaitem;
  1282. currparanr : byte;
  1283. def_from,
  1284. def_to : tdef;
  1285. pt : tcallparanode;
  1286. eq : tequaltype;
  1287. convtype : tconverttype;
  1288. pdoper : tprocdef;
  1289. begin
  1290. { process all procs }
  1291. hp:=procs;
  1292. while assigned(hp) do
  1293. begin
  1294. { We compare parameters in reverse order (right to left),
  1295. the firstpara is already pointing to the last parameter
  1296. were we need to start comparing }
  1297. currparanr:=paralength;
  1298. currpara:=hp^.firstpara;
  1299. while assigned(currpara) and (currpara.is_hidden) do
  1300. currpara:=tparaitem(currpara.previous);
  1301. pt:=tcallparanode(left);
  1302. while assigned(pt) and assigned(currpara) do
  1303. begin
  1304. { retrieve current parameter definitions to compares }
  1305. eq:=te_incompatible;
  1306. def_from:=pt.resulttype.def;
  1307. def_to:=currpara.paratype.def;
  1308. if not(assigned(def_from)) then
  1309. internalerror(200212091);
  1310. if not(
  1311. assigned(def_to) or
  1312. ((po_varargs in hp^.data.procoptions) and
  1313. (currparanr>hp^.data.minparacount))
  1314. ) then
  1315. internalerror(200212092);
  1316. { varargs are always equal, but not exact }
  1317. if (po_varargs in hp^.data.procoptions) and
  1318. (currparanr>hp^.data.minparacount) then
  1319. begin
  1320. inc(hp^.equal_count);
  1321. eq:=te_equal;
  1322. end
  1323. else
  1324. { same definition -> exact }
  1325. if (def_from=def_to) then
  1326. begin
  1327. inc(hp^.exact_count);
  1328. eq:=te_exact;
  1329. end
  1330. else
  1331. { for value and const parameters check if a integer is constant or
  1332. included in other integer -> equal and calc ordinal_distance }
  1333. if not(currpara.paratyp in [vs_var,vs_out]) and
  1334. is_integer(def_from) and
  1335. is_integer(def_to) and
  1336. is_in_limit(def_from,def_to) then
  1337. begin
  1338. inc(hp^.equal_count);
  1339. eq:=te_equal;
  1340. hp^.ordinal_distance:=hp^.ordinal_distance+
  1341. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1342. hp^.ordinal_distance:=hp^.ordinal_distance+
  1343. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1344. { Give wrong sign a small penalty, this is need to get a diffrence
  1345. from word->[longword,longint] }
  1346. if is_signed(def_from)<>is_signed(def_to) then
  1347. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1348. end
  1349. else
  1350. { generic type comparision }
  1351. begin
  1352. eq:=compare_defs_ext(def_from,def_to,pt.left.nodetype,
  1353. false,true,convtype,pdoper);
  1354. { when the types are not equal we need to check
  1355. some special case for parameter passing }
  1356. if (eq<te_equal) then
  1357. begin
  1358. if currpara.paratyp in [vs_var,vs_out] then
  1359. begin
  1360. { para requires an equal type so the previous found
  1361. match was not good enough, reset to incompatible }
  1362. eq:=te_incompatible;
  1363. { var_para_allowed will return te_equal and te_convert_l1 to
  1364. make a difference for best matching }
  1365. var_para_allowed(eq,pt.resulttype.def,currpara.paratype.def)
  1366. end
  1367. else
  1368. para_allowed(eq,pt,def_to);
  1369. end;
  1370. case eq of
  1371. te_exact :
  1372. internalerror(200212071); { already checked }
  1373. te_equal :
  1374. inc(hp^.equal_count);
  1375. te_convert_l1 :
  1376. inc(hp^.cl1_count);
  1377. te_convert_l2 :
  1378. inc(hp^.cl2_count);
  1379. te_convert_l3 :
  1380. inc(hp^.cl3_count);
  1381. te_convert_operator :
  1382. inc(hp^.coper_count);
  1383. te_incompatible :
  1384. hp^.invalid:=true;
  1385. else
  1386. internalerror(200212072);
  1387. end;
  1388. end;
  1389. { stop checking when an incompatible parameter is found }
  1390. if hp^.invalid then
  1391. begin
  1392. { store the current parameter info for
  1393. a nice error message when no procedure is found }
  1394. hp^.wrongpara:=currpara;
  1395. hp^.wrongparanr:=currparanr;
  1396. break;
  1397. end;
  1398. {$ifdef EXTDEBUG}
  1399. { store equal in node tree for dump }
  1400. currpara.eqval:=eq;
  1401. {$endif EXTDEBUG}
  1402. { next parameter in the call tree }
  1403. pt:=tcallparanode(pt.right);
  1404. { next parameter for definition, only goto next para
  1405. if we're out of the varargs }
  1406. if not(po_varargs in hp^.data.procoptions) or
  1407. (currparanr<=hp^.data.maxparacount) then
  1408. begin
  1409. { Ignore vs_hidden parameters }
  1410. repeat
  1411. currpara:=tparaitem(currpara.previous);
  1412. until (not assigned(currpara)) or (not currpara.is_hidden);
  1413. end;
  1414. dec(currparanr);
  1415. end;
  1416. if not(hp^.invalid) and
  1417. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1418. internalerror(200212141);
  1419. { next candidate }
  1420. hp:=hp^.next;
  1421. end;
  1422. end;
  1423. function Tcallnode.candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  1424. var
  1425. besthpstart,
  1426. hp : pcandidate;
  1427. cntpd,
  1428. res : integer;
  1429. begin
  1430. {
  1431. Returns the number of candidates left and the
  1432. first candidate is returned in pdbest
  1433. }
  1434. { Setup the first procdef as best, only count it as a result
  1435. when it is valid }
  1436. bestpd:=procs^.data;
  1437. if procs^.invalid then
  1438. cntpd:=0
  1439. else
  1440. cntpd:=1;
  1441. if assigned(procs^.next) then
  1442. begin
  1443. besthpstart:=procs;
  1444. hp:=procs^.next;
  1445. while assigned(hp) do
  1446. begin
  1447. res:=is_better_candidate(hp,besthpstart);
  1448. if (res>0) then
  1449. begin
  1450. { hp is better, flag all procs to be incompatible }
  1451. while (besthpstart<>hp) do
  1452. begin
  1453. besthpstart^.invalid:=true;
  1454. besthpstart:=besthpstart^.next;
  1455. end;
  1456. { besthpstart is already set to hp }
  1457. bestpd:=besthpstart^.data;
  1458. cntpd:=1;
  1459. end
  1460. else
  1461. if (res<0) then
  1462. begin
  1463. { besthpstart is better, flag current hp to be incompatible }
  1464. hp^.invalid:=true;
  1465. end
  1466. else
  1467. begin
  1468. { res=0, both are valid }
  1469. if not hp^.invalid then
  1470. inc(cntpd);
  1471. end;
  1472. hp:=hp^.next;
  1473. end;
  1474. end;
  1475. candidates_choose_best:=cntpd;
  1476. end;
  1477. procedure tcallnode.candidates_find_wrong_para(procs:pcandidate);
  1478. var
  1479. currparanr : smallint;
  1480. hp : pcandidate;
  1481. pt : tcallparanode;
  1482. begin
  1483. { Only process the first overloaded procdef }
  1484. hp:=procs;
  1485. { Find callparanode corresponding to the argument }
  1486. pt:=tcallparanode(left);
  1487. currparanr:=paralength;
  1488. while assigned(pt) and
  1489. (currparanr>hp^.wrongparanr) do
  1490. begin
  1491. pt:=tcallparanode(pt.right);
  1492. dec(currparanr);
  1493. end;
  1494. if (currparanr<>hp^.wrongparanr) or
  1495. not assigned(pt) then
  1496. internalerror(200212094);
  1497. { Show error message, when it was a var or out parameter
  1498. guess that it is a missing typeconv }
  1499. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1500. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  1501. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1502. else
  1503. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1504. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1505. end;
  1506. function tcallnode.gen_self_tree_methodpointer:tnode;
  1507. var
  1508. hsym : tvarsym;
  1509. begin
  1510. { find self field in methodpointer record }
  1511. hsym:=tvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1512. if not assigned(hsym) then
  1513. internalerror(200305251);
  1514. { Load tmehodpointer(right).self }
  1515. result:=csubscriptnode.create(
  1516. hsym,
  1517. ctypeconvnode.create_explicit(right.getcopy,methodpointertype));
  1518. end;
  1519. function tcallnode.gen_self_tree:tnode;
  1520. var
  1521. selftree : tnode;
  1522. begin
  1523. selftree:=nil;
  1524. { constructors }
  1525. if (procdefinition.proctypeoption=potype_constructor) then
  1526. begin
  1527. if not(nf_inherited in flags) then
  1528. begin
  1529. { push 0 as self when allocation is needed }
  1530. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1531. (nf_new_call in flags) then
  1532. selftree:=cpointerconstnode.create(0,voidpointertype)
  1533. else
  1534. begin
  1535. if methodpointer.nodetype=typen then
  1536. selftree:=load_self_node
  1537. else
  1538. selftree:=methodpointer.getcopy;
  1539. end;
  1540. end
  1541. else
  1542. selftree:=load_self_node;
  1543. end
  1544. else
  1545. begin
  1546. { Calling a static/class method from a non-static/class method,
  1547. then we need to load self with the VMT }
  1548. if (
  1549. (po_classmethod in procdefinition.procoptions) and
  1550. not(assigned(current_procinfo.procdef) and
  1551. (po_classmethod in current_procinfo.procdef.procoptions))
  1552. ) or
  1553. (
  1554. (po_staticmethod in procdefinition.procoptions) and
  1555. not(assigned(current_procinfo.procdef) and
  1556. (po_staticmethod in current_procinfo.procdef.procoptions))
  1557. ) then
  1558. begin
  1559. if (procdefinition.deftype<>procdef) then
  1560. internalerror(200305062);
  1561. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1562. begin
  1563. if methodpointer.resulttype.def.deftype=classrefdef then
  1564. selftree:=methodpointer.getcopy
  1565. else
  1566. selftree:=cloadvmtaddrnode.create(methodpointer.getcopy);
  1567. end
  1568. else
  1569. selftree:=cpointerconstnode.create(0,voidpointertype);
  1570. end
  1571. else
  1572. begin
  1573. if methodpointer.nodetype=typen then
  1574. selftree:=load_self_node
  1575. else
  1576. selftree:=methodpointer.getcopy;
  1577. end;
  1578. end;
  1579. result:=selftree;
  1580. end;
  1581. function tcallnode.gen_vmt_tree:tnode;
  1582. var
  1583. vmttree : tnode;
  1584. begin
  1585. vmttree:=nil;
  1586. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1587. internalerror(200305051);
  1588. { inherited call, no create/destroy }
  1589. if (nf_inherited in flags) then
  1590. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1591. else
  1592. { do not create/destroy when called from member function
  1593. without specifying self explicit }
  1594. if (nf_member_call in flags) then
  1595. begin
  1596. if (methodpointer.resulttype.def.deftype=classrefdef) and
  1597. (procdefinition.proctypeoption=potype_constructor) then
  1598. vmttree:=methodpointer.getcopy
  1599. else
  1600. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1601. end
  1602. else
  1603. { constructor with extended syntax called from new }
  1604. if (nf_new_call in flags) then
  1605. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1606. else
  1607. { destructor with extended syntax called from dispose }
  1608. if (nf_dispose_call in flags) then
  1609. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1610. else
  1611. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1612. begin
  1613. { constructor call via classreference => allocate memory }
  1614. if (procdefinition.proctypeoption=potype_constructor) and
  1615. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1616. vmttree:=methodpointer.getcopy
  1617. else
  1618. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1619. end
  1620. else
  1621. { class }
  1622. if is_class(methodpointer.resulttype.def) then
  1623. begin
  1624. { destructor: release instance, flag(vmt)=1
  1625. constructor: direct call, do nothing, leave vmt=0 }
  1626. if (procdefinition.proctypeoption=potype_destructor) then
  1627. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1628. else
  1629. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1630. end
  1631. else
  1632. { object }
  1633. begin
  1634. { destructor: direct call, no dispose, vmt=0
  1635. constructor: initialize object, load vmt }
  1636. if (procdefinition.proctypeoption=potype_constructor) then
  1637. { old styled inherited call? }
  1638. if (methodpointer.nodetype=typen) then
  1639. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1640. else
  1641. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1642. else
  1643. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1644. end;
  1645. result:=vmttree;
  1646. end;
  1647. procedure tcallnode.bind_paraitem;
  1648. var
  1649. i : integer;
  1650. pt : tcallparanode;
  1651. oldppt : ^tcallparanode;
  1652. varargspara,
  1653. currpara : tparaitem;
  1654. used_by_callnode : boolean;
  1655. hiddentree : tnode;
  1656. newstatement : tstatementnode;
  1657. temp : ttempcreatenode;
  1658. begin
  1659. pt:=tcallparanode(left);
  1660. oldppt:=@left;
  1661. { flag all callparanodes that belong to the varargs }
  1662. i:=paralength;
  1663. while (i>procdefinition.maxparacount) do
  1664. begin
  1665. include(pt.flags,nf_varargs_para);
  1666. oldppt:[email protected];
  1667. pt:=tcallparanode(pt.right);
  1668. dec(i);
  1669. end;
  1670. { skip varargs that are inserted by array of const }
  1671. while assigned(pt) and
  1672. (nf_varargs_para in pt.flags) do
  1673. pt:=tcallparanode(pt.right);
  1674. { process normal parameters and insert hidden parameters }
  1675. currpara:=tparaitem(procdefinition.Para.last);
  1676. while assigned(currpara) do
  1677. begin
  1678. if currpara.is_hidden then
  1679. begin
  1680. { generate hidden tree }
  1681. used_by_callnode:=false;
  1682. hiddentree:=nil;
  1683. if (vo_is_funcret in tvarsym(currpara.parasym).varoptions) then
  1684. begin
  1685. { Generate funcretnode if not specified }
  1686. if assigned(funcretnode) then
  1687. begin
  1688. hiddentree:=funcretnode.getcopy;
  1689. end
  1690. else
  1691. begin
  1692. hiddentree:=internalstatements(newstatement,false);
  1693. { need to use resulttype instead of procdefinition.rettype,
  1694. because they can be different }
  1695. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent);
  1696. addstatement(newstatement,temp);
  1697. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1698. addstatement(newstatement,ctemprefnode.create(temp));
  1699. end;
  1700. end
  1701. else
  1702. if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1703. begin
  1704. if not assigned(pt) then
  1705. internalerror(200304082);
  1706. { we need the information of the next parameter }
  1707. hiddentree:=gen_high_tree(pt.left,is_open_string(tparaitem(currpara.previous).paratype.def));
  1708. end
  1709. else
  1710. if vo_is_self in tvarsym(currpara.parasym).varoptions then
  1711. begin
  1712. if assigned(right) then
  1713. hiddentree:=gen_self_tree_methodpointer
  1714. else
  1715. hiddentree:=gen_self_tree;
  1716. end
  1717. else
  1718. if vo_is_vmt in tvarsym(currpara.parasym).varoptions then
  1719. begin
  1720. hiddentree:=gen_vmt_tree;
  1721. end
  1722. else
  1723. if vo_is_parentfp in tvarsym(currpara.parasym).varoptions then
  1724. begin
  1725. if not(assigned(procdefinition.owner.defowner)) then
  1726. internalerror(200309287);
  1727. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1728. end;
  1729. { add the hidden parameter }
  1730. if not assigned(hiddentree) then
  1731. internalerror(200304073);
  1732. { Already insert para and let the previous node point to
  1733. this new node }
  1734. pt:=ccallparanode.create(hiddentree,oldppt^);
  1735. pt.used_by_callnode:=used_by_callnode;
  1736. oldppt^:=pt;
  1737. end;
  1738. if not assigned(pt) then
  1739. internalerror(200310052);
  1740. pt.paraitem:=currpara;
  1741. oldppt:[email protected];
  1742. pt:=tcallparanode(pt.right);
  1743. currpara:=tparaitem(currpara.previous)
  1744. end;
  1745. { Create paraitems for varargs }
  1746. pt:=tcallparanode(left);
  1747. while assigned(pt) do
  1748. begin
  1749. if nf_varargs_para in pt.flags then
  1750. begin
  1751. if not assigned(varargsparas) then
  1752. varargsparas:=tlinkedlist.create;
  1753. varargspara:=tparaitem.create;
  1754. varargspara.paratyp:=vs_value;
  1755. varargspara.paratype:=pt.resulttype;
  1756. varargsparas.concat(varargspara);
  1757. pt.paraitem:=varargspara;
  1758. end;
  1759. pt:=tcallparanode(pt.right);
  1760. end;
  1761. end;
  1762. function tcallnode.det_resulttype:tnode;
  1763. var
  1764. procs : pcandidate;
  1765. oldcallnode : tcallnode;
  1766. hpt : tnode;
  1767. pt : tcallparanode;
  1768. lastpara : longint;
  1769. currpara : tparaitem;
  1770. cand_cnt : integer;
  1771. i : longint;
  1772. method_must_be_valid,
  1773. is_const : boolean;
  1774. label
  1775. errorexit;
  1776. begin
  1777. result:=nil;
  1778. procs:=nil;
  1779. oldcallnode:=aktcallnode;
  1780. aktcallnode:=nil;
  1781. { determine length of parameter list }
  1782. pt:=tcallparanode(left);
  1783. paralength:=0;
  1784. while assigned(pt) do
  1785. begin
  1786. inc(paralength);
  1787. pt:=tcallparanode(pt.right);
  1788. end;
  1789. { determine the type of the parameters }
  1790. if assigned(left) then
  1791. begin
  1792. tcallparanode(left).get_paratype;
  1793. if codegenerror then
  1794. goto errorexit;
  1795. end;
  1796. { procedure variable ? }
  1797. if assigned(right) then
  1798. begin
  1799. set_varstate(right,vs_used,true);
  1800. resulttypepass(right);
  1801. if codegenerror then
  1802. exit;
  1803. procdefinition:=tabstractprocdef(right.resulttype.def);
  1804. { Compare parameters from right to left }
  1805. currpara:=tparaitem(procdefinition.Para.last);
  1806. while assigned(currpara) and (currpara.is_hidden) do
  1807. currpara:=tparaitem(currpara.previous);
  1808. pt:=tcallparanode(left);
  1809. lastpara:=paralength;
  1810. while assigned(currpara) and assigned(pt) do
  1811. begin
  1812. { only goto next para if we're out of the varargs }
  1813. if not(po_varargs in procdefinition.procoptions) or
  1814. (lastpara<=procdefinition.maxparacount) then
  1815. begin
  1816. repeat
  1817. currpara:=tparaitem(currpara.previous);
  1818. until (not assigned(currpara)) or (not currpara.is_hidden);
  1819. end;
  1820. pt:=tcallparanode(pt.right);
  1821. dec(lastpara);
  1822. end;
  1823. if assigned(pt) or assigned(currpara) then
  1824. begin
  1825. if assigned(pt) then
  1826. aktfilepos:=pt.fileinfo;
  1827. CGMessage(parser_e_wrong_parameter_size);
  1828. goto errorexit;
  1829. end;
  1830. end
  1831. else
  1832. { not a procedure variable }
  1833. begin
  1834. { do we know the procedure to call ? }
  1835. if not(assigned(procdefinition)) then
  1836. begin
  1837. procs:=candidates_find;
  1838. { no procedures found? then there is something wrong
  1839. with the parameter size or the procedures are
  1840. not accessible }
  1841. if not assigned(procs) then
  1842. begin
  1843. { when it's an auto inherited call and there
  1844. is no procedure found, but the procedures
  1845. were defined with overload directive and at
  1846. least two procedures are defined then we ignore
  1847. this inherited by inserting a nothingn. Only
  1848. do this ugly hack in Delphi mode as it looks more
  1849. like a bug. It's also not documented }
  1850. if (m_delphi in aktmodeswitches) and
  1851. (nf_anon_inherited in flags) and
  1852. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1853. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1854. (symtableprocentry.procdef_count>=2) then
  1855. result:=cnothingnode.create
  1856. else
  1857. begin
  1858. { in tp mode we can try to convert to procvar if
  1859. there are no parameters specified. Only try it
  1860. when there is only one proc definition, else the
  1861. loadnode will give a strange error }
  1862. if not(assigned(left)) and
  1863. not(nf_inherited in flags) and
  1864. (m_tp_procvar in aktmodeswitches) and
  1865. (symtableprocentry.procdef_count=1) then
  1866. begin
  1867. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1868. if assigned(methodpointer) then
  1869. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1870. resulttypepass(hpt);
  1871. result:=hpt;
  1872. end
  1873. else
  1874. begin
  1875. if assigned(left) then
  1876. aktfilepos:=left.fileinfo;
  1877. if paravisible then
  1878. begin
  1879. CGMessage(parser_e_wrong_parameter_size);
  1880. symtableprocentry.write_parameter_lists(nil);
  1881. end
  1882. else
  1883. CGMessage(parser_e_cant_access_private_member);
  1884. end;
  1885. end;
  1886. goto errorexit;
  1887. end;
  1888. { Retrieve information about the candidates }
  1889. candidates_get_information(procs);
  1890. {$ifdef EXTDEBUG}
  1891. { Display info when multiple candidates are found }
  1892. if assigned(procs^.next) then
  1893. candidates_dump_info(V_Debug,procs);
  1894. {$endif EXTDEBUG}
  1895. { Choose the best candidate and count the number of
  1896. candidates left }
  1897. cand_cnt:=candidates_choose_best(procs,tprocdef(procdefinition));
  1898. { All parameters are checked, check if there are any
  1899. procedures left }
  1900. if cand_cnt>0 then
  1901. begin
  1902. { Multiple candidates left? }
  1903. if cand_cnt>1 then
  1904. begin
  1905. CGMessage(cg_e_cant_choose_overload_function);
  1906. {$ifdef EXTDEBUG}
  1907. candidates_dump_info(V_Hint,procs);
  1908. {$else}
  1909. candidates_list(procs,false);
  1910. {$endif EXTDEBUG}
  1911. { we'll just use the first candidate to make the
  1912. call }
  1913. end;
  1914. { assign procdefinition }
  1915. if symtableproc=nil then
  1916. symtableproc:=procdefinition.owner;
  1917. { update browser information }
  1918. if make_ref then
  1919. begin
  1920. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1921. inc(tprocdef(procdefinition).refcount);
  1922. if tprocdef(procdefinition).defref=nil then
  1923. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1924. end;
  1925. end
  1926. else
  1927. begin
  1928. { No candidates left, this must be a type error,
  1929. because wrong size is already checked. procdefinition
  1930. is filled with the first (random) definition that is
  1931. found. We use this definition to display a nice error
  1932. message that the wrong type is passed }
  1933. candidates_find_wrong_para(procs);
  1934. candidates_list(procs,true);
  1935. {$ifdef EXTDEBUG}
  1936. candidates_dump_info(V_Hint,procs);
  1937. {$endif EXTDEBUG}
  1938. { We can not proceed, release all procs and exit }
  1939. candidates_free(procs);
  1940. goto errorexit;
  1941. end;
  1942. candidates_free(procs);
  1943. end; { end of procedure to call determination }
  1944. { add needed default parameters }
  1945. if assigned(procdefinition) and
  1946. (paralength<procdefinition.maxparacount) then
  1947. begin
  1948. currpara:=tparaitem(procdefinition.Para.first);
  1949. i:=0;
  1950. while (i<paralength) do
  1951. begin
  1952. if not assigned(currpara) then
  1953. internalerror(200306181);
  1954. if not currpara.is_hidden then
  1955. inc(i);
  1956. currpara:=tparaitem(currpara.next);
  1957. end;
  1958. while assigned(currpara) and
  1959. currpara.is_hidden do
  1960. currpara:=tparaitem(currpara.next);
  1961. while assigned(currpara) do
  1962. begin
  1963. if not assigned(currpara.defaultvalue) then
  1964. internalerror(200212142);
  1965. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1966. currpara:=tparaitem(currpara.next);
  1967. end;
  1968. end;
  1969. end;
  1970. { handle predefined procedures }
  1971. is_const:=(po_internconst in procdefinition.procoptions) and
  1972. ((block_type in [bt_const,bt_type]) or
  1973. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1974. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1975. begin
  1976. if assigned(left) then
  1977. begin
  1978. { ptr and settextbuf needs two args }
  1979. if assigned(tcallparanode(left).right) then
  1980. begin
  1981. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1982. left:=nil;
  1983. end
  1984. else
  1985. begin
  1986. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1987. tcallparanode(left).left:=nil;
  1988. end;
  1989. end
  1990. else
  1991. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1992. result:=hpt;
  1993. goto errorexit;
  1994. end;
  1995. { ensure that the result type is set }
  1996. if not restypeset then
  1997. begin
  1998. { constructors return their current class type, not the type where the
  1999. constructor is declared, this can be different because of inheritance }
  2000. if (procdefinition.proctypeoption=potype_constructor) and
  2001. assigned(methodpointer) and
  2002. assigned(methodpointer.resulttype.def) and
  2003. (methodpointer.resulttype.def.deftype=classrefdef) then
  2004. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  2005. else
  2006. resulttype:=procdefinition.rettype;
  2007. end
  2008. else
  2009. resulttype:=restype;
  2010. if resulttype.def.needs_inittable then
  2011. include(current_procinfo.flags,pi_needs_implicit_finally);
  2012. if assigned(methodpointer) then
  2013. begin
  2014. resulttypepass(methodpointer);
  2015. { direct call to inherited abstract method, then we
  2016. can already give a error in the compiler instead
  2017. of a runtime error }
  2018. if (nf_inherited in flags) and
  2019. (po_abstractmethod in procdefinition.procoptions) then
  2020. CGMessage(cg_e_cant_call_abstract_method);
  2021. { if an inherited con- or destructor should be }
  2022. { called in a con- or destructor then a warning }
  2023. { will be made }
  2024. { con- and destructors need a pointer to the vmt }
  2025. if (nf_inherited in flags) and
  2026. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2027. is_object(methodpointer.resulttype.def) and
  2028. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  2029. CGMessage(cg_w_member_cd_call_from_method);
  2030. if methodpointer.nodetype<>typen then
  2031. begin
  2032. hpt:=methodpointer;
  2033. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  2034. hpt:=tunarynode(hpt).left;
  2035. if (procdefinition.proctypeoption=potype_constructor) and
  2036. assigned(symtableproc) and
  2037. (symtableproc.symtabletype=withsymtable) and
  2038. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  2039. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2040. { R.Init then R will be initialized by the constructor,
  2041. Also allow it for simple loads }
  2042. if (procdefinition.proctypeoption=potype_constructor) or
  2043. ((hpt.nodetype=loadn) and
  2044. (
  2045. (methodpointer.resulttype.def.deftype=classrefdef) or
  2046. (
  2047. (methodpointer.resulttype.def.deftype=objectdef) and
  2048. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2049. )
  2050. )
  2051. ) then
  2052. method_must_be_valid:=false
  2053. else
  2054. method_must_be_valid:=true;
  2055. set_varstate(methodpointer,vs_used,method_must_be_valid);
  2056. { The object is already used if it is called once }
  2057. if (hpt.nodetype=loadn) and
  2058. (tloadnode(hpt).symtableentry.typ=varsym) then
  2059. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  2060. end;
  2061. { if we are calling the constructor, ignore inherited
  2062. calls }
  2063. if (procdefinition.proctypeoption=potype_constructor) and
  2064. not(nf_inherited in flags) then
  2065. verifyabstractcalls;
  2066. end
  2067. else
  2068. begin
  2069. { When this is method the methodpointer must be available }
  2070. if (right=nil) and
  2071. (procdefinition.owner.symtabletype=objectsymtable) then
  2072. internalerror(200305061);
  2073. end;
  2074. { Change loading of array of const to varargs }
  2075. if assigned(left) and
  2076. is_array_of_const(tparaitem(procdefinition.para.last).paratype.def) and
  2077. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  2078. convert_carg_array_of_const;
  2079. { bind paraitems to the callparanodes and insert hidden parameters }
  2080. aktcallnode:=self;
  2081. bind_paraitem;
  2082. { methodpointer is only needed for virtual calls, and
  2083. it should then be loaded with the VMT }
  2084. if (po_virtualmethod in procdefinition.procoptions) and
  2085. not(assigned(methodpointer) and
  2086. (methodpointer.nodetype=typen)) then
  2087. begin
  2088. if not assigned(methodpointer) then
  2089. internalerror(200305063);
  2090. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  2091. begin
  2092. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  2093. resulttypepass(methodpointer);
  2094. end;
  2095. end
  2096. else
  2097. begin
  2098. { not needed anymore }
  2099. methodpointer.free;
  2100. methodpointer:=nil;
  2101. end;
  2102. { insert type conversions for parameters }
  2103. if assigned(left) then
  2104. tcallparanode(left).insert_typeconv(true);
  2105. errorexit:
  2106. aktcallnode:=oldcallnode;
  2107. end;
  2108. function tcallnode.pass_1 : tnode;
  2109. {$ifdef m68k}
  2110. var
  2111. regi : tregister;
  2112. {$endif}
  2113. label
  2114. errorexit;
  2115. begin
  2116. result:=nil;
  2117. { work trough all parameters to get the register requirements }
  2118. if assigned(left) then
  2119. tcallparanode(left).det_registers;
  2120. { function result node }
  2121. if assigned(_funcretnode) then
  2122. firstpass(_funcretnode);
  2123. { procedure variable ? }
  2124. if assigned(right) then
  2125. begin
  2126. firstpass(right);
  2127. { procedure does a call }
  2128. if not (block_type in [bt_const,bt_type]) then
  2129. include(current_procinfo.flags,pi_do_call);
  2130. end
  2131. else
  2132. { not a procedure variable }
  2133. begin
  2134. { calc the correture value for the register }
  2135. { handle predefined procedures }
  2136. if (procdefinition.proccalloption=pocall_inline) then
  2137. begin
  2138. if assigned(methodpointer) then
  2139. CGMessage(cg_e_unable_inline_object_methods);
  2140. if assigned(right) then
  2141. CGMessage(cg_e_unable_inline_procvar);
  2142. if not assigned(inlinecode) then
  2143. begin
  2144. if assigned(tprocdef(procdefinition).code) then
  2145. inlinecode:=tprocdef(procdefinition).code.getcopy
  2146. else
  2147. CGMessage(cg_e_no_code_for_inline_stored);
  2148. if assigned(inlinecode) then
  2149. begin
  2150. { consider it has not inlined if called
  2151. again inside the args }
  2152. procdefinition.proccalloption:=pocall_default;
  2153. firstpass(inlinecode);
  2154. end;
  2155. end;
  2156. end
  2157. else
  2158. begin
  2159. if not (block_type in [bt_const,bt_type]) then
  2160. include(current_procinfo.flags,pi_do_call);
  2161. end;
  2162. end;
  2163. { get a register for the return value }
  2164. if (not is_void(resulttype.def)) then
  2165. begin
  2166. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2167. begin
  2168. expectloc:=LOC_REFERENCE;
  2169. end
  2170. else
  2171. { for win32 records returned in EDX:EAX, we
  2172. move them to memory after ... }
  2173. if (resulttype.def.deftype=recorddef) then
  2174. begin
  2175. expectloc:=LOC_CREFERENCE;
  2176. end
  2177. else
  2178. { ansi/widestrings must be registered, so we can dispose them }
  2179. if is_ansistring(resulttype.def) or
  2180. is_widestring(resulttype.def) then
  2181. begin
  2182. expectloc:=LOC_CREFERENCE;
  2183. registers32:=1;
  2184. end
  2185. else
  2186. { we have only to handle the result if it is used }
  2187. if (nf_return_value_used in flags) then
  2188. begin
  2189. case resulttype.def.deftype of
  2190. enumdef,
  2191. orddef :
  2192. begin
  2193. if (procdefinition.proctypeoption=potype_constructor) then
  2194. begin
  2195. expectloc:=LOC_REGISTER;
  2196. registers32:=1;
  2197. end
  2198. else
  2199. begin
  2200. expectloc:=LOC_REGISTER;
  2201. if is_64bit(resulttype.def) then
  2202. registers32:=2
  2203. else
  2204. registers32:=1;
  2205. end;
  2206. end;
  2207. floatdef :
  2208. begin
  2209. expectloc:=LOC_FPUREGISTER;
  2210. {$ifdef cpufpemu}
  2211. if (cs_fp_emulation in aktmoduleswitches) then
  2212. registers32:=1
  2213. else
  2214. {$endif cpufpemu}
  2215. {$ifdef m68k}
  2216. if (tfloatdef(resulttype.def).typ=s32real) then
  2217. registers32:=1
  2218. else
  2219. {$endif m68k}
  2220. registersfpu:=1;
  2221. end;
  2222. else
  2223. begin
  2224. expectloc:=LOC_REGISTER;
  2225. registers32:=1;
  2226. end;
  2227. end;
  2228. end
  2229. else
  2230. expectloc:=LOC_VOID;
  2231. end
  2232. else
  2233. expectloc:=LOC_VOID;
  2234. {$ifdef m68k}
  2235. { we need one more address register for virtual calls on m68k }
  2236. if (po_virtualmethod in procdefinition.procoptions) then
  2237. inc(registers32);
  2238. {$endif m68k}
  2239. { a fpu can be used in any procedure !! }
  2240. {$ifdef i386}
  2241. registersfpu:=procdefinition.fpu_used;
  2242. {$endif i386}
  2243. { if this is a call to a method calc the registers }
  2244. if (methodpointer<>nil) then
  2245. begin
  2246. if methodpointer.nodetype<>typen then
  2247. begin
  2248. firstpass(methodpointer);
  2249. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2250. registers32:=max(methodpointer.registers32,registers32);
  2251. {$ifdef SUPPORT_MMX }
  2252. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2253. {$endif SUPPORT_MMX}
  2254. end;
  2255. end;
  2256. { determine the registers of the procedure variable }
  2257. { is this OK for inlined procs also ?? (PM) }
  2258. if assigned(inlinecode) then
  2259. begin
  2260. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  2261. registers32:=max(inlinecode.registers32,registers32);
  2262. {$ifdef SUPPORT_MMX}
  2263. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  2264. {$endif SUPPORT_MMX}
  2265. end;
  2266. { determine the registers of the procedure variable }
  2267. { is this OK for inlined procs also ?? (PM) }
  2268. if assigned(right) then
  2269. begin
  2270. registersfpu:=max(right.registersfpu,registersfpu);
  2271. registers32:=max(right.registers32,registers32);
  2272. {$ifdef SUPPORT_MMX}
  2273. registersmmx:=max(right.registersmmx,registersmmx);
  2274. {$endif SUPPORT_MMX}
  2275. end;
  2276. { determine the registers of the procedure }
  2277. if assigned(left) then
  2278. begin
  2279. registersfpu:=max(left.registersfpu,registersfpu);
  2280. registers32:=max(left.registers32,registers32);
  2281. {$ifdef SUPPORT_MMX}
  2282. registersmmx:=max(left.registersmmx,registersmmx);
  2283. {$endif SUPPORT_MMX}
  2284. end;
  2285. errorexit:
  2286. if assigned(inlinecode) then
  2287. procdefinition.proccalloption:=pocall_inline;
  2288. end;
  2289. {$ifdef state_tracking}
  2290. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2291. var hp:Tcallparanode;
  2292. value:Tnode;
  2293. begin
  2294. track_state_pass:=false;
  2295. hp:=Tcallparanode(left);
  2296. while assigned(hp) do
  2297. begin
  2298. if left.track_state_pass(exec_known) then
  2299. begin
  2300. left.resulttype.def:=nil;
  2301. do_resulttypepass(left);
  2302. end;
  2303. value:=aktstate.find_fact(hp.left);
  2304. if value<>nil then
  2305. begin
  2306. track_state_pass:=true;
  2307. hp.left.destroy;
  2308. hp.left:=value.getcopy;
  2309. do_resulttypepass(hp.left);
  2310. end;
  2311. hp:=Tcallparanode(hp.right);
  2312. end;
  2313. end;
  2314. {$endif}
  2315. function tcallnode.para_count:longint;
  2316. var
  2317. ppn : tcallparanode;
  2318. begin
  2319. result:=0;
  2320. ppn:=tcallparanode(left);
  2321. while assigned(ppn) do
  2322. begin
  2323. if not(assigned(ppn.paraitem) and
  2324. ppn.paraitem.is_hidden) then
  2325. inc(result);
  2326. ppn:=tcallparanode(ppn.right);
  2327. end;
  2328. end;
  2329. function tcallnode.docompare(p: tnode): boolean;
  2330. begin
  2331. docompare :=
  2332. inherited docompare(p) and
  2333. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2334. (procdefinition = tcallnode(p).procdefinition) and
  2335. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2336. ((restypeset and tcallnode(p).restypeset and
  2337. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2338. (not restypeset and not tcallnode(p).restypeset));
  2339. end;
  2340. procedure tcallnode.printnodedata(var t:text);
  2341. begin
  2342. if assigned(procdefinition) and
  2343. (procdefinition.deftype=procdef) then
  2344. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2345. else
  2346. begin
  2347. if assigned(symtableprocentry) then
  2348. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2349. else
  2350. writeln(t,printnodeindention,'proc = <nil>');
  2351. end;
  2352. printnode(t,methodpointer);
  2353. printnode(t,right);
  2354. printnode(t,left);
  2355. end;
  2356. begin
  2357. ccallnode:=tcallnode;
  2358. ccallparanode:=tcallparanode;
  2359. end.
  2360. {
  2361. $Log$
  2362. Revision 1.200 2003-10-23 14:44:07 peter
  2363. * splitted buildderef and buildderefimpl to fix interface crc
  2364. calculation
  2365. Revision 1.199 2003/10/22 20:40:00 peter
  2366. * write derefdata in a separate ppu entry
  2367. Revision 1.198 2003/10/21 18:17:02 peter
  2368. * only search for overloaded constructors in classes
  2369. Revision 1.197 2003/10/21 15:14:55 peter
  2370. * also search in parents for overloads when calling a constructor
  2371. Revision 1.196 2003/10/13 14:05:12 peter
  2372. * removed is_visible_for_proc
  2373. * search also for class overloads when finding interface
  2374. implementations
  2375. Revision 1.195 2003/10/09 21:31:37 daniel
  2376. * Register allocator splitted, ans abstract now
  2377. Revision 1.194 2003/10/09 15:00:13 florian
  2378. * fixed constructor call in class methods
  2379. Revision 1.193 2003/10/08 19:19:45 peter
  2380. * set_varstate cleanup
  2381. Revision 1.192 2003/10/07 21:14:32 peter
  2382. * compare_paras() has a parameter to ignore hidden parameters
  2383. * cross unit overload searching ignores hidden parameters when
  2384. comparing parameter lists. Now function(string):string is
  2385. not overriden with procedure(string) which has the same visible
  2386. parameter list
  2387. Revision 1.191 2003/10/05 21:21:52 peter
  2388. * c style array of const generates callparanodes
  2389. * varargs paraloc fixes
  2390. Revision 1.190 2003/10/05 12:54:17 peter
  2391. * don't check for abstract methods when the constructor is called
  2392. by inherited
  2393. * fix private member error instead of wrong number of parameters
  2394. Revision 1.189 2003/10/04 19:00:52 florian
  2395. * fixed TP 6.0 styled inherited call; fixes IDE with 1.1
  2396. Revision 1.188 2003/10/03 22:00:33 peter
  2397. * parameter alignment fixes
  2398. Revision 1.187 2003/10/03 14:44:38 peter
  2399. * fix IE when callnode was firstpassed twice
  2400. Revision 1.186 2003/10/02 21:13:46 peter
  2401. * protected visibility fixes
  2402. Revision 1.185 2003/10/01 20:34:48 peter
  2403. * procinfo unit contains tprocinfo
  2404. * cginfo renamed to cgbase
  2405. * moved cgmessage to verbose
  2406. * fixed ppc and sparc compiles
  2407. Revision 1.184 2003/09/28 21:44:55 peter
  2408. * fix check that filedef needs var para
  2409. Revision 1.183 2003/09/28 17:55:03 peter
  2410. * parent framepointer changed to hidden parameter
  2411. * tloadparentfpnode added
  2412. Revision 1.182 2003/09/25 21:28:00 peter
  2413. * parameter fixes
  2414. Revision 1.181 2003/09/23 17:56:05 peter
  2415. * locals and paras are allocated in the code generation
  2416. * tvarsym.localloc contains the location of para/local when
  2417. generating code for the current procedure
  2418. Revision 1.180 2003/09/16 16:17:01 peter
  2419. * varspez in calls to push_addr_param
  2420. Revision 1.179 2003/09/07 22:09:35 peter
  2421. * preparations for different default calling conventions
  2422. * various RA fixes
  2423. Revision 1.178 2003/09/06 22:27:08 florian
  2424. * fixed web bug 2669
  2425. * cosmetic fix in printnode
  2426. * tobjectdef.gettypename implemented
  2427. Revision 1.177 2003/09/03 15:55:00 peter
  2428. * NEWRA branch merged
  2429. Revision 1.176.2.3 2003/08/31 21:07:44 daniel
  2430. * callparatemp ripped
  2431. Revision 1.176.2.2 2003/08/27 20:23:55 peter
  2432. * remove old ra code
  2433. Revision 1.176.2.1 2003/08/27 19:55:54 peter
  2434. * first tregister patch
  2435. Revision 1.176 2003/08/23 18:42:57 peter
  2436. * only check for size matches when parameter is enum,ord,float
  2437. Revision 1.175 2003/08/10 17:25:23 peter
  2438. * fixed some reported bugs
  2439. Revision 1.174 2003/07/25 09:54:57 jonas
  2440. * fixed bogus abstract method warnings
  2441. Revision 1.173 2003/06/25 18:31:23 peter
  2442. * sym,def resolving partly rewritten to support also parent objects
  2443. not directly available through the uses clause
  2444. Revision 1.172 2003/06/17 16:34:44 jonas
  2445. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  2446. * renamed all_intregisters to volatile_intregisters and made it
  2447. processor dependent
  2448. Revision 1.171 2003/06/15 16:47:33 jonas
  2449. * fixed revious commit
  2450. Revision 1.170 2003/06/15 15:10:57 jonas
  2451. * callparatemp fix: if a threadvar is a parameter, that paramter also
  2452. does a call
  2453. Revision 1.169 2003/06/13 21:19:30 peter
  2454. * current_procdef removed, use current_procinfo.procdef instead
  2455. Revision 1.168 2003/06/08 20:01:53 jonas
  2456. * optimized assignments with on the right side a function that returns
  2457. an ansi- or widestring
  2458. Revision 1.167 2003/06/08 18:27:15 jonas
  2459. + ability to change the location of a ttempref node with changelocation()
  2460. method. Useful to use instead of copying the contents from one temp to
  2461. another
  2462. + some shortstring optimizations in tassignmentnode that avoid some
  2463. copying (required some shortstring optimizations to be moved from
  2464. resulttype to firstpass, because they work on callnodes and string
  2465. addnodes are only changed to callnodes in the firstpass)
  2466. * allow setting/changing the funcretnode of callnodes after the
  2467. resulttypepass has been done, funcretnode is now a property
  2468. (all of the above should have a quite big effect on callparatemp)
  2469. Revision 1.166 2003/06/08 11:42:33 peter
  2470. * creating class with abstract call checking fixed
  2471. * there will be only one warning for each class, the methods
  2472. are listed as hint
  2473. Revision 1.165 2003/06/07 20:26:32 peter
  2474. * re-resolving added instead of reloading from ppu
  2475. * tderef object added to store deref info for resolving
  2476. Revision 1.164 2003/06/03 21:05:48 peter
  2477. * fix check for procedure without parameters
  2478. * calling constructor as member will not allocate memory
  2479. Revision 1.163 2003/06/03 13:01:59 daniel
  2480. * Register allocator finished
  2481. Revision 1.162 2003/05/26 21:17:17 peter
  2482. * procinlinenode removed
  2483. * aktexit2label removed, fast exit removed
  2484. + tcallnode.inlined_pass_2 added
  2485. Revision 1.161 2003/05/25 11:34:17 peter
  2486. * methodpointer self pushing fixed
  2487. Revision 1.160 2003/05/25 08:59:16 peter
  2488. * inline fixes
  2489. Revision 1.159 2003/05/24 17:16:37 jonas
  2490. * added missing firstpass for callparatemp code
  2491. Revision 1.158 2003/05/23 14:27:35 peter
  2492. * remove some unit dependencies
  2493. * current_procinfo changes to store more info
  2494. Revision 1.157 2003/05/17 14:05:58 jonas
  2495. * fixed callparatemp for ansi/widestring and interfacecoms
  2496. Revision 1.156 2003/05/17 13:30:08 jonas
  2497. * changed tt_persistant to tt_persistent :)
  2498. * tempcreatenode now doesn't accept a boolean anymore for persistent
  2499. temps, but a ttemptype, so you can also create ansistring temps etc
  2500. Revision 1.155 2003/05/16 14:33:31 peter
  2501. * regvar fixes
  2502. Revision 1.154 2003/05/14 19:35:50 jonas
  2503. * fixed callparatemp so it works with vs_var, vs_out and formal const
  2504. parameters
  2505. Revision 1.153 2003/05/13 20:53:41 peter
  2506. * constructors return in register
  2507. Revision 1.152 2003/05/13 15:18:49 peter
  2508. * fixed various crashes
  2509. Revision 1.151 2003/05/11 21:37:03 peter
  2510. * moved implicit exception frame from ncgutil to psub
  2511. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2512. Revision 1.150 2003/05/11 14:45:12 peter
  2513. * tloadnode does not support objectsymtable,withsymtable anymore
  2514. * withnode cleanup
  2515. * direct with rewritten to use temprefnode
  2516. Revision 1.149 2003/05/09 17:47:02 peter
  2517. * self moved to hidden parameter
  2518. * removed hdisposen,hnewn,selfn
  2519. Revision 1.148 2003/05/05 14:53:16 peter
  2520. * vs_hidden replaced by is_hidden boolean
  2521. Revision 1.147 2003/04/27 11:21:33 peter
  2522. * aktprocdef renamed to current_procinfo.procdef
  2523. * procinfo renamed to current_procinfo
  2524. * procinfo will now be stored in current_module so it can be
  2525. cleaned up properly
  2526. * gen_main_procsym changed to create_main_proc and release_main_proc
  2527. to also generate a tprocinfo structure
  2528. * fixed unit implicit initfinal
  2529. Revision 1.146 2003/04/27 09:08:44 jonas
  2530. * do callparatemp stuff only after the parameters have been firstpassed,
  2531. because some nodes are turned into calls during the firstpass
  2532. Revision 1.145 2003/04/27 07:29:50 peter
  2533. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2534. a new procdef declaration
  2535. * aktprocsym removed
  2536. * lexlevel removed, use symtable.symtablelevel instead
  2537. * implicit init/final code uses the normal genentry/genexit
  2538. * funcret state checking updated for new funcret handling
  2539. Revision 1.144 2003/04/25 20:59:33 peter
  2540. * removed funcretn,funcretsym, function result is now in varsym
  2541. and aliases for result and function name are added using absolutesym
  2542. * vs_hidden parameter for funcret passed in parameter
  2543. * vs_hidden fixes
  2544. * writenode changed to printnode and released from extdebug
  2545. * -vp option added to generate a tree.log with the nodetree
  2546. * nicer printnode for statements, callnode
  2547. Revision 1.143 2002/04/25 20:15:39 florian
  2548. * block nodes within expressions shouldn't release the used registers,
  2549. fixed using a flag till the new rg is ready
  2550. Revision 1.142 2003/04/23 20:16:04 peter
  2551. + added currency support based on int64
  2552. + is_64bit for use in cg units instead of is_64bitint
  2553. * removed cgmessage from n386add, replace with internalerrors
  2554. Revision 1.141 2003/04/23 13:21:06 peter
  2555. * fix warning for calling constructor inside constructor
  2556. Revision 1.140 2003/04/23 12:35:34 florian
  2557. * fixed several issues with powerpc
  2558. + applied a patch from Jonas for nested function calls (PowerPC only)
  2559. * ...
  2560. Revision 1.139 2003/04/22 23:50:22 peter
  2561. * firstpass uses expectloc
  2562. * checks if there are differences between the expectloc and
  2563. location.loc from secondpass in EXTDEBUG
  2564. Revision 1.138 2003/04/22 09:53:33 peter
  2565. * fix insert_typeconv to handle new varargs which don't have a
  2566. paraitem set
  2567. Revision 1.137 2003/04/11 16:02:05 peter
  2568. * don't firstpass typen
  2569. Revision 1.136 2003/04/11 15:51:04 peter
  2570. * support subscript,vec for setting methodpointer varstate
  2571. Revision 1.135 2003/04/10 17:57:52 peter
  2572. * vs_hidden released
  2573. Revision 1.134 2003/04/07 11:58:22 jonas
  2574. * more vs_invisible fixes
  2575. Revision 1.133 2003/04/07 10:40:21 jonas
  2576. * fixed VS_HIDDEN for high parameter so it works again
  2577. Revision 1.132 2003/04/04 15:38:56 peter
  2578. * moved generic code from n386cal to ncgcal, i386 now also
  2579. uses the generic ncgcal
  2580. Revision 1.131 2003/03/17 18:54:23 peter
  2581. * fix missing self setting for method to procvar conversion in
  2582. tp_procvar mode
  2583. Revision 1.130 2003/03/17 16:54:41 peter
  2584. * support DefaultHandler and anonymous inheritance fixed
  2585. for message methods
  2586. Revision 1.129 2003/03/17 15:54:22 peter
  2587. * store symoptions also for procdef
  2588. * check symoptions (private,public) when calculating possible
  2589. overload candidates
  2590. Revision 1.128 2003/02/19 22:00:14 daniel
  2591. * Code generator converted to new register notation
  2592. - Horribily outdated todo.txt removed
  2593. Revision 1.127 2003/01/16 22:13:52 peter
  2594. * convert_l3 convertlevel added. This level is used for conversions
  2595. where information can be lost like converting widestring->ansistring
  2596. or dword->byte
  2597. Revision 1.126 2003/01/15 01:44:32 peter
  2598. * merged methodpointer fixes from 1.0.x
  2599. Revision 1.125 2003/01/12 17:52:07 peter
  2600. * only check for auto inherited in objectsymtable
  2601. Revision 1.124 2003/01/09 21:45:46 peter
  2602. * extended information about overloaded candidates when compiled
  2603. with EXTDEBUG
  2604. Revision 1.123 2002/12/26 18:24:33 jonas
  2605. * fixed check for whether or not a high parameter was already generated
  2606. * no type checking/conversions for invisible parameters
  2607. Revision 1.122 2002/12/15 22:50:00 florian
  2608. + some stuff for the new hidden parameter handling added
  2609. Revision 1.121 2002/12/15 21:34:15 peter
  2610. * give sign difference between ordinals a small penalty. This is
  2611. needed to get word->[longword|longint] working
  2612. Revision 1.120 2002/12/15 21:30:12 florian
  2613. * tcallnode.paraitem introduced, all references to defcoll removed
  2614. Revision 1.119 2002/12/15 20:59:58 peter
  2615. * fix crash with default parameters
  2616. Revision 1.118 2002/12/15 11:26:02 peter
  2617. * ignore vs_hidden parameters when choosing overloaded proc
  2618. Revision 1.117 2002/12/11 22:42:28 peter
  2619. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2620. the old code. The new code collects the information about possible
  2621. candidates only once resultting in much less calls to type compare
  2622. routines
  2623. Revision 1.116 2002/12/07 14:27:07 carl
  2624. * 3% memory optimization
  2625. * changed some types
  2626. + added type checking with different size for call node and for
  2627. parameters
  2628. Revision 1.115 2002/12/06 17:51:10 peter
  2629. * merged cdecl and array fixes
  2630. Revision 1.114 2002/12/06 16:56:58 peter
  2631. * only compile cs_fp_emulation support when cpufpuemu is defined
  2632. * define cpufpuemu for m68k only
  2633. Revision 1.113 2002/11/27 20:04:38 peter
  2634. * cdecl array of const fixes
  2635. Revision 1.112 2002/11/27 15:33:46 peter
  2636. * the never ending story of tp procvar hacks
  2637. Revision 1.111 2002/11/27 02:31:17 peter
  2638. * fixed inlinetree parsing in det_resulttype
  2639. Revision 1.110 2002/11/25 18:43:32 carl
  2640. - removed the invalid if <> checking (Delphi is strange on this)
  2641. + implemented abstract warning on instance creation of class with
  2642. abstract methods.
  2643. * some error message cleanups
  2644. Revision 1.109 2002/11/25 17:43:17 peter
  2645. * splitted defbase in defutil,symutil,defcmp
  2646. * merged isconvertable and is_equal into compare_defs(_ext)
  2647. * made operator search faster by walking the list only once
  2648. Revision 1.108 2002/11/18 17:31:54 peter
  2649. * pass proccalloption to ret_in_xxx and push_xxx functions
  2650. Revision 1.107 2002/11/15 01:58:50 peter
  2651. * merged changes from 1.0.7 up to 04-11
  2652. - -V option for generating bug report tracing
  2653. - more tracing for option parsing
  2654. - errors for cdecl and high()
  2655. - win32 import stabs
  2656. - win32 records<=8 are returned in eax:edx (turned off by default)
  2657. - heaptrc update
  2658. - more info for temp management in .s file with EXTDEBUG
  2659. Revision 1.106 2002/10/14 18:20:30 carl
  2660. * var parameter checking for classes and interfaces in Delphi mode
  2661. Revision 1.105 2002/10/06 21:02:17 peter
  2662. * fixed limit checking for qword
  2663. Revision 1.104 2002/10/05 15:15:45 peter
  2664. * Write unknwon compiler proc using Comment and only in Extdebug
  2665. Revision 1.103 2002/10/05 12:43:25 carl
  2666. * fixes for Delphi 6 compilation
  2667. (warning : Some features do not work under Delphi)
  2668. Revision 1.102 2002/10/05 00:48:57 peter
  2669. * support inherited; support for overload as it is handled by
  2670. delphi. This is only for delphi mode as it is working is
  2671. undocumented and hard to predict what is done
  2672. Revision 1.101 2002/09/16 14:11:12 peter
  2673. * add argument to equal_paras() to support default values or not
  2674. Revision 1.100 2002/09/15 17:49:59 peter
  2675. * don't have strict var parameter checking for procedures in the
  2676. system unit
  2677. Revision 1.99 2002/09/09 19:30:34 peter
  2678. * don't allow convertable parameters for var and out parameters in
  2679. delphi and tp mode
  2680. Revision 1.98 2002/09/07 15:25:02 peter
  2681. * old logs removed and tabs fixed
  2682. Revision 1.97 2002/09/07 12:16:05 carl
  2683. * second part bug report 1996 fix, testrange in cordconstnode
  2684. only called if option is set (also make parsing a tiny faster)
  2685. Revision 1.96 2002/09/05 14:53:41 peter
  2686. * fixed old callnode.det_resulttype code
  2687. * old ncal code is default again
  2688. Revision 1.95 2002/09/03 21:32:49 daniel
  2689. * Small bugfix for procdef selection
  2690. Revision 1.94 2002/09/03 19:27:22 daniel
  2691. * Activated new ncal code
  2692. Revision 1.93 2002/09/03 16:26:26 daniel
  2693. * Make Tprocdef.defs protected
  2694. Revision 1.92 2002/09/01 13:28:37 daniel
  2695. - write_access fields removed in favor of a flag
  2696. Revision 1.91 2002/09/01 12:14:15 peter
  2697. * remove debug line
  2698. * containself methods can be called directly
  2699. Revision 1.90 2002/09/01 08:01:16 daniel
  2700. * Removed sets from Tcallnode.det_resulttype
  2701. + Added read/write notifications of variables. These will be usefull
  2702. for providing information for several optimizations. For example
  2703. the value of the loop variable of a for loop does matter is the
  2704. variable is read after the for loop, but if it's no longer used
  2705. or written, it doesn't matter and this can be used to optimize
  2706. the loop code generation.
  2707. Revision 1.89 2002/08/23 16:13:16 peter
  2708. * also firstpass funcretrefnode if available. This was breaking the
  2709. asnode compilerproc code
  2710. Revision 1.88 2002/08/20 10:31:26 daniel
  2711. * Tcallnode.det_resulttype rewritten
  2712. Revision 1.87 2002/08/19 19:36:42 peter
  2713. * More fixes for cross unit inlining, all tnodes are now implemented
  2714. * Moved pocall_internconst to po_internconst because it is not a
  2715. calling type at all and it conflicted when inlining of these small
  2716. functions was requested
  2717. Revision 1.86 2002/08/17 22:09:44 florian
  2718. * result type handling in tcgcal.pass_2 overhauled
  2719. * better tnode.dowrite
  2720. * some ppc stuff fixed
  2721. Revision 1.85 2002/08/17 09:23:34 florian
  2722. * first part of current_procinfo rewrite
  2723. Revision 1.84 2002/08/16 14:24:57 carl
  2724. * issameref() to test if two references are the same (then emit no opcodes)
  2725. + ret_in_reg to replace ret_in_acc
  2726. (fix some register allocation bugs at the same time)
  2727. + save_std_register now has an extra parameter which is the
  2728. usedinproc registers
  2729. Revision 1.83 2002/07/20 11:57:53 florian
  2730. * types.pas renamed to defbase.pas because D6 contains a types
  2731. unit so this would conflicts if D6 programms are compiled
  2732. + Willamette/SSE2 instructions to assembler added
  2733. Revision 1.82 2002/07/19 11:41:35 daniel
  2734. * State tracker work
  2735. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2736. allows the state tracker to change while nodes automatically into
  2737. repeat nodes.
  2738. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2739. 'not(a>b)' is optimized into 'a<=b'.
  2740. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2741. by removing the notn and later switchting the true and falselabels. The
  2742. same is done with 'repeat until not a'.
  2743. Revision 1.81 2002/07/15 18:03:14 florian
  2744. * readded removed changes
  2745. Revision 1.79 2002/07/11 14:41:27 florian
  2746. * start of the new generic parameter handling
  2747. Revision 1.80 2002/07/14 18:00:43 daniel
  2748. + Added the beginning of a state tracker. This will track the values of
  2749. variables through procedures and optimize things away.
  2750. Revision 1.78 2002/07/04 20:43:00 florian
  2751. * first x86-64 patches
  2752. }