ncal.pas 102 KB

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