ncal.pas 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104
  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. rgobj,
  168. cgbase,procinfo
  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. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1622. else
  1623. { constructor with extended syntax called from new }
  1624. if (nf_new_call in flags) then
  1625. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1626. else
  1627. { destructor with extended syntax called from dispose }
  1628. if (nf_dispose_call in flags) then
  1629. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1630. else
  1631. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1632. begin
  1633. { constructor call via classreference => allocate memory }
  1634. if (procdefinition.proctypeoption=potype_constructor) and
  1635. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1636. vmttree:=methodpointer.getcopy
  1637. else
  1638. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1639. end
  1640. else
  1641. { class }
  1642. if is_class(methodpointer.resulttype.def) then
  1643. begin
  1644. { destructor: release instance, flag(vmt)=1
  1645. constructor: direct call, do nothing, leave vmt=0 }
  1646. if (procdefinition.proctypeoption=potype_destructor) then
  1647. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1648. else
  1649. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1650. end
  1651. else
  1652. { object }
  1653. begin
  1654. { destructor: direct call, no dispose, vmt=0
  1655. constructor: initialize object, load vmt }
  1656. if (procdefinition.proctypeoption=potype_constructor) then
  1657. { old styled inherited call? }
  1658. if (methodpointer.nodetype=typen) then
  1659. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1660. else
  1661. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1662. else
  1663. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1664. end;
  1665. result:=vmttree;
  1666. end;
  1667. procedure tcallnode.bind_paraitem;
  1668. var
  1669. i : integer;
  1670. pt : tcallparanode;
  1671. oldppt : ^tcallparanode;
  1672. varargspara,
  1673. currpara : tparaitem;
  1674. used_by_callnode : boolean;
  1675. hiddentree : tnode;
  1676. newstatement : tstatementnode;
  1677. temp : ttempcreatenode;
  1678. begin
  1679. pt:=tcallparanode(left);
  1680. oldppt:=@left;
  1681. { flag all callparanodes that belong to the varargs }
  1682. i:=paralength;
  1683. while (i>procdefinition.maxparacount) do
  1684. begin
  1685. include(pt.flags,nf_varargs_para);
  1686. oldppt:[email protected];
  1687. pt:=tcallparanode(pt.right);
  1688. dec(i);
  1689. end;
  1690. { skip varargs that are inserted by array of const }
  1691. while assigned(pt) and
  1692. (nf_varargs_para in pt.flags) do
  1693. pt:=tcallparanode(pt.right);
  1694. { process normal parameters and insert hidden parameters }
  1695. currpara:=tparaitem(procdefinition.Para.last);
  1696. while assigned(currpara) do
  1697. begin
  1698. if currpara.is_hidden then
  1699. begin
  1700. { generate hidden tree }
  1701. used_by_callnode:=false;
  1702. hiddentree:=nil;
  1703. if (vo_is_funcret in tvarsym(currpara.parasym).varoptions) then
  1704. begin
  1705. { Generate funcretnode if not specified }
  1706. if assigned(funcretnode) then
  1707. begin
  1708. hiddentree:=funcretnode.getcopy;
  1709. end
  1710. else
  1711. begin
  1712. hiddentree:=internalstatements(newstatement,false);
  1713. { need to use resulttype instead of procdefinition.rettype,
  1714. because they can be different }
  1715. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent);
  1716. addstatement(newstatement,temp);
  1717. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1718. addstatement(newstatement,ctemprefnode.create(temp));
  1719. end;
  1720. end
  1721. else
  1722. if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1723. begin
  1724. if not assigned(pt) then
  1725. internalerror(200304082);
  1726. { we need the information of the next parameter }
  1727. hiddentree:=gen_high_tree(pt.left,is_open_string(tparaitem(currpara.previous).paratype.def));
  1728. end
  1729. else
  1730. if vo_is_self in tvarsym(currpara.parasym).varoptions then
  1731. begin
  1732. if assigned(right) then
  1733. hiddentree:=gen_self_tree_methodpointer
  1734. else
  1735. hiddentree:=gen_self_tree;
  1736. end
  1737. else
  1738. if vo_is_vmt in tvarsym(currpara.parasym).varoptions then
  1739. begin
  1740. hiddentree:=gen_vmt_tree;
  1741. end
  1742. else
  1743. if vo_is_parentfp in tvarsym(currpara.parasym).varoptions then
  1744. begin
  1745. if not(assigned(procdefinition.owner.defowner)) then
  1746. internalerror(200309287);
  1747. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1748. end;
  1749. { add the hidden parameter }
  1750. if not assigned(hiddentree) then
  1751. internalerror(200304073);
  1752. { Already insert para and let the previous node point to
  1753. this new node }
  1754. pt:=ccallparanode.create(hiddentree,oldppt^);
  1755. pt.used_by_callnode:=used_by_callnode;
  1756. oldppt^:=pt;
  1757. end;
  1758. if not assigned(pt) then
  1759. internalerror(200310052);
  1760. pt.paraitem:=currpara;
  1761. oldppt:[email protected];
  1762. pt:=tcallparanode(pt.right);
  1763. currpara:=tparaitem(currpara.previous)
  1764. end;
  1765. { Create paraitems for varargs }
  1766. pt:=tcallparanode(left);
  1767. while assigned(pt) do
  1768. begin
  1769. if nf_varargs_para in pt.flags then
  1770. begin
  1771. if not assigned(varargsparas) then
  1772. varargsparas:=tlinkedlist.create;
  1773. varargspara:=tparaitem.create;
  1774. varargspara.paratyp:=vs_value;
  1775. varargspara.paratype:=pt.resulttype;
  1776. varargsparas.concat(varargspara);
  1777. pt.paraitem:=varargspara;
  1778. end;
  1779. pt:=tcallparanode(pt.right);
  1780. end;
  1781. end;
  1782. function tcallnode.det_resulttype:tnode;
  1783. var
  1784. procs : pcandidate;
  1785. oldcallnode : tcallnode;
  1786. hpt : tnode;
  1787. pt : tcallparanode;
  1788. lastpara : longint;
  1789. currpara : tparaitem;
  1790. cand_cnt : integer;
  1791. i : longint;
  1792. method_must_be_valid,
  1793. is_const : boolean;
  1794. label
  1795. errorexit;
  1796. begin
  1797. result:=nil;
  1798. procs:=nil;
  1799. oldcallnode:=aktcallnode;
  1800. aktcallnode:=nil;
  1801. { determine length of parameter list }
  1802. pt:=tcallparanode(left);
  1803. paralength:=0;
  1804. while assigned(pt) do
  1805. begin
  1806. inc(paralength);
  1807. pt:=tcallparanode(pt.right);
  1808. end;
  1809. { determine the type of the parameters }
  1810. if assigned(left) then
  1811. begin
  1812. tcallparanode(left).get_paratype;
  1813. if codegenerror then
  1814. goto errorexit;
  1815. end;
  1816. { procedure variable ? }
  1817. if assigned(right) then
  1818. begin
  1819. set_varstate(right,vs_used,true);
  1820. resulttypepass(right);
  1821. if codegenerror then
  1822. exit;
  1823. procdefinition:=tabstractprocdef(right.resulttype.def);
  1824. { Compare parameters from right to left }
  1825. currpara:=tparaitem(procdefinition.Para.last);
  1826. while assigned(currpara) and (currpara.is_hidden) do
  1827. currpara:=tparaitem(currpara.previous);
  1828. pt:=tcallparanode(left);
  1829. lastpara:=paralength;
  1830. while assigned(currpara) and assigned(pt) do
  1831. begin
  1832. { only goto next para if we're out of the varargs }
  1833. if not(po_varargs in procdefinition.procoptions) or
  1834. (lastpara<=procdefinition.maxparacount) then
  1835. begin
  1836. repeat
  1837. currpara:=tparaitem(currpara.previous);
  1838. until (not assigned(currpara)) or (not currpara.is_hidden);
  1839. end;
  1840. pt:=tcallparanode(pt.right);
  1841. dec(lastpara);
  1842. end;
  1843. if assigned(pt) or assigned(currpara) then
  1844. begin
  1845. if assigned(pt) then
  1846. aktfilepos:=pt.fileinfo;
  1847. CGMessage(parser_e_wrong_parameter_size);
  1848. goto errorexit;
  1849. end;
  1850. end
  1851. else
  1852. { not a procedure variable }
  1853. begin
  1854. { do we know the procedure to call ? }
  1855. if not(assigned(procdefinition)) then
  1856. begin
  1857. procs:=candidates_find;
  1858. { no procedures found? then there is something wrong
  1859. with the parameter size or the procedures are
  1860. not accessible }
  1861. if not assigned(procs) then
  1862. begin
  1863. { when it's an auto inherited call and there
  1864. is no procedure found, but the procedures
  1865. were defined with overload directive and at
  1866. least two procedures are defined then we ignore
  1867. this inherited by inserting a nothingn. Only
  1868. do this ugly hack in Delphi mode as it looks more
  1869. like a bug. It's also not documented }
  1870. if (m_delphi in aktmodeswitches) and
  1871. (nf_anon_inherited in flags) and
  1872. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1873. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1874. (symtableprocentry.procdef_count>=2) then
  1875. result:=cnothingnode.create
  1876. else
  1877. begin
  1878. { in tp mode we can try to convert to procvar if
  1879. there are no parameters specified. Only try it
  1880. when there is only one proc definition, else the
  1881. loadnode will give a strange error }
  1882. if not(assigned(left)) and
  1883. not(nf_inherited in flags) and
  1884. (m_tp_procvar in aktmodeswitches) and
  1885. (symtableprocentry.procdef_count=1) then
  1886. begin
  1887. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1888. if assigned(methodpointer) then
  1889. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1890. resulttypepass(hpt);
  1891. result:=hpt;
  1892. end
  1893. else
  1894. begin
  1895. if assigned(left) then
  1896. aktfilepos:=left.fileinfo;
  1897. if paravisible then
  1898. begin
  1899. CGMessage(parser_e_wrong_parameter_size);
  1900. symtableprocentry.write_parameter_lists(nil);
  1901. end
  1902. else
  1903. CGMessage(parser_e_cant_access_private_member);
  1904. end;
  1905. end;
  1906. goto errorexit;
  1907. end;
  1908. { Retrieve information about the candidates }
  1909. candidates_get_information(procs);
  1910. {$ifdef EXTDEBUG}
  1911. { Display info when multiple candidates are found }
  1912. if assigned(procs^.next) then
  1913. candidates_dump_info(V_Debug,procs);
  1914. {$endif EXTDEBUG}
  1915. { Choose the best candidate and count the number of
  1916. candidates left }
  1917. cand_cnt:=candidates_choose_best(procs,tprocdef(procdefinition));
  1918. { All parameters are checked, check if there are any
  1919. procedures left }
  1920. if cand_cnt>0 then
  1921. begin
  1922. { Multiple candidates left? }
  1923. if cand_cnt>1 then
  1924. begin
  1925. CGMessage(cg_e_cant_choose_overload_function);
  1926. {$ifdef EXTDEBUG}
  1927. candidates_dump_info(V_Hint,procs);
  1928. {$else}
  1929. candidates_list(procs,false);
  1930. {$endif EXTDEBUG}
  1931. { we'll just use the first candidate to make the
  1932. call }
  1933. end;
  1934. { assign procdefinition }
  1935. if symtableproc=nil then
  1936. symtableproc:=procdefinition.owner;
  1937. { update browser information }
  1938. if make_ref then
  1939. begin
  1940. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1941. inc(tprocdef(procdefinition).refcount);
  1942. if tprocdef(procdefinition).defref=nil then
  1943. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1944. end;
  1945. end
  1946. else
  1947. begin
  1948. { No candidates left, this must be a type error,
  1949. because wrong size is already checked. procdefinition
  1950. is filled with the first (random) definition that is
  1951. found. We use this definition to display a nice error
  1952. message that the wrong type is passed }
  1953. candidates_find_wrong_para(procs);
  1954. candidates_list(procs,true);
  1955. {$ifdef EXTDEBUG}
  1956. candidates_dump_info(V_Hint,procs);
  1957. {$endif EXTDEBUG}
  1958. { We can not proceed, release all procs and exit }
  1959. candidates_free(procs);
  1960. goto errorexit;
  1961. end;
  1962. candidates_free(procs);
  1963. end; { end of procedure to call determination }
  1964. { add needed default parameters }
  1965. if assigned(procdefinition) and
  1966. (paralength<procdefinition.maxparacount) then
  1967. begin
  1968. currpara:=tparaitem(procdefinition.Para.first);
  1969. i:=0;
  1970. while (i<paralength) do
  1971. begin
  1972. if not assigned(currpara) then
  1973. internalerror(200306181);
  1974. if not currpara.is_hidden then
  1975. inc(i);
  1976. currpara:=tparaitem(currpara.next);
  1977. end;
  1978. while assigned(currpara) and
  1979. currpara.is_hidden do
  1980. currpara:=tparaitem(currpara.next);
  1981. while assigned(currpara) do
  1982. begin
  1983. if not assigned(currpara.defaultvalue) then
  1984. internalerror(200212142);
  1985. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1986. currpara:=tparaitem(currpara.next);
  1987. end;
  1988. end;
  1989. end;
  1990. { handle predefined procedures }
  1991. is_const:=(po_internconst in procdefinition.procoptions) and
  1992. ((block_type in [bt_const,bt_type]) or
  1993. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1994. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1995. begin
  1996. if assigned(left) then
  1997. begin
  1998. { ptr and settextbuf needs two args }
  1999. if assigned(tcallparanode(left).right) then
  2000. begin
  2001. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  2002. left:=nil;
  2003. end
  2004. else
  2005. begin
  2006. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  2007. tcallparanode(left).left:=nil;
  2008. end;
  2009. end
  2010. else
  2011. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  2012. result:=hpt;
  2013. goto errorexit;
  2014. end;
  2015. { ensure that the result type is set }
  2016. if not restypeset then
  2017. begin
  2018. { constructors return their current class type, not the type where the
  2019. constructor is declared, this can be different because of inheritance }
  2020. if (procdefinition.proctypeoption=potype_constructor) and
  2021. assigned(methodpointer) and
  2022. assigned(methodpointer.resulttype.def) and
  2023. (methodpointer.resulttype.def.deftype=classrefdef) then
  2024. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  2025. else
  2026. resulttype:=procdefinition.rettype;
  2027. end
  2028. else
  2029. resulttype:=restype;
  2030. if resulttype.def.needs_inittable then
  2031. include(current_procinfo.flags,pi_needs_implicit_finally);
  2032. if assigned(methodpointer) then
  2033. begin
  2034. resulttypepass(methodpointer);
  2035. { direct call to inherited abstract method, then we
  2036. can already give a error in the compiler instead
  2037. of a runtime error }
  2038. if (nf_inherited in flags) and
  2039. (po_abstractmethod in procdefinition.procoptions) then
  2040. CGMessage(cg_e_cant_call_abstract_method);
  2041. { if an inherited con- or destructor should be }
  2042. { called in a con- or destructor then a warning }
  2043. { will be made }
  2044. { con- and destructors need a pointer to the vmt }
  2045. if (nf_inherited in flags) and
  2046. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2047. is_object(methodpointer.resulttype.def) and
  2048. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  2049. CGMessage(cg_w_member_cd_call_from_method);
  2050. if methodpointer.nodetype<>typen then
  2051. begin
  2052. hpt:=methodpointer;
  2053. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  2054. hpt:=tunarynode(hpt).left;
  2055. if (procdefinition.proctypeoption=potype_constructor) and
  2056. assigned(symtableproc) and
  2057. (symtableproc.symtabletype=withsymtable) and
  2058. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  2059. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2060. { R.Init then R will be initialized by the constructor,
  2061. Also allow it for simple loads }
  2062. if (procdefinition.proctypeoption=potype_constructor) or
  2063. ((hpt.nodetype=loadn) and
  2064. (
  2065. (methodpointer.resulttype.def.deftype=classrefdef) or
  2066. (
  2067. (methodpointer.resulttype.def.deftype=objectdef) and
  2068. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2069. )
  2070. )
  2071. ) then
  2072. method_must_be_valid:=false
  2073. else
  2074. method_must_be_valid:=true;
  2075. set_varstate(methodpointer,vs_used,method_must_be_valid);
  2076. { The object is already used if it is called once }
  2077. if (hpt.nodetype=loadn) and
  2078. (tloadnode(hpt).symtableentry.typ=varsym) then
  2079. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  2080. end;
  2081. { if we are calling the constructor, ignore inherited
  2082. calls }
  2083. if (procdefinition.proctypeoption=potype_constructor) and
  2084. not(nf_inherited in flags) then
  2085. verifyabstractcalls;
  2086. end
  2087. else
  2088. begin
  2089. { When this is method the methodpointer must be available }
  2090. if (right=nil) and
  2091. (procdefinition.owner.symtabletype=objectsymtable) then
  2092. internalerror(200305061);
  2093. end;
  2094. { Change loading of array of const to varargs }
  2095. if assigned(left) and
  2096. is_array_of_const(tparaitem(procdefinition.para.last).paratype.def) and
  2097. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  2098. convert_carg_array_of_const;
  2099. { bind paraitems to the callparanodes and insert hidden parameters }
  2100. aktcallnode:=self;
  2101. bind_paraitem;
  2102. { methodpointer is only needed for virtual calls, and
  2103. it should then be loaded with the VMT }
  2104. if (po_virtualmethod in procdefinition.procoptions) and
  2105. not(assigned(methodpointer) and
  2106. (methodpointer.nodetype=typen)) then
  2107. begin
  2108. if not assigned(methodpointer) then
  2109. internalerror(200305063);
  2110. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  2111. begin
  2112. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  2113. resulttypepass(methodpointer);
  2114. end;
  2115. end
  2116. else
  2117. begin
  2118. { not needed anymore }
  2119. methodpointer.free;
  2120. methodpointer:=nil;
  2121. end;
  2122. { insert type conversions for parameters }
  2123. if assigned(left) then
  2124. tcallparanode(left).insert_typeconv(true);
  2125. errorexit:
  2126. aktcallnode:=oldcallnode;
  2127. end;
  2128. function tcallnode.pass_1 : tnode;
  2129. {$ifdef m68k}
  2130. var
  2131. regi : tregister;
  2132. {$endif}
  2133. label
  2134. errorexit;
  2135. begin
  2136. result:=nil;
  2137. { work trough all parameters to get the register requirements }
  2138. if assigned(left) then
  2139. tcallparanode(left).det_registers;
  2140. { function result node }
  2141. if assigned(_funcretnode) then
  2142. firstpass(_funcretnode);
  2143. { procedure variable ? }
  2144. if assigned(right) then
  2145. begin
  2146. firstpass(right);
  2147. { procedure does a call }
  2148. if not (block_type in [bt_const,bt_type]) then
  2149. include(current_procinfo.flags,pi_do_call);
  2150. rg.incrementotherregisterpushed(all_otherregisters);
  2151. end
  2152. else
  2153. { not a procedure variable }
  2154. begin
  2155. { calc the correture value for the register }
  2156. { handle predefined procedures }
  2157. if (procdefinition.proccalloption=pocall_inline) then
  2158. begin
  2159. if assigned(methodpointer) then
  2160. CGMessage(cg_e_unable_inline_object_methods);
  2161. if assigned(right) then
  2162. CGMessage(cg_e_unable_inline_procvar);
  2163. if not assigned(inlinecode) then
  2164. begin
  2165. if assigned(tprocdef(procdefinition).code) then
  2166. inlinecode:=tprocdef(procdefinition).code.getcopy
  2167. else
  2168. CGMessage(cg_e_no_code_for_inline_stored);
  2169. if assigned(inlinecode) then
  2170. begin
  2171. { consider it has not inlined if called
  2172. again inside the args }
  2173. procdefinition.proccalloption:=pocall_default;
  2174. firstpass(inlinecode);
  2175. end;
  2176. end;
  2177. end
  2178. else
  2179. begin
  2180. if not (block_type in [bt_const,bt_type]) then
  2181. include(current_procinfo.flags,pi_do_call);
  2182. end;
  2183. { It doesn't hurt to calculate it already though :) (JM) }
  2184. rg.incrementotherregisterpushed(tprocdef(procdefinition).usedotherregisters);
  2185. end;
  2186. { get a register for the return value }
  2187. if (not is_void(resulttype.def)) then
  2188. begin
  2189. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2190. begin
  2191. expectloc:=LOC_REFERENCE;
  2192. end
  2193. else
  2194. { for win32 records returned in EDX:EAX, we
  2195. move them to memory after ... }
  2196. if (resulttype.def.deftype=recorddef) then
  2197. begin
  2198. expectloc:=LOC_CREFERENCE;
  2199. end
  2200. else
  2201. { ansi/widestrings must be registered, so we can dispose them }
  2202. if is_ansistring(resulttype.def) or
  2203. is_widestring(resulttype.def) then
  2204. begin
  2205. expectloc:=LOC_CREFERENCE;
  2206. registers32:=1;
  2207. end
  2208. else
  2209. { we have only to handle the result if it is used }
  2210. if (nf_return_value_used in flags) then
  2211. begin
  2212. case resulttype.def.deftype of
  2213. enumdef,
  2214. orddef :
  2215. begin
  2216. if (procdefinition.proctypeoption=potype_constructor) then
  2217. begin
  2218. expectloc:=LOC_REGISTER;
  2219. registers32:=1;
  2220. end
  2221. else
  2222. begin
  2223. expectloc:=LOC_REGISTER;
  2224. if is_64bit(resulttype.def) then
  2225. registers32:=2
  2226. else
  2227. registers32:=1;
  2228. end;
  2229. end;
  2230. floatdef :
  2231. begin
  2232. expectloc:=LOC_FPUREGISTER;
  2233. {$ifdef cpufpemu}
  2234. if (cs_fp_emulation in aktmoduleswitches) then
  2235. registers32:=1
  2236. else
  2237. {$endif cpufpemu}
  2238. {$ifdef m68k}
  2239. if (tfloatdef(resulttype.def).typ=s32real) then
  2240. registers32:=1
  2241. else
  2242. {$endif m68k}
  2243. registersfpu:=1;
  2244. end;
  2245. else
  2246. begin
  2247. expectloc:=LOC_REGISTER;
  2248. registers32:=1;
  2249. end;
  2250. end;
  2251. end
  2252. else
  2253. expectloc:=LOC_VOID;
  2254. end
  2255. else
  2256. expectloc:=LOC_VOID;
  2257. {$ifdef m68k}
  2258. { we need one more address register for virtual calls on m68k }
  2259. if (po_virtualmethod in procdefinition.procoptions) then
  2260. inc(registers32);
  2261. {$endif m68k}
  2262. { a fpu can be used in any procedure !! }
  2263. {$ifdef i386}
  2264. registersfpu:=procdefinition.fpu_used;
  2265. {$endif i386}
  2266. { if this is a call to a method calc the registers }
  2267. if (methodpointer<>nil) then
  2268. begin
  2269. if methodpointer.nodetype<>typen then
  2270. begin
  2271. firstpass(methodpointer);
  2272. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2273. registers32:=max(methodpointer.registers32,registers32);
  2274. {$ifdef SUPPORT_MMX }
  2275. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2276. {$endif SUPPORT_MMX}
  2277. end;
  2278. end;
  2279. { determine the registers of the procedure variable }
  2280. { is this OK for inlined procs also ?? (PM) }
  2281. if assigned(inlinecode) then
  2282. begin
  2283. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  2284. registers32:=max(inlinecode.registers32,registers32);
  2285. {$ifdef SUPPORT_MMX}
  2286. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  2287. {$endif SUPPORT_MMX}
  2288. end;
  2289. { determine the registers of the procedure variable }
  2290. { is this OK for inlined procs also ?? (PM) }
  2291. if assigned(right) then
  2292. begin
  2293. registersfpu:=max(right.registersfpu,registersfpu);
  2294. registers32:=max(right.registers32,registers32);
  2295. {$ifdef SUPPORT_MMX}
  2296. registersmmx:=max(right.registersmmx,registersmmx);
  2297. {$endif SUPPORT_MMX}
  2298. end;
  2299. { determine the registers of the procedure }
  2300. if assigned(left) then
  2301. begin
  2302. registersfpu:=max(left.registersfpu,registersfpu);
  2303. registers32:=max(left.registers32,registers32);
  2304. {$ifdef SUPPORT_MMX}
  2305. registersmmx:=max(left.registersmmx,registersmmx);
  2306. {$endif SUPPORT_MMX}
  2307. end;
  2308. errorexit:
  2309. if assigned(inlinecode) then
  2310. procdefinition.proccalloption:=pocall_inline;
  2311. end;
  2312. {$ifdef state_tracking}
  2313. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2314. var hp:Tcallparanode;
  2315. value:Tnode;
  2316. begin
  2317. track_state_pass:=false;
  2318. hp:=Tcallparanode(left);
  2319. while assigned(hp) do
  2320. begin
  2321. if left.track_state_pass(exec_known) then
  2322. begin
  2323. left.resulttype.def:=nil;
  2324. do_resulttypepass(left);
  2325. end;
  2326. value:=aktstate.find_fact(hp.left);
  2327. if value<>nil then
  2328. begin
  2329. track_state_pass:=true;
  2330. hp.left.destroy;
  2331. hp.left:=value.getcopy;
  2332. do_resulttypepass(hp.left);
  2333. end;
  2334. hp:=Tcallparanode(hp.right);
  2335. end;
  2336. end;
  2337. {$endif}
  2338. function tcallnode.para_count:longint;
  2339. var
  2340. ppn : tcallparanode;
  2341. begin
  2342. result:=0;
  2343. ppn:=tcallparanode(left);
  2344. while assigned(ppn) do
  2345. begin
  2346. if not(assigned(ppn.paraitem) and
  2347. ppn.paraitem.is_hidden) then
  2348. inc(result);
  2349. ppn:=tcallparanode(ppn.right);
  2350. end;
  2351. end;
  2352. function tcallnode.docompare(p: tnode): boolean;
  2353. begin
  2354. docompare :=
  2355. inherited docompare(p) and
  2356. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2357. (procdefinition = tcallnode(p).procdefinition) and
  2358. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2359. ((restypeset and tcallnode(p).restypeset and
  2360. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2361. (not restypeset and not tcallnode(p).restypeset));
  2362. end;
  2363. procedure tcallnode.printnodedata(var t:text);
  2364. begin
  2365. if assigned(procdefinition) and
  2366. (procdefinition.deftype=procdef) then
  2367. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2368. else
  2369. begin
  2370. if assigned(symtableprocentry) then
  2371. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2372. else
  2373. writeln(t,printnodeindention,'proc = <nil>');
  2374. end;
  2375. printnode(t,methodpointer);
  2376. printnode(t,right);
  2377. printnode(t,left);
  2378. end;
  2379. begin
  2380. ccallnode:=tcallnode;
  2381. ccallparanode:=tcallparanode;
  2382. end.
  2383. {
  2384. $Log$
  2385. Revision 1.193 2003-10-08 19:19:45 peter
  2386. * set_varstate cleanup
  2387. Revision 1.192 2003/10/07 21:14:32 peter
  2388. * compare_paras() has a parameter to ignore hidden parameters
  2389. * cross unit overload searching ignores hidden parameters when
  2390. comparing parameter lists. Now function(string):string is
  2391. not overriden with procedure(string) which has the same visible
  2392. parameter list
  2393. Revision 1.191 2003/10/05 21:21:52 peter
  2394. * c style array of const generates callparanodes
  2395. * varargs paraloc fixes
  2396. Revision 1.190 2003/10/05 12:54:17 peter
  2397. * don't check for abstract methods when the constructor is called
  2398. by inherited
  2399. * fix private member error instead of wrong number of parameters
  2400. Revision 1.189 2003/10/04 19:00:52 florian
  2401. * fixed TP 6.0 styled inherited call; fixes IDE with 1.1
  2402. Revision 1.188 2003/10/03 22:00:33 peter
  2403. * parameter alignment fixes
  2404. Revision 1.187 2003/10/03 14:44:38 peter
  2405. * fix IE when callnode was firstpassed twice
  2406. Revision 1.186 2003/10/02 21:13:46 peter
  2407. * protected visibility fixes
  2408. Revision 1.185 2003/10/01 20:34:48 peter
  2409. * procinfo unit contains tprocinfo
  2410. * cginfo renamed to cgbase
  2411. * moved cgmessage to verbose
  2412. * fixed ppc and sparc compiles
  2413. Revision 1.184 2003/09/28 21:44:55 peter
  2414. * fix check that filedef needs var para
  2415. Revision 1.183 2003/09/28 17:55:03 peter
  2416. * parent framepointer changed to hidden parameter
  2417. * tloadparentfpnode added
  2418. Revision 1.182 2003/09/25 21:28:00 peter
  2419. * parameter fixes
  2420. Revision 1.181 2003/09/23 17:56:05 peter
  2421. * locals and paras are allocated in the code generation
  2422. * tvarsym.localloc contains the location of para/local when
  2423. generating code for the current procedure
  2424. Revision 1.180 2003/09/16 16:17:01 peter
  2425. * varspez in calls to push_addr_param
  2426. Revision 1.179 2003/09/07 22:09:35 peter
  2427. * preparations for different default calling conventions
  2428. * various RA fixes
  2429. Revision 1.178 2003/09/06 22:27:08 florian
  2430. * fixed web bug 2669
  2431. * cosmetic fix in printnode
  2432. * tobjectdef.gettypename implemented
  2433. Revision 1.177 2003/09/03 15:55:00 peter
  2434. * NEWRA branch merged
  2435. Revision 1.176.2.3 2003/08/31 21:07:44 daniel
  2436. * callparatemp ripped
  2437. Revision 1.176.2.2 2003/08/27 20:23:55 peter
  2438. * remove old ra code
  2439. Revision 1.176.2.1 2003/08/27 19:55:54 peter
  2440. * first tregister patch
  2441. Revision 1.176 2003/08/23 18:42:57 peter
  2442. * only check for size matches when parameter is enum,ord,float
  2443. Revision 1.175 2003/08/10 17:25:23 peter
  2444. * fixed some reported bugs
  2445. Revision 1.174 2003/07/25 09:54:57 jonas
  2446. * fixed bogus abstract method warnings
  2447. Revision 1.173 2003/06/25 18:31:23 peter
  2448. * sym,def resolving partly rewritten to support also parent objects
  2449. not directly available through the uses clause
  2450. Revision 1.172 2003/06/17 16:34:44 jonas
  2451. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  2452. * renamed all_intregisters to volatile_intregisters and made it
  2453. processor dependent
  2454. Revision 1.171 2003/06/15 16:47:33 jonas
  2455. * fixed revious commit
  2456. Revision 1.170 2003/06/15 15:10:57 jonas
  2457. * callparatemp fix: if a threadvar is a parameter, that paramter also
  2458. does a call
  2459. Revision 1.169 2003/06/13 21:19:30 peter
  2460. * current_procdef removed, use current_procinfo.procdef instead
  2461. Revision 1.168 2003/06/08 20:01:53 jonas
  2462. * optimized assignments with on the right side a function that returns
  2463. an ansi- or widestring
  2464. Revision 1.167 2003/06/08 18:27:15 jonas
  2465. + ability to change the location of a ttempref node with changelocation()
  2466. method. Useful to use instead of copying the contents from one temp to
  2467. another
  2468. + some shortstring optimizations in tassignmentnode that avoid some
  2469. copying (required some shortstring optimizations to be moved from
  2470. resulttype to firstpass, because they work on callnodes and string
  2471. addnodes are only changed to callnodes in the firstpass)
  2472. * allow setting/changing the funcretnode of callnodes after the
  2473. resulttypepass has been done, funcretnode is now a property
  2474. (all of the above should have a quite big effect on callparatemp)
  2475. Revision 1.166 2003/06/08 11:42:33 peter
  2476. * creating class with abstract call checking fixed
  2477. * there will be only one warning for each class, the methods
  2478. are listed as hint
  2479. Revision 1.165 2003/06/07 20:26:32 peter
  2480. * re-resolving added instead of reloading from ppu
  2481. * tderef object added to store deref info for resolving
  2482. Revision 1.164 2003/06/03 21:05:48 peter
  2483. * fix check for procedure without parameters
  2484. * calling constructor as member will not allocate memory
  2485. Revision 1.163 2003/06/03 13:01:59 daniel
  2486. * Register allocator finished
  2487. Revision 1.162 2003/05/26 21:17:17 peter
  2488. * procinlinenode removed
  2489. * aktexit2label removed, fast exit removed
  2490. + tcallnode.inlined_pass_2 added
  2491. Revision 1.161 2003/05/25 11:34:17 peter
  2492. * methodpointer self pushing fixed
  2493. Revision 1.160 2003/05/25 08:59:16 peter
  2494. * inline fixes
  2495. Revision 1.159 2003/05/24 17:16:37 jonas
  2496. * added missing firstpass for callparatemp code
  2497. Revision 1.158 2003/05/23 14:27:35 peter
  2498. * remove some unit dependencies
  2499. * current_procinfo changes to store more info
  2500. Revision 1.157 2003/05/17 14:05:58 jonas
  2501. * fixed callparatemp for ansi/widestring and interfacecoms
  2502. Revision 1.156 2003/05/17 13:30:08 jonas
  2503. * changed tt_persistant to tt_persistent :)
  2504. * tempcreatenode now doesn't accept a boolean anymore for persistent
  2505. temps, but a ttemptype, so you can also create ansistring temps etc
  2506. Revision 1.155 2003/05/16 14:33:31 peter
  2507. * regvar fixes
  2508. Revision 1.154 2003/05/14 19:35:50 jonas
  2509. * fixed callparatemp so it works with vs_var, vs_out and formal const
  2510. parameters
  2511. Revision 1.153 2003/05/13 20:53:41 peter
  2512. * constructors return in register
  2513. Revision 1.152 2003/05/13 15:18:49 peter
  2514. * fixed various crashes
  2515. Revision 1.151 2003/05/11 21:37:03 peter
  2516. * moved implicit exception frame from ncgutil to psub
  2517. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2518. Revision 1.150 2003/05/11 14:45:12 peter
  2519. * tloadnode does not support objectsymtable,withsymtable anymore
  2520. * withnode cleanup
  2521. * direct with rewritten to use temprefnode
  2522. Revision 1.149 2003/05/09 17:47:02 peter
  2523. * self moved to hidden parameter
  2524. * removed hdisposen,hnewn,selfn
  2525. Revision 1.148 2003/05/05 14:53:16 peter
  2526. * vs_hidden replaced by is_hidden boolean
  2527. Revision 1.147 2003/04/27 11:21:33 peter
  2528. * aktprocdef renamed to current_procinfo.procdef
  2529. * procinfo renamed to current_procinfo
  2530. * procinfo will now be stored in current_module so it can be
  2531. cleaned up properly
  2532. * gen_main_procsym changed to create_main_proc and release_main_proc
  2533. to also generate a tprocinfo structure
  2534. * fixed unit implicit initfinal
  2535. Revision 1.146 2003/04/27 09:08:44 jonas
  2536. * do callparatemp stuff only after the parameters have been firstpassed,
  2537. because some nodes are turned into calls during the firstpass
  2538. Revision 1.145 2003/04/27 07:29:50 peter
  2539. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2540. a new procdef declaration
  2541. * aktprocsym removed
  2542. * lexlevel removed, use symtable.symtablelevel instead
  2543. * implicit init/final code uses the normal genentry/genexit
  2544. * funcret state checking updated for new funcret handling
  2545. Revision 1.144 2003/04/25 20:59:33 peter
  2546. * removed funcretn,funcretsym, function result is now in varsym
  2547. and aliases for result and function name are added using absolutesym
  2548. * vs_hidden parameter for funcret passed in parameter
  2549. * vs_hidden fixes
  2550. * writenode changed to printnode and released from extdebug
  2551. * -vp option added to generate a tree.log with the nodetree
  2552. * nicer printnode for statements, callnode
  2553. Revision 1.143 2002/04/25 20:15:39 florian
  2554. * block nodes within expressions shouldn't release the used registers,
  2555. fixed using a flag till the new rg is ready
  2556. Revision 1.142 2003/04/23 20:16:04 peter
  2557. + added currency support based on int64
  2558. + is_64bit for use in cg units instead of is_64bitint
  2559. * removed cgmessage from n386add, replace with internalerrors
  2560. Revision 1.141 2003/04/23 13:21:06 peter
  2561. * fix warning for calling constructor inside constructor
  2562. Revision 1.140 2003/04/23 12:35:34 florian
  2563. * fixed several issues with powerpc
  2564. + applied a patch from Jonas for nested function calls (PowerPC only)
  2565. * ...
  2566. Revision 1.139 2003/04/22 23:50:22 peter
  2567. * firstpass uses expectloc
  2568. * checks if there are differences between the expectloc and
  2569. location.loc from secondpass in EXTDEBUG
  2570. Revision 1.138 2003/04/22 09:53:33 peter
  2571. * fix insert_typeconv to handle new varargs which don't have a
  2572. paraitem set
  2573. Revision 1.137 2003/04/11 16:02:05 peter
  2574. * don't firstpass typen
  2575. Revision 1.136 2003/04/11 15:51:04 peter
  2576. * support subscript,vec for setting methodpointer varstate
  2577. Revision 1.135 2003/04/10 17:57:52 peter
  2578. * vs_hidden released
  2579. Revision 1.134 2003/04/07 11:58:22 jonas
  2580. * more vs_invisible fixes
  2581. Revision 1.133 2003/04/07 10:40:21 jonas
  2582. * fixed VS_HIDDEN for high parameter so it works again
  2583. Revision 1.132 2003/04/04 15:38:56 peter
  2584. * moved generic code from n386cal to ncgcal, i386 now also
  2585. uses the generic ncgcal
  2586. Revision 1.131 2003/03/17 18:54:23 peter
  2587. * fix missing self setting for method to procvar conversion in
  2588. tp_procvar mode
  2589. Revision 1.130 2003/03/17 16:54:41 peter
  2590. * support DefaultHandler and anonymous inheritance fixed
  2591. for message methods
  2592. Revision 1.129 2003/03/17 15:54:22 peter
  2593. * store symoptions also for procdef
  2594. * check symoptions (private,public) when calculating possible
  2595. overload candidates
  2596. Revision 1.128 2003/02/19 22:00:14 daniel
  2597. * Code generator converted to new register notation
  2598. - Horribily outdated todo.txt removed
  2599. Revision 1.127 2003/01/16 22:13:52 peter
  2600. * convert_l3 convertlevel added. This level is used for conversions
  2601. where information can be lost like converting widestring->ansistring
  2602. or dword->byte
  2603. Revision 1.126 2003/01/15 01:44:32 peter
  2604. * merged methodpointer fixes from 1.0.x
  2605. Revision 1.125 2003/01/12 17:52:07 peter
  2606. * only check for auto inherited in objectsymtable
  2607. Revision 1.124 2003/01/09 21:45:46 peter
  2608. * extended information about overloaded candidates when compiled
  2609. with EXTDEBUG
  2610. Revision 1.123 2002/12/26 18:24:33 jonas
  2611. * fixed check for whether or not a high parameter was already generated
  2612. * no type checking/conversions for invisible parameters
  2613. Revision 1.122 2002/12/15 22:50:00 florian
  2614. + some stuff for the new hidden parameter handling added
  2615. Revision 1.121 2002/12/15 21:34:15 peter
  2616. * give sign difference between ordinals a small penalty. This is
  2617. needed to get word->[longword|longint] working
  2618. Revision 1.120 2002/12/15 21:30:12 florian
  2619. * tcallnode.paraitem introduced, all references to defcoll removed
  2620. Revision 1.119 2002/12/15 20:59:58 peter
  2621. * fix crash with default parameters
  2622. Revision 1.118 2002/12/15 11:26:02 peter
  2623. * ignore vs_hidden parameters when choosing overloaded proc
  2624. Revision 1.117 2002/12/11 22:42:28 peter
  2625. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2626. the old code. The new code collects the information about possible
  2627. candidates only once resultting in much less calls to type compare
  2628. routines
  2629. Revision 1.116 2002/12/07 14:27:07 carl
  2630. * 3% memory optimization
  2631. * changed some types
  2632. + added type checking with different size for call node and for
  2633. parameters
  2634. Revision 1.115 2002/12/06 17:51:10 peter
  2635. * merged cdecl and array fixes
  2636. Revision 1.114 2002/12/06 16:56:58 peter
  2637. * only compile cs_fp_emulation support when cpufpuemu is defined
  2638. * define cpufpuemu for m68k only
  2639. Revision 1.113 2002/11/27 20:04:38 peter
  2640. * cdecl array of const fixes
  2641. Revision 1.112 2002/11/27 15:33:46 peter
  2642. * the never ending story of tp procvar hacks
  2643. Revision 1.111 2002/11/27 02:31:17 peter
  2644. * fixed inlinetree parsing in det_resulttype
  2645. Revision 1.110 2002/11/25 18:43:32 carl
  2646. - removed the invalid if <> checking (Delphi is strange on this)
  2647. + implemented abstract warning on instance creation of class with
  2648. abstract methods.
  2649. * some error message cleanups
  2650. Revision 1.109 2002/11/25 17:43:17 peter
  2651. * splitted defbase in defutil,symutil,defcmp
  2652. * merged isconvertable and is_equal into compare_defs(_ext)
  2653. * made operator search faster by walking the list only once
  2654. Revision 1.108 2002/11/18 17:31:54 peter
  2655. * pass proccalloption to ret_in_xxx and push_xxx functions
  2656. Revision 1.107 2002/11/15 01:58:50 peter
  2657. * merged changes from 1.0.7 up to 04-11
  2658. - -V option for generating bug report tracing
  2659. - more tracing for option parsing
  2660. - errors for cdecl and high()
  2661. - win32 import stabs
  2662. - win32 records<=8 are returned in eax:edx (turned off by default)
  2663. - heaptrc update
  2664. - more info for temp management in .s file with EXTDEBUG
  2665. Revision 1.106 2002/10/14 18:20:30 carl
  2666. * var parameter checking for classes and interfaces in Delphi mode
  2667. Revision 1.105 2002/10/06 21:02:17 peter
  2668. * fixed limit checking for qword
  2669. Revision 1.104 2002/10/05 15:15:45 peter
  2670. * Write unknwon compiler proc using Comment and only in Extdebug
  2671. Revision 1.103 2002/10/05 12:43:25 carl
  2672. * fixes for Delphi 6 compilation
  2673. (warning : Some features do not work under Delphi)
  2674. Revision 1.102 2002/10/05 00:48:57 peter
  2675. * support inherited; support for overload as it is handled by
  2676. delphi. This is only for delphi mode as it is working is
  2677. undocumented and hard to predict what is done
  2678. Revision 1.101 2002/09/16 14:11:12 peter
  2679. * add argument to equal_paras() to support default values or not
  2680. Revision 1.100 2002/09/15 17:49:59 peter
  2681. * don't have strict var parameter checking for procedures in the
  2682. system unit
  2683. Revision 1.99 2002/09/09 19:30:34 peter
  2684. * don't allow convertable parameters for var and out parameters in
  2685. delphi and tp mode
  2686. Revision 1.98 2002/09/07 15:25:02 peter
  2687. * old logs removed and tabs fixed
  2688. Revision 1.97 2002/09/07 12:16:05 carl
  2689. * second part bug report 1996 fix, testrange in cordconstnode
  2690. only called if option is set (also make parsing a tiny faster)
  2691. Revision 1.96 2002/09/05 14:53:41 peter
  2692. * fixed old callnode.det_resulttype code
  2693. * old ncal code is default again
  2694. Revision 1.95 2002/09/03 21:32:49 daniel
  2695. * Small bugfix for procdef selection
  2696. Revision 1.94 2002/09/03 19:27:22 daniel
  2697. * Activated new ncal code
  2698. Revision 1.93 2002/09/03 16:26:26 daniel
  2699. * Make Tprocdef.defs protected
  2700. Revision 1.92 2002/09/01 13:28:37 daniel
  2701. - write_access fields removed in favor of a flag
  2702. Revision 1.91 2002/09/01 12:14:15 peter
  2703. * remove debug line
  2704. * containself methods can be called directly
  2705. Revision 1.90 2002/09/01 08:01:16 daniel
  2706. * Removed sets from Tcallnode.det_resulttype
  2707. + Added read/write notifications of variables. These will be usefull
  2708. for providing information for several optimizations. For example
  2709. the value of the loop variable of a for loop does matter is the
  2710. variable is read after the for loop, but if it's no longer used
  2711. or written, it doesn't matter and this can be used to optimize
  2712. the loop code generation.
  2713. Revision 1.89 2002/08/23 16:13:16 peter
  2714. * also firstpass funcretrefnode if available. This was breaking the
  2715. asnode compilerproc code
  2716. Revision 1.88 2002/08/20 10:31:26 daniel
  2717. * Tcallnode.det_resulttype rewritten
  2718. Revision 1.87 2002/08/19 19:36:42 peter
  2719. * More fixes for cross unit inlining, all tnodes are now implemented
  2720. * Moved pocall_internconst to po_internconst because it is not a
  2721. calling type at all and it conflicted when inlining of these small
  2722. functions was requested
  2723. Revision 1.86 2002/08/17 22:09:44 florian
  2724. * result type handling in tcgcal.pass_2 overhauled
  2725. * better tnode.dowrite
  2726. * some ppc stuff fixed
  2727. Revision 1.85 2002/08/17 09:23:34 florian
  2728. * first part of current_procinfo rewrite
  2729. Revision 1.84 2002/08/16 14:24:57 carl
  2730. * issameref() to test if two references are the same (then emit no opcodes)
  2731. + ret_in_reg to replace ret_in_acc
  2732. (fix some register allocation bugs at the same time)
  2733. + save_std_register now has an extra parameter which is the
  2734. usedinproc registers
  2735. Revision 1.83 2002/07/20 11:57:53 florian
  2736. * types.pas renamed to defbase.pas because D6 contains a types
  2737. unit so this would conflicts if D6 programms are compiled
  2738. + Willamette/SSE2 instructions to assembler added
  2739. Revision 1.82 2002/07/19 11:41:35 daniel
  2740. * State tracker work
  2741. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2742. allows the state tracker to change while nodes automatically into
  2743. repeat nodes.
  2744. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2745. 'not(a>b)' is optimized into 'a<=b'.
  2746. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2747. by removing the notn and later switchting the true and falselabels. The
  2748. same is done with 'repeat until not a'.
  2749. Revision 1.81 2002/07/15 18:03:14 florian
  2750. * readded removed changes
  2751. Revision 1.79 2002/07/11 14:41:27 florian
  2752. * start of the new generic parameter handling
  2753. Revision 1.80 2002/07/14 18:00:43 daniel
  2754. + Added the beginning of a state tracker. This will track the values of
  2755. variables through procedures and optimize things away.
  2756. Revision 1.78 2002/07/04 20:43:00 florian
  2757. * first x86-64 patches
  2758. }