ncal.pas 121 KB

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