ncal.pas 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746
  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. { define nice_ncal}
  21. interface
  22. uses
  23. node,
  24. {$ifdef state_tracking}
  25. nstate,
  26. {$endif state_tracking}
  27. symbase,symtype,symppu,symsym,symdef,symtable;
  28. type
  29. tcallnode = class(tbinarynode)
  30. { the symbol containing the definition of the procedure }
  31. { to call }
  32. symtableprocentry : tprocsym;
  33. { the symtable containing symtableprocentry }
  34. symtableproc : tsymtable;
  35. { the definition of the procedure to call }
  36. procdefinition : tabstractprocdef;
  37. methodpointer : tnode;
  38. { separately specified resulttype for some compilerprocs (e.g. }
  39. { you can't have a function with an "array of char" resulttype }
  40. { the RTL) (JM) }
  41. restype: ttype;
  42. restypeset: boolean;
  43. { function return reference node, this is used to pass an already
  44. allocated reference for a ret_in_param return value }
  45. funcretrefnode : tnode;
  46. { only the processor specific nodes need to override this }
  47. { constructor }
  48. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  49. constructor createintern(const name: string; params: tnode);
  50. constructor createinternres(const name: string; params: tnode; const res: ttype);
  51. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  52. destructor destroy;override;
  53. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  54. procedure ppuwrite(ppufile:tcompilerppufile);override;
  55. procedure derefimpl;override;
  56. function getcopy : tnode;override;
  57. procedure insertintolist(l : tnodelist);override;
  58. function pass_1 : tnode;override;
  59. {$ifdef nice_ncal}
  60. function choose_definition_to_call(paralength:byte;var errorexit:boolean):Tnode;
  61. {$endif}
  62. function det_resulttype:tnode;override;
  63. {$ifdef state_tracking}
  64. function track_state_pass(exec_known:boolean):boolean;override;
  65. {$endif state_tracking}
  66. function docompare(p: tnode): boolean; override;
  67. procedure set_procvar(procvar:tnode);
  68. end;
  69. tcallnodeclass = class of tcallnode;
  70. tcallparaflags = (
  71. { flags used by tcallparanode }
  72. cpf_exact_match_found,
  73. cpf_convlevel1found,
  74. cpf_convlevel2found,
  75. cpf_is_colon_para
  76. {$ifdef nice_ncal}
  77. ,cpf_nomatchfound
  78. {$endif}
  79. );
  80. tcallparanode = class(tbinarynode)
  81. callparaflags : set of tcallparaflags;
  82. hightree : tnode;
  83. { only the processor specific nodes need to override this }
  84. { constructor }
  85. constructor create(expr,next : tnode);virtual;
  86. destructor destroy;override;
  87. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  88. procedure ppuwrite(ppufile:tcompilerppufile);override;
  89. procedure derefimpl;override;
  90. function getcopy : tnode;override;
  91. procedure insertintolist(l : tnodelist);override;
  92. procedure gen_high_tree(openstring:boolean);
  93. procedure get_paratype;
  94. procedure insert_typeconv(defcoll : tparaitem;do_count : boolean);
  95. procedure det_registers;
  96. procedure firstcallparan(defcoll : tparaitem;do_count : boolean);
  97. procedure secondcallparan(defcoll : tparaitem;
  98. push_from_left_to_right,inlined,is_cdecl : boolean;
  99. para_alignment,para_offset : longint);virtual;abstract;
  100. function docompare(p: tnode): boolean; override;
  101. end;
  102. tcallparanodeclass = class of tcallparanode;
  103. tprocinlinenode = class(tnode)
  104. inlinetree : tnode;
  105. inlineprocdef : tprocdef;
  106. retoffset,para_offset,para_size : longint;
  107. constructor create(p:tprocdef);virtual;
  108. destructor destroy;override;
  109. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  110. procedure ppuwrite(ppufile:tcompilerppufile);override;
  111. procedure derefimpl;override;
  112. function getcopy : tnode;override;
  113. function det_resulttype : tnode;override;
  114. procedure insertintolist(l : tnodelist);override;
  115. function pass_1 : tnode;override;
  116. function docompare(p: tnode): boolean; override;
  117. end;
  118. tprocinlinenodeclass = class of tprocinlinenode;
  119. function reverseparameters(p: tcallparanode): tcallparanode;
  120. var
  121. ccallnode : tcallnodeclass;
  122. ccallparanode : tcallparanodeclass;
  123. cprocinlinenode : tprocinlinenodeclass;
  124. implementation
  125. uses
  126. cutils,globtype,systems,
  127. verbose,globals,
  128. symconst,paramgr,defbase,
  129. htypechk,pass_1,cpuinfo,cpubase,
  130. nbas,ncnv,nld,ninl,nadd,ncon,
  131. rgobj,cgbase
  132. ;
  133. {****************************************************************************
  134. HELPERS
  135. ****************************************************************************}
  136. function reverseparameters(p: tcallparanode): tcallparanode;
  137. var
  138. hp1, hp2: tcallparanode;
  139. begin
  140. hp1:=nil;
  141. while assigned(p) do
  142. begin
  143. { pull out }
  144. hp2:=p;
  145. p:=tcallparanode(p.right);
  146. { pull in }
  147. hp2.right:=hp1;
  148. hp1:=hp2;
  149. end;
  150. reverseparameters:=hp1;
  151. end;
  152. procedure search_class_overloads(aprocsym : tprocsym);
  153. { searches n in symtable of pd and all anchestors }
  154. var
  155. speedvalue : cardinal;
  156. srsym : tprocsym;
  157. s : string;
  158. srpdl : pprocdeflist;
  159. objdef : tobjectdef;
  160. begin
  161. if aprocsym.overloadchecked then
  162. exit;
  163. aprocsym.overloadchecked:=true;
  164. if (aprocsym.owner.symtabletype<>objectsymtable) then
  165. internalerror(200111021);
  166. objdef:=tobjectdef(aprocsym.owner.defowner);
  167. { we start in the parent }
  168. if not assigned(objdef.childof) then
  169. exit;
  170. objdef:=objdef.childof;
  171. s:=aprocsym.name;
  172. speedvalue:=getspeedvalue(s);
  173. while assigned(objdef) do
  174. begin
  175. srsym:=tprocsym(objdef.symtable.speedsearch(s,speedvalue));
  176. if assigned(srsym) then
  177. begin
  178. if (srsym.typ<>procsym) then
  179. internalerror(200111022);
  180. if srsym.is_visible_for_proc(aktprocdef) then
  181. begin
  182. srsym.add_para_match_to(Aprocsym);
  183. { we can stop if the overloads were already added
  184. for the found symbol }
  185. if srsym.overloadchecked then
  186. break;
  187. end;
  188. end;
  189. { next parent }
  190. objdef:=objdef.childof;
  191. end;
  192. end;
  193. {****************************************************************************
  194. TCALLPARANODE
  195. ****************************************************************************}
  196. constructor tcallparanode.create(expr,next : tnode);
  197. begin
  198. inherited create(callparan,expr,next);
  199. hightree:=nil;
  200. if assigned(expr) then
  201. expr.set_file_line(self);
  202. callparaflags:=[];
  203. end;
  204. destructor tcallparanode.destroy;
  205. begin
  206. hightree.free;
  207. inherited destroy;
  208. end;
  209. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  210. begin
  211. inherited ppuload(t,ppufile);
  212. ppufile.getsmallset(callparaflags);
  213. hightree:=ppuloadnode(ppufile);
  214. end;
  215. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  216. begin
  217. inherited ppuwrite(ppufile);
  218. ppufile.putsmallset(callparaflags);
  219. ppuwritenode(ppufile,hightree);
  220. end;
  221. procedure tcallparanode.derefimpl;
  222. begin
  223. inherited derefimpl;
  224. if assigned(hightree) then
  225. hightree.derefimpl;
  226. end;
  227. function tcallparanode.getcopy : tnode;
  228. var
  229. n : tcallparanode;
  230. begin
  231. n:=tcallparanode(inherited getcopy);
  232. n.callparaflags:=callparaflags;
  233. if assigned(hightree) then
  234. n.hightree:=hightree.getcopy
  235. else
  236. n.hightree:=nil;
  237. result:=n;
  238. end;
  239. procedure tcallparanode.insertintolist(l : tnodelist);
  240. begin
  241. end;
  242. procedure tcallparanode.get_paratype;
  243. var
  244. old_get_para_resulttype : boolean;
  245. old_array_constructor : boolean;
  246. begin
  247. inc(parsing_para_level);
  248. if assigned(right) then
  249. tcallparanode(right).get_paratype;
  250. old_array_constructor:=allow_array_constructor;
  251. old_get_para_resulttype:=get_para_resulttype;
  252. get_para_resulttype:=true;
  253. allow_array_constructor:=true;
  254. resulttypepass(left);
  255. get_para_resulttype:=old_get_para_resulttype;
  256. allow_array_constructor:=old_array_constructor;
  257. if codegenerror then
  258. resulttype:=generrortype
  259. else
  260. resulttype:=left.resulttype;
  261. dec(parsing_para_level);
  262. end;
  263. function is_var_para_incompatible(from_def,to_def:Tdef):boolean;
  264. {Might be an idea to move this to defbase...}
  265. begin
  266. is_var_para_incompatible:=
  267. { allows conversion from word to integer and
  268. byte to shortint, but only for TP7 compatibility }
  269. (not(
  270. (m_tp7 in aktmodeswitches) and
  271. (from_def.deftype=orddef) and
  272. (to_def.deftype=orddef) and
  273. (from_def.size=to_def.size)
  274. ) and
  275. { an implicit pointer conversion is allowed }
  276. not(
  277. (from_def.deftype=pointerdef) and
  278. (to_def.deftype=pointerdef)
  279. ) and
  280. { child classes can be also passed }
  281. not(
  282. (from_def.deftype=objectdef) and
  283. (to_def.deftype=objectdef) and
  284. tobjectdef(from_def).is_related(tobjectdef(to_def))
  285. ) and
  286. { passing a single element to a openarray of the same type }
  287. not(
  288. (is_open_array(to_def) and
  289. is_equal(tarraydef(to_def).elementtype.def,from_def))
  290. ) and
  291. { an implicit file conversion is also allowed }
  292. { from a typed file to an untyped one }
  293. not(
  294. (from_def.deftype=filedef) and
  295. (to_def.deftype=filedef) and
  296. (tfiledef(to_def).filetyp = ft_untyped) and
  297. (tfiledef(from_def).filetyp = ft_typed)
  298. ) and
  299. not(is_equal(from_def,to_def)));
  300. end;
  301. procedure tcallparanode.insert_typeconv(defcoll : tparaitem;do_count : boolean);
  302. var
  303. oldtype : ttype;
  304. {$ifdef extdebug}
  305. store_count_ref : boolean;
  306. {$endif def extdebug}
  307. p1 : tnode;
  308. begin
  309. inc(parsing_para_level);
  310. if not assigned(defcoll) then
  311. internalerror(200104261);
  312. {$ifdef extdebug}
  313. if do_count then
  314. begin
  315. store_count_ref:=count_ref;
  316. count_ref:=true;
  317. end;
  318. {$endif def extdebug}
  319. if assigned(right) then
  320. begin
  321. { if we are a para that belongs to varargs then keep
  322. the current defcoll }
  323. if (nf_varargs_para in flags) then
  324. tcallparanode(right).insert_typeconv(defcoll,do_count)
  325. else
  326. tcallparanode(right).insert_typeconv(tparaitem(defcoll.next),do_count);
  327. end;
  328. { Be sure to have the resulttype }
  329. if not assigned(left.resulttype.def) then
  330. resulttypepass(left);
  331. { Handle varargs directly, no typeconvs or typechecking needed }
  332. if (nf_varargs_para in flags) then
  333. begin
  334. { convert pascal to C types }
  335. case left.resulttype.def.deftype of
  336. stringdef :
  337. inserttypeconv(left,charpointertype);
  338. floatdef :
  339. inserttypeconv(left,s64floattype);
  340. end;
  341. set_varstate(left,true);
  342. resulttype:=left.resulttype;
  343. dec(parsing_para_level);
  344. exit;
  345. end;
  346. { Do we need arrayconstructor -> set conversion, then insert
  347. it here before the arrayconstructor node breaks the tree
  348. with its conversions of enum->ord }
  349. if (left.nodetype=arrayconstructorn) and
  350. (defcoll.paratype.def.deftype=setdef) then
  351. inserttypeconv(left,defcoll.paratype);
  352. { set some settings needed for arrayconstructor }
  353. if is_array_constructor(left.resulttype.def) then
  354. begin
  355. if is_array_of_const(defcoll.paratype.def) then
  356. begin
  357. if assigned(aktcallprocdef) and
  358. (aktcallprocdef.proccalloption in [pocall_cppdecl,pocall_cdecl]) and
  359. (po_external in aktcallprocdef.procoptions) then
  360. include(left.flags,nf_cargs);
  361. { force variant array }
  362. include(left.flags,nf_forcevaria);
  363. end
  364. else
  365. begin
  366. include(left.flags,nf_novariaallowed);
  367. { now that the resultting type is know we can insert the required
  368. typeconvs for the array constructor }
  369. tarrayconstructornode(left).force_type(tarraydef(defcoll.paratype.def).elementtype);
  370. end;
  371. end;
  372. { check if local proc/func is assigned to procvar }
  373. if left.resulttype.def.deftype=procvardef then
  374. test_local_to_procvar(tprocvardef(left.resulttype.def),defcoll.paratype.def);
  375. { generate the high() value tree }
  376. if not(assigned(aktcallprocdef) and
  377. (aktcallprocdef.proccalloption in [pocall_cppdecl,pocall_cdecl]) and
  378. (po_external in aktcallprocdef.procoptions)) and
  379. paramanager.push_high_param(defcoll.paratype.def) then
  380. gen_high_tree(is_open_string(defcoll.paratype.def));
  381. { test conversions }
  382. if not(is_shortstring(left.resulttype.def) and
  383. is_shortstring(defcoll.paratype.def)) and
  384. (defcoll.paratype.def.deftype<>formaldef) then
  385. begin
  386. if (defcoll.paratyp in [vs_var,vs_out]) and
  387. is_var_para_incompatible(left.resulttype.def,defcoll.paratype.def) then
  388. begin
  389. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  390. left.resulttype.def.typename,defcoll.paratype.def.typename);
  391. end;
  392. { Process open parameters }
  393. if paramanager.push_high_param(defcoll.paratype.def) then
  394. begin
  395. { insert type conv but hold the ranges of the array }
  396. oldtype:=left.resulttype;
  397. inserttypeconv(left,defcoll.paratype);
  398. left.resulttype:=oldtype;
  399. end
  400. else
  401. begin
  402. inserttypeconv(left,defcoll.paratype);
  403. end;
  404. if codegenerror then
  405. begin
  406. dec(parsing_para_level);
  407. exit;
  408. end;
  409. end;
  410. { check var strings }
  411. if (cs_strict_var_strings in aktlocalswitches) and
  412. is_shortstring(left.resulttype.def) and
  413. is_shortstring(defcoll.paratype.def) and
  414. (defcoll.paratyp in [vs_out,vs_var]) and
  415. not(is_open_string(defcoll.paratype.def)) and
  416. not(is_equal(left.resulttype.def,defcoll.paratype.def)) then
  417. begin
  418. aktfilepos:=left.fileinfo;
  419. CGMessage(type_e_strict_var_string_violation);
  420. end;
  421. { Handle formal parameters separate }
  422. if (defcoll.paratype.def.deftype=formaldef) then
  423. begin
  424. { load procvar if a procedure is passed }
  425. if (m_tp_procvar in aktmodeswitches) and
  426. (left.nodetype=calln) and
  427. (is_void(left.resulttype.def)) then
  428. begin
  429. p1:=cloadnode.create_procvar(tcallnode(left).symtableprocentry,
  430. tprocdef(tcallnode(left).procdefinition),tcallnode(left).symtableproc);
  431. if assigned(tcallnode(left).right) then
  432. tloadnode(p1).set_mp(tcallnode(left).right);
  433. left.free;
  434. left:=p1;
  435. resulttypepass(left);
  436. end;
  437. case defcoll.paratyp of
  438. vs_var,
  439. vs_out :
  440. begin
  441. if not valid_for_formal_var(left) then
  442. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  443. end;
  444. vs_const :
  445. begin
  446. if not valid_for_formal_const(left) then
  447. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  448. end;
  449. end;
  450. end
  451. else
  452. begin
  453. { check if the argument is allowed }
  454. if (defcoll.paratyp in [vs_out,vs_var]) then
  455. valid_for_var(left);
  456. end;
  457. if defcoll.paratyp in [vs_var,vs_const] then
  458. begin
  459. { Causes problems with const ansistrings if also }
  460. { done for vs_const (JM) }
  461. if defcoll.paratyp = vs_var then
  462. set_unique(left);
  463. make_not_regable(left);
  464. end;
  465. { ansistrings out paramaters doesn't need to be }
  466. { unique, they are finalized }
  467. if defcoll.paratyp=vs_out then
  468. make_not_regable(left);
  469. if do_count then
  470. begin
  471. { not completly proper, but avoids some warnings }
  472. if (defcoll.paratyp in [vs_var,vs_out]) then
  473. set_funcret_is_valid(left);
  474. set_varstate(left,not(defcoll.paratyp in [vs_var,vs_out]));
  475. end;
  476. { must only be done after typeconv PM }
  477. resulttype:=defcoll.paratype;
  478. dec(parsing_para_level);
  479. {$ifdef extdebug}
  480. if do_count then
  481. count_ref:=store_count_ref;
  482. {$endif def extdebug}
  483. end;
  484. procedure tcallparanode.det_registers;
  485. var
  486. old_get_para_resulttype : boolean;
  487. old_array_constructor : boolean;
  488. begin
  489. if assigned(right) then
  490. begin
  491. tcallparanode(right).det_registers;
  492. registers32:=right.registers32;
  493. registersfpu:=right.registersfpu;
  494. {$ifdef SUPPORT_MMX}
  495. registersmmx:=right.registersmmx;
  496. {$endif}
  497. end;
  498. old_array_constructor:=allow_array_constructor;
  499. old_get_para_resulttype:=get_para_resulttype;
  500. get_para_resulttype:=true;
  501. allow_array_constructor:=true;
  502. firstpass(left);
  503. get_para_resulttype:=old_get_para_resulttype;
  504. allow_array_constructor:=old_array_constructor;
  505. if left.registers32>registers32 then
  506. registers32:=left.registers32;
  507. if left.registersfpu>registersfpu then
  508. registersfpu:=left.registersfpu;
  509. {$ifdef SUPPORT_MMX}
  510. if left.registersmmx>registersmmx then
  511. registersmmx:=left.registersmmx;
  512. {$endif SUPPORT_MMX}
  513. end;
  514. procedure tcallparanode.firstcallparan(defcoll : tparaitem;do_count : boolean);
  515. begin
  516. if not assigned(left.resulttype.def) then
  517. begin
  518. get_paratype;
  519. if assigned(defcoll) then
  520. insert_typeconv(defcoll,do_count);
  521. end;
  522. det_registers;
  523. end;
  524. procedure tcallparanode.gen_high_tree(openstring:boolean);
  525. var
  526. temp: tnode;
  527. len : integer;
  528. loadconst : boolean;
  529. begin
  530. if assigned(hightree) then
  531. exit;
  532. len:=-1;
  533. loadconst:=true;
  534. case left.resulttype.def.deftype of
  535. arraydef :
  536. begin
  537. { handle via a normal inline in_high_x node }
  538. loadconst := false;
  539. hightree := geninlinenode(in_high_x,false,left.getcopy);
  540. { only substract low(array) if it's <> 0 }
  541. temp := geninlinenode(in_low_x,false,left.getcopy);
  542. firstpass(temp);
  543. if (temp.nodetype <> ordconstn) or
  544. (tordconstnode(temp).value <> 0) then
  545. hightree := caddnode.create(subn,hightree,temp)
  546. else
  547. temp.free;
  548. end;
  549. stringdef :
  550. begin
  551. if openstring then
  552. begin
  553. { handle via a normal inline in_high_x node }
  554. loadconst := false;
  555. hightree := geninlinenode(in_high_x,false,left.getcopy);
  556. end
  557. else
  558. { passing a string to an array of char }
  559. begin
  560. if (left.nodetype=stringconstn) then
  561. begin
  562. len:=str_length(left);
  563. if len>0 then
  564. dec(len);
  565. end
  566. else
  567. begin
  568. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,left.getcopy),
  569. cordconstnode.create(1,s32bittype,false));
  570. loadconst:=false;
  571. end;
  572. end;
  573. end;
  574. else
  575. len:=0;
  576. end;
  577. if loadconst then
  578. hightree:=cordconstnode.create(len,s32bittype,true)
  579. else
  580. hightree:=ctypeconvnode.create(hightree,s32bittype);
  581. firstpass(hightree);
  582. end;
  583. function tcallparanode.docompare(p: tnode): boolean;
  584. begin
  585. docompare :=
  586. inherited docompare(p) and
  587. (callparaflags = tcallparanode(p).callparaflags) and
  588. hightree.isequal(tcallparanode(p).hightree);
  589. end;
  590. {****************************************************************************
  591. TCALLNODE
  592. ****************************************************************************}
  593. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp : tnode);
  594. begin
  595. inherited create(calln,l,nil);
  596. symtableprocentry:=v;
  597. symtableproc:=st;
  598. include(flags,nf_return_value_used);
  599. methodpointer:=mp;
  600. procdefinition:=nil;
  601. restypeset := false;
  602. funcretrefnode:=nil;
  603. end;
  604. constructor tcallnode.createintern(const name: string; params: tnode);
  605. var
  606. srsym: tsym;
  607. symowner: tsymtable;
  608. begin
  609. if not (cs_compilesystem in aktmoduleswitches) then
  610. begin
  611. srsym := searchsymonlyin(systemunit,name);
  612. symowner := systemunit;
  613. end
  614. else
  615. begin
  616. searchsym(name,srsym,symowner);
  617. if not assigned(srsym) then
  618. searchsym(upper(name),srsym,symowner);
  619. end;
  620. if not assigned(srsym) or
  621. (srsym.typ <> procsym) then
  622. begin
  623. writeln('unknown compilerproc ',name);
  624. internalerror(200107271);
  625. end;
  626. self.create(params,tprocsym(srsym),symowner,nil);
  627. end;
  628. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  629. begin
  630. self.createintern(name,params);
  631. restype := res;
  632. restypeset := true;
  633. { both the normal and specified resulttype either have to be returned via a }
  634. { parameter or not, but no mixing (JM) }
  635. if paramanager.ret_in_param(restype.def) xor paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def) then
  636. internalerror(200108291);
  637. end;
  638. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  639. begin
  640. self.createintern(name,params);
  641. funcretrefnode:=returnnode;
  642. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def) then
  643. internalerror(200204247);
  644. end;
  645. destructor tcallnode.destroy;
  646. begin
  647. methodpointer.free;
  648. funcretrefnode.free;
  649. inherited destroy;
  650. end;
  651. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  652. begin
  653. inherited ppuload(t,ppufile);
  654. symtableprocentry:=tprocsym(ppufile.getderef);
  655. {$ifdef fpc}
  656. {$warning FIXME: No withsymtable support}
  657. {$endif}
  658. symtableproc:=nil;
  659. procdefinition:=tprocdef(ppufile.getderef);
  660. restypeset:=boolean(ppufile.getbyte);
  661. methodpointer:=ppuloadnode(ppufile);
  662. funcretrefnode:=ppuloadnode(ppufile);
  663. end;
  664. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  665. begin
  666. inherited ppuwrite(ppufile);
  667. ppufile.putderef(symtableprocentry);
  668. ppufile.putderef(procdefinition);
  669. ppufile.putbyte(byte(restypeset));
  670. ppuwritenode(ppufile,methodpointer);
  671. ppuwritenode(ppufile,funcretrefnode);
  672. end;
  673. procedure tcallnode.derefimpl;
  674. begin
  675. inherited derefimpl;
  676. resolvesym(pointer(symtableprocentry));
  677. symtableproc:=symtableprocentry.owner;
  678. resolvedef(pointer(procdefinition));
  679. if assigned(methodpointer) then
  680. methodpointer.derefimpl;
  681. if assigned(funcretrefnode) then
  682. funcretrefnode.derefimpl;
  683. end;
  684. procedure tcallnode.set_procvar(procvar:tnode);
  685. begin
  686. right:=procvar;
  687. end;
  688. function tcallnode.getcopy : tnode;
  689. var
  690. n : tcallnode;
  691. begin
  692. n:=tcallnode(inherited getcopy);
  693. n.symtableprocentry:=symtableprocentry;
  694. n.symtableproc:=symtableproc;
  695. n.procdefinition:=procdefinition;
  696. n.restype := restype;
  697. n.restypeset := restypeset;
  698. if assigned(methodpointer) then
  699. n.methodpointer:=methodpointer.getcopy
  700. else
  701. n.methodpointer:=nil;
  702. if assigned(funcretrefnode) then
  703. n.funcretrefnode:=funcretrefnode.getcopy
  704. else
  705. n.funcretrefnode:=nil;
  706. result:=n;
  707. end;
  708. procedure tcallnode.insertintolist(l : tnodelist);
  709. begin
  710. end;
  711. {$ifdef nice_ncal}
  712. function Tcallnode.choose_definition_to_call(paralength:byte;var errorexit:boolean):Tnode;
  713. { check if the resulttype.def from tree p is equal with def, needed
  714. for stringconstn and formaldef }
  715. function is_equal(p:tcallparanode;def:tdef) : boolean;
  716. begin
  717. { safety check }
  718. if not (assigned(def) or assigned(p.resulttype.def)) then
  719. begin
  720. is_equal:=false;
  721. exit;
  722. end;
  723. { all types can be passed to a formaldef }
  724. is_equal:=(def.deftype=formaldef) or
  725. (defbase.is_equal(p.resulttype.def,def))
  726. { integer constants are compatible with all integer parameters if
  727. the specified value matches the range }
  728. or
  729. (
  730. (tbinarynode(p).left.nodetype=ordconstn) and
  731. is_integer(p.resulttype.def) and
  732. is_integer(def) and
  733. (tordconstnode(p.left).value>=torddef(def).low) and
  734. (tordconstnode(p.left).value<=torddef(def).high)
  735. )
  736. { to support ansi/long/wide strings in a proper way }
  737. { string and string[10] are assumed as equal }
  738. { when searching the correct overloaded procedure }
  739. or
  740. (
  741. (def.deftype=stringdef) and (p.resulttype.def.deftype=stringdef) and
  742. (tstringdef(def).string_typ=tstringdef(p.resulttype.def).string_typ)
  743. )
  744. or
  745. (
  746. (p.left.nodetype=stringconstn) and
  747. (is_ansistring(p.resulttype.def) and is_pchar(def))
  748. )
  749. or
  750. (
  751. (p.left.nodetype=ordconstn) and
  752. (is_char(p.resulttype.def) and (is_shortstring(def) or is_ansistring(def)))
  753. )
  754. { set can also be a not yet converted array constructor }
  755. or
  756. (
  757. (def.deftype=setdef) and (p.resulttype.def.deftype=arraydef) and
  758. (tarraydef(p.resulttype.def).IsConstructor) and not(tarraydef(p.resulttype.def).IsVariant)
  759. )
  760. { in tp7 mode proc -> procvar is allowed }
  761. or
  762. (
  763. (m_tp_procvar in aktmodeswitches) and
  764. (def.deftype=procvardef) and (p.left.nodetype=calln) and
  765. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def),false))
  766. )
  767. ;
  768. end;
  769. procedure get_candidate_information(var cl2_count,cl1_count,equal_count,exact_count:byte;
  770. var ordspace:double;
  771. treeparas:Tcallparanode;candparas:Tparaitem);
  772. {Gets information how the parameters would be converted to the candidate.}
  773. var hcvt:Tconverttype;
  774. from_def,to_def:Tdef;
  775. begin
  776. cl2_count:=0;
  777. cl1_count:=0;
  778. equal_count:=0;
  779. exact_count:=0;
  780. ordspace:=0;
  781. while candparas<>nil do
  782. begin
  783. from_def:=treeparas.resulttype.def;
  784. to_def:=candparas.paratype.def;
  785. if to_def=from_def then
  786. inc(exact_count)
  787. { if a type is totally included in the other }
  788. { we don't fear an overflow , }
  789. { so we can do as if it is an equal match }
  790. else if (treeparas.left.nodetype=ordconstn) and is_integer(to_def) then
  791. begin
  792. inc(equal_count);
  793. ordspace:=ordspace+(double(Torddef(from_def).low)-Torddef(to_def).low)+
  794. (double(Torddef(to_def).high)-Torddef(from_def).high);
  795. end
  796. else if ((from_def.deftype=orddef) and (to_def.deftype=orddef)) and
  797. (is_in_limit(from_def,to_def) or
  798. ((candparas.paratyp in [vs_var,vs_out]) and (from_def.size=to_def.size))
  799. ) then
  800. begin
  801. ordspace:=ordspace+Torddef(to_def).high;
  802. ordspace:=ordspace-Torddef(to_def).low;
  803. inc(equal_count);
  804. end
  805. else if is_equal(treeparas,to_def) then
  806. inc(equal_count)
  807. else
  808. case isconvertable(from_def,to_def,
  809. hcvt,treeparas.left.nodetype,false) of
  810. 0:
  811. internalerror(200208021);
  812. 1:
  813. inc(cl1_count);
  814. 2:
  815. inc(cl2_count);
  816. end;
  817. treeparas:=Tcallparanode(treeparas.right);
  818. candparas:=Tparaitem(candparas.next);
  819. end;
  820. end;
  821. type Tcandidate_array=array[1..$ffff] of Tprocdef;
  822. Pcandidate_array=^Tcandidate_array;
  823. var candidate_alloc,candidates_left,candidate_count:cardinal;
  824. c1,c2,delete_start:cardinal;
  825. cl2_count1,cl1_count1,equal_count1,exact_count1:byte;
  826. ordspace1:double;
  827. cl2_count2,cl1_count2,equal_count2,exact_count2:byte;
  828. ordspace2:double;
  829. i,n:cardinal;
  830. pt:Tcallparanode;
  831. def:Tprocdef;
  832. hcvt:Tconverttype;
  833. pdc:Tparaitem;
  834. hpt:Tnode;
  835. srprocsym:Tprocsym;
  836. srsymtable:Tsymtable;
  837. candidate_defs:Pcandidate_array;
  838. begin
  839. if fileinfo.line=398 then
  840. i:=0;
  841. choose_definition_to_call:=nil;
  842. errorexit:=true;
  843. { when the definition has overload directive set, we search for
  844. overloaded definitions in the class, this only needs to be done once
  845. for class entries as the tree keeps always the same }
  846. if (not symtableprocentry.overloadchecked) and
  847. (po_overload in symtableprocentry.first_procdef.procoptions) and
  848. (symtableprocentry.owner.symtabletype=objectsymtable) then
  849. search_class_overloads(symtableprocentry);
  850. {Collect all procedures which have the same # of parameters }
  851. candidates_left:=0;
  852. candidate_count:=0;
  853. candidate_alloc:=32;
  854. getmem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  855. srprocsym:=symtableprocentry;
  856. srsymtable:=symtableprocentry.owner;
  857. repeat
  858. for i:=1 to srprocsym.procdef_count do
  859. begin
  860. def:=srprocsym.procdef[i];
  861. { only when the # of parameters are supported by the procedure }
  862. if (paralength>=def.minparacount) and
  863. ((po_varargs in def.procoptions) or (paralength<=def.maxparacount)) then
  864. begin
  865. candidate_defs^[i]:=def;
  866. inc(candidates_left);
  867. end
  868. else
  869. candidate_defs^[i]:=nil;
  870. inc(candidate_count);
  871. if candidate_alloc=candidate_count then
  872. begin
  873. candidate_alloc:=candidate_alloc*2;
  874. reallocmem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  875. end;
  876. end;
  877. if po_overload in srprocsym.first_procdef.procoptions then
  878. begin
  879. repeat
  880. srprocsym:=nil;
  881. repeat
  882. srsymtable:=srsymtable.next;
  883. until (srsymtable=nil) or (srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable]);
  884. if assigned(srsymtable) then
  885. srprocsym:=Tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  886. until (srsymtable=nil) or (srprocsym<>nil);
  887. if not assigned(srprocsym) then
  888. break;
  889. end
  890. else
  891. break;
  892. until false;
  893. { no procedures found? then there is something wrong
  894. with the parameter size }
  895. if candidates_left=0 then
  896. begin
  897. { in tp mode we can try to convert to procvar if
  898. there are no parameters specified }
  899. if not(assigned(left)) and
  900. (m_tp_procvar in aktmodeswitches) then
  901. begin
  902. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  903. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  904. assigned(methodpointer) then
  905. tloadnode(hpt).set_mp(methodpointer.getcopy);
  906. resulttypepass(hpt);
  907. choose_definition_to_call:=hpt;
  908. end
  909. else
  910. begin
  911. if assigned(left) then
  912. aktfilepos:=left.fileinfo;
  913. cgmessage(parser_e_wrong_parameter_size);
  914. symtableprocentry.write_parameter_lists(nil);
  915. end;
  916. exit;
  917. end;
  918. {Walk through all candidates and remove the ones
  919. that have incompatible parameters.}
  920. for i:=1 to candidate_count do
  921. if assigned(candidate_defs^[i]) then
  922. begin
  923. def:=candidate_defs^[i];
  924. {Walk through all parameters.}
  925. pdc:=Tparaitem(def.para.first);
  926. pt:=Tcallparanode(left);
  927. while assigned(pdc) do
  928. begin
  929. if pdc.paratyp in [vs_var,vs_out] then
  930. if is_var_para_incompatible(pt.resulttype.def,pdc.paratype.def) and
  931. not(is_shortstring(pt.resulttype.def) and is_shortstring(pdc.paratype.def)) and
  932. (pdc.paratype.def.deftype<>formaldef) then
  933. begin
  934. {Not convertable, def is no longer a candidate.}
  935. candidate_defs^[i]:=nil;
  936. dec(candidates_left);
  937. break;
  938. end
  939. else
  940. exclude(pt.callparaflags,cpf_nomatchfound)
  941. else
  942. if (pt.resulttype.def<>pdc.paratype.def) and
  943. ((isconvertable(pt.resulttype.def,pdc.paratype.def,
  944. hcvt,pt.left.nodetype,false)=0) and
  945. not is_equal(pt,pdc.paratype.def)) then
  946. begin
  947. {Not convertable, def is no longer a candidate.}
  948. candidate_defs^[i]:=nil;
  949. dec(candidates_left);
  950. break;
  951. end
  952. else
  953. exclude(pt.callparaflags,cpf_nomatchfound);
  954. pdc:=Tparaitem(pdc.next);
  955. pt:=Tcallparanode(pt.right);
  956. end;
  957. end;
  958. {Are there any candidates left?}
  959. if candidates_left=0 then
  960. begin
  961. {There is an error, must be wrong type, because
  962. wrong size is already checked (PFV) }
  963. pt:=Tcallparanode(left);
  964. n:=0;
  965. while assigned(pt) do
  966. if cpf_nomatchfound in pt.callparaflags then
  967. break
  968. else
  969. begin
  970. pt:=tcallparanode(pt.right);
  971. inc(n);
  972. end;
  973. if not(assigned(pt) and assigned(pt.resulttype.def)) then
  974. internalerror(39393);
  975. {Def contains the last candidate tested.}
  976. pdc:=Tparaitem(def.para.first);
  977. for i:=1 to n do
  978. pdc:=Tparaitem(pdc.next);
  979. aktfilepos:=pt.fileinfo;
  980. cgmessage3(type_e_wrong_parameter_type,tostr(n+1),
  981. pt.resulttype.def.typename,pdc.paratype.def.typename);
  982. symtableprocentry.write_parameter_lists(nil);
  983. exit;
  984. end;
  985. {If there is more candidate that can be called, we have to
  986. find the most suitable one. We collect the following
  987. information:
  988. - Amount of convertlevel 2 parameters.
  989. - Amount of convertlevel 1 parameters.
  990. - Amount of equal parameters.
  991. - Amount of exact parameters.
  992. - Amount of ordinal space the destination parameters
  993. provide. For exampe, a word provides 65535-255=65280
  994. of ordinal space above a byte.
  995. The first criterium is the candidate that has the least
  996. convertlevel 2 parameters. The next criterium is
  997. the candidate that has the most exact parameters, next
  998. criterium is the least ordinal space and
  999. the last criterium is the most equal parameters. (DM)}
  1000. if candidates_left>1 then
  1001. begin
  1002. {Find the first candidate.}
  1003. c1:=1;
  1004. while c1<=candidate_count do
  1005. if assigned(candidate_defs^[c1]) then
  1006. break
  1007. else
  1008. inc(c1);
  1009. delete_start:=c1;
  1010. {Get information about candidate c1.}
  1011. get_candidate_information(cl2_count1,cl1_count1,equal_count1,
  1012. exact_count1,ordspace1,Tcallparanode(left),
  1013. Tparaitem(candidate_defs^[c1].para.first));
  1014. {Find the other candidates and eliminate the lesser ones.}
  1015. c2:=c1+1;
  1016. while c2<=candidate_count do
  1017. if assigned(candidate_defs^[c2]) then
  1018. begin
  1019. {Candidate found, get information on it.}
  1020. get_candidate_information(cl2_count2,cl1_count2,equal_count2,
  1021. exact_count2,ordspace2,Tcallparanode(left),
  1022. Tparaitem(candidate_defs^[c2].para.first));
  1023. {Is c1 the better candidate?}
  1024. if (cl2_count1<cl2_count2) or
  1025. ((cl2_count1=cl2_count2) and (exact_count1>exact_count2)) or
  1026. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1>equal_count2)) or
  1027. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1=equal_count2) and (ordspace1<ordspace2)) then
  1028. {C1 is better, drop c2.}
  1029. candidate_defs^[c2]:=nil
  1030. {Is c2 the better candidate?}
  1031. else if (cl2_count2<cl2_count1) or
  1032. ((cl2_count2=cl2_count1) and (exact_count2>exact_count1)) or
  1033. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2>equal_count1)) or
  1034. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2=equal_count1) and (ordspace2<ordspace1)) then
  1035. begin
  1036. {C2 is better, drop all previous
  1037. candidates.}
  1038. for i:=delete_start to c2-1 do
  1039. candidate_defs^[i]:=nil;
  1040. delete_start:=c2;
  1041. c1:=c2;
  1042. cl2_count1:=cl2_count2;
  1043. cl1_count1:=cl1_count2;
  1044. equal_count1:=equal_count2;
  1045. exact_count1:=exact_count2;
  1046. ordspace1:=ordspace2;
  1047. end;
  1048. {else the candidates have no advantage over each other,
  1049. do nothing}
  1050. inc(c2);
  1051. end
  1052. else
  1053. inc(c2);
  1054. end;
  1055. {Count the candidates that are left.}
  1056. candidates_left:=0;
  1057. for i:=1 to candidate_count do
  1058. if assigned(candidate_defs^[i]) then
  1059. begin
  1060. inc(candidates_left);
  1061. procdefinition:=candidate_defs^[i];
  1062. end;
  1063. if candidates_left>1 then
  1064. begin
  1065. cgmessage(cg_e_cant_choose_overload_function);
  1066. symtableprocentry.write_parameter_lists(nil);
  1067. exit;
  1068. end;
  1069. freemem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  1070. if make_ref then
  1071. begin
  1072. Tprocdef(procdefinition).lastref:=Tref.create(Tprocdef(procdefinition).lastref,@fileinfo);
  1073. inc(Tprocdef(procdefinition).refcount);
  1074. if Tprocdef(procdefinition).defref=nil then
  1075. Tprocdef(procdefinition).defref:=Tprocdef(procdefinition).lastref;
  1076. end;
  1077. { big error for with statements
  1078. symtableproc:=procdefinition.owner;
  1079. but neede for overloaded operators !! }
  1080. if symtableproc=nil then
  1081. symtableproc:=procdefinition.owner;
  1082. errorexit:=false;
  1083. end;
  1084. function tcallnode.det_resulttype:tnode;
  1085. var lastpara,paralength:byte;
  1086. oldcallprocdef:Tabstractprocdef;
  1087. pt:Tcallparanode;
  1088. i,n:byte;
  1089. e,is_const:boolean;
  1090. pdc:Tparaitem;
  1091. hpt:Tnode;
  1092. label errorexit;
  1093. begin
  1094. result:=nil;
  1095. oldcallprocdef:=aktcallprocdef;
  1096. aktcallprocdef:=nil;
  1097. { determine length of parameter list }
  1098. pt:=tcallparanode(left);
  1099. paralength:=0;
  1100. while assigned(pt) do
  1101. begin
  1102. include(pt.callparaflags,cpf_nomatchfound);
  1103. inc(paralength);
  1104. pt:=tcallparanode(pt.right);
  1105. end;
  1106. { determine the type of the parameters }
  1107. if assigned(left) then
  1108. begin
  1109. tcallparanode(left).get_paratype;
  1110. if codegenerror then
  1111. goto errorexit;
  1112. end;
  1113. { procedure variable ? }
  1114. if assigned(right) then
  1115. begin
  1116. set_varstate(right,true);
  1117. resulttypepass(right);
  1118. if codegenerror then
  1119. exit;
  1120. procdefinition:=tabstractprocdef(right.resulttype.def);
  1121. { check the amount of parameters }
  1122. pdc:=tparaitem(procdefinition.Para.first);
  1123. pt:=tcallparanode(left);
  1124. lastpara:=paralength;
  1125. while assigned(pdc) and assigned(pt) do
  1126. begin
  1127. { only goto next para if we're out of the varargs }
  1128. if not(po_varargs in procdefinition.procoptions) or
  1129. (lastpara<=procdefinition.maxparacount) then
  1130. pdc:=tparaitem(pdc.next);
  1131. pt:=tcallparanode(pt.right);
  1132. dec(lastpara);
  1133. end;
  1134. if assigned(pt) or assigned(pdc) then
  1135. begin
  1136. if assigned(pt) then
  1137. aktfilepos:=pt.fileinfo;
  1138. CGMessage(parser_e_wrong_parameter_size);
  1139. end;
  1140. end
  1141. else
  1142. { not a procedure variable }
  1143. begin
  1144. { do we know the procedure to call ? }
  1145. if not(assigned(procdefinition)) then
  1146. begin
  1147. result:=choose_definition_to_call(paralength,e);
  1148. if e then
  1149. goto errorexit;
  1150. end;
  1151. (* To do!!!
  1152. { add needed default parameters }
  1153. if assigned(procdefinition) and
  1154. (paralength<procdefinition.maxparacount) then
  1155. begin
  1156. { add default parameters, just read back the skipped
  1157. paras starting from firstPara.previous, when not available
  1158. (all parameters are default) then start with the last
  1159. parameter and read backward (PFV) }
  1160. if not assigned(procs^.firstpara) then
  1161. pdc:=tparaitem(procs^.data.Para.last)
  1162. else
  1163. pdc:=tparaitem(procs^.firstPara.previous);
  1164. while assigned(pdc) do
  1165. begin
  1166. if not assigned(pdc.defaultvalue) then
  1167. internalerror(751349858);
  1168. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1169. pdc:=tparaitem(pdc.previous);
  1170. end;
  1171. end;
  1172. *)
  1173. end;
  1174. { handle predefined procedures }
  1175. is_const:=(po_internconst in procdefinition.procoptions) and
  1176. ((block_type in [bt_const,bt_type]) or
  1177. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1178. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1179. begin
  1180. if assigned(left) then
  1181. begin
  1182. { ptr and settextbuf needs two args }
  1183. if assigned(tcallparanode(left).right) then
  1184. begin
  1185. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,left);
  1186. left:=nil;
  1187. end
  1188. else
  1189. begin
  1190. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,Tcallparanode(left).left);
  1191. Tcallparanode(left).left:=nil;
  1192. end;
  1193. end
  1194. else
  1195. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,nil);
  1196. result:=hpt;
  1197. goto errorexit;
  1198. end;
  1199. {$ifdef dummy}
  1200. { Calling a message method directly ? }
  1201. if assigned(procdefinition) and
  1202. (po_containsself in procdefinition.procoptions) then
  1203. message(cg_e_cannot_call_message_direct);
  1204. {$endif}
  1205. { ensure that the result type is set }
  1206. if not restypeset then
  1207. resulttype:=procdefinition.rettype
  1208. else
  1209. resulttype:=restype;
  1210. { modify the exit code, in case of special cases }
  1211. if (not is_void(resulttype.def)) then
  1212. begin
  1213. if paramanager.ret_in_acc(resulttype.def) then
  1214. begin
  1215. { wide- and ansistrings are returned in EAX }
  1216. { but they are imm. moved to a memory location }
  1217. if is_widestring(resulttype.def) or
  1218. is_ansistring(resulttype.def) then
  1219. begin
  1220. { we use ansistrings so no fast exit here }
  1221. if assigned(procinfo) then
  1222. procinfo.no_fast_exit:=true;
  1223. end;
  1224. end;
  1225. end;
  1226. { constructors return their current class type, not the type where the
  1227. constructor is declared, this can be different because of inheritance }
  1228. if (procdefinition.proctypeoption=potype_constructor) then
  1229. begin
  1230. if assigned(methodpointer) and
  1231. assigned(methodpointer.resulttype.def) and
  1232. (methodpointer.resulttype.def.deftype=classrefdef) then
  1233. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  1234. end;
  1235. { flag all callparanodes that belong to the varargs }
  1236. if (po_varargs in procdefinition.procoptions) then
  1237. begin
  1238. pt:=tcallparanode(left);
  1239. i:=paralength;
  1240. while (i>procdefinition.maxparacount) do
  1241. begin
  1242. include(tcallparanode(pt).flags,nf_varargs_para);
  1243. pt:=tcallparanode(pt.right);
  1244. dec(i);
  1245. end;
  1246. end;
  1247. { insert type conversions }
  1248. if assigned(left) then
  1249. begin
  1250. aktcallprocdef:=procdefinition;
  1251. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  1252. end;
  1253. errorexit:
  1254. { Reset some settings back }
  1255. aktcallprocdef:=oldcallprocdef;
  1256. end;
  1257. {$else}
  1258. function tcallnode.det_resulttype:tnode;
  1259. type
  1260. pprocdefcoll = ^tprocdefcoll;
  1261. tprocdefcoll = record
  1262. data : tprocdef;
  1263. nextpara : tparaitem;
  1264. firstpara : tparaitem;
  1265. next : pprocdefcoll;
  1266. end;
  1267. var
  1268. hp,procs,hp2 : pprocdefcoll;
  1269. pd : tprocdef;
  1270. oldcallprocdef : tabstractprocdef;
  1271. def_from,def_to,conv_to : tdef;
  1272. hpt : tnode;
  1273. pt : tcallparanode;
  1274. exactmatch : boolean;
  1275. paralength,lastpara : longint;
  1276. lastparatype : tdef;
  1277. pdc : tparaitem;
  1278. { only Dummy }
  1279. hcvt : tconverttype;
  1280. label
  1281. errorexit;
  1282. { check if the resulttype.def from tree p is equal with def, needed
  1283. for stringconstn and formaldef }
  1284. function is_equal(p:tcallparanode;def:tdef) : boolean;
  1285. begin
  1286. { safety check }
  1287. if not (assigned(def) or assigned(p.resulttype.def)) then
  1288. begin
  1289. is_equal:=false;
  1290. exit;
  1291. end;
  1292. { all types can be passed to a formaldef }
  1293. is_equal:=(def.deftype=formaldef) or
  1294. (defbase.is_equal(p.resulttype.def,def))
  1295. { integer constants are compatible with all integer parameters if
  1296. the specified value matches the range }
  1297. or
  1298. (
  1299. (tbinarynode(p).left.nodetype=ordconstn) and
  1300. is_integer(p.resulttype.def) and
  1301. is_integer(def) and
  1302. (tordconstnode(p.left).value>=torddef(def).low) and
  1303. (tordconstnode(p.left).value<=torddef(def).high)
  1304. )
  1305. { to support ansi/long/wide strings in a proper way }
  1306. { string and string[10] are assumed as equal }
  1307. { when searching the correct overloaded procedure }
  1308. or
  1309. (
  1310. (def.deftype=stringdef) and (p.resulttype.def.deftype=stringdef) and
  1311. (tstringdef(def).string_typ=tstringdef(p.resulttype.def).string_typ)
  1312. )
  1313. or
  1314. (
  1315. (p.left.nodetype=stringconstn) and
  1316. (is_ansistring(p.resulttype.def) and is_pchar(def))
  1317. )
  1318. or
  1319. (
  1320. (p.left.nodetype=ordconstn) and
  1321. (is_char(p.resulttype.def) and (is_shortstring(def) or is_ansistring(def)))
  1322. )
  1323. { set can also be a not yet converted array constructor }
  1324. or
  1325. (
  1326. (def.deftype=setdef) and (p.resulttype.def.deftype=arraydef) and
  1327. (tarraydef(p.resulttype.def).IsConstructor) and not(tarraydef(p.resulttype.def).IsVariant)
  1328. )
  1329. { in tp7 mode proc -> procvar is allowed }
  1330. or
  1331. (
  1332. (m_tp_procvar in aktmodeswitches) and
  1333. (def.deftype=procvardef) and (p.left.nodetype=calln) and
  1334. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def),false))
  1335. )
  1336. ;
  1337. end;
  1338. var
  1339. i,j : longint;
  1340. has_overload_directive,
  1341. found,
  1342. is_const : boolean;
  1343. bestord : torddef;
  1344. srprocsym : tprocsym;
  1345. srsymtable : tsymtable;
  1346. begin
  1347. result:=nil;
  1348. procs:=nil;
  1349. has_overload_directive:=false;
  1350. oldcallprocdef:=aktcallprocdef;
  1351. aktcallprocdef:=nil;
  1352. { determine length of parameter list }
  1353. pt:=tcallparanode(left);
  1354. paralength:=0;
  1355. while assigned(pt) do
  1356. begin
  1357. inc(paralength);
  1358. pt:=tcallparanode(pt.right);
  1359. end;
  1360. { determine the type of the parameters }
  1361. if assigned(left) then
  1362. begin
  1363. tcallparanode(left).get_paratype;
  1364. if codegenerror then
  1365. goto errorexit;
  1366. end;
  1367. { procedure variable ? }
  1368. if assigned(right) then
  1369. begin
  1370. set_varstate(right,true);
  1371. resulttypepass(right);
  1372. if codegenerror then
  1373. exit;
  1374. procdefinition:=tabstractprocdef(right.resulttype.def);
  1375. { check the amount of parameters }
  1376. pdc:=tparaitem(procdefinition.Para.first);
  1377. pt:=tcallparanode(left);
  1378. lastpara:=paralength;
  1379. while assigned(pdc) and assigned(pt) do
  1380. begin
  1381. { only goto next para if we're out of the varargs }
  1382. if not(po_varargs in procdefinition.procoptions) or
  1383. (lastpara<=procdefinition.maxparacount) then
  1384. pdc:=tparaitem(pdc.next);
  1385. pt:=tcallparanode(pt.right);
  1386. dec(lastpara);
  1387. end;
  1388. if assigned(pt) or assigned(pdc) then
  1389. begin
  1390. if assigned(pt) then
  1391. aktfilepos:=pt.fileinfo;
  1392. CGMessage(parser_e_wrong_parameter_size);
  1393. end;
  1394. end
  1395. else
  1396. { not a procedure variable }
  1397. begin
  1398. { do we know the procedure to call ? }
  1399. if not(assigned(procdefinition)) then
  1400. begin
  1401. { when the definition has overload directive set, we search for
  1402. overloaded definitions in the class, this only needs to be done once
  1403. for class entries as the tree keeps always the same }
  1404. if (not symtableprocentry.overloadchecked) and
  1405. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1406. (symtableprocentry.owner.symtabletype=objectsymtable) then
  1407. search_class_overloads(symtableprocentry);
  1408. { link all procedures which have the same # of parameters }
  1409. for j:=1 to symtableprocentry.procdef_count do
  1410. begin
  1411. pd:=symtableprocentry.procdef[j];
  1412. { only when the # of parameter are supported by the
  1413. procedure }
  1414. if (paralength>=pd.minparacount) and
  1415. ((po_varargs in pd.procoptions) or { varargs }
  1416. (paralength<=pd.maxparacount)) then
  1417. begin
  1418. new(hp);
  1419. hp^.data:=pd;
  1420. hp^.next:=procs;
  1421. hp^.firstpara:=tparaitem(pd.Para.first);
  1422. if not(po_varargs in pd.procoptions) then
  1423. begin
  1424. { if not all parameters are given, then skip the
  1425. default parameters }
  1426. for i:=1 to pd.maxparacount-paralength do
  1427. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1428. end;
  1429. hp^.nextpara:=hp^.firstpara;
  1430. procs:=hp;
  1431. end;
  1432. end;
  1433. { remember if the procedure is declared with the overload directive,
  1434. it's information is still needed also after all procs are removed }
  1435. has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
  1436. { when the definition has overload directive set, we search for
  1437. overloaded definitions in the symtablestack. The found
  1438. entries are only added to the procs list and not the procsym, because
  1439. the list can change in every situation }
  1440. if has_overload_directive and
  1441. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1442. begin
  1443. srsymtable:=symtableprocentry.owner.next;
  1444. while assigned(srsymtable) do
  1445. begin
  1446. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1447. begin
  1448. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1449. { process only visible procsyms }
  1450. if assigned(srprocsym) and
  1451. (srprocsym.typ=procsym) and
  1452. srprocsym.is_visible_for_proc(aktprocdef) then
  1453. begin
  1454. { if this procedure doesn't have overload we can stop
  1455. searching }
  1456. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1457. break;
  1458. { process all overloaded definitions }
  1459. for j:=1 to srprocsym.procdef_count do
  1460. begin
  1461. pd:=srprocsym.procdef[j];
  1462. { only when the # of parameter are supported by the
  1463. procedure }
  1464. if (paralength>=pd.minparacount) and
  1465. ((po_varargs in pd.procoptions) or { varargs }
  1466. (paralength<=pd.maxparacount)) then
  1467. begin
  1468. found:=false;
  1469. hp:=procs;
  1470. while assigned(hp) do
  1471. begin
  1472. if equal_paras(hp^.data.para,pd.para,cp_value_equal_const,false) then
  1473. begin
  1474. found:=true;
  1475. break;
  1476. end;
  1477. hp:=hp^.next;
  1478. end;
  1479. if not found then
  1480. begin
  1481. new(hp);
  1482. hp^.data:=pd;
  1483. hp^.next:=procs;
  1484. hp^.firstpara:=tparaitem(pd.Para.first);
  1485. if not(po_varargs in pd.procoptions) then
  1486. begin
  1487. { if not all parameters are given, then skip the
  1488. default parameters }
  1489. for i:=1 to pd.maxparacount-paralength do
  1490. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1491. end;
  1492. hp^.nextpara:=hp^.firstpara;
  1493. procs:=hp;
  1494. end;
  1495. end;
  1496. end;
  1497. end;
  1498. end;
  1499. srsymtable:=srsymtable.next;
  1500. end;
  1501. end;
  1502. { no procedures found? then there is something wrong
  1503. with the parameter size }
  1504. if not assigned(procs) then
  1505. begin
  1506. { when it's an auto inherited call and there
  1507. is no procedure found, but the procedures
  1508. were defined with overload directive and at
  1509. least two procedures are defined then we ignore
  1510. this inherited by inserting a nothingn. Only
  1511. do this ugly hack in Delphi mode as it looks more
  1512. like a bug. It's also not documented }
  1513. if (m_delphi in aktmodeswitches) and
  1514. (nf_auto_inherited in flags) and
  1515. (has_overload_directive) and
  1516. (symtableprocentry.procdef_count>=2) then
  1517. result:=cnothingnode.create
  1518. else
  1519. begin
  1520. { in tp mode we can try to convert to procvar if
  1521. there are no parameters specified. Only try it
  1522. when there is only one proc definition, else the
  1523. loadnode will give a strange error }
  1524. if not(assigned(left)) and
  1525. (m_tp_procvar in aktmodeswitches) and
  1526. (symtableprocentry.procdef_count=1) then
  1527. begin
  1528. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1529. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  1530. assigned(methodpointer) then
  1531. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1532. resulttypepass(hpt);
  1533. result:=hpt;
  1534. end
  1535. else
  1536. begin
  1537. if assigned(left) then
  1538. aktfilepos:=left.fileinfo;
  1539. CGMessage(parser_e_wrong_parameter_size);
  1540. symtableprocentry.write_parameter_lists(nil);
  1541. end;
  1542. end;
  1543. goto errorexit;
  1544. end;
  1545. { now we can compare parameter after parameter }
  1546. pt:=tcallparanode(left);
  1547. { we start with the last parameter }
  1548. lastpara:=paralength+1;
  1549. lastparatype:=nil;
  1550. while assigned(pt) do
  1551. begin
  1552. dec(lastpara);
  1553. { walk all procedures and determine how this parameter matches and set:
  1554. 1. pt.exact_match_found if one parameter has an exact match
  1555. 2. exactmatch if an equal or exact match is found
  1556. 3. Para.argconvtyp to exact,equal or convertable
  1557. (when convertable then also convertlevel is set)
  1558. 4. pt.convlevel1found if there is a convertlevel=1
  1559. 5. pt.convlevel2found if there is a convertlevel=2
  1560. }
  1561. exactmatch:=false;
  1562. hp:=procs;
  1563. while assigned(hp) do
  1564. begin
  1565. { varargs are always equal, but not exact }
  1566. if (po_varargs in hp^.data.procoptions) and
  1567. (lastpara>hp^.data.minparacount) then
  1568. begin
  1569. hp^.nextPara.argconvtyp:=act_equal;
  1570. exactmatch:=true;
  1571. end
  1572. else
  1573. begin
  1574. if is_equal(pt,hp^.nextPara.paratype.def) then
  1575. begin
  1576. if hp^.nextPara.paratype.def=pt.resulttype.def then
  1577. begin
  1578. include(pt.callparaflags,cpf_exact_match_found);
  1579. hp^.nextPara.argconvtyp:=act_exact;
  1580. end
  1581. else
  1582. hp^.nextPara.argconvtyp:=act_equal;
  1583. exactmatch:=true;
  1584. end
  1585. else
  1586. begin
  1587. hp^.nextPara.argconvtyp:=act_convertable;
  1588. { var and out parameters are not be convertable
  1589. in Delphi/tp mode. The only exception is when the
  1590. procedure is defined in the system unit }
  1591. if (hp^.nextPara.paratyp in [vs_var,vs_out]) and
  1592. (procs^.data.owner.unitid<>1) and
  1593. ((m_delphi in aktmodeswitches) or
  1594. (m_tp7 in aktmodeswitches)) then
  1595. hp^.nextPara.convertlevel:=0
  1596. else
  1597. hp^.nextPara.convertlevel:=isconvertable(pt.resulttype.def,hp^.nextPara.paratype.def,
  1598. hcvt,pt.left.nodetype,false);
  1599. case hp^.nextPara.convertlevel of
  1600. 1 : include(pt.callparaflags,cpf_convlevel1found);
  1601. 2 : include(pt.callparaflags,cpf_convlevel2found);
  1602. end;
  1603. end;
  1604. end;
  1605. hp:=hp^.next;
  1606. end;
  1607. { If there was an exactmatch then delete all convertables }
  1608. if exactmatch then
  1609. begin
  1610. hp:=procs;
  1611. procs:=nil;
  1612. while assigned(hp) do
  1613. begin
  1614. hp2:=hp^.next;
  1615. { keep if not convertable }
  1616. if (hp^.nextPara.argconvtyp<>act_convertable) then
  1617. begin
  1618. hp^.next:=procs;
  1619. procs:=hp;
  1620. end
  1621. else
  1622. dispose(hp);
  1623. hp:=hp2;
  1624. end;
  1625. end
  1626. else
  1627. { No exact match was found, remove all procedures that are
  1628. not convertable (convertlevel=0) }
  1629. begin
  1630. hp:=procs;
  1631. procs:=nil;
  1632. while assigned(hp) do
  1633. begin
  1634. hp2:=hp^.next;
  1635. { keep if not convertable }
  1636. if (hp^.nextPara.convertlevel<>0) then
  1637. begin
  1638. hp^.next:=procs;
  1639. procs:=hp;
  1640. end
  1641. else
  1642. begin
  1643. { save the type for nice error message }
  1644. lastparatype:=hp^.nextPara.paratype.def;
  1645. dispose(hp);
  1646. end;
  1647. hp:=hp2;
  1648. end;
  1649. end;
  1650. { update nextpara for all procedures }
  1651. hp:=procs;
  1652. while assigned(hp) do
  1653. begin
  1654. { only goto next para if we're out of the varargs }
  1655. if not(po_varargs in hp^.data.procoptions) or
  1656. (lastpara<=hp^.data.maxparacount) then
  1657. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1658. hp:=hp^.next;
  1659. end;
  1660. { load next parameter or quit loop if no procs left }
  1661. if assigned(procs) then
  1662. pt:=tcallparanode(pt.right)
  1663. else
  1664. break;
  1665. end;
  1666. { All parameters are checked, check if there are any
  1667. procedures left }
  1668. if not assigned(procs) then
  1669. begin
  1670. { there is an error, must be wrong type, because
  1671. wrong size is already checked (PFV) }
  1672. if (not assigned(lastparatype)) or
  1673. (not assigned(pt)) or
  1674. (not assigned(pt.resulttype.def)) then
  1675. internalerror(39393)
  1676. else
  1677. begin
  1678. aktfilepos:=pt.fileinfo;
  1679. CGMessage3(type_e_wrong_parameter_type,tostr(lastpara),
  1680. pt.resulttype.def.typename,lastparatype.typename);
  1681. end;
  1682. symtableprocentry.write_parameter_lists(nil);
  1683. goto errorexit;
  1684. end;
  1685. { if there are several choices left then for orddef }
  1686. { if a type is totally included in the other }
  1687. { we don't fear an overflow , }
  1688. { so we can do as if it is an exact match }
  1689. { this will convert integer to longint }
  1690. { rather than to words }
  1691. { conversion of byte to integer or longint }
  1692. { would still not be solved }
  1693. if assigned(procs) and assigned(procs^.next) then
  1694. begin
  1695. hp:=procs;
  1696. while assigned(hp) do
  1697. begin
  1698. hp^.nextpara:=hp^.firstpara;
  1699. hp:=hp^.next;
  1700. end;
  1701. pt:=tcallparanode(left);
  1702. while assigned(pt) do
  1703. begin
  1704. { matches a parameter of one procedure exact ? }
  1705. exactmatch:=false;
  1706. def_from:=pt.resulttype.def;
  1707. hp:=procs;
  1708. while assigned(hp) do
  1709. begin
  1710. if not is_equal(pt,hp^.nextPara.paratype.def) then
  1711. begin
  1712. def_to:=hp^.nextPara.paratype.def;
  1713. if ((def_from.deftype=orddef) and (def_to.deftype=orddef)) and
  1714. (is_in_limit(def_from,def_to) or
  1715. ((hp^.nextPara.paratyp in [vs_var,vs_out]) and
  1716. (def_from.size=def_to.size))) then
  1717. begin
  1718. exactmatch:=true;
  1719. conv_to:=def_to;
  1720. { there's no use in continuing the search, it will }
  1721. { only result in conv_to being overwritten }
  1722. break;
  1723. end;
  1724. end;
  1725. hp:=hp^.next;
  1726. end;
  1727. { .... if yes, del all the other procedures }
  1728. if exactmatch then
  1729. begin
  1730. { the first .... }
  1731. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextPara.paratype.def)) do
  1732. begin
  1733. hp:=procs^.next;
  1734. dispose(procs);
  1735. procs:=hp;
  1736. end;
  1737. { and the others }
  1738. hp:=procs;
  1739. while (assigned(hp)) and assigned(hp^.next) do
  1740. begin
  1741. def_to:=hp^.next^.nextPara.paratype.def;
  1742. if not(is_in_limit(def_from,def_to)) then
  1743. begin
  1744. hp2:=hp^.next^.next;
  1745. dispose(hp^.next);
  1746. hp^.next:=hp2;
  1747. end
  1748. else
  1749. begin
  1750. { did we possibly find a better match? }
  1751. if (conv_to.size>def_to.size) or
  1752. is_in_limit(def_to,conv_to) then
  1753. begin
  1754. { is it the same as the previous best? }
  1755. if not defbase.is_equal(def_to,conv_to) then
  1756. begin
  1757. { no -> remove all previous best matches }
  1758. hp := hp^.next;
  1759. while procs <> hp do
  1760. begin
  1761. hp2 := procs;
  1762. procs := procs^.next;
  1763. dispose(hp2);
  1764. end;
  1765. { set new match type }
  1766. conv_to:=def_to;
  1767. end
  1768. { the new one matches just as well as the }
  1769. { old one -> keep both }
  1770. else
  1771. hp := hp^.next;
  1772. end
  1773. { not a better match -> remove }
  1774. else
  1775. begin
  1776. hp2 := hp^.next^.next;
  1777. dispose(hp^.next);
  1778. hp^.next:=hp2;
  1779. end;
  1780. end;
  1781. end;
  1782. end;
  1783. { update nextpara for all procedures }
  1784. hp:=procs;
  1785. while assigned(hp) do
  1786. begin
  1787. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1788. hp:=hp^.next;
  1789. end;
  1790. pt:=tcallparanode(pt.right);
  1791. end;
  1792. end;
  1793. { let's try to eliminate equal if there is an exact match
  1794. is there }
  1795. if assigned(procs) and assigned(procs^.next) then
  1796. begin
  1797. { reset nextpara for all procs left }
  1798. hp:=procs;
  1799. while assigned(hp) do
  1800. begin
  1801. hp^.nextpara:=hp^.firstpara;
  1802. hp:=hp^.next;
  1803. end;
  1804. pt:=tcallparanode(left);
  1805. while assigned(pt) do
  1806. begin
  1807. if cpf_exact_match_found in pt.callparaflags then
  1808. begin
  1809. hp:=procs;
  1810. procs:=nil;
  1811. while assigned(hp) do
  1812. begin
  1813. hp2:=hp^.next;
  1814. { keep the exact matches, dispose the others }
  1815. if (hp^.nextPara.argconvtyp=act_exact) then
  1816. begin
  1817. hp^.next:=procs;
  1818. procs:=hp;
  1819. end
  1820. else
  1821. dispose(hp);
  1822. hp:=hp2;
  1823. end;
  1824. end;
  1825. { update nextpara for all procedures }
  1826. hp:=procs;
  1827. while assigned(hp) do
  1828. begin
  1829. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1830. hp:=hp^.next;
  1831. end;
  1832. pt:=tcallparanode(pt.right);
  1833. end;
  1834. end;
  1835. { Check if there are integer constant to integer
  1836. parameters then choose the best matching integer
  1837. parameter and remove the others, this is Delphi
  1838. compatible. 1 = byte, 256 = word, etc. }
  1839. if assigned(procs) and assigned(procs^.next) then
  1840. begin
  1841. { reset nextpara for all procs left }
  1842. hp:=procs;
  1843. while assigned(hp) do
  1844. begin
  1845. hp^.nextpara:=hp^.firstpara;
  1846. hp:=hp^.next;
  1847. end;
  1848. pt:=tcallparanode(left);
  1849. while assigned(pt) do
  1850. begin
  1851. bestord:=nil;
  1852. if (pt.left.nodetype=ordconstn) and
  1853. is_integer(pt.resulttype.def) then
  1854. begin
  1855. hp:=procs;
  1856. while assigned(hp) do
  1857. begin
  1858. def_to:=hp^.nextPara.paratype.def;
  1859. { to be sure, it couldn't be something else,
  1860. also the defs here are all in the range
  1861. so now find the closest range }
  1862. if not is_integer(def_to) then
  1863. internalerror(43297815);
  1864. if (not assigned(bestord)) or
  1865. ((torddef(def_to).low>bestord.low) or
  1866. (torddef(def_to).high<bestord.high)) then
  1867. bestord:=torddef(def_to);
  1868. hp:=hp^.next;
  1869. end;
  1870. end;
  1871. { if a bestmatch is found then remove the other
  1872. procs which don't match the bestord }
  1873. if assigned(bestord) then
  1874. begin
  1875. hp:=procs;
  1876. procs:=nil;
  1877. while assigned(hp) do
  1878. begin
  1879. hp2:=hp^.next;
  1880. { keep matching bestord, dispose the others }
  1881. if (torddef(hp^.nextPara.paratype.def)=bestord) then
  1882. begin
  1883. hp^.next:=procs;
  1884. procs:=hp;
  1885. end
  1886. else
  1887. dispose(hp);
  1888. hp:=hp2;
  1889. end;
  1890. end;
  1891. { update nextpara for all procedures }
  1892. hp:=procs;
  1893. while assigned(hp) do
  1894. begin
  1895. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1896. hp:=hp^.next;
  1897. end;
  1898. pt:=tcallparanode(pt.right);
  1899. end;
  1900. end;
  1901. { Check if there are convertlevel 1 and 2 differences
  1902. left for the parameters, then discard all convertlevel
  1903. 2 procedures. The value of convlevelXfound can still
  1904. be used, because all convertables are still here or
  1905. not }
  1906. if assigned(procs) and assigned(procs^.next) then
  1907. begin
  1908. { reset nextpara for all procs left }
  1909. hp:=procs;
  1910. while assigned(hp) do
  1911. begin
  1912. hp^.nextpara:=hp^.firstpara;
  1913. hp:=hp^.next;
  1914. end;
  1915. pt:=tcallparanode(left);
  1916. while assigned(pt) do
  1917. begin
  1918. if (cpf_convlevel1found in pt.callparaflags) and
  1919. (cpf_convlevel2found in pt.callparaflags) then
  1920. begin
  1921. hp:=procs;
  1922. procs:=nil;
  1923. while assigned(hp) do
  1924. begin
  1925. hp2:=hp^.next;
  1926. { keep all not act_convertable and all convertlevels=1 }
  1927. if (hp^.nextPara.argconvtyp<>act_convertable) or
  1928. (hp^.nextPara.convertlevel=1) then
  1929. begin
  1930. hp^.next:=procs;
  1931. procs:=hp;
  1932. end
  1933. else
  1934. dispose(hp);
  1935. hp:=hp2;
  1936. end;
  1937. end;
  1938. { update nextpara for all procedures }
  1939. hp:=procs;
  1940. while assigned(hp) do
  1941. begin
  1942. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1943. hp:=hp^.next;
  1944. end;
  1945. pt:=tcallparanode(pt.right);
  1946. end;
  1947. end;
  1948. if not(assigned(procs)) or assigned(procs^.next) then
  1949. begin
  1950. CGMessage(cg_e_cant_choose_overload_function);
  1951. symtableprocentry.write_parameter_lists(nil);
  1952. goto errorexit;
  1953. end;
  1954. if make_ref then
  1955. begin
  1956. procs^.data.lastref:=tref.create(procs^.data.lastref,@fileinfo);
  1957. inc(procs^.data.refcount);
  1958. if procs^.data.defref=nil then
  1959. procs^.data.defref:=procs^.data.lastref;
  1960. end;
  1961. procdefinition:=procs^.data;
  1962. { big error for with statements
  1963. symtableproc:=procdefinition.owner;
  1964. but neede for overloaded operators !! }
  1965. if symtableproc=nil then
  1966. symtableproc:=procdefinition.owner;
  1967. end; { end of procedure to call determination }
  1968. { add needed default parameters }
  1969. if assigned(procs) and
  1970. (paralength<procdefinition.maxparacount) then
  1971. begin
  1972. { add default parameters, just read back the skipped
  1973. paras starting from firstPara.previous, when not available
  1974. (all parameters are default) then start with the last
  1975. parameter and read backward (PFV) }
  1976. if not assigned(procs^.firstpara) then
  1977. pdc:=tparaitem(procs^.data.Para.last)
  1978. else
  1979. pdc:=tparaitem(procs^.firstPara.previous);
  1980. while assigned(pdc) do
  1981. begin
  1982. if not assigned(pdc.defaultvalue) then
  1983. internalerror(751349858);
  1984. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1985. pdc:=tparaitem(pdc.previous);
  1986. end;
  1987. end;
  1988. end;
  1989. { handle predefined procedures }
  1990. is_const:=(po_internconst in procdefinition.procoptions) and
  1991. ((block_type in [bt_const,bt_type]) or
  1992. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1993. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1994. begin
  1995. if assigned(left) then
  1996. begin
  1997. { ptr and settextbuf needs two args }
  1998. if assigned(tcallparanode(left).right) then
  1999. begin
  2000. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  2001. left:=nil;
  2002. end
  2003. else
  2004. begin
  2005. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  2006. tcallparanode(left).left:=nil;
  2007. end;
  2008. end
  2009. else
  2010. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  2011. result:=hpt;
  2012. goto errorexit;
  2013. end;
  2014. {$ifdef dummy}
  2015. { Calling a message method directly ? }
  2016. if assigned(procdefinition) and
  2017. (po_containsself in procdefinition.procoptions) then
  2018. message(cg_e_cannot_call_message_direct);
  2019. {$endif}
  2020. { ensure that the result type is set }
  2021. if not restypeset then
  2022. resulttype:=procdefinition.rettype
  2023. else
  2024. resulttype:=restype;
  2025. { modify the exit code, in case of special cases }
  2026. if (not is_void(resulttype.def)) then
  2027. begin
  2028. if paramanager.ret_in_reg(resulttype.def) then
  2029. begin
  2030. { wide- and ansistrings are returned in EAX }
  2031. { but they are imm. moved to a memory location }
  2032. if is_widestring(resulttype.def) or
  2033. is_ansistring(resulttype.def) then
  2034. begin
  2035. { we use ansistrings so no fast exit here }
  2036. if assigned(procinfo) then
  2037. procinfo.no_fast_exit:=true;
  2038. end;
  2039. end;
  2040. end;
  2041. { constructors return their current class type, not the type where the
  2042. constructor is declared, this can be different because of inheritance }
  2043. if (procdefinition.proctypeoption=potype_constructor) then
  2044. begin
  2045. if assigned(methodpointer) and
  2046. assigned(methodpointer.resulttype.def) and
  2047. (methodpointer.resulttype.def.deftype=classrefdef) then
  2048. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  2049. end;
  2050. { flag all callparanodes that belong to the varargs }
  2051. if (po_varargs in procdefinition.procoptions) then
  2052. begin
  2053. pt:=tcallparanode(left);
  2054. i:=paralength;
  2055. while (i>procdefinition.maxparacount) do
  2056. begin
  2057. include(tcallparanode(pt).flags,nf_varargs_para);
  2058. pt:=tcallparanode(pt.right);
  2059. dec(i);
  2060. end;
  2061. end;
  2062. { insert type conversions }
  2063. if assigned(left) then
  2064. begin
  2065. aktcallprocdef:=procdefinition;
  2066. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  2067. end;
  2068. errorexit:
  2069. { Reset some settings back }
  2070. if assigned(procs) then
  2071. dispose(procs);
  2072. aktcallprocdef:=oldcallprocdef;
  2073. end;
  2074. {$endif}
  2075. function tcallnode.pass_1 : tnode;
  2076. var
  2077. inlinecode : tnode;
  2078. inlined : boolean;
  2079. {$ifdef m68k}
  2080. regi : tregister;
  2081. {$endif}
  2082. method_must_be_valid : boolean;
  2083. label
  2084. errorexit;
  2085. begin
  2086. { the default is nothing to return }
  2087. location.loc:=LOC_INVALID;
  2088. result:=nil;
  2089. inlined:=false;
  2090. inlinecode := nil;
  2091. { work trough all parameters to get the register requirements }
  2092. if assigned(left) then
  2093. tcallparanode(left).det_registers;
  2094. { return node }
  2095. if assigned(funcretrefnode) then
  2096. firstpass(funcretrefnode);
  2097. if assigned(procdefinition) and
  2098. (procdefinition.proccalloption=pocall_inline) then
  2099. begin
  2100. inlinecode:=right;
  2101. if assigned(inlinecode) then
  2102. inlined:=true;
  2103. right:=nil;
  2104. end;
  2105. { procedure variable ? }
  2106. if assigned(right) then
  2107. begin
  2108. firstpass(right);
  2109. { procedure does a call }
  2110. if not (block_type in [bt_const,bt_type]) then
  2111. procinfo.flags:=procinfo.flags or pi_do_call;
  2112. rg.incrementregisterpushed(all_registers);
  2113. end
  2114. else
  2115. { not a procedure variable }
  2116. begin
  2117. { calc the correture value for the register }
  2118. { handle predefined procedures }
  2119. if (procdefinition.proccalloption=pocall_inline) then
  2120. begin
  2121. if assigned(methodpointer) then
  2122. CGMessage(cg_e_unable_inline_object_methods);
  2123. if assigned(right) and (right.nodetype<>procinlinen) then
  2124. CGMessage(cg_e_unable_inline_procvar);
  2125. { nodetype:=procinlinen; }
  2126. if not assigned(right) then
  2127. begin
  2128. if assigned(tprocdef(procdefinition).code) then
  2129. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  2130. else
  2131. CGMessage(cg_e_no_code_for_inline_stored);
  2132. if assigned(inlinecode) then
  2133. begin
  2134. { consider it has not inlined if called
  2135. again inside the args }
  2136. procdefinition.proccalloption:=pocall_fpccall;
  2137. firstpass(inlinecode);
  2138. inlined:=true;
  2139. end;
  2140. end;
  2141. end
  2142. else
  2143. begin
  2144. if not (block_type in [bt_const,bt_type]) then
  2145. procinfo.flags:=procinfo.flags or pi_do_call;
  2146. end;
  2147. { It doesn't hurt to calculate it already though :) (JM) }
  2148. rg.incrementregisterpushed(tprocdef(procdefinition).usedregisters);
  2149. end;
  2150. { get a register for the return value }
  2151. if (not is_void(resulttype.def)) then
  2152. begin
  2153. if paramanager.ret_in_param(resulttype.def) then
  2154. begin
  2155. location.loc:=LOC_CREFERENCE;
  2156. end
  2157. else
  2158. { ansi/widestrings must be registered, so we can dispose them }
  2159. if is_ansistring(resulttype.def) or
  2160. is_widestring(resulttype.def) then
  2161. begin
  2162. location.loc:=LOC_CREFERENCE;
  2163. registers32:=1;
  2164. end
  2165. else
  2166. { we have only to handle the result if it is used }
  2167. if (nf_return_value_used in flags) then
  2168. begin
  2169. case resulttype.def.deftype of
  2170. enumdef,
  2171. orddef :
  2172. begin
  2173. if (procdefinition.proctypeoption=potype_constructor) then
  2174. begin
  2175. if assigned(methodpointer) and
  2176. (methodpointer.resulttype.def.deftype=classrefdef) then
  2177. begin
  2178. location.loc:=LOC_REGISTER;
  2179. registers32:=1;
  2180. end
  2181. else
  2182. location.loc:=LOC_FLAGS;
  2183. end
  2184. else
  2185. begin
  2186. location.loc:=LOC_REGISTER;
  2187. if is_64bitint(resulttype.def) then
  2188. registers32:=2
  2189. else
  2190. registers32:=1;
  2191. end;
  2192. end;
  2193. floatdef :
  2194. begin
  2195. location.loc:=LOC_FPUREGISTER;
  2196. {$ifdef m68k}
  2197. if (cs_fp_emulation in aktmoduleswitches) or
  2198. (tfloatdef(resulttype.def).typ=s32real) then
  2199. registers32:=1
  2200. else
  2201. registersfpu:=1;
  2202. {$else not m68k}
  2203. registersfpu:=1;
  2204. {$endif not m68k}
  2205. end;
  2206. else
  2207. begin
  2208. location.loc:=LOC_REGISTER;
  2209. registers32:=1;
  2210. end;
  2211. end;
  2212. end;
  2213. end;
  2214. { a fpu can be used in any procedure !! }
  2215. {$ifdef i386}
  2216. registersfpu:=procdefinition.fpu_used;
  2217. {$endif i386}
  2218. { if this is a call to a method calc the registers }
  2219. if (methodpointer<>nil) then
  2220. begin
  2221. case methodpointer.nodetype of
  2222. { but only, if this is not a supporting node }
  2223. typen: ;
  2224. { we need one register for new return value PM }
  2225. hnewn : if registers32=0 then
  2226. registers32:=1;
  2227. else
  2228. begin
  2229. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2230. assigned(symtableproc) and (symtableproc.symtabletype=withsymtable) and
  2231. not twithsymtable(symtableproc).direct_with then
  2232. begin
  2233. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2234. end; { Is accepted by Delphi !! }
  2235. { this is not a good reason to accept it in FPC if we produce
  2236. wrong code for it !!! (PM) }
  2237. { R.Assign is not a constructor !!! }
  2238. { but for R^.Assign, R must be valid !! }
  2239. if (procdefinition.proctypeoption=potype_constructor) or
  2240. ((methodpointer.nodetype=loadn) and
  2241. ((methodpointer.resulttype.def.deftype=classrefdef) or
  2242. ((methodpointer.resulttype.def.deftype=objectdef) and
  2243. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2244. )
  2245. )
  2246. ) then
  2247. method_must_be_valid:=false
  2248. else
  2249. method_must_be_valid:=true;
  2250. firstpass(methodpointer);
  2251. set_varstate(methodpointer,method_must_be_valid);
  2252. { The object is already used ven if it is called once }
  2253. if (methodpointer.nodetype=loadn) and
  2254. (tloadnode(methodpointer).symtableentry.typ=varsym) then
  2255. tvarsym(tloadnode(methodpointer).symtableentry).varstate:=vs_used;
  2256. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2257. registers32:=max(methodpointer.registers32,registers32);
  2258. {$ifdef SUPPORT_MMX }
  2259. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2260. {$endif SUPPORT_MMX}
  2261. end;
  2262. end;
  2263. end;
  2264. if inlined then
  2265. right:=inlinecode;
  2266. { determine the registers of the procedure variable }
  2267. { is this OK for inlined procs also ?? (PM) }
  2268. if assigned(right) then
  2269. begin
  2270. registersfpu:=max(right.registersfpu,registersfpu);
  2271. registers32:=max(right.registers32,registers32);
  2272. {$ifdef SUPPORT_MMX}
  2273. registersmmx:=max(right.registersmmx,registersmmx);
  2274. {$endif SUPPORT_MMX}
  2275. end;
  2276. { determine the registers of the procedure }
  2277. if assigned(left) then
  2278. begin
  2279. registersfpu:=max(left.registersfpu,registersfpu);
  2280. registers32:=max(left.registers32,registers32);
  2281. {$ifdef SUPPORT_MMX}
  2282. registersmmx:=max(left.registersmmx,registersmmx);
  2283. {$endif SUPPORT_MMX}
  2284. end;
  2285. errorexit:
  2286. if inlined then
  2287. procdefinition.proccalloption:=pocall_inline;
  2288. end;
  2289. {$ifdef state_tracking}
  2290. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2291. var hp:Tcallparanode;
  2292. value:Tnode;
  2293. begin
  2294. track_state_pass:=false;
  2295. hp:=Tcallparanode(left);
  2296. while assigned(hp) do
  2297. begin
  2298. if left.track_state_pass(exec_known) then
  2299. begin
  2300. left.resulttype.def:=nil;
  2301. do_resulttypepass(left);
  2302. end;
  2303. value:=aktstate.find_fact(hp.left);
  2304. if value<>nil then
  2305. begin
  2306. track_state_pass:=true;
  2307. hp.left.destroy;
  2308. hp.left:=value.getcopy;
  2309. do_resulttypepass(hp.left);
  2310. end;
  2311. hp:=Tcallparanode(hp.right);
  2312. end;
  2313. end;
  2314. {$endif}
  2315. function tcallnode.docompare(p: tnode): boolean;
  2316. begin
  2317. docompare :=
  2318. inherited docompare(p) and
  2319. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2320. (symtableproc = tcallnode(p).symtableproc) and
  2321. (procdefinition = tcallnode(p).procdefinition) and
  2322. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2323. ((restypeset and tcallnode(p).restypeset and
  2324. (is_equal(restype.def,tcallnode(p).restype.def))) or
  2325. (not restypeset and not tcallnode(p).restypeset));
  2326. end;
  2327. {****************************************************************************
  2328. TPROCINLINENODE
  2329. ****************************************************************************}
  2330. constructor tprocinlinenode.create(p:tprocdef);
  2331. begin
  2332. inherited create(procinlinen);
  2333. inlineprocdef:=p;
  2334. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2335. para_offset:=0;
  2336. para_size:=0;
  2337. { copy inlinetree }
  2338. if assigned(p.code) then
  2339. inlinetree:=p.code.getcopy
  2340. else
  2341. inlinetree:=nil;
  2342. end;
  2343. destructor tprocinlinenode.destroy;
  2344. begin
  2345. if assigned(inlinetree) then
  2346. inlinetree.free;
  2347. inherited destroy;
  2348. end;
  2349. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2350. begin
  2351. inherited ppuload(t,ppufile);
  2352. inlineprocdef:=tprocdef(ppufile.getderef);
  2353. inlinetree:=ppuloadnode(ppufile);
  2354. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2355. para_offset:=0;
  2356. para_size:=0;
  2357. end;
  2358. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2359. begin
  2360. inherited ppuwrite(ppufile);
  2361. ppufile.putderef(inlineprocdef);
  2362. ppuwritenode(ppufile,inlinetree);
  2363. end;
  2364. procedure tprocinlinenode.derefimpl;
  2365. begin
  2366. inherited derefimpl;
  2367. if assigned(inlinetree) then
  2368. inlinetree.derefimpl;
  2369. resolvedef(pointer(inlineprocdef));
  2370. end;
  2371. function tprocinlinenode.getcopy : tnode;
  2372. var
  2373. n : tprocinlinenode;
  2374. begin
  2375. n:=tprocinlinenode(inherited getcopy);
  2376. n.inlineprocdef:=inlineprocdef;
  2377. if assigned(inlinetree) then
  2378. n.inlinetree:=inlinetree.getcopy
  2379. else
  2380. n.inlinetree:=nil;
  2381. n.retoffset:=retoffset;
  2382. n.para_offset:=para_offset;
  2383. n.para_size:=para_size;
  2384. getcopy:=n;
  2385. end;
  2386. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2387. begin
  2388. end;
  2389. function tprocinlinenode.det_resulttype : tnode;
  2390. begin
  2391. resulttype:=inlineprocdef.rettype;
  2392. { retrieve info from inlineprocdef }
  2393. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2394. para_offset:=0;
  2395. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2396. if paramanager.ret_in_param(inlineprocdef.rettype.def) then
  2397. inc(para_size,POINTER_SIZE);
  2398. result:=nil;
  2399. end;
  2400. function tprocinlinenode.pass_1 : tnode;
  2401. begin
  2402. firstpass(inlinetree);
  2403. registers32:=inlinetree.registers32;
  2404. registersfpu:=inlinetree.registersfpu;
  2405. {$ifdef SUPPORT_MMX}
  2406. registersmmx:=inlinetree.registersmmx;
  2407. {$endif SUPPORT_MMX}
  2408. result:=nil;
  2409. end;
  2410. function tprocinlinenode.docompare(p: tnode): boolean;
  2411. begin
  2412. docompare :=
  2413. inherited docompare(p) and
  2414. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2415. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2416. end;
  2417. begin
  2418. ccallnode:=tcallnode;
  2419. ccallparanode:=tcallparanode;
  2420. cprocinlinenode:=tprocinlinenode;
  2421. end.
  2422. {
  2423. $Log$
  2424. Revision 1.103 2002-10-05 12:43:25 carl
  2425. * fixes for Delphi 6 compilation
  2426. (warning : Some features do not work under Delphi)
  2427. Revision 1.102 2002/10/05 00:48:57 peter
  2428. * support inherited; support for overload as it is handled by
  2429. delphi. This is only for delphi mode as it is working is
  2430. undocumented and hard to predict what is done
  2431. Revision 1.101 2002/09/16 14:11:12 peter
  2432. * add argument to equal_paras() to support default values or not
  2433. Revision 1.100 2002/09/15 17:49:59 peter
  2434. * don't have strict var parameter checking for procedures in the
  2435. system unit
  2436. Revision 1.99 2002/09/09 19:30:34 peter
  2437. * don't allow convertable parameters for var and out parameters in
  2438. delphi and tp mode
  2439. Revision 1.98 2002/09/07 15:25:02 peter
  2440. * old logs removed and tabs fixed
  2441. Revision 1.97 2002/09/07 12:16:05 carl
  2442. * second part bug report 1996 fix, testrange in cordconstnode
  2443. only called if option is set (also make parsing a tiny faster)
  2444. Revision 1.96 2002/09/05 14:53:41 peter
  2445. * fixed old callnode.det_resulttype code
  2446. * old ncal code is default again
  2447. Revision 1.95 2002/09/03 21:32:49 daniel
  2448. * Small bugfix for procdef selection
  2449. Revision 1.94 2002/09/03 19:27:22 daniel
  2450. * Activated new ncal code
  2451. Revision 1.93 2002/09/03 16:26:26 daniel
  2452. * Make Tprocdef.defs protected
  2453. Revision 1.92 2002/09/01 13:28:37 daniel
  2454. - write_access fields removed in favor of a flag
  2455. Revision 1.91 2002/09/01 12:14:15 peter
  2456. * remove debug line
  2457. * containself methods can be called directly
  2458. Revision 1.90 2002/09/01 08:01:16 daniel
  2459. * Removed sets from Tcallnode.det_resulttype
  2460. + Added read/write notifications of variables. These will be usefull
  2461. for providing information for several optimizations. For example
  2462. the value of the loop variable of a for loop does matter is the
  2463. variable is read after the for loop, but if it's no longer used
  2464. or written, it doesn't matter and this can be used to optimize
  2465. the loop code generation.
  2466. Revision 1.89 2002/08/23 16:13:16 peter
  2467. * also firstpass funcretrefnode if available. This was breaking the
  2468. asnode compilerproc code
  2469. Revision 1.88 2002/08/20 10:31:26 daniel
  2470. * Tcallnode.det_resulttype rewritten
  2471. Revision 1.87 2002/08/19 19:36:42 peter
  2472. * More fixes for cross unit inlining, all tnodes are now implemented
  2473. * Moved pocall_internconst to po_internconst because it is not a
  2474. calling type at all and it conflicted when inlining of these small
  2475. functions was requested
  2476. Revision 1.86 2002/08/17 22:09:44 florian
  2477. * result type handling in tcgcal.pass_2 overhauled
  2478. * better tnode.dowrite
  2479. * some ppc stuff fixed
  2480. Revision 1.85 2002/08/17 09:23:34 florian
  2481. * first part of procinfo rewrite
  2482. Revision 1.84 2002/08/16 14:24:57 carl
  2483. * issameref() to test if two references are the same (then emit no opcodes)
  2484. + ret_in_reg to replace ret_in_acc
  2485. (fix some register allocation bugs at the same time)
  2486. + save_std_register now has an extra parameter which is the
  2487. usedinproc registers
  2488. Revision 1.83 2002/07/20 11:57:53 florian
  2489. * types.pas renamed to defbase.pas because D6 contains a types
  2490. unit so this would conflicts if D6 programms are compiled
  2491. + Willamette/SSE2 instructions to assembler added
  2492. Revision 1.82 2002/07/19 11:41:35 daniel
  2493. * State tracker work
  2494. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2495. allows the state tracker to change while nodes automatically into
  2496. repeat nodes.
  2497. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2498. 'not(a>b)' is optimized into 'a<=b'.
  2499. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2500. by removing the notn and later switchting the true and falselabels. The
  2501. same is done with 'repeat until not a'.
  2502. Revision 1.81 2002/07/15 18:03:14 florian
  2503. * readded removed changes
  2504. Revision 1.79 2002/07/11 14:41:27 florian
  2505. * start of the new generic parameter handling
  2506. Revision 1.80 2002/07/14 18:00:43 daniel
  2507. + Added the beginning of a state tracker. This will track the values of
  2508. variables through procedures and optimize things away.
  2509. Revision 1.78 2002/07/04 20:43:00 florian
  2510. * first x86-64 patches
  2511. }