ncal.pas 113 KB

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