ncal.pas 111 KB

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