ncal.pas 120 KB

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