ncal.pas 113 KB

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