ncal.pas 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This file implements the node for sub procedure calling.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,cpuinfo,
  24. node,nbas,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symppu,symsym,symdef,symtable;
  29. type
  30. pcandidate = ^tcandidate;
  31. tcandidate = record
  32. next : pcandidate;
  33. data : tprocdef;
  34. wrongpara,
  35. firstpara : tparaitem;
  36. exact_count,
  37. equal_count,
  38. cl1_count,
  39. cl2_count,
  40. cl3_count,
  41. coper_count : integer; { should be signed }
  42. ordinal_distance : bestreal;
  43. invalid : boolean;
  44. wrongparanr : byte;
  45. end;
  46. tcallnode = class(tbinarynode)
  47. private
  48. paralength : smallint;
  49. function candidates_find:pcandidate;
  50. procedure candidates_free(procs:pcandidate);
  51. procedure candidates_list(procs:pcandidate;all:boolean);
  52. procedure candidates_get_information(procs:pcandidate);
  53. function candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  54. procedure candidates_find_wrong_para(procs:pcandidate);
  55. {$ifdef EXTDEBUG}
  56. procedure candidates_dump_info(lvl:longint;procs:pcandidate);
  57. {$endif EXTDEBUG}
  58. function gen_self_tree_methodpointer:tnode;
  59. function gen_self_tree:tnode;
  60. function gen_vmt_tree:tnode;
  61. procedure bind_paraitem;
  62. { function return node, this is used to pass the data for a
  63. ret_in_param return value }
  64. _funcretnode : tnode;
  65. procedure setfuncretnode(const returnnode: tnode);
  66. public
  67. { the symbol containing the definition of the procedure }
  68. { to call }
  69. symtableprocentry : tprocsym;
  70. symtableprocentryderef : tderef;
  71. { symtable where the entry was found, needed for with support }
  72. symtableproc : tsymtable;
  73. { the definition of the procedure to call }
  74. procdefinition : tabstractprocdef;
  75. procdefinitionderef : tderef;
  76. { tree that contains the pointer to the object for this method }
  77. methodpointer : tnode;
  78. { inline function body }
  79. inlinecode : tnode;
  80. { node that specifies where the result should be put for calls }
  81. { that return their result in a parameter }
  82. property funcretnode: tnode read _funcretnode write setfuncretnode;
  83. { separately specified resulttype for some compilerprocs (e.g. }
  84. { you can't have a function with an "array of char" resulttype }
  85. { the RTL) (JM) }
  86. restype: ttype;
  87. restypeset: boolean;
  88. { only the processor specific nodes need to override this }
  89. { constructor }
  90. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  91. constructor create_def(l:tnode;def:tprocdef;mp:tnode);virtual;
  92. constructor create_procvar(l,r:tnode);
  93. constructor createintern(const name: string; params: tnode);
  94. constructor createinternres(const name: string; params: tnode; const res: ttype);
  95. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  96. destructor destroy;override;
  97. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  98. procedure ppuwrite(ppufile:tcompilerppufile);override;
  99. procedure derefimpl;override;
  100. function getcopy : tnode;override;
  101. { Goes through all symbols in a class and subclasses and calls
  102. verify abstract for each .
  103. }
  104. procedure verifyabstractcalls;
  105. { called for each definition in a class and verifies if a method
  106. is abstract or not, if it is abstract, give out a warning
  107. }
  108. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  109. procedure insertintolist(l : tnodelist);override;
  110. function pass_1 : tnode;override;
  111. function det_resulttype:tnode;override;
  112. {$ifdef state_tracking}
  113. function track_state_pass(exec_known:boolean):boolean;override;
  114. {$endif state_tracking}
  115. function docompare(p: tnode): boolean; override;
  116. procedure printnodedata(var t:text);override;
  117. function para_count:longint;
  118. private
  119. AbstractMethodsList : TStringList;
  120. end;
  121. tcallnodeclass = class of tcallnode;
  122. tcallparaflags = (
  123. { flags used by tcallparanode }
  124. cpf_exact_match_found,
  125. cpf_convlevel1found,
  126. cpf_convlevel2found,
  127. cpf_is_colon_para
  128. );
  129. tcallparanode = class(tbinarynode)
  130. callparaflags : set of tcallparaflags;
  131. paraitem : tparaitem;
  132. used_by_callnode : boolean;
  133. { only the processor specific nodes need to override this }
  134. { constructor }
  135. constructor create(expr,next : tnode);virtual;
  136. destructor destroy;override;
  137. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  138. procedure ppuwrite(ppufile:tcompilerppufile);override;
  139. procedure derefimpl;override;
  140. function getcopy : tnode;override;
  141. procedure insertintolist(l : tnodelist);override;
  142. procedure get_paratype;
  143. procedure insert_typeconv(do_count : boolean);
  144. procedure det_registers;
  145. procedure firstcallparan(do_count : boolean);
  146. procedure secondcallparan(calloption:tproccalloption;alignment:byte);virtual;abstract;
  147. function docompare(p: tnode): boolean; override;
  148. procedure printnodetree(var t:text);override;
  149. end;
  150. tcallparanodeclass = class of tcallparanode;
  151. function reverseparameters(p: tcallparanode): tcallparanode;
  152. var
  153. ccallnode : tcallnodeclass;
  154. ccallparanode : tcallparanodeclass;
  155. { Current callnode, this is needed for having a link
  156. between the callparanodes and the callnode they belong to }
  157. aktcallnode : tcallnode;
  158. implementation
  159. uses
  160. systems,
  161. verbose,globals,
  162. symconst,paramgr,defutil,defcmp,
  163. htypechk,pass_1,cpubase,
  164. ncnv,nld,ninl,nadd,ncon,nmem,
  165. nutils,
  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. srsymtable : tsymtable;
  1068. srprocsym : tprocsym;
  1069. procedure proc_add(pd:tprocdef);
  1070. var
  1071. i : integer;
  1072. begin
  1073. { generate new candidate entry }
  1074. new(hp);
  1075. fillchar(hp^,sizeof(tcandidate),0);
  1076. hp^.data:=pd;
  1077. hp^.next:=procs;
  1078. procs:=hp;
  1079. { Find last parameter, skip all default parameters
  1080. that are not passed. Ignore this skipping for varargs }
  1081. hp^.firstpara:=tparaitem(pd.Para.last);
  1082. if not(po_varargs in pd.procoptions) then
  1083. begin
  1084. for i:=1 to pd.maxparacount-paralength do
  1085. hp^.firstpara:=tparaitem(hp^.firstPara.previous);
  1086. end;
  1087. end;
  1088. begin
  1089. procs:=nil;
  1090. { when the definition has overload directive set, we search for
  1091. overloaded definitions in the class, this only needs to be done once
  1092. for class entries as the tree keeps always the same }
  1093. if (not symtableprocentry.overloadchecked) and
  1094. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1095. (symtableprocentry.owner.symtabletype=objectsymtable) then
  1096. search_class_overloads(symtableprocentry);
  1097. { link all procedures which have the same # of parameters }
  1098. for j:=1 to symtableprocentry.procdef_count do
  1099. begin
  1100. pd:=symtableprocentry.procdef[j];
  1101. { Is the procdef visible? This needs to be checked on
  1102. procdef level since a symbol can contain both private and
  1103. public declarations. But the check should not be done
  1104. when the callnode is generated by a property }
  1105. if (nf_isproperty in flags) or
  1106. (pd.owner.symtabletype<>objectsymtable) or
  1107. pd.is_visible_for_proc(current_procinfo.procdef) then
  1108. begin
  1109. { only when the # of parameter are supported by the
  1110. procedure }
  1111. if (paralength>=pd.minparacount) and
  1112. ((po_varargs in pd.procoptions) or { varargs }
  1113. (paralength<=pd.maxparacount)) then
  1114. proc_add(pd);
  1115. end;
  1116. end;
  1117. { remember if the procedure is declared with the overload directive,
  1118. it's information is still needed also after all procs are removed }
  1119. has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
  1120. { when the definition has overload directive set, we search for
  1121. overloaded definitions in the symtablestack. The found
  1122. entries are only added to the procs list and not the procsym, because
  1123. the list can change in every situation }
  1124. if has_overload_directive and
  1125. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1126. begin
  1127. srsymtable:=symtableprocentry.owner.next;
  1128. while assigned(srsymtable) do
  1129. begin
  1130. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1131. begin
  1132. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1133. { process only visible procsyms }
  1134. if assigned(srprocsym) and
  1135. (srprocsym.typ=procsym) and
  1136. srprocsym.is_visible_for_proc(current_procinfo.procdef) then
  1137. begin
  1138. { if this procedure doesn't have overload we can stop
  1139. searching }
  1140. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1141. break;
  1142. { process all overloaded definitions }
  1143. for j:=1 to srprocsym.procdef_count do
  1144. begin
  1145. pd:=srprocsym.procdef[j];
  1146. { only when the # of parameter are supported by the
  1147. procedure }
  1148. if (paralength>=pd.minparacount) and
  1149. ((po_varargs in pd.procoptions) or { varargs }
  1150. (paralength<=pd.maxparacount)) then
  1151. begin
  1152. found:=false;
  1153. hp:=procs;
  1154. while assigned(hp) do
  1155. begin
  1156. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,false)>=te_equal then
  1157. begin
  1158. found:=true;
  1159. break;
  1160. end;
  1161. hp:=hp^.next;
  1162. end;
  1163. if not found then
  1164. proc_add(pd);
  1165. end;
  1166. end;
  1167. end;
  1168. end;
  1169. srsymtable:=srsymtable.next;
  1170. end;
  1171. end;
  1172. candidates_find:=procs;
  1173. end;
  1174. procedure tcallnode.candidates_free(procs:pcandidate);
  1175. var
  1176. hpnext,
  1177. hp : pcandidate;
  1178. begin
  1179. hp:=procs;
  1180. while assigned(hp) do
  1181. begin
  1182. hpnext:=hp^.next;
  1183. dispose(hp);
  1184. hp:=hpnext;
  1185. end;
  1186. end;
  1187. procedure tcallnode.candidates_list(procs:pcandidate;all:boolean);
  1188. var
  1189. hp : pcandidate;
  1190. begin
  1191. hp:=procs;
  1192. while assigned(hp) do
  1193. begin
  1194. if all or
  1195. (not hp^.invalid) then
  1196. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname(false));
  1197. hp:=hp^.next;
  1198. end;
  1199. end;
  1200. {$ifdef EXTDEBUG}
  1201. procedure Tcallnode.candidates_dump_info(lvl:longint;procs:pcandidate);
  1202. function ParaTreeStr(p:tcallparanode):string;
  1203. begin
  1204. result:='';
  1205. while assigned(p) do
  1206. begin
  1207. if result<>'' then
  1208. result:=result+',';
  1209. result:=result+p.resulttype.def.typename;
  1210. p:=tcallparanode(p.right);
  1211. end;
  1212. end;
  1213. var
  1214. hp : pcandidate;
  1215. currpara : tparaitem;
  1216. begin
  1217. if not CheckVerbosity(lvl) then
  1218. exit;
  1219. Comment(lvl+V_LineInfo,'Overloaded callnode: '+symtableprocentry.name+'('+ParaTreeStr(tcallparanode(left))+')');
  1220. hp:=procs;
  1221. while assigned(hp) do
  1222. begin
  1223. Comment(lvl,' '+hp^.data.fullprocname(false));
  1224. if (hp^.invalid) then
  1225. Comment(lvl,' invalid')
  1226. else
  1227. begin
  1228. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1229. ' eq: '+tostr(hp^.equal_count)+
  1230. ' l1: '+tostr(hp^.cl1_count)+
  1231. ' l2: '+tostr(hp^.cl2_count)+
  1232. ' l3: '+tostr(hp^.cl3_count)+
  1233. ' oper: '+tostr(hp^.coper_count)+
  1234. ' ord: '+realtostr(hp^.exact_count));
  1235. { Print parameters in left-right order }
  1236. currpara:=hp^.firstpara;
  1237. if assigned(currpara) then
  1238. begin
  1239. while assigned(currpara.next) do
  1240. currpara:=tparaitem(currpara.next);
  1241. end;
  1242. while assigned(currpara) do
  1243. begin
  1244. if (not currpara.is_hidden) then
  1245. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1246. currpara:=tparaitem(currpara.previous);
  1247. end;
  1248. end;
  1249. hp:=hp^.next;
  1250. end;
  1251. end;
  1252. {$endif EXTDEBUG}
  1253. procedure Tcallnode.candidates_get_information(procs:pcandidate);
  1254. var
  1255. hp : pcandidate;
  1256. currpara : tparaitem;
  1257. currparanr : byte;
  1258. def_from,
  1259. def_to : tdef;
  1260. pt : tcallparanode;
  1261. eq : tequaltype;
  1262. convtype : tconverttype;
  1263. pdoper : tprocdef;
  1264. begin
  1265. { process all procs }
  1266. hp:=procs;
  1267. while assigned(hp) do
  1268. begin
  1269. { We compare parameters in reverse order (right to left),
  1270. the firstpara is already pointing to the last parameter
  1271. were we need to start comparing }
  1272. currparanr:=paralength;
  1273. currpara:=hp^.firstpara;
  1274. while assigned(currpara) and (currpara.is_hidden) do
  1275. currpara:=tparaitem(currpara.previous);
  1276. pt:=tcallparanode(left);
  1277. while assigned(pt) and assigned(currpara) do
  1278. begin
  1279. { retrieve current parameter definitions to compares }
  1280. eq:=te_incompatible;
  1281. def_from:=pt.resulttype.def;
  1282. def_to:=currpara.paratype.def;
  1283. if not(assigned(def_from)) then
  1284. internalerror(200212091);
  1285. if not(
  1286. assigned(def_to) or
  1287. ((po_varargs in hp^.data.procoptions) and
  1288. (currparanr>hp^.data.minparacount))
  1289. ) then
  1290. internalerror(200212092);
  1291. { varargs are always equal, but not exact }
  1292. if (po_varargs in hp^.data.procoptions) and
  1293. (currparanr>hp^.data.minparacount) then
  1294. begin
  1295. inc(hp^.equal_count);
  1296. eq:=te_equal;
  1297. end
  1298. else
  1299. { same definition -> exact }
  1300. if (def_from=def_to) then
  1301. begin
  1302. inc(hp^.exact_count);
  1303. eq:=te_exact;
  1304. end
  1305. else
  1306. { for value and const parameters check if a integer is constant or
  1307. included in other integer -> equal and calc ordinal_distance }
  1308. if not(currpara.paratyp in [vs_var,vs_out]) and
  1309. is_integer(def_from) and
  1310. is_integer(def_to) and
  1311. is_in_limit(def_from,def_to) then
  1312. begin
  1313. inc(hp^.equal_count);
  1314. eq:=te_equal;
  1315. hp^.ordinal_distance:=hp^.ordinal_distance+
  1316. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1317. hp^.ordinal_distance:=hp^.ordinal_distance+
  1318. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1319. { Give wrong sign a small penalty, this is need to get a diffrence
  1320. from word->[longword,longint] }
  1321. if is_signed(def_from)<>is_signed(def_to) then
  1322. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1323. end
  1324. else
  1325. { generic type comparision }
  1326. begin
  1327. eq:=compare_defs_ext(def_from,def_to,pt.left.nodetype,
  1328. false,true,convtype,pdoper);
  1329. { when the types are not equal we need to check
  1330. some special case for parameter passing }
  1331. if (eq<te_equal) then
  1332. begin
  1333. if currpara.paratyp in [vs_var,vs_out] then
  1334. begin
  1335. { para requires an equal type so the previous found
  1336. match was not good enough, reset to incompatible }
  1337. eq:=te_incompatible;
  1338. { var_para_allowed will return te_equal and te_convert_l1 to
  1339. make a difference for best matching }
  1340. var_para_allowed(eq,pt.resulttype.def,currpara.paratype.def)
  1341. end
  1342. else
  1343. para_allowed(eq,pt,def_to);
  1344. end;
  1345. case eq of
  1346. te_exact :
  1347. internalerror(200212071); { already checked }
  1348. te_equal :
  1349. inc(hp^.equal_count);
  1350. te_convert_l1 :
  1351. inc(hp^.cl1_count);
  1352. te_convert_l2 :
  1353. inc(hp^.cl2_count);
  1354. te_convert_l3 :
  1355. inc(hp^.cl3_count);
  1356. te_convert_operator :
  1357. inc(hp^.coper_count);
  1358. te_incompatible :
  1359. hp^.invalid:=true;
  1360. else
  1361. internalerror(200212072);
  1362. end;
  1363. end;
  1364. { stop checking when an incompatible parameter is found }
  1365. if hp^.invalid then
  1366. begin
  1367. { store the current parameter info for
  1368. a nice error message when no procedure is found }
  1369. hp^.wrongpara:=currpara;
  1370. hp^.wrongparanr:=currparanr;
  1371. break;
  1372. end;
  1373. {$ifdef EXTDEBUG}
  1374. { store equal in node tree for dump }
  1375. currpara.eqval:=eq;
  1376. {$endif EXTDEBUG}
  1377. { next parameter in the call tree }
  1378. pt:=tcallparanode(pt.right);
  1379. { next parameter for definition, only goto next para
  1380. if we're out of the varargs }
  1381. if not(po_varargs in hp^.data.procoptions) or
  1382. (currparanr<=hp^.data.maxparacount) then
  1383. begin
  1384. { Ignore vs_hidden parameters }
  1385. repeat
  1386. currpara:=tparaitem(currpara.previous);
  1387. until (not assigned(currpara)) or (not currpara.is_hidden);
  1388. end;
  1389. dec(currparanr);
  1390. end;
  1391. if not(hp^.invalid) and
  1392. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1393. internalerror(200212141);
  1394. { next candidate }
  1395. hp:=hp^.next;
  1396. end;
  1397. end;
  1398. function Tcallnode.candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  1399. var
  1400. besthpstart,
  1401. hp : pcandidate;
  1402. cntpd,
  1403. res : integer;
  1404. begin
  1405. {
  1406. Returns the number of candidates left and the
  1407. first candidate is returned in pdbest
  1408. }
  1409. { Setup the first procdef as best, only count it as a result
  1410. when it is valid }
  1411. bestpd:=procs^.data;
  1412. if procs^.invalid then
  1413. cntpd:=0
  1414. else
  1415. cntpd:=1;
  1416. if assigned(procs^.next) then
  1417. begin
  1418. besthpstart:=procs;
  1419. hp:=procs^.next;
  1420. while assigned(hp) do
  1421. begin
  1422. res:=is_better_candidate(hp,besthpstart);
  1423. if (res>0) then
  1424. begin
  1425. { hp is better, flag all procs to be incompatible }
  1426. while (besthpstart<>hp) do
  1427. begin
  1428. besthpstart^.invalid:=true;
  1429. besthpstart:=besthpstart^.next;
  1430. end;
  1431. { besthpstart is already set to hp }
  1432. bestpd:=besthpstart^.data;
  1433. cntpd:=1;
  1434. end
  1435. else
  1436. if (res<0) then
  1437. begin
  1438. { besthpstart is better, flag current hp to be incompatible }
  1439. hp^.invalid:=true;
  1440. end
  1441. else
  1442. begin
  1443. { res=0, both are valid }
  1444. if not hp^.invalid then
  1445. inc(cntpd);
  1446. end;
  1447. hp:=hp^.next;
  1448. end;
  1449. end;
  1450. candidates_choose_best:=cntpd;
  1451. end;
  1452. procedure tcallnode.candidates_find_wrong_para(procs:pcandidate);
  1453. var
  1454. currparanr : smallint;
  1455. hp : pcandidate;
  1456. pt : tcallparanode;
  1457. begin
  1458. { Only process the first overloaded procdef }
  1459. hp:=procs;
  1460. { Find callparanode corresponding to the argument }
  1461. pt:=tcallparanode(left);
  1462. currparanr:=paralength;
  1463. while assigned(pt) and
  1464. (currparanr>hp^.wrongparanr) do
  1465. begin
  1466. pt:=tcallparanode(pt.right);
  1467. dec(currparanr);
  1468. end;
  1469. if (currparanr<>hp^.wrongparanr) or
  1470. not assigned(pt) then
  1471. internalerror(200212094);
  1472. { Show error message, when it was a var or out parameter
  1473. guess that it is a missing typeconv }
  1474. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1475. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  1476. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1477. else
  1478. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1479. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1480. end;
  1481. function tcallnode.gen_self_tree_methodpointer:tnode;
  1482. var
  1483. hsym : tvarsym;
  1484. begin
  1485. { find self field in methodpointer record }
  1486. hsym:=tvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1487. if not assigned(hsym) then
  1488. internalerror(200305251);
  1489. { Load tmehodpointer(right).self }
  1490. result:=csubscriptnode.create(
  1491. hsym,
  1492. ctypeconvnode.create_explicit(right.getcopy,methodpointertype));
  1493. end;
  1494. function tcallnode.gen_self_tree:tnode;
  1495. var
  1496. selftree : tnode;
  1497. begin
  1498. selftree:=nil;
  1499. { constructors }
  1500. if (procdefinition.proctypeoption=potype_constructor) then
  1501. begin
  1502. if not(nf_inherited in flags) then
  1503. begin
  1504. { push 0 as self when allocation is needed }
  1505. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1506. (nf_new_call in flags) then
  1507. selftree:=cpointerconstnode.create(0,voidpointertype)
  1508. else
  1509. begin
  1510. if methodpointer.nodetype=typen then
  1511. selftree:=load_self_node
  1512. else
  1513. selftree:=methodpointer.getcopy;
  1514. end;
  1515. end
  1516. else
  1517. selftree:=load_self_node;
  1518. end
  1519. else
  1520. begin
  1521. { Calling a static/class method from a non-static/class method,
  1522. then we need to load self with the VMT }
  1523. if (
  1524. (po_classmethod in procdefinition.procoptions) and
  1525. not(assigned(current_procinfo.procdef) and
  1526. (po_classmethod in current_procinfo.procdef.procoptions))
  1527. ) or
  1528. (
  1529. (po_staticmethod in procdefinition.procoptions) and
  1530. not(assigned(current_procinfo.procdef) and
  1531. (po_staticmethod in current_procinfo.procdef.procoptions))
  1532. ) then
  1533. begin
  1534. if (procdefinition.deftype<>procdef) then
  1535. internalerror(200305062);
  1536. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1537. begin
  1538. if methodpointer.resulttype.def.deftype=classrefdef then
  1539. selftree:=methodpointer.getcopy
  1540. else
  1541. selftree:=cloadvmtaddrnode.create(methodpointer.getcopy);
  1542. end
  1543. else
  1544. selftree:=cpointerconstnode.create(0,voidpointertype);
  1545. end
  1546. else
  1547. begin
  1548. if methodpointer.nodetype=typen then
  1549. selftree:=load_self_node
  1550. else
  1551. selftree:=methodpointer.getcopy;
  1552. end;
  1553. end;
  1554. result:=selftree;
  1555. end;
  1556. function tcallnode.gen_vmt_tree:tnode;
  1557. var
  1558. vmttree : tnode;
  1559. begin
  1560. vmttree:=nil;
  1561. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1562. internalerror(200305051);
  1563. { inherited call, no create/destroy }
  1564. if (nf_inherited in flags) then
  1565. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1566. else
  1567. { do not create/destroy when called from member function
  1568. without specifying self explicit }
  1569. if (nf_member_call in flags) then
  1570. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1571. else
  1572. { constructor with extended syntax called from new }
  1573. if (nf_new_call in flags) then
  1574. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1575. else
  1576. { destructor with extended syntax called from dispose }
  1577. if (nf_dispose_call in flags) then
  1578. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1579. else
  1580. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1581. begin
  1582. { constructor call via classreference => allocate memory }
  1583. if (procdefinition.proctypeoption=potype_constructor) and
  1584. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1585. vmttree:=methodpointer.getcopy
  1586. else
  1587. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1588. end
  1589. else
  1590. { class }
  1591. if is_class(methodpointer.resulttype.def) then
  1592. begin
  1593. { destructor: release instance, flag(vmt)=1
  1594. constructor: direct call, do nothing, leave vmt=0 }
  1595. if (procdefinition.proctypeoption=potype_destructor) then
  1596. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1597. else
  1598. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1599. end
  1600. else
  1601. { object }
  1602. begin
  1603. { destructor: direct call, no dispose, vmt=0
  1604. constructor: initialize object, load vmt }
  1605. if (procdefinition.proctypeoption=potype_constructor) then
  1606. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1607. else
  1608. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1609. end;
  1610. result:=vmttree;
  1611. end;
  1612. procedure tcallnode.bind_paraitem;
  1613. var
  1614. i : integer;
  1615. pt : tcallparanode;
  1616. oldppt : ^tcallparanode;
  1617. currpara : tparaitem;
  1618. used_by_callnode : boolean;
  1619. hiddentree : tnode;
  1620. newstatement : tstatementnode;
  1621. temp : ttempcreatenode;
  1622. begin
  1623. pt:=tcallparanode(left);
  1624. oldppt:=@left;
  1625. { flag all callparanodes that belong to the varargs }
  1626. if (po_varargs in procdefinition.procoptions) then
  1627. begin
  1628. i:=paralength;
  1629. while (i>procdefinition.maxparacount) do
  1630. begin
  1631. include(tcallparanode(pt).flags,nf_varargs_para);
  1632. oldppt:[email protected];
  1633. pt:=tcallparanode(pt.right);
  1634. dec(i);
  1635. end;
  1636. end;
  1637. { insert hidden parameters }
  1638. currpara:=tparaitem(procdefinition.Para.last);
  1639. while assigned(currpara) do
  1640. begin
  1641. if currpara.is_hidden then
  1642. begin
  1643. { generate hidden tree }
  1644. used_by_callnode:=false;
  1645. hiddentree:=nil;
  1646. if (vo_is_funcret in tvarsym(currpara.parasym).varoptions) then
  1647. begin
  1648. { Generate funcretnode if not specified }
  1649. if assigned(funcretnode) then
  1650. begin
  1651. hiddentree:=funcretnode.getcopy;
  1652. end
  1653. else
  1654. begin
  1655. hiddentree:=internalstatements(newstatement,false);
  1656. { need to use resulttype instead of procdefinition.rettype,
  1657. because they can be different }
  1658. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent);
  1659. addstatement(newstatement,temp);
  1660. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1661. addstatement(newstatement,ctemprefnode.create(temp));
  1662. end;
  1663. end
  1664. else
  1665. if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1666. begin
  1667. if not assigned(pt) then
  1668. internalerror(200304082);
  1669. { we need the information of the next parameter }
  1670. hiddentree:=gen_high_tree(pt.left,is_open_string(tparaitem(currpara.previous).paratype.def));
  1671. end
  1672. else
  1673. if vo_is_self in tvarsym(currpara.parasym).varoptions then
  1674. begin
  1675. if assigned(right) then
  1676. hiddentree:=gen_self_tree_methodpointer
  1677. else
  1678. hiddentree:=gen_self_tree;
  1679. end
  1680. else
  1681. if vo_is_vmt in tvarsym(currpara.parasym).varoptions then
  1682. begin
  1683. hiddentree:=gen_vmt_tree;
  1684. end
  1685. else
  1686. if vo_is_parentfp in tvarsym(currpara.parasym).varoptions then
  1687. begin
  1688. if not(assigned(procdefinition.owner.defowner)) then
  1689. internalerror(200309287);
  1690. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1691. end;
  1692. { add the hidden parameter }
  1693. if not assigned(hiddentree) then
  1694. internalerror(200304073);
  1695. { Already insert para and let the previous node point to
  1696. this new node }
  1697. pt:=ccallparanode.create(hiddentree,oldppt^);
  1698. pt.used_by_callnode:=used_by_callnode;
  1699. oldppt^:=pt;
  1700. end;
  1701. { Bind paraitem to this node and varsym }
  1702. pt.paraitem:=currpara;
  1703. { Next node and paraitem }
  1704. oldppt:[email protected];
  1705. pt:=tcallparanode(pt.right);
  1706. currpara:=tparaitem(currpara.previous);
  1707. end;
  1708. end;
  1709. function tcallnode.det_resulttype:tnode;
  1710. var
  1711. procs : pcandidate;
  1712. oldcallnode : tcallnode;
  1713. hpt : tnode;
  1714. pt : tcallparanode;
  1715. lastpara : longint;
  1716. currpara : tparaitem;
  1717. cand_cnt : integer;
  1718. i : longint;
  1719. method_must_be_valid,
  1720. is_const : boolean;
  1721. label
  1722. errorexit;
  1723. begin
  1724. result:=nil;
  1725. procs:=nil;
  1726. oldcallnode:=aktcallnode;
  1727. aktcallnode:=nil;
  1728. { determine length of parameter list }
  1729. pt:=tcallparanode(left);
  1730. paralength:=0;
  1731. while assigned(pt) do
  1732. begin
  1733. inc(paralength);
  1734. pt:=tcallparanode(pt.right);
  1735. end;
  1736. { determine the type of the parameters }
  1737. if assigned(left) then
  1738. begin
  1739. tcallparanode(left).get_paratype;
  1740. if codegenerror then
  1741. goto errorexit;
  1742. end;
  1743. { procedure variable ? }
  1744. if assigned(right) then
  1745. begin
  1746. set_varstate(right,true);
  1747. resulttypepass(right);
  1748. if codegenerror then
  1749. exit;
  1750. procdefinition:=tabstractprocdef(right.resulttype.def);
  1751. { Compare parameters from right to left }
  1752. currpara:=tparaitem(procdefinition.Para.last);
  1753. while assigned(currpara) and (currpara.is_hidden) do
  1754. currpara:=tparaitem(currpara.previous);
  1755. pt:=tcallparanode(left);
  1756. lastpara:=paralength;
  1757. while assigned(currpara) and assigned(pt) do
  1758. begin
  1759. { only goto next para if we're out of the varargs }
  1760. if not(po_varargs in procdefinition.procoptions) or
  1761. (lastpara<=procdefinition.maxparacount) then
  1762. begin
  1763. repeat
  1764. currpara:=tparaitem(currpara.previous);
  1765. until (not assigned(currpara)) or (not currpara.is_hidden);
  1766. end;
  1767. pt:=tcallparanode(pt.right);
  1768. dec(lastpara);
  1769. end;
  1770. if assigned(pt) or assigned(currpara) then
  1771. begin
  1772. if assigned(pt) then
  1773. aktfilepos:=pt.fileinfo;
  1774. CGMessage(parser_e_wrong_parameter_size);
  1775. goto errorexit;
  1776. end;
  1777. end
  1778. else
  1779. { not a procedure variable }
  1780. begin
  1781. { do we know the procedure to call ? }
  1782. if not(assigned(procdefinition)) then
  1783. begin
  1784. procs:=candidates_find;
  1785. { no procedures found? then there is something wrong
  1786. with the parameter size }
  1787. if not assigned(procs) then
  1788. begin
  1789. { when it's an auto inherited call and there
  1790. is no procedure found, but the procedures
  1791. were defined with overload directive and at
  1792. least two procedures are defined then we ignore
  1793. this inherited by inserting a nothingn. Only
  1794. do this ugly hack in Delphi mode as it looks more
  1795. like a bug. It's also not documented }
  1796. if (m_delphi in aktmodeswitches) and
  1797. (nf_anon_inherited in flags) and
  1798. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1799. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1800. (symtableprocentry.procdef_count>=2) then
  1801. result:=cnothingnode.create
  1802. else
  1803. begin
  1804. { in tp mode we can try to convert to procvar if
  1805. there are no parameters specified. Only try it
  1806. when there is only one proc definition, else the
  1807. loadnode will give a strange error }
  1808. if not(assigned(left)) and
  1809. not(nf_inherited in flags) and
  1810. (m_tp_procvar in aktmodeswitches) and
  1811. (symtableprocentry.procdef_count=1) then
  1812. begin
  1813. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1814. if assigned(methodpointer) then
  1815. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1816. resulttypepass(hpt);
  1817. result:=hpt;
  1818. end
  1819. else
  1820. begin
  1821. if assigned(left) then
  1822. aktfilepos:=left.fileinfo;
  1823. CGMessage(parser_e_wrong_parameter_size);
  1824. symtableprocentry.write_parameter_lists(nil);
  1825. end;
  1826. end;
  1827. goto errorexit;
  1828. end;
  1829. { Retrieve information about the candidates }
  1830. candidates_get_information(procs);
  1831. {$ifdef EXTDEBUG}
  1832. { Display info when multiple candidates are found }
  1833. if assigned(procs^.next) then
  1834. candidates_dump_info(V_Debug,procs);
  1835. {$endif EXTDEBUG}
  1836. { Choose the best candidate and count the number of
  1837. candidates left }
  1838. cand_cnt:=candidates_choose_best(procs,tprocdef(procdefinition));
  1839. { All parameters are checked, check if there are any
  1840. procedures left }
  1841. if cand_cnt>0 then
  1842. begin
  1843. { Multiple candidates left? }
  1844. if cand_cnt>1 then
  1845. begin
  1846. CGMessage(cg_e_cant_choose_overload_function);
  1847. {$ifdef EXTDEBUG}
  1848. candidates_dump_info(V_Hint,procs);
  1849. {$else}
  1850. candidates_list(procs,false);
  1851. {$endif EXTDEBUG}
  1852. { we'll just use the first candidate to make the
  1853. call }
  1854. end;
  1855. { assign procdefinition }
  1856. if symtableproc=nil then
  1857. symtableproc:=procdefinition.owner;
  1858. { update browser information }
  1859. if make_ref then
  1860. begin
  1861. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1862. inc(tprocdef(procdefinition).refcount);
  1863. if tprocdef(procdefinition).defref=nil then
  1864. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1865. end;
  1866. end
  1867. else
  1868. begin
  1869. { No candidates left, this must be a type error,
  1870. because wrong size is already checked. procdefinition
  1871. is filled with the first (random) definition that is
  1872. found. We use this definition to display a nice error
  1873. message that the wrong type is passed }
  1874. candidates_find_wrong_para(procs);
  1875. candidates_list(procs,true);
  1876. {$ifdef EXTDEBUG}
  1877. candidates_dump_info(V_Hint,procs);
  1878. {$endif EXTDEBUG}
  1879. { We can not proceed, release all procs and exit }
  1880. candidates_free(procs);
  1881. goto errorexit;
  1882. end;
  1883. candidates_free(procs);
  1884. end; { end of procedure to call determination }
  1885. { add needed default parameters }
  1886. if assigned(procdefinition) and
  1887. (paralength<procdefinition.maxparacount) then
  1888. begin
  1889. currpara:=tparaitem(procdefinition.Para.first);
  1890. i:=0;
  1891. while (i<paralength) do
  1892. begin
  1893. if not assigned(currpara) then
  1894. internalerror(200306181);
  1895. if not currpara.is_hidden then
  1896. inc(i);
  1897. currpara:=tparaitem(currpara.next);
  1898. end;
  1899. while assigned(currpara) and
  1900. currpara.is_hidden do
  1901. currpara:=tparaitem(currpara.next);
  1902. while assigned(currpara) do
  1903. begin
  1904. if not assigned(currpara.defaultvalue) then
  1905. internalerror(200212142);
  1906. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1907. currpara:=tparaitem(currpara.next);
  1908. end;
  1909. end;
  1910. end;
  1911. { handle predefined procedures }
  1912. is_const:=(po_internconst in procdefinition.procoptions) and
  1913. ((block_type in [bt_const,bt_type]) or
  1914. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1915. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1916. begin
  1917. if assigned(left) then
  1918. begin
  1919. { ptr and settextbuf needs two args }
  1920. if assigned(tcallparanode(left).right) then
  1921. begin
  1922. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1923. left:=nil;
  1924. end
  1925. else
  1926. begin
  1927. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1928. tcallparanode(left).left:=nil;
  1929. end;
  1930. end
  1931. else
  1932. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1933. result:=hpt;
  1934. goto errorexit;
  1935. end;
  1936. { ensure that the result type is set }
  1937. if not restypeset then
  1938. begin
  1939. { constructors return their current class type, not the type where the
  1940. constructor is declared, this can be different because of inheritance }
  1941. if (procdefinition.proctypeoption=potype_constructor) and
  1942. assigned(methodpointer) and
  1943. assigned(methodpointer.resulttype.def) and
  1944. (methodpointer.resulttype.def.deftype=classrefdef) then
  1945. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1946. else
  1947. resulttype:=procdefinition.rettype;
  1948. end
  1949. else
  1950. resulttype:=restype;
  1951. if resulttype.def.needs_inittable then
  1952. include(current_procinfo.flags,pi_needs_implicit_finally);
  1953. if assigned(methodpointer) then
  1954. begin
  1955. resulttypepass(methodpointer);
  1956. { direct call to inherited abstract method, then we
  1957. can already give a error in the compiler instead
  1958. of a runtime error }
  1959. if (nf_inherited in flags) and
  1960. (po_abstractmethod in procdefinition.procoptions) then
  1961. CGMessage(cg_e_cant_call_abstract_method);
  1962. { if an inherited con- or destructor should be }
  1963. { called in a con- or destructor then a warning }
  1964. { will be made }
  1965. { con- and destructors need a pointer to the vmt }
  1966. if (nf_inherited in flags) and
  1967. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1968. is_object(methodpointer.resulttype.def) and
  1969. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1970. CGMessage(cg_w_member_cd_call_from_method);
  1971. if methodpointer.nodetype<>typen then
  1972. begin
  1973. hpt:=methodpointer;
  1974. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1975. hpt:=tunarynode(hpt).left;
  1976. if (procdefinition.proctypeoption=potype_constructor) and
  1977. assigned(symtableproc) and
  1978. (symtableproc.symtabletype=withsymtable) and
  1979. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1980. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1981. { R.Init then R will be initialized by the constructor,
  1982. Also allow it for simple loads }
  1983. if (procdefinition.proctypeoption=potype_constructor) or
  1984. ((hpt.nodetype=loadn) and
  1985. (
  1986. (methodpointer.resulttype.def.deftype=classrefdef) or
  1987. (
  1988. (methodpointer.resulttype.def.deftype=objectdef) and
  1989. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1990. )
  1991. )
  1992. ) then
  1993. method_must_be_valid:=false
  1994. else
  1995. method_must_be_valid:=true;
  1996. set_varstate(methodpointer,method_must_be_valid);
  1997. { The object is already used if it is called once }
  1998. if (hpt.nodetype=loadn) and
  1999. (tloadnode(hpt).symtableentry.typ=varsym) then
  2000. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  2001. end;
  2002. { if we are calling the constructor }
  2003. if procdefinition.proctypeoption=potype_constructor then
  2004. verifyabstractcalls;
  2005. end
  2006. else
  2007. begin
  2008. { When this is method the methodpointer must be available }
  2009. if (right=nil) and
  2010. (procdefinition.owner.symtabletype=objectsymtable) then
  2011. internalerror(200305061);
  2012. end;
  2013. { bind paraitems to the callparanodes and insert hidden parameters }
  2014. aktcallnode:=self;
  2015. bind_paraitem;
  2016. { methodpointer is only needed for virtual calls, and
  2017. it should then be loaded with the VMT }
  2018. if (po_virtualmethod in procdefinition.procoptions) and
  2019. not(assigned(methodpointer) and
  2020. (methodpointer.nodetype=typen)) then
  2021. begin
  2022. if not assigned(methodpointer) then
  2023. internalerror(200305063);
  2024. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  2025. begin
  2026. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  2027. resulttypepass(methodpointer);
  2028. end;
  2029. end
  2030. else
  2031. begin
  2032. { not needed anymore }
  2033. methodpointer.free;
  2034. methodpointer:=nil;
  2035. end;
  2036. { insert type conversions for parameters }
  2037. if assigned(left) then
  2038. tcallparanode(left).insert_typeconv(true);
  2039. errorexit:
  2040. aktcallnode:=oldcallnode;
  2041. end;
  2042. function tcallnode.pass_1 : tnode;
  2043. {$ifdef m68k}
  2044. var
  2045. regi : tregister;
  2046. {$endif}
  2047. label
  2048. errorexit;
  2049. begin
  2050. result:=nil;
  2051. { work trough all parameters to get the register requirements }
  2052. if assigned(left) then
  2053. tcallparanode(left).det_registers;
  2054. { function result node }
  2055. if assigned(_funcretnode) then
  2056. firstpass(_funcretnode);
  2057. { procedure variable ? }
  2058. if assigned(right) then
  2059. begin
  2060. firstpass(right);
  2061. { procedure does a call }
  2062. if not (block_type in [bt_const,bt_type]) then
  2063. include(current_procinfo.flags,pi_do_call);
  2064. rg.incrementotherregisterpushed(all_otherregisters);
  2065. end
  2066. else
  2067. { not a procedure variable }
  2068. begin
  2069. { calc the correture value for the register }
  2070. { handle predefined procedures }
  2071. if (procdefinition.proccalloption=pocall_inline) then
  2072. begin
  2073. if assigned(methodpointer) then
  2074. CGMessage(cg_e_unable_inline_object_methods);
  2075. if assigned(right) then
  2076. CGMessage(cg_e_unable_inline_procvar);
  2077. if assigned(inlinecode) then
  2078. internalerror(200305261);
  2079. if assigned(tprocdef(procdefinition).code) then
  2080. inlinecode:=tprocdef(procdefinition).code.getcopy
  2081. else
  2082. CGMessage(cg_e_no_code_for_inline_stored);
  2083. if assigned(inlinecode) then
  2084. begin
  2085. { consider it has not inlined if called
  2086. again inside the args }
  2087. procdefinition.proccalloption:=pocall_default;
  2088. firstpass(inlinecode);
  2089. end;
  2090. end
  2091. else
  2092. begin
  2093. if not (block_type in [bt_const,bt_type]) then
  2094. include(current_procinfo.flags,pi_do_call);
  2095. end;
  2096. { It doesn't hurt to calculate it already though :) (JM) }
  2097. rg.incrementotherregisterpushed(tprocdef(procdefinition).usedotherregisters);
  2098. end;
  2099. { get a register for the return value }
  2100. if (not is_void(resulttype.def)) then
  2101. begin
  2102. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2103. begin
  2104. expectloc:=LOC_REFERENCE;
  2105. end
  2106. else
  2107. { for win32 records returned in EDX:EAX, we
  2108. move them to memory after ... }
  2109. if (resulttype.def.deftype=recorddef) then
  2110. begin
  2111. expectloc:=LOC_CREFERENCE;
  2112. end
  2113. else
  2114. { ansi/widestrings must be registered, so we can dispose them }
  2115. if is_ansistring(resulttype.def) or
  2116. is_widestring(resulttype.def) then
  2117. begin
  2118. expectloc:=LOC_CREFERENCE;
  2119. registers32:=1;
  2120. end
  2121. else
  2122. { we have only to handle the result if it is used }
  2123. if (nf_return_value_used in flags) then
  2124. begin
  2125. case resulttype.def.deftype of
  2126. enumdef,
  2127. orddef :
  2128. begin
  2129. if (procdefinition.proctypeoption=potype_constructor) then
  2130. begin
  2131. expectloc:=LOC_REGISTER;
  2132. registers32:=1;
  2133. end
  2134. else
  2135. begin
  2136. expectloc:=LOC_REGISTER;
  2137. if is_64bit(resulttype.def) then
  2138. registers32:=2
  2139. else
  2140. registers32:=1;
  2141. end;
  2142. end;
  2143. floatdef :
  2144. begin
  2145. expectloc:=LOC_FPUREGISTER;
  2146. {$ifdef cpufpemu}
  2147. if (cs_fp_emulation in aktmoduleswitches) then
  2148. registers32:=1
  2149. else
  2150. {$endif cpufpemu}
  2151. {$ifdef m68k}
  2152. if (tfloatdef(resulttype.def).typ=s32real) then
  2153. registers32:=1
  2154. else
  2155. {$endif m68k}
  2156. registersfpu:=1;
  2157. end;
  2158. else
  2159. begin
  2160. expectloc:=LOC_REGISTER;
  2161. registers32:=1;
  2162. end;
  2163. end;
  2164. end
  2165. else
  2166. expectloc:=LOC_VOID;
  2167. end
  2168. else
  2169. expectloc:=LOC_VOID;
  2170. {$ifdef m68k}
  2171. { we need one more address register for virtual calls on m68k }
  2172. if (po_virtualmethod in procdefinition.procoptions) then
  2173. inc(registers32);
  2174. {$endif m68k}
  2175. { a fpu can be used in any procedure !! }
  2176. {$ifdef i386}
  2177. registersfpu:=procdefinition.fpu_used;
  2178. {$endif i386}
  2179. { if this is a call to a method calc the registers }
  2180. if (methodpointer<>nil) then
  2181. begin
  2182. if methodpointer.nodetype<>typen then
  2183. begin
  2184. firstpass(methodpointer);
  2185. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2186. registers32:=max(methodpointer.registers32,registers32);
  2187. {$ifdef SUPPORT_MMX }
  2188. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2189. {$endif SUPPORT_MMX}
  2190. end;
  2191. end;
  2192. { determine the registers of the procedure variable }
  2193. { is this OK for inlined procs also ?? (PM) }
  2194. if assigned(inlinecode) then
  2195. begin
  2196. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  2197. registers32:=max(inlinecode.registers32,registers32);
  2198. {$ifdef SUPPORT_MMX}
  2199. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  2200. {$endif SUPPORT_MMX}
  2201. end;
  2202. { determine the registers of the procedure variable }
  2203. { is this OK for inlined procs also ?? (PM) }
  2204. if assigned(right) then
  2205. begin
  2206. registersfpu:=max(right.registersfpu,registersfpu);
  2207. registers32:=max(right.registers32,registers32);
  2208. {$ifdef SUPPORT_MMX}
  2209. registersmmx:=max(right.registersmmx,registersmmx);
  2210. {$endif SUPPORT_MMX}
  2211. end;
  2212. { determine the registers of the procedure }
  2213. if assigned(left) then
  2214. begin
  2215. registersfpu:=max(left.registersfpu,registersfpu);
  2216. registers32:=max(left.registers32,registers32);
  2217. {$ifdef SUPPORT_MMX}
  2218. registersmmx:=max(left.registersmmx,registersmmx);
  2219. {$endif SUPPORT_MMX}
  2220. end;
  2221. errorexit:
  2222. if assigned(inlinecode) then
  2223. procdefinition.proccalloption:=pocall_inline;
  2224. end;
  2225. {$ifdef state_tracking}
  2226. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2227. var hp:Tcallparanode;
  2228. value:Tnode;
  2229. begin
  2230. track_state_pass:=false;
  2231. hp:=Tcallparanode(left);
  2232. while assigned(hp) do
  2233. begin
  2234. if left.track_state_pass(exec_known) then
  2235. begin
  2236. left.resulttype.def:=nil;
  2237. do_resulttypepass(left);
  2238. end;
  2239. value:=aktstate.find_fact(hp.left);
  2240. if value<>nil then
  2241. begin
  2242. track_state_pass:=true;
  2243. hp.left.destroy;
  2244. hp.left:=value.getcopy;
  2245. do_resulttypepass(hp.left);
  2246. end;
  2247. hp:=Tcallparanode(hp.right);
  2248. end;
  2249. end;
  2250. {$endif}
  2251. function tcallnode.para_count:longint;
  2252. var
  2253. ppn : tcallparanode;
  2254. begin
  2255. result:=0;
  2256. ppn:=tcallparanode(left);
  2257. while assigned(ppn) do
  2258. begin
  2259. if not(assigned(ppn.paraitem) and
  2260. ppn.paraitem.is_hidden) then
  2261. inc(result);
  2262. ppn:=tcallparanode(ppn.right);
  2263. end;
  2264. end;
  2265. function tcallnode.docompare(p: tnode): boolean;
  2266. begin
  2267. docompare :=
  2268. inherited docompare(p) and
  2269. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2270. (procdefinition = tcallnode(p).procdefinition) and
  2271. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2272. ((restypeset and tcallnode(p).restypeset and
  2273. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2274. (not restypeset and not tcallnode(p).restypeset));
  2275. end;
  2276. procedure tcallnode.printnodedata(var t:text);
  2277. begin
  2278. if assigned(procdefinition) and
  2279. (procdefinition.deftype=procdef) then
  2280. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2281. else
  2282. begin
  2283. if assigned(symtableprocentry) then
  2284. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2285. else
  2286. writeln(t,printnodeindention,'proc = <nil>');
  2287. end;
  2288. printnode(t,methodpointer);
  2289. printnode(t,right);
  2290. printnode(t,left);
  2291. end;
  2292. begin
  2293. ccallnode:=tcallnode;
  2294. ccallparanode:=tcallparanode;
  2295. end.
  2296. {
  2297. $Log$
  2298. Revision 1.185 2003-10-01 20:34:48 peter
  2299. * procinfo unit contains tprocinfo
  2300. * cginfo renamed to cgbase
  2301. * moved cgmessage to verbose
  2302. * fixed ppc and sparc compiles
  2303. Revision 1.184 2003/09/28 21:44:55 peter
  2304. * fix check that filedef needs var para
  2305. Revision 1.183 2003/09/28 17:55:03 peter
  2306. * parent framepointer changed to hidden parameter
  2307. * tloadparentfpnode added
  2308. Revision 1.182 2003/09/25 21:28:00 peter
  2309. * parameter fixes
  2310. Revision 1.181 2003/09/23 17:56:05 peter
  2311. * locals and paras are allocated in the code generation
  2312. * tvarsym.localloc contains the location of para/local when
  2313. generating code for the current procedure
  2314. Revision 1.180 2003/09/16 16:17:01 peter
  2315. * varspez in calls to push_addr_param
  2316. Revision 1.179 2003/09/07 22:09:35 peter
  2317. * preparations for different default calling conventions
  2318. * various RA fixes
  2319. Revision 1.178 2003/09/06 22:27:08 florian
  2320. * fixed web bug 2669
  2321. * cosmetic fix in printnode
  2322. * tobjectdef.gettypename implemented
  2323. Revision 1.177 2003/09/03 15:55:00 peter
  2324. * NEWRA branch merged
  2325. Revision 1.176.2.3 2003/08/31 21:07:44 daniel
  2326. * callparatemp ripped
  2327. Revision 1.176.2.2 2003/08/27 20:23:55 peter
  2328. * remove old ra code
  2329. Revision 1.176.2.1 2003/08/27 19:55:54 peter
  2330. * first tregister patch
  2331. Revision 1.176 2003/08/23 18:42:57 peter
  2332. * only check for size matches when parameter is enum,ord,float
  2333. Revision 1.175 2003/08/10 17:25:23 peter
  2334. * fixed some reported bugs
  2335. Revision 1.174 2003/07/25 09:54:57 jonas
  2336. * fixed bogus abstract method warnings
  2337. Revision 1.173 2003/06/25 18:31:23 peter
  2338. * sym,def resolving partly rewritten to support also parent objects
  2339. not directly available through the uses clause
  2340. Revision 1.172 2003/06/17 16:34:44 jonas
  2341. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  2342. * renamed all_intregisters to volatile_intregisters and made it
  2343. processor dependent
  2344. Revision 1.171 2003/06/15 16:47:33 jonas
  2345. * fixed revious commit
  2346. Revision 1.170 2003/06/15 15:10:57 jonas
  2347. * callparatemp fix: if a threadvar is a parameter, that paramter also
  2348. does a call
  2349. Revision 1.169 2003/06/13 21:19:30 peter
  2350. * current_procdef removed, use current_procinfo.procdef instead
  2351. Revision 1.168 2003/06/08 20:01:53 jonas
  2352. * optimized assignments with on the right side a function that returns
  2353. an ansi- or widestring
  2354. Revision 1.167 2003/06/08 18:27:15 jonas
  2355. + ability to change the location of a ttempref node with changelocation()
  2356. method. Useful to use instead of copying the contents from one temp to
  2357. another
  2358. + some shortstring optimizations in tassignmentnode that avoid some
  2359. copying (required some shortstring optimizations to be moved from
  2360. resulttype to firstpass, because they work on callnodes and string
  2361. addnodes are only changed to callnodes in the firstpass)
  2362. * allow setting/changing the funcretnode of callnodes after the
  2363. resulttypepass has been done, funcretnode is now a property
  2364. (all of the above should have a quite big effect on callparatemp)
  2365. Revision 1.166 2003/06/08 11:42:33 peter
  2366. * creating class with abstract call checking fixed
  2367. * there will be only one warning for each class, the methods
  2368. are listed as hint
  2369. Revision 1.165 2003/06/07 20:26:32 peter
  2370. * re-resolving added instead of reloading from ppu
  2371. * tderef object added to store deref info for resolving
  2372. Revision 1.164 2003/06/03 21:05:48 peter
  2373. * fix check for procedure without parameters
  2374. * calling constructor as member will not allocate memory
  2375. Revision 1.163 2003/06/03 13:01:59 daniel
  2376. * Register allocator finished
  2377. Revision 1.162 2003/05/26 21:17:17 peter
  2378. * procinlinenode removed
  2379. * aktexit2label removed, fast exit removed
  2380. + tcallnode.inlined_pass_2 added
  2381. Revision 1.161 2003/05/25 11:34:17 peter
  2382. * methodpointer self pushing fixed
  2383. Revision 1.160 2003/05/25 08:59:16 peter
  2384. * inline fixes
  2385. Revision 1.159 2003/05/24 17:16:37 jonas
  2386. * added missing firstpass for callparatemp code
  2387. Revision 1.158 2003/05/23 14:27:35 peter
  2388. * remove some unit dependencies
  2389. * current_procinfo changes to store more info
  2390. Revision 1.157 2003/05/17 14:05:58 jonas
  2391. * fixed callparatemp for ansi/widestring and interfacecoms
  2392. Revision 1.156 2003/05/17 13:30:08 jonas
  2393. * changed tt_persistant to tt_persistent :)
  2394. * tempcreatenode now doesn't accept a boolean anymore for persistent
  2395. temps, but a ttemptype, so you can also create ansistring temps etc
  2396. Revision 1.155 2003/05/16 14:33:31 peter
  2397. * regvar fixes
  2398. Revision 1.154 2003/05/14 19:35:50 jonas
  2399. * fixed callparatemp so it works with vs_var, vs_out and formal const
  2400. parameters
  2401. Revision 1.153 2003/05/13 20:53:41 peter
  2402. * constructors return in register
  2403. Revision 1.152 2003/05/13 15:18:49 peter
  2404. * fixed various crashes
  2405. Revision 1.151 2003/05/11 21:37:03 peter
  2406. * moved implicit exception frame from ncgutil to psub
  2407. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2408. Revision 1.150 2003/05/11 14:45:12 peter
  2409. * tloadnode does not support objectsymtable,withsymtable anymore
  2410. * withnode cleanup
  2411. * direct with rewritten to use temprefnode
  2412. Revision 1.149 2003/05/09 17:47:02 peter
  2413. * self moved to hidden parameter
  2414. * removed hdisposen,hnewn,selfn
  2415. Revision 1.148 2003/05/05 14:53:16 peter
  2416. * vs_hidden replaced by is_hidden boolean
  2417. Revision 1.147 2003/04/27 11:21:33 peter
  2418. * aktprocdef renamed to current_procinfo.procdef
  2419. * procinfo renamed to current_procinfo
  2420. * procinfo will now be stored in current_module so it can be
  2421. cleaned up properly
  2422. * gen_main_procsym changed to create_main_proc and release_main_proc
  2423. to also generate a tprocinfo structure
  2424. * fixed unit implicit initfinal
  2425. Revision 1.146 2003/04/27 09:08:44 jonas
  2426. * do callparatemp stuff only after the parameters have been firstpassed,
  2427. because some nodes are turned into calls during the firstpass
  2428. Revision 1.145 2003/04/27 07:29:50 peter
  2429. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2430. a new procdef declaration
  2431. * aktprocsym removed
  2432. * lexlevel removed, use symtable.symtablelevel instead
  2433. * implicit init/final code uses the normal genentry/genexit
  2434. * funcret state checking updated for new funcret handling
  2435. Revision 1.144 2003/04/25 20:59:33 peter
  2436. * removed funcretn,funcretsym, function result is now in varsym
  2437. and aliases for result and function name are added using absolutesym
  2438. * vs_hidden parameter for funcret passed in parameter
  2439. * vs_hidden fixes
  2440. * writenode changed to printnode and released from extdebug
  2441. * -vp option added to generate a tree.log with the nodetree
  2442. * nicer printnode for statements, callnode
  2443. Revision 1.143 2002/04/25 20:15:39 florian
  2444. * block nodes within expressions shouldn't release the used registers,
  2445. fixed using a flag till the new rg is ready
  2446. Revision 1.142 2003/04/23 20:16:04 peter
  2447. + added currency support based on int64
  2448. + is_64bit for use in cg units instead of is_64bitint
  2449. * removed cgmessage from n386add, replace with internalerrors
  2450. Revision 1.141 2003/04/23 13:21:06 peter
  2451. * fix warning for calling constructor inside constructor
  2452. Revision 1.140 2003/04/23 12:35:34 florian
  2453. * fixed several issues with powerpc
  2454. + applied a patch from Jonas for nested function calls (PowerPC only)
  2455. * ...
  2456. Revision 1.139 2003/04/22 23:50:22 peter
  2457. * firstpass uses expectloc
  2458. * checks if there are differences between the expectloc and
  2459. location.loc from secondpass in EXTDEBUG
  2460. Revision 1.138 2003/04/22 09:53:33 peter
  2461. * fix insert_typeconv to handle new varargs which don't have a
  2462. paraitem set
  2463. Revision 1.137 2003/04/11 16:02:05 peter
  2464. * don't firstpass typen
  2465. Revision 1.136 2003/04/11 15:51:04 peter
  2466. * support subscript,vec for setting methodpointer varstate
  2467. Revision 1.135 2003/04/10 17:57:52 peter
  2468. * vs_hidden released
  2469. Revision 1.134 2003/04/07 11:58:22 jonas
  2470. * more vs_invisible fixes
  2471. Revision 1.133 2003/04/07 10:40:21 jonas
  2472. * fixed VS_HIDDEN for high parameter so it works again
  2473. Revision 1.132 2003/04/04 15:38:56 peter
  2474. * moved generic code from n386cal to ncgcal, i386 now also
  2475. uses the generic ncgcal
  2476. Revision 1.131 2003/03/17 18:54:23 peter
  2477. * fix missing self setting for method to procvar conversion in
  2478. tp_procvar mode
  2479. Revision 1.130 2003/03/17 16:54:41 peter
  2480. * support DefaultHandler and anonymous inheritance fixed
  2481. for message methods
  2482. Revision 1.129 2003/03/17 15:54:22 peter
  2483. * store symoptions also for procdef
  2484. * check symoptions (private,public) when calculating possible
  2485. overload candidates
  2486. Revision 1.128 2003/02/19 22:00:14 daniel
  2487. * Code generator converted to new register notation
  2488. - Horribily outdated todo.txt removed
  2489. Revision 1.127 2003/01/16 22:13:52 peter
  2490. * convert_l3 convertlevel added. This level is used for conversions
  2491. where information can be lost like converting widestring->ansistring
  2492. or dword->byte
  2493. Revision 1.126 2003/01/15 01:44:32 peter
  2494. * merged methodpointer fixes from 1.0.x
  2495. Revision 1.125 2003/01/12 17:52:07 peter
  2496. * only check for auto inherited in objectsymtable
  2497. Revision 1.124 2003/01/09 21:45:46 peter
  2498. * extended information about overloaded candidates when compiled
  2499. with EXTDEBUG
  2500. Revision 1.123 2002/12/26 18:24:33 jonas
  2501. * fixed check for whether or not a high parameter was already generated
  2502. * no type checking/conversions for invisible parameters
  2503. Revision 1.122 2002/12/15 22:50:00 florian
  2504. + some stuff for the new hidden parameter handling added
  2505. Revision 1.121 2002/12/15 21:34:15 peter
  2506. * give sign difference between ordinals a small penalty. This is
  2507. needed to get word->[longword|longint] working
  2508. Revision 1.120 2002/12/15 21:30:12 florian
  2509. * tcallnode.paraitem introduced, all references to defcoll removed
  2510. Revision 1.119 2002/12/15 20:59:58 peter
  2511. * fix crash with default parameters
  2512. Revision 1.118 2002/12/15 11:26:02 peter
  2513. * ignore vs_hidden parameters when choosing overloaded proc
  2514. Revision 1.117 2002/12/11 22:42:28 peter
  2515. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2516. the old code. The new code collects the information about possible
  2517. candidates only once resultting in much less calls to type compare
  2518. routines
  2519. Revision 1.116 2002/12/07 14:27:07 carl
  2520. * 3% memory optimization
  2521. * changed some types
  2522. + added type checking with different size for call node and for
  2523. parameters
  2524. Revision 1.115 2002/12/06 17:51:10 peter
  2525. * merged cdecl and array fixes
  2526. Revision 1.114 2002/12/06 16:56:58 peter
  2527. * only compile cs_fp_emulation support when cpufpuemu is defined
  2528. * define cpufpuemu for m68k only
  2529. Revision 1.113 2002/11/27 20:04:38 peter
  2530. * cdecl array of const fixes
  2531. Revision 1.112 2002/11/27 15:33:46 peter
  2532. * the never ending story of tp procvar hacks
  2533. Revision 1.111 2002/11/27 02:31:17 peter
  2534. * fixed inlinetree parsing in det_resulttype
  2535. Revision 1.110 2002/11/25 18:43:32 carl
  2536. - removed the invalid if <> checking (Delphi is strange on this)
  2537. + implemented abstract warning on instance creation of class with
  2538. abstract methods.
  2539. * some error message cleanups
  2540. Revision 1.109 2002/11/25 17:43:17 peter
  2541. * splitted defbase in defutil,symutil,defcmp
  2542. * merged isconvertable and is_equal into compare_defs(_ext)
  2543. * made operator search faster by walking the list only once
  2544. Revision 1.108 2002/11/18 17:31:54 peter
  2545. * pass proccalloption to ret_in_xxx and push_xxx functions
  2546. Revision 1.107 2002/11/15 01:58:50 peter
  2547. * merged changes from 1.0.7 up to 04-11
  2548. - -V option for generating bug report tracing
  2549. - more tracing for option parsing
  2550. - errors for cdecl and high()
  2551. - win32 import stabs
  2552. - win32 records<=8 are returned in eax:edx (turned off by default)
  2553. - heaptrc update
  2554. - more info for temp management in .s file with EXTDEBUG
  2555. Revision 1.106 2002/10/14 18:20:30 carl
  2556. * var parameter checking for classes and interfaces in Delphi mode
  2557. Revision 1.105 2002/10/06 21:02:17 peter
  2558. * fixed limit checking for qword
  2559. Revision 1.104 2002/10/05 15:15:45 peter
  2560. * Write unknwon compiler proc using Comment and only in Extdebug
  2561. Revision 1.103 2002/10/05 12:43:25 carl
  2562. * fixes for Delphi 6 compilation
  2563. (warning : Some features do not work under Delphi)
  2564. Revision 1.102 2002/10/05 00:48:57 peter
  2565. * support inherited; support for overload as it is handled by
  2566. delphi. This is only for delphi mode as it is working is
  2567. undocumented and hard to predict what is done
  2568. Revision 1.101 2002/09/16 14:11:12 peter
  2569. * add argument to equal_paras() to support default values or not
  2570. Revision 1.100 2002/09/15 17:49:59 peter
  2571. * don't have strict var parameter checking for procedures in the
  2572. system unit
  2573. Revision 1.99 2002/09/09 19:30:34 peter
  2574. * don't allow convertable parameters for var and out parameters in
  2575. delphi and tp mode
  2576. Revision 1.98 2002/09/07 15:25:02 peter
  2577. * old logs removed and tabs fixed
  2578. Revision 1.97 2002/09/07 12:16:05 carl
  2579. * second part bug report 1996 fix, testrange in cordconstnode
  2580. only called if option is set (also make parsing a tiny faster)
  2581. Revision 1.96 2002/09/05 14:53:41 peter
  2582. * fixed old callnode.det_resulttype code
  2583. * old ncal code is default again
  2584. Revision 1.95 2002/09/03 21:32:49 daniel
  2585. * Small bugfix for procdef selection
  2586. Revision 1.94 2002/09/03 19:27:22 daniel
  2587. * Activated new ncal code
  2588. Revision 1.93 2002/09/03 16:26:26 daniel
  2589. * Make Tprocdef.defs protected
  2590. Revision 1.92 2002/09/01 13:28:37 daniel
  2591. - write_access fields removed in favor of a flag
  2592. Revision 1.91 2002/09/01 12:14:15 peter
  2593. * remove debug line
  2594. * containself methods can be called directly
  2595. Revision 1.90 2002/09/01 08:01:16 daniel
  2596. * Removed sets from Tcallnode.det_resulttype
  2597. + Added read/write notifications of variables. These will be usefull
  2598. for providing information for several optimizations. For example
  2599. the value of the loop variable of a for loop does matter is the
  2600. variable is read after the for loop, but if it's no longer used
  2601. or written, it doesn't matter and this can be used to optimize
  2602. the loop code generation.
  2603. Revision 1.89 2002/08/23 16:13:16 peter
  2604. * also firstpass funcretrefnode if available. This was breaking the
  2605. asnode compilerproc code
  2606. Revision 1.88 2002/08/20 10:31:26 daniel
  2607. * Tcallnode.det_resulttype rewritten
  2608. Revision 1.87 2002/08/19 19:36:42 peter
  2609. * More fixes for cross unit inlining, all tnodes are now implemented
  2610. * Moved pocall_internconst to po_internconst because it is not a
  2611. calling type at all and it conflicted when inlining of these small
  2612. functions was requested
  2613. Revision 1.86 2002/08/17 22:09:44 florian
  2614. * result type handling in tcgcal.pass_2 overhauled
  2615. * better tnode.dowrite
  2616. * some ppc stuff fixed
  2617. Revision 1.85 2002/08/17 09:23:34 florian
  2618. * first part of current_procinfo rewrite
  2619. Revision 1.84 2002/08/16 14:24:57 carl
  2620. * issameref() to test if two references are the same (then emit no opcodes)
  2621. + ret_in_reg to replace ret_in_acc
  2622. (fix some register allocation bugs at the same time)
  2623. + save_std_register now has an extra parameter which is the
  2624. usedinproc registers
  2625. Revision 1.83 2002/07/20 11:57:53 florian
  2626. * types.pas renamed to defbase.pas because D6 contains a types
  2627. unit so this would conflicts if D6 programms are compiled
  2628. + Willamette/SSE2 instructions to assembler added
  2629. Revision 1.82 2002/07/19 11:41:35 daniel
  2630. * State tracker work
  2631. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2632. allows the state tracker to change while nodes automatically into
  2633. repeat nodes.
  2634. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2635. 'not(a>b)' is optimized into 'a<=b'.
  2636. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2637. by removing the notn and later switchting the true and falselabels. The
  2638. same is done with 'repeat until not a'.
  2639. Revision 1.81 2002/07/15 18:03:14 florian
  2640. * readded removed changes
  2641. Revision 1.79 2002/07/11 14:41:27 florian
  2642. * start of the new generic parameter handling
  2643. Revision 1.80 2002/07/14 18:00:43 daniel
  2644. + Added the beginning of a state tracker. This will track the values of
  2645. variables through procedures and optimize things away.
  2646. Revision 1.78 2002/07/04 20:43:00 florian
  2647. * first x86-64 patches
  2648. }