ncal.pas 114 KB

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