ncal.pas 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818
  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(aktprocdef) 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.paratyp = vs_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(aktprocdef) 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(aktprocdef) 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 (currpara.paratyp<>vs_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.paratyp=vs_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 (currpara.paratyp<>vs_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.paratyp=vs_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.paratyp=vs_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 (currpara.paratyp<>vs_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. resulttype:=procdefinition.rettype
  1724. else
  1725. resulttype:=restype;
  1726. { modify the exit code, in case of special cases }
  1727. if (not is_void(resulttype.def)) then
  1728. begin
  1729. if paramanager.ret_in_reg(resulttype.def,procdefinition.proccalloption) then
  1730. begin
  1731. { wide- and ansistrings are returned in EAX }
  1732. { but they are imm. moved to a memory location }
  1733. if is_widestring(resulttype.def) or
  1734. is_ansistring(resulttype.def) then
  1735. begin
  1736. { we use ansistrings so no fast exit here }
  1737. if assigned(procinfo) then
  1738. procinfo.no_fast_exit:=true;
  1739. end;
  1740. end;
  1741. end;
  1742. { constructors return their current class type, not the type where the
  1743. constructor is declared, this can be different because of inheritance }
  1744. if (procdefinition.proctypeoption=potype_constructor) then
  1745. begin
  1746. if assigned(methodpointer) and
  1747. assigned(methodpointer.resulttype.def) and
  1748. (methodpointer.resulttype.def.deftype=classrefdef) then
  1749. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  1750. end;
  1751. if assigned(methodpointer) then
  1752. begin
  1753. resulttypepass(methodpointer);
  1754. { direct call to inherited abstract method, then we
  1755. can already give a error in the compiler instead
  1756. of a runtime error }
  1757. if (methodpointer.nodetype=typen) and
  1758. (po_abstractmethod in procdefinition.procoptions) then
  1759. CGMessage(cg_e_cant_call_abstract_method);
  1760. { if an inherited con- or destructor should be }
  1761. { called in a con- or destructor then a warning }
  1762. { will be made }
  1763. { con- and destructors need a pointer to the vmt }
  1764. if (methodpointer.nodetype=typen) and
  1765. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1766. is_object(methodpointer.resulttype.def) and
  1767. not(aktprocdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1768. CGMessage(cg_w_member_cd_call_from_method);
  1769. if not(methodpointer.nodetype in [typen,hnewn]) then
  1770. begin
  1771. hpt:=methodpointer;
  1772. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1773. hpt:=tunarynode(hpt).left;
  1774. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1775. assigned(symtableproc) and
  1776. (symtableproc.symtabletype=withsymtable) and
  1777. (not twithsymtable(symtableproc).direct_with) then
  1778. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1779. { R.Init then R will be initialized by the constructor,
  1780. Also allow it for simple loads }
  1781. if (procdefinition.proctypeoption=potype_constructor) or
  1782. ((hpt.nodetype=loadn) and
  1783. (
  1784. (methodpointer.resulttype.def.deftype=classrefdef) or
  1785. (
  1786. (methodpointer.resulttype.def.deftype=objectdef) and
  1787. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1788. )
  1789. )
  1790. ) then
  1791. method_must_be_valid:=false
  1792. else
  1793. method_must_be_valid:=true;
  1794. set_varstate(methodpointer,method_must_be_valid);
  1795. { The object is already used if it is called once }
  1796. if (hpt.nodetype=loadn) and
  1797. (tloadnode(hpt).symtableentry.typ=varsym) then
  1798. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  1799. end;
  1800. end;
  1801. { bind paraitems to the callparanodes and insert hidden parameters }
  1802. aktcallprocdef:=procdefinition;
  1803. bind_paraitem;
  1804. { insert type conversions for parameters }
  1805. if assigned(left) then
  1806. tcallparanode(left).insert_typeconv(true);
  1807. errorexit:
  1808. aktcallprocdef:=oldcallprocdef;
  1809. end;
  1810. {$ifdef callparatemp}
  1811. function tree_contains_function_call(var n: tnode): foreachnoderesult;
  1812. begin
  1813. result := fen_false;
  1814. if n.nodetype = calln then
  1815. { stop when we encounter a call node }
  1816. result := fen_norecurse_true;
  1817. end;
  1818. function tcallnode.extract_functioncall_paras: tblocknode;
  1819. var
  1820. curpara: tcallparanode;
  1821. newblock: tblocknode;
  1822. newstatement: tstatementnode;
  1823. temp: ttempcreatenode;
  1824. foundcall: boolean;
  1825. begin
  1826. foundcall := false;
  1827. curpara := tcallparanode(left);
  1828. if assigned(curpara) then
  1829. curpara := tcallparanode(curpara.right);
  1830. newblock := nil;
  1831. while assigned(curpara) do
  1832. begin
  1833. if foreachnodestatic(curpara.left,@tree_contains_function_call) then
  1834. begin
  1835. if (not foundcall) then
  1836. begin
  1837. foundcall := true;
  1838. newblock := internalstatements(newstatement,false);
  1839. end;
  1840. temp := ctempcreatenode.create(curpara.left.resulttype,curpara.left.resulttype.def.size,true);
  1841. addstatement(newstatement,temp);
  1842. resulttypepass(newstatement);
  1843. addstatement(newstatement,
  1844. cassignmentnode.create(ctemprefnode.create(temp),curpara.left));
  1845. resulttypepass(newstatement);
  1846. { after the assignment, turn the temp into a non-persistent one, so }
  1847. { that it will be freed once it's used as parameter }
  1848. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1849. resulttypepass(newstatement);
  1850. curpara.left := ctemprefnode.create(temp);
  1851. { the para's themselves are "resulttypepassed" in in tcallnode.pass_1 }
  1852. end;
  1853. curpara := tcallparanode(curpara.right);
  1854. end;
  1855. result := newblock;
  1856. end;
  1857. {$endif callparatemp}
  1858. function tcallnode.pass_1 : tnode;
  1859. var
  1860. inlinecode : tnode;
  1861. inlined : boolean;
  1862. {$ifdef m68k}
  1863. regi : tregister;
  1864. {$endif}
  1865. {$ifdef callparatemp}
  1866. callparatemps, newblock: tblocknode;
  1867. statement: tstatementnode;
  1868. paras, oldright, newcall: tnode;
  1869. {$endif callparatemp}
  1870. label
  1871. errorexit;
  1872. begin
  1873. result:=nil;
  1874. inlined:=false;
  1875. inlinecode := nil;
  1876. {$ifdef callparatemp}
  1877. callparatemps := extract_functioncall_paras;
  1878. {$endif callparatemp}
  1879. { work trough all parameters to get the register requirements }
  1880. if assigned(left) then
  1881. tcallparanode(left).det_registers;
  1882. { function result node }
  1883. if assigned(funcretnode) then
  1884. firstpass(funcretnode);
  1885. if assigned(procdefinition) and
  1886. (procdefinition.proccalloption=pocall_inline) then
  1887. begin
  1888. inlinecode:=right;
  1889. if assigned(inlinecode) then
  1890. inlined:=true;
  1891. right:=nil;
  1892. end;
  1893. { procedure variable ? }
  1894. if assigned(right) then
  1895. begin
  1896. firstpass(right);
  1897. { procedure does a call }
  1898. if not (block_type in [bt_const,bt_type]) then
  1899. procinfo.flags:=procinfo.flags or pi_do_call;
  1900. rg.incrementintregisterpushed(all_intregisters);
  1901. rg.incrementotherregisterpushed(all_registers);
  1902. end
  1903. else
  1904. { not a procedure variable }
  1905. begin
  1906. { calc the correture value for the register }
  1907. { handle predefined procedures }
  1908. if (procdefinition.proccalloption=pocall_inline) then
  1909. begin
  1910. if assigned(methodpointer) then
  1911. CGMessage(cg_e_unable_inline_object_methods);
  1912. if assigned(right) and (right.nodetype<>procinlinen) then
  1913. CGMessage(cg_e_unable_inline_procvar);
  1914. if not assigned(inlinecode) then
  1915. begin
  1916. if assigned(tprocdef(procdefinition).code) then
  1917. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  1918. else
  1919. CGMessage(cg_e_no_code_for_inline_stored);
  1920. if assigned(inlinecode) then
  1921. begin
  1922. { consider it has not inlined if called
  1923. again inside the args }
  1924. procdefinition.proccalloption:=pocall_fpccall;
  1925. firstpass(inlinecode);
  1926. inlined:=true;
  1927. end;
  1928. end;
  1929. end
  1930. else
  1931. begin
  1932. if not (block_type in [bt_const,bt_type]) then
  1933. procinfo.flags:=procinfo.flags or pi_do_call;
  1934. end;
  1935. { It doesn't hurt to calculate it already though :) (JM) }
  1936. rg.incrementintregisterpushed(tprocdef(procdefinition).usedintregisters);
  1937. rg.incrementotherregisterpushed(tprocdef(procdefinition).usedotherregisters);
  1938. end;
  1939. { get a register for the return value }
  1940. if (not is_void(resulttype.def)) then
  1941. begin
  1942. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1943. begin
  1944. expectloc:=LOC_REFERENCE;
  1945. end
  1946. else
  1947. { for win32 records returned in EDX:EAX, we
  1948. move them to memory after ... }
  1949. if (resulttype.def.deftype=recorddef) then
  1950. begin
  1951. expectloc:=LOC_CREFERENCE;
  1952. end
  1953. else
  1954. { ansi/widestrings must be registered, so we can dispose them }
  1955. if is_ansistring(resulttype.def) or
  1956. is_widestring(resulttype.def) then
  1957. begin
  1958. expectloc:=LOC_CREFERENCE;
  1959. registers32:=1;
  1960. end
  1961. else
  1962. { we have only to handle the result if it is used }
  1963. if (nf_return_value_used in flags) then
  1964. begin
  1965. case resulttype.def.deftype of
  1966. enumdef,
  1967. orddef :
  1968. begin
  1969. if (procdefinition.proctypeoption=potype_constructor) then
  1970. begin
  1971. if assigned(methodpointer) and
  1972. (methodpointer.resulttype.def.deftype=classrefdef) then
  1973. begin
  1974. expectloc:=LOC_REGISTER;
  1975. registers32:=1;
  1976. end
  1977. else
  1978. expectloc:=LOC_FLAGS;
  1979. end
  1980. else
  1981. begin
  1982. expectloc:=LOC_REGISTER;
  1983. if is_64bit(resulttype.def) then
  1984. registers32:=2
  1985. else
  1986. registers32:=1;
  1987. end;
  1988. end;
  1989. floatdef :
  1990. begin
  1991. expectloc:=LOC_FPUREGISTER;
  1992. {$ifdef cpufpemu}
  1993. if (cs_fp_emulation in aktmoduleswitches) then
  1994. registers32:=1
  1995. else
  1996. {$endif cpufpemu}
  1997. {$ifdef m68k}
  1998. if (tfloatdef(resulttype.def).typ=s32real) then
  1999. registers32:=1
  2000. else
  2001. {$endif m68k}
  2002. registersfpu:=1;
  2003. end;
  2004. else
  2005. begin
  2006. expectloc:=LOC_REGISTER;
  2007. registers32:=1;
  2008. end;
  2009. end;
  2010. end
  2011. else
  2012. expectloc:=LOC_VOID;
  2013. end
  2014. else
  2015. expectloc:=LOC_VOID;
  2016. {$ifdef m68k}
  2017. { we need one more address register for virtual calls on m68k }
  2018. if (po_virtualmethod in procdefinition.procoptions) then
  2019. inc(registers32);
  2020. {$endif m68k}
  2021. { a fpu can be used in any procedure !! }
  2022. {$ifdef i386}
  2023. registersfpu:=procdefinition.fpu_used;
  2024. {$endif i386}
  2025. { if this is a call to a method calc the registers }
  2026. if (methodpointer<>nil) then
  2027. begin
  2028. if methodpointer.nodetype<>typen then
  2029. firstpass(methodpointer);
  2030. { if we are calling the constructor }
  2031. if procdefinition.proctypeoption in [potype_constructor] then
  2032. verifyabstractcalls;
  2033. case methodpointer.nodetype of
  2034. { but only, if this is not a supporting node }
  2035. typen: ;
  2036. { we need one register for new return value PM }
  2037. hnewn : if registers32=0 then
  2038. registers32:=1;
  2039. else
  2040. begin
  2041. { this is not a good reason to accept it in FPC if we produce
  2042. wrong code for it !!! (PM) }
  2043. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2044. registers32:=max(methodpointer.registers32,registers32);
  2045. {$ifdef SUPPORT_MMX }
  2046. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2047. {$endif SUPPORT_MMX}
  2048. end;
  2049. end;
  2050. end;
  2051. if inlined then
  2052. right:=inlinecode;
  2053. { determine the registers of the procedure variable }
  2054. { is this OK for inlined procs also ?? (PM) }
  2055. if assigned(right) then
  2056. begin
  2057. registersfpu:=max(right.registersfpu,registersfpu);
  2058. registers32:=max(right.registers32,registers32);
  2059. {$ifdef SUPPORT_MMX}
  2060. registersmmx:=max(right.registersmmx,registersmmx);
  2061. {$endif SUPPORT_MMX}
  2062. end;
  2063. { determine the registers of the procedure }
  2064. if assigned(left) then
  2065. begin
  2066. registersfpu:=max(left.registersfpu,registersfpu);
  2067. registers32:=max(left.registers32,registers32);
  2068. {$ifdef SUPPORT_MMX}
  2069. registersmmx:=max(left.registersmmx,registersmmx);
  2070. {$endif SUPPORT_MMX}
  2071. end;
  2072. {$ifdef callparatemp}
  2073. if (callparatemps <> nil) then
  2074. begin
  2075. { we have to replace the callnode with a blocknode. firstpass will }
  2076. { free the original call node. Avoid copying all subnodes though }
  2077. paras := left;
  2078. oldright := right;
  2079. left := nil;
  2080. right := nil;
  2081. newcall := self.getcopy;
  2082. tcallnode(newcall).left := paras;
  2083. tcallnode(newcall).right := oldright;
  2084. newblock := internalstatements(statement,false);
  2085. addstatement(statement,callparatemps);
  2086. { add the copy of the call node after the callparatemps block }
  2087. { and return that. The last statement of a bocknode determines }
  2088. { the resulttype & location of the block -> ok. Working with a }
  2089. { new block is easier than going to the end of the callparatemps }
  2090. { block (JM) }
  2091. addstatement(statement,newcall);
  2092. result := newblock;
  2093. { set to nil so we can free this one in case of an errorexit }
  2094. callparatemps := nil;
  2095. end;
  2096. {$endif callparatemp}
  2097. errorexit:
  2098. if inlined then
  2099. procdefinition.proccalloption:=pocall_inline;
  2100. {$ifdef callparatemp}
  2101. if assigned(callparatemps) then
  2102. callparatemps.free;
  2103. {$endif callparatemp}
  2104. end;
  2105. {$ifdef state_tracking}
  2106. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2107. var hp:Tcallparanode;
  2108. value:Tnode;
  2109. begin
  2110. track_state_pass:=false;
  2111. hp:=Tcallparanode(left);
  2112. while assigned(hp) do
  2113. begin
  2114. if left.track_state_pass(exec_known) then
  2115. begin
  2116. left.resulttype.def:=nil;
  2117. do_resulttypepass(left);
  2118. end;
  2119. value:=aktstate.find_fact(hp.left);
  2120. if value<>nil then
  2121. begin
  2122. track_state_pass:=true;
  2123. hp.left.destroy;
  2124. hp.left:=value.getcopy;
  2125. do_resulttypepass(hp.left);
  2126. end;
  2127. hp:=Tcallparanode(hp.right);
  2128. end;
  2129. end;
  2130. {$endif}
  2131. function tcallnode.docompare(p: tnode): boolean;
  2132. begin
  2133. docompare :=
  2134. inherited docompare(p) and
  2135. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2136. (procdefinition = tcallnode(p).procdefinition) and
  2137. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2138. ((restypeset and tcallnode(p).restypeset and
  2139. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2140. (not restypeset and not tcallnode(p).restypeset));
  2141. end;
  2142. procedure tcallnode.printnodedata(var t:text);
  2143. begin
  2144. if assigned(procdefinition) and
  2145. (procdefinition.deftype=procdef) then
  2146. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2147. else
  2148. writeln(t,printnodeindention,'proc = ',symtableprocentry.name);
  2149. printnode(t,methodpointer);
  2150. printnode(t,right);
  2151. printnode(t,left);
  2152. end;
  2153. {****************************************************************************
  2154. TPROCINLINENODE
  2155. ****************************************************************************}
  2156. constructor tprocinlinenode.create(p:tprocdef);
  2157. begin
  2158. inherited create(procinlinen);
  2159. inlineprocdef:=p;
  2160. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2161. para_offset:=0;
  2162. para_size:=0;
  2163. { copy inlinetree }
  2164. if assigned(p.code) then
  2165. inlinetree:=p.code.getcopy
  2166. else
  2167. inlinetree:=nil;
  2168. end;
  2169. destructor tprocinlinenode.destroy;
  2170. begin
  2171. if assigned(inlinetree) then
  2172. inlinetree.free;
  2173. inherited destroy;
  2174. end;
  2175. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2176. begin
  2177. inherited ppuload(t,ppufile);
  2178. inlineprocdef:=tprocdef(ppufile.getderef);
  2179. inlinetree:=ppuloadnode(ppufile);
  2180. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2181. para_offset:=0;
  2182. para_size:=0;
  2183. end;
  2184. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2185. begin
  2186. inherited ppuwrite(ppufile);
  2187. ppufile.putderef(inlineprocdef);
  2188. ppuwritenode(ppufile,inlinetree);
  2189. end;
  2190. procedure tprocinlinenode.derefimpl;
  2191. begin
  2192. inherited derefimpl;
  2193. if assigned(inlinetree) then
  2194. inlinetree.derefimpl;
  2195. resolvedef(pointer(inlineprocdef));
  2196. end;
  2197. function tprocinlinenode.getcopy : tnode;
  2198. var
  2199. n : tprocinlinenode;
  2200. begin
  2201. n:=tprocinlinenode(inherited getcopy);
  2202. n.inlineprocdef:=inlineprocdef;
  2203. if assigned(inlinetree) then
  2204. n.inlinetree:=inlinetree.getcopy
  2205. else
  2206. n.inlinetree:=nil;
  2207. n.retoffset:=retoffset;
  2208. n.para_offset:=para_offset;
  2209. n.para_size:=para_size;
  2210. getcopy:=n;
  2211. end;
  2212. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2213. begin
  2214. end;
  2215. function tprocinlinenode.det_resulttype : tnode;
  2216. var
  2217. storesymtablelevel : longint;
  2218. storeparasymtable,
  2219. storelocalsymtable : tsymtabletype;
  2220. oldprocdef : tprocdef;
  2221. oldprocinfo : tprocinfo;
  2222. oldinlining_procedure : boolean;
  2223. begin
  2224. result:=nil;
  2225. oldinlining_procedure:=inlining_procedure;
  2226. oldprocdef:=aktprocdef;
  2227. oldprocinfo:=procinfo;
  2228. { we're inlining a procedure }
  2229. inlining_procedure:=true;
  2230. aktprocdef:=inlineprocdef;
  2231. { clone procinfo, but not the asmlists }
  2232. procinfo:=tprocinfo(cprocinfo.newinstance);
  2233. move(pointer(oldprocinfo)^,pointer(procinfo)^,cprocinfo.InstanceSize);
  2234. procinfo.aktentrycode:=nil;
  2235. procinfo.aktexitcode:=nil;
  2236. procinfo.aktproccode:=nil;
  2237. procinfo.aktlocaldata:=nil;
  2238. { set new procinfo }
  2239. procinfo.return_offset:=retoffset;
  2240. procinfo.para_offset:=para_offset;
  2241. procinfo.no_fast_exit:=false;
  2242. { set it to the same lexical level }
  2243. storesymtablelevel:=aktprocdef.localst.symtablelevel;
  2244. storelocalsymtable:=aktprocdef.localst.symtabletype;
  2245. storeparasymtable:=aktprocdef.parast.symtabletype;
  2246. aktprocdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  2247. aktprocdef.localst.symtabletype:=inlinelocalsymtable;
  2248. aktprocdef.parast.symtabletype:=inlineparasymtable;
  2249. { pass inlinetree }
  2250. resulttypepass(inlinetree);
  2251. resulttype:=inlineprocdef.rettype;
  2252. { retrieve info from inlineprocdef }
  2253. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2254. para_offset:=0;
  2255. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2256. if paramanager.ret_in_param(inlineprocdef.rettype.def,inlineprocdef.proccalloption) then
  2257. inc(para_size,POINTER_SIZE);
  2258. { restore procinfo }
  2259. procinfo.free;
  2260. procinfo:=oldprocinfo;
  2261. { restore symtable }
  2262. aktprocdef.localst.symtablelevel:=storesymtablelevel;
  2263. aktprocdef.localst.symtabletype:=storelocalsymtable;
  2264. aktprocdef.parast.symtabletype:=storeparasymtable;
  2265. { restore }
  2266. aktprocdef:=oldprocdef;
  2267. inlining_procedure:=oldinlining_procedure;
  2268. end;
  2269. function tprocinlinenode.pass_1 : tnode;
  2270. begin
  2271. firstpass(inlinetree);
  2272. registers32:=inlinetree.registers32;
  2273. registersfpu:=inlinetree.registersfpu;
  2274. {$ifdef SUPPORT_MMX}
  2275. registersmmx:=inlinetree.registersmmx;
  2276. {$endif SUPPORT_MMX}
  2277. result:=nil;
  2278. end;
  2279. function tprocinlinenode.docompare(p: tnode): boolean;
  2280. begin
  2281. docompare :=
  2282. inherited docompare(p) and
  2283. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2284. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2285. end;
  2286. begin
  2287. ccallnode:=tcallnode;
  2288. ccallparanode:=tcallparanode;
  2289. cprocinlinenode:=tprocinlinenode;
  2290. end.
  2291. {
  2292. $Log$
  2293. Revision 1.144 2003-04-25 20:59:33 peter
  2294. * removed funcretn,funcretsym, function result is now in varsym
  2295. and aliases for result and function name are added using absolutesym
  2296. * vs_hidden parameter for funcret passed in parameter
  2297. * vs_hidden fixes
  2298. * writenode changed to printnode and released from extdebug
  2299. * -vp option added to generate a tree.log with the nodetree
  2300. * nicer printnode for statements, callnode
  2301. Revision 1.143 2002/04/25 20:15:39 florian
  2302. * block nodes within expressions shouldn't release the used registers,
  2303. fixed using a flag till the new rg is ready
  2304. Revision 1.142 2003/04/23 20:16:04 peter
  2305. + added currency support based on int64
  2306. + is_64bit for use in cg units instead of is_64bitint
  2307. * removed cgmessage from n386add, replace with internalerrors
  2308. Revision 1.141 2003/04/23 13:21:06 peter
  2309. * fix warning for calling constructor inside constructor
  2310. Revision 1.140 2003/04/23 12:35:34 florian
  2311. * fixed several issues with powerpc
  2312. + applied a patch from Jonas for nested function calls (PowerPC only)
  2313. * ...
  2314. Revision 1.139 2003/04/22 23:50:22 peter
  2315. * firstpass uses expectloc
  2316. * checks if there are differences between the expectloc and
  2317. location.loc from secondpass in EXTDEBUG
  2318. Revision 1.138 2003/04/22 09:53:33 peter
  2319. * fix insert_typeconv to handle new varargs which don't have a
  2320. paraitem set
  2321. Revision 1.137 2003/04/11 16:02:05 peter
  2322. * don't firstpass typen
  2323. Revision 1.136 2003/04/11 15:51:04 peter
  2324. * support subscript,vec for setting methodpointer varstate
  2325. Revision 1.135 2003/04/10 17:57:52 peter
  2326. * vs_hidden released
  2327. Revision 1.134 2003/04/07 11:58:22 jonas
  2328. * more vs_invisible fixes
  2329. Revision 1.133 2003/04/07 10:40:21 jonas
  2330. * fixed VS_HIDDEN for high parameter so it works again
  2331. Revision 1.132 2003/04/04 15:38:56 peter
  2332. * moved generic code from n386cal to ncgcal, i386 now also
  2333. uses the generic ncgcal
  2334. Revision 1.131 2003/03/17 18:54:23 peter
  2335. * fix missing self setting for method to procvar conversion in
  2336. tp_procvar mode
  2337. Revision 1.130 2003/03/17 16:54:41 peter
  2338. * support DefaultHandler and anonymous inheritance fixed
  2339. for message methods
  2340. Revision 1.129 2003/03/17 15:54:22 peter
  2341. * store symoptions also for procdef
  2342. * check symoptions (private,public) when calculating possible
  2343. overload candidates
  2344. Revision 1.128 2003/02/19 22:00:14 daniel
  2345. * Code generator converted to new register notation
  2346. - Horribily outdated todo.txt removed
  2347. Revision 1.127 2003/01/16 22:13:52 peter
  2348. * convert_l3 convertlevel added. This level is used for conversions
  2349. where information can be lost like converting widestring->ansistring
  2350. or dword->byte
  2351. Revision 1.126 2003/01/15 01:44:32 peter
  2352. * merged methodpointer fixes from 1.0.x
  2353. Revision 1.125 2003/01/12 17:52:07 peter
  2354. * only check for auto inherited in objectsymtable
  2355. Revision 1.124 2003/01/09 21:45:46 peter
  2356. * extended information about overloaded candidates when compiled
  2357. with EXTDEBUG
  2358. Revision 1.123 2002/12/26 18:24:33 jonas
  2359. * fixed check for whether or not a high parameter was already generated
  2360. * no type checking/conversions for invisible parameters
  2361. Revision 1.122 2002/12/15 22:50:00 florian
  2362. + some stuff for the new hidden parameter handling added
  2363. Revision 1.121 2002/12/15 21:34:15 peter
  2364. * give sign difference between ordinals a small penalty. This is
  2365. needed to get word->[longword|longint] working
  2366. Revision 1.120 2002/12/15 21:30:12 florian
  2367. * tcallnode.paraitem introduced, all references to defcoll removed
  2368. Revision 1.119 2002/12/15 20:59:58 peter
  2369. * fix crash with default parameters
  2370. Revision 1.118 2002/12/15 11:26:02 peter
  2371. * ignore vs_hidden parameters when choosing overloaded proc
  2372. Revision 1.117 2002/12/11 22:42:28 peter
  2373. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2374. the old code. The new code collects the information about possible
  2375. candidates only once resultting in much less calls to type compare
  2376. routines
  2377. Revision 1.116 2002/12/07 14:27:07 carl
  2378. * 3% memory optimization
  2379. * changed some types
  2380. + added type checking with different size for call node and for
  2381. parameters
  2382. Revision 1.115 2002/12/06 17:51:10 peter
  2383. * merged cdecl and array fixes
  2384. Revision 1.114 2002/12/06 16:56:58 peter
  2385. * only compile cs_fp_emulation support when cpufpuemu is defined
  2386. * define cpufpuemu for m68k only
  2387. Revision 1.113 2002/11/27 20:04:38 peter
  2388. * cdecl array of const fixes
  2389. Revision 1.112 2002/11/27 15:33:46 peter
  2390. * the never ending story of tp procvar hacks
  2391. Revision 1.111 2002/11/27 02:31:17 peter
  2392. * fixed inlinetree parsing in det_resulttype
  2393. Revision 1.110 2002/11/25 18:43:32 carl
  2394. - removed the invalid if <> checking (Delphi is strange on this)
  2395. + implemented abstract warning on instance creation of class with
  2396. abstract methods.
  2397. * some error message cleanups
  2398. Revision 1.109 2002/11/25 17:43:17 peter
  2399. * splitted defbase in defutil,symutil,defcmp
  2400. * merged isconvertable and is_equal into compare_defs(_ext)
  2401. * made operator search faster by walking the list only once
  2402. Revision 1.108 2002/11/18 17:31:54 peter
  2403. * pass proccalloption to ret_in_xxx and push_xxx functions
  2404. Revision 1.107 2002/11/15 01:58:50 peter
  2405. * merged changes from 1.0.7 up to 04-11
  2406. - -V option for generating bug report tracing
  2407. - more tracing for option parsing
  2408. - errors for cdecl and high()
  2409. - win32 import stabs
  2410. - win32 records<=8 are returned in eax:edx (turned off by default)
  2411. - heaptrc update
  2412. - more info for temp management in .s file with EXTDEBUG
  2413. Revision 1.106 2002/10/14 18:20:30 carl
  2414. * var parameter checking for classes and interfaces in Delphi mode
  2415. Revision 1.105 2002/10/06 21:02:17 peter
  2416. * fixed limit checking for qword
  2417. Revision 1.104 2002/10/05 15:15:45 peter
  2418. * Write unknwon compiler proc using Comment and only in Extdebug
  2419. Revision 1.103 2002/10/05 12:43:25 carl
  2420. * fixes for Delphi 6 compilation
  2421. (warning : Some features do not work under Delphi)
  2422. Revision 1.102 2002/10/05 00:48:57 peter
  2423. * support inherited; support for overload as it is handled by
  2424. delphi. This is only for delphi mode as it is working is
  2425. undocumented and hard to predict what is done
  2426. Revision 1.101 2002/09/16 14:11:12 peter
  2427. * add argument to equal_paras() to support default values or not
  2428. Revision 1.100 2002/09/15 17:49:59 peter
  2429. * don't have strict var parameter checking for procedures in the
  2430. system unit
  2431. Revision 1.99 2002/09/09 19:30:34 peter
  2432. * don't allow convertable parameters for var and out parameters in
  2433. delphi and tp mode
  2434. Revision 1.98 2002/09/07 15:25:02 peter
  2435. * old logs removed and tabs fixed
  2436. Revision 1.97 2002/09/07 12:16:05 carl
  2437. * second part bug report 1996 fix, testrange in cordconstnode
  2438. only called if option is set (also make parsing a tiny faster)
  2439. Revision 1.96 2002/09/05 14:53:41 peter
  2440. * fixed old callnode.det_resulttype code
  2441. * old ncal code is default again
  2442. Revision 1.95 2002/09/03 21:32:49 daniel
  2443. * Small bugfix for procdef selection
  2444. Revision 1.94 2002/09/03 19:27:22 daniel
  2445. * Activated new ncal code
  2446. Revision 1.93 2002/09/03 16:26:26 daniel
  2447. * Make Tprocdef.defs protected
  2448. Revision 1.92 2002/09/01 13:28:37 daniel
  2449. - write_access fields removed in favor of a flag
  2450. Revision 1.91 2002/09/01 12:14:15 peter
  2451. * remove debug line
  2452. * containself methods can be called directly
  2453. Revision 1.90 2002/09/01 08:01:16 daniel
  2454. * Removed sets from Tcallnode.det_resulttype
  2455. + Added read/write notifications of variables. These will be usefull
  2456. for providing information for several optimizations. For example
  2457. the value of the loop variable of a for loop does matter is the
  2458. variable is read after the for loop, but if it's no longer used
  2459. or written, it doesn't matter and this can be used to optimize
  2460. the loop code generation.
  2461. Revision 1.89 2002/08/23 16:13:16 peter
  2462. * also firstpass funcretrefnode if available. This was breaking the
  2463. asnode compilerproc code
  2464. Revision 1.88 2002/08/20 10:31:26 daniel
  2465. * Tcallnode.det_resulttype rewritten
  2466. Revision 1.87 2002/08/19 19:36:42 peter
  2467. * More fixes for cross unit inlining, all tnodes are now implemented
  2468. * Moved pocall_internconst to po_internconst because it is not a
  2469. calling type at all and it conflicted when inlining of these small
  2470. functions was requested
  2471. Revision 1.86 2002/08/17 22:09:44 florian
  2472. * result type handling in tcgcal.pass_2 overhauled
  2473. * better tnode.dowrite
  2474. * some ppc stuff fixed
  2475. Revision 1.85 2002/08/17 09:23:34 florian
  2476. * first part of procinfo rewrite
  2477. Revision 1.84 2002/08/16 14:24:57 carl
  2478. * issameref() to test if two references are the same (then emit no opcodes)
  2479. + ret_in_reg to replace ret_in_acc
  2480. (fix some register allocation bugs at the same time)
  2481. + save_std_register now has an extra parameter which is the
  2482. usedinproc registers
  2483. Revision 1.83 2002/07/20 11:57:53 florian
  2484. * types.pas renamed to defbase.pas because D6 contains a types
  2485. unit so this would conflicts if D6 programms are compiled
  2486. + Willamette/SSE2 instructions to assembler added
  2487. Revision 1.82 2002/07/19 11:41:35 daniel
  2488. * State tracker work
  2489. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2490. allows the state tracker to change while nodes automatically into
  2491. repeat nodes.
  2492. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2493. 'not(a>b)' is optimized into 'a<=b'.
  2494. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2495. by removing the notn and later switchting the true and falselabels. The
  2496. same is done with 'repeat until not a'.
  2497. Revision 1.81 2002/07/15 18:03:14 florian
  2498. * readded removed changes
  2499. Revision 1.79 2002/07/11 14:41:27 florian
  2500. * start of the new generic parameter handling
  2501. Revision 1.80 2002/07/14 18:00:43 daniel
  2502. + Added the beginning of a state tracker. This will track the values of
  2503. variables through procedures and optimize things away.
  2504. Revision 1.78 2002/07/04 20:43:00 florian
  2505. * first x86-64 patches
  2506. }