ncal.pas 113 KB

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