ncal.pas 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This file implements the node for sub procedure calling.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,cpuinfo,
  24. node,nbas,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symppu,symsym,symdef,symtable;
  29. type
  30. pcandidate = ^tcandidate;
  31. tcandidate = record
  32. next : pcandidate;
  33. data : tprocdef;
  34. wrongpara,
  35. firstpara : tparaitem;
  36. exact_count,
  37. equal_count,
  38. cl1_count,
  39. cl2_count,
  40. cl3_count,
  41. coper_count : integer; { should be signed }
  42. ordinal_distance : bestreal;
  43. invalid : boolean;
  44. wrongparanr : byte;
  45. end;
  46. tcallnode = class(tbinarynode)
  47. private
  48. paravisible : boolean;
  49. paralength : smallint;
  50. function candidates_find:pcandidate;
  51. procedure candidates_free(procs:pcandidate);
  52. procedure candidates_list(procs:pcandidate;all:boolean);
  53. procedure candidates_get_information(procs:pcandidate);
  54. function candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  55. procedure candidates_find_wrong_para(procs:pcandidate);
  56. {$ifdef EXTDEBUG}
  57. procedure candidates_dump_info(lvl:longint;procs:pcandidate);
  58. {$endif EXTDEBUG}
  59. function gen_self_tree_methodpointer:tnode;
  60. function gen_self_tree:tnode;
  61. function gen_vmt_tree:tnode;
  62. procedure bind_paraitem;
  63. { function return node, this is used to pass the data for a
  64. ret_in_param return value }
  65. _funcretnode : tnode;
  66. procedure setfuncretnode(const returnnode: tnode);
  67. procedure convert_carg_array_of_const;
  68. public
  69. { the symbol containing the definition of the procedure }
  70. { to call }
  71. symtableprocentry : tprocsym;
  72. symtableprocentryderef : tderef;
  73. { symtable where the entry was found, needed for with support }
  74. symtableproc : tsymtable;
  75. { the definition of the procedure to call }
  76. procdefinition : tabstractprocdef;
  77. procdefinitionderef : tderef;
  78. { tree that contains the pointer to the object for this method }
  79. methodpointer : tnode;
  80. { inline function body }
  81. inlinecode : tnode;
  82. { varargs tparaitems }
  83. varargsparas : tlinkedlist;
  84. { node that specifies where the result should be put for calls }
  85. { that return their result in a parameter }
  86. property funcretnode: tnode read _funcretnode write setfuncretnode;
  87. { separately specified resulttype for some compilerprocs (e.g. }
  88. { you can't have a function with an "array of char" resulttype }
  89. { the RTL) (JM) }
  90. restype: ttype;
  91. restypeset: boolean;
  92. { only the processor specific nodes need to override this }
  93. { constructor }
  94. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  95. constructor create_def(l:tnode;def:tprocdef;mp:tnode);virtual;
  96. constructor create_procvar(l,r:tnode);
  97. constructor createintern(const name: string; params: tnode);
  98. constructor createinternres(const name: string; params: tnode; const res: ttype);
  99. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  100. destructor destroy;override;
  101. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  102. procedure ppuwrite(ppufile:tcompilerppufile);override;
  103. procedure 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. (
  1102. (
  1103. (symtableprocentry.first_procdef.proctypeoption=potype_constructor) and
  1104. is_class(tdef(symtableprocentry.owner.defowner))
  1105. ) or
  1106. (po_overload in symtableprocentry.first_procdef.procoptions)
  1107. ) then
  1108. search_class_overloads(symtableprocentry);
  1109. { when the class passed is defined in this unit we
  1110. need to use the scope of that class. This is a trick
  1111. that can be used to access protected members in other
  1112. units. At least kylix supports it this way (PFV) }
  1113. if assigned(symtableproc) and
  1114. (symtableproc.symtabletype=objectsymtable) and
  1115. (symtableproc.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1116. (symtableproc.defowner.owner.unitid=0) then
  1117. topclassh:=tobjectdef(symtableproc.defowner)
  1118. else
  1119. begin
  1120. if assigned(current_procinfo) then
  1121. topclassh:=current_procinfo.procdef._class
  1122. else
  1123. topclassh:=nil;
  1124. end;
  1125. { link all procedures which have the same # of parameters }
  1126. paravisible:=false;
  1127. for j:=1 to symtableprocentry.procdef_count do
  1128. begin
  1129. pd:=symtableprocentry.procdef[j];
  1130. { Is the procdef visible? This needs to be checked on
  1131. procdef level since a symbol can contain both private and
  1132. public declarations. But the check should not be done
  1133. when the callnode is generated by a property }
  1134. if (nf_isproperty in flags) or
  1135. (pd.owner.symtabletype<>objectsymtable) or
  1136. pd.is_visible_for_object(topclassh) then
  1137. begin
  1138. { we have at least one procedure that is visible }
  1139. paravisible:=true;
  1140. { only when the # of parameter are supported by the
  1141. procedure }
  1142. if (paralength>=pd.minparacount) and
  1143. ((po_varargs in pd.procoptions) or { varargs }
  1144. (paralength<=pd.maxparacount)) then
  1145. proc_add(pd);
  1146. end;
  1147. end;
  1148. { remember if the procedure is declared with the overload directive,
  1149. it's information is still needed also after all procs are removed }
  1150. has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
  1151. { when the definition has overload directive set, we search for
  1152. overloaded definitions in the symtablestack. The found
  1153. entries are only added to the procs list and not the procsym, because
  1154. the list can change in every situation }
  1155. if has_overload_directive and
  1156. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1157. begin
  1158. srsymtable:=symtableprocentry.owner.next;
  1159. while assigned(srsymtable) do
  1160. begin
  1161. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1162. begin
  1163. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1164. { process only visible procsyms }
  1165. if assigned(srprocsym) and
  1166. (srprocsym.typ=procsym) and
  1167. srprocsym.is_visible_for_object(topclassh) then
  1168. begin
  1169. { if this procedure doesn't have overload we can stop
  1170. searching }
  1171. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1172. break;
  1173. { process all overloaded definitions }
  1174. for j:=1 to srprocsym.procdef_count do
  1175. begin
  1176. pd:=srprocsym.procdef[j];
  1177. { only when the # of parameter are supported by the
  1178. procedure }
  1179. if (paralength>=pd.minparacount) and
  1180. ((po_varargs in pd.procoptions) or { varargs }
  1181. (paralength<=pd.maxparacount)) then
  1182. begin
  1183. found:=false;
  1184. hp:=procs;
  1185. while assigned(hp) do
  1186. begin
  1187. { Only compare visible parameters for the user }
  1188. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,false,true)>=te_equal then
  1189. begin
  1190. found:=true;
  1191. break;
  1192. end;
  1193. hp:=hp^.next;
  1194. end;
  1195. if not found then
  1196. proc_add(pd);
  1197. end;
  1198. end;
  1199. end;
  1200. end;
  1201. srsymtable:=srsymtable.next;
  1202. end;
  1203. end;
  1204. candidates_find:=procs;
  1205. end;
  1206. procedure tcallnode.candidates_free(procs:pcandidate);
  1207. var
  1208. hpnext,
  1209. hp : pcandidate;
  1210. begin
  1211. hp:=procs;
  1212. while assigned(hp) do
  1213. begin
  1214. hpnext:=hp^.next;
  1215. dispose(hp);
  1216. hp:=hpnext;
  1217. end;
  1218. end;
  1219. procedure tcallnode.candidates_list(procs:pcandidate;all:boolean);
  1220. var
  1221. hp : pcandidate;
  1222. begin
  1223. hp:=procs;
  1224. while assigned(hp) do
  1225. begin
  1226. if all or
  1227. (not hp^.invalid) then
  1228. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname(false));
  1229. hp:=hp^.next;
  1230. end;
  1231. end;
  1232. {$ifdef EXTDEBUG}
  1233. procedure Tcallnode.candidates_dump_info(lvl:longint;procs:pcandidate);
  1234. function ParaTreeStr(p:tcallparanode):string;
  1235. begin
  1236. result:='';
  1237. while assigned(p) do
  1238. begin
  1239. if result<>'' then
  1240. result:=result+',';
  1241. result:=result+p.resulttype.def.typename;
  1242. p:=tcallparanode(p.right);
  1243. end;
  1244. end;
  1245. var
  1246. hp : pcandidate;
  1247. currpara : tparaitem;
  1248. begin
  1249. if not CheckVerbosity(lvl) then
  1250. exit;
  1251. Comment(lvl+V_LineInfo,'Overloaded callnode: '+symtableprocentry.name+'('+ParaTreeStr(tcallparanode(left))+')');
  1252. hp:=procs;
  1253. while assigned(hp) do
  1254. begin
  1255. Comment(lvl,' '+hp^.data.fullprocname(false));
  1256. if (hp^.invalid) then
  1257. Comment(lvl,' invalid')
  1258. else
  1259. begin
  1260. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1261. ' eq: '+tostr(hp^.equal_count)+
  1262. ' l1: '+tostr(hp^.cl1_count)+
  1263. ' l2: '+tostr(hp^.cl2_count)+
  1264. ' l3: '+tostr(hp^.cl3_count)+
  1265. ' oper: '+tostr(hp^.coper_count)+
  1266. ' ord: '+realtostr(hp^.exact_count));
  1267. { Print parameters in left-right order }
  1268. currpara:=hp^.firstpara;
  1269. if assigned(currpara) then
  1270. begin
  1271. while assigned(currpara.next) do
  1272. currpara:=tparaitem(currpara.next);
  1273. end;
  1274. while assigned(currpara) do
  1275. begin
  1276. if (not currpara.is_hidden) then
  1277. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1278. currpara:=tparaitem(currpara.previous);
  1279. end;
  1280. end;
  1281. hp:=hp^.next;
  1282. end;
  1283. end;
  1284. {$endif EXTDEBUG}
  1285. procedure Tcallnode.candidates_get_information(procs:pcandidate);
  1286. var
  1287. hp : pcandidate;
  1288. currpara : tparaitem;
  1289. currparanr : byte;
  1290. def_from,
  1291. def_to : tdef;
  1292. pt : tcallparanode;
  1293. eq : tequaltype;
  1294. convtype : tconverttype;
  1295. pdoper : tprocdef;
  1296. begin
  1297. { process all procs }
  1298. hp:=procs;
  1299. while assigned(hp) do
  1300. begin
  1301. { We compare parameters in reverse order (right to left),
  1302. the firstpara is already pointing to the last parameter
  1303. were we need to start comparing }
  1304. currparanr:=paralength;
  1305. currpara:=hp^.firstpara;
  1306. while assigned(currpara) and (currpara.is_hidden) do
  1307. currpara:=tparaitem(currpara.previous);
  1308. pt:=tcallparanode(left);
  1309. while assigned(pt) and assigned(currpara) do
  1310. begin
  1311. { retrieve current parameter definitions to compares }
  1312. eq:=te_incompatible;
  1313. def_from:=pt.resulttype.def;
  1314. def_to:=currpara.paratype.def;
  1315. if not(assigned(def_from)) then
  1316. internalerror(200212091);
  1317. if not(
  1318. assigned(def_to) or
  1319. ((po_varargs in hp^.data.procoptions) and
  1320. (currparanr>hp^.data.minparacount))
  1321. ) then
  1322. internalerror(200212092);
  1323. { varargs are always equal, but not exact }
  1324. if (po_varargs in hp^.data.procoptions) and
  1325. (currparanr>hp^.data.minparacount) then
  1326. begin
  1327. inc(hp^.equal_count);
  1328. eq:=te_equal;
  1329. end
  1330. else
  1331. { same definition -> exact }
  1332. if (def_from=def_to) then
  1333. begin
  1334. inc(hp^.exact_count);
  1335. eq:=te_exact;
  1336. end
  1337. else
  1338. { for value and const parameters check if a integer is constant or
  1339. included in other integer -> equal and calc ordinal_distance }
  1340. if not(currpara.paratyp in [vs_var,vs_out]) and
  1341. is_integer(def_from) and
  1342. is_integer(def_to) and
  1343. is_in_limit(def_from,def_to) then
  1344. begin
  1345. inc(hp^.equal_count);
  1346. eq:=te_equal;
  1347. hp^.ordinal_distance:=hp^.ordinal_distance+
  1348. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1349. hp^.ordinal_distance:=hp^.ordinal_distance+
  1350. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1351. { Give wrong sign a small penalty, this is need to get a diffrence
  1352. from word->[longword,longint] }
  1353. if is_signed(def_from)<>is_signed(def_to) then
  1354. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1355. end
  1356. else
  1357. { generic type comparision }
  1358. begin
  1359. eq:=compare_defs_ext(def_from,def_to,pt.left.nodetype,
  1360. false,true,convtype,pdoper);
  1361. { when the types are not equal we need to check
  1362. some special case for parameter passing }
  1363. if (eq<te_equal) then
  1364. begin
  1365. if currpara.paratyp in [vs_var,vs_out] then
  1366. begin
  1367. { para requires an equal type so the previous found
  1368. match was not good enough, reset to incompatible }
  1369. eq:=te_incompatible;
  1370. { var_para_allowed will return te_equal and te_convert_l1 to
  1371. make a difference for best matching }
  1372. var_para_allowed(eq,pt.resulttype.def,currpara.paratype.def)
  1373. end
  1374. else
  1375. para_allowed(eq,pt,def_to);
  1376. end;
  1377. case eq of
  1378. te_exact :
  1379. internalerror(200212071); { already checked }
  1380. te_equal :
  1381. inc(hp^.equal_count);
  1382. te_convert_l1 :
  1383. inc(hp^.cl1_count);
  1384. te_convert_l2 :
  1385. inc(hp^.cl2_count);
  1386. te_convert_l3 :
  1387. inc(hp^.cl3_count);
  1388. te_convert_operator :
  1389. inc(hp^.coper_count);
  1390. te_incompatible :
  1391. hp^.invalid:=true;
  1392. else
  1393. internalerror(200212072);
  1394. end;
  1395. end;
  1396. { stop checking when an incompatible parameter is found }
  1397. if hp^.invalid then
  1398. begin
  1399. { store the current parameter info for
  1400. a nice error message when no procedure is found }
  1401. hp^.wrongpara:=currpara;
  1402. hp^.wrongparanr:=currparanr;
  1403. break;
  1404. end;
  1405. {$ifdef EXTDEBUG}
  1406. { store equal in node tree for dump }
  1407. currpara.eqval:=eq;
  1408. {$endif EXTDEBUG}
  1409. { next parameter in the call tree }
  1410. pt:=tcallparanode(pt.right);
  1411. { next parameter for definition, only goto next para
  1412. if we're out of the varargs }
  1413. if not(po_varargs in hp^.data.procoptions) or
  1414. (currparanr<=hp^.data.maxparacount) then
  1415. begin
  1416. { Ignore vs_hidden parameters }
  1417. repeat
  1418. currpara:=tparaitem(currpara.previous);
  1419. until (not assigned(currpara)) or (not currpara.is_hidden);
  1420. end;
  1421. dec(currparanr);
  1422. end;
  1423. if not(hp^.invalid) and
  1424. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1425. internalerror(200212141);
  1426. { next candidate }
  1427. hp:=hp^.next;
  1428. end;
  1429. end;
  1430. function Tcallnode.candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  1431. var
  1432. besthpstart,
  1433. hp : pcandidate;
  1434. cntpd,
  1435. res : integer;
  1436. begin
  1437. {
  1438. Returns the number of candidates left and the
  1439. first candidate is returned in pdbest
  1440. }
  1441. { Setup the first procdef as best, only count it as a result
  1442. when it is valid }
  1443. bestpd:=procs^.data;
  1444. if procs^.invalid then
  1445. cntpd:=0
  1446. else
  1447. cntpd:=1;
  1448. if assigned(procs^.next) then
  1449. begin
  1450. besthpstart:=procs;
  1451. hp:=procs^.next;
  1452. while assigned(hp) do
  1453. begin
  1454. res:=is_better_candidate(hp,besthpstart);
  1455. if (res>0) then
  1456. begin
  1457. { hp is better, flag all procs to be incompatible }
  1458. while (besthpstart<>hp) do
  1459. begin
  1460. besthpstart^.invalid:=true;
  1461. besthpstart:=besthpstart^.next;
  1462. end;
  1463. { besthpstart is already set to hp }
  1464. bestpd:=besthpstart^.data;
  1465. cntpd:=1;
  1466. end
  1467. else
  1468. if (res<0) then
  1469. begin
  1470. { besthpstart is better, flag current hp to be incompatible }
  1471. hp^.invalid:=true;
  1472. end
  1473. else
  1474. begin
  1475. { res=0, both are valid }
  1476. if not hp^.invalid then
  1477. inc(cntpd);
  1478. end;
  1479. hp:=hp^.next;
  1480. end;
  1481. end;
  1482. candidates_choose_best:=cntpd;
  1483. end;
  1484. procedure tcallnode.candidates_find_wrong_para(procs:pcandidate);
  1485. var
  1486. currparanr : smallint;
  1487. hp : pcandidate;
  1488. pt : tcallparanode;
  1489. begin
  1490. { Only process the first overloaded procdef }
  1491. hp:=procs;
  1492. { Find callparanode corresponding to the argument }
  1493. pt:=tcallparanode(left);
  1494. currparanr:=paralength;
  1495. while assigned(pt) and
  1496. (currparanr>hp^.wrongparanr) do
  1497. begin
  1498. pt:=tcallparanode(pt.right);
  1499. dec(currparanr);
  1500. end;
  1501. if (currparanr<>hp^.wrongparanr) or
  1502. not assigned(pt) then
  1503. internalerror(200212094);
  1504. { Show error message, when it was a var or out parameter
  1505. guess that it is a missing typeconv }
  1506. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1507. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  1508. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1509. else
  1510. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1511. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1512. end;
  1513. function tcallnode.gen_self_tree_methodpointer:tnode;
  1514. var
  1515. hsym : tvarsym;
  1516. begin
  1517. { find self field in methodpointer record }
  1518. hsym:=tvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1519. if not assigned(hsym) then
  1520. internalerror(200305251);
  1521. { Load tmehodpointer(right).self }
  1522. result:=csubscriptnode.create(
  1523. hsym,
  1524. ctypeconvnode.create_explicit(right.getcopy,methodpointertype));
  1525. end;
  1526. function tcallnode.gen_self_tree:tnode;
  1527. var
  1528. selftree : tnode;
  1529. begin
  1530. selftree:=nil;
  1531. { constructors }
  1532. if (procdefinition.proctypeoption=potype_constructor) then
  1533. begin
  1534. if not(nf_inherited in flags) then
  1535. begin
  1536. { push 0 as self when allocation is needed }
  1537. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1538. (nf_new_call in flags) then
  1539. selftree:=cpointerconstnode.create(0,voidpointertype)
  1540. else
  1541. begin
  1542. if methodpointer.nodetype=typen then
  1543. selftree:=load_self_node
  1544. else
  1545. selftree:=methodpointer.getcopy;
  1546. end;
  1547. end
  1548. else
  1549. selftree:=load_self_node;
  1550. end
  1551. else
  1552. begin
  1553. { Calling a static/class method from a non-static/class method,
  1554. then we need to load self with the VMT }
  1555. if (
  1556. (po_classmethod in procdefinition.procoptions) and
  1557. not(assigned(current_procinfo.procdef) and
  1558. (po_classmethod in current_procinfo.procdef.procoptions))
  1559. ) or
  1560. (
  1561. (po_staticmethod in procdefinition.procoptions) and
  1562. not(assigned(current_procinfo.procdef) and
  1563. (po_staticmethod in current_procinfo.procdef.procoptions))
  1564. ) then
  1565. begin
  1566. if (procdefinition.deftype<>procdef) then
  1567. internalerror(200305062);
  1568. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1569. begin
  1570. if methodpointer.resulttype.def.deftype=classrefdef then
  1571. selftree:=methodpointer.getcopy
  1572. else
  1573. selftree:=cloadvmtaddrnode.create(methodpointer.getcopy);
  1574. end
  1575. else
  1576. selftree:=cpointerconstnode.create(0,voidpointertype);
  1577. end
  1578. else
  1579. begin
  1580. if methodpointer.nodetype=typen then
  1581. selftree:=load_self_node
  1582. else
  1583. selftree:=methodpointer.getcopy;
  1584. end;
  1585. end;
  1586. result:=selftree;
  1587. end;
  1588. function tcallnode.gen_vmt_tree:tnode;
  1589. var
  1590. vmttree : tnode;
  1591. begin
  1592. vmttree:=nil;
  1593. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1594. internalerror(200305051);
  1595. { inherited call, no create/destroy }
  1596. if (nf_inherited in flags) then
  1597. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1598. else
  1599. { do not create/destroy when called from member function
  1600. without specifying self explicit }
  1601. if (nf_member_call in flags) then
  1602. begin
  1603. if (methodpointer.resulttype.def.deftype=classrefdef) and
  1604. (procdefinition.proctypeoption=potype_constructor) then
  1605. vmttree:=methodpointer.getcopy
  1606. else
  1607. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1608. end
  1609. else
  1610. { constructor with extended syntax called from new }
  1611. if (nf_new_call in flags) then
  1612. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1613. else
  1614. { destructor with extended syntax called from dispose }
  1615. if (nf_dispose_call in flags) then
  1616. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1617. else
  1618. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1619. begin
  1620. { constructor call via classreference => allocate memory }
  1621. if (procdefinition.proctypeoption=potype_constructor) and
  1622. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1623. vmttree:=methodpointer.getcopy
  1624. else
  1625. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1626. end
  1627. else
  1628. { class }
  1629. if is_class(methodpointer.resulttype.def) then
  1630. begin
  1631. { destructor: release instance, flag(vmt)=1
  1632. constructor: direct call, do nothing, leave vmt=0 }
  1633. if (procdefinition.proctypeoption=potype_destructor) then
  1634. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1635. else
  1636. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1637. end
  1638. else
  1639. { object }
  1640. begin
  1641. { destructor: direct call, no dispose, vmt=0
  1642. constructor: initialize object, load vmt }
  1643. if (procdefinition.proctypeoption=potype_constructor) then
  1644. { old styled inherited call? }
  1645. if (methodpointer.nodetype=typen) then
  1646. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1647. else
  1648. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1649. else
  1650. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1651. end;
  1652. result:=vmttree;
  1653. end;
  1654. procedure tcallnode.bind_paraitem;
  1655. var
  1656. i : integer;
  1657. pt : tcallparanode;
  1658. oldppt : ^tcallparanode;
  1659. varargspara,
  1660. currpara : tparaitem;
  1661. used_by_callnode : boolean;
  1662. hiddentree : tnode;
  1663. newstatement : tstatementnode;
  1664. temp : ttempcreatenode;
  1665. begin
  1666. pt:=tcallparanode(left);
  1667. oldppt:=@left;
  1668. { flag all callparanodes that belong to the varargs }
  1669. i:=paralength;
  1670. while (i>procdefinition.maxparacount) do
  1671. begin
  1672. include(pt.flags,nf_varargs_para);
  1673. oldppt:[email protected];
  1674. pt:=tcallparanode(pt.right);
  1675. dec(i);
  1676. end;
  1677. { skip varargs that are inserted by array of const }
  1678. while assigned(pt) and
  1679. (nf_varargs_para in pt.flags) do
  1680. pt:=tcallparanode(pt.right);
  1681. { process normal parameters and insert hidden parameters }
  1682. currpara:=tparaitem(procdefinition.Para.last);
  1683. while assigned(currpara) do
  1684. begin
  1685. if currpara.is_hidden then
  1686. begin
  1687. { generate hidden tree }
  1688. used_by_callnode:=false;
  1689. hiddentree:=nil;
  1690. if (vo_is_funcret in tvarsym(currpara.parasym).varoptions) then
  1691. begin
  1692. { Generate funcretnode if not specified }
  1693. if assigned(funcretnode) then
  1694. begin
  1695. hiddentree:=funcretnode.getcopy;
  1696. end
  1697. else
  1698. begin
  1699. hiddentree:=internalstatements(newstatement,false);
  1700. { need to use resulttype instead of procdefinition.rettype,
  1701. because they can be different }
  1702. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent);
  1703. addstatement(newstatement,temp);
  1704. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1705. addstatement(newstatement,ctemprefnode.create(temp));
  1706. end;
  1707. end
  1708. else
  1709. if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1710. begin
  1711. if not assigned(pt) then
  1712. internalerror(200304082);
  1713. { we need the information of the next parameter }
  1714. hiddentree:=gen_high_tree(pt.left,is_open_string(tparaitem(currpara.previous).paratype.def));
  1715. end
  1716. else
  1717. if vo_is_self in tvarsym(currpara.parasym).varoptions then
  1718. begin
  1719. if assigned(right) then
  1720. hiddentree:=gen_self_tree_methodpointer
  1721. else
  1722. hiddentree:=gen_self_tree;
  1723. end
  1724. else
  1725. if vo_is_vmt in tvarsym(currpara.parasym).varoptions then
  1726. begin
  1727. hiddentree:=gen_vmt_tree;
  1728. end
  1729. else
  1730. if vo_is_parentfp in tvarsym(currpara.parasym).varoptions then
  1731. begin
  1732. if not(assigned(procdefinition.owner.defowner)) then
  1733. internalerror(200309287);
  1734. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1735. end;
  1736. { add the hidden parameter }
  1737. if not assigned(hiddentree) then
  1738. internalerror(200304073);
  1739. { Already insert para and let the previous node point to
  1740. this new node }
  1741. pt:=ccallparanode.create(hiddentree,oldppt^);
  1742. pt.used_by_callnode:=used_by_callnode;
  1743. oldppt^:=pt;
  1744. end;
  1745. if not assigned(pt) then
  1746. internalerror(200310052);
  1747. pt.paraitem:=currpara;
  1748. oldppt:[email protected];
  1749. pt:=tcallparanode(pt.right);
  1750. currpara:=tparaitem(currpara.previous)
  1751. end;
  1752. { Create paraitems for varargs }
  1753. pt:=tcallparanode(left);
  1754. while assigned(pt) do
  1755. begin
  1756. if nf_varargs_para in pt.flags then
  1757. begin
  1758. if not assigned(varargsparas) then
  1759. varargsparas:=tlinkedlist.create;
  1760. varargspara:=tparaitem.create;
  1761. varargspara.paratyp:=vs_value;
  1762. varargspara.paratype:=pt.resulttype;
  1763. varargsparas.concat(varargspara);
  1764. pt.paraitem:=varargspara;
  1765. end;
  1766. pt:=tcallparanode(pt.right);
  1767. end;
  1768. end;
  1769. function tcallnode.det_resulttype:tnode;
  1770. var
  1771. procs : pcandidate;
  1772. oldcallnode : tcallnode;
  1773. hpt : tnode;
  1774. pt : tcallparanode;
  1775. lastpara : longint;
  1776. currpara : tparaitem;
  1777. cand_cnt : integer;
  1778. i : longint;
  1779. method_must_be_valid,
  1780. is_const : boolean;
  1781. label
  1782. errorexit;
  1783. begin
  1784. result:=nil;
  1785. procs:=nil;
  1786. oldcallnode:=aktcallnode;
  1787. aktcallnode:=nil;
  1788. { determine length of parameter list }
  1789. pt:=tcallparanode(left);
  1790. paralength:=0;
  1791. while assigned(pt) do
  1792. begin
  1793. inc(paralength);
  1794. pt:=tcallparanode(pt.right);
  1795. end;
  1796. { determine the type of the parameters }
  1797. if assigned(left) then
  1798. begin
  1799. tcallparanode(left).get_paratype;
  1800. if codegenerror then
  1801. goto errorexit;
  1802. end;
  1803. { procedure variable ? }
  1804. if assigned(right) then
  1805. begin
  1806. set_varstate(right,vs_used,true);
  1807. resulttypepass(right);
  1808. if codegenerror then
  1809. exit;
  1810. procdefinition:=tabstractprocdef(right.resulttype.def);
  1811. { Compare parameters from right to left }
  1812. currpara:=tparaitem(procdefinition.Para.last);
  1813. while assigned(currpara) and (currpara.is_hidden) do
  1814. currpara:=tparaitem(currpara.previous);
  1815. pt:=tcallparanode(left);
  1816. lastpara:=paralength;
  1817. while assigned(currpara) and assigned(pt) do
  1818. begin
  1819. { only goto next para if we're out of the varargs }
  1820. if not(po_varargs in procdefinition.procoptions) or
  1821. (lastpara<=procdefinition.maxparacount) then
  1822. begin
  1823. repeat
  1824. currpara:=tparaitem(currpara.previous);
  1825. until (not assigned(currpara)) or (not currpara.is_hidden);
  1826. end;
  1827. pt:=tcallparanode(pt.right);
  1828. dec(lastpara);
  1829. end;
  1830. if assigned(pt) or assigned(currpara) then
  1831. begin
  1832. if assigned(pt) then
  1833. aktfilepos:=pt.fileinfo;
  1834. CGMessage(parser_e_wrong_parameter_size);
  1835. goto errorexit;
  1836. end;
  1837. end
  1838. else
  1839. { not a procedure variable }
  1840. begin
  1841. { do we know the procedure to call ? }
  1842. if not(assigned(procdefinition)) then
  1843. begin
  1844. procs:=candidates_find;
  1845. { no procedures found? then there is something wrong
  1846. with the parameter size or the procedures are
  1847. not accessible }
  1848. if not assigned(procs) then
  1849. begin
  1850. { when it's an auto inherited call and there
  1851. is no procedure found, but the procedures
  1852. were defined with overload directive and at
  1853. least two procedures are defined then we ignore
  1854. this inherited by inserting a nothingn. Only
  1855. do this ugly hack in Delphi mode as it looks more
  1856. like a bug. It's also not documented }
  1857. if (m_delphi in aktmodeswitches) and
  1858. (nf_anon_inherited in flags) and
  1859. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1860. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1861. (symtableprocentry.procdef_count>=2) then
  1862. result:=cnothingnode.create
  1863. else
  1864. begin
  1865. { in tp mode we can try to convert to procvar if
  1866. there are no parameters specified. Only try it
  1867. when there is only one proc definition, else the
  1868. loadnode will give a strange error }
  1869. if not(assigned(left)) and
  1870. not(nf_inherited in flags) and
  1871. (m_tp_procvar in aktmodeswitches) and
  1872. (symtableprocentry.procdef_count=1) then
  1873. begin
  1874. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1875. if assigned(methodpointer) then
  1876. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1877. resulttypepass(hpt);
  1878. result:=hpt;
  1879. end
  1880. else
  1881. begin
  1882. if assigned(left) then
  1883. aktfilepos:=left.fileinfo;
  1884. if paravisible then
  1885. begin
  1886. CGMessage(parser_e_wrong_parameter_size);
  1887. symtableprocentry.write_parameter_lists(nil);
  1888. end
  1889. else
  1890. CGMessage(parser_e_cant_access_private_member);
  1891. end;
  1892. end;
  1893. goto errorexit;
  1894. end;
  1895. { Retrieve information about the candidates }
  1896. candidates_get_information(procs);
  1897. {$ifdef EXTDEBUG}
  1898. { Display info when multiple candidates are found }
  1899. if assigned(procs^.next) then
  1900. candidates_dump_info(V_Debug,procs);
  1901. {$endif EXTDEBUG}
  1902. { Choose the best candidate and count the number of
  1903. candidates left }
  1904. cand_cnt:=candidates_choose_best(procs,tprocdef(procdefinition));
  1905. { All parameters are checked, check if there are any
  1906. procedures left }
  1907. if cand_cnt>0 then
  1908. begin
  1909. { Multiple candidates left? }
  1910. if cand_cnt>1 then
  1911. begin
  1912. CGMessage(cg_e_cant_choose_overload_function);
  1913. {$ifdef EXTDEBUG}
  1914. candidates_dump_info(V_Hint,procs);
  1915. {$else}
  1916. candidates_list(procs,false);
  1917. {$endif EXTDEBUG}
  1918. { we'll just use the first candidate to make the
  1919. call }
  1920. end;
  1921. { assign procdefinition }
  1922. if symtableproc=nil then
  1923. symtableproc:=procdefinition.owner;
  1924. { update browser information }
  1925. if make_ref then
  1926. begin
  1927. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1928. inc(tprocdef(procdefinition).refcount);
  1929. if tprocdef(procdefinition).defref=nil then
  1930. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1931. end;
  1932. end
  1933. else
  1934. begin
  1935. { No candidates left, this must be a type error,
  1936. because wrong size is already checked. procdefinition
  1937. is filled with the first (random) definition that is
  1938. found. We use this definition to display a nice error
  1939. message that the wrong type is passed }
  1940. candidates_find_wrong_para(procs);
  1941. candidates_list(procs,true);
  1942. {$ifdef EXTDEBUG}
  1943. candidates_dump_info(V_Hint,procs);
  1944. {$endif EXTDEBUG}
  1945. { We can not proceed, release all procs and exit }
  1946. candidates_free(procs);
  1947. goto errorexit;
  1948. end;
  1949. candidates_free(procs);
  1950. end; { end of procedure to call determination }
  1951. { add needed default parameters }
  1952. if assigned(procdefinition) and
  1953. (paralength<procdefinition.maxparacount) then
  1954. begin
  1955. currpara:=tparaitem(procdefinition.Para.first);
  1956. i:=0;
  1957. while (i<paralength) do
  1958. begin
  1959. if not assigned(currpara) then
  1960. internalerror(200306181);
  1961. if not currpara.is_hidden then
  1962. inc(i);
  1963. currpara:=tparaitem(currpara.next);
  1964. end;
  1965. while assigned(currpara) and
  1966. currpara.is_hidden do
  1967. currpara:=tparaitem(currpara.next);
  1968. while assigned(currpara) do
  1969. begin
  1970. if not assigned(currpara.defaultvalue) then
  1971. internalerror(200212142);
  1972. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1973. currpara:=tparaitem(currpara.next);
  1974. end;
  1975. end;
  1976. end;
  1977. { handle predefined procedures }
  1978. is_const:=(po_internconst in procdefinition.procoptions) and
  1979. ((block_type in [bt_const,bt_type]) or
  1980. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1981. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1982. begin
  1983. if assigned(left) then
  1984. begin
  1985. { ptr and settextbuf needs two args }
  1986. if assigned(tcallparanode(left).right) then
  1987. begin
  1988. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1989. left:=nil;
  1990. end
  1991. else
  1992. begin
  1993. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1994. tcallparanode(left).left:=nil;
  1995. end;
  1996. end
  1997. else
  1998. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1999. result:=hpt;
  2000. goto errorexit;
  2001. end;
  2002. { ensure that the result type is set }
  2003. if not restypeset then
  2004. begin
  2005. { constructors return their current class type, not the type where the
  2006. constructor is declared, this can be different because of inheritance }
  2007. if (procdefinition.proctypeoption=potype_constructor) and
  2008. assigned(methodpointer) and
  2009. assigned(methodpointer.resulttype.def) and
  2010. (methodpointer.resulttype.def.deftype=classrefdef) then
  2011. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  2012. else
  2013. resulttype:=procdefinition.rettype;
  2014. end
  2015. else
  2016. resulttype:=restype;
  2017. if resulttype.def.needs_inittable then
  2018. include(current_procinfo.flags,pi_needs_implicit_finally);
  2019. if assigned(methodpointer) then
  2020. begin
  2021. resulttypepass(methodpointer);
  2022. { direct call to inherited abstract method, then we
  2023. can already give a error in the compiler instead
  2024. of a runtime error }
  2025. if (nf_inherited in flags) and
  2026. (po_abstractmethod in procdefinition.procoptions) then
  2027. CGMessage(cg_e_cant_call_abstract_method);
  2028. { if an inherited con- or destructor should be }
  2029. { called in a con- or destructor then a warning }
  2030. { will be made }
  2031. { con- and destructors need a pointer to the vmt }
  2032. if (nf_inherited in flags) and
  2033. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2034. is_object(methodpointer.resulttype.def) and
  2035. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  2036. CGMessage(cg_w_member_cd_call_from_method);
  2037. if methodpointer.nodetype<>typen then
  2038. begin
  2039. hpt:=methodpointer;
  2040. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  2041. hpt:=tunarynode(hpt).left;
  2042. if (procdefinition.proctypeoption=potype_constructor) and
  2043. assigned(symtableproc) and
  2044. (symtableproc.symtabletype=withsymtable) and
  2045. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  2046. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2047. { R.Init then R will be initialized by the constructor,
  2048. Also allow it for simple loads }
  2049. if (procdefinition.proctypeoption=potype_constructor) or
  2050. ((hpt.nodetype=loadn) and
  2051. (
  2052. (methodpointer.resulttype.def.deftype=classrefdef) or
  2053. (
  2054. (methodpointer.resulttype.def.deftype=objectdef) and
  2055. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2056. )
  2057. )
  2058. ) then
  2059. method_must_be_valid:=false
  2060. else
  2061. method_must_be_valid:=true;
  2062. set_varstate(methodpointer,vs_used,method_must_be_valid);
  2063. { The object is already used if it is called once }
  2064. if (hpt.nodetype=loadn) and
  2065. (tloadnode(hpt).symtableentry.typ=varsym) then
  2066. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  2067. end;
  2068. { if we are calling the constructor, ignore inherited
  2069. calls }
  2070. if (procdefinition.proctypeoption=potype_constructor) and
  2071. not(nf_inherited in flags) then
  2072. verifyabstractcalls;
  2073. end
  2074. else
  2075. begin
  2076. { When this is method the methodpointer must be available }
  2077. if (right=nil) and
  2078. (procdefinition.owner.symtabletype=objectsymtable) then
  2079. internalerror(200305061);
  2080. end;
  2081. { Change loading of array of const to varargs }
  2082. if assigned(left) and
  2083. is_array_of_const(tparaitem(procdefinition.para.last).paratype.def) and
  2084. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  2085. convert_carg_array_of_const;
  2086. { bind paraitems to the callparanodes and insert hidden parameters }
  2087. aktcallnode:=self;
  2088. bind_paraitem;
  2089. { methodpointer is only needed for virtual calls, and
  2090. it should then be loaded with the VMT }
  2091. if (po_virtualmethod in procdefinition.procoptions) and
  2092. not(assigned(methodpointer) and
  2093. (methodpointer.nodetype=typen)) then
  2094. begin
  2095. if not assigned(methodpointer) then
  2096. internalerror(200305063);
  2097. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  2098. begin
  2099. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  2100. resulttypepass(methodpointer);
  2101. end;
  2102. end
  2103. else
  2104. begin
  2105. { not needed anymore }
  2106. methodpointer.free;
  2107. methodpointer:=nil;
  2108. end;
  2109. { insert type conversions for parameters }
  2110. if assigned(left) then
  2111. tcallparanode(left).insert_typeconv(true);
  2112. errorexit:
  2113. aktcallnode:=oldcallnode;
  2114. end;
  2115. function tcallnode.pass_1 : tnode;
  2116. {$ifdef m68k}
  2117. var
  2118. regi : tregister;
  2119. {$endif}
  2120. label
  2121. errorexit;
  2122. begin
  2123. result:=nil;
  2124. { work trough all parameters to get the register requirements }
  2125. if assigned(left) then
  2126. tcallparanode(left).det_registers;
  2127. { function result node }
  2128. if assigned(_funcretnode) then
  2129. firstpass(_funcretnode);
  2130. { procedure variable ? }
  2131. if assigned(right) then
  2132. begin
  2133. firstpass(right);
  2134. { procedure does a call }
  2135. if not (block_type in [bt_const,bt_type]) then
  2136. include(current_procinfo.flags,pi_do_call);
  2137. end
  2138. else
  2139. { not a procedure variable }
  2140. begin
  2141. { calc the correture value for the register }
  2142. { handle predefined procedures }
  2143. if (procdefinition.proccalloption=pocall_inline) then
  2144. begin
  2145. if assigned(methodpointer) then
  2146. CGMessage(cg_e_unable_inline_object_methods);
  2147. if assigned(right) then
  2148. CGMessage(cg_e_unable_inline_procvar);
  2149. if not assigned(inlinecode) then
  2150. begin
  2151. if assigned(tprocdef(procdefinition).code) then
  2152. inlinecode:=tprocdef(procdefinition).code.getcopy
  2153. else
  2154. CGMessage(cg_e_no_code_for_inline_stored);
  2155. if assigned(inlinecode) then
  2156. begin
  2157. { consider it has not inlined if called
  2158. again inside the args }
  2159. procdefinition.proccalloption:=pocall_default;
  2160. firstpass(inlinecode);
  2161. end;
  2162. end;
  2163. end
  2164. else
  2165. begin
  2166. if not (block_type in [bt_const,bt_type]) then
  2167. include(current_procinfo.flags,pi_do_call);
  2168. end;
  2169. end;
  2170. { get a register for the return value }
  2171. if (not is_void(resulttype.def)) then
  2172. begin
  2173. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2174. begin
  2175. expectloc:=LOC_REFERENCE;
  2176. end
  2177. else
  2178. { for win32 records returned in EDX:EAX, we
  2179. move them to memory after ... }
  2180. if (resulttype.def.deftype=recorddef) then
  2181. begin
  2182. expectloc:=LOC_CREFERENCE;
  2183. end
  2184. else
  2185. { ansi/widestrings must be registered, so we can dispose them }
  2186. if is_ansistring(resulttype.def) or
  2187. is_widestring(resulttype.def) then
  2188. begin
  2189. expectloc:=LOC_CREFERENCE;
  2190. registers32:=1;
  2191. end
  2192. else
  2193. { we have only to handle the result if it is used }
  2194. if (nf_return_value_used in flags) then
  2195. begin
  2196. case resulttype.def.deftype of
  2197. enumdef,
  2198. orddef :
  2199. begin
  2200. if (procdefinition.proctypeoption=potype_constructor) then
  2201. begin
  2202. expectloc:=LOC_REGISTER;
  2203. registers32:=1;
  2204. end
  2205. else
  2206. begin
  2207. expectloc:=LOC_REGISTER;
  2208. if is_64bit(resulttype.def) then
  2209. registers32:=2
  2210. else
  2211. registers32:=1;
  2212. end;
  2213. end;
  2214. floatdef :
  2215. begin
  2216. expectloc:=LOC_FPUREGISTER;
  2217. {$ifdef cpufpemu}
  2218. if (cs_fp_emulation in aktmoduleswitches) then
  2219. registers32:=1
  2220. else
  2221. {$endif cpufpemu}
  2222. {$ifdef m68k}
  2223. if (tfloatdef(resulttype.def).typ=s32real) then
  2224. registers32:=1
  2225. else
  2226. {$endif m68k}
  2227. registersfpu:=1;
  2228. end;
  2229. else
  2230. begin
  2231. expectloc:=LOC_REGISTER;
  2232. registers32:=1;
  2233. end;
  2234. end;
  2235. end
  2236. else
  2237. expectloc:=LOC_VOID;
  2238. end
  2239. else
  2240. expectloc:=LOC_VOID;
  2241. {$ifdef m68k}
  2242. { we need one more address register for virtual calls on m68k }
  2243. if (po_virtualmethod in procdefinition.procoptions) then
  2244. inc(registers32);
  2245. {$endif m68k}
  2246. { a fpu can be used in any procedure !! }
  2247. {$ifdef i386}
  2248. registersfpu:=procdefinition.fpu_used;
  2249. {$endif i386}
  2250. { if this is a call to a method calc the registers }
  2251. if (methodpointer<>nil) then
  2252. begin
  2253. if methodpointer.nodetype<>typen then
  2254. begin
  2255. firstpass(methodpointer);
  2256. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2257. registers32:=max(methodpointer.registers32,registers32);
  2258. {$ifdef SUPPORT_MMX }
  2259. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2260. {$endif SUPPORT_MMX}
  2261. end;
  2262. end;
  2263. { determine the registers of the procedure variable }
  2264. { is this OK for inlined procs also ?? (PM) }
  2265. if assigned(inlinecode) then
  2266. begin
  2267. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  2268. registers32:=max(inlinecode.registers32,registers32);
  2269. {$ifdef SUPPORT_MMX}
  2270. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  2271. {$endif SUPPORT_MMX}
  2272. end;
  2273. { determine the registers of the procedure variable }
  2274. { is this OK for inlined procs also ?? (PM) }
  2275. if assigned(right) then
  2276. begin
  2277. registersfpu:=max(right.registersfpu,registersfpu);
  2278. registers32:=max(right.registers32,registers32);
  2279. {$ifdef SUPPORT_MMX}
  2280. registersmmx:=max(right.registersmmx,registersmmx);
  2281. {$endif SUPPORT_MMX}
  2282. end;
  2283. { determine the registers of the procedure }
  2284. if assigned(left) then
  2285. begin
  2286. registersfpu:=max(left.registersfpu,registersfpu);
  2287. registers32:=max(left.registers32,registers32);
  2288. {$ifdef SUPPORT_MMX}
  2289. registersmmx:=max(left.registersmmx,registersmmx);
  2290. {$endif SUPPORT_MMX}
  2291. end;
  2292. errorexit:
  2293. if assigned(inlinecode) then
  2294. procdefinition.proccalloption:=pocall_inline;
  2295. end;
  2296. {$ifdef state_tracking}
  2297. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2298. var hp:Tcallparanode;
  2299. value:Tnode;
  2300. begin
  2301. track_state_pass:=false;
  2302. hp:=Tcallparanode(left);
  2303. while assigned(hp) do
  2304. begin
  2305. if left.track_state_pass(exec_known) then
  2306. begin
  2307. left.resulttype.def:=nil;
  2308. do_resulttypepass(left);
  2309. end;
  2310. value:=aktstate.find_fact(hp.left);
  2311. if value<>nil then
  2312. begin
  2313. track_state_pass:=true;
  2314. hp.left.destroy;
  2315. hp.left:=value.getcopy;
  2316. do_resulttypepass(hp.left);
  2317. end;
  2318. hp:=Tcallparanode(hp.right);
  2319. end;
  2320. end;
  2321. {$endif}
  2322. function tcallnode.para_count:longint;
  2323. var
  2324. ppn : tcallparanode;
  2325. begin
  2326. result:=0;
  2327. ppn:=tcallparanode(left);
  2328. while assigned(ppn) do
  2329. begin
  2330. if not(assigned(ppn.paraitem) and
  2331. ppn.paraitem.is_hidden) then
  2332. inc(result);
  2333. ppn:=tcallparanode(ppn.right);
  2334. end;
  2335. end;
  2336. function tcallnode.docompare(p: tnode): boolean;
  2337. begin
  2338. docompare :=
  2339. inherited docompare(p) and
  2340. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2341. (procdefinition = tcallnode(p).procdefinition) and
  2342. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2343. ((restypeset and tcallnode(p).restypeset and
  2344. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2345. (not restypeset and not tcallnode(p).restypeset));
  2346. end;
  2347. procedure tcallnode.printnodedata(var t:text);
  2348. begin
  2349. if assigned(procdefinition) and
  2350. (procdefinition.deftype=procdef) then
  2351. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2352. else
  2353. begin
  2354. if assigned(symtableprocentry) then
  2355. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2356. else
  2357. writeln(t,printnodeindention,'proc = <nil>');
  2358. end;
  2359. printnode(t,methodpointer);
  2360. printnode(t,right);
  2361. printnode(t,left);
  2362. end;
  2363. begin
  2364. ccallnode:=tcallnode;
  2365. ccallparanode:=tcallparanode;
  2366. end.
  2367. {
  2368. $Log$
  2369. Revision 1.201 2003-10-29 22:01:20 florian
  2370. * fixed passing of dyn. arrays to open array parameters
  2371. Revision 1.200 2003/10/23 14:44:07 peter
  2372. * splitted buildderef and buildderefimpl to fix interface crc
  2373. calculation
  2374. Revision 1.199 2003/10/22 20:40:00 peter
  2375. * write derefdata in a separate ppu entry
  2376. Revision 1.198 2003/10/21 18:17:02 peter
  2377. * only search for overloaded constructors in classes
  2378. Revision 1.197 2003/10/21 15:14:55 peter
  2379. * also search in parents for overloads when calling a constructor
  2380. Revision 1.196 2003/10/13 14:05:12 peter
  2381. * removed is_visible_for_proc
  2382. * search also for class overloads when finding interface
  2383. implementations
  2384. Revision 1.195 2003/10/09 21:31:37 daniel
  2385. * Register allocator splitted, ans abstract now
  2386. Revision 1.194 2003/10/09 15:00:13 florian
  2387. * fixed constructor call in class methods
  2388. Revision 1.193 2003/10/08 19:19:45 peter
  2389. * set_varstate cleanup
  2390. Revision 1.192 2003/10/07 21:14:32 peter
  2391. * compare_paras() has a parameter to ignore hidden parameters
  2392. * cross unit overload searching ignores hidden parameters when
  2393. comparing parameter lists. Now function(string):string is
  2394. not overriden with procedure(string) which has the same visible
  2395. parameter list
  2396. Revision 1.191 2003/10/05 21:21:52 peter
  2397. * c style array of const generates callparanodes
  2398. * varargs paraloc fixes
  2399. Revision 1.190 2003/10/05 12:54:17 peter
  2400. * don't check for abstract methods when the constructor is called
  2401. by inherited
  2402. * fix private member error instead of wrong number of parameters
  2403. Revision 1.189 2003/10/04 19:00:52 florian
  2404. * fixed TP 6.0 styled inherited call; fixes IDE with 1.1
  2405. Revision 1.188 2003/10/03 22:00:33 peter
  2406. * parameter alignment fixes
  2407. Revision 1.187 2003/10/03 14:44:38 peter
  2408. * fix IE when callnode was firstpassed twice
  2409. Revision 1.186 2003/10/02 21:13:46 peter
  2410. * protected visibility fixes
  2411. Revision 1.185 2003/10/01 20:34:48 peter
  2412. * procinfo unit contains tprocinfo
  2413. * cginfo renamed to cgbase
  2414. * moved cgmessage to verbose
  2415. * fixed ppc and sparc compiles
  2416. Revision 1.184 2003/09/28 21:44:55 peter
  2417. * fix check that filedef needs var para
  2418. Revision 1.183 2003/09/28 17:55:03 peter
  2419. * parent framepointer changed to hidden parameter
  2420. * tloadparentfpnode added
  2421. Revision 1.182 2003/09/25 21:28:00 peter
  2422. * parameter fixes
  2423. Revision 1.181 2003/09/23 17:56:05 peter
  2424. * locals and paras are allocated in the code generation
  2425. * tvarsym.localloc contains the location of para/local when
  2426. generating code for the current procedure
  2427. Revision 1.180 2003/09/16 16:17:01 peter
  2428. * varspez in calls to push_addr_param
  2429. Revision 1.179 2003/09/07 22:09:35 peter
  2430. * preparations for different default calling conventions
  2431. * various RA fixes
  2432. Revision 1.178 2003/09/06 22:27:08 florian
  2433. * fixed web bug 2669
  2434. * cosmetic fix in printnode
  2435. * tobjectdef.gettypename implemented
  2436. Revision 1.177 2003/09/03 15:55:00 peter
  2437. * NEWRA branch merged
  2438. Revision 1.176.2.3 2003/08/31 21:07:44 daniel
  2439. * callparatemp ripped
  2440. Revision 1.176.2.2 2003/08/27 20:23:55 peter
  2441. * remove old ra code
  2442. Revision 1.176.2.1 2003/08/27 19:55:54 peter
  2443. * first tregister patch
  2444. Revision 1.176 2003/08/23 18:42:57 peter
  2445. * only check for size matches when parameter is enum,ord,float
  2446. Revision 1.175 2003/08/10 17:25:23 peter
  2447. * fixed some reported bugs
  2448. Revision 1.174 2003/07/25 09:54:57 jonas
  2449. * fixed bogus abstract method warnings
  2450. Revision 1.173 2003/06/25 18:31:23 peter
  2451. * sym,def resolving partly rewritten to support also parent objects
  2452. not directly available through the uses clause
  2453. Revision 1.172 2003/06/17 16:34:44 jonas
  2454. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  2455. * renamed all_intregisters to volatile_intregisters and made it
  2456. processor dependent
  2457. Revision 1.171 2003/06/15 16:47:33 jonas
  2458. * fixed revious commit
  2459. Revision 1.170 2003/06/15 15:10:57 jonas
  2460. * callparatemp fix: if a threadvar is a parameter, that paramter also
  2461. does a call
  2462. Revision 1.169 2003/06/13 21:19:30 peter
  2463. * current_procdef removed, use current_procinfo.procdef instead
  2464. Revision 1.168 2003/06/08 20:01:53 jonas
  2465. * optimized assignments with on the right side a function that returns
  2466. an ansi- or widestring
  2467. Revision 1.167 2003/06/08 18:27:15 jonas
  2468. + ability to change the location of a ttempref node with changelocation()
  2469. method. Useful to use instead of copying the contents from one temp to
  2470. another
  2471. + some shortstring optimizations in tassignmentnode that avoid some
  2472. copying (required some shortstring optimizations to be moved from
  2473. resulttype to firstpass, because they work on callnodes and string
  2474. addnodes are only changed to callnodes in the firstpass)
  2475. * allow setting/changing the funcretnode of callnodes after the
  2476. resulttypepass has been done, funcretnode is now a property
  2477. (all of the above should have a quite big effect on callparatemp)
  2478. Revision 1.166 2003/06/08 11:42:33 peter
  2479. * creating class with abstract call checking fixed
  2480. * there will be only one warning for each class, the methods
  2481. are listed as hint
  2482. Revision 1.165 2003/06/07 20:26:32 peter
  2483. * re-resolving added instead of reloading from ppu
  2484. * tderef object added to store deref info for resolving
  2485. Revision 1.164 2003/06/03 21:05:48 peter
  2486. * fix check for procedure without parameters
  2487. * calling constructor as member will not allocate memory
  2488. Revision 1.163 2003/06/03 13:01:59 daniel
  2489. * Register allocator finished
  2490. Revision 1.162 2003/05/26 21:17:17 peter
  2491. * procinlinenode removed
  2492. * aktexit2label removed, fast exit removed
  2493. + tcallnode.inlined_pass_2 added
  2494. Revision 1.161 2003/05/25 11:34:17 peter
  2495. * methodpointer self pushing fixed
  2496. Revision 1.160 2003/05/25 08:59:16 peter
  2497. * inline fixes
  2498. Revision 1.159 2003/05/24 17:16:37 jonas
  2499. * added missing firstpass for callparatemp code
  2500. Revision 1.158 2003/05/23 14:27:35 peter
  2501. * remove some unit dependencies
  2502. * current_procinfo changes to store more info
  2503. Revision 1.157 2003/05/17 14:05:58 jonas
  2504. * fixed callparatemp for ansi/widestring and interfacecoms
  2505. Revision 1.156 2003/05/17 13:30:08 jonas
  2506. * changed tt_persistant to tt_persistent :)
  2507. * tempcreatenode now doesn't accept a boolean anymore for persistent
  2508. temps, but a ttemptype, so you can also create ansistring temps etc
  2509. Revision 1.155 2003/05/16 14:33:31 peter
  2510. * regvar fixes
  2511. Revision 1.154 2003/05/14 19:35:50 jonas
  2512. * fixed callparatemp so it works with vs_var, vs_out and formal const
  2513. parameters
  2514. Revision 1.153 2003/05/13 20:53:41 peter
  2515. * constructors return in register
  2516. Revision 1.152 2003/05/13 15:18:49 peter
  2517. * fixed various crashes
  2518. Revision 1.151 2003/05/11 21:37:03 peter
  2519. * moved implicit exception frame from ncgutil to psub
  2520. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2521. Revision 1.150 2003/05/11 14:45:12 peter
  2522. * tloadnode does not support objectsymtable,withsymtable anymore
  2523. * withnode cleanup
  2524. * direct with rewritten to use temprefnode
  2525. Revision 1.149 2003/05/09 17:47:02 peter
  2526. * self moved to hidden parameter
  2527. * removed hdisposen,hnewn,selfn
  2528. Revision 1.148 2003/05/05 14:53:16 peter
  2529. * vs_hidden replaced by is_hidden boolean
  2530. Revision 1.147 2003/04/27 11:21:33 peter
  2531. * aktprocdef renamed to current_procinfo.procdef
  2532. * procinfo renamed to current_procinfo
  2533. * procinfo will now be stored in current_module so it can be
  2534. cleaned up properly
  2535. * gen_main_procsym changed to create_main_proc and release_main_proc
  2536. to also generate a tprocinfo structure
  2537. * fixed unit implicit initfinal
  2538. Revision 1.146 2003/04/27 09:08:44 jonas
  2539. * do callparatemp stuff only after the parameters have been firstpassed,
  2540. because some nodes are turned into calls during the firstpass
  2541. Revision 1.145 2003/04/27 07:29:50 peter
  2542. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2543. a new procdef declaration
  2544. * aktprocsym removed
  2545. * lexlevel removed, use symtable.symtablelevel instead
  2546. * implicit init/final code uses the normal genentry/genexit
  2547. * funcret state checking updated for new funcret handling
  2548. Revision 1.144 2003/04/25 20:59:33 peter
  2549. * removed funcretn,funcretsym, function result is now in varsym
  2550. and aliases for result and function name are added using absolutesym
  2551. * vs_hidden parameter for funcret passed in parameter
  2552. * vs_hidden fixes
  2553. * writenode changed to printnode and released from extdebug
  2554. * -vp option added to generate a tree.log with the nodetree
  2555. * nicer printnode for statements, callnode
  2556. Revision 1.143 2002/04/25 20:15:39 florian
  2557. * block nodes within expressions shouldn't release the used registers,
  2558. fixed using a flag till the new rg is ready
  2559. Revision 1.142 2003/04/23 20:16:04 peter
  2560. + added currency support based on int64
  2561. + is_64bit for use in cg units instead of is_64bitint
  2562. * removed cgmessage from n386add, replace with internalerrors
  2563. Revision 1.141 2003/04/23 13:21:06 peter
  2564. * fix warning for calling constructor inside constructor
  2565. Revision 1.140 2003/04/23 12:35:34 florian
  2566. * fixed several issues with powerpc
  2567. + applied a patch from Jonas for nested function calls (PowerPC only)
  2568. * ...
  2569. Revision 1.139 2003/04/22 23:50:22 peter
  2570. * firstpass uses expectloc
  2571. * checks if there are differences between the expectloc and
  2572. location.loc from secondpass in EXTDEBUG
  2573. Revision 1.138 2003/04/22 09:53:33 peter
  2574. * fix insert_typeconv to handle new varargs which don't have a
  2575. paraitem set
  2576. Revision 1.137 2003/04/11 16:02:05 peter
  2577. * don't firstpass typen
  2578. Revision 1.136 2003/04/11 15:51:04 peter
  2579. * support subscript,vec for setting methodpointer varstate
  2580. Revision 1.135 2003/04/10 17:57:52 peter
  2581. * vs_hidden released
  2582. Revision 1.134 2003/04/07 11:58:22 jonas
  2583. * more vs_invisible fixes
  2584. Revision 1.133 2003/04/07 10:40:21 jonas
  2585. * fixed VS_HIDDEN for high parameter so it works again
  2586. Revision 1.132 2003/04/04 15:38:56 peter
  2587. * moved generic code from n386cal to ncgcal, i386 now also
  2588. uses the generic ncgcal
  2589. Revision 1.131 2003/03/17 18:54:23 peter
  2590. * fix missing self setting for method to procvar conversion in
  2591. tp_procvar mode
  2592. Revision 1.130 2003/03/17 16:54:41 peter
  2593. * support DefaultHandler and anonymous inheritance fixed
  2594. for message methods
  2595. Revision 1.129 2003/03/17 15:54:22 peter
  2596. * store symoptions also for procdef
  2597. * check symoptions (private,public) when calculating possible
  2598. overload candidates
  2599. Revision 1.128 2003/02/19 22:00:14 daniel
  2600. * Code generator converted to new register notation
  2601. - Horribily outdated todo.txt removed
  2602. Revision 1.127 2003/01/16 22:13:52 peter
  2603. * convert_l3 convertlevel added. This level is used for conversions
  2604. where information can be lost like converting widestring->ansistring
  2605. or dword->byte
  2606. Revision 1.126 2003/01/15 01:44:32 peter
  2607. * merged methodpointer fixes from 1.0.x
  2608. Revision 1.125 2003/01/12 17:52:07 peter
  2609. * only check for auto inherited in objectsymtable
  2610. Revision 1.124 2003/01/09 21:45:46 peter
  2611. * extended information about overloaded candidates when compiled
  2612. with EXTDEBUG
  2613. Revision 1.123 2002/12/26 18:24:33 jonas
  2614. * fixed check for whether or not a high parameter was already generated
  2615. * no type checking/conversions for invisible parameters
  2616. Revision 1.122 2002/12/15 22:50:00 florian
  2617. + some stuff for the new hidden parameter handling added
  2618. Revision 1.121 2002/12/15 21:34:15 peter
  2619. * give sign difference between ordinals a small penalty. This is
  2620. needed to get word->[longword|longint] working
  2621. Revision 1.120 2002/12/15 21:30:12 florian
  2622. * tcallnode.paraitem introduced, all references to defcoll removed
  2623. Revision 1.119 2002/12/15 20:59:58 peter
  2624. * fix crash with default parameters
  2625. Revision 1.118 2002/12/15 11:26:02 peter
  2626. * ignore vs_hidden parameters when choosing overloaded proc
  2627. Revision 1.117 2002/12/11 22:42:28 peter
  2628. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2629. the old code. The new code collects the information about possible
  2630. candidates only once resultting in much less calls to type compare
  2631. routines
  2632. Revision 1.116 2002/12/07 14:27:07 carl
  2633. * 3% memory optimization
  2634. * changed some types
  2635. + added type checking with different size for call node and for
  2636. parameters
  2637. Revision 1.115 2002/12/06 17:51:10 peter
  2638. * merged cdecl and array fixes
  2639. Revision 1.114 2002/12/06 16:56:58 peter
  2640. * only compile cs_fp_emulation support when cpufpuemu is defined
  2641. * define cpufpuemu for m68k only
  2642. Revision 1.113 2002/11/27 20:04:38 peter
  2643. * cdecl array of const fixes
  2644. Revision 1.112 2002/11/27 15:33:46 peter
  2645. * the never ending story of tp procvar hacks
  2646. Revision 1.111 2002/11/27 02:31:17 peter
  2647. * fixed inlinetree parsing in det_resulttype
  2648. Revision 1.110 2002/11/25 18:43:32 carl
  2649. - removed the invalid if <> checking (Delphi is strange on this)
  2650. + implemented abstract warning on instance creation of class with
  2651. abstract methods.
  2652. * some error message cleanups
  2653. Revision 1.109 2002/11/25 17:43:17 peter
  2654. * splitted defbase in defutil,symutil,defcmp
  2655. * merged isconvertable and is_equal into compare_defs(_ext)
  2656. * made operator search faster by walking the list only once
  2657. Revision 1.108 2002/11/18 17:31:54 peter
  2658. * pass proccalloption to ret_in_xxx and push_xxx functions
  2659. Revision 1.107 2002/11/15 01:58:50 peter
  2660. * merged changes from 1.0.7 up to 04-11
  2661. - -V option for generating bug report tracing
  2662. - more tracing for option parsing
  2663. - errors for cdecl and high()
  2664. - win32 import stabs
  2665. - win32 records<=8 are returned in eax:edx (turned off by default)
  2666. - heaptrc update
  2667. - more info for temp management in .s file with EXTDEBUG
  2668. Revision 1.106 2002/10/14 18:20:30 carl
  2669. * var parameter checking for classes and interfaces in Delphi mode
  2670. Revision 1.105 2002/10/06 21:02:17 peter
  2671. * fixed limit checking for qword
  2672. Revision 1.104 2002/10/05 15:15:45 peter
  2673. * Write unknwon compiler proc using Comment and only in Extdebug
  2674. Revision 1.103 2002/10/05 12:43:25 carl
  2675. * fixes for Delphi 6 compilation
  2676. (warning : Some features do not work under Delphi)
  2677. Revision 1.102 2002/10/05 00:48:57 peter
  2678. * support inherited; support for overload as it is handled by
  2679. delphi. This is only for delphi mode as it is working is
  2680. undocumented and hard to predict what is done
  2681. Revision 1.101 2002/09/16 14:11:12 peter
  2682. * add argument to equal_paras() to support default values or not
  2683. Revision 1.100 2002/09/15 17:49:59 peter
  2684. * don't have strict var parameter checking for procedures in the
  2685. system unit
  2686. Revision 1.99 2002/09/09 19:30:34 peter
  2687. * don't allow convertable parameters for var and out parameters in
  2688. delphi and tp mode
  2689. Revision 1.98 2002/09/07 15:25:02 peter
  2690. * old logs removed and tabs fixed
  2691. Revision 1.97 2002/09/07 12:16:05 carl
  2692. * second part bug report 1996 fix, testrange in cordconstnode
  2693. only called if option is set (also make parsing a tiny faster)
  2694. Revision 1.96 2002/09/05 14:53:41 peter
  2695. * fixed old callnode.det_resulttype code
  2696. * old ncal code is default again
  2697. Revision 1.95 2002/09/03 21:32:49 daniel
  2698. * Small bugfix for procdef selection
  2699. Revision 1.94 2002/09/03 19:27:22 daniel
  2700. * Activated new ncal code
  2701. Revision 1.93 2002/09/03 16:26:26 daniel
  2702. * Make Tprocdef.defs protected
  2703. Revision 1.92 2002/09/01 13:28:37 daniel
  2704. - write_access fields removed in favor of a flag
  2705. Revision 1.91 2002/09/01 12:14:15 peter
  2706. * remove debug line
  2707. * containself methods can be called directly
  2708. Revision 1.90 2002/09/01 08:01:16 daniel
  2709. * Removed sets from Tcallnode.det_resulttype
  2710. + Added read/write notifications of variables. These will be usefull
  2711. for providing information for several optimizations. For example
  2712. the value of the loop variable of a for loop does matter is the
  2713. variable is read after the for loop, but if it's no longer used
  2714. or written, it doesn't matter and this can be used to optimize
  2715. the loop code generation.
  2716. Revision 1.89 2002/08/23 16:13:16 peter
  2717. * also firstpass funcretrefnode if available. This was breaking the
  2718. asnode compilerproc code
  2719. Revision 1.88 2002/08/20 10:31:26 daniel
  2720. * Tcallnode.det_resulttype rewritten
  2721. Revision 1.87 2002/08/19 19:36:42 peter
  2722. * More fixes for cross unit inlining, all tnodes are now implemented
  2723. * Moved pocall_internconst to po_internconst because it is not a
  2724. calling type at all and it conflicted when inlining of these small
  2725. functions was requested
  2726. Revision 1.86 2002/08/17 22:09:44 florian
  2727. * result type handling in tcgcal.pass_2 overhauled
  2728. * better tnode.dowrite
  2729. * some ppc stuff fixed
  2730. Revision 1.85 2002/08/17 09:23:34 florian
  2731. * first part of current_procinfo rewrite
  2732. Revision 1.84 2002/08/16 14:24:57 carl
  2733. * issameref() to test if two references are the same (then emit no opcodes)
  2734. + ret_in_reg to replace ret_in_acc
  2735. (fix some register allocation bugs at the same time)
  2736. + save_std_register now has an extra parameter which is the
  2737. usedinproc registers
  2738. Revision 1.83 2002/07/20 11:57:53 florian
  2739. * types.pas renamed to defbase.pas because D6 contains a types
  2740. unit so this would conflicts if D6 programms are compiled
  2741. + Willamette/SSE2 instructions to assembler added
  2742. Revision 1.82 2002/07/19 11:41:35 daniel
  2743. * State tracker work
  2744. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2745. allows the state tracker to change while nodes automatically into
  2746. repeat nodes.
  2747. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2748. 'not(a>b)' is optimized into 'a<=b'.
  2749. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2750. by removing the notn and later switchting the true and falselabels. The
  2751. same is done with 'repeat until not a'.
  2752. Revision 1.81 2002/07/15 18:03:14 florian
  2753. * readded removed changes
  2754. Revision 1.79 2002/07/11 14:41:27 florian
  2755. * start of the new generic parameter handling
  2756. Revision 1.80 2002/07/14 18:00:43 daniel
  2757. + Added the beginning of a state tracker. This will track the values of
  2758. variables through procedures and optimize things away.
  2759. Revision 1.78 2002/07/04 20:43:00 florian
  2760. * first x86-64 patches
  2761. }