ncal.pas 112 KB

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