ncal.pas 111 KB

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