ncal.pas 111 KB

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