ncal.pas 110 KB

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