ncal.pas 103 KB

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