ncal.pas 109 KB

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