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 not(methodpointer.nodetype in [typen,hnewn]) then
  1718. begin
  1719. hpt:=methodpointer;
  1720. while assigned(hpt) and (hpt.nodetype in [subscriptn,vecn]) do
  1721. hpt:=tunarynode(hpt).left;
  1722. if (procdefinition.proctypeoption in [potype_constructor,potype_destructor]) then
  1723. begin
  1724. { if an inherited con- or destructor should be }
  1725. { called in a con- or destructor then a warning }
  1726. { will be made }
  1727. { con- and destructors need a pointer to the vmt }
  1728. if is_object(methodpointer.resulttype.def) and
  1729. not(aktprocdef.proctypeoption in
  1730. [potype_constructor,potype_destructor]) then
  1731. CGMessage(cg_w_member_cd_call_from_method);
  1732. if assigned(symtableproc) and
  1733. (symtableproc.symtabletype=withsymtable) and
  1734. (not twithsymtable(symtableproc).direct_with) then
  1735. begin
  1736. CGmessage(cg_e_cannot_call_cons_dest_inside_with);
  1737. end; { Is accepted by Delphi !! }
  1738. end;
  1739. { R.Init then R will be initialized by the constructor,
  1740. Also allow it for simple loads }
  1741. if (procdefinition.proctypeoption=potype_constructor) or
  1742. ((hpt.nodetype=loadn) and
  1743. (
  1744. (methodpointer.resulttype.def.deftype=classrefdef) or
  1745. (
  1746. (methodpointer.resulttype.def.deftype=objectdef) and
  1747. not(oo_has_virtual in tobjectdef(methodpointer.resulttype.def).objectoptions)
  1748. )
  1749. )
  1750. ) then
  1751. method_must_be_valid:=false
  1752. else
  1753. method_must_be_valid:=true;
  1754. set_varstate(methodpointer,method_must_be_valid);
  1755. { The object is already used if it is called once }
  1756. if (hpt.nodetype=loadn) and
  1757. (tloadnode(hpt).symtableentry.typ=varsym) then
  1758. tvarsym(tloadnode(hpt).symtableentry).varstate:=vs_used;
  1759. end;
  1760. end;
  1761. { bind paraitems to the callparanodes and insert hidden parameters }
  1762. aktcallprocdef:=procdefinition;
  1763. bind_paraitem;
  1764. { insert type conversions for parameters }
  1765. if assigned(left) then
  1766. tcallparanode(left).insert_typeconv(true);
  1767. { direct call to inherited abstract method, then we
  1768. can already give a error in the compiler instead
  1769. of a runtime error }
  1770. if assigned(methodpointer) and
  1771. (methodpointer.nodetype=typen) and
  1772. (po_abstractmethod in procdefinition.procoptions) then
  1773. CGMessage(cg_e_cant_call_abstract_method);
  1774. errorexit:
  1775. aktcallprocdef:=oldcallprocdef;
  1776. end;
  1777. {$ifdef callparatemp}
  1778. function tree_contains_function_call(var n: tnode): foreachnoderesult;
  1779. begin
  1780. result := fen_false;
  1781. if n.nodetype = calln then
  1782. { stop when we encounter a call node }
  1783. result := fen_norecurse_true;
  1784. end;
  1785. function tcallnode.extract_functioncall_paras: tblocknode;
  1786. var
  1787. curpara: tcallparanode;
  1788. newblock: tblocknode;
  1789. newstatement: tstatementnode;
  1790. temp: ttempcreatenode;
  1791. foundcall: boolean;
  1792. begin
  1793. foundcall := false;
  1794. curpara := tcallparanode(left);
  1795. if assigned(curpara) then
  1796. curpara := tcallparanode(curpara.right);
  1797. newblock := nil;
  1798. while assigned(curpara) do
  1799. begin
  1800. if foreachnodestatic(curpara.left,@tree_contains_function_call) then
  1801. begin
  1802. if (not foundcall) then
  1803. begin
  1804. foundcall := true;
  1805. newblock := internalstatements(newstatement);
  1806. end;
  1807. temp := ctempcreatenode.create(curpara.left.resulttype,curpara.left.resulttype.def.size,true);
  1808. addstatement(newstatement,temp);
  1809. resulttypepass(newstatement);
  1810. addstatement(newstatement,
  1811. cassignmentnode.create(ctemprefnode.create(temp),curpara.left));
  1812. resulttypepass(newstatement);
  1813. { after the assignment, turn the temp into a non-persistent one, so }
  1814. { that it will be freed once it's used as parameter }
  1815. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1816. resulttypepass(newstatement);
  1817. curpara.left := ctemprefnode.create(temp);
  1818. { the para's themselves are "resulttypepassed" in in tcallnode.pass_1 }
  1819. end;
  1820. curpara := tcallparanode(curpara.right);
  1821. end;
  1822. result := newblock;
  1823. end;
  1824. {$endif callparatemp}
  1825. function tcallnode.pass_1 : tnode;
  1826. var
  1827. inlinecode : tnode;
  1828. inlined : boolean;
  1829. {$ifdef m68k}
  1830. regi : tregister;
  1831. {$endif}
  1832. {$ifdef callparatemp}
  1833. callparatemps, newblock: tblocknode;
  1834. statement: tstatementnode;
  1835. paras, oldright, newcall: tnode;
  1836. {$endif callparatemp}
  1837. label
  1838. errorexit;
  1839. begin
  1840. result:=nil;
  1841. inlined:=false;
  1842. inlinecode := nil;
  1843. {$ifdef callparatemp}
  1844. callparatemps := extract_functioncall_paras;
  1845. {$endif callparatemp}
  1846. { work trough all parameters to get the register requirements }
  1847. if assigned(left) then
  1848. tcallparanode(left).det_registers;
  1849. { return node }
  1850. if assigned(funcretrefnode) then
  1851. firstpass(funcretrefnode);
  1852. if assigned(procdefinition) and
  1853. (procdefinition.proccalloption=pocall_inline) then
  1854. begin
  1855. inlinecode:=right;
  1856. if assigned(inlinecode) then
  1857. inlined:=true;
  1858. right:=nil;
  1859. end;
  1860. { procedure variable ? }
  1861. if assigned(right) then
  1862. begin
  1863. firstpass(right);
  1864. { procedure does a call }
  1865. if not (block_type in [bt_const,bt_type]) then
  1866. procinfo.flags:=procinfo.flags or pi_do_call;
  1867. rg.incrementintregisterpushed(all_intregisters);
  1868. rg.incrementotherregisterpushed(all_registers);
  1869. end
  1870. else
  1871. { not a procedure variable }
  1872. begin
  1873. { calc the correture value for the register }
  1874. { handle predefined procedures }
  1875. if (procdefinition.proccalloption=pocall_inline) then
  1876. begin
  1877. if assigned(methodpointer) then
  1878. CGMessage(cg_e_unable_inline_object_methods);
  1879. if assigned(right) and (right.nodetype<>procinlinen) then
  1880. CGMessage(cg_e_unable_inline_procvar);
  1881. if not assigned(inlinecode) then
  1882. begin
  1883. if assigned(tprocdef(procdefinition).code) then
  1884. inlinecode:=cprocinlinenode.create(tprocdef(procdefinition))
  1885. else
  1886. CGMessage(cg_e_no_code_for_inline_stored);
  1887. if assigned(inlinecode) then
  1888. begin
  1889. { consider it has not inlined if called
  1890. again inside the args }
  1891. procdefinition.proccalloption:=pocall_fpccall;
  1892. firstpass(inlinecode);
  1893. inlined:=true;
  1894. end;
  1895. end;
  1896. end
  1897. else
  1898. begin
  1899. if not (block_type in [bt_const,bt_type]) then
  1900. procinfo.flags:=procinfo.flags or pi_do_call;
  1901. end;
  1902. { It doesn't hurt to calculate it already though :) (JM) }
  1903. rg.incrementintregisterpushed(tprocdef(procdefinition).usedintregisters);
  1904. rg.incrementotherregisterpushed(tprocdef(procdefinition).usedotherregisters);
  1905. end;
  1906. { get a register for the return value }
  1907. if (not is_void(resulttype.def)) then
  1908. begin
  1909. { for win32 records returned in EDX:EAX, we
  1910. move them to memory after ... }
  1911. if (resulttype.def.deftype=recorddef) then
  1912. begin
  1913. expectloc:=LOC_CREFERENCE;
  1914. end
  1915. else
  1916. if paramanager.ret_in_param(resulttype.def,procdefinition.proccalloption) then
  1917. begin
  1918. expectloc:=LOC_CREFERENCE;
  1919. end
  1920. else
  1921. { ansi/widestrings must be registered, so we can dispose them }
  1922. if is_ansistring(resulttype.def) or
  1923. is_widestring(resulttype.def) then
  1924. begin
  1925. expectloc:=LOC_CREFERENCE;
  1926. registers32:=1;
  1927. end
  1928. else
  1929. { we have only to handle the result if it is used }
  1930. if (nf_return_value_used in flags) then
  1931. begin
  1932. case resulttype.def.deftype of
  1933. enumdef,
  1934. orddef :
  1935. begin
  1936. if (procdefinition.proctypeoption=potype_constructor) then
  1937. begin
  1938. if assigned(methodpointer) and
  1939. (methodpointer.resulttype.def.deftype=classrefdef) then
  1940. begin
  1941. expectloc:=LOC_REGISTER;
  1942. registers32:=1;
  1943. end
  1944. else
  1945. expectloc:=LOC_FLAGS;
  1946. end
  1947. else
  1948. begin
  1949. expectloc:=LOC_REGISTER;
  1950. if is_64bitint(resulttype.def) then
  1951. registers32:=2
  1952. else
  1953. registers32:=1;
  1954. end;
  1955. end;
  1956. floatdef :
  1957. begin
  1958. expectloc:=LOC_FPUREGISTER;
  1959. {$ifdef cpufpemu}
  1960. if (cs_fp_emulation in aktmoduleswitches) then
  1961. registers32:=1
  1962. else
  1963. {$endif cpufpemu}
  1964. {$ifdef m68k}
  1965. if (tfloatdef(resulttype.def).typ=s32real) then
  1966. registers32:=1
  1967. else
  1968. {$endif m68k}
  1969. registersfpu:=1;
  1970. end;
  1971. else
  1972. begin
  1973. expectloc:=LOC_REGISTER;
  1974. registers32:=1;
  1975. end;
  1976. end;
  1977. end
  1978. else
  1979. expectloc:=LOC_VOID;
  1980. end
  1981. else
  1982. expectloc:=LOC_VOID;
  1983. {$ifdef m68k}
  1984. { we need one more address register for virtual calls on m68k }
  1985. if (po_virtualmethod in procdefinition.procoptions) then
  1986. inc(registers32);
  1987. {$endif m68k}
  1988. { a fpu can be used in any procedure !! }
  1989. {$ifdef i386}
  1990. registersfpu:=procdefinition.fpu_used;
  1991. {$endif i386}
  1992. { if this is a call to a method calc the registers }
  1993. if (methodpointer<>nil) then
  1994. begin
  1995. if methodpointer.nodetype<>typen then
  1996. firstpass(methodpointer);
  1997. { if we are calling the constructor }
  1998. if procdefinition.proctypeoption in [potype_constructor] then
  1999. verifyabstractcalls;
  2000. case methodpointer.nodetype of
  2001. { but only, if this is not a supporting node }
  2002. typen: ;
  2003. { we need one register for new return value PM }
  2004. hnewn : if registers32=0 then
  2005. registers32:=1;
  2006. else
  2007. begin
  2008. { this is not a good reason to accept it in FPC if we produce
  2009. wrong code for it !!! (PM) }
  2010. registersfpu:=max(methodpointer.registersfpu,registersfpu);
  2011. registers32:=max(methodpointer.registers32,registers32);
  2012. {$ifdef SUPPORT_MMX }
  2013. registersmmx:=max(methodpointer.registersmmx,registersmmx);
  2014. {$endif SUPPORT_MMX}
  2015. end;
  2016. end;
  2017. end;
  2018. if inlined then
  2019. right:=inlinecode;
  2020. { determine the registers of the procedure variable }
  2021. { is this OK for inlined procs also ?? (PM) }
  2022. if assigned(right) then
  2023. begin
  2024. registersfpu:=max(right.registersfpu,registersfpu);
  2025. registers32:=max(right.registers32,registers32);
  2026. {$ifdef SUPPORT_MMX}
  2027. registersmmx:=max(right.registersmmx,registersmmx);
  2028. {$endif SUPPORT_MMX}
  2029. end;
  2030. { determine the registers of the procedure }
  2031. if assigned(left) then
  2032. begin
  2033. registersfpu:=max(left.registersfpu,registersfpu);
  2034. registers32:=max(left.registers32,registers32);
  2035. {$ifdef SUPPORT_MMX}
  2036. registersmmx:=max(left.registersmmx,registersmmx);
  2037. {$endif SUPPORT_MMX}
  2038. end;
  2039. {$ifdef callparatemp}
  2040. if (callparatemps <> nil) then
  2041. begin
  2042. { we have to replace the callnode with a blocknode. firstpass will }
  2043. { free the original call node. Avoid copying all subnodes though }
  2044. paras := left;
  2045. oldright := right;
  2046. left := nil;
  2047. right := nil;
  2048. newcall := self.getcopy;
  2049. tcallnode(newcall).left := paras;
  2050. tcallnode(newcall).right := oldright;
  2051. newblock := internalstatements(statement);
  2052. addstatement(statement,callparatemps);
  2053. { add the copy of the call node after the callparatemps block }
  2054. { and return that. The last statement of a bocknode determines }
  2055. { the resulttype & location of the block -> ok. Working with a }
  2056. { new block is easier than going to the end of the callparatemps }
  2057. { block (JM) }
  2058. addstatement(statement,newcall);
  2059. result := newblock;
  2060. { set to nil so we can free this one in case of an errorexit }
  2061. callparatemps := nil;
  2062. end;
  2063. {$endif callparatemp}
  2064. errorexit:
  2065. if inlined then
  2066. procdefinition.proccalloption:=pocall_inline;
  2067. {$ifdef callparatemp}
  2068. if assigned(callparatemps) then
  2069. callparatemps.free;
  2070. {$endif callparatemp}
  2071. end;
  2072. {$ifdef state_tracking}
  2073. function Tcallnode.track_state_pass(exec_known:boolean):boolean;
  2074. var hp:Tcallparanode;
  2075. value:Tnode;
  2076. begin
  2077. track_state_pass:=false;
  2078. hp:=Tcallparanode(left);
  2079. while assigned(hp) do
  2080. begin
  2081. if left.track_state_pass(exec_known) then
  2082. begin
  2083. left.resulttype.def:=nil;
  2084. do_resulttypepass(left);
  2085. end;
  2086. value:=aktstate.find_fact(hp.left);
  2087. if value<>nil then
  2088. begin
  2089. track_state_pass:=true;
  2090. hp.left.destroy;
  2091. hp.left:=value.getcopy;
  2092. do_resulttypepass(hp.left);
  2093. end;
  2094. hp:=Tcallparanode(hp.right);
  2095. end;
  2096. end;
  2097. {$endif}
  2098. function tcallnode.docompare(p: tnode): boolean;
  2099. begin
  2100. docompare :=
  2101. inherited docompare(p) and
  2102. (symtableprocentry = tcallnode(p).symtableprocentry) and
  2103. (procdefinition = tcallnode(p).procdefinition) and
  2104. (methodpointer.isequal(tcallnode(p).methodpointer)) and
  2105. ((restypeset and tcallnode(p).restypeset and
  2106. (equal_defs(restype.def,tcallnode(p).restype.def))) or
  2107. (not restypeset and not tcallnode(p).restypeset));
  2108. end;
  2109. {****************************************************************************
  2110. TPROCINLINENODE
  2111. ****************************************************************************}
  2112. constructor tprocinlinenode.create(p:tprocdef);
  2113. begin
  2114. inherited create(procinlinen);
  2115. inlineprocdef:=p;
  2116. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2117. para_offset:=0;
  2118. para_size:=0;
  2119. { copy inlinetree }
  2120. if assigned(p.code) then
  2121. inlinetree:=p.code.getcopy
  2122. else
  2123. inlinetree:=nil;
  2124. end;
  2125. destructor tprocinlinenode.destroy;
  2126. begin
  2127. if assigned(inlinetree) then
  2128. inlinetree.free;
  2129. inherited destroy;
  2130. end;
  2131. constructor tprocinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  2132. begin
  2133. inherited ppuload(t,ppufile);
  2134. inlineprocdef:=tprocdef(ppufile.getderef);
  2135. inlinetree:=ppuloadnode(ppufile);
  2136. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2137. para_offset:=0;
  2138. para_size:=0;
  2139. end;
  2140. procedure tprocinlinenode.ppuwrite(ppufile:tcompilerppufile);
  2141. begin
  2142. inherited ppuwrite(ppufile);
  2143. ppufile.putderef(inlineprocdef);
  2144. ppuwritenode(ppufile,inlinetree);
  2145. end;
  2146. procedure tprocinlinenode.derefimpl;
  2147. begin
  2148. inherited derefimpl;
  2149. if assigned(inlinetree) then
  2150. inlinetree.derefimpl;
  2151. resolvedef(pointer(inlineprocdef));
  2152. end;
  2153. function tprocinlinenode.getcopy : tnode;
  2154. var
  2155. n : tprocinlinenode;
  2156. begin
  2157. n:=tprocinlinenode(inherited getcopy);
  2158. n.inlineprocdef:=inlineprocdef;
  2159. if assigned(inlinetree) then
  2160. n.inlinetree:=inlinetree.getcopy
  2161. else
  2162. n.inlinetree:=nil;
  2163. n.retoffset:=retoffset;
  2164. n.para_offset:=para_offset;
  2165. n.para_size:=para_size;
  2166. getcopy:=n;
  2167. end;
  2168. procedure tprocinlinenode.insertintolist(l : tnodelist);
  2169. begin
  2170. end;
  2171. function tprocinlinenode.det_resulttype : tnode;
  2172. var
  2173. storesymtablelevel : longint;
  2174. storeparasymtable,
  2175. storelocalsymtable : tsymtabletype;
  2176. oldprocdef : tprocdef;
  2177. oldprocinfo : tprocinfo;
  2178. oldinlining_procedure : boolean;
  2179. begin
  2180. result:=nil;
  2181. oldinlining_procedure:=inlining_procedure;
  2182. oldprocdef:=aktprocdef;
  2183. oldprocinfo:=procinfo;
  2184. { we're inlining a procedure }
  2185. inlining_procedure:=true;
  2186. aktprocdef:=inlineprocdef;
  2187. { clone procinfo, but not the asmlists }
  2188. procinfo:=tprocinfo(cprocinfo.newinstance);
  2189. move(pointer(oldprocinfo)^,pointer(procinfo)^,cprocinfo.InstanceSize);
  2190. procinfo.aktentrycode:=nil;
  2191. procinfo.aktexitcode:=nil;
  2192. procinfo.aktproccode:=nil;
  2193. procinfo.aktlocaldata:=nil;
  2194. { set new procinfo }
  2195. procinfo.return_offset:=retoffset;
  2196. procinfo.para_offset:=para_offset;
  2197. procinfo.no_fast_exit:=false;
  2198. { set it to the same lexical level }
  2199. storesymtablelevel:=aktprocdef.localst.symtablelevel;
  2200. storelocalsymtable:=aktprocdef.localst.symtabletype;
  2201. storeparasymtable:=aktprocdef.parast.symtabletype;
  2202. aktprocdef.localst.symtablelevel:=oldprocdef.localst.symtablelevel;
  2203. aktprocdef.localst.symtabletype:=inlinelocalsymtable;
  2204. aktprocdef.parast.symtabletype:=inlineparasymtable;
  2205. { pass inlinetree }
  2206. resulttypepass(inlinetree);
  2207. resulttype:=inlineprocdef.rettype;
  2208. { retrieve info from inlineprocdef }
  2209. retoffset:=-POINTER_SIZE; { less dangerous as zero (PM) }
  2210. para_offset:=0;
  2211. para_size:=inlineprocdef.para_size(target_info.alignment.paraalign);
  2212. if paramanager.ret_in_param(inlineprocdef.rettype.def,inlineprocdef.proccalloption) then
  2213. inc(para_size,POINTER_SIZE);
  2214. { restore procinfo }
  2215. procinfo.free;
  2216. procinfo:=oldprocinfo;
  2217. { restore symtable }
  2218. aktprocdef.localst.symtablelevel:=storesymtablelevel;
  2219. aktprocdef.localst.symtabletype:=storelocalsymtable;
  2220. aktprocdef.parast.symtabletype:=storeparasymtable;
  2221. { restore }
  2222. aktprocdef:=oldprocdef;
  2223. inlining_procedure:=oldinlining_procedure;
  2224. end;
  2225. function tprocinlinenode.pass_1 : tnode;
  2226. begin
  2227. firstpass(inlinetree);
  2228. registers32:=inlinetree.registers32;
  2229. registersfpu:=inlinetree.registersfpu;
  2230. {$ifdef SUPPORT_MMX}
  2231. registersmmx:=inlinetree.registersmmx;
  2232. {$endif SUPPORT_MMX}
  2233. result:=nil;
  2234. end;
  2235. function tprocinlinenode.docompare(p: tnode): boolean;
  2236. begin
  2237. docompare :=
  2238. inherited docompare(p) and
  2239. inlinetree.isequal(tprocinlinenode(p).inlinetree) and
  2240. (inlineprocdef = tprocinlinenode(p).inlineprocdef);
  2241. end;
  2242. begin
  2243. ccallnode:=tcallnode;
  2244. ccallparanode:=tcallparanode;
  2245. cprocinlinenode:=tprocinlinenode;
  2246. end.
  2247. {
  2248. $Log$
  2249. Revision 1.140 2003-04-23 12:35:34 florian
  2250. * fixed several issues with powerpc
  2251. + applied a patch from Jonas for nested function calls (PowerPC only)
  2252. * ...
  2253. Revision 1.139 2003/04/22 23:50:22 peter
  2254. * firstpass uses expectloc
  2255. * checks if there are differences between the expectloc and
  2256. location.loc from secondpass in EXTDEBUG
  2257. Revision 1.138 2003/04/22 09:53:33 peter
  2258. * fix insert_typeconv to handle new varargs which don't have a
  2259. paraitem set
  2260. Revision 1.137 2003/04/11 16:02:05 peter
  2261. * don't firstpass typen
  2262. Revision 1.136 2003/04/11 15:51:04 peter
  2263. * support subscript,vec for setting methodpointer varstate
  2264. Revision 1.135 2003/04/10 17:57:52 peter
  2265. * vs_hidden released
  2266. Revision 1.134 2003/04/07 11:58:22 jonas
  2267. * more vs_invisible fixes
  2268. Revision 1.133 2003/04/07 10:40:21 jonas
  2269. * fixed VS_HIDDEN for high parameter so it works again
  2270. Revision 1.132 2003/04/04 15:38:56 peter
  2271. * moved generic code from n386cal to ncgcal, i386 now also
  2272. uses the generic ncgcal
  2273. Revision 1.131 2003/03/17 18:54:23 peter
  2274. * fix missing self setting for method to procvar conversion in
  2275. tp_procvar mode
  2276. Revision 1.130 2003/03/17 16:54:41 peter
  2277. * support DefaultHandler and anonymous inheritance fixed
  2278. for message methods
  2279. Revision 1.129 2003/03/17 15:54:22 peter
  2280. * store symoptions also for procdef
  2281. * check symoptions (private,public) when calculating possible
  2282. overload candidates
  2283. Revision 1.128 2003/02/19 22:00:14 daniel
  2284. * Code generator converted to new register notation
  2285. - Horribily outdated todo.txt removed
  2286. Revision 1.127 2003/01/16 22:13:52 peter
  2287. * convert_l3 convertlevel added. This level is used for conversions
  2288. where information can be lost like converting widestring->ansistring
  2289. or dword->byte
  2290. Revision 1.126 2003/01/15 01:44:32 peter
  2291. * merged methodpointer fixes from 1.0.x
  2292. Revision 1.125 2003/01/12 17:52:07 peter
  2293. * only check for auto inherited in objectsymtable
  2294. Revision 1.124 2003/01/09 21:45:46 peter
  2295. * extended information about overloaded candidates when compiled
  2296. with EXTDEBUG
  2297. Revision 1.123 2002/12/26 18:24:33 jonas
  2298. * fixed check for whether or not a high parameter was already generated
  2299. * no type checking/conversions for invisible parameters
  2300. Revision 1.122 2002/12/15 22:50:00 florian
  2301. + some stuff for the new hidden parameter handling added
  2302. Revision 1.121 2002/12/15 21:34:15 peter
  2303. * give sign difference between ordinals a small penalty. This is
  2304. needed to get word->[longword|longint] working
  2305. Revision 1.120 2002/12/15 21:30:12 florian
  2306. * tcallnode.paraitem introduced, all references to defcoll removed
  2307. Revision 1.119 2002/12/15 20:59:58 peter
  2308. * fix crash with default parameters
  2309. Revision 1.118 2002/12/15 11:26:02 peter
  2310. * ignore vs_hidden parameters when choosing overloaded proc
  2311. Revision 1.117 2002/12/11 22:42:28 peter
  2312. * tcallnode.det_resulttype rewrite, merged code from nice_ncal and
  2313. the old code. The new code collects the information about possible
  2314. candidates only once resultting in much less calls to type compare
  2315. routines
  2316. Revision 1.116 2002/12/07 14:27:07 carl
  2317. * 3% memory optimization
  2318. * changed some types
  2319. + added type checking with different size for call node and for
  2320. parameters
  2321. Revision 1.115 2002/12/06 17:51:10 peter
  2322. * merged cdecl and array fixes
  2323. Revision 1.114 2002/12/06 16:56:58 peter
  2324. * only compile cs_fp_emulation support when cpufpuemu is defined
  2325. * define cpufpuemu for m68k only
  2326. Revision 1.113 2002/11/27 20:04:38 peter
  2327. * cdecl array of const fixes
  2328. Revision 1.112 2002/11/27 15:33:46 peter
  2329. * the never ending story of tp procvar hacks
  2330. Revision 1.111 2002/11/27 02:31:17 peter
  2331. * fixed inlinetree parsing in det_resulttype
  2332. Revision 1.110 2002/11/25 18:43:32 carl
  2333. - removed the invalid if <> checking (Delphi is strange on this)
  2334. + implemented abstract warning on instance creation of class with
  2335. abstract methods.
  2336. * some error message cleanups
  2337. Revision 1.109 2002/11/25 17:43:17 peter
  2338. * splitted defbase in defutil,symutil,defcmp
  2339. * merged isconvertable and is_equal into compare_defs(_ext)
  2340. * made operator search faster by walking the list only once
  2341. Revision 1.108 2002/11/18 17:31:54 peter
  2342. * pass proccalloption to ret_in_xxx and push_xxx functions
  2343. Revision 1.107 2002/11/15 01:58:50 peter
  2344. * merged changes from 1.0.7 up to 04-11
  2345. - -V option for generating bug report tracing
  2346. - more tracing for option parsing
  2347. - errors for cdecl and high()
  2348. - win32 import stabs
  2349. - win32 records<=8 are returned in eax:edx (turned off by default)
  2350. - heaptrc update
  2351. - more info for temp management in .s file with EXTDEBUG
  2352. Revision 1.106 2002/10/14 18:20:30 carl
  2353. * var parameter checking for classes and interfaces in Delphi mode
  2354. Revision 1.105 2002/10/06 21:02:17 peter
  2355. * fixed limit checking for qword
  2356. Revision 1.104 2002/10/05 15:15:45 peter
  2357. * Write unknwon compiler proc using Comment and only in Extdebug
  2358. Revision 1.103 2002/10/05 12:43:25 carl
  2359. * fixes for Delphi 6 compilation
  2360. (warning : Some features do not work under Delphi)
  2361. Revision 1.102 2002/10/05 00:48:57 peter
  2362. * support inherited; support for overload as it is handled by
  2363. delphi. This is only for delphi mode as it is working is
  2364. undocumented and hard to predict what is done
  2365. Revision 1.101 2002/09/16 14:11:12 peter
  2366. * add argument to equal_paras() to support default values or not
  2367. Revision 1.100 2002/09/15 17:49:59 peter
  2368. * don't have strict var parameter checking for procedures in the
  2369. system unit
  2370. Revision 1.99 2002/09/09 19:30:34 peter
  2371. * don't allow convertable parameters for var and out parameters in
  2372. delphi and tp mode
  2373. Revision 1.98 2002/09/07 15:25:02 peter
  2374. * old logs removed and tabs fixed
  2375. Revision 1.97 2002/09/07 12:16:05 carl
  2376. * second part bug report 1996 fix, testrange in cordconstnode
  2377. only called if option is set (also make parsing a tiny faster)
  2378. Revision 1.96 2002/09/05 14:53:41 peter
  2379. * fixed old callnode.det_resulttype code
  2380. * old ncal code is default again
  2381. Revision 1.95 2002/09/03 21:32:49 daniel
  2382. * Small bugfix for procdef selection
  2383. Revision 1.94 2002/09/03 19:27:22 daniel
  2384. * Activated new ncal code
  2385. Revision 1.93 2002/09/03 16:26:26 daniel
  2386. * Make Tprocdef.defs protected
  2387. Revision 1.92 2002/09/01 13:28:37 daniel
  2388. - write_access fields removed in favor of a flag
  2389. Revision 1.91 2002/09/01 12:14:15 peter
  2390. * remove debug line
  2391. * containself methods can be called directly
  2392. Revision 1.90 2002/09/01 08:01:16 daniel
  2393. * Removed sets from Tcallnode.det_resulttype
  2394. + Added read/write notifications of variables. These will be usefull
  2395. for providing information for several optimizations. For example
  2396. the value of the loop variable of a for loop does matter is the
  2397. variable is read after the for loop, but if it's no longer used
  2398. or written, it doesn't matter and this can be used to optimize
  2399. the loop code generation.
  2400. Revision 1.89 2002/08/23 16:13:16 peter
  2401. * also firstpass funcretrefnode if available. This was breaking the
  2402. asnode compilerproc code
  2403. Revision 1.88 2002/08/20 10:31:26 daniel
  2404. * Tcallnode.det_resulttype rewritten
  2405. Revision 1.87 2002/08/19 19:36:42 peter
  2406. * More fixes for cross unit inlining, all tnodes are now implemented
  2407. * Moved pocall_internconst to po_internconst because it is not a
  2408. calling type at all and it conflicted when inlining of these small
  2409. functions was requested
  2410. Revision 1.86 2002/08/17 22:09:44 florian
  2411. * result type handling in tcgcal.pass_2 overhauled
  2412. * better tnode.dowrite
  2413. * some ppc stuff fixed
  2414. Revision 1.85 2002/08/17 09:23:34 florian
  2415. * first part of procinfo rewrite
  2416. Revision 1.84 2002/08/16 14:24:57 carl
  2417. * issameref() to test if two references are the same (then emit no opcodes)
  2418. + ret_in_reg to replace ret_in_acc
  2419. (fix some register allocation bugs at the same time)
  2420. + save_std_register now has an extra parameter which is the
  2421. usedinproc registers
  2422. Revision 1.83 2002/07/20 11:57:53 florian
  2423. * types.pas renamed to defbase.pas because D6 contains a types
  2424. unit so this would conflicts if D6 programms are compiled
  2425. + Willamette/SSE2 instructions to assembler added
  2426. Revision 1.82 2002/07/19 11:41:35 daniel
  2427. * State tracker work
  2428. * The whilen and repeatn are now completely unified into whilerepeatn. This
  2429. allows the state tracker to change while nodes automatically into
  2430. repeat nodes.
  2431. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  2432. 'not(a>b)' is optimized into 'a<=b'.
  2433. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  2434. by removing the notn and later switchting the true and falselabels. The
  2435. same is done with 'repeat until not a'.
  2436. Revision 1.81 2002/07/15 18:03:14 florian
  2437. * readded removed changes
  2438. Revision 1.79 2002/07/11 14:41:27 florian
  2439. * start of the new generic parameter handling
  2440. Revision 1.80 2002/07/14 18:00:43 daniel
  2441. + Added the beginning of a state tracker. This will track the values of
  2442. variables through procedures and optimize things away.
  2443. Revision 1.78 2002/07/04 20:43:00 florian
  2444. * first x86-64 patches
  2445. }