ncal.pas 106 KB

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