ncal.pas 109 KB

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