ncal.pas 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777
  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. ordspace:=ordspace+(double(Torddef(from_def).low)-Torddef(to_def).low)+
  791. (double(Torddef(to_def).high)-Torddef(from_def).high);
  792. end
  793. else if ((from_def.deftype=orddef) and (to_def.deftype=orddef)) and
  794. (is_in_limit(from_def,to_def) or
  795. ((candparas.paratyp in [vs_var,vs_out]) and (from_def.size=to_def.size))
  796. ) then
  797. begin
  798. ordspace:=ordspace+Torddef(to_def).high;
  799. ordspace:=ordspace-Torddef(to_def).low;
  800. inc(equal_count);
  801. end
  802. else if is_equal(treeparas,to_def) then
  803. inc(equal_count)
  804. else
  805. case isconvertable(from_def,to_def,
  806. hcvt,treeparas.left.nodetype,false) of
  807. 0:
  808. internalerror(200208021);
  809. 1:
  810. inc(cl1_count);
  811. 2:
  812. inc(cl2_count);
  813. end;
  814. treeparas:=Tcallparanode(treeparas.right);
  815. candparas:=Tparaitem(candparas.next);
  816. end;
  817. end;
  818. type Tcandidate_array=array[1..$ffff] of Tprocdef;
  819. Pcandidate_array=^Tcandidate_array;
  820. var candidate_alloc,candidates_left,candidate_count:cardinal;
  821. c1,c2,delete_start:cardinal;
  822. cl2_count1,cl1_count1,equal_count1,exact_count1:byte;
  823. ordspace1:double;
  824. cl2_count2,cl1_count2,equal_count2,exact_count2:byte;
  825. ordspace2:double;
  826. i,n:cardinal;
  827. pt:Tcallparanode;
  828. def:Tprocdef;
  829. hcvt:Tconverttype;
  830. pdc:Tparaitem;
  831. hpt:Tnode;
  832. srprocsym:Tprocsym;
  833. srsymtable:Tsymtable;
  834. candidate_defs:Pcandidate_array;
  835. begin
  836. if fileinfo.line=398 then
  837. i:=0;
  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. {Collect all procedures which have the same # of parameters }
  848. candidates_left:=0;
  849. candidate_count:=0;
  850. candidate_alloc:=32;
  851. getmem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  852. srprocsym:=symtableprocentry;
  853. srsymtable:=symtableprocentry.owner;
  854. repeat
  855. for i:=1 to srprocsym.procdef_count do
  856. begin
  857. def:=srprocsym.procdef(i);
  858. { only when the # of parameters are supported by the procedure }
  859. if (paralength>=def.minparacount) and
  860. ((po_varargs in def.procoptions) or (paralength<=def.maxparacount)) then
  861. begin
  862. candidate_defs^[i]:=def;
  863. inc(candidates_left);
  864. end
  865. else
  866. candidate_defs^[i]:=nil;
  867. inc(candidate_count);
  868. if candidate_alloc=candidate_count then
  869. begin
  870. candidate_alloc:=candidate_alloc*2;
  871. reallocmem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  872. end;
  873. end;
  874. if po_overload in srprocsym.first_procdef.procoptions then
  875. begin
  876. repeat
  877. repeat
  878. srsymtable:=srsymtable.next;
  879. until (srsymtable=nil) or (srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable]);
  880. if assigned(srsymtable) then
  881. srprocsym:=Tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  882. until (srsymtable=nil) or (srprocsym<>nil);
  883. if not assigned(srprocsym) then
  884. break;
  885. end
  886. else
  887. break;
  888. until false;
  889. { no procedures found? then there is something wrong
  890. with the parameter size }
  891. if candidates_left=0 then
  892. begin
  893. { in tp mode we can try to convert to procvar if
  894. there are no parameters specified }
  895. if not(assigned(left)) and
  896. (m_tp_procvar in aktmodeswitches) then
  897. begin
  898. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  899. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  900. assigned(methodpointer) then
  901. tloadnode(hpt).set_mp(methodpointer.getcopy);
  902. resulttypepass(hpt);
  903. choose_definition_to_call:=hpt;
  904. end
  905. else
  906. begin
  907. if assigned(left) then
  908. aktfilepos:=left.fileinfo;
  909. cgmessage(parser_e_wrong_parameter_size);
  910. symtableprocentry.write_parameter_lists(nil);
  911. end;
  912. exit;
  913. end;
  914. {Walk through all candidates and remove the ones
  915. that have incompatible parameters.}
  916. for i:=1 to candidate_count do
  917. if assigned(candidate_defs^[i]) then
  918. begin
  919. def:=candidate_defs^[i];
  920. {Walk through all parameters.}
  921. pdc:=Tparaitem(def.para.first);
  922. pt:=Tcallparanode(left);
  923. while assigned(pdc) do
  924. begin
  925. if pdc.paratyp in [vs_var,vs_out] then
  926. if is_var_para_incompatible(pt.resulttype.def,pdc.paratype.def) and
  927. not(is_shortstring(pt.resulttype.def) and is_shortstring(pdc.paratype.def)) and
  928. (pdc.paratype.def.deftype<>formaldef) then
  929. begin
  930. {Not convertable, def is no longer a candidate.}
  931. candidate_defs^[i]:=nil;
  932. dec(candidates_left);
  933. break;
  934. end
  935. else
  936. exclude(pt.callparaflags,cpf_nomatchfound)
  937. else
  938. if (pt.resulttype.def<>pdc.paratype.def) and
  939. ((isconvertable(pt.resulttype.def,pdc.paratype.def,
  940. hcvt,pt.left.nodetype,false)=0) and
  941. not is_equal(pt,pdc.paratype.def)) then
  942. begin
  943. {Not convertable, def is no longer a candidate.}
  944. candidate_defs^[i]:=nil;
  945. dec(candidates_left);
  946. break;
  947. end
  948. else
  949. exclude(pt.callparaflags,cpf_nomatchfound);
  950. pdc:=Tparaitem(pdc.next);
  951. pt:=Tcallparanode(pt.right);
  952. end;
  953. end;
  954. {Are there any candidates left?}
  955. if candidates_left=0 then
  956. begin
  957. {There is an error, must be wrong type, because
  958. wrong size is already checked (PFV) }
  959. pt:=Tcallparanode(left);
  960. n:=0;
  961. while assigned(pt) do
  962. if cpf_nomatchfound in pt.callparaflags then
  963. break
  964. else
  965. begin
  966. pt:=tcallparanode(pt.right);
  967. inc(n);
  968. end;
  969. if not(assigned(pt) and assigned(pt.resulttype.def)) then
  970. internalerror(39393);
  971. {Def contains the last candidate tested.}
  972. pdc:=Tparaitem(def.para.first);
  973. for i:=1 to n do
  974. pdc:=Tparaitem(pdc.next);
  975. aktfilepos:=pt.fileinfo;
  976. cgmessage3(type_e_wrong_parameter_type,tostr(n+1),
  977. pt.resulttype.def.typename,pdc.paratype.def.typename);
  978. symtableprocentry.write_parameter_lists(nil);
  979. exit;
  980. end;
  981. {If there is more candidate that can be called, we have to
  982. find the most suitable one. We collect the following
  983. information:
  984. - Amount of convertlevel 2 parameters.
  985. - Amount of convertlevel 1 parameters.
  986. - Amount of equal parameters.
  987. - Amount of exact parameters.
  988. - Amount of ordinal space the destination parameters
  989. provide. For exampe, a word provides 65535-255=65280
  990. of ordinal space above a byte.
  991. The first criterium is the candidate that has the least
  992. convertlevel 2 parameters. The next criterium is
  993. the candidate that has the most exact parameters, next
  994. criterium is the least ordinal space and
  995. the last criterium is the most equal parameters. (DM)}
  996. if candidates_left>1 then
  997. begin
  998. {Find the first candidate.}
  999. c1:=1;
  1000. while c1<=candidate_count do
  1001. if assigned(candidate_defs^[c1]) then
  1002. break
  1003. else
  1004. inc(c1);
  1005. delete_start:=c1;
  1006. {Get information about candidate c1.}
  1007. get_candidate_information(cl2_count1,cl1_count1,equal_count1,
  1008. exact_count1,ordspace1,Tcallparanode(left),
  1009. Tparaitem(candidate_defs^[c1].para.first));
  1010. {Find the other candidates and eliminate the lesser ones.}
  1011. c2:=c1+1;
  1012. while c2<=candidate_count do
  1013. if assigned(candidate_defs^[c2]) then
  1014. begin
  1015. {Candidate found, get information on it.}
  1016. get_candidate_information(cl2_count2,cl1_count2,equal_count2,
  1017. exact_count2,ordspace2,Tcallparanode(left),
  1018. Tparaitem(candidate_defs^[c2].para.first));
  1019. {Is c1 the better candidate?}
  1020. if (cl2_count1<cl2_count2) or
  1021. ((cl2_count1=cl2_count2) and (exact_count1>exact_count2)) or
  1022. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1>equal_count2)) or
  1023. ((cl2_count1=cl2_count2) and (exact_count1=exact_count2) and (equal_count1=equal_count2) and (ordspace1<ordspace2)) then
  1024. {C1 is better, drop c2.}
  1025. candidate_defs^[c2]:=nil
  1026. {Is c2 the better candidate?}
  1027. else if (cl2_count2<cl2_count1) or
  1028. ((cl2_count2=cl2_count1) and (exact_count2>exact_count1)) or
  1029. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2>equal_count1)) or
  1030. ((cl2_count2=cl2_count1) and (exact_count2=exact_count1) and (equal_count2=equal_count1) and (ordspace2<ordspace1)) then
  1031. begin
  1032. {C2 is better, drop all previous
  1033. candidates.}
  1034. for i:=delete_start to c2-1 do
  1035. candidate_defs^[i]:=nil;
  1036. delete_start:=c2;
  1037. c1:=c2;
  1038. cl2_count1:=cl2_count2;
  1039. cl1_count1:=cl1_count2;
  1040. equal_count1:=equal_count2;
  1041. exact_count1:=exact_count2;
  1042. ordspace1:=ordspace2;
  1043. end;
  1044. {else the candidates have no advantage over each other,
  1045. do nothing}
  1046. inc(c2);
  1047. end
  1048. else
  1049. inc(c2);
  1050. end;
  1051. {Count the candidates that are left.}
  1052. candidates_left:=0;
  1053. for i:=1 to candidate_count do
  1054. if assigned(candidate_defs^[i]) then
  1055. begin
  1056. inc(candidates_left);
  1057. procdefinition:=candidate_defs^[i];
  1058. end;
  1059. if candidates_left>1 then
  1060. begin
  1061. cgmessage(cg_e_cant_choose_overload_function);
  1062. symtableprocentry.write_parameter_lists(nil);
  1063. exit;
  1064. end;
  1065. freemem(candidate_defs,candidate_alloc*sizeof(Tprocdef));
  1066. if make_ref then
  1067. begin
  1068. Tprocdef(procdefinition).lastref:=Tref.create(Tprocdef(procdefinition).lastref,@fileinfo);
  1069. inc(Tprocdef(procdefinition).refcount);
  1070. if Tprocdef(procdefinition).defref=nil then
  1071. Tprocdef(procdefinition).defref:=Tprocdef(procdefinition).lastref;
  1072. end;
  1073. { big error for with statements
  1074. symtableproc:=procdefinition.owner;
  1075. but neede for overloaded operators !! }
  1076. if symtableproc=nil then
  1077. symtableproc:=procdefinition.owner;
  1078. errorexit:=false;
  1079. end;
  1080. function tcallnode.det_resulttype:tnode;
  1081. var lastpara,paralength:byte;
  1082. oldcallprocdef:Tabstractprocdef;
  1083. pt:Tcallparanode;
  1084. i,n:byte;
  1085. e,is_const:boolean;
  1086. pdc:Tparaitem;
  1087. hpt:Tnode;
  1088. label errorexit;
  1089. begin
  1090. result:=nil;
  1091. oldcallprocdef:=aktcallprocdef;
  1092. aktcallprocdef:=nil;
  1093. { determine length of parameter list }
  1094. pt:=tcallparanode(left);
  1095. paralength:=0;
  1096. while assigned(pt) do
  1097. begin
  1098. include(pt.callparaflags,cpf_nomatchfound);
  1099. inc(paralength);
  1100. pt:=tcallparanode(pt.right);
  1101. end;
  1102. { determine the type of the parameters }
  1103. if assigned(left) then
  1104. begin
  1105. tcallparanode(left).get_paratype;
  1106. if codegenerror then
  1107. goto errorexit;
  1108. end;
  1109. { procedure variable ? }
  1110. if assigned(right) then
  1111. begin
  1112. set_varstate(right,true);
  1113. resulttypepass(right);
  1114. if codegenerror then
  1115. exit;
  1116. procdefinition:=tabstractprocdef(right.resulttype.def);
  1117. { check the amount of parameters }
  1118. pdc:=tparaitem(procdefinition.Para.first);
  1119. pt:=tcallparanode(left);
  1120. lastpara:=paralength;
  1121. while assigned(pdc) and assigned(pt) do
  1122. begin
  1123. { only goto next para if we're out of the varargs }
  1124. if not(po_varargs in procdefinition.procoptions) or
  1125. (lastpara<=procdefinition.maxparacount) then
  1126. pdc:=tparaitem(pdc.next);
  1127. pt:=tcallparanode(pt.right);
  1128. dec(lastpara);
  1129. end;
  1130. if assigned(pt) or assigned(pdc) then
  1131. begin
  1132. if assigned(pt) then
  1133. aktfilepos:=pt.fileinfo;
  1134. CGMessage(parser_e_wrong_parameter_size);
  1135. end;
  1136. end
  1137. else
  1138. { not a procedure variable }
  1139. begin
  1140. { do we know the procedure to call ? }
  1141. if not(assigned(procdefinition)) then
  1142. begin
  1143. result:=choose_definition_to_call(paralength,e);
  1144. if e then
  1145. goto errorexit;
  1146. end;
  1147. (* To do!!!
  1148. { add needed default parameters }
  1149. if assigned(procdefinition) and
  1150. (paralength<procdefinition.maxparacount) then
  1151. begin
  1152. { add default parameters, just read back the skipped
  1153. paras starting from firstPara.previous, when not available
  1154. (all parameters are default) then start with the last
  1155. parameter and read backward (PFV) }
  1156. if not assigned(procs^.firstpara) then
  1157. pdc:=tparaitem(procs^.data.Para.last)
  1158. else
  1159. pdc:=tparaitem(procs^.firstPara.previous);
  1160. while assigned(pdc) do
  1161. begin
  1162. if not assigned(pdc.defaultvalue) then
  1163. internalerror(751349858);
  1164. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1165. pdc:=tparaitem(pdc.previous);
  1166. end;
  1167. end;
  1168. *)
  1169. end;
  1170. { handle predefined procedures }
  1171. is_const:=(po_internconst in procdefinition.procoptions) and
  1172. ((block_type in [bt_const,bt_type]) or
  1173. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1174. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1175. begin
  1176. if assigned(left) then
  1177. begin
  1178. { ptr and settextbuf needs two args }
  1179. if assigned(tcallparanode(left).right) then
  1180. begin
  1181. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,left);
  1182. left:=nil;
  1183. end
  1184. else
  1185. begin
  1186. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,Tcallparanode(left).left);
  1187. Tcallparanode(left).left:=nil;
  1188. end;
  1189. end
  1190. else
  1191. hpt:=geninlinenode(Tprocdef(procdefinition).extnumber,is_const,nil);
  1192. result:=hpt;
  1193. goto errorexit;
  1194. end;
  1195. { Calling a message method directly ? }
  1196. if assigned(procdefinition) and
  1197. (po_containsself in procdefinition.procoptions) then
  1198. message(cg_e_cannot_call_message_direct);
  1199. { ensure that the result type is set }
  1200. if not restypeset then
  1201. resulttype:=procdefinition.rettype
  1202. else
  1203. resulttype:=restype;
  1204. { modify the exit code, in case of special cases }
  1205. if (not is_void(resulttype.def)) then
  1206. begin
  1207. if paramanager.ret_in_acc(resulttype.def) then
  1208. begin
  1209. { wide- and ansistrings are returned in EAX }
  1210. { but they are imm. moved to a memory location }
  1211. if is_widestring(resulttype.def) or
  1212. is_ansistring(resulttype.def) then
  1213. begin
  1214. { we use ansistrings so no fast exit here }
  1215. if assigned(procinfo) then
  1216. procinfo.no_fast_exit:=true;
  1217. end;
  1218. end;
  1219. end;
  1220. { constructors return their current class type, not the type where the
  1221. constructor is declared, this can be different because of inheritance }
  1222. if (procdefinition.proctypeoption=potype_constructor) then
  1223. begin
  1224. if assigned(methodpointer) and
  1225. assigned(methodpointer.resulttype.def) and
  1226. (methodpointer.resulttype.def.deftype=classrefdef) then
  1227. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  1228. end;
  1229. { flag all callparanodes that belong to the varargs }
  1230. if (po_varargs in procdefinition.procoptions) then
  1231. begin
  1232. pt:=tcallparanode(left);
  1233. i:=paralength;
  1234. while (i>procdefinition.maxparacount) do
  1235. begin
  1236. include(tcallparanode(pt).flags,nf_varargs_para);
  1237. pt:=tcallparanode(pt.right);
  1238. dec(i);
  1239. end;
  1240. end;
  1241. { insert type conversions }
  1242. if assigned(left) then
  1243. begin
  1244. aktcallprocdef:=procdefinition;
  1245. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  1246. end;
  1247. errorexit:
  1248. { Reset some settings back }
  1249. aktcallprocdef:=oldcallprocdef;
  1250. end;
  1251. {$else}
  1252. function tcallnode.det_resulttype:tnode;
  1253. type
  1254. pprocdefcoll = ^tprocdefcoll;
  1255. tprocdefcoll = record
  1256. data : tprocdef;
  1257. nextpara : tparaitem;
  1258. firstpara : tparaitem;
  1259. next : pprocdefcoll;
  1260. end;
  1261. var
  1262. hp,procs,hp2 : pprocdefcoll;
  1263. pd : pprocdeflist;
  1264. oldcallprocdef : tabstractprocdef;
  1265. def_from,def_to,conv_to : tdef;
  1266. hpt : tnode;
  1267. pt : tcallparanode;
  1268. exactmatch : boolean;
  1269. paralength,lastpara : longint;
  1270. lastparatype : tdef;
  1271. pdc : tparaitem;
  1272. { only Dummy }
  1273. hcvt : tconverttype;
  1274. label
  1275. errorexit;
  1276. { check if the resulttype.def from tree p is equal with def, needed
  1277. for stringconstn and formaldef }
  1278. function is_equal(p:tcallparanode;def:tdef) : boolean;
  1279. begin
  1280. { safety check }
  1281. if not (assigned(def) or assigned(p.resulttype.def)) then
  1282. begin
  1283. is_equal:=false;
  1284. exit;
  1285. end;
  1286. { all types can be passed to a formaldef }
  1287. is_equal:=(def.deftype=formaldef) or
  1288. (defbase.is_equal(p.resulttype.def,def))
  1289. { integer constants are compatible with all integer parameters if
  1290. the specified value matches the range }
  1291. or
  1292. (
  1293. (tbinarynode(p).left.nodetype=ordconstn) and
  1294. is_integer(p.resulttype.def) and
  1295. is_integer(def) and
  1296. (tordconstnode(p.left).value>=torddef(def).low) and
  1297. (tordconstnode(p.left).value<=torddef(def).high)
  1298. )
  1299. { to support ansi/long/wide strings in a proper way }
  1300. { string and string[10] are assumed as equal }
  1301. { when searching the correct overloaded procedure }
  1302. or
  1303. (
  1304. (def.deftype=stringdef) and (p.resulttype.def.deftype=stringdef) and
  1305. (tstringdef(def).string_typ=tstringdef(p.resulttype.def).string_typ)
  1306. )
  1307. or
  1308. (
  1309. (p.left.nodetype=stringconstn) and
  1310. (is_ansistring(p.resulttype.def) and is_pchar(def))
  1311. )
  1312. or
  1313. (
  1314. (p.left.nodetype=ordconstn) and
  1315. (is_char(p.resulttype.def) and (is_shortstring(def) or is_ansistring(def)))
  1316. )
  1317. { set can also be a not yet converted array constructor }
  1318. or
  1319. (
  1320. (def.deftype=setdef) and (p.resulttype.def.deftype=arraydef) and
  1321. (tarraydef(p.resulttype.def).IsConstructor) and not(tarraydef(p.resulttype.def).IsVariant)
  1322. )
  1323. { in tp7 mode proc -> procvar is allowed }
  1324. or
  1325. (
  1326. (m_tp_procvar in aktmodeswitches) and
  1327. (def.deftype=procvardef) and (p.left.nodetype=calln) and
  1328. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def),false))
  1329. )
  1330. ;
  1331. end;
  1332. var
  1333. i : longint;
  1334. found,
  1335. is_const : boolean;
  1336. bestord : torddef;
  1337. srprocsym : tprocsym;
  1338. srsymtable : tsymtable;
  1339. begin
  1340. result:=nil;
  1341. procs:=nil;
  1342. oldcallprocdef:=aktcallprocdef;
  1343. aktcallprocdef:=nil;
  1344. { determine length of parameter list }
  1345. pt:=tcallparanode(left);
  1346. paralength:=0;
  1347. while assigned(pt) do
  1348. begin
  1349. inc(paralength);
  1350. pt:=tcallparanode(pt.right);
  1351. end;
  1352. { determine the type of the parameters }
  1353. if assigned(left) then
  1354. begin
  1355. tcallparanode(left).get_paratype;
  1356. if codegenerror then
  1357. goto errorexit;
  1358. end;
  1359. { procedure variable ? }
  1360. if assigned(right) then
  1361. begin
  1362. set_varstate(right,true);
  1363. resulttypepass(right);
  1364. if codegenerror then
  1365. exit;
  1366. procdefinition:=tabstractprocdef(right.resulttype.def);
  1367. { check the amount of parameters }
  1368. pdc:=tparaitem(procdefinition.Para.first);
  1369. pt:=tcallparanode(left);
  1370. lastpara:=paralength;
  1371. while assigned(pdc) and assigned(pt) do
  1372. begin
  1373. { only goto next para if we're out of the varargs }
  1374. if not(po_varargs in procdefinition.procoptions) or
  1375. (lastpara<=procdefinition.maxparacount) then
  1376. pdc:=tparaitem(pdc.next);
  1377. pt:=tcallparanode(pt.right);
  1378. dec(lastpara);
  1379. end;
  1380. if assigned(pt) or assigned(pdc) then
  1381. begin
  1382. if assigned(pt) then
  1383. aktfilepos:=pt.fileinfo;
  1384. CGMessage(parser_e_wrong_parameter_size);
  1385. end;
  1386. end
  1387. else
  1388. { not a procedure variable }
  1389. begin
  1390. { do we know the procedure to call ? }
  1391. if not(assigned(procdefinition)) then
  1392. begin
  1393. { when the definition has overload directive set, we search for
  1394. overloaded definitions in the class, this only needs to be done once
  1395. for class entries as the tree keeps always the same }
  1396. if (not symtableprocentry.overloadchecked) and
  1397. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1398. (symtableprocentry.owner.symtabletype=objectsymtable) then
  1399. search_class_overloads(symtableprocentry);
  1400. { link all procedures which have the same # of parameters }
  1401. pd:=symtableprocentry.defs;
  1402. while assigned(pd) do
  1403. begin
  1404. { only when the # of parameter are supported by the
  1405. procedure }
  1406. if (paralength>=pd^.def.minparacount) and
  1407. ((po_varargs in pd^.def.procoptions) or { varargs }
  1408. (paralength<=pd^.def.maxparacount)) then
  1409. begin
  1410. new(hp);
  1411. hp^.data:=pd^.def;
  1412. hp^.next:=procs;
  1413. hp^.firstpara:=tparaitem(pd^.def.Para.first);
  1414. if not(po_varargs in pd^.def.procoptions) then
  1415. begin
  1416. { if not all parameters are given, then skip the
  1417. default parameters }
  1418. for i:=1 to pd^.def.maxparacount-paralength do
  1419. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1420. end;
  1421. hp^.nextpara:=hp^.firstpara;
  1422. procs:=hp;
  1423. end;
  1424. pd:=pd^.next;
  1425. end;
  1426. { when the definition has overload directive set, we search for
  1427. overloaded definitions in the symtablestack. The found
  1428. entries are only added to the procs list and not the procsym, because
  1429. the list can change in every situation }
  1430. if (po_overload in symtableprocentry.first_procdef.procoptions) and
  1431. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1432. begin
  1433. srsymtable:=symtableprocentry.owner.next;
  1434. while assigned(srsymtable) do
  1435. begin
  1436. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1437. begin
  1438. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1439. { process only visible procsyms }
  1440. if assigned(srprocsym) and
  1441. (srprocsym.typ=procsym) and
  1442. srprocsym.is_visible_for_proc(aktprocdef) then
  1443. begin
  1444. { if this procedure doesn't have overload we can stop
  1445. searching }
  1446. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1447. break;
  1448. { process all overloaded definitions }
  1449. pd:=srprocsym.defs;
  1450. while assigned(pd) do
  1451. begin
  1452. { only when the # of parameter are supported by the
  1453. procedure }
  1454. if (paralength>=pd^.def.minparacount) and
  1455. ((po_varargs in pd^.def.procoptions) or { varargs }
  1456. (paralength<=pd^.def.maxparacount)) then
  1457. begin
  1458. found:=false;
  1459. hp:=procs;
  1460. while assigned(hp) do
  1461. begin
  1462. if equal_paras(hp^.data.para,pd^.def.para,cp_value_equal_const) then
  1463. begin
  1464. found:=true;
  1465. break;
  1466. end;
  1467. hp:=hp^.next;
  1468. end;
  1469. if not found then
  1470. begin
  1471. new(hp);
  1472. hp^.data:=pd^.def;
  1473. hp^.next:=procs;
  1474. hp^.firstpara:=tparaitem(pd^.def.Para.first);
  1475. if not(po_varargs in pd^.def.procoptions) then
  1476. begin
  1477. { if not all parameters are given, then skip the
  1478. default parameters }
  1479. for i:=1 to pd^.def.maxparacount-paralength do
  1480. hp^.firstpara:=tparaitem(hp^.firstPara.next);
  1481. end;
  1482. hp^.nextpara:=hp^.firstpara;
  1483. procs:=hp;
  1484. end;
  1485. end;
  1486. pd:=pd^.next;
  1487. end;
  1488. end;
  1489. end;
  1490. srsymtable:=srsymtable.next;
  1491. end;
  1492. end;
  1493. { no procedures found? then there is something wrong
  1494. with the parameter size }
  1495. if not assigned(procs) then
  1496. begin
  1497. { in tp mode we can try to convert to procvar if
  1498. there are no parameters specified }
  1499. if not(assigned(left)) and
  1500. (m_tp_procvar in aktmodeswitches) then
  1501. begin
  1502. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1503. if (symtableprocentry.owner.symtabletype=objectsymtable) and
  1504. assigned(methodpointer) then
  1505. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1506. resulttypepass(hpt);
  1507. result:=hpt;
  1508. end
  1509. else
  1510. begin
  1511. if assigned(left) then
  1512. aktfilepos:=left.fileinfo;
  1513. CGMessage(parser_e_wrong_parameter_size);
  1514. symtableprocentry.write_parameter_lists(nil);
  1515. end;
  1516. goto errorexit;
  1517. end;
  1518. { now we can compare parameter after parameter }
  1519. pt:=tcallparanode(left);
  1520. { we start with the last parameter }
  1521. lastpara:=paralength+1;
  1522. lastparatype:=nil;
  1523. while assigned(pt) do
  1524. begin
  1525. dec(lastpara);
  1526. { walk all procedures and determine how this parameter matches and set:
  1527. 1. pt.exact_match_found if one parameter has an exact match
  1528. 2. exactmatch if an equal or exact match is found
  1529. 3. Para.argconvtyp to exact,equal or convertable
  1530. (when convertable then also convertlevel is set)
  1531. 4. pt.convlevel1found if there is a convertlevel=1
  1532. 5. pt.convlevel2found if there is a convertlevel=2
  1533. }
  1534. exactmatch:=false;
  1535. hp:=procs;
  1536. while assigned(hp) do
  1537. begin
  1538. { varargs are always equal, but not exact }
  1539. if (po_varargs in hp^.data.procoptions) and
  1540. (lastpara>hp^.data.minparacount) then
  1541. begin
  1542. hp^.nextPara.argconvtyp:=act_equal;
  1543. exactmatch:=true;
  1544. end
  1545. else
  1546. begin
  1547. if is_equal(pt,hp^.nextPara.paratype.def) then
  1548. begin
  1549. if hp^.nextPara.paratype.def=pt.resulttype.def then
  1550. begin
  1551. include(pt.callparaflags,cpf_exact_match_found);
  1552. hp^.nextPara.argconvtyp:=act_exact;
  1553. end
  1554. else
  1555. hp^.nextPara.argconvtyp:=act_equal;
  1556. exactmatch:=true;
  1557. end
  1558. else
  1559. begin
  1560. hp^.nextPara.argconvtyp:=act_convertable;
  1561. hp^.nextPara.convertlevel:=isconvertable(pt.resulttype.def,hp^.nextPara.paratype.def,
  1562. hcvt,pt.left.nodetype,false);
  1563. case hp^.nextPara.convertlevel of
  1564. 1 : include(pt.callparaflags,cpf_convlevel1found);
  1565. 2 : include(pt.callparaflags,cpf_convlevel2found);
  1566. end;
  1567. end;
  1568. end;
  1569. hp:=hp^.next;
  1570. end;
  1571. { If there was an exactmatch then delete all convertables }
  1572. if exactmatch then
  1573. begin
  1574. hp:=procs;
  1575. procs:=nil;
  1576. while assigned(hp) do
  1577. begin
  1578. hp2:=hp^.next;
  1579. { keep if not convertable }
  1580. if (hp^.nextPara.argconvtyp<>act_convertable) then
  1581. begin
  1582. hp^.next:=procs;
  1583. procs:=hp;
  1584. end
  1585. else
  1586. dispose(hp);
  1587. hp:=hp2;
  1588. end;
  1589. end
  1590. else
  1591. { No exact match was found, remove all procedures that are
  1592. not convertable (convertlevel=0) }
  1593. begin
  1594. hp:=procs;
  1595. procs:=nil;
  1596. while assigned(hp) do
  1597. begin
  1598. hp2:=hp^.next;
  1599. { keep if not convertable }
  1600. if (hp^.nextPara.convertlevel<>0) then
  1601. begin
  1602. hp^.next:=procs;
  1603. procs:=hp;
  1604. end
  1605. else
  1606. begin
  1607. { save the type for nice error message }
  1608. lastparatype:=hp^.nextPara.paratype.def;
  1609. dispose(hp);
  1610. end;
  1611. hp:=hp2;
  1612. end;
  1613. end;
  1614. { update nextpara for all procedures }
  1615. hp:=procs;
  1616. while assigned(hp) do
  1617. begin
  1618. { only goto next para if we're out of the varargs }
  1619. if not(po_varargs in hp^.data.procoptions) or
  1620. (lastpara<=hp^.data.maxparacount) then
  1621. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1622. hp:=hp^.next;
  1623. end;
  1624. { load next parameter or quit loop if no procs left }
  1625. if assigned(procs) then
  1626. pt:=tcallparanode(pt.right)
  1627. else
  1628. break;
  1629. end;
  1630. { All parameters are checked, check if there are any
  1631. procedures left }
  1632. if not assigned(procs) then
  1633. begin
  1634. { there is an error, must be wrong type, because
  1635. wrong size is already checked (PFV) }
  1636. if (not assigned(lastparatype)) or
  1637. (not assigned(pt)) or
  1638. (not assigned(pt.resulttype.def)) then
  1639. internalerror(39393)
  1640. else
  1641. begin
  1642. aktfilepos:=pt.fileinfo;
  1643. CGMessage3(type_e_wrong_parameter_type,tostr(lastpara),
  1644. pt.resulttype.def.typename,lastparatype.typename);
  1645. end;
  1646. symtableprocentry.write_parameter_lists(nil);
  1647. goto errorexit;
  1648. end;
  1649. { if there are several choices left then for orddef }
  1650. { if a type is totally included in the other }
  1651. { we don't fear an overflow , }
  1652. { so we can do as if it is an exact match }
  1653. { this will convert integer to longint }
  1654. { rather than to words }
  1655. { conversion of byte to integer or longint }
  1656. { would still not be solved }
  1657. if assigned(procs) and assigned(procs^.next) then
  1658. begin
  1659. hp:=procs;
  1660. while assigned(hp) do
  1661. begin
  1662. hp^.nextpara:=hp^.firstpara;
  1663. hp:=hp^.next;
  1664. end;
  1665. pt:=tcallparanode(left);
  1666. while assigned(pt) do
  1667. begin
  1668. { matches a parameter of one procedure exact ? }
  1669. exactmatch:=false;
  1670. def_from:=pt.resulttype.def;
  1671. hp:=procs;
  1672. while assigned(hp) do
  1673. begin
  1674. if not is_equal(pt,hp^.nextPara.paratype.def) then
  1675. begin
  1676. def_to:=hp^.nextPara.paratype.def;
  1677. if ((def_from.deftype=orddef) and (def_to.deftype=orddef)) and
  1678. (is_in_limit(def_from,def_to) or
  1679. ((hp^.nextPara.paratyp in [vs_var,vs_out]) and
  1680. (def_from.size=def_to.size))) then
  1681. begin
  1682. exactmatch:=true;
  1683. conv_to:=def_to;
  1684. { there's no use in continuing the search, it will }
  1685. { only result in conv_to being overwritten }
  1686. break;
  1687. end;
  1688. end;
  1689. hp:=hp^.next;
  1690. end;
  1691. { .... if yes, del all the other procedures }
  1692. if exactmatch then
  1693. begin
  1694. { the first .... }
  1695. while (assigned(procs)) and not(is_in_limit(def_from,procs^.nextPara.paratype.def)) do
  1696. begin
  1697. hp:=procs^.next;
  1698. dispose(procs);
  1699. procs:=hp;
  1700. end;
  1701. { and the others }
  1702. hp:=procs;
  1703. while (assigned(hp)) and assigned(hp^.next) do
  1704. begin
  1705. def_to:=hp^.next^.nextPara.paratype.def;
  1706. if not(is_in_limit(def_from,def_to)) then
  1707. begin
  1708. hp2:=hp^.next^.next;
  1709. dispose(hp^.next);
  1710. hp^.next:=hp2;
  1711. end
  1712. else
  1713. begin
  1714. { did we possibly find a better match? }
  1715. if (conv_to.size>def_to.size) or
  1716. is_in_limit(def_to,conv_to) then
  1717. begin
  1718. { is it the same as the previous best? }
  1719. if not defbase.is_equal(def_to,conv_to) then
  1720. begin
  1721. { no -> remove all previous best matches }
  1722. hp := hp^.next;
  1723. while procs <> hp do
  1724. begin
  1725. hp2 := procs;
  1726. procs := procs^.next;
  1727. dispose(hp2);
  1728. end;
  1729. { set new match type }
  1730. conv_to:=def_to;
  1731. end
  1732. { the new one matches just as well as the }
  1733. { old one -> keep both }
  1734. else
  1735. hp := hp^.next;
  1736. end
  1737. { not a better match -> remove }
  1738. else
  1739. begin
  1740. hp2 := hp^.next^.next;
  1741. dispose(hp^.next);
  1742. hp^.next:=hp2;
  1743. end;
  1744. end;
  1745. end;
  1746. end;
  1747. { update nextpara for all procedures }
  1748. hp:=procs;
  1749. while assigned(hp) do
  1750. begin
  1751. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1752. hp:=hp^.next;
  1753. end;
  1754. pt:=tcallparanode(pt.right);
  1755. end;
  1756. end;
  1757. { let's try to eliminate equal if there is an exact match
  1758. is there }
  1759. if assigned(procs) and assigned(procs^.next) then
  1760. begin
  1761. { reset nextpara for all procs left }
  1762. hp:=procs;
  1763. while assigned(hp) do
  1764. begin
  1765. hp^.nextpara:=hp^.firstpara;
  1766. hp:=hp^.next;
  1767. end;
  1768. pt:=tcallparanode(left);
  1769. while assigned(pt) do
  1770. begin
  1771. if cpf_exact_match_found in pt.callparaflags then
  1772. begin
  1773. hp:=procs;
  1774. procs:=nil;
  1775. while assigned(hp) do
  1776. begin
  1777. hp2:=hp^.next;
  1778. { keep the exact matches, dispose the others }
  1779. if (hp^.nextPara.argconvtyp=act_exact) then
  1780. begin
  1781. hp^.next:=procs;
  1782. procs:=hp;
  1783. end
  1784. else
  1785. dispose(hp);
  1786. hp:=hp2;
  1787. end;
  1788. end;
  1789. { update nextpara for all procedures }
  1790. hp:=procs;
  1791. while assigned(hp) do
  1792. begin
  1793. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1794. hp:=hp^.next;
  1795. end;
  1796. pt:=tcallparanode(pt.right);
  1797. end;
  1798. end;
  1799. { Check if there are integer constant to integer
  1800. parameters then choose the best matching integer
  1801. parameter and remove the others, this is Delphi
  1802. compatible. 1 = byte, 256 = word, etc. }
  1803. if assigned(procs) and assigned(procs^.next) then
  1804. begin
  1805. { reset nextpara for all procs left }
  1806. hp:=procs;
  1807. while assigned(hp) do
  1808. begin
  1809. hp^.nextpara:=hp^.firstpara;
  1810. hp:=hp^.next;
  1811. end;
  1812. pt:=tcallparanode(left);
  1813. while assigned(pt) do
  1814. begin
  1815. bestord:=nil;
  1816. if (pt.left.nodetype=ordconstn) and
  1817. is_integer(pt.resulttype.def) then
  1818. begin
  1819. hp:=procs;
  1820. while assigned(hp) do
  1821. begin
  1822. def_to:=hp^.nextPara.paratype.def;
  1823. { to be sure, it couldn't be something else,
  1824. also the defs here are all in the range
  1825. so now find the closest range }
  1826. if not is_integer(def_to) then
  1827. internalerror(43297815);
  1828. if (not assigned(bestord)) or
  1829. ((torddef(def_to).low>bestord.low) or
  1830. (torddef(def_to).high<bestord.high)) then
  1831. bestord:=torddef(def_to);
  1832. hp:=hp^.next;
  1833. end;
  1834. end;
  1835. { if a bestmatch is found then remove the other
  1836. procs which don't match the bestord }
  1837. if assigned(bestord) then
  1838. begin
  1839. hp:=procs;
  1840. procs:=nil;
  1841. while assigned(hp) do
  1842. begin
  1843. hp2:=hp^.next;
  1844. { keep matching bestord, dispose the others }
  1845. if (torddef(hp^.nextPara.paratype.def)=bestord) then
  1846. begin
  1847. hp^.next:=procs;
  1848. procs:=hp;
  1849. end
  1850. else
  1851. dispose(hp);
  1852. hp:=hp2;
  1853. end;
  1854. end;
  1855. { update nextpara for all procedures }
  1856. hp:=procs;
  1857. while assigned(hp) do
  1858. begin
  1859. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1860. hp:=hp^.next;
  1861. end;
  1862. pt:=tcallparanode(pt.right);
  1863. end;
  1864. end;
  1865. { Check if there are convertlevel 1 and 2 differences
  1866. left for the parameters, then discard all convertlevel
  1867. 2 procedures. The value of convlevelXfound can still
  1868. be used, because all convertables are still here or
  1869. not }
  1870. if assigned(procs) and assigned(procs^.next) then
  1871. begin
  1872. { reset nextpara for all procs left }
  1873. hp:=procs;
  1874. while assigned(hp) do
  1875. begin
  1876. hp^.nextpara:=hp^.firstpara;
  1877. hp:=hp^.next;
  1878. end;
  1879. pt:=tcallparanode(left);
  1880. while assigned(pt) do
  1881. begin
  1882. if (cpf_convlevel1found in pt.callparaflags) and
  1883. (cpf_convlevel2found in pt.callparaflags) then
  1884. begin
  1885. hp:=procs;
  1886. procs:=nil;
  1887. while assigned(hp) do
  1888. begin
  1889. hp2:=hp^.next;
  1890. { keep all not act_convertable and all convertlevels=1 }
  1891. if (hp^.nextPara.argconvtyp<>act_convertable) or
  1892. (hp^.nextPara.convertlevel=1) then
  1893. begin
  1894. hp^.next:=procs;
  1895. procs:=hp;
  1896. end
  1897. else
  1898. dispose(hp);
  1899. hp:=hp2;
  1900. end;
  1901. end;
  1902. { update nextpara for all procedures }
  1903. hp:=procs;
  1904. while assigned(hp) do
  1905. begin
  1906. hp^.nextpara:=tparaitem(hp^.nextPara.next);
  1907. hp:=hp^.next;
  1908. end;
  1909. pt:=tcallparanode(pt.right);
  1910. end;
  1911. end;
  1912. if not(assigned(procs)) or assigned(procs^.next) then
  1913. begin
  1914. CGMessage(cg_e_cant_choose_overload_function);
  1915. symtableprocentry.write_parameter_lists(nil);
  1916. goto errorexit;
  1917. end;
  1918. if make_ref then
  1919. begin
  1920. procs^.data.lastref:=tref.create(procs^.data.lastref,@fileinfo);
  1921. inc(procs^.data.refcount);
  1922. if procs^.data.defref=nil then
  1923. procs^.data.defref:=procs^.data.lastref;
  1924. end;
  1925. procdefinition:=procs^.data;
  1926. { big error for with statements
  1927. symtableproc:=procdefinition.owner;
  1928. but neede for overloaded operators !! }
  1929. if symtableproc=nil then
  1930. symtableproc:=procdefinition.owner;
  1931. end; { end of procedure to call determination }
  1932. { add needed default parameters }
  1933. if assigned(procs) and
  1934. (paralength<procdefinition.maxparacount) then
  1935. begin
  1936. { add default parameters, just read back the skipped
  1937. paras starting from firstPara.previous, when not available
  1938. (all parameters are default) then start with the last
  1939. parameter and read backward (PFV) }
  1940. if not assigned(procs^.firstpara) then
  1941. pdc:=tparaitem(procs^.data.Para.last)
  1942. else
  1943. pdc:=tparaitem(procs^.firstPara.previous);
  1944. while assigned(pdc) do
  1945. begin
  1946. if not assigned(pdc.defaultvalue) then
  1947. internalerror(751349858);
  1948. left:=ccallparanode.create(genconstsymtree(tconstsym(pdc.defaultvalue)),left);
  1949. pdc:=tparaitem(pdc.previous);
  1950. end;
  1951. end;
  1952. end;
  1953. { handle predefined procedures }
  1954. is_const:=(po_internconst in procdefinition.procoptions) and
  1955. ((block_type in [bt_const,bt_type]) or
  1956. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1957. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1958. begin
  1959. if assigned(left) then
  1960. begin
  1961. { ptr and settextbuf needs two args }
  1962. if assigned(tcallparanode(left).right) then
  1963. begin
  1964. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1965. left:=nil;
  1966. end
  1967. else
  1968. begin
  1969. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1970. tcallparanode(left).left:=nil;
  1971. end;
  1972. end
  1973. else
  1974. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1975. result:=hpt;
  1976. goto errorexit;
  1977. end;
  1978. {$ifdef dummy}
  1979. { Calling a message method directly ? }
  1980. if assigned(procdefinition) and
  1981. (po_containsself in procdefinition.procoptions) then
  1982. message(cg_e_cannot_call_message_direct);
  1983. {$endif}
  1984. { ensure that the result type is set }
  1985. if not restypeset then
  1986. resulttype:=procdefinition.rettype
  1987. else
  1988. resulttype:=restype;
  1989. { modify the exit code, in case of special cases }
  1990. if (not is_void(resulttype.def)) then
  1991. begin
  1992. if paramanager.ret_in_reg(resulttype.def) then
  1993. begin
  1994. { wide- and ansistrings are returned in EAX }
  1995. { but they are imm. moved to a memory location }
  1996. if is_widestring(resulttype.def) or
  1997. is_ansistring(resulttype.def) then
  1998. begin
  1999. { we use ansistrings so no fast exit here }
  2000. if assigned(procinfo) then
  2001. procinfo.no_fast_exit:=true;
  2002. end;
  2003. end;
  2004. end;
  2005. { constructors return their current class type, not the type where the
  2006. constructor is declared, this can be different because of inheritance }
  2007. if (procdefinition.proctypeoption=potype_constructor) then
  2008. begin
  2009. if assigned(methodpointer) and
  2010. assigned(methodpointer.resulttype.def) and
  2011. (methodpointer.resulttype.def.deftype=classrefdef) then
  2012. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  2013. end;
  2014. { flag all callparanodes that belong to the varargs }
  2015. if (po_varargs in procdefinition.procoptions) then
  2016. begin
  2017. pt:=tcallparanode(left);
  2018. i:=paralength;
  2019. while (i>procdefinition.maxparacount) do
  2020. begin
  2021. include(tcallparanode(pt).flags,nf_varargs_para);
  2022. pt:=tcallparanode(pt.right);
  2023. dec(i);
  2024. end;
  2025. end;
  2026. { insert type conversions }
  2027. if assigned(left) then
  2028. begin
  2029. aktcallprocdef:=procdefinition;
  2030. tcallparanode(left).insert_typeconv(tparaitem(procdefinition.Para.first),true);
  2031. end;
  2032. errorexit:
  2033. { Reset some settings back }
  2034. if assigned(procs) then
  2035. dispose(procs);
  2036. aktcallprocdef:=oldcallprocdef;
  2037. end;
  2038. {$endif}
  2039. function tcallnode.pass_1 : tnode;
  2040. var
  2041. inlinecode : tnode;
  2042. inlined : boolean;
  2043. {$ifdef m68k}
  2044. regi : tregister;
  2045. {$endif}
  2046. method_must_be_valid : boolean;
  2047. label
  2048. errorexit;
  2049. begin
  2050. { the default is nothing to return }
  2051. location.loc:=LOC_INVALID;
  2052. result:=nil;
  2053. inlined:=false;
  2054. inlinecode := nil;
  2055. { work trough all parameters to get the register requirements }
  2056. if assigned(left) then
  2057. tcallparanode(left).det_registers;
  2058. { return node }
  2059. if assigned(funcretrefnode) then
  2060. firstpass(funcretrefnode);
  2061. if assigned(procdefinition) and
  2062. (procdefinition.proccalloption=pocall_inline) then
  2063. begin
  2064. inlinecode:=right;
  2065. if assigned(inlinecode) then
  2066. inlined:=true;
  2067. right:=nil;
  2068. end;
  2069. { procedure variable ? }
  2070. if assigned(right) then
  2071. begin
  2072. firstpass(right);
  2073. { procedure does a call }
  2074. if not (block_type in [bt_const,bt_type]) then
  2075. procinfo.flags:=procinfo.flags or pi_do_call;
  2076. rg.incrementregisterpushed(all_registers);
  2077. end
  2078. else
  2079. { not a procedure variable }
  2080. begin
  2081. { calc the correture value for the register }
  2082. { handle predefined procedures }
  2083. if (procdefinition.proccalloption=pocall_inline) then
  2084. begin
  2085. if assigned(methodpointer) then
  2086. CGMessage(cg_e_unable_inline_object_methods);
  2087. if assigned(right) and (right.nodetype<>procinlinen) then
  2088. CGMessage(cg_e_unable_inline_procvar);
  2089. { nodetype:=procinlinen; }
  2090. if not assigned(right) then
  2091. begin
  2092. if assigned(tprocdef(procdefinition).code) then
  2093. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  2094. else
  2095. CGMessage(cg_e_no_code_for_inline_stored);
  2096. if assigned(inlinecode) then
  2097. begin
  2098. { consider it has not inlined if called
  2099. again inside the args }
  2100. procdefinition.proccalloption:=pocall_fpccall;
  2101. firstpass(inlinecode);
  2102. inlined:=true;
  2103. end;
  2104. end;
  2105. end
  2106. else
  2107. begin
  2108. if not (block_type in [bt_const,bt_type]) then
  2109. procinfo.flags:=procinfo.flags or pi_do_call;
  2110. end;
  2111. { It doesn't hurt to calculate it already though :) (JM) }
  2112. rg.incrementregisterpushed(tprocdef(procdefinition).usedregisters);
  2113. end;
  2114. { get a register for the return value }
  2115. if (not is_void(resulttype.def)) then
  2116. begin
  2117. if paramanager.ret_in_param(resulttype.def) then
  2118. begin
  2119. location.loc:=LOC_CREFERENCE;
  2120. end
  2121. else
  2122. { ansi/widestrings must be registered, so we can dispose them }
  2123. if is_ansistring(resulttype.def) or
  2124. is_widestring(resulttype.def) then
  2125. begin
  2126. location.loc:=LOC_CREFERENCE;
  2127. registers32:=1;
  2128. end
  2129. else
  2130. { we have only to handle the result if it is used }
  2131. if (nf_return_value_used in flags) then
  2132. begin
  2133. case resulttype.def.deftype of
  2134. enumdef,
  2135. orddef :
  2136. begin
  2137. if (procdefinition.proctypeoption=potype_constructor) then
  2138. begin
  2139. if assigned(methodpointer) and
  2140. (methodpointer.resulttype.def.deftype=classrefdef) then
  2141. begin
  2142. location.loc:=LOC_REGISTER;
  2143. registers32:=1;
  2144. end
  2145. else
  2146. location.loc:=LOC_FLAGS;
  2147. end
  2148. else
  2149. begin
  2150. location.loc:=LOC_REGISTER;
  2151. if is_64bitint(resulttype.def) then
  2152. registers32:=2
  2153. else
  2154. registers32:=1;
  2155. end;
  2156. end;
  2157. floatdef :
  2158. begin
  2159. location.loc:=LOC_FPUREGISTER;
  2160. {$ifdef m68k}
  2161. if (cs_fp_emulation in aktmoduleswitches) or
  2162. (tfloatdef(resulttype.def).typ=s32real) then
  2163. registers32:=1
  2164. else
  2165. registersfpu:=1;
  2166. {$else not m68k}
  2167. registersfpu:=1;
  2168. {$endif not m68k}
  2169. end;
  2170. else
  2171. begin
  2172. location.loc:=LOC_REGISTER;
  2173. registers32:=1;
  2174. end;
  2175. end;
  2176. end;
  2177. end;
  2178. { a fpu can be used in any procedure !! }
  2179. {$ifdef i386}
  2180. registersfpu:=procdefinition.fpu_used;
  2181. {$endif i386}
  2182. { if this is a call to a method calc the registers }
  2183. if (methodpointer<>nil) then
  2184. begin
  2185. case methodpointer.nodetype of
  2186. { but only, if this is not a supporting node }
  2187. typen: ;
  2188. { we need one register for new return value PM }
  2189. hnewn : if registers32=0 then
  2190. registers32:=1;
  2191. else
  2192. begin
  2193. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  2194. assigned(symtableproc) and (symtableproc.symtabletype=withsymtable) and
  2195. not twithsymtable(symtableproc).direct_with then
  2196. begin
  2197. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2198. end; { Is accepted by Delphi !! }
  2199. { this is not a good reason to accept it in FPC if we produce
  2200. wrong code for it !!! (PM) }
  2201. { R.Assign is not a constructor !!! }
  2202. { but for R^.Assign, R must be valid !! }
  2203. if (procdefinition.proctypeoption=potype_constructor) or
  2204. ((methodpointer.nodetype=loadn) and
  2205. ((methodpointer.resulttype.def.deftype=classrefdef) or
  2206. ((methodpointer.resulttype.def.deftype=objectdef) and
  2207. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  2208. )
  2209. )
  2210. ) then
  2211. method_must_be_valid:=false
  2212. else
  2213. method_must_be_valid:=true;
  2214. firstpass(methodpointer);
  2215. set_varstate(methodpointer,method_must_be_valid);
  2216. { The object is already used ven if it is called once }
  2217. if (methodpointer.nodetype=loadn) and
  2218. (tloadnode(methodpointer).symtableentry.typ=varsym) then
  2219. tvarsym(tloadnode(methodpointer).symtableentry).varstate:=vs_used;
  2220. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2221. registers32:=max(methodpointer.registers32,registers32);
  2222. {$ifdef SUPPORT_MMX }
  2223. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2224. {$endif SUPPORT_MMX}
  2225. end;
  2226. end;
  2227. end;
  2228. if inlined then
  2229. right:=inlinecode;
  2230. { determine the registers of the procedure variable }
  2231. { is this OK for inlined procs also ?? (PM) }
  2232. if assigned(right) then
  2233. begin
  2234. registersfpu:=max(right.registersfpu,registersfpu);
  2235. registers32:=max(right.registers32,registers32);
  2236. {$ifdef SUPPORT_MMX}
  2237. registersmmx:=max(right.registersmmx,registersmmx);
  2238. {$endif SUPPORT_MMX}
  2239. end;
  2240. { determine the registers of the procedure }
  2241. if assigned(left) then
  2242. begin
  2243. registersfpu:=max(left.registersfpu,registersfpu);
  2244. registers32:=max(left.registers32,registers32);
  2245. {$ifdef SUPPORT_MMX}
  2246. registersmmx:=max(left.registersmmx,registersmmx);
  2247. {$endif SUPPORT_MMX}
  2248. end;
  2249. errorexit:
  2250. if inlined then
  2251. procdefinition.proccalloption:=pocall_inline;
  2252. end;
  2253. {$ifdef state_tracking}
  2254. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2255. var hp:Tcallparanode;
  2256. value:Tnode;
  2257. begin
  2258. track_state_pass:=false;
  2259. hp:=Tcallparanode(left);
  2260. while assigned(hp) do
  2261. begin
  2262. if left.track_state_pass(exec_known) then
  2263. begin
  2264. left.resulttype.def:=nil;
  2265. do_resulttypepass(left);
  2266. end;
  2267. value:=aktstate.find_fact(hp.left);
  2268. if value<>nil then
  2269. begin
  2270. track_state_pass:=true;
  2271. hp.left.destroy;
  2272. hp.left:=value.getcopy;
  2273. do_resulttypepass(hp.left);
  2274. end;
  2275. hp:=Tcallparanode(hp.right);
  2276. end;
  2277. end;
  2278. {$endif}
  2279. function tcallnode.docompare(p: tnode): boolean;
  2280. begin
  2281. docompare :=
  2282. inherited docompare(p) and
  2283. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2284. (symtableproc = tcallnode(p).symtableproc) and
  2285. (procdefinition = tcallnode(p).procdefinition) and
  2286. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2287. ((restypeset and tcallnode(p).restypeset and
  2288. (is_equal(restype.def,tcallnode(p).restype.def))) or
  2289. (not restypeset and not tcallnode(p).restypeset));
  2290. end;
  2291. {****************************************************************************
  2292. TPROCINLINENODE
  2293. ****************************************************************************}
  2294. constructor tprocinlinenode.create(p:tprocdef);
  2295. begin
  2296. inherited create(procinlinen);
  2297. inlineprocdef:=p;
  2298. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2299. para_offset:=0;
  2300. para_size:=0;
  2301. { copy inlinetree }
  2302. if assigned(p.code) then
  2303. inlinetree:=p.code.getcopy
  2304. else
  2305. inlinetree:=nil;
  2306. end;
  2307. destructor tprocinlinenode.destroy;
  2308. begin
  2309. if assigned(inlinetree) then
  2310. inlinetree.free;
  2311. inherited destroy;
  2312. end;
  2313. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2314. begin
  2315. inherited ppuload(t,ppufile);
  2316. inlineprocdef:=tprocdef(ppufile.getderef);
  2317. inlinetree:=ppuloadnode(ppufile);
  2318. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2319. para_offset:=0;
  2320. para_size:=0;
  2321. end;
  2322. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2323. begin
  2324. inherited ppuwrite(ppufile);
  2325. ppufile.putderef(inlineprocdef);
  2326. ppuwritenode(ppufile,inlinetree);
  2327. end;
  2328. procedure tprocinlinenode.derefimpl;
  2329. begin
  2330. inherited derefimpl;
  2331. if assigned(inlinetree) then
  2332. inlinetree.derefimpl;
  2333. resolvedef(pointer(inlineprocdef));
  2334. end;
  2335. function tprocinlinenode.getcopy : tnode;
  2336. var
  2337. n : tprocinlinenode;
  2338. begin
  2339. n:=tprocinlinenode(inherited getcopy);
  2340. n.inlineprocdef:=inlineprocdef;
  2341. if assigned(inlinetree) then
  2342. n.inlinetree:=inlinetree.getcopy
  2343. else
  2344. n.inlinetree:=nil;
  2345. n.retoffset:=retoffset;
  2346. n.para_offset:=para_offset;
  2347. n.para_size:=para_size;
  2348. getcopy:=n;
  2349. end;
  2350. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2351. begin
  2352. end;
  2353. function tprocinlinenode.det_resulttype : tnode;
  2354. begin
  2355. resulttype:=inlineprocdef.rettype;
  2356. { retrieve info from inlineprocdef }
  2357. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2358. para_offset:=0;
  2359. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2360. if paramanager.ret_in_param(inlineprocdef.rettype.def) then
  2361. inc(para_size,POINTER_SIZE);
  2362. result:=nil;
  2363. end;
  2364. function tprocinlinenode.pass_1 : tnode;
  2365. begin
  2366. firstpass(inlinetree);
  2367. registers32:=inlinetree.registers32;
  2368. registersfpu:=inlinetree.registersfpu;
  2369. {$ifdef SUPPORT_MMX}
  2370. registersmmx:=inlinetree.registersmmx;
  2371. {$endif SUPPORT_MMX}
  2372. result:=nil;
  2373. end;
  2374. function tprocinlinenode.docompare(p: tnode): boolean;
  2375. begin
  2376. docompare :=
  2377. inherited docompare(p) and
  2378. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2379. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2380. end;
  2381. begin
  2382. ccallnode:=tcallnode;
  2383. ccallparanode:=tcallparanode;
  2384. cprocinlinenode:=tprocinlinenode;
  2385. end.
  2386. {
  2387. $Log$
  2388. Revision 1.91 2002-09-01 12:14:15 peter
  2389. * remove debug line
  2390. * containself methods can be called directly
  2391. Revision 1.90 2002/09/01 08:01:16 daniel
  2392. * Removed sets from Tcallnode.det_resulttype
  2393. + Added read/write notifications of variables. These will be usefull
  2394. for providing information for several optimizations. For example
  2395. the value of the loop variable of a for loop does matter is the
  2396. variable is read after the for loop, but if it's no longer used
  2397. or written, it doesn't matter and this can be used to optimize
  2398. the loop code generation.
  2399. Revision 1.89 2002/08/23 16:13:16 peter
  2400. * also firstpass funcretrefnode if available. This was breaking the
  2401. asnode compilerproc code
  2402. Revision 1.88 2002/08/20 10:31:26 daniel
  2403. * Tcallnode.det_resulttype rewritten
  2404. Revision 1.87 2002/08/19 19:36:42 peter
  2405. * More fixes for cross unit inlining, all tnodes are now implemented
  2406. * Moved pocall_internconst to po_internconst because it is not a
  2407. calling type at all and it conflicted when inlining of these small
  2408. functions was requested
  2409. Revision 1.86 2002/08/17 22:09:44 florian
  2410. * result type handling in tcgcal.pass_2 overhauled
  2411. * better tnode.dowrite
  2412. * some ppc stuff fixed
  2413. Revision 1.85 2002/08/17 09:23:34 florian
  2414. * first part of procinfo rewrite
  2415. Revision 1.84 2002/08/16 14:24:57 carl
  2416. * issameref() to test if two references are the same (then emit no opcodes)
  2417. + ret_in_reg to replace ret_in_acc
  2418. (fix some register allocation bugs at the same time)
  2419. + save_std_register now has an extra parameter which is the
  2420. usedinproc registers
  2421. Revision 1.83 2002/07/20 11:57:53 florian
  2422. * types.pas renamed to defbase.pas because D6 contains a types
  2423. unit so this would conflicts if D6 programms are compiled
  2424. + Willamette/SSE2 instructions to assembler added
  2425. Revision 1.82 2002/07/19 11:41:35 daniel
  2426. * State tracker work
  2427. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2428. allows the state tracker to change while nodes automatically into
  2429. repeat nodes.
  2430. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2431. 'not(a>b)' is optimized into 'a<=b'.
  2432. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2433. by removing the notn and later switchting the true and falselabels. The
  2434. same is done with 'repeat until not a'.
  2435. Revision 1.81 2002/07/15 18:03:14 florian
  2436. * readded removed changes
  2437. Revision 1.79 2002/07/11 14:41:27 florian
  2438. * start of the new generic parameter handling
  2439. Revision 1.80 2002/07/14 18:00:43 daniel
  2440. + Added the beginning of a state tracker. This will track the values of
  2441. variables through procedures and optimize things away.
  2442. Revision 1.78 2002/07/04 20:43:00 florian
  2443. * first x86-64 patches
  2444. Revision 1.77 2002/07/01 16:23:52 peter
  2445. * cg64 patch
  2446. * basics for currency
  2447. * asnode updates for class and interface (not finished)
  2448. Revision 1.76 2002/05/18 13:34:09 peter
  2449. * readded missing revisions
  2450. Revision 1.75 2002/05/16 19:46:37 carl
  2451. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2452. + try to fix temp allocation (still in ifdef)
  2453. + generic constructor calls
  2454. + start of tassembler / tmodulebase class cleanup
  2455. Revision 1.73 2002/05/12 16:53:06 peter
  2456. * moved entry and exitcode to ncgutil and cgobj
  2457. * foreach gets extra argument for passing local data to the
  2458. iterator function
  2459. * -CR checks also class typecasts at runtime by changing them
  2460. into as
  2461. * fixed compiler to cycle with the -CR option
  2462. * fixed stabs with elf writer, finally the global variables can
  2463. be watched
  2464. * removed a lot of routines from cga unit and replaced them by
  2465. calls to cgobj
  2466. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2467. u32bit then the other is typecasted also to u32bit without giving
  2468. a rangecheck warning/error.
  2469. * fixed pascal calling method with reversing also the high tree in
  2470. the parast, detected by tcalcst3 test
  2471. Revision 1.72 2002/04/25 20:16:38 peter
  2472. * moved more routines from cga/n386util
  2473. Revision 1.71 2002/04/20 21:32:23 carl
  2474. + generic FPC_CHECKPOINTER
  2475. + first parameter offset in stack now portable
  2476. * rename some constants
  2477. + move some cpu stuff to other units
  2478. - remove unused constents
  2479. * fix stacksize for some targets
  2480. * fix generic size problems which depend now on EXTEND_SIZE constant
  2481. Revision 1.70 2002/04/16 16:09:08 peter
  2482. * allow passing the address of a procedure to a formal parameter
  2483. in delphi mode
  2484. Revision 1.69 2002/04/15 19:44:19 peter
  2485. * fixed stackcheck that would be called recursively when a stack
  2486. error was found
  2487. * generic changeregsize(reg,size) for i386 register resizing
  2488. * removed some more routines from cga unit
  2489. * fixed returnvalue handling
  2490. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  2491. Revision 1.68 2002/04/15 18:57:22 carl
  2492. + target_info.size_of_pointer -> POINTER_SIZE
  2493. Revision 1.67 2002/04/02 17:11:28 peter
  2494. * tlocation,treference update
  2495. * LOC_CONSTANT added for better constant handling
  2496. * secondadd splitted in multiple routines
  2497. * location_force_reg added for loading a location to a register
  2498. of a specified size
  2499. * secondassignment parses now first the right and then the left node
  2500. (this is compatible with Kylix). This saves a lot of push/pop especially
  2501. with string operations
  2502. * adapted some routines to use the new cg methods
  2503. Revision 1.66 2002/03/31 20:26:33 jonas
  2504. + a_loadfpu_* and a_loadmm_* methods in tcg
  2505. * register allocation is now handled by a class and is mostly processor
  2506. independent (+rgobj.pas and i386/rgcpu.pas)
  2507. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2508. * some small improvements and fixes to the optimizer
  2509. * some register allocation fixes
  2510. * some fpuvaroffset fixes in the unary minus node
  2511. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2512. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2513. also better optimizable)
  2514. * fixed and optimized register saving/restoring for new/dispose nodes
  2515. * LOC_FPU locations now also require their "register" field to be set to
  2516. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2517. - list field removed of the tnode class because it's not used currently
  2518. and can cause hard-to-find bugs
  2519. Revision 1.65 2002/03/30 23:02:42 carl
  2520. * avoid crash with inline routines
  2521. Revision 1.64 2002/01/24 18:25:48 peter
  2522. * implicit result variable generation for assembler routines
  2523. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2524. Revision 1.63 2002/01/24 12:33:52 jonas
  2525. * adapted ranges of native types to int64 (e.g. high cardinal is no
  2526. longer longint($ffffffff), but just $fffffff in psystem)
  2527. * small additional fix in 64bit rangecheck code generation for 32 bit
  2528. processors
  2529. * adaption of ranges required the matching talgorithm used for selecting
  2530. which overloaded procedure to call to be adapted. It should now always
  2531. select the closest match for ordinal parameters.
  2532. + inttostr(qword) in sysstr.inc/sysstrh.inc
  2533. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  2534. fixes were required to be able to add them)
  2535. * is_in_limit() moved from ncal to types unit, should always be used
  2536. instead of direct comparisons of low/high values of orddefs because
  2537. qword is a special case
  2538. Revision 1.62 2002/01/19 11:57:05 peter
  2539. * fixed path appending for lib
  2540. }