ncal.pas 102 KB

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