ncal.pas 107 KB

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