ncal.pas 108 KB

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