htypechk.pas 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit exports some help routines for the type checking
  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 htypechk;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. tokens,cpuinfo,
  23. node,
  24. symconst,symtype,symdef,symsym,symbase;
  25. type
  26. Ttok2nodeRec=record
  27. tok : ttoken;
  28. nod : tnodetype;
  29. op_overloading_supported : boolean;
  30. end;
  31. pcandidate = ^tcandidate;
  32. tcandidate = record
  33. next : pcandidate;
  34. data : tprocdef;
  35. wrongpara,
  36. firstpara : tparaitem;
  37. exact_count,
  38. equal_count,
  39. cl1_count,
  40. cl2_count,
  41. cl3_count,
  42. coper_count : integer; { should be signed }
  43. ordinal_distance : bestreal;
  44. invalid : boolean;
  45. wrongparanr : byte;
  46. end;
  47. tcallcandidates = class
  48. private
  49. FProcSym : tprocsym;
  50. FProcs : pcandidate;
  51. FProcVisibleCnt,
  52. FProcCnt : integer;
  53. FParaNode : tnode;
  54. FParaLength : smallint;
  55. FAllowVariant : boolean;
  56. function proc_add(pd:tprocdef):pcandidate;
  57. public
  58. constructor create(sym:tprocsym;st:tsymtable;ppn:tnode;isprop:boolean);
  59. constructor create_operator(op:ttoken;ppn:tnode);
  60. destructor destroy;override;
  61. procedure list(all:boolean);
  62. {$ifdef EXTDEBUG}
  63. procedure dump_info(lvl:longint);
  64. {$endif EXTDEBUG}
  65. procedure get_information;
  66. function choose_best(var bestpd:tabstractprocdef):integer;
  67. procedure find_wrong_para;
  68. property Count:integer read FProcCnt;
  69. property VisibleCount:integer read FProcVisibleCnt;
  70. end;
  71. const
  72. tok2nodes=25;
  73. tok2node:array[1..tok2nodes] of ttok2noderec=(
  74. (tok:_PLUS ;nod:addn;op_overloading_supported:true), { binary overloading supported }
  75. (tok:_MINUS ;nod:subn;op_overloading_supported:true), { binary and unary overloading supported }
  76. (tok:_STAR ;nod:muln;op_overloading_supported:true), { binary overloading supported }
  77. (tok:_SLASH ;nod:slashn;op_overloading_supported:true), { binary overloading supported }
  78. (tok:_EQUAL ;nod:equaln;op_overloading_supported:true), { binary overloading supported }
  79. (tok:_GT ;nod:gtn;op_overloading_supported:true), { binary overloading supported }
  80. (tok:_LT ;nod:ltn;op_overloading_supported:true), { binary overloading supported }
  81. (tok:_GTE ;nod:gten;op_overloading_supported:true), { binary overloading supported }
  82. (tok:_LTE ;nod:lten;op_overloading_supported:true), { binary overloading supported }
  83. (tok:_SYMDIF ;nod:symdifn;op_overloading_supported:true), { binary overloading supported }
  84. (tok:_STARSTAR;nod:starstarn;op_overloading_supported:true), { binary overloading supported }
  85. (tok:_OP_AS ;nod:asn;op_overloading_supported:false), { binary overloading NOT supported }
  86. (tok:_OP_IN ;nod:inn;op_overloading_supported:false), { binary overloading NOT supported }
  87. (tok:_OP_IS ;nod:isn;op_overloading_supported:false), { binary overloading NOT supported }
  88. (tok:_OP_OR ;nod:orn;op_overloading_supported:true), { binary overloading supported }
  89. (tok:_OP_AND ;nod:andn;op_overloading_supported:true), { binary overloading supported }
  90. (tok:_OP_DIV ;nod:divn;op_overloading_supported:true), { binary overloading supported }
  91. (tok:_OP_NOT ;nod:notn;op_overloading_supported:true), { unary overloading supported }
  92. (tok:_OP_MOD ;nod:modn;op_overloading_supported:true), { binary overloading supported }
  93. (tok:_OP_SHL ;nod:shln;op_overloading_supported:true), { binary overloading supported }
  94. (tok:_OP_SHR ;nod:shrn;op_overloading_supported:true), { binary overloading supported }
  95. (tok:_OP_XOR ;nod:xorn;op_overloading_supported:true), { binary overloading supported }
  96. (tok:_ASSIGNMENT;nod:assignn;op_overloading_supported:true), { unary overloading supported }
  97. (tok:_CARET ;nod:caretn;op_overloading_supported:false), { binary overloading NOT supported }
  98. (tok:_UNEQUAL ;nod:unequaln;op_overloading_supported:false) { binary overloading NOT supported overload = instead }
  99. );
  100. const
  101. { firstcallparan without varspez we don't count the ref }
  102. {$ifdef extdebug}
  103. count_ref : boolean = true;
  104. {$endif def extdebug}
  105. allow_array_constructor : boolean = false;
  106. function node2opstr(nt:tnodetype):string;
  107. { check operator args and result type }
  108. function isbinaryoperatoroverloadable(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype) : boolean;
  109. function isoperatoracceptable(pf : tprocdef; optoken : ttoken) : boolean;
  110. function isunaryoverloaded(var t : tnode) : boolean;
  111. function isbinaryoverloaded(var t : tnode) : boolean;
  112. { Register Allocation }
  113. procedure make_not_regable(p : tnode);
  114. procedure calcregisters(p : tbinarynode;r32,fpu,mmx : word);
  115. { subroutine handling }
  116. function is_procsym_load(p:tnode):boolean;
  117. procedure test_local_to_procvar(from_def:tprocvardef;to_def:tdef);
  118. { sets varsym varstate field correctly }
  119. procedure set_varstate(p:tnode;newstate:tvarstate;must_be_valid:boolean);
  120. { sets the callunique flag, if the node is a vecn, }
  121. { takes care of type casts etc. }
  122. procedure set_unique(p : tnode);
  123. function valid_for_formal_var(p : tnode) : boolean;
  124. function valid_for_formal_const(p : tnode) : boolean;
  125. function valid_for_var(p:tnode):boolean;
  126. function valid_for_assignment(p:tnode):boolean;
  127. implementation
  128. uses
  129. globtype,systems,
  130. cutils,verbose,globals,
  131. symtable,
  132. defutil,defcmp,
  133. pass_1,nbas,ncnv,nld,nmem,ncal,nmat,nutils,
  134. cgbase,procinfo
  135. ;
  136. type
  137. TValidAssign=(Valid_Property,Valid_Void);
  138. TValidAssigns=set of TValidAssign;
  139. function node2opstr(nt:tnodetype):string;
  140. var
  141. i : integer;
  142. begin
  143. result:='<unknown>';
  144. for i:=1 to tok2nodes do
  145. if tok2node[i].nod=nt then
  146. begin
  147. result:=tokeninfo^[tok2node[i].tok].str;
  148. break;
  149. end;
  150. end;
  151. function isbinaryoperatoroverloadable(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype) : boolean;
  152. function internal_check(treetyp:tnodetype;ld:tdef;lt:tnodetype;rd:tdef;rt:tnodetype;var allowed:boolean):boolean;
  153. begin
  154. internal_check:=true;
  155. case ld.deftype of
  156. formaldef,
  157. recorddef,
  158. variantdef :
  159. begin
  160. allowed:=true;
  161. end;
  162. procvardef :
  163. begin
  164. if (rd.deftype in [pointerdef,procdef,procvardef]) then
  165. begin
  166. allowed:=false;
  167. exit;
  168. end;
  169. allowed:=true;
  170. end;
  171. pointerdef :
  172. begin
  173. if ((rd.deftype in [orddef,enumdef,pointerdef,classrefdef,procvardef]) or
  174. is_class_or_interface(rd)) then
  175. begin
  176. allowed:=false;
  177. exit;
  178. end;
  179. { don't allow pchar+string }
  180. if (is_pchar(ld) or is_pwidechar(ld)) and
  181. ((rd.deftype=stringdef) or
  182. is_pchar(rd) or
  183. is_pwidechar(rd) or
  184. is_chararray(rd) or
  185. is_widechararray(rd)) then
  186. begin
  187. allowed:=false;
  188. exit;
  189. end;
  190. allowed:=true;
  191. end;
  192. arraydef :
  193. begin
  194. { not mmx }
  195. if (cs_mmx in aktlocalswitches) and
  196. is_mmx_able_array(ld) then
  197. begin
  198. allowed:=false;
  199. exit;
  200. end;
  201. { not chararray+[(wide)char,(wide)string,(wide)chararray] }
  202. if (is_chararray(ld) or is_widechararray(ld)) and
  203. ((rd.deftype in [stringdef,orddef,enumdef]) or
  204. is_pchar(rd) or
  205. is_pwidechar(rd) or
  206. is_chararray(rd) or
  207. is_widechararray(rd) or
  208. (rt=niln)) then
  209. begin
  210. allowed:=false;
  211. exit;
  212. end;
  213. { dynamic array compare with niln }
  214. if ((is_dynamic_array(ld) and
  215. (rt=niln)) or
  216. (is_dynamic_array(ld) and is_dynamic_array(rd)))
  217. and
  218. (treetyp in [equaln,unequaln]) then
  219. begin
  220. allowed:=false;
  221. exit;
  222. end;
  223. allowed:=true;
  224. end;
  225. objectdef :
  226. begin
  227. { <> and = are defined for classes }
  228. if (treetyp in [equaln,unequaln]) and
  229. is_class_or_interface(ld) then
  230. begin
  231. allowed:=false;
  232. exit;
  233. end;
  234. allowed:=true;
  235. end;
  236. stringdef :
  237. begin
  238. if ((rd.deftype in [orddef,enumdef,stringdef]) or
  239. is_pchar(rd) or
  240. is_pwidechar(rd) or
  241. is_chararray(rd) or
  242. is_widechararray(rd)) then
  243. begin
  244. allowed:=false;
  245. exit;
  246. end;
  247. allowed:=true;
  248. end;
  249. else
  250. internal_check:=false;
  251. end;
  252. end;
  253. var
  254. allowed : boolean;
  255. begin
  256. { power ** is always possible }
  257. if (treetyp=starstarn) then
  258. begin
  259. isbinaryoperatoroverloadable:=true;
  260. exit;
  261. end;
  262. { order of arguments does not matter so we have to check also
  263. the reversed order }
  264. allowed:=false;
  265. if not internal_check(treetyp,ld,lt,rd,rt,allowed) then
  266. internal_check(treetyp,rd,rt,ld,lt,allowed);
  267. isbinaryoperatoroverloadable:=allowed;
  268. end;
  269. function isunaryoperatoroverloadable(treetyp : tnodetype;ld : tdef) : boolean;
  270. begin
  271. result:=false;
  272. case treetyp of
  273. subn,
  274. unaryminusn :
  275. begin
  276. if is_integer(ld) or
  277. (ld.deftype=floatdef) then
  278. exit;
  279. {$ifdef SUPPORT_MMX}
  280. if (cs_mmx in aktlocalswitches) and
  281. is_mmx_able_array(ld) then
  282. exit;
  283. {$endif SUPPORT_MMX}
  284. result:=true;
  285. end;
  286. notn :
  287. begin
  288. if is_integer(ld) or
  289. is_boolean(ld) then
  290. exit;
  291. {$ifdef SUPPORT_MMX}
  292. if (cs_mmx in aktlocalswitches) and
  293. is_mmx_able_array(ld) then
  294. exit;
  295. {$endif SUPPORT_MMX}
  296. result:=true;
  297. end;
  298. end;
  299. end;
  300. function isoperatoracceptable(pf : tprocdef; optoken : ttoken) : boolean;
  301. var
  302. ld,rd : tdef;
  303. i : longint;
  304. eq : tequaltype;
  305. conv : tconverttype;
  306. pd : tprocdef;
  307. begin
  308. result:=false;
  309. case pf.parast.symindex.count of
  310. 1 : begin
  311. ld:=tvarsym(pf.parast.symindex.first).vartype.def;
  312. { assignment is a special case }
  313. if optoken=_ASSIGNMENT then
  314. begin
  315. eq:=compare_defs_ext(ld,pf.rettype.def,nothingn,conv,pd,[cdo_explicit]);
  316. result:=(eq=te_incompatible);
  317. end
  318. else
  319. begin
  320. for i:=1 to tok2nodes do
  321. if tok2node[i].tok=optoken then
  322. begin
  323. result:=
  324. tok2node[i].op_overloading_supported and
  325. isunaryoperatoroverloadable(tok2node[i].nod,ld);
  326. break;
  327. end;
  328. end;
  329. end;
  330. 2 : begin
  331. for i:=1 to tok2nodes do
  332. if tok2node[i].tok=optoken then
  333. begin
  334. ld:=tvarsym(pf.parast.symindex.first).vartype.def;
  335. rd:=tvarsym(pf.parast.symindex.first.indexnext).vartype.def;
  336. result:=
  337. tok2node[i].op_overloading_supported and
  338. isbinaryoperatoroverloadable(tok2node[i].nod,ld,nothingn,rd,nothingn);
  339. break;
  340. end;
  341. end;
  342. end;
  343. end;
  344. function isunaryoverloaded(var t : tnode) : boolean;
  345. var
  346. ld : tdef;
  347. optoken : ttoken;
  348. operpd : tprocdef;
  349. ppn : tcallparanode;
  350. candidates : tcallcandidates;
  351. cand_cnt : integer;
  352. begin
  353. result:=false;
  354. operpd:=nil;
  355. { load easier access variables }
  356. ld:=tunarynode(t).left.resulttype.def;
  357. if not isunaryoperatoroverloadable(t.nodetype,ld) then
  358. exit;
  359. { operator overload is possible }
  360. result:=true;
  361. case t.nodetype of
  362. notn:
  363. optoken:=_OP_NOT;
  364. unaryminusn:
  365. optoken:=_MINUS;
  366. else
  367. begin
  368. CGMessage(parser_e_operator_not_overloaded);
  369. t:=cnothingnode.create;
  370. exit;
  371. end;
  372. end;
  373. { generate parameter nodes }
  374. ppn:=ccallparanode.create(tunarynode(t).left.getcopy,nil);
  375. ppn.get_paratype;
  376. candidates:=tcallcandidates.create_operator(optoken,ppn);
  377. { stop when there are no operators found }
  378. if candidates.count=0 then
  379. begin
  380. CGMessage(parser_e_operator_not_overloaded);
  381. candidates.free;
  382. ppn.free;
  383. t:=cnothingnode.create;
  384. exit;
  385. end;
  386. { Retrieve information about the candidates }
  387. candidates.get_information;
  388. {$ifdef EXTDEBUG}
  389. { Display info when multiple candidates are found }
  390. candidates.dump_info(V_Debug);
  391. {$endif EXTDEBUG}
  392. cand_cnt:=candidates.choose_best(operpd);
  393. { exit when no overloads are found }
  394. if cand_cnt=0 then
  395. begin
  396. CGMessage(parser_e_operator_not_overloaded);
  397. candidates.free;
  398. ppn.free;
  399. t:=cnothingnode.create;
  400. exit;
  401. end;
  402. { Multiple candidates left? }
  403. if cand_cnt>1 then
  404. begin
  405. CGMessage(cg_e_cant_choose_overload_function);
  406. {$ifdef EXTDEBUG}
  407. candidates.dump_info(V_Hint);
  408. {$else EXTDEBUG}
  409. candidates.list(false);
  410. {$endif EXTDEBUG}
  411. { we'll just use the first candidate to make the
  412. call }
  413. end;
  414. candidates.free;
  415. inc(operpd.procsym.refs);
  416. { the nil as symtable signs firstcalln that this is
  417. an overloaded operator }
  418. t:=ccallnode.create(ppn,Tprocsym(operpd.procsym),nil,nil,[]);
  419. { we already know the procdef to use, so it can
  420. skip the overload choosing in callnode.det_resulttype }
  421. tcallnode(t).procdefinition:=operpd;
  422. end;
  423. function isbinaryoverloaded(var t : tnode) : boolean;
  424. var
  425. rd,ld : tdef;
  426. optoken : ttoken;
  427. operpd : tprocdef;
  428. ht : tnode;
  429. ppn : tcallparanode;
  430. candidates : tcallcandidates;
  431. cand_cnt : integer;
  432. begin
  433. isbinaryoverloaded:=false;
  434. operpd:=nil;
  435. { load easier access variables }
  436. ld:=tbinarynode(t).left.resulttype.def;
  437. rd:=tbinarynode(t).right.resulttype.def;
  438. if not isbinaryoperatoroverloadable(t.nodetype,ld,tbinarynode(t).left.nodetype,rd,tbinarynode(t).right.nodetype) then
  439. exit;
  440. { operator overload is possible }
  441. result:=true;
  442. case t.nodetype of
  443. equaln,
  444. unequaln :
  445. optoken:=_EQUAL;
  446. addn:
  447. optoken:=_PLUS;
  448. subn:
  449. optoken:=_MINUS;
  450. muln:
  451. optoken:=_STAR;
  452. starstarn:
  453. optoken:=_STARSTAR;
  454. slashn:
  455. optoken:=_SLASH;
  456. ltn:
  457. optoken:=_LT;
  458. gtn:
  459. optoken:=_GT;
  460. lten:
  461. optoken:=_LTE;
  462. gten:
  463. optoken:=_GTE;
  464. symdifn :
  465. optoken:=_SYMDIF;
  466. modn :
  467. optoken:=_OP_MOD;
  468. orn :
  469. optoken:=_OP_OR;
  470. xorn :
  471. optoken:=_OP_XOR;
  472. andn :
  473. optoken:=_OP_AND;
  474. divn :
  475. optoken:=_OP_DIV;
  476. shln :
  477. optoken:=_OP_SHL;
  478. shrn :
  479. optoken:=_OP_SHR;
  480. else
  481. begin
  482. CGMessage(parser_e_operator_not_overloaded);
  483. t:=cnothingnode.create;
  484. exit;
  485. end;
  486. end;
  487. { generate parameter nodes }
  488. ppn:=ccallparanode.create(tbinarynode(t).right.getcopy,ccallparanode.create(tbinarynode(t).left.getcopy,nil));
  489. ppn.get_paratype;
  490. candidates:=tcallcandidates.create_operator(optoken,ppn);
  491. { for commutative operators we can swap arguments and try again }
  492. if (candidates.count=0) and
  493. not(optoken in [_OP_SHL,_OP_SHR,_OP_DIV,_OP_MOD,_STARSTAR,_SLASH,_MINUS]) then
  494. begin
  495. candidates.free;
  496. reverseparameters(ppn);
  497. { reverse compare operators }
  498. case optoken of
  499. _LT:
  500. optoken:=_GTE;
  501. _GT:
  502. optoken:=_LTE;
  503. _LTE:
  504. optoken:=_GT;
  505. _GTE:
  506. optoken:=_LT;
  507. end;
  508. candidates:=tcallcandidates.create_operator(optoken,ppn);
  509. end;
  510. { stop when there are no operators found }
  511. if candidates.count=0 then
  512. begin
  513. CGMessage(parser_e_operator_not_overloaded);
  514. candidates.free;
  515. ppn.free;
  516. t:=cnothingnode.create;
  517. exit;
  518. end;
  519. { Retrieve information about the candidates }
  520. candidates.get_information;
  521. {$ifdef EXTDEBUG}
  522. { Display info when multiple candidates are found }
  523. candidates.dump_info(V_Debug);
  524. {$endif EXTDEBUG}
  525. cand_cnt:=candidates.choose_best(operpd);
  526. { exit when no overloads are found }
  527. if cand_cnt=0 then
  528. begin
  529. CGMessage(parser_e_operator_not_overloaded);
  530. candidates.free;
  531. ppn.free;
  532. t:=cnothingnode.create;
  533. exit;
  534. end;
  535. { Multiple candidates left? }
  536. if cand_cnt>1 then
  537. begin
  538. CGMessage(cg_e_cant_choose_overload_function);
  539. {$ifdef EXTDEBUG}
  540. candidates.dump_info(V_Hint);
  541. {$else EXTDEBUG}
  542. candidates.list(false);
  543. {$endif EXTDEBUG}
  544. { we'll just use the first candidate to make the
  545. call }
  546. end;
  547. candidates.free;
  548. inc(operpd.procsym.refs);
  549. { the nil as symtable signs firstcalln that this is
  550. an overloaded operator }
  551. ht:=ccallnode.create(ppn,Tprocsym(operpd.procsym),nil,nil,[]);
  552. { we already know the procdef to use, so it can
  553. skip the overload choosing in callnode.det_resulttype }
  554. tcallnode(ht).procdefinition:=operpd;
  555. if t.nodetype=unequaln then
  556. ht:=cnotnode.create(ht);
  557. t:=ht;
  558. end;
  559. {****************************************************************************
  560. Register Calculation
  561. ****************************************************************************}
  562. { marks an lvalue as "unregable" }
  563. procedure make_not_regable(p : tnode);
  564. begin
  565. case p.nodetype of
  566. typeconvn :
  567. make_not_regable(ttypeconvnode(p).left);
  568. loadn :
  569. if tloadnode(p).symtableentry.typ=varsym then
  570. tvarsym(tloadnode(p).symtableentry).varoptions:=tvarsym(tloadnode(p).symtableentry).varoptions-[vo_regable,vo_fpuregable];
  571. end;
  572. end;
  573. { calculates the needed registers for a binary operator }
  574. procedure calcregisters(p : tbinarynode;r32,fpu,mmx : word);
  575. begin
  576. p.left_right_max;
  577. { Only when the difference between the left and right registers < the
  578. wanted registers allocate the amount of registers }
  579. if assigned(p.left) then
  580. begin
  581. if assigned(p.right) then
  582. begin
  583. { the location must be already filled in because we need it to }
  584. { calculate the necessary number of registers (JM) }
  585. if p.expectloc = LOC_INVALID then
  586. internalerror(200110101);
  587. if (abs(p.left.registersint-p.right.registersint)<r32) or
  588. ((p.expectloc = LOC_FPUREGISTER) and
  589. (p.right.registersfpu <= p.left.registersfpu) and
  590. ((p.right.registersfpu <> 0) or (p.left.registersfpu <> 0)) and
  591. (p.left.registersint < p.right.registersint)) then
  592. inc(p.registersint,r32);
  593. if (abs(p.left.registersfpu-p.right.registersfpu)<fpu) then
  594. inc(p.registersfpu,fpu);
  595. {$ifdef SUPPORT_MMX}
  596. if (abs(p.left.registersmmx-p.right.registersmmx)<mmx) then
  597. inc(p.registersmmx,mmx);
  598. {$endif SUPPORT_MMX}
  599. { the following is a little bit guessing but I think }
  600. { it's the only way to solve same internalerrors: }
  601. { if the left and right node both uses registers }
  602. { and return a mem location, but the current node }
  603. { doesn't use an integer register we get probably }
  604. { trouble when restoring a node }
  605. if (p.left.registersint=p.right.registersint) and
  606. (p.registersint=p.left.registersint) and
  607. (p.registersint>0) and
  608. (p.left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  609. (p.right.expectloc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  610. inc(p.registersint);
  611. end
  612. else
  613. begin
  614. if (p.left.registersint<r32) then
  615. inc(p.registersint,r32);
  616. if (p.left.registersfpu<fpu) then
  617. inc(p.registersfpu,fpu);
  618. {$ifdef SUPPORT_MMX}
  619. if (p.left.registersmmx<mmx) then
  620. inc(p.registersmmx,mmx);
  621. {$endif SUPPORT_MMX}
  622. end;
  623. end;
  624. { error CGMessage, if more than 8 floating point }
  625. { registers are needed }
  626. { if p.registersfpu>maxfpuregs then
  627. CGMessage(cg_e_too_complex_expr); now pushed if needed PM }
  628. end;
  629. {****************************************************************************
  630. Subroutine Handling
  631. ****************************************************************************}
  632. function is_procsym_load(p:tnode):boolean;
  633. begin
  634. { ignore vecn,subscriptn }
  635. repeat
  636. case p.nodetype of
  637. vecn :
  638. p:=tvecnode(p).left;
  639. subscriptn :
  640. p:=tsubscriptnode(p).left;
  641. else
  642. break;
  643. end;
  644. until false;
  645. is_procsym_load:=((p.nodetype=loadn) and (tloadnode(p).symtableentry.typ=procsym)) or
  646. ((p.nodetype=addrn) and (taddrnode(p).left.nodetype=loadn)
  647. and (tloadnode(taddrnode(p).left).symtableentry.typ=procsym)) ;
  648. end;
  649. { local routines can't be assigned to procvars }
  650. procedure test_local_to_procvar(from_def:tprocvardef;to_def:tdef);
  651. begin
  652. if (from_def.parast.symtablelevel>normal_function_level) and
  653. (to_def.deftype=procvardef) then
  654. CGMessage(type_e_cannot_local_proc_to_procvar);
  655. end;
  656. procedure set_varstate(p:tnode;newstate:tvarstate;must_be_valid:boolean);
  657. var
  658. hsym : tvarsym;
  659. begin
  660. while assigned(p) do
  661. begin
  662. case p.nodetype of
  663. typeconvn :
  664. begin
  665. case ttypeconvnode(p).convtype of
  666. tc_cchar_2_pchar,
  667. tc_cstring_2_pchar,
  668. tc_array_2_pointer :
  669. must_be_valid:=false;
  670. tc_pchar_2_string,
  671. tc_pointer_2_array :
  672. must_be_valid:=true;
  673. end;
  674. p:=tunarynode(p).left;
  675. end;
  676. subscriptn :
  677. p:=tunarynode(p).left;
  678. vecn:
  679. begin
  680. set_varstate(tbinarynode(p).right,vs_used,true);
  681. if not(tunarynode(p).left.resulttype.def.deftype in [stringdef,arraydef]) then
  682. must_be_valid:=true;
  683. p:=tunarynode(p).left;
  684. end;
  685. { do not parse calln }
  686. calln :
  687. break;
  688. loadn :
  689. begin
  690. if (tloadnode(p).symtableentry.typ=varsym) then
  691. begin
  692. hsym:=tvarsym(tloadnode(p).symtableentry);
  693. if must_be_valid and (hsym.varstate=vs_declared) then
  694. begin
  695. { Give warning/note for uninitialized locals }
  696. if assigned(hsym.owner) and
  697. not(vo_is_external in hsym.varoptions) and
  698. (hsym.owner.symtabletype in [localsymtable,staticsymtable]) and
  699. (hsym.owner=current_procinfo.procdef.localst) then
  700. begin
  701. if (vo_is_funcret in hsym.varoptions) then
  702. CGMessage(sym_w_function_result_not_set)
  703. else
  704. if tloadnode(p).symtable.symtabletype=localsymtable then
  705. CGMessage1(sym_n_uninitialized_local_variable,hsym.realname)
  706. else
  707. CGMessage1(sym_n_uninitialized_variable,hsym.realname);
  708. end;
  709. end;
  710. { don't override vs_used with vs_assigned }
  711. if hsym.varstate<>vs_used then
  712. hsym.varstate:=newstate;
  713. end;
  714. break;
  715. end;
  716. callparan :
  717. internalerror(200310081);
  718. else
  719. break;
  720. end;{case }
  721. end;
  722. end;
  723. procedure set_unique(p : tnode);
  724. begin
  725. while assigned(p) do
  726. begin
  727. case p.nodetype of
  728. vecn:
  729. begin
  730. include(p.flags,nf_callunique);
  731. break;
  732. end;
  733. typeconvn,
  734. subscriptn,
  735. derefn:
  736. p:=tunarynode(p).left;
  737. else
  738. break;
  739. end;
  740. end;
  741. end;
  742. function valid_for_assign(p:tnode;opts:TValidAssigns):boolean;
  743. var
  744. hp : tnode;
  745. gotwith,
  746. gotsubscript,
  747. gotpointer,
  748. gotvec,
  749. gotclass,
  750. gotderef : boolean;
  751. fromdef,
  752. todef : tdef;
  753. begin
  754. valid_for_assign:=false;
  755. gotsubscript:=false;
  756. gotvec:=false;
  757. gotderef:=false;
  758. gotclass:=false;
  759. gotpointer:=false;
  760. gotwith:=false;
  761. hp:=p;
  762. if not(valid_void in opts) and
  763. is_void(hp.resulttype.def) then
  764. begin
  765. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  766. exit;
  767. end;
  768. while assigned(hp) do
  769. begin
  770. { property allowed? calln has a property check itself }
  771. if (nf_isproperty in hp.flags) then
  772. begin
  773. if (valid_property in opts) then
  774. valid_for_assign:=true
  775. else
  776. begin
  777. { check return type }
  778. case hp.resulttype.def.deftype of
  779. pointerdef :
  780. gotpointer:=true;
  781. objectdef :
  782. gotclass:=is_class_or_interface(hp.resulttype.def);
  783. recorddef, { handle record like class it needs a subscription }
  784. classrefdef :
  785. gotclass:=true;
  786. end;
  787. { 1. if it returns a pointer and we've found a deref,
  788. 2. if it returns a class or record and a subscription or with is found }
  789. if (gotpointer and gotderef) or
  790. (gotclass and (gotsubscript or gotwith)) then
  791. valid_for_assign:=true
  792. else
  793. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  794. end;
  795. exit;
  796. end;
  797. case hp.nodetype of
  798. temprefn :
  799. begin
  800. valid_for_assign := true;
  801. exit;
  802. end;
  803. derefn :
  804. begin
  805. gotderef:=true;
  806. hp:=tderefnode(hp).left;
  807. end;
  808. typeconvn :
  809. begin
  810. { typecast sizes must match, exceptions:
  811. - implicit typecast made by absolute
  812. - from formaldef
  813. - from void
  814. - from/to open array
  815. - typecast from pointer to array }
  816. fromdef:=ttypeconvnode(hp).left.resulttype.def;
  817. todef:=hp.resulttype.def;
  818. if not((nf_absolute in ttypeconvnode(hp).flags) or
  819. (fromdef.deftype=formaldef) or
  820. is_void(fromdef) or
  821. is_open_array(fromdef) or
  822. is_open_array(todef) or
  823. ((fromdef.deftype=pointerdef) and (todef.deftype=arraydef)) or
  824. ((fromdef.deftype = objectdef) and (todef.deftype = objectdef) and
  825. (tobjectdef(fromdef).is_related(tobjectdef(todef))))) and
  826. (fromdef.size<>todef.size) then
  827. begin
  828. { in TP it is allowed to typecast to smaller types }
  829. if not(m_tp7 in aktmodeswitches) or
  830. (todef.size>fromdef.size) then
  831. CGMessagePos2(hp.fileinfo,type_e_typecast_wrong_size_for_assignment,tostr(fromdef.size),tostr(todef.size));
  832. end;
  833. { don't allow assignments to typeconvs that need special code }
  834. if not(gotsubscript or gotvec or gotderef) and
  835. not(ttypeconvnode(hp).assign_allowed) then
  836. begin
  837. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  838. exit;
  839. end;
  840. case hp.resulttype.def.deftype of
  841. pointerdef :
  842. gotpointer:=true;
  843. objectdef :
  844. gotclass:=is_class_or_interface(hp.resulttype.def);
  845. classrefdef :
  846. gotclass:=true;
  847. arraydef :
  848. begin
  849. { pointer -> array conversion is done then we need to see it
  850. as a deref, because a ^ is then not required anymore }
  851. if (ttypeconvnode(hp).left.resulttype.def.deftype=pointerdef) then
  852. gotderef:=true;
  853. end;
  854. end;
  855. hp:=ttypeconvnode(hp).left;
  856. end;
  857. vecn :
  858. begin
  859. gotvec:=true;
  860. hp:=tunarynode(hp).left;
  861. end;
  862. asn :
  863. begin
  864. { asn can't be assigned directly, it returns the value in a register instead
  865. of reference. }
  866. if not(gotsubscript or gotderef or gotvec) then
  867. begin
  868. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  869. exit;
  870. end;
  871. hp:=tunarynode(hp).left;
  872. end;
  873. subscriptn :
  874. begin
  875. gotsubscript:=true;
  876. { a class/interface access is an implicit }
  877. { dereferencing }
  878. hp:=tsubscriptnode(hp).left;
  879. if is_class_or_interface(hp.resulttype.def) then
  880. gotderef:=true;
  881. end;
  882. subn,
  883. addn :
  884. begin
  885. { Allow add/sub operators on a pointer, or an integer
  886. and a pointer typecast and deref has been found }
  887. if ((hp.resulttype.def.deftype=pointerdef) or
  888. (is_integer(hp.resulttype.def) and gotpointer)) and
  889. gotderef then
  890. valid_for_assign:=true
  891. else
  892. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  893. exit;
  894. end;
  895. addrn :
  896. begin
  897. if gotderef or
  898. (nf_procvarload in hp.flags) then
  899. valid_for_assign:=true
  900. else
  901. CGMessagePos(hp.fileinfo,type_e_no_assign_to_addr);
  902. exit;
  903. end;
  904. calln :
  905. begin
  906. { check return type }
  907. case hp.resulttype.def.deftype of
  908. arraydef :
  909. begin
  910. { dynamic arrays are allowed when there is also a
  911. vec node }
  912. if is_dynamic_array(hp.resulttype.def) and
  913. gotvec then
  914. begin
  915. gotderef:=true;
  916. gotpointer:=true;
  917. end;
  918. end;
  919. pointerdef :
  920. gotpointer:=true;
  921. objectdef :
  922. gotclass:=is_class_or_interface(hp.resulttype.def);
  923. recorddef, { handle record like class it needs a subscription }
  924. classrefdef :
  925. gotclass:=true;
  926. end;
  927. { 1. if it returns a pointer and we've found a deref,
  928. 2. if it returns a class or record and a subscription or with is found }
  929. if (gotpointer and gotderef) or
  930. (gotclass and (gotsubscript or gotwith)) then
  931. valid_for_assign:=true
  932. else
  933. CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
  934. exit;
  935. end;
  936. loadn :
  937. begin
  938. case tloadnode(hp).symtableentry.typ of
  939. absolutesym,
  940. varsym :
  941. begin
  942. if (tvarsym(tloadnode(hp).symtableentry).varspez=vs_const) then
  943. begin
  944. { allow p^:= constructions with p is const parameter }
  945. if gotderef then
  946. valid_for_assign:=true
  947. else
  948. CGMessagePos(tloadnode(hp).fileinfo,type_e_no_assign_to_const);
  949. exit;
  950. end;
  951. { Are we at a with symtable, then we need to process the
  952. withrefnode also to check for maybe a const load }
  953. if (tloadnode(hp).symtable.symtabletype=withsymtable) then
  954. begin
  955. { continue with processing the withref node }
  956. hp:=tnode(twithsymtable(tloadnode(hp).symtable).withrefnode);
  957. gotwith:=true;
  958. end
  959. else
  960. begin
  961. valid_for_assign:=true;
  962. exit;
  963. end;
  964. end;
  965. typedconstsym :
  966. begin
  967. if ttypedconstsym(tloadnode(hp).symtableentry).is_writable then
  968. valid_for_assign:=true
  969. else
  970. CGMessagePos(hp.fileinfo,type_e_no_assign_to_const);
  971. exit;
  972. end;
  973. else
  974. begin
  975. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  976. exit;
  977. end;
  978. end;
  979. end;
  980. else
  981. begin
  982. CGMessagePos(hp.fileinfo,type_e_variable_id_expected);
  983. exit;
  984. end;
  985. end;
  986. end;
  987. end;
  988. function valid_for_var(p:tnode):boolean;
  989. begin
  990. valid_for_var:=valid_for_assign(p,[]);
  991. end;
  992. function valid_for_formal_var(p : tnode) : boolean;
  993. begin
  994. valid_for_formal_var:=valid_for_assign(p,[valid_void]);
  995. end;
  996. function valid_for_formal_const(p : tnode) : boolean;
  997. var
  998. v : boolean;
  999. begin
  1000. { p must have been firstpass'd before }
  1001. { accept about anything but not a statement ! }
  1002. case p.nodetype of
  1003. calln,
  1004. statementn,
  1005. addrn :
  1006. begin
  1007. { addrn is not allowed as this generate a constant value,
  1008. but a tp procvar are allowed (PFV) }
  1009. if nf_procvarload in p.flags then
  1010. v:=true
  1011. else
  1012. v:=false;
  1013. end;
  1014. else
  1015. v:=true;
  1016. end;
  1017. valid_for_formal_const:=v;
  1018. end;
  1019. function valid_for_assignment(p:tnode):boolean;
  1020. begin
  1021. valid_for_assignment:=valid_for_assign(p,[valid_property]);
  1022. end;
  1023. procedure var_para_allowed(var eq:tequaltype;def_from,def_to:Tdef);
  1024. begin
  1025. { Note: eq must be already valid, it will only be updated! }
  1026. case def_to.deftype of
  1027. formaldef :
  1028. begin
  1029. { all types can be passed to a formaldef }
  1030. eq:=te_equal;
  1031. end;
  1032. orddef :
  1033. begin
  1034. { allows conversion from word to integer and
  1035. byte to shortint, but only for TP7 compatibility }
  1036. if (m_tp7 in aktmodeswitches) and
  1037. (def_from.deftype=orddef) and
  1038. (def_from.size=def_to.size) then
  1039. eq:=te_convert_l1;
  1040. end;
  1041. arraydef :
  1042. begin
  1043. if is_open_array(def_to) and
  1044. is_dynamic_array(def_from) and
  1045. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  1046. eq:=te_convert_l2;
  1047. end;
  1048. pointerdef :
  1049. begin
  1050. { an implicit pointer conversion is allowed }
  1051. if (def_from.deftype=pointerdef) then
  1052. eq:=te_convert_l1;
  1053. end;
  1054. stringdef :
  1055. begin
  1056. { all shortstrings are allowed, size is not important }
  1057. if is_shortstring(def_from) and
  1058. is_shortstring(def_to) then
  1059. eq:=te_equal;
  1060. end;
  1061. objectdef :
  1062. begin
  1063. { child objects can be also passed }
  1064. { in non-delphi mode, otherwise }
  1065. { they must match exactly, except }
  1066. { if they are objects }
  1067. if (def_from.deftype=objectdef) and
  1068. (
  1069. not(m_delphi in aktmodeswitches) or
  1070. (
  1071. (tobjectdef(def_from).objecttype=odt_object) and
  1072. (tobjectdef(def_to).objecttype=odt_object)
  1073. )
  1074. ) and
  1075. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  1076. eq:=te_convert_l1;
  1077. end;
  1078. filedef :
  1079. begin
  1080. { an implicit file conversion is also allowed }
  1081. { from a typed file to an untyped one }
  1082. if (def_from.deftype=filedef) and
  1083. (tfiledef(def_from).filetyp = ft_typed) and
  1084. (tfiledef(def_to).filetyp = ft_untyped) then
  1085. eq:=te_convert_l1;
  1086. end;
  1087. end;
  1088. end;
  1089. procedure para_allowed(var eq:tequaltype;p:tcallparanode;def_to:tdef);
  1090. begin
  1091. { Note: eq must be already valid, it will only be updated! }
  1092. case def_to.deftype of
  1093. formaldef :
  1094. begin
  1095. { all types can be passed to a formaldef }
  1096. eq:=te_equal;
  1097. end;
  1098. stringdef :
  1099. begin
  1100. { to support ansi/long/wide strings in a proper way }
  1101. { string and string[10] are assumed as equal }
  1102. { when searching the correct overloaded procedure }
  1103. if (p.resulttype.def.deftype=stringdef) and
  1104. (tstringdef(def_to).string_typ=tstringdef(p.resulttype.def).string_typ) then
  1105. eq:=te_equal
  1106. else
  1107. { Passing a constant char to ansistring or shortstring or
  1108. a widechar to widestring then handle it as equal. }
  1109. if (p.left.nodetype=ordconstn) and
  1110. (
  1111. is_char(p.resulttype.def) and
  1112. (is_shortstring(def_to) or is_ansistring(def_to))
  1113. ) or
  1114. (
  1115. is_widechar(p.resulttype.def) and
  1116. is_widestring(def_to)
  1117. ) then
  1118. eq:=te_equal
  1119. end;
  1120. setdef :
  1121. begin
  1122. { set can also be a not yet converted array constructor }
  1123. if (p.resulttype.def.deftype=arraydef) and
  1124. (tarraydef(p.resulttype.def).IsConstructor) and
  1125. not(tarraydef(p.resulttype.def).IsVariant) then
  1126. eq:=te_equal;
  1127. end;
  1128. procvardef :
  1129. begin
  1130. { in tp7 mode proc -> procvar is allowed }
  1131. if (m_tp_procvar in aktmodeswitches) and
  1132. (p.left.nodetype=calln) and
  1133. (proc_to_procvar_equal(tprocdef(tcallnode(p.left).procdefinition),tprocvardef(def_to),true)>=te_equal) then
  1134. eq:=te_equal;
  1135. end;
  1136. end;
  1137. end;
  1138. {****************************************************************************
  1139. TCallCandidates
  1140. ****************************************************************************}
  1141. constructor tcallcandidates.create(sym:tprocsym;st:tsymtable;ppn:tnode;isprop:boolean);
  1142. var
  1143. j : integer;
  1144. pd : tprocdef;
  1145. hp : pcandidate;
  1146. found,
  1147. has_overload_directive : boolean;
  1148. topclassh : tobjectdef;
  1149. srsymtable : tsymtable;
  1150. srprocsym : tprocsym;
  1151. pt : tcallparanode;
  1152. begin
  1153. FProcSym:=sym;
  1154. FProcs:=nil;
  1155. FProccnt:=0;
  1156. FProcvisiblecnt:=0;
  1157. FParanode:=ppn;
  1158. FAllowVariant:=true;
  1159. { determine length of parameter list }
  1160. pt:=tcallparanode(ppn);
  1161. FParalength:=0;
  1162. while assigned(pt) do
  1163. begin
  1164. inc(FParalength);
  1165. pt:=tcallparanode(pt.right);
  1166. end;
  1167. { when the definition has overload directive set, we search for
  1168. overloaded definitions in the class, this only needs to be done once
  1169. for class entries as the tree keeps always the same }
  1170. if (not sym.overloadchecked) and
  1171. (sym.owner.symtabletype=objectsymtable) and
  1172. (po_overload in sym.first_procdef.procoptions) then
  1173. search_class_overloads(sym);
  1174. { when the class passed is defined in this unit we
  1175. need to use the scope of that class. This is a trick
  1176. that can be used to access protected members in other
  1177. units. At least kylix supports it this way (PFV) }
  1178. if assigned(st) and
  1179. (st.symtabletype=objectsymtable) and
  1180. (st.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1181. (st.defowner.owner.unitid=0) then
  1182. topclassh:=tobjectdef(st.defowner)
  1183. else
  1184. begin
  1185. if assigned(current_procinfo) then
  1186. topclassh:=current_procinfo.procdef._class
  1187. else
  1188. topclassh:=nil;
  1189. end;
  1190. { link all procedures which have the same # of parameters }
  1191. for j:=1 to sym.procdef_count do
  1192. begin
  1193. pd:=sym.procdef[j];
  1194. { Is the procdef visible? This needs to be checked on
  1195. procdef level since a symbol can contain both private and
  1196. public declarations. But the check should not be done
  1197. when the callnode is generated by a property }
  1198. if isprop or
  1199. (pd.owner.symtabletype<>objectsymtable) or
  1200. pd.is_visible_for_object(topclassh) then
  1201. begin
  1202. { we have at least one procedure that is visible }
  1203. inc(FProcvisiblecnt);
  1204. { only when the # of parameter are supported by the
  1205. procedure }
  1206. if (FParalength>=pd.minparacount) and
  1207. ((po_varargs in pd.procoptions) or { varargs }
  1208. (FParalength<=pd.maxparacount)) then
  1209. proc_add(pd);
  1210. end;
  1211. end;
  1212. { remember if the procedure is declared with the overload directive,
  1213. it's information is still needed also after all procs are removed }
  1214. has_overload_directive:=(po_overload in sym.first_procdef.procoptions);
  1215. { when the definition has overload directive set, we search for
  1216. overloaded definitions in the symtablestack. The found
  1217. entries are only added to the procs list and not the procsym, because
  1218. the list can change in every situation }
  1219. if has_overload_directive and
  1220. (sym.owner.symtabletype<>objectsymtable) then
  1221. begin
  1222. srsymtable:=sym.owner.next;
  1223. while assigned(srsymtable) do
  1224. begin
  1225. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1226. begin
  1227. srprocsym:=tprocsym(srsymtable.speedsearch(sym.name,sym.speedvalue));
  1228. { process only visible procsyms }
  1229. if assigned(srprocsym) and
  1230. (srprocsym.typ=procsym) and
  1231. srprocsym.is_visible_for_object(topclassh) then
  1232. begin
  1233. { if this procedure doesn't have overload we can stop
  1234. searching }
  1235. if not(po_overload in srprocsym.first_procdef.procoptions) then
  1236. break;
  1237. { process all overloaded definitions }
  1238. for j:=1 to srprocsym.procdef_count do
  1239. begin
  1240. pd:=srprocsym.procdef[j];
  1241. { only when the # of parameter are supported by the
  1242. procedure }
  1243. if (FParalength>=pd.minparacount) and
  1244. ((po_varargs in pd.procoptions) or { varargs }
  1245. (FParalength<=pd.maxparacount)) then
  1246. begin
  1247. found:=false;
  1248. hp:=FProcs;
  1249. while assigned(hp) do
  1250. begin
  1251. { Only compare visible parameters for the user }
  1252. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,[cpo_ignorehidden])>=te_equal then
  1253. begin
  1254. found:=true;
  1255. break;
  1256. end;
  1257. hp:=hp^.next;
  1258. end;
  1259. if not found then
  1260. proc_add(pd);
  1261. end;
  1262. end;
  1263. end;
  1264. end;
  1265. srsymtable:=srsymtable.next;
  1266. end;
  1267. end;
  1268. end;
  1269. constructor tcallcandidates.create_operator(op:ttoken;ppn:tnode);
  1270. var
  1271. j : integer;
  1272. pd : tprocdef;
  1273. hp : pcandidate;
  1274. found : boolean;
  1275. srsymtable : tsymtable;
  1276. srprocsym : tprocsym;
  1277. pt : tcallparanode;
  1278. sv : cardinal;
  1279. begin
  1280. FProcSym:=nil;
  1281. FProcs:=nil;
  1282. FProccnt:=0;
  1283. FProcvisiblecnt:=0;
  1284. FParanode:=ppn;
  1285. FAllowVariant:=false;
  1286. { determine length of parameter list }
  1287. pt:=tcallparanode(ppn);
  1288. FParalength:=0;
  1289. while assigned(pt) do
  1290. begin
  1291. if pt.resulttype.def.deftype=variantdef then
  1292. FAllowVariant:=true;
  1293. inc(FParalength);
  1294. pt:=tcallparanode(pt.right);
  1295. end;
  1296. { we search all overloaded operator definitions in the symtablestack. The found
  1297. entries are only added to the procs list and not the procsym, because
  1298. the list can change in every situation }
  1299. sv:=getspeedvalue(overloaded_names[op]);
  1300. srsymtable:=symtablestack;
  1301. while assigned(srsymtable) do
  1302. begin
  1303. if srsymtable.symtabletype in [localsymtable,staticsymtable,globalsymtable] then
  1304. begin
  1305. srprocsym:=tprocsym(srsymtable.speedsearch(overloaded_names[op],sv));
  1306. if assigned(srprocsym) and
  1307. (srprocsym.typ=procsym) then
  1308. begin
  1309. { Store first procsym found }
  1310. if not assigned(FProcsym) then
  1311. FProcsym:=srprocsym;
  1312. { process all overloaded definitions }
  1313. for j:=1 to srprocsym.procdef_count do
  1314. begin
  1315. pd:=srprocsym.procdef[j];
  1316. { only when the # of parameter are supported by the
  1317. procedure }
  1318. if (FParalength>=pd.minparacount) and
  1319. (FParalength<=pd.maxparacount) then
  1320. begin
  1321. found:=false;
  1322. hp:=FProcs;
  1323. while assigned(hp) do
  1324. begin
  1325. { Only compare visible parameters for the user }
  1326. if compare_paras(hp^.data.para,pd.para,cp_value_equal_const,[cpo_ignorehidden])>=te_equal then
  1327. begin
  1328. found:=true;
  1329. break;
  1330. end;
  1331. hp:=hp^.next;
  1332. end;
  1333. if not found then
  1334. proc_add(pd);
  1335. end;
  1336. end;
  1337. end;
  1338. end;
  1339. srsymtable:=srsymtable.next;
  1340. end;
  1341. end;
  1342. destructor tcallcandidates.destroy;
  1343. var
  1344. hpnext,
  1345. hp : pcandidate;
  1346. begin
  1347. hp:=FProcs;
  1348. while assigned(hp) do
  1349. begin
  1350. hpnext:=hp^.next;
  1351. dispose(hp);
  1352. hp:=hpnext;
  1353. end;
  1354. end;
  1355. function tcallcandidates.proc_add(pd:tprocdef):pcandidate;
  1356. var
  1357. i : integer;
  1358. begin
  1359. { generate new candidate entry }
  1360. new(result);
  1361. fillchar(result^,sizeof(tcandidate),0);
  1362. result^.data:=pd;
  1363. result^.next:=FProcs;
  1364. FProcs:=result;
  1365. inc(FProccnt);
  1366. { Find last parameter, skip all default parameters
  1367. that are not passed. Ignore this skipping for varargs }
  1368. result^.firstpara:=tparaitem(pd.Para.last);
  1369. if not(po_varargs in pd.procoptions) then
  1370. begin
  1371. { ignore hidden parameters }
  1372. while assigned(result^.firstpara) and (result^.firstpara.is_hidden) do
  1373. result^.firstpara:=tparaitem(result^.firstpara.previous);
  1374. for i:=1 to pd.maxparacount-FParalength do
  1375. begin
  1376. if not assigned(result^.firstpara) then
  1377. internalerror(200401141);
  1378. result^.firstpara:=tparaitem(result^.firstPara.previous);
  1379. end;
  1380. end;
  1381. end;
  1382. procedure tcallcandidates.list(all:boolean);
  1383. var
  1384. hp : pcandidate;
  1385. begin
  1386. hp:=FProcs;
  1387. while assigned(hp) do
  1388. begin
  1389. if all or
  1390. (not hp^.invalid) then
  1391. MessagePos1(hp^.data.fileinfo,sym_h_param_list,hp^.data.fullprocname(false));
  1392. hp:=hp^.next;
  1393. end;
  1394. end;
  1395. {$ifdef EXTDEBUG}
  1396. procedure tcallcandidates.dump_info(lvl:longint);
  1397. function ParaTreeStr(p:tcallparanode):string;
  1398. begin
  1399. result:='';
  1400. while assigned(p) do
  1401. begin
  1402. if result<>'' then
  1403. result:=result+',';
  1404. result:=result+p.resulttype.def.typename;
  1405. p:=tcallparanode(p.right);
  1406. end;
  1407. end;
  1408. var
  1409. hp : pcandidate;
  1410. currpara : tparaitem;
  1411. begin
  1412. if not CheckVerbosity(lvl) then
  1413. exit;
  1414. Comment(lvl+V_LineInfo,'Overloaded callnode: '+FProcSym.name+'('+ParaTreeStr(tcallparanode(FParaNode))+')');
  1415. hp:=FProcs;
  1416. while assigned(hp) do
  1417. begin
  1418. Comment(lvl,' '+hp^.data.fullprocname(false));
  1419. if (hp^.invalid) then
  1420. Comment(lvl,' invalid')
  1421. else
  1422. begin
  1423. Comment(lvl,' ex: '+tostr(hp^.exact_count)+
  1424. ' eq: '+tostr(hp^.equal_count)+
  1425. ' l1: '+tostr(hp^.cl1_count)+
  1426. ' l2: '+tostr(hp^.cl2_count)+
  1427. ' l3: '+tostr(hp^.cl3_count)+
  1428. ' oper: '+tostr(hp^.coper_count)+
  1429. ' ord: '+realtostr(hp^.exact_count));
  1430. { Print parameters in left-right order }
  1431. currpara:=hp^.firstpara;
  1432. if assigned(currpara) then
  1433. begin
  1434. while assigned(currpara.next) do
  1435. currpara:=tparaitem(currpara.next);
  1436. end;
  1437. while assigned(currpara) do
  1438. begin
  1439. if (not currpara.is_hidden) then
  1440. Comment(lvl,' - '+currpara.paratype.def.typename+' : '+EqualTypeName[currpara.eqval]);
  1441. currpara:=tparaitem(currpara.previous);
  1442. end;
  1443. end;
  1444. hp:=hp^.next;
  1445. end;
  1446. end;
  1447. {$endif EXTDEBUG}
  1448. procedure tcallcandidates.get_information;
  1449. var
  1450. hp : pcandidate;
  1451. currpara : tparaitem;
  1452. currparanr : byte;
  1453. def_from,
  1454. def_to : tdef;
  1455. currpt,
  1456. pt : tcallparanode;
  1457. eq : tequaltype;
  1458. convtype : tconverttype;
  1459. pdoper : tprocdef;
  1460. releasecurrpt : boolean;
  1461. cdoptions : tcompare_defs_options;
  1462. begin
  1463. cdoptions:=[cdo_check_operator];
  1464. if FAllowVariant then
  1465. include(cdoptions,cdo_allow_variant);
  1466. { process all procs }
  1467. hp:=FProcs;
  1468. while assigned(hp) do
  1469. begin
  1470. { We compare parameters in reverse order (right to left),
  1471. the firstpara is already pointing to the last parameter
  1472. were we need to start comparing }
  1473. currparanr:=FParalength;
  1474. currpara:=hp^.firstpara;
  1475. while assigned(currpara) and (currpara.is_hidden) do
  1476. currpara:=tparaitem(currpara.previous);
  1477. pt:=tcallparanode(FParaNode);
  1478. while assigned(pt) and assigned(currpara) do
  1479. begin
  1480. { currpt can be changed from loadn to calln when a procvar
  1481. is passed. This is to prevent that the change is permanent }
  1482. currpt:=pt;
  1483. releasecurrpt:=false;
  1484. { retrieve current parameter definitions to compares }
  1485. eq:=te_incompatible;
  1486. def_from:=currpt.resulttype.def;
  1487. def_to:=currpara.paratype.def;
  1488. if not(assigned(def_from)) then
  1489. internalerror(200212091);
  1490. if not(
  1491. assigned(def_to) or
  1492. ((po_varargs in hp^.data.procoptions) and
  1493. (currparanr>hp^.data.minparacount))
  1494. ) then
  1495. internalerror(200212092);
  1496. { Convert tp procvars when not expecting a procvar }
  1497. if (def_to.deftype<>procvardef) and
  1498. (currpt.left.resulttype.def.deftype=procvardef) then
  1499. begin
  1500. releasecurrpt:=true;
  1501. currpt:=tcallparanode(pt.getcopy);
  1502. if maybe_call_procvar(currpt.left,true) then
  1503. begin
  1504. currpt.resulttype:=currpt.left.resulttype;
  1505. def_from:=currpt.left.resulttype.def;
  1506. end;
  1507. end;
  1508. { varargs are always equal, but not exact }
  1509. if (po_varargs in hp^.data.procoptions) and
  1510. (currparanr>hp^.data.minparacount) then
  1511. begin
  1512. eq:=te_equal;
  1513. end
  1514. else
  1515. { same definition -> exact }
  1516. if (def_from=def_to) then
  1517. begin
  1518. eq:=te_exact;
  1519. end
  1520. else
  1521. { for value and const parameters check if a integer is constant or
  1522. included in other integer -> equal and calc ordinal_distance }
  1523. if not(currpara.paratyp in [vs_var,vs_out]) and
  1524. is_integer(def_from) and
  1525. is_integer(def_to) and
  1526. is_in_limit(def_from,def_to) then
  1527. begin
  1528. eq:=te_equal;
  1529. hp^.ordinal_distance:=hp^.ordinal_distance+
  1530. abs(bestreal(torddef(def_from).low)-bestreal(torddef(def_to).low));
  1531. hp^.ordinal_distance:=hp^.ordinal_distance+
  1532. abs(bestreal(torddef(def_to).high)-bestreal(torddef(def_from).high));
  1533. { Give wrong sign a small penalty, this is need to get a diffrence
  1534. from word->[longword,longint] }
  1535. if is_signed(def_from)<>is_signed(def_to) then
  1536. hp^.ordinal_distance:=hp^.ordinal_distance+1.0;
  1537. end
  1538. else
  1539. { generic type comparision }
  1540. begin
  1541. eq:=compare_defs_ext(def_from,def_to,currpt.left.nodetype,convtype,pdoper,cdoptions);
  1542. { when the types are not equal we need to check
  1543. some special case for parameter passing }
  1544. if (eq<te_equal) then
  1545. begin
  1546. if currpara.paratyp in [vs_var,vs_out] then
  1547. begin
  1548. { para requires an equal type so the previous found
  1549. match was not good enough, reset to incompatible }
  1550. eq:=te_incompatible;
  1551. { var_para_allowed will return te_equal and te_convert_l1 to
  1552. make a difference for best matching }
  1553. var_para_allowed(eq,currpt.resulttype.def,currpara.paratype.def)
  1554. end
  1555. else
  1556. para_allowed(eq,currpt,def_to);
  1557. end;
  1558. end;
  1559. { when a procvar was changed to a call an exact much is
  1560. downgraded to equal. This way an overload call with the
  1561. procvar is choosen. See tb0471 (PFV) }
  1562. if (pt<>currpt) and (eq=te_exact) then
  1563. eq:=te_equal;
  1564. { increase correct counter }
  1565. case eq of
  1566. te_exact :
  1567. inc(hp^.exact_count);
  1568. te_equal :
  1569. inc(hp^.equal_count);
  1570. te_convert_l1 :
  1571. inc(hp^.cl1_count);
  1572. te_convert_l2 :
  1573. inc(hp^.cl2_count);
  1574. te_convert_l3 :
  1575. inc(hp^.cl3_count);
  1576. te_convert_operator :
  1577. inc(hp^.coper_count);
  1578. te_incompatible :
  1579. hp^.invalid:=true;
  1580. else
  1581. internalerror(200212072);
  1582. end;
  1583. { stop checking when an incompatible parameter is found }
  1584. if hp^.invalid then
  1585. begin
  1586. { store the current parameter info for
  1587. a nice error message when no procedure is found }
  1588. hp^.wrongpara:=currpara;
  1589. hp^.wrongparanr:=currparanr;
  1590. break;
  1591. end;
  1592. {$ifdef EXTDEBUG}
  1593. { store equal in node tree for dump }
  1594. currpara.eqval:=eq;
  1595. {$endif EXTDEBUG}
  1596. { maybe release temp currpt }
  1597. if releasecurrpt then
  1598. currpt.free;
  1599. { next parameter in the call tree }
  1600. pt:=tcallparanode(pt.right);
  1601. { next parameter for definition, only goto next para
  1602. if we're out of the varargs }
  1603. if not(po_varargs in hp^.data.procoptions) or
  1604. (currparanr<=hp^.data.maxparacount) then
  1605. begin
  1606. { Ignore vs_hidden parameters }
  1607. repeat
  1608. currpara:=tparaitem(currpara.previous);
  1609. until (not assigned(currpara)) or (not currpara.is_hidden);
  1610. end;
  1611. dec(currparanr);
  1612. end;
  1613. if not(hp^.invalid) and
  1614. (assigned(pt) or assigned(currpara) or (currparanr<>0)) then
  1615. internalerror(200212141);
  1616. { next candidate }
  1617. hp:=hp^.next;
  1618. end;
  1619. end;
  1620. function is_better_candidate(currpd,bestpd:pcandidate):integer;
  1621. var
  1622. res : integer;
  1623. begin
  1624. {
  1625. Return values:
  1626. > 0 when currpd is better than bestpd
  1627. < 0 when bestpd is better than currpd
  1628. = 0 when both are equal
  1629. To choose the best candidate we use the following order:
  1630. - Incompatible flag
  1631. - (Smaller) Number of convert operator parameters.
  1632. - (Smaller) Number of convertlevel 2 parameters.
  1633. - (Smaller) Number of convertlevel 1 parameters.
  1634. - (Bigger) Number of exact parameters.
  1635. - (Smaller) Number of equal parameters.
  1636. - (Smaller) Total of ordinal distance. For example, the distance of a word
  1637. to a byte is 65535-255=65280.
  1638. }
  1639. if bestpd^.invalid then
  1640. begin
  1641. if currpd^.invalid then
  1642. res:=0
  1643. else
  1644. res:=1;
  1645. end
  1646. else
  1647. if currpd^.invalid then
  1648. res:=-1
  1649. else
  1650. begin
  1651. { less operator parameters? }
  1652. res:=(bestpd^.coper_count-currpd^.coper_count);
  1653. if (res=0) then
  1654. begin
  1655. { less cl3 parameters? }
  1656. res:=(bestpd^.cl3_count-currpd^.cl3_count);
  1657. if (res=0) then
  1658. begin
  1659. { less cl2 parameters? }
  1660. res:=(bestpd^.cl2_count-currpd^.cl2_count);
  1661. if (res=0) then
  1662. begin
  1663. { less cl1 parameters? }
  1664. res:=(bestpd^.cl1_count-currpd^.cl1_count);
  1665. if (res=0) then
  1666. begin
  1667. { more exact parameters? }
  1668. res:=(currpd^.exact_count-bestpd^.exact_count);
  1669. if (res=0) then
  1670. begin
  1671. { less equal parameters? }
  1672. res:=(bestpd^.equal_count-currpd^.equal_count);
  1673. if (res=0) then
  1674. begin
  1675. { smaller ordinal distance? }
  1676. if (currpd^.ordinal_distance<bestpd^.ordinal_distance) then
  1677. res:=1
  1678. else
  1679. if (currpd^.ordinal_distance>bestpd^.ordinal_distance) then
  1680. res:=-1
  1681. else
  1682. res:=0;
  1683. end;
  1684. end;
  1685. end;
  1686. end;
  1687. end;
  1688. end;
  1689. end;
  1690. is_better_candidate:=res;
  1691. end;
  1692. function tcallcandidates.choose_best(var bestpd:tabstractprocdef):integer;
  1693. var
  1694. besthpstart,
  1695. hp : pcandidate;
  1696. cntpd,
  1697. res : integer;
  1698. begin
  1699. {
  1700. Returns the number of candidates left and the
  1701. first candidate is returned in pdbest
  1702. }
  1703. { Setup the first procdef as best, only count it as a result
  1704. when it is valid }
  1705. bestpd:=FProcs^.data;
  1706. if FProcs^.invalid then
  1707. cntpd:=0
  1708. else
  1709. cntpd:=1;
  1710. if assigned(FProcs^.next) then
  1711. begin
  1712. besthpstart:=FProcs;
  1713. hp:=FProcs^.next;
  1714. while assigned(hp) do
  1715. begin
  1716. res:=is_better_candidate(hp,besthpstart);
  1717. if (res>0) then
  1718. begin
  1719. { hp is better, flag all procs to be incompatible }
  1720. while (besthpstart<>hp) do
  1721. begin
  1722. besthpstart^.invalid:=true;
  1723. besthpstart:=besthpstart^.next;
  1724. end;
  1725. { besthpstart is already set to hp }
  1726. bestpd:=besthpstart^.data;
  1727. cntpd:=1;
  1728. end
  1729. else
  1730. if (res<0) then
  1731. begin
  1732. { besthpstart is better, flag current hp to be incompatible }
  1733. hp^.invalid:=true;
  1734. end
  1735. else
  1736. begin
  1737. { res=0, both are valid }
  1738. if not hp^.invalid then
  1739. inc(cntpd);
  1740. end;
  1741. hp:=hp^.next;
  1742. end;
  1743. end;
  1744. result:=cntpd;
  1745. end;
  1746. procedure tcallcandidates.find_wrong_para;
  1747. var
  1748. currparanr : smallint;
  1749. hp : pcandidate;
  1750. pt : tcallparanode;
  1751. begin
  1752. { Only process the first overloaded procdef }
  1753. hp:=FProcs;
  1754. { Find callparanode corresponding to the argument }
  1755. pt:=tcallparanode(FParanode);
  1756. currparanr:=FParalength;
  1757. while assigned(pt) and
  1758. (currparanr>hp^.wrongparanr) do
  1759. begin
  1760. pt:=tcallparanode(pt.right);
  1761. dec(currparanr);
  1762. end;
  1763. if (currparanr<>hp^.wrongparanr) or
  1764. not assigned(pt) then
  1765. internalerror(200212094);
  1766. { Show error message, when it was a var or out parameter
  1767. guess that it is a missing typeconv }
  1768. if hp^.wrongpara.paratyp in [vs_var,vs_out] then
  1769. CGMessagePos2(pt.fileinfo,parser_e_call_by_ref_without_typeconv,
  1770. pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename)
  1771. else
  1772. CGMessagePos3(pt.fileinfo,type_e_wrong_parameter_type,
  1773. tostr(hp^.wrongparanr),pt.resulttype.def.typename,hp^.wrongpara.paratype.def.typename);
  1774. end;
  1775. end.
  1776. {
  1777. $Log$
  1778. Revision 1.88 2004-05-23 18:28:40 peter
  1779. * methodpointer is loaded into a temp when it was a calln
  1780. Revision 1.87 2004/05/23 15:03:40 peter
  1781. * some typeconvs don't allow assignment or passing to var para
  1782. Revision 1.86 2004/05/16 13:29:46 peter
  1783. * forbid more overloaded operators with orddef/enumdef
  1784. Revision 1.85 2004/04/18 07:52:43 florian
  1785. * fixed web bug 3048: comparision of dyn. arrays
  1786. Revision 1.84 2004/03/18 16:29:07 peter
  1787. * missing result initialization in node2opstr
  1788. Revision 1.83 2004/03/18 16:19:03 peter
  1789. * fixed operator overload allowing for pointer-string
  1790. * replaced some type_e_mismatch with more informational messages
  1791. Revision 1.82 2004/02/26 16:11:09 peter
  1792. * return cnothingn and give error when the operator is not overloaded
  1793. Revision 1.81 2004/02/24 16:12:39 peter
  1794. * operator overload chooses rewrite
  1795. * overload choosing is now generic and moved to htypechk
  1796. Revision 1.80 2004/02/20 21:55:19 peter
  1797. * widestring conversions added to allowed operator check
  1798. Revision 1.79 2004/02/13 15:42:21 peter
  1799. * compare_defs_ext has now a options argument
  1800. * fixes for variants
  1801. Revision 1.78 2004/02/12 15:54:03 peter
  1802. * make extcycle is working again
  1803. Revision 1.77 2004/02/04 22:15:15 daniel
  1804. * Rtti generation moved to ncgutil
  1805. * Assmtai usage of symsym removed
  1806. * operator overloading cleanup up
  1807. Revision 1.76 2004/02/03 22:32:53 peter
  1808. * renamed xNNbittype to xNNinttype
  1809. * renamed registers32 to registersint
  1810. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  1811. Revision 1.75 2003/11/12 15:48:27 peter
  1812. * fix set_varstate in for loops
  1813. * fix set_varstate from case statements
  1814. Revision 1.74 2003/10/30 19:20:05 peter
  1815. * fix IE when passing array to open array
  1816. Revision 1.73 2003/10/30 17:42:48 peter
  1817. * also check for uninited vars in staticsymtable
  1818. Revision 1.72 2003/10/28 15:36:01 peter
  1819. * absolute to object field supported, fixes tb0458
  1820. Revision 1.71 2003/10/21 18:16:13 peter
  1821. * IncompatibleTypes() added that will include unit names when
  1822. the typenames are the same
  1823. Revision 1.70 2003/10/20 19:29:12 peter
  1824. * fix check for typecasting wrong sizes in assignment left
  1825. Revision 1.69 2003/10/08 19:19:45 peter
  1826. * set_varstate cleanup
  1827. Revision 1.68 2003/10/05 21:21:52 peter
  1828. * c style array of const generates callparanodes
  1829. * varargs paraloc fixes
  1830. Revision 1.67 2003/10/01 20:34:48 peter
  1831. * procinfo unit contains tprocinfo
  1832. * cginfo renamed to cgbase
  1833. * moved cgmessage to verbose
  1834. * fixed ppc and sparc compiles
  1835. Revision 1.66 2003/08/23 18:52:18 peter
  1836. * don't check size for open array in valid_for_assign
  1837. Revision 1.65 2003/07/08 15:20:56 peter
  1838. * don't allow add/assignments for formaldef
  1839. * formaldef size changed to 0
  1840. Revision 1.64 2003/06/13 21:19:30 peter
  1841. * current_procdef removed, use current_procinfo.procdef instead
  1842. Revision 1.63 2003/05/09 17:47:02 peter
  1843. * self moved to hidden parameter
  1844. * removed hdisposen,hnewn,selfn
  1845. Revision 1.62 2003/04/27 11:21:32 peter
  1846. * aktprocdef renamed to current_procinfo.procdef
  1847. * procinfo renamed to current_procinfo
  1848. * procinfo will now be stored in current_module so it can be
  1849. cleaned up properly
  1850. * gen_main_procsym changed to create_main_proc and release_main_proc
  1851. to also generate a tprocinfo structure
  1852. * fixed unit implicit initfinal
  1853. Revision 1.61 2003/04/27 07:29:50 peter
  1854. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1855. a new procdef declaration
  1856. * aktprocsym removed
  1857. * lexlevel removed, use symtable.symtablelevel instead
  1858. * implicit init/final code uses the normal genentry/genexit
  1859. * funcret state checking updated for new funcret handling
  1860. Revision 1.60 2003/04/25 20:59:33 peter
  1861. * removed funcretn,funcretsym, function result is now in varsym
  1862. and aliases for result and function name are added using absolutesym
  1863. * vs_hidden parameter for funcret passed in parameter
  1864. * vs_hidden fixes
  1865. * writenode changed to printnode and released from extdebug
  1866. * -vp option added to generate a tree.log with the nodetree
  1867. * nicer printnode for statements, callnode
  1868. Revision 1.59 2003/04/22 23:50:22 peter
  1869. * firstpass uses expectloc
  1870. * checks if there are differences between the expectloc and
  1871. location.loc from secondpass in EXTDEBUG
  1872. Revision 1.58 2003/01/03 17:17:26 peter
  1873. * use compare_def_ext to test if assignn operator is allowed
  1874. Revision 1.57 2003/01/02 22:21:19 peter
  1875. * fixed previous operator change
  1876. Revision 1.56 2003/01/02 19:50:21 peter
  1877. * fixed operator checking for objects
  1878. * made binary operator checking simpeler
  1879. Revision 1.55 2002/12/27 18:06:32 peter
  1880. * fix overload error for dynarr:=nil
  1881. Revision 1.54 2002/12/22 16:34:49 peter
  1882. * proc-procvar crash fixed (tw2277)
  1883. Revision 1.53 2002/12/11 22:39:24 peter
  1884. * better error message when no operator is found for equal
  1885. Revision 1.52 2002/11/27 22:11:59 peter
  1886. * rewrote isbinaryoverloadable to use a case. it's now much easier
  1887. to understand what is happening
  1888. Revision 1.51 2002/11/25 17:43:17 peter
  1889. * splitted defbase in defutil,symutil,defcmp
  1890. * merged isconvertable and is_equal into compare_defs(_ext)
  1891. * made operator search faster by walking the list only once
  1892. Revision 1.50 2002/10/07 20:12:08 peter
  1893. * ugly hack to fix tb0411
  1894. Revision 1.49 2002/10/05 00:47:03 peter
  1895. * support dynamicarray<>nil
  1896. Revision 1.48 2002/10/04 21:13:59 peter
  1897. * ignore vecn,subscriptn when checking for a procvar loadn
  1898. Revision 1.47 2002/09/16 18:09:34 peter
  1899. * set_funcret_valid fixed when result was already used in a nested
  1900. procedure
  1901. Revision 1.46 2002/07/20 11:57:53 florian
  1902. * types.pas renamed to defbase.pas because D6 contains a types
  1903. unit so this would conflicts if D6 programms are compiled
  1904. + Willamette/SSE2 instructions to assembler added
  1905. Revision 1.45 2002/05/18 13:34:08 peter
  1906. * readded missing revisions
  1907. Revision 1.44 2002/05/16 19:46:37 carl
  1908. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1909. + try to fix temp allocation (still in ifdef)
  1910. + generic constructor calls
  1911. + start of tassembler / tmodulebase class cleanup
  1912. Revision 1.42 2002/04/02 17:11:28 peter
  1913. * tlocation,treference update
  1914. * LOC_CONSTANT added for better constant handling
  1915. * secondadd splitted in multiple routines
  1916. * location_force_reg added for loading a location to a register
  1917. of a specified size
  1918. * secondassignment parses now first the right and then the left node
  1919. (this is compatible with Kylix). This saves a lot of push/pop especially
  1920. with string operations
  1921. * adapted some routines to use the new cg methods
  1922. Revision 1.41 2002/01/16 09:33:46 jonas
  1923. * no longer allow assignments to pointer expressions (unless there's a
  1924. deref), reported by John Lee
  1925. }