ncal.pas 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085
  1. {
  2. This file implements the node for sub procedure calling.
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,cclasses,
  22. globtype,
  23. paramgr,parabase,
  24. node,nbas,nutils,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symsym,symdef,symtable;
  29. type
  30. tcallnodeflag = (
  31. cnf_typedefset,
  32. cnf_return_value_used,
  33. cnf_inherited,
  34. cnf_anon_inherited,
  35. cnf_new_call,
  36. cnf_dispose_call,
  37. cnf_member_call, { called with implicit methodpointer tree }
  38. cnf_uses_varargs, { varargs are used in the declaration }
  39. cnf_create_failed { exception thrown in constructor -> don't call beforedestruction }
  40. );
  41. tcallnodeflags = set of tcallnodeflag;
  42. tcallnode = class(tbinarynode)
  43. private
  44. { info for inlining }
  45. inlinelocals: TFPObjectList;
  46. { number of parameters passed from the source, this does not include the hidden parameters }
  47. paralength : smallint;
  48. function gen_self_tree_methodpointer:tnode;
  49. function gen_self_tree:tnode;
  50. function gen_vmt_tree:tnode;
  51. procedure bind_parasym;
  52. { function return node, this is used to pass the data for a
  53. ret_in_param return value }
  54. _funcretnode : tnode;
  55. procedure setfuncretnode(const returnnode: tnode);
  56. procedure convert_carg_array_of_const;
  57. procedure order_parameters;
  58. procedure createinlineparas(var createstatement, deletestatement: tstatementnode);
  59. function replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  60. procedure createlocaltemps(p:TObject;arg:pointer);
  61. function pass1_inline:tnode;
  62. protected
  63. pushedparasize : longint;
  64. public
  65. { the symbol containing the definition of the procedure }
  66. { to call }
  67. symtableprocentry : tprocsym;
  68. symtableprocentryderef : tderef;
  69. { symtable where the entry was found, needed for with support }
  70. symtableproc : TSymtable;
  71. { the definition of the procedure to call }
  72. procdefinition : tabstractprocdef;
  73. procdefinitionderef : tderef;
  74. methodpointerinit,
  75. methodpointerdone : tblocknode;
  76. { tree that contains the pointer to the object for this method }
  77. methodpointer : tnode;
  78. { varargs parasyms }
  79. varargsparas : tvarargsparalist;
  80. { node that specifies where the result should be put for calls }
  81. { that return their result in a parameter }
  82. property funcretnode: tnode read _funcretnode write setfuncretnode;
  83. { separately specified resultdef for some compilerprocs (e.g. }
  84. { you can't have a function with an "array of char" resultdef }
  85. { the RTL) (JM) }
  86. typedef: tdef;
  87. callnodeflags : tcallnodeflags;
  88. { only the processor specific nodes need to override this }
  89. { constructor }
  90. constructor create(l:tnode; v : tprocsym;st : TSymtable; mp: tnode; callflags:tcallnodeflags);virtual;
  91. constructor create_procvar(l,r:tnode);
  92. constructor createintern(const name: string; params: tnode);
  93. constructor createinternres(const name: string; params: tnode; res:tdef);
  94. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  95. destructor destroy;override;
  96. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  97. procedure ppuwrite(ppufile:tcompilerppufile);override;
  98. procedure derefnode;override;
  99. procedure buildderefimpl;override;
  100. procedure derefimpl;override;
  101. function dogetcopy : tnode;override;
  102. { Goes through all symbols in a class and subclasses and calls
  103. verify abstract for each .
  104. }
  105. procedure verifyabstractcalls;
  106. { called for each definition in a class and verifies if a method
  107. is abstract or not, if it is abstract, give out a warning
  108. }
  109. procedure verifyabstract(sym:TObject;arg:pointer);
  110. procedure insertintolist(l : tnodelist);override;
  111. function pass_1 : tnode;override;
  112. function pass_typecheck:tnode;override;
  113. {$ifdef state_tracking}
  114. function track_state_pass(exec_known:boolean):boolean;override;
  115. {$endif state_tracking}
  116. function docompare(p: tnode): boolean; override;
  117. procedure printnodedata(var t:text);override;
  118. function para_count:longint;
  119. function get_load_methodpointer:tnode;
  120. { checks if there are any parameters which end up at the stack, i.e.
  121. which have LOC_REFERENCE and set pi_has_stackparameter if this applies }
  122. procedure check_stack_parameters;
  123. property parameters : tnode read left write left;
  124. private
  125. AbstractMethodsList : TFPHashList;
  126. end;
  127. tcallnodeclass = class of tcallnode;
  128. tcallparaflag = (
  129. cpf_is_colon_para,
  130. cpf_varargs_para { belongs this para to varargs }
  131. );
  132. tcallparaflags = set of tcallparaflag;
  133. tcallparanode = class(ttertiarynode)
  134. public
  135. callparaflags : tcallparaflags;
  136. parasym : tparavarsym;
  137. used_by_callnode : boolean;
  138. { only the processor specific nodes need to override this }
  139. { constructor }
  140. constructor create(expr,next : tnode);virtual;
  141. destructor destroy;override;
  142. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  143. procedure ppuwrite(ppufile:tcompilerppufile);override;
  144. function dogetcopy : tnode;override;
  145. procedure insertintolist(l : tnodelist);override;
  146. procedure get_paratype;
  147. procedure insert_typeconv(do_count : boolean);
  148. procedure det_registers;
  149. procedure firstcallparan;
  150. procedure secondcallparan;virtual;abstract;
  151. function docompare(p: tnode): boolean; override;
  152. procedure printnodetree(var t:text);override;
  153. { returns whether a parameter contains a type conversion from }
  154. { a refcounted into a non-refcounted type }
  155. function contains_unsafe_typeconversion: boolean;
  156. property value : tnode read left write left;
  157. property nextpara : tnode read right write right;
  158. property parametername : tnode read third write third;
  159. end;
  160. tcallparanodeclass = class of tcallparanode;
  161. function reverseparameters(p: tcallparanode): tcallparanode;
  162. function translate_disp_call(selfnode,parametersnode : tnode;methodname : ansistring = '';dispid : longint = 0) : tnode;
  163. var
  164. ccallnode : tcallnodeclass;
  165. ccallparanode : tcallparanodeclass;
  166. { Current callnode, this is needed for having a link
  167. between the callparanodes and the callnode they belong to }
  168. aktcallnode : tcallnode;
  169. implementation
  170. uses
  171. systems,
  172. verbose,globals,
  173. symconst,defutil,defcmp,
  174. htypechk,pass_1,
  175. ncnv,nld,ninl,nadd,ncon,nmem,nset,
  176. procinfo,
  177. cgbase
  178. ;
  179. type
  180. tobjectinfoitem = class(tlinkedlistitem)
  181. objinfo : tobjectdef;
  182. constructor create(def : tobjectdef);
  183. end;
  184. {****************************************************************************
  185. HELPERS
  186. ****************************************************************************}
  187. function reverseparameters(p: tcallparanode): tcallparanode;
  188. var
  189. hp1, hp2: tcallparanode;
  190. begin
  191. hp1:=nil;
  192. while assigned(p) do
  193. begin
  194. { pull out }
  195. hp2:=p;
  196. p:=tcallparanode(p.right);
  197. { pull in }
  198. hp2.right:=hp1;
  199. hp1:=hp2;
  200. end;
  201. reverseparameters:=hp1;
  202. end;
  203. function translate_disp_call(selfnode,parametersnode : tnode;methodname : ansistring = '';dispid : longint = 0) : tnode;
  204. const
  205. DISPATCH_METHOD = $1;
  206. DISPATCH_PROPERTYGET = $2;
  207. DISPATCH_PROPERTYPUT = $4;
  208. DISPATCH_PROPERTYPUTREF = $8;
  209. DISPATCH_CONSTRUCT = $4000;
  210. var
  211. statements : tstatementnode;
  212. result_data,
  213. params : ttempcreatenode;
  214. paramssize : longint;
  215. calldescnode : tdataconstnode;
  216. para : tcallparanode;
  217. currargpos,
  218. namedparacount,
  219. paracount : longint;
  220. assignmenttype,
  221. vardatadef,
  222. pvardatadef : tdef;
  223. dispatchbyref : boolean;
  224. calldesc : packed record
  225. calltype,argcount,namedargcount : byte;
  226. { size of argtypes is unknown at compile time
  227. so this is basically a dummy }
  228. argtypes : array[0..255] of byte;
  229. { argtypes is followed by method name
  230. names of named parameters, each being
  231. a zero terminated string
  232. }
  233. end;
  234. names : ansistring;
  235. dispintfinvoke,
  236. variantdispatch : boolean;
  237. procedure increase_paramssize;
  238. begin
  239. { for now we pass everything by reference
  240. case para.value.resultdef.typ of
  241. variantdef:
  242. inc(paramssize,para.value.resultdef.size);
  243. else
  244. }
  245. inc(paramssize,sizeof(voidpointertype.size ));
  246. {
  247. end;
  248. }
  249. end;
  250. begin
  251. variantdispatch:=selfnode.resultdef.typ=variantdef;
  252. dispintfinvoke:=not(variantdispatch);
  253. result:=internalstatements(statements);
  254. fillchar(calldesc,sizeof(calldesc),0);
  255. { get temp for the result }
  256. result_data:=ctempcreatenode.create(colevarianttype,colevarianttype.size,tt_persistent,true);
  257. addstatement(statements,result_data);
  258. { build parameters }
  259. { first, count and check parameters }
  260. // p2:=reverseparameters(tcallparanode(p2));
  261. para:=tcallparanode(parametersnode);
  262. paracount:=0;
  263. namedparacount:=0;
  264. paramssize:=0;
  265. while assigned(para) do
  266. begin
  267. inc(paracount);
  268. typecheckpass(para.value);
  269. { insert some extra casts }
  270. if is_constintnode(para.value) and not(is_64bitint(para.value.resultdef)) then
  271. begin
  272. para.value:=ctypeconvnode.create_internal(para.value,s32inttype);
  273. typecheckpass(para.value);
  274. end
  275. else if para.value.nodetype=stringconstn then
  276. begin
  277. para.value:=ctypeconvnode.create_internal(para.value,cwidestringtype);
  278. typecheckpass(para.value);
  279. end
  280. { force automatable boolean type }
  281. else if is_boolean(para.value.resultdef) then
  282. begin
  283. para.value:=ctypeconvnode.create_internal(para.value,bool16type);
  284. typecheckpass(para.value);
  285. end
  286. { force automatable float type }
  287. else if is_extended(para.value.resultdef) then
  288. begin
  289. para.value:=ctypeconvnode.create_internal(para.value,s64floattype);
  290. typecheckpass(para.value);
  291. end;
  292. if assigned(para.parametername) then
  293. begin
  294. typecheckpass(para.value);
  295. inc(namedparacount);
  296. end;
  297. if para.value.nodetype<>nothingn then
  298. if not is_automatable(para.value.resultdef) then
  299. CGMessagePos1(para.value.fileinfo,type_e_not_automatable,para.value.resultdef.typename);
  300. { we've to know the parameter size to allocate the temp. space }
  301. increase_paramssize;
  302. para:=tcallparanode(para.nextpara);
  303. end;
  304. calldesc.calltype:=DISPATCH_METHOD;
  305. calldesc.argcount:=paracount;
  306. { allocate space }
  307. params:=ctempcreatenode.create(voidtype,paramssize,tt_persistent,true);
  308. addstatement(statements,params);
  309. calldescnode:=cdataconstnode.create;
  310. if dispintfinvoke then
  311. calldescnode.append(dispid,sizeof(dispid));
  312. { build up parameters and description }
  313. para:=tcallparanode(parametersnode);
  314. currargpos:=0;
  315. paramssize:=0;
  316. names := '';
  317. while assigned(para) do
  318. begin
  319. if assigned(para.parametername) then
  320. begin
  321. if para.parametername.nodetype=stringconstn then
  322. names:=names+tstringconstnode(para.parametername).value_str+#0
  323. else
  324. internalerror(200611041);
  325. end;
  326. dispatchbyref:=para.value.resultdef.typ in [variantdef];
  327. { assign the argument/parameter to the temporary location }
  328. if para.value.nodetype<>nothingn then
  329. if dispatchbyref then
  330. addstatement(statements,cassignmentnode.create(
  331. ctypeconvnode.create_internal(cderefnode.create(caddnode.create(addn,
  332. caddrnode.create(ctemprefnode.create(params)),
  333. cordconstnode.create(paramssize,ptruinttype,false)
  334. )),voidpointertype),
  335. ctypeconvnode.create_internal(caddrnode.create_internal(para.value),voidpointertype)))
  336. else
  337. begin
  338. case para.value.resultdef.size of
  339. 1..4:
  340. assignmenttype:=u32inttype;
  341. 8:
  342. assignmenttype:=u64inttype;
  343. else
  344. internalerror(2007042801);
  345. end;
  346. addstatement(statements,cassignmentnode.create(
  347. ctypeconvnode.create_internal(cderefnode.create(caddnode.create(addn,
  348. caddrnode.create(ctemprefnode.create(params)),
  349. cordconstnode.create(paramssize,ptruinttype,false)
  350. )),assignmenttype),
  351. ctypeconvnode.create_internal(para.value,assignmenttype)));
  352. end;
  353. if is_ansistring(para.value.resultdef) then
  354. calldesc.argtypes[currargpos]:=varStrArg
  355. else
  356. calldesc.argtypes[currargpos]:=para.value.resultdef.getvardef;
  357. if dispatchbyref then
  358. calldesc.argtypes[currargpos]:=calldesc.argtypes[currargpos] or $80;
  359. increase_paramssize;
  360. para.value:=nil;
  361. inc(currargpos);
  362. para:=tcallparanode(para.nextpara);
  363. end;
  364. // typecheckpass(statements);
  365. // printnode(output,statements);
  366. { old argument list skeleton isn't needed anymore }
  367. parametersnode.free;
  368. calldescnode.append(calldesc,3+calldesc.argcount);
  369. pvardatadef:=tpointerdef(search_system_type('PVARDATA').typedef);
  370. if variantdispatch then
  371. begin
  372. methodname:=methodname+#0;
  373. calldescnode.append(pointer(methodname)^,length(methodname));
  374. calldescnode.append(pointer(names)^,length(names));
  375. { actual call }
  376. vardatadef:=trecorddef(search_system_type('TVARDATA').typedef);
  377. addstatement(statements,ccallnode.createintern('fpc_dispinvoke_variant',
  378. { parameters are passed always reverted, i.e. the last comes first }
  379. ccallparanode.create(caddrnode.create(ctemprefnode.create(params)),
  380. ccallparanode.create(caddrnode.create(calldescnode),
  381. ccallparanode.create(ctypeconvnode.create_internal(selfnode,vardatadef),
  382. ccallparanode.create(ctypeconvnode.create_internal(caddrnode.create(
  383. ctemprefnode.create(result_data)
  384. ),pvardatadef),nil)))))
  385. );
  386. end
  387. else
  388. begin
  389. addstatement(statements,ccallnode.createintern('fpc_dispatch_by_id',
  390. { parameters are passed always reverted, i.e. the last comes first }
  391. ccallparanode.create(caddrnode.create(ctemprefnode.create(params)),
  392. ccallparanode.create(caddrnode.create(calldescnode),
  393. ccallparanode.create(ctypeconvnode.create_internal(selfnode,voidpointertype),
  394. ccallparanode.create(ctypeconvnode.create_internal(caddrnode.create(
  395. ctemprefnode.create(result_data)
  396. ),pvardatadef),nil)))))
  397. );
  398. end;
  399. { clean up }
  400. addstatement(statements,ctempdeletenode.create_normal_temp(result_data));
  401. addstatement(statements,ctemprefnode.create(result_data));
  402. end;
  403. procedure maybe_load_para_in_temp(var p:tnode);
  404. function is_simple_node(hp:tnode):boolean;
  405. begin
  406. is_simple_node:=(hp.nodetype in [typen,loadvmtaddrn,loadn,arrayconstructorn]);
  407. end;
  408. var
  409. hp,
  410. loadp,
  411. refp : tnode;
  412. hdef : tdef;
  413. ptemp : ttempcreatenode;
  414. usederef : boolean;
  415. usevoidpointer : boolean;
  416. newinitstatement,
  417. newdonestatement : tstatementnode;
  418. begin
  419. if not assigned(aktcallnode) then
  420. internalerror(200410121);
  421. { Load all complex loads into a temp to prevent
  422. double calls to a function. We can't simply check for a hp.nodetype=calln
  423. }
  424. hp:=p;
  425. while assigned(hp) and
  426. (hp.nodetype=typeconvn) and
  427. (ttypeconvnode(hp).convtype=tc_equal) do
  428. hp:=tunarynode(hp).left;
  429. if assigned(hp) and
  430. not is_simple_node(hp) then
  431. begin
  432. if not assigned(aktcallnode.methodpointerinit) then
  433. begin
  434. aktcallnode.methodpointerinit:=internalstatements(newinitstatement);
  435. aktcallnode.methodpointerdone:=internalstatements(newdonestatement);
  436. end
  437. else
  438. begin
  439. newinitstatement:=laststatement(aktcallnode.methodpointerinit);
  440. newdonestatement:=laststatement(aktcallnode.methodpointerdone);
  441. end;
  442. { temp create }
  443. usederef:=(p.resultdef.typ in [arraydef,recorddef]) or
  444. is_shortstring(p.resultdef) or
  445. is_object(p.resultdef);
  446. { avoid refcount increase }
  447. usevoidpointer:=is_interface(p.resultdef);
  448. if usederef then
  449. hdef:=tpointerdef.create(p.resultdef)
  450. else
  451. hdef:=p.resultdef;
  452. if usevoidpointer then
  453. begin
  454. ptemp:=ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,true);
  455. loadp := ctypeconvnode.create_internal(p,voidpointertype);
  456. refp:=ctypeconvnode.create_internal(ctemprefnode.create(ptemp),hdef);
  457. end
  458. else
  459. begin
  460. ptemp:=ctempcreatenode.create(hdef,hdef.size,tt_persistent,true);
  461. if usederef then
  462. begin
  463. loadp:=caddrnode.create_internal(p);
  464. refp:=cderefnode.create(ctemprefnode.create(ptemp));
  465. end
  466. else
  467. begin
  468. loadp:=p;
  469. refp:=ctemprefnode.create(ptemp)
  470. end
  471. end;
  472. addstatement(newinitstatement,ptemp);
  473. addstatement(newinitstatement,cassignmentnode.create(
  474. ctemprefnode.create(ptemp),
  475. loadp));
  476. { new tree is only a temp reference }
  477. p:=refp;
  478. { temp release. We need to return a reference to the methodpointer
  479. otherwise the conversion from callnode to loadnode can't be done
  480. for the methodpointer unless the loadnode will also get a methodpointerinit and
  481. methodpointerdone node. For the moment we use register as temp and therefor
  482. don't create a temp-leak in the stackframe (PFV) }
  483. { the last statement should return the value as
  484. location and type, this is done be referencing the
  485. temp and converting it first from a persistent temp to
  486. normal temp }
  487. addstatement(newdonestatement,ctempdeletenode.create_normal_temp(ptemp));
  488. if usevoidpointer then
  489. addstatement(newdonestatement,ctypeconvnode.create_internal(
  490. ctemprefnode.create(ptemp),hdef))
  491. else
  492. addstatement(newdonestatement,ctemprefnode.create(ptemp));
  493. { call typecheckpass for new nodes }
  494. typecheckpass(p);
  495. typecheckpass(aktcallnode.methodpointerinit);
  496. typecheckpass(aktcallnode.methodpointerdone);
  497. end;
  498. end;
  499. function gen_high_tree(var p:tnode;paradef:tdef):tnode;
  500. {When passing an array to an open array, or a string to an open string,
  501. some code is needed that generates the high bound of the array. This
  502. function returns a tree containing the nodes for it.}
  503. var
  504. temp: tnode;
  505. len : integer;
  506. loadconst : boolean;
  507. hightree,l,r : tnode;
  508. begin
  509. len:=-1;
  510. loadconst:=true;
  511. hightree:=nil;
  512. case p.resultdef.typ of
  513. arraydef :
  514. begin
  515. if (paradef.typ<>arraydef) then
  516. internalerror(200405241);
  517. { passing a string to an array of char }
  518. if (p.nodetype=stringconstn) and
  519. is_char(tarraydef(paradef).elementdef) then
  520. begin
  521. len:=tstringconstnode(p).len;
  522. if len>0 then
  523. dec(len);
  524. end
  525. else
  526. { handle special case of passing an single array to an array of array }
  527. if compare_defs(tarraydef(paradef).elementdef,p.resultdef,nothingn)>=te_equal then
  528. len:=0
  529. else
  530. begin
  531. { handle via a normal inline in_high_x node }
  532. loadconst:=false;
  533. { slice? }
  534. if (p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=in_slice_x) then
  535. with Tcallparanode(Tinlinenode(p).left) do
  536. begin
  537. {Array slice using slice builtin function.}
  538. l:=Tcallparanode(right).left;
  539. hightree:=caddnode.create(subn,l,genintconstnode(1));
  540. Tcallparanode(right).left:=nil;
  541. {Remove the inline node.}
  542. temp:=p;
  543. p:=left;
  544. Tcallparanode(tinlinenode(temp).left).left:=nil;
  545. temp.free;
  546. typecheckpass(hightree);
  547. end
  548. else if (p.nodetype=vecn) and (Tvecnode(p).right.nodetype=rangen) then
  549. begin
  550. {Array slice using .. operator.}
  551. with Trangenode(Tvecnode(p).right) do
  552. begin
  553. l:=left; {Get lower bound.}
  554. r:=right; {Get upper bound.}
  555. end;
  556. {In the procedure the array range is 0..(upper_bound-lower_bound).}
  557. hightree:=caddnode.create(subn,r,l);
  558. {Replace the rangnode in the tree by its lower_bound, and
  559. dispose the rangenode.}
  560. temp:=Tvecnode(p).right;
  561. Tvecnode(p).right:=l.getcopy;
  562. {Typecheckpass can only be performed *after* the l.getcopy since it
  563. can modify the tree, and l is in the hightree.}
  564. typecheckpass(hightree);
  565. with Trangenode(temp) do
  566. begin
  567. left:=nil;
  568. right:=nil;
  569. end;
  570. temp.free;
  571. {Tree changed from p[l..h] to p[l], recalculate resultdef.}
  572. p.resultdef:=nil;
  573. typecheckpass(p);
  574. end
  575. else
  576. begin
  577. maybe_load_para_in_temp(p);
  578. hightree:=geninlinenode(in_high_x,false,p.getcopy);
  579. typecheckpass(hightree);
  580. { only substract low(array) if it's <> 0 }
  581. temp:=geninlinenode(in_low_x,false,p.getcopy);
  582. typecheckpass(temp);
  583. if (temp.nodetype <> ordconstn) or
  584. (tordconstnode(temp).value <> 0) then
  585. hightree := caddnode.create(subn,hightree,temp)
  586. else
  587. temp.free;
  588. end;
  589. end;
  590. end;
  591. stringdef :
  592. begin
  593. if is_open_string(paradef) then
  594. begin
  595. maybe_load_para_in_temp(p);
  596. { handle via a normal inline in_high_x node }
  597. loadconst := false;
  598. hightree := geninlinenode(in_high_x,false,p.getcopy);
  599. end
  600. else
  601. { handle special case of passing an single string to an array of string }
  602. if compare_defs(tarraydef(paradef).elementdef,p.resultdef,nothingn)>=te_equal then
  603. len:=0
  604. else
  605. { passing a string to an array of char }
  606. if (p.nodetype=stringconstn) and
  607. is_char(tarraydef(paradef).elementdef) then
  608. begin
  609. len:=tstringconstnode(p).len;
  610. if len>0 then
  611. dec(len);
  612. end
  613. else
  614. begin
  615. maybe_load_para_in_temp(p);
  616. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  617. cordconstnode.create(1,sinttype,false));
  618. loadconst:=false;
  619. end;
  620. end;
  621. else
  622. len:=0;
  623. end;
  624. if loadconst then
  625. hightree:=cordconstnode.create(len,sinttype,true)
  626. else
  627. begin
  628. if not assigned(hightree) then
  629. internalerror(200304071);
  630. { Need to use explicit, because it can also be a enum }
  631. hightree:=ctypeconvnode.create_internal(hightree,sinttype);
  632. end;
  633. result:=hightree;
  634. end;
  635. {****************************************************************************
  636. TOBJECTINFOITEM
  637. ****************************************************************************}
  638. constructor tobjectinfoitem.create(def : tobjectdef);
  639. begin
  640. inherited create;
  641. objinfo := def;
  642. end;
  643. {****************************************************************************
  644. TCALLPARANODE
  645. ****************************************************************************}
  646. constructor tcallparanode.create(expr,next : tnode);
  647. begin
  648. inherited create(callparan,expr,next,nil);
  649. if not assigned(expr) then
  650. internalerror(200305091);
  651. expr.fileinfo:=fileinfo;
  652. callparaflags:=[];
  653. end;
  654. destructor tcallparanode.destroy;
  655. begin
  656. { When the node is used by callnode then
  657. we don't destroy left, the callnode takes care of it }
  658. if used_by_callnode then
  659. left:=nil;
  660. inherited destroy;
  661. end;
  662. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  663. begin
  664. inherited ppuload(t,ppufile);
  665. ppufile.getsmallset(callparaflags);
  666. end;
  667. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  668. begin
  669. inherited ppuwrite(ppufile);
  670. ppufile.putsmallset(callparaflags);
  671. end;
  672. function tcallparanode.dogetcopy : tnode;
  673. var
  674. n : tcallparanode;
  675. begin
  676. n:=tcallparanode(inherited dogetcopy);
  677. n.callparaflags:=callparaflags;
  678. n.parasym:=parasym;
  679. result:=n;
  680. end;
  681. procedure tcallparanode.insertintolist(l : tnodelist);
  682. begin
  683. end;
  684. procedure tcallparanode.get_paratype;
  685. var
  686. old_array_constructor : boolean;
  687. begin
  688. inc(parsing_para_level);
  689. if assigned(right) then
  690. tcallparanode(right).get_paratype;
  691. old_array_constructor:=allow_array_constructor;
  692. allow_array_constructor:=true;
  693. typecheckpass(left);
  694. allow_array_constructor:=old_array_constructor;
  695. if codegenerror then
  696. resultdef:=generrordef
  697. else
  698. resultdef:=left.resultdef;
  699. dec(parsing_para_level);
  700. end;
  701. procedure tcallparanode.insert_typeconv(do_count : boolean);
  702. var
  703. olddef : tdef;
  704. hp : tnode;
  705. {$ifdef extdebug}
  706. store_count_ref : boolean;
  707. {$endif def extdebug}
  708. begin
  709. inc(parsing_para_level);
  710. {$ifdef extdebug}
  711. if do_count then
  712. begin
  713. store_count_ref:=count_ref;
  714. count_ref:=true;
  715. end;
  716. {$endif def extdebug}
  717. { Be sure to have the resultdef }
  718. if not assigned(left.resultdef) then
  719. typecheckpass(left);
  720. if (left.nodetype<>nothingn) then
  721. begin
  722. { Convert tp procvars, this is needs to be done
  723. here to make the change permanent. in the overload
  724. choosing the changes are only made temporary }
  725. if (left.resultdef.typ=procvardef) and
  726. (parasym.vardef.typ<>procvardef) then
  727. begin
  728. if maybe_call_procvar(left,true) then
  729. resultdef:=left.resultdef;
  730. end;
  731. { Remove implicitly inserted typecast to pointer for
  732. @procvar in macpas }
  733. if (m_mac_procvar in current_settings.modeswitches) and
  734. (parasym.vardef.typ=procvardef) and
  735. (left.nodetype=typeconvn) and
  736. is_voidpointer(left.resultdef) and
  737. (ttypeconvnode(left).left.nodetype=typeconvn) and
  738. (ttypeconvnode(ttypeconvnode(left).left).convtype=tc_proc_2_procvar) then
  739. begin
  740. hp:=left;
  741. left:=ttypeconvnode(left).left;
  742. ttypeconvnode(hp).left:=nil;
  743. hp.free;
  744. end;
  745. { Handle varargs and hidden paras directly, no typeconvs or }
  746. { pass_typechecking needed }
  747. if (cpf_varargs_para in callparaflags) then
  748. begin
  749. { this should only happen vor C varargs }
  750. { the necessary conversions have already been performed in }
  751. { tarrayconstructornode.insert_typeconvs }
  752. set_varstate(left,vs_read,[vsf_must_be_valid]);
  753. insert_varargstypeconv(left,true);
  754. resultdef:=left.resultdef;
  755. { also update parasym type to get the correct parameter location
  756. for the new types }
  757. parasym.vardef:=left.resultdef;
  758. end
  759. else
  760. if (vo_is_hidden_para in parasym.varoptions) then
  761. begin
  762. set_varstate(left,vs_read,[vsf_must_be_valid]);
  763. resultdef:=left.resultdef;
  764. end
  765. else
  766. begin
  767. { Do we need arrayconstructor -> set conversion, then insert
  768. it here before the arrayconstructor node breaks the tree
  769. with its conversions of enum->ord }
  770. if (left.nodetype=arrayconstructorn) and
  771. (parasym.vardef.typ=setdef) then
  772. inserttypeconv(left,parasym.vardef);
  773. { set some settings needed for arrayconstructor }
  774. if is_array_constructor(left.resultdef) then
  775. begin
  776. if left.nodetype<>arrayconstructorn then
  777. internalerror(200504041);
  778. if is_array_of_const(parasym.vardef) then
  779. begin
  780. { force variant array }
  781. include(left.flags,nf_forcevaria);
  782. end
  783. else
  784. begin
  785. include(left.flags,nf_novariaallowed);
  786. { now that the resultting type is know we can insert the required
  787. typeconvs for the array constructor }
  788. if parasym.vardef.typ=arraydef then
  789. tarrayconstructornode(left).force_type(tarraydef(parasym.vardef).elementdef);
  790. end;
  791. end;
  792. { check if local proc/func is assigned to procvar }
  793. if left.resultdef.typ=procvardef then
  794. test_local_to_procvar(tprocvardef(left.resultdef),parasym.vardef);
  795. { test conversions }
  796. if not(is_shortstring(left.resultdef) and
  797. is_shortstring(parasym.vardef)) and
  798. (parasym.vardef.typ<>formaldef) then
  799. begin
  800. { Process open parameters }
  801. if paramanager.push_high_param(parasym.varspez,parasym.vardef,aktcallnode.procdefinition.proccalloption) then
  802. begin
  803. { insert type conv but hold the ranges of the array }
  804. olddef:=left.resultdef;
  805. inserttypeconv(left,parasym.vardef);
  806. left.resultdef:=olddef;
  807. end
  808. else
  809. begin
  810. check_ranges(left.fileinfo,left,parasym.vardef);
  811. inserttypeconv(left,parasym.vardef);
  812. end;
  813. if codegenerror then
  814. begin
  815. dec(parsing_para_level);
  816. exit;
  817. end;
  818. end;
  819. { check var strings }
  820. if (cs_strict_var_strings in current_settings.localswitches) and
  821. is_shortstring(left.resultdef) and
  822. is_shortstring(parasym.vardef) and
  823. (parasym.varspez in [vs_out,vs_var]) and
  824. not(is_open_string(parasym.vardef)) and
  825. not(equal_defs(left.resultdef,parasym.vardef)) then
  826. begin
  827. current_filepos:=left.fileinfo;
  828. CGMessage(type_e_strict_var_string_violation);
  829. end;
  830. { Handle formal parameters separate }
  831. if (parasym.vardef.typ=formaldef) then
  832. begin
  833. { load procvar if a procedure is passed }
  834. if ((m_tp_procvar in current_settings.modeswitches) or
  835. (m_mac_procvar in current_settings.modeswitches)) and
  836. (left.nodetype=calln) and
  837. (is_void(left.resultdef)) then
  838. load_procvar_from_calln(left);
  839. case parasym.varspez of
  840. vs_var,
  841. vs_out :
  842. begin
  843. if not valid_for_formal_var(left,true) then
  844. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  845. end;
  846. vs_const :
  847. begin
  848. if not valid_for_formal_const(left,true) then
  849. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  850. end;
  851. end;
  852. end
  853. else
  854. begin
  855. { check if the argument is allowed }
  856. if (parasym.varspez in [vs_out,vs_var]) then
  857. valid_for_var(left,true);
  858. end;
  859. if parasym.varspez in [vs_var,vs_out] then
  860. set_unique(left);
  861. { When the address needs to be pushed then the register is
  862. not regable. Exception is when the location is also a var
  863. parameter and we can pass the address transparently }
  864. if (
  865. not(
  866. (vo_is_hidden_para in parasym.varoptions) and
  867. (left.resultdef.typ in [pointerdef,classrefdef])
  868. ) and
  869. paramanager.push_addr_param(parasym.varspez,parasym.vardef,
  870. aktcallnode.procdefinition.proccalloption) and
  871. not(
  872. (left.nodetype=loadn) and
  873. (tloadnode(left).is_addr_param_load)
  874. )
  875. ) then
  876. make_not_regable(left,vr_addr);
  877. if do_count then
  878. begin
  879. case parasym.varspez of
  880. vs_out :
  881. set_varstate(left,vs_readwritten,[]);
  882. vs_var :
  883. set_varstate(left,vs_readwritten,[vsf_must_be_valid,vsf_use_hints]);
  884. else
  885. set_varstate(left,vs_read,[vsf_must_be_valid]);
  886. end;
  887. end;
  888. { must only be done after typeconv PM }
  889. resultdef:=parasym.vardef;
  890. end;
  891. end;
  892. { process next node }
  893. if assigned(right) then
  894. tcallparanode(right).insert_typeconv(do_count);
  895. dec(parsing_para_level);
  896. {$ifdef extdebug}
  897. if do_count then
  898. count_ref:=store_count_ref;
  899. {$endif def extdebug}
  900. end;
  901. procedure tcallparanode.det_registers;
  902. begin
  903. if assigned(right) then
  904. begin
  905. tcallparanode(right).det_registers;
  906. registersint:=right.registersint;
  907. registersfpu:=right.registersfpu;
  908. {$ifdef SUPPORT_MMX}
  909. registersmmx:=right.registersmmx;
  910. {$endif}
  911. end;
  912. firstpass(left);
  913. if left.registersint>registersint then
  914. registersint:=left.registersint;
  915. if left.registersfpu>registersfpu then
  916. registersfpu:=left.registersfpu;
  917. {$ifdef SUPPORT_MMX}
  918. if left.registersmmx>registersmmx then
  919. registersmmx:=left.registersmmx;
  920. {$endif SUPPORT_MMX}
  921. end;
  922. function tcallparanode.contains_unsafe_typeconversion: boolean;
  923. var
  924. n: tnode;
  925. begin
  926. n:=left;
  927. while assigned(n) and
  928. (n.nodetype=typeconvn) do
  929. begin
  930. { look for type conversion nodes which convert a }
  931. { refcounted type into a non-refcounted type }
  932. if (not n.resultdef.needs_inittable or
  933. is_class(n.resultdef)) and
  934. (ttypeconvnode(n).left.resultdef.needs_inittable and
  935. not is_class(ttypeconvnode(n).left.resultdef)) then
  936. begin
  937. result:=true;
  938. exit;
  939. end;
  940. n:=ttypeconvnode(n).left;
  941. end;
  942. result:=false;
  943. end;
  944. procedure tcallparanode.firstcallparan;
  945. begin
  946. if not assigned(left.resultdef) then
  947. get_paratype;
  948. det_registers;
  949. end;
  950. function tcallparanode.docompare(p: tnode): boolean;
  951. begin
  952. docompare :=
  953. inherited docompare(p) and
  954. (callparaflags = tcallparanode(p).callparaflags)
  955. ;
  956. end;
  957. procedure tcallparanode.printnodetree(var t:text);
  958. begin
  959. printnodelist(t);
  960. end;
  961. {****************************************************************************
  962. TCALLNODE
  963. ****************************************************************************}
  964. constructor tcallnode.create(l:tnode;v : tprocsym;st : TSymtable; mp: tnode; callflags:tcallnodeflags);
  965. begin
  966. inherited create(calln,l,nil);
  967. symtableprocentry:=v;
  968. symtableproc:=st;
  969. callnodeflags:=callflags+[cnf_return_value_used];
  970. methodpointer:=mp;
  971. methodpointerinit:=nil;
  972. methodpointerdone:=nil;
  973. procdefinition:=nil;
  974. _funcretnode:=nil;
  975. paralength:=-1;
  976. varargsparas:=nil;
  977. end;
  978. constructor tcallnode.create_procvar(l,r:tnode);
  979. begin
  980. inherited create(calln,l,r);
  981. symtableprocentry:=nil;
  982. symtableproc:=nil;
  983. methodpointer:=nil;
  984. methodpointerinit:=nil;
  985. methodpointerdone:=nil;
  986. procdefinition:=nil;
  987. callnodeflags:=[cnf_return_value_used];
  988. _funcretnode:=nil;
  989. paralength:=-1;
  990. varargsparas:=nil;
  991. end;
  992. constructor tcallnode.createintern(const name: string; params: tnode);
  993. var
  994. srsym: tsym;
  995. begin
  996. srsym := tsym(systemunit.Find(name));
  997. if not assigned(srsym) and
  998. (cs_compilesystem in current_settings.moduleswitches) then
  999. srsym := tsym(systemunit.Find(upper(name)));
  1000. if not assigned(srsym) or
  1001. (srsym.typ<>procsym) then
  1002. Message1(cg_f_unknown_compilerproc,name);
  1003. create(params,tprocsym(srsym),srsym.owner,nil,[]);
  1004. end;
  1005. constructor tcallnode.createinternres(const name: string; params: tnode; res:tdef);
  1006. var
  1007. pd : tprocdef;
  1008. begin
  1009. createintern(name,params);
  1010. typedef := res;
  1011. include(callnodeflags,cnf_typedefset);
  1012. pd:=tprocdef(symtableprocentry.ProcdefList[0]);
  1013. { both the normal and specified resultdef either have to be returned via a }
  1014. { parameter or not, but no mixing (JM) }
  1015. if paramanager.ret_in_param(typedef,pd.proccalloption) xor
  1016. paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  1017. internalerror(200108291);
  1018. end;
  1019. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  1020. var
  1021. pd : tprocdef;
  1022. begin
  1023. createintern(name,params);
  1024. _funcretnode:=returnnode;
  1025. pd:=tprocdef(symtableprocentry.ProcdefList[0]);
  1026. if not paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  1027. internalerror(200204247);
  1028. end;
  1029. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  1030. var
  1031. para: tcallparanode;
  1032. begin
  1033. if assigned(_funcretnode) then
  1034. _funcretnode.free;
  1035. _funcretnode := returnnode;
  1036. { if the resultdef pass hasn't occurred yet, that one will do }
  1037. { everything }
  1038. if assigned(resultdef) then
  1039. begin
  1040. { these are returned as values, but we can optimize their loading }
  1041. { as well }
  1042. if is_ansistring(resultdef) or
  1043. is_widestring(resultdef) then
  1044. exit;
  1045. para := tcallparanode(left);
  1046. while assigned(para) do
  1047. begin
  1048. if (vo_is_hidden_para in para.parasym.varoptions) and
  1049. (vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  1050. begin
  1051. para.left.free;
  1052. para.left := _funcretnode.getcopy;
  1053. exit;
  1054. end;
  1055. para := tcallparanode(para.right);
  1056. end;
  1057. { no hidden resultpara found, error! }
  1058. if not(po_inline in procdefinition.procoptions) then
  1059. internalerror(200306087);
  1060. end;
  1061. end;
  1062. destructor tcallnode.destroy;
  1063. begin
  1064. methodpointer.free;
  1065. methodpointerinit.free;
  1066. methodpointerdone.free;
  1067. _funcretnode.free;
  1068. if assigned(varargsparas) then
  1069. varargsparas.free;
  1070. inherited destroy;
  1071. end;
  1072. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1073. begin
  1074. methodpointerinit:=tblocknode(ppuloadnode(ppufile));
  1075. methodpointer:=ppuloadnode(ppufile);
  1076. methodpointerdone:=tblocknode(ppuloadnode(ppufile));
  1077. _funcretnode:=ppuloadnode(ppufile);
  1078. inherited ppuload(t,ppufile);
  1079. ppufile.getderef(symtableprocentryderef);
  1080. {$warning FIXME: No withsymtable support}
  1081. symtableproc:=nil;
  1082. ppufile.getderef(procdefinitionderef);
  1083. ppufile.getsmallset(callnodeflags);
  1084. end;
  1085. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  1086. begin
  1087. ppuwritenode(ppufile,methodpointerinit);
  1088. ppuwritenode(ppufile,methodpointer);
  1089. ppuwritenode(ppufile,methodpointerdone);
  1090. ppuwritenode(ppufile,_funcretnode);
  1091. inherited ppuwrite(ppufile);
  1092. ppufile.putderef(symtableprocentryderef);
  1093. ppufile.putderef(procdefinitionderef);
  1094. ppufile.putsmallset(callnodeflags);
  1095. end;
  1096. procedure tcallnode.derefnode;
  1097. begin
  1098. if assigned(methodpointerinit) then
  1099. methodpointerinit.derefnode;
  1100. if assigned(methodpointer) then
  1101. methodpointer.derefnode;
  1102. if assigned(methodpointerdone) then
  1103. methodpointerdone.derefnode;
  1104. if assigned(_funcretnode) then
  1105. _funcretnode.derefnode;
  1106. inherited derefnode;
  1107. end;
  1108. procedure tcallnode.buildderefimpl;
  1109. begin
  1110. inherited buildderefimpl;
  1111. symtableprocentryderef.build(symtableprocentry);
  1112. procdefinitionderef.build(procdefinition);
  1113. if assigned(methodpointer) then
  1114. methodpointer.buildderefimpl;
  1115. if assigned(methodpointerinit) then
  1116. methodpointerinit.buildderefimpl;
  1117. if assigned(methodpointerdone) then
  1118. methodpointerdone.buildderefimpl;
  1119. if assigned(_funcretnode) then
  1120. _funcretnode.buildderefimpl;
  1121. end;
  1122. procedure tcallnode.derefimpl;
  1123. var
  1124. pt : tcallparanode;
  1125. i : integer;
  1126. begin
  1127. inherited derefimpl;
  1128. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  1129. if assigned(symtableprocentry) then
  1130. symtableproc:=symtableprocentry.owner;
  1131. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  1132. if assigned(methodpointer) then
  1133. methodpointer.derefimpl;
  1134. if assigned(methodpointerinit) then
  1135. methodpointerinit.derefimpl;
  1136. if assigned(methodpointerdone) then
  1137. methodpointerdone.derefimpl;
  1138. if assigned(_funcretnode) then
  1139. _funcretnode.derefimpl;
  1140. { Connect parasyms }
  1141. pt:=tcallparanode(left);
  1142. while assigned(pt) and
  1143. (cpf_varargs_para in pt.callparaflags) do
  1144. pt:=tcallparanode(pt.right);
  1145. for i:=procdefinition.paras.count-1 downto 0 do
  1146. begin
  1147. if not assigned(pt) then
  1148. internalerror(200311077);
  1149. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  1150. pt:=tcallparanode(pt.right);
  1151. end;
  1152. if assigned(pt) then
  1153. internalerror(200311078);
  1154. end;
  1155. function tcallnode.dogetcopy : tnode;
  1156. var
  1157. n : tcallnode;
  1158. i : integer;
  1159. hp,hpn : tparavarsym;
  1160. oldleft : tnode;
  1161. begin
  1162. { Need to use a hack here to prevent the parameters from being copied.
  1163. The parameters must be copied between methodpointerinit/methodpointerdone because
  1164. the can reference methodpointer }
  1165. oldleft:=left;
  1166. left:=nil;
  1167. n:=tcallnode(inherited dogetcopy);
  1168. left:=oldleft;
  1169. n.symtableprocentry:=symtableprocentry;
  1170. n.symtableproc:=symtableproc;
  1171. n.procdefinition:=procdefinition;
  1172. n.typedef := typedef;
  1173. n.callnodeflags := callnodeflags;
  1174. if assigned(methodpointerinit) then
  1175. n.methodpointerinit:=tblocknode(methodpointerinit.dogetcopy)
  1176. else
  1177. n.methodpointerinit:=nil;
  1178. { methodpointerinit is copied, now references to the temp will also be copied
  1179. correctly. We can now copy the parameters and methodpointer }
  1180. if assigned(left) then
  1181. n.left:=left.dogetcopy
  1182. else
  1183. n.left:=nil;
  1184. if assigned(methodpointer) then
  1185. n.methodpointer:=methodpointer.dogetcopy
  1186. else
  1187. n.methodpointer:=nil;
  1188. if assigned(methodpointerdone) then
  1189. n.methodpointerdone:=tblocknode(methodpointerdone.dogetcopy)
  1190. else
  1191. n.methodpointerdone:=nil;
  1192. if assigned(_funcretnode) then
  1193. n._funcretnode:=_funcretnode.dogetcopy
  1194. else
  1195. n._funcretnode:=nil;
  1196. if assigned(varargsparas) then
  1197. begin
  1198. n.varargsparas:=tvarargsparalist.create(true);
  1199. for i:=0 to varargsparas.count-1 do
  1200. begin
  1201. hp:=tparavarsym(varargsparas[i]);
  1202. hpn:=tparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vardef,[]);
  1203. n.varargsparas.add(hpn);
  1204. end;
  1205. end
  1206. else
  1207. n.varargsparas:=nil;
  1208. result:=n;
  1209. end;
  1210. procedure tcallnode.insertintolist(l : tnodelist);
  1211. begin
  1212. end;
  1213. procedure tcallnode.convert_carg_array_of_const;
  1214. var
  1215. hp : tarrayconstructornode;
  1216. oldleft : tcallparanode;
  1217. begin
  1218. oldleft:=tcallparanode(left);
  1219. if oldleft.left.nodetype<>arrayconstructorn then
  1220. begin
  1221. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resultdef.typename);
  1222. exit;
  1223. end;
  1224. include(callnodeflags,cnf_uses_varargs);
  1225. { Get arrayconstructor node and insert typeconvs }
  1226. hp:=tarrayconstructornode(oldleft.left);
  1227. { Add c args parameters }
  1228. { It could be an empty set }
  1229. if assigned(hp) and
  1230. assigned(hp.left) then
  1231. begin
  1232. while assigned(hp) do
  1233. begin
  1234. left:=ccallparanode.create(hp.left,left);
  1235. { set callparanode resultdef and flags }
  1236. left.resultdef:=hp.left.resultdef;
  1237. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  1238. hp.left:=nil;
  1239. hp:=tarrayconstructornode(hp.right);
  1240. end;
  1241. end;
  1242. { Remove value of old array of const parameter, but keep it
  1243. in the list because it is required for bind_parasym.
  1244. Generate a nothign to keep callparanoed.left valid }
  1245. oldleft.left.free;
  1246. oldleft.left:=cnothingnode.create;
  1247. end;
  1248. procedure tcallnode.verifyabstract(sym:TObject;arg:pointer);
  1249. var
  1250. pd : tprocdef;
  1251. i : longint;
  1252. j : integer;
  1253. hs : string;
  1254. begin
  1255. if (tsym(sym).typ<>procsym) then
  1256. exit;
  1257. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  1258. begin
  1259. pd:=tprocdef(tprocsym(sym).ProcdefList[i]);
  1260. hs:=pd.procsym.name+pd.typename_paras(false);
  1261. j:=AbstractMethodsList.FindIndexOf(hs);
  1262. if j<>-1 then
  1263. AbstractMethodsList[j]:=pd
  1264. else
  1265. AbstractMethodsList.Add(hs,pd);
  1266. end;
  1267. end;
  1268. procedure tcallnode.verifyabstractcalls;
  1269. var
  1270. objectdf : tobjectdef;
  1271. parents : tlinkedlist;
  1272. objectinfo : tobjectinfoitem;
  1273. stritem : TCmdStrListItem;
  1274. pd : tprocdef;
  1275. i : integer;
  1276. first : boolean;
  1277. begin
  1278. objectdf := nil;
  1279. { verify if trying to create an instance of a class which contains
  1280. non-implemented abstract methods }
  1281. { first verify this class type, no class than exit }
  1282. { also, this checking can only be done if the constructor is directly
  1283. called, indirect constructor calls cannot be checked.
  1284. }
  1285. if assigned(methodpointer) and
  1286. not (nf_is_self in methodpointer.flags) then
  1287. begin
  1288. if (methodpointer.resultdef.typ = objectdef) then
  1289. objectdf:=tobjectdef(methodpointer.resultdef)
  1290. else
  1291. if (methodpointer.resultdef.typ = classrefdef) and
  1292. (tclassrefdef(methodpointer.resultdef).pointeddef.typ = objectdef) and
  1293. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  1294. objectdf:=tobjectdef(tclassrefdef(methodpointer.resultdef).pointeddef);
  1295. end;
  1296. if not assigned(objectdf) then
  1297. exit;
  1298. parents := tlinkedlist.create;
  1299. AbstractMethodsList := TFPHashList.create;
  1300. { insert all parents in this class : the first item in the
  1301. list will be the base parent of the class .
  1302. }
  1303. while assigned(objectdf) do
  1304. begin
  1305. objectinfo:=tobjectinfoitem.create(objectdf);
  1306. parents.insert(objectinfo);
  1307. objectdf := objectdf.childof;
  1308. end;
  1309. { now all parents are in the correct order
  1310. insert all abstract methods in the list, and remove
  1311. those which are overriden by parent classes.
  1312. }
  1313. objectinfo:=tobjectinfoitem(parents.first);
  1314. while assigned(objectinfo) do
  1315. begin
  1316. objectdf := objectinfo.objinfo;
  1317. if assigned(objectdf.symtable) then
  1318. objectdf.symtable.SymList.ForEachCall(@verifyabstract,nil);
  1319. objectinfo:=tobjectinfoitem(objectinfo.next);
  1320. end;
  1321. if assigned(parents) then
  1322. parents.free;
  1323. { Finally give out a warning for each abstract method still in the list }
  1324. first:=true;
  1325. for i:=0 to AbstractMethodsList.Count-1 do
  1326. begin
  1327. pd:=tprocdef(AbstractMethodsList[i]);
  1328. if po_abstractmethod in pd.procoptions then
  1329. begin
  1330. if first then
  1331. begin
  1332. Message1(type_w_instance_with_abstract,objectdf.objrealname^);
  1333. first:=false;
  1334. end;
  1335. MessagePos1(pd.fileinfo,sym_h_abstract_method_list,pd.fullprocname(true));
  1336. end;
  1337. end;
  1338. if assigned(AbstractMethodsList) then
  1339. AbstractMethodsList.Free;
  1340. end;
  1341. function tcallnode.gen_self_tree_methodpointer:tnode;
  1342. var
  1343. hsym : tfieldvarsym;
  1344. begin
  1345. { find self field in methodpointer record }
  1346. hsym:=tfieldvarsym(trecorddef(methodpointertype).symtable.Find('self'));
  1347. if not assigned(hsym) then
  1348. internalerror(200305251);
  1349. { Load tmehodpointer(right).self }
  1350. result:=csubscriptnode.create(
  1351. hsym,
  1352. ctypeconvnode.create_internal(right.getcopy,methodpointertype));
  1353. end;
  1354. function tcallnode.gen_self_tree:tnode;
  1355. var
  1356. selftree : tnode;
  1357. begin
  1358. selftree:=nil;
  1359. { inherited }
  1360. if (cnf_inherited in callnodeflags) then
  1361. selftree:=load_self_node
  1362. else
  1363. { constructors }
  1364. if (procdefinition.proctypeoption=potype_constructor) then
  1365. begin
  1366. { push 0 as self when allocation is needed }
  1367. if (methodpointer.resultdef.typ=classrefdef) or
  1368. (cnf_new_call in callnodeflags) then
  1369. selftree:=cpointerconstnode.create(0,voidpointertype)
  1370. else
  1371. begin
  1372. if methodpointer.nodetype=typen then
  1373. selftree:=load_self_node
  1374. else
  1375. selftree:=methodpointer.getcopy;
  1376. end;
  1377. end
  1378. else
  1379. { Calling a static/class method }
  1380. if (po_classmethod in procdefinition.procoptions) or
  1381. (po_staticmethod in procdefinition.procoptions) then
  1382. begin
  1383. if (procdefinition.typ<>procdef) then
  1384. internalerror(200305062);
  1385. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1386. begin
  1387. { we only need the vmt, loading self is not required and there is no
  1388. need to check for typen, because that will always get the
  1389. loadvmtaddrnode added }
  1390. selftree:=methodpointer.getcopy;
  1391. if (methodpointer.resultdef.typ<>classrefdef) or
  1392. (methodpointer.nodetype = typen) then
  1393. selftree:=cloadvmtaddrnode.create(selftree);
  1394. end
  1395. else
  1396. selftree:=cpointerconstnode.create(0,voidpointertype);
  1397. end
  1398. else
  1399. begin
  1400. if methodpointer.nodetype=typen then
  1401. selftree:=load_self_node
  1402. else
  1403. selftree:=methodpointer.getcopy;
  1404. end;
  1405. result:=selftree;
  1406. end;
  1407. function tcallnode.gen_vmt_tree:tnode;
  1408. var
  1409. vmttree : tnode;
  1410. begin
  1411. vmttree:=nil;
  1412. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1413. internalerror(200305051);
  1414. { Handle classes and legacy objects separate to make it
  1415. more maintainable }
  1416. if (methodpointer.resultdef.typ=classrefdef) then
  1417. begin
  1418. if not is_class(tclassrefdef(methodpointer.resultdef).pointeddef) then
  1419. internalerror(200501041);
  1420. { constructor call via classreference => allocate memory }
  1421. if (procdefinition.proctypeoption=potype_constructor) then
  1422. begin
  1423. vmttree:=methodpointer.getcopy;
  1424. { Only a typenode can be passed when it is called with <class of xx>.create }
  1425. if vmttree.nodetype=typen then
  1426. vmttree:=cloadvmtaddrnode.create(vmttree);
  1427. end
  1428. else
  1429. begin
  1430. { Call afterconstruction }
  1431. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1432. end;
  1433. end
  1434. else
  1435. { Class style objects }
  1436. if is_class(methodpointer.resultdef) then
  1437. begin
  1438. { inherited call, no create/destroy }
  1439. if (cnf_inherited in callnodeflags) then
  1440. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1441. else
  1442. { do not create/destroy when called from member function
  1443. without specifying self explicit }
  1444. if (cnf_member_call in callnodeflags) then
  1445. begin
  1446. { destructor: don't release instance, vmt=0
  1447. constructor:
  1448. if called from a constructor in the same class then
  1449. don't call afterconstruction, vmt=0
  1450. else
  1451. call afterconstrution, vmt=1 }
  1452. if (procdefinition.proctypeoption=potype_destructor) then
  1453. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1454. else if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1455. (procdefinition.proctypeoption=potype_constructor) then
  1456. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1457. else
  1458. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1459. end
  1460. else
  1461. { normal call to method like cl1.proc }
  1462. begin
  1463. { destructor:
  1464. if not called from exception block in constructor
  1465. call beforedestruction and release instance, vmt=1
  1466. else
  1467. don't call beforedestruction and release instance, vmt=-1
  1468. constructor:
  1469. if called from a constructor in the same class using self.create then
  1470. don't call afterconstruction, vmt=0
  1471. else
  1472. call afterconstrution, vmt=1 }
  1473. if (procdefinition.proctypeoption=potype_destructor) then
  1474. if not(cnf_create_failed in callnodeflags) then
  1475. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1476. else
  1477. vmttree:=cpointerconstnode.create(TConstPtrUInt(-1),voidpointertype)
  1478. else
  1479. begin
  1480. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  1481. (procdefinition.proctypeoption=potype_constructor) and
  1482. (nf_is_self in methodpointer.flags) then
  1483. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1484. else
  1485. vmttree:=cpointerconstnode.create(1,voidpointertype);
  1486. end;
  1487. end;
  1488. end
  1489. else
  1490. { Old style object }
  1491. begin
  1492. { constructor with extended syntax called from new }
  1493. if (cnf_new_call in callnodeflags) then
  1494. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resultdef))
  1495. else
  1496. { destructor with extended syntax called from dispose }
  1497. if (cnf_dispose_call in callnodeflags) then
  1498. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1499. else
  1500. { inherited call, no create/destroy }
  1501. if (cnf_inherited in callnodeflags) then
  1502. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1503. else
  1504. { do not create/destroy when called from member function
  1505. without specifying self explicit }
  1506. if (cnf_member_call in callnodeflags) then
  1507. begin
  1508. { destructor: don't release instance, vmt=0
  1509. constructor: don't initialize instance, vmt=0 }
  1510. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1511. end
  1512. else
  1513. { normal object call like obj.proc }
  1514. begin
  1515. { destructor: direct call, no dispose, vmt=0
  1516. constructor: initialize object, load vmt }
  1517. if (procdefinition.proctypeoption=potype_constructor) then
  1518. begin
  1519. { old styled inherited call? }
  1520. if (methodpointer.nodetype=typen) then
  1521. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1522. else
  1523. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resultdef))
  1524. end
  1525. else
  1526. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1527. end;
  1528. end;
  1529. result:=vmttree;
  1530. end;
  1531. type
  1532. pcallparanode = ^tcallparanode;
  1533. procedure tcallnode.bind_parasym;
  1534. var
  1535. i : integer;
  1536. pt : tcallparanode;
  1537. oldppt : pcallparanode;
  1538. varargspara,
  1539. currpara : tparavarsym;
  1540. used_by_callnode : boolean;
  1541. hiddentree : tnode;
  1542. newstatement : tstatementnode;
  1543. temp : ttempcreatenode;
  1544. begin
  1545. pt:=tcallparanode(left);
  1546. oldppt:=pcallparanode(@left);
  1547. { flag all callparanodes that belong to the varargs }
  1548. i:=paralength;
  1549. while (i>procdefinition.maxparacount) do
  1550. begin
  1551. include(pt.callparaflags,cpf_varargs_para);
  1552. oldppt:=pcallparanode(@pt.right);
  1553. pt:=tcallparanode(pt.right);
  1554. dec(i);
  1555. end;
  1556. { skip varargs that are inserted by array of const }
  1557. while assigned(pt) and
  1558. (cpf_varargs_para in pt.callparaflags) do
  1559. pt:=tcallparanode(pt.right);
  1560. { process normal parameters and insert hidden parameters }
  1561. for i:=procdefinition.paras.count-1 downto 0 do
  1562. begin
  1563. currpara:=tparavarsym(procdefinition.paras[i]);
  1564. if vo_is_hidden_para in currpara.varoptions then
  1565. begin
  1566. { generate hidden tree }
  1567. used_by_callnode:=false;
  1568. hiddentree:=nil;
  1569. if (vo_is_funcret in currpara.varoptions) then
  1570. begin
  1571. { Generate funcretnode if not specified }
  1572. if assigned(funcretnode) then
  1573. begin
  1574. hiddentree:=funcretnode.getcopy;
  1575. end
  1576. else
  1577. begin
  1578. hiddentree:=internalstatements(newstatement);
  1579. { need to use resultdef instead of procdefinition.returndef,
  1580. because they can be different }
  1581. temp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,false);
  1582. addstatement(newstatement,temp);
  1583. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1584. addstatement(newstatement,ctemprefnode.create(temp));
  1585. end;
  1586. end
  1587. else
  1588. if vo_is_high_para in currpara.varoptions then
  1589. begin
  1590. if not assigned(pt) or
  1591. (i=0) then
  1592. internalerror(200304082);
  1593. { we need the information of the previous parameter }
  1594. hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vardef);
  1595. end
  1596. else
  1597. if vo_is_self in currpara.varoptions then
  1598. begin
  1599. if assigned(right) then
  1600. hiddentree:=gen_self_tree_methodpointer
  1601. else
  1602. hiddentree:=gen_self_tree;
  1603. end
  1604. else
  1605. if vo_is_vmt in currpara.varoptions then
  1606. begin
  1607. hiddentree:=gen_vmt_tree;
  1608. end
  1609. {$if defined(powerpc) or defined(m68k)}
  1610. else
  1611. if vo_is_syscall_lib in currpara.varoptions then
  1612. begin
  1613. { lib parameter has no special type but proccalloptions must be a syscall }
  1614. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1615. end
  1616. {$endif powerpc or m68k}
  1617. else
  1618. if vo_is_parentfp in currpara.varoptions then
  1619. begin
  1620. if not(assigned(procdefinition.owner.defowner)) then
  1621. internalerror(200309287);
  1622. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1623. end;
  1624. { add the hidden parameter }
  1625. if not assigned(hiddentree) then
  1626. internalerror(200304073);
  1627. { Already insert para and let the previous node point to
  1628. this new node }
  1629. pt:=ccallparanode.create(hiddentree,oldppt^);
  1630. pt.used_by_callnode:=used_by_callnode;
  1631. oldppt^:=pt;
  1632. end;
  1633. if not assigned(pt) then
  1634. internalerror(200310052);
  1635. pt.parasym:=currpara;
  1636. oldppt:=pcallparanode(@pt.right);
  1637. pt:=tcallparanode(pt.right);
  1638. end;
  1639. { Create parasyms for varargs, first count the number of varargs paras,
  1640. then insert the parameters with numbering in reverse order. The SortParas
  1641. will set the correct order at the end}
  1642. pt:=tcallparanode(left);
  1643. i:=0;
  1644. while assigned(pt) do
  1645. begin
  1646. if cpf_varargs_para in pt.callparaflags then
  1647. inc(i);
  1648. pt:=tcallparanode(pt.right);
  1649. end;
  1650. if (i>0) then
  1651. begin
  1652. varargsparas:=tvarargsparalist.create;
  1653. pt:=tcallparanode(left);
  1654. while assigned(pt) do
  1655. begin
  1656. if cpf_varargs_para in pt.callparaflags then
  1657. begin
  1658. varargspara:=tparavarsym.create('va'+tostr(i),i,vs_value,pt.resultdef,[]);
  1659. dec(i);
  1660. { varargspara is left-right, use insert
  1661. instead of concat }
  1662. varargsparas.add(varargspara);
  1663. pt.parasym:=varargspara;
  1664. end;
  1665. pt:=tcallparanode(pt.right);
  1666. end;
  1667. varargsparas.sortparas;
  1668. end;
  1669. end;
  1670. function tcallnode.pass_typecheck:tnode;
  1671. var
  1672. candidates : tcallcandidates;
  1673. oldcallnode : tcallnode;
  1674. hpt : tnode;
  1675. pt : tcallparanode;
  1676. lastpara : longint;
  1677. paraidx,
  1678. cand_cnt : integer;
  1679. i : longint;
  1680. is_const : boolean;
  1681. statements : tstatementnode;
  1682. converted_result_data : ttempcreatenode;
  1683. label
  1684. errorexit;
  1685. begin
  1686. result:=nil;
  1687. candidates:=nil;
  1688. oldcallnode:=aktcallnode;
  1689. aktcallnode:=self;
  1690. { determine length of parameter list }
  1691. pt:=tcallparanode(left);
  1692. paralength:=0;
  1693. while assigned(pt) do
  1694. begin
  1695. inc(paralength);
  1696. pt:=tcallparanode(pt.right);
  1697. end;
  1698. { determine the type of the parameters }
  1699. if assigned(left) then
  1700. begin
  1701. tcallparanode(left).get_paratype;
  1702. if codegenerror then
  1703. goto errorexit;
  1704. end;
  1705. if assigned(methodpointer) then
  1706. begin
  1707. typecheckpass(methodpointer);
  1708. maybe_load_para_in_temp(methodpointer);
  1709. end;
  1710. { procedure variable ? }
  1711. if assigned(right) then
  1712. begin
  1713. set_varstate(right,vs_read,[vsf_must_be_valid]);
  1714. typecheckpass(right);
  1715. if codegenerror then
  1716. exit;
  1717. procdefinition:=tabstractprocdef(right.resultdef);
  1718. { Compare parameters from right to left }
  1719. paraidx:=procdefinition.Paras.count-1;
  1720. { Skip default parameters }
  1721. if not(po_varargs in procdefinition.procoptions) then
  1722. begin
  1723. { ignore hidden parameters }
  1724. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1725. dec(paraidx);
  1726. for i:=1 to procdefinition.maxparacount-paralength do
  1727. begin
  1728. if paraidx<0 then
  1729. internalerror(200402261);
  1730. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1731. begin
  1732. CGMessage1(parser_e_wrong_parameter_size,'<Procedure Variable>');
  1733. goto errorexit;
  1734. end;
  1735. dec(paraidx);
  1736. end;
  1737. end;
  1738. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1739. dec(paraidx);
  1740. pt:=tcallparanode(left);
  1741. lastpara:=paralength;
  1742. while (paraidx>=0) and assigned(pt) do
  1743. begin
  1744. { only goto next para if we're out of the varargs }
  1745. if not(po_varargs in procdefinition.procoptions) or
  1746. (lastpara<=procdefinition.maxparacount) then
  1747. begin
  1748. repeat
  1749. dec(paraidx);
  1750. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1751. end;
  1752. pt:=tcallparanode(pt.right);
  1753. dec(lastpara);
  1754. end;
  1755. if assigned(pt) or
  1756. ((paraidx>=0) and
  1757. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  1758. begin
  1759. if assigned(pt) then
  1760. current_filepos:=pt.fileinfo;
  1761. CGMessage1(parser_e_wrong_parameter_size,'<Procedure Variable>');
  1762. goto errorexit;
  1763. end;
  1764. end
  1765. else
  1766. { not a procedure variable }
  1767. begin
  1768. { do we know the procedure to call ? }
  1769. if not(assigned(procdefinition)) then
  1770. begin
  1771. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags),
  1772. { ignore possible private in delphi mode for anon. inherited (FK) }
  1773. (m_delphi in current_settings.modeswitches) and (cnf_anon_inherited in callnodeflags));
  1774. { no procedures found? then there is something wrong
  1775. with the parameter size or the procedures are
  1776. not accessible }
  1777. if candidates.count=0 then
  1778. begin
  1779. { when it's an auto inherited call and there
  1780. is no procedure found, but the procedures
  1781. were defined with overload directive and at
  1782. least two procedures are defined then we ignore
  1783. this inherited by inserting a nothingn. Only
  1784. do this ugly hack in Delphi mode as it looks more
  1785. like a bug. It's also not documented }
  1786. if (m_delphi in current_settings.modeswitches) and
  1787. (cnf_anon_inherited in callnodeflags) and
  1788. (symtableprocentry.owner.symtabletype=ObjectSymtable) and
  1789. (po_overload in tprocdef(symtableprocentry.ProcdefList[0]).procoptions) and
  1790. (symtableprocentry.ProcdefList.Count>=2) then
  1791. result:=cnothingnode.create
  1792. else
  1793. begin
  1794. { in tp mode we can try to convert to procvar if
  1795. there are no parameters specified }
  1796. if not(assigned(left)) and
  1797. not(cnf_inherited in callnodeflags) and
  1798. ((m_tp_procvar in current_settings.modeswitches) or
  1799. (m_mac_procvar in current_settings.modeswitches)) and
  1800. (not assigned(methodpointer) or
  1801. (methodpointer.nodetype <> typen)) then
  1802. begin
  1803. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1804. if assigned(methodpointer) then
  1805. tloadnode(hpt).set_mp(get_load_methodpointer);
  1806. typecheckpass(hpt);
  1807. result:=hpt;
  1808. end
  1809. else
  1810. begin
  1811. if assigned(left) then
  1812. current_filepos:=left.fileinfo;
  1813. CGMessage1(parser_e_wrong_parameter_size,symtableprocentry.realname);
  1814. symtableprocentry.write_parameter_lists(nil);
  1815. end;
  1816. end;
  1817. goto errorexit;
  1818. end;
  1819. { Retrieve information about the candidates }
  1820. candidates.get_information;
  1821. {$ifdef EXTDEBUG}
  1822. { Display info when multiple candidates are found }
  1823. if candidates.count>1 then
  1824. candidates.dump_info(V_Debug);
  1825. {$endif EXTDEBUG}
  1826. { Choose the best candidate and count the number of
  1827. candidates left }
  1828. cand_cnt:=candidates.choose_best(procdefinition,
  1829. assigned(left) and
  1830. not assigned(tcallparanode(left).right) and
  1831. (tcallparanode(left).left.resultdef.typ=variantdef));
  1832. { All parameters are checked, check if there are any
  1833. procedures left }
  1834. if cand_cnt>0 then
  1835. begin
  1836. { Multiple candidates left? }
  1837. if cand_cnt>1 then
  1838. begin
  1839. CGMessage(type_e_cant_choose_overload_function);
  1840. {$ifdef EXTDEBUG}
  1841. candidates.dump_info(V_Hint);
  1842. {$else EXTDEBUG}
  1843. candidates.list(false);
  1844. {$endif EXTDEBUG}
  1845. { we'll just use the first candidate to make the
  1846. call }
  1847. end;
  1848. { assign procdefinition }
  1849. if symtableproc=nil then
  1850. symtableproc:=procdefinition.owner;
  1851. end
  1852. else
  1853. begin
  1854. { No candidates left, this must be a type error,
  1855. because wrong size is already checked. procdefinition
  1856. is filled with the first (random) definition that is
  1857. found. We use this definition to display a nice error
  1858. message that the wrong type is passed }
  1859. candidates.find_wrong_para;
  1860. candidates.list(true);
  1861. {$ifdef EXTDEBUG}
  1862. candidates.dump_info(V_Hint);
  1863. {$endif EXTDEBUG}
  1864. { We can not proceed, release all procs and exit }
  1865. candidates.free;
  1866. goto errorexit;
  1867. end;
  1868. candidates.free;
  1869. end; { end of procedure to call determination }
  1870. end;
  1871. { check for hints (deprecated etc) }
  1872. if (procdefinition.typ = procdef) then
  1873. check_hints(tprocdef(procdefinition).procsym,tprocdef(procdefinition).symoptions);
  1874. { add needed default parameters }
  1875. if assigned(procdefinition) and
  1876. (paralength<procdefinition.maxparacount) then
  1877. begin
  1878. paraidx:=0;
  1879. i:=0;
  1880. while (i<paralength) do
  1881. begin
  1882. if paraidx>=procdefinition.Paras.count then
  1883. internalerror(200306181);
  1884. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  1885. inc(i);
  1886. inc(paraidx);
  1887. end;
  1888. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1889. inc(paraidx);
  1890. while (paraidx<procdefinition.paras.count) do
  1891. begin
  1892. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1893. internalerror(200212142);
  1894. left:=ccallparanode.create(genconstsymtree(
  1895. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  1896. { Ignore vs_hidden parameters }
  1897. repeat
  1898. inc(paraidx);
  1899. until (paraidx>=procdefinition.paras.count) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1900. end;
  1901. end;
  1902. { recursive call? }
  1903. if assigned(current_procinfo) and
  1904. (procdefinition=current_procinfo.procdef) then
  1905. include(current_procinfo.flags,pi_is_recursive);
  1906. { handle predefined procedures }
  1907. is_const:=(po_internconst in procdefinition.procoptions) and
  1908. ((block_type in [bt_const,bt_type]) or
  1909. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1910. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1911. begin
  1912. if assigned(left) then
  1913. begin
  1914. { ptr and settextbuf needs two args }
  1915. if assigned(tcallparanode(left).right) then
  1916. begin
  1917. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1918. left:=nil;
  1919. end
  1920. else
  1921. begin
  1922. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1923. tcallparanode(left).left:=nil;
  1924. end;
  1925. end
  1926. else
  1927. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1928. result:=hpt;
  1929. goto errorexit;
  1930. end;
  1931. { ensure that the result type is set }
  1932. if not(cnf_typedefset in callnodeflags) then
  1933. begin
  1934. { constructors return their current class type, not the type where the
  1935. constructor is declared, this can be different because of inheritance }
  1936. if (procdefinition.proctypeoption=potype_constructor) and
  1937. assigned(methodpointer) and
  1938. assigned(methodpointer.resultdef) and
  1939. (methodpointer.resultdef.typ=classrefdef) then
  1940. resultdef:=tclassrefdef(methodpointer.resultdef).pointeddef
  1941. else
  1942. { Member call to a (inherited) constructor from the class, the return
  1943. value is always self, so we change it to voidtype to generate an
  1944. error and to prevent users from generating non-working code
  1945. when they expect to clone the current instance, see bug 3662 (PFV) }
  1946. if (procdefinition.proctypeoption=potype_constructor) and
  1947. is_class(tprocdef(procdefinition)._class) and
  1948. assigned(methodpointer) and
  1949. (nf_is_self in methodpointer.flags) then
  1950. resultdef:=voidtype
  1951. else
  1952. resultdef:=procdefinition.returndef;
  1953. end
  1954. else
  1955. resultdef:=typedef;
  1956. {if resultdef.needs_inittable then
  1957. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1958. if assigned(methodpointer) then
  1959. begin
  1960. { when methodpointer is a callnode we must load it first into a
  1961. temp to prevent the processing callnode twice }
  1962. if (methodpointer.nodetype=calln) then
  1963. internalerror(200405121);
  1964. { direct call to inherited abstract method, then we
  1965. can already give a error in the compiler instead
  1966. of a runtime error }
  1967. if (cnf_inherited in callnodeflags) and
  1968. (po_abstractmethod in procdefinition.procoptions) then
  1969. begin
  1970. if (m_delphi in current_settings.modeswitches) and
  1971. (cnf_anon_inherited in callnodeflags) then
  1972. begin
  1973. CGMessage(cg_h_inherited_ignored);
  1974. result:=cnothingnode.create;
  1975. exit;
  1976. end
  1977. else
  1978. CGMessage(cg_e_cant_call_abstract_method);
  1979. end;
  1980. { if an inherited con- or destructor should be }
  1981. { called in a con- or destructor then a warning }
  1982. { will be made }
  1983. { con- and destructors need a pointer to the vmt }
  1984. if (cnf_inherited in callnodeflags) and
  1985. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1986. is_object(methodpointer.resultdef) and
  1987. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1988. CGMessage(cg_w_member_cd_call_from_method);
  1989. if methodpointer.nodetype<>typen then
  1990. begin
  1991. { Remove all postfix operators }
  1992. hpt:=methodpointer;
  1993. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1994. hpt:=tunarynode(hpt).left;
  1995. if (procdefinition.proctypeoption=potype_constructor) and
  1996. assigned(symtableproc) and
  1997. (symtableproc.symtabletype=withsymtable) and
  1998. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1999. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  2000. { R.Init then R will be initialized by the constructor,
  2001. Also allow it for simple loads }
  2002. if (procdefinition.proctypeoption=potype_constructor) or
  2003. ((hpt.nodetype=loadn) and
  2004. (methodpointer.resultdef.typ=objectdef) and
  2005. not(oo_has_virtual in tobjectdef(methodpointer.resultdef).objectoptions)
  2006. ) then
  2007. { a constructor will and a method may write something to }
  2008. { the fields }
  2009. set_varstate(methodpointer,vs_readwritten,[])
  2010. else if ((hpt.nodetype=loadn) and
  2011. (methodpointer.resultdef.typ=classrefdef)) then
  2012. set_varstate(methodpointer,vs_read,[])
  2013. else
  2014. set_varstate(methodpointer,vs_read,[vsf_must_be_valid]);
  2015. { The object is already used if it is called once }
  2016. if (hpt.nodetype=loadn) and
  2017. (tloadnode(hpt).symtableentry.typ in [localvarsym,paravarsym,staticvarsym]) then
  2018. set_varstate(hpt,vs_read,[]);
  2019. // tabstractvarsym(tloadnode(hpt).symtableentry).varstate:=vs_readwritten;
  2020. end;
  2021. { if we are calling the constructor check for abstract
  2022. methods. Ignore inherited and member calls, because the
  2023. class is then already created }
  2024. if (procdefinition.proctypeoption=potype_constructor) and
  2025. not(cnf_inherited in callnodeflags) and
  2026. not(cnf_member_call in callnodeflags) then
  2027. verifyabstractcalls;
  2028. end
  2029. else
  2030. begin
  2031. { When this is method the methodpointer must be available }
  2032. if (right=nil) and
  2033. (procdefinition.owner.symtabletype=ObjectSymtable) then
  2034. internalerror(200305061);
  2035. end;
  2036. { Set flag that the procedure uses varargs, also if they are not passed it is still
  2037. needed for x86_64 to pass the number of SSE registers used }
  2038. if po_varargs in procdefinition.procoptions then
  2039. include(callnodeflags,cnf_uses_varargs);
  2040. { Change loading of array of const to varargs }
  2041. if assigned(left) and
  2042. is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vardef) and
  2043. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  2044. convert_carg_array_of_const;
  2045. { bind parasyms to the callparanodes and insert hidden parameters }
  2046. bind_parasym;
  2047. { insert type conversions for parameters }
  2048. if assigned(left) then
  2049. tcallparanode(left).insert_typeconv(true);
  2050. { dispinterface methode invoke? }
  2051. if assigned(methodpointer) and is_dispinterface(methodpointer.resultdef) then
  2052. begin
  2053. { if the result is used, we've to insert a call to convert the type to be on the "safe side" }
  2054. if cnf_return_value_used in callnodeflags then
  2055. begin
  2056. result:=internalstatements(statements);
  2057. converted_result_data:=ctempcreatenode.create(procdefinition.returndef,sizeof(procdefinition.returndef),tt_persistent,true);
  2058. addstatement(statements,converted_result_data);
  2059. addstatement(statements,cassignmentnode.create(ctemprefnode.create(converted_result_data),
  2060. ctypeconvnode.create_internal(translate_disp_call(methodpointer,parameters,'',tprocdef(procdefinition).dispid),
  2061. procdefinition.returndef)));
  2062. addstatement(statements,ctempdeletenode.create_normal_temp(converted_result_data));
  2063. addstatement(statements,ctemprefnode.create(converted_result_data));
  2064. end
  2065. else
  2066. result:=translate_disp_call(methodpointer,parameters,'',tprocdef(procdefinition).dispid);
  2067. { don't free reused nodes }
  2068. methodpointer:=nil;
  2069. parameters:=nil;
  2070. end;
  2071. errorexit:
  2072. aktcallnode:=oldcallnode;
  2073. end;
  2074. procedure tcallnode.order_parameters;
  2075. var
  2076. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  2077. currloc : tcgloc;
  2078. begin
  2079. hpfirst:=nil;
  2080. hpcurr:=tcallparanode(left);
  2081. while assigned(hpcurr) do
  2082. begin
  2083. { pull out }
  2084. hpnext:=tcallparanode(hpcurr.right);
  2085. { pull in at the correct place.
  2086. Used order:
  2087. 1. LOC_REFERENCE with smallest offset (x86 only)
  2088. 2. LOC_REFERENCE with most registers
  2089. 3. LOC_REGISTER with most registers
  2090. For the moment we only look at the first parameter field. Combining it
  2091. with multiple parameter fields will make things a lot complexer (PFV) }
  2092. if not assigned(hpcurr.parasym.paraloc[callerside].location) then
  2093. internalerror(200412152);
  2094. currloc:=hpcurr.parasym.paraloc[callerside].location^.loc;
  2095. hpprev:=nil;
  2096. hp:=hpfirst;
  2097. while assigned(hp) do
  2098. begin
  2099. case currloc of
  2100. LOC_REFERENCE :
  2101. begin
  2102. case hp.parasym.paraloc[callerside].location^.loc of
  2103. LOC_REFERENCE :
  2104. begin
  2105. { Offset is calculated like:
  2106. sub esp,12
  2107. mov [esp+8],para3
  2108. mov [esp+4],para2
  2109. mov [esp],para1
  2110. call function
  2111. That means the for pushes the para with the
  2112. highest offset (see para3) needs to be pushed first
  2113. }
  2114. if (hpcurr.registersint>hp.registersint)
  2115. {$ifdef x86}
  2116. or (hpcurr.parasym.paraloc[callerside].location^.reference.offset>hp.parasym.paraloc[callerside].location^.reference.offset)
  2117. {$endif x86}
  2118. then
  2119. break;
  2120. end;
  2121. LOC_REGISTER,
  2122. LOC_FPUREGISTER :
  2123. break;
  2124. end;
  2125. end;
  2126. LOC_FPUREGISTER,
  2127. LOC_REGISTER :
  2128. begin
  2129. if (hp.parasym.paraloc[callerside].location^.loc=currloc) and
  2130. (hpcurr.registersint>hp.registersint) then
  2131. break;
  2132. end;
  2133. end;
  2134. hpprev:=hp;
  2135. hp:=tcallparanode(hp.right);
  2136. end;
  2137. hpcurr.right:=hp;
  2138. if assigned(hpprev) then
  2139. hpprev.right:=hpcurr
  2140. else
  2141. hpfirst:=hpcurr;
  2142. { next }
  2143. hpcurr:=hpnext;
  2144. end;
  2145. left:=hpfirst;
  2146. end;
  2147. function tcallnode.replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  2148. var
  2149. paras: tcallparanode;
  2150. temp: tnode;
  2151. indexnr : integer;
  2152. begin
  2153. result := fen_false;
  2154. n.fileinfo := pfileposinfo(arg)^;
  2155. if (n.nodetype = loadn) then
  2156. begin
  2157. case tloadnode(n).symtableentry.typ of
  2158. paravarsym :
  2159. begin
  2160. paras := tcallparanode(left);
  2161. while assigned(paras) and
  2162. (paras.parasym <> tloadnode(n).symtableentry) do
  2163. paras := tcallparanode(paras.right);
  2164. if assigned(paras) then
  2165. begin
  2166. n.free;
  2167. n := paras.left.getcopy;
  2168. typecheckpass(n);
  2169. result := fen_true;
  2170. end;
  2171. end;
  2172. localvarsym :
  2173. begin
  2174. { local? }
  2175. if (tloadnode(n).symtableentry.owner <> tprocdef(procdefinition).localst) then
  2176. exit;
  2177. indexnr:=tloadnode(n).symtableentry.owner.SymList.IndexOf(tloadnode(n).symtableentry);
  2178. if (indexnr >= inlinelocals.count) or
  2179. not assigned(inlinelocals[indexnr]) then
  2180. internalerror(20040720);
  2181. temp := tnode(inlinelocals[indexnr]).getcopy;
  2182. n.free;
  2183. n := temp;
  2184. typecheckpass(n);
  2185. result := fen_true;
  2186. end;
  2187. end;
  2188. end;
  2189. end;
  2190. type
  2191. ptempnodes = ^ttempnodes;
  2192. ttempnodes = record
  2193. createstatement, deletestatement: tstatementnode;
  2194. end;
  2195. procedure tcallnode.createlocaltemps(p:TObject;arg:pointer);
  2196. var
  2197. tempinfo: ptempnodes absolute arg;
  2198. tempnode: ttempcreatenode;
  2199. indexnr : integer;
  2200. begin
  2201. if (TSym(p).typ <> localvarsym) then
  2202. exit;
  2203. indexnr:=TSym(p).Owner.SymList.IndexOf(p);
  2204. if (indexnr >= inlinelocals.count) then
  2205. inlinelocals.count:=indexnr+10;
  2206. if (vo_is_funcret in tabstractvarsym(p).varoptions) and
  2207. assigned(funcretnode) then
  2208. begin
  2209. if node_complexity(funcretnode) > 1 then
  2210. begin
  2211. { can this happen? }
  2212. { we may have to replace the funcretnode with the address of funcretnode }
  2213. { loaded in a temp in this case, because the expression may e.g. contain }
  2214. { a global variable that gets changed inside the function }
  2215. internalerror(2004072101);
  2216. end;
  2217. inlinelocals[indexnr] := funcretnode.getcopy
  2218. end
  2219. else
  2220. begin
  2221. tempnode := ctempcreatenode.create(tabstractvarsym(p).vardef,tabstractvarsym(p).vardef.size,tt_persistent,tabstractvarsym(p).is_regvar(false));
  2222. addstatement(tempinfo^.createstatement,tempnode);
  2223. if (vo_is_funcret in tlocalvarsym(p).varoptions) then
  2224. begin
  2225. funcretnode := ctemprefnode.create(tempnode);
  2226. addstatement(tempinfo^.deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  2227. end
  2228. else
  2229. addstatement(tempinfo^.deletestatement,ctempdeletenode.create(tempnode));
  2230. inlinelocals[indexnr] := ctemprefnode.create(tempnode);
  2231. end;
  2232. end;
  2233. function nonlocalvars(var n: tnode; arg: pointer): foreachnoderesult;
  2234. begin
  2235. result := fen_false;
  2236. { this is just to play it safe, there are more safe situations }
  2237. if (n.nodetype = derefn) or
  2238. ((n.nodetype = loadn) and
  2239. { globals and fields of (possibly global) objects could always be changed in the callee }
  2240. ((tloadnode(n).symtable.symtabletype in [globalsymtable,ObjectSymtable]) or
  2241. { statics can only be modified by functions in the same unit }
  2242. ((tloadnode(n).symtable.symtabletype = staticsymtable) and
  2243. (tloadnode(n).symtable = TSymtable(arg))))) or
  2244. ((n.nodetype = subscriptn) and
  2245. (tsubscriptnode(n).vs.owner.symtabletype = ObjectSymtable)) then
  2246. result := fen_norecurse_true;
  2247. end;
  2248. procedure tcallnode.createinlineparas(var createstatement, deletestatement: tstatementnode);
  2249. var
  2250. para: tcallparanode;
  2251. tempnode: ttempcreatenode;
  2252. tempnodes: ttempnodes;
  2253. n: tnode;
  2254. paracomplexity: longint;
  2255. begin
  2256. { parameters }
  2257. para := tcallparanode(left);
  2258. while assigned(para) do
  2259. begin
  2260. if (para.parasym.typ = paravarsym) and
  2261. { para.left will already be the same as funcretnode in the following case, so don't change }
  2262. (not(vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  2263. (not assigned(funcretnode))) then
  2264. begin
  2265. { must take copy of para.left, because if it contains a }
  2266. { temprefn pointing to a copied temp (e.g. methodpointer), }
  2267. { then this parameter must be changed to point to the copy of }
  2268. { that temp (JM) }
  2269. n := para.left.getcopy;
  2270. para.left.free;
  2271. para.left := n;
  2272. firstpass(para.left);
  2273. { create temps for value parameters, function result and also for }
  2274. { const parameters which are passed by value instead of by reference }
  2275. { we need to take care that we use the type of the defined parameter and not of the
  2276. passed parameter, because these can be different in case of a formaldef (PFV) }
  2277. paracomplexity := node_complexity(para.left);
  2278. { check if we have to create a temp, assign the parameter's }
  2279. { contents to that temp and then substitute the paramter }
  2280. { with the temp everywhere in the function }
  2281. if
  2282. ((tparavarsym(para.parasym).varregable in [vr_none,vr_addr]) and
  2283. not(para.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE])) or
  2284. { we can't assign to formaldef temps }
  2285. ((para.parasym.vardef.typ<>formaldef) and
  2286. (
  2287. { if paracomplexity > 1, we normally take the address of }
  2288. { the parameter expression, store it in a temp and }
  2289. { substitute the dereferenced temp in the inlined function }
  2290. { We can't do this if we can't take the address of the }
  2291. { parameter expression, so in that case assign to a temp }
  2292. not(para.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CONSTANT]) or
  2293. ((paracomplexity > 1) and
  2294. (not valid_for_addr(para.left,false) or
  2295. (para.left.nodetype = calln) or
  2296. is_constnode(para.left))) or
  2297. { the problem is that we can't take the address of a function result :( }
  2298. (vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  2299. { we do not need to create a temp for value parameters }
  2300. { which are not modified in the inlined function }
  2301. { const parameters can get vs_readwritten if their }
  2302. { address is taken }
  2303. ((((para.parasym.varspez = vs_value) and
  2304. (para.parasym.varstate in [vs_initialised,vs_declared,vs_read])) or
  2305. { in case of const, this is only necessary if the }
  2306. { variable would be passed by value normally, or if }
  2307. { there is such a variable somewhere in an expression }
  2308. ((para.parasym.varspez = vs_const) and
  2309. (not paramanager.push_addr_param(vs_const,para.parasym.vardef,procdefinition.proccalloption) or
  2310. (paracomplexity > 1)))) and
  2311. { however, if we pass a global variable, an object field or}
  2312. { an expression containing a pointer dereference as }
  2313. { parameter, this value could be modified in other ways as }
  2314. { well and in such cases create a temp to be on the safe }
  2315. { side }
  2316. foreachnodestatic(para.left,@nonlocalvars,pointer(symtableproc))) or
  2317. { value parameters of which we know they are modified by }
  2318. { definition have to be copied to a temp }
  2319. ((para.parasym.varspez = vs_value) and
  2320. not(para.parasym.varstate in [vs_initialised,vs_declared,vs_read])) or
  2321. { the compiler expects that it can take the address of parameters passed by reference in
  2322. the case of const so we can't replace the node simply by a constant node
  2323. When playing with this code, ensure that
  2324. function f(const a,b : longint) : longint;inline;
  2325. begin
  2326. result:=a*b;
  2327. end;
  2328. [...]
  2329. ...:=f(10,20));
  2330. [...]
  2331. is still folded. (FK)
  2332. }
  2333. ((para.parasym.varspez = vs_const) and
  2334. { const para's can get vs_readwritten if their address }
  2335. { is taken }
  2336. ((para.parasym.varstate = vs_readwritten) or
  2337. { call-by-reference const's may need to be passed by }
  2338. { reference to function called in the inlined code }
  2339. (paramanager.push_addr_param(vs_const,para.parasym.vardef,procdefinition.proccalloption) and
  2340. (not valid_for_addr(para.left,false) or
  2341. is_constnode(para.left)))))
  2342. )
  2343. ) then
  2344. begin
  2345. tempnode:=nil;
  2346. {$ifdef reuse_existing_para_temp}
  2347. { Try to reuse existing result tempnode from a parameter }
  2348. if para.left.nodetype=blockn then
  2349. begin
  2350. n:=tstatementnode(tblocknode(para.left).left);
  2351. while assigned(n) and assigned(tstatementnode(n).right) do
  2352. begin
  2353. if tstatementnode(n).left.nodetype=tempdeleten then
  2354. break;
  2355. n:=tstatementnode(tstatementnode(n).right);
  2356. end;
  2357. { We expect to find the following statements
  2358. tempdeletenode
  2359. tempref
  2360. nil }
  2361. if assigned(n) and
  2362. assigned(tstatementnode(n).right) and
  2363. (tstatementnode(tstatementnode(n).right).right=nil) and
  2364. (tstatementnode(tstatementnode(n).right).left.nodetype=temprefn) then
  2365. begin
  2366. tempnode:=ttempdeletenode(tstatementnode(n).left).tempinfo^.owner;
  2367. para.left:=tstatementnode(tstatementnode(n).right).left;
  2368. addstatement(deletestatement,tstatementnode(n).left);
  2369. { Replace tempdelete,tempref with dummy statement }
  2370. tstatementnode(n).left:=cnothingnode.create;
  2371. tstatementnode(tstatementnode(n).right).left:=cnothingnode.create;
  2372. end;
  2373. end;
  2374. {$endif reuse_existing_para_temp}
  2375. tempnode := ctempcreatenode.create(para.parasym.vardef,para.parasym.vardef.size,tt_persistent,tparavarsym(para.parasym).is_regvar(false));
  2376. addstatement(createstatement,tempnode);
  2377. { assign the value of the parameter to the temp, except in case of the function result }
  2378. { (in that case, para.left is a block containing the creation of a new temp, while we }
  2379. { only need a temprefnode, so delete the old stuff) }
  2380. if not(vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  2381. begin
  2382. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2383. para.left));
  2384. para.left := ctemprefnode.create(tempnode);
  2385. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2386. end
  2387. else
  2388. begin
  2389. if not(assigned(funcretnode)) then
  2390. funcretnode := ctemprefnode.create(tempnode);
  2391. para.left.free;
  2392. para.left := ctemprefnode.create(tempnode);
  2393. addstatement(deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  2394. end;
  2395. end
  2396. { otherwise if the parameter is "complex", take the address }
  2397. { of the parameter expression, store it in a temp and replace }
  2398. { occurrences of the parameter with dereferencings of this }
  2399. { temp }
  2400. else if (paracomplexity > 1) then
  2401. begin
  2402. tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.size,tt_persistent,tparavarsym(para.parasym).is_regvar(true));
  2403. addstatement(createstatement,tempnode);
  2404. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  2405. caddrnode.create_internal(para.left)));
  2406. para.left := ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),para.left.resultdef);
  2407. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  2408. end;
  2409. end;
  2410. para := tcallparanode(para.right);
  2411. end;
  2412. { local variables }
  2413. if not assigned(tprocdef(procdefinition).localst) or
  2414. (tprocdef(procdefinition).localst.SymList.count = 0) then
  2415. exit;
  2416. tempnodes.createstatement := createstatement;
  2417. tempnodes.deletestatement := deletestatement;
  2418. inlinelocals.count:=tprocdef(procdefinition).localst.SymList.count;
  2419. tprocdef(procdefinition).localst.SymList.ForEachCall(@createlocaltemps,@tempnodes);
  2420. createstatement := tempnodes.createstatement;
  2421. deletestatement := tempnodes.deletestatement;
  2422. end;
  2423. function tcallnode.pass1_inline:tnode;
  2424. var
  2425. createstatement,deletestatement: tstatementnode;
  2426. createblock,deleteblock: tblocknode;
  2427. body : tnode;
  2428. begin
  2429. if not(assigned(tprocdef(procdefinition).inlininginfo) and
  2430. assigned(tprocdef(procdefinition).inlininginfo^.code)) then
  2431. internalerror(200412021);
  2432. { inherit flags }
  2433. current_procinfo.flags := current_procinfo.flags + ((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  2434. { create blocks for loading/deleting of local data }
  2435. createblock:=internalstatements(createstatement);
  2436. deleteblock:=internalstatements(deletestatement);
  2437. { add methodpointer init code to init statement }
  2438. { (fini must be done later, as it will delete the hookoncopy info) }
  2439. if assigned(methodpointerinit) then
  2440. addstatement(createstatement,methodpointerinit.getcopy);
  2441. inlinelocals:=TFPObjectList.create(true);
  2442. { get copy of the procedure body }
  2443. body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
  2444. { replace complex parameters with temps }
  2445. createinlineparas(createstatement,deletestatement);
  2446. { replace the parameter loads with the parameter values }
  2447. foreachnode(body,@replaceparaload,@fileinfo);
  2448. { copy methodpointer fini code }
  2449. if assigned(methodpointerdone) then
  2450. addstatement(deletestatement,methodpointerdone.getcopy);
  2451. { free the temps for the locals }
  2452. inlinelocals.free;
  2453. inlinelocals:=nil;
  2454. addstatement(createstatement,body);
  2455. addstatement(createstatement,deleteblock);
  2456. { set function result location if necessary }
  2457. if assigned(funcretnode) and
  2458. (cnf_return_value_used in callnodeflags) then
  2459. addstatement(createstatement,funcretnode.getcopy);
  2460. { consider it must not be inlined if called
  2461. again inside the args or itself }
  2462. exclude(procdefinition.procoptions,po_inline);
  2463. dosimplify(createblock);
  2464. firstpass(createblock);
  2465. include(procdefinition.procoptions,po_inline);
  2466. { return inlined block }
  2467. result := createblock;
  2468. {$ifdef DEBUGINLINE}
  2469. writeln;
  2470. writeln('**************************',tprocdef(procdefinition).mangledname);
  2471. printnode(output,result);
  2472. {$endif DEBUGINLINE}
  2473. end;
  2474. procedure tcallnode.check_stack_parameters;
  2475. var
  2476. hp : tcallparanode;
  2477. begin
  2478. hp:=tcallparanode(left);
  2479. while assigned(hp) do
  2480. begin
  2481. if assigned(hp.parasym) and
  2482. assigned(hp.parasym.paraloc[callerside].location) and
  2483. (hp.parasym.paraloc[callerside].location^.loc=LOC_REFERENCE) then
  2484. include(current_procinfo.flags,pi_has_stackparameter);
  2485. hp:=tcallparanode(hp.right);
  2486. end;
  2487. end;
  2488. function tcallnode.pass_1 : tnode;
  2489. var
  2490. st : TSymtable;
  2491. n: tcallparanode;
  2492. do_inline: boolean;
  2493. begin
  2494. result:=nil;
  2495. { Can we inline the procedure? }
  2496. if ([po_inline,po_has_inlininginfo] <= procdefinition.procoptions) then
  2497. begin
  2498. { Check if we can inline the procedure when it references proc/var that
  2499. are not in the globally available }
  2500. st:=procdefinition.owner;
  2501. if (st.symtabletype=ObjectSymtable) then
  2502. st:=st.defowner.owner;
  2503. do_inline:=true;
  2504. if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
  2505. (st.symtabletype=globalsymtable) and
  2506. (not st.iscurrentunit) then
  2507. begin
  2508. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
  2509. do_inline:=false;
  2510. end;
  2511. n:=tcallparanode(parameters);
  2512. while assigned(n) do
  2513. begin
  2514. if n.contains_unsafe_typeconversion then
  2515. begin
  2516. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", invocation parameter contains unsafe type conversion');
  2517. do_inline:=false;
  2518. break;
  2519. end;
  2520. n:=tcallparanode(n.nextpara);
  2521. end;
  2522. if do_inline then
  2523. begin
  2524. result:=pass1_inline;
  2525. exit;
  2526. end;
  2527. end;
  2528. { calculate the parameter info for the procdef }
  2529. if not procdefinition.has_paraloc_info then
  2530. begin
  2531. procdefinition.requiredargarea:=paramanager.create_paraloc_info(procdefinition,callerside);
  2532. procdefinition.has_paraloc_info:=true;
  2533. end;
  2534. { calculate the parameter size needed for this call include varargs if they are available }
  2535. if assigned(varargsparas) then
  2536. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  2537. else
  2538. pushedparasize:=procdefinition.requiredargarea;
  2539. { record maximum parameter size used in this proc }
  2540. current_procinfo.allocate_push_parasize(pushedparasize);
  2541. { work trough all parameters to get the register requirements }
  2542. if assigned(left) then
  2543. begin
  2544. tcallparanode(left).det_registers;
  2545. if (current_settings.optimizerswitches*[cs_opt_stackframe,cs_opt_level1]<>[]) then
  2546. begin
  2547. { check for stacked parameters }
  2548. check_stack_parameters;
  2549. end;
  2550. end;
  2551. { order parameters }
  2552. order_parameters;
  2553. if assigned(methodpointerinit) then
  2554. firstpass(methodpointerinit);
  2555. if assigned(methodpointerdone) then
  2556. firstpass(methodpointerdone);
  2557. { function result node }
  2558. if assigned(_funcretnode) then
  2559. firstpass(_funcretnode);
  2560. { procedure variable ? }
  2561. if assigned(right) then
  2562. firstpass(right);
  2563. if not (block_type in [bt_const,bt_type]) then
  2564. include(current_procinfo.flags,pi_do_call);
  2565. { implicit finally needed ? }
  2566. if resultdef.needs_inittable and
  2567. not paramanager.ret_in_param(resultdef,procdefinition.proccalloption) and
  2568. not assigned(funcretnode) then
  2569. include(current_procinfo.flags,pi_needs_implicit_finally);
  2570. { get a register for the return value }
  2571. if (not is_void(resultdef)) then
  2572. begin
  2573. if paramanager.ret_in_param(resultdef,procdefinition.proccalloption) then
  2574. begin
  2575. expectloc:=LOC_REFERENCE;
  2576. end
  2577. else
  2578. { ansi/widestrings must be registered, so we can dispose them }
  2579. if is_ansistring(resultdef) or
  2580. is_widestring(resultdef) then
  2581. begin
  2582. expectloc:=LOC_REFERENCE;
  2583. registersint:=1;
  2584. end
  2585. else
  2586. { we have only to handle the result if it is used }
  2587. if (cnf_return_value_used in callnodeflags) then
  2588. begin
  2589. case resultdef.typ of
  2590. enumdef,
  2591. orddef :
  2592. begin
  2593. if (procdefinition.proctypeoption=potype_constructor) then
  2594. begin
  2595. expectloc:=LOC_REGISTER;
  2596. registersint:=1;
  2597. end
  2598. else
  2599. begin
  2600. expectloc:=LOC_REGISTER;
  2601. if is_64bit(resultdef) then
  2602. registersint:=2
  2603. else
  2604. registersint:=1;
  2605. end;
  2606. end;
  2607. floatdef :
  2608. begin
  2609. expectloc:=LOC_FPUREGISTER;
  2610. {$ifdef cpufpemu}
  2611. if (cs_fp_emulation in current_settings.moduleswitches) then
  2612. registersint:=1
  2613. else
  2614. {$endif cpufpemu}
  2615. {$ifdef m68k}
  2616. if (tfloatdef(resultdef).floattype=s32real) then
  2617. registersint:=1
  2618. else
  2619. {$endif m68k}
  2620. registersfpu:=1;
  2621. end;
  2622. else
  2623. begin
  2624. expectloc:=procdefinition.funcretloc[callerside].loc;
  2625. if (expectloc = LOC_REGISTER) then
  2626. {$ifndef cpu64bit}
  2627. if (resultdef.size > sizeof(aint)) then
  2628. registersint:=2
  2629. else
  2630. {$endif cpu64bit}
  2631. registersint:=1
  2632. else
  2633. registersint:=0;
  2634. end;
  2635. end;
  2636. end
  2637. else
  2638. expectloc:=LOC_VOID;
  2639. end
  2640. else
  2641. expectloc:=LOC_VOID;
  2642. {$ifdef m68k}
  2643. { we need one more address register for virtual calls on m68k }
  2644. if (po_virtualmethod in procdefinition.procoptions) then
  2645. inc(registersint);
  2646. {$endif m68k}
  2647. { a fpu can be used in any procedure !! }
  2648. {$ifdef i386}
  2649. registersfpu:=procdefinition.fpu_used;
  2650. {$endif i386}
  2651. { if this is a call to a method calc the registers }
  2652. if (methodpointer<>nil) then
  2653. begin
  2654. if methodpointer.nodetype<>typen then
  2655. begin
  2656. firstpass(methodpointer);
  2657. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2658. registersint:=max(methodpointer.registersint,registersint);
  2659. {$ifdef SUPPORT_MMX }
  2660. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2661. {$endif SUPPORT_MMX}
  2662. end;
  2663. end;
  2664. { determine the registers of the procedure variable }
  2665. { is this OK for inlined procs also ?? (PM) }
  2666. if assigned(right) then
  2667. begin
  2668. registersfpu:=max(right.registersfpu,registersfpu);
  2669. registersint:=max(right.registersint,registersint);
  2670. {$ifdef SUPPORT_MMX}
  2671. registersmmx:=max(right.registersmmx,registersmmx);
  2672. {$endif SUPPORT_MMX}
  2673. end;
  2674. { determine the registers of the procedure }
  2675. if assigned(left) then
  2676. begin
  2677. registersfpu:=max(left.registersfpu,registersfpu);
  2678. registersint:=max(left.registersint,registersint);
  2679. {$ifdef SUPPORT_MMX}
  2680. registersmmx:=max(left.registersmmx,registersmmx);
  2681. {$endif SUPPORT_MMX}
  2682. end;
  2683. end;
  2684. {$ifdef state_tracking}
  2685. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2686. var hp:Tcallparanode;
  2687. value:Tnode;
  2688. begin
  2689. track_state_pass:=false;
  2690. hp:=Tcallparanode(left);
  2691. while assigned(hp) do
  2692. begin
  2693. if left.track_state_pass(exec_known) then
  2694. begin
  2695. left.resultdef:=nil;
  2696. do_typecheckpass(left);
  2697. end;
  2698. value:=aktstate.find_fact(hp.left);
  2699. if value<>nil then
  2700. begin
  2701. track_state_pass:=true;
  2702. hp.left.destroy;
  2703. hp.left:=value.getcopy;
  2704. do_typecheckpass(hp.left);
  2705. end;
  2706. hp:=Tcallparanode(hp.right);
  2707. end;
  2708. end;
  2709. {$endif}
  2710. function tcallnode.para_count:longint;
  2711. var
  2712. ppn : tcallparanode;
  2713. begin
  2714. result:=0;
  2715. ppn:=tcallparanode(left);
  2716. while assigned(ppn) do
  2717. begin
  2718. if not(assigned(ppn.parasym) and
  2719. (vo_is_hidden_para in ppn.parasym.varoptions)) then
  2720. inc(result);
  2721. ppn:=tcallparanode(ppn.right);
  2722. end;
  2723. end;
  2724. function tcallnode.get_load_methodpointer:tnode;
  2725. var
  2726. newstatement : tstatementnode;
  2727. begin
  2728. if assigned(methodpointerinit) then
  2729. begin
  2730. result:=internalstatements(newstatement);
  2731. addstatement(newstatement,methodpointerinit);
  2732. addstatement(newstatement,methodpointer);
  2733. addstatement(newstatement,methodpointerdone);
  2734. methodpointerinit:=nil;
  2735. methodpointer:=nil;
  2736. methodpointerdone:=nil;
  2737. end
  2738. else
  2739. begin
  2740. result:=methodpointer;
  2741. methodpointer:=nil;
  2742. end;
  2743. end;
  2744. function tcallnode.docompare(p: tnode): boolean;
  2745. begin
  2746. docompare :=
  2747. inherited docompare(p) and
  2748. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2749. (procdefinition = tcallnode(p).procdefinition) and
  2750. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2751. (((cnf_typedefset in callnodeflags) and (cnf_typedefset in tcallnode(p).callnodeflags) and
  2752. (equal_defs(typedef,tcallnode(p).typedef))) or
  2753. (not(cnf_typedefset in callnodeflags) and not(cnf_typedefset in tcallnode(p).callnodeflags)));
  2754. end;
  2755. procedure tcallnode.printnodedata(var t:text);
  2756. begin
  2757. if assigned(procdefinition) and
  2758. (procdefinition.typ=procdef) then
  2759. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2760. else
  2761. begin
  2762. if assigned(symtableprocentry) then
  2763. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2764. else
  2765. writeln(t,printnodeindention,'proc = <nil>');
  2766. end;
  2767. if assigned(methodpointer) then
  2768. begin
  2769. writeln(t,printnodeindention,'methodpointer =');
  2770. printnode(t,methodpointer);
  2771. end;
  2772. if assigned(methodpointerinit) then
  2773. begin
  2774. writeln(t,printnodeindention,'methodpointerinit =');
  2775. printnode(t,methodpointerinit);
  2776. end;
  2777. if assigned(methodpointerdone) then
  2778. begin
  2779. writeln(t,printnodeindention,'methodpointerdone =');
  2780. printnode(t,methodpointerdone);
  2781. end;
  2782. if assigned(right) then
  2783. begin
  2784. writeln(t,printnodeindention,'right =');
  2785. printnode(t,right);
  2786. end;
  2787. if assigned(left) then
  2788. begin
  2789. writeln(t,printnodeindention,'left =');
  2790. printnode(t,left);
  2791. end;
  2792. end;
  2793. begin
  2794. ccallnode:=tcallnode;
  2795. ccallparanode:=tcallparanode;
  2796. end.