ncal.pas 113 KB

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