ncal.pas 111 KB

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