ncal.pas 121 KB

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