ncal.pas 107 KB

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