ncal.pas 122 KB

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