ncal.pas 108 KB

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