ncal.pas 113 KB

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