ncal.pas 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  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. node,
  23. {$ifdef state_tracking}
  24. nstate,
  25. {$endif state_tracking}
  26. symbase,symtype,symppu,symsym,symdef,symtable;
  27. type
  28. tcallnode = class(tbinarynode)
  29. { the symbol containing the definition of the procedure }
  30. { to call }
  31. symtableprocentry : tprocsym;
  32. { the symtable containing symtableprocentry }
  33. symtableproc : tsymtable;
  34. { the definition of the procedure to call }
  35. procdefinition : tabstractprocdef;
  36. methodpointer : tnode;
  37. { separately specified resulttype for some compilerprocs (e.g. }
  38. { you can't have a function with an "array of char" resulttype }
  39. { the RTL) (JM) }
  40. restype: ttype;
  41. restypeset: boolean;
  42. { function return reference node, this is used to pass an already
  43. allocated reference for a ret_in_param return value }
  44. funcretrefnode : tnode;
  45. { only the processor specific nodes need to override this }
  46. { constructor }
  47. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  48. constructor createintern(const name: string; params: tnode);
  49. constructor createinternres(const name: string; params: tnode; const res: ttype);
  50. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  51. destructor destroy;override;
  52. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  53. procedure ppuwrite(ppufile:tcompilerppufile);override;
  54. procedure derefimpl;override;
  55. function getcopy : tnode;override;
  56. procedure insertintolist(l : tnodelist);override;
  57. function pass_1 : tnode;override;
  58. {$ifdef nice_ncal}
  59. function choose_definition_to_call(paralength:byte;var errorexit:boolean):Tnode;
  60. {$endif}
  61. function det_resulttype:tnode;override;
  62. {$ifdef state_tracking}
  63. function track_state_pass(exec_known:boolean):boolean;override;
  64. {$endif state_tracking}
  65. function docompare(p: tnode): boolean; override;
  66. procedure set_procvar(procvar:tnode);
  67. end;
  68. tcallnodeclass = class of tcallnode;
  69. tcallparaflags = (
  70. { flags used by tcallparanode }
  71. cpf_exact_match_found,
  72. cpf_convlevel1found,
  73. cpf_convlevel2found,
  74. cpf_is_colon_para
  75. {$ifdef nice_ncal}
  76. ,cpf_nomatchfound
  77. {$endif}
  78. );
  79. tcallparanode = class(tbinarynode)
  80. callparaflags : set of tcallparaflags;
  81. hightree : tnode;
  82. { only the processor specific nodes need to override this }
  83. { constructor }
  84. constructor create(expr,next : tnode);virtual;
  85. destructor destroy;override;
  86. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  87. procedure ppuwrite(ppufile:tcompilerppufile);override;
  88. procedure derefimpl;override;
  89. function getcopy : tnode;override;
  90. procedure insertintolist(l : tnodelist);override;
  91. procedure gen_high_tree(openstring:boolean);
  92. procedure get_paratype;
  93. procedure insert_typeconv(defcoll : tparaitem;do_count : boolean);
  94. procedure det_registers;
  95. procedure firstcallparan(defcoll : tparaitem;do_count : boolean);
  96. procedure secondcallparan(defcoll : tparaitem;
  97. push_from_left_to_right,inlined,is_cdecl : boolean;
  98. para_alignment,para_offset : longint);virtual;abstract;
  99. function docompare(p: tnode): boolean; override;
  100. end;
  101. tcallparanodeclass = class of tcallparanode;
  102. tprocinlinenode = class(tnode)
  103. inlinetree : tnode;
  104. inlineprocdef : tprocdef;
  105. retoffset,para_offset,para_size : longint;
  106. constructor create(p:tprocdef);virtual;
  107. destructor destroy;override;
  108. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  109. procedure ppuwrite(ppufile:tcompilerppufile);override;
  110. procedure derefimpl;override;
  111. function getcopy : tnode;override;
  112. function det_resulttype : tnode;override;
  113. procedure insertintolist(l : tnodelist);override;
  114. function pass_1 : tnode;override;
  115. function docompare(p: tnode): boolean; override;
  116. end;
  117. tprocinlinenodeclass = class of tprocinlinenode;
  118. function reverseparameters(p: tcallparanode): tcallparanode;
  119. var
  120. ccallnode : tcallnodeclass;
  121. ccallparanode : tcallparanodeclass;
  122. cprocinlinenode : tprocinlinenodeclass;
  123. implementation
  124. uses
  125. cutils,globtype,systems,
  126. verbose,globals,
  127. symconst,paramgr,defbase,
  128. htypechk,pass_1,cpuinfo,cpubase,
  129. ncnv,nld,ninl,nadd,ncon,
  130. rgobj,cgbase
  131. ;
  132. {****************************************************************************
  133. HELPERS
  134. ****************************************************************************}
  135. function reverseparameters(p: tcallparanode): tcallparanode;
  136. var
  137. hp1, hp2: tcallparanode;
  138. begin
  139. hp1:=nil;
  140. while assigned(p) do
  141. begin
  142. { pull out }
  143. hp2:=p;
  144. p:=tcallparanode(p.right);
  145. { pull in }
  146. hp2.right:=hp1;
  147. hp1:=hp2;
  148. end;
  149. reverseparameters:=hp1;
  150. end;
  151. procedure search_class_overloads(aprocsym : tprocsym);
  152. { searches n in symtable of pd and all anchestors }
  153. var
  154. speedvalue : cardinal;
  155. srsym : tprocsym;
  156. s : string;
  157. srpdl : pprocdeflist;
  158. objdef : tobjectdef;
  159. begin
  160. if aprocsym.overloadchecked then
  161. exit;
  162. aprocsym.overloadchecked:=true;
  163. if (aprocsym.owner.symtabletype<>objectsymtable) then
  164. internalerror(200111021);
  165. objdef:=tobjectdef(aprocsym.owner.defowner);
  166. { we start in the parent }
  167. if not assigned(objdef.childof) then
  168. exit;
  169. objdef:=objdef.childof;
  170. s:=aprocsym.name;
  171. speedvalue:=getspeedvalue(s);
  172. while assigned(objdef) do
  173. begin
  174. srsym:=tprocsym(objdef.symtable.speedsearch(s,speedvalue));
  175. if assigned(srsym) then
  176. begin
  177. if (srsym.typ<>procsym) then
  178. internalerror(200111022);
  179. if srsym.is_visible_for_proc(aktprocdef) then
  180. begin
  181. srsym.add_para_match_to(Aprocsym);
  182. { we can stop if the overloads were already added
  183. for the found symbol }
  184. if srsym.overloadchecked then
  185. break;
  186. end;
  187. end;
  188. { next parent }
  189. objdef:=objdef.childof;
  190. end;
  191. end;
  192. {****************************************************************************
  193. TCALLPARANODE
  194. ****************************************************************************}
  195. constructor tcallparanode.create(expr,next : tnode);
  196. begin
  197. inherited create(callparan,expr,next);
  198. hightree:=nil;
  199. if assigned(expr) then
  200. expr.set_file_line(self);
  201. callparaflags:=[];
  202. end;
  203. destructor tcallparanode.destroy;
  204. begin
  205. hightree.free;
  206. inherited destroy;
  207. end;
  208. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  209. begin
  210. inherited ppuload(t,ppufile);
  211. ppufile.getsmallset(callparaflags);
  212. hightree:=ppuloadnode(ppufile);
  213. end;
  214. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  215. begin
  216. inherited ppuwrite(ppufile);
  217. ppufile.putsmallset(callparaflags);
  218. ppuwritenode(ppufile,hightree);
  219. end;
  220. procedure tcallparanode.derefimpl;
  221. begin
  222. inherited derefimpl;
  223. if assigned(hightree) then
  224. hightree.derefimpl;
  225. end;
  226. function tcallparanode.getcopy : tnode;
  227. var
  228. n : tcallparanode;
  229. begin
  230. n:=tcallparanode(inherited getcopy);
  231. n.callparaflags:=callparaflags;
  232. if assigned(hightree) then
  233. n.hightree:=hightree.getcopy
  234. else
  235. n.hightree:=nil;
  236. result:=n;
  237. end;
  238. procedure tcallparanode.insertintolist(l : tnodelist);
  239. begin
  240. end;
  241. procedure tcallparanode.get_paratype;
  242. var
  243. old_get_para_resulttype : boolean;
  244. old_array_constructor : boolean;
  245. begin
  246. inc(parsing_para_level);
  247. if assigned(right) then
  248. tcallparanode(right).get_paratype;
  249. old_array_constructor:=allow_array_constructor;
  250. old_get_para_resulttype:=get_para_resulttype;
  251. get_para_resulttype:=true;
  252. allow_array_constructor:=true;
  253. resulttypepass(left);
  254. get_para_resulttype:=old_get_para_resulttype;
  255. allow_array_constructor:=old_array_constructor;
  256. if codegenerror then
  257. resulttype:=generrortype
  258. else
  259. resulttype:=left.resulttype;
  260. dec(parsing_para_level);
  261. end;
  262. function is_var_para_incompatible(from_def,to_def:Tdef):boolean;
  263. {Might be an idea to move this to defbase...}
  264. begin
  265. is_var_para_incompatible:=
  266. { allows conversion from word to integer and
  267. byte to shortint, but only for TP7 compatibility }
  268. (not(
  269. (m_tp7 in aktmodeswitches) and
  270. (from_def.deftype=orddef) and
  271. (to_def.deftype=orddef) and
  272. (from_def.size=to_def.size)
  273. ) and
  274. { an implicit pointer conversion is allowed }
  275. not(
  276. (from_def.deftype=pointerdef) and
  277. (to_def.deftype=pointerdef)
  278. ) and
  279. { child classes can be also passed }
  280. not(
  281. (from_def.deftype=objectdef) and
  282. (to_def.deftype=objectdef) and
  283. tobjectdef(from_def).is_related(tobjectdef(to_def))
  284. ) and
  285. { passing a single element to a openarray of the same type }
  286. not(
  287. (is_open_array(to_def) and
  288. is_equal(tarraydef(to_def).elementtype.def,from_def))
  289. ) and
  290. { an implicit file conversion is also allowed }
  291. { from a typed file to an untyped one }
  292. not(
  293. (from_def.deftype=filedef) and
  294. (to_def.deftype=filedef) and
  295. (tfiledef(to_def).filetyp = ft_untyped) and
  296. (tfiledef(from_def).filetyp = ft_typed)
  297. ) and
  298. not(is_equal(from_def,to_def)));
  299. end;
  300. procedure tcallparanode.insert_typeconv(defcoll : tparaitem;do_count : boolean);
  301. var
  302. oldtype : ttype;
  303. {$ifdef extdebug}
  304. store_count_ref : boolean;
  305. {$endif def extdebug}
  306. p1 : tnode;
  307. begin
  308. inc(parsing_para_level);
  309. if not assigned(defcoll) then
  310. internalerror(200104261);
  311. {$ifdef extdebug}
  312. if do_count then
  313. begin
  314. store_count_ref:=count_ref;
  315. count_ref:=true;
  316. end;
  317. {$endif def extdebug}
  318. if assigned(right) then
  319. begin
  320. { if we are a para that belongs to varargs then keep
  321. the current defcoll }
  322. if (nf_varargs_para in flags) then
  323. tcallparanode(right).insert_typeconv(defcoll,do_count)
  324. else
  325. tcallparanode(right).insert_typeconv(tparaitem(defcoll.next),do_count);
  326. end;
  327. { Be sure to have the resulttype }
  328. if not assigned(left.resulttype.def) then
  329. resulttypepass(left);
  330. { Handle varargs directly, no typeconvs or typechecking needed }
  331. if (nf_varargs_para in flags) then
  332. begin
  333. { convert pascal to C types }
  334. case left.resulttype.def.deftype of
  335. stringdef :
  336. inserttypeconv(left,charpointertype);
  337. floatdef :
  338. inserttypeconv(left,s64floattype);
  339. end;
  340. set_varstate(left,true);
  341. resulttype:=left.resulttype;
  342. dec(parsing_para_level);
  343. exit;
  344. end;
  345. { Do we need arrayconstructor -> set conversion, then insert
  346. it here before the arrayconstructor node breaks the tree
  347. with its conversions of enum->ord }
  348. if (left.nodetype=arrayconstructorn) and
  349. (defcoll.paratype.def.deftype=setdef) then
  350. inserttypeconv(left,defcoll.paratype);
  351. { set some settings needed for arrayconstructor }
  352. if is_array_constructor(left.resulttype.def) then
  353. begin
  354. if is_array_of_const(defcoll.paratype.def) then
  355. begin
  356. if assigned(aktcallprocdef) and
  357. (aktcallprocdef.proccalloption in [pocall_cppdecl,pocall_cdecl]) and
  358. (po_external in aktcallprocdef.procoptions) then
  359. include(left.flags,nf_cargs);
  360. { force variant array }
  361. include(left.flags,nf_forcevaria);
  362. end
  363. else
  364. begin
  365. include(left.flags,nf_novariaallowed);
  366. { now that the resultting type is know we can insert the required
  367. typeconvs for the array constructor }
  368. tarrayconstructornode(left).force_type(tarraydef(defcoll.paratype.def).elementtype);
  369. end;
  370. end;
  371. { check if local proc/func is assigned to procvar }
  372. if left.resulttype.def.deftype=procvardef then
  373. test_local_to_procvar(tprocvardef(left.resulttype.def),defcoll.paratype.def);
  374. { generate the high() value tree }
  375. if not(assigned(aktcallprocdef) and
  376. (aktcallprocdef.proccalloption in [pocall_cppdecl,pocall_cdecl]) and
  377. (po_external in aktcallprocdef.procoptions)) and
  378. paramanager.push_high_param(defcoll.paratype.def) then
  379. gen_high_tree(is_open_string(defcoll.paratype.def));
  380. { test conversions }
  381. if not(is_shortstring(left.resulttype.def) and
  382. is_shortstring(defcoll.paratype.def)) and
  383. (defcoll.paratype.def.deftype<>formaldef) then
  384. begin
  385. if (defcoll.paratyp in [vs_var,vs_out]) and
  386. is_var_para_incompatible(left.resulttype.def,defcoll.paratype.def) then
  387. begin
  388. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  389. left.resulttype.def.typename,defcoll.paratype.def.typename);
  390. end;
  391. { Process open parameters }
  392. if paramanager.push_high_param(defcoll.paratype.def) then
  393. begin
  394. { insert type conv but hold the ranges of the array }
  395. oldtype:=left.resulttype;
  396. inserttypeconv(left,defcoll.paratype);
  397. left.resulttype:=oldtype;
  398. end
  399. else
  400. begin
  401. inserttypeconv(left,defcoll.paratype);
  402. end;
  403. if codegenerror then
  404. begin
  405. dec(parsing_para_level);
  406. exit;
  407. end;
  408. end;
  409. { check var strings }
  410. if (cs_strict_var_strings in aktlocalswitches) and
  411. is_shortstring(left.resulttype.def) and
  412. is_shortstring(defcoll.paratype.def) and
  413. (defcoll.paratyp in [vs_out,vs_var]) and
  414. not(is_open_string(defcoll.paratype.def)) and
  415. not(is_equal(left.resulttype.def,defcoll.paratype.def)) then
  416. begin
  417. aktfilepos:=left.fileinfo;
  418. CGMessage(type_e_strict_var_string_violation);
  419. end;
  420. { Handle formal parameters separate }
  421. if (defcoll.paratype.def.deftype=formaldef) then
  422. begin
  423. { load procvar if a procedure is passed }
  424. if (m_tp_procvar in aktmodeswitches) and
  425. (left.nodetype=calln) and
  426. (is_void(left.resulttype.def)) then
  427. begin
  428. p1:=cloadnode.create_procvar(tcallnode(left).symtableprocentry,
  429. tprocdef(tcallnode(left).procdefinition),tcallnode(left).symtableproc);
  430. if assigned(tcallnode(left).right) then
  431. tloadnode(p1).set_mp(tcallnode(left).right);
  432. left.free;
  433. left:=p1;
  434. resulttypepass(left);
  435. end;
  436. case defcoll.paratyp of
  437. vs_var,
  438. vs_out :
  439. begin
  440. if not valid_for_formal_var(left) then
  441. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  442. end;
  443. vs_const :
  444. begin
  445. if not valid_for_formal_const(left) then
  446. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  447. end;
  448. end;
  449. end
  450. else
  451. begin
  452. { check if the argument is allowed }
  453. if (defcoll.paratyp in [vs_out,vs_var]) then
  454. valid_for_var(left);
  455. end;
  456. if defcoll.paratyp in [vs_var,vs_const] then
  457. begin
  458. { Causes problems with const ansistrings if also }
  459. { done for vs_const (JM) }
  460. if defcoll.paratyp = vs_var then
  461. set_unique(left);
  462. make_not_regable(left);
  463. end;
  464. { ansistrings out paramaters doesn't need to be }
  465. { unique, they are finalized }
  466. if defcoll.paratyp=vs_out then
  467. make_not_regable(left);
  468. if do_count then
  469. begin
  470. { not completly proper, but avoids some warnings }
  471. if (defcoll.paratyp in [vs_var,vs_out]) then
  472. set_funcret_is_valid(left);
  473. set_varstate(left,not(defcoll.paratyp in [vs_var,vs_out]));
  474. end;
  475. { must only be done after typeconv PM }
  476. resulttype:=defcoll.paratype;
  477. dec(parsing_para_level);
  478. {$ifdef extdebug}
  479. if do_count then
  480. count_ref:=store_count_ref;
  481. {$endif def extdebug}
  482. end;
  483. procedure tcallparanode.det_registers;
  484. var
  485. old_get_para_resulttype : boolean;
  486. old_array_constructor : boolean;
  487. begin
  488. if assigned(right) then
  489. begin
  490. tcallparanode(right).det_registers;
  491. registers32:=right.registers32;
  492. registersfpu:=right.registersfpu;
  493. {$ifdef SUPPORT_MMX}
  494. registersmmx:=right.registersmmx;
  495. {$endif}
  496. end;
  497. old_array_constructor:=allow_array_constructor;
  498. old_get_para_resulttype:=get_para_resulttype;
  499. get_para_resulttype:=true;
  500. allow_array_constructor:=true;
  501. firstpass(left);
  502. get_para_resulttype:=old_get_para_resulttype;
  503. allow_array_constructor:=old_array_constructor;
  504. if left.registers32>registers32 then
  505. registers32:=left.registers32;
  506. if left.registersfpu>registersfpu then
  507. registersfpu:=left.registersfpu;
  508. {$ifdef SUPPORT_MMX}
  509. if left.registersmmx>registersmmx then
  510. registersmmx:=left.registersmmx;
  511. {$endif SUPPORT_MMX}
  512. end;
  513. procedure tcallparanode.firstcallparan(defcoll : tparaitem;do_count : boolean);
  514. begin
  515. if not assigned(left.resulttype.def) then
  516. begin
  517. get_paratype;
  518. if assigned(defcoll) then
  519. insert_typeconv(defcoll,do_count);
  520. end;
  521. det_registers;
  522. end;
  523. procedure tcallparanode.gen_high_tree(openstring:boolean);
  524. var
  525. temp: tnode;
  526. len : integer;
  527. loadconst : boolean;
  528. begin
  529. if assigned(hightree) then
  530. exit;
  531. len:=-1;
  532. loadconst:=true;
  533. case left.resulttype.def.deftype of
  534. arraydef :
  535. begin
  536. { handle via a normal inline in_high_x node }
  537. loadconst := false;
  538. hightree := geninlinenode(in_high_x,false,left.getcopy);
  539. { only substract low(array) if it's <> 0 }
  540. temp := geninlinenode(in_low_x,false,left.getcopy);
  541. firstpass(temp);
  542. if (temp.nodetype <> ordconstn) or
  543. (tordconstnode(temp).value <> 0) then
  544. hightree := caddnode.create(subn,hightree,temp)
  545. else
  546. temp.free;
  547. end;
  548. stringdef :
  549. begin
  550. if openstring then
  551. begin
  552. { handle via a normal inline in_high_x node }
  553. loadconst := false;
  554. hightree := geninlinenode(in_high_x,false,left.getcopy);
  555. end
  556. else
  557. { passing a string to an array of char }
  558. begin
  559. if (left.nodetype=stringconstn) then
  560. begin
  561. len:=str_length(left);
  562. if len>0 then
  563. dec(len);
  564. end
  565. else
  566. begin
  567. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,left.getcopy),
  568. cordconstnode.create(1,s32bittype));
  569. loadconst:=false;
  570. end;
  571. end;
  572. end;
  573. else
  574. len:=0;
  575. end;
  576. if loadconst then
  577. hightree:=cordconstnode.create(len,s32bittype)
  578. else
  579. hightree:=ctypeconvnode.create(hightree,s32bittype);
  580. firstpass(hightree);
  581. end;
  582. function tcallparanode.docompare(p: tnode): boolean;
  583. begin
  584. docompare :=
  585. inherited docompare(p) and
  586. (callparaflags = tcallparanode(p).callparaflags) and
  587. hightree.isequal(tcallparanode(p).hightree);
  588. end;
  589. {****************************************************************************
  590. TCALLNODE
  591. ****************************************************************************}
  592. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp : tnode);
  593. begin
  594. inherited create(calln,l,nil);
  595. symtableprocentry:=v;
  596. symtableproc:=st;
  597. include(flags,nf_return_value_used);
  598. methodpointer:=mp;
  599. procdefinition:=nil;
  600. restypeset := false;
  601. funcretrefnode:=nil;
  602. end;
  603. constructor tcallnode.createintern(const name: string; params: tnode);
  604. var
  605. srsym: tsym;
  606. symowner: tsymtable;
  607. begin
  608. if not (cs_compilesystem in aktmoduleswitches) then
  609. begin
  610. srsym := searchsymonlyin(systemunit,name);
  611. symowner := systemunit;
  612. end
  613. else
  614. begin
  615. searchsym(name,srsym,symowner);
  616. if not assigned(srsym) then
  617. searchsym(upper(name),srsym,symowner);
  618. end;
  619. if not assigned(srsym) or
  620. (srsym.typ <> procsym) then
  621. begin
  622. writeln('unknown compilerproc ',name);
  623. internalerror(200107271);
  624. end;
  625. self.create(params,tprocsym(srsym),symowner,nil);
  626. end;
  627. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  628. begin
  629. self.createintern(name,params);
  630. restype := res;
  631. restypeset := true;
  632. { both the normal and specified resulttype either have to be returned via a }
  633. { parameter or not, but no mixing (JM) }
  634. if paramanager.ret_in_param(restype.def) xor paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def) then
  635. internalerror(200108291);
  636. end;
  637. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  638. begin
  639. self.createintern(name,params);
  640. funcretrefnode:=returnnode;
  641. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def) then
  642. internalerror(200204247);
  643. end;
  644. destructor tcallnode.destroy;
  645. begin
  646. methodpointer.free;
  647. funcretrefnode.free;
  648. inherited destroy;
  649. end;
  650. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  651. begin
  652. inherited ppuload(t,ppufile);
  653. symtableprocentry:=tprocsym(ppufile.getderef);
  654. {$warning FIXME: No withsymtable support}
  655. symtableproc:=nil;
  656. procdefinition:=tprocdef(ppufile.getderef);
  657. restypeset:=boolean(ppufile.getbyte);
  658. methodpointer:=ppuloadnode(ppufile);
  659. funcretrefnode:=ppuloadnode(ppufile);
  660. end;
  661. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  662. begin
  663. inherited ppuwrite(ppufile);
  664. ppufile.putderef(symtableprocentry);
  665. ppufile.putderef(procdefinition);
  666. ppufile.putbyte(byte(restypeset));
  667. ppuwritenode(ppufile,methodpointer);
  668. ppuwritenode(ppufile,funcretrefnode);
  669. end;
  670. procedure tcallnode.derefimpl;
  671. begin
  672. inherited derefimpl;
  673. resolvesym(pointer(symtableprocentry));
  674. symtableproc:=symtableprocentry.owner;
  675. resolvedef(pointer(procdefinition));
  676. if assigned(methodpointer) then
  677. methodpointer.derefimpl;
  678. if assigned(funcretrefnode) then
  679. funcretrefnode.derefimpl;
  680. end;
  681. procedure tcallnode.set_procvar(procvar:tnode);
  682. begin
  683. right:=procvar;
  684. end;
  685. function tcallnode.getcopy : tnode;
  686. var
  687. n : tcallnode;
  688. begin
  689. n:=tcallnode(inherited getcopy);
  690. n.symtableprocentry:=symtableprocentry;
  691. n.symtableproc:=symtableproc;
  692. n.procdefinition:=procdefinition;
  693. n.restype := restype;
  694. n.restypeset := restypeset;
  695. if assigned(methodpointer) then
  696. n.methodpointer:=methodpointer.getcopy
  697. else
  698. n.methodpointer:=nil;
  699. if assigned(funcretrefnode) then
  700. n.funcretrefnode:=funcretrefnode.getcopy
  701. else
  702. n.funcretrefnode:=nil;
  703. result:=n;
  704. end;
  705. procedure tcallnode.insertintolist(l : tnodelist);
  706. begin
  707. end;
  708. {$ifdef nice_ncal}
  709. function Tcallnode.choose_definition_to_call(paralength:byte;var errorexit:boolean):Tnode;
  710. { check if the resulttype.def from tree p is equal with def, needed
  711. for stringconstn and formaldef }
  712. function is_equal(p:tcallparanode;def:tdef) : boolean;
  713. begin
  714. { safety check }
  715. if not (assigned(def) or assigned(p.resulttype.def)) then
  716. begin
  717. is_equal:=false;
  718. exit;
  719. end;
  720. { all types can be passed to a formaldef }
  721. is_equal:=(def.deftype=formaldef) or
  722. (defbase.is_equal(p.resulttype.def,def))
  723. { integer constants are compatible with all integer parameters if
  724. the specified value matches the range }
  725. or
  726. (
  727. (tbinarynode(p).left.nodetype=ordconstn) and
  728. is_integer(p.resulttype.def) and
  729. is_integer(def) and
  730. (tordconstnode(p.left).value>=torddef(def).low) and
  731. (tordconstnode(p.left).value<=torddef(def).high)
  732. )
  733. { to support ansi/long/wide strings in a proper way }
  734. { string and string[10] are assumed as equal }
  735. { when searching the correct overloaded procedure }
  736. or
  737. (
  738. (def.deftype=stringdef) and (p.resulttype.def.deftype=stringdef) and
  739. (tstringdef(def).string_typ=tstringdef(p.resulttype.def).string_typ)
  740. )
  741. or
  742. (
  743. (p.left.nodetype=stringconstn) and
  744. (is_ansistring(p.resulttype.def) and is_pchar(def))
  745. )
  746. or
  747. (
  748. (p.left.nodetype=ordconstn) and
  749. (is_char(p.resulttype.def) and (is_shortstring(def) or is_ansistring(def)))
  750. )
  751. { set can also be a not yet converted array constructor }
  752. or
  753. (
  754. (def.deftype=setdef) and (p.resulttype.def.deftype=arraydef) and
  755. (tarraydef(p.resulttype.def).IsConstructor) and not(tarraydef(p.resulttype.def).IsVariant)
  756. )
  757. { in tp7 mode proc -> procvar is allowed }
  758. or
  759. (
  760. (m_tp_procvar in aktmodeswitches) and
  761. (def.deftype=procvardef) and (p.left.nodetype=calln) and
  762. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def),false))
  763. )
  764. ;
  765. end;
  766. procedure get_candidate_information(var cl2_count,cl1_count,equal_count,exact_count:byte;
  767. var ordspace:double;
  768. treeparas:Tcallparanode;candparas:Tparaitem);
  769. {Gets information how the parameters would be converted to the candidate.}
  770. var hcvt:Tconverttype;
  771. from_def,to_def:Tdef;
  772. begin
  773. cl2_count:=0;
  774. cl1_count:=0;
  775. equal_count:=0;
  776. exact_count:=0;
  777. ordspace:=0;
  778. while candparas<>nil do
  779. begin
  780. from_def:=treeparas.resulttype.def;
  781. to_def:=candparas.paratype.def;
  782. if to_def=from_def then
  783. inc(exact_count)
  784. { if a type is totally included in the other }
  785. { we don't fear an overflow , }
  786. { so we can do as if it is an equal match }
  787. else if (treeparas.left.nodetype=ordconstn) and is_integer(to_def) then
  788. begin
  789. inc(equal_count);
  790. {To do: What to do with overflow??}
  791. ordspace:=ordspace+(double(Torddef(from_def).low)-Torddef(to_def).low)+
  792. (double(Torddef(to_def).high)-Torddef(from_def).high);
  793. end
  794. else if ((from_def.deftype=orddef) and (to_def.deftype=orddef)) and
  795. (is_in_limit(from_def,to_def) or
  796. ((candparas.paratyp in [vs_var,vs_out]) and (from_def.size=to_def.size))
  797. ) then
  798. begin
  799. ordspace:=ordspace+Torddef(to_def).high;
  800. ordspace:=ordspace-Torddef(to_def).low;
  801. inc(equal_count);
  802. end
  803. else if is_equal(treeparas,to_def) then
  804. inc(equal_count)
  805. else
  806. case isconvertable(from_def,to_def,
  807. hcvt,treeparas.left.nodetype,false) of
  808. 0:
  809. internalerror(200208021);
  810. 1:
  811. inc(cl1_count);
  812. 2:
  813. inc(cl2_count);
  814. end;
  815. treeparas:=Tcallparanode(treeparas.right);
  816. candparas:=Tparaitem(candparas.next);
  817. end;
  818. end;
  819. var candidates_left,candidate_count,c1,c2:byte;
  820. cl2_count1,cl1_count1,equal_count1,exact_count1:byte;
  821. ordspace1:double;
  822. cl2_count2,cl1_count2,equal_count2,exact_count2:byte;
  823. ordspace2:double;
  824. i,n:byte;
  825. cont:boolean;
  826. pt:Tcallparanode;
  827. def:Tprocdef;
  828. hcvt:Tconverttype;
  829. pdc:Tparaitem;
  830. hpt:Tnode;
  831. srprocsym:Tprocsym;
  832. srsymtable:Tsymtable;
  833. candidates:set of 0..255;
  834. candidates_exactmatch:set of 0..255;
  835. delete_mask:set of 0..255;
  836. candidate_defs:array[0..255] of Tprocdef;
  837. begin
  838. choose_definition_to_call:=nil;
  839. errorexit:=true;
  840. { when the definition has overload directive set, we search for
  841. overloaded definitions in the class, this only needs to be done once
  842. for class entries as the tree keeps always the same }
  843. if (not symtableprocentry.overloadchecked) and
  844. (po_overload in symtableprocentry.first_procdef.procoptions) and
  845. (symtableprocentry.owner.symtabletype=objectsymtable) then
  846. search_class_overloads(symtableprocentry);
  847. candidates:=[];
  848. candidates_exactmatch:=[];
  849. {Collect all procedures which have the same # of parameters }
  850. candidate_count:=0;
  851. srprocsym:=symtableprocentry;
  852. srsymtable:=symtableprocentry.owner;
  853. repeat
  854. for i:=1 to srprocsym.procdef_count do
  855. begin
  856. def:=srprocsym.procdef(i);
  857. candidate_defs[i-1]:=def;
  858. { only when the # of parameter are supported by the
  859. procedure }
  860. if (paralength>=def.minparacount) and
  861. ((po_varargs in def.procoptions) or { varargs }
  862. (paralength<=def.maxparacount)) then
  863. include(candidates,i-1);
  864. inc(candidate_count);
  865. end;
  866. if po_overload in srprocsym.first_procdef.procoptions then
  867. begin
  868. repeat
  869. repeat
  870. srsymtable:=srsymtable.next;
  871. until (srsymtable=nil) or (srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable]);
  872. if assigned(srsymtable) then
  873. srprocsym:=Tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  874. until (srsymtable=nil) or (srprocsym<>nil);
  875. cont:=assigned(srprocsym);
  876. end
  877. else
  878. cont:=false;
  879. until not cont;
  880. { no procedures found? then there is something wrong
  881. with the parameter size }
  882. if candidates=[] then
  883. begin
  884. { in tp mode we can try to convert to procvar if
  885. there are no parameters specified }
  886. if not(assigned(left)) and
  887. (m_tp_procvar in aktmodeswitches) then
  888. begin
  889. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  890. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  891. assigned(methodpointer) then
  892. tloadnode(hpt).set_mp(methodpointer.getcopy);
  893. resulttypepass(hpt);
  894. choose_definition_to_call:=hpt;
  895. end
  896. else
  897. begin
  898. if assigned(left) then
  899. aktfilepos:=left.fileinfo;
  900. CGMessage(parser_e_wrong_parameter_size);
  901. symtableprocentry.write_parameter_lists(nil);
  902. end;
  903. exit;
  904. end;
  905. {Walk through all candidates and remove the ones
  906. that have incompatible parameters.}
  907. for i:=1 to candidate_count do
  908. if (i-1) in candidates then
  909. begin
  910. def:=candidate_defs[i-1];
  911. {Walk through all parameters.}
  912. pdc:=Tparaitem(def.para.first);
  913. pt:=Tcallparanode(left);
  914. while assigned(pdc) do
  915. begin
  916. if pdc.paratyp in [vs_var,vs_out] then
  917. if is_var_para_incompatible(pt.resulttype.def,pdc.paratype.def) and
  918. not(is_shortstring(pt.resulttype.def) and is_shortstring(pdc.paratype.def)) and
  919. (pdc.paratype.def.deftype<>formaldef) then
  920. {Not convertable, def is no longer a candidate.}
  921. exclude(candidates,i-1)
  922. else
  923. exclude(pt.callparaflags,cpf_nomatchfound)
  924. else
  925. if (pt.resulttype.def<>pdc.paratype.def) and
  926. ((isconvertable(pt.resulttype.def,pdc.paratype.def,
  927. hcvt,pt.left.nodetype,false)=0) and
  928. not is_equal(pt,pdc.paratype.def)) then
  929. {Not convertable, def is no longer a candidate.}
  930. exclude(candidates,i-1)
  931. else
  932. exclude(pt.callparaflags,cpf_nomatchfound);
  933. pdc:=Tparaitem(pdc.next);
  934. pt:=Tcallparanode(pt.right);
  935. end;
  936. end;
  937. {Count the candidates that are left.}
  938. candidates_left:=0;
  939. for i:=1 to candidate_count do
  940. if (i-1) in candidates then
  941. inc(candidates_left);
  942. {Are there any candidates left?}
  943. if candidates_left=0 then
  944. begin
  945. {There is an error, must be wrong type, because
  946. wrong size is already checked (PFV) }
  947. pt:=Tcallparanode(left);
  948. n:=0;
  949. while assigned(pt) do
  950. if cpf_nomatchfound in pt.callparaflags then
  951. break
  952. else
  953. begin
  954. pt:=tcallparanode(pt.right);
  955. inc(n);
  956. end;
  957. if not(assigned(pt) and assigned(pt.resulttype.def)) then
  958. internalerror(39393);
  959. {Def contains the last candidate tested.}
  960. pdc:=Tparaitem(def.para.first);
  961. for i:=1 to n do
  962. pdc:=Tparaitem(pdc.next);
  963. aktfilepos:=pt.fileinfo;
  964. cgmessage3(type_e_wrong_parameter_type,tostr(n+1),
  965. pt.resulttype.def.typename,pdc.paratype.def.typename);
  966. symtableprocentry.write_parameter_lists(nil);
  967. exit;
  968. end;
  969. {If there is more candidate that can be called, we have to
  970. find the most suitable one. We collect the following
  971. information:
  972. - Amount of convertlevel 2 parameters.
  973. - Amount of convertlevel 1 parameters.
  974. - Amount of equal parameters.
  975. - Amount of exact parameters.
  976. - Amount of ordinal space the destination parameters
  977. provide. For exampe, a word provides 65535-255=65280
  978. of ordinal space above a byte.
  979. The first criterium is the candidate that has the least
  980. convertlevel 2 parameters. The next criterium is
  981. the candidate that has the most exact parameters, next
  982. criterium is the least ordinal space and
  983. the last criterium is the most equal parameters. (DM)}
  984. if candidates_left>1 then
  985. begin
  986. {Find the first candidate.}
  987. c1:=1;
  988. while c1<=candidate_count do
  989. if (c1-1) in candidates then
  990. break
  991. else
  992. inc(c1);
  993. delete_mask:=[c1-1];
  994. {Get information about candidate c1.}
  995. get_candidate_information(cl2_count1,cl1_count1,equal_count1,
  996. exact_count1,ordspace1,Tcallparanode(left),
  997. Tparaitem(candidate_defs[c1-1].para.first));
  998. {Find the other candidates and eliminate the lesser ones.}
  999. c2:=c1+1;
  1000. while c2<=candidate_count do
  1001. if (c2-1) in candidates then
  1002. begin
  1003. {Candidate found, get information on it.}
  1004. get_candidate_information(cl2_count2,cl1_count2,equal_count2,
  1005. exact_count2,ordspace2,Tcallparanode(left),
  1006. Tparaitem(candidate_defs[c2-1].para.first));
  1007. {Is c1 the better candidate?}
  1008. if (cl2_count1<cl2_count2) or
  1009. ((cl2_count1=cl2_count2) and (exact_count1>exact_count2)) or
  1010. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1>equal_count2)) or
  1011. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1=equal_count2) and (ordspace1<ordspace2)) then
  1012. begin
  1013. {C1 is better, drop c2.}
  1014. exclude(candidates,c2-1);
  1015. end
  1016. {Is c2 the better candidate?}
  1017. else if (cl2_count2<cl2_count1) or
  1018. ((cl2_count2=cl2_count1) and (exact_count2>exact_count1)) or
  1019. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2>equal_count1)) or
  1020. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2=equal_count1) and (ordspace2<ordspace1)) then
  1021. begin
  1022. {C2 is better, drop all previous
  1023. candidates.}
  1024. include(delete_mask,c1-1);
  1025. candidates:=candidates-delete_mask;
  1026. c1:=c2;
  1027. cl2_count1:=cl2_count2;
  1028. cl1_count1:=cl1_count2;
  1029. equal_count1:=equal_count2;
  1030. exact_count1:=exact_count2;
  1031. ordspace1:=ordspace2;
  1032. end
  1033. else
  1034. include(delete_mask,c2-1);
  1035. {else the candidates have no advantage over each other,
  1036. do nothing}
  1037. inc(c2);
  1038. end
  1039. else
  1040. inc(c2);
  1041. end;
  1042. {Count the candidates that are left.}
  1043. candidates_left:=0;
  1044. for i:=1 to candidate_count do
  1045. if (i-1) in candidates then
  1046. inc(candidates_left);
  1047. if candidates_left>1 then
  1048. begin
  1049. cgmessage(cg_e_cant_choose_overload_function);
  1050. symtableprocentry.write_parameter_lists(nil);
  1051. exit;
  1052. end;
  1053. for i:=1 to candidate_count do
  1054. if (i-1) in candidates then
  1055. begin
  1056. procdefinition:=candidate_defs[i-1];
  1057. break;
  1058. end;
  1059. if make_ref then
  1060. begin
  1061. Tprocdef(procdefinition).lastref:=Tref.create(Tprocdef(procdefinition).lastref,@fileinfo);
  1062. inc(Tprocdef(procdefinition).refcount);
  1063. if Tprocdef(procdefinition).defref=nil then
  1064. Tprocdef(procdefinition).defref:=Tprocdef(procdefinition).lastref;
  1065. end;
  1066. { big error for with statements
  1067. symtableproc:=procdefinition.owner;
  1068. but neede for overloaded operators !! }
  1069. if symtableproc=nil then
  1070. symtableproc:=procdefinition.owner;
  1071. errorexit:=false;
  1072. end;
  1073. function tcallnode.det_resulttype:tnode;
  1074. var lastpara,paralength:byte;
  1075. oldcallprocdef:Tabstractprocdef;
  1076. pt:Tcallparanode;
  1077. i,n:byte;
  1078. e,is_const:boolean;
  1079. pdc:Tparaitem;
  1080. hpt:Tnode;
  1081. label errorexit;
  1082. begin
  1083. result:=nil;
  1084. oldcallprocdef:=aktcallprocdef;
  1085. aktcallprocdef:=nil;
  1086. { determine length of parameter list }
  1087. pt:=tcallparanode(left);
  1088. paralength:=0;
  1089. while assigned(pt) do
  1090. begin
  1091. include(pt.callparaflags,cpf_nomatchfound);
  1092. inc(paralength);
  1093. pt:=tcallparanode(pt.right);
  1094. end;
  1095. { determine the type of the parameters }
  1096. if assigned(left) then
  1097. begin
  1098. tcallparanode(left).get_paratype;
  1099. if codegenerror then
  1100. goto errorexit;
  1101. end;
  1102. { procedure variable ? }
  1103. if assigned(right) then
  1104. begin
  1105. set_varstate(right,true);
  1106. resulttypepass(right);
  1107. if codegenerror then
  1108. exit;
  1109. procdefinition:=tabstractprocdef(right.resulttype.def);
  1110. { check the amount of parameters }
  1111. pdc:=tparaitem(procdefinition.Para.first);
  1112. pt:=tcallparanode(left);
  1113. lastpara:=paralength;
  1114. while assigned(pdc) and assigned(pt) do
  1115. begin
  1116. { only goto next para if we're out of the varargs }
  1117. if not(po_varargs in procdefinition.procoptions) or
  1118. (lastpara<=procdefinition.maxparacount) then
  1119. pdc:=tparaitem(pdc.next);
  1120. pt:=tcallparanode(pt.right);
  1121. dec(lastpara);
  1122. end;
  1123. if assigned(pt) or assigned(pdc) then
  1124. begin
  1125. if assigned(pt) then
  1126. aktfilepos:=pt.fileinfo;
  1127. CGMessage(parser_e_wrong_parameter_size);
  1128. end;
  1129. end
  1130. else
  1131. { not a procedure variable }
  1132. begin
  1133. { do we know the procedure to call ? }
  1134. if not(assigned(procdefinition)) then
  1135. begin
  1136. result:=choose_definition_to_call(paralength,e);
  1137. if e then
  1138. goto errorexit;
  1139. end;
  1140. (* To do!!!
  1141. { add needed default parameters }
  1142. if assigned(procdefinition) and
  1143. (paralength<procdefinition.maxparacount) then
  1144. begin
  1145. { add default parameters, just read back the skipped
  1146. paras starting from firstPara.previous, when not available
  1147. (all parameters are default) then start with the last
  1148. parameter and read backward (PFV) }
  1149. if not assigned(procs^.firstpara) then
  1150. pdc:=tparaitem(procs^.data.Para.last)
  1151. else
  1152. pdc:=tparaitem(procs^.firstPara.previous);
  1153. while assigned(pdc) do
  1154. begin
  1155. if not assigned(pdc.defaultvalue) then
  1156. internalerror(751349858);
  1157. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1158. pdc:=tparaitem(pdc.previous);
  1159. end;
  1160. end;
  1161. *)
  1162. end;
  1163. { handle predefined procedures }
  1164. is_const:=(po_internconst in procdefinition.procoptions) and
  1165. ((block_type in [bt_const,bt_type]) or
  1166. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1167. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1168. begin
  1169. if assigned(left) then
  1170. begin
  1171. { ptr and settextbuf needs two args }
  1172. if assigned(tcallparanode(left).right) then
  1173. begin
  1174. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,left);
  1175. left:=nil;
  1176. end
  1177. else
  1178. begin
  1179. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,Tcallparanode(left).left);
  1180. Tcallparanode(left).left:=nil;
  1181. end;
  1182. end
  1183. else
  1184. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,nil);
  1185. result:=hpt;
  1186. goto errorexit;
  1187. end;
  1188. { Calling a message method directly ? }
  1189. if assigned(procdefinition) and
  1190. (po_containsself in procdefinition.procoptions) then
  1191. message(cg_e_cannot_call_message_direct);
  1192. { ensure that the result type is set }
  1193. if not restypeset then
  1194. resulttype:=procdefinition.rettype
  1195. else
  1196. resulttype:=restype;
  1197. { modify the exit code, in case of special cases }
  1198. if (not is_void(resulttype.def)) then
  1199. begin
  1200. if paramanager.ret_in_acc(resulttype.def) then
  1201. begin
  1202. { wide- and ansistrings are returned in EAX }
  1203. { but they are imm. moved to a memory location }
  1204. if is_widestring(resulttype.def) or
  1205. is_ansistring(resulttype.def) then
  1206. begin
  1207. { we use ansistrings so no fast exit here }
  1208. if assigned(procinfo) then
  1209. procinfo.no_fast_exit:=true;
  1210. end;
  1211. end;
  1212. end;
  1213. { constructors return their current class type, not the type where the
  1214. constructor is declared, this can be different because of inheritance }
  1215. if (procdefinition.proctypeoption=potype_constructor) then
  1216. begin
  1217. if assigned(methodpointer) and
  1218. assigned(methodpointer.resulttype.def) and
  1219. (methodpointer.resulttype.def.deftype=classrefdef) then
  1220. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  1221. end;
  1222. { flag all callparanodes that belong to the varargs }
  1223. if (po_varargs in procdefinition.procoptions) then
  1224. begin
  1225. pt:=tcallparanode(left);
  1226. i:=paralength;
  1227. while (i>procdefinition.maxparacount) do
  1228. begin
  1229. include(tcallparanode(pt).flags,nf_varargs_para);
  1230. pt:=tcallparanode(pt.right);
  1231. dec(i);
  1232. end;
  1233. end;
  1234. { insert type conversions }
  1235. if assigned(left) then
  1236. begin
  1237. aktcallprocdef:=procdefinition;
  1238. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  1239. end;
  1240. errorexit:
  1241. { Reset some settings back }
  1242. aktcallprocdef:=oldcallprocdef;
  1243. end;
  1244. {$else}
  1245. function tcallnode.det_resulttype:tnode;
  1246. type
  1247. pprocdefcoll = ^tprocdefcoll;
  1248. tprocdefcoll = record
  1249. data : tprocdef;
  1250. nextpara : tparaitem;
  1251. firstpara : tparaitem;
  1252. next : pprocdefcoll;
  1253. end;
  1254. var
  1255. hp,procs,hp2 : pprocdefcoll;
  1256. pd : pprocdeflist;
  1257. oldcallprocdef : tabstractprocdef;
  1258. def_from,def_to,conv_to : tdef;
  1259. hpt : tnode;
  1260. pt : tcallparanode;
  1261. exactmatch : boolean;
  1262. paralength,lastpara : longint;
  1263. lastparatype : tdef;
  1264. pdc : tparaitem;
  1265. { only Dummy }
  1266. hcvt : tconverttype;
  1267. label
  1268. errorexit;
  1269. { check if the resulttype.def from tree p is equal with def, needed
  1270. for stringconstn and formaldef }
  1271. function is_equal(p:tcallparanode;def:tdef) : boolean;
  1272. begin
  1273. { safety check }
  1274. if not (assigned(def) or assigned(p.resulttype.def)) then
  1275. begin
  1276. is_equal:=false;
  1277. exit;
  1278. end;
  1279. { all types can be passed to a formaldef }
  1280. is_equal:=(def.deftype=formaldef) or
  1281. (defbase.is_equal(p.resulttype.def,def))
  1282. { integer constants are compatible with all integer parameters if
  1283. the specified value matches the range }
  1284. or
  1285. (
  1286. (tbinarynode(p).left.nodetype=ordconstn) and
  1287. is_integer(p.resulttype.def) and
  1288. is_integer(def) and
  1289. (tordconstnode(p.left).value>=torddef(def).low) and
  1290. (tordconstnode(p.left).value<=torddef(def).high)
  1291. )
  1292. { to support ansi/long/wide strings in a proper way }
  1293. { string and string[10] are assumed as equal }
  1294. { when searching the correct overloaded procedure }
  1295. or
  1296. (
  1297. (def.deftype=stringdef) and (p.resulttype.def.deftype=stringdef) and
  1298. (tstringdef(def).string_typ=tstringdef(p.resulttype.def).string_typ)
  1299. )
  1300. or
  1301. (
  1302. (p.left.nodetype=stringconstn) and
  1303. (is_ansistring(p.resulttype.def) and is_pchar(def))
  1304. )
  1305. or
  1306. (
  1307. (p.left.nodetype=ordconstn) and
  1308. (is_char(p.resulttype.def) and (is_shortstring(def) or is_ansistring(def)))
  1309. )
  1310. { set can also be a not yet converted array constructor }
  1311. or
  1312. (
  1313. (def.deftype=setdef) and (p.resulttype.def.deftype=arraydef) and
  1314. (tarraydef(p.resulttype.def).IsConstructor) and not(tarraydef(p.resulttype.def).IsVariant)
  1315. )
  1316. { in tp7 mode proc -> procvar is allowed }
  1317. or
  1318. (
  1319. (m_tp_procvar in aktmodeswitches) and
  1320. (def.deftype=procvardef) and (p.left.nodetype=calln) and
  1321. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def),false))
  1322. )
  1323. ;
  1324. end;
  1325. var
  1326. i : longint;
  1327. found,
  1328. is_const : boolean;
  1329. bestord : torddef;
  1330. srprocsym : tprocsym;
  1331. srsymtable : tsymtable;
  1332. begin
  1333. if fileinfo.line=300 then
  1334. result:=nil;
  1335. result:=nil;
  1336. procs:=nil;
  1337. oldcallprocdef:=aktcallprocdef;
  1338. aktcallprocdef:=nil;
  1339. { determine length of parameter list }
  1340. pt:=tcallparanode(left);
  1341. paralength:=0;
  1342. while assigned(pt) do
  1343. begin
  1344. inc(paralength);
  1345. pt:=tcallparanode(pt.right);
  1346. end;
  1347. { determine the type of the parameters }
  1348. if assigned(left) then
  1349. begin
  1350. tcallparanode(left).get_paratype;
  1351. if codegenerror then
  1352. goto errorexit;
  1353. end;
  1354. { procedure variable ? }
  1355. if assigned(right) then
  1356. begin
  1357. set_varstate(right,true);
  1358. resulttypepass(right);
  1359. if codegenerror then
  1360. exit;
  1361. procdefinition:=tabstractprocdef(right.resulttype.def);
  1362. { check the amount of parameters }
  1363. pdc:=tparaitem(procdefinition.Para.first);
  1364. pt:=tcallparanode(left);
  1365. lastpara:=paralength;
  1366. while assigned(pdc) and assigned(pt) do
  1367. begin
  1368. { only goto next para if we're out of the varargs }
  1369. if not(po_varargs in procdefinition.procoptions) or
  1370. (lastpara<=procdefinition.maxparacount) then
  1371. pdc:=tparaitem(pdc.next);
  1372. pt:=tcallparanode(pt.right);
  1373. dec(lastpara);
  1374. end;
  1375. if assigned(pt) or assigned(pdc) then
  1376. begin
  1377. if assigned(pt) then
  1378. aktfilepos:=pt.fileinfo;
  1379. CGMessage(parser_e_wrong_parameter_size);
  1380. end;
  1381. end
  1382. else
  1383. { not a procedure variable }
  1384. begin
  1385. { do we know the procedure to call ? }
  1386. if not(assigned(procdefinition)) then
  1387. begin
  1388. { when the definition has overload directive set, we search for
  1389. overloaded definitions in the class, this only needs to be done once
  1390. for class entries as the tree keeps always the same }
  1391. if (not symtableprocentry.overloadchecked) and
  1392. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1393. (symtableprocentry.owner.symtabletype=objectsymtable) then
  1394. search_class_overloads(symtableprocentry);
  1395. { link all procedures which have the same # of parameters }
  1396. pd:=symtableprocentry.defs;
  1397. while assigned(pd) do
  1398. begin
  1399. { only when the # of parameter are supported by the
  1400. procedure }
  1401. if (paralength>=pd^.def.minparacount) and
  1402. ((po_varargs in pd^.def.procoptions) or { varargs }
  1403. (paralength<=pd^.def.maxparacount)) then
  1404. begin
  1405. new(hp);
  1406. hp^.data:=pd^.def;
  1407. hp^.next:=procs;
  1408. hp^.firstpara:=tparaitem(pd^.def.Para.first);
  1409. if not(po_varargs in pd^.def.procoptions) then
  1410. begin
  1411. { if not all parameters are given, then skip the
  1412. default parameters }
  1413. for i:=1 to pd^.def.maxparacount-paralength do
  1414. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1415. end;
  1416. hp^.nextpara:=hp^.firstpara;
  1417. procs:=hp;
  1418. end;
  1419. pd:=pd^.next;
  1420. end;
  1421. { when the definition has overload directive set, we search for
  1422. overloaded definitions in the symtablestack. The found
  1423. entries are only added to the procs list and not the procsym, because
  1424. the list can change in every situation }
  1425. if (po_overload in symtableprocentry.first_procdef.procoptions) and
  1426. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1427. begin
  1428. srsymtable:=symtableprocentry.owner.next;
  1429. while assigned(srsymtable) do
  1430. begin
  1431. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1432. begin
  1433. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1434. { process only visible procsyms }
  1435. if assigned(srprocsym) and
  1436. (srprocsym.typ=procsym) and
  1437. srprocsym.is_visible_for_proc(aktprocdef) then
  1438. begin
  1439. { if this procedure doesn't have overload we can stop
  1440. searching }
  1441. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1442. break;
  1443. { process all overloaded definitions }
  1444. pd:=srprocsym.defs;
  1445. while assigned(pd) do
  1446. begin
  1447. { only when the # of parameter are supported by the
  1448. procedure }
  1449. if (paralength>=pd^.def.minparacount) and
  1450. ((po_varargs in pd^.def.procoptions) or { varargs }
  1451. (paralength<=pd^.def.maxparacount)) then
  1452. begin
  1453. found:=false;
  1454. hp:=procs;
  1455. while assigned(hp) do
  1456. begin
  1457. if equal_paras(hp^.data.para,pd^.def.para,cp_value_equal_const) then
  1458. begin
  1459. found:=true;
  1460. break;
  1461. end;
  1462. hp:=hp^.next;
  1463. end;
  1464. if not found then
  1465. begin
  1466. new(hp);
  1467. hp^.data:=pd^.def;
  1468. hp^.next:=procs;
  1469. hp^.firstpara:=tparaitem(pd^.def.Para.first);
  1470. if not(po_varargs in pd^.def.procoptions) then
  1471. begin
  1472. { if not all parameters are given, then skip the
  1473. default parameters }
  1474. for i:=1 to pd^.def.maxparacount-paralength do
  1475. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1476. end;
  1477. hp^.nextpara:=hp^.firstpara;
  1478. procs:=hp;
  1479. end;
  1480. end;
  1481. pd:=pd^.next;
  1482. end;
  1483. end;
  1484. end;
  1485. srsymtable:=srsymtable.next;
  1486. end;
  1487. end;
  1488. { no procedures found? then there is something wrong
  1489. with the parameter size }
  1490. if not assigned(procs) then
  1491. begin
  1492. { in tp mode we can try to convert to procvar if
  1493. there are no parameters specified }
  1494. if not(assigned(left)) and
  1495. (m_tp_procvar in aktmodeswitches) then
  1496. begin
  1497. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1498. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  1499. assigned(methodpointer) then
  1500. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1501. resulttypepass(hpt);
  1502. result:=hpt;
  1503. end
  1504. else
  1505. begin
  1506. if assigned(left) then
  1507. aktfilepos:=left.fileinfo;
  1508. CGMessage(parser_e_wrong_parameter_size);
  1509. symtableprocentry.write_parameter_lists(nil);
  1510. end;
  1511. goto errorexit;
  1512. end;
  1513. { now we can compare parameter after parameter }
  1514. pt:=tcallparanode(left);
  1515. { we start with the last parameter }
  1516. lastpara:=paralength+1;
  1517. lastparatype:=nil;
  1518. while assigned(pt) do
  1519. begin
  1520. dec(lastpara);
  1521. { walk all procedures and determine how this parameter matches and set:
  1522. 1. pt.exact_match_found if one parameter has an exact match
  1523. 2. exactmatch if an equal or exact match is found
  1524. 3. Para.argconvtyp to exact,equal or convertable
  1525. (when convertable then also convertlevel is set)
  1526. 4. pt.convlevel1found if there is a convertlevel=1
  1527. 5. pt.convlevel2found if there is a convertlevel=2
  1528. }
  1529. exactmatch:=false;
  1530. hp:=procs;
  1531. while assigned(hp) do
  1532. begin
  1533. { varargs are always equal, but not exact }
  1534. if (po_varargs in hp^.data.procoptions) and
  1535. (lastpara>hp^.data.minparacount) then
  1536. begin
  1537. hp^.nextPara.argconvtyp:=act_equal;
  1538. exactmatch:=true;
  1539. end
  1540. else
  1541. begin
  1542. if is_equal(pt,hp^.nextPara.paratype.def) then
  1543. begin
  1544. if hp^.nextPara.paratype.def=pt.resulttype.def then
  1545. begin
  1546. include(pt.callparaflags,cpf_exact_match_found);
  1547. hp^.nextPara.argconvtyp:=act_exact;
  1548. end
  1549. else
  1550. hp^.nextPara.argconvtyp:=act_equal;
  1551. exactmatch:=true;
  1552. end
  1553. else
  1554. begin
  1555. hp^.nextPara.argconvtyp:=act_convertable;
  1556. hp^.nextPara.convertlevel:=isconvertable(pt.resulttype.def,hp^.nextPara.paratype.def,
  1557. hcvt,pt.left.nodetype,false);
  1558. case hp^.nextPara.convertlevel of
  1559. 1 : include(pt.callparaflags,cpf_convlevel1found);
  1560. 2 : include(pt.callparaflags,cpf_convlevel2found);
  1561. end;
  1562. end;
  1563. end;
  1564. hp:=hp^.next;
  1565. end;
  1566. { If there was an exactmatch then delete all convertables }
  1567. if exactmatch then
  1568. begin
  1569. hp:=procs;
  1570. procs:=nil;
  1571. while assigned(hp) do
  1572. begin
  1573. hp2:=hp^.next;
  1574. { keep if not convertable }
  1575. if (hp^.nextPara.argconvtyp<>act_convertable) then
  1576. begin
  1577. hp^.next:=procs;
  1578. procs:=hp;
  1579. end
  1580. else
  1581. dispose(hp);
  1582. hp:=hp2;
  1583. end;
  1584. end
  1585. else
  1586. { No exact match was found, remove all procedures that are
  1587. not convertable (convertlevel=0) }
  1588. begin
  1589. hp:=procs;
  1590. procs:=nil;
  1591. while assigned(hp) do
  1592. begin
  1593. hp2:=hp^.next;
  1594. { keep if not convertable }
  1595. if (hp^.nextPara.convertlevel<>0) then
  1596. begin
  1597. hp^.next:=procs;
  1598. procs:=hp;
  1599. end
  1600. else
  1601. begin
  1602. { save the type for nice error message }
  1603. lastparatype:=hp^.nextPara.paratype.def;
  1604. dispose(hp);
  1605. end;
  1606. hp:=hp2;
  1607. end;
  1608. end;
  1609. { update nextpara for all procedures }
  1610. hp:=procs;
  1611. while assigned(hp) do
  1612. begin
  1613. { only goto next para if we're out of the varargs }
  1614. if not(po_varargs in hp^.data.procoptions) or
  1615. (lastpara<=hp^.data.maxparacount) then
  1616. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1617. hp:=hp^.next;
  1618. end;
  1619. { load next parameter or quit loop if no procs left }
  1620. if assigned(procs) then
  1621. pt:=tcallparanode(pt.right)
  1622. else
  1623. break;
  1624. end;
  1625. { All parameters are checked, check if there are any
  1626. procedures left }
  1627. if not assigned(procs) then
  1628. begin
  1629. { there is an error, must be wrong type, because
  1630. wrong size is already checked (PFV) }
  1631. if (not assigned(lastparatype)) or
  1632. (not assigned(pt)) or
  1633. (not assigned(pt.resulttype.def)) then
  1634. internalerror(39393)
  1635. else
  1636. begin
  1637. aktfilepos:=pt.fileinfo;
  1638. CGMessage3(type_e_wrong_parameter_type,tostr(lastpara),
  1639. pt.resulttype.def.typename,lastparatype.typename);
  1640. end;
  1641. symtableprocentry.write_parameter_lists(nil);
  1642. goto errorexit;
  1643. end;
  1644. { if there are several choices left then for orddef }
  1645. { if a type is totally included in the other }
  1646. { we don't fear an overflow , }
  1647. { so we can do as if it is an exact match }
  1648. { this will convert integer to longint }
  1649. { rather than to words }
  1650. { conversion of byte to integer or longint }
  1651. { would still not be solved }
  1652. if assigned(procs) and assigned(procs^.next) then
  1653. begin
  1654. hp:=procs;
  1655. while assigned(hp) do
  1656. begin
  1657. hp^.nextpara:=hp^.firstpara;
  1658. hp:=hp^.next;
  1659. end;
  1660. pt:=tcallparanode(left);
  1661. while assigned(pt) do
  1662. begin
  1663. { matches a parameter of one procedure exact ? }
  1664. exactmatch:=false;
  1665. def_from:=pt.resulttype.def;
  1666. hp:=procs;
  1667. while assigned(hp) do
  1668. begin
  1669. if not is_equal(pt,hp^.nextPara.paratype.def) then
  1670. begin
  1671. def_to:=hp^.nextPara.paratype.def;
  1672. if ((def_from.deftype=orddef) and (def_to.deftype=orddef)) and
  1673. (is_in_limit(def_from,def_to) or
  1674. ((hp^.nextPara.paratyp in [vs_var,vs_out]) and
  1675. (def_from.size=def_to.size))) then
  1676. begin
  1677. exactmatch:=true;
  1678. conv_to:=def_to;
  1679. { there's no use in continuing the search, it will }
  1680. { only result in conv_to being overwritten }
  1681. break;
  1682. end;
  1683. end;
  1684. hp:=hp^.next;
  1685. end;
  1686. { .... if yes, del all the other procedures }
  1687. if exactmatch then
  1688. begin
  1689. { the first .... }
  1690. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextPara.paratype.def)) do
  1691. begin
  1692. hp:=procs^.next;
  1693. dispose(procs);
  1694. procs:=hp;
  1695. end;
  1696. { and the others }
  1697. hp:=procs;
  1698. while (assigned(hp)) and assigned(hp^.next) do
  1699. begin
  1700. def_to:=hp^.next^.nextPara.paratype.def;
  1701. if not(is_in_limit(def_from,def_to)) then
  1702. begin
  1703. hp2:=hp^.next^.next;
  1704. dispose(hp^.next);
  1705. hp^.next:=hp2;
  1706. end
  1707. else
  1708. begin
  1709. { did we possibly find a better match? }
  1710. if (conv_to.size>def_to.size) or
  1711. is_in_limit(def_to,conv_to) then
  1712. begin
  1713. { is it the same as the previous best? }
  1714. if not defbase.is_equal(def_to,conv_to) then
  1715. begin
  1716. { no -> remove all previous best matches }
  1717. hp := hp^.next;
  1718. while procs <> hp do
  1719. begin
  1720. hp2 := procs;
  1721. procs := procs^.next;
  1722. dispose(hp2);
  1723. end;
  1724. { set new match type }
  1725. conv_to:=def_to;
  1726. end
  1727. { the new one matches just as well as the }
  1728. { old one -> keep both }
  1729. else
  1730. hp := hp^.next;
  1731. end
  1732. { not a better match -> remove }
  1733. else
  1734. begin
  1735. hp2 := hp^.next^.next;
  1736. dispose(hp^.next);
  1737. hp^.next:=hp2;
  1738. end;
  1739. end;
  1740. end;
  1741. end;
  1742. { update nextpara for all procedures }
  1743. hp:=procs;
  1744. while assigned(hp) do
  1745. begin
  1746. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1747. hp:=hp^.next;
  1748. end;
  1749. pt:=tcallparanode(pt.right);
  1750. end;
  1751. end;
  1752. { let's try to eliminate equal if there is an exact match
  1753. is there }
  1754. if assigned(procs) and assigned(procs^.next) then
  1755. begin
  1756. { reset nextpara for all procs left }
  1757. hp:=procs;
  1758. while assigned(hp) do
  1759. begin
  1760. hp^.nextpara:=hp^.firstpara;
  1761. hp:=hp^.next;
  1762. end;
  1763. pt:=tcallparanode(left);
  1764. while assigned(pt) do
  1765. begin
  1766. if cpf_exact_match_found in pt.callparaflags then
  1767. begin
  1768. hp:=procs;
  1769. procs:=nil;
  1770. while assigned(hp) do
  1771. begin
  1772. hp2:=hp^.next;
  1773. { keep the exact matches, dispose the others }
  1774. if (hp^.nextPara.argconvtyp=act_exact) then
  1775. begin
  1776. hp^.next:=procs;
  1777. procs:=hp;
  1778. end
  1779. else
  1780. dispose(hp);
  1781. hp:=hp2;
  1782. end;
  1783. end;
  1784. { update nextpara for all procedures }
  1785. hp:=procs;
  1786. while assigned(hp) do
  1787. begin
  1788. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1789. hp:=hp^.next;
  1790. end;
  1791. pt:=tcallparanode(pt.right);
  1792. end;
  1793. end;
  1794. { Check if there are integer constant to integer
  1795. parameters then choose the best matching integer
  1796. parameter and remove the others, this is Delphi
  1797. compatible. 1 = byte, 256 = word, etc. }
  1798. if assigned(procs) and assigned(procs^.next) then
  1799. begin
  1800. { reset nextpara for all procs left }
  1801. hp:=procs;
  1802. while assigned(hp) do
  1803. begin
  1804. hp^.nextpara:=hp^.firstpara;
  1805. hp:=hp^.next;
  1806. end;
  1807. pt:=tcallparanode(left);
  1808. while assigned(pt) do
  1809. begin
  1810. bestord:=nil;
  1811. if (pt.left.nodetype=ordconstn) and
  1812. is_integer(pt.resulttype.def) then
  1813. begin
  1814. hp:=procs;
  1815. while assigned(hp) do
  1816. begin
  1817. def_to:=hp^.nextPara.paratype.def;
  1818. { to be sure, it couldn't be something else,
  1819. also the defs here are all in the range
  1820. so now find the closest range }
  1821. if not is_integer(def_to) then
  1822. internalerror(43297815);
  1823. if (not assigned(bestord)) or
  1824. ((torddef(def_to).low>bestord.low) or
  1825. (torddef(def_to).high<bestord.high)) then
  1826. bestord:=torddef(def_to);
  1827. hp:=hp^.next;
  1828. end;
  1829. end;
  1830. { if a bestmatch is found then remove the other
  1831. procs which don't match the bestord }
  1832. if assigned(bestord) then
  1833. begin
  1834. hp:=procs;
  1835. procs:=nil;
  1836. while assigned(hp) do
  1837. begin
  1838. hp2:=hp^.next;
  1839. { keep matching bestord, dispose the others }
  1840. if (torddef(hp^.nextPara.paratype.def)=bestord) then
  1841. begin
  1842. hp^.next:=procs;
  1843. procs:=hp;
  1844. end
  1845. else
  1846. dispose(hp);
  1847. hp:=hp2;
  1848. end;
  1849. end;
  1850. { update nextpara for all procedures }
  1851. hp:=procs;
  1852. while assigned(hp) do
  1853. begin
  1854. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1855. hp:=hp^.next;
  1856. end;
  1857. pt:=tcallparanode(pt.right);
  1858. end;
  1859. end;
  1860. { Check if there are convertlevel 1 and 2 differences
  1861. left for the parameters, then discard all convertlevel
  1862. 2 procedures. The value of convlevelXfound can still
  1863. be used, because all convertables are still here or
  1864. not }
  1865. if assigned(procs) and assigned(procs^.next) then
  1866. begin
  1867. { reset nextpara for all procs left }
  1868. hp:=procs;
  1869. while assigned(hp) do
  1870. begin
  1871. hp^.nextpara:=hp^.firstpara;
  1872. hp:=hp^.next;
  1873. end;
  1874. pt:=tcallparanode(left);
  1875. while assigned(pt) do
  1876. begin
  1877. if (cpf_convlevel1found in pt.callparaflags) and
  1878. (cpf_convlevel2found in pt.callparaflags) then
  1879. begin
  1880. hp:=procs;
  1881. procs:=nil;
  1882. while assigned(hp) do
  1883. begin
  1884. hp2:=hp^.next;
  1885. { keep all not act_convertable and all convertlevels=1 }
  1886. if (hp^.nextPara.argconvtyp<>act_convertable) or
  1887. (hp^.nextPara.convertlevel=1) then
  1888. begin
  1889. hp^.next:=procs;
  1890. procs:=hp;
  1891. end
  1892. else
  1893. dispose(hp);
  1894. hp:=hp2;
  1895. end;
  1896. end;
  1897. { update nextpara for all procedures }
  1898. hp:=procs;
  1899. while assigned(hp) do
  1900. begin
  1901. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1902. hp:=hp^.next;
  1903. end;
  1904. pt:=tcallparanode(pt.right);
  1905. end;
  1906. end;
  1907. if not(assigned(procs)) or assigned(procs^.next) then
  1908. begin
  1909. CGMessage(cg_e_cant_choose_overload_function);
  1910. symtableprocentry.write_parameter_lists(nil);
  1911. goto errorexit;
  1912. end;
  1913. if make_ref then
  1914. begin
  1915. procs^.data.lastref:=tref.create(procs^.data.lastref,@fileinfo);
  1916. inc(procs^.data.refcount);
  1917. if procs^.data.defref=nil then
  1918. procs^.data.defref:=procs^.data.lastref;
  1919. end;
  1920. procdefinition:=procs^.data;
  1921. { big error for with statements
  1922. symtableproc:=procdefinition.owner;
  1923. but neede for overloaded operators !! }
  1924. if symtableproc=nil then
  1925. symtableproc:=procdefinition.owner;
  1926. end; { end of procedure to call determination }
  1927. { add needed default parameters }
  1928. if assigned(procs) and
  1929. (paralength<procdefinition.maxparacount) then
  1930. begin
  1931. { add default parameters, just read back the skipped
  1932. paras starting from firstPara.previous, when not available
  1933. (all parameters are default) then start with the last
  1934. parameter and read backward (PFV) }
  1935. if not assigned(procs^.firstpara) then
  1936. pdc:=tparaitem(procs^.data.Para.last)
  1937. else
  1938. pdc:=tparaitem(procs^.firstPara.previous);
  1939. while assigned(pdc) do
  1940. begin
  1941. if not assigned(pdc.defaultvalue) then
  1942. internalerror(751349858);
  1943. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1944. pdc:=tparaitem(pdc.previous);
  1945. end;
  1946. end;
  1947. end;
  1948. { handle predefined procedures }
  1949. is_const:=(po_internconst in procdefinition.procoptions) and
  1950. ((block_type in [bt_const,bt_type]) or
  1951. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1952. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1953. begin
  1954. if assigned(left) then
  1955. begin
  1956. { ptr and settextbuf needs two args }
  1957. if assigned(tcallparanode(left).right) then
  1958. begin
  1959. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1960. left:=nil;
  1961. end
  1962. else
  1963. begin
  1964. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1965. tcallparanode(left).left:=nil;
  1966. end;
  1967. end
  1968. else
  1969. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1970. result:=hpt;
  1971. goto errorexit;
  1972. end;
  1973. { Calling a message method directly ? }
  1974. if assigned(procdefinition) and
  1975. (po_containsself in procdefinition.procoptions) then
  1976. message(cg_e_cannot_call_message_direct);
  1977. { ensure that the result type is set }
  1978. if not restypeset then
  1979. resulttype:=procdefinition.rettype
  1980. else
  1981. resulttype:=restype;
  1982. { modify the exit code, in case of special cases }
  1983. if (not is_void(resulttype.def)) then
  1984. begin
  1985. if paramanager.ret_in_reg(resulttype.def) then
  1986. begin
  1987. { wide- and ansistrings are returned in EAX }
  1988. { but they are imm. moved to a memory location }
  1989. if is_widestring(resulttype.def) or
  1990. is_ansistring(resulttype.def) then
  1991. begin
  1992. { we use ansistrings so no fast exit here }
  1993. if assigned(procinfo) then
  1994. procinfo.no_fast_exit:=true;
  1995. end;
  1996. end;
  1997. end;
  1998. { constructors return their current class type, not the type where the
  1999. constructor is declared, this can be different because of inheritance }
  2000. if (procdefinition.proctypeoption=potype_constructor) then
  2001. begin
  2002. if assigned(methodpointer) and
  2003. assigned(methodpointer.resulttype.def) and
  2004. (methodpointer.resulttype.def.deftype=classrefdef) then
  2005. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  2006. end;
  2007. { flag all callparanodes that belong to the varargs }
  2008. if (po_varargs in procdefinition.procoptions) then
  2009. begin
  2010. pt:=tcallparanode(left);
  2011. i:=paralength;
  2012. while (i>procdefinition.maxparacount) do
  2013. begin
  2014. include(tcallparanode(pt).flags,nf_varargs_para);
  2015. pt:=tcallparanode(pt.right);
  2016. dec(i);
  2017. end;
  2018. end;
  2019. { insert type conversions }
  2020. if assigned(left) then
  2021. begin
  2022. aktcallprocdef:=procdefinition;
  2023. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  2024. end;
  2025. errorexit:
  2026. { Reset some settings back }
  2027. if assigned(procs) then
  2028. dispose(procs);
  2029. aktcallprocdef:=oldcallprocdef;
  2030. end;
  2031. {$endif}
  2032. function tcallnode.pass_1 : tnode;
  2033. var
  2034. inlinecode : tnode;
  2035. inlined : boolean;
  2036. {$ifdef m68k}
  2037. regi : tregister;
  2038. {$endif}
  2039. method_must_be_valid : boolean;
  2040. label
  2041. errorexit;
  2042. begin
  2043. { the default is nothing to return }
  2044. location.loc:=LOC_INVALID;
  2045. result:=nil;
  2046. inlined:=false;
  2047. inlinecode := nil;
  2048. { work trough all parameters to get the register requirements }
  2049. if assigned(left) then
  2050. tcallparanode(left).det_registers;
  2051. if assigned(procdefinition) and
  2052. (procdefinition.proccalloption=pocall_inline) then
  2053. begin
  2054. inlinecode:=right;
  2055. if assigned(inlinecode) then
  2056. inlined:=true;
  2057. right:=nil;
  2058. end;
  2059. { procedure variable ? }
  2060. if assigned(right) then
  2061. begin
  2062. firstpass(right);
  2063. { procedure does a call }
  2064. if not (block_type in [bt_const,bt_type]) then
  2065. procinfo.flags:=procinfo.flags or pi_do_call;
  2066. rg.incrementregisterpushed(all_registers);
  2067. end
  2068. else
  2069. { not a procedure variable }
  2070. begin
  2071. { calc the correture value for the register }
  2072. { handle predefined procedures }
  2073. if (procdefinition.proccalloption=pocall_inline) then
  2074. begin
  2075. if assigned(methodpointer) then
  2076. CGMessage(cg_e_unable_inline_object_methods);
  2077. if assigned(right) and (right.nodetype<>procinlinen) then
  2078. CGMessage(cg_e_unable_inline_procvar);
  2079. { nodetype:=procinlinen; }
  2080. if not assigned(right) then
  2081. begin
  2082. if assigned(tprocdef(procdefinition).code) then
  2083. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  2084. else
  2085. CGMessage(cg_e_no_code_for_inline_stored);
  2086. if assigned(inlinecode) then
  2087. begin
  2088. { consider it has not inlined if called
  2089. again inside the args }
  2090. procdefinition.proccalloption:=pocall_fpccall;
  2091. firstpass(inlinecode);
  2092. inlined:=true;
  2093. end;
  2094. end;
  2095. end
  2096. else
  2097. begin
  2098. if not (block_type in [bt_const,bt_type]) then
  2099. procinfo.flags:=procinfo.flags or pi_do_call;
  2100. end;
  2101. { It doesn't hurt to calculate it already though :) (JM) }
  2102. rg.incrementregisterpushed(tprocdef(procdefinition).usedregisters);
  2103. end;
  2104. { get a register for the return value }
  2105. if (not is_void(resulttype.def)) then
  2106. begin
  2107. if paramanager.ret_in_param(resulttype.def) then
  2108. begin
  2109. location.loc:=LOC_CREFERENCE;
  2110. end
  2111. else
  2112. { ansi/widestrings must be registered, so we can dispose them }
  2113. if is_ansistring(resulttype.def) or
  2114. is_widestring(resulttype.def) then
  2115. begin
  2116. location.loc:=LOC_CREFERENCE;
  2117. registers32:=1;
  2118. end
  2119. else
  2120. { we have only to handle the result if it is used }
  2121. if (nf_return_value_used in flags) then
  2122. begin
  2123. case resulttype.def.deftype of
  2124. enumdef,
  2125. orddef :
  2126. begin
  2127. if (procdefinition.proctypeoption=potype_constructor) then
  2128. begin
  2129. if assigned(methodpointer) and
  2130. (methodpointer.resulttype.def.deftype=classrefdef) then
  2131. begin
  2132. location.loc:=LOC_REGISTER;
  2133. registers32:=1;
  2134. end
  2135. else
  2136. location.loc:=LOC_FLAGS;
  2137. end
  2138. else
  2139. begin
  2140. location.loc:=LOC_REGISTER;
  2141. if is_64bitint(resulttype.def) then
  2142. registers32:=2
  2143. else
  2144. registers32:=1;
  2145. end;
  2146. end;
  2147. floatdef :
  2148. begin
  2149. location.loc:=LOC_FPUREGISTER;
  2150. {$ifdef m68k}
  2151. if (cs_fp_emulation in aktmoduleswitches) or
  2152. (tfloatdef(resulttype.def).typ=s32real) then
  2153. registers32:=1
  2154. else
  2155. registersfpu:=1;
  2156. {$else not m68k}
  2157. registersfpu:=1;
  2158. {$endif not m68k}
  2159. end;
  2160. else
  2161. begin
  2162. location.loc:=LOC_REGISTER;
  2163. registers32:=1;
  2164. end;
  2165. end;
  2166. end;
  2167. end;
  2168. { a fpu can be used in any procedure !! }
  2169. {$ifdef i386}
  2170. registersfpu:=procdefinition.fpu_used;
  2171. {$endif i386}
  2172. { if this is a call to a method calc the registers }
  2173. if (methodpointer<>nil) then
  2174. begin
  2175. case methodpointer.nodetype of
  2176. { but only, if this is not a supporting node }
  2177. typen: ;
  2178. { we need one register for new return value PM }
  2179. hnewn : if registers32=0 then
  2180. registers32:=1;
  2181. else
  2182. begin
  2183. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2184. assigned(symtableproc) and (symtableproc.symtabletype=withsymtable) and
  2185. not twithsymtable(symtableproc).direct_with then
  2186. begin
  2187. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2188. end; { Is accepted by Delphi !! }
  2189. { this is not a good reason to accept it in FPC if we produce
  2190. wrong code for it !!! (PM) }
  2191. { R.Assign is not a constructor !!! }
  2192. { but for R^.Assign, R must be valid !! }
  2193. if (procdefinition.proctypeoption=potype_constructor) or
  2194. ((methodpointer.nodetype=loadn) and
  2195. ((methodpointer.resulttype.def.deftype=classrefdef) or
  2196. ((methodpointer.resulttype.def.deftype=objectdef) and
  2197. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2198. )
  2199. )
  2200. ) then
  2201. method_must_be_valid:=false
  2202. else
  2203. method_must_be_valid:=true;
  2204. firstpass(methodpointer);
  2205. set_varstate(methodpointer,method_must_be_valid);
  2206. { The object is already used ven if it is called once }
  2207. if (methodpointer.nodetype=loadn) and
  2208. (tloadnode(methodpointer).symtableentry.typ=varsym) then
  2209. tvarsym(tloadnode(methodpointer).symtableentry).varstate:=vs_used;
  2210. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2211. registers32:=max(methodpointer.registers32,registers32);
  2212. {$ifdef SUPPORT_MMX }
  2213. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2214. {$endif SUPPORT_MMX}
  2215. end;
  2216. end;
  2217. end;
  2218. if inlined then
  2219. right:=inlinecode;
  2220. { determine the registers of the procedure variable }
  2221. { is this OK for inlined procs also ?? (PM) }
  2222. if assigned(right) then
  2223. begin
  2224. registersfpu:=max(right.registersfpu,registersfpu);
  2225. registers32:=max(right.registers32,registers32);
  2226. {$ifdef SUPPORT_MMX}
  2227. registersmmx:=max(right.registersmmx,registersmmx);
  2228. {$endif SUPPORT_MMX}
  2229. end;
  2230. { determine the registers of the procedure }
  2231. if assigned(left) then
  2232. begin
  2233. registersfpu:=max(left.registersfpu,registersfpu);
  2234. registers32:=max(left.registers32,registers32);
  2235. {$ifdef SUPPORT_MMX}
  2236. registersmmx:=max(left.registersmmx,registersmmx);
  2237. {$endif SUPPORT_MMX}
  2238. end;
  2239. errorexit:
  2240. if inlined then
  2241. procdefinition.proccalloption:=pocall_inline;
  2242. end;
  2243. {$ifdef state_tracking}
  2244. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2245. var hp:Tcallparanode;
  2246. value:Tnode;
  2247. begin
  2248. track_state_pass:=false;
  2249. hp:=Tcallparanode(left);
  2250. while assigned(hp) do
  2251. begin
  2252. if left.track_state_pass(exec_known) then
  2253. begin
  2254. left.resulttype.def:=nil;
  2255. do_resulttypepass(left);
  2256. end;
  2257. value:=aktstate.find_fact(hp.left);
  2258. if value<>nil then
  2259. begin
  2260. track_state_pass:=true;
  2261. hp.left.destroy;
  2262. hp.left:=value.getcopy;
  2263. do_resulttypepass(hp.left);
  2264. end;
  2265. hp:=Tcallparanode(hp.right);
  2266. end;
  2267. end;
  2268. {$endif}
  2269. function tcallnode.docompare(p: tnode): boolean;
  2270. begin
  2271. docompare :=
  2272. inherited docompare(p) and
  2273. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2274. (symtableproc = tcallnode(p).symtableproc) and
  2275. (procdefinition = tcallnode(p).procdefinition) and
  2276. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2277. ((restypeset and tcallnode(p).restypeset and
  2278. (is_equal(restype.def,tcallnode(p).restype.def))) or
  2279. (not restypeset and not tcallnode(p).restypeset));
  2280. end;
  2281. {****************************************************************************
  2282. TPROCINLINENODE
  2283. ****************************************************************************}
  2284. constructor tprocinlinenode.create(p:tprocdef);
  2285. begin
  2286. inherited create(procinlinen);
  2287. inlineprocdef:=p;
  2288. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2289. para_offset:=0;
  2290. para_size:=0;
  2291. { copy inlinetree }
  2292. if assigned(p.code) then
  2293. inlinetree:=p.code.getcopy
  2294. else
  2295. inlinetree:=nil;
  2296. end;
  2297. destructor tprocinlinenode.destroy;
  2298. begin
  2299. if assigned(inlinetree) then
  2300. inlinetree.free;
  2301. inherited destroy;
  2302. end;
  2303. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2304. begin
  2305. inherited ppuload(t,ppufile);
  2306. inlineprocdef:=tprocdef(ppufile.getderef);
  2307. inlinetree:=ppuloadnode(ppufile);
  2308. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2309. para_offset:=0;
  2310. para_size:=0;
  2311. end;
  2312. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2313. begin
  2314. inherited ppuwrite(ppufile);
  2315. ppufile.putderef(inlineprocdef);
  2316. ppuwritenode(ppufile,inlinetree);
  2317. end;
  2318. procedure tprocinlinenode.derefimpl;
  2319. begin
  2320. inherited derefimpl;
  2321. if assigned(inlinetree) then
  2322. inlinetree.derefimpl;
  2323. resolvedef(pointer(inlineprocdef));
  2324. end;
  2325. function tprocinlinenode.getcopy : tnode;
  2326. var
  2327. n : tprocinlinenode;
  2328. begin
  2329. n:=tprocinlinenode(inherited getcopy);
  2330. n.inlineprocdef:=inlineprocdef;
  2331. if assigned(inlinetree) then
  2332. n.inlinetree:=inlinetree.getcopy
  2333. else
  2334. n.inlinetree:=nil;
  2335. n.retoffset:=retoffset;
  2336. n.para_offset:=para_offset;
  2337. n.para_size:=para_size;
  2338. getcopy:=n;
  2339. end;
  2340. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2341. begin
  2342. end;
  2343. function tprocinlinenode.det_resulttype : tnode;
  2344. begin
  2345. resulttype:=inlineprocdef.rettype;
  2346. { retrieve info from inlineprocdef }
  2347. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2348. para_offset:=0;
  2349. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2350. if paramanager.ret_in_param(inlineprocdef.rettype.def) then
  2351. inc(para_size,POINTER_SIZE);
  2352. result:=nil;
  2353. end;
  2354. function tprocinlinenode.pass_1 : tnode;
  2355. begin
  2356. firstpass(inlinetree);
  2357. registers32:=inlinetree.registers32;
  2358. registersfpu:=inlinetree.registersfpu;
  2359. {$ifdef SUPPORT_MMX}
  2360. registersmmx:=inlinetree.registersmmx;
  2361. {$endif SUPPORT_MMX}
  2362. result:=nil;
  2363. end;
  2364. function tprocinlinenode.docompare(p: tnode): boolean;
  2365. begin
  2366. docompare :=
  2367. inherited docompare(p) and
  2368. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2369. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2370. end;
  2371. begin
  2372. ccallnode:=tcallnode;
  2373. ccallparanode:=tcallparanode;
  2374. cprocinlinenode:=tprocinlinenode;
  2375. end.
  2376. {
  2377. $Log$
  2378. Revision 1.88 2002-08-20 10:31:26 daniel
  2379. * Tcallnode.det_resulttype rewritten
  2380. Revision 1.87 2002/08/19 19:36:42 peter
  2381. * More fixes for cross unit inlining, all tnodes are now implemented
  2382. * Moved pocall_internconst to po_internconst because it is not a
  2383. calling type at all and it conflicted when inlining of these small
  2384. functions was requested
  2385. Revision 1.86 2002/08/17 22:09:44 florian
  2386. * result type handling in tcgcal.pass_2 overhauled
  2387. * better tnode.dowrite
  2388. * some ppc stuff fixed
  2389. Revision 1.85 2002/08/17 09:23:34 florian
  2390. * first part of procinfo rewrite
  2391. Revision 1.84 2002/08/16 14:24:57 carl
  2392. * issameref() to test if two references are the same (then emit no opcodes)
  2393. + ret_in_reg to replace ret_in_acc
  2394. (fix some register allocation bugs at the same time)
  2395. + save_std_register now has an extra parameter which is the
  2396. usedinproc registers
  2397. Revision 1.83 2002/07/20 11:57:53 florian
  2398. * types.pas renamed to defbase.pas because D6 contains a types
  2399. unit so this would conflicts if D6 programms are compiled
  2400. + Willamette/SSE2 instructions to assembler added
  2401. Revision 1.82 2002/07/19 11:41:35 daniel
  2402. * State tracker work
  2403. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2404. allows the state tracker to change while nodes automatically into
  2405. repeat nodes.
  2406. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2407. 'not(a>b)' is optimized into 'a<=b'.
  2408. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2409. by removing the notn and later switchting the true and falselabels. The
  2410. same is done with 'repeat until not a'.
  2411. Revision 1.81 2002/07/15 18:03:14 florian
  2412. * readded removed changes
  2413. Revision 1.79 2002/07/11 14:41:27 florian
  2414. * start of the new generic parameter handling
  2415. Revision 1.80 2002/07/14 18:00:43 daniel
  2416. + Added the beginning of a state tracker. This will track the values of
  2417. variables through procedures and optimize things away.
  2418. Revision 1.78 2002/07/04 20:43:00 florian
  2419. * first x86-64 patches
  2420. Revision 1.77 2002/07/01 16:23:52 peter
  2421. * cg64 patch
  2422. * basics for currency
  2423. * asnode updates for class and interface (not finished)
  2424. Revision 1.76 2002/05/18 13:34:09 peter
  2425. * readded missing revisions
  2426. Revision 1.75 2002/05/16 19:46:37 carl
  2427. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2428. + try to fix temp allocation (still in ifdef)
  2429. + generic constructor calls
  2430. + start of tassembler / tmodulebase class cleanup
  2431. Revision 1.73 2002/05/12 16:53:06 peter
  2432. * moved entry and exitcode to ncgutil and cgobj
  2433. * foreach gets extra argument for passing local data to the
  2434. iterator function
  2435. * -CR checks also class typecasts at runtime by changing them
  2436. into as
  2437. * fixed compiler to cycle with the -CR option
  2438. * fixed stabs with elf writer, finally the global variables can
  2439. be watched
  2440. * removed a lot of routines from cga unit and replaced them by
  2441. calls to cgobj
  2442. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2443. u32bit then the other is typecasted also to u32bit without giving
  2444. a rangecheck warning/error.
  2445. * fixed pascal calling method with reversing also the high tree in
  2446. the parast, detected by tcalcst3 test
  2447. Revision 1.72 2002/04/25 20:16:38 peter
  2448. * moved more routines from cga/n386util
  2449. Revision 1.71 2002/04/20 21:32:23 carl
  2450. + generic FPC_CHECKPOINTER
  2451. + first parameter offset in stack now portable
  2452. * rename some constants
  2453. + move some cpu stuff to other units
  2454. - remove unused constents
  2455. * fix stacksize for some targets
  2456. * fix generic size problems which depend now on EXTEND_SIZE constant
  2457. Revision 1.70 2002/04/16 16:09:08 peter
  2458. * allow passing the address of a procedure to a formal parameter
  2459. in delphi mode
  2460. Revision 1.69 2002/04/15 19:44:19 peter
  2461. * fixed stackcheck that would be called recursively when a stack
  2462. error was found
  2463. * generic changeregsize(reg,size) for i386 register resizing
  2464. * removed some more routines from cga unit
  2465. * fixed returnvalue handling
  2466. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  2467. Revision 1.68 2002/04/15 18:57:22 carl
  2468. + target_info.size_of_pointer -> POINTER_SIZE
  2469. Revision 1.67 2002/04/02 17:11:28 peter
  2470. * tlocation,treference update
  2471. * LOC_CONSTANT added for better constant handling
  2472. * secondadd splitted in multiple routines
  2473. * location_force_reg added for loading a location to a register
  2474. of a specified size
  2475. * secondassignment parses now first the right and then the left node
  2476. (this is compatible with Kylix). This saves a lot of push/pop especially
  2477. with string operations
  2478. * adapted some routines to use the new cg methods
  2479. Revision 1.66 2002/03/31 20:26:33 jonas
  2480. + a_loadfpu_* and a_loadmm_* methods in tcg
  2481. * register allocation is now handled by a class and is mostly processor
  2482. independent (+rgobj.pas and i386/rgcpu.pas)
  2483. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2484. * some small improvements and fixes to the optimizer
  2485. * some register allocation fixes
  2486. * some fpuvaroffset fixes in the unary minus node
  2487. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2488. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2489. also better optimizable)
  2490. * fixed and optimized register saving/restoring for new/dispose nodes
  2491. * LOC_FPU locations now also require their "register" field to be set to
  2492. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2493. - list field removed of the tnode class because it's not used currently
  2494. and can cause hard-to-find bugs
  2495. Revision 1.65 2002/03/30 23:02:42 carl
  2496. * avoid crash with inline routines
  2497. Revision 1.64 2002/01/24 18:25:48 peter
  2498. * implicit result variable generation for assembler routines
  2499. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2500. Revision 1.63 2002/01/24 12:33:52 jonas
  2501. * adapted ranges of native types to int64 (e.g. high cardinal is no
  2502. longer longint($ffffffff), but just $fffffff in psystem)
  2503. * small additional fix in 64bit rangecheck code generation for 32 bit
  2504. processors
  2505. * adaption of ranges required the matching talgorithm used for selecting
  2506. which overloaded procedure to call to be adapted. It should now always
  2507. select the closest match for ordinal parameters.
  2508. + inttostr(qword) in sysstr.inc/sysstrh.inc
  2509. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  2510. fixes were required to be able to add them)
  2511. * is_in_limit() moved from ncal to types unit, should always be used
  2512. instead of direct comparisons of low/high values of orddefs because
  2513. qword is a special case
  2514. Revision 1.62 2002/01/19 11:57:05 peter
  2515. * fixed path appending for lib
  2516. }