ncal.pas 107 KB

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