ncal.pas 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This file implements the node for sub procedure calling.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cutils,cclasses,
  23. globtype,
  24. paramgr,parabase,
  25. node,nbas,nutils,
  26. {$ifdef state_tracking}
  27. nstate,
  28. {$endif state_tracking}
  29. symbase,symtype,symsym,symdef,symtable;
  30. type
  31. tcallnodeflag = (
  32. cnf_restypeset,
  33. cnf_return_value_used,
  34. cnf_inherited,
  35. cnf_anon_inherited,
  36. cnf_new_call,
  37. cnf_dispose_call,
  38. cnf_member_call { called with implicit methodpointer tree }
  39. );
  40. tcallnodeflags = set of tcallnodeflag;
  41. tcallnode = class(tbinarynode)
  42. private
  43. { info for inlining }
  44. inlinelocals: TList;
  45. { number of parameters passed from the source, this does not include the hidden parameters }
  46. paralength : smallint;
  47. function gen_self_tree_methodpointer:tnode;
  48. function gen_self_tree:tnode;
  49. function gen_vmt_tree:tnode;
  50. procedure bind_parasym;
  51. { function return node, this is used to pass the data for a
  52. ret_in_param return value }
  53. _funcretnode : tnode;
  54. procedure setfuncretnode(const returnnode: tnode);
  55. procedure convert_carg_array_of_const;
  56. procedure order_parameters;
  57. procedure createinlineparas(var createstatement, deletestatement: tstatementnode);
  58. function replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  59. procedure createlocaltemps(p:TNamedIndexItem;arg:pointer);
  60. function pass1_inline:tnode;
  61. protected
  62. pushedparasize : longint;
  63. public
  64. { the symbol containing the definition of the procedure }
  65. { to call }
  66. symtableprocentry : tprocsym;
  67. symtableprocentryderef : tderef;
  68. { symtable where the entry was found, needed for with support }
  69. symtableproc : tsymtable;
  70. { the definition of the procedure to call }
  71. procdefinition : tabstractprocdef;
  72. procdefinitionderef : tderef;
  73. { tree that contains the pointer to the object for this method }
  74. methodpointerinit,
  75. methodpointerdone : tblocknode;
  76. methodpointer : tnode;
  77. {$ifdef PASS2INLINE}
  78. { inline function body }
  79. inlinecode : tnode;
  80. {$endif PASS2INLINE}
  81. { varargs parasyms }
  82. varargsparas : tvarargsparalist;
  83. { node that specifies where the result should be put for calls }
  84. { that return their result in a parameter }
  85. property funcretnode: tnode read _funcretnode write setfuncretnode;
  86. { separately specified resulttype for some compilerprocs (e.g. }
  87. { you can't have a function with an "array of char" resulttype }
  88. { the RTL) (JM) }
  89. restype: ttype;
  90. callnodeflags : tcallnodeflags;
  91. { only the processor specific nodes need to override this }
  92. { constructor }
  93. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);virtual;
  94. constructor create_procvar(l,r:tnode);
  95. constructor createintern(const name: string; params: tnode);
  96. constructor createinternres(const name: string; params: tnode; const res: ttype);
  97. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  98. destructor destroy;override;
  99. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. procedure buildderefimpl;override;
  102. procedure derefimpl;override;
  103. function getcopy : tnode;override;
  104. { Goes through all symbols in a class and subclasses and calls
  105. verify abstract for each .
  106. }
  107. procedure verifyabstractcalls;
  108. { called for each definition in a class and verifies if a method
  109. is abstract or not, if it is abstract, give out a warning
  110. }
  111. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  112. procedure insertintolist(l : tnodelist);override;
  113. function pass_1 : tnode;override;
  114. function det_resulttype:tnode;override;
  115. {$ifdef state_tracking}
  116. function track_state_pass(exec_known:boolean):boolean;override;
  117. {$endif state_tracking}
  118. function docompare(p: tnode): boolean; override;
  119. procedure printnodedata(var t:text);override;
  120. function para_count:longint;
  121. private
  122. AbstractMethodsList : TStringList;
  123. end;
  124. tcallnodeclass = class of tcallnode;
  125. tcallparaflag = (
  126. cpf_is_colon_para,
  127. cpf_varargs_para { belongs this para to varargs }
  128. );
  129. tcallparaflags = set of tcallparaflag;
  130. tcallparanode = class(tbinarynode)
  131. public
  132. callparaflags : tcallparaflags;
  133. parasym : tparavarsym;
  134. used_by_callnode : boolean;
  135. { only the processor specific nodes need to override this }
  136. { constructor }
  137. constructor create(expr,next : tnode);virtual;
  138. destructor destroy;override;
  139. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  140. procedure ppuwrite(ppufile:tcompilerppufile);override;
  141. function getcopy : tnode;override;
  142. procedure insertintolist(l : tnodelist);override;
  143. procedure get_paratype;
  144. procedure insert_typeconv(do_count : boolean);
  145. procedure det_registers;
  146. procedure firstcallparan;
  147. procedure secondcallparan;virtual;abstract;
  148. function docompare(p: tnode): boolean; override;
  149. procedure printnodetree(var t:text);override;
  150. end;
  151. tcallparanodeclass = class of tcallparanode;
  152. function reverseparameters(p: tcallparanode): tcallparanode;
  153. var
  154. ccallnode : tcallnodeclass;
  155. ccallparanode : tcallparanodeclass;
  156. { Current callnode, this is needed for having a link
  157. between the callparanodes and the callnode they belong to }
  158. aktcallnode : tcallnode;
  159. implementation
  160. uses
  161. systems,
  162. verbose,globals,
  163. symconst,defutil,defcmp,
  164. htypechk,pass_1,
  165. ncnv,nld,ninl,nadd,ncon,nmem,
  166. procinfo,
  167. cgbase
  168. ;
  169. type
  170. tobjectinfoitem = class(tlinkedlistitem)
  171. objinfo : tobjectdef;
  172. constructor create(def : tobjectdef);
  173. end;
  174. {****************************************************************************
  175. HELPERS
  176. ****************************************************************************}
  177. function reverseparameters(p: tcallparanode): tcallparanode;
  178. var
  179. hp1, hp2: tcallparanode;
  180. begin
  181. hp1:=nil;
  182. while assigned(p) do
  183. begin
  184. { pull out }
  185. hp2:=p;
  186. p:=tcallparanode(p.right);
  187. { pull in }
  188. hp2.right:=hp1;
  189. hp1:=hp2;
  190. end;
  191. reverseparameters:=hp1;
  192. end;
  193. procedure maybe_load_para_in_temp(var p:tnode);
  194. var
  195. hp : tnode;
  196. ptemp : ttempcreatenode;
  197. newinitstatement,
  198. newdonestatement : tstatementnode;
  199. begin
  200. if not assigned(aktcallnode) then
  201. internalerror(200410121);
  202. hp:=p;
  203. while assigned(hp) and
  204. (hp.nodetype=typeconvn) do
  205. hp:=tunarynode(hp).left;
  206. if assigned(hp) and
  207. (
  208. { call result must always be loaded in temp to prevent
  209. double creation }
  210. (hp.nodetype=calln)
  211. { Also optimize also complex loads }
  212. {$warning Complex loads can also be optimized}
  213. // or not(hp.nodetype in [typen,loadvmtaddrn,loadn])
  214. ) then
  215. begin
  216. if not assigned(aktcallnode.methodpointerinit) then
  217. begin
  218. aktcallnode.methodpointerinit:=internalstatements(newinitstatement);
  219. aktcallnode.methodpointerdone:=internalstatements(newdonestatement);
  220. end
  221. else
  222. begin
  223. newinitstatement:=laststatement(aktcallnode.methodpointerinit);
  224. newdonestatement:=laststatement(aktcallnode.methodpointerdone);
  225. end;
  226. { temp create }
  227. ptemp:=ctempcreatenode.create(p.resulttype,p.resulttype.def.size,tt_persistent,true);
  228. addstatement(newinitstatement,ptemp);
  229. addstatement(newinitstatement,cassignmentnode.create(
  230. ctemprefnode.create(ptemp),
  231. p));
  232. resulttypepass(aktcallnode.methodpointerinit);
  233. { new tree is only a temp reference }
  234. p:=ctemprefnode.create(ptemp);
  235. resulttypepass(p);
  236. { temp release }
  237. addstatement(newdonestatement,ctempdeletenode.create(ptemp));
  238. resulttypepass(aktcallnode.methodpointerdone);
  239. end;
  240. end;
  241. function gen_high_tree(var p:tnode;paradef:tdef):tnode;
  242. var
  243. temp: tnode;
  244. len : integer;
  245. loadconst : boolean;
  246. hightree : tnode;
  247. begin
  248. len:=-1;
  249. loadconst:=true;
  250. hightree:=nil;
  251. case p.resulttype.def.deftype of
  252. arraydef :
  253. begin
  254. if (paradef.deftype<>arraydef) then
  255. internalerror(200405241);
  256. { handle special case of passing an single array to an array of array }
  257. if compare_defs(tarraydef(paradef).elementtype.def,p.resulttype.def,nothingn)>=te_equal then
  258. len:=0
  259. else
  260. begin
  261. maybe_load_para_in_temp(p);
  262. { handle via a normal inline in_high_x node }
  263. loadconst := false;
  264. hightree := geninlinenode(in_high_x,false,p.getcopy);
  265. resulttypepass(hightree);
  266. { only substract low(array) if it's <> 0 }
  267. temp := geninlinenode(in_low_x,false,p.getcopy);
  268. resulttypepass(temp);
  269. if (temp.nodetype <> ordconstn) or
  270. (tordconstnode(temp).value <> 0) then
  271. hightree := caddnode.create(subn,hightree,temp)
  272. else
  273. temp.free;
  274. end;
  275. end;
  276. stringdef :
  277. begin
  278. if is_open_string(paradef) then
  279. begin
  280. maybe_load_para_in_temp(p);
  281. { handle via a normal inline in_high_x node }
  282. loadconst := false;
  283. hightree := geninlinenode(in_high_x,false,p.getcopy);
  284. end
  285. else
  286. begin
  287. { passing a string to an array of char }
  288. if (p.nodetype=stringconstn) then
  289. begin
  290. len:=str_length(p);
  291. if len>0 then
  292. dec(len);
  293. end
  294. else
  295. begin
  296. maybe_load_para_in_temp(p);
  297. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  298. cordconstnode.create(1,s32inttype,false));
  299. loadconst:=false;
  300. end;
  301. end;
  302. end;
  303. else
  304. len:=0;
  305. end;
  306. if loadconst then
  307. hightree:=cordconstnode.create(len,s32inttype,true)
  308. else
  309. begin
  310. if not assigned(hightree) then
  311. internalerror(200304071);
  312. { Need to use explicit, because it can also be a enum }
  313. hightree:=ctypeconvnode.create_internal(hightree,s32inttype);
  314. end;
  315. result:=hightree;
  316. end;
  317. {****************************************************************************
  318. TOBJECTINFOITEM
  319. ****************************************************************************}
  320. constructor tobjectinfoitem.create(def : tobjectdef);
  321. begin
  322. inherited create;
  323. objinfo := def;
  324. end;
  325. {****************************************************************************
  326. TCALLPARANODE
  327. ****************************************************************************}
  328. constructor tcallparanode.create(expr,next : tnode);
  329. begin
  330. inherited create(callparan,expr,next);
  331. if not assigned(expr) then
  332. internalerror(200305091);
  333. expr.fileinfo:=fileinfo;
  334. callparaflags:=[];
  335. end;
  336. destructor tcallparanode.destroy;
  337. begin
  338. { When the node is used by callnode then
  339. we don't destroy left, the callnode takes care of it }
  340. if used_by_callnode then
  341. left:=nil;
  342. inherited destroy;
  343. end;
  344. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  345. begin
  346. inherited ppuload(t,ppufile);
  347. ppufile.getsmallset(callparaflags);
  348. end;
  349. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  350. begin
  351. inherited ppuwrite(ppufile);
  352. ppufile.putsmallset(callparaflags);
  353. end;
  354. function tcallparanode.getcopy : tnode;
  355. var
  356. n : tcallparanode;
  357. begin
  358. n:=tcallparanode(inherited getcopy);
  359. n.callparaflags:=callparaflags;
  360. n.parasym:=parasym;
  361. result:=n;
  362. end;
  363. procedure tcallparanode.insertintolist(l : tnodelist);
  364. begin
  365. end;
  366. procedure tcallparanode.get_paratype;
  367. var
  368. old_array_constructor : boolean;
  369. begin
  370. inc(parsing_para_level);
  371. if assigned(right) then
  372. tcallparanode(right).get_paratype;
  373. old_array_constructor:=allow_array_constructor;
  374. allow_array_constructor:=true;
  375. resulttypepass(left);
  376. allow_array_constructor:=old_array_constructor;
  377. if codegenerror then
  378. resulttype:=generrortype
  379. else
  380. resulttype:=left.resulttype;
  381. dec(parsing_para_level);
  382. end;
  383. procedure tcallparanode.insert_typeconv(do_count : boolean);
  384. var
  385. oldtype : ttype;
  386. {$ifdef extdebug}
  387. store_count_ref : boolean;
  388. {$endif def extdebug}
  389. begin
  390. inc(parsing_para_level);
  391. {$ifdef extdebug}
  392. if do_count then
  393. begin
  394. store_count_ref:=count_ref;
  395. count_ref:=true;
  396. end;
  397. {$endif def extdebug}
  398. { Be sure to have the resulttype }
  399. if not assigned(left.resulttype.def) then
  400. resulttypepass(left);
  401. if (left.nodetype<>nothingn) then
  402. begin
  403. { Convert tp procvars, this is needs to be done
  404. here to make the change permanent. in the overload
  405. choosing the changes are only made temporary }
  406. if (left.resulttype.def.deftype=procvardef) and
  407. (parasym.vartype.def.deftype<>procvardef) then
  408. begin
  409. if maybe_call_procvar(left,true) then
  410. resulttype:=left.resulttype;
  411. end;
  412. { Handle varargs and hidden paras directly, no typeconvs or }
  413. { typechecking needed }
  414. if (cpf_varargs_para in callparaflags) then
  415. begin
  416. { convert pascal to C types }
  417. case left.resulttype.def.deftype of
  418. stringdef :
  419. inserttypeconv(left,charpointertype);
  420. floatdef :
  421. inserttypeconv(left,s64floattype);
  422. end;
  423. set_varstate(left,vs_used,true);
  424. resulttype:=left.resulttype;
  425. { also update parasym type to get the correct parameter location
  426. for the new types }
  427. parasym.vartype:=left.resulttype;
  428. end
  429. else
  430. if (vo_is_hidden_para in parasym.varoptions) then
  431. begin
  432. set_varstate(left,vs_used,true);
  433. resulttype:=left.resulttype;
  434. end
  435. else
  436. begin
  437. { Do we need arrayconstructor -> set conversion, then insert
  438. it here before the arrayconstructor node breaks the tree
  439. with its conversions of enum->ord }
  440. if (left.nodetype=arrayconstructorn) and
  441. (parasym.vartype.def.deftype=setdef) then
  442. inserttypeconv(left,parasym.vartype);
  443. { set some settings needed for arrayconstructor }
  444. if is_array_constructor(left.resulttype.def) then
  445. begin
  446. if is_array_of_const(parasym.vartype.def) then
  447. begin
  448. { force variant array }
  449. include(left.flags,nf_forcevaria);
  450. end
  451. else
  452. begin
  453. include(left.flags,nf_novariaallowed);
  454. { now that the resultting type is know we can insert the required
  455. typeconvs for the array constructor }
  456. if parasym.vartype.def.deftype=arraydef then
  457. tarrayconstructornode(left).force_type(tarraydef(parasym.vartype.def).elementtype);
  458. end;
  459. end;
  460. { check if local proc/func is assigned to procvar }
  461. if left.resulttype.def.deftype=procvardef then
  462. test_local_to_procvar(tprocvardef(left.resulttype.def),parasym.vartype.def);
  463. { test conversions }
  464. if not(is_shortstring(left.resulttype.def) and
  465. is_shortstring(parasym.vartype.def)) and
  466. (parasym.vartype.def.deftype<>formaldef) then
  467. begin
  468. { Process open parameters }
  469. if paramanager.push_high_param(parasym.varspez,parasym.vartype.def,aktcallnode.procdefinition.proccalloption) then
  470. begin
  471. { insert type conv but hold the ranges of the array }
  472. oldtype:=left.resulttype;
  473. inserttypeconv(left,parasym.vartype);
  474. left.resulttype:=oldtype;
  475. end
  476. else
  477. begin
  478. { for ordinals, floats and enums, verify if we might cause
  479. some range-check errors. }
  480. if (parasym.vartype.def.deftype in [enumdef,orddef,floatdef]) and
  481. (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) and
  482. (left.nodetype in [vecn,loadn,calln]) then
  483. begin
  484. if (left.resulttype.def.size>parasym.vartype.def.size) then
  485. begin
  486. if (cs_check_range in aktlocalswitches) then
  487. Message(type_w_smaller_possible_range_check)
  488. else
  489. Message(type_h_smaller_possible_range_check);
  490. end;
  491. end;
  492. inserttypeconv(left,parasym.vartype);
  493. end;
  494. if codegenerror then
  495. begin
  496. dec(parsing_para_level);
  497. exit;
  498. end;
  499. end;
  500. { check var strings }
  501. if (cs_strict_var_strings in aktlocalswitches) and
  502. is_shortstring(left.resulttype.def) and
  503. is_shortstring(parasym.vartype.def) and
  504. (parasym.varspez in [vs_out,vs_var]) and
  505. not(is_open_string(parasym.vartype.def)) and
  506. not(equal_defs(left.resulttype.def,parasym.vartype.def)) then
  507. begin
  508. aktfilepos:=left.fileinfo;
  509. CGMessage(type_e_strict_var_string_violation);
  510. end;
  511. { Handle formal parameters separate }
  512. if (parasym.vartype.def.deftype=formaldef) then
  513. begin
  514. { load procvar if a procedure is passed }
  515. if (m_tp_procvar in aktmodeswitches) and
  516. (left.nodetype=calln) and
  517. (is_void(left.resulttype.def)) then
  518. load_procvar_from_calln(left);
  519. case parasym.varspez of
  520. vs_var,
  521. vs_out :
  522. begin
  523. if not valid_for_formal_var(left) then
  524. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  525. end;
  526. vs_const :
  527. begin
  528. if not valid_for_formal_const(left) then
  529. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  530. end;
  531. end;
  532. end
  533. else
  534. begin
  535. { check if the argument is allowed }
  536. if (parasym.varspez in [vs_out,vs_var]) then
  537. valid_for_var(left);
  538. end;
  539. if parasym.varspez = vs_var then
  540. set_unique(left);
  541. { When the address needs to be pushed then the register is
  542. not regable. Exception is when the location is also a var
  543. parameter and we can pass the address transparently }
  544. if (
  545. not(
  546. (vo_is_hidden_para in parasym.varoptions) and
  547. (left.resulttype.def.deftype in [pointerdef,classrefdef])
  548. ) and
  549. paramanager.push_addr_param(parasym.varspez,parasym.vartype.def,
  550. aktcallnode.procdefinition.proccalloption) and
  551. not(
  552. (left.nodetype=loadn) and
  553. (tloadnode(left).is_addr_param_load)
  554. )
  555. ) then
  556. make_not_regable(left);
  557. if do_count then
  558. begin
  559. if parasym.varspez in [vs_var,vs_out] then
  560. set_varstate(left,vs_used,false)
  561. else
  562. set_varstate(left,vs_used,true);
  563. end;
  564. { must only be done after typeconv PM }
  565. resulttype:=parasym.vartype;
  566. end;
  567. end;
  568. { process next node }
  569. if assigned(right) then
  570. tcallparanode(right).insert_typeconv(do_count);
  571. dec(parsing_para_level);
  572. {$ifdef extdebug}
  573. if do_count then
  574. count_ref:=store_count_ref;
  575. {$endif def extdebug}
  576. end;
  577. procedure tcallparanode.det_registers;
  578. begin
  579. if assigned(right) then
  580. begin
  581. tcallparanode(right).det_registers;
  582. registersint:=right.registersint;
  583. registersfpu:=right.registersfpu;
  584. {$ifdef SUPPORT_MMX}
  585. registersmmx:=right.registersmmx;
  586. {$endif}
  587. end;
  588. firstpass(left);
  589. if left.registersint>registersint then
  590. registersint:=left.registersint;
  591. if left.registersfpu>registersfpu then
  592. registersfpu:=left.registersfpu;
  593. {$ifdef SUPPORT_MMX}
  594. if left.registersmmx>registersmmx then
  595. registersmmx:=left.registersmmx;
  596. {$endif SUPPORT_MMX}
  597. end;
  598. procedure tcallparanode.firstcallparan;
  599. begin
  600. if not assigned(left.resulttype.def) then
  601. get_paratype;
  602. det_registers;
  603. end;
  604. function tcallparanode.docompare(p: tnode): boolean;
  605. begin
  606. docompare :=
  607. inherited docompare(p) and
  608. (callparaflags = tcallparanode(p).callparaflags)
  609. ;
  610. end;
  611. procedure tcallparanode.printnodetree(var t:text);
  612. begin
  613. printnodelist(t);
  614. end;
  615. {****************************************************************************
  616. TCALLNODE
  617. ****************************************************************************}
  618. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp: tnode; callflags:tcallnodeflags);
  619. begin
  620. inherited create(calln,l,nil);
  621. symtableprocentry:=v;
  622. symtableproc:=st;
  623. callnodeflags:=callflags+[cnf_return_value_used];
  624. methodpointer:=mp;
  625. methodpointerinit:=nil;
  626. methodpointerdone:=nil;
  627. procdefinition:=nil;
  628. _funcretnode:=nil;
  629. {$ifdef PASS2INLINE}
  630. inlinecode:=nil;
  631. {$endif PASS2INLINE}
  632. paralength:=-1;
  633. varargsparas:=nil;
  634. end;
  635. constructor tcallnode.create_procvar(l,r:tnode);
  636. begin
  637. inherited create(calln,l,r);
  638. symtableprocentry:=nil;
  639. symtableproc:=nil;
  640. methodpointer:=nil;
  641. methodpointerinit:=nil;
  642. methodpointerdone:=nil;
  643. procdefinition:=nil;
  644. callnodeflags:=[cnf_return_value_used];
  645. _funcretnode:=nil;
  646. {$ifdef PASS2INLINE}
  647. inlinecode:=nil;
  648. {$endif PASS2INLINE}
  649. paralength:=-1;
  650. varargsparas:=nil;
  651. end;
  652. constructor tcallnode.createintern(const name: string; params: tnode);
  653. var
  654. srsym: tsym;
  655. symowner: tsymtable;
  656. begin
  657. if not (cs_compilesystem in aktmoduleswitches) then
  658. begin
  659. srsym := searchsymonlyin(systemunit,name);
  660. symowner := systemunit;
  661. end
  662. else
  663. begin
  664. searchsym(name,srsym,symowner);
  665. if not assigned(srsym) then
  666. searchsym(upper(name),srsym,symowner);
  667. end;
  668. if not assigned(srsym) or
  669. (srsym.typ <> procsym) then
  670. begin
  671. {$ifdef EXTDEBUG}
  672. Comment(V_Error,'unknown compilerproc '+name);
  673. {$endif EXTDEBUG}
  674. internalerror(200107271);
  675. end;
  676. self.create(params,tprocsym(srsym),symowner,nil,[]);
  677. end;
  678. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  679. begin
  680. self.createintern(name,params);
  681. restype := res;
  682. include(callnodeflags,cnf_restypeset);
  683. { both the normal and specified resulttype either have to be returned via a }
  684. { parameter or not, but no mixing (JM) }
  685. if paramanager.ret_in_param(restype.def,pocall_compilerproc) xor
  686. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  687. internalerror(200108291);
  688. end;
  689. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  690. begin
  691. self.createintern(name,params);
  692. _funcretnode:=returnnode;
  693. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  694. internalerror(200204247);
  695. end;
  696. procedure tcallnode.setfuncretnode(const returnnode: tnode);
  697. var
  698. para: tcallparanode;
  699. begin
  700. if assigned(_funcretnode) then
  701. _funcretnode.free;
  702. _funcretnode := returnnode;
  703. { if the resulttype pass hasn't occurred yet, that one will do }
  704. { everything }
  705. if assigned(resulttype.def) then
  706. begin
  707. { these are returned as values, but we can optimize their loading }
  708. { as well }
  709. if is_ansistring(resulttype.def) or
  710. is_widestring(resulttype.def) then
  711. exit;
  712. para := tcallparanode(left);
  713. while assigned(para) do
  714. begin
  715. if (vo_is_hidden_para in para.parasym.varoptions) and
  716. (vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  717. begin
  718. para.left.free;
  719. para.left := _funcretnode.getcopy;
  720. exit;
  721. end;
  722. para := tcallparanode(para.right);
  723. end;
  724. { no hidden resultpara found, error! }
  725. if not(procdefinition.proccalloption = pocall_inline) then
  726. internalerror(200306087);
  727. end;
  728. end;
  729. destructor tcallnode.destroy;
  730. var
  731. i : longint;
  732. begin
  733. methodpointer.free;
  734. methodpointerinit.free;
  735. methodpointerdone.free;
  736. _funcretnode.free;
  737. {$ifdef PASS2INLINE}
  738. inlinecode.free;
  739. {$endif PASS2INLINE}
  740. if assigned(varargsparas) then
  741. begin
  742. for i:=0 to varargsparas.count-1 do
  743. tparavarsym(varargsparas[i]).free;
  744. varargsparas.free;
  745. end;
  746. inherited destroy;
  747. end;
  748. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  749. begin
  750. inherited ppuload(t,ppufile);
  751. ppufile.getderef(symtableprocentryderef);
  752. {$ifdef fpc}
  753. {$warning FIXME: No withsymtable support}
  754. {$endif}
  755. symtableproc:=nil;
  756. ppufile.getderef(procdefinitionderef);
  757. ppufile.getsmallset(callnodeflags);
  758. methodpointer:=ppuloadnode(ppufile);
  759. methodpointerinit:=tblocknode(ppuloadnode(ppufile));
  760. methodpointerdone:=tblocknode(ppuloadnode(ppufile));
  761. _funcretnode:=ppuloadnode(ppufile);
  762. {$ifdef PASS2INLINE}
  763. inlinecode:=ppuloadnode(ppufile);
  764. {$endif PASS2INLINE}
  765. end;
  766. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  767. begin
  768. inherited ppuwrite(ppufile);
  769. ppufile.putderef(symtableprocentryderef);
  770. ppufile.putderef(procdefinitionderef);
  771. ppufile.putsmallset(callnodeflags);
  772. ppuwritenode(ppufile,methodpointer);
  773. ppuwritenode(ppufile,methodpointerinit);
  774. ppuwritenode(ppufile,methodpointerdone);
  775. ppuwritenode(ppufile,_funcretnode);
  776. {$ifdef PASS2INLINE}
  777. ppuwritenode(ppufile,inlinecode);
  778. {$endif PASS2INLINE}
  779. end;
  780. procedure tcallnode.buildderefimpl;
  781. begin
  782. inherited buildderefimpl;
  783. symtableprocentryderef.build(symtableprocentry);
  784. procdefinitionderef.build(procdefinition);
  785. if assigned(methodpointer) then
  786. methodpointer.buildderefimpl;
  787. if assigned(methodpointerinit) then
  788. methodpointerinit.buildderefimpl;
  789. if assigned(methodpointerdone) then
  790. methodpointerdone.buildderefimpl;
  791. if assigned(_funcretnode) then
  792. _funcretnode.buildderefimpl;
  793. {$ifdef PASS2INLINE}
  794. if assigned(inlinecode) then
  795. inlinecode.buildderefimpl;
  796. {$endif PASS2INLINE}
  797. end;
  798. procedure tcallnode.derefimpl;
  799. var
  800. pt : tcallparanode;
  801. i : integer;
  802. begin
  803. inherited derefimpl;
  804. symtableprocentry:=tprocsym(symtableprocentryderef.resolve);
  805. if assigned(symtableprocentry) then
  806. symtableproc:=symtableprocentry.owner;
  807. procdefinition:=tabstractprocdef(procdefinitionderef.resolve);
  808. if assigned(methodpointer) then
  809. methodpointer.derefimpl;
  810. if assigned(methodpointerinit) then
  811. methodpointerinit.derefimpl;
  812. if assigned(methodpointerdone) then
  813. methodpointerdone.derefimpl;
  814. if assigned(_funcretnode) then
  815. _funcretnode.derefimpl;
  816. {$ifdef PASS2INLINE}
  817. if assigned(inlinecode) then
  818. inlinecode.derefimpl;
  819. {$endif PASS2INLINE}
  820. { Connect parasyms }
  821. pt:=tcallparanode(left);
  822. while assigned(pt) and
  823. (cpf_varargs_para in pt.callparaflags) do
  824. pt:=tcallparanode(pt.right);
  825. for i:=procdefinition.paras.count-1 downto 0 do
  826. begin
  827. if not assigned(pt) then
  828. internalerror(200311077);
  829. pt.parasym:=tparavarsym(procdefinition.paras[i]);
  830. pt:=tcallparanode(pt.right);
  831. end;
  832. if assigned(pt) then
  833. internalerror(200311078);
  834. end;
  835. function tcallnode.getcopy : tnode;
  836. var
  837. n : tcallnode;
  838. i : integer;
  839. hp,hpn : tparavarsym;
  840. oldleft : tnode;
  841. begin
  842. { Need to use a hack here to prevent the parameters from being copied.
  843. The parameters must be copied between methodpointerinit/methodpointerdone because
  844. the can reference methodpointer }
  845. oldleft:=left;
  846. left:=nil;
  847. n:=tcallnode(inherited getcopy);
  848. left:=oldleft;
  849. n.symtableprocentry:=symtableprocentry;
  850. n.symtableproc:=symtableproc;
  851. n.procdefinition:=procdefinition;
  852. n.restype := restype;
  853. n.callnodeflags := callnodeflags;
  854. if assigned(methodpointerinit) then
  855. n.methodpointerinit:=tblocknode(methodpointerinit.getcopy)
  856. else
  857. n.methodpointerinit:=nil;
  858. { methodpointerinit is copied, now references to the temp will also be copied
  859. correctly. We can now copy the parameters and methodpointer }
  860. if assigned(left) then
  861. n.left:=left.getcopy
  862. else
  863. n.left:=nil;
  864. if assigned(methodpointer) then
  865. n.methodpointer:=methodpointer.getcopy
  866. else
  867. n.methodpointer:=nil;
  868. if assigned(methodpointerdone) then
  869. n.methodpointerdone:=tblocknode(methodpointerdone.getcopy)
  870. else
  871. n.methodpointerdone:=nil;
  872. if assigned(_funcretnode) then
  873. n._funcretnode:=_funcretnode.getcopy
  874. else
  875. n._funcretnode:=nil;
  876. {$ifdef PASS2INLINE}
  877. if assigned(inlinecode) then
  878. n.inlinecode:=inlinecode.getcopy
  879. else
  880. n.inlinecode:=nil;
  881. {$endif PASS2INLINE}
  882. if assigned(varargsparas) then
  883. begin
  884. n.varargsparas:=tvarargsparalist.create;
  885. for i:=0 to varargsparas.count-1 do
  886. begin
  887. hp:=tparavarsym(varargsparas[i]);
  888. hpn:=tparavarsym.create(hp.realname,hp.paranr,hp.varspez,hp.vartype,[]);
  889. n.varargsparas.add(hpn);
  890. end;
  891. end
  892. else
  893. n.varargsparas:=nil;
  894. result:=n;
  895. end;
  896. procedure tcallnode.insertintolist(l : tnodelist);
  897. begin
  898. end;
  899. procedure tcallnode.convert_carg_array_of_const;
  900. var
  901. hp : tarrayconstructornode;
  902. oldleft : tcallparanode;
  903. begin
  904. oldleft:=tcallparanode(left);
  905. if oldleft.left.nodetype<>arrayconstructorn then
  906. begin
  907. CGMessage1(type_e_wrong_type_in_array_constructor,oldleft.left.resulttype.def.typename);
  908. exit;
  909. end;
  910. { Get arrayconstructor node and insert typeconvs }
  911. hp:=tarrayconstructornode(oldleft.left);
  912. hp.insert_typeconvs;
  913. { Add c args parameters }
  914. { It could be an empty set }
  915. if assigned(hp) and
  916. assigned(hp.left) then
  917. begin
  918. while assigned(hp) do
  919. begin
  920. left:=ccallparanode.create(hp.left,left);
  921. { set callparanode resulttype and flags }
  922. left.resulttype:=hp.left.resulttype;
  923. include(tcallparanode(left).callparaflags,cpf_varargs_para);
  924. hp.left:=nil;
  925. hp:=tarrayconstructornode(hp.right);
  926. end;
  927. end;
  928. { Remove value of old array of const parameter, but keep it
  929. in the list because it is required for bind_parasym.
  930. Generate a nothign to keep callparanoed.left valid }
  931. oldleft.left.free;
  932. oldleft.left:=cnothingnode.create;
  933. end;
  934. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  935. var
  936. hp : tprocdef;
  937. j: integer;
  938. begin
  939. if (tsym(p).typ=procsym) then
  940. begin
  941. for j:=1 to tprocsym(p).procdef_count do
  942. begin
  943. { index starts at 1 }
  944. hp:=tprocsym(p).procdef[j];
  945. { If this is an abstract method insert into the list }
  946. if (po_abstractmethod in hp.procoptions) then
  947. AbstractMethodsList.Insert(hp.procsym.realname)
  948. else
  949. { If this symbol is a virtual (includes override) method,
  950. then remove it from the list }
  951. if po_virtualmethod in hp.procoptions then
  952. AbstractMethodsList.Remove(hp.procsym.realname);
  953. end;
  954. end;
  955. end;
  956. procedure tcallnode.verifyabstractcalls;
  957. var
  958. objectdf : tobjectdef;
  959. parents : tlinkedlist;
  960. objectinfo : tobjectinfoitem;
  961. stritem : tstringlistitem;
  962. begin
  963. objectdf := nil;
  964. { verify if trying to create an instance of a class which contains
  965. non-implemented abstract methods }
  966. { first verify this class type, no class than exit }
  967. { also, this checking can only be done if the constructor is directly
  968. called, indirect constructor calls cannot be checked.
  969. }
  970. if assigned(methodpointer) then
  971. begin
  972. if (methodpointer.resulttype.def.deftype = objectdef) then
  973. objectdf:=tobjectdef(methodpointer.resulttype.def)
  974. else
  975. if (methodpointer.resulttype.def.deftype = classrefdef) and
  976. (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) and
  977. (methodpointer.nodetype in [typen,loadvmtaddrn]) then
  978. objectdf:=tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  979. end;
  980. if not assigned(objectdf) then
  981. exit;
  982. parents := tlinkedlist.create;
  983. AbstractMethodsList := tstringlist.create;
  984. { insert all parents in this class : the first item in the
  985. list will be the base parent of the class .
  986. }
  987. while assigned(objectdf) do
  988. begin
  989. objectinfo:=tobjectinfoitem.create(objectdf);
  990. parents.insert(objectinfo);
  991. objectdf := objectdf.childof;
  992. end;
  993. { now all parents are in the correct order
  994. insert all abstract methods in the list, and remove
  995. those which are overriden by parent classes.
  996. }
  997. objectinfo:=tobjectinfoitem(parents.first);
  998. while assigned(objectinfo) do
  999. begin
  1000. objectdf := objectinfo.objinfo;
  1001. if assigned(objectdf.symtable) then
  1002. objectdf.symtable.foreach(@verifyabstract,nil);
  1003. objectinfo:=tobjectinfoitem(objectinfo.next);
  1004. end;
  1005. if assigned(parents) then
  1006. parents.free;
  1007. { Finally give out a warning for each abstract method still in the list }
  1008. stritem := tstringlistitem(AbstractMethodsList.first);
  1009. if assigned(stritem) then
  1010. Message1(type_w_instance_with_abstract,objectdf.objrealname^);
  1011. while assigned(stritem) do
  1012. begin
  1013. if assigned(stritem.fpstr) then
  1014. Message1(sym_h_param_list,stritem.str);
  1015. stritem := tstringlistitem(stritem.next);
  1016. end;
  1017. if assigned(AbstractMethodsList) then
  1018. AbstractMethodsList.Free;
  1019. end;
  1020. function tcallnode.gen_self_tree_methodpointer:tnode;
  1021. var
  1022. hsym : tfieldvarsym;
  1023. begin
  1024. { find self field in methodpointer record }
  1025. hsym:=tfieldvarsym(trecorddef(methodpointertype.def).symtable.search('self'));
  1026. if not assigned(hsym) then
  1027. internalerror(200305251);
  1028. { Load tmehodpointer(right).self }
  1029. result:=csubscriptnode.create(
  1030. hsym,
  1031. ctypeconvnode.create_internal(right.getcopy,methodpointertype));
  1032. end;
  1033. function tcallnode.gen_self_tree:tnode;
  1034. var
  1035. selftree : tnode;
  1036. begin
  1037. selftree:=nil;
  1038. { inherited }
  1039. if (cnf_inherited in callnodeflags) then
  1040. selftree:=load_self_node
  1041. else
  1042. { constructors }
  1043. if (procdefinition.proctypeoption=potype_constructor) then
  1044. begin
  1045. { push 0 as self when allocation is needed }
  1046. if (methodpointer.resulttype.def.deftype=classrefdef) or
  1047. (cnf_new_call in callnodeflags) then
  1048. selftree:=cpointerconstnode.create(0,voidpointertype)
  1049. else
  1050. begin
  1051. if methodpointer.nodetype=typen then
  1052. selftree:=load_self_node
  1053. else
  1054. selftree:=methodpointer.getcopy;
  1055. end;
  1056. end
  1057. else
  1058. { Calling a static/class method }
  1059. if (po_classmethod in procdefinition.procoptions) or
  1060. (po_staticmethod in procdefinition.procoptions) then
  1061. begin
  1062. if (procdefinition.deftype<>procdef) then
  1063. internalerror(200305062);
  1064. if (oo_has_vmt in tprocdef(procdefinition)._class.objectoptions) then
  1065. begin
  1066. { we only need the vmt, loading self is not required and there is no
  1067. need to check for typen, because that will always get the
  1068. loadvmtaddrnode added }
  1069. selftree:=methodpointer.getcopy;
  1070. if methodpointer.resulttype.def.deftype<>classrefdef then
  1071. selftree:=cloadvmtaddrnode.create(selftree);
  1072. end
  1073. else
  1074. selftree:=cpointerconstnode.create(0,voidpointertype);
  1075. end
  1076. else
  1077. begin
  1078. if methodpointer.nodetype=typen then
  1079. selftree:=load_self_node
  1080. else
  1081. selftree:=methodpointer.getcopy;
  1082. end;
  1083. result:=selftree;
  1084. end;
  1085. function tcallnode.gen_vmt_tree:tnode;
  1086. var
  1087. vmttree : tnode;
  1088. begin
  1089. vmttree:=nil;
  1090. if not(procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1091. internalerror(200305051);
  1092. { inherited call, no create/destroy }
  1093. if (cnf_inherited in callnodeflags) then
  1094. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1095. else
  1096. { do not create/destroy when called from member function
  1097. without specifying self explicit }
  1098. if (cnf_member_call in callnodeflags) then
  1099. begin
  1100. if (methodpointer.resulttype.def.deftype=classrefdef) and
  1101. (procdefinition.proctypeoption=potype_constructor) then
  1102. vmttree:=methodpointer.getcopy
  1103. else
  1104. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1105. end
  1106. else
  1107. { constructor with extended syntax called from new }
  1108. if (cnf_new_call in callnodeflags) then
  1109. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1110. else
  1111. { destructor with extended syntax called from dispose }
  1112. if (cnf_dispose_call in callnodeflags) then
  1113. vmttree:=cloadvmtaddrnode.create(methodpointer.getcopy)
  1114. else
  1115. if (methodpointer.resulttype.def.deftype=classrefdef) then
  1116. begin
  1117. { constructor call via classreference => allocate memory }
  1118. if (procdefinition.proctypeoption=potype_constructor) and
  1119. is_class(tclassrefdef(methodpointer.resulttype.def).pointertype.def) then
  1120. begin
  1121. vmttree:=methodpointer.getcopy;
  1122. { Only a typenode can be passed when it is called with <class of xx>.create }
  1123. if vmttree.nodetype=typen then
  1124. vmttree:=cloadvmtaddrnode.create(vmttree);
  1125. end
  1126. else
  1127. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1128. end
  1129. else
  1130. { class }
  1131. if is_class(methodpointer.resulttype.def) then
  1132. begin
  1133. { destructor: release instance, flag(vmt)=1
  1134. constructor: direct call, do nothing, leave vmt=0 }
  1135. if (procdefinition.proctypeoption=potype_destructor) then
  1136. vmttree:=cpointerconstnode.create(1,voidpointertype)
  1137. else
  1138. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1139. end
  1140. else
  1141. { object }
  1142. begin
  1143. { destructor: direct call, no dispose, vmt=0
  1144. constructor: initialize object, load vmt }
  1145. if (procdefinition.proctypeoption=potype_constructor) then
  1146. { old styled inherited call? }
  1147. if (methodpointer.nodetype=typen) then
  1148. vmttree:=cpointerconstnode.create(0,voidpointertype)
  1149. else
  1150. vmttree:=cloadvmtaddrnode.create(ctypenode.create(methodpointer.resulttype))
  1151. else
  1152. vmttree:=cpointerconstnode.create(0,voidpointertype);
  1153. end;
  1154. result:=vmttree;
  1155. end;
  1156. procedure tcallnode.bind_parasym;
  1157. var
  1158. i : integer;
  1159. pt : tcallparanode;
  1160. oldppt : ^tcallparanode;
  1161. varargspara,
  1162. currpara : tparavarsym;
  1163. used_by_callnode : boolean;
  1164. hiddentree : tnode;
  1165. newstatement : tstatementnode;
  1166. temp : ttempcreatenode;
  1167. begin
  1168. pt:=tcallparanode(left);
  1169. oldppt:=@left;
  1170. { flag all callparanodes that belong to the varargs }
  1171. i:=paralength;
  1172. while (i>procdefinition.maxparacount) do
  1173. begin
  1174. include(pt.callparaflags,cpf_varargs_para);
  1175. oldppt:[email protected];
  1176. pt:=tcallparanode(pt.right);
  1177. dec(i);
  1178. end;
  1179. { skip varargs that are inserted by array of const }
  1180. while assigned(pt) and
  1181. (cpf_varargs_para in pt.callparaflags) do
  1182. pt:=tcallparanode(pt.right);
  1183. { process normal parameters and insert hidden parameters }
  1184. for i:=procdefinition.paras.count-1 downto 0 do
  1185. begin
  1186. currpara:=tparavarsym(procdefinition.paras[i]);
  1187. if vo_is_hidden_para in currpara.varoptions then
  1188. begin
  1189. { generate hidden tree }
  1190. used_by_callnode:=false;
  1191. hiddentree:=nil;
  1192. if (vo_is_funcret in currpara.varoptions) then
  1193. begin
  1194. { Generate funcretnode if not specified }
  1195. if assigned(funcretnode) then
  1196. begin
  1197. hiddentree:=funcretnode.getcopy;
  1198. end
  1199. else
  1200. begin
  1201. hiddentree:=internalstatements(newstatement);
  1202. { need to use resulttype instead of procdefinition.rettype,
  1203. because they can be different }
  1204. temp:=ctempcreatenode.create(resulttype,resulttype.def.size,tt_persistent,false);
  1205. addstatement(newstatement,temp);
  1206. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1207. addstatement(newstatement,ctemprefnode.create(temp));
  1208. end;
  1209. end
  1210. else
  1211. if vo_is_high_para in currpara.varoptions then
  1212. begin
  1213. if not assigned(pt) or
  1214. (i=0) then
  1215. internalerror(200304082);
  1216. { we need the information of the previous parameter }
  1217. hiddentree:=gen_high_tree(pt.left,tparavarsym(procdefinition.paras[i-1]).vartype.def);
  1218. end
  1219. else
  1220. if vo_is_self in currpara.varoptions then
  1221. begin
  1222. if assigned(right) then
  1223. hiddentree:=gen_self_tree_methodpointer
  1224. else
  1225. hiddentree:=gen_self_tree;
  1226. end
  1227. else
  1228. if vo_is_vmt in currpara.varoptions then
  1229. begin
  1230. hiddentree:=gen_vmt_tree;
  1231. end
  1232. {$ifdef powerpc}
  1233. else
  1234. if vo_is_syscall_lib in currpara.varoptions then
  1235. begin
  1236. { lib parameter has no special type but proccalloptions must be a syscall }
  1237. hiddentree:=cloadnode.create(tprocdef(procdefinition).libsym,tprocdef(procdefinition).libsym.owner);
  1238. end
  1239. {$endif powerpc}
  1240. else
  1241. if vo_is_parentfp in currpara.varoptions then
  1242. begin
  1243. if not(assigned(procdefinition.owner.defowner)) then
  1244. internalerror(200309287);
  1245. hiddentree:=cloadparentfpnode.create(tprocdef(procdefinition.owner.defowner));
  1246. end;
  1247. { add the hidden parameter }
  1248. if not assigned(hiddentree) then
  1249. internalerror(200304073);
  1250. { Already insert para and let the previous node point to
  1251. this new node }
  1252. pt:=ccallparanode.create(hiddentree,oldppt^);
  1253. pt.used_by_callnode:=used_by_callnode;
  1254. oldppt^:=pt;
  1255. end;
  1256. if not assigned(pt) then
  1257. internalerror(200310052);
  1258. pt.parasym:=currpara;
  1259. oldppt:[email protected];
  1260. pt:=tcallparanode(pt.right);
  1261. end;
  1262. { Create parasyms for varargs, first count the number of varargs paras,
  1263. then insert the parameters with numbering in reverse order. The SortParas
  1264. will set the correct order at the end}
  1265. pt:=tcallparanode(left);
  1266. i:=0;
  1267. while assigned(pt) do
  1268. begin
  1269. if cpf_varargs_para in pt.callparaflags then
  1270. inc(i);
  1271. pt:=tcallparanode(pt.right);
  1272. end;
  1273. if (i>0) then
  1274. begin
  1275. varargsparas:=tvarargsparalist.create;
  1276. pt:=tcallparanode(left);
  1277. while assigned(pt) do
  1278. begin
  1279. if cpf_varargs_para in pt.callparaflags then
  1280. begin
  1281. varargspara:=tparavarsym.create('va'+tostr(i),i,vs_value,pt.resulttype,[]);
  1282. dec(i);
  1283. { varargspara is left-right, use insert
  1284. instead of concat }
  1285. varargsparas.add(varargspara);
  1286. pt.parasym:=varargspara;
  1287. end;
  1288. pt:=tcallparanode(pt.right);
  1289. end;
  1290. varargsparas.sortparas;
  1291. end;
  1292. end;
  1293. function tcallnode.det_resulttype:tnode;
  1294. var
  1295. candidates : tcallcandidates;
  1296. oldcallnode : tcallnode;
  1297. hpt : tnode;
  1298. pt : tcallparanode;
  1299. lastpara : longint;
  1300. paraidx,
  1301. cand_cnt : integer;
  1302. i : longint;
  1303. method_must_be_valid,
  1304. is_const : boolean;
  1305. label
  1306. errorexit;
  1307. begin
  1308. result:=nil;
  1309. candidates:=nil;
  1310. oldcallnode:=aktcallnode;
  1311. aktcallnode:=self;
  1312. { determine length of parameter list }
  1313. pt:=tcallparanode(left);
  1314. paralength:=0;
  1315. while assigned(pt) do
  1316. begin
  1317. inc(paralength);
  1318. pt:=tcallparanode(pt.right);
  1319. end;
  1320. { determine the type of the parameters }
  1321. if assigned(left) then
  1322. begin
  1323. tcallparanode(left).get_paratype;
  1324. if codegenerror then
  1325. goto errorexit;
  1326. end;
  1327. if assigned(methodpointer) then
  1328. begin
  1329. resulttypepass(methodpointer);
  1330. maybe_load_para_in_temp(methodpointer);
  1331. end;
  1332. { procedure variable ? }
  1333. if assigned(right) then
  1334. begin
  1335. set_varstate(right,vs_used,true);
  1336. resulttypepass(right);
  1337. if codegenerror then
  1338. exit;
  1339. procdefinition:=tabstractprocdef(right.resulttype.def);
  1340. { Compare parameters from right to left }
  1341. paraidx:=procdefinition.Paras.count-1;
  1342. { Skip default parameters }
  1343. if not(po_varargs in procdefinition.procoptions) then
  1344. begin
  1345. { ignore hidden parameters }
  1346. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1347. dec(paraidx);
  1348. for i:=1 to procdefinition.maxparacount-paralength do
  1349. begin
  1350. if paraidx<0 then
  1351. internalerror(200402261);
  1352. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1353. begin
  1354. CGMessage(parser_e_wrong_parameter_size);
  1355. goto errorexit;
  1356. end;
  1357. dec(paraidx);
  1358. end;
  1359. end;
  1360. while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1361. dec(paraidx);
  1362. pt:=tcallparanode(left);
  1363. lastpara:=paralength;
  1364. while (paraidx>=0) and assigned(pt) do
  1365. begin
  1366. { only goto next para if we're out of the varargs }
  1367. if not(po_varargs in procdefinition.procoptions) or
  1368. (lastpara<=procdefinition.maxparacount) then
  1369. begin
  1370. repeat
  1371. dec(paraidx);
  1372. until (paraidx<0) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1373. end;
  1374. pt:=tcallparanode(pt.right);
  1375. dec(lastpara);
  1376. end;
  1377. if assigned(pt) or
  1378. ((paraidx>=0) and
  1379. not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)) then
  1380. begin
  1381. if assigned(pt) then
  1382. aktfilepos:=pt.fileinfo;
  1383. CGMessage(parser_e_wrong_parameter_size);
  1384. goto errorexit;
  1385. end;
  1386. end
  1387. else
  1388. { not a procedure variable }
  1389. begin
  1390. { do we know the procedure to call ? }
  1391. if not(assigned(procdefinition)) then
  1392. begin
  1393. candidates:=tcallcandidates.create(symtableprocentry,symtableproc,left,(nf_isproperty in flags));
  1394. { no procedures found? then there is something wrong
  1395. with the parameter size or the procedures are
  1396. not accessible }
  1397. if candidates.count=0 then
  1398. begin
  1399. { when it's an auto inherited call and there
  1400. is no procedure found, but the procedures
  1401. were defined with overload directive and at
  1402. least two procedures are defined then we ignore
  1403. this inherited by inserting a nothingn. Only
  1404. do this ugly hack in Delphi mode as it looks more
  1405. like a bug. It's also not documented }
  1406. if (m_delphi in aktmodeswitches) and
  1407. (cnf_anon_inherited in callnodeflags) and
  1408. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1409. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1410. (symtableprocentry.procdef_count>=2) then
  1411. result:=cnothingnode.create
  1412. else
  1413. begin
  1414. { in tp mode we can try to convert to procvar if
  1415. there are no parameters specified. Only try it
  1416. when there is only one proc definition, else the
  1417. loadnode will give a strange error }
  1418. if not(assigned(left)) and
  1419. not(cnf_inherited in callnodeflags) and
  1420. (m_tp_procvar in aktmodeswitches) and
  1421. (symtableprocentry.procdef_count=1) then
  1422. begin
  1423. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1424. if assigned(methodpointer) then
  1425. tloadnode(hpt).set_mp(methodpointer.getcopy);
  1426. resulttypepass(hpt);
  1427. result:=hpt;
  1428. end
  1429. else
  1430. begin
  1431. if assigned(left) then
  1432. aktfilepos:=left.fileinfo;
  1433. CGMessage(parser_e_wrong_parameter_size);
  1434. symtableprocentry.write_parameter_lists(nil);
  1435. end;
  1436. end;
  1437. goto errorexit;
  1438. end;
  1439. { Retrieve information about the candidates }
  1440. candidates.get_information;
  1441. {$ifdef EXTDEBUG}
  1442. { Display info when multiple candidates are found }
  1443. if candidates.count>1 then
  1444. candidates.dump_info(V_Debug);
  1445. {$endif EXTDEBUG}
  1446. { Choose the best candidate and count the number of
  1447. candidates left }
  1448. cand_cnt:=candidates.choose_best(procdefinition);
  1449. { All parameters are checked, check if there are any
  1450. procedures left }
  1451. if cand_cnt>0 then
  1452. begin
  1453. { Multiple candidates left? }
  1454. if cand_cnt>1 then
  1455. begin
  1456. CGMessage(type_e_cant_choose_overload_function);
  1457. {$ifdef EXTDEBUG}
  1458. candidates.dump_info(V_Hint);
  1459. {$else EXTDEBUG}
  1460. candidates.list(false);
  1461. {$endif EXTDEBUG}
  1462. { we'll just use the first candidate to make the
  1463. call }
  1464. end;
  1465. { assign procdefinition }
  1466. if symtableproc=nil then
  1467. symtableproc:=procdefinition.owner;
  1468. { update browser information }
  1469. if make_ref then
  1470. begin
  1471. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1472. inc(tprocdef(procdefinition).refcount);
  1473. if tprocdef(procdefinition).defref=nil then
  1474. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1475. end;
  1476. end
  1477. else
  1478. begin
  1479. { No candidates left, this must be a type error,
  1480. because wrong size is already checked. procdefinition
  1481. is filled with the first (random) definition that is
  1482. found. We use this definition to display a nice error
  1483. message that the wrong type is passed }
  1484. candidates.find_wrong_para;
  1485. candidates.list(true);
  1486. {$ifdef EXTDEBUG}
  1487. candidates.dump_info(V_Hint);
  1488. {$endif EXTDEBUG}
  1489. { We can not proceed, release all procs and exit }
  1490. candidates.free;
  1491. goto errorexit;
  1492. end;
  1493. candidates.free;
  1494. end; { end of procedure to call determination }
  1495. end;
  1496. { add needed default parameters }
  1497. if assigned(procdefinition) and
  1498. (paralength<procdefinition.maxparacount) then
  1499. begin
  1500. paraidx:=0;
  1501. i:=0;
  1502. while (i<paralength) do
  1503. begin
  1504. if paraidx>=procdefinition.Paras.count then
  1505. internalerror(200306181);
  1506. if not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) then
  1507. inc(i);
  1508. inc(paraidx);
  1509. end;
  1510. while (paraidx<procdefinition.paras.count) and (vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions) do
  1511. inc(paraidx);
  1512. while (paraidx<procdefinition.paras.count) do
  1513. begin
  1514. if not assigned(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym) then
  1515. internalerror(200212142);
  1516. left:=ccallparanode.create(genconstsymtree(
  1517. tconstsym(tparavarsym(procdefinition.paras[paraidx]).defaultconstsym)),left);
  1518. { Ignore vs_hidden parameters }
  1519. repeat
  1520. inc(paraidx);
  1521. until (paraidx>=procdefinition.paras.count) or not(vo_is_hidden_para in tparavarsym(procdefinition.paras[paraidx]).varoptions);
  1522. end;
  1523. end;
  1524. { handle predefined procedures }
  1525. is_const:=(po_internconst in procdefinition.procoptions) and
  1526. ((block_type in [bt_const,bt_type]) or
  1527. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1528. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1529. begin
  1530. if assigned(left) then
  1531. begin
  1532. { ptr and settextbuf needs two args }
  1533. if assigned(tcallparanode(left).right) then
  1534. begin
  1535. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1536. left:=nil;
  1537. end
  1538. else
  1539. begin
  1540. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1541. tcallparanode(left).left:=nil;
  1542. end;
  1543. end
  1544. else
  1545. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1546. result:=hpt;
  1547. goto errorexit;
  1548. end;
  1549. { ensure that the result type is set }
  1550. if not(cnf_restypeset in callnodeflags) then
  1551. begin
  1552. { constructors return their current class type, not the type where the
  1553. constructor is declared, this can be different because of inheritance }
  1554. if (procdefinition.proctypeoption=potype_constructor) and
  1555. assigned(methodpointer) and
  1556. assigned(methodpointer.resulttype.def) and
  1557. (methodpointer.resulttype.def.deftype=classrefdef) then
  1558. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype
  1559. else
  1560. resulttype:=procdefinition.rettype;
  1561. end
  1562. else
  1563. resulttype:=restype;
  1564. {if resulttype.def.needs_inittable then
  1565. include(current_procinfo.flags,pi_needs_implicit_finally);}
  1566. if assigned(methodpointer) then
  1567. begin
  1568. { when methodpointer is a callnode we must load it first into a
  1569. temp to prevent the processing callnode twice }
  1570. if (methodpointer.nodetype=calln) then
  1571. internalerror(200405121);
  1572. { direct call to inherited abstract method, then we
  1573. can already give a error in the compiler instead
  1574. of a runtime error }
  1575. if (cnf_inherited in callnodeflags) and
  1576. (po_abstractmethod in procdefinition.procoptions) then
  1577. CGMessage(cg_e_cant_call_abstract_method);
  1578. { if an inherited con- or destructor should be }
  1579. { called in a con- or destructor then a warning }
  1580. { will be made }
  1581. { con- and destructors need a pointer to the vmt }
  1582. if (cnf_inherited in callnodeflags) and
  1583. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1584. is_object(methodpointer.resulttype.def) and
  1585. not(current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1586. CGMessage(cg_w_member_cd_call_from_method);
  1587. if methodpointer.nodetype<>typen then
  1588. begin
  1589. { Remove all postfix operators }
  1590. hpt:=methodpointer;
  1591. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1592. hpt:=tunarynode(hpt).left;
  1593. if (procdefinition.proctypeoption=potype_constructor) and
  1594. assigned(symtableproc) and
  1595. (symtableproc.symtabletype=withsymtable) and
  1596. (tnode(twithsymtable(symtableproc).withrefnode).nodetype=temprefn) then
  1597. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1598. { R.Init then R will be initialized by the constructor,
  1599. Also allow it for simple loads }
  1600. if (procdefinition.proctypeoption=potype_constructor) or
  1601. ((hpt.nodetype=loadn) and
  1602. (
  1603. (methodpointer.resulttype.def.deftype=classrefdef) or
  1604. (
  1605. (methodpointer.resulttype.def.deftype=objectdef) and
  1606. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1607. )
  1608. )
  1609. ) then
  1610. method_must_be_valid:=false
  1611. else
  1612. method_must_be_valid:=true;
  1613. set_varstate(methodpointer,vs_used,method_must_be_valid);
  1614. { The object is already used if it is called once }
  1615. if (hpt.nodetype=loadn) and
  1616. (tloadnode(hpt).symtableentry.typ in [localvarsym,paravarsym,globalvarsym]) then
  1617. tabstractvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  1618. end;
  1619. { if we are calling the constructor check for abstract
  1620. methods. Ignore inherited and member calls, because the
  1621. class is then already created }
  1622. if (procdefinition.proctypeoption=potype_constructor) and
  1623. not(cnf_inherited in callnodeflags) and
  1624. not(cnf_member_call in callnodeflags) then
  1625. verifyabstractcalls;
  1626. end
  1627. else
  1628. begin
  1629. { When this is method the methodpointer must be available }
  1630. if (right=nil) and
  1631. (procdefinition.owner.symtabletype=objectsymtable) then
  1632. internalerror(200305061);
  1633. end;
  1634. { Change loading of array of const to varargs }
  1635. if assigned(left) and
  1636. is_array_of_const(tparavarsym(procdefinition.paras[procdefinition.paras.count-1]).vartype.def) and
  1637. (procdefinition.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  1638. convert_carg_array_of_const;
  1639. { bind parasyms to the callparanodes and insert hidden parameters }
  1640. bind_parasym;
  1641. { methodpointer is only needed for virtual calls, and
  1642. it should then be loaded with the VMT }
  1643. if (po_virtualmethod in procdefinition.procoptions) and
  1644. not(assigned(methodpointer) and
  1645. (methodpointer.nodetype=typen)) then
  1646. begin
  1647. if not assigned(methodpointer) then
  1648. internalerror(200305063);
  1649. if (methodpointer.resulttype.def.deftype<>classrefdef) then
  1650. begin
  1651. methodpointer:=cloadvmtaddrnode.create(methodpointer);
  1652. resulttypepass(methodpointer);
  1653. end;
  1654. end
  1655. else
  1656. begin
  1657. { not needed anymore }
  1658. methodpointer.free;
  1659. methodpointer:=nil;
  1660. end;
  1661. { insert type conversions for parameters }
  1662. if assigned(left) then
  1663. tcallparanode(left).insert_typeconv(true);
  1664. errorexit:
  1665. aktcallnode:=oldcallnode;
  1666. end;
  1667. procedure tcallnode.order_parameters;
  1668. var
  1669. hp,hpcurr,hpnext,hpfirst,hpprev : tcallparanode;
  1670. currloc : tcgloc;
  1671. begin
  1672. hpfirst:=nil;
  1673. hpcurr:=tcallparanode(left);
  1674. while assigned(hpcurr) do
  1675. begin
  1676. { pull out }
  1677. hpnext:=tcallparanode(hpcurr.right);
  1678. { pull in at the correct place.
  1679. Used order:
  1680. 1. LOC_REFERENCE with smallest offset (x86 only)
  1681. 2. LOC_REFERENCE with most registers
  1682. 3. LOC_REGISTER with most registers
  1683. For the moment we only look at the first parameter field. Combining it
  1684. with multiple parameter fields will make things a lot complexer (PFV) }
  1685. if not assigned(hpcurr.parasym.paraloc[callerside].location) then
  1686. internalerror(200412152);
  1687. currloc:=hpcurr.parasym.paraloc[callerside].location^.loc;
  1688. hpprev:=nil;
  1689. hp:=hpfirst;
  1690. while assigned(hp) do
  1691. begin
  1692. case currloc of
  1693. LOC_REFERENCE :
  1694. begin
  1695. case hp.parasym.paraloc[callerside].location^.loc of
  1696. LOC_REFERENCE :
  1697. begin
  1698. { Offset is calculated like:
  1699. sub esp,12
  1700. mov [esp+8],para3
  1701. mov [esp+4],para2
  1702. mov [esp],para1
  1703. call function
  1704. That means the for pushes the para with the
  1705. highest offset (see para3) needs to be pushed first
  1706. }
  1707. if (hpcurr.registersint>hp.registersint)
  1708. {$ifdef x86}
  1709. or (hpcurr.parasym.paraloc[callerside].location^.reference.offset>hp.parasym.paraloc[callerside].location^.reference.offset)
  1710. {$endif x86}
  1711. then
  1712. break;
  1713. end;
  1714. LOC_REGISTER,
  1715. LOC_FPUREGISTER :
  1716. break;
  1717. end;
  1718. end;
  1719. LOC_FPUREGISTER,
  1720. LOC_REGISTER :
  1721. begin
  1722. if (hp.parasym.paraloc[callerside].location^.loc=currloc) and
  1723. (hpcurr.registersint>hp.registersint) then
  1724. break;
  1725. end;
  1726. end;
  1727. hpprev:=hp;
  1728. hp:=tcallparanode(hp.right);
  1729. end;
  1730. hpcurr.right:=hp;
  1731. if assigned(hpprev) then
  1732. hpprev.right:=hpcurr
  1733. else
  1734. hpfirst:=hpcurr;
  1735. { next }
  1736. hpcurr:=hpnext;
  1737. end;
  1738. left:=hpfirst;
  1739. end;
  1740. function tcallnode.replaceparaload(var n: tnode; arg: pointer): foreachnoderesult;
  1741. var
  1742. paras: tcallparanode;
  1743. temp: tnode;
  1744. begin
  1745. result := fen_false;
  1746. n.fileinfo := pfileposinfo(arg)^;
  1747. if (n.nodetype = loadn) then
  1748. begin
  1749. case tloadnode(n).symtableentry.typ of
  1750. paravarsym :
  1751. begin
  1752. paras := tcallparanode(left);
  1753. while assigned(paras) and
  1754. (paras.parasym <> tloadnode(n).symtableentry) do
  1755. paras := tcallparanode(paras.right);
  1756. if assigned(paras) then
  1757. begin
  1758. n.free;
  1759. n := paras.left.getcopy;
  1760. resulttypepass(n);
  1761. result := fen_true;
  1762. end;
  1763. end;
  1764. localvarsym :
  1765. begin
  1766. { local? }
  1767. if (tloadnode(n).symtableentry.owner <> tprocdef(procdefinition).localst) then
  1768. exit;
  1769. if (tloadnode(n).symtableentry.indexnr >= inlinelocals.count) or
  1770. not assigned(inlinelocals[tloadnode(n).symtableentry.indexnr]) then
  1771. internalerror(20040720);
  1772. temp := tnode(inlinelocals[tloadnode(n).symtableentry.indexnr]).getcopy;
  1773. n.free;
  1774. n := temp;
  1775. resulttypepass(n);
  1776. result := fen_true;
  1777. end;
  1778. end;
  1779. end;
  1780. end;
  1781. type
  1782. ptempnodes = ^ttempnodes;
  1783. ttempnodes = record
  1784. createstatement, deletestatement: tstatementnode;
  1785. end;
  1786. procedure tcallnode.createlocaltemps(p:TNamedIndexItem;arg:pointer);
  1787. var
  1788. tempinfo: ptempnodes absolute arg;
  1789. tempnode: ttempcreatenode;
  1790. begin
  1791. if (tsymentry(p).typ <> localvarsym) then
  1792. exit;
  1793. if (p.indexnr >= inlinelocals.count) then
  1794. inlinelocals.count:=p.indexnr+10;
  1795. if (vo_is_funcret in tabstractvarsym(p).varoptions) and
  1796. assigned(funcretnode) then
  1797. begin
  1798. if node_complexity(funcretnode) > 1 then
  1799. begin
  1800. { can this happen? }
  1801. { we may have to replace the funcretnode with the address of funcretnode }
  1802. { loaded in a temp in this case, because the expression may e.g. contain }
  1803. { a global variable that gets changed inside the function }
  1804. internalerror(2004072101);
  1805. end;
  1806. inlinelocals[tabstractvarsym(p).indexnr] := funcretnode.getcopy
  1807. end
  1808. else
  1809. begin
  1810. tempnode := ctempcreatenode.create(tabstractvarsym(p).vartype,tabstractvarsym(p).vartype.def.size,tt_persistent,tabstractvarsym(p).varregable<>vr_none);
  1811. addstatement(tempinfo^.createstatement,tempnode);
  1812. if assigned(tlocalvarsym(p).defaultconstsym) then
  1813. begin
  1814. { warning: duplicate from psub.pas:initializevars() -> must refactor }
  1815. addstatement(tempinfo^.createstatement,cassignmentnode.create(
  1816. ctemprefnode.create(tempnode),
  1817. cloadnode.create(tlocalvarsym(p).defaultconstsym,tlocalvarsym(p).defaultconstsym.owner)));
  1818. end;
  1819. if (vo_is_funcret in tlocalvarsym(p).varoptions) then
  1820. begin
  1821. funcretnode := ctemprefnode.create(tempnode);
  1822. addstatement(tempinfo^.deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  1823. end
  1824. else
  1825. addstatement(tempinfo^.deletestatement,ctempdeletenode.create(tempnode));
  1826. inlinelocals[p.indexnr] := ctemprefnode.create(tempnode);
  1827. end;
  1828. end;
  1829. procedure tcallnode.createinlineparas(var createstatement, deletestatement: tstatementnode);
  1830. var
  1831. para: tcallparanode;
  1832. tempnode: ttempcreatenode;
  1833. tempnodes: ttempnodes;
  1834. begin
  1835. { parameters }
  1836. para := tcallparanode(left);
  1837. while assigned(para) do
  1838. begin
  1839. if (para.parasym.typ = paravarsym) and
  1840. { para.left will already be the same as funcretnode in the following case, so don't change }
  1841. (not(vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1842. (not assigned(funcretnode))) then
  1843. begin
  1844. { create temps for value parameters, function result and also for }
  1845. { const parameters which are passed by value instead of by reference }
  1846. if (vo_is_funcret in tparavarsym(para.parasym).varoptions) or
  1847. (para.parasym.varspez = vs_value) or
  1848. ((para.parasym.varspez = vs_const) and
  1849. (not paramanager.push_addr_param(vs_const,para.left.resulttype.def,procdefinition.proccalloption) or
  1850. { the problem is that we can't take the address of a function result :( }
  1851. (node_complexity(para.left) >= NODE_COMPLEXITY_INF))) then
  1852. begin
  1853. { in theory, this is always regable, but ncgcall can't }
  1854. { handle it yet in all situations (JM) }
  1855. tempnode := ctempcreatenode.create(para.left.resulttype,para.left.resulttype.def.size,tt_persistent,tparavarsym(para.parasym).varregable <> vr_none);
  1856. addstatement(createstatement,tempnode);
  1857. { assign the value of the parameter to the temp, except in case of the function result }
  1858. { (in that case, para.left is a block containing the creation of a new temp, while we }
  1859. { only need a temprefnode, so delete the old stuff) }
  1860. if not(vo_is_funcret in tparavarsym(para.parasym).varoptions) then
  1861. begin
  1862. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  1863. para.left));
  1864. para.left := ctemprefnode.create(tempnode);
  1865. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  1866. end
  1867. else
  1868. begin
  1869. if not(assigned(funcretnode)) then
  1870. funcretnode := ctemprefnode.create(tempnode);
  1871. para.left.free;
  1872. para.left := ctemprefnode.create(tempnode);
  1873. addstatement(deletestatement,ctempdeletenode.create_normal_temp(tempnode));
  1874. end
  1875. end
  1876. else if (node_complexity(para.left) > 1) then
  1877. begin
  1878. tempnode := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent,tparavarsym(para.parasym).varregable<>vr_none);
  1879. addstatement(createstatement,tempnode);
  1880. addstatement(createstatement,cassignmentnode.create(ctemprefnode.create(tempnode),
  1881. caddrnode.create_internal(para.left)));
  1882. para.left := ctypeconvnode.create_internal(cderefnode.create(ctemprefnode.create(tempnode)),para.left.resulttype);
  1883. addstatement(deletestatement,ctempdeletenode.create(tempnode));
  1884. end;
  1885. para := tcallparanode(para.right);
  1886. end;
  1887. end;
  1888. { local variables }
  1889. if not assigned(tprocdef(procdefinition).localst) or
  1890. (tprocdef(procdefinition).localst.symindex.count = 0) then
  1891. exit;
  1892. tempnodes.createstatement := createstatement;
  1893. tempnodes.deletestatement := deletestatement;
  1894. inlinelocals.count:=tprocdef(procdefinition).localst.symindex.count;
  1895. tprocdef(procdefinition).localst.foreach(@createlocaltemps,@tempnodes);
  1896. createstatement := tempnodes.createstatement;
  1897. deletestatement := tempnodes.deletestatement;
  1898. end;
  1899. function tcallnode.pass1_inline:tnode;
  1900. var
  1901. createstatement,deletestatement: tstatementnode;
  1902. createblock,deleteblock: tblocknode;
  1903. body : tnode;
  1904. i: longint;
  1905. begin
  1906. if not(assigned(tprocdef(procdefinition).inlininginfo) and
  1907. assigned(tprocdef(procdefinition).inlininginfo^.code)) then
  1908. internalerror(200412021);
  1909. { inherit flags }
  1910. current_procinfo.flags := current_procinfo.flags + ((procdefinition as tprocdef).inlininginfo^.flags*inherited_inlining_flags);
  1911. { create blocks for loading/deleting of local data }
  1912. createblock:=internalstatements(createstatement);
  1913. deleteblock:=internalstatements(deletestatement);
  1914. inlinelocals:=tlist.create;
  1915. { get copy of the procedure body }
  1916. body:=tprocdef(procdefinition).inlininginfo^.code.getcopy;
  1917. { replace complex parameters with temps }
  1918. createinlineparas(createstatement,deletestatement);
  1919. { replace the parameter loads with the parameter values }
  1920. foreachnode(body,@replaceparaload,@fileinfo);
  1921. { free the temps for the locals }
  1922. for i := 0 to inlinelocals.count-1 do
  1923. if assigned(inlinelocals[i]) then
  1924. tnode(inlinelocals[i]).free;
  1925. inlinelocals.free;
  1926. inlinelocals:=nil;
  1927. addstatement(createstatement,body);
  1928. addstatement(createstatement,deleteblock);
  1929. { set function result location if necessary }
  1930. if assigned(funcretnode) and
  1931. (cnf_return_value_used in callnodeflags) then
  1932. addstatement(createstatement,funcretnode.getcopy);
  1933. { consider it must not be inlined if called
  1934. again inside the args or itself }
  1935. procdefinition.proccalloption:=pocall_default;
  1936. firstpass(createblock);
  1937. procdefinition.proccalloption:=pocall_inline;
  1938. { return inlined block }
  1939. result := createblock;
  1940. end;
  1941. function tcallnode.pass_1 : tnode;
  1942. var
  1943. st : tsymtable;
  1944. begin
  1945. result:=nil;
  1946. { Can we inline the procedure? }
  1947. if (procdefinition.proccalloption=pocall_inline) and
  1948. (po_has_inlininginfo in procdefinition.procoptions) then
  1949. begin
  1950. { Check if we can inline the procedure when it references proc/var that
  1951. are not in the globally available }
  1952. st:=procdefinition.owner;
  1953. if (st.symtabletype=objectsymtable) then
  1954. st:=st.defowner.owner;
  1955. if (pi_uses_static_symtable in tprocdef(procdefinition).inlininginfo^.flags) and
  1956. (st.unitid<>0) then
  1957. begin
  1958. Comment(V_lineinfo+V_Debug,'Not inlining "'+tprocdef(procdefinition).procsym.realname+'", references static symtable');
  1959. end
  1960. else
  1961. begin
  1962. result:=pass1_inline;
  1963. exit;
  1964. end;
  1965. end;
  1966. { calculate the parameter info for the procdef }
  1967. if not procdefinition.has_paraloc_info then
  1968. begin
  1969. procdefinition.requiredargarea:=paramanager.create_paraloc_info(procdefinition,callerside);
  1970. procdefinition.has_paraloc_info:=true;
  1971. end;
  1972. { calculate the parameter size needed for this call include varargs if they are available }
  1973. if assigned(varargsparas) then
  1974. pushedparasize:=paramanager.create_varargs_paraloc_info(procdefinition,varargsparas)
  1975. else
  1976. pushedparasize:=procdefinition.requiredargarea;
  1977. { record maximum parameter size used in this proc }
  1978. current_procinfo.allocate_push_parasize(pushedparasize);
  1979. { work trough all parameters to get the register requirements }
  1980. if assigned(left) then
  1981. tcallparanode(left).det_registers;
  1982. { order parameters }
  1983. order_parameters;
  1984. if assigned(methodpointerinit) then
  1985. firstpass(methodpointerinit);
  1986. if assigned(methodpointerdone) then
  1987. firstpass(methodpointerdone);
  1988. { function result node }
  1989. if assigned(_funcretnode) then
  1990. firstpass(_funcretnode);
  1991. { procedure variable ? }
  1992. if assigned(right) then
  1993. begin
  1994. firstpass(right);
  1995. { procedure does a call }
  1996. if not (block_type in [bt_const,bt_type]) then
  1997. include(current_procinfo.flags,pi_do_call);
  1998. end
  1999. else
  2000. { not a procedure variable }
  2001. begin
  2002. if procdefinition.deftype<>procdef then
  2003. internalerror(200411071);
  2004. {$ifdef PASS2INLINE}
  2005. { calc the correture value for the register }
  2006. { handle predefined procedures }
  2007. if (procdefinition.proccalloption=pocall_inline) then
  2008. begin
  2009. { inherit flags }
  2010. current_procinfo.flags := current_procinfo.flags + (tprocdef(procdefinition).inlininginfo^.flags*inherited_inlining_flags);
  2011. if assigned(methodpointer) then
  2012. CGMessage(cg_e_unable_inline_object_methods);
  2013. if assigned(right) then
  2014. CGMessage(cg_e_unable_inline_procvar);
  2015. if not assigned(inlinecode) then
  2016. begin
  2017. if assigned(tprocdef(procdefinition).inlininginfo^.code) then
  2018. inlinecode:=tprocdef(procdefinition).inlininginfo^.code.getcopy
  2019. else
  2020. CGMessage(cg_e_no_code_for_inline_stored);
  2021. if assigned(inlinecode) then
  2022. begin
  2023. { consider it has not inlined if called
  2024. again inside the args }
  2025. procdefinition.proccalloption:=pocall_default;
  2026. firstpass(inlinecode);
  2027. end;
  2028. end;
  2029. end
  2030. else
  2031. {$endif PASS2INLINE}
  2032. begin
  2033. if not (block_type in [bt_const,bt_type]) then
  2034. include(current_procinfo.flags,pi_do_call);
  2035. end;
  2036. end;
  2037. { implicit finally needed ? }
  2038. if resulttype.def.needs_inittable and
  2039. not paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) and
  2040. not assigned(funcretnode) then
  2041. include(current_procinfo.flags,pi_needs_implicit_finally);
  2042. { get a register for the return value }
  2043. if (not is_void(resulttype.def)) then
  2044. begin
  2045. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  2046. begin
  2047. expectloc:=LOC_REFERENCE;
  2048. end
  2049. else
  2050. { for win32 records returned in EDX:EAX, we
  2051. move them to memory after ... }
  2052. if (resulttype.def.deftype=recorddef) then
  2053. begin
  2054. expectloc:=LOC_REFERENCE;
  2055. end
  2056. else
  2057. { ansi/widestrings must be registered, so we can dispose them }
  2058. if is_ansistring(resulttype.def) or
  2059. is_widestring(resulttype.def) then
  2060. begin
  2061. expectloc:=LOC_REFERENCE;
  2062. registersint:=1;
  2063. end
  2064. else
  2065. { we have only to handle the result if it is used }
  2066. if (cnf_return_value_used in callnodeflags) then
  2067. begin
  2068. case resulttype.def.deftype of
  2069. enumdef,
  2070. orddef :
  2071. begin
  2072. if (procdefinition.proctypeoption=potype_constructor) then
  2073. begin
  2074. expectloc:=LOC_REGISTER;
  2075. registersint:=1;
  2076. end
  2077. else
  2078. begin
  2079. expectloc:=LOC_REGISTER;
  2080. if is_64bit(resulttype.def) then
  2081. registersint:=2
  2082. else
  2083. registersint:=1;
  2084. end;
  2085. end;
  2086. floatdef :
  2087. begin
  2088. expectloc:=LOC_FPUREGISTER;
  2089. {$ifdef cpufpemu}
  2090. if (cs_fp_emulation in aktmoduleswitches) then
  2091. registersint:=1
  2092. else
  2093. {$endif cpufpemu}
  2094. {$ifdef m68k}
  2095. if (tfloatdef(resulttype.def).typ=s32real) then
  2096. registersint:=1
  2097. else
  2098. {$endif m68k}
  2099. registersfpu:=1;
  2100. end;
  2101. else
  2102. begin
  2103. expectloc:=LOC_REGISTER;
  2104. registersint:=1;
  2105. end;
  2106. end;
  2107. end
  2108. else
  2109. expectloc:=LOC_VOID;
  2110. end
  2111. else
  2112. expectloc:=LOC_VOID;
  2113. {$ifdef m68k}
  2114. { we need one more address register for virtual calls on m68k }
  2115. if (po_virtualmethod in procdefinition.procoptions) then
  2116. inc(registersint);
  2117. {$endif m68k}
  2118. { a fpu can be used in any procedure !! }
  2119. {$ifdef i386}
  2120. registersfpu:=procdefinition.fpu_used;
  2121. {$endif i386}
  2122. { if this is a call to a method calc the registers }
  2123. if (methodpointer<>nil) then
  2124. begin
  2125. if methodpointer.nodetype<>typen then
  2126. begin
  2127. firstpass(methodpointer);
  2128. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2129. registersint:=max(methodpointer.registersint,registersint);
  2130. {$ifdef SUPPORT_MMX }
  2131. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2132. {$endif SUPPORT_MMX}
  2133. end;
  2134. end;
  2135. {$ifdef PASS2INLINE}
  2136. { determine the registers of the procedure variable }
  2137. { is this OK for inlined procs also ?? (PM) }
  2138. if assigned(inlinecode) then
  2139. begin
  2140. registersfpu:=max(inlinecode.registersfpu,registersfpu);
  2141. registersint:=max(inlinecode.registersint,registersint);
  2142. {$ifdef SUPPORT_MMX}
  2143. registersmmx:=max(inlinecode.registersmmx,registersmmx);
  2144. {$endif SUPPORT_MMX}
  2145. end;
  2146. {$endif PASS2INLINE}
  2147. { determine the registers of the procedure variable }
  2148. { is this OK for inlined procs also ?? (PM) }
  2149. if assigned(right) then
  2150. begin
  2151. registersfpu:=max(right.registersfpu,registersfpu);
  2152. registersint:=max(right.registersint,registersint);
  2153. {$ifdef SUPPORT_MMX}
  2154. registersmmx:=max(right.registersmmx,registersmmx);
  2155. {$endif SUPPORT_MMX}
  2156. end;
  2157. { determine the registers of the procedure }
  2158. if assigned(left) then
  2159. begin
  2160. registersfpu:=max(left.registersfpu,registersfpu);
  2161. registersint:=max(left.registersint,registersint);
  2162. {$ifdef SUPPORT_MMX}
  2163. registersmmx:=max(left.registersmmx,registersmmx);
  2164. {$endif SUPPORT_MMX}
  2165. end;
  2166. {$ifdef PASS2INLINE}
  2167. if assigned(inlinecode) then
  2168. procdefinition.proccalloption:=pocall_inline;
  2169. {$endif PASS2INLINE}
  2170. end;
  2171. {$ifdef state_tracking}
  2172. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2173. var hp:Tcallparanode;
  2174. value:Tnode;
  2175. begin
  2176. track_state_pass:=false;
  2177. hp:=Tcallparanode(left);
  2178. while assigned(hp) do
  2179. begin
  2180. if left.track_state_pass(exec_known) then
  2181. begin
  2182. left.resulttype.def:=nil;
  2183. do_resulttypepass(left);
  2184. end;
  2185. value:=aktstate.find_fact(hp.left);
  2186. if value<>nil then
  2187. begin
  2188. track_state_pass:=true;
  2189. hp.left.destroy;
  2190. hp.left:=value.getcopy;
  2191. do_resulttypepass(hp.left);
  2192. end;
  2193. hp:=Tcallparanode(hp.right);
  2194. end;
  2195. end;
  2196. {$endif}
  2197. function tcallnode.para_count:longint;
  2198. var
  2199. ppn : tcallparanode;
  2200. begin
  2201. result:=0;
  2202. ppn:=tcallparanode(left);
  2203. while assigned(ppn) do
  2204. begin
  2205. if not(assigned(ppn.parasym) and
  2206. (vo_is_hidden_para in ppn.parasym.varoptions)) then
  2207. inc(result);
  2208. ppn:=tcallparanode(ppn.right);
  2209. end;
  2210. end;
  2211. function tcallnode.docompare(p: tnode): boolean;
  2212. begin
  2213. docompare :=
  2214. inherited docompare(p) and
  2215. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2216. (procdefinition = tcallnode(p).procdefinition) and
  2217. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2218. (((cnf_restypeset in callnodeflags) and (cnf_restypeset in tcallnode(p).callnodeflags) and
  2219. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2220. (not(cnf_restypeset in callnodeflags) and not(cnf_restypeset in tcallnode(p).callnodeflags)));
  2221. end;
  2222. procedure tcallnode.printnodedata(var t:text);
  2223. begin
  2224. if assigned(procdefinition) and
  2225. (procdefinition.deftype=procdef) then
  2226. writeln(t,printnodeindention,'proc = ',tprocdef(procdefinition).fullprocname(true))
  2227. else
  2228. begin
  2229. if assigned(symtableprocentry) then
  2230. writeln(t,printnodeindention,'proc = ',symtableprocentry.name)
  2231. else
  2232. writeln(t,printnodeindention,'proc = <nil>');
  2233. end;
  2234. printnode(t,methodpointer);
  2235. printnode(t,right);
  2236. printnode(t,left);
  2237. end;
  2238. begin
  2239. ccallnode:=tcallnode;
  2240. ccallparanode:=tcallparanode;
  2241. end.
  2242. {
  2243. $Log$
  2244. Revision 1.273 2004-12-27 16:36:10 peter
  2245. * fix crash with callnode.ppuload when symtableproc=nil
  2246. Revision 1.272 2004/12/26 16:22:01 peter
  2247. * fix lineinfo for with blocks
  2248. Revision 1.271 2004/12/15 21:08:15 peter
  2249. * disable inlining across units when the inline procedure references
  2250. a variable or procedure in the static symtable
  2251. Revision 1.270 2004/12/15 19:30:16 peter
  2252. * give error when paraloc is not filled in order_parameter
  2253. Revision 1.269 2004/12/07 16:11:52 peter
  2254. * set vo_explicit_paraloc flag
  2255. Revision 1.268 2004/12/05 12:28:11 peter
  2256. * procvar handling for tp procvar mode fixed
  2257. * proc to procvar moved from addrnode to typeconvnode
  2258. * inlininginfo is now allocated only for inline routines that
  2259. can be inlined, introduced a new flag po_has_inlining_info
  2260. Revision 1.267 2004/12/03 16:07:04 peter
  2261. * fix crashes with nodeinlining
  2262. Revision 1.266 2004/12/02 19:26:14 peter
  2263. * disable pass2inline
  2264. Revision 1.265 2004/11/28 14:34:59 jonas
  2265. * only try to replace locals from the inlined procedure with temps,
  2266. cycle now works with -dNODEINLINE
  2267. Revision 1.264 2004/11/27 22:43:01 jonas
  2268. * fixed some bugs in the node inlining code due to the transition from
  2269. dynamic array to tlist
  2270. * fixed some register temp bugs (node inlining still does not work again
  2271. though)
  2272. Revision 1.263 2004/11/22 22:19:00 peter
  2273. * enabled pass1 inlining from Jonas
  2274. Revision 1.262 2004/11/22 22:01:19 peter
  2275. * fixed varargs
  2276. * replaced dynarray with tlist
  2277. Revision 1.261 2004/11/21 17:54:59 peter
  2278. * ttempcreatenode.create_reg merged into .create with parameter
  2279. whether a register is allowed
  2280. * funcret_paraloc renamed to funcretloc
  2281. Revision 1.260 2004/11/15 23:35:31 peter
  2282. * tparaitem removed, use tparavarsym instead
  2283. * parameter order is now calculated from paranr value in tparavarsym
  2284. Revision 1.259 2004/11/09 17:26:47 peter
  2285. * fixed wrong typecasts
  2286. Revision 1.258 2004/11/08 22:09:58 peter
  2287. * tvarsym splitted
  2288. Revision 1.257 2004/11/02 12:55:16 peter
  2289. * nf_internal flag for internal inserted typeconvs. This will
  2290. supress the generation of warning/hints
  2291. Revision 1.256 2004/11/01 18:16:48 peter
  2292. * removed wrong check for symtableprocentry
  2293. Revision 1.255 2004/11/01 16:58:57 peter
  2294. * give IE instead of crash when no procsym is passed for calln
  2295. Revision 1.254 2004/10/31 21:45:03 peter
  2296. * generic tlocation
  2297. * move tlocation to cgutils
  2298. Revision 1.253 2004/10/25 15:38:41 peter
  2299. * heap and heapsize removed
  2300. * checkpointer fixes
  2301. Revision 1.252 2004/10/15 09:14:16 mazen
  2302. - remove $IFDEF DELPHI and related code
  2303. - remove $IFDEF FPCPROCVAR and related code
  2304. Revision 1.251 2004/10/12 14:36:38 peter
  2305. * gen high tree makes copy in temp when there is a calln
  2306. Revision 1.250 2004/10/10 20:22:53 peter
  2307. * symtable allocation rewritten
  2308. * loading of parameters to local temps/regs cleanup
  2309. * regvar support for parameters
  2310. * regvar support for staticsymtable (main body)
  2311. Revision 1.249 2004/10/08 17:09:43 peter
  2312. * tvarsym.varregable added, split vo_regable from varoptions
  2313. Revision 1.248 2004/09/21 17:25:12 peter
  2314. * paraloc branch merged
  2315. Revision 1.247 2004/09/13 20:29:00 peter
  2316. * use realname for abstract procs found
  2317. Revision 1.246.4.1 2004/08/31 20:43:06 peter
  2318. * paraloc patch
  2319. Revision 1.246 2004/08/28 20:00:50 peter
  2320. * use objrealname in Message1
  2321. Revision 1.245 2004/08/22 10:17:13 peter
  2322. * fixed crash when passing array constructor to formal parameter
  2323. Revision 1.244 2004/08/14 14:50:42 florian
  2324. * fixed several sparc alignment issues
  2325. + Jonas' inline node patch; non functional yet
  2326. Revision 1.243 2004/07/16 19:45:15 jonas
  2327. + temps can now also hold fpu values in registers (take care with use,
  2328. bacause of the x86 fpu stack)
  2329. * fpu parameters to node-inlined procedures can now also be put in
  2330. a register
  2331. Revision 1.242 2004/07/15 21:02:05 jonas
  2332. * the condition for when to use a temp in case of reference var/const
  2333. parameters was inverse
  2334. Revision 1.241 2004/07/15 19:55:39 jonas
  2335. + (incomplete) node_complexity function to assess the complexity of a
  2336. tree
  2337. + support for inlining value and const parameters at the node level
  2338. (all procedures without local variables and without formal parameters
  2339. can now be inlined at the node level)
  2340. Revision 1.240 2004/07/12 09:14:04 jonas
  2341. * inline procedures at the node tree level, but only under some very
  2342. limited circumstances for now (only procedures, and only if they have
  2343. no or only vs_out/vs_var parameters).
  2344. * fixed ppudump for inline procedures
  2345. * fixed ppudump for ppc
  2346. Revision 1.239 2004/06/20 08:55:29 florian
  2347. * logs truncated
  2348. Revision 1.238 2004/06/16 20:07:08 florian
  2349. * dwarf branch merged
  2350. Revision 1.237 2004/05/25 18:51:49 peter
  2351. * fix tcallnode.getcopy. the parameters need to be copied after
  2352. methodpointerinit is copied
  2353. Revision 1.236 2004/05/24 17:31:51 peter
  2354. * fix passing of array to open array of array (bug 3113)
  2355. Revision 1.235 2004/05/23 18:28:41 peter
  2356. * methodpointer is loaded into a temp when it was a calln
  2357. Revision 1.234 2004/05/23 15:06:20 peter
  2358. * implicit_finally flag must be set in pass1
  2359. * add check whether the implicit frame is generated when expected
  2360. }