ncal.pas 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748
  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. node,nbas,
  25. {$ifdef state_tracking}
  26. nstate,
  27. {$endif state_tracking}
  28. symbase,symtype,symppu,symsym,symdef,symtable;
  29. type
  30. pcandidate = ^tcandidate;
  31. tcandidate = record
  32. next : pcandidate;
  33. data : tprocdef;
  34. wrongpara,
  35. firstpara : tparaitem;
  36. exact_count,
  37. equal_count,
  38. cl1_count,
  39. cl2_count,
  40. cl3_count,
  41. coper_count : integer; { should be signed }
  42. ordinal_distance : bestreal;
  43. invalid : boolean;
  44. wrongparanr : byte;
  45. end;
  46. tcallnode = class(tbinarynode)
  47. private
  48. paralength : smallint;
  49. function candidates_find:pcandidate;
  50. procedure candidates_free(procs:pcandidate);
  51. procedure candidates_list(procs:pcandidate;all:boolean);
  52. procedure candidates_get_information(procs:pcandidate);
  53. function candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  54. procedure candidates_find_wrong_para(procs:pcandidate);
  55. {$ifdef EXTDEBUG}
  56. procedure candidates_dump_info(lvl:longint;procs:pcandidate);
  57. {$endif EXTDEBUG}
  58. procedure bind_paraitem;
  59. public
  60. { the symbol containing the definition of the procedure }
  61. { to call }
  62. symtableprocentry : tprocsym;
  63. { symtable where the entry was found, needed for with support }
  64. symtableproc : tsymtable;
  65. { the definition of the procedure to call }
  66. procdefinition : tabstractprocdef;
  67. methodpointer : tnode;
  68. { separately specified resulttype for some compilerprocs (e.g. }
  69. { you can't have a function with an "array of char" resulttype }
  70. { the RTL) (JM) }
  71. restype: ttype;
  72. restypeset: boolean;
  73. { function return reference node, this is used to pass an already
  74. allocated reference for a ret_in_param return value }
  75. funcretrefnode : tnode;
  76. { only the processor specific nodes need to override this }
  77. { constructor }
  78. constructor create(l:tnode; v : tprocsym;st : tsymtable; mp : tnode);virtual;
  79. constructor createintern(const name: string; params: tnode);
  80. constructor createinternres(const name: string; params: tnode; const res: ttype);
  81. constructor createinternreturn(const name: string; params: tnode; returnnode : tnode);
  82. destructor destroy;override;
  83. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  84. procedure ppuwrite(ppufile:tcompilerppufile);override;
  85. procedure derefimpl;override;
  86. function getcopy : tnode;override;
  87. { Goes through all symbols in a class and subclasses and calls
  88. verify abstract for each .
  89. }
  90. procedure verifyabstractcalls;
  91. { called for each definition in a class and verifies if a method
  92. is abstract or not, if it is abstract, give out a warning
  93. }
  94. procedure verifyabstract(p : tnamedindexitem;arg:pointer);
  95. procedure insertintolist(l : tnodelist);override;
  96. function pass_1 : tnode;override;
  97. function det_resulttype:tnode;override;
  98. {$ifdef state_tracking}
  99. function track_state_pass(exec_known:boolean):boolean;override;
  100. {$endif state_tracking}
  101. function docompare(p: tnode): boolean; override;
  102. procedure set_procvar(procvar:tnode);
  103. private
  104. {$ifdef callparatemp}
  105. function extract_functioncall_paras: tblocknode;
  106. {$endif callparatemp}
  107. AbstractMethodsList : TStringList;
  108. end;
  109. tcallnodeclass = class of tcallnode;
  110. tcallparaflags = (
  111. { flags used by tcallparanode }
  112. cpf_exact_match_found,
  113. cpf_convlevel1found,
  114. cpf_convlevel2found,
  115. cpf_is_colon_para
  116. );
  117. tcallparanode = class(tbinarynode)
  118. callparaflags : set of tcallparaflags;
  119. paraitem : tparaitem;
  120. { only the processor specific nodes need to override this }
  121. { constructor }
  122. constructor create(expr,next : tnode);virtual;
  123. destructor destroy;override;
  124. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  125. procedure ppuwrite(ppufile:tcompilerppufile);override;
  126. procedure derefimpl;override;
  127. function getcopy : tnode;override;
  128. procedure insertintolist(l : tnodelist);override;
  129. procedure get_paratype;
  130. procedure insert_typeconv(do_count : boolean);
  131. procedure det_registers;
  132. procedure firstcallparan(do_count : boolean);
  133. procedure secondcallparan(push_from_left_to_right:boolean;calloption:tproccalloption;
  134. para_alignment,para_offset : longint);virtual;abstract;
  135. function docompare(p: tnode): boolean; override;
  136. end;
  137. tcallparanodeclass = class of tcallparanode;
  138. tprocinlinenode = class(tnode)
  139. inlinetree : tnode;
  140. inlineprocdef : tprocdef;
  141. retoffset,para_offset,para_size : longint;
  142. constructor create(p:tprocdef);virtual;
  143. destructor destroy;override;
  144. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  145. procedure ppuwrite(ppufile:tcompilerppufile);override;
  146. procedure derefimpl;override;
  147. function getcopy : tnode;override;
  148. function det_resulttype : tnode;override;
  149. procedure insertintolist(l : tnodelist);override;
  150. function pass_1 : tnode;override;
  151. function docompare(p: tnode): boolean; override;
  152. end;
  153. tprocinlinenodeclass = class of tprocinlinenode;
  154. function reverseparameters(p: tcallparanode): tcallparanode;
  155. var
  156. ccallnode : tcallnodeclass;
  157. ccallparanode : tcallparanodeclass;
  158. cprocinlinenode : tprocinlinenodeclass;
  159. implementation
  160. uses
  161. systems,
  162. verbose,globals,
  163. symconst,paramgr,defutil,defcmp,
  164. htypechk,pass_1,cpubase,
  165. ncnv,nld,ninl,nadd,ncon,nmem,
  166. nutils,
  167. rgobj,cginfo,cgbase
  168. ;
  169. type
  170. tobjectinfoitem = class(tlinkedlistitem)
  171. objinfo : tobjectdef;
  172. constructor create(def : tobjectdef);
  173. end;
  174. {****************************************************************************
  175. HELPERS
  176. ****************************************************************************}
  177. function reverseparameters(p: tcallparanode): tcallparanode;
  178. var
  179. hp1, hp2: tcallparanode;
  180. begin
  181. hp1:=nil;
  182. while assigned(p) do
  183. begin
  184. { pull out }
  185. hp2:=p;
  186. p:=tcallparanode(p.right);
  187. { pull in }
  188. hp2.right:=hp1;
  189. hp1:=hp2;
  190. end;
  191. reverseparameters:=hp1;
  192. end;
  193. function gen_high_tree(p:tnode;openstring:boolean):tnode;
  194. var
  195. temp: tnode;
  196. len : integer;
  197. loadconst : boolean;
  198. hightree : tnode;
  199. begin
  200. len:=-1;
  201. loadconst:=true;
  202. hightree:=nil;
  203. case p.resulttype.def.deftype of
  204. arraydef :
  205. begin
  206. { handle via a normal inline in_high_x node }
  207. loadconst := false;
  208. hightree := geninlinenode(in_high_x,false,p.getcopy);
  209. { only substract low(array) if it's <> 0 }
  210. temp := geninlinenode(in_low_x,false,p.getcopy);
  211. resulttypepass(temp);
  212. if (temp.nodetype <> ordconstn) or
  213. (tordconstnode(temp).value <> 0) then
  214. hightree := caddnode.create(subn,hightree,temp)
  215. else
  216. temp.free;
  217. end;
  218. stringdef :
  219. begin
  220. if openstring then
  221. begin
  222. { handle via a normal inline in_high_x node }
  223. loadconst := false;
  224. hightree := geninlinenode(in_high_x,false,p.getcopy);
  225. end
  226. else
  227. begin
  228. { passing a string to an array of char }
  229. if (p.nodetype=stringconstn) then
  230. begin
  231. len:=str_length(p);
  232. if len>0 then
  233. dec(len);
  234. end
  235. else
  236. begin
  237. hightree:=caddnode.create(subn,geninlinenode(in_length_x,false,p.getcopy),
  238. cordconstnode.create(1,s32bittype,false));
  239. loadconst:=false;
  240. end;
  241. end;
  242. end;
  243. else
  244. len:=0;
  245. end;
  246. if loadconst then
  247. hightree:=cordconstnode.create(len,s32bittype,true)
  248. else
  249. begin
  250. if not assigned(hightree) then
  251. internalerror(200304071);
  252. hightree:=ctypeconvnode.create(hightree,s32bittype);
  253. end;
  254. result:=hightree;
  255. end;
  256. procedure search_class_overloads(aprocsym : tprocsym);
  257. { searches n in symtable of pd and all anchestors }
  258. var
  259. speedvalue : cardinal;
  260. srsym : tprocsym;
  261. s : string;
  262. objdef : tobjectdef;
  263. begin
  264. if aprocsym.overloadchecked then
  265. exit;
  266. aprocsym.overloadchecked:=true;
  267. if (aprocsym.owner.symtabletype<>objectsymtable) then
  268. internalerror(200111021);
  269. objdef:=tobjectdef(aprocsym.owner.defowner);
  270. { we start in the parent }
  271. if not assigned(objdef.childof) then
  272. exit;
  273. objdef:=objdef.childof;
  274. s:=aprocsym.name;
  275. speedvalue:=getspeedvalue(s);
  276. while assigned(objdef) do
  277. begin
  278. srsym:=tprocsym(objdef.symtable.speedsearch(s,speedvalue));
  279. if assigned(srsym) then
  280. begin
  281. if (srsym.typ<>procsym) then
  282. internalerror(200111022);
  283. if srsym.is_visible_for_proc(aktprocdef) then
  284. begin
  285. srsym.add_para_match_to(Aprocsym);
  286. { we can stop if the overloads were already added
  287. for the found symbol }
  288. if srsym.overloadchecked then
  289. break;
  290. end;
  291. end;
  292. { next parent }
  293. objdef:=objdef.childof;
  294. end;
  295. end;
  296. function is_better_candidate(currpd,bestpd:pcandidate):integer;
  297. var
  298. res : integer;
  299. begin
  300. {
  301. Return values:
  302. > 0 when currpd is better than bestpd
  303. < 0 when bestpd is better than currpd
  304. = 0 when both are equal
  305. To choose the best candidate we use the following order:
  306. - Incompatible flag
  307. - (Smaller) Number of convert operator parameters.
  308. - (Smaller) Number of convertlevel 2 parameters.
  309. - (Smaller) Number of convertlevel 1 parameters.
  310. - (Bigger) Number of exact parameters.
  311. - (Smaller) Number of equal parameters.
  312. - (Smaller) Total of ordinal distance. For example, the distance of a word
  313. to a byte is 65535-255=65280.
  314. }
  315. if bestpd^.invalid then
  316. begin
  317. if currpd^.invalid then
  318. res:=0
  319. else
  320. res:=1;
  321. end
  322. else
  323. if currpd^.invalid then
  324. res:=-1
  325. else
  326. begin
  327. { less operator parameters? }
  328. res:=(bestpd^.coper_count-currpd^.coper_count);
  329. if (res=0) then
  330. begin
  331. { less cl3 parameters? }
  332. res:=(bestpd^.cl3_count-currpd^.cl3_count);
  333. if (res=0) then
  334. begin
  335. { less cl2 parameters? }
  336. res:=(bestpd^.cl2_count-currpd^.cl2_count);
  337. if (res=0) then
  338. begin
  339. { less cl1 parameters? }
  340. res:=(bestpd^.cl1_count-currpd^.cl1_count);
  341. if (res=0) then
  342. begin
  343. { more exact parameters? }
  344. res:=(currpd^.exact_count-bestpd^.exact_count);
  345. if (res=0) then
  346. begin
  347. { less equal parameters? }
  348. res:=(bestpd^.equal_count-currpd^.equal_count);
  349. if (res=0) then
  350. begin
  351. { smaller ordinal distance? }
  352. if (currpd^.ordinal_distance<bestpd^.ordinal_distance) then
  353. res:=1
  354. else
  355. if (currpd^.ordinal_distance>bestpd^.ordinal_distance) then
  356. res:=-1
  357. else
  358. res:=0;
  359. end;
  360. end;
  361. end;
  362. end;
  363. end;
  364. end;
  365. end;
  366. is_better_candidate:=res;
  367. end;
  368. procedure var_para_allowed(var eq:tequaltype;def_from,def_to:Tdef);
  369. begin
  370. { Note: eq must be already valid, it will only be updated! }
  371. case def_to.deftype of
  372. formaldef :
  373. begin
  374. { all types can be passed to a formaldef }
  375. eq:=te_equal;
  376. end;
  377. orddef :
  378. begin
  379. { allows conversion from word to integer and
  380. byte to shortint, but only for TP7 compatibility }
  381. if (m_tp7 in aktmodeswitches) and
  382. (def_from.deftype=orddef) and
  383. (def_from.size=def_to.size) then
  384. eq:=te_convert_l1;
  385. end;
  386. pointerdef :
  387. begin
  388. { an implicit pointer conversion is allowed }
  389. if (def_from.deftype=pointerdef) then
  390. eq:=te_convert_l1;
  391. end;
  392. stringdef :
  393. begin
  394. { all shortstrings are allowed, size is not important }
  395. if is_shortstring(def_from) and
  396. is_shortstring(def_to) then
  397. eq:=te_equal;
  398. end;
  399. objectdef :
  400. begin
  401. { child objects can be also passed }
  402. { in non-delphi mode, otherwise }
  403. { they must match exactly, except }
  404. { if they are objects }
  405. if (def_from.deftype=objectdef) and
  406. (
  407. not(m_delphi in aktmodeswitches) or
  408. (
  409. (tobjectdef(def_from).objecttype=odt_object) and
  410. (tobjectdef(def_to).objecttype=odt_object)
  411. )
  412. ) and
  413. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  414. eq:=te_convert_l1;
  415. end;
  416. filedef :
  417. begin
  418. { an implicit file conversion is also allowed }
  419. { from a typed file to an untyped one }
  420. if (def_from.deftype=filedef) and
  421. (tfiledef(def_from).filetyp = ft_typed) and
  422. (tfiledef(def_to).filetyp = ft_untyped) then
  423. eq:=te_convert_l1;
  424. end;
  425. end;
  426. end;
  427. procedure para_allowed(var eq:tequaltype;p:tcallparanode;def_to:tdef);
  428. begin
  429. { Note: eq must be already valid, it will only be updated! }
  430. case def_to.deftype of
  431. formaldef :
  432. begin
  433. { all types can be passed to a formaldef }
  434. eq:=te_equal;
  435. end;
  436. stringdef :
  437. begin
  438. { to support ansi/long/wide strings in a proper way }
  439. { string and string[10] are assumed as equal }
  440. { when searching the correct overloaded procedure }
  441. if (p.resulttype.def.deftype=stringdef) and
  442. (tstringdef(def_to).string_typ=tstringdef(p.resulttype.def).string_typ) then
  443. eq:=te_equal
  444. else
  445. { Passing a constant char to ansistring or shortstring or
  446. a widechar to widestring then handle it as equal. }
  447. if (p.left.nodetype=ordconstn) and
  448. (
  449. is_char(p.resulttype.def) and
  450. (is_shortstring(def_to) or is_ansistring(def_to))
  451. ) or
  452. (
  453. is_widechar(p.resulttype.def) and
  454. is_widestring(def_to)
  455. ) then
  456. eq:=te_equal
  457. end;
  458. setdef :
  459. begin
  460. { set can also be a not yet converted array constructor }
  461. if (p.resulttype.def.deftype=arraydef) and
  462. (tarraydef(p.resulttype.def).IsConstructor) and
  463. not(tarraydef(p.resulttype.def).IsVariant) then
  464. eq:=te_equal;
  465. end;
  466. procvardef :
  467. begin
  468. { in tp7 mode proc -> procvar is allowed }
  469. if (m_tp_procvar in aktmodeswitches) and
  470. (p.left.nodetype=calln) and
  471. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def_to),true)>=te_equal) then
  472. eq:=te_equal;
  473. end;
  474. end;
  475. end;
  476. {****************************************************************************
  477. TOBJECTINFOITEM
  478. ****************************************************************************}
  479. constructor tobjectinfoitem.create(def : tobjectdef);
  480. begin
  481. inherited create;
  482. objinfo := def;
  483. end;
  484. {****************************************************************************
  485. TCALLPARANODE
  486. ****************************************************************************}
  487. constructor tcallparanode.create(expr,next : tnode);
  488. begin
  489. inherited create(callparan,expr,next);
  490. if assigned(expr) then
  491. expr.set_file_line(self);
  492. callparaflags:=[];
  493. end;
  494. destructor tcallparanode.destroy;
  495. begin
  496. inherited destroy;
  497. end;
  498. constructor tcallparanode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  499. begin
  500. inherited ppuload(t,ppufile);
  501. ppufile.getsmallset(callparaflags);
  502. end;
  503. procedure tcallparanode.ppuwrite(ppufile:tcompilerppufile);
  504. begin
  505. inherited ppuwrite(ppufile);
  506. ppufile.putsmallset(callparaflags);
  507. end;
  508. procedure tcallparanode.derefimpl;
  509. begin
  510. inherited derefimpl;
  511. end;
  512. function tcallparanode.getcopy : tnode;
  513. var
  514. n : tcallparanode;
  515. begin
  516. n:=tcallparanode(inherited getcopy);
  517. n.callparaflags:=callparaflags;
  518. n.paraitem:=paraitem;
  519. result:=n;
  520. end;
  521. procedure tcallparanode.insertintolist(l : tnodelist);
  522. begin
  523. end;
  524. procedure tcallparanode.get_paratype;
  525. var
  526. old_get_para_resulttype : boolean;
  527. old_array_constructor : boolean;
  528. begin
  529. inc(parsing_para_level);
  530. if assigned(right) then
  531. tcallparanode(right).get_paratype;
  532. old_array_constructor:=allow_array_constructor;
  533. old_get_para_resulttype:=get_para_resulttype;
  534. get_para_resulttype:=true;
  535. allow_array_constructor:=true;
  536. resulttypepass(left);
  537. get_para_resulttype:=old_get_para_resulttype;
  538. allow_array_constructor:=old_array_constructor;
  539. if codegenerror then
  540. resulttype:=generrortype
  541. else
  542. resulttype:=left.resulttype;
  543. dec(parsing_para_level);
  544. end;
  545. procedure tcallparanode.insert_typeconv(do_count : boolean);
  546. var
  547. oldtype : ttype;
  548. {$ifdef extdebug}
  549. store_count_ref : boolean;
  550. {$endif def extdebug}
  551. begin
  552. inc(parsing_para_level);
  553. {$ifdef extdebug}
  554. if do_count then
  555. begin
  556. store_count_ref:=count_ref;
  557. count_ref:=true;
  558. end;
  559. {$endif def extdebug}
  560. { Be sure to have the resulttype }
  561. if not assigned(left.resulttype.def) then
  562. resulttypepass(left);
  563. { Handle varargs and hidden paras directly, no typeconvs or }
  564. { typechecking needed }
  565. if (nf_varargs_para in flags) then
  566. begin
  567. { convert pascal to C types }
  568. case left.resulttype.def.deftype of
  569. stringdef :
  570. inserttypeconv(left,charpointertype);
  571. floatdef :
  572. inserttypeconv(left,s64floattype);
  573. end;
  574. set_varstate(left,true);
  575. resulttype:=left.resulttype;
  576. end
  577. else
  578. if (paraitem.paratyp = vs_hidden) then
  579. begin
  580. set_varstate(left,true);
  581. resulttype:=left.resulttype;
  582. end
  583. else
  584. begin
  585. { Do we need arrayconstructor -> set conversion, then insert
  586. it here before the arrayconstructor node breaks the tree
  587. with its conversions of enum->ord }
  588. if (left.nodetype=arrayconstructorn) and
  589. (paraitem.paratype.def.deftype=setdef) then
  590. inserttypeconv(left,paraitem.paratype);
  591. { set some settings needed for arrayconstructor }
  592. if is_array_constructor(left.resulttype.def) then
  593. begin
  594. if is_array_of_const(paraitem.paratype.def) then
  595. begin
  596. if assigned(aktcallprocdef) and
  597. (aktcallprocdef.proccalloption in [pocall_cppdecl,pocall_cdecl]) then
  598. include(left.flags,nf_cargs);
  599. { force variant array }
  600. include(left.flags,nf_forcevaria);
  601. end
  602. else
  603. begin
  604. include(left.flags,nf_novariaallowed);
  605. { now that the resultting type is know we can insert the required
  606. typeconvs for the array constructor }
  607. tarrayconstructornode(left).force_type(tarraydef(paraitem.paratype.def).elementtype);
  608. end;
  609. end;
  610. { check if local proc/func is assigned to procvar }
  611. if left.resulttype.def.deftype=procvardef then
  612. test_local_to_procvar(tprocvardef(left.resulttype.def),paraitem.paratype.def);
  613. { test conversions }
  614. if not(is_shortstring(left.resulttype.def) and
  615. is_shortstring(paraitem.paratype.def)) and
  616. (paraitem.paratype.def.deftype<>formaldef) then
  617. begin
  618. { Process open parameters }
  619. if paramanager.push_high_param(paraitem.paratype.def,aktcallprocdef.proccalloption) then
  620. begin
  621. { insert type conv but hold the ranges of the array }
  622. oldtype:=left.resulttype;
  623. inserttypeconv(left,paraitem.paratype);
  624. left.resulttype:=oldtype;
  625. end
  626. else
  627. begin
  628. { for ordinals, floats and enums, verify if we might cause
  629. some range-check errors. }
  630. if (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) and
  631. (left.nodetype in [vecn,loadn,calln]) then
  632. begin
  633. if (left.resulttype.def.size>paraitem.paratype.def.size) then
  634. begin
  635. if (cs_check_range in aktlocalswitches) then
  636. Message(type_w_smaller_possible_range_check)
  637. else
  638. Message(type_h_smaller_possible_range_check);
  639. end;
  640. end;
  641. inserttypeconv(left,paraitem.paratype);
  642. end;
  643. if codegenerror then
  644. begin
  645. dec(parsing_para_level);
  646. exit;
  647. end;
  648. end;
  649. { check var strings }
  650. if (cs_strict_var_strings in aktlocalswitches) and
  651. is_shortstring(left.resulttype.def) and
  652. is_shortstring(paraitem.paratype.def) and
  653. (paraitem.paratyp in [vs_out,vs_var]) and
  654. not(is_open_string(paraitem.paratype.def)) and
  655. not(equal_defs(left.resulttype.def,paraitem.paratype.def)) then
  656. begin
  657. aktfilepos:=left.fileinfo;
  658. CGMessage(type_e_strict_var_string_violation);
  659. end;
  660. { File types are only allowed for var parameters }
  661. if (paraitem.paratype.def.deftype=filedef) and
  662. (paraitem.paratyp<>vs_var) then
  663. CGMessage(cg_e_file_must_call_by_reference);
  664. { Handle formal parameters separate }
  665. if (paraitem.paratype.def.deftype=formaldef) then
  666. begin
  667. { load procvar if a procedure is passed }
  668. if (m_tp_procvar in aktmodeswitches) and
  669. (left.nodetype=calln) and
  670. (is_void(left.resulttype.def)) then
  671. load_procvar_from_calln(left);
  672. case paraitem.paratyp of
  673. vs_var,
  674. vs_out :
  675. begin
  676. if not valid_for_formal_var(left) then
  677. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  678. end;
  679. vs_const :
  680. begin
  681. if not valid_for_formal_const(left) then
  682. CGMessagePos(left.fileinfo,parser_e_illegal_parameter_list);
  683. end;
  684. end;
  685. end
  686. else
  687. begin
  688. { check if the argument is allowed }
  689. if (paraitem.paratyp in [vs_out,vs_var]) then
  690. valid_for_var(left);
  691. end;
  692. if paraitem.paratyp in [vs_var,vs_const] then
  693. begin
  694. { Causes problems with const ansistrings if also }
  695. { done for vs_const (JM) }
  696. if paraitem.paratyp = vs_var then
  697. set_unique(left);
  698. make_not_regable(left);
  699. end;
  700. { ansistrings out paramaters doesn't need to be }
  701. { unique, they are finalized }
  702. if paraitem.paratyp=vs_out then
  703. make_not_regable(left);
  704. if do_count then
  705. begin
  706. { not completly proper, but avoids some warnings }
  707. if (paraitem.paratyp in [vs_var,vs_out]) then
  708. set_funcret_is_valid(left);
  709. set_varstate(left,not(paraitem.paratyp in [vs_var,vs_out]));
  710. end;
  711. { must only be done after typeconv PM }
  712. resulttype:=paraitem.paratype;
  713. end;
  714. { process next node }
  715. if assigned(right) then
  716. tcallparanode(right).insert_typeconv(do_count);
  717. dec(parsing_para_level);
  718. {$ifdef extdebug}
  719. if do_count then
  720. count_ref:=store_count_ref;
  721. {$endif def extdebug}
  722. end;
  723. procedure tcallparanode.det_registers;
  724. var
  725. old_get_para_resulttype : boolean;
  726. old_array_constructor : boolean;
  727. begin
  728. if assigned(right) then
  729. begin
  730. tcallparanode(right).det_registers;
  731. registers32:=right.registers32;
  732. registersfpu:=right.registersfpu;
  733. {$ifdef SUPPORT_MMX}
  734. registersmmx:=right.registersmmx;
  735. {$endif}
  736. end;
  737. old_array_constructor:=allow_array_constructor;
  738. old_get_para_resulttype:=get_para_resulttype;
  739. get_para_resulttype:=true;
  740. allow_array_constructor:=true;
  741. firstpass(left);
  742. get_para_resulttype:=old_get_para_resulttype;
  743. allow_array_constructor:=old_array_constructor;
  744. if left.registers32>registers32 then
  745. registers32:=left.registers32;
  746. if left.registersfpu>registersfpu then
  747. registersfpu:=left.registersfpu;
  748. {$ifdef SUPPORT_MMX}
  749. if left.registersmmx>registersmmx then
  750. registersmmx:=left.registersmmx;
  751. {$endif SUPPORT_MMX}
  752. end;
  753. procedure tcallparanode.firstcallparan(do_count : boolean);
  754. begin
  755. if not assigned(left.resulttype.def) then
  756. begin
  757. get_paratype;
  758. {
  759. if assigned(defcoll) then
  760. insert_typeconv(defcoll,do_count);
  761. }
  762. end;
  763. det_registers;
  764. end;
  765. function tcallparanode.docompare(p: tnode): boolean;
  766. begin
  767. docompare :=
  768. inherited docompare(p) and
  769. (callparaflags = tcallparanode(p).callparaflags)
  770. ;
  771. end;
  772. {****************************************************************************
  773. TCALLNODE
  774. ****************************************************************************}
  775. constructor tcallnode.create(l:tnode;v : tprocsym;st : tsymtable; mp : tnode);
  776. begin
  777. inherited create(calln,l,nil);
  778. symtableprocentry:=v;
  779. symtableproc:=st;
  780. include(flags,nf_return_value_used);
  781. methodpointer:=mp;
  782. procdefinition:=nil;
  783. restypeset := false;
  784. funcretrefnode:=nil;
  785. paralength:=-1;
  786. end;
  787. constructor tcallnode.createintern(const name: string; params: tnode);
  788. var
  789. srsym: tsym;
  790. symowner: tsymtable;
  791. begin
  792. if not (cs_compilesystem in aktmoduleswitches) then
  793. begin
  794. srsym := searchsymonlyin(systemunit,name);
  795. symowner := systemunit;
  796. end
  797. else
  798. begin
  799. searchsym(name,srsym,symowner);
  800. if not assigned(srsym) then
  801. searchsym(upper(name),srsym,symowner);
  802. end;
  803. if not assigned(srsym) or
  804. (srsym.typ <> procsym) then
  805. begin
  806. {$ifdef EXTDEBUG}
  807. Comment(V_Error,'unknown compilerproc '+name);
  808. {$endif EXTDEBUG}
  809. internalerror(200107271);
  810. end;
  811. self.create(params,tprocsym(srsym),symowner,nil);
  812. end;
  813. constructor tcallnode.createinternres(const name: string; params: tnode; const res: ttype);
  814. begin
  815. self.createintern(name,params);
  816. restype := res;
  817. restypeset := true;
  818. { both the normal and specified resulttype either have to be returned via a }
  819. { parameter or not, but no mixing (JM) }
  820. if paramanager.ret_in_param(restype.def,pocall_compilerproc) xor
  821. paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  822. internalerror(200108291);
  823. end;
  824. constructor tcallnode.createinternreturn(const name: string; params: tnode; returnnode : tnode);
  825. begin
  826. self.createintern(name,params);
  827. funcretrefnode:=returnnode;
  828. if not paramanager.ret_in_param(symtableprocentry.first_procdef.rettype.def,symtableprocentry.first_procdef.proccalloption) then
  829. internalerror(200204247);
  830. end;
  831. destructor tcallnode.destroy;
  832. begin
  833. methodpointer.free;
  834. funcretrefnode.free;
  835. inherited destroy;
  836. end;
  837. constructor tcallnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  838. begin
  839. inherited ppuload(t,ppufile);
  840. symtableprocentry:=tprocsym(ppufile.getderef);
  841. {$ifdef fpc}
  842. {$warning FIXME: No withsymtable support}
  843. {$endif}
  844. symtableproc:=nil;
  845. procdefinition:=tprocdef(ppufile.getderef);
  846. restypeset:=boolean(ppufile.getbyte);
  847. methodpointer:=ppuloadnode(ppufile);
  848. funcretrefnode:=ppuloadnode(ppufile);
  849. end;
  850. procedure tcallnode.ppuwrite(ppufile:tcompilerppufile);
  851. begin
  852. inherited ppuwrite(ppufile);
  853. ppufile.putderef(symtableprocentry);
  854. ppufile.putderef(procdefinition);
  855. ppufile.putbyte(byte(restypeset));
  856. ppuwritenode(ppufile,methodpointer);
  857. ppuwritenode(ppufile,funcretrefnode);
  858. end;
  859. procedure tcallnode.derefimpl;
  860. begin
  861. inherited derefimpl;
  862. resolvesym(pointer(symtableprocentry));
  863. symtableproc:=symtableprocentry.owner;
  864. resolvedef(pointer(procdefinition));
  865. if assigned(methodpointer) then
  866. methodpointer.derefimpl;
  867. if assigned(funcretrefnode) then
  868. funcretrefnode.derefimpl;
  869. end;
  870. procedure tcallnode.set_procvar(procvar:tnode);
  871. begin
  872. right:=procvar;
  873. end;
  874. function tcallnode.getcopy : tnode;
  875. var
  876. n : tcallnode;
  877. begin
  878. n:=tcallnode(inherited getcopy);
  879. n.symtableprocentry:=symtableprocentry;
  880. n.symtableproc:=symtableproc;
  881. n.procdefinition:=procdefinition;
  882. n.restype := restype;
  883. n.restypeset := restypeset;
  884. if assigned(methodpointer) then
  885. n.methodpointer:=methodpointer.getcopy
  886. else
  887. n.methodpointer:=nil;
  888. if assigned(funcretrefnode) then
  889. n.funcretrefnode:=funcretrefnode.getcopy
  890. else
  891. n.funcretrefnode:=nil;
  892. result:=n;
  893. end;
  894. procedure tcallnode.insertintolist(l : tnodelist);
  895. begin
  896. end;
  897. procedure tcallnode.verifyabstract(p : tnamedindexitem;arg:pointer);
  898. var
  899. hp : tprocdef;
  900. j: integer;
  901. begin
  902. if (tsym(p).typ=procsym) then
  903. begin
  904. for j:=1 to tprocsym(p).procdef_count do
  905. begin
  906. { index starts at 1 }
  907. hp:=tprocsym(p).procdef[j];
  908. { If this is an abstract method insert into the list }
  909. if (po_abstractmethod in hp.procoptions) then
  910. AbstractMethodsList.Insert(hp.procsym.name)
  911. else
  912. { If this symbol is already in the list, and it is
  913. an overriding method or dynamic, then remove it from the list
  914. }
  915. begin
  916. { symbol was found }
  917. if AbstractMethodsList.Find(hp.procsym.name) <> nil then
  918. begin
  919. if po_overridingmethod in hp.procoptions then
  920. AbstractMethodsList.Remove(hp.procsym.name);
  921. end;
  922. end;
  923. end;
  924. end;
  925. end;
  926. procedure tcallnode.verifyabstractcalls;
  927. var
  928. objectdf : tobjectdef;
  929. parents : tlinkedlist;
  930. objectinfo : tobjectinfoitem;
  931. stritem : tstringlistitem;
  932. _classname : string;
  933. begin
  934. objectdf := nil;
  935. { verify if trying to create an instance of a class which contains
  936. non-implemented abstract methods }
  937. { first verify this class type, no class than exit }
  938. { also, this checking can only be done if the constructor is directly
  939. called, indirect constructor calls cannot be checked.
  940. }
  941. if assigned(methodpointer) and assigned(methodpointer.resulttype.def) then
  942. if (methodpointer.resulttype.def.deftype = classrefdef) and
  943. (methodpointer.nodetype in [typen,loadvmtn]) then
  944. begin
  945. if (tclassrefdef(methodpointer.resulttype.def).pointertype.def.deftype = objectdef) then
  946. objectdf := tobjectdef(tclassrefdef(methodpointer.resulttype.def).pointertype.def);
  947. end;
  948. if not assigned(objectdf) then exit;
  949. if assigned(objectdf.symtable.name) then
  950. _classname := objectdf.symtable.name^
  951. else
  952. _classname := '';
  953. parents := tlinkedlist.create;
  954. AbstractMethodsList := tstringlist.create;
  955. { insert all parents in this class : the first item in the
  956. list will be the base parent of the class .
  957. }
  958. while assigned(objectdf) do
  959. begin
  960. objectinfo:=tobjectinfoitem.create(objectdf);
  961. parents.insert(objectinfo);
  962. objectdf := objectdf.childof;
  963. end;
  964. { now all parents are in the correct order
  965. insert all abstract methods in the list, and remove
  966. those which are overriden by parent classes.
  967. }
  968. objectinfo:=tobjectinfoitem(parents.first);
  969. while assigned(objectinfo) do
  970. begin
  971. objectdf := objectinfo.objinfo;
  972. if assigned(objectdf.symtable) then
  973. objectdf.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}verifyabstract,nil);
  974. objectinfo:=tobjectinfoitem(objectinfo.next);
  975. end;
  976. if assigned(parents) then
  977. parents.free;
  978. { Finally give out a warning for each abstract method still in the list }
  979. stritem := tstringlistitem(AbstractMethodsList.first);
  980. while assigned(stritem) do
  981. begin
  982. if assigned(stritem.fpstr) then
  983. Message2(type_w_instance_with_abstract,lower(_classname),lower(stritem.fpstr^));
  984. stritem := tstringlistitem(stritem.next);
  985. end;
  986. if assigned(AbstractMethodsList) then
  987. AbstractMethodsList.Free;
  988. end;
  989. function Tcallnode.candidates_find:pcandidate;
  990. var
  991. j : integer;
  992. pd : tprocdef;
  993. procs,hp : pcandidate;
  994. found,
  995. has_overload_directive : boolean;
  996. srsymtable : tsymtable;
  997. srprocsym : tprocsym;
  998. procedure proc_add(pd:tprocdef);
  999. var
  1000. i : integer;
  1001. begin
  1002. { generate new candidate entry }
  1003. new(hp);
  1004. fillchar(hp^,sizeof(tcandidate),0);
  1005. hp^.data:=pd;
  1006. hp^.next:=procs;
  1007. procs:=hp;
  1008. { Find last parameter, skip all default parameters
  1009. that are not passed. Ignore this skipping for varargs }
  1010. hp^.firstpara:=tparaitem(pd.Para.last);
  1011. if not(po_varargs in pd.procoptions) then
  1012. begin
  1013. for i:=1 to pd.maxparacount-paralength do
  1014. hp^.firstpara:=tparaitem(hp^.firstPara.previous);
  1015. end;
  1016. end;
  1017. begin
  1018. procs:=nil;
  1019. { when the definition has overload directive set, we search for
  1020. overloaded definitions in the class, this only needs to be done once
  1021. for class entries as the tree keeps always the same }
  1022. if (not symtableprocentry.overloadchecked) and
  1023. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1024. (symtableprocentry.owner.symtabletype=objectsymtable) then
  1025. search_class_overloads(symtableprocentry);
  1026. { link all procedures which have the same # of parameters }
  1027. for j:=1 to symtableprocentry.procdef_count do
  1028. begin
  1029. pd:=symtableprocentry.procdef[j];
  1030. { Is the procdef visible? This needs to be checked on
  1031. procdef level since a symbol can contain both private and
  1032. public declarations. But the check should not be done
  1033. when the callnode is generated by a property }
  1034. if (nf_isproperty in flags) or
  1035. (pd.owner.symtabletype<>objectsymtable) or
  1036. pd.is_visible_for_proc(aktprocdef) then
  1037. begin
  1038. { only when the # of parameter are supported by the
  1039. procedure }
  1040. if (paralength>=pd.minparacount) and
  1041. ((po_varargs in pd.procoptions) or { varargs }
  1042. (paralength<=pd.maxparacount)) then
  1043. proc_add(pd);
  1044. end;
  1045. end;
  1046. { remember if the procedure is declared with the overload directive,
  1047. it's information is still needed also after all procs are removed }
  1048. has_overload_directive:=(po_overload in symtableprocentry.first_procdef.procoptions);
  1049. { when the definition has overload directive set, we search for
  1050. overloaded definitions in the symtablestack. The found
  1051. entries are only added to the procs list and not the procsym, because
  1052. the list can change in every situation }
  1053. if has_overload_directive and
  1054. (symtableprocentry.owner.symtabletype<>objectsymtable) then
  1055. begin
  1056. srsymtable:=symtableprocentry.owner.next;
  1057. while assigned(srsymtable) do
  1058. begin
  1059. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1060. begin
  1061. srprocsym:=tprocsym(srsymtable.speedsearch(symtableprocentry.name,symtableprocentry.speedvalue));
  1062. { process only visible procsyms }
  1063. if assigned(srprocsym) and
  1064. (srprocsym.typ=procsym) and
  1065. srprocsym.is_visible_for_proc(aktprocdef) then
  1066. begin
  1067. { if this procedure doesn't have overload we can stop
  1068. searching }
  1069. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1070. break;
  1071. { process all overloaded definitions }
  1072. for j:=1 to srprocsym.procdef_count do
  1073. begin
  1074. pd:=srprocsym.procdef[j];
  1075. { only when the # of parameter are supported by the
  1076. procedure }
  1077. if (paralength>=pd.minparacount) and
  1078. ((po_varargs in pd.procoptions) or { varargs }
  1079. (paralength<=pd.maxparacount)) then
  1080. begin
  1081. found:=false;
  1082. hp:=procs;
  1083. while assigned(hp) do
  1084. begin
  1085. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,false)>=te_equal then
  1086. begin
  1087. found:=true;
  1088. break;
  1089. end;
  1090. hp:=hp^.next;
  1091. end;
  1092. if not found then
  1093. proc_add(pd);
  1094. end;
  1095. end;
  1096. end;
  1097. end;
  1098. srsymtable:=srsymtable.next;
  1099. end;
  1100. end;
  1101. candidates_find:=procs;
  1102. end;
  1103. procedure tcallnode.candidates_free(procs:pcandidate);
  1104. var
  1105. hpnext,
  1106. hp : pcandidate;
  1107. begin
  1108. hp:=procs;
  1109. while assigned(hp) do
  1110. begin
  1111. hpnext:=hp^.next;
  1112. dispose(hp);
  1113. hp:=hpnext;
  1114. end;
  1115. end;
  1116. procedure tcallnode.candidates_list(procs:pcandidate;all:boolean);
  1117. var
  1118. hp : pcandidate;
  1119. begin
  1120. hp:=procs;
  1121. while assigned(hp) do
  1122. begin
  1123. if all or
  1124. (not hp^.invalid) then
  1125. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname);
  1126. hp:=hp^.next;
  1127. end;
  1128. end;
  1129. {$ifdef EXTDEBUG}
  1130. procedure Tcallnode.candidates_dump_info(lvl:longint;procs:pcandidate);
  1131. function ParaTreeStr(p:tcallparanode):string;
  1132. begin
  1133. result:='';
  1134. while assigned(p) do
  1135. begin
  1136. if result<>'' then
  1137. result:=result+',';
  1138. result:=result+p.resulttype.def.typename;
  1139. p:=tcallparanode(p.right);
  1140. end;
  1141. end;
  1142. var
  1143. hp : pcandidate;
  1144. currpara : tparaitem;
  1145. begin
  1146. if not CheckVerbosity(lvl) then
  1147. exit;
  1148. Comment(lvl+V_LineInfo,'Overloaded callnode: '+symtableprocentry.name+'('+ParaTreeStr(tcallparanode(left))+')');
  1149. hp:=procs;
  1150. while assigned(hp) do
  1151. begin
  1152. Comment(lvl,' '+hp^.data.fullprocname);
  1153. if (hp^.invalid) then
  1154. Comment(lvl,' invalid')
  1155. else
  1156. begin
  1157. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1158. ' eq: '+tostr(hp^.equal_count)+
  1159. ' l1: '+tostr(hp^.cl1_count)+
  1160. ' l2: '+tostr(hp^.cl2_count)+
  1161. ' l3: '+tostr(hp^.cl3_count)+
  1162. ' oper: '+tostr(hp^.coper_count)+
  1163. ' ord: '+realtostr(hp^.exact_count));
  1164. { Print parameters in left-right order }
  1165. currpara:=hp^.firstpara;
  1166. if assigned(currpara) then
  1167. begin
  1168. while assigned(currpara.next) do
  1169. currpara:=tparaitem(currpara.next);
  1170. end;
  1171. while assigned(currpara) do
  1172. begin
  1173. if (currpara.paratyp<>vs_hidden) then
  1174. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1175. currpara:=tparaitem(currpara.previous);
  1176. end;
  1177. end;
  1178. hp:=hp^.next;
  1179. end;
  1180. end;
  1181. {$endif EXTDEBUG}
  1182. procedure Tcallnode.candidates_get_information(procs:pcandidate);
  1183. var
  1184. hp : pcandidate;
  1185. currpara : tparaitem;
  1186. currparanr : byte;
  1187. def_from,
  1188. def_to : tdef;
  1189. pt : tcallparanode;
  1190. eq : tequaltype;
  1191. convtype : tconverttype;
  1192. pdoper : tprocdef;
  1193. begin
  1194. { process all procs }
  1195. hp:=procs;
  1196. while assigned(hp) do
  1197. begin
  1198. { We compare parameters in reverse order (right to left),
  1199. the firstpara is already pointing to the last parameter
  1200. were we need to start comparing }
  1201. currparanr:=paralength;
  1202. currpara:=hp^.firstpara;
  1203. while assigned(currpara) and (currpara.paratyp=vs_hidden) do
  1204. currpara:=tparaitem(currpara.previous);
  1205. pt:=tcallparanode(left);
  1206. while assigned(pt) and assigned(currpara) do
  1207. begin
  1208. { retrieve current parameter definitions to compares }
  1209. eq:=te_incompatible;
  1210. def_from:=pt.resulttype.def;
  1211. def_to:=currpara.paratype.def;
  1212. if not(assigned(def_from)) then
  1213. internalerror(200212091);
  1214. if not(
  1215. assigned(def_to) or
  1216. ((po_varargs in hp^.data.procoptions) and
  1217. (currparanr>hp^.data.minparacount))
  1218. ) then
  1219. internalerror(200212092);
  1220. { varargs are always equal, but not exact }
  1221. if (po_varargs in hp^.data.procoptions) and
  1222. (currparanr>hp^.data.minparacount) then
  1223. begin
  1224. inc(hp^.equal_count);
  1225. eq:=te_equal;
  1226. end
  1227. else
  1228. { same definition -> exact }
  1229. if (def_from=def_to) then
  1230. begin
  1231. inc(hp^.exact_count);
  1232. eq:=te_exact;
  1233. end
  1234. else
  1235. { for value and const parameters check if a integer is constant or
  1236. included in other integer -> equal and calc ordinal_distance }
  1237. if not(currpara.paratyp in [vs_var,vs_out]) and
  1238. is_integer(def_from) and
  1239. is_integer(def_to) and
  1240. is_in_limit(def_from,def_to) then
  1241. begin
  1242. inc(hp^.equal_count);
  1243. eq:=te_equal;
  1244. hp^.ordinal_distance:=hp^.ordinal_distance+
  1245. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1246. hp^.ordinal_distance:=hp^.ordinal_distance+
  1247. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1248. { Give wrong sign a small penalty, this is need to get a diffrence
  1249. from word->[longword,longint] }
  1250. if is_signed(def_from)<>is_signed(def_to) then
  1251. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1252. end
  1253. else
  1254. { generic type comparision }
  1255. begin
  1256. eq:=compare_defs_ext(def_from,def_to,pt.left.nodetype,
  1257. false,true,convtype,pdoper);
  1258. { when the types are not equal we need to check
  1259. some special case for parameter passing }
  1260. if (eq<te_equal) then
  1261. begin
  1262. if currpara.paratyp in [vs_var,vs_out] then
  1263. begin
  1264. { para requires an equal type so the previous found
  1265. match was not good enough, reset to incompatible }
  1266. eq:=te_incompatible;
  1267. { var_para_allowed will return te_equal and te_convert_l1 to
  1268. make a difference for best matching }
  1269. var_para_allowed(eq,pt.resulttype.def,currpara.paratype.def)
  1270. end
  1271. else
  1272. para_allowed(eq,pt,def_to);
  1273. end;
  1274. case eq of
  1275. te_exact :
  1276. internalerror(200212071); { already checked }
  1277. te_equal :
  1278. inc(hp^.equal_count);
  1279. te_convert_l1 :
  1280. inc(hp^.cl1_count);
  1281. te_convert_l2 :
  1282. inc(hp^.cl2_count);
  1283. te_convert_l3 :
  1284. inc(hp^.cl3_count);
  1285. te_convert_operator :
  1286. inc(hp^.coper_count);
  1287. te_incompatible :
  1288. hp^.invalid:=true;
  1289. else
  1290. internalerror(200212072);
  1291. end;
  1292. end;
  1293. { stop checking when an incompatible parameter is found }
  1294. if hp^.invalid then
  1295. begin
  1296. { store the current parameter info for
  1297. a nice error message when no procedure is found }
  1298. hp^.wrongpara:=currpara;
  1299. hp^.wrongparanr:=currparanr;
  1300. break;
  1301. end;
  1302. {$ifdef EXTDEBUG}
  1303. { store equal in node tree for dump }
  1304. currpara.eqval:=eq;
  1305. {$endif EXTDEBUG}
  1306. { next parameter in the call tree }
  1307. pt:=tcallparanode(pt.right);
  1308. { next parameter for definition, only goto next para
  1309. if we're out of the varargs }
  1310. if not(po_varargs in hp^.data.procoptions) or
  1311. (currparanr<=hp^.data.maxparacount) then
  1312. begin
  1313. { Ignore vs_hidden parameters }
  1314. repeat
  1315. currpara:=tparaitem(currpara.previous);
  1316. until (not assigned(currpara)) or (currpara.paratyp<>vs_hidden);
  1317. end;
  1318. dec(currparanr);
  1319. end;
  1320. if not(hp^.invalid) and
  1321. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1322. internalerror(200212141);
  1323. { next candidate }
  1324. hp:=hp^.next;
  1325. end;
  1326. end;
  1327. function Tcallnode.candidates_choose_best(procs:pcandidate;var bestpd:tprocdef):integer;
  1328. var
  1329. besthpstart,
  1330. hp : pcandidate;
  1331. cntpd,
  1332. res : integer;
  1333. begin
  1334. {
  1335. Returns the number of candidates left and the
  1336. first candidate is returned in pdbest
  1337. }
  1338. { Setup the first procdef as best, only count it as a result
  1339. when it is valid }
  1340. bestpd:=procs^.data;
  1341. if procs^.invalid then
  1342. cntpd:=0
  1343. else
  1344. cntpd:=1;
  1345. if assigned(procs^.next) then
  1346. begin
  1347. besthpstart:=procs;
  1348. hp:=procs^.next;
  1349. while assigned(hp) do
  1350. begin
  1351. res:=is_better_candidate(hp,besthpstart);
  1352. if (res>0) then
  1353. begin
  1354. { hp is better, flag all procs to be incompatible }
  1355. while (besthpstart<>hp) do
  1356. begin
  1357. besthpstart^.invalid:=true;
  1358. besthpstart:=besthpstart^.next;
  1359. end;
  1360. { besthpstart is already set to hp }
  1361. bestpd:=besthpstart^.data;
  1362. cntpd:=1;
  1363. end
  1364. else
  1365. if (res<0) then
  1366. begin
  1367. { besthpstart is better, flag current hp to be incompatible }
  1368. hp^.invalid:=true;
  1369. end
  1370. else
  1371. begin
  1372. { res=0, both are valid }
  1373. if not hp^.invalid then
  1374. inc(cntpd);
  1375. end;
  1376. hp:=hp^.next;
  1377. end;
  1378. end;
  1379. candidates_choose_best:=cntpd;
  1380. end;
  1381. procedure tcallnode.candidates_find_wrong_para(procs:pcandidate);
  1382. var
  1383. currparanr : smallint;
  1384. hp : pcandidate;
  1385. pt : tcallparanode;
  1386. begin
  1387. { Only process the first overloaded procdef }
  1388. hp:=procs;
  1389. { Find callparanode corresponding to the argument }
  1390. pt:=tcallparanode(left);
  1391. currparanr:=paralength;
  1392. while assigned(pt) and
  1393. (currparanr>hp^.wrongparanr) do
  1394. begin
  1395. pt:=tcallparanode(pt.right);
  1396. dec(currparanr);
  1397. end;
  1398. if (currparanr<>hp^.wrongparanr) or
  1399. not assigned(pt) then
  1400. internalerror(200212094);
  1401. { Show error message, when it was a var or out parameter
  1402. guess that it is a missing typeconv }
  1403. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1404. CGMessagePos2(left.fileinfo,parser_e_call_by_ref_without_typeconv,
  1405. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1406. else
  1407. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1408. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1409. end;
  1410. procedure tcallnode.bind_paraitem;
  1411. var
  1412. i : integer;
  1413. pt : tcallparanode;
  1414. oldppt : ^tcallparanode;
  1415. currpara : tparaitem;
  1416. hiddentree : tnode;
  1417. begin
  1418. pt:=tcallparanode(left);
  1419. oldppt:=@left;
  1420. { flag all callparanodes that belong to the varargs }
  1421. if (po_varargs in procdefinition.procoptions) then
  1422. begin
  1423. i:=paralength;
  1424. while (i>procdefinition.maxparacount) do
  1425. begin
  1426. include(tcallparanode(pt).flags,nf_varargs_para);
  1427. oldppt:[email protected];
  1428. pt:=tcallparanode(pt.right);
  1429. dec(i);
  1430. end;
  1431. end;
  1432. { insert hidden parameters }
  1433. currpara:=tparaitem(procdefinition.Para.last);
  1434. while assigned(currpara) do
  1435. begin
  1436. if not assigned(pt) then
  1437. internalerror(200304082);
  1438. if (currpara.paratyp=vs_hidden) then
  1439. begin
  1440. hiddentree:=nil;
  1441. if assigned(currpara.previous) and
  1442. paramanager.push_high_param(tparaitem(currpara.previous).paratype.def,procdefinition.proccalloption) then
  1443. // if vo_is_high_value in tvarsym(currpara.parasym).varoptions then
  1444. begin
  1445. { we need the information of the next parameter }
  1446. hiddentree:=gen_high_tree(pt.left,is_open_string(tparaitem(currpara.previous).paratype.def));
  1447. end;
  1448. { add a callparanode for the hidden parameter and
  1449. let the previous node point to this new node }
  1450. if not assigned(hiddentree) then
  1451. internalerror(200304073);
  1452. pt:=ccallparanode.create(hiddentree,oldppt^);
  1453. oldppt^:=pt;
  1454. end;
  1455. { Bind paraitem to this node }
  1456. pt.paraitem:=currpara;
  1457. { Next node and paraitem }
  1458. oldppt:[email protected];
  1459. pt:=tcallparanode(pt.right);
  1460. currpara:=tparaitem(currpara.previous);
  1461. end;
  1462. end;
  1463. function tcallnode.det_resulttype:tnode;
  1464. var
  1465. procs : pcandidate;
  1466. oldcallprocdef : tabstractprocdef;
  1467. hpt : tnode;
  1468. pt : tcallparanode;
  1469. lastpara : longint;
  1470. currpara : tparaitem;
  1471. cand_cnt : integer;
  1472. i : longint;
  1473. method_must_be_valid,
  1474. is_const : boolean;
  1475. label
  1476. errorexit;
  1477. begin
  1478. result:=nil;
  1479. procs:=nil;
  1480. oldcallprocdef:=aktcallprocdef;
  1481. aktcallprocdef:=nil;
  1482. { determine length of parameter list }
  1483. pt:=tcallparanode(left);
  1484. paralength:=0;
  1485. while assigned(pt) do
  1486. begin
  1487. inc(paralength);
  1488. pt:=tcallparanode(pt.right);
  1489. end;
  1490. { determine the type of the parameters }
  1491. if assigned(left) then
  1492. begin
  1493. tcallparanode(left).get_paratype;
  1494. if codegenerror then
  1495. goto errorexit;
  1496. end;
  1497. { procedure variable ? }
  1498. if assigned(right) then
  1499. begin
  1500. set_varstate(right,true);
  1501. resulttypepass(right);
  1502. if codegenerror then
  1503. exit;
  1504. procdefinition:=tabstractprocdef(right.resulttype.def);
  1505. { Compare parameters from right to left }
  1506. currpara:=tparaitem(procdefinition.Para.last);
  1507. while assigned(currpara) and (currpara.paratyp=vs_hidden) do
  1508. currpara:=tparaitem(currpara.previous);
  1509. pt:=tcallparanode(left);
  1510. lastpara:=paralength;
  1511. while assigned(currpara) and assigned(pt) do
  1512. begin
  1513. { only goto next para if we're out of the varargs }
  1514. if not(po_varargs in procdefinition.procoptions) or
  1515. (lastpara<=procdefinition.maxparacount) then
  1516. begin
  1517. repeat
  1518. currpara:=tparaitem(currpara.previous);
  1519. until (not assigned(currpara)) or (currpara.paratyp<>vs_hidden);
  1520. end;
  1521. pt:=tcallparanode(pt.right);
  1522. dec(lastpara);
  1523. end;
  1524. if assigned(pt) or assigned(currpara) then
  1525. begin
  1526. if assigned(pt) then
  1527. aktfilepos:=pt.fileinfo;
  1528. CGMessage(parser_e_wrong_parameter_size);
  1529. goto errorexit;
  1530. end;
  1531. end
  1532. else
  1533. { not a procedure variable }
  1534. begin
  1535. { do we know the procedure to call ? }
  1536. if not(assigned(procdefinition)) then
  1537. begin
  1538. procs:=candidates_find;
  1539. { no procedures found? then there is something wrong
  1540. with the parameter size }
  1541. if not assigned(procs) then
  1542. begin
  1543. { when it's an auto inherited call and there
  1544. is no procedure found, but the procedures
  1545. were defined with overload directive and at
  1546. least two procedures are defined then we ignore
  1547. this inherited by inserting a nothingn. Only
  1548. do this ugly hack in Delphi mode as it looks more
  1549. like a bug. It's also not documented }
  1550. if (m_delphi in aktmodeswitches) and
  1551. (nf_anon_inherited in flags) and
  1552. (symtableprocentry.owner.symtabletype=objectsymtable) and
  1553. (po_overload in symtableprocentry.first_procdef.procoptions) and
  1554. (symtableprocentry.procdef_count>=2) then
  1555. result:=cnothingnode.create
  1556. else
  1557. begin
  1558. { in tp mode we can try to convert to procvar if
  1559. there are no parameters specified. Only try it
  1560. when there is only one proc definition, else the
  1561. loadnode will give a strange error }
  1562. if not(assigned(left)) and
  1563. (m_tp_procvar in aktmodeswitches) and
  1564. (symtableprocentry.procdef_count=1) then
  1565. begin
  1566. hpt:=cloadnode.create(tprocsym(symtableprocentry),symtableproc);
  1567. if (symtableprocentry.owner.symtabletype=objectsymtable) then
  1568. begin
  1569. if assigned(methodpointer) then
  1570. tloadnode(hpt).set_mp(methodpointer.getcopy)
  1571. else
  1572. tloadnode(hpt).set_mp(cselfnode.create(tobjectdef(symtableprocentry.owner.defowner)));
  1573. end;
  1574. resulttypepass(hpt);
  1575. result:=hpt;
  1576. end
  1577. else
  1578. begin
  1579. if assigned(left) then
  1580. aktfilepos:=left.fileinfo;
  1581. CGMessage(parser_e_wrong_parameter_size);
  1582. symtableprocentry.write_parameter_lists(nil);
  1583. end;
  1584. end;
  1585. goto errorexit;
  1586. end;
  1587. { Retrieve information about the candidates }
  1588. candidates_get_information(procs);
  1589. {$ifdef EXTDEBUG}
  1590. { Display info when multiple candidates are found }
  1591. if assigned(procs^.next) then
  1592. candidates_dump_info(V_Debug,procs);
  1593. {$endif EXTDEBUG}
  1594. { Choose the best candidate and count the number of
  1595. candidates left }
  1596. cand_cnt:=candidates_choose_best(procs,tprocdef(procdefinition));
  1597. { All parameters are checked, check if there are any
  1598. procedures left }
  1599. if cand_cnt>0 then
  1600. begin
  1601. { Multiple candidates left? }
  1602. if cand_cnt>1 then
  1603. begin
  1604. CGMessage(cg_e_cant_choose_overload_function);
  1605. {$ifdef EXTDEBUG}
  1606. candidates_dump_info(V_Hint,procs);
  1607. {$else}
  1608. candidates_list(procs,false);
  1609. {$endif EXTDEBUG}
  1610. { we'll just use the first candidate to make the
  1611. call }
  1612. end;
  1613. { assign procdefinition }
  1614. if symtableproc=nil then
  1615. symtableproc:=procdefinition.owner;
  1616. { update browser information }
  1617. if make_ref then
  1618. begin
  1619. tprocdef(procdefinition).lastref:=tref.create(tprocdef(procdefinition).lastref,@fileinfo);
  1620. inc(tprocdef(procdefinition).refcount);
  1621. if tprocdef(procdefinition).defref=nil then
  1622. tprocdef(procdefinition).defref:=tprocdef(procdefinition).lastref;
  1623. end;
  1624. end
  1625. else
  1626. begin
  1627. { No candidates left, this must be a type error,
  1628. because wrong size is already checked. procdefinition
  1629. is filled with the first (random) definition that is
  1630. found. We use this definition to display a nice error
  1631. message that the wrong type is passed }
  1632. candidates_find_wrong_para(procs);
  1633. candidates_list(procs,true);
  1634. {$ifdef EXTDEBUG}
  1635. candidates_dump_info(V_Hint,procs);
  1636. {$endif EXTDEBUG}
  1637. { We can not proceed, release all procs and exit }
  1638. candidates_free(procs);
  1639. goto errorexit;
  1640. end;
  1641. candidates_free(procs);
  1642. end; { end of procedure to call determination }
  1643. { add needed default parameters }
  1644. if assigned(procdefinition) and
  1645. (paralength<procdefinition.maxparacount) then
  1646. begin
  1647. currpara:=tparaitem(procdefinition.Para.first);
  1648. for i:=1 to paralength do
  1649. currpara:=tparaitem(currpara.next);
  1650. while assigned(currpara) do
  1651. begin
  1652. if not assigned(currpara.defaultvalue) then
  1653. internalerror(200212142);
  1654. left:=ccallparanode.create(genconstsymtree(tconstsym(currpara.defaultvalue)),left);
  1655. currpara:=tparaitem(currpara.next);
  1656. end;
  1657. end;
  1658. end;
  1659. { handle predefined procedures }
  1660. is_const:=(po_internconst in procdefinition.procoptions) and
  1661. ((block_type in [bt_const,bt_type]) or
  1662. (assigned(left) and (tcallparanode(left).left.nodetype in [realconstn,ordconstn])));
  1663. if (procdefinition.proccalloption=pocall_internproc) or is_const then
  1664. begin
  1665. if assigned(left) then
  1666. begin
  1667. { ptr and settextbuf needs two args }
  1668. if assigned(tcallparanode(left).right) then
  1669. begin
  1670. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,left);
  1671. left:=nil;
  1672. end
  1673. else
  1674. begin
  1675. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,tcallparanode(left).left);
  1676. tcallparanode(left).left:=nil;
  1677. end;
  1678. end
  1679. else
  1680. hpt:=geninlinenode(tprocdef(procdefinition).extnumber,is_const,nil);
  1681. result:=hpt;
  1682. goto errorexit;
  1683. end;
  1684. { ensure that the result type is set }
  1685. if not restypeset then
  1686. resulttype:=procdefinition.rettype
  1687. else
  1688. resulttype:=restype;
  1689. { modify the exit code, in case of special cases }
  1690. if (not is_void(resulttype.def)) then
  1691. begin
  1692. if paramanager.ret_in_reg(resulttype.def,procdefinition.proccalloption) then
  1693. begin
  1694. { wide- and ansistrings are returned in EAX }
  1695. { but they are imm. moved to a memory location }
  1696. if is_widestring(resulttype.def) or
  1697. is_ansistring(resulttype.def) then
  1698. begin
  1699. { we use ansistrings so no fast exit here }
  1700. if assigned(procinfo) then
  1701. procinfo.no_fast_exit:=true;
  1702. end;
  1703. end;
  1704. end;
  1705. { constructors return their current class type, not the type where the
  1706. constructor is declared, this can be different because of inheritance }
  1707. if (procdefinition.proctypeoption=potype_constructor) then
  1708. begin
  1709. if assigned(methodpointer) and
  1710. assigned(methodpointer.resulttype.def) and
  1711. (methodpointer.resulttype.def.deftype=classrefdef) then
  1712. resulttype:=tclassrefdef(methodpointer.resulttype.def).pointertype;
  1713. end;
  1714. if assigned(methodpointer) then
  1715. begin
  1716. resulttypepass(methodpointer);
  1717. { if an inherited con- or destructor should be }
  1718. { called in a con- or destructor then a warning }
  1719. { will be made }
  1720. { con- and destructors need a pointer to the vmt }
  1721. if (methodpointer.nodetype=typen) and
  1722. (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1723. is_object(methodpointer.resulttype.def) and
  1724. not(aktprocdef.proctypeoption in [potype_constructor,potype_destructor]) then
  1725. CGMessage(cg_w_member_cd_call_from_method);
  1726. if not(methodpointer.nodetype in [typen,hnewn]) then
  1727. begin
  1728. hpt:=methodpointer;
  1729. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1730. hpt:=tunarynode(hpt).left;
  1731. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) and
  1732. assigned(symtableproc) and
  1733. (symtableproc.symtabletype=withsymtable) and
  1734. (not twithsymtable(symtableproc).direct_with) then
  1735. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1736. { R.Init then R will be initialized by the constructor,
  1737. Also allow it for simple loads }
  1738. if (procdefinition.proctypeoption=potype_constructor) or
  1739. ((hpt.nodetype=loadn) and
  1740. (
  1741. (methodpointer.resulttype.def.deftype=classrefdef) or
  1742. (
  1743. (methodpointer.resulttype.def.deftype=objectdef) and
  1744. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1745. )
  1746. )
  1747. ) then
  1748. method_must_be_valid:=false
  1749. else
  1750. method_must_be_valid:=true;
  1751. set_varstate(methodpointer,method_must_be_valid);
  1752. { The object is already used if it is called once }
  1753. if (hpt.nodetype=loadn) and
  1754. (tloadnode(hpt).symtableentry.typ=varsym) then
  1755. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  1756. end;
  1757. end;
  1758. { bind paraitems to the callparanodes and insert hidden parameters }
  1759. aktcallprocdef:=procdefinition;
  1760. bind_paraitem;
  1761. { insert type conversions for parameters }
  1762. if assigned(left) then
  1763. tcallparanode(left).insert_typeconv(true);
  1764. { direct call to inherited abstract method, then we
  1765. can already give a error in the compiler instead
  1766. of a runtime error }
  1767. if assigned(methodpointer) and
  1768. (methodpointer.nodetype=typen) and
  1769. (po_abstractmethod in procdefinition.procoptions) then
  1770. CGMessage(cg_e_cant_call_abstract_method);
  1771. errorexit:
  1772. aktcallprocdef:=oldcallprocdef;
  1773. end;
  1774. {$ifdef callparatemp}
  1775. function tree_contains_function_call(var n: tnode): foreachnoderesult;
  1776. begin
  1777. result := fen_false;
  1778. if n.nodetype = calln then
  1779. { stop when we encounter a call node }
  1780. result := fen_norecurse_true;
  1781. end;
  1782. function tcallnode.extract_functioncall_paras: tblocknode;
  1783. var
  1784. curpara: tcallparanode;
  1785. newblock: tblocknode;
  1786. newstatement: tstatementnode;
  1787. temp: ttempcreatenode;
  1788. foundcall: boolean;
  1789. begin
  1790. foundcall := false;
  1791. curpara := tcallparanode(left);
  1792. if assigned(curpara) then
  1793. curpara := tcallparanode(curpara.right);
  1794. newblock := nil;
  1795. while assigned(curpara) do
  1796. begin
  1797. if foreachnodestatic(curpara.left,@tree_contains_function_call) then
  1798. begin
  1799. if (not foundcall) then
  1800. begin
  1801. foundcall := true;
  1802. newblock := internalstatements(newstatement);
  1803. end;
  1804. temp := ctempcreatenode.create(curpara.left.resulttype,curpara.left.resulttype.def.size,true);
  1805. addstatement(newstatement,temp);
  1806. resulttypepass(newstatement);
  1807. addstatement(newstatement,
  1808. cassignmentnode.create(ctemprefnode.create(temp),curpara.left));
  1809. resulttypepass(newstatement);
  1810. { after the assignment, turn the temp into a non-persistent one, so }
  1811. { that it will be freed once it's used as parameter }
  1812. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1813. resulttypepass(newstatement);
  1814. curpara.left := ctemprefnode.create(temp);
  1815. { the para's themselves are "resulttypepassed" in in tcallnode.pass_1 }
  1816. end;
  1817. curpara := tcallparanode(curpara.right);
  1818. end;
  1819. result := newblock;
  1820. end;
  1821. {$endif callparatemp}
  1822. function tcallnode.pass_1 : tnode;
  1823. var
  1824. inlinecode : tnode;
  1825. inlined : boolean;
  1826. {$ifdef m68k}
  1827. regi : tregister;
  1828. {$endif}
  1829. {$ifdef callparatemp}
  1830. callparatemps, newblock: tblocknode;
  1831. statement: tstatementnode;
  1832. paras, oldright, newcall: tnode;
  1833. {$endif callparatemp}
  1834. label
  1835. errorexit;
  1836. begin
  1837. result:=nil;
  1838. inlined:=false;
  1839. inlinecode := nil;
  1840. {$ifdef callparatemp}
  1841. callparatemps := extract_functioncall_paras;
  1842. {$endif callparatemp}
  1843. { work trough all parameters to get the register requirements }
  1844. if assigned(left) then
  1845. tcallparanode(left).det_registers;
  1846. { return node }
  1847. if assigned(funcretrefnode) then
  1848. firstpass(funcretrefnode);
  1849. if assigned(procdefinition) and
  1850. (procdefinition.proccalloption=pocall_inline) then
  1851. begin
  1852. inlinecode:=right;
  1853. if assigned(inlinecode) then
  1854. inlined:=true;
  1855. right:=nil;
  1856. end;
  1857. { procedure variable ? }
  1858. if assigned(right) then
  1859. begin
  1860. firstpass(right);
  1861. { procedure does a call }
  1862. if not (block_type in [bt_const,bt_type]) then
  1863. procinfo.flags:=procinfo.flags or pi_do_call;
  1864. rg.incrementintregisterpushed(all_intregisters);
  1865. rg.incrementotherregisterpushed(all_registers);
  1866. end
  1867. else
  1868. { not a procedure variable }
  1869. begin
  1870. { calc the correture value for the register }
  1871. { handle predefined procedures }
  1872. if (procdefinition.proccalloption=pocall_inline) then
  1873. begin
  1874. if assigned(methodpointer) then
  1875. CGMessage(cg_e_unable_inline_object_methods);
  1876. if assigned(right) and (right.nodetype<>procinlinen) then
  1877. CGMessage(cg_e_unable_inline_procvar);
  1878. if not assigned(inlinecode) then
  1879. begin
  1880. if assigned(tprocdef(procdefinition).code) then
  1881. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  1882. else
  1883. CGMessage(cg_e_no_code_for_inline_stored);
  1884. if assigned(inlinecode) then
  1885. begin
  1886. { consider it has not inlined if called
  1887. again inside the args }
  1888. procdefinition.proccalloption:=pocall_fpccall;
  1889. firstpass(inlinecode);
  1890. inlined:=true;
  1891. end;
  1892. end;
  1893. end
  1894. else
  1895. begin
  1896. if not (block_type in [bt_const,bt_type]) then
  1897. procinfo.flags:=procinfo.flags or pi_do_call;
  1898. end;
  1899. { It doesn't hurt to calculate it already though :) (JM) }
  1900. rg.incrementintregisterpushed(tprocdef(procdefinition).usedintregisters);
  1901. rg.incrementotherregisterpushed(tprocdef(procdefinition).usedotherregisters);
  1902. end;
  1903. { get a register for the return value }
  1904. if (not is_void(resulttype.def)) then
  1905. begin
  1906. { for win32 records returned in EDX:EAX, we
  1907. move them to memory after ... }
  1908. if (resulttype.def.deftype=recorddef) then
  1909. begin
  1910. expectloc:=LOC_CREFERENCE;
  1911. end
  1912. else
  1913. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1914. begin
  1915. expectloc:=LOC_CREFERENCE;
  1916. end
  1917. else
  1918. { ansi/widestrings must be registered, so we can dispose them }
  1919. if is_ansistring(resulttype.def) or
  1920. is_widestring(resulttype.def) then
  1921. begin
  1922. expectloc:=LOC_CREFERENCE;
  1923. registers32:=1;
  1924. end
  1925. else
  1926. { we have only to handle the result if it is used }
  1927. if (nf_return_value_used in flags) then
  1928. begin
  1929. case resulttype.def.deftype of
  1930. enumdef,
  1931. orddef :
  1932. begin
  1933. if (procdefinition.proctypeoption=potype_constructor) then
  1934. begin
  1935. if assigned(methodpointer) and
  1936. (methodpointer.resulttype.def.deftype=classrefdef) then
  1937. begin
  1938. expectloc:=LOC_REGISTER;
  1939. registers32:=1;
  1940. end
  1941. else
  1942. expectloc:=LOC_FLAGS;
  1943. end
  1944. else
  1945. begin
  1946. expectloc:=LOC_REGISTER;
  1947. if is_64bitint(resulttype.def) then
  1948. registers32:=2
  1949. else
  1950. registers32:=1;
  1951. end;
  1952. end;
  1953. floatdef :
  1954. begin
  1955. expectloc:=LOC_FPUREGISTER;
  1956. {$ifdef cpufpemu}
  1957. if (cs_fp_emulation in aktmoduleswitches) then
  1958. registers32:=1
  1959. else
  1960. {$endif cpufpemu}
  1961. {$ifdef m68k}
  1962. if (tfloatdef(resulttype.def).typ=s32real) then
  1963. registers32:=1
  1964. else
  1965. {$endif m68k}
  1966. registersfpu:=1;
  1967. end;
  1968. else
  1969. begin
  1970. expectloc:=LOC_REGISTER;
  1971. registers32:=1;
  1972. end;
  1973. end;
  1974. end
  1975. else
  1976. expectloc:=LOC_VOID;
  1977. end
  1978. else
  1979. expectloc:=LOC_VOID;
  1980. {$ifdef m68k}
  1981. { we need one more address register for virtual calls on m68k }
  1982. if (po_virtualmethod in procdefinition.procoptions) then
  1983. inc(registers32);
  1984. {$endif m68k}
  1985. { a fpu can be used in any procedure !! }
  1986. {$ifdef i386}
  1987. registersfpu:=procdefinition.fpu_used;
  1988. {$endif i386}
  1989. { if this is a call to a method calc the registers }
  1990. if (methodpointer<>nil) then
  1991. begin
  1992. if methodpointer.nodetype<>typen then
  1993. firstpass(methodpointer);
  1994. { if we are calling the constructor }
  1995. if procdefinition.proctypeoption in [potype_constructor] then
  1996. verifyabstractcalls;
  1997. case methodpointer.nodetype of
  1998. { but only, if this is not a supporting node }
  1999. typen: ;
  2000. { we need one register for new return value PM }
  2001. hnewn : if registers32=0 then
  2002. registers32:=1;
  2003. else
  2004. begin
  2005. { this is not a good reason to accept it in FPC if we produce
  2006. wrong code for it !!! (PM) }
  2007. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2008. registers32:=max(methodpointer.registers32,registers32);
  2009. {$ifdef SUPPORT_MMX }
  2010. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2011. {$endif SUPPORT_MMX}
  2012. end;
  2013. end;
  2014. end;
  2015. if inlined then
  2016. right:=inlinecode;
  2017. { determine the registers of the procedure variable }
  2018. { is this OK for inlined procs also ?? (PM) }
  2019. if assigned(right) then
  2020. begin
  2021. registersfpu:=max(right.registersfpu,registersfpu);
  2022. registers32:=max(right.registers32,registers32);
  2023. {$ifdef SUPPORT_MMX}
  2024. registersmmx:=max(right.registersmmx,registersmmx);
  2025. {$endif SUPPORT_MMX}
  2026. end;
  2027. { determine the registers of the procedure }
  2028. if assigned(left) then
  2029. begin
  2030. registersfpu:=max(left.registersfpu,registersfpu);
  2031. registers32:=max(left.registers32,registers32);
  2032. {$ifdef SUPPORT_MMX}
  2033. registersmmx:=max(left.registersmmx,registersmmx);
  2034. {$endif SUPPORT_MMX}
  2035. end;
  2036. {$ifdef callparatemp}
  2037. if (callparatemps <> nil) then
  2038. begin
  2039. { we have to replace the callnode with a blocknode. firstpass will }
  2040. { free the original call node. Avoid copying all subnodes though }
  2041. paras := left;
  2042. oldright := right;
  2043. left := nil;
  2044. right := nil;
  2045. newcall := self.getcopy;
  2046. tcallnode(newcall).left := paras;
  2047. tcallnode(newcall).right := oldright;
  2048. newblock := internalstatements(statement);
  2049. addstatement(statement,callparatemps);
  2050. { add the copy of the call node after the callparatemps block }
  2051. { and return that. The last statement of a bocknode determines }
  2052. { the resulttype & location of the block -> ok. Working with a }
  2053. { new block is easier than going to the end of the callparatemps }
  2054. { block (JM) }
  2055. addstatement(statement,newcall);
  2056. result := newblock;
  2057. { set to nil so we can free this one in case of an errorexit }
  2058. callparatemps := nil;
  2059. end;
  2060. {$endif callparatemp}
  2061. errorexit:
  2062. if inlined then
  2063. procdefinition.proccalloption:=pocall_inline;
  2064. {$ifdef callparatemp}
  2065. if assigned(callparatemps) then
  2066. callparatemps.free;
  2067. {$endif callparatemp}
  2068. end;
  2069. {$ifdef state_tracking}
  2070. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2071. var hp:Tcallparanode;
  2072. value:Tnode;
  2073. begin
  2074. track_state_pass:=false;
  2075. hp:=Tcallparanode(left);
  2076. while assigned(hp) do
  2077. begin
  2078. if left.track_state_pass(exec_known) then
  2079. begin
  2080. left.resulttype.def:=nil;
  2081. do_resulttypepass(left);
  2082. end;
  2083. value:=aktstate.find_fact(hp.left);
  2084. if value<>nil then
  2085. begin
  2086. track_state_pass:=true;
  2087. hp.left.destroy;
  2088. hp.left:=value.getcopy;
  2089. do_resulttypepass(hp.left);
  2090. end;
  2091. hp:=Tcallparanode(hp.right);
  2092. end;
  2093. end;
  2094. {$endif}
  2095. function tcallnode.docompare(p: tnode): boolean;
  2096. begin
  2097. docompare :=
  2098. inherited docompare(p) and
  2099. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2100. (procdefinition = tcallnode(p).procdefinition) and
  2101. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2102. ((restypeset and tcallnode(p).restypeset and
  2103. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2104. (not restypeset and not tcallnode(p).restypeset));
  2105. end;
  2106. {****************************************************************************
  2107. TPROCINLINENODE
  2108. ****************************************************************************}
  2109. constructor tprocinlinenode.create(p:tprocdef);
  2110. begin
  2111. inherited create(procinlinen);
  2112. inlineprocdef:=p;
  2113. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2114. para_offset:=0;
  2115. para_size:=0;
  2116. { copy inlinetree }
  2117. if assigned(p.code) then
  2118. inlinetree:=p.code.getcopy
  2119. else
  2120. inlinetree:=nil;
  2121. end;
  2122. destructor tprocinlinenode.destroy;
  2123. begin
  2124. if assigned(inlinetree) then
  2125. inlinetree.free;
  2126. inherited destroy;
  2127. end;
  2128. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2129. begin
  2130. inherited ppuload(t,ppufile);
  2131. inlineprocdef:=tprocdef(ppufile.getderef);
  2132. inlinetree:=ppuloadnode(ppufile);
  2133. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2134. para_offset:=0;
  2135. para_size:=0;
  2136. end;
  2137. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2138. begin
  2139. inherited ppuwrite(ppufile);
  2140. ppufile.putderef(inlineprocdef);
  2141. ppuwritenode(ppufile,inlinetree);
  2142. end;
  2143. procedure tprocinlinenode.derefimpl;
  2144. begin
  2145. inherited derefimpl;
  2146. if assigned(inlinetree) then
  2147. inlinetree.derefimpl;
  2148. resolvedef(pointer(inlineprocdef));
  2149. end;
  2150. function tprocinlinenode.getcopy : tnode;
  2151. var
  2152. n : tprocinlinenode;
  2153. begin
  2154. n:=tprocinlinenode(inherited getcopy);
  2155. n.inlineprocdef:=inlineprocdef;
  2156. if assigned(inlinetree) then
  2157. n.inlinetree:=inlinetree.getcopy
  2158. else
  2159. n.inlinetree:=nil;
  2160. n.retoffset:=retoffset;
  2161. n.para_offset:=para_offset;
  2162. n.para_size:=para_size;
  2163. getcopy:=n;
  2164. end;
  2165. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2166. begin
  2167. end;
  2168. function tprocinlinenode.det_resulttype : tnode;
  2169. var
  2170. storesymtablelevel : longint;
  2171. storeparasymtable,
  2172. storelocalsymtable : tsymtabletype;
  2173. oldprocdef : tprocdef;
  2174. oldprocinfo : tprocinfo;
  2175. oldinlining_procedure : boolean;
  2176. begin
  2177. result:=nil;
  2178. oldinlining_procedure:=inlining_procedure;
  2179. oldprocdef:=aktprocdef;
  2180. oldprocinfo:=procinfo;
  2181. { we're inlining a procedure }
  2182. inlining_procedure:=true;
  2183. aktprocdef:=inlineprocdef;
  2184. { clone procinfo, but not the asmlists }
  2185. procinfo:=tprocinfo(cprocinfo.newinstance);
  2186. move(pointer(oldprocinfo)^,pointer(procinfo)^,cprocinfo.InstanceSize);
  2187. procinfo.aktentrycode:=nil;
  2188. procinfo.aktexitcode:=nil;
  2189. procinfo.aktproccode:=nil;
  2190. procinfo.aktlocaldata:=nil;
  2191. { set new procinfo }
  2192. procinfo.return_offset:=retoffset;
  2193. procinfo.para_offset:=para_offset;
  2194. procinfo.no_fast_exit:=false;
  2195. { set it to the same lexical level }
  2196. storesymtablelevel:=aktprocdef.localst.symtablelevel;
  2197. storelocalsymtable:=aktprocdef.localst.symtabletype;
  2198. storeparasymtable:=aktprocdef.parast.symtabletype;
  2199. aktprocdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  2200. aktprocdef.localst.symtabletype:=inlinelocalsymtable;
  2201. aktprocdef.parast.symtabletype:=inlineparasymtable;
  2202. { pass inlinetree }
  2203. resulttypepass(inlinetree);
  2204. resulttype:=inlineprocdef.rettype;
  2205. { retrieve info from inlineprocdef }
  2206. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2207. para_offset:=0;
  2208. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2209. if paramanager.ret_in_param(inlineprocdef.rettype.def,inlineprocdef.proccalloption) then
  2210. inc(para_size,POINTER_SIZE);
  2211. { restore procinfo }
  2212. procinfo.free;
  2213. procinfo:=oldprocinfo;
  2214. { restore symtable }
  2215. aktprocdef.localst.symtablelevel:=storesymtablelevel;
  2216. aktprocdef.localst.symtabletype:=storelocalsymtable;
  2217. aktprocdef.parast.symtabletype:=storeparasymtable;
  2218. { restore }
  2219. aktprocdef:=oldprocdef;
  2220. inlining_procedure:=oldinlining_procedure;
  2221. end;
  2222. function tprocinlinenode.pass_1 : tnode;
  2223. begin
  2224. firstpass(inlinetree);
  2225. registers32:=inlinetree.registers32;
  2226. registersfpu:=inlinetree.registersfpu;
  2227. {$ifdef SUPPORT_MMX}
  2228. registersmmx:=inlinetree.registersmmx;
  2229. {$endif SUPPORT_MMX}
  2230. result:=nil;
  2231. end;
  2232. function tprocinlinenode.docompare(p: tnode): boolean;
  2233. begin
  2234. docompare :=
  2235. inherited docompare(p) and
  2236. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2237. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2238. end;
  2239. begin
  2240. ccallnode:=tcallnode;
  2241. ccallparanode:=tcallparanode;
  2242. cprocinlinenode:=tprocinlinenode;
  2243. end.
  2244. {
  2245. $Log$
  2246. Revision 1.141 2003-04-23 13:21:06 peter
  2247. * fix warning for calling constructor inside constructor
  2248. Revision 1.140 2003/04/23 12:35:34 florian
  2249. * fixed several issues with powerpc
  2250. + applied a patch from Jonas for nested function calls (PowerPC only)
  2251. * ...
  2252. Revision 1.139 2003/04/22 23:50:22 peter
  2253. * firstpass uses expectloc
  2254. * checks if there are differences between the expectloc and
  2255. location.loc from secondpass in EXTDEBUG
  2256. Revision 1.138 2003/04/22 09:53:33 peter
  2257. * fix insert_typeconv to handle new varargs which don't have a
  2258. paraitem set
  2259. Revision 1.137 2003/04/11 16:02:05 peter
  2260. * don't firstpass typen
  2261. Revision 1.136 2003/04/11 15:51:04 peter
  2262. * support subscript,vec for setting methodpointer varstate
  2263. Revision 1.135 2003/04/10 17:57:52 peter
  2264. * vs_hidden released
  2265. Revision 1.134 2003/04/07 11:58:22 jonas
  2266. * more vs_invisible fixes
  2267. Revision 1.133 2003/04/07 10:40:21 jonas
  2268. * fixed VS_HIDDEN for high parameter so it works again
  2269. Revision 1.132 2003/04/04 15:38:56 peter
  2270. * moved generic code from n386cal to ncgcal, i386 now also
  2271. uses the generic ncgcal
  2272. Revision 1.131 2003/03/17 18:54:23 peter
  2273. * fix missing self setting for method to procvar conversion in
  2274. tp_procvar mode
  2275. Revision 1.130 2003/03/17 16:54:41 peter
  2276. * support DefaultHandler and anonymous inheritance fixed
  2277. for message methods
  2278. Revision 1.129 2003/03/17 15:54:22 peter
  2279. * store symoptions also for procdef
  2280. * check symoptions (private,public) when calculating possible
  2281. overload candidates
  2282. Revision 1.128 2003/02/19 22:00:14 daniel
  2283. * Code generator converted to new register notation
  2284. - Horribily outdated todo.txt removed
  2285. Revision 1.127 2003/01/16 22:13:52 peter
  2286. * convert_l3 convertlevel added. This level is used for conversions
  2287. where information can be lost like converting widestring->ansistring
  2288. or dword->byte
  2289. Revision 1.126 2003/01/15 01:44:32 peter
  2290. * merged methodpointer fixes from 1.0.x
  2291. Revision 1.125 2003/01/12 17:52:07 peter
  2292. * only check for auto inherited in objectsymtable
  2293. Revision 1.124 2003/01/09 21:45:46 peter
  2294. * extended information about overloaded candidates when compiled
  2295. with EXTDEBUG
  2296. Revision 1.123 2002/12/26 18:24:33 jonas
  2297. * fixed check for whether or not a high parameter was already generated
  2298. * no type checking/conversions for invisible parameters
  2299. Revision 1.122 2002/12/15 22:50:00 florian
  2300. + some stuff for the new hidden parameter handling added
  2301. Revision 1.121 2002/12/15 21:34:15 peter
  2302. * give sign difference between ordinals a small penalty. This is
  2303. needed to get word->[longword|longint] working
  2304. Revision 1.120 2002/12/15 21:30:12 florian
  2305. * tcallnode.paraitem introduced, all references to defcoll removed
  2306. Revision 1.119 2002/12/15 20:59:58 peter
  2307. * fix crash with default parameters
  2308. Revision 1.118 2002/12/15 11:26:02 peter
  2309. * ignore vs_hidden parameters when choosing overloaded proc
  2310. Revision 1.117 2002/12/11 22:42:28 peter
  2311. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2312. the old code. The new code collects the information about possible
  2313. candidates only once resultting in much less calls to type compare
  2314. routines
  2315. Revision 1.116 2002/12/07 14:27:07 carl
  2316. * 3% memory optimization
  2317. * changed some types
  2318. + added type checking with different size for call node and for
  2319. parameters
  2320. Revision 1.115 2002/12/06 17:51:10 peter
  2321. * merged cdecl and array fixes
  2322. Revision 1.114 2002/12/06 16:56:58 peter
  2323. * only compile cs_fp_emulation support when cpufpuemu is defined
  2324. * define cpufpuemu for m68k only
  2325. Revision 1.113 2002/11/27 20:04:38 peter
  2326. * cdecl array of const fixes
  2327. Revision 1.112 2002/11/27 15:33:46 peter
  2328. * the never ending story of tp procvar hacks
  2329. Revision 1.111 2002/11/27 02:31:17 peter
  2330. * fixed inlinetree parsing in det_resulttype
  2331. Revision 1.110 2002/11/25 18:43:32 carl
  2332. - removed the invalid if <> checking (Delphi is strange on this)
  2333. + implemented abstract warning on instance creation of class with
  2334. abstract methods.
  2335. * some error message cleanups
  2336. Revision 1.109 2002/11/25 17:43:17 peter
  2337. * splitted defbase in defutil,symutil,defcmp
  2338. * merged isconvertable and is_equal into compare_defs(_ext)
  2339. * made operator search faster by walking the list only once
  2340. Revision 1.108 2002/11/18 17:31:54 peter
  2341. * pass proccalloption to ret_in_xxx and push_xxx functions
  2342. Revision 1.107 2002/11/15 01:58:50 peter
  2343. * merged changes from 1.0.7 up to 04-11
  2344. - -V option for generating bug report tracing
  2345. - more tracing for option parsing
  2346. - errors for cdecl and high()
  2347. - win32 import stabs
  2348. - win32 records<=8 are returned in eax:edx (turned off by default)
  2349. - heaptrc update
  2350. - more info for temp management in .s file with EXTDEBUG
  2351. Revision 1.106 2002/10/14 18:20:30 carl
  2352. * var parameter checking for classes and interfaces in Delphi mode
  2353. Revision 1.105 2002/10/06 21:02:17 peter
  2354. * fixed limit checking for qword
  2355. Revision 1.104 2002/10/05 15:15:45 peter
  2356. * Write unknwon compiler proc using Comment and only in Extdebug
  2357. Revision 1.103 2002/10/05 12:43:25 carl
  2358. * fixes for Delphi 6 compilation
  2359. (warning : Some features do not work under Delphi)
  2360. Revision 1.102 2002/10/05 00:48:57 peter
  2361. * support inherited; support for overload as it is handled by
  2362. delphi. This is only for delphi mode as it is working is
  2363. undocumented and hard to predict what is done
  2364. Revision 1.101 2002/09/16 14:11:12 peter
  2365. * add argument to equal_paras() to support default values or not
  2366. Revision 1.100 2002/09/15 17:49:59 peter
  2367. * don't have strict var parameter checking for procedures in the
  2368. system unit
  2369. Revision 1.99 2002/09/09 19:30:34 peter
  2370. * don't allow convertable parameters for var and out parameters in
  2371. delphi and tp mode
  2372. Revision 1.98 2002/09/07 15:25:02 peter
  2373. * old logs removed and tabs fixed
  2374. Revision 1.97 2002/09/07 12:16:05 carl
  2375. * second part bug report 1996 fix, testrange in cordconstnode
  2376. only called if option is set (also make parsing a tiny faster)
  2377. Revision 1.96 2002/09/05 14:53:41 peter
  2378. * fixed old callnode.det_resulttype code
  2379. * old ncal code is default again
  2380. Revision 1.95 2002/09/03 21:32:49 daniel
  2381. * Small bugfix for procdef selection
  2382. Revision 1.94 2002/09/03 19:27:22 daniel
  2383. * Activated new ncal code
  2384. Revision 1.93 2002/09/03 16:26:26 daniel
  2385. * Make Tprocdef.defs protected
  2386. Revision 1.92 2002/09/01 13:28:37 daniel
  2387. - write_access fields removed in favor of a flag
  2388. Revision 1.91 2002/09/01 12:14:15 peter
  2389. * remove debug line
  2390. * containself methods can be called directly
  2391. Revision 1.90 2002/09/01 08:01:16 daniel
  2392. * Removed sets from Tcallnode.det_resulttype
  2393. + Added read/write notifications of variables. These will be usefull
  2394. for providing information for several optimizations. For example
  2395. the value of the loop variable of a for loop does matter is the
  2396. variable is read after the for loop, but if it's no longer used
  2397. or written, it doesn't matter and this can be used to optimize
  2398. the loop code generation.
  2399. Revision 1.89 2002/08/23 16:13:16 peter
  2400. * also firstpass funcretrefnode if available. This was breaking the
  2401. asnode compilerproc code
  2402. Revision 1.88 2002/08/20 10:31:26 daniel
  2403. * Tcallnode.det_resulttype rewritten
  2404. Revision 1.87 2002/08/19 19:36:42 peter
  2405. * More fixes for cross unit inlining, all tnodes are now implemented
  2406. * Moved pocall_internconst to po_internconst because it is not a
  2407. calling type at all and it conflicted when inlining of these small
  2408. functions was requested
  2409. Revision 1.86 2002/08/17 22:09:44 florian
  2410. * result type handling in tcgcal.pass_2 overhauled
  2411. * better tnode.dowrite
  2412. * some ppc stuff fixed
  2413. Revision 1.85 2002/08/17 09:23:34 florian
  2414. * first part of procinfo rewrite
  2415. Revision 1.84 2002/08/16 14:24:57 carl
  2416. * issameref() to test if two references are the same (then emit no opcodes)
  2417. + ret_in_reg to replace ret_in_acc
  2418. (fix some register allocation bugs at the same time)
  2419. + save_std_register now has an extra parameter which is the
  2420. usedinproc registers
  2421. Revision 1.83 2002/07/20 11:57:53 florian
  2422. * types.pas renamed to defbase.pas because D6 contains a types
  2423. unit so this would conflicts if D6 programms are compiled
  2424. + Willamette/SSE2 instructions to assembler added
  2425. Revision 1.82 2002/07/19 11:41:35 daniel
  2426. * State tracker work
  2427. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2428. allows the state tracker to change while nodes automatically into
  2429. repeat nodes.
  2430. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2431. 'not(a>b)' is optimized into 'a<=b'.
  2432. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2433. by removing the notn and later switchting the true and falselabels. The
  2434. same is done with 'repeat until not a'.
  2435. Revision 1.81 2002/07/15 18:03:14 florian
  2436. * readded removed changes
  2437. Revision 1.79 2002/07/11 14:41:27 florian
  2438. * start of the new generic parameter handling
  2439. Revision 1.80 2002/07/14 18:00:43 daniel
  2440. + Added the beginning of a state tracker. This will track the values of
  2441. variables through procedures and optimize things away.
  2442. Revision 1.78 2002/07/04 20:43:00 florian
  2443. * first x86-64 patches
  2444. }